| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 |  * QLogic Fibre Channel HBA Driver | 
| Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 3 |  * Copyright (c)  2003-2008 QLogic Corporation | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 |  * | 
| Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 |  * See LICENSE.qla2xxx for copyright and licensing details. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 |  */ | 
 | 7 | #include "qla_def.h" | 
 | 8 |  | 
 | 9 | #include <linux/moduleparam.h> | 
 | 10 | #include <linux/vmalloc.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/delay.h> | 
| Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 12 | #include <linux/kthread.h> | 
| Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 13 | #include <linux/mutex.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 |  | 
 | 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 |  */ | 
 | 23 | char qla2x00_version_str[40]; | 
 | 24 |  | 
 | 25 | /* | 
 | 26 |  * SRB allocation cache | 
 | 27 |  */ | 
| Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 28 | static struct kmem_cache *srb_cachep; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | int ql2xlogintimeout = 20; | 
 | 31 | module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR); | 
 | 32 | MODULE_PARM_DESC(ql2xlogintimeout, | 
 | 33 | 		"Login timeout value in seconds."); | 
 | 34 |  | 
| Andrew Vasquez | a7b6184 | 2007-05-07 07:42:59 -0700 | [diff] [blame] | 35 | int qlport_down_retry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR); | 
 | 37 | MODULE_PARM_DESC(qlport_down_retry, | 
| Jesper Juhl | 900d9f9 | 2006-06-30 02:33:07 -0700 | [diff] [blame] | 38 | 		"Maximum number of command retries to a port that returns " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | 		"a PORT-DOWN status."); | 
 | 40 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | int ql2xplogiabsentdevice; | 
 | 42 | module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR); | 
 | 43 | MODULE_PARM_DESC(ql2xplogiabsentdevice, | 
 | 44 | 		"Option to enable PLOGI to devices that are not present after " | 
| Jesper Juhl | 900d9f9 | 2006-06-30 02:33:07 -0700 | [diff] [blame] | 45 | 		"a Fabric scan.  This is needed for several broken switches. " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | 		"Default is 0 - no PLOGI. 1 - perfom PLOGI."); | 
 | 47 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | int ql2xloginretrycount = 0; | 
 | 49 | module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR); | 
 | 50 | MODULE_PARM_DESC(ql2xloginretrycount, | 
 | 51 | 		"Specify an alternate value for the NVRAM login retry count."); | 
 | 52 |  | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 53 | int ql2xallocfwdump = 1; | 
 | 54 | module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR); | 
 | 55 | MODULE_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 Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 60 | int ql2xextended_error_logging; | 
| Andrew Vasquez | 27d9403 | 2007-03-12 10:41:30 -0700 | [diff] [blame] | 61 | module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR); | 
| Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 62 | MODULE_PARM_DESC(ql2xextended_error_logging, | 
| Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 63 | 		"Option to enable extended error logging, " | 
 | 64 | 		"Default is 0 - no logging. 1 - log errors."); | 
 | 65 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static void qla2x00_free_device(scsi_qla_host_t *); | 
 | 67 |  | 
| Andrew Vasquez | 7e47e5c | 2008-04-24 15:21:26 -0700 | [diff] [blame] | 68 | int ql2xfdmienable=1; | 
| Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 69 | module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR); | 
 | 70 | MODULE_PARM_DESC(ql2xfdmienable, | 
 | 71 | 		"Enables FDMI registratons " | 
 | 72 | 		"Default is 0 - no FDMI. 1 - perfom FDMI."); | 
 | 73 |  | 
| Andrew Vasquez | df7baa5 | 2006-10-13 09:33:39 -0700 | [diff] [blame] | 74 | #define MAX_Q_DEPTH    32 | 
 | 75 | static int ql2xmaxqdepth = MAX_Q_DEPTH; | 
 | 76 | module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR); | 
 | 77 | MODULE_PARM_DESC(ql2xmaxqdepth, | 
 | 78 | 		"Maximum queue depth to report for target devices."); | 
 | 79 |  | 
 | 80 | int ql2xqfullrampup = 120; | 
 | 81 | module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR); | 
 | 82 | MODULE_PARM_DESC(ql2xqfullrampup, | 
 | 83 | 		"Number of seconds to wait to begin to ramp-up the queue " | 
 | 84 | 		"depth for a device after a queue-full condition has been " | 
 | 85 | 		"detected.  Default is 120 seconds."); | 
 | 86 |  | 
| Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 87 | int ql2xiidmaenable=1; | 
 | 88 | module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR); | 
 | 89 | MODULE_PARM_DESC(ql2xiidmaenable, | 
 | 90 | 		"Enables iIDMA settings " | 
 | 91 | 		"Default is 1 - perform iIDMA. 0 - no iIDMA."); | 
 | 92 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 93 | int ql2xmaxqueues = 1; | 
 | 94 | module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR); | 
 | 95 | MODULE_PARM_DESC(ql2xmaxqueues, | 
 | 96 | 		"Enables MQ settings " | 
 | 97 | 		"Default is 1 for single queue. Set it to number \ | 
 | 98 | 			of queues in MQ mode."); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 100 |  * SCSI host template entry points | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 |  */ | 
 | 102 | static int qla2xxx_slave_configure(struct scsi_device * device); | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 103 | static int qla2xxx_slave_alloc(struct scsi_device *); | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 104 | static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time); | 
 | 105 | static void qla2xxx_scan_start(struct Scsi_Host *); | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 106 | static void qla2xxx_slave_destroy(struct scsi_device *); | 
| Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 107 | static int qla2xxx_queuecommand(struct scsi_cmnd *cmd, | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 108 | 		void (*fn)(struct scsi_cmnd *)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | static int qla2xxx_eh_abort(struct scsi_cmnd *); | 
 | 110 | static int qla2xxx_eh_device_reset(struct scsi_cmnd *); | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 111 | static int qla2xxx_eh_target_reset(struct scsi_cmnd *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | static int qla2xxx_eh_bus_reset(struct scsi_cmnd *); | 
 | 113 | static int qla2xxx_eh_host_reset(struct scsi_cmnd *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 |  | 
| Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 115 | static int qla2x00_change_queue_depth(struct scsi_device *, int); | 
 | 116 | static int qla2x00_change_queue_type(struct scsi_device *, int); | 
 | 117 |  | 
| Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 118 | struct scsi_host_template qla2xxx_driver_template = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | 	.module			= THIS_MODULE, | 
| Andrew Vasquez | cb63067 | 2006-05-17 15:09:45 -0700 | [diff] [blame] | 120 | 	.name			= QLA2XXX_DRIVER_NAME, | 
| Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 121 | 	.queuecommand		= qla2xxx_queuecommand, | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 122 |  | 
 | 123 | 	.eh_abort_handler	= qla2xxx_eh_abort, | 
 | 124 | 	.eh_device_reset_handler = qla2xxx_eh_device_reset, | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 125 | 	.eh_target_reset_handler = qla2xxx_eh_target_reset, | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 126 | 	.eh_bus_reset_handler	= qla2xxx_eh_bus_reset, | 
 | 127 | 	.eh_host_reset_handler	= qla2xxx_eh_host_reset, | 
 | 128 |  | 
 | 129 | 	.slave_configure	= qla2xxx_slave_configure, | 
 | 130 |  | 
 | 131 | 	.slave_alloc		= qla2xxx_slave_alloc, | 
 | 132 | 	.slave_destroy		= qla2xxx_slave_destroy, | 
| Andrew Vasquez | ed67708 | 2007-03-12 10:41:27 -0700 | [diff] [blame] | 133 | 	.scan_finished		= qla2xxx_scan_finished, | 
 | 134 | 	.scan_start		= qla2xxx_scan_start, | 
| Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 135 | 	.change_queue_depth	= qla2x00_change_queue_depth, | 
 | 136 | 	.change_queue_type	= qla2x00_change_queue_type, | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 137 | 	.this_id		= -1, | 
 | 138 | 	.cmd_per_lun		= 3, | 
 | 139 | 	.use_clustering		= ENABLE_CLUSTERING, | 
 | 140 | 	.sg_tablesize		= SG_ALL, | 
 | 141 |  | 
 | 142 | 	.max_sectors		= 0xFFFF, | 
| Andrew Vasquez | afb046e | 2005-08-26 19:09:40 -0700 | [diff] [blame] | 143 | 	.shost_attrs		= qla2x00_host_attrs, | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 144 | }; | 
 | 145 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | static struct scsi_transport_template *qla2xxx_transport_template = NULL; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 147 | struct scsi_transport_template *qla2xxx_transport_vport_template = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* TODO Convert to inlines | 
 | 150 |  * | 
 | 151 |  * Timer routines | 
 | 152 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 |  | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 154 | __inline__ void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 155 | qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 157 | 	init_timer(&vha->timer); | 
 | 158 | 	vha->timer.expires = jiffies + interval * HZ; | 
 | 159 | 	vha->timer.data = (unsigned long)vha; | 
 | 160 | 	vha->timer.function = (void (*)(unsigned long))func; | 
 | 161 | 	add_timer(&vha->timer); | 
 | 162 | 	vha->timer_active = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } | 
 | 164 |  | 
 | 165 | static inline void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 166 | qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 168 | 	mod_timer(&vha->timer, jiffies + interval * HZ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } | 
 | 170 |  | 
| Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 171 | static __inline__ void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 172 | qla2x00_stop_timer(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 174 | 	del_timer_sync(&vha->timer); | 
 | 175 | 	vha->timer_active = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } | 
 | 177 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | static int qla2x00_do_dpc(void *data); | 
 | 179 |  | 
 | 180 | static void qla2x00_rst_aen(scsi_qla_host_t *); | 
 | 181 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 182 | static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t, | 
 | 183 | 	struct req_que **, struct rsp_que **); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 184 | static void qla2x00_mem_free(struct qla_hw_data *); | 
 | 185 | static void qla2x00_sp_free_dma(srb_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /* -------------------------------------------------------------------------- */ | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 188 | static int qla2x00_alloc_queues(struct qla_hw_data *ha) | 
 | 189 | { | 
 | 190 | 	ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_queues, | 
 | 191 | 				GFP_KERNEL); | 
 | 192 | 	if (!ha->req_q_map) { | 
 | 193 | 		qla_printk(KERN_WARNING, ha, | 
 | 194 | 			"Unable to allocate memory for request queue ptrs\n"); | 
 | 195 | 		goto fail_req_map; | 
 | 196 | 	} | 
 | 197 |  | 
 | 198 | 	ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_queues, | 
 | 199 | 				GFP_KERNEL); | 
 | 200 | 	if (!ha->rsp_q_map) { | 
 | 201 | 		qla_printk(KERN_WARNING, ha, | 
 | 202 | 			"Unable to allocate memory for response queue ptrs\n"); | 
 | 203 | 		goto fail_rsp_map; | 
 | 204 | 	} | 
 | 205 | 	set_bit(0, ha->rsp_qid_map); | 
 | 206 | 	set_bit(0, ha->req_qid_map); | 
 | 207 | 	return 1; | 
 | 208 |  | 
 | 209 | fail_rsp_map: | 
 | 210 | 	kfree(ha->req_q_map); | 
 | 211 | 	ha->req_q_map = NULL; | 
 | 212 | fail_req_map: | 
 | 213 | 	return -ENOMEM; | 
 | 214 | } | 
 | 215 |  | 
 | 216 | static void qla2x00_free_que(struct qla_hw_data *ha, struct req_que *req, | 
 | 217 | 	struct rsp_que *rsp) | 
 | 218 | { | 
 | 219 | 	if (rsp && rsp->ring) | 
 | 220 | 		dma_free_coherent(&ha->pdev->dev, | 
 | 221 | 		(rsp->length + 1) * sizeof(response_t), | 
 | 222 | 		rsp->ring, rsp->dma); | 
 | 223 |  | 
 | 224 | 	kfree(rsp); | 
 | 225 | 	rsp = NULL; | 
 | 226 | 	if (req && req->ring) | 
 | 227 | 		dma_free_coherent(&ha->pdev->dev, | 
 | 228 | 		(req->length + 1) * sizeof(request_t), | 
 | 229 | 		req->ring, req->dma); | 
 | 230 |  | 
 | 231 | 	kfree(req); | 
 | 232 | 	req = NULL; | 
 | 233 | } | 
 | 234 |  | 
 | 235 | static void qla2x00_free_queues(struct qla_hw_data *ha) | 
 | 236 | { | 
 | 237 | 	struct req_que *req; | 
 | 238 | 	struct rsp_que *rsp; | 
 | 239 | 	int cnt; | 
 | 240 |  | 
 | 241 | 	for (cnt = 0; cnt < ha->max_queues; cnt++) { | 
 | 242 | 		rsp = ha->rsp_q_map[cnt]; | 
 | 243 | 		req = ha->req_q_map[cnt]; | 
 | 244 | 		qla2x00_free_que(ha, req, rsp); | 
 | 245 | 	} | 
 | 246 | 	kfree(ha->rsp_q_map); | 
 | 247 | 	ha->rsp_q_map = NULL; | 
 | 248 |  | 
 | 249 | 	kfree(ha->req_q_map); | 
 | 250 | 	ha->req_q_map = NULL; | 
 | 251 | } | 
 | 252 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | static char * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 254 | qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 256 | 	struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | 	static char *pci_bus_modes[] = { | 
 | 258 | 		"33", "66", "100", "133", | 
 | 259 | 	}; | 
 | 260 | 	uint16_t pci_bus; | 
 | 261 |  | 
 | 262 | 	strcpy(str, "PCI"); | 
 | 263 | 	pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9; | 
 | 264 | 	if (pci_bus) { | 
 | 265 | 		strcat(str, "-X ("); | 
 | 266 | 		strcat(str, pci_bus_modes[pci_bus]); | 
 | 267 | 	} else { | 
 | 268 | 		pci_bus = (ha->pci_attr & BIT_8) >> 8; | 
 | 269 | 		strcat(str, " ("); | 
 | 270 | 		strcat(str, pci_bus_modes[pci_bus]); | 
 | 271 | 	} | 
 | 272 | 	strcat(str, " MHz)"); | 
 | 273 |  | 
 | 274 | 	return (str); | 
 | 275 | } | 
 | 276 |  | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 277 | static char * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 278 | qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str) | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 279 | { | 
 | 280 | 	static char *pci_bus_modes[] = { "33", "66", "100", "133", }; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 281 | 	struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 282 | 	uint32_t pci_bus; | 
 | 283 | 	int pcie_reg; | 
 | 284 |  | 
 | 285 | 	pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP); | 
 | 286 | 	if (pcie_reg) { | 
 | 287 | 		char lwstr[6]; | 
 | 288 | 		uint16_t pcie_lstat, lspeed, lwidth; | 
 | 289 |  | 
 | 290 | 		pcie_reg += 0x12; | 
 | 291 | 		pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat); | 
 | 292 | 		lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3); | 
 | 293 | 		lwidth = (pcie_lstat & | 
 | 294 | 		    (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4; | 
 | 295 |  | 
 | 296 | 		strcpy(str, "PCIe ("); | 
 | 297 | 		if (lspeed == 1) | 
| Andrew Vasquez | c87a0d8 | 2008-04-03 13:13:21 -0700 | [diff] [blame] | 298 | 			strcat(str, "2.5GT/s "); | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 299 | 		else if (lspeed == 2) | 
| Andrew Vasquez | c87a0d8 | 2008-04-03 13:13:21 -0700 | [diff] [blame] | 300 | 			strcat(str, "5.0GT/s "); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 301 | 		else | 
 | 302 | 			strcat(str, "<unknown> "); | 
 | 303 | 		snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth); | 
 | 304 | 		strcat(str, lwstr); | 
 | 305 |  | 
 | 306 | 		return str; | 
 | 307 | 	} | 
 | 308 |  | 
 | 309 | 	strcpy(str, "PCI"); | 
 | 310 | 	pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8; | 
 | 311 | 	if (pci_bus == 0 || pci_bus == 8) { | 
 | 312 | 		strcat(str, " ("); | 
 | 313 | 		strcat(str, pci_bus_modes[pci_bus >> 3]); | 
 | 314 | 	} else { | 
 | 315 | 		strcat(str, "-X "); | 
 | 316 | 		if (pci_bus & BIT_2) | 
 | 317 | 			strcat(str, "Mode 2"); | 
 | 318 | 		else | 
 | 319 | 			strcat(str, "Mode 1"); | 
 | 320 | 		strcat(str, " ("); | 
 | 321 | 		strcat(str, pci_bus_modes[pci_bus & ~BIT_2]); | 
 | 322 | 	} | 
 | 323 | 	strcat(str, " MHz)"); | 
 | 324 |  | 
 | 325 | 	return str; | 
 | 326 | } | 
 | 327 |  | 
| Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 328 | static char * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 329 | qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { | 
 | 331 | 	char un_str[10]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 332 | 	struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 333 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | 	sprintf(str, "%d.%02d.%02d ", ha->fw_major_version, | 
 | 335 | 	    ha->fw_minor_version, | 
 | 336 | 	    ha->fw_subminor_version); | 
 | 337 |  | 
 | 338 | 	if (ha->fw_attributes & BIT_9) { | 
 | 339 | 		strcat(str, "FLX"); | 
 | 340 | 		return (str); | 
 | 341 | 	} | 
 | 342 |  | 
 | 343 | 	switch (ha->fw_attributes & 0xFF) { | 
 | 344 | 	case 0x7: | 
 | 345 | 		strcat(str, "EF"); | 
 | 346 | 		break; | 
 | 347 | 	case 0x17: | 
 | 348 | 		strcat(str, "TP"); | 
 | 349 | 		break; | 
 | 350 | 	case 0x37: | 
 | 351 | 		strcat(str, "IP"); | 
 | 352 | 		break; | 
 | 353 | 	case 0x77: | 
 | 354 | 		strcat(str, "VI"); | 
 | 355 | 		break; | 
 | 356 | 	default: | 
 | 357 | 		sprintf(un_str, "(%x)", ha->fw_attributes); | 
 | 358 | 		strcat(str, un_str); | 
 | 359 | 		break; | 
 | 360 | 	} | 
 | 361 | 	if (ha->fw_attributes & 0x100) | 
 | 362 | 		strcat(str, "X"); | 
 | 363 |  | 
 | 364 | 	return (str); | 
 | 365 | } | 
 | 366 |  | 
| Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 367 | static char * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 368 | qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str) | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 369 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 370 | 	struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | f0883ac | 2005-07-08 17:58:43 -0700 | [diff] [blame] | 371 |  | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 372 | 	sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version, | 
 | 373 | 	    ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 374 | 	return str; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 375 | } | 
 | 376 |  | 
 | 377 | static inline srb_t * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 378 | qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport, | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 379 |     struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) | 
 | 380 | { | 
 | 381 | 	srb_t *sp; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 382 | 	struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 383 |  | 
 | 384 | 	sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); | 
 | 385 | 	if (!sp) | 
 | 386 | 		return sp; | 
 | 387 |  | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 388 | 	sp->fcport = fcport; | 
 | 389 | 	sp->cmd = cmd; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 390 | 	sp->que = ha->req_q_map[0]; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 391 | 	sp->flags = 0; | 
 | 392 | 	CMD_SP(cmd) = (void *)sp; | 
 | 393 | 	cmd->scsi_done = done; | 
 | 394 |  | 
 | 395 | 	return sp; | 
 | 396 | } | 
 | 397 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | static int | 
| Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 399 | qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 400 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 401 | 	scsi_qla_host_t *vha = shost_priv(cmd->device->host); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 402 | 	fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 403 | 	struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 404 | 	struct qla_hw_data *ha = vha->hw; | 
 | 405 | 	struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 406 | 	srb_t *sp; | 
 | 407 | 	int rval; | 
 | 408 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 409 | 	if (unlikely(pci_channel_offline(ha->pdev))) { | 
| Seokmann Ju | b9b12f7 | 2009-03-24 09:08:18 -0700 | [diff] [blame] | 410 | 		if (ha->pdev->error_state == pci_channel_io_frozen) | 
 | 411 | 			cmd->result = DID_REQUEUE << 16; | 
 | 412 | 		else | 
 | 413 | 			cmd->result = DID_NO_CONNECT << 16; | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 414 | 		goto qc24_fail_command; | 
 | 415 | 	} | 
 | 416 |  | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 417 | 	rval = fc_remote_port_chkready(rport); | 
 | 418 | 	if (rval) { | 
 | 419 | 		cmd->result = rval; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 420 | 		goto qc24_fail_command; | 
 | 421 | 	} | 
 | 422 |  | 
