blob: d7b271339a5cc24fd4f33b91fc3ce688bd469925 [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
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700290 if (!(ha->fw_attributes & BIT_6)) {
291 qla_printk(KERN_INFO, ha,
292 "Firmware is not multi-queue capable\n");
293 goto fail;
294 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700295 if (ql2xmultique_tag) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700296 /* create a request queue for IO */
297 options |= BIT_7;
298 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
299 QLA_DEFAULT_QUE_QOS);
300 if (!req) {
301 qla_printk(KERN_WARNING, ha,
302 "Can't create request queue\n");
303 goto fail;
304 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700305 ha->wq = create_workqueue("qla2xxx_wq");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700306 vha->req = ha->req_q_map[req];
307 options |= BIT_1;
308 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
309 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
310 if (!ret) {
311 qla_printk(KERN_WARNING, ha,
312 "Response Queue create failed\n");
313 goto fail2;
314 }
315 }
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700316 ha->flags.cpu_affinity_enabled = 1;
317
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700318 DEBUG2(qla_printk(KERN_INFO, ha,
319 "CPU affinity mode enabled, no. of response"
320 " queues:%d, no. of request queues:%d\n",
321 ha->max_rsp_queues, ha->max_req_queues));
322 }
323 return 0;
324fail2:
325 qla25xx_delete_queues(vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700326 destroy_workqueue(ha->wq);
327 ha->wq = NULL;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700328fail:
329 ha->mqenable = 0;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -0700330 kfree(ha->req_q_map);
331 kfree(ha->rsp_q_map);
332 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700333 return 1;
334}
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800337qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800339 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 static char *pci_bus_modes[] = {
341 "33", "66", "100", "133",
342 };
343 uint16_t pci_bus;
344
345 strcpy(str, "PCI");
346 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
347 if (pci_bus) {
348 strcat(str, "-X (");
349 strcat(str, pci_bus_modes[pci_bus]);
350 } else {
351 pci_bus = (ha->pci_attr & BIT_8) >> 8;
352 strcat(str, " (");
353 strcat(str, pci_bus_modes[pci_bus]);
354 }
355 strcat(str, " MHz)");
356
357 return (str);
358}
359
Andrew Vasquezfca29702005-07-06 10:31:47 -0700360static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800361qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700362{
363 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800364 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700365 uint32_t pci_bus;
366 int pcie_reg;
367
368 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
369 if (pcie_reg) {
370 char lwstr[6];
371 uint16_t pcie_lstat, lspeed, lwidth;
372
373 pcie_reg += 0x12;
374 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
375 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
376 lwidth = (pcie_lstat &
377 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
378
379 strcpy(str, "PCIe (");
380 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700381 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700382 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700383 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700384 else
385 strcat(str, "<unknown> ");
386 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
387 strcat(str, lwstr);
388
389 return str;
390 }
391
392 strcpy(str, "PCI");
393 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
394 if (pci_bus == 0 || pci_bus == 8) {
395 strcat(str, " (");
396 strcat(str, pci_bus_modes[pci_bus >> 3]);
397 } else {
398 strcat(str, "-X ");
399 if (pci_bus & BIT_2)
400 strcat(str, "Mode 2");
401 else
402 strcat(str, "Mode 1");
403 strcat(str, " (");
404 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
405 }
406 strcat(str, " MHz)");
407
408 return str;
409}
410
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800411static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800412qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
414 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800415 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
418 ha->fw_minor_version,
419 ha->fw_subminor_version);
420
421 if (ha->fw_attributes & BIT_9) {
422 strcat(str, "FLX");
423 return (str);
424 }
425
426 switch (ha->fw_attributes & 0xFF) {
427 case 0x7:
428 strcat(str, "EF");
429 break;
430 case 0x17:
431 strcat(str, "TP");
432 break;
433 case 0x37:
434 strcat(str, "IP");
435 break;
436 case 0x77:
437 strcat(str, "VI");
438 break;
439 default:
440 sprintf(un_str, "(%x)", ha->fw_attributes);
441 strcat(str, un_str);
442 break;
443 }
444 if (ha->fw_attributes & 0x100)
445 strcat(str, "X");
446
447 return (str);
448}
449
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800450static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800451qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700452{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800453 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700454
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800455 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
456 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700457 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700458}
459
460static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800461qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700462 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
463{
464 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800465 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700466
467 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
468 if (!sp)
469 return sp;
470
Andrew Vasquezfca29702005-07-06 10:31:47 -0700471 sp->fcport = fcport;
472 sp->cmd = cmd;
473 sp->flags = 0;
474 CMD_SP(cmd) = (void *)sp;
475 cmd->scsi_done = done;
476
477 return sp;
478}
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480static int
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700481qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Andrew Vasquezfca29702005-07-06 10:31:47 -0700482{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800483 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700484 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400485 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800486 struct qla_hw_data *ha = vha->hw;
487 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700488 srb_t *sp;
489 int rval;
490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800491 if (unlikely(pci_channel_offline(ha->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -0700492 if (ha->pdev->error_state == pci_channel_io_frozen)
493 cmd->result = DID_REQUEUE << 16;
494 else
495 cmd->result = DID_NO_CONNECT << 16;
Seokmann Ju14e660e2007-09-20 14:07:36 -0700496 goto qc24_fail_command;
497 }
498
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400499 rval = fc_remote_port_chkready(rport);
500 if (rval) {
501 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700502 goto qc24_fail_command;
503 }
504
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800505 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500506 if (fcport->drport)
507 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800508
Andrew Vasquezfca29702005-07-06 10:31:47 -0700509 if (atomic_read(&fcport->state) != FCS_ONLINE) {
510 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700512 cmd->result = DID_NO_CONNECT << 16;
513 goto qc24_fail_command;
514 }
Mike Christie7b594132008-08-17 15:24:40 -0500515 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700516 }
517
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800518 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800520 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700521 if (!sp)
522 goto qc24_host_busy_lock;
523
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700525 if (rval != QLA_SUCCESS)
526 goto qc24_host_busy_free_sp;
527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800528 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700529
530 return 0;
531
532qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800533 qla2x00_sp_free_dma(sp);
534 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700535
536qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800537 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700538 return SCSI_MLQUEUE_HOST_BUSY;
539
Mike Christie7b594132008-08-17 15:24:40 -0500540qc24_target_busy:
541 return SCSI_MLQUEUE_TARGET_BUSY;
542
Andrew Vasquezfca29702005-07-06 10:31:47 -0700543qc24_fail_command:
544 done(cmd);
545
546 return 0;
547}
548
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550/*
551 * qla2x00_eh_wait_on_command
552 * Waits for the command to be returned by the Firmware for some
553 * max time.
554 *
555 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 *
558 * Return:
559 * Not Found : 0
560 * Found : 1
561 */
562static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700565#define ABORT_POLLING_PERIOD 1000
566#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500567 unsigned long wait_iter = ABORT_WAIT_ITER;
568 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
f4f051e2005-04-17 15:02:26 -0500570 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700571 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
f4f051e2005-04-17 15:02:26 -0500573 if (--wait_iter)
574 break;
575 }
576 if (CMD_SP(cmd))
577 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
f4f051e2005-04-17 15:02:26 -0500579 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580}
581
582/*
583 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700584 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 * <= MAX_RETRIES_OF_ISP_ABORT or
586 * finally HBA is disabled ie marked offline
587 *
588 * Input:
589 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700590 *
591 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 * Does context switching-Release SPIN_LOCK
593 * (if any) before calling this routine.
594 *
595 * Return:
596 * Success (Adapter is online) : 0
597 * Failed (Adapter is offline/disabled) : 1
598 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800599int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800600qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700602 int return_status;
603 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800604 struct qla_hw_data *ha = vha->hw;
605 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700607 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800608 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
609 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
610 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
611 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 msleep(1000);
614 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800615 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700616 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 else
618 return_status = QLA_FUNCTION_FAILED;
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 return (return_status);
621}
622
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700623int
624qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
625{
626 int return_status;
627 unsigned long wait_reset;
628 struct qla_hw_data *ha = vha->hw;
629 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
630
631 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
632 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
633 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
634 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
635 ha->dpc_active) && time_before(jiffies, wait_reset)) {
636
637 msleep(1000);
638
639 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
640 ha->flags.chip_reset_done)
641 break;
642 }
643 if (ha->flags.chip_reset_done)
644 return_status = QLA_SUCCESS;
645 else
646 return_status = QLA_FUNCTION_FAILED;
647
648 return return_status;
649}
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651/*
652 * qla2x00_wait_for_loop_ready
653 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700654 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 * Input:
656 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700657 *
658 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 * Does context switching-Release SPIN_LOCK
660 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700661 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 *
663 * Return:
664 * Success (LOOP_READY) : 0
665 * Failed (LOOP_NOT_READY) : 1
666 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700667static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800668qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
670 int return_status = QLA_SUCCESS;
671 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800672 struct qla_hw_data *ha = vha->hw;
673 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700676 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 while ((!atomic_read(&base_vha->loop_down_timer) &&
679 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
680 atomic_read(&base_vha->loop_state) != LOOP_READY) {
681 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700682 return_status = QLA_FUNCTION_FAILED;
683 break;
684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 msleep(1000);
686 if (time_after_eq(jiffies, loop_timeout)) {
687 return_status = QLA_FUNCTION_FAILED;
688 break;
689 }
690 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700691 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700694void
695qla2x00_abort_fcport_cmds(fc_port_t *fcport)
696{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700697 int cnt;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700698 unsigned long flags;
699 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800700 scsi_qla_host_t *vha = fcport->vha;
701 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800702 struct req_que *req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700703
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800704 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700705 req = vha->req;
706 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
707 sp = req->outstanding_cmds[cnt];
708 if (!sp)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700709 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700710 if (sp->fcport != fcport)
711 continue;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700712
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700713 spin_unlock_irqrestore(&ha->hardware_lock, flags);
714 if (ha->isp_ops->abort_command(sp)) {
715 DEBUG2(qla_printk(KERN_WARNING, ha,
716 "Abort failed -- %lx\n",
717 sp->cmd->serial_number));
718 } else {
719 if (qla2x00_eh_wait_on_command(sp->cmd) !=
720 QLA_SUCCESS)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700721 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700722 "Abort failed while waiting -- %lx\n",
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800723 sp->cmd->serial_number));
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700724 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700725 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700726 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700728}
729
Andrew Vasquez07db5182006-10-02 12:00:49 -0700730static void
731qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
732{
733 struct Scsi_Host *shost = cmnd->device->host;
734 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
735 unsigned long flags;
736
737 spin_lock_irqsave(shost->host_lock, flags);
738 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
739 spin_unlock_irqrestore(shost->host_lock, flags);
740 msleep(1000);
741 spin_lock_irqsave(shost->host_lock, flags);
742 }
743 spin_unlock_irqrestore(shost->host_lock, flags);
744 return;
745}
746
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747/**************************************************************************
748* qla2xxx_eh_abort
749*
750* Description:
751* The abort function will abort the specified command.
752*
753* Input:
754* cmd = Linux SCSI command packet to be aborted.
755*
756* Returns:
757* Either SUCCESS or FAILED.
758*
759* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700760* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800762static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763qla2xxx_eh_abort(struct scsi_cmnd *cmd)
764{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800765 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500766 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800767 int ret, i;
f4f051e2005-04-17 15:02:26 -0500768 unsigned int id, lun;
769 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700770 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700771 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800772 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700773 struct req_que *req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800774 srb_t *spt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Andrew Vasquez07db5182006-10-02 12:00:49 -0700776 qla2x00_block_error_handler(cmd);
777
f4f051e2005-04-17 15:02:26 -0500778 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700779 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Michael Reed2ea00202006-04-27 16:25:30 -0700781 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
f4f051e2005-04-17 15:02:26 -0500783 id = cmd->device->id;
784 lun = cmd->device->lun;
785 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800786 spt = (srb_t *) CMD_SP(cmd);
787 if (!spt)
788 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500789
790 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800791 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800792 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
793 sp = req->outstanding_cmds[i];
794
795 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500796 continue;
797
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800798 if (sp->cmd != cmd)
799 continue;
f4f051e2005-04-17 15:02:26 -0500800
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800801 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
802 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500803
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800804 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700805 if (ha->isp_ops->abort_command(sp)) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800806 DEBUG2(printk("%s(%ld): abort_command "
807 "mbx failed.\n", __func__, vha->host_no));
Andrew Vasquez2ac4b642009-01-22 09:45:35 -0800808 ret = FAILED;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800809 } else {
810 DEBUG3(printk("%s(%ld): abort_command "
811 "mbx success.\n", __func__, vha->host_no));
812 wait = 1;
f4f051e2005-04-17 15:02:26 -0500813 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800814 spin_lock_irqsave(&ha->hardware_lock, flags);
815 break;
f4f051e2005-04-17 15:02:26 -0500816 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800817 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500818
819 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700820 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800821 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700822 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500823 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800824 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700825 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700829 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700830 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
f4f051e2005-04-17 15:02:26 -0500833 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834}
835
Andrew Vasquez523ec772008-04-03 13:13:24 -0700836enum nexus_wait_type {
837 WAIT_HOST = 0,
838 WAIT_TARGET,
839 WAIT_LUN,
840};
841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800843qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800844 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800846 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700847 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800848 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800849 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Andrew Vasquez523ec772008-04-03 13:13:24 -0700851 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800852 if (!sp)
853 return status;
854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800855 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700856 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800857 for (cnt = 1; status == QLA_SUCCESS &&
858 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
859 sp = req->outstanding_cmds[cnt];
860 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700861 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700862
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800863 if (vha->vp_idx != sp->fcport->vha->vp_idx)
864 continue;
865 match = 0;
866 switch (type) {
867 case WAIT_HOST:
868 match = 1;
869 break;
870 case WAIT_TARGET:
871 match = sp->cmd->device->id == t;
872 break;
873 case WAIT_LUN:
874 match = (sp->cmd->device->id == t &&
875 sp->cmd->device->lun == l);
876 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800878 if (!match)
879 continue;
880
881 spin_unlock_irqrestore(&ha->hardware_lock, flags);
882 status = qla2x00_eh_wait_on_command(sp->cmd);
883 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800885 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700886
887 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888}
889
Andrew Vasquez523ec772008-04-03 13:13:24 -0700890static char *reset_errors[] = {
891 "HBA not online",
892 "HBA not ready",
893 "Task management failed",
894 "Waiting for command completions",
895};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Andrew Vasquez523ec772008-04-03 13:13:24 -0700897static int
898__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700899 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700900{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800901 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700902 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
903 int err;
904
905 qla2x00_block_error_handler(cmd);
906
907 if (!fcport)
908 return FAILED;
909
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800910 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
911 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700912
913 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800914 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700915 goto eh_reset_failed;
916 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800917 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700918 goto eh_reset_failed;
919 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700920 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
921 != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700922 goto eh_reset_failed;
923 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800924 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800925 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700926 goto eh_reset_failed;
927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
929 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700930
931 return SUCCESS;
932
933 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
935 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700936 reset_errors[err]);
937 return FAILED;
938}
939
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800940static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
942{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800943 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
944 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Andrew Vasquez523ec772008-04-03 13:13:24 -0700946 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
947 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948}
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700951qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800953 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
954 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Andrew Vasquez523ec772008-04-03 13:13:24 -0700956 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
957 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960/**************************************************************************
961* qla2xxx_eh_bus_reset
962*
963* Description:
964* The bus reset function will reset the bus and abort any executing
965* commands.
966*
967* Input:
968* cmd = Linux SCSI command packet of the command that cause the
969* bus reset.
970*
971* Returns:
972* SUCCESS/FAILURE (defined as macro in scsi.h).
973*
974**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800975static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
977{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800978 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500979 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700980 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500981 unsigned int id, lun;
982 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800983 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Andrew Vasquez07db5182006-10-02 12:00:49 -0700985 qla2x00_block_error_handler(cmd);
986
f4f051e2005-04-17 15:02:26 -0500987 id = cmd->device->id;
988 lun = cmd->device->lun;
989 serial = cmd->serial_number;
990
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700991 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500992 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800994 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -0800995 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800997 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500999 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 }
1001
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001002 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
1003 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001004 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 }
f4f051e2005-04-17 15:02:26 -05001006 if (ret == FAILED)
1007 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001009 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001010 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -07001011 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001012 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
f4f051e2005-04-17 15:02:26 -05001014eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001015 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -05001016 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
f4f051e2005-04-17 15:02:26 -05001018 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
1020
1021/**************************************************************************
1022* qla2xxx_eh_host_reset
1023*
1024* Description:
1025* The reset function will reset the Adapter.
1026*
1027* Input:
1028* cmd = Linux SCSI command packet of the command that cause the
1029* adapter reset.
1030*
1031* Returns:
1032* Either SUCCESS or FAILED.
1033*
1034* Note:
1035**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001036static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1038{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001039 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001040 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001041 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001042 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001043 unsigned int id, lun;
1044 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001045 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001046 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Andrew Vasquez07db5182006-10-02 12:00:49 -07001048 qla2x00_block_error_handler(cmd);
1049
f4f051e2005-04-17 15:02:26 -05001050 id = cmd->device->id;
1051 lun = cmd->device->lun;
1052 serial = cmd->serial_number;
1053
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001054 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001055 return ret;
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001058 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001061 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 /*
1064 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001065 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 * be completed and then issue big hammer.Otherwise
1067 * it may cause I/O failure as big hammer marks the
1068 * devices as lost kicking of the port_down_timer
1069 * while dpc is stuck for the mailbox to complete.
1070 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001071 qla2x00_wait_for_loop_ready(vha);
1072 if (vha != base_vha) {
1073 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001074 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001076 if (ha->wq)
1077 flush_workqueue(ha->wq);
1078
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001079 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1080 if (qla2x00_abort_isp(base_vha)) {
1081 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1082 /* failed. schedule dpc to try */
1083 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1084
1085 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1086 goto eh_host_reset_lock;
1087 }
1088 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001091 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001092 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001093 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001094 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
f4f051e2005-04-17 15:02:26 -05001096eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001097 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1098 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
f4f051e2005-04-17 15:02:26 -05001100 return ret;
1101}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103/*
1104* qla2x00_loop_reset
1105* Issue loop reset.
1106*
1107* Input:
1108* ha = adapter block pointer.
1109*
1110* Returns:
1111* 0 = success
1112*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001113int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001114qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001116 int ret;
bdf79622005-04-17 15:06:53 -05001117 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001118 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Seokmann Jud53b48d2009-04-06 22:33:37 -07001120 if (ha->flags.enable_lip_full_login && !vha->vp_idx &&
1121 !IS_QLA81XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001122 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001123 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001124 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001125 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001126 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001127 }
1128 atomic_set(&vha->loop_state, LOOP_DOWN);
1129 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1130 qla2x00_mark_all_devices_lost(vha, 0);
1131 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 }
1133
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001134 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001135 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001136 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001137 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001138 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1139 } else
1140 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001141 }
1142
1143 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001144 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001145 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 continue;
1147
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001148 ret = ha->isp_ops->target_reset(fcport, 0, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001149 if (ret != QLA_SUCCESS) {
1150 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1151 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001152 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
1155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001157 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001159 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001162void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001163qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001164{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001165 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001166 unsigned long flags;
1167 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001168 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001169 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001170
1171 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001172 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001173 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001174 if (!req)
1175 continue;
1176 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1177 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001178 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001179 req->outstanding_cmds[cnt] = NULL;
1180 sp->cmd->result = res;
1181 qla2x00_sp_compl(ha, sp);
1182 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001183 }
1184 }
1185 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1186}
1187
f4f051e2005-04-17 15:02:26 -05001188static int
1189qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
bdf79622005-04-17 15:06:53 -05001191 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001193 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001194 return -ENXIO;
1195
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001196 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001197
1198 return 0;
1199}
1200
1201static int
1202qla2xxx_slave_configure(struct scsi_device *sdev)
1203{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001204 scsi_qla_host_t *vha = shost_priv(sdev->host);
1205 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001206 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001207 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001208
f4f051e2005-04-17 15:02:26 -05001209 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001210 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001212 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Andrew Vasquez85821c92008-07-10 16:55:48 -07001214 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001215
f4f051e2005-04-17 15:02:26 -05001216 return 0;
1217}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
f4f051e2005-04-17 15:02:26 -05001219static void
1220qla2xxx_slave_destroy(struct scsi_device *sdev)
1221{
1222 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001225static int
1226qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1227{
1228 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1229 return sdev->queue_depth;
1230}
1231
1232static int
1233qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1234{
1235 if (sdev->tagged_supported) {
1236 scsi_set_tag_type(sdev, tag_type);
1237 if (tag_type)
1238 scsi_activate_tcq(sdev, sdev->queue_depth);
1239 else
1240 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1241 } else
1242 tag_type = 0;
1243
1244 return tag_type;
1245}
1246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247/**
1248 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1249 * @ha: HA context
1250 *
1251 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1252 * supported addressing method.
1253 */
1254static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001255qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001257 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Yang Hongyang6a355282009-04-06 19:01:13 -07001260 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001261 /* Any upper-dword bits set? */
1262 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001263 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001264 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001266 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1267 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001268 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001271
Yang Hongyang284901a2009-04-06 19:01:15 -07001272 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1273 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274}
1275
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001276static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001277qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001278{
1279 unsigned long flags = 0;
1280 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1281
1282 spin_lock_irqsave(&ha->hardware_lock, flags);
1283 ha->interrupts_on = 1;
1284 /* enable risc and host interrupts */
1285 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1286 RD_REG_WORD(&reg->ictrl);
1287 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1288
1289}
1290
1291static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001292qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001293{
1294 unsigned long flags = 0;
1295 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1296
1297 spin_lock_irqsave(&ha->hardware_lock, flags);
1298 ha->interrupts_on = 0;
1299 /* disable risc and host interrupts */
1300 WRT_REG_WORD(&reg->ictrl, 0);
1301 RD_REG_WORD(&reg->ictrl);
1302 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1303}
1304
1305static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001306qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001307{
1308 unsigned long flags = 0;
1309 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1310
1311 spin_lock_irqsave(&ha->hardware_lock, flags);
1312 ha->interrupts_on = 1;
1313 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1314 RD_REG_DWORD(&reg->ictrl);
1315 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1316}
1317
1318static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001319qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001320{
1321 unsigned long flags = 0;
1322 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1323
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001324 if (IS_NOPOLLING_TYPE(ha))
1325 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001326 spin_lock_irqsave(&ha->hardware_lock, flags);
1327 ha->interrupts_on = 0;
1328 WRT_REG_DWORD(&reg->ictrl, 0);
1329 RD_REG_DWORD(&reg->ictrl);
1330 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1331}
1332
1333static struct isp_operations qla2100_isp_ops = {
1334 .pci_config = qla2100_pci_config,
1335 .reset_chip = qla2x00_reset_chip,
1336 .chip_diag = qla2x00_chip_diag,
1337 .config_rings = qla2x00_config_rings,
1338 .reset_adapter = qla2x00_reset_adapter,
1339 .nvram_config = qla2x00_nvram_config,
1340 .update_fw_options = qla2x00_update_fw_options,
1341 .load_risc = qla2x00_load_risc,
1342 .pci_info_str = qla2x00_pci_info_str,
1343 .fw_version_str = qla2x00_fw_version_str,
1344 .intr_handler = qla2100_intr_handler,
1345 .enable_intrs = qla2x00_enable_intrs,
1346 .disable_intrs = qla2x00_disable_intrs,
1347 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001348 .target_reset = qla2x00_abort_target,
1349 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001350 .fabric_login = qla2x00_login_fabric,
1351 .fabric_logout = qla2x00_fabric_logout,
1352 .calc_req_entries = qla2x00_calc_iocbs_32,
1353 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1354 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1355 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1356 .read_nvram = qla2x00_read_nvram_data,
1357 .write_nvram = qla2x00_write_nvram_data,
1358 .fw_dump = qla2100_fw_dump,
1359 .beacon_on = NULL,
1360 .beacon_off = NULL,
1361 .beacon_blink = NULL,
1362 .read_optrom = qla2x00_read_optrom_data,
1363 .write_optrom = qla2x00_write_optrom_data,
1364 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001366};
1367
1368static struct isp_operations qla2300_isp_ops = {
1369 .pci_config = qla2300_pci_config,
1370 .reset_chip = qla2x00_reset_chip,
1371 .chip_diag = qla2x00_chip_diag,
1372 .config_rings = qla2x00_config_rings,
1373 .reset_adapter = qla2x00_reset_adapter,
1374 .nvram_config = qla2x00_nvram_config,
1375 .update_fw_options = qla2x00_update_fw_options,
1376 .load_risc = qla2x00_load_risc,
1377 .pci_info_str = qla2x00_pci_info_str,
1378 .fw_version_str = qla2x00_fw_version_str,
1379 .intr_handler = qla2300_intr_handler,
1380 .enable_intrs = qla2x00_enable_intrs,
1381 .disable_intrs = qla2x00_disable_intrs,
1382 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001383 .target_reset = qla2x00_abort_target,
1384 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001385 .fabric_login = qla2x00_login_fabric,
1386 .fabric_logout = qla2x00_fabric_logout,
1387 .calc_req_entries = qla2x00_calc_iocbs_32,
1388 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1389 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1390 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1391 .read_nvram = qla2x00_read_nvram_data,
1392 .write_nvram = qla2x00_write_nvram_data,
1393 .fw_dump = qla2300_fw_dump,
1394 .beacon_on = qla2x00_beacon_on,
1395 .beacon_off = qla2x00_beacon_off,
1396 .beacon_blink = qla2x00_beacon_blink,
1397 .read_optrom = qla2x00_read_optrom_data,
1398 .write_optrom = qla2x00_write_optrom_data,
1399 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001400 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001401};
1402
1403static struct isp_operations qla24xx_isp_ops = {
1404 .pci_config = qla24xx_pci_config,
1405 .reset_chip = qla24xx_reset_chip,
1406 .chip_diag = qla24xx_chip_diag,
1407 .config_rings = qla24xx_config_rings,
1408 .reset_adapter = qla24xx_reset_adapter,
1409 .nvram_config = qla24xx_nvram_config,
1410 .update_fw_options = qla24xx_update_fw_options,
1411 .load_risc = qla24xx_load_risc,
1412 .pci_info_str = qla24xx_pci_info_str,
1413 .fw_version_str = qla24xx_fw_version_str,
1414 .intr_handler = qla24xx_intr_handler,
1415 .enable_intrs = qla24xx_enable_intrs,
1416 .disable_intrs = qla24xx_disable_intrs,
1417 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001418 .target_reset = qla24xx_abort_target,
1419 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001420 .fabric_login = qla24xx_login_fabric,
1421 .fabric_logout = qla24xx_fabric_logout,
1422 .calc_req_entries = NULL,
1423 .build_iocbs = NULL,
1424 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1425 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1426 .read_nvram = qla24xx_read_nvram_data,
1427 .write_nvram = qla24xx_write_nvram_data,
1428 .fw_dump = qla24xx_fw_dump,
1429 .beacon_on = qla24xx_beacon_on,
1430 .beacon_off = qla24xx_beacon_off,
1431 .beacon_blink = qla24xx_beacon_blink,
1432 .read_optrom = qla24xx_read_optrom_data,
1433 .write_optrom = qla24xx_write_optrom_data,
1434 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001435 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001436};
1437
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001438static struct isp_operations qla25xx_isp_ops = {
1439 .pci_config = qla25xx_pci_config,
1440 .reset_chip = qla24xx_reset_chip,
1441 .chip_diag = qla24xx_chip_diag,
1442 .config_rings = qla24xx_config_rings,
1443 .reset_adapter = qla24xx_reset_adapter,
1444 .nvram_config = qla24xx_nvram_config,
1445 .update_fw_options = qla24xx_update_fw_options,
1446 .load_risc = qla24xx_load_risc,
1447 .pci_info_str = qla24xx_pci_info_str,
1448 .fw_version_str = qla24xx_fw_version_str,
1449 .intr_handler = qla24xx_intr_handler,
1450 .enable_intrs = qla24xx_enable_intrs,
1451 .disable_intrs = qla24xx_disable_intrs,
1452 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001453 .target_reset = qla24xx_abort_target,
1454 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001455 .fabric_login = qla24xx_login_fabric,
1456 .fabric_logout = qla24xx_fabric_logout,
1457 .calc_req_entries = NULL,
1458 .build_iocbs = NULL,
1459 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1460 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1461 .read_nvram = qla25xx_read_nvram_data,
1462 .write_nvram = qla25xx_write_nvram_data,
1463 .fw_dump = qla25xx_fw_dump,
1464 .beacon_on = qla24xx_beacon_on,
1465 .beacon_off = qla24xx_beacon_off,
1466 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001467 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001468 .write_optrom = qla24xx_write_optrom_data,
1469 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001470 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001471};
1472
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001473static struct isp_operations qla81xx_isp_ops = {
1474 .pci_config = qla25xx_pci_config,
1475 .reset_chip = qla24xx_reset_chip,
1476 .chip_diag = qla24xx_chip_diag,
1477 .config_rings = qla24xx_config_rings,
1478 .reset_adapter = qla24xx_reset_adapter,
1479 .nvram_config = qla81xx_nvram_config,
1480 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001481 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001482 .pci_info_str = qla24xx_pci_info_str,
1483 .fw_version_str = qla24xx_fw_version_str,
1484 .intr_handler = qla24xx_intr_handler,
1485 .enable_intrs = qla24xx_enable_intrs,
1486 .disable_intrs = qla24xx_disable_intrs,
1487 .abort_command = qla24xx_abort_command,
1488 .target_reset = qla24xx_abort_target,
1489 .lun_reset = qla24xx_lun_reset,
1490 .fabric_login = qla24xx_login_fabric,
1491 .fabric_logout = qla24xx_fabric_logout,
1492 .calc_req_entries = NULL,
1493 .build_iocbs = NULL,
1494 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1495 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001496 .read_nvram = NULL,
1497 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001498 .fw_dump = qla81xx_fw_dump,
1499 .beacon_on = qla24xx_beacon_on,
1500 .beacon_off = qla24xx_beacon_off,
1501 .beacon_blink = qla24xx_beacon_blink,
1502 .read_optrom = qla25xx_read_optrom_data,
1503 .write_optrom = qla24xx_write_optrom_data,
1504 .get_flash_version = qla24xx_get_flash_version,
1505 .start_scsi = qla24xx_start_scsi,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001506};
1507
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001508static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001509qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001510{
1511 ha->device_type = DT_EXTENDED_IDS;
1512 switch (ha->pdev->device) {
1513 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1514 ha->device_type |= DT_ISP2100;
1515 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001516 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001517 break;
1518 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1519 ha->device_type |= DT_ISP2200;
1520 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001521 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001522 break;
1523 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1524 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001525 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001526 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001527 break;
1528 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1529 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001530 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001531 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001532 break;
1533 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1534 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001535 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001536 if (ha->pdev->subsystem_vendor == 0x1028 &&
1537 ha->pdev->subsystem_device == 0x0170)
1538 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001539 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001540 break;
1541 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1542 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001543 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001544 break;
1545 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1546 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001547 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001548 break;
1549 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1550 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001551 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001552 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001553 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001554 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001555 break;
1556 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1557 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001558 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001559 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001560 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001561 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001562 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001563 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1564 ha->device_type |= DT_ISP8432;
1565 ha->device_type |= DT_ZIO_SUPPORTED;
1566 ha->device_type |= DT_FWI2;
1567 ha->device_type |= DT_IIDMA;
1568 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1569 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001570 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1571 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001572 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001573 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001574 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001575 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1576 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001577 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001578 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001579 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001580 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1581 ha->device_type |= DT_ISP2532;
1582 ha->device_type |= DT_ZIO_SUPPORTED;
1583 ha->device_type |= DT_FWI2;
1584 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001585 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1586 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001587 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1588 ha->device_type |= DT_ISP8001;
1589 ha->device_type |= DT_ZIO_SUPPORTED;
1590 ha->device_type |= DT_FWI2;
1591 ha->device_type |= DT_IIDMA;
1592 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1593 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001594 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001595
1596 /* Get adapter physical port no from interrupt pin register. */
1597 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1598 if (ha->port_no & 1)
1599 ha->flags.port0 = 1;
1600 else
1601 ha->flags.port0 = 0;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001602}
1603
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001605qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
Andrew Vasquez37765412008-01-17 09:02:09 -08001607 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001608 uint16_t msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001609 int cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Andrew Vasquez285d0322007-10-19 15:59:17 -07001611 if (pci_request_selected_regions(ha->pdev, ha->bars,
1612 QLA2XXX_DRIVER_NAME)) {
1613 qla_printk(KERN_WARNING, ha,
1614 "Failed to reserve PIO/MMIO regions (%s)\n",
1615 pci_name(ha->pdev));
1616
1617 goto iospace_error_exit;
1618 }
1619 if (!(ha->bars & 1))
1620 goto skip_pio;
1621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1623 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001624 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1625 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 qla_printk(KERN_WARNING, ha,
1627 "Invalid PCI I/O region size (%s)...\n",
1628 pci_name(ha->pdev));
1629 pio = 0;
1630 }
1631 } else {
1632 qla_printk(KERN_WARNING, ha,
1633 "region #0 not a PIO resource (%s)...\n",
1634 pci_name(ha->pdev));
1635 pio = 0;
1636 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001637 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Andrew Vasquez285d0322007-10-19 15:59:17 -07001639skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001641 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001643 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 pci_name(ha->pdev));
1645 goto iospace_error_exit;
1646 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001647 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 qla_printk(KERN_ERR, ha,
1649 "Invalid PCI mem region size (%s), aborting\n",
1650 pci_name(ha->pdev));
1651 goto iospace_error_exit;
1652 }
1653
Andrew Vasquez37765412008-01-17 09:02:09 -08001654 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 if (!ha->iobase) {
1656 qla_printk(KERN_ERR, ha,
1657 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1658
1659 goto iospace_error_exit;
1660 }
1661
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001662 /* Determine queue resources */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001663 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001664 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001665 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001666 goto mqiobase_exit;
1667 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1668 pci_resource_len(ha->pdev, 3));
1669 if (ha->mqiobase) {
1670 /* Read MSIX vector size of the board */
1671 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1672 ha->msix_count = msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001673 /* Max queues are bounded by available msix vectors */
1674 /* queue 0 uses two msix vectors */
1675 if (ql2xmultique_tag) {
1676 cpus = num_online_cpus();
Anirban Chakraborty27dc9c52009-06-17 10:30:28 -07001677 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001678 (cpus + 1) : (ha->msix_count - 1);
1679 ha->max_req_queues = 2;
1680 } else if (ql2xmaxqueues > 1) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001681 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1682 QLA_MQ_SIZE : ql2xmaxqueues;
1683 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1684 " of request queues:%d\n", ha->max_req_queues));
1685 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001686 qla_printk(KERN_INFO, ha,
1687 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001688 } else
1689 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001690
1691mqiobase_exit:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001692 ha->msix_count = ha->max_rsp_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 return (0);
1694
1695iospace_error_exit:
1696 return (-ENOMEM);
1697}
1698
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001699static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001700qla2xxx_scan_start(struct Scsi_Host *shost)
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
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001704 if (vha->hw->flags.running_gold_fw)
1705 return;
1706
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001707 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1708 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1709 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1710 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001711}
1712
1713static int
1714qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1715{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001717
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001718 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001719 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001720 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001721 return 1;
1722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001723 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001724}
1725
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726/*
1727 * PCI driver interface
1728 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001729static int __devinit
1730qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001732 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001734 scsi_qla_host_t *base_vha = NULL;
1735 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001736 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001738 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001739 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001740 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001741 struct req_que *req = NULL;
1742 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
Andrew Vasquez285d0322007-10-19 15:59:17 -07001744 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001745 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001746 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1747 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001748 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001749 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1750 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001751 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1752 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001753 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001754 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001755 }
1756
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001757 if (mem_only) {
1758 if (pci_enable_device_mem(pdev))
1759 goto probe_out;
1760 } else {
1761 if (pci_enable_device(pdev))
1762 goto probe_out;
1763 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
Jesse Barnes09276782008-10-18 17:33:19 -07001765 /* This may fail but that's ok */
1766 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001767
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001768 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1769 if (!ha) {
1770 DEBUG(printk("Unable to allocate memory for ha\n"));
1771 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001776 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001777 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001778 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001780 /* Set ISP-type information. */
1781 qla2x00_set_isp_flags(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 /* Configure PCI I/O space */
1783 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001784 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001785 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001788 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1789 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001792 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001793 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001794 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001796 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001797 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001799 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001801 req_length = REQUEST_ENTRY_CNT_2100;
1802 rsp_length = RESPONSE_ENTRY_CNT_2100;
1803 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001804 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001805 ha->flash_conf_off = ~0;
1806 ha->flash_data_off = ~0;
1807 ha->nvram_conf_off = ~0;
1808 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001809 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001812 req_length = REQUEST_ENTRY_CNT_2200;
1813 rsp_length = RESPONSE_ENTRY_CNT_2100;
1814 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001815 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001816 ha->flash_conf_off = ~0;
1817 ha->flash_data_off = ~0;
1818 ha->nvram_conf_off = ~0;
1819 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001820 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001821 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001823 req_length = REQUEST_ENTRY_CNT_2200;
1824 rsp_length = RESPONSE_ENTRY_CNT_2300;
1825 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001826 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001827 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1828 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001829 ha->flash_conf_off = ~0;
1830 ha->flash_data_off = ~0;
1831 ha->nvram_conf_off = ~0;
1832 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001833 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001834 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -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;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001839 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001840 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001841 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001842 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001843 ha->isp_ops = &qla24xx_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;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001848 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001849 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001850 req_length = REQUEST_ENTRY_CNT_24XX;
1851 rsp_length = RESPONSE_ENTRY_CNT_2300;
1852 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001853 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001854 ha->gid_list_info_size = 8;
1855 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001856 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001857 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001858 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1859 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1860 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1861 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1862 } else if (IS_QLA81XX(ha)) {
1863 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1864 req_length = REQUEST_ENTRY_CNT_24XX;
1865 rsp_length = RESPONSE_ENTRY_CNT_2300;
1866 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1867 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1868 ha->gid_list_info_size = 8;
1869 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07001870 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001871 ha->isp_ops = &qla81xx_isp_ops;
1872 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1873 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1874 ha->nvram_conf_off = ~0;
1875 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001878 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001879 init_completion(&ha->mbx_cmd_comp);
1880 complete(&ha->mbx_cmd_comp);
1881 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001883 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Andrew Vasquez53303c42009-01-22 09:45:37 -08001885 qla2x00_config_dma_addressing(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001886 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 qla_printk(KERN_WARNING, ha,
1889 "[ERROR] Failed to allocate memory for adapter\n");
1890
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001891 goto probe_hw_failed;
1892 }
1893
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001894 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001895 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001896 req->max_q_depth = ql2xmaxqdepth;
1897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001898
1899 base_vha = qla2x00_create_host(sht, ha);
1900 if (!base_vha) {
1901 qla_printk(KERN_WARNING, ha,
1902 "[ERROR] Failed to allocate memory for scsi_host\n");
1903
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001904 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001905 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001906 qla2x00_free_req_que(ha, req);
1907 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001908 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 }
1910
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001911 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001914 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001915 host->can_queue = req->length + 128;
1916 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001918 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001919 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1920 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 if (IS_QLA2100(ha))
1922 host->sg_tablesize = 32;
1923 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001924 host->this_id = 255;
1925 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001926 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001927 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001928 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001929 host->max_lun = MAX_LUNS;
1930 host->transportt = qla2xxx_transport_template;
1931
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001932 /* Set up the irqs */
1933 ret = qla2x00_request_irqs(ha, rsp);
1934 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001935 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001936 /* Alloc arrays of request and response ring ptrs */
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001937que_init:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001938 if (!qla2x00_alloc_queues(ha)) {
1939 qla_printk(KERN_WARNING, ha,
1940 "[ERROR] Failed to allocate memory for queue"
1941 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001942 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001943 }
1944 ha->rsp_q_map[0] = rsp;
1945 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001946 rsp->req = req;
1947 req->rsp = rsp;
1948 set_bit(0, ha->req_qid_map);
1949 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07001950 /* FWI2-capable only. */
1951 req->req_q_in = &ha->iobase->isp24.req_q_in;
1952 req->req_q_out = &ha->iobase->isp24.req_q_out;
1953 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1954 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001955 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07001956 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1957 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1958 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1959 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001960 }
1961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 if (qla2x00_initialize_adapter(base_vha)) {
1963 qla_printk(KERN_WARNING, ha,
1964 "Failed to initialize adapter\n");
1965
1966 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1967 "Adapter flags %x.\n",
1968 base_vha->host_no, base_vha->device_flags));
1969
1970 ret = -ENODEV;
1971 goto probe_failed;
1972 }
1973
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001974 if (ha->mqenable) {
1975 if (qla25xx_setup_mode(base_vha)) {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001976 qla_printk(KERN_WARNING, ha,
1977 "Can't create queues, falling back to single"
1978 " queue mode\n");
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001979 goto que_init;
1980 }
1981 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001982
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001983 if (ha->flags.running_gold_fw)
1984 goto skip_dpc;
1985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986 /*
1987 * Startup the kernel thread for this host adapter
1988 */
1989 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1990 "%s_dpc", base_vha->host_str);
1991 if (IS_ERR(ha->dpc_thread)) {
1992 qla_printk(KERN_WARNING, ha,
1993 "Unable to start DPC thread!\n");
1994 ret = PTR_ERR(ha->dpc_thread);
1995 goto probe_failed;
1996 }
1997
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07001998skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001999 list_add_tail(&base_vha->list, &ha->vp_list);
2000 base_vha->host->irq = ha->pdev->irq;
2001
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
2005 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002006 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008 base_vha->flags.init_done = 1;
2009 base_vha->flags.online = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08002010
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002011 ret = scsi_add_host(host, &pdev->dev);
2012 if (ret)
2013 goto probe_failed;
2014
Andrew Vasquez048feec2008-09-11 22:19:45 -07002015 ha->isp_ops->enable_intrs(ha);
2016
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002017 scsi_scan_host(host);
2018
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 qla_printk(KERN_INFO, ha, "\n"
2026 " QLogic Fibre Channel HBA Driver: %s\n"
2027 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08002028 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2029 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030 ha->model_desc ? ha->model_desc : "", pdev->device,
2031 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2032 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2033 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 return 0;
2036
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002037probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002038 qla2x00_free_req_que(ha, req);
2039 qla2x00_free_rsp_que(ha, rsp);
2040 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002043 if (base_vha->timer_active)
2044 qla2x00_stop_timer(base_vha);
2045 base_vha->flags.online = 0;
2046 if (ha->dpc_thread) {
2047 struct task_struct *t = ha->dpc_thread;
2048
2049 ha->dpc_thread = NULL;
2050 kthread_stop(t);
2051 }
2052
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002053 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002057probe_hw_failed:
2058 if (ha->iobase)
2059 iounmap(ha->iobase);
2060
2061 pci_release_selected_regions(ha->pdev, ha->bars);
2062 kfree(ha);
2063 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002065probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002066 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002067 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
Adrian Bunk4c993f72008-01-14 00:55:16 -08002070static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002071qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002073 scsi_qla_host_t *base_vha, *vha, *temp;
2074 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002076 base_vha = pci_get_drvdata(pdev);
2077 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2080 if (vha && vha->fc_vport)
2081 fc_vport_terminate(vha->fc_vport);
2082 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002083
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002084 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002085
Andrew Vasquezb9978762009-03-24 09:08:05 -07002086 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2087
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002088 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002089
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002090 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002091
Andrew Vasquezb9978762009-03-24 09:08:05 -07002092 /* Disable timer */
2093 if (base_vha->timer_active)
2094 qla2x00_stop_timer(base_vha);
2095
2096 base_vha->flags.online = 0;
2097
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002098 /* Flush the work queue and remove it */
2099 if (ha->wq) {
2100 flush_workqueue(ha->wq);
2101 destroy_workqueue(ha->wq);
2102 ha->wq = NULL;
2103 }
2104
Andrew Vasquezb9978762009-03-24 09:08:05 -07002105 /* Kill the kernel thread for this host */
2106 if (ha->dpc_thread) {
2107 struct task_struct *t = ha->dpc_thread;
2108
2109 /*
2110 * qla2xxx_wake_dpc checks for ->dpc_thread
2111 * so we need to zero it out.
2112 */
2113 ha->dpc_thread = NULL;
2114 kthread_stop(t);
2115 }
2116
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002117 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002120
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002121 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002123 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002125 scsi_host_put(base_vha->host);
2126
2127 if (ha->iobase)
2128 iounmap(ha->iobase);
2129
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002130 if (ha->mqiobase)
2131 iounmap(ha->mqiobase);
2132
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002133 pci_release_selected_regions(ha->pdev, ha->bars);
2134 kfree(ha);
2135 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
Bernhard Walle665db932007-03-28 00:49:49 +02002137 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 pci_set_drvdata(pdev, NULL);
2139}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
2141static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002142qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002144 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002146 qla25xx_delete_queues(vha);
2147
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002148 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002149 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002150
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002151 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002152 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002153
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002154 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002157 /* turn-off interrupts on the card */
2158 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002159 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002160
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002161 qla2x00_free_irqs(vha);
2162
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002163 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002164
2165 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166}
2167
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002168static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002169qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002170 int defer)
2171{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002172 struct fc_rport *rport;
2173
2174 if (!fcport->rport)
2175 return;
2176
2177 rport = fcport->rport;
2178 if (defer) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002179 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002180 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002181 spin_unlock_irq(vha->host->host_lock);
2182 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2183 qla2xxx_wake_dpc(vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002184 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002185 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002186}
2187
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2190 *
2191 * Input: ha = adapter block pointer. fcport = port structure pointer.
2192 *
2193 * Return: None.
2194 *
2195 * Context:
2196 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002197void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002198 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002200 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002201 vha->vp_idx == fcport->vp_idx) {
2202 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2203 qla2x00_schedule_rport_del(vha, fcport, defer);
2204 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002205 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 * We may need to retry the login, so don't change the state of the
2207 * port but do the retries.
2208 */
2209 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2210 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2211
2212 if (!do_login)
2213 return;
2214
2215 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002216 fcport->login_retry = vha->hw->login_retry_count;
2217 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
2219 DEBUG(printk("scsi(%ld): Port login retry: "
2220 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2221 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002222 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 fcport->port_name[0],
2224 fcport->port_name[1],
2225 fcport->port_name[2],
2226 fcport->port_name[3],
2227 fcport->port_name[4],
2228 fcport->port_name[5],
2229 fcport->port_name[6],
2230 fcport->port_name[7],
2231 fcport->loop_id,
2232 fcport->login_retry));
2233 }
2234}
2235
2236/*
2237 * qla2x00_mark_all_devices_lost
2238 * Updates fcport state when device goes offline.
2239 *
2240 * Input:
2241 * ha = adapter block pointer.
2242 * fcport = port structure pointer.
2243 *
2244 * Return:
2245 * None.
2246 *
2247 * Context:
2248 */
2249void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251{
2252 fc_port_t *fcport;
2253
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002254 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2255 if (vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 /*
2258 * No point in marking the device as lost, if the device is
2259 * already DEAD.
2260 */
2261 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2262 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2264 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2265 qla2x00_schedule_rport_del(vha, fcport, defer);
2266 } else
2267 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 }
2269}
2270
2271/*
2272* qla2x00_mem_alloc
2273* Allocates adapter memory.
2274*
2275* Returns:
2276* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002277* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002279static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002280qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2281 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282{
2283 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
Andrew Vasqueze8711082008-01-31 12:33:48 -08002285 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002286 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002287 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2291 &ha->gid_list_dma, GFP_KERNEL);
2292 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002293 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
Andrew Vasqueze8711082008-01-31 12:33:48 -08002295 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2296 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Andrew Vasqueze8711082008-01-31 12:33:48 -08002299 /* Get memory for cached NVRAM */
2300 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2301 if (!ha->nvram)
2302 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2305 ha->pdev->device);
2306 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2307 DMA_POOL_SIZE, 8, 0);
2308 if (!ha->s_dma_pool)
2309 goto fail_free_nvram;
2310
Andrew Vasqueze8711082008-01-31 12:33:48 -08002311 /* Allocate memory for SNS commands */
2312 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002314 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002316 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002317 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002318 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002320 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002322 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 goto fail_dma_pool;
2324 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002325 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002326 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002327 if (!ha->ct_sns)
2328 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 }
2330
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002332 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2333 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334 DEBUG(printk("Unable to allocate memory for req\n"));
2335 goto fail_req;
2336 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002337 (*req)->length = req_len;
2338 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2339 ((*req)->length + 1) * sizeof(request_t),
2340 &(*req)->dma, GFP_KERNEL);
2341 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2343 goto fail_req_ring;
2344 }
2345 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002346 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2347 if (!*rsp) {
2348 qla_printk(KERN_WARNING, ha,
2349 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350 goto fail_rsp;
2351 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002352 (*rsp)->hw = ha;
2353 (*rsp)->length = rsp_len;
2354 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2355 ((*rsp)->length + 1) * sizeof(response_t),
2356 &(*rsp)->dma, GFP_KERNEL);
2357 if (!(*rsp)->ring) {
2358 qla_printk(KERN_WARNING, ha,
2359 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002360 goto fail_rsp_ring;
2361 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002362 (*req)->rsp = *rsp;
2363 (*rsp)->req = *req;
2364 /* Allocate memory for NVRAM data for vports */
2365 if (ha->nvram_npiv_size) {
2366 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2367 ha->nvram_npiv_size, GFP_KERNEL);
2368 if (!ha->npiv_info) {
2369 qla_printk(KERN_WARNING, ha,
2370 "Unable to allocate memory for npiv info\n");
2371 goto fail_npiv_info;
2372 }
2373 } else
2374 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002375
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002376 /* Get consistent memory allocated for EX-INIT-CB. */
2377 if (IS_QLA81XX(ha)) {
2378 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2379 &ha->ex_init_cb_dma);
2380 if (!ha->ex_init_cb)
2381 goto fail_ex_init_cb;
2382 }
2383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384 INIT_LIST_HEAD(&ha->vp_list);
2385 return 1;
2386
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002387fail_ex_init_cb:
2388 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002389fail_npiv_info:
2390 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2391 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2392 (*rsp)->ring = NULL;
2393 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002395 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002396fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002397 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2398 sizeof(request_t), (*req)->ring, (*req)->dma);
2399 (*req)->ring = NULL;
2400 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002401fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002402 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403fail_req:
2404 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2405 ha->ct_sns, ha->ct_sns_dma);
2406 ha->ct_sns = NULL;
2407 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002408fail_free_ms_iocb:
2409 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2410 ha->ms_iocb = NULL;
2411 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412fail_dma_pool:
2413 dma_pool_destroy(ha->s_dma_pool);
2414 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002415fail_free_nvram:
2416 kfree(ha->nvram);
2417 ha->nvram = NULL;
2418fail_free_srb_mempool:
2419 mempool_destroy(ha->srb_mempool);
2420 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002421fail_free_gid_list:
2422 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002423 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002424 ha->gid_list = NULL;
2425 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002426fail_free_init_cb:
2427 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2428 ha->init_cb_dma);
2429 ha->init_cb = NULL;
2430 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002431fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002433 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
2436/*
2437* qla2x00_mem_free
2438* Frees all adapter allocated memory.
2439*
2440* Input:
2441* ha = adapter block pointer.
2442*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002443static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002446 if (ha->srb_mempool)
2447 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002449 if (ha->fce)
2450 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002451 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002452
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002453 if (ha->fw_dump) {
2454 if (ha->eft)
2455 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002457 vfree(ha->fw_dump);
2458 }
2459
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07002460 if (ha->dcbx_tlv)
2461 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
2462 ha->dcbx_tlv, ha->dcbx_tlv_dma);
2463
Andrew Vasquezce0423f2009-06-03 09:55:13 -07002464 if (ha->xgmac_data)
2465 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2466 ha->xgmac_data, ha->xgmac_data_dma);
2467
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 if (ha->sns_cmd)
2469 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002470 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
2472 if (ha->ct_sns)
2473 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002474 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Andrew Vasquez88729e52006-06-23 16:10:50 -07002476 if (ha->sfp_data)
2477 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2478
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07002479 if (ha->edc_data)
2480 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2481
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 if (ha->ms_iocb)
2483 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2484
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002485 if (ha->ex_init_cb)
2486 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2487
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 if (ha->s_dma_pool)
2489 dma_pool_destroy(ha->s_dma_pool);
2490
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 if (ha->gid_list)
2492 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 if (ha->init_cb)
2496 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2497 ha->init_cb, ha->init_cb_dma);
2498 vfree(ha->optrom_buffer);
2499 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002500 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Andrew Vasqueze8711082008-01-31 12:33:48 -08002502 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002503 ha->eft = NULL;
2504 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 ha->sns_cmd = NULL;
2506 ha->sns_cmd_dma = 0;
2507 ha->ct_sns = NULL;
2508 ha->ct_sns_dma = 0;
2509 ha->ms_iocb = NULL;
2510 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 ha->init_cb = NULL;
2512 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002513 ha->ex_init_cb = NULL;
2514 ha->ex_init_cb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
2516 ha->s_dma_pool = NULL;
2517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 ha->gid_list = NULL;
2519 ha->gid_list_dma = 0;
2520
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002522 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002524}
2525
2526struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2527 struct qla_hw_data *ha)
2528{
2529 struct Scsi_Host *host;
2530 struct scsi_qla_host *vha = NULL;
2531
2532 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2533 if (host == NULL) {
2534 printk(KERN_WARNING
2535 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2536 goto fail;
2537 }
2538
2539 /* Clear our data area */
2540 vha = shost_priv(host);
2541 memset(vha, 0, sizeof(scsi_qla_host_t));
2542
2543 vha->host = host;
2544 vha->host_no = host->host_no;
2545 vha->hw = ha;
2546
2547 INIT_LIST_HEAD(&vha->vp_fcports);
2548 INIT_LIST_HEAD(&vha->work_list);
2549 INIT_LIST_HEAD(&vha->list);
2550
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002551 spin_lock_init(&vha->work_lock);
2552
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002553 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2554 return vha;
2555
2556fail:
2557 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558}
2559
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002560static struct qla_work_evt *
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002561qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002562{
2563 struct qla_work_evt *e;
2564
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002565 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002566 if (!e)
2567 return NULL;
2568
2569 INIT_LIST_HEAD(&e->list);
2570 e->type = type;
2571 e->flags = QLA_EVT_FLAG_FREE;
2572 return e;
2573}
2574
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002575static int
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002576qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002577{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002578 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002579
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002580 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002582 spin_unlock_irqrestore(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002584
Andrew Vasquez0971de72008-04-03 13:13:18 -07002585 return QLA_SUCCESS;
2586}
2587
2588int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002589qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002590 u32 data)
2591{
2592 struct qla_work_evt *e;
2593
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002594 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002595 if (!e)
2596 return QLA_FUNCTION_FAILED;
2597
2598 e->u.aen.code = code;
2599 e->u.aen.data = data;
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002600 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002601}
2602
Andrew Vasquez8a659572009-02-08 20:50:12 -08002603int
2604qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2605{
2606 struct qla_work_evt *e;
2607
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002608 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08002609 if (!e)
2610 return QLA_FUNCTION_FAILED;
2611
2612 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002613 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08002614}
2615
Andrew Vasquez0971de72008-04-03 13:13:18 -07002616static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002618{
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002619 struct qla_work_evt *e, *tmp;
2620 unsigned long flags;
2621 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002622
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002623 spin_lock_irqsave(&vha->work_lock, flags);
2624 list_splice_init(&vha->work_list, &work);
2625 spin_unlock_irqrestore(&vha->work_lock, flags);
2626
2627 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07002628 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002629
2630 switch (e->type) {
2631 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002632 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002633 e->u.aen.code, e->u.aen.data);
2634 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08002635 case QLA_EVT_IDC_ACK:
2636 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2637 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002638 }
2639 if (e->flags & QLA_EVT_FLAG_FREE)
2640 kfree(e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002641 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642}
Andrew Vasquezf999f4c2009-06-03 09:55:28 -07002643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002644/* Relogins all the fcports of a vport
2645 * Context: dpc thread
2646 */
2647void qla2x00_relogin(struct scsi_qla_host *vha)
2648{
2649 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08002650 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002651 uint16_t next_loopid = 0;
2652 struct qla_hw_data *ha = vha->hw;
2653
2654 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2655 /*
2656 * If the port is not ONLINE then try to login
2657 * to it if we haven't run out of retries.
2658 */
2659 if (atomic_read(&fcport->state) !=
2660 FCS_ONLINE && fcport->login_retry) {
2661
2662 if (fcport->flags & FCF_FABRIC_DEVICE) {
2663 if (fcport->flags & FCF_TAPE_PRESENT)
2664 ha->isp_ops->fabric_logout(vha,
2665 fcport->loop_id,
2666 fcport->d_id.b.domain,
2667 fcport->d_id.b.area,
2668 fcport->d_id.b.al_pa);
2669
2670 status = qla2x00_fabric_login(vha, fcport,
2671 &next_loopid);
2672 } else
2673 status = qla2x00_local_device_login(vha,
2674 fcport);
2675
2676 fcport->login_retry--;
2677 if (status == QLA_SUCCESS) {
2678 fcport->old_loop_id = fcport->loop_id;
2679
2680 DEBUG(printk("scsi(%ld): port login OK: logged "
2681 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2682
2683 qla2x00_update_fcport(vha, fcport);
2684
2685 } else if (status == 1) {
2686 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2687 /* retry the login again */
2688 DEBUG(printk("scsi(%ld): Retrying"
2689 " %d login again loop_id 0x%x\n",
2690 vha->host_no, fcport->login_retry,
2691 fcport->loop_id));
2692 } else {
2693 fcport->login_retry = 0;
2694 }
2695
2696 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2697 fcport->loop_id = FC_NO_LOOP_ID;
2698 }
2699 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2700 break;
2701 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002702}
2703
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704/**************************************************************************
2705* qla2x00_do_dpc
2706* This kernel thread is a task that is schedule by the interrupt handler
2707* to perform the background processing for interrupts.
2708*
2709* Notes:
2710* This task always run in the context of a kernel thread. It
2711* is kick-off by the driver's detect code and starts up
2712* up one per adapter. It immediately goes to sleep and waits for
2713* some fibre event. When either the interrupt handler or
2714* the timer routine detects a event it will one of the task
2715* bits then wake us up.
2716**************************************************************************/
2717static int
2718qla2x00_do_dpc(void *data)
2719{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002720 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 scsi_qla_host_t *base_vha;
2722 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002723
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 ha = (struct qla_hw_data *)data;
2725 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 set_user_nice(current, -20);
2728
Christoph Hellwig39a11242006-02-14 18:46:22 +01002729 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2731
Christoph Hellwig39a11242006-02-14 18:46:22 +01002732 set_current_state(TASK_INTERRUPTIBLE);
2733 schedule();
2734 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
2736 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2737
2738 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 continue;
2741
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002742 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
2744 ha->dpc_active = 1;
2745
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 ha->dpc_active = 0;
2748 continue;
2749 }
2750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002752
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002753 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2754 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
2756 DEBUG(printk("scsi(%ld): dpc: sched "
2757 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002758 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002762 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 /* failed. retry later */
2764 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002765 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002767 clear_bit(ABORT_ISP_ACTIVE,
2768 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002769 }
2770
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002772 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 }
2774
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002775 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2776 qla2x00_update_fcports(base_vha);
2777 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002778 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002779
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002780 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2781 &base_vha->dpc_flags) &&
2782 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
2784 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002785 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787 qla2x00_rst_aen(base_vha);
2788 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 }
2790
2791 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002792 if ((test_and_clear_bit(RELOGIN_NEEDED,
2793 &base_vha->dpc_flags)) &&
2794 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2795 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
2797 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 base_vha->host_no));
2799 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 }
2804
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002805 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2806 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002809 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810
2811 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002812 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 clear_bit(LOOP_RESYNC_ACTIVE,
2817 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 }
2819
2820 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 }
2823
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002824 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2825 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2826 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2827 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002828 }
2829
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002831 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002833 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2834 &base_vha->dpc_flags))
2835 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002838
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 ha->dpc_active = 0;
2840 } /* End of while(1) */
2841
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
2844 /*
2845 * Make sure that nobody tries to wake us up again.
2846 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 ha->dpc_active = 0;
2848
Christoph Hellwig39a11242006-02-14 18:46:22 +01002849 return 0;
2850}
2851
2852void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01002854{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002855 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002856 struct task_struct *t = ha->dpc_thread;
2857
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002858 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002859 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860}
2861
2862/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863* qla2x00_rst_aen
2864* Processes asynchronous reset.
2865*
2866* Input:
2867* ha = adapter block pointer.
2868*/
2869static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002870qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 if (vha->flags.online && !vha->flags.reset_active &&
2873 !atomic_read(&vha->loop_down_timer) &&
2874 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877
2878 /*
2879 * Issue marker command only when we are going to start
2880 * the I/O.
2881 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002882 vha->marker_needed = 1;
2883 } while (!atomic_read(&vha->loop_down_timer) &&
2884 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 }
2886}
2887
f4f051e2005-04-17 15:02:26 -05002888static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002890{
2891 struct scsi_cmnd *cmd = sp->cmd;
2892
2893 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002894 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002895 sp->flags &= ~SRB_DMA_VALID;
2896 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002897 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002898}
2899
2900void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002901qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002902{
2903 struct scsi_cmnd *cmd = sp->cmd;
2904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05002906
f4f051e2005-04-17 15:02:26 -05002907 mempool_free(sp, ha->srb_mempool);
2908
2909 cmd->scsi_done(cmd);
2910}
bdf79622005-04-17 15:06:53 -05002911
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912/**************************************************************************
2913* qla2x00_timer
2914*
2915* Description:
2916* One second timer
2917*
2918* Context: Interrupt
2919***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002920void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 unsigned long cpu_flags = 0;
2924 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 int start_dpc = 0;
2926 int index;
2927 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002928 int t;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002930 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 /*
2932 * Ports - Port down timer.
2933 *
2934 * Whenever, a port is in the LOST state we start decrementing its port
2935 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002936 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 */
2938 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 if (fcport->port_type != FCT_TARGET)
2941 continue;
2942
2943 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2944
2945 if (atomic_read(&fcport->port_down_timer) == 0)
2946 continue;
2947
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002948 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002950
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002952 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 t, atomic_read(&fcport->port_down_timer)));
2955 }
2956 t++;
2957 } /* End of for fcport */
2958
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
2960 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 if (atomic_read(&vha->loop_down_timer) > 0 &&
2962 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2963 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 if (atomic_read(&vha->loop_down_timer) ==
2966 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
2968 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2969 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2973 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
2975 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002976 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002978 spin_lock_irqsave(&ha->hardware_lock,
2979 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002980 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002981 for (index = 1;
2982 index < MAX_OUTSTANDING_COMMANDS;
2983 index++) {
2984 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002986 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002987 if (!sp)
2988 continue;
2989 sfcp = sp->fcport;
2990 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2991 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002993 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002994 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002995 break;
2996 }
2997 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 start_dpc++;
3001 }
3002
3003 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003005 if (!(vha->device_flags & DFLG_NO_CABLE) &&
3006 !vha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 DEBUG(printk("scsi(%ld): Loop down - "
3008 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 qla_printk(KERN_WARNING, ha,
3011 "Loop down - aborting ISP.\n");
3012
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 }
3015 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07003016 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 vha->host_no,
3018 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 }
3020
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003021 /* Check if beacon LED needs to be blinked */
3022 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08003024 start_dpc++;
3025 }
3026
Andrew Vasquez550bf572008-04-24 15:21:23 -07003027 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003029 start_dpc++;
3030
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3033 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3034 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3037 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3038 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3039 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3040 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043}
3044
Andrew Vasquez54333832005-11-09 15:49:04 -08003045/* Firmware interface routines. */
3046
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003047#define FW_BLOBS 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003048#define FW_ISP21XX 0
3049#define FW_ISP22XX 1
3050#define FW_ISP2300 2
3051#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003052#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003053#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003054#define FW_ISP81XX 6
Andrew Vasquez54333832005-11-09 15:49:04 -08003055
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003056#define FW_FILE_ISP21XX "ql2100_fw.bin"
3057#define FW_FILE_ISP22XX "ql2200_fw.bin"
3058#define FW_FILE_ISP2300 "ql2300_fw.bin"
3059#define FW_FILE_ISP2322 "ql2322_fw.bin"
3060#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003061#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003062#define FW_FILE_ISP81XX "ql8100_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003063
Daniel Walkere1e82b62008-05-12 22:21:10 -07003064static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003065
3066static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003067 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3068 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3069 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3070 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3071 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003072 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003073 { .name = FW_FILE_ISP81XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003074};
3075
3076struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003078{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003079 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003080 struct fw_blob *blob;
3081
3082 blob = NULL;
3083 if (IS_QLA2100(ha)) {
3084 blob = &qla_fw_blobs[FW_ISP21XX];
3085 } else if (IS_QLA2200(ha)) {
3086 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003087 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003088 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003089 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003090 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003091 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003092 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003093 } else if (IS_QLA25XX(ha)) {
3094 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003095 } else if (IS_QLA81XX(ha)) {
3096 blob = &qla_fw_blobs[FW_ISP81XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003097 }
3098
Daniel Walkere1e82b62008-05-12 22:21:10 -07003099 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003100 if (blob->fw)
3101 goto out;
3102
3103 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3104 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003105 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08003106 blob->fw = NULL;
3107 blob = NULL;
3108 goto out;
3109 }
3110
3111out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003112 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003113 return blob;
3114}
3115
3116static void
3117qla2x00_release_firmware(void)
3118{
3119 int idx;
3120
Daniel Walkere1e82b62008-05-12 22:21:10 -07003121 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003122 for (idx = 0; idx < FW_BLOBS; idx++)
3123 if (qla_fw_blobs[idx].fw)
3124 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003125 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003126}
3127
Seokmann Ju14e660e2007-09-20 14:07:36 -07003128static pci_ers_result_t
3129qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3130{
Seokmann Jub9b12f72009-03-24 09:08:18 -07003131 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3132
Seokmann Ju14e660e2007-09-20 14:07:36 -07003133 switch (state) {
3134 case pci_channel_io_normal:
3135 return PCI_ERS_RESULT_CAN_RECOVER;
3136 case pci_channel_io_frozen:
3137 pci_disable_device(pdev);
3138 return PCI_ERS_RESULT_NEED_RESET;
3139 case pci_channel_io_perm_failure:
Seokmann Jub9b12f72009-03-24 09:08:18 -07003140 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003141 return PCI_ERS_RESULT_DISCONNECT;
3142 }
3143 return PCI_ERS_RESULT_NEED_RESET;
3144}
3145
3146static pci_ers_result_t
3147qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3148{
3149 int risc_paused = 0;
3150 uint32_t stat;
3151 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3153 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003154 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3155 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3156
3157 spin_lock_irqsave(&ha->hardware_lock, flags);
3158 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3159 stat = RD_REG_DWORD(&reg->hccr);
3160 if (stat & HCCR_RISC_PAUSE)
3161 risc_paused = 1;
3162 } else if (IS_QLA23XX(ha)) {
3163 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3164 if (stat & HSR_RISC_PAUSED)
3165 risc_paused = 1;
3166 } else if (IS_FWI2_CAPABLE(ha)) {
3167 stat = RD_REG_DWORD(&reg24->host_status);
3168 if (stat & HSRX_RISC_PAUSED)
3169 risc_paused = 1;
3170 }
3171 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3172
3173 if (risc_paused) {
3174 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3175 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003177
3178 return PCI_ERS_RESULT_NEED_RESET;
3179 } else
3180 return PCI_ERS_RESULT_RECOVERED;
3181}
3182
3183static pci_ers_result_t
3184qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3185{
3186 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003187 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3188 struct qla_hw_data *ha = base_vha->hw;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003189 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003190
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003191 if (ha->mem_only)
3192 rc = pci_enable_device_mem(pdev);
3193 else
3194 rc = pci_enable_device(pdev);
3195
3196 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003197 qla_printk(KERN_WARNING, ha,
3198 "Can't re-enable PCI device after reset.\n");
3199
3200 return ret;
3201 }
3202 pci_set_master(pdev);
3203
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003204 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003205 return ret;
3206
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3208 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003209 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003211
3212 return ret;
3213}
3214
3215static void
3216qla2xxx_pci_resume(struct pci_dev *pdev)
3217{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003218 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3219 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003220 int ret;
3221
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003222 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003223 if (ret != QLA_SUCCESS) {
3224 qla_printk(KERN_ERR, ha,
3225 "the device failed to resume I/O "
3226 "from slot/link_reset");
3227 }
3228 pci_cleanup_aer_uncorrect_error_status(pdev);
3229}
3230
3231static struct pci_error_handlers qla2xxx_err_handler = {
3232 .error_detected = qla2xxx_pci_error_detected,
3233 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3234 .slot_reset = qla2xxx_pci_slot_reset,
3235 .resume = qla2xxx_pci_resume,
3236};
3237
Andrew Vasquez54333832005-11-09 15:49:04 -08003238static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003239 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3240 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3241 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3242 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3243 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3244 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3245 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3246 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3247 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003248 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003249 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3250 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003251 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003252 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003253 { 0 },
3254};
3255MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3256
Andrew Vasquezfca29702005-07-06 10:31:47 -07003257static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003258 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003259 .driver = {
3260 .owner = THIS_MODULE,
3261 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003262 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003263 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003264 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003265 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003266};
3267
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268/**
3269 * qla2x00_module_init - Module initialization.
3270 **/
3271static int __init
3272qla2x00_module_init(void)
3273{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003274 int ret = 0;
3275
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003277 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003278 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 if (srb_cachep == NULL) {
3280 printk(KERN_ERR
3281 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3282 return -ENOMEM;
3283 }
3284
3285 /* Derive version string. */
3286 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003287 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003288 strcat(qla2x00_version_str, "-debug");
3289
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003290 qla2xxx_transport_template =
3291 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003292 if (!qla2xxx_transport_template) {
3293 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003295 }
3296 qla2xxx_transport_vport_template =
3297 fc_attach_transport(&qla2xxx_transport_vport_functions);
3298 if (!qla2xxx_transport_vport_template) {
3299 kmem_cache_destroy(srb_cachep);
3300 fc_release_transport(qla2xxx_transport_template);
3301 return -ENODEV;
3302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003304 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3305 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003306 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003307 if (ret) {
3308 kmem_cache_destroy(srb_cachep);
3309 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003310 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003311 }
3312 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313}
3314
3315/**
3316 * qla2x00_module_exit - Module cleanup.
3317 **/
3318static void __exit
3319qla2x00_module_exit(void)
3320{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003321 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003322 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003323 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003325 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326}
3327
3328module_init(qla2x00_module_init);
3329module_exit(qla2x00_module_exit);
3330
3331MODULE_AUTHOR("QLogic Corporation");
3332MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3333MODULE_LICENSE("GPL");
3334MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003335MODULE_FIRMWARE(FW_FILE_ISP21XX);
3336MODULE_FIRMWARE(FW_FILE_ISP22XX);
3337MODULE_FIRMWARE(FW_FILE_ISP2300);
3338MODULE_FIRMWARE(FW_FILE_ISP2322);
3339MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003340MODULE_FIRMWARE(FW_FILE_ISP25XX);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003341MODULE_FIRMWARE(FW_FILE_ISP81XX);