| andrew.vasquez@qlogic.com | 387f96b | 2006-02-07 08:45:45 -0800 | [diff] [blame] | 423 | 	/* Close window on fcport/rport state-transitioning. */ | 
| Mike Christie | 7b59413 | 2008-08-17 15:24:40 -0500 | [diff] [blame] | 424 | 	if (fcport->drport) | 
 | 425 | 		goto qc24_target_busy; | 
| andrew.vasquez@qlogic.com | 387f96b | 2006-02-07 08:45:45 -0800 | [diff] [blame] | 426 |  | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 427 | 	if (atomic_read(&fcport->state) != FCS_ONLINE) { | 
 | 428 | 		if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 429 | 		    atomic_read(&base_vha->loop_state) == LOOP_DEAD) { | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 430 | 			cmd->result = DID_NO_CONNECT << 16; | 
 | 431 | 			goto qc24_fail_command; | 
 | 432 | 		} | 
| Mike Christie | 7b59413 | 2008-08-17 15:24:40 -0500 | [diff] [blame] | 433 | 		goto qc24_target_busy; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 434 | 	} | 
 | 435 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 436 | 	spin_unlock_irq(vha->host->host_lock); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 437 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 438 | 	sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 439 | 	if (!sp) | 
 | 440 | 		goto qc24_host_busy_lock; | 
 | 441 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 442 | 	rval = ha->isp_ops->start_scsi(sp); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 443 | 	if (rval != QLA_SUCCESS) | 
 | 444 | 		goto qc24_host_busy_free_sp; | 
 | 445 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 446 | 	spin_lock_irq(vha->host->host_lock); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 447 |  | 
 | 448 | 	return 0; | 
 | 449 |  | 
 | 450 | qc24_host_busy_free_sp: | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 451 | 	qla2x00_sp_free_dma(sp); | 
 | 452 | 	mempool_free(sp, ha->srb_mempool); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 453 |  | 
 | 454 | qc24_host_busy_lock: | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 455 | 	spin_lock_irq(vha->host->host_lock); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 456 | 	return SCSI_MLQUEUE_HOST_BUSY; | 
 | 457 |  | 
| Mike Christie | 7b59413 | 2008-08-17 15:24:40 -0500 | [diff] [blame] | 458 | qc24_target_busy: | 
 | 459 | 	return SCSI_MLQUEUE_TARGET_BUSY; | 
 | 460 |  | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 461 | qc24_fail_command: | 
 | 462 | 	done(cmd); | 
 | 463 |  | 
 | 464 | 	return 0; | 
 | 465 | } | 
 | 466 |  | 
 | 467 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | /* | 
 | 469 |  * qla2x00_eh_wait_on_command | 
 | 470 |  *    Waits for the command to be returned by the Firmware for some | 
 | 471 |  *    max time. | 
 | 472 |  * | 
 | 473 |  * Input: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 |  *    cmd = Scsi Command to wait on. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 |  * | 
 | 476 |  * Return: | 
 | 477 |  *    Not Found : 0 | 
 | 478 |  *    Found : 1 | 
 | 479 |  */ | 
 | 480 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 481 | qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { | 
| Andrew Vasquez | fe74c71 | 2005-08-26 19:10:10 -0700 | [diff] [blame] | 483 | #define ABORT_POLLING_PERIOD	1000 | 
 | 484 | #define ABORT_WAIT_ITER		((10 * 1000) / (ABORT_POLLING_PERIOD)) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 485 | 	unsigned long wait_iter = ABORT_WAIT_ITER; | 
 | 486 | 	int ret = QLA_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 488 | 	while (CMD_SP(cmd)) { | 
| Andrew Vasquez | fe74c71 | 2005-08-26 19:10:10 -0700 | [diff] [blame] | 489 | 		msleep(ABORT_POLLING_PERIOD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 491 | 		if (--wait_iter) | 
 | 492 | 			break; | 
 | 493 | 	} | 
 | 494 | 	if (CMD_SP(cmd)) | 
 | 495 | 		ret = QLA_FUNCTION_FAILED; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 497 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } | 
 | 499 |  | 
 | 500 | /* | 
 | 501 |  * qla2x00_wait_for_hba_online | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 502 |  *    Wait till the HBA is online after going through | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 |  *    <= MAX_RETRIES_OF_ISP_ABORT  or | 
 | 504 |  *    finally HBA is disabled ie marked offline | 
 | 505 |  * | 
 | 506 |  * Input: | 
 | 507 |  *     ha - pointer to host adapter structure | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 508 |  * | 
 | 509 |  * Note: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 |  *    Does context switching-Release SPIN_LOCK | 
 | 511 |  *    (if any) before calling this routine. | 
 | 512 |  * | 
 | 513 |  * Return: | 
 | 514 |  *    Success (Adapter is online) : 0 | 
 | 515 |  *    Failed  (Adapter is offline/disabled) : 1 | 
 | 516 |  */ | 
| andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 517 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 518 | qla2x00_wait_for_hba_online(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 520 | 	int		return_status; | 
 | 521 | 	unsigned long	wait_online; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 522 | 	struct qla_hw_data *ha = vha->hw; | 
 | 523 | 	scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 |  | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 525 | 	wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 526 | 	while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || | 
 | 527 | 	    test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || | 
 | 528 | 	    test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || | 
 | 529 | 	    ha->dpc_active) && time_before(jiffies, wait_online)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 |  | 
 | 531 | 		msleep(1000); | 
 | 532 | 	} | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 533 | 	if (base_vha->flags.online) | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 534 | 		return_status = QLA_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | 	else | 
 | 536 | 		return_status = QLA_FUNCTION_FAILED; | 
 | 537 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | 	return (return_status); | 
 | 539 | } | 
 | 540 |  | 
| Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 541 | int | 
 | 542 | qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha) | 
 | 543 | { | 
 | 544 | 	int		return_status; | 
 | 545 | 	unsigned long	wait_reset; | 
 | 546 | 	struct qla_hw_data *ha = vha->hw; | 
 | 547 | 	scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | 
 | 548 |  | 
 | 549 | 	wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ); | 
 | 550 | 	while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || | 
 | 551 | 	    test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || | 
 | 552 | 	    test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || | 
 | 553 | 	    ha->dpc_active) && time_before(jiffies, wait_reset)) { | 
 | 554 |  | 
 | 555 | 		msleep(1000); | 
 | 556 |  | 
 | 557 | 		if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) && | 
 | 558 | 		    ha->flags.chip_reset_done) | 
 | 559 | 			break; | 
 | 560 | 	} | 
 | 561 | 	if (ha->flags.chip_reset_done) | 
 | 562 | 		return_status = QLA_SUCCESS; | 
 | 563 | 	else | 
 | 564 | 		return_status = QLA_FUNCTION_FAILED; | 
 | 565 |  | 
 | 566 | 	return return_status; | 
 | 567 | } | 
 | 568 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | /* | 
 | 570 |  * qla2x00_wait_for_loop_ready | 
 | 571 |  *    Wait for MAX_LOOP_TIMEOUT(5 min) value for loop | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 572 |  *    to be in LOOP_READY state. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 |  * Input: | 
 | 574 |  *     ha - pointer to host adapter structure | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 575 |  * | 
 | 576 |  * Note: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 |  *    Does context switching-Release SPIN_LOCK | 
 | 578 |  *    (if any) before calling this routine. | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 579 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 |  * | 
 | 581 |  * Return: | 
 | 582 |  *    Success (LOOP_READY) : 0 | 
 | 583 |  *    Failed  (LOOP_NOT_READY) : 1 | 
 | 584 |  */ | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 585 | static inline int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 586 | qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { | 
 | 588 | 	int 	 return_status = QLA_SUCCESS; | 
 | 589 | 	unsigned long loop_timeout ; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 590 | 	struct qla_hw_data *ha = vha->hw; | 
 | 591 | 	scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 |  | 
 | 593 | 	/* wait for 5 min at the max for loop to be ready */ | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 594 | 	loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 596 | 	while ((!atomic_read(&base_vha->loop_down_timer) && | 
 | 597 | 	    atomic_read(&base_vha->loop_state) == LOOP_DOWN) || | 
 | 598 | 	    atomic_read(&base_vha->loop_state) != LOOP_READY) { | 
 | 599 | 		if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) { | 
| Ravi Anand | 5768008 | 2006-05-17 15:08:44 -0700 | [diff] [blame] | 600 | 			return_status = QLA_FUNCTION_FAILED; | 
 | 601 | 			break; | 
 | 602 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | 		msleep(1000); | 
 | 604 | 		if (time_after_eq(jiffies, loop_timeout)) { | 
 | 605 | 			return_status = QLA_FUNCTION_FAILED; | 
 | 606 | 			break; | 
 | 607 | 		} | 
 | 608 | 	} | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 609 | 	return (return_status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } | 
 | 611 |  | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 612 | void | 
 | 613 | qla2x00_abort_fcport_cmds(fc_port_t *fcport) | 
 | 614 | { | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 615 | 	int cnt, que, id; | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 616 | 	unsigned long flags; | 
 | 617 | 	srb_t *sp; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 618 | 	scsi_qla_host_t *vha = fcport->vha; | 
 | 619 | 	struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 620 | 	struct req_que *req; | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 621 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 622 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 623 | 	for (que = 0; que < QLA_MAX_HOST_QUES; que++) { | 
 | 624 | 		id = vha->req_ques[que]; | 
 | 625 | 		req = ha->req_q_map[id]; | 
 | 626 | 		if (!req) | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 627 | 			continue; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 628 | 		for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { | 
 | 629 | 			sp = req->outstanding_cmds[cnt]; | 
 | 630 | 			if (!sp) | 
 | 631 | 				continue; | 
 | 632 | 			if (sp->fcport != fcport) | 
 | 633 | 				continue; | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 634 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 635 | 			spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 636 | 			if (ha->isp_ops->abort_command(vha, sp, req)) { | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 637 | 				DEBUG2(qla_printk(KERN_WARNING, ha, | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 638 | 				"Abort failed --  %lx\n", | 
 | 639 | 				sp->cmd->serial_number)); | 
 | 640 | 			} else { | 
 | 641 | 				if (qla2x00_eh_wait_on_command(sp->cmd) != | 
 | 642 | 					QLA_SUCCESS) | 
 | 643 | 					DEBUG2(qla_printk(KERN_WARNING, ha, | 
 | 644 | 					"Abort failed while waiting --  %lx\n", | 
 | 645 | 					sp->cmd->serial_number)); | 
 | 646 | 			} | 
 | 647 | 			spin_lock_irqsave(&ha->hardware_lock, flags); | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 648 | 		} | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 649 | 	} | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 650 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 651 | } | 
 | 652 |  | 
| Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 653 | static void | 
 | 654 | qla2x00_block_error_handler(struct scsi_cmnd *cmnd) | 
 | 655 | { | 
 | 656 | 	struct Scsi_Host *shost = cmnd->device->host; | 
 | 657 | 	struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); | 
 | 658 | 	unsigned long flags; | 
 | 659 |  | 
 | 660 | 	spin_lock_irqsave(shost->host_lock, flags); | 
 | 661 | 	while (rport->port_state == FC_PORTSTATE_BLOCKED) { | 
 | 662 | 		spin_unlock_irqrestore(shost->host_lock, flags); | 
 | 663 | 		msleep(1000); | 
 | 664 | 		spin_lock_irqsave(shost->host_lock, flags); | 
 | 665 | 	} | 
 | 666 | 	spin_unlock_irqrestore(shost->host_lock, flags); | 
 | 667 | 	return; | 
 | 668 | } | 
 | 669 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /************************************************************************** | 
 | 671 | * qla2xxx_eh_abort | 
 | 672 | * | 
 | 673 | * Description: | 
 | 674 | *    The abort function will abort the specified command. | 
 | 675 | * | 
 | 676 | * Input: | 
 | 677 | *    cmd = Linux SCSI command packet to be aborted. | 
 | 678 | * | 
 | 679 | * Returns: | 
 | 680 | *    Either SUCCESS or FAILED. | 
 | 681 | * | 
 | 682 | * Note: | 
| Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 683 | *    Only return FAILED if command not returned by firmware. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | **************************************************************************/ | 
| Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 685 | static int | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | qla2xxx_eh_abort(struct scsi_cmnd *cmd) | 
 | 687 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 688 | 	scsi_qla_host_t *vha = shost_priv(cmd->device->host); | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 689 | 	srb_t *sp; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 690 | 	int ret, i; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 691 | 	unsigned int id, lun; | 
 | 692 | 	unsigned long serial; | 
| Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 693 | 	unsigned long flags; | 
| Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 694 | 	int wait = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 695 | 	struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 696 | 	struct req_que *req; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 697 | 	srb_t *spt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 |  | 
| Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 699 | 	qla2x00_block_error_handler(cmd); | 
 | 700 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 701 | 	if (!CMD_SP(cmd)) | 
| Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 702 | 		return SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 |  | 
| Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 704 | 	ret = SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 706 | 	id = cmd->device->id; | 
 | 707 | 	lun = cmd->device->lun; | 
 | 708 | 	serial = cmd->serial_number; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 709 | 	spt = (srb_t *) CMD_SP(cmd); | 
 | 710 | 	if (!spt) | 
 | 711 | 		return SUCCESS; | 
 | 712 | 	req = spt->que; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 713 |  | 
 | 714 | 	/* Check active list for command command. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 715 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 716 | 	for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) { | 
 | 717 | 		sp = req->outstanding_cmds[i]; | 
 | 718 |  | 
 | 719 | 		if (sp == NULL) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 720 | 			continue; | 
 | 721 |  | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 722 | 		if (sp->cmd != cmd) | 
 | 723 | 			continue; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 724 |  | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 725 | 		DEBUG2(printk("%s(%ld): aborting sp %p from RISC." | 
 | 726 | 		" pid=%ld.\n", __func__, vha->host_no, sp, serial)); | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 727 |  | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 728 | 		spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 729 | 		if (ha->isp_ops->abort_command(vha, sp, req)) { | 
 | 730 | 			DEBUG2(printk("%s(%ld): abort_command " | 
 | 731 | 			"mbx failed.\n", __func__, vha->host_no)); | 
| Andrew Vasquez | 2ac4b64 | 2009-01-22 09:45:35 -0800 | [diff] [blame] | 732 | 			ret = FAILED; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 733 | 		} else { | 
 | 734 | 			DEBUG3(printk("%s(%ld): abort_command " | 
 | 735 | 			"mbx success.\n", __func__, vha->host_no)); | 
 | 736 | 			wait = 1; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 737 | 		} | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 738 | 		spin_lock_irqsave(&ha->hardware_lock, flags); | 
 | 739 | 		break; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 740 | 	} | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 741 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 742 |  | 
 | 743 | 	/* Wait for the command to be returned. */ | 
| Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 744 | 	if (wait) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 745 | 		if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) { | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 746 | 			qla_printk(KERN_ERR, ha, | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 747 | 			    "scsi(%ld:%d:%d): Abort handler timed out -- %lx " | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 748 | 			    "%x.\n", vha->host_no, id, lun, serial, ret); | 
| Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 749 | 			ret = FAILED; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 750 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 |  | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 753 | 	qla_printk(KERN_INFO, ha, | 
| Michael Reed | 2ea0020 | 2006-04-27 16:25:30 -0700 | [diff] [blame] | 754 | 	    "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 755 | 	    vha->host_no, id, lun, wait, serial, ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 757 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } | 
 | 759 |  | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 760 | enum nexus_wait_type { | 
 | 761 | 	WAIT_HOST = 0, | 
 | 762 | 	WAIT_TARGET, | 
 | 763 | 	WAIT_LUN, | 
 | 764 | }; | 
 | 765 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 767 | qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t, | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 768 | 	unsigned int l, srb_t *sp, enum nexus_wait_type type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 770 | 	int cnt, match, status; | 
| Andrew Vasquez | 18e144d | 2005-05-27 15:04:47 -0700 | [diff] [blame] | 771 | 	unsigned long flags; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 772 | 	struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 773 | 	struct req_que *req; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 |  | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 775 | 	status = QLA_SUCCESS; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 776 | 	if (!sp) | 
 | 777 | 		return status; | 
 | 778 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 779 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 780 | 	req = sp->que; | 
 | 781 | 	for (cnt = 1; status == QLA_SUCCESS && | 
 | 782 | 		cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { | 
 | 783 | 		sp = req->outstanding_cmds[cnt]; | 
 | 784 | 		if (!sp) | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 785 | 			continue; | 
| Andrew Vasquez | 19851f1 | 2008-08-13 21:37:00 -0700 | [diff] [blame] | 786 |  | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 787 | 		if (vha->vp_idx != sp->fcport->vha->vp_idx) | 
 | 788 | 			continue; | 
 | 789 | 		match = 0; | 
 | 790 | 		switch (type) { | 
 | 791 | 		case WAIT_HOST: | 
 | 792 | 			match = 1; | 
 | 793 | 			break; | 
 | 794 | 		case WAIT_TARGET: | 
 | 795 | 			match = sp->cmd->device->id == t; | 
 | 796 | 			break; | 
 | 797 | 		case WAIT_LUN: | 
 | 798 | 			match = (sp->cmd->device->id == t && | 
 | 799 | 				sp->cmd->device->lun == l); | 
 | 800 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | 		} | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 802 | 		if (!match) | 
 | 803 | 			continue; | 
 | 804 |  | 
 | 805 | 		spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 806 | 		status = qla2x00_eh_wait_on_command(sp->cmd); | 
 | 807 | 		spin_lock_irqsave(&ha->hardware_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | 	} | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 809 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 810 |  | 
 | 811 | 	return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } | 
 | 813 |  | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 814 | static char *reset_errors[] = { | 
 | 815 | 	"HBA not online", | 
 | 816 | 	"HBA not ready", | 
 | 817 | 	"Task management failed", | 
 | 818 | 	"Waiting for command completions", | 
 | 819 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 |  | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 821 | static int | 
 | 822 | __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type, | 
 | 823 |     struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int)) | 
 | 824 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 825 | 	scsi_qla_host_t *vha = shost_priv(cmd->device->host); | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 826 | 	fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; | 
 | 827 | 	int err; | 
 | 828 |  | 
 | 829 | 	qla2x00_block_error_handler(cmd); | 
 | 830 |  | 
 | 831 | 	if (!fcport) | 
 | 832 | 		return FAILED; | 
 | 833 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 834 | 	qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n", | 
 | 835 | 	    vha->host_no, cmd->device->id, cmd->device->lun, name); | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 836 |  | 
 | 837 | 	err = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 838 | 	if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 839 | 		goto eh_reset_failed; | 
 | 840 | 	err = 1; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 841 | 	if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS) | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 842 | 		goto eh_reset_failed; | 
 | 843 | 	err = 2; | 
 | 844 | 	if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS) | 
 | 845 | 		goto eh_reset_failed; | 
 | 846 | 	err = 3; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 847 | 	if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id, | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 848 | 	    cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS) | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 849 | 		goto eh_reset_failed; | 
 | 850 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 851 | 	qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n", | 
 | 852 | 	    vha->host_no, cmd->device->id, cmd->device->lun, name); | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 853 |  | 
 | 854 | 	return SUCCESS; | 
 | 855 |  | 
 | 856 |  eh_reset_failed: | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 857 | 	qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n" | 
 | 858 | 	    , vha->host_no, cmd->device->id, cmd->device->lun, name, | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 859 | 	    reset_errors[err]); | 
 | 860 | 	return FAILED; | 
 | 861 | } | 
 | 862 |  | 
| Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 863 | static int | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | qla2xxx_eh_device_reset(struct scsi_cmnd *cmd) | 
 | 865 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 866 | 	scsi_qla_host_t *vha = shost_priv(cmd->device->host); | 
 | 867 | 	struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 |  | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 869 | 	return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd, | 
 | 870 | 	    ha->isp_ops->lun_reset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | } | 
 | 872 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | static int | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 874 | qla2xxx_eh_target_reset(struct scsi_cmnd *cmd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 876 | 	scsi_qla_host_t *vha = shost_priv(cmd->device->host); | 
 | 877 | 	struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 |  | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 879 | 	return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd, | 
 | 880 | 	    ha->isp_ops->target_reset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | } | 
 | 882 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | /************************************************************************** | 
 | 884 | * qla2xxx_eh_bus_reset | 
 | 885 | * | 
 | 886 | * Description: | 
 | 887 | *    The bus reset function will reset the bus and abort any executing | 
 | 888 | *    commands. | 
 | 889 | * | 
 | 890 | * Input: | 
 | 891 | *    cmd = Linux SCSI command packet of the command that cause the | 
 | 892 | *          bus reset. | 
 | 893 | * | 
 | 894 | * Returns: | 
 | 895 | *    SUCCESS/FAILURE (defined as macro in scsi.h). | 
 | 896 | * | 
 | 897 | **************************************************************************/ | 
| Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 898 | static int | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd) | 
 | 900 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 901 | 	scsi_qla_host_t *vha = shost_priv(cmd->device->host); | 
 | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 902 | 	fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 903 | 	int ret = FAILED; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 904 | 	unsigned int id, lun; | 
 | 905 | 	unsigned long serial; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 906 | 	srb_t *sp = (srb_t *) CMD_SP(cmd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 |  | 
| Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 908 | 	qla2x00_block_error_handler(cmd); | 
 | 909 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 910 | 	id = cmd->device->id; | 
 | 911 | 	lun = cmd->device->lun; | 
 | 912 | 	serial = cmd->serial_number; | 
 | 913 |  | 
| Vladislav Bolkhovitin | b0328be | 2006-08-01 13:48:15 -0700 | [diff] [blame] | 914 | 	if (!fcport) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 915 | 		return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 917 | 	qla_printk(KERN_INFO, vha->hw, | 
| Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 918 | 	    "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 920 | 	if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | 		DEBUG2(printk("%s failed:board disabled\n",__func__)); | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 922 | 		goto eh_bus_reset_done; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | 	} | 
 | 924 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 925 | 	if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) { | 
 | 926 | 		if (qla2x00_loop_reset(vha) == QLA_SUCCESS) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 927 | 			ret = SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | 	} | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 929 | 	if (ret == FAILED) | 
 | 930 | 		goto eh_bus_reset_done; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 |  | 
| Andrew Vasquez | 9a41a62 | 2005-09-20 13:25:53 -0700 | [diff] [blame] | 932 | 	/* Flush outstanding commands. */ | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 933 | 	if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) != | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 934 | 	    QLA_SUCCESS) | 
| Andrew Vasquez | 9a41a62 | 2005-09-20 13:25:53 -0700 | [diff] [blame] | 935 | 		ret = FAILED; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 937 | eh_bus_reset_done: | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 938 | 	qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__, | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 939 | 	    (ret == FAILED) ? "failed" : "succeded"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 941 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } | 
 | 943 |  | 
 | 944 | /************************************************************************** | 
 | 945 | * qla2xxx_eh_host_reset | 
 | 946 | * | 
 | 947 | * Description: | 
 | 948 | *    The reset function will reset the Adapter. | 
 | 949 | * | 
 | 950 | * Input: | 
 | 951 | *      cmd = Linux SCSI command packet of the command that cause the | 
 | 952 | *            adapter reset. | 
 | 953 | * | 
 | 954 | * Returns: | 
 | 955 | *      Either SUCCESS or FAILED. | 
 | 956 | * | 
 | 957 | * Note: | 
 | 958 | **************************************************************************/ | 
| Adrian Bunk | e5f82ab | 2006-11-08 19:55:50 -0800 | [diff] [blame] | 959 | static int | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | qla2xxx_eh_host_reset(struct scsi_cmnd *cmd) | 
 | 961 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 962 | 	scsi_qla_host_t *vha = shost_priv(cmd->device->host); | 
 | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 963 | 	fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 964 | 	struct qla_hw_data *ha = vha->hw; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 965 | 	int ret = FAILED; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 966 | 	unsigned int id, lun; | 
 | 967 | 	unsigned long serial; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 968 | 	srb_t *sp = (srb_t *) CMD_SP(cmd); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 969 | 	scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 |  | 
| Andrew Vasquez | 07db518 | 2006-10-02 12:00:49 -0700 | [diff] [blame] | 971 | 	qla2x00_block_error_handler(cmd); | 
 | 972 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 973 | 	id = cmd->device->id; | 
 | 974 | 	lun = cmd->device->lun; | 
 | 975 | 	serial = cmd->serial_number; | 
 | 976 |  | 
| Vladislav Bolkhovitin | b0328be | 2006-08-01 13:48:15 -0700 | [diff] [blame] | 977 | 	if (!fcport) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 978 | 		return ret; | 
 | 979 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | 	qla_printk(KERN_INFO, ha, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 981 | 	    "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 983 | 	if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 984 | 		goto eh_host_reset_lock; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 |  | 
 | 986 | 	/* | 
 | 987 | 	 * Fixme-may be dpc thread is active and processing | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 988 | 	 * loop_resync,so wait a while for it to | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | 	 * be completed and then issue big hammer.Otherwise | 
 | 990 | 	 * it may cause I/O failure as big hammer marks the | 
 | 991 | 	 * devices as lost kicking of the port_down_timer | 
 | 992 | 	 * while dpc is stuck for the mailbox to complete. | 
 | 993 | 	 */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 994 | 	qla2x00_wait_for_loop_ready(vha); | 
 | 995 | 	if (vha != base_vha) { | 
 | 996 | 		if (qla2x00_vp_abort_isp(vha)) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 997 | 			goto eh_host_reset_lock; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 998 | 	} else { | 
 | 999 | 		set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | 
 | 1000 | 		if (qla2x00_abort_isp(base_vha)) { | 
 | 1001 | 			clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | 
 | 1002 | 			/* failed. schedule dpc to try */ | 
 | 1003 | 			set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); | 
 | 1004 |  | 
 | 1005 | 			if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) | 
 | 1006 | 				goto eh_host_reset_lock; | 
 | 1007 | 		} | 
 | 1008 | 		clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1009 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1011 | 	/* Waiting for command to be returned to OS.*/ | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1012 | 	if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) == | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1013 | 		QLA_SUCCESS) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1014 | 		ret = SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1016 | eh_host_reset_lock: | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1017 | 	qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, | 
 | 1018 | 	    (ret == FAILED) ? "failed" : "succeded"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1020 | 	return ret; | 
 | 1021 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 |  | 
 | 1023 | /* | 
 | 1024 | * qla2x00_loop_reset | 
 | 1025 | *      Issue loop reset. | 
 | 1026 | * | 
 | 1027 | * Input: | 
 | 1028 | *      ha = adapter block pointer. | 
 | 1029 | * | 
 | 1030 | * Returns: | 
 | 1031 | *      0 = success | 
 | 1032 | */ | 
| Andrew Vasquez | a4722cf | 2008-01-17 09:02:12 -0800 | [diff] [blame] | 1033 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1034 | qla2x00_loop_reset(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | { | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1036 | 	int ret; | 
 | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1037 | 	struct fc_port *fcport; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1038 | 	struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 |  | 
| Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1040 | 	if (ha->flags.enable_lip_full_login && !vha->vp_idx) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1041 | 		ret = qla2x00_full_login_lip(vha); | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1042 | 		if (ret != QLA_SUCCESS) { | 
| Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1043 | 			DEBUG2_3(printk("%s(%ld): failed: " | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1044 | 			    "full_login_lip=%d.\n", __func__, vha->host_no, | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1045 | 			    ret)); | 
| Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1046 | 		} | 
 | 1047 | 		atomic_set(&vha->loop_state, LOOP_DOWN); | 
 | 1048 | 		atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | 
 | 1049 | 		qla2x00_mark_all_devices_lost(vha, 0); | 
 | 1050 | 		qla2x00_wait_for_loop_ready(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | 	} | 
 | 1052 |  | 
| Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1053 | 	if (ha->flags.enable_lip_reset && !vha->vp_idx) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1054 | 		ret = qla2x00_lip_reset(vha); | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1055 | 		if (ret != QLA_SUCCESS) { | 
| Anirban Chakraborty | 749af3d | 2008-11-14 13:48:12 -0800 | [diff] [blame] | 1056 | 			DEBUG2_3(printk("%s(%ld): failed: " | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1057 | 			    "lip_reset=%d.\n", __func__, vha->host_no, ret)); | 
 | 1058 | 		} else | 
 | 1059 | 			qla2x00_wait_for_loop_ready(vha); | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1060 | 	} | 
 | 1061 |  | 
 | 1062 | 	if (ha->flags.enable_target_reset) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1063 | 		list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
 | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1064 | 			if (fcport->port_type != FCT_TARGET) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | 				continue; | 
 | 1066 |  | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1067 | 			ret = ha->isp_ops->target_reset(fcport, 0); | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1068 | 			if (ret != QLA_SUCCESS) { | 
 | 1069 | 				DEBUG2_3(printk("%s(%ld): bus_reset failed: " | 
 | 1070 | 				    "target_reset=%d d_id=%x.\n", __func__, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1071 | 				    vha->host_no, ret, fcport->d_id.b24)); | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1072 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | 		} | 
 | 1074 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | 	/* Issue marker command only when we are going to start the I/O */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1076 | 	vha->marker_needed = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 |  | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 1078 | 	return QLA_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } | 
 | 1080 |  | 
| Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1081 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1082 | qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res) | 
| Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1083 | { | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1084 | 	int que, cnt; | 
| Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1085 | 	unsigned long flags; | 
 | 1086 | 	srb_t *sp; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1087 | 	struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1088 | 	struct req_que *req; | 
| Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1089 |  | 
 | 1090 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1091 | 	for (que = 0; que < ha->max_queues; que++) { | 
 | 1092 | 		req = ha->req_q_map[que]; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1093 | 		if (!req) | 
 | 1094 | 			continue; | 
 | 1095 | 		for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { | 
 | 1096 | 			sp = req->outstanding_cmds[cnt]; | 
| Andrew Vasquez | e612d46 | 2009-03-24 09:08:04 -0700 | [diff] [blame] | 1097 | 			if (sp) { | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1098 | 				req->outstanding_cmds[cnt] = NULL; | 
 | 1099 | 				sp->cmd->result = res; | 
 | 1100 | 				qla2x00_sp_compl(ha, sp); | 
 | 1101 | 			} | 
| Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1102 | 		} | 
 | 1103 | 	} | 
 | 1104 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 1105 | } | 
 | 1106 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1107 | static int | 
 | 1108 | qla2xxx_slave_alloc(struct scsi_device *sdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | { | 
 | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1110 | 	struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 |  | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1112 | 	if (!rport || fc_remote_port_chkready(rport)) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1113 | 		return -ENXIO; | 
 | 1114 |  | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1115 | 	sdev->hostdata = *(fc_port_t **)rport->dd_data; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1116 |  | 
 | 1117 | 	return 0; | 
 | 1118 | } | 
 | 1119 |  | 
 | 1120 | static int | 
 | 1121 | qla2xxx_slave_configure(struct scsi_device *sdev) | 
 | 1122 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1123 | 	scsi_qla_host_t *vha = shost_priv(sdev->host); | 
 | 1124 | 	struct qla_hw_data *ha = vha->hw; | 
 | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1125 | 	struct fc_rport *rport = starget_to_rport(sdev->sdev_target); | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1126 | 	struct req_que *req = ha->req_q_map[vha->req_ques[0]]; | 
 | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1127 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1128 | 	if (sdev->tagged_supported) | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1129 | 		scsi_activate_tcq(sdev, req->max_q_depth); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | 	else | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1131 | 		scsi_deactivate_tcq(sdev, req->max_q_depth); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 |  | 
| Andrew Vasquez | 85821c9 | 2008-07-10 16:55:48 -0700 | [diff] [blame] | 1133 | 	rport->dev_loss_tmo = ha->port_down_retry_count; | 
 | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 1134 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1135 | 	return 0; | 
 | 1136 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 1138 | static void | 
 | 1139 | qla2xxx_slave_destroy(struct scsi_device *sdev) | 
 | 1140 | { | 
 | 1141 | 	sdev->hostdata = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | } | 
 | 1143 |  | 
| Andrew Vasquez | ce7e4af | 2005-08-26 19:09:30 -0700 | [diff] [blame] | 1144 | static int | 
 | 1145 | qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth) | 
 | 1146 | { | 
 | 1147 | 	scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); | 
 | 1148 | 	return sdev->queue_depth; | 
 | 1149 | } | 
 | 1150 |  | 
 | 1151 | static int | 
 | 1152 | qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type) | 
 | 1153 | { | 
 | 1154 | 	if (sdev->tagged_supported) { | 
 | 1155 | 		scsi_set_tag_type(sdev, tag_type); | 
 | 1156 | 		if (tag_type) | 
 | 1157 | 			scsi_activate_tcq(sdev, sdev->queue_depth); | 
 | 1158 | 		else | 
 | 1159 | 			scsi_deactivate_tcq(sdev, sdev->queue_depth); | 
 | 1160 | 	} else | 
 | 1161 | 		tag_type = 0; | 
 | 1162 |  | 
 | 1163 | 	return tag_type; | 
 | 1164 | } | 
 | 1165 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | /** | 
 | 1167 |  * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. | 
 | 1168 |  * @ha: HA context | 
 | 1169 |  * | 
 | 1170 |  * At exit, the @ha's flags.enable_64bit_addressing set to indicated | 
 | 1171 |  * supported addressing method. | 
 | 1172 |  */ | 
 | 1173 | static void | 
| Andrew Vasquez | 53303c4 | 2009-01-22 09:45:37 -0800 | [diff] [blame] | 1174 | qla2x00_config_dma_addressing(struct qla_hw_data *ha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | { | 
| Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1176 | 	/* Assume a 32bit DMA mask. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | 	ha->flags.enable_64bit_addressing = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 |  | 
| Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 1179 | 	if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) { | 
| Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1180 | 		/* Any upper-dword bits set? */ | 
 | 1181 | 		if (MSD(dma_get_required_mask(&ha->pdev->dev)) && | 
| Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 1182 | 		    !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { | 
| Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1183 | 			/* Ok, a 64bit DMA mask is applicable. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | 			ha->flags.enable_64bit_addressing = 1; | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1185 | 			ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64; | 
 | 1186 | 			ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64; | 
| Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1187 | 			return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | 	} | 
| Andrew Vasquez | 7524f9b | 2005-08-26 19:08:00 -0700 | [diff] [blame] | 1190 |  | 
| Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1191 | 	dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32)); | 
 | 1192 | 	pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | } | 
 | 1194 |  | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1195 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1196 | qla2x00_enable_intrs(struct qla_hw_data *ha) | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1197 | { | 
 | 1198 | 	unsigned long flags = 0; | 
 | 1199 | 	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
 | 1200 |  | 
 | 1201 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
 | 1202 | 	ha->interrupts_on = 1; | 
 | 1203 | 	/* enable risc and host interrupts */ | 
 | 1204 | 	WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC); | 
 | 1205 | 	RD_REG_WORD(®->ictrl); | 
 | 1206 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 1207 |  | 
 | 1208 | } | 
 | 1209 |  | 
 | 1210 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1211 | qla2x00_disable_intrs(struct qla_hw_data *ha) | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1212 | { | 
 | 1213 | 	unsigned long flags = 0; | 
 | 1214 | 	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
 | 1215 |  | 
 | 1216 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
 | 1217 | 	ha->interrupts_on = 0; | 
 | 1218 | 	/* disable risc and host interrupts */ | 
 | 1219 | 	WRT_REG_WORD(®->ictrl, 0); | 
 | 1220 | 	RD_REG_WORD(®->ictrl); | 
 | 1221 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 1222 | } | 
 | 1223 |  | 
 | 1224 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1225 | qla24xx_enable_intrs(struct qla_hw_data *ha) | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1226 | { | 
 | 1227 | 	unsigned long flags = 0; | 
 | 1228 | 	struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | 
 | 1229 |  | 
 | 1230 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
 | 1231 | 	ha->interrupts_on = 1; | 
 | 1232 | 	WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT); | 
 | 1233 | 	RD_REG_DWORD(®->ictrl); | 
 | 1234 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 1235 | } | 
 | 1236 |  | 
 | 1237 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1238 | qla24xx_disable_intrs(struct qla_hw_data *ha) | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1239 | { | 
 | 1240 | 	unsigned long flags = 0; | 
 | 1241 | 	struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | 
 | 1242 |  | 
| Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1243 | 	if (IS_NOPOLLING_TYPE(ha)) | 
 | 1244 | 		return; | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1245 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
 | 1246 | 	ha->interrupts_on = 0; | 
 | 1247 | 	WRT_REG_DWORD(®->ictrl, 0); | 
 | 1248 | 	RD_REG_DWORD(®->ictrl); | 
 | 1249 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 1250 | } | 
 | 1251 |  | 
 | 1252 | static struct isp_operations qla2100_isp_ops = { | 
 | 1253 | 	.pci_config		= qla2100_pci_config, | 
 | 1254 | 	.reset_chip		= qla2x00_reset_chip, | 
 | 1255 | 	.chip_diag		= qla2x00_chip_diag, | 
 | 1256 | 	.config_rings		= qla2x00_config_rings, | 
 | 1257 | 	.reset_adapter		= qla2x00_reset_adapter, | 
 | 1258 | 	.nvram_config		= qla2x00_nvram_config, | 
 | 1259 | 	.update_fw_options	= qla2x00_update_fw_options, | 
 | 1260 | 	.load_risc		= qla2x00_load_risc, | 
 | 1261 | 	.pci_info_str		= qla2x00_pci_info_str, | 
 | 1262 | 	.fw_version_str		= qla2x00_fw_version_str, | 
 | 1263 | 	.intr_handler		= qla2100_intr_handler, | 
 | 1264 | 	.enable_intrs		= qla2x00_enable_intrs, | 
 | 1265 | 	.disable_intrs		= qla2x00_disable_intrs, | 
 | 1266 | 	.abort_command		= qla2x00_abort_command, | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1267 | 	.target_reset		= qla2x00_abort_target, | 
 | 1268 | 	.lun_reset		= qla2x00_lun_reset, | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1269 | 	.fabric_login		= qla2x00_login_fabric, | 
 | 1270 | 	.fabric_logout		= qla2x00_fabric_logout, | 
 | 1271 | 	.calc_req_entries	= qla2x00_calc_iocbs_32, | 
 | 1272 | 	.build_iocbs		= qla2x00_build_scsi_iocbs_32, | 
 | 1273 | 	.prep_ms_iocb		= qla2x00_prep_ms_iocb, | 
 | 1274 | 	.prep_ms_fdmi_iocb	= qla2x00_prep_ms_fdmi_iocb, | 
 | 1275 | 	.read_nvram		= qla2x00_read_nvram_data, | 
 | 1276 | 	.write_nvram		= qla2x00_write_nvram_data, | 
 | 1277 | 	.fw_dump		= qla2100_fw_dump, | 
 | 1278 | 	.beacon_on		= NULL, | 
 | 1279 | 	.beacon_off		= NULL, | 
 | 1280 | 	.beacon_blink		= NULL, | 
 | 1281 | 	.read_optrom		= qla2x00_read_optrom_data, | 
 | 1282 | 	.write_optrom		= qla2x00_write_optrom_data, | 
 | 1283 | 	.get_flash_version	= qla2x00_get_flash_version, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1284 | 	.start_scsi		= qla2x00_start_scsi, | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1285 | }; | 
 | 1286 |  | 
 | 1287 | static struct isp_operations qla2300_isp_ops = { | 
 | 1288 | 	.pci_config		= qla2300_pci_config, | 
 | 1289 | 	.reset_chip		= qla2x00_reset_chip, | 
 | 1290 | 	.chip_diag		= qla2x00_chip_diag, | 
 | 1291 | 	.config_rings		= qla2x00_config_rings, | 
 | 1292 | 	.reset_adapter		= qla2x00_reset_adapter, | 
 | 1293 | 	.nvram_config		= qla2x00_nvram_config, | 
 | 1294 | 	.update_fw_options	= qla2x00_update_fw_options, | 
 | 1295 | 	.load_risc		= qla2x00_load_risc, | 
 | 1296 | 	.pci_info_str		= qla2x00_pci_info_str, | 
 | 1297 | 	.fw_version_str		= qla2x00_fw_version_str, | 
 | 1298 | 	.intr_handler		= qla2300_intr_handler, | 
 | 1299 | 	.enable_intrs		= qla2x00_enable_intrs, | 
 | 1300 | 	.disable_intrs		= qla2x00_disable_intrs, | 
 | 1301 | 	.abort_command		= qla2x00_abort_command, | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1302 | 	.target_reset		= qla2x00_abort_target, | 
 | 1303 | 	.lun_reset		= qla2x00_lun_reset, | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1304 | 	.fabric_login		= qla2x00_login_fabric, | 
 | 1305 | 	.fabric_logout		= qla2x00_fabric_logout, | 
 | 1306 | 	.calc_req_entries	= qla2x00_calc_iocbs_32, | 
 | 1307 | 	.build_iocbs		= qla2x00_build_scsi_iocbs_32, | 
 | 1308 | 	.prep_ms_iocb		= qla2x00_prep_ms_iocb, | 
 | 1309 | 	.prep_ms_fdmi_iocb	= qla2x00_prep_ms_fdmi_iocb, | 
 | 1310 | 	.read_nvram		= qla2x00_read_nvram_data, | 
 | 1311 | 	.write_nvram		= qla2x00_write_nvram_data, | 
 | 1312 | 	.fw_dump		= qla2300_fw_dump, | 
 | 1313 | 	.beacon_on		= qla2x00_beacon_on, | 
 | 1314 | 	.beacon_off		= qla2x00_beacon_off, | 
 | 1315 | 	.beacon_blink		= qla2x00_beacon_blink, | 
 | 1316 | 	.read_optrom		= qla2x00_read_optrom_data, | 
 | 1317 | 	.write_optrom		= qla2x00_write_optrom_data, | 
 | 1318 | 	.get_flash_version	= qla2x00_get_flash_version, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1319 | 	.start_scsi		= qla2x00_start_scsi, | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1320 | }; | 
 | 1321 |  | 
 | 1322 | static struct isp_operations qla24xx_isp_ops = { | 
 | 1323 | 	.pci_config		= qla24xx_pci_config, | 
 | 1324 | 	.reset_chip		= qla24xx_reset_chip, | 
 | 1325 | 	.chip_diag		= qla24xx_chip_diag, | 
 | 1326 | 	.config_rings		= qla24xx_config_rings, | 
 | 1327 | 	.reset_adapter		= qla24xx_reset_adapter, | 
 | 1328 | 	.nvram_config		= qla24xx_nvram_config, | 
 | 1329 | 	.update_fw_options	= qla24xx_update_fw_options, | 
 | 1330 | 	.load_risc		= qla24xx_load_risc, | 
 | 1331 | 	.pci_info_str		= qla24xx_pci_info_str, | 
 | 1332 | 	.fw_version_str		= qla24xx_fw_version_str, | 
 | 1333 | 	.intr_handler		= qla24xx_intr_handler, | 
 | 1334 | 	.enable_intrs		= qla24xx_enable_intrs, | 
 | 1335 | 	.disable_intrs		= qla24xx_disable_intrs, | 
 | 1336 | 	.abort_command		= qla24xx_abort_command, | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1337 | 	.target_reset		= qla24xx_abort_target, | 
 | 1338 | 	.lun_reset		= qla24xx_lun_reset, | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1339 | 	.fabric_login		= qla24xx_login_fabric, | 
 | 1340 | 	.fabric_logout		= qla24xx_fabric_logout, | 
 | 1341 | 	.calc_req_entries	= NULL, | 
 | 1342 | 	.build_iocbs		= NULL, | 
 | 1343 | 	.prep_ms_iocb		= qla24xx_prep_ms_iocb, | 
 | 1344 | 	.prep_ms_fdmi_iocb	= qla24xx_prep_ms_fdmi_iocb, | 
 | 1345 | 	.read_nvram		= qla24xx_read_nvram_data, | 
 | 1346 | 	.write_nvram		= qla24xx_write_nvram_data, | 
 | 1347 | 	.fw_dump		= qla24xx_fw_dump, | 
 | 1348 | 	.beacon_on		= qla24xx_beacon_on, | 
 | 1349 | 	.beacon_off		= qla24xx_beacon_off, | 
 | 1350 | 	.beacon_blink		= qla24xx_beacon_blink, | 
 | 1351 | 	.read_optrom		= qla24xx_read_optrom_data, | 
 | 1352 | 	.write_optrom		= qla24xx_write_optrom_data, | 
 | 1353 | 	.get_flash_version	= qla24xx_get_flash_version, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1354 | 	.start_scsi		= qla24xx_start_scsi, | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1355 | }; | 
 | 1356 |  | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1357 | static struct isp_operations qla25xx_isp_ops = { | 
 | 1358 | 	.pci_config		= qla25xx_pci_config, | 
 | 1359 | 	.reset_chip		= qla24xx_reset_chip, | 
 | 1360 | 	.chip_diag		= qla24xx_chip_diag, | 
 | 1361 | 	.config_rings		= qla24xx_config_rings, | 
 | 1362 | 	.reset_adapter		= qla24xx_reset_adapter, | 
 | 1363 | 	.nvram_config		= qla24xx_nvram_config, | 
 | 1364 | 	.update_fw_options	= qla24xx_update_fw_options, | 
 | 1365 | 	.load_risc		= qla24xx_load_risc, | 
 | 1366 | 	.pci_info_str		= qla24xx_pci_info_str, | 
 | 1367 | 	.fw_version_str		= qla24xx_fw_version_str, | 
 | 1368 | 	.intr_handler		= qla24xx_intr_handler, | 
 | 1369 | 	.enable_intrs		= qla24xx_enable_intrs, | 
 | 1370 | 	.disable_intrs		= qla24xx_disable_intrs, | 
 | 1371 | 	.abort_command		= qla24xx_abort_command, | 
| Andrew Vasquez | 523ec77 | 2008-04-03 13:13:24 -0700 | [diff] [blame] | 1372 | 	.target_reset		= qla24xx_abort_target, | 
 | 1373 | 	.lun_reset		= qla24xx_lun_reset, | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1374 | 	.fabric_login		= qla24xx_login_fabric, | 
 | 1375 | 	.fabric_logout		= qla24xx_fabric_logout, | 
 | 1376 | 	.calc_req_entries	= NULL, | 
 | 1377 | 	.build_iocbs		= NULL, | 
 | 1378 | 	.prep_ms_iocb		= qla24xx_prep_ms_iocb, | 
 | 1379 | 	.prep_ms_fdmi_iocb	= qla24xx_prep_ms_fdmi_iocb, | 
 | 1380 | 	.read_nvram		= qla25xx_read_nvram_data, | 
 | 1381 | 	.write_nvram		= qla25xx_write_nvram_data, | 
 | 1382 | 	.fw_dump		= qla25xx_fw_dump, | 
 | 1383 | 	.beacon_on		= qla24xx_beacon_on, | 
 | 1384 | 	.beacon_off		= qla24xx_beacon_off, | 
 | 1385 | 	.beacon_blink		= qla24xx_beacon_blink, | 
| Andrew Vasquez | 338c916 | 2007-09-20 14:07:33 -0700 | [diff] [blame] | 1386 | 	.read_optrom		= qla25xx_read_optrom_data, | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1387 | 	.write_optrom		= qla24xx_write_optrom_data, | 
 | 1388 | 	.get_flash_version	= qla24xx_get_flash_version, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1389 | 	.start_scsi		= qla24xx_start_scsi, | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1390 | }; | 
 | 1391 |  | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1392 | static struct isp_operations qla81xx_isp_ops = { | 
 | 1393 | 	.pci_config		= qla25xx_pci_config, | 
 | 1394 | 	.reset_chip		= qla24xx_reset_chip, | 
 | 1395 | 	.chip_diag		= qla24xx_chip_diag, | 
 | 1396 | 	.config_rings		= qla24xx_config_rings, | 
 | 1397 | 	.reset_adapter		= qla24xx_reset_adapter, | 
 | 1398 | 	.nvram_config		= qla81xx_nvram_config, | 
 | 1399 | 	.update_fw_options	= qla81xx_update_fw_options, | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 1400 | 	.load_risc		= qla81xx_load_risc, | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1401 | 	.pci_info_str		= qla24xx_pci_info_str, | 
 | 1402 | 	.fw_version_str		= qla24xx_fw_version_str, | 
 | 1403 | 	.intr_handler		= qla24xx_intr_handler, | 
 | 1404 | 	.enable_intrs		= qla24xx_enable_intrs, | 
 | 1405 | 	.disable_intrs		= qla24xx_disable_intrs, | 
 | 1406 | 	.abort_command		= qla24xx_abort_command, | 
 | 1407 | 	.target_reset		= qla24xx_abort_target, | 
 | 1408 | 	.lun_reset		= qla24xx_lun_reset, | 
 | 1409 | 	.fabric_login		= qla24xx_login_fabric, | 
 | 1410 | 	.fabric_logout		= qla24xx_fabric_logout, | 
 | 1411 | 	.calc_req_entries	= NULL, | 
 | 1412 | 	.build_iocbs		= NULL, | 
 | 1413 | 	.prep_ms_iocb		= qla24xx_prep_ms_iocb, | 
 | 1414 | 	.prep_ms_fdmi_iocb	= qla24xx_prep_ms_fdmi_iocb, | 
| Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 1415 | 	.read_nvram		= NULL, | 
 | 1416 | 	.write_nvram		= NULL, | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1417 | 	.fw_dump		= qla81xx_fw_dump, | 
 | 1418 | 	.beacon_on		= qla24xx_beacon_on, | 
 | 1419 | 	.beacon_off		= qla24xx_beacon_off, | 
 | 1420 | 	.beacon_blink		= qla24xx_beacon_blink, | 
 | 1421 | 	.read_optrom		= qla25xx_read_optrom_data, | 
 | 1422 | 	.write_optrom		= qla24xx_write_optrom_data, | 
 | 1423 | 	.get_flash_version	= qla24xx_get_flash_version, | 
 | 1424 | 	.start_scsi		= qla24xx_start_scsi, | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1425 | }; | 
 | 1426 |  | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1427 | static inline void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1428 | qla2x00_set_isp_flags(struct qla_hw_data *ha) | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1429 | { | 
 | 1430 | 	ha->device_type = DT_EXTENDED_IDS; | 
 | 1431 | 	switch (ha->pdev->device) { | 
 | 1432 | 	case PCI_DEVICE_ID_QLOGIC_ISP2100: | 
 | 1433 | 		ha->device_type |= DT_ISP2100; | 
 | 1434 | 		ha->device_type &= ~DT_EXTENDED_IDS; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1435 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2100; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1436 | 		break; | 
 | 1437 | 	case PCI_DEVICE_ID_QLOGIC_ISP2200: | 
 | 1438 | 		ha->device_type |= DT_ISP2200; | 
 | 1439 | 		ha->device_type &= ~DT_EXTENDED_IDS; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1440 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2100; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1441 | 		break; | 
 | 1442 | 	case PCI_DEVICE_ID_QLOGIC_ISP2300: | 
 | 1443 | 		ha->device_type |= DT_ISP2300; | 
| andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1444 | 		ha->device_type |= DT_ZIO_SUPPORTED; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1445 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2300; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1446 | 		break; | 
 | 1447 | 	case PCI_DEVICE_ID_QLOGIC_ISP2312: | 
 | 1448 | 		ha->device_type |= DT_ISP2312; | 
| andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1449 | 		ha->device_type |= DT_ZIO_SUPPORTED; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1450 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2300; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1451 | 		break; | 
 | 1452 | 	case PCI_DEVICE_ID_QLOGIC_ISP2322: | 
 | 1453 | 		ha->device_type |= DT_ISP2322; | 
| andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1454 | 		ha->device_type |= DT_ZIO_SUPPORTED; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1455 | 		if (ha->pdev->subsystem_vendor == 0x1028 && | 
 | 1456 | 		    ha->pdev->subsystem_device == 0x0170) | 
 | 1457 | 			ha->device_type |= DT_OEM_001; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1458 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2300; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1459 | 		break; | 
 | 1460 | 	case PCI_DEVICE_ID_QLOGIC_ISP6312: | 
 | 1461 | 		ha->device_type |= DT_ISP6312; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1462 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2300; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1463 | 		break; | 
 | 1464 | 	case PCI_DEVICE_ID_QLOGIC_ISP6322: | 
 | 1465 | 		ha->device_type |= DT_ISP6322; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1466 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2300; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1467 | 		break; | 
 | 1468 | 	case PCI_DEVICE_ID_QLOGIC_ISP2422: | 
 | 1469 | 		ha->device_type |= DT_ISP2422; | 
| andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1470 | 		ha->device_type |= DT_ZIO_SUPPORTED; | 
| Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1471 | 		ha->device_type |= DT_FWI2; | 
| Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 1472 | 		ha->device_type |= DT_IIDMA; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1473 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2400; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1474 | 		break; | 
 | 1475 | 	case PCI_DEVICE_ID_QLOGIC_ISP2432: | 
 | 1476 | 		ha->device_type |= DT_ISP2432; | 
| andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1477 | 		ha->device_type |= DT_ZIO_SUPPORTED; | 
| Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1478 | 		ha->device_type |= DT_FWI2; | 
| Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 1479 | 		ha->device_type |= DT_IIDMA; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1480 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2400; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1481 | 		break; | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1482 | 	case PCI_DEVICE_ID_QLOGIC_ISP8432: | 
 | 1483 | 		ha->device_type |= DT_ISP8432; | 
 | 1484 | 		ha->device_type |= DT_ZIO_SUPPORTED; | 
 | 1485 | 		ha->device_type |= DT_FWI2; | 
 | 1486 | 		ha->device_type |= DT_IIDMA; | 
 | 1487 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2400; | 
 | 1488 | 		break; | 
| andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1489 | 	case PCI_DEVICE_ID_QLOGIC_ISP5422: | 
 | 1490 | 		ha->device_type |= DT_ISP5422; | 
| Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1491 | 		ha->device_type |= DT_FWI2; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1492 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2400; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1493 | 		break; | 
| andrew.vasquez@qlogic.com | 044cc6c | 2006-03-09 14:27:13 -0800 | [diff] [blame] | 1494 | 	case PCI_DEVICE_ID_QLOGIC_ISP5432: | 
 | 1495 | 		ha->device_type |= DT_ISP5432; | 
| Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1496 | 		ha->device_type |= DT_FWI2; | 
| Andrew Vasquez | 441d107 | 2006-05-17 15:09:34 -0700 | [diff] [blame] | 1497 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2400; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1498 | 		break; | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1499 | 	case PCI_DEVICE_ID_QLOGIC_ISP2532: | 
 | 1500 | 		ha->device_type |= DT_ISP2532; | 
 | 1501 | 		ha->device_type |= DT_ZIO_SUPPORTED; | 
 | 1502 | 		ha->device_type |= DT_FWI2; | 
 | 1503 | 		ha->device_type |= DT_IIDMA; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1504 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2400; | 
 | 1505 | 		break; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1506 | 	case PCI_DEVICE_ID_QLOGIC_ISP8001: | 
 | 1507 | 		ha->device_type |= DT_ISP8001; | 
 | 1508 | 		ha->device_type |= DT_ZIO_SUPPORTED; | 
 | 1509 | 		ha->device_type |= DT_FWI2; | 
 | 1510 | 		ha->device_type |= DT_IIDMA; | 
 | 1511 | 		ha->fw_srisc_address = RISC_START_ADDRESS_2400; | 
 | 1512 | 		break; | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1513 | 	} | 
 | 1514 | } | 
 | 1515 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1517 | qla2x00_iospace_config(struct qla_hw_data *ha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | { | 
| Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1519 | 	resource_size_t pio; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1520 | 	uint16_t msix; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 |  | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1522 | 	if (pci_request_selected_regions(ha->pdev, ha->bars, | 
 | 1523 | 	    QLA2XXX_DRIVER_NAME)) { | 
 | 1524 | 		qla_printk(KERN_WARNING, ha, | 
 | 1525 | 		    "Failed to reserve PIO/MMIO regions (%s)\n", | 
 | 1526 | 		    pci_name(ha->pdev)); | 
 | 1527 |  | 
 | 1528 | 		goto iospace_error_exit; | 
 | 1529 | 	} | 
 | 1530 | 	if (!(ha->bars & 1)) | 
 | 1531 | 		goto skip_pio; | 
 | 1532 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | 	/* We only need PIO for Flash operations on ISP2312 v2 chips. */ | 
 | 1534 | 	pio = pci_resource_start(ha->pdev, 0); | 
| Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1535 | 	if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) { | 
 | 1536 | 		if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | 			qla_printk(KERN_WARNING, ha, | 
 | 1538 | 			    "Invalid PCI I/O region size (%s)...\n", | 
 | 1539 | 				pci_name(ha->pdev)); | 
 | 1540 | 			pio = 0; | 
 | 1541 | 		} | 
 | 1542 | 	} else { | 
 | 1543 | 		qla_printk(KERN_WARNING, ha, | 
 | 1544 | 		    "region #0 not a PIO resource (%s)...\n", | 
 | 1545 | 		    pci_name(ha->pdev)); | 
 | 1546 | 		pio = 0; | 
 | 1547 | 	} | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1548 | 	ha->pio_address = pio; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 |  | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1550 | skip_pio: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | 	/* Use MMIO operations for all accesses. */ | 
| Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1552 | 	if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | 		qla_printk(KERN_ERR, ha, | 
| Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1554 | 		    "region #1 not an MMIO resource (%s), aborting\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | 		    pci_name(ha->pdev)); | 
 | 1556 | 		goto iospace_error_exit; | 
 | 1557 | 	} | 
| Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1558 | 	if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | 		qla_printk(KERN_ERR, ha, | 
 | 1560 | 		    "Invalid PCI mem region size (%s), aborting\n", | 
 | 1561 | 			pci_name(ha->pdev)); | 
 | 1562 | 		goto iospace_error_exit; | 
 | 1563 | 	} | 
 | 1564 |  | 
| Andrew Vasquez | 3776541 | 2008-01-17 09:02:09 -0800 | [diff] [blame] | 1565 | 	ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | 	if (!ha->iobase) { | 
 | 1567 | 		qla_printk(KERN_ERR, ha, | 
 | 1568 | 		    "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev)); | 
 | 1569 |  | 
 | 1570 | 		goto iospace_error_exit; | 
 | 1571 | 	} | 
 | 1572 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1573 | 	/* Determine queue resources */ | 
 | 1574 | 	ha->max_queues = 1; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1575 | 	if (ql2xmaxqueues <= 1 || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))) | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1576 | 		goto mqiobase_exit; | 
 | 1577 | 	ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3), | 
 | 1578 | 			pci_resource_len(ha->pdev, 3)); | 
 | 1579 | 	if (ha->mqiobase) { | 
 | 1580 | 		/* Read MSIX vector size of the board */ | 
 | 1581 | 		pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix); | 
 | 1582 | 		ha->msix_count = msix; | 
 | 1583 | 		/* Max queues are bounded by available msix vectors */ | 
 | 1584 | 		/* queue 0 uses two msix vectors */ | 
 | 1585 | 		if (ha->msix_count - 1 < ql2xmaxqueues) | 
 | 1586 | 			ha->max_queues = ha->msix_count - 1; | 
 | 1587 | 		else if (ql2xmaxqueues > QLA_MQ_SIZE) | 
 | 1588 | 			ha->max_queues = QLA_MQ_SIZE; | 
 | 1589 | 		else | 
 | 1590 | 			ha->max_queues = ql2xmaxqueues; | 
 | 1591 | 		qla_printk(KERN_INFO, ha, | 
 | 1592 | 			"MSI-X vector count: %d\n", msix); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1593 | 	} | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1594 |  | 
 | 1595 | mqiobase_exit: | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1596 | 	ha->msix_count = ha->max_queues + 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | 	return (0); | 
 | 1598 |  | 
 | 1599 | iospace_error_exit: | 
 | 1600 | 	return (-ENOMEM); | 
 | 1601 | } | 
 | 1602 |  | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1603 | static void | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1604 | qla2xxx_scan_start(struct Scsi_Host *shost) | 
 | 1605 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1606 | 	scsi_qla_host_t *vha = shost_priv(shost); | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1607 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1608 | 	set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 
 | 1609 | 	set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | 
 | 1610 | 	set_bit(RSCN_UPDATE, &vha->dpc_flags); | 
 | 1611 | 	set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags); | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1612 | } | 
 | 1613 |  | 
 | 1614 | static int | 
 | 1615 | qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time) | 
 | 1616 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1617 | 	scsi_qla_host_t *vha = shost_priv(shost); | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1618 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1619 | 	if (!vha->host) | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1620 | 		return 1; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1621 | 	if (time > vha->hw->loop_reset_delay * HZ) | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1622 | 		return 1; | 
 | 1623 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1624 | 	return atomic_read(&vha->loop_state) == LOOP_READY; | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1625 | } | 
 | 1626 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | /* | 
 | 1628 |  * PCI driver interface | 
 | 1629 |  */ | 
| Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 1630 | static int __devinit | 
 | 1631 | qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | { | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1633 | 	int	ret = -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | 	struct Scsi_Host *host; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1635 | 	scsi_qla_host_t *base_vha = NULL; | 
 | 1636 | 	struct qla_hw_data *ha; | 
| Andrew Vasquez | 29856e2 | 2007-08-12 18:22:52 -0700 | [diff] [blame] | 1637 | 	char pci_info[30]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | 	char fw_str[30]; | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1639 | 	struct scsi_host_template *sht; | 
| Anirban Chakraborty | c51da4e | 2008-11-10 15:53:20 -0800 | [diff] [blame] | 1640 | 	int bars, max_id, mem_only = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1641 | 	uint16_t req_length = 0, rsp_length = 0; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1642 | 	struct req_que *req = NULL; | 
 | 1643 | 	struct rsp_que *rsp = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 |  | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1645 | 	bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); | 
| Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 1646 | 	sht = &qla2xxx_driver_template; | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1647 | 	if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 || | 
 | 1648 | 	    pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 || | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1649 | 	    pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 || | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1650 | 	    pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 || | 
 | 1651 | 	    pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 || | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1652 | 	    pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 || | 
 | 1653 | 	    pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) { | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1654 | 		bars = pci_select_bars(pdev, IORESOURCE_MEM); | 
| Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1655 | 		mem_only = 1; | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1656 | 	} | 
 | 1657 |  | 
| Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1658 | 	if (mem_only) { | 
 | 1659 | 		if (pci_enable_device_mem(pdev)) | 
 | 1660 | 			goto probe_out; | 
 | 1661 | 	} else { | 
 | 1662 | 		if (pci_enable_device(pdev)) | 
 | 1663 | 			goto probe_out; | 
 | 1664 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 |  | 
| Jesse Barnes | 0927678 | 2008-10-18 17:33:19 -0700 | [diff] [blame] | 1666 | 	/* This may fail but that's ok */ | 
 | 1667 | 	pci_enable_pcie_error_reporting(pdev); | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 1668 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1669 | 	ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL); | 
 | 1670 | 	if (!ha) { | 
 | 1671 | 		DEBUG(printk("Unable to allocate memory for ha\n")); | 
 | 1672 | 		goto probe_out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | 	} | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1674 | 	ha->pdev = pdev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 |  | 
 | 1676 | 	/* Clear our data area */ | 
| Andrew Vasquez | 285d032 | 2007-10-19 15:59:17 -0700 | [diff] [blame] | 1677 | 	ha->bars = bars; | 
| Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 1678 | 	ha->mem_only = mem_only; | 
| Andrew Vasquez | df4bf0b | 2008-01-31 12:33:46 -0800 | [diff] [blame] | 1679 | 	spin_lock_init(&ha->hardware_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 |  | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1681 | 	/* Set ISP-type information. */ | 
 | 1682 | 	qla2x00_set_isp_flags(ha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | 	/* Configure PCI I/O space */ | 
 | 1684 | 	ret = qla2x00_iospace_config(ha); | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1685 | 	if (ret) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1686 | 		goto probe_hw_failed; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | 	qla_printk(KERN_INFO, ha, | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1689 | 	    "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq, | 
 | 1690 | 	    ha->iobase); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | 	ha->prev_topology = 0; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1693 | 	ha->init_cb_size = sizeof(init_cb_t); | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 1694 | 	ha->link_data_rate = PORT_SPEED_UNKNOWN; | 
| andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1695 | 	ha->optrom_size = OPTROM_SIZE_2300; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 |  | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1697 | 	/* Assign ISP specific operations. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1698 | 	max_id = MAX_TARGETS_2200; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | 	if (IS_QLA2100(ha)) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1700 | 		max_id = MAX_TARGETS_2100; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | 		ha->mbx_count = MAILBOX_REGISTER_COUNT_2100; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1702 | 		req_length = REQUEST_ENTRY_CNT_2100; | 
 | 1703 | 		rsp_length = RESPONSE_ENTRY_CNT_2100; | 
 | 1704 | 		ha->max_loop_id = SNS_LAST_LOOP_ID_2100; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1705 | 		ha->gid_list_info_size = 4; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1706 | 		ha->flash_conf_off = ~0; | 
 | 1707 | 		ha->flash_data_off = ~0; | 
 | 1708 | 		ha->nvram_conf_off = ~0; | 
 | 1709 | 		ha->nvram_data_off = ~0; | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1710 | 		ha->isp_ops = &qla2100_isp_ops; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | 	} else if (IS_QLA2200(ha)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | 		ha->mbx_count = MAILBOX_REGISTER_COUNT; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1713 | 		req_length = REQUEST_ENTRY_CNT_2200; | 
 | 1714 | 		rsp_length = RESPONSE_ENTRY_CNT_2100; | 
 | 1715 | 		ha->max_loop_id = SNS_LAST_LOOP_ID_2100; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1716 | 		ha->gid_list_info_size = 4; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1717 | 		ha->flash_conf_off = ~0; | 
 | 1718 | 		ha->flash_data_off = ~0; | 
 | 1719 | 		ha->nvram_conf_off = ~0; | 
 | 1720 | 		ha->nvram_data_off = ~0; | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1721 | 		ha->isp_ops = &qla2100_isp_ops; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1722 | 	} else if (IS_QLA23XX(ha)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | 		ha->mbx_count = MAILBOX_REGISTER_COUNT; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1724 | 		req_length = REQUEST_ENTRY_CNT_2200; | 
 | 1725 | 		rsp_length = RESPONSE_ENTRY_CNT_2300; | 
 | 1726 | 		ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1727 | 		ha->gid_list_info_size = 6; | 
| andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1728 | 		if (IS_QLA2322(ha) || IS_QLA6322(ha)) | 
 | 1729 | 			ha->optrom_size = OPTROM_SIZE_2322; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1730 | 		ha->flash_conf_off = ~0; | 
 | 1731 | 		ha->flash_data_off = ~0; | 
 | 1732 | 		ha->nvram_conf_off = ~0; | 
 | 1733 | 		ha->nvram_data_off = ~0; | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1734 | 		ha->isp_ops = &qla2300_isp_ops; | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1735 | 	} else if (IS_QLA24XX_TYPE(ha)) { | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1736 | 		ha->mbx_count = MAILBOX_REGISTER_COUNT; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1737 | 		req_length = REQUEST_ENTRY_CNT_24XX; | 
 | 1738 | 		rsp_length = RESPONSE_ENTRY_CNT_2300; | 
 | 1739 | 		ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1740 | 		ha->init_cb_size = sizeof(struct mid_init_cb_24xx); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 1741 | 		ha->gid_list_info_size = 8; | 
| andrew.vasquez@qlogic.com | 854165f | 2006-01-31 16:05:17 -0800 | [diff] [blame] | 1742 | 		ha->optrom_size = OPTROM_SIZE_24XX; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1743 | 		ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX; | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1744 | 		ha->isp_ops = &qla24xx_isp_ops; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1745 | 		ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; | 
 | 1746 | 		ha->flash_data_off = FARX_ACCESS_FLASH_DATA; | 
 | 1747 | 		ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; | 
 | 1748 | 		ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1749 | 	} else if (IS_QLA25XX(ha)) { | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1750 | 		ha->mbx_count = MAILBOX_REGISTER_COUNT; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1751 | 		req_length = REQUEST_ENTRY_CNT_24XX; | 
 | 1752 | 		rsp_length = RESPONSE_ENTRY_CNT_2300; | 
 | 1753 | 		ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1754 | 		ha->init_cb_size = sizeof(struct mid_init_cb_24xx); | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1755 | 		ha->gid_list_info_size = 8; | 
 | 1756 | 		ha->optrom_size = OPTROM_SIZE_25XX; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1757 | 		ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1758 | 		ha->isp_ops = &qla25xx_isp_ops; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1759 | 		ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; | 
 | 1760 | 		ha->flash_data_off = FARX_ACCESS_FLASH_DATA; | 
 | 1761 | 		ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; | 
 | 1762 | 		ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; | 
 | 1763 | 	} else if (IS_QLA81XX(ha)) { | 
 | 1764 | 		ha->mbx_count = MAILBOX_REGISTER_COUNT; | 
 | 1765 | 		req_length = REQUEST_ENTRY_CNT_24XX; | 
 | 1766 | 		rsp_length = RESPONSE_ENTRY_CNT_2300; | 
 | 1767 | 		ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | 
 | 1768 | 		ha->init_cb_size = sizeof(struct mid_init_cb_81xx); | 
 | 1769 | 		ha->gid_list_info_size = 8; | 
 | 1770 | 		ha->optrom_size = OPTROM_SIZE_81XX; | 
 | 1771 | 		ha->isp_ops = &qla81xx_isp_ops; | 
 | 1772 | 		ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX; | 
 | 1773 | 		ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX; | 
 | 1774 | 		ha->nvram_conf_off = ~0; | 
 | 1775 | 		ha->nvram_data_off = ~0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 |  | 
| matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 1778 | 	mutex_init(&ha->vport_lock); | 
| Marcus Barrow | 0b05a1f | 2008-01-17 09:02:13 -0800 | [diff] [blame] | 1779 | 	init_completion(&ha->mbx_cmd_comp); | 
 | 1780 | 	complete(&ha->mbx_cmd_comp); | 
 | 1781 | 	init_completion(&ha->mbx_intr_comp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 |  | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1783 | 	set_bit(0, (unsigned long *) ha->vp_idx_map); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 |  | 
| Andrew Vasquez | 53303c4 | 2009-01-22 09:45:37 -0800 | [diff] [blame] | 1785 | 	qla2x00_config_dma_addressing(ha); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1786 | 	ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1787 | 	if (!ret) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | 		qla_printk(KERN_WARNING, ha, | 
 | 1789 | 		    "[ERROR] Failed to allocate memory for adapter\n"); | 
 | 1790 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1791 | 		goto probe_hw_failed; | 
 | 1792 | 	} | 
 | 1793 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1794 | 	req->max_q_depth = MAX_Q_DEPTH; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1795 | 	if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU) | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1796 | 		req->max_q_depth = ql2xmaxqdepth; | 
 | 1797 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1798 |  | 
 | 1799 | 	base_vha = qla2x00_create_host(sht, ha); | 
 | 1800 | 	if (!base_vha) { | 
 | 1801 | 		qla_printk(KERN_WARNING, ha, | 
 | 1802 | 		    "[ERROR] Failed to allocate memory for scsi_host\n"); | 
 | 1803 |  | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1804 | 		ret = -ENOMEM; | 
| Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 1805 | 		qla2x00_mem_free(ha); | 
 | 1806 | 		qla2x00_free_que(ha, req, rsp); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1807 | 		goto probe_hw_failed; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | 	} | 
 | 1809 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1810 | 	pci_set_drvdata(pdev, base_vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1812 | 	host = base_vha->host; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1813 | 	base_vha->req_ques[0] = req->id; | 
 | 1814 | 	host->can_queue = req->length + 128; | 
 | 1815 | 	if (IS_QLA2XXX_MIDTYPE(ha)) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1816 | 		base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1817 | 	else | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1818 | 		base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER + | 
 | 1819 | 						base_vha->vp_idx; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1820 | 	if (IS_QLA2100(ha)) | 
 | 1821 | 		host->sg_tablesize = 32; | 
 | 1822 | 	host->max_id = max_id; | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1823 | 	host->this_id = 255; | 
 | 1824 | 	host->cmd_per_lun = 3; | 
| Seokmann Ju | 711c1d9 | 2008-07-10 16:55:51 -0700 | [diff] [blame] | 1825 | 	host->unique_id = host->host_no; | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1826 | 	host->max_cmd_len = MAX_CMDSZ; | 
| Andrew Vasquez | 75bc419 | 2006-05-17 15:09:22 -0700 | [diff] [blame] | 1827 | 	host->max_channel = MAX_BUSES - 1; | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1828 | 	host->max_lun = MAX_LUNS; | 
 | 1829 | 	host->transportt = qla2xxx_transport_template; | 
 | 1830 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1831 | 	/* Set up the irqs */ | 
 | 1832 | 	ret = qla2x00_request_irqs(ha, rsp); | 
 | 1833 | 	if (ret) | 
| Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 1834 | 		goto probe_init_failed; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1835 | 	/* Alloc arrays of request and response ring ptrs */ | 
 | 1836 | 	if (!qla2x00_alloc_queues(ha)) { | 
 | 1837 | 		qla_printk(KERN_WARNING, ha, | 
 | 1838 | 		"[ERROR] Failed to allocate memory for queue" | 
 | 1839 | 		" pointers\n"); | 
| Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 1840 | 		goto probe_init_failed; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1841 | 	} | 
 | 1842 | 	ha->rsp_q_map[0] = rsp; | 
 | 1843 | 	ha->req_q_map[0] = req; | 
 | 1844 |  | 
| Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 1845 | 	/* FWI2-capable only. */ | 
 | 1846 | 	req->req_q_in = &ha->iobase->isp24.req_q_in; | 
 | 1847 | 	req->req_q_out = &ha->iobase->isp24.req_q_out; | 
 | 1848 | 	rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in; | 
 | 1849 | 	rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1850 | 	if (ha->mqenable) { | 
| Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 1851 | 		req->req_q_in = &ha->mqiobase->isp25mq.req_q_in; | 
 | 1852 | 		req->req_q_out = &ha->mqiobase->isp25mq.req_q_out; | 
 | 1853 | 		rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in; | 
 | 1854 | 		rsp->rsp_q_out =  &ha->mqiobase->isp25mq.rsp_q_out; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1855 | 	} | 
 | 1856 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1857 | 	if (qla2x00_initialize_adapter(base_vha)) { | 
 | 1858 | 		qla_printk(KERN_WARNING, ha, | 
 | 1859 | 		    "Failed to initialize adapter\n"); | 
 | 1860 |  | 
 | 1861 | 		DEBUG2(printk("scsi(%ld): Failed to initialize adapter - " | 
 | 1862 | 		    "Adapter flags %x.\n", | 
 | 1863 | 		    base_vha->host_no, base_vha->device_flags)); | 
 | 1864 |  | 
 | 1865 | 		ret = -ENODEV; | 
 | 1866 | 		goto probe_failed; | 
 | 1867 | 	} | 
 | 1868 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1869 | 	/* | 
 | 1870 | 	 * Startup the kernel thread for this host adapter | 
 | 1871 | 	 */ | 
 | 1872 | 	ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha, | 
 | 1873 | 			"%s_dpc", base_vha->host_str); | 
 | 1874 | 	if (IS_ERR(ha->dpc_thread)) { | 
 | 1875 | 		qla_printk(KERN_WARNING, ha, | 
 | 1876 | 		    "Unable to start DPC thread!\n"); | 
 | 1877 | 		ret = PTR_ERR(ha->dpc_thread); | 
 | 1878 | 		goto probe_failed; | 
 | 1879 | 	} | 
 | 1880 |  | 
 | 1881 | 	list_add_tail(&base_vha->list, &ha->vp_list); | 
 | 1882 | 	base_vha->host->irq = ha->pdev->irq; | 
 | 1883 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | 	/* Initialized the timer */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1885 | 	qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 |  | 
 | 1887 | 	DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1888 | 	    base_vha->host_no, ha)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1890 | 	base_vha->flags.init_done = 1; | 
 | 1891 | 	base_vha->flags.online = 1; | 
| Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1892 |  | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1893 | 	ret = scsi_add_host(host, &pdev->dev); | 
 | 1894 | 	if (ret) | 
 | 1895 | 		goto probe_failed; | 
 | 1896 |  | 
| Andrew Vasquez | 048feec | 2008-09-11 22:19:45 -0700 | [diff] [blame] | 1897 | 	ha->isp_ops->enable_intrs(ha); | 
 | 1898 |  | 
| Andrew Vasquez | 1e99e33 | 2006-11-22 08:24:48 -0800 | [diff] [blame] | 1899 | 	scsi_scan_host(host); | 
 | 1900 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1901 | 	qla2x00_alloc_sysfs_attr(base_vha); | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1902 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1903 | 	qla2x00_init_host_attr(base_vha); | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1904 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1905 | 	qla2x00_dfs_setup(base_vha); | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1906 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | 	qla_printk(KERN_INFO, ha, "\n" | 
 | 1908 | 	    " QLogic Fibre Channel HBA Driver: %s\n" | 
 | 1909 | 	    "  QLogic %s - %s\n" | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 1910 | 	    "  ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n", | 
 | 1911 | 	    qla2x00_version_str, ha->model_number, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1912 | 	    ha->model_desc ? ha->model_desc : "", pdev->device, | 
 | 1913 | 	    ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev), | 
 | 1914 | 	    ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no, | 
 | 1915 | 	    ha->isp_ops->fw_version_str(base_vha, fw_str)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | 	return 0; | 
 | 1918 |  | 
| Anirban Chakraborty | 6e9f21f | 2009-01-22 09:45:28 -0800 | [diff] [blame] | 1919 | probe_init_failed: | 
 | 1920 | 	qla2x00_free_que(ha, req, rsp); | 
 | 1921 | 	ha->max_queues = 0; | 
 | 1922 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | probe_failed: | 
| Andrew Vasquez | b997876 | 2009-03-24 09:08:05 -0700 | [diff] [blame] | 1924 | 	if (base_vha->timer_active) | 
 | 1925 | 		qla2x00_stop_timer(base_vha); | 
 | 1926 | 	base_vha->flags.online = 0; | 
 | 1927 | 	if (ha->dpc_thread) { | 
 | 1928 | 		struct task_struct *t = ha->dpc_thread; | 
 | 1929 |  | 
 | 1930 | 		ha->dpc_thread = NULL; | 
 | 1931 | 		kthread_stop(t); | 
 | 1932 | 	} | 
 | 1933 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1934 | 	qla2x00_free_device(base_vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1936 | 	scsi_host_put(base_vha->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1938 | probe_hw_failed: | 
 | 1939 | 	if (ha->iobase) | 
 | 1940 | 		iounmap(ha->iobase); | 
 | 1941 |  | 
 | 1942 | 	pci_release_selected_regions(ha->pdev, ha->bars); | 
 | 1943 | 	kfree(ha); | 
 | 1944 | 	ha = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 |  | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1946 | probe_out: | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1947 | 	pci_disable_device(pdev); | 
| Andrew Vasquez | a1541d5 | 2005-06-09 17:21:28 -0700 | [diff] [blame] | 1948 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 |  | 
| Adrian Bunk | 4c993f7 | 2008-01-14 00:55:16 -0800 | [diff] [blame] | 1951 | static void | 
| Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 1952 | qla2x00_remove_one(struct pci_dev *pdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1954 | 	scsi_qla_host_t *base_vha, *vha, *temp; | 
 | 1955 | 	struct qla_hw_data  *ha; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1957 | 	base_vha = pci_get_drvdata(pdev); | 
 | 1958 | 	ha = base_vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1960 | 	list_for_each_entry_safe(vha, temp, &ha->vp_list, list) { | 
 | 1961 | 		if (vha && vha->fc_vport) | 
 | 1962 | 			fc_vport_terminate(vha->fc_vport); | 
 | 1963 | 	} | 
| Andrew Vasquez | c795c1e | 2008-08-13 21:37:01 -0700 | [diff] [blame] | 1964 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1965 | 	set_bit(UNLOADING, &base_vha->dpc_flags); | 
| Andrew Vasquez | c795c1e | 2008-08-13 21:37:01 -0700 | [diff] [blame] | 1966 |  | 
| Andrew Vasquez | b997876 | 2009-03-24 09:08:05 -0700 | [diff] [blame] | 1967 | 	qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16); | 
 | 1968 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1969 | 	qla2x00_dfs_remove(base_vha); | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1970 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1971 | 	qla84xx_put_chip(base_vha); | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1972 |  | 
| Andrew Vasquez | b997876 | 2009-03-24 09:08:05 -0700 | [diff] [blame] | 1973 | 	/* Disable timer */ | 
 | 1974 | 	if (base_vha->timer_active) | 
 | 1975 | 		qla2x00_stop_timer(base_vha); | 
 | 1976 |  | 
 | 1977 | 	base_vha->flags.online = 0; | 
 | 1978 |  | 
 | 1979 | 	/* Kill the kernel thread for this host */ | 
 | 1980 | 	if (ha->dpc_thread) { | 
 | 1981 | 		struct task_struct *t = ha->dpc_thread; | 
 | 1982 |  | 
 | 1983 | 		/* | 
 | 1984 | 		 * qla2xxx_wake_dpc checks for ->dpc_thread | 
 | 1985 | 		 * so we need to zero it out. | 
 | 1986 | 		 */ | 
 | 1987 | 		ha->dpc_thread = NULL; | 
 | 1988 | 		kthread_stop(t); | 
 | 1989 | 	} | 
 | 1990 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1991 | 	qla2x00_free_sysfs_attr(base_vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1993 | 	fc_remove_host(base_vha->host); | 
 | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 1994 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1995 | 	scsi_remove_host(base_vha->host); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1997 | 	qla2x00_free_device(base_vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1999 | 	scsi_host_put(base_vha->host); | 
 | 2000 |  | 
 | 2001 | 	if (ha->iobase) | 
 | 2002 | 		iounmap(ha->iobase); | 
 | 2003 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2004 | 	if (ha->mqiobase) | 
 | 2005 | 		iounmap(ha->mqiobase); | 
 | 2006 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2007 | 	pci_release_selected_regions(ha->pdev, ha->bars); | 
 | 2008 | 	kfree(ha); | 
 | 2009 | 	ha = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 |  | 
| Bernhard Walle | 665db93 | 2007-03-28 00:49:49 +0200 | [diff] [blame] | 2011 | 	pci_disable_device(pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | 	pci_set_drvdata(pdev, NULL); | 
 | 2013 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 |  | 
 | 2015 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2016 | qla2x00_free_device(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2018 | 	struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 |  | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2020 | 	if (ha->flags.fce_enabled) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2021 | 		qla2x00_disable_fce_trace(vha, NULL, NULL); | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2022 |  | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2023 | 	if (ha->eft) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2024 | 		qla2x00_disable_eft_trace(vha); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2025 |  | 
| Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2026 | 	/* Stop currently executing firmware. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2027 | 	qla2x00_try_to_stop_firmware(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 |  | 
| Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2029 | 	/* turn-off interrupts on the card */ | 
 | 2030 | 	if (ha->interrupts_on) | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2031 | 		ha->isp_ops->disable_intrs(ha); | 
| Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2032 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2033 | 	qla2x00_free_irqs(vha); | 
 | 2034 |  | 
| Andrew Vasquez | f6ef3b1 | 2005-08-26 19:10:20 -0700 | [diff] [blame] | 2035 | 	qla2x00_mem_free(ha); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2036 |  | 
 | 2037 | 	qla2x00_free_queues(ha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | } | 
 | 2039 |  | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2040 | static inline void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2041 | qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport, | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2042 |     int defer) | 
 | 2043 | { | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2044 | 	struct fc_rport *rport; | 
 | 2045 |  | 
 | 2046 | 	if (!fcport->rport) | 
 | 2047 | 		return; | 
 | 2048 |  | 
 | 2049 | 	rport = fcport->rport; | 
 | 2050 | 	if (defer) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2051 | 		spin_lock_irq(vha->host->host_lock); | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2052 | 		fcport->drport = rport; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2053 | 		spin_unlock_irq(vha->host->host_lock); | 
 | 2054 | 		set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags); | 
 | 2055 | 		qla2xxx_wake_dpc(vha); | 
| Seokmann Ju | 5f3a9a2 | 2008-07-10 16:55:47 -0700 | [diff] [blame] | 2056 | 	} else | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2057 | 		fc_remote_port_delete(rport); | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2058 | } | 
 | 2059 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 |  * qla2x00_mark_device_lost Updates fcport state when device goes offline. | 
 | 2062 |  * | 
 | 2063 |  * Input: ha = adapter block pointer.  fcport = port structure pointer. | 
 | 2064 |  * | 
 | 2065 |  * Return: None. | 
 | 2066 |  * | 
 | 2067 |  * Context: | 
 | 2068 |  */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2069 | void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport, | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2070 |     int do_login, int defer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | { | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2072 | 	if (atomic_read(&fcport->state) == FCS_ONLINE && | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2073 | 	    vha->vp_idx == fcport->vp_idx) { | 
 | 2074 | 		atomic_set(&fcport->state, FCS_DEVICE_LOST); | 
 | 2075 | 		qla2x00_schedule_rport_del(vha, fcport, defer); | 
 | 2076 | 	} | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2077 | 	/* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | 	 * We may need to retry the login, so don't change the state of the | 
 | 2079 | 	 * port but do the retries. | 
 | 2080 | 	 */ | 
 | 2081 | 	if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD) | 
 | 2082 | 		atomic_set(&fcport->state, FCS_DEVICE_LOST); | 
 | 2083 |  | 
 | 2084 | 	if (!do_login) | 
 | 2085 | 		return; | 
 | 2086 |  | 
 | 2087 | 	if (fcport->login_retry == 0) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2088 | 		fcport->login_retry = vha->hw->login_retry_count; | 
 | 2089 | 		set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 |  | 
 | 2091 | 		DEBUG(printk("scsi(%ld): Port login retry: " | 
 | 2092 | 		    "%02x%02x%02x%02x%02x%02x%02x%02x, " | 
 | 2093 | 		    "id = 0x%04x retry cnt=%d\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2094 | 		    vha->host_no, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | 		    fcport->port_name[0], | 
 | 2096 | 		    fcport->port_name[1], | 
 | 2097 | 		    fcport->port_name[2], | 
 | 2098 | 		    fcport->port_name[3], | 
 | 2099 | 		    fcport->port_name[4], | 
 | 2100 | 		    fcport->port_name[5], | 
 | 2101 | 		    fcport->port_name[6], | 
 | 2102 | 		    fcport->port_name[7], | 
 | 2103 | 		    fcport->loop_id, | 
 | 2104 | 		    fcport->login_retry)); | 
 | 2105 | 	} | 
 | 2106 | } | 
 | 2107 |  | 
 | 2108 | /* | 
 | 2109 |  * qla2x00_mark_all_devices_lost | 
 | 2110 |  *	Updates fcport state when device goes offline. | 
 | 2111 |  * | 
 | 2112 |  * Input: | 
 | 2113 |  *	ha = adapter block pointer. | 
 | 2114 |  *	fcport = port structure pointer. | 
 | 2115 |  * | 
 | 2116 |  * Return: | 
 | 2117 |  *	None. | 
 | 2118 |  * | 
 | 2119 |  * Context: | 
 | 2120 |  */ | 
 | 2121 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2122 | qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | { | 
 | 2124 | 	fc_port_t *fcport; | 
 | 2125 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2126 | 	list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
 | 2127 | 		if (vha->vp_idx != fcport->vp_idx) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | 			continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | 		/* | 
 | 2130 | 		 * No point in marking the device as lost, if the device is | 
 | 2131 | 		 * already DEAD. | 
 | 2132 | 		 */ | 
 | 2133 | 		if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) | 
 | 2134 | 			continue; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2135 | 		if (atomic_read(&fcport->state) == FCS_ONLINE) { | 
 | 2136 | 			atomic_set(&fcport->state, FCS_DEVICE_LOST); | 
 | 2137 | 			qla2x00_schedule_rport_del(vha, fcport, defer); | 
 | 2138 | 		} else | 
 | 2139 | 			atomic_set(&fcport->state, FCS_DEVICE_LOST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | 	} | 
 | 2141 | } | 
 | 2142 |  | 
 | 2143 | /* | 
 | 2144 | * qla2x00_mem_alloc | 
 | 2145 | *      Allocates adapter memory. | 
 | 2146 | * | 
 | 2147 | * Returns: | 
 | 2148 | *      0  = success. | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2149 | *      !0  = failure. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | */ | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2151 | static int | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2152 | qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len, | 
 | 2153 | 	struct req_que **req, struct rsp_que **rsp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | { | 
 | 2155 | 	char	name[16]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 |  | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2157 | 	ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2158 | 		&ha->init_cb_dma, GFP_KERNEL); | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2159 | 	if (!ha->init_cb) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2160 | 		goto fail; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2162 | 	ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE, | 
 | 2163 | 		&ha->gid_list_dma, GFP_KERNEL); | 
 | 2164 | 	if (!ha->gid_list) | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2165 | 		goto fail_free_init_cb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 |  | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2167 | 	ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); | 
 | 2168 | 	if (!ha->srb_mempool) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2169 | 		goto fail_free_gid_list; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 |  | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2171 | 	/* Get memory for cached NVRAM */ | 
 | 2172 | 	ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL); | 
 | 2173 | 	if (!ha->nvram) | 
 | 2174 | 		goto fail_free_srb_mempool; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2176 | 	snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME, | 
 | 2177 | 		ha->pdev->device); | 
 | 2178 | 	ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev, | 
 | 2179 | 		DMA_POOL_SIZE, 8, 0); | 
 | 2180 | 	if (!ha->s_dma_pool) | 
 | 2181 | 		goto fail_free_nvram; | 
 | 2182 |  | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2183 | 	/* Allocate memory for SNS commands */ | 
 | 2184 | 	if (IS_QLA2100(ha) || IS_QLA2200(ha)) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2185 | 	/* Get consistent memory allocated for SNS commands */ | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2186 | 		ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2187 | 		sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL); | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2188 | 		if (!ha->sns_cmd) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2189 | 			goto fail_dma_pool; | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2190 | 	} else { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2191 | 	/* Get consistent memory allocated for MS IOCB */ | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2192 | 		ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2193 | 			&ha->ms_iocb_dma); | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2194 | 		if (!ha->ms_iocb) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2195 | 			goto fail_dma_pool; | 
 | 2196 | 	/* Get consistent memory allocated for CT SNS commands */ | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2197 | 		ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2198 | 			sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL); | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2199 | 		if (!ha->ct_sns) | 
 | 2200 | 			goto fail_free_ms_iocb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | 	} | 
 | 2202 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2203 | 	/* Allocate memory for request ring */ | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2204 | 	*req = kzalloc(sizeof(struct req_que), GFP_KERNEL); | 
 | 2205 | 	if (!*req) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2206 | 		DEBUG(printk("Unable to allocate memory for req\n")); | 
 | 2207 | 		goto fail_req; | 
 | 2208 | 	} | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2209 | 	(*req)->length = req_len; | 
 | 2210 | 	(*req)->ring = dma_alloc_coherent(&ha->pdev->dev, | 
 | 2211 | 		((*req)->length + 1) * sizeof(request_t), | 
 | 2212 | 		&(*req)->dma, GFP_KERNEL); | 
 | 2213 | 	if (!(*req)->ring) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2214 | 		DEBUG(printk("Unable to allocate memory for req_ring\n")); | 
 | 2215 | 		goto fail_req_ring; | 
 | 2216 | 	} | 
 | 2217 | 	/* Allocate memory for response ring */ | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2218 | 	*rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL); | 
 | 2219 | 	if (!*rsp) { | 
 | 2220 | 		qla_printk(KERN_WARNING, ha, | 
 | 2221 | 			"Unable to allocate memory for rsp\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2222 | 		goto fail_rsp; | 
 | 2223 | 	} | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2224 | 	(*rsp)->hw = ha; | 
 | 2225 | 	(*rsp)->length = rsp_len; | 
 | 2226 | 	(*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev, | 
 | 2227 | 		((*rsp)->length + 1) * sizeof(response_t), | 
 | 2228 | 		&(*rsp)->dma, GFP_KERNEL); | 
 | 2229 | 	if (!(*rsp)->ring) { | 
 | 2230 | 		qla_printk(KERN_WARNING, ha, | 
 | 2231 | 			"Unable to allocate memory for rsp_ring\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2232 | 		goto fail_rsp_ring; | 
 | 2233 | 	} | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2234 | 	(*req)->rsp = *rsp; | 
 | 2235 | 	(*rsp)->req = *req; | 
 | 2236 | 	/* Allocate memory for NVRAM data for vports */ | 
 | 2237 | 	if (ha->nvram_npiv_size) { | 
 | 2238 | 		ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) * | 
 | 2239 | 					ha->nvram_npiv_size, GFP_KERNEL); | 
 | 2240 | 		if (!ha->npiv_info) { | 
 | 2241 | 			qla_printk(KERN_WARNING, ha, | 
 | 2242 | 				"Unable to allocate memory for npiv info\n"); | 
 | 2243 | 			goto fail_npiv_info; | 
 | 2244 | 		} | 
 | 2245 | 	} else | 
 | 2246 | 		ha->npiv_info = NULL; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2247 |  | 
| Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2248 | 	/* Get consistent memory allocated for EX-INIT-CB. */ | 
 | 2249 | 	if (IS_QLA81XX(ha)) { | 
 | 2250 | 		ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, | 
 | 2251 | 		    &ha->ex_init_cb_dma); | 
 | 2252 | 		if (!ha->ex_init_cb) | 
 | 2253 | 			goto fail_ex_init_cb; | 
 | 2254 | 	} | 
 | 2255 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2256 | 	INIT_LIST_HEAD(&ha->vp_list); | 
 | 2257 | 	return 1; | 
 | 2258 |  | 
| Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2259 | fail_ex_init_cb: | 
 | 2260 | 	kfree(ha->npiv_info); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2261 | fail_npiv_info: | 
 | 2262 | 	dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) * | 
 | 2263 | 		sizeof(response_t), (*rsp)->ring, (*rsp)->dma); | 
 | 2264 | 	(*rsp)->ring = NULL; | 
 | 2265 | 	(*rsp)->dma = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2266 | fail_rsp_ring: | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2267 | 	kfree(*rsp); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2268 | fail_rsp: | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2269 | 	dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) * | 
 | 2270 | 		sizeof(request_t), (*req)->ring, (*req)->dma); | 
 | 2271 | 	(*req)->ring = NULL; | 
 | 2272 | 	(*req)->dma = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2273 | fail_req_ring: | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2274 | 	kfree(*req); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2275 | fail_req: | 
 | 2276 | 	dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), | 
 | 2277 | 		ha->ct_sns, ha->ct_sns_dma); | 
 | 2278 | 	ha->ct_sns = NULL; | 
 | 2279 | 	ha->ct_sns_dma = 0; | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2280 | fail_free_ms_iocb: | 
 | 2281 | 	dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); | 
 | 2282 | 	ha->ms_iocb = NULL; | 
 | 2283 | 	ha->ms_iocb_dma = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2284 | fail_dma_pool: | 
 | 2285 | 	dma_pool_destroy(ha->s_dma_pool); | 
 | 2286 | 	ha->s_dma_pool = NULL; | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2287 | fail_free_nvram: | 
 | 2288 | 	kfree(ha->nvram); | 
 | 2289 | 	ha->nvram = NULL; | 
 | 2290 | fail_free_srb_mempool: | 
 | 2291 | 	mempool_destroy(ha->srb_mempool); | 
 | 2292 | 	ha->srb_mempool = NULL; | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2293 | fail_free_gid_list: | 
 | 2294 | 	dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2295 | 	ha->gid_list_dma); | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2296 | 	ha->gid_list = NULL; | 
 | 2297 | 	ha->gid_list_dma = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2298 | fail_free_init_cb: | 
 | 2299 | 	dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb, | 
 | 2300 | 	ha->init_cb_dma); | 
 | 2301 | 	ha->init_cb = NULL; | 
 | 2302 | 	ha->init_cb_dma = 0; | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2303 | fail: | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2304 | 	DEBUG(printk("%s: Memory allocation failure\n", __func__)); | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2305 | 	return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | } | 
 | 2307 |  | 
 | 2308 | /* | 
 | 2309 | * qla2x00_mem_free | 
 | 2310 | *      Frees all adapter allocated memory. | 
 | 2311 | * | 
 | 2312 | * Input: | 
 | 2313 | *      ha = adapter block pointer. | 
 | 2314 | */ | 
| Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 2315 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2316 | qla2x00_mem_free(struct qla_hw_data *ha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | { | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2318 | 	if (ha->srb_mempool) | 
 | 2319 | 		mempool_destroy(ha->srb_mempool); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 |  | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2321 | 	if (ha->fce) | 
 | 2322 | 		dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2323 | 		ha->fce_dma); | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2324 |  | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2325 | 	if (ha->fw_dump) { | 
 | 2326 | 		if (ha->eft) | 
 | 2327 | 			dma_free_coherent(&ha->pdev->dev, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2328 | 			ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2329 | 		vfree(ha->fw_dump); | 
 | 2330 | 	} | 
 | 2331 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | 	if (ha->sns_cmd) | 
 | 2333 | 		dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2334 | 		ha->sns_cmd, ha->sns_cmd_dma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 |  | 
 | 2336 | 	if (ha->ct_sns) | 
 | 2337 | 		dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2338 | 		ha->ct_sns, ha->ct_sns_dma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 |  | 
| Andrew Vasquez | 88729e5 | 2006-06-23 16:10:50 -0700 | [diff] [blame] | 2340 | 	if (ha->sfp_data) | 
 | 2341 | 		dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma); | 
 | 2342 |  | 
| Joe Carnuccio | ad0ecd6 | 2009-03-24 09:08:12 -0700 | [diff] [blame] | 2343 | 	if (ha->edc_data) | 
 | 2344 | 		dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma); | 
 | 2345 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | 	if (ha->ms_iocb) | 
 | 2347 | 		dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); | 
 | 2348 |  | 
| Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2349 | 	if (ha->ex_init_cb) | 
 | 2350 | 		dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma); | 
 | 2351 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | 	if (ha->s_dma_pool) | 
 | 2353 | 		dma_pool_destroy(ha->s_dma_pool); | 
 | 2354 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | 	if (ha->gid_list) | 
 | 2356 | 		dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2357 | 		ha->gid_list_dma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2359 | 	if (ha->init_cb) | 
 | 2360 | 		dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, | 
 | 2361 | 		ha->init_cb, ha->init_cb_dma); | 
 | 2362 | 	vfree(ha->optrom_buffer); | 
 | 2363 | 	kfree(ha->nvram); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2364 | 	kfree(ha->npiv_info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 |  | 
| Andrew Vasquez | e871108 | 2008-01-31 12:33:48 -0800 | [diff] [blame] | 2366 | 	ha->srb_mempool = NULL; | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2367 | 	ha->eft = NULL; | 
 | 2368 | 	ha->eft_dma = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | 	ha->sns_cmd = NULL; | 
 | 2370 | 	ha->sns_cmd_dma = 0; | 
 | 2371 | 	ha->ct_sns = NULL; | 
 | 2372 | 	ha->ct_sns_dma = 0; | 
 | 2373 | 	ha->ms_iocb = NULL; | 
 | 2374 | 	ha->ms_iocb_dma = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | 	ha->init_cb = NULL; | 
 | 2376 | 	ha->init_cb_dma = 0; | 
| Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 2377 | 	ha->ex_init_cb = NULL; | 
 | 2378 | 	ha->ex_init_cb_dma = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 |  | 
 | 2380 | 	ha->s_dma_pool = NULL; | 
 | 2381 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | 	ha->gid_list = NULL; | 
 | 2383 | 	ha->gid_list_dma = 0; | 
 | 2384 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | 	ha->fw_dump = NULL; | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2386 | 	ha->fw_dumped = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | 	ha->fw_dump_reading = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2388 | } | 
 | 2389 |  | 
 | 2390 | struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, | 
 | 2391 | 						struct qla_hw_data *ha) | 
 | 2392 | { | 
 | 2393 | 	struct Scsi_Host *host; | 
 | 2394 | 	struct scsi_qla_host *vha = NULL; | 
 | 2395 |  | 
 | 2396 | 	host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t)); | 
 | 2397 | 	if (host == NULL) { | 
 | 2398 | 		printk(KERN_WARNING | 
 | 2399 | 		"qla2xxx: Couldn't allocate host from scsi layer!\n"); | 
 | 2400 | 		goto fail; | 
 | 2401 | 	} | 
 | 2402 |  | 
 | 2403 | 	/* Clear our data area */ | 
 | 2404 | 	vha = shost_priv(host); | 
 | 2405 | 	memset(vha, 0, sizeof(scsi_qla_host_t)); | 
 | 2406 |  | 
 | 2407 | 	vha->host = host; | 
 | 2408 | 	vha->host_no = host->host_no; | 
 | 2409 | 	vha->hw = ha; | 
 | 2410 |  | 
 | 2411 | 	INIT_LIST_HEAD(&vha->vp_fcports); | 
 | 2412 | 	INIT_LIST_HEAD(&vha->work_list); | 
 | 2413 | 	INIT_LIST_HEAD(&vha->list); | 
 | 2414 |  | 
 | 2415 | 	sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no); | 
 | 2416 | 	return vha; | 
 | 2417 |  | 
 | 2418 | fail: | 
 | 2419 | 	return vha; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | } | 
 | 2421 |  | 
| Adrian Bunk | 01ef66b | 2008-04-24 15:21:27 -0700 | [diff] [blame] | 2422 | static struct qla_work_evt * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2423 | qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type, | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2424 |     int locked) | 
 | 2425 | { | 
 | 2426 | 	struct qla_work_evt *e; | 
 | 2427 |  | 
 | 2428 | 	e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC: | 
 | 2429 | 	    GFP_KERNEL); | 
 | 2430 | 	if (!e) | 
 | 2431 | 		return NULL; | 
 | 2432 |  | 
 | 2433 | 	INIT_LIST_HEAD(&e->list); | 
 | 2434 | 	e->type = type; | 
 | 2435 | 	e->flags = QLA_EVT_FLAG_FREE; | 
 | 2436 | 	return e; | 
 | 2437 | } | 
 | 2438 |  | 
| Adrian Bunk | 01ef66b | 2008-04-24 15:21:27 -0700 | [diff] [blame] | 2439 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2440 | qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked) | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2441 | { | 
| Andrew Morton | bf6583b | 2008-07-24 08:31:48 -0700 | [diff] [blame] | 2442 | 	unsigned long uninitialized_var(flags); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2443 | 	struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2444 |  | 
 | 2445 | 	if (!locked) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2446 | 		spin_lock_irqsave(&ha->hardware_lock, flags); | 
 | 2447 | 	list_add_tail(&e->list, &vha->work_list); | 
 | 2448 | 	qla2xxx_wake_dpc(vha); | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2449 | 	if (!locked) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2450 | 		spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2451 | 	return QLA_SUCCESS; | 
 | 2452 | } | 
 | 2453 |  | 
 | 2454 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2455 | qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code, | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2456 |     u32 data) | 
 | 2457 | { | 
 | 2458 | 	struct qla_work_evt *e; | 
 | 2459 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2460 | 	e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1); | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2461 | 	if (!e) | 
 | 2462 | 		return QLA_FUNCTION_FAILED; | 
 | 2463 |  | 
 | 2464 | 	e->u.aen.code = code; | 
 | 2465 | 	e->u.aen.data = data; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2466 | 	return qla2x00_post_work(vha, e, 1); | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2467 | } | 
 | 2468 |  | 
| Andrew Vasquez | 8a65957 | 2009-02-08 20:50:12 -0800 | [diff] [blame] | 2469 | int | 
 | 2470 | qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb) | 
 | 2471 | { | 
 | 2472 | 	struct qla_work_evt *e; | 
 | 2473 |  | 
 | 2474 | 	e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK, 1); | 
 | 2475 | 	if (!e) | 
 | 2476 | 		return QLA_FUNCTION_FAILED; | 
 | 2477 |  | 
 | 2478 | 	memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t)); | 
 | 2479 | 	return qla2x00_post_work(vha, e, 1); | 
 | 2480 | } | 
 | 2481 |  | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2482 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2483 | qla2x00_do_work(struct scsi_qla_host *vha) | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2484 | { | 
 | 2485 | 	struct qla_work_evt *e; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2486 | 	struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2487 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2488 | 	spin_lock_irq(&ha->hardware_lock); | 
 | 2489 | 	while (!list_empty(&vha->work_list)) { | 
 | 2490 | 		e = list_entry(vha->work_list.next, struct qla_work_evt, list); | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2491 | 		list_del_init(&e->list); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2492 | 		spin_unlock_irq(&ha->hardware_lock); | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2493 |  | 
 | 2494 | 		switch (e->type) { | 
 | 2495 | 		case QLA_EVT_AEN: | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2496 | 			fc_host_post_event(vha->host, fc_get_event_number(), | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2497 | 			    e->u.aen.code, e->u.aen.data); | 
 | 2498 | 			break; | 
| Andrew Vasquez | 8a65957 | 2009-02-08 20:50:12 -0800 | [diff] [blame] | 2499 | 		case QLA_EVT_IDC_ACK: | 
 | 2500 | 			qla81xx_idc_ack(vha, e->u.idc_ack.mb); | 
 | 2501 | 			break; | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2502 | 		} | 
 | 2503 | 		if (e->flags & QLA_EVT_FLAG_FREE) | 
 | 2504 | 			kfree(e); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2505 | 		spin_lock_irq(&ha->hardware_lock); | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2506 | 	} | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2507 | 	spin_unlock_irq(&ha->hardware_lock); | 
 | 2508 | } | 
 | 2509 | /* Relogins all the fcports of a vport | 
 | 2510 |  * Context: dpc thread | 
 | 2511 |  */ | 
 | 2512 | void qla2x00_relogin(struct scsi_qla_host *vha) | 
 | 2513 | { | 
 | 2514 | 	fc_port_t       *fcport; | 
| Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 2515 | 	int status; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2516 | 	uint16_t        next_loopid = 0; | 
 | 2517 | 	struct qla_hw_data *ha = vha->hw; | 
 | 2518 |  | 
 | 2519 | 	list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
 | 2520 | 	/* | 
 | 2521 | 	 * If the port is not ONLINE then try to login | 
 | 2522 | 	 * to it if we haven't run out of retries. | 
 | 2523 | 	 */ | 
 | 2524 | 		if (atomic_read(&fcport->state) != | 
 | 2525 | 			FCS_ONLINE && fcport->login_retry) { | 
 | 2526 |  | 
 | 2527 | 			if (fcport->flags & FCF_FABRIC_DEVICE) { | 
 | 2528 | 				if (fcport->flags & FCF_TAPE_PRESENT) | 
 | 2529 | 					ha->isp_ops->fabric_logout(vha, | 
 | 2530 | 							fcport->loop_id, | 
 | 2531 | 							fcport->d_id.b.domain, | 
 | 2532 | 							fcport->d_id.b.area, | 
 | 2533 | 							fcport->d_id.b.al_pa); | 
 | 2534 |  | 
 | 2535 | 				status = qla2x00_fabric_login(vha, fcport, | 
 | 2536 | 							&next_loopid); | 
 | 2537 | 			} else | 
 | 2538 | 				status = qla2x00_local_device_login(vha, | 
 | 2539 | 								fcport); | 
 | 2540 |  | 
 | 2541 | 			fcport->login_retry--; | 
 | 2542 | 			if (status == QLA_SUCCESS) { | 
 | 2543 | 				fcport->old_loop_id = fcport->loop_id; | 
 | 2544 |  | 
 | 2545 | 				DEBUG(printk("scsi(%ld): port login OK: logged " | 
 | 2546 | 				"in ID 0x%x\n", vha->host_no, fcport->loop_id)); | 
 | 2547 |  | 
 | 2548 | 				qla2x00_update_fcport(vha, fcport); | 
 | 2549 |  | 
 | 2550 | 			} else if (status == 1) { | 
 | 2551 | 				set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | 
 | 2552 | 				/* retry the login again */ | 
 | 2553 | 				DEBUG(printk("scsi(%ld): Retrying" | 
 | 2554 | 				" %d login again loop_id 0x%x\n", | 
 | 2555 | 				vha->host_no, fcport->login_retry, | 
 | 2556 | 						fcport->loop_id)); | 
 | 2557 | 			} else { | 
 | 2558 | 				fcport->login_retry = 0; | 
 | 2559 | 			} | 
 | 2560 |  | 
 | 2561 | 			if (fcport->login_retry == 0 && status != QLA_SUCCESS) | 
 | 2562 | 				fcport->loop_id = FC_NO_LOOP_ID; | 
 | 2563 | 		} | 
 | 2564 | 		if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) | 
 | 2565 | 			break; | 
 | 2566 | 	} | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2567 | } | 
 | 2568 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | /************************************************************************** | 
 | 2570 | * qla2x00_do_dpc | 
 | 2571 | *   This kernel thread is a task that is schedule by the interrupt handler | 
 | 2572 | *   to perform the background processing for interrupts. | 
 | 2573 | * | 
 | 2574 | * Notes: | 
 | 2575 | * This task always run in the context of a kernel thread.  It | 
 | 2576 | * is kick-off by the driver's detect code and starts up | 
 | 2577 | * up one per adapter. It immediately goes to sleep and waits for | 
 | 2578 | * some fibre event.  When either the interrupt handler or | 
 | 2579 | * the timer routine detects a event it will one of the task | 
 | 2580 | * bits then wake us up. | 
 | 2581 | **************************************************************************/ | 
 | 2582 | static int | 
 | 2583 | qla2x00_do_dpc(void *data) | 
 | 2584 | { | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2585 | 	int		rval; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2586 | 	scsi_qla_host_t *base_vha; | 
 | 2587 | 	struct qla_hw_data *ha; | 
| Seokmann Ju | 99363ef | 2008-01-31 12:33:51 -0800 | [diff] [blame] | 2588 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2589 | 	ha = (struct qla_hw_data *)data; | 
 | 2590 | 	base_vha = pci_get_drvdata(ha->pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | 	set_user_nice(current, -20); | 
 | 2593 |  | 
| Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2594 | 	while (!kthread_should_stop()) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | 		DEBUG3(printk("qla2x00: DPC handler sleeping\n")); | 
 | 2596 |  | 
| Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2597 | 		set_current_state(TASK_INTERRUPTIBLE); | 
 | 2598 | 		schedule(); | 
 | 2599 | 		__set_current_state(TASK_RUNNING); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 |  | 
 | 2601 | 		DEBUG3(printk("qla2x00: DPC handler waking up\n")); | 
 | 2602 |  | 
 | 2603 | 		/* Initialization not yet finished. Don't do anything yet. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2604 | 		if (!base_vha->flags.init_done) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | 			continue; | 
 | 2606 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2607 | 		DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 |  | 
 | 2609 | 		ha->dpc_active = 1; | 
 | 2610 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | 		if (ha->flags.mbox_busy) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | 			ha->dpc_active = 0; | 
 | 2613 | 			continue; | 
 | 2614 | 		} | 
 | 2615 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2616 | 		qla2x00_do_work(base_vha); | 
| Andrew Vasquez | 0971de7 | 2008-04-03 13:13:18 -0700 | [diff] [blame] | 2617 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2618 | 		if (test_and_clear_bit(ISP_ABORT_NEEDED, | 
 | 2619 | 						&base_vha->dpc_flags)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 |  | 
 | 2621 | 			DEBUG(printk("scsi(%ld): dpc: sched " | 
 | 2622 | 			    "qla2x00_abort_isp ha = %p\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2623 | 			    base_vha->host_no, ha)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | 			if (!(test_and_set_bit(ABORT_ISP_ACTIVE, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2625 | 			    &base_vha->dpc_flags))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2627 | 				if (qla2x00_abort_isp(base_vha)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | 					/* failed. retry later */ | 
 | 2629 | 					set_bit(ISP_ABORT_NEEDED, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2630 | 					    &base_vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | 				} | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2632 | 				clear_bit(ABORT_ISP_ACTIVE, | 
 | 2633 | 						&base_vha->dpc_flags); | 
| Seokmann Ju | 99363ef | 2008-01-31 12:33:51 -0800 | [diff] [blame] | 2634 | 			} | 
 | 2635 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | 			DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2637 | 			    base_vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | 		} | 
 | 2639 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2640 | 		if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) { | 
 | 2641 | 			qla2x00_update_fcports(base_vha); | 
 | 2642 | 			clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); | 
| Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 2643 | 		} | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2644 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2645 | 		if (test_and_clear_bit(RESET_MARKER_NEEDED, | 
 | 2646 | 							&base_vha->dpc_flags) && | 
 | 2647 | 		    (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 |  | 
 | 2649 | 			DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2650 | 			    base_vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2652 | 			qla2x00_rst_aen(base_vha); | 
 | 2653 | 			clear_bit(RESET_ACTIVE, &base_vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | 		} | 
 | 2655 |  | 
 | 2656 | 		/* Retry each device up to login retry count */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2657 | 		if ((test_and_clear_bit(RELOGIN_NEEDED, | 
 | 2658 | 						&base_vha->dpc_flags)) && | 
 | 2659 | 		    !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) && | 
 | 2660 | 		    atomic_read(&base_vha->loop_state) != LOOP_DOWN) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 |  | 
 | 2662 | 			DEBUG(printk("scsi(%ld): qla2x00_port_login()\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2663 | 					base_vha->host_no)); | 
 | 2664 | 			qla2x00_relogin(base_vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | 			DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2667 | 			    base_vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | 		} | 
 | 2669 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2670 | 		if (test_and_clear_bit(LOOP_RESYNC_NEEDED, | 
 | 2671 | 							&base_vha->dpc_flags)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 |  | 
 | 2673 | 			DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2674 | 				base_vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 |  | 
 | 2676 | 			if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2677 | 			    &base_vha->dpc_flags))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2679 | 				rval = qla2x00_loop_resync(base_vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2681 | 				clear_bit(LOOP_RESYNC_ACTIVE, | 
 | 2682 | 						&base_vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | 			} | 
 | 2684 |  | 
 | 2685 | 			DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2686 | 			    base_vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | 		} | 
 | 2688 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2689 | 		if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) && | 
 | 2690 | 		    atomic_read(&base_vha->loop_state) == LOOP_READY) { | 
 | 2691 | 			clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags); | 
 | 2692 | 			qla2xxx_flash_npiv_conf(base_vha); | 
| Andrew Vasquez | 272976c | 2008-09-11 21:22:50 -0700 | [diff] [blame] | 2693 | 		} | 
 | 2694 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | 		if (!ha->interrupts_on) | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2696 | 			ha->isp_ops->enable_intrs(ha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2698 | 		if (test_and_clear_bit(BEACON_BLINK_NEEDED, | 
 | 2699 | 					&base_vha->dpc_flags)) | 
 | 2700 | 			ha->isp_ops->beacon_blink(base_vha); | 
| andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 2701 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2702 | 		qla2x00_do_dpc_all_vps(base_vha); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2703 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | 		ha->dpc_active = 0; | 
 | 2705 | 	} /* End of while(1) */ | 
 | 2706 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2707 | 	DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 |  | 
 | 2709 | 	/* | 
 | 2710 | 	 * Make sure that nobody tries to wake us up again. | 
 | 2711 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | 	ha->dpc_active = 0; | 
 | 2713 |  | 
| Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2714 | 	return 0; | 
 | 2715 | } | 
 | 2716 |  | 
 | 2717 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2718 | qla2xxx_wake_dpc(struct scsi_qla_host *vha) | 
| Christoph Hellwig | 39a1124 | 2006-02-14 18:46:22 +0100 | [diff] [blame] | 2719 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2720 | 	struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | c795c1e | 2008-08-13 21:37:01 -0700 | [diff] [blame] | 2721 | 	struct task_struct *t = ha->dpc_thread; | 
 | 2722 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2723 | 	if (!test_bit(UNLOADING, &vha->dpc_flags) && t) | 
| Andrew Vasquez | c795c1e | 2008-08-13 21:37:01 -0700 | [diff] [blame] | 2724 | 		wake_up_process(t); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | } | 
 | 2726 |  | 
 | 2727 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | *  qla2x00_rst_aen | 
 | 2729 | *      Processes asynchronous reset. | 
 | 2730 | * | 
 | 2731 | * Input: | 
 | 2732 | *      ha  = adapter block pointer. | 
 | 2733 | */ | 
 | 2734 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2735 | qla2x00_rst_aen(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2737 | 	if (vha->flags.online && !vha->flags.reset_active && | 
 | 2738 | 	    !atomic_read(&vha->loop_down_timer) && | 
 | 2739 | 	    !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | 		do { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2741 | 			clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 |  | 
 | 2743 | 			/* | 
 | 2744 | 			 * Issue marker command only when we are going to start | 
 | 2745 | 			 * the I/O. | 
 | 2746 | 			 */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2747 | 			vha->marker_needed = 1; | 
 | 2748 | 		} while (!atomic_read(&vha->loop_down_timer) && | 
 | 2749 | 		    (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | 	} | 
 | 2751 | } | 
 | 2752 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2753 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2754 | qla2x00_sp_free_dma(srb_t *sp) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2755 | { | 
 | 2756 | 	struct scsi_cmnd *cmd = sp->cmd; | 
 | 2757 |  | 
 | 2758 | 	if (sp->flags & SRB_DMA_VALID) { | 
| FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 2759 | 		scsi_dma_unmap(cmd); | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2760 | 		sp->flags &= ~SRB_DMA_VALID; | 
 | 2761 | 	} | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2762 | 	CMD_SP(cmd) = NULL; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2763 | } | 
 | 2764 |  | 
 | 2765 | void | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2766 | qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp) | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2767 | { | 
 | 2768 | 	struct scsi_cmnd *cmd = sp->cmd; | 
 | 2769 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2770 | 	qla2x00_sp_free_dma(sp); | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2771 |  | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2772 | 	mempool_free(sp, ha->srb_mempool); | 
 | 2773 |  | 
 | 2774 | 	cmd->scsi_done(cmd); | 
 | 2775 | } | 
 | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2776 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | /************************************************************************** | 
 | 2778 | *   qla2x00_timer | 
 | 2779 | * | 
 | 2780 | * Description: | 
 | 2781 | *   One second timer | 
 | 2782 | * | 
 | 2783 | * Context: Interrupt | 
 | 2784 | ***************************************************************************/ | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2785 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2786 | qla2x00_timer(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | 	unsigned long	cpu_flags = 0; | 
 | 2789 | 	fc_port_t	*fcport; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | 	int		start_dpc = 0; | 
 | 2791 | 	int		index; | 
 | 2792 | 	srb_t		*sp; | 
 | f4f051e | 2005-04-17 15:02:26 -0500 | [diff] [blame] | 2793 | 	int		t; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2794 | 	struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2795 | 	struct req_que *req; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | 	/* | 
 | 2797 | 	 * Ports - Port down timer. | 
 | 2798 | 	 * | 
 | 2799 | 	 * Whenever, a port is in the LOST state we start decrementing its port | 
 | 2800 | 	 * down timer every second until it reaches zero. Once  it reaches zero | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2801 | 	 * the port it marked DEAD. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | 	 */ | 
 | 2803 | 	t = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2804 | 	list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | 		if (fcport->port_type != FCT_TARGET) | 
 | 2806 | 			continue; | 
 | 2807 |  | 
 | 2808 | 		if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { | 
 | 2809 |  | 
 | 2810 | 			if (atomic_read(&fcport->port_down_timer) == 0) | 
 | 2811 | 				continue; | 
 | 2812 |  | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2813 | 			if (atomic_dec_and_test(&fcport->port_down_timer) != 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | 				atomic_set(&fcport->state, FCS_DEVICE_DEAD); | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2815 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | 			DEBUG(printk("scsi(%ld): fcport-%d - port retry count: " | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2817 | 			    "%d remaining\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2818 | 			    vha->host_no, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | 			    t, atomic_read(&fcport->port_down_timer))); | 
 | 2820 | 		} | 
 | 2821 | 		t++; | 
 | 2822 | 	} /* End of for fcport  */ | 
 | 2823 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 |  | 
 | 2825 | 	/* Loop down handler. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2826 | 	if (atomic_read(&vha->loop_down_timer) > 0 && | 
 | 2827 | 	    !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) | 
 | 2828 | 		&& vha->flags.online) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2830 | 		if (atomic_read(&vha->loop_down_timer) == | 
 | 2831 | 		    vha->loop_down_abort_time) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 |  | 
 | 2833 | 			DEBUG(printk("scsi(%ld): Loop Down - aborting the " | 
 | 2834 | 			    "queues before time expire\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2835 | 			    vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2837 | 			if (!IS_QLA2100(ha) && vha->link_down_timeout) | 
 | 2838 | 				atomic_set(&vha->loop_state, LOOP_DEAD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 |  | 
 | 2840 | 			/* Schedule an ISP abort to return any tape commands. */ | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2841 | 			/* NPIV - scan physical port only */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2842 | 			if (!vha->vp_idx) { | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2843 | 				spin_lock_irqsave(&ha->hardware_lock, | 
 | 2844 | 				    cpu_flags); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2845 | 				req = ha->req_q_map[0]; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2846 | 				for (index = 1; | 
 | 2847 | 				    index < MAX_OUTSTANDING_COMMANDS; | 
 | 2848 | 				    index++) { | 
 | 2849 | 					fc_port_t *sfcp; | 
 | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2850 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2851 | 					sp = req->outstanding_cmds[index]; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2852 | 					if (!sp) | 
 | 2853 | 						continue; | 
 | 2854 | 					sfcp = sp->fcport; | 
 | 2855 | 					if (!(sfcp->flags & FCF_TAPE_PRESENT)) | 
 | 2856 | 						continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 |  | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2858 | 					set_bit(ISP_ABORT_NEEDED, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2859 | 							&vha->dpc_flags); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2860 | 					break; | 
 | 2861 | 				} | 
 | 2862 | 				spin_unlock_irqrestore(&ha->hardware_lock, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2863 | 								cpu_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | 			start_dpc++; | 
 | 2866 | 		} | 
 | 2867 |  | 
 | 2868 | 		/* if the loop has been down for 4 minutes, reinit adapter */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2869 | 		if (atomic_dec_and_test(&vha->loop_down_timer) != 0) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2870 | 			if (!(vha->device_flags & DFLG_NO_CABLE) && | 
 | 2871 | 			    !vha->vp_idx) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | 				DEBUG(printk("scsi(%ld): Loop down - " | 
 | 2873 | 				    "aborting ISP.\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2874 | 				    vha->host_no)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | 				qla_printk(KERN_WARNING, ha, | 
 | 2876 | 				    "Loop down - aborting ISP.\n"); | 
 | 2877 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2878 | 				set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | 			} | 
 | 2880 | 		} | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 2881 | 		DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2882 | 		    vha->host_no, | 
 | 2883 | 		    atomic_read(&vha->loop_down_timer))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | 	} | 
 | 2885 |  | 
| andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 2886 | 	/* Check if beacon LED needs to be blinked */ | 
 | 2887 | 	if (ha->beacon_blink_led == 1) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2888 | 		set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags); | 
| andrew.vasquez@qlogic.com | f6df144 | 2006-01-31 16:05:07 -0800 | [diff] [blame] | 2889 | 		start_dpc++; | 
 | 2890 | 	} | 
 | 2891 |  | 
| Andrew Vasquez | 550bf57 | 2008-04-24 15:21:23 -0700 | [diff] [blame] | 2892 | 	/* Process any deferred work. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2893 | 	if (!list_empty(&vha->work_list)) | 
| Andrew Vasquez | 550bf57 | 2008-04-24 15:21:23 -0700 | [diff] [blame] | 2894 | 		start_dpc++; | 
 | 2895 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | 	/* Schedule the DPC routine if needed */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2897 | 	if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || | 
 | 2898 | 	    test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) || | 
 | 2899 | 	    test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | 	    start_dpc || | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2901 | 	    test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) || | 
 | 2902 | 	    test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) || | 
 | 2903 | 	    test_bit(VP_DPC_NEEDED, &vha->dpc_flags) || | 
 | 2904 | 	    test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) | 
 | 2905 | 		qla2xxx_wake_dpc(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2907 | 	qla2x00_restart_timer(vha, WATCH_INTERVAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | } | 
 | 2909 |  | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2910 | /* Firmware interface routines. */ | 
 | 2911 |  | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2912 | #define FW_BLOBS	7 | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2913 | #define FW_ISP21XX	0 | 
 | 2914 | #define FW_ISP22XX	1 | 
 | 2915 | #define FW_ISP2300	2 | 
 | 2916 | #define FW_ISP2322	3 | 
| andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2917 | #define FW_ISP24XX	4 | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2918 | #define FW_ISP25XX	5 | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2919 | #define FW_ISP81XX	6 | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2920 |  | 
| Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 2921 | #define FW_FILE_ISP21XX	"ql2100_fw.bin" | 
 | 2922 | #define FW_FILE_ISP22XX	"ql2200_fw.bin" | 
 | 2923 | #define FW_FILE_ISP2300	"ql2300_fw.bin" | 
 | 2924 | #define FW_FILE_ISP2322	"ql2322_fw.bin" | 
 | 2925 | #define FW_FILE_ISP24XX	"ql2400_fw.bin" | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2926 | #define FW_FILE_ISP25XX	"ql2500_fw.bin" | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2927 | #define FW_FILE_ISP81XX	"ql8100_fw.bin" | 
| Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 2928 |  | 
| Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 2929 | static DEFINE_MUTEX(qla_fw_lock); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2930 |  | 
 | 2931 | static struct fw_blob qla_fw_blobs[FW_BLOBS] = { | 
| Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 2932 | 	{ .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, }, | 
 | 2933 | 	{ .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, }, | 
 | 2934 | 	{ .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, }, | 
 | 2935 | 	{ .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, }, | 
 | 2936 | 	{ .name = FW_FILE_ISP24XX, }, | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2937 | 	{ .name = FW_FILE_ISP25XX, }, | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2938 | 	{ .name = FW_FILE_ISP81XX, }, | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2939 | }; | 
 | 2940 |  | 
 | 2941 | struct fw_blob * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2942 | qla2x00_request_firmware(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2943 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2944 | 	struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2945 | 	struct fw_blob *blob; | 
 | 2946 |  | 
 | 2947 | 	blob = NULL; | 
 | 2948 | 	if (IS_QLA2100(ha)) { | 
 | 2949 | 		blob = &qla_fw_blobs[FW_ISP21XX]; | 
 | 2950 | 	} else if (IS_QLA2200(ha)) { | 
 | 2951 | 		blob = &qla_fw_blobs[FW_ISP22XX]; | 
| andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2952 | 	} else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2953 | 		blob = &qla_fw_blobs[FW_ISP2300]; | 
| andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2954 | 	} else if (IS_QLA2322(ha) || IS_QLA6322(ha)) { | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2955 | 		blob = &qla_fw_blobs[FW_ISP2322]; | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2956 | 	} else if (IS_QLA24XX_TYPE(ha)) { | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2957 | 		blob = &qla_fw_blobs[FW_ISP24XX]; | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2958 | 	} else if (IS_QLA25XX(ha)) { | 
 | 2959 | 		blob = &qla_fw_blobs[FW_ISP25XX]; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2960 | 	} else if (IS_QLA81XX(ha)) { | 
 | 2961 | 		blob = &qla_fw_blobs[FW_ISP81XX]; | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2962 | 	} | 
 | 2963 |  | 
| Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 2964 | 	mutex_lock(&qla_fw_lock); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2965 | 	if (blob->fw) | 
 | 2966 | 		goto out; | 
 | 2967 |  | 
 | 2968 | 	if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) { | 
 | 2969 | 		DEBUG2(printk("scsi(%ld): Failed to load firmware image " | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2970 | 		    "(%s).\n", vha->host_no, blob->name)); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2971 | 		blob->fw = NULL; | 
 | 2972 | 		blob = NULL; | 
 | 2973 | 		goto out; | 
 | 2974 | 	} | 
 | 2975 |  | 
 | 2976 | out: | 
| Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 2977 | 	mutex_unlock(&qla_fw_lock); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2978 | 	return blob; | 
 | 2979 | } | 
 | 2980 |  | 
 | 2981 | static void | 
 | 2982 | qla2x00_release_firmware(void) | 
 | 2983 | { | 
 | 2984 | 	int idx; | 
 | 2985 |  | 
| Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 2986 | 	mutex_lock(&qla_fw_lock); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2987 | 	for (idx = 0; idx < FW_BLOBS; idx++) | 
 | 2988 | 		if (qla_fw_blobs[idx].fw) | 
 | 2989 | 			release_firmware(qla_fw_blobs[idx].fw); | 
| Daniel Walker | e1e82b6 | 2008-05-12 22:21:10 -0700 | [diff] [blame] | 2990 | 	mutex_unlock(&qla_fw_lock); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 2991 | } | 
 | 2992 |  | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 2993 | static pci_ers_result_t | 
 | 2994 | qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | 
 | 2995 | { | 
| Seokmann Ju | b9b12f7 | 2009-03-24 09:08:18 -0700 | [diff] [blame] | 2996 | 	scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); | 
 | 2997 |  | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 2998 | 	switch (state) { | 
 | 2999 | 	case pci_channel_io_normal: | 
 | 3000 | 		return PCI_ERS_RESULT_CAN_RECOVER; | 
 | 3001 | 	case pci_channel_io_frozen: | 
 | 3002 | 		pci_disable_device(pdev); | 
 | 3003 | 		return PCI_ERS_RESULT_NEED_RESET; | 
 | 3004 | 	case pci_channel_io_perm_failure: | 
| Seokmann Ju | b9b12f7 | 2009-03-24 09:08:18 -0700 | [diff] [blame] | 3005 | 		qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16); | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3006 | 		return PCI_ERS_RESULT_DISCONNECT; | 
 | 3007 | 	} | 
 | 3008 | 	return PCI_ERS_RESULT_NEED_RESET; | 
 | 3009 | } | 
 | 3010 |  | 
 | 3011 | static pci_ers_result_t | 
 | 3012 | qla2xxx_pci_mmio_enabled(struct pci_dev *pdev) | 
 | 3013 | { | 
 | 3014 | 	int risc_paused = 0; | 
 | 3015 | 	uint32_t stat; | 
 | 3016 | 	unsigned long flags; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3017 | 	scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); | 
 | 3018 | 	struct qla_hw_data *ha = base_vha->hw; | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3019 | 	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
 | 3020 | 	struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24; | 
 | 3021 |  | 
 | 3022 | 	spin_lock_irqsave(&ha->hardware_lock, flags); | 
 | 3023 | 	if (IS_QLA2100(ha) || IS_QLA2200(ha)){ | 
 | 3024 | 		stat = RD_REG_DWORD(®->hccr); | 
 | 3025 | 		if (stat & HCCR_RISC_PAUSE) | 
 | 3026 | 			risc_paused = 1; | 
 | 3027 | 	} else if (IS_QLA23XX(ha)) { | 
 | 3028 | 		stat = RD_REG_DWORD(®->u.isp2300.host_status); | 
 | 3029 | 		if (stat & HSR_RISC_PAUSED) | 
 | 3030 | 			risc_paused = 1; | 
 | 3031 | 	} else if (IS_FWI2_CAPABLE(ha)) { | 
 | 3032 | 		stat = RD_REG_DWORD(®24->host_status); | 
 | 3033 | 		if (stat & HSRX_RISC_PAUSED) | 
 | 3034 | 			risc_paused = 1; | 
 | 3035 | 	} | 
 | 3036 | 	spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
 | 3037 |  | 
 | 3038 | 	if (risc_paused) { | 
 | 3039 | 		qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, " | 
 | 3040 | 		    "Dumping firmware!\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3041 | 		ha->isp_ops->fw_dump(base_vha, 0); | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3042 |  | 
 | 3043 | 		return PCI_ERS_RESULT_NEED_RESET; | 
 | 3044 | 	} else | 
 | 3045 | 		return PCI_ERS_RESULT_RECOVERED; | 
 | 3046 | } | 
 | 3047 |  | 
 | 3048 | static pci_ers_result_t | 
 | 3049 | qla2xxx_pci_slot_reset(struct pci_dev *pdev) | 
 | 3050 | { | 
 | 3051 | 	pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3052 | 	scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); | 
 | 3053 | 	struct qla_hw_data *ha = base_vha->hw; | 
| Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 3054 | 	int rc; | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3055 |  | 
| Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 3056 | 	if (ha->mem_only) | 
 | 3057 | 		rc = pci_enable_device_mem(pdev); | 
 | 3058 | 	else | 
 | 3059 | 		rc = pci_enable_device(pdev); | 
 | 3060 |  | 
 | 3061 | 	if (rc) { | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3062 | 		qla_printk(KERN_WARNING, ha, | 
 | 3063 | 		    "Can't re-enable PCI device after reset.\n"); | 
 | 3064 |  | 
 | 3065 | 		return ret; | 
 | 3066 | 	} | 
 | 3067 | 	pci_set_master(pdev); | 
 | 3068 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3069 | 	if (ha->isp_ops->pci_config(base_vha)) | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3070 | 		return ret; | 
 | 3071 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3072 | 	set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | 
 | 3073 | 	if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS) | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3074 | 		ret =  PCI_ERS_RESULT_RECOVERED; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3075 | 	clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3076 |  | 
 | 3077 | 	return ret; | 
 | 3078 | } | 
 | 3079 |  | 
 | 3080 | static void | 
 | 3081 | qla2xxx_pci_resume(struct pci_dev *pdev) | 
 | 3082 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3083 | 	scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); | 
 | 3084 | 	struct qla_hw_data *ha = base_vha->hw; | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3085 | 	int ret; | 
 | 3086 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3087 | 	ret = qla2x00_wait_for_hba_online(base_vha); | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3088 | 	if (ret != QLA_SUCCESS) { | 
 | 3089 | 		qla_printk(KERN_ERR, ha, | 
 | 3090 | 		    "the device failed to resume I/O " | 
 | 3091 | 		    "from slot/link_reset"); | 
 | 3092 | 	} | 
 | 3093 | 	pci_cleanup_aer_uncorrect_error_status(pdev); | 
 | 3094 | } | 
 | 3095 |  | 
 | 3096 | static struct pci_error_handlers qla2xxx_err_handler = { | 
 | 3097 | 	.error_detected = qla2xxx_pci_error_detected, | 
 | 3098 | 	.mmio_enabled = qla2xxx_pci_mmio_enabled, | 
 | 3099 | 	.slot_reset = qla2xxx_pci_slot_reset, | 
 | 3100 | 	.resume = qla2xxx_pci_resume, | 
 | 3101 | }; | 
 | 3102 |  | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3103 | static struct pci_device_id qla2xxx_pci_tbl[] = { | 
| Andrew Vasquez | 47f5e06 | 2006-05-17 15:09:39 -0700 | [diff] [blame] | 3104 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) }, | 
 | 3105 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) }, | 
 | 3106 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) }, | 
 | 3107 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) }, | 
 | 3108 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) }, | 
 | 3109 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) }, | 
 | 3110 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) }, | 
 | 3111 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) }, | 
 | 3112 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) }, | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3113 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) }, | 
| Andrew Vasquez | 47f5e06 | 2006-05-17 15:09:39 -0700 | [diff] [blame] | 3114 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) }, | 
 | 3115 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) }, | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 3116 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) }, | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 3117 | 	{ PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) }, | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3118 | 	{ 0 }, | 
 | 3119 | }; | 
 | 3120 | MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl); | 
 | 3121 |  | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 3122 | static struct pci_driver qla2xxx_pci_driver = { | 
| Andrew Vasquez | cb63067 | 2006-05-17 15:09:45 -0700 | [diff] [blame] | 3123 | 	.name		= QLA2XXX_DRIVER_NAME, | 
| James Bottomley | 0a21ef1 | 2005-12-01 12:51:50 -0600 | [diff] [blame] | 3124 | 	.driver		= { | 
 | 3125 | 		.owner		= THIS_MODULE, | 
 | 3126 | 	}, | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 3127 | 	.id_table	= qla2xxx_pci_tbl, | 
| Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 3128 | 	.probe		= qla2x00_probe_one, | 
| Adrian Bunk | 4c993f7 | 2008-01-14 00:55:16 -0800 | [diff] [blame] | 3129 | 	.remove		= qla2x00_remove_one, | 
| Seokmann Ju | 14e660e | 2007-09-20 14:07:36 -0700 | [diff] [blame] | 3130 | 	.err_handler	= &qla2xxx_err_handler, | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 3131 | }; | 
 | 3132 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | /** | 
 | 3134 |  * qla2x00_module_init - Module initialization. | 
 | 3135 |  **/ | 
 | 3136 | static int __init | 
 | 3137 | qla2x00_module_init(void) | 
 | 3138 | { | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 3139 | 	int ret = 0; | 
 | 3140 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | 	/* Allocate cache for SRBs. */ | 
| Andrew Vasquez  | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 3142 | 	srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0, | 
| Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 3143 | 	    SLAB_HWCACHE_ALIGN, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | 	if (srb_cachep == NULL) { | 
 | 3145 | 		printk(KERN_ERR | 
 | 3146 | 		    "qla2xxx: Unable to allocate SRB cache...Failing load!\n"); | 
 | 3147 | 		return -ENOMEM; | 
 | 3148 | 	} | 
 | 3149 |  | 
 | 3150 | 	/* Derive version string. */ | 
 | 3151 | 	strcpy(qla2x00_version_str, QLA2XXX_VERSION); | 
| Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 3152 | 	if (ql2xextended_error_logging) | 
| Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 3153 | 		strcat(qla2x00_version_str, "-debug"); | 
 | 3154 |  | 
| Andrew Vasquez | 1c97a12 | 2005-04-21 16:13:36 -0400 | [diff] [blame] | 3155 | 	qla2xxx_transport_template = | 
 | 3156 | 	    fc_attach_transport(&qla2xxx_transport_functions); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3157 | 	if (!qla2xxx_transport_template) { | 
 | 3158 | 		kmem_cache_destroy(srb_cachep); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | 		return -ENODEV; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3160 | 	} | 
 | 3161 | 	qla2xxx_transport_vport_template = | 
 | 3162 | 	    fc_attach_transport(&qla2xxx_transport_vport_functions); | 
 | 3163 | 	if (!qla2xxx_transport_vport_template) { | 
 | 3164 | 		kmem_cache_destroy(srb_cachep); | 
 | 3165 | 		fc_release_transport(qla2xxx_transport_template); | 
 | 3166 | 		return -ENODEV; | 
 | 3167 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 |  | 
| Andrew Vasquez | fd9a29f | 2008-05-12 22:21:08 -0700 | [diff] [blame] | 3169 | 	printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n", | 
 | 3170 | 	    qla2x00_version_str); | 
| Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 3171 | 	ret = pci_register_driver(&qla2xxx_pci_driver); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 3172 | 	if (ret) { | 
 | 3173 | 		kmem_cache_destroy(srb_cachep); | 
 | 3174 | 		fc_release_transport(qla2xxx_transport_template); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3175 | 		fc_release_transport(qla2xxx_transport_vport_template); | 
| Andrew Vasquez | fca2970 | 2005-07-06 10:31:47 -0700 | [diff] [blame] | 3176 | 	} | 
 | 3177 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | } | 
 | 3179 |  | 
 | 3180 | /** | 
 | 3181 |  * qla2x00_module_exit - Module cleanup. | 
 | 3182 |  **/ | 
 | 3183 | static void __exit | 
 | 3184 | qla2x00_module_exit(void) | 
 | 3185 | { | 
| Andrew Vasquez | 7ee6139 | 2006-06-23 16:11:22 -0700 | [diff] [blame] | 3186 | 	pci_unregister_driver(&qla2xxx_pci_driver); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3187 | 	qla2x00_release_firmware(); | 
| Andrew Vasquez  | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 3188 | 	kmem_cache_destroy(srb_cachep); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | 	fc_release_transport(qla2xxx_transport_template); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3190 | 	fc_release_transport(qla2xxx_transport_vport_template); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | } | 
 | 3192 |  | 
 | 3193 | module_init(qla2x00_module_init); | 
 | 3194 | module_exit(qla2x00_module_exit); | 
 | 3195 |  | 
 | 3196 | MODULE_AUTHOR("QLogic Corporation"); | 
 | 3197 | MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver"); | 
 | 3198 | MODULE_LICENSE("GPL"); | 
 | 3199 | MODULE_VERSION(QLA2XXX_VERSION); | 
| Andrew Vasquez | bb8ee49 | 2006-10-02 12:00:48 -0700 | [diff] [blame] | 3200 | MODULE_FIRMWARE(FW_FILE_ISP21XX); | 
 | 3201 | MODULE_FIRMWARE(FW_FILE_ISP22XX); | 
 | 3202 | MODULE_FIRMWARE(FW_FILE_ISP2300); | 
 | 3203 | MODULE_FIRMWARE(FW_FILE_ISP2322); | 
 | 3204 | MODULE_FIRMWARE(FW_FILE_ISP24XX); | 
| Andrew Vasquez | 61623fc | 2008-01-31 12:33:45 -0800 | [diff] [blame] | 3205 | MODULE_FIRMWARE(FW_FILE_ISP25XX); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 3206 | MODULE_FIRMWARE(FW_FILE_ISP81XX); |