]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fa90c54f | 2 | * QLogic Fibre Channel HBA Driver |
bd21eaf9 | 3 | * Copyright (c) 2003-2014 QLogic Corporation |
1da177e4 | 4 | * |
fa90c54f | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
1da177e4 LT |
6 | */ |
7 | #include "qla_def.h" | |
8 | ||
9 | #include <linux/moduleparam.h> | |
10 | #include <linux/vmalloc.h> | |
1da177e4 | 11 | #include <linux/delay.h> |
39a11240 | 12 | #include <linux/kthread.h> |
e1e82b6f | 13 | #include <linux/mutex.h> |
3420d36c | 14 | #include <linux/kobject.h> |
5a0e3ad6 | 15 | #include <linux/slab.h> |
5601236b | 16 | #include <linux/blk-mq-pci.h> |
585def9b QT |
17 | #include <linux/refcount.h> |
18 | ||
1da177e4 LT |
19 | #include <scsi/scsi_tcq.h> |
20 | #include <scsi/scsicam.h> | |
21 | #include <scsi/scsi_transport.h> | |
22 | #include <scsi/scsi_transport_fc.h> | |
23 | ||
2d70c103 NB |
24 | #include "qla_target.h" |
25 | ||
1da177e4 LT |
26 | /* |
27 | * Driver version | |
28 | */ | |
29 | char qla2x00_version_str[40]; | |
30 | ||
6a03b4cd HZ |
31 | static int apidev_major; |
32 | ||
1da177e4 LT |
33 | /* |
34 | * SRB allocation cache | |
35 | */ | |
d7459527 | 36 | struct kmem_cache *srb_cachep; |
1da177e4 | 37 | |
a9083016 GM |
38 | /* |
39 | * CT6 CTX allocation cache | |
40 | */ | |
41 | static struct kmem_cache *ctx_cachep; | |
3ce8866c SK |
42 | /* |
43 | * error level for logging | |
44 | */ | |
3f006ac3 | 45 | uint ql_errlev = 0x8001; |
a9083016 | 46 | |
fa492630 | 47 | static int ql2xenableclass2; |
2d70c103 NB |
48 | module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR); |
49 | MODULE_PARM_DESC(ql2xenableclass2, | |
50 | "Specify if Class 2 operations are supported from the very " | |
51 | "beginning. Default is 0 - class 2 not supported."); | |
52 | ||
8ae6d9c7 | 53 | |
1da177e4 | 54 | int ql2xlogintimeout = 20; |
f2019cb1 | 55 | module_param(ql2xlogintimeout, int, S_IRUGO); |
1da177e4 LT |
56 | MODULE_PARM_DESC(ql2xlogintimeout, |
57 | "Login timeout value in seconds."); | |
58 | ||
a7b61842 | 59 | int qlport_down_retry; |
f2019cb1 | 60 | module_param(qlport_down_retry, int, S_IRUGO); |
1da177e4 | 61 | MODULE_PARM_DESC(qlport_down_retry, |
900d9f98 | 62 | "Maximum number of command retries to a port that returns " |
1da177e4 LT |
63 | "a PORT-DOWN status."); |
64 | ||
1da177e4 LT |
65 | int ql2xplogiabsentdevice; |
66 | module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR); | |
67 | MODULE_PARM_DESC(ql2xplogiabsentdevice, | |
68 | "Option to enable PLOGI to devices that are not present after " | |
900d9f98 | 69 | "a Fabric scan. This is needed for several broken switches. " |
0d52e642 | 70 | "Default is 0 - no PLOGI. 1 - perform PLOGI."); |
1da177e4 | 71 | |
c1c7178c | 72 | int ql2xloginretrycount; |
f2019cb1 | 73 | module_param(ql2xloginretrycount, int, S_IRUGO); |
1da177e4 LT |
74 | MODULE_PARM_DESC(ql2xloginretrycount, |
75 | "Specify an alternate value for the NVRAM login retry count."); | |
76 | ||
a7a167bf | 77 | int ql2xallocfwdump = 1; |
f2019cb1 | 78 | module_param(ql2xallocfwdump, int, S_IRUGO); |
a7a167bf AV |
79 | MODULE_PARM_DESC(ql2xallocfwdump, |
80 | "Option to enable allocation of memory for a firmware dump " | |
81 | "during HBA initialization. Memory allocation requirements " | |
82 | "vary by ISP type. Default is 1 - allocate memory."); | |
83 | ||
11010fec | 84 | int ql2xextended_error_logging; |
27d94035 | 85 | module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR); |
a2b3e01d | 86 | module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR); |
11010fec | 87 | MODULE_PARM_DESC(ql2xextended_error_logging, |
3ce8866c SK |
88 | "Option to enable extended error logging,\n" |
89 | "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n" | |
90 | "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n" | |
91 | "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n" | |
92 | "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n" | |
93 | "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n" | |
94 | "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n" | |
95 | "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n" | |
96 | "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n" | |
29f9f90c CD |
97 | "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n" |
98 | "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n" | |
3ce8866c | 99 | "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n" |
cfb0919c CD |
100 | "\t\t0x1e400000 - Preferred value for capturing essential " |
101 | "debug information (equivalent to old " | |
102 | "ql2xextended_error_logging=1).\n" | |
3ce8866c | 103 | "\t\tDo LOGICAL OR of the value to enable more than one level"); |
0181944f | 104 | |
a9083016 | 105 | int ql2xshiftctondsd = 6; |
f2019cb1 | 106 | module_param(ql2xshiftctondsd, int, S_IRUGO); |
a9083016 GM |
107 | MODULE_PARM_DESC(ql2xshiftctondsd, |
108 | "Set to control shifting of command type processing " | |
109 | "based on total number of SG elements."); | |
110 | ||
58e2753c | 111 | int ql2xfdmienable = 1; |
de187df8 | 112 | module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR); |
a2b3e01d | 113 | module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR); |
cca5335c | 114 | MODULE_PARM_DESC(ql2xfdmienable, |
7794a5af FW |
115 | "Enables FDMI registrations. " |
116 | "0 - no FDMI. Default is 1 - perform FDMI."); | |
cca5335c | 117 | |
d213a4b7 | 118 | #define MAX_Q_DEPTH 64 |
50280c01 | 119 | static int ql2xmaxqdepth = MAX_Q_DEPTH; |
df7baa50 AV |
120 | module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR); |
121 | MODULE_PARM_DESC(ql2xmaxqdepth, | |
e92e4a8f | 122 | "Maximum queue depth to set for each LUN. " |
d213a4b7 | 123 | "Default is 64."); |
df7baa50 | 124 | |
e84067d7 DG |
125 | #if (IS_ENABLED(CONFIG_NVME_FC)) |
126 | int ql2xenabledif; | |
127 | #else | |
9e522cd8 | 128 | int ql2xenabledif = 2; |
e84067d7 | 129 | #endif |
9e522cd8 | 130 | module_param(ql2xenabledif, int, S_IRUGO); |
bad75002 | 131 | MODULE_PARM_DESC(ql2xenabledif, |
b97f5d0b SM |
132 | " Enable T10-CRC-DIF:\n" |
133 | " Default is 2.\n" | |
134 | " 0 -- No DIF Support\n" | |
135 | " 1 -- Enable DIF for all types\n" | |
136 | " 2 -- Enable DIF for all types, except Type 0.\n"); | |
bad75002 | 137 | |
e84067d7 DG |
138 | #if (IS_ENABLED(CONFIG_NVME_FC)) |
139 | int ql2xnvmeenable = 1; | |
140 | #else | |
141 | int ql2xnvmeenable; | |
142 | #endif | |
143 | module_param(ql2xnvmeenable, int, 0644); | |
144 | MODULE_PARM_DESC(ql2xnvmeenable, | |
145 | "Enables NVME support. " | |
146 | "0 - no NVMe. Default is Y"); | |
147 | ||
8cb2049c | 148 | int ql2xenablehba_err_chk = 2; |
bad75002 AE |
149 | module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR); |
150 | MODULE_PARM_DESC(ql2xenablehba_err_chk, | |
8cb2049c | 151 | " Enable T10-CRC-DIF Error isolation by HBA:\n" |
b97f5d0b | 152 | " Default is 2.\n" |
8cb2049c AE |
153 | " 0 -- Error isolation disabled\n" |
154 | " 1 -- Error isolation enabled only for DIX Type 0\n" | |
155 | " 2 -- Error isolation enabled for all Types\n"); | |
bad75002 | 156 | |
58e2753c | 157 | int ql2xiidmaenable = 1; |
f2019cb1 | 158 | module_param(ql2xiidmaenable, int, S_IRUGO); |
e5896bd5 AV |
159 | MODULE_PARM_DESC(ql2xiidmaenable, |
160 | "Enables iIDMA settings " | |
161 | "Default is 1 - perform iIDMA. 0 - no iIDMA."); | |
162 | ||
d7459527 MH |
163 | int ql2xmqsupport = 1; |
164 | module_param(ql2xmqsupport, int, S_IRUGO); | |
165 | MODULE_PARM_DESC(ql2xmqsupport, | |
166 | "Enable on demand multiple queue pairs support " | |
167 | "Default is 1 for supported. " | |
168 | "Set it to 0 to turn off mq qpair support."); | |
e337d907 AV |
169 | |
170 | int ql2xfwloadbin; | |
86e45bf6 | 171 | module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR); |
a2b3e01d | 172 | module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR); |
e337d907 | 173 | MODULE_PARM_DESC(ql2xfwloadbin, |
7c3df132 SK |
174 | "Option to specify location from which to load ISP firmware:.\n" |
175 | " 2 -- load firmware via the request_firmware() (hotplug).\n" | |
e337d907 AV |
176 | " interface.\n" |
177 | " 1 -- load firmware from flash.\n" | |
178 | " 0 -- use default semantics.\n"); | |
179 | ||
ae97c91e | 180 | int ql2xetsenable; |
f2019cb1 | 181 | module_param(ql2xetsenable, int, S_IRUGO); |
ae97c91e AV |
182 | MODULE_PARM_DESC(ql2xetsenable, |
183 | "Enables firmware ETS burst." | |
184 | "Default is 0 - skip ETS enablement."); | |
185 | ||
6907869d | 186 | int ql2xdbwr = 1; |
86e45bf6 | 187 | module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR); |
a9083016 | 188 | MODULE_PARM_DESC(ql2xdbwr, |
08de2844 GM |
189 | "Option to specify scheme for request queue posting.\n" |
190 | " 0 -- Regular doorbell.\n" | |
191 | " 1 -- CAMRAM doorbell (faster).\n"); | |
a9083016 | 192 | |
f4c496c1 | 193 | int ql2xtargetreset = 1; |
f2019cb1 | 194 | module_param(ql2xtargetreset, int, S_IRUGO); |
f4c496c1 GM |
195 | MODULE_PARM_DESC(ql2xtargetreset, |
196 | "Enable target reset." | |
197 | "Default is 1 - use hw defaults."); | |
198 | ||
4da26e16 | 199 | int ql2xgffidenable; |
f2019cb1 | 200 | module_param(ql2xgffidenable, int, S_IRUGO); |
4da26e16 CD |
201 | MODULE_PARM_DESC(ql2xgffidenable, |
202 | "Enables GFF_ID checks of port type. " | |
203 | "Default is 0 - Do not use GFF_ID information."); | |
a9083016 | 204 | |
043dc1d7 | 205 | int ql2xasynctmfenable = 1; |
f2019cb1 | 206 | module_param(ql2xasynctmfenable, int, S_IRUGO); |
3822263e MI |
207 | MODULE_PARM_DESC(ql2xasynctmfenable, |
208 | "Enables issue of TM IOCBs asynchronously via IOCB mechanism" | |
84e13c45 | 209 | "Default is 1 - Issue TM IOCBs via mailbox mechanism."); |
ed0de87c GM |
210 | |
211 | int ql2xdontresethba; | |
86e45bf6 | 212 | module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR); |
ed0de87c | 213 | MODULE_PARM_DESC(ql2xdontresethba, |
08de2844 GM |
214 | "Option to specify reset behaviour.\n" |
215 | " 0 (Default) -- Reset on failure.\n" | |
216 | " 1 -- Do not reset on failure.\n"); | |
ed0de87c | 217 | |
1abf635d HR |
218 | uint64_t ql2xmaxlun = MAX_LUNS; |
219 | module_param(ql2xmaxlun, ullong, S_IRUGO); | |
82515920 AV |
220 | MODULE_PARM_DESC(ql2xmaxlun, |
221 | "Defines the maximum LU number to register with the SCSI " | |
222 | "midlayer. Default is 65535."); | |
223 | ||
08de2844 GM |
224 | int ql2xmdcapmask = 0x1F; |
225 | module_param(ql2xmdcapmask, int, S_IRUGO); | |
226 | MODULE_PARM_DESC(ql2xmdcapmask, | |
227 | "Set the Minidump driver capture mask level. " | |
6e96fa7b | 228 | "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F."); |
08de2844 | 229 | |
3aadff35 | 230 | int ql2xmdenable = 1; |
08de2844 GM |
231 | module_param(ql2xmdenable, int, S_IRUGO); |
232 | MODULE_PARM_DESC(ql2xmdenable, | |
233 | "Enable/disable MiniDump. " | |
3aadff35 GM |
234 | "0 - MiniDump disabled. " |
235 | "1 (Default) - MiniDump enabled."); | |
08de2844 | 236 | |
c1c7178c | 237 | int ql2xexlogins; |
b0d6cabd HM |
238 | module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR); |
239 | MODULE_PARM_DESC(ql2xexlogins, | |
240 | "Number of extended Logins. " | |
241 | "0 (Default)- Disabled."); | |
242 | ||
99e1b683 QT |
243 | int ql2xexchoffld = 1024; |
244 | module_param(ql2xexchoffld, uint, 0644); | |
2f56a7f1 | 245 | MODULE_PARM_DESC(ql2xexchoffld, |
99e1b683 QT |
246 | "Number of target exchanges."); |
247 | ||
248 | int ql2xiniexchg = 1024; | |
249 | module_param(ql2xiniexchg, uint, 0644); | |
250 | MODULE_PARM_DESC(ql2xiniexchg, | |
251 | "Number of initiator exchanges."); | |
2f56a7f1 | 252 | |
c1c7178c | 253 | int ql2xfwholdabts; |
f198cafa HM |
254 | module_param(ql2xfwholdabts, int, S_IRUGO); |
255 | MODULE_PARM_DESC(ql2xfwholdabts, | |
256 | "Allow FW to hold status IOCB until ABTS rsp received. " | |
257 | "0 (Default) Do not set fw option. " | |
258 | "1 - Set fw option to hold ABTS."); | |
259 | ||
41dc529a QT |
260 | int ql2xmvasynctoatio = 1; |
261 | module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR); | |
262 | MODULE_PARM_DESC(ql2xmvasynctoatio, | |
263 | "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ" | |
264 | "0 (Default). Do not move IOCBs" | |
265 | "1 - Move IOCBs."); | |
266 | ||
e4e3a2ce QT |
267 | int ql2xautodetectsfp = 1; |
268 | module_param(ql2xautodetectsfp, int, 0444); | |
269 | MODULE_PARM_DESC(ql2xautodetectsfp, | |
270 | "Detect SFP range and set appropriate distance.\n" | |
271 | "1 (Default): Enable\n"); | |
272 | ||
e7240af5 HM |
273 | int ql2xenablemsix = 1; |
274 | module_param(ql2xenablemsix, int, 0444); | |
275 | MODULE_PARM_DESC(ql2xenablemsix, | |
276 | "Set to enable MSI or MSI-X interrupt mechanism.\n" | |
277 | " Default is 1, enable MSI-X interrupt mechanism.\n" | |
278 | " 0 -- enable traditional pin-based mechanism.\n" | |
279 | " 1 -- enable MSI-X interrupt mechanism.\n" | |
280 | " 2 -- enable MSI interrupt mechanism.\n"); | |
281 | ||
9ecf0b0d QT |
282 | int qla2xuseresexchforels; |
283 | module_param(qla2xuseresexchforels, int, 0444); | |
284 | MODULE_PARM_DESC(qla2xuseresexchforels, | |
285 | "Reserve 1/2 of emergency exchanges for ELS.\n" | |
286 | " 0 (default): disabled"); | |
287 | ||
b3ede8ea | 288 | static int ql2xprotmask; |
7855d2ba MP |
289 | module_param(ql2xprotmask, int, 0644); |
290 | MODULE_PARM_DESC(ql2xprotmask, | |
291 | "Override DIF/DIX protection capabilities mask\n" | |
292 | "Default is 0 which sets protection mask based on " | |
293 | "capabilities reported by HBA firmware.\n"); | |
294 | ||
b3ede8ea | 295 | static int ql2xprotguard; |
7855d2ba MP |
296 | module_param(ql2xprotguard, int, 0644); |
297 | MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n" | |
298 | " 0 -- Let HBA firmware decide\n" | |
299 | " 1 -- Force T10 CRC\n" | |
300 | " 2 -- Force IP checksum\n"); | |
301 | ||
50b81275 GM |
302 | int ql2xdifbundlinginternalbuffers; |
303 | module_param(ql2xdifbundlinginternalbuffers, int, 0644); | |
304 | MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers, | |
305 | "Force using internal buffers for DIF information\n" | |
306 | "0 (Default). Based on check.\n" | |
307 | "1 Force using internal buffers\n"); | |
308 | ||
1a2fbf18 | 309 | static void qla2x00_clear_drv_active(struct qla_hw_data *); |
3491255e | 310 | static void qla2x00_free_device(scsi_qla_host_t *); |
5601236b | 311 | static int qla2xxx_map_queues(struct Scsi_Host *shost); |
e84067d7 | 312 | static void qla2x00_destroy_deferred_work(struct qla_hw_data *); |
ce7e4af7 | 313 | |
45235022 | 314 | |
1da177e4 | 315 | static struct scsi_transport_template *qla2xxx_transport_template = NULL; |
2c3dfe3f | 316 | struct scsi_transport_template *qla2xxx_transport_vport_template = NULL; |
1da177e4 | 317 | |
1da177e4 LT |
318 | /* TODO Convert to inlines |
319 | * | |
320 | * Timer routines | |
321 | */ | |
1da177e4 | 322 | |
2c3dfe3f | 323 | __inline__ void |
8e5f4ba0 | 324 | qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval) |
1da177e4 | 325 | { |
8e5f4ba0 | 326 | timer_setup(&vha->timer, qla2x00_timer, 0); |
e315cd28 | 327 | vha->timer.expires = jiffies + interval * HZ; |
e315cd28 AC |
328 | add_timer(&vha->timer); |
329 | vha->timer_active = 1; | |
1da177e4 LT |
330 | } |
331 | ||
332 | static inline void | |
e315cd28 | 333 | qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval) |
1da177e4 | 334 | { |
a9083016 | 335 | /* Currently used for 82XX only. */ |
7c3df132 SK |
336 | if (vha->device_flags & DFLG_DEV_FAILED) { |
337 | ql_dbg(ql_dbg_timer, vha, 0x600d, | |
338 | "Device in a failed state, returning.\n"); | |
a9083016 | 339 | return; |
7c3df132 | 340 | } |
a9083016 | 341 | |
e315cd28 | 342 | mod_timer(&vha->timer, jiffies + interval * HZ); |
1da177e4 LT |
343 | } |
344 | ||
a824ebb3 | 345 | static __inline__ void |
e315cd28 | 346 | qla2x00_stop_timer(scsi_qla_host_t *vha) |
1da177e4 | 347 | { |
e315cd28 AC |
348 | del_timer_sync(&vha->timer); |
349 | vha->timer_active = 0; | |
1da177e4 LT |
350 | } |
351 | ||
1da177e4 LT |
352 | static int qla2x00_do_dpc(void *data); |
353 | ||
354 | static void qla2x00_rst_aen(scsi_qla_host_t *); | |
355 | ||
73208dfd AC |
356 | static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t, |
357 | struct req_que **, struct rsp_que **); | |
e30d1756 | 358 | static void qla2x00_free_fw_dump(struct qla_hw_data *); |
e315cd28 | 359 | static void qla2x00_mem_free(struct qla_hw_data *); |
d7459527 MH |
360 | int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd, |
361 | struct qla_qpair *qpair); | |
1da177e4 | 362 | |
1da177e4 | 363 | /* -------------------------------------------------------------------------- */ |
8abfa9e2 QT |
364 | static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req, |
365 | struct rsp_que *rsp) | |
366 | { | |
367 | struct qla_hw_data *ha = vha->hw; | |
bd432bb5 | 368 | |
8abfa9e2 QT |
369 | rsp->qpair = ha->base_qpair; |
370 | rsp->req = req; | |
0691094f | 371 | ha->base_qpair->hw = ha; |
8abfa9e2 QT |
372 | ha->base_qpair->req = req; |
373 | ha->base_qpair->rsp = rsp; | |
374 | ha->base_qpair->vha = vha; | |
375 | ha->base_qpair->qp_lock_ptr = &ha->hardware_lock; | |
376 | ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0; | |
377 | ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q]; | |
6a629468 | 378 | ha->base_qpair->srb_mempool = ha->srb_mempool; |
8abfa9e2 QT |
379 | INIT_LIST_HEAD(&ha->base_qpair->hints_list); |
380 | ha->base_qpair->enable_class_2 = ql2xenableclass2; | |
381 | /* init qpair to this cpu. Will adjust at run time. */ | |
86531887 | 382 | qla_cpu_update(rsp->qpair, raw_smp_processor_id()); |
8abfa9e2 QT |
383 | ha->base_qpair->pdev = ha->pdev; |
384 | ||
ecc89f25 | 385 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha)) |
8abfa9e2 QT |
386 | ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs; |
387 | } | |
388 | ||
9a347ff4 CD |
389 | static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req, |
390 | struct rsp_que *rsp) | |
73208dfd | 391 | { |
7c3df132 | 392 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
bd432bb5 | 393 | |
6396bb22 | 394 | ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *), |
73208dfd AC |
395 | GFP_KERNEL); |
396 | if (!ha->req_q_map) { | |
7c3df132 SK |
397 | ql_log(ql_log_fatal, vha, 0x003b, |
398 | "Unable to allocate memory for request queue ptrs.\n"); | |
73208dfd AC |
399 | goto fail_req_map; |
400 | } | |
401 | ||
6396bb22 | 402 | ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *), |
73208dfd AC |
403 | GFP_KERNEL); |
404 | if (!ha->rsp_q_map) { | |
7c3df132 SK |
405 | ql_log(ql_log_fatal, vha, 0x003c, |
406 | "Unable to allocate memory for response queue ptrs.\n"); | |
73208dfd AC |
407 | goto fail_rsp_map; |
408 | } | |
d7459527 | 409 | |
e326d22a QT |
410 | ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); |
411 | if (ha->base_qpair == NULL) { | |
412 | ql_log(ql_log_warn, vha, 0x00e0, | |
413 | "Failed to allocate base queue pair memory.\n"); | |
414 | goto fail_base_qpair; | |
415 | } | |
416 | ||
8abfa9e2 | 417 | qla_init_base_qpair(vha, req, rsp); |
e326d22a | 418 | |
c38d1baf | 419 | if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) { |
d7459527 MH |
420 | ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *), |
421 | GFP_KERNEL); | |
422 | if (!ha->queue_pair_map) { | |
423 | ql_log(ql_log_fatal, vha, 0x0180, | |
424 | "Unable to allocate memory for queue pair ptrs.\n"); | |
425 | goto fail_qpair_map; | |
426 | } | |
d7459527 MH |
427 | } |
428 | ||
9a347ff4 CD |
429 | /* |
430 | * Make sure we record at least the request and response queue zero in | |
431 | * case we need to free them if part of the probe fails. | |
432 | */ | |
433 | ha->rsp_q_map[0] = rsp; | |
434 | ha->req_q_map[0] = req; | |
73208dfd AC |
435 | set_bit(0, ha->rsp_qid_map); |
436 | set_bit(0, ha->req_qid_map); | |
6a2cf8d3 | 437 | return 0; |
73208dfd | 438 | |
d7459527 | 439 | fail_qpair_map: |
82de802a QT |
440 | kfree(ha->base_qpair); |
441 | ha->base_qpair = NULL; | |
442 | fail_base_qpair: | |
d7459527 MH |
443 | kfree(ha->rsp_q_map); |
444 | ha->rsp_q_map = NULL; | |
73208dfd AC |
445 | fail_rsp_map: |
446 | kfree(ha->req_q_map); | |
447 | ha->req_q_map = NULL; | |
448 | fail_req_map: | |
449 | return -ENOMEM; | |
450 | } | |
451 | ||
2afa19a9 | 452 | static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req) |
73208dfd | 453 | { |
8ae6d9c7 GM |
454 | if (IS_QLAFX00(ha)) { |
455 | if (req && req->ring_fx00) | |
456 | dma_free_coherent(&ha->pdev->dev, | |
457 | (req->length_fx00 + 1) * sizeof(request_t), | |
458 | req->ring_fx00, req->dma_fx00); | |
459 | } else if (req && req->ring) | |
73208dfd AC |
460 | dma_free_coherent(&ha->pdev->dev, |
461 | (req->length + 1) * sizeof(request_t), | |
462 | req->ring, req->dma); | |
463 | ||
6d634067 | 464 | if (req) |
8d93f550 | 465 | kfree(req->outstanding_cmds); |
6d634067 BK |
466 | |
467 | kfree(req); | |
73208dfd AC |
468 | } |
469 | ||
2afa19a9 AC |
470 | static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp) |
471 | { | |
8ae6d9c7 | 472 | if (IS_QLAFX00(ha)) { |
3f6c9be2 | 473 | if (rsp && rsp->ring_fx00) |
8ae6d9c7 GM |
474 | dma_free_coherent(&ha->pdev->dev, |
475 | (rsp->length_fx00 + 1) * sizeof(request_t), | |
476 | rsp->ring_fx00, rsp->dma_fx00); | |
477 | } else if (rsp && rsp->ring) { | |
2afa19a9 AC |
478 | dma_free_coherent(&ha->pdev->dev, |
479 | (rsp->length + 1) * sizeof(response_t), | |
480 | rsp->ring, rsp->dma); | |
8ae6d9c7 | 481 | } |
6d634067 | 482 | kfree(rsp); |
2afa19a9 AC |
483 | } |
484 | ||
73208dfd AC |
485 | static void qla2x00_free_queues(struct qla_hw_data *ha) |
486 | { | |
487 | struct req_que *req; | |
488 | struct rsp_que *rsp; | |
489 | int cnt; | |
093df737 | 490 | unsigned long flags; |
73208dfd | 491 | |
82de802a QT |
492 | if (ha->queue_pair_map) { |
493 | kfree(ha->queue_pair_map); | |
494 | ha->queue_pair_map = NULL; | |
495 | } | |
496 | if (ha->base_qpair) { | |
497 | kfree(ha->base_qpair); | |
498 | ha->base_qpair = NULL; | |
499 | } | |
500 | ||
093df737 | 501 | spin_lock_irqsave(&ha->hardware_lock, flags); |
2afa19a9 | 502 | for (cnt = 0; cnt < ha->max_req_queues; cnt++) { |
cb43285f QT |
503 | if (!test_bit(cnt, ha->req_qid_map)) |
504 | continue; | |
505 | ||
73208dfd | 506 | req = ha->req_q_map[cnt]; |
093df737 QT |
507 | clear_bit(cnt, ha->req_qid_map); |
508 | ha->req_q_map[cnt] = NULL; | |
509 | ||
510 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
2afa19a9 | 511 | qla2x00_free_req_que(ha, req); |
093df737 | 512 | spin_lock_irqsave(&ha->hardware_lock, flags); |
73208dfd | 513 | } |
093df737 QT |
514 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
515 | ||
73208dfd AC |
516 | kfree(ha->req_q_map); |
517 | ha->req_q_map = NULL; | |
2afa19a9 | 518 | |
093df737 QT |
519 | |
520 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
2afa19a9 | 521 | for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) { |
cb43285f QT |
522 | if (!test_bit(cnt, ha->rsp_qid_map)) |
523 | continue; | |
524 | ||
2afa19a9 | 525 | rsp = ha->rsp_q_map[cnt]; |
c3c42394 | 526 | clear_bit(cnt, ha->rsp_qid_map); |
093df737 QT |
527 | ha->rsp_q_map[cnt] = NULL; |
528 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
2afa19a9 | 529 | qla2x00_free_rsp_que(ha, rsp); |
093df737 | 530 | spin_lock_irqsave(&ha->hardware_lock, flags); |
2afa19a9 | 531 | } |
093df737 QT |
532 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
533 | ||
2afa19a9 AC |
534 | kfree(ha->rsp_q_map); |
535 | ha->rsp_q_map = NULL; | |
73208dfd AC |
536 | } |
537 | ||
1da177e4 | 538 | static char * |
e315cd28 | 539 | qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str) |
1da177e4 | 540 | { |
e315cd28 | 541 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
542 | static char *pci_bus_modes[] = { |
543 | "33", "66", "100", "133", | |
544 | }; | |
545 | uint16_t pci_bus; | |
546 | ||
547 | strcpy(str, "PCI"); | |
548 | pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9; | |
549 | if (pci_bus) { | |
550 | strcat(str, "-X ("); | |
551 | strcat(str, pci_bus_modes[pci_bus]); | |
552 | } else { | |
553 | pci_bus = (ha->pci_attr & BIT_8) >> 8; | |
554 | strcat(str, " ("); | |
555 | strcat(str, pci_bus_modes[pci_bus]); | |
556 | } | |
557 | strcat(str, " MHz)"); | |
558 | ||
559 | return (str); | |
560 | } | |
561 | ||
fca29703 | 562 | static char * |
e315cd28 | 563 | qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str) |
fca29703 AV |
564 | { |
565 | static char *pci_bus_modes[] = { "33", "66", "100", "133", }; | |
e315cd28 | 566 | struct qla_hw_data *ha = vha->hw; |
fca29703 | 567 | uint32_t pci_bus; |
fca29703 | 568 | |
62a276f8 | 569 | if (pci_is_pcie(ha->pdev)) { |
fca29703 | 570 | char lwstr[6]; |
62a276f8 | 571 | uint32_t lstat, lspeed, lwidth; |
fca29703 | 572 | |
62a276f8 BH |
573 | pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat); |
574 | lspeed = lstat & PCI_EXP_LNKCAP_SLS; | |
575 | lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4; | |
fca29703 AV |
576 | |
577 | strcpy(str, "PCIe ("); | |
49300af7 SK |
578 | switch (lspeed) { |
579 | case 1: | |
c87a0d8c | 580 | strcat(str, "2.5GT/s "); |
49300af7 SK |
581 | break; |
582 | case 2: | |
c87a0d8c | 583 | strcat(str, "5.0GT/s "); |
49300af7 SK |
584 | break; |
585 | case 3: | |
586 | strcat(str, "8.0GT/s "); | |
587 | break; | |
588 | default: | |
fca29703 | 589 | strcat(str, "<unknown> "); |
49300af7 SK |
590 | break; |
591 | } | |
fca29703 AV |
592 | snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth); |
593 | strcat(str, lwstr); | |
594 | ||
595 | return str; | |
596 | } | |
597 | ||
598 | strcpy(str, "PCI"); | |
599 | pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8; | |
600 | if (pci_bus == 0 || pci_bus == 8) { | |
601 | strcat(str, " ("); | |
602 | strcat(str, pci_bus_modes[pci_bus >> 3]); | |
603 | } else { | |
604 | strcat(str, "-X "); | |
605 | if (pci_bus & BIT_2) | |
606 | strcat(str, "Mode 2"); | |
607 | else | |
608 | strcat(str, "Mode 1"); | |
609 | strcat(str, " ("); | |
610 | strcat(str, pci_bus_modes[pci_bus & ~BIT_2]); | |
611 | } | |
612 | strcat(str, " MHz)"); | |
613 | ||
614 | return str; | |
615 | } | |
616 | ||
e5f82ab8 | 617 | static char * |
df57caba | 618 | qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size) |
1da177e4 LT |
619 | { |
620 | char un_str[10]; | |
e315cd28 | 621 | struct qla_hw_data *ha = vha->hw; |
fa2a1ce5 | 622 | |
df57caba HM |
623 | snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version, |
624 | ha->fw_minor_version, ha->fw_subminor_version); | |
1da177e4 LT |
625 | |
626 | if (ha->fw_attributes & BIT_9) { | |
627 | strcat(str, "FLX"); | |
628 | return (str); | |
629 | } | |
630 | ||
631 | switch (ha->fw_attributes & 0xFF) { | |
632 | case 0x7: | |
633 | strcat(str, "EF"); | |
634 | break; | |
635 | case 0x17: | |
636 | strcat(str, "TP"); | |
637 | break; | |
638 | case 0x37: | |
639 | strcat(str, "IP"); | |
640 | break; | |
641 | case 0x77: | |
642 | strcat(str, "VI"); | |
643 | break; | |
644 | default: | |
645 | sprintf(un_str, "(%x)", ha->fw_attributes); | |
646 | strcat(str, un_str); | |
647 | break; | |
648 | } | |
649 | if (ha->fw_attributes & 0x100) | |
650 | strcat(str, "X"); | |
651 | ||
652 | return (str); | |
653 | } | |
654 | ||
e5f82ab8 | 655 | static char * |
df57caba | 656 | qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size) |
fca29703 | 657 | { |
e315cd28 | 658 | struct qla_hw_data *ha = vha->hw; |
f0883ac6 | 659 | |
df57caba | 660 | snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version, |
3a03eb79 | 661 | ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes); |
fca29703 | 662 | return str; |
fca29703 AV |
663 | } |
664 | ||
9ba56b95 | 665 | void |
25ff6af1 | 666 | qla2x00_sp_free_dma(void *ptr) |
fca29703 | 667 | { |
25ff6af1 JC |
668 | srb_t *sp = ptr; |
669 | struct qla_hw_data *ha = sp->vha->hw; | |
9ba56b95 | 670 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
9ba56b95 | 671 | void *ctx = GET_CMD_CTX_SP(sp); |
fca29703 | 672 | |
9ba56b95 GM |
673 | if (sp->flags & SRB_DMA_VALID) { |
674 | scsi_dma_unmap(cmd); | |
675 | sp->flags &= ~SRB_DMA_VALID; | |
7c3df132 | 676 | } |
fca29703 | 677 | |
9ba56b95 GM |
678 | if (sp->flags & SRB_CRC_PROT_DMA_VALID) { |
679 | dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd), | |
680 | scsi_prot_sg_count(cmd), cmd->sc_data_direction); | |
681 | sp->flags &= ~SRB_CRC_PROT_DMA_VALID; | |
682 | } | |
683 | ||
d5ff0eed | 684 | if (!ctx) |
711a08d7 | 685 | return; |
d5ff0eed | 686 | |
9ba56b95 GM |
687 | if (sp->flags & SRB_CRC_CTX_DSD_VALID) { |
688 | /* List assured to be having elements */ | |
d5ff0eed | 689 | qla2x00_clean_dsd_pool(ha, ctx); |
9ba56b95 GM |
690 | sp->flags &= ~SRB_CRC_CTX_DSD_VALID; |
691 | } | |
692 | ||
693 | if (sp->flags & SRB_CRC_CTX_DMA_VALID) { | |
d5ff0eed JC |
694 | struct crc_context *ctx0 = ctx; |
695 | ||
696 | dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma); | |
9ba56b95 GM |
697 | sp->flags &= ~SRB_CRC_CTX_DMA_VALID; |
698 | } | |
699 | ||
700 | if (sp->flags & SRB_FCP_CMND_DMA_VALID) { | |
d5ff0eed | 701 | struct ct6_dsd *ctx1 = ctx; |
fca29703 | 702 | |
9ba56b95 | 703 | dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd, |
d5ff0eed | 704 | ctx1->fcp_cmnd_dma); |
9ba56b95 GM |
705 | list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list); |
706 | ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt; | |
707 | ha->gbl_dsd_avail += ctx1->dsd_use_cnt; | |
708 | mempool_free(ctx1, ha->ctx_mempool); | |
9ba56b95 | 709 | } |
9ba56b95 GM |
710 | } |
711 | ||
d7459527 | 712 | void |
25ff6af1 | 713 | qla2x00_sp_compl(void *ptr, int res) |
9ba56b95 | 714 | { |
25ff6af1 | 715 | srb_t *sp = ptr; |
9ba56b95 | 716 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
219d27d7 | 717 | struct completion *comp = sp->comp; |
9ba56b95 | 718 | |
db4bf822 | 719 | if (WARN_ON_ONCE(atomic_read(&sp->ref_count) == 0)) |
9ba56b95 | 720 | return; |
219d27d7 BVA |
721 | |
722 | atomic_dec(&sp->ref_count); | |
9ba56b95 | 723 | |
f3caa990 | 724 | sp->free(sp); |
740e2935 | 725 | cmd->result = res; |
711a08d7 | 726 | CMD_SP(cmd) = NULL; |
9ba56b95 | 727 | cmd->scsi_done(cmd); |
219d27d7 BVA |
728 | if (comp) |
729 | complete(comp); | |
711a08d7 | 730 | qla2x00_rel_sp(sp); |
fca29703 AV |
731 | } |
732 | ||
d7459527 | 733 | void |
25ff6af1 | 734 | qla2xxx_qpair_sp_free_dma(void *ptr) |
d7459527 MH |
735 | { |
736 | srb_t *sp = (srb_t *)ptr; | |
737 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); | |
738 | struct qla_hw_data *ha = sp->fcport->vha->hw; | |
739 | void *ctx = GET_CMD_CTX_SP(sp); | |
740 | ||
741 | if (sp->flags & SRB_DMA_VALID) { | |
742 | scsi_dma_unmap(cmd); | |
743 | sp->flags &= ~SRB_DMA_VALID; | |
744 | } | |
745 | ||
746 | if (sp->flags & SRB_CRC_PROT_DMA_VALID) { | |
747 | dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd), | |
748 | scsi_prot_sg_count(cmd), cmd->sc_data_direction); | |
749 | sp->flags &= ~SRB_CRC_PROT_DMA_VALID; | |
750 | } | |
751 | ||
d5ff0eed | 752 | if (!ctx) |
711a08d7 | 753 | return; |
d5ff0eed | 754 | |
d7459527 MH |
755 | if (sp->flags & SRB_CRC_CTX_DSD_VALID) { |
756 | /* List assured to be having elements */ | |
d5ff0eed | 757 | qla2x00_clean_dsd_pool(ha, ctx); |
d7459527 MH |
758 | sp->flags &= ~SRB_CRC_CTX_DSD_VALID; |
759 | } | |
760 | ||
50b81275 | 761 | if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) { |
d8f945bf | 762 | struct crc_context *difctx = ctx; |
50b81275 GM |
763 | struct dsd_dma *dif_dsd, *nxt_dsd; |
764 | ||
765 | list_for_each_entry_safe(dif_dsd, nxt_dsd, | |
766 | &difctx->ldif_dma_hndl_list, list) { | |
767 | list_del(&dif_dsd->list); | |
768 | dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr, | |
769 | dif_dsd->dsd_list_dma); | |
770 | kfree(dif_dsd); | |
771 | difctx->no_dif_bundl--; | |
772 | } | |
773 | ||
774 | list_for_each_entry_safe(dif_dsd, nxt_dsd, | |
775 | &difctx->ldif_dsd_list, list) { | |
776 | list_del(&dif_dsd->list); | |
777 | dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr, | |
778 | dif_dsd->dsd_list_dma); | |
779 | kfree(dif_dsd); | |
780 | difctx->no_ldif_dsd--; | |
781 | } | |
782 | ||
783 | if (difctx->no_ldif_dsd) { | |
784 | ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022, | |
785 | "%s: difctx->no_ldif_dsd=%x\n", | |
786 | __func__, difctx->no_ldif_dsd); | |
787 | } | |
788 | ||
789 | if (difctx->no_dif_bundl) { | |
790 | ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022, | |
791 | "%s: difctx->no_dif_bundl=%x\n", | |
792 | __func__, difctx->no_dif_bundl); | |
793 | } | |
794 | sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID; | |
d7459527 | 795 | } |
d8f945bf BVA |
796 | |
797 | if (sp->flags & SRB_FCP_CMND_DMA_VALID) { | |
798 | struct ct6_dsd *ctx1 = ctx; | |
799 | ||
800 | dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd, | |
801 | ctx1->fcp_cmnd_dma); | |
802 | list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list); | |
803 | ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt; | |
804 | ha->gbl_dsd_avail += ctx1->dsd_use_cnt; | |
805 | mempool_free(ctx1, ha->ctx_mempool); | |
806 | sp->flags &= ~SRB_FCP_CMND_DMA_VALID; | |
807 | } | |
808 | ||
809 | if (sp->flags & SRB_CRC_CTX_DMA_VALID) { | |
810 | struct crc_context *ctx0 = ctx; | |
811 | ||
812 | dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma); | |
813 | sp->flags &= ~SRB_CRC_CTX_DMA_VALID; | |
814 | } | |
d7459527 MH |
815 | } |
816 | ||
817 | void | |
25ff6af1 | 818 | qla2xxx_qpair_sp_compl(void *ptr, int res) |
d7459527 | 819 | { |
25ff6af1 | 820 | srb_t *sp = ptr; |
d7459527 | 821 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
219d27d7 | 822 | struct completion *comp = sp->comp; |
d7459527 | 823 | |
db4bf822 | 824 | if (WARN_ON_ONCE(atomic_read(&sp->ref_count) == 0)) |
d7459527 | 825 | return; |
219d27d7 BVA |
826 | |
827 | atomic_dec(&sp->ref_count); | |
d7459527 | 828 | |
f3caa990 | 829 | sp->free(sp); |
711a08d7 GM |
830 | cmd->result = res; |
831 | CMD_SP(cmd) = NULL; | |
d7459527 | 832 | cmd->scsi_done(cmd); |
219d27d7 BVA |
833 | if (comp) |
834 | complete(comp); | |
711a08d7 | 835 | qla2xxx_rel_qpair_sp(sp->qpair, sp); |
d7459527 MH |
836 | } |
837 | ||
1da177e4 | 838 | static int |
f5e3e40b | 839 | qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
fca29703 | 840 | { |
134ae078 | 841 | scsi_qla_host_t *vha = shost_priv(host); |
fca29703 | 842 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
19a7b4ae | 843 | struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); |
e315cd28 AC |
844 | struct qla_hw_data *ha = vha->hw; |
845 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
fca29703 AV |
846 | srb_t *sp; |
847 | int rval; | |
848 | ||
2dbb02fd BVA |
849 | if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) || |
850 | WARN_ON_ONCE(!rport)) { | |
04dfaa53 MFO |
851 | cmd->result = DID_NO_CONNECT << 16; |
852 | goto qc24_fail_command; | |
853 | } | |
854 | ||
5601236b | 855 | if (ha->mqenable) { |
6d58ef05 BVA |
856 | uint32_t tag; |
857 | uint16_t hwq; | |
858 | struct qla_qpair *qpair = NULL; | |
859 | ||
f664a3cc JA |
860 | tag = blk_mq_unique_tag(cmd->request); |
861 | hwq = blk_mq_unique_tag_to_hwq(tag); | |
862 | qpair = ha->queue_pair_map[hwq]; | |
5601236b MH |
863 | |
864 | if (qpair) | |
865 | return qla2xxx_mqueuecommand(host, cmd, qpair); | |
d7459527 MH |
866 | } |
867 | ||
85880801 | 868 | if (ha->flags.eeh_busy) { |
7c3df132 | 869 | if (ha->flags.pci_channel_io_perm_failure) { |
5f28d2d7 | 870 | ql_dbg(ql_dbg_aer, vha, 0x9010, |
7c3df132 SK |
871 | "PCI Channel IO permanent failure, exiting " |
872 | "cmd=%p.\n", cmd); | |
b9b12f73 | 873 | cmd->result = DID_NO_CONNECT << 16; |
7c3df132 | 874 | } else { |
5f28d2d7 | 875 | ql_dbg(ql_dbg_aer, vha, 0x9011, |
7c3df132 | 876 | "EEH_Busy, Requeuing the cmd=%p.\n", cmd); |
85880801 | 877 | cmd->result = DID_REQUEUE << 16; |
7c3df132 | 878 | } |
14e660e6 SJ |
879 | goto qc24_fail_command; |
880 | } | |
881 | ||
19a7b4ae JSEC |
882 | rval = fc_remote_port_chkready(rport); |
883 | if (rval) { | |
884 | cmd->result = rval; | |
5f28d2d7 | 885 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003, |
7c3df132 SK |
886 | "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n", |
887 | cmd, rval); | |
fca29703 AV |
888 | goto qc24_fail_command; |
889 | } | |
890 | ||
bad75002 AE |
891 | if (!vha->flags.difdix_supported && |
892 | scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { | |
7c3df132 SK |
893 | ql_dbg(ql_dbg_io, vha, 0x3004, |
894 | "DIF Cap not reg, fail DIF capable cmd's:%p.\n", | |
895 | cmd); | |
bad75002 AE |
896 | cmd->result = DID_NO_CONNECT << 16; |
897 | goto qc24_fail_command; | |
898 | } | |
aa651be8 CD |
899 | |
900 | if (!fcport) { | |
901 | cmd->result = DID_NO_CONNECT << 16; | |
902 | goto qc24_fail_command; | |
903 | } | |
904 | ||
fca29703 AV |
905 | if (atomic_read(&fcport->state) != FCS_ONLINE) { |
906 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || | |
38170fa8 | 907 | atomic_read(&base_vha->loop_state) == LOOP_DEAD) { |
7c3df132 SK |
908 | ql_dbg(ql_dbg_io, vha, 0x3005, |
909 | "Returning DNC, fcport_state=%d loop_state=%d.\n", | |
910 | atomic_read(&fcport->state), | |
911 | atomic_read(&base_vha->loop_state)); | |
fca29703 AV |
912 | cmd->result = DID_NO_CONNECT << 16; |
913 | goto qc24_fail_command; | |
914 | } | |
7b594131 | 915 | goto qc24_target_busy; |
fca29703 AV |
916 | } |
917 | ||
e05fe292 CD |
918 | /* |
919 | * Return target busy if we've received a non-zero retry_delay_timer | |
920 | * in a FCP_RSP. | |
921 | */ | |
975f7d46 BP |
922 | if (fcport->retry_delay_timestamp == 0) { |
923 | /* retry delay not set */ | |
924 | } else if (time_after(jiffies, fcport->retry_delay_timestamp)) | |
e05fe292 CD |
925 | fcport->retry_delay_timestamp = 0; |
926 | else | |
927 | goto qc24_target_busy; | |
928 | ||
b00ee7d7 | 929 | sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC); |
50280c01 | 930 | if (!sp) |
f5e3e40b | 931 | goto qc24_host_busy; |
fca29703 | 932 | |
9ba56b95 GM |
933 | sp->u.scmd.cmd = cmd; |
934 | sp->type = SRB_SCSI_CMD; | |
935 | atomic_set(&sp->ref_count, 1); | |
936 | CMD_SP(cmd) = (void *)sp; | |
937 | sp->free = qla2x00_sp_free_dma; | |
938 | sp->done = qla2x00_sp_compl; | |
939 | ||
e315cd28 | 940 | rval = ha->isp_ops->start_scsi(sp); |
7c3df132 | 941 | if (rval != QLA_SUCCESS) { |
53016ed3 | 942 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013, |
7c3df132 | 943 | "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd); |
fca29703 | 944 | goto qc24_host_busy_free_sp; |
7c3df132 | 945 | } |
fca29703 | 946 | |
fca29703 AV |
947 | return 0; |
948 | ||
949 | qc24_host_busy_free_sp: | |
f3caa990 | 950 | sp->free(sp); |
fca29703 | 951 | |
f5e3e40b | 952 | qc24_host_busy: |
fca29703 AV |
953 | return SCSI_MLQUEUE_HOST_BUSY; |
954 | ||
7b594131 MC |
955 | qc24_target_busy: |
956 | return SCSI_MLQUEUE_TARGET_BUSY; | |
957 | ||
fca29703 | 958 | qc24_fail_command: |
f5e3e40b | 959 | cmd->scsi_done(cmd); |
fca29703 AV |
960 | |
961 | return 0; | |
962 | } | |
963 | ||
d7459527 MH |
964 | /* For MQ supported I/O */ |
965 | int | |
966 | qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd, | |
967 | struct qla_qpair *qpair) | |
968 | { | |
969 | scsi_qla_host_t *vha = shost_priv(host); | |
970 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; | |
971 | struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); | |
972 | struct qla_hw_data *ha = vha->hw; | |
973 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
974 | srb_t *sp; | |
975 | int rval; | |
976 | ||
2dbb02fd | 977 | rval = rport ? fc_remote_port_chkready(rport) : FC_PORTSTATE_OFFLINE; |
d7459527 MH |
978 | if (rval) { |
979 | cmd->result = rval; | |
980 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076, | |
981 | "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n", | |
982 | cmd, rval); | |
983 | goto qc24_fail_command; | |
984 | } | |
985 | ||
986 | if (!fcport) { | |
987 | cmd->result = DID_NO_CONNECT << 16; | |
988 | goto qc24_fail_command; | |
989 | } | |
990 | ||
991 | if (atomic_read(&fcport->state) != FCS_ONLINE) { | |
992 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || | |
993 | atomic_read(&base_vha->loop_state) == LOOP_DEAD) { | |
994 | ql_dbg(ql_dbg_io, vha, 0x3077, | |
995 | "Returning DNC, fcport_state=%d loop_state=%d.\n", | |
996 | atomic_read(&fcport->state), | |
997 | atomic_read(&base_vha->loop_state)); | |
998 | cmd->result = DID_NO_CONNECT << 16; | |
999 | goto qc24_fail_command; | |
1000 | } | |
1001 | goto qc24_target_busy; | |
1002 | } | |
1003 | ||
1004 | /* | |
1005 | * Return target busy if we've received a non-zero retry_delay_timer | |
1006 | * in a FCP_RSP. | |
1007 | */ | |
1008 | if (fcport->retry_delay_timestamp == 0) { | |
1009 | /* retry delay not set */ | |
1010 | } else if (time_after(jiffies, fcport->retry_delay_timestamp)) | |
1011 | fcport->retry_delay_timestamp = 0; | |
1012 | else | |
1013 | goto qc24_target_busy; | |
1014 | ||
6a629468 | 1015 | sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC); |
d7459527 MH |
1016 | if (!sp) |
1017 | goto qc24_host_busy; | |
1018 | ||
1019 | sp->u.scmd.cmd = cmd; | |
1020 | sp->type = SRB_SCSI_CMD; | |
1021 | atomic_set(&sp->ref_count, 1); | |
1022 | CMD_SP(cmd) = (void *)sp; | |
1023 | sp->free = qla2xxx_qpair_sp_free_dma; | |
1024 | sp->done = qla2xxx_qpair_sp_compl; | |
1025 | sp->qpair = qpair; | |
1026 | ||
1027 | rval = ha->isp_ops->start_scsi_mq(sp); | |
1028 | if (rval != QLA_SUCCESS) { | |
1029 | ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078, | |
1030 | "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd); | |
1031 | if (rval == QLA_INTERFACE_ERROR) | |
1032 | goto qc24_fail_command; | |
1033 | goto qc24_host_busy_free_sp; | |
1034 | } | |
1035 | ||
1036 | return 0; | |
1037 | ||
1038 | qc24_host_busy_free_sp: | |
f3caa990 | 1039 | sp->free(sp); |
d7459527 MH |
1040 | |
1041 | qc24_host_busy: | |
1042 | return SCSI_MLQUEUE_HOST_BUSY; | |
1043 | ||
1044 | qc24_target_busy: | |
1045 | return SCSI_MLQUEUE_TARGET_BUSY; | |
1046 | ||
1047 | qc24_fail_command: | |
1048 | cmd->scsi_done(cmd); | |
1049 | ||
1050 | return 0; | |
1051 | } | |
1052 | ||
1da177e4 LT |
1053 | /* |
1054 | * qla2x00_eh_wait_on_command | |
1055 | * Waits for the command to be returned by the Firmware for some | |
1056 | * max time. | |
1057 | * | |
1058 | * Input: | |
1da177e4 | 1059 | * cmd = Scsi Command to wait on. |
1da177e4 LT |
1060 | * |
1061 | * Return: | |
1062 | * Not Found : 0 | |
1063 | * Found : 1 | |
1064 | */ | |
1065 | static int | |
e315cd28 | 1066 | qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd) |
1da177e4 | 1067 | { |
fe74c71f | 1068 | #define ABORT_POLLING_PERIOD 1000 |
478c3b03 | 1069 | #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD)) |
f4f051eb | 1070 | unsigned long wait_iter = ABORT_WAIT_ITER; |
85880801 AV |
1071 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
1072 | struct qla_hw_data *ha = vha->hw; | |
f4f051eb | 1073 | int ret = QLA_SUCCESS; |
1da177e4 | 1074 | |
85880801 | 1075 | if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) { |
7c3df132 SK |
1076 | ql_dbg(ql_dbg_taskm, vha, 0x8005, |
1077 | "Return:eh_wait.\n"); | |
85880801 AV |
1078 | return ret; |
1079 | } | |
1080 | ||
d970432c | 1081 | while (CMD_SP(cmd) && wait_iter--) { |
fe74c71f | 1082 | msleep(ABORT_POLLING_PERIOD); |
f4f051eb AV |
1083 | } |
1084 | if (CMD_SP(cmd)) | |
1085 | ret = QLA_FUNCTION_FAILED; | |
1da177e4 | 1086 | |
f4f051eb | 1087 | return ret; |
1da177e4 LT |
1088 | } |
1089 | ||
1090 | /* | |
1091 | * qla2x00_wait_for_hba_online | |
fa2a1ce5 | 1092 | * Wait till the HBA is online after going through |
1da177e4 LT |
1093 | * <= MAX_RETRIES_OF_ISP_ABORT or |
1094 | * finally HBA is disabled ie marked offline | |
1095 | * | |
1096 | * Input: | |
1097 | * ha - pointer to host adapter structure | |
fa2a1ce5 AV |
1098 | * |
1099 | * Note: | |
1da177e4 LT |
1100 | * Does context switching-Release SPIN_LOCK |
1101 | * (if any) before calling this routine. | |
1102 | * | |
1103 | * Return: | |
1104 | * Success (Adapter is online) : 0 | |
1105 | * Failed (Adapter is offline/disabled) : 1 | |
1106 | */ | |
854165f4 | 1107 | int |
e315cd28 | 1108 | qla2x00_wait_for_hba_online(scsi_qla_host_t *vha) |
1da177e4 | 1109 | { |
fca29703 AV |
1110 | int return_status; |
1111 | unsigned long wait_online; | |
e315cd28 AC |
1112 | struct qla_hw_data *ha = vha->hw; |
1113 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
1da177e4 | 1114 | |
fa2a1ce5 | 1115 | wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ); |
e315cd28 AC |
1116 | while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || |
1117 | test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || | |
1118 | test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || | |
1119 | ha->dpc_active) && time_before(jiffies, wait_online)) { | |
1da177e4 LT |
1120 | |
1121 | msleep(1000); | |
1122 | } | |
e315cd28 | 1123 | if (base_vha->flags.online) |
fa2a1ce5 | 1124 | return_status = QLA_SUCCESS; |
1da177e4 LT |
1125 | else |
1126 | return_status = QLA_FUNCTION_FAILED; | |
1127 | ||
1da177e4 LT |
1128 | return (return_status); |
1129 | } | |
1130 | ||
726b8548 QT |
1131 | static inline int test_fcport_count(scsi_qla_host_t *vha) |
1132 | { | |
1133 | struct qla_hw_data *ha = vha->hw; | |
1134 | unsigned long flags; | |
1135 | int res; | |
1136 | ||
1137 | spin_lock_irqsave(&ha->tgt.sess_lock, flags); | |
83548fe2 QT |
1138 | ql_dbg(ql_dbg_init, vha, 0x00ec, |
1139 | "tgt %p, fcport_count=%d\n", | |
1140 | vha, vha->fcport_count); | |
726b8548 QT |
1141 | res = (vha->fcport_count == 0); |
1142 | spin_unlock_irqrestore(&ha->tgt.sess_lock, flags); | |
1143 | ||
1144 | return res; | |
1145 | } | |
1146 | ||
1147 | /* | |
1148 | * qla2x00_wait_for_sess_deletion can only be called from remove_one. | |
1149 | * it has dependency on UNLOADING flag to stop device discovery | |
1150 | */ | |
efa93f48 | 1151 | void |
726b8548 QT |
1152 | qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha) |
1153 | { | |
1154 | qla2x00_mark_all_devices_lost(vha, 0); | |
1155 | ||
b85e0957 | 1156 | wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ); |
726b8548 QT |
1157 | } |
1158 | ||
86fbee86 | 1159 | /* |
638a1a01 SC |
1160 | * qla2x00_wait_for_hba_ready |
1161 | * Wait till the HBA is ready before doing driver unload | |
86fbee86 LC |
1162 | * |
1163 | * Input: | |
1164 | * ha - pointer to host adapter structure | |
1165 | * | |
1166 | * Note: | |
1167 | * Does context switching-Release SPIN_LOCK | |
1168 | * (if any) before calling this routine. | |
1169 | * | |
86fbee86 | 1170 | */ |
638a1a01 SC |
1171 | static void |
1172 | qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha) | |
86fbee86 | 1173 | { |
86fbee86 | 1174 | struct qla_hw_data *ha = vha->hw; |
783e0dc4 | 1175 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
86fbee86 | 1176 | |
1d483901 DC |
1177 | while ((qla2x00_reset_active(vha) || ha->dpc_active || |
1178 | ha->flags.mbox_busy) || | |
1179 | test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) || | |
1180 | test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) { | |
1181 | if (test_bit(UNLOADING, &base_vha->dpc_flags)) | |
1182 | break; | |
86fbee86 | 1183 | msleep(1000); |
783e0dc4 | 1184 | } |
86fbee86 LC |
1185 | } |
1186 | ||
2533cf67 LC |
1187 | int |
1188 | qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha) | |
1189 | { | |
1190 | int return_status; | |
1191 | unsigned long wait_reset; | |
1192 | struct qla_hw_data *ha = vha->hw; | |
1193 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
1194 | ||
1195 | wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ); | |
1196 | while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) || | |
1197 | test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) || | |
1198 | test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) || | |
1199 | ha->dpc_active) && time_before(jiffies, wait_reset)) { | |
1200 | ||
1201 | msleep(1000); | |
1202 | ||
1203 | if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) && | |
1204 | ha->flags.chip_reset_done) | |
1205 | break; | |
1206 | } | |
1207 | if (ha->flags.chip_reset_done) | |
1208 | return_status = QLA_SUCCESS; | |
1209 | else | |
1210 | return_status = QLA_FUNCTION_FAILED; | |
1211 | ||
1212 | return return_status; | |
1213 | } | |
1214 | ||
585def9b | 1215 | static int |
083a469d GM |
1216 | sp_get(struct srb *sp) |
1217 | { | |
845bbb09 | 1218 | if (!refcount_inc_not_zero((refcount_t *)&sp->ref_count)) |
585def9b QT |
1219 | /* kref get fail */ |
1220 | return ENXIO; | |
1221 | else | |
1222 | return 0; | |
083a469d GM |
1223 | } |
1224 | ||
a465537a SC |
1225 | #define ISP_REG_DISCONNECT 0xffffffffU |
1226 | /************************************************************************** | |
1227 | * qla2x00_isp_reg_stat | |
1228 | * | |
1229 | * Description: | |
1230 | * Read the host status register of ISP before aborting the command. | |
1231 | * | |
1232 | * Input: | |
1233 | * ha = pointer to host adapter structure. | |
1234 | * | |
1235 | * | |
1236 | * Returns: | |
1237 | * Either true or false. | |
1238 | * | |
1239 | * Note: Return true if there is register disconnect. | |
1240 | **************************************************************************/ | |
1241 | static inline | |
1242 | uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha) | |
1243 | { | |
1244 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | |
bf6061b1 | 1245 | struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82; |
a465537a | 1246 | |
bf6061b1 SC |
1247 | if (IS_P3P_TYPE(ha)) |
1248 | return ((RD_REG_DWORD(®82->host_int)) == ISP_REG_DISCONNECT); | |
1249 | else | |
1250 | return ((RD_REG_DWORD(®->host_status)) == | |
1251 | ISP_REG_DISCONNECT); | |
a465537a SC |
1252 | } |
1253 | ||
1da177e4 LT |
1254 | /************************************************************************** |
1255 | * qla2xxx_eh_abort | |
1256 | * | |
1257 | * Description: | |
1258 | * The abort function will abort the specified command. | |
1259 | * | |
1260 | * Input: | |
1261 | * cmd = Linux SCSI command packet to be aborted. | |
1262 | * | |
1263 | * Returns: | |
1264 | * Either SUCCESS or FAILED. | |
1265 | * | |
1266 | * Note: | |
2ea00202 | 1267 | * Only return FAILED if command not returned by firmware. |
1da177e4 | 1268 | **************************************************************************/ |
e5f82ab8 | 1269 | static int |
1da177e4 LT |
1270 | qla2xxx_eh_abort(struct scsi_cmnd *cmd) |
1271 | { | |
e315cd28 | 1272 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
8dd9593c | 1273 | DECLARE_COMPLETION_ONSTACK(comp); |
f4f051eb | 1274 | srb_t *sp; |
4e98d3b8 | 1275 | int ret; |
9cb78c16 HR |
1276 | unsigned int id; |
1277 | uint64_t lun; | |
18e144d3 | 1278 | unsigned long flags; |
219d27d7 | 1279 | int rval; |
e315cd28 | 1280 | struct qla_hw_data *ha = vha->hw; |
585def9b | 1281 | struct qla_qpair *qpair; |
1da177e4 | 1282 | |
a465537a SC |
1283 | if (qla2x00_isp_reg_stat(ha)) { |
1284 | ql_log(ql_log_info, vha, 0x8042, | |
1285 | "PCI/Register disconnect, exiting.\n"); | |
1286 | return FAILED; | |
1287 | } | |
1da177e4 | 1288 | |
4e98d3b8 AV |
1289 | ret = fc_block_scsi_eh(cmd); |
1290 | if (ret != 0) | |
1291 | return ret; | |
4e98d3b8 | 1292 | |
170babc3 | 1293 | sp = (srb_t *) CMD_SP(cmd); |
585def9b QT |
1294 | if (!sp) |
1295 | return SUCCESS; | |
1296 | ||
1297 | qpair = sp->qpair; | |
1298 | if (!qpair) | |
1299 | return SUCCESS; | |
1300 | ||
7f4374e6 QT |
1301 | if (sp->fcport && sp->fcport->deleted) |
1302 | return SUCCESS; | |
1303 | ||
585def9b | 1304 | spin_lock_irqsave(qpair->qp_lock_ptr, flags); |
219d27d7 | 1305 | if (sp->type != SRB_SCSI_CMD || GET_CMD_SP(sp) != cmd) { |
585def9b QT |
1306 | /* there's a chance an interrupt could clear |
1307 | the ptr as part of done & free */ | |
1308 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); | |
170babc3 MC |
1309 | return SUCCESS; |
1310 | } | |
1da177e4 | 1311 | |
8dd9593c | 1312 | /* Get a reference to the sp and drop the lock. */ |
585def9b QT |
1313 | if (sp_get(sp)){ |
1314 | /* ref_count is already 0 */ | |
1315 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); | |
170babc3 MC |
1316 | return SUCCESS; |
1317 | } | |
585def9b QT |
1318 | spin_unlock_irqrestore(qpair->qp_lock_ptr, flags); |
1319 | ||
1320 | id = cmd->device->id; | |
1321 | lun = cmd->device->lun; | |
1da177e4 | 1322 | |
7c3df132 | 1323 | ql_dbg(ql_dbg_taskm, vha, 0x8002, |
c7bc4cae CD |
1324 | "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n", |
1325 | vha->host_no, id, lun, sp, cmd, sp->handle); | |
17d98630 | 1326 | |
f934c9d0 | 1327 | rval = ha->isp_ops->abort_command(sp); |
219d27d7 BVA |
1328 | ql_dbg(ql_dbg_taskm, vha, 0x8003, |
1329 | "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval); | |
f934c9d0 | 1330 | |
219d27d7 BVA |
1331 | switch (rval) { |
1332 | case QLA_SUCCESS: | |
711a08d7 | 1333 | /* |
219d27d7 BVA |
1334 | * The command has been aborted. That means that the firmware |
1335 | * won't report a completion. | |
711a08d7 | 1336 | */ |
219d27d7 BVA |
1337 | sp->done(sp, DID_ABORT << 16); |
1338 | ret = SUCCESS; | |
1339 | break; | |
8dd9593c BVA |
1340 | case QLA_FUNCTION_PARAMETER_ERROR: { |
1341 | /* Wait for the command completion. */ | |
1342 | uint32_t ratov = ha->r_a_tov/10; | |
1343 | uint32_t ratov_j = msecs_to_jiffies(4 * ratov * 1000); | |
1344 | ||
1345 | WARN_ON_ONCE(sp->comp); | |
1346 | sp->comp = ∁ | |
1347 | if (!wait_for_completion_timeout(&comp, ratov_j)) { | |
1348 | ql_dbg(ql_dbg_taskm, vha, 0xffff, | |
1349 | "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n", | |
1350 | __func__, ha->r_a_tov); | |
1351 | ret = FAILED; | |
1352 | } else { | |
1353 | ret = SUCCESS; | |
1354 | } | |
1355 | break; | |
1356 | } | |
219d27d7 BVA |
1357 | default: |
1358 | /* | |
1359 | * Either abort failed or abort and completion raced. Let | |
1360 | * the SCSI core retry the abort in the former case. | |
1361 | */ | |
1362 | ret = FAILED; | |
1363 | break; | |
1da177e4 | 1364 | } |
219d27d7 | 1365 | |
8dd9593c BVA |
1366 | sp->comp = NULL; |
1367 | atomic_dec(&sp->ref_count); | |
7c3df132 | 1368 | ql_log(ql_log_info, vha, 0x801c, |
219d27d7 BVA |
1369 | "Abort command issued nexus=%ld:%d:%llu -- %x.\n", |
1370 | vha->host_no, id, lun, ret); | |
1da177e4 | 1371 | |
f4f051eb AV |
1372 | return ret; |
1373 | } | |
1da177e4 | 1374 | |
4d78c973 | 1375 | int |
e315cd28 | 1376 | qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t, |
9cb78c16 | 1377 | uint64_t l, enum nexus_wait_type type) |
f4f051eb | 1378 | { |
17d98630 | 1379 | int cnt, match, status; |
18e144d3 | 1380 | unsigned long flags; |
e315cd28 | 1381 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 1382 | struct req_que *req; |
4d78c973 | 1383 | srb_t *sp; |
9ba56b95 | 1384 | struct scsi_cmnd *cmd; |
1da177e4 | 1385 | |
523ec773 | 1386 | status = QLA_SUCCESS; |
17d98630 | 1387 | |
e315cd28 | 1388 | spin_lock_irqsave(&ha->hardware_lock, flags); |
67c2e93a | 1389 | req = vha->req; |
17d98630 | 1390 | for (cnt = 1; status == QLA_SUCCESS && |
8d93f550 | 1391 | cnt < req->num_outstanding_cmds; cnt++) { |
17d98630 AC |
1392 | sp = req->outstanding_cmds[cnt]; |
1393 | if (!sp) | |
523ec773 | 1394 | continue; |
9ba56b95 | 1395 | if (sp->type != SRB_SCSI_CMD) |
cf53b069 | 1396 | continue; |
25ff6af1 | 1397 | if (vha->vp_idx != sp->vha->vp_idx) |
17d98630 AC |
1398 | continue; |
1399 | match = 0; | |
9ba56b95 | 1400 | cmd = GET_CMD_SP(sp); |
17d98630 AC |
1401 | switch (type) { |
1402 | case WAIT_HOST: | |
1403 | match = 1; | |
1404 | break; | |
1405 | case WAIT_TARGET: | |
9ba56b95 | 1406 | match = cmd->device->id == t; |
17d98630 AC |
1407 | break; |
1408 | case WAIT_LUN: | |
9ba56b95 GM |
1409 | match = (cmd->device->id == t && |
1410 | cmd->device->lun == l); | |
17d98630 | 1411 | break; |
73208dfd | 1412 | } |
17d98630 AC |
1413 | if (!match) |
1414 | continue; | |
1415 | ||
1416 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
9ba56b95 | 1417 | status = qla2x00_eh_wait_on_command(cmd); |
17d98630 | 1418 | spin_lock_irqsave(&ha->hardware_lock, flags); |
1da177e4 | 1419 | } |
e315cd28 | 1420 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
523ec773 AV |
1421 | |
1422 | return status; | |
1da177e4 LT |
1423 | } |
1424 | ||
523ec773 AV |
1425 | static char *reset_errors[] = { |
1426 | "HBA not online", | |
1427 | "HBA not ready", | |
1428 | "Task management failed", | |
1429 | "Waiting for command completions", | |
1430 | }; | |
1da177e4 | 1431 | |
e5f82ab8 | 1432 | static int |
523ec773 | 1433 | __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type, |
9cb78c16 | 1434 | struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int)) |
1da177e4 | 1435 | { |
e315cd28 | 1436 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
bdf79621 | 1437 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
523ec773 | 1438 | int err; |
1da177e4 | 1439 | |
7c3df132 | 1440 | if (!fcport) { |
523ec773 | 1441 | return FAILED; |
7c3df132 | 1442 | } |
1da177e4 | 1443 | |
4e98d3b8 AV |
1444 | err = fc_block_scsi_eh(cmd); |
1445 | if (err != 0) | |
1446 | return err; | |
1447 | ||
7f4374e6 QT |
1448 | if (fcport->deleted) |
1449 | return SUCCESS; | |
1450 | ||
7c3df132 | 1451 | ql_log(ql_log_info, vha, 0x8009, |
9cb78c16 | 1452 | "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no, |
7c3df132 | 1453 | cmd->device->id, cmd->device->lun, cmd); |
1da177e4 | 1454 | |
523ec773 | 1455 | err = 0; |
7c3df132 SK |
1456 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
1457 | ql_log(ql_log_warn, vha, 0x800a, | |
1458 | "Wait for hba online failed for cmd=%p.\n", cmd); | |
523ec773 | 1459 | goto eh_reset_failed; |
7c3df132 | 1460 | } |
523ec773 | 1461 | err = 2; |
ac444b4f | 1462 | if (do_reset(fcport, cmd->device->lun, 1) |
7c3df132 SK |
1463 | != QLA_SUCCESS) { |
1464 | ql_log(ql_log_warn, vha, 0x800c, | |
1465 | "do_reset failed for cmd=%p.\n", cmd); | |
523ec773 | 1466 | goto eh_reset_failed; |
7c3df132 | 1467 | } |
523ec773 | 1468 | err = 3; |
e315cd28 | 1469 | if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id, |
7c3df132 SK |
1470 | cmd->device->lun, type) != QLA_SUCCESS) { |
1471 | ql_log(ql_log_warn, vha, 0x800d, | |
d6a03581 | 1472 | "wait for pending cmds failed for cmd=%p.\n", cmd); |
523ec773 | 1473 | goto eh_reset_failed; |
7c3df132 | 1474 | } |
523ec773 | 1475 | |
7c3df132 | 1476 | ql_log(ql_log_info, vha, 0x800e, |
9cb78c16 | 1477 | "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name, |
cfb0919c | 1478 | vha->host_no, cmd->device->id, cmd->device->lun, cmd); |
523ec773 AV |
1479 | |
1480 | return SUCCESS; | |
1481 | ||
4d78c973 | 1482 | eh_reset_failed: |
7c3df132 | 1483 | ql_log(ql_log_info, vha, 0x800f, |
9cb78c16 | 1484 | "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name, |
cfb0919c CD |
1485 | reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun, |
1486 | cmd); | |
523ec773 AV |
1487 | return FAILED; |
1488 | } | |
1da177e4 | 1489 | |
523ec773 AV |
1490 | static int |
1491 | qla2xxx_eh_device_reset(struct scsi_cmnd *cmd) | |
1492 | { | |
e315cd28 AC |
1493 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
1494 | struct qla_hw_data *ha = vha->hw; | |
1da177e4 | 1495 | |
a465537a SC |
1496 | if (qla2x00_isp_reg_stat(ha)) { |
1497 | ql_log(ql_log_info, vha, 0x803e, | |
1498 | "PCI/Register disconnect, exiting.\n"); | |
1499 | return FAILED; | |
1500 | } | |
1501 | ||
523ec773 AV |
1502 | return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd, |
1503 | ha->isp_ops->lun_reset); | |
1da177e4 LT |
1504 | } |
1505 | ||
1da177e4 | 1506 | static int |
523ec773 | 1507 | qla2xxx_eh_target_reset(struct scsi_cmnd *cmd) |
1da177e4 | 1508 | { |
e315cd28 AC |
1509 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
1510 | struct qla_hw_data *ha = vha->hw; | |
1da177e4 | 1511 | |
a465537a SC |
1512 | if (qla2x00_isp_reg_stat(ha)) { |
1513 | ql_log(ql_log_info, vha, 0x803f, | |
1514 | "PCI/Register disconnect, exiting.\n"); | |
1515 | return FAILED; | |
1516 | } | |
1517 | ||
523ec773 AV |
1518 | return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd, |
1519 | ha->isp_ops->target_reset); | |
1da177e4 LT |
1520 | } |
1521 | ||
1da177e4 LT |
1522 | /************************************************************************** |
1523 | * qla2xxx_eh_bus_reset | |
1524 | * | |
1525 | * Description: | |
1526 | * The bus reset function will reset the bus and abort any executing | |
1527 | * commands. | |
1528 | * | |
1529 | * Input: | |
1530 | * cmd = Linux SCSI command packet of the command that cause the | |
1531 | * bus reset. | |
1532 | * | |
1533 | * Returns: | |
1534 | * SUCCESS/FAILURE (defined as macro in scsi.h). | |
1535 | * | |
1536 | **************************************************************************/ | |
e5f82ab8 | 1537 | static int |
1da177e4 LT |
1538 | qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd) |
1539 | { | |
e315cd28 | 1540 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
bdf79621 | 1541 | fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; |
2c3dfe3f | 1542 | int ret = FAILED; |
9cb78c16 HR |
1543 | unsigned int id; |
1544 | uint64_t lun; | |
a465537a SC |
1545 | struct qla_hw_data *ha = vha->hw; |
1546 | ||
1547 | if (qla2x00_isp_reg_stat(ha)) { | |
1548 | ql_log(ql_log_info, vha, 0x8040, | |
1549 | "PCI/Register disconnect, exiting.\n"); | |
1550 | return FAILED; | |
1551 | } | |
f4f051eb | 1552 | |
f4f051eb AV |
1553 | id = cmd->device->id; |
1554 | lun = cmd->device->lun; | |
1da177e4 | 1555 | |
7c3df132 | 1556 | if (!fcport) { |
f4f051eb | 1557 | return ret; |
7c3df132 | 1558 | } |
1da177e4 | 1559 | |
4e98d3b8 AV |
1560 | ret = fc_block_scsi_eh(cmd); |
1561 | if (ret != 0) | |
1562 | return ret; | |
1563 | ret = FAILED; | |
1564 | ||
7f4374e6 QT |
1565 | if (qla2x00_chip_is_down(vha)) |
1566 | return ret; | |
1567 | ||
7c3df132 | 1568 | ql_log(ql_log_info, vha, 0x8012, |
9cb78c16 | 1569 | "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun); |
1da177e4 | 1570 | |
e315cd28 | 1571 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
7c3df132 SK |
1572 | ql_log(ql_log_fatal, vha, 0x8013, |
1573 | "Wait for hba online failed board disabled.\n"); | |
f4f051eb | 1574 | goto eh_bus_reset_done; |
1da177e4 LT |
1575 | } |
1576 | ||
ad537689 SK |
1577 | if (qla2x00_loop_reset(vha) == QLA_SUCCESS) |
1578 | ret = SUCCESS; | |
1579 | ||
f4f051eb AV |
1580 | if (ret == FAILED) |
1581 | goto eh_bus_reset_done; | |
1da177e4 | 1582 | |
9a41a62b | 1583 | /* Flush outstanding commands. */ |
4d78c973 | 1584 | if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) != |
7c3df132 SK |
1585 | QLA_SUCCESS) { |
1586 | ql_log(ql_log_warn, vha, 0x8014, | |
1587 | "Wait for pending commands failed.\n"); | |
9a41a62b | 1588 | ret = FAILED; |
7c3df132 | 1589 | } |
1da177e4 | 1590 | |
f4f051eb | 1591 | eh_bus_reset_done: |
7c3df132 | 1592 | ql_log(ql_log_warn, vha, 0x802b, |
9cb78c16 | 1593 | "BUS RESET %s nexus=%ld:%d:%llu.\n", |
d6a03581 | 1594 | (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun); |
1da177e4 | 1595 | |
f4f051eb | 1596 | return ret; |
1da177e4 LT |
1597 | } |
1598 | ||
1599 | /************************************************************************** | |
1600 | * qla2xxx_eh_host_reset | |
1601 | * | |
1602 | * Description: | |
1603 | * The reset function will reset the Adapter. | |
1604 | * | |
1605 | * Input: | |
1606 | * cmd = Linux SCSI command packet of the command that cause the | |
1607 | * adapter reset. | |
1608 | * | |
1609 | * Returns: | |
1610 | * Either SUCCESS or FAILED. | |
1611 | * | |
1612 | * Note: | |
1613 | **************************************************************************/ | |
e5f82ab8 | 1614 | static int |
1da177e4 LT |
1615 | qla2xxx_eh_host_reset(struct scsi_cmnd *cmd) |
1616 | { | |
e315cd28 | 1617 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
e315cd28 | 1618 | struct qla_hw_data *ha = vha->hw; |
2c3dfe3f | 1619 | int ret = FAILED; |
9cb78c16 HR |
1620 | unsigned int id; |
1621 | uint64_t lun; | |
e315cd28 | 1622 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
1da177e4 | 1623 | |
a465537a SC |
1624 | if (qla2x00_isp_reg_stat(ha)) { |
1625 | ql_log(ql_log_info, vha, 0x8041, | |
1626 | "PCI/Register disconnect, exiting.\n"); | |
1627 | schedule_work(&ha->board_disable); | |
1628 | return SUCCESS; | |
1629 | } | |
1630 | ||
f4f051eb AV |
1631 | id = cmd->device->id; |
1632 | lun = cmd->device->lun; | |
f4f051eb | 1633 | |
7c3df132 | 1634 | ql_log(ql_log_info, vha, 0x8018, |
9cb78c16 | 1635 | "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun); |
1da177e4 | 1636 | |
63ee7072 CD |
1637 | /* |
1638 | * No point in issuing another reset if one is active. Also do not | |
1639 | * attempt a reset if we are updating flash. | |
1640 | */ | |
1641 | if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING) | |
f4f051eb | 1642 | goto eh_host_reset_lock; |
1da177e4 | 1643 | |
e315cd28 AC |
1644 | if (vha != base_vha) { |
1645 | if (qla2x00_vp_abort_isp(vha)) | |
f4f051eb | 1646 | goto eh_host_reset_lock; |
e315cd28 | 1647 | } else { |
7ec0effd | 1648 | if (IS_P3P_TYPE(vha->hw)) { |
a9083016 GM |
1649 | if (!qla82xx_fcoe_ctx_reset(vha)) { |
1650 | /* Ctx reset success */ | |
1651 | ret = SUCCESS; | |
1652 | goto eh_host_reset_lock; | |
1653 | } | |
1654 | /* fall thru if ctx reset failed */ | |
1655 | } | |
68ca949c AC |
1656 | if (ha->wq) |
1657 | flush_workqueue(ha->wq); | |
1658 | ||
e315cd28 | 1659 | set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
a9083016 | 1660 | if (ha->isp_ops->abort_isp(base_vha)) { |
e315cd28 AC |
1661 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
1662 | /* failed. schedule dpc to try */ | |
1663 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); | |
1664 | ||
7c3df132 SK |
1665 | if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) { |
1666 | ql_log(ql_log_warn, vha, 0x802a, | |
1667 | "wait for hba online failed.\n"); | |
e315cd28 | 1668 | goto eh_host_reset_lock; |
7c3df132 | 1669 | } |
e315cd28 AC |
1670 | } |
1671 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | |
fa2a1ce5 | 1672 | } |
1da177e4 | 1673 | |
e315cd28 | 1674 | /* Waiting for command to be returned to OS.*/ |
4d78c973 | 1675 | if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) == |
e315cd28 | 1676 | QLA_SUCCESS) |
f4f051eb | 1677 | ret = SUCCESS; |
1da177e4 | 1678 | |
f4f051eb | 1679 | eh_host_reset_lock: |
cfb0919c | 1680 | ql_log(ql_log_info, vha, 0x8017, |
9cb78c16 | 1681 | "ADAPTER RESET %s nexus=%ld:%d:%llu.\n", |
cfb0919c | 1682 | (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun); |
1da177e4 | 1683 | |
f4f051eb AV |
1684 | return ret; |
1685 | } | |
1da177e4 LT |
1686 | |
1687 | /* | |
1688 | * qla2x00_loop_reset | |
1689 | * Issue loop reset. | |
1690 | * | |
1691 | * Input: | |
1692 | * ha = adapter block pointer. | |
1693 | * | |
1694 | * Returns: | |
1695 | * 0 = success | |
1696 | */ | |
a4722cf2 | 1697 | int |
e315cd28 | 1698 | qla2x00_loop_reset(scsi_qla_host_t *vha) |
1da177e4 | 1699 | { |
0c8c39af | 1700 | int ret; |
bdf79621 | 1701 | struct fc_port *fcport; |
e315cd28 | 1702 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 1703 | |
5854771e AB |
1704 | if (IS_QLAFX00(ha)) { |
1705 | return qlafx00_loop_reset(vha); | |
1706 | } | |
1707 | ||
f4c496c1 | 1708 | if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) { |
55e5ed27 AV |
1709 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
1710 | if (fcport->port_type != FCT_TARGET) | |
1711 | continue; | |
1712 | ||
1713 | ret = ha->isp_ops->target_reset(fcport, 0, 0); | |
1714 | if (ret != QLA_SUCCESS) { | |
7c3df132 | 1715 | ql_dbg(ql_dbg_taskm, vha, 0x802c, |
5854771e | 1716 | "Bus Reset failed: Reset=%d " |
7c3df132 | 1717 | "d_id=%x.\n", ret, fcport->d_id.b24); |
55e5ed27 AV |
1718 | } |
1719 | } | |
1720 | } | |
1721 | ||
8ae6d9c7 | 1722 | |
6246b8a1 | 1723 | if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) { |
0b7e7c53 AV |
1724 | atomic_set(&vha->loop_state, LOOP_DOWN); |
1725 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
1726 | qla2x00_mark_all_devices_lost(vha, 0); | |
e315cd28 | 1727 | ret = qla2x00_full_login_lip(vha); |
0c8c39af | 1728 | if (ret != QLA_SUCCESS) { |
7c3df132 SK |
1729 | ql_dbg(ql_dbg_taskm, vha, 0x802d, |
1730 | "full_login_lip=%d.\n", ret); | |
749af3d5 | 1731 | } |
0c8c39af AV |
1732 | } |
1733 | ||
0d6e61bc | 1734 | if (ha->flags.enable_lip_reset) { |
e315cd28 | 1735 | ret = qla2x00_lip_reset(vha); |
ad537689 | 1736 | if (ret != QLA_SUCCESS) |
7c3df132 SK |
1737 | ql_dbg(ql_dbg_taskm, vha, 0x802e, |
1738 | "lip_reset failed (%d).\n", ret); | |
1da177e4 LT |
1739 | } |
1740 | ||
1da177e4 | 1741 | /* Issue marker command only when we are going to start the I/O */ |
e315cd28 | 1742 | vha->marker_needed = 1; |
1da177e4 | 1743 | |
0c8c39af | 1744 | return QLA_SUCCESS; |
1da177e4 LT |
1745 | } |
1746 | ||
c4e521b6 BVA |
1747 | static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res, |
1748 | unsigned long *flags) | |
1749 | __releases(qp->qp_lock_ptr) | |
1750 | __acquires(qp->qp_lock_ptr) | |
1751 | { | |
219d27d7 | 1752 | DECLARE_COMPLETION_ONSTACK(comp); |
c4e521b6 BVA |
1753 | scsi_qla_host_t *vha = qp->vha; |
1754 | struct qla_hw_data *ha = vha->hw; | |
219d27d7 | 1755 | int rval; |
c4e521b6 | 1756 | |
219d27d7 BVA |
1757 | if (sp_get(sp)) |
1758 | return; | |
1759 | ||
1760 | if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS || | |
1761 | (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy && | |
1762 | !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) && | |
1763 | !qla2x00_isp_reg_stat(ha))) { | |
1764 | sp->comp = ∁ | |
219d27d7 | 1765 | spin_unlock_irqrestore(qp->qp_lock_ptr, *flags); |
5589b08e | 1766 | rval = ha->isp_ops->abort_command(sp); |
219d27d7 BVA |
1767 | |
1768 | switch (rval) { | |
1769 | case QLA_SUCCESS: | |
1770 | sp->done(sp, res); | |
1771 | break; | |
1772 | case QLA_FUNCTION_PARAMETER_ERROR: | |
1773 | wait_for_completion(&comp); | |
1774 | break; | |
c4e521b6 | 1775 | } |
219d27d7 BVA |
1776 | |
1777 | spin_lock_irqsave(qp->qp_lock_ptr, *flags); | |
1778 | sp->comp = NULL; | |
c4e521b6 | 1779 | } |
d2d2b5a5 BVA |
1780 | |
1781 | atomic_dec(&sp->ref_count); | |
c4e521b6 BVA |
1782 | } |
1783 | ||
bbead493 QT |
1784 | static void |
1785 | __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res) | |
df4bf0bb | 1786 | { |
eb023220 | 1787 | int cnt; |
df4bf0bb AV |
1788 | unsigned long flags; |
1789 | srb_t *sp; | |
bbead493 | 1790 | scsi_qla_host_t *vha = qp->vha; |
e315cd28 | 1791 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 1792 | struct req_que *req; |
c5419e26 QT |
1793 | struct qla_tgt *tgt = vha->vha_tgt.qla_tgt; |
1794 | struct qla_tgt_cmd *cmd; | |
c0cb4496 | 1795 | |
6a2cf8d3 BK |
1796 | if (!ha->req_q_map) |
1797 | return; | |
bbead493 QT |
1798 | spin_lock_irqsave(qp->qp_lock_ptr, flags); |
1799 | req = qp->req; | |
1800 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) { | |
1801 | sp = req->outstanding_cmds[cnt]; | |
1802 | if (sp) { | |
1803 | req->outstanding_cmds[cnt] = NULL; | |
6b0431d6 QT |
1804 | switch (sp->cmd_type) { |
1805 | case TYPE_SRB: | |
c4e521b6 | 1806 | qla2x00_abort_srb(qp, sp, res, &flags); |
585def9b QT |
1807 | break; |
1808 | case TYPE_TGT_CMD: | |
bbead493 QT |
1809 | if (!vha->hw->tgt.tgt_ops || !tgt || |
1810 | qla_ini_mode_enabled(vha)) { | |
585def9b QT |
1811 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003, |
1812 | "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n", | |
1813 | vha->dpc_flags); | |
bbead493 | 1814 | continue; |
c733ab35 | 1815 | } |
bbead493 | 1816 | cmd = (struct qla_tgt_cmd *)sp; |
aefed3e5 | 1817 | cmd->aborted = 1; |
585def9b QT |
1818 | break; |
1819 | case TYPE_TGT_TMCMD: | |
aefed3e5 | 1820 | /* Skip task management functions. */ |
585def9b QT |
1821 | break; |
1822 | default: | |
1823 | break; | |
73208dfd | 1824 | } |
df4bf0bb AV |
1825 | } |
1826 | } | |
bbead493 QT |
1827 | spin_unlock_irqrestore(qp->qp_lock_ptr, flags); |
1828 | } | |
1829 | ||
1830 | void | |
1831 | qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res) | |
1832 | { | |
1833 | int que; | |
1834 | struct qla_hw_data *ha = vha->hw; | |
1835 | ||
26a77799 AV |
1836 | /* Continue only if initialization complete. */ |
1837 | if (!ha->base_qpair) | |
1838 | return; | |
bbead493 QT |
1839 | __qla2x00_abort_all_cmds(ha->base_qpair, res); |
1840 | ||
26a77799 AV |
1841 | if (!ha->queue_pair_map) |
1842 | return; | |
bbead493 QT |
1843 | for (que = 0; que < ha->max_qpairs; que++) { |
1844 | if (!ha->queue_pair_map[que]) | |
1845 | continue; | |
1846 | ||
1847 | __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res); | |
1848 | } | |
df4bf0bb AV |
1849 | } |
1850 | ||
f4f051eb AV |
1851 | static int |
1852 | qla2xxx_slave_alloc(struct scsi_device *sdev) | |
1da177e4 | 1853 | { |
bdf79621 | 1854 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
1da177e4 | 1855 | |
19a7b4ae | 1856 | if (!rport || fc_remote_port_chkready(rport)) |
f4f051eb | 1857 | return -ENXIO; |
bdf79621 | 1858 | |
19a7b4ae | 1859 | sdev->hostdata = *(fc_port_t **)rport->dd_data; |
1da177e4 | 1860 | |
f4f051eb AV |
1861 | return 0; |
1862 | } | |
1da177e4 | 1863 | |
f4f051eb AV |
1864 | static int |
1865 | qla2xxx_slave_configure(struct scsi_device *sdev) | |
1866 | { | |
e315cd28 | 1867 | scsi_qla_host_t *vha = shost_priv(sdev->host); |
2afa19a9 | 1868 | struct req_que *req = vha->req; |
8482e118 | 1869 | |
9e522cd8 AE |
1870 | if (IS_T10_PI_CAPABLE(vha->hw)) |
1871 | blk_queue_update_dma_alignment(sdev->request_queue, 0x7); | |
1872 | ||
db5ed4df | 1873 | scsi_change_queue_depth(sdev, req->max_q_depth); |
f4f051eb AV |
1874 | return 0; |
1875 | } | |
1da177e4 | 1876 | |
f4f051eb AV |
1877 | static void |
1878 | qla2xxx_slave_destroy(struct scsi_device *sdev) | |
1879 | { | |
1880 | sdev->hostdata = NULL; | |
1da177e4 LT |
1881 | } |
1882 | ||
1883 | /** | |
1884 | * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. | |
1885 | * @ha: HA context | |
1886 | * | |
1887 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated | |
1888 | * supported addressing method. | |
1889 | */ | |
1890 | static void | |
53303c42 | 1891 | qla2x00_config_dma_addressing(struct qla_hw_data *ha) |
1da177e4 | 1892 | { |
7524f9b9 | 1893 | /* Assume a 32bit DMA mask. */ |
1da177e4 | 1894 | ha->flags.enable_64bit_addressing = 0; |
1da177e4 | 1895 | |
6a35528a | 1896 | if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) { |
7524f9b9 AV |
1897 | /* Any upper-dword bits set? */ |
1898 | if (MSD(dma_get_required_mask(&ha->pdev->dev)) && | |
6a35528a | 1899 | !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { |
7524f9b9 | 1900 | /* Ok, a 64bit DMA mask is applicable. */ |
1da177e4 | 1901 | ha->flags.enable_64bit_addressing = 1; |
fd34f556 AV |
1902 | ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64; |
1903 | ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64; | |
7524f9b9 | 1904 | return; |
1da177e4 | 1905 | } |
1da177e4 | 1906 | } |
7524f9b9 | 1907 | |
284901a9 YH |
1908 | dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32)); |
1909 | pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32)); | |
1da177e4 LT |
1910 | } |
1911 | ||
fd34f556 | 1912 | static void |
e315cd28 | 1913 | qla2x00_enable_intrs(struct qla_hw_data *ha) |
fd34f556 AV |
1914 | { |
1915 | unsigned long flags = 0; | |
1916 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | |
1917 | ||
1918 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1919 | ha->interrupts_on = 1; | |
1920 | /* enable risc and host interrupts */ | |
1921 | WRT_REG_WORD(®->ictrl, ICR_EN_INT | ICR_EN_RISC); | |
1922 | RD_REG_WORD(®->ictrl); | |
1923 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1924 | ||
1925 | } | |
1926 | ||
1927 | static void | |
e315cd28 | 1928 | qla2x00_disable_intrs(struct qla_hw_data *ha) |
fd34f556 AV |
1929 | { |
1930 | unsigned long flags = 0; | |
1931 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | |
1932 | ||
1933 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1934 | ha->interrupts_on = 0; | |
1935 | /* disable risc and host interrupts */ | |
1936 | WRT_REG_WORD(®->ictrl, 0); | |
1937 | RD_REG_WORD(®->ictrl); | |
1938 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1939 | } | |
1940 | ||
1941 | static void | |
e315cd28 | 1942 | qla24xx_enable_intrs(struct qla_hw_data *ha) |
fd34f556 AV |
1943 | { |
1944 | unsigned long flags = 0; | |
1945 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | |
1946 | ||
1947 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1948 | ha->interrupts_on = 1; | |
1949 | WRT_REG_DWORD(®->ictrl, ICRX_EN_RISC_INT); | |
1950 | RD_REG_DWORD(®->ictrl); | |
1951 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1952 | } | |
1953 | ||
1954 | static void | |
e315cd28 | 1955 | qla24xx_disable_intrs(struct qla_hw_data *ha) |
fd34f556 AV |
1956 | { |
1957 | unsigned long flags = 0; | |
1958 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | |
1959 | ||
124f85e6 AV |
1960 | if (IS_NOPOLLING_TYPE(ha)) |
1961 | return; | |
fd34f556 AV |
1962 | spin_lock_irqsave(&ha->hardware_lock, flags); |
1963 | ha->interrupts_on = 0; | |
1964 | WRT_REG_DWORD(®->ictrl, 0); | |
1965 | RD_REG_DWORD(®->ictrl); | |
1966 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1967 | } | |
1968 | ||
706f457d GM |
1969 | static int |
1970 | qla2x00_iospace_config(struct qla_hw_data *ha) | |
1971 | { | |
1972 | resource_size_t pio; | |
1973 | uint16_t msix; | |
706f457d | 1974 | |
706f457d GM |
1975 | if (pci_request_selected_regions(ha->pdev, ha->bars, |
1976 | QLA2XXX_DRIVER_NAME)) { | |
1977 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0011, | |
1978 | "Failed to reserve PIO/MMIO regions (%s), aborting.\n", | |
1979 | pci_name(ha->pdev)); | |
1980 | goto iospace_error_exit; | |
1981 | } | |
1982 | if (!(ha->bars & 1)) | |
1983 | goto skip_pio; | |
1984 | ||
1985 | /* We only need PIO for Flash operations on ISP2312 v2 chips. */ | |
1986 | pio = pci_resource_start(ha->pdev, 0); | |
1987 | if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) { | |
1988 | if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) { | |
1989 | ql_log_pci(ql_log_warn, ha->pdev, 0x0012, | |
1990 | "Invalid pci I/O region size (%s).\n", | |
1991 | pci_name(ha->pdev)); | |
1992 | pio = 0; | |
1993 | } | |
1994 | } else { | |
1995 | ql_log_pci(ql_log_warn, ha->pdev, 0x0013, | |
1996 | "Region #0 no a PIO resource (%s).\n", | |
1997 | pci_name(ha->pdev)); | |
1998 | pio = 0; | |
1999 | } | |
2000 | ha->pio_address = pio; | |
2001 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014, | |
2002 | "PIO address=%llu.\n", | |
2003 | (unsigned long long)ha->pio_address); | |
2004 | ||
2005 | skip_pio: | |
2006 | /* Use MMIO operations for all accesses. */ | |
2007 | if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) { | |
2008 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0015, | |
2009 | "Region #1 not an MMIO resource (%s), aborting.\n", | |
2010 | pci_name(ha->pdev)); | |
2011 | goto iospace_error_exit; | |
2012 | } | |
2013 | if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) { | |
2014 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0016, | |
2015 | "Invalid PCI mem region size (%s), aborting.\n", | |
2016 | pci_name(ha->pdev)); | |
2017 | goto iospace_error_exit; | |
2018 | } | |
2019 | ||
2020 | ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN); | |
2021 | if (!ha->iobase) { | |
2022 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0017, | |
2023 | "Cannot remap MMIO (%s), aborting.\n", | |
2024 | pci_name(ha->pdev)); | |
2025 | goto iospace_error_exit; | |
2026 | } | |
2027 | ||
2028 | /* Determine queue resources */ | |
2029 | ha->max_req_queues = ha->max_rsp_queues = 1; | |
f54f2cb5 | 2030 | ha->msix_count = QLA_BASE_VECTORS; |
c38d1baf HM |
2031 | if (!ql2xmqsupport || !ql2xnvmeenable || |
2032 | (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))) | |
706f457d GM |
2033 | goto mqiobase_exit; |
2034 | ||
2035 | ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3), | |
2036 | pci_resource_len(ha->pdev, 3)); | |
2037 | if (ha->mqiobase) { | |
2038 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018, | |
2039 | "MQIO Base=%p.\n", ha->mqiobase); | |
2040 | /* Read MSIX vector size of the board */ | |
2041 | pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix); | |
d7459527 | 2042 | ha->msix_count = msix + 1; |
706f457d | 2043 | /* Max queues are bounded by available msix vectors */ |
d7459527 MH |
2044 | /* MB interrupt uses 1 vector */ |
2045 | ha->max_req_queues = ha->msix_count - 1; | |
2046 | ha->max_rsp_queues = ha->max_req_queues; | |
2047 | /* Queue pairs is the max value minus the base queue pair */ | |
2048 | ha->max_qpairs = ha->max_rsp_queues - 1; | |
2049 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188, | |
2050 | "Max no of queues pairs: %d.\n", ha->max_qpairs); | |
2051 | ||
706f457d | 2052 | ql_log_pci(ql_log_info, ha->pdev, 0x001a, |
d7459527 | 2053 | "MSI-X vector count: %d.\n", ha->msix_count); |
706f457d GM |
2054 | } else |
2055 | ql_log_pci(ql_log_info, ha->pdev, 0x001b, | |
2056 | "BAR 3 not enabled.\n"); | |
2057 | ||
2058 | mqiobase_exit: | |
706f457d | 2059 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c, |
f54f2cb5 | 2060 | "MSIX Count: %d.\n", ha->msix_count); |
706f457d GM |
2061 | return (0); |
2062 | ||
2063 | iospace_error_exit: | |
2064 | return (-ENOMEM); | |
2065 | } | |
2066 | ||
2067 | ||
6246b8a1 GM |
2068 | static int |
2069 | qla83xx_iospace_config(struct qla_hw_data *ha) | |
2070 | { | |
2071 | uint16_t msix; | |
6246b8a1 GM |
2072 | |
2073 | if (pci_request_selected_regions(ha->pdev, ha->bars, | |
2074 | QLA2XXX_DRIVER_NAME)) { | |
2075 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0117, | |
2076 | "Failed to reserve PIO/MMIO regions (%s), aborting.\n", | |
2077 | pci_name(ha->pdev)); | |
2078 | ||
2079 | goto iospace_error_exit; | |
2080 | } | |
2081 | ||
2082 | /* Use MMIO operations for all accesses. */ | |
2083 | if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) { | |
2084 | ql_log_pci(ql_log_warn, ha->pdev, 0x0118, | |
2085 | "Invalid pci I/O region size (%s).\n", | |
2086 | pci_name(ha->pdev)); | |
2087 | goto iospace_error_exit; | |
2088 | } | |
2089 | if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) { | |
2090 | ql_log_pci(ql_log_warn, ha->pdev, 0x0119, | |
2091 | "Invalid PCI mem region size (%s), aborting\n", | |
2092 | pci_name(ha->pdev)); | |
2093 | goto iospace_error_exit; | |
2094 | } | |
2095 | ||
2096 | ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN); | |
2097 | if (!ha->iobase) { | |
2098 | ql_log_pci(ql_log_fatal, ha->pdev, 0x011a, | |
2099 | "Cannot remap MMIO (%s), aborting.\n", | |
2100 | pci_name(ha->pdev)); | |
2101 | goto iospace_error_exit; | |
2102 | } | |
2103 | ||
2104 | /* 64bit PCI BAR - BAR2 will correspoond to region 4 */ | |
2105 | /* 83XX 26XX always use MQ type access for queues | |
2106 | * - mbar 2, a.k.a region 4 */ | |
2107 | ha->max_req_queues = ha->max_rsp_queues = 1; | |
f54f2cb5 | 2108 | ha->msix_count = QLA_BASE_VECTORS; |
6246b8a1 GM |
2109 | ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4), |
2110 | pci_resource_len(ha->pdev, 4)); | |
2111 | ||
2112 | if (!ha->mqiobase) { | |
2113 | ql_log_pci(ql_log_fatal, ha->pdev, 0x011d, | |
2114 | "BAR2/region4 not enabled\n"); | |
2115 | goto mqiobase_exit; | |
2116 | } | |
2117 | ||
2118 | ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2), | |
2119 | pci_resource_len(ha->pdev, 2)); | |
2120 | if (ha->msixbase) { | |
2121 | /* Read MSIX vector size of the board */ | |
2122 | pci_read_config_word(ha->pdev, | |
2123 | QLA_83XX_PCI_MSIX_CONTROL, &msix); | |
e326d22a | 2124 | ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1; |
093df737 QT |
2125 | /* |
2126 | * By default, driver uses at least two msix vectors | |
2127 | * (default & rspq) | |
2128 | */ | |
c38d1baf | 2129 | if (ql2xmqsupport || ql2xnvmeenable) { |
d7459527 MH |
2130 | /* MB interrupt uses 1 vector */ |
2131 | ha->max_req_queues = ha->msix_count - 1; | |
093df737 QT |
2132 | |
2133 | /* ATIOQ needs 1 vector. That's 1 less QPair */ | |
2134 | if (QLA_TGT_MODE_ENABLED()) | |
2135 | ha->max_req_queues--; | |
2136 | ||
d0d2c68b MH |
2137 | ha->max_rsp_queues = ha->max_req_queues; |
2138 | ||
d7459527 MH |
2139 | /* Queue pairs is the max value minus |
2140 | * the base queue pair */ | |
2141 | ha->max_qpairs = ha->max_req_queues - 1; | |
83548fe2 | 2142 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3, |
d7459527 | 2143 | "Max no of queues pairs: %d.\n", ha->max_qpairs); |
6246b8a1 GM |
2144 | } |
2145 | ql_log_pci(ql_log_info, ha->pdev, 0x011c, | |
d7459527 | 2146 | "MSI-X vector count: %d.\n", ha->msix_count); |
6246b8a1 GM |
2147 | } else |
2148 | ql_log_pci(ql_log_info, ha->pdev, 0x011e, | |
2149 | "BAR 1 not enabled.\n"); | |
2150 | ||
2151 | mqiobase_exit: | |
6246b8a1 | 2152 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f, |
f54f2cb5 | 2153 | "MSIX Count: %d.\n", ha->msix_count); |
6246b8a1 GM |
2154 | return 0; |
2155 | ||
2156 | iospace_error_exit: | |
2157 | return -ENOMEM; | |
2158 | } | |
2159 | ||
fd34f556 AV |
2160 | static struct isp_operations qla2100_isp_ops = { |
2161 | .pci_config = qla2100_pci_config, | |
2162 | .reset_chip = qla2x00_reset_chip, | |
2163 | .chip_diag = qla2x00_chip_diag, | |
2164 | .config_rings = qla2x00_config_rings, | |
2165 | .reset_adapter = qla2x00_reset_adapter, | |
2166 | .nvram_config = qla2x00_nvram_config, | |
2167 | .update_fw_options = qla2x00_update_fw_options, | |
2168 | .load_risc = qla2x00_load_risc, | |
2169 | .pci_info_str = qla2x00_pci_info_str, | |
2170 | .fw_version_str = qla2x00_fw_version_str, | |
2171 | .intr_handler = qla2100_intr_handler, | |
2172 | .enable_intrs = qla2x00_enable_intrs, | |
2173 | .disable_intrs = qla2x00_disable_intrs, | |
2174 | .abort_command = qla2x00_abort_command, | |
523ec773 AV |
2175 | .target_reset = qla2x00_abort_target, |
2176 | .lun_reset = qla2x00_lun_reset, | |
fd34f556 AV |
2177 | .fabric_login = qla2x00_login_fabric, |
2178 | .fabric_logout = qla2x00_fabric_logout, | |
2179 | .calc_req_entries = qla2x00_calc_iocbs_32, | |
2180 | .build_iocbs = qla2x00_build_scsi_iocbs_32, | |
2181 | .prep_ms_iocb = qla2x00_prep_ms_iocb, | |
2182 | .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb, | |
2183 | .read_nvram = qla2x00_read_nvram_data, | |
2184 | .write_nvram = qla2x00_write_nvram_data, | |
2185 | .fw_dump = qla2100_fw_dump, | |
2186 | .beacon_on = NULL, | |
2187 | .beacon_off = NULL, | |
2188 | .beacon_blink = NULL, | |
2189 | .read_optrom = qla2x00_read_optrom_data, | |
2190 | .write_optrom = qla2x00_write_optrom_data, | |
2191 | .get_flash_version = qla2x00_get_flash_version, | |
e315cd28 | 2192 | .start_scsi = qla2x00_start_scsi, |
d7459527 | 2193 | .start_scsi_mq = NULL, |
a9083016 | 2194 | .abort_isp = qla2x00_abort_isp, |
706f457d | 2195 | .iospace_config = qla2x00_iospace_config, |
8ae6d9c7 | 2196 | .initialize_adapter = qla2x00_initialize_adapter, |
fd34f556 AV |
2197 | }; |
2198 | ||
2199 | static struct isp_operations qla2300_isp_ops = { | |
2200 | .pci_config = qla2300_pci_config, | |
2201 | .reset_chip = qla2x00_reset_chip, | |
2202 | .chip_diag = qla2x00_chip_diag, | |
2203 | .config_rings = qla2x00_config_rings, | |
2204 | .reset_adapter = qla2x00_reset_adapter, | |
2205 | .nvram_config = qla2x00_nvram_config, | |
2206 | .update_fw_options = qla2x00_update_fw_options, | |
2207 | .load_risc = qla2x00_load_risc, | |
2208 | .pci_info_str = qla2x00_pci_info_str, | |
2209 | .fw_version_str = qla2x00_fw_version_str, | |
2210 | .intr_handler = qla2300_intr_handler, | |
2211 | .enable_intrs = qla2x00_enable_intrs, | |
2212 | .disable_intrs = qla2x00_disable_intrs, | |
2213 | .abort_command = qla2x00_abort_command, | |
523ec773 AV |
2214 | .target_reset = qla2x00_abort_target, |
2215 | .lun_reset = qla2x00_lun_reset, | |
fd34f556 AV |
2216 | .fabric_login = qla2x00_login_fabric, |
2217 | .fabric_logout = qla2x00_fabric_logout, | |
2218 | .calc_req_entries = qla2x00_calc_iocbs_32, | |
2219 | .build_iocbs = qla2x00_build_scsi_iocbs_32, | |
2220 | .prep_ms_iocb = qla2x00_prep_ms_iocb, | |
2221 | .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb, | |
2222 | .read_nvram = qla2x00_read_nvram_data, | |
2223 | .write_nvram = qla2x00_write_nvram_data, | |
2224 | .fw_dump = qla2300_fw_dump, | |
2225 | .beacon_on = qla2x00_beacon_on, | |
2226 | .beacon_off = qla2x00_beacon_off, | |
2227 | .beacon_blink = qla2x00_beacon_blink, | |
2228 | .read_optrom = qla2x00_read_optrom_data, | |
2229 | .write_optrom = qla2x00_write_optrom_data, | |
2230 | .get_flash_version = qla2x00_get_flash_version, | |
e315cd28 | 2231 | .start_scsi = qla2x00_start_scsi, |
d7459527 | 2232 | .start_scsi_mq = NULL, |
a9083016 | 2233 | .abort_isp = qla2x00_abort_isp, |
7ec0effd | 2234 | .iospace_config = qla2x00_iospace_config, |
8ae6d9c7 | 2235 | .initialize_adapter = qla2x00_initialize_adapter, |
fd34f556 AV |
2236 | }; |
2237 | ||
2238 | static struct isp_operations qla24xx_isp_ops = { | |
2239 | .pci_config = qla24xx_pci_config, | |
2240 | .reset_chip = qla24xx_reset_chip, | |
2241 | .chip_diag = qla24xx_chip_diag, | |
2242 | .config_rings = qla24xx_config_rings, | |
2243 | .reset_adapter = qla24xx_reset_adapter, | |
2244 | .nvram_config = qla24xx_nvram_config, | |
2245 | .update_fw_options = qla24xx_update_fw_options, | |
2246 | .load_risc = qla24xx_load_risc, | |
2247 | .pci_info_str = qla24xx_pci_info_str, | |
2248 | .fw_version_str = qla24xx_fw_version_str, | |
2249 | .intr_handler = qla24xx_intr_handler, | |
2250 | .enable_intrs = qla24xx_enable_intrs, | |
2251 | .disable_intrs = qla24xx_disable_intrs, | |
2252 | .abort_command = qla24xx_abort_command, | |
523ec773 AV |
2253 | .target_reset = qla24xx_abort_target, |
2254 | .lun_reset = qla24xx_lun_reset, | |
fd34f556 AV |
2255 | .fabric_login = qla24xx_login_fabric, |
2256 | .fabric_logout = qla24xx_fabric_logout, | |
2257 | .calc_req_entries = NULL, | |
2258 | .build_iocbs = NULL, | |
2259 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
2260 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
2261 | .read_nvram = qla24xx_read_nvram_data, | |
2262 | .write_nvram = qla24xx_write_nvram_data, | |
2263 | .fw_dump = qla24xx_fw_dump, | |
2264 | .beacon_on = qla24xx_beacon_on, | |
2265 | .beacon_off = qla24xx_beacon_off, | |
2266 | .beacon_blink = qla24xx_beacon_blink, | |
2267 | .read_optrom = qla24xx_read_optrom_data, | |
2268 | .write_optrom = qla24xx_write_optrom_data, | |
2269 | .get_flash_version = qla24xx_get_flash_version, | |
e315cd28 | 2270 | .start_scsi = qla24xx_start_scsi, |
d7459527 | 2271 | .start_scsi_mq = NULL, |
a9083016 | 2272 | .abort_isp = qla2x00_abort_isp, |
7ec0effd | 2273 | .iospace_config = qla2x00_iospace_config, |
8ae6d9c7 | 2274 | .initialize_adapter = qla2x00_initialize_adapter, |
fd34f556 AV |
2275 | }; |
2276 | ||
c3a2f0df AV |
2277 | static struct isp_operations qla25xx_isp_ops = { |
2278 | .pci_config = qla25xx_pci_config, | |
2279 | .reset_chip = qla24xx_reset_chip, | |
2280 | .chip_diag = qla24xx_chip_diag, | |
2281 | .config_rings = qla24xx_config_rings, | |
2282 | .reset_adapter = qla24xx_reset_adapter, | |
2283 | .nvram_config = qla24xx_nvram_config, | |
2284 | .update_fw_options = qla24xx_update_fw_options, | |
2285 | .load_risc = qla24xx_load_risc, | |
2286 | .pci_info_str = qla24xx_pci_info_str, | |
2287 | .fw_version_str = qla24xx_fw_version_str, | |
2288 | .intr_handler = qla24xx_intr_handler, | |
2289 | .enable_intrs = qla24xx_enable_intrs, | |
2290 | .disable_intrs = qla24xx_disable_intrs, | |
2291 | .abort_command = qla24xx_abort_command, | |
523ec773 AV |
2292 | .target_reset = qla24xx_abort_target, |
2293 | .lun_reset = qla24xx_lun_reset, | |
c3a2f0df AV |
2294 | .fabric_login = qla24xx_login_fabric, |
2295 | .fabric_logout = qla24xx_fabric_logout, | |
2296 | .calc_req_entries = NULL, | |
2297 | .build_iocbs = NULL, | |
2298 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
2299 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
2300 | .read_nvram = qla25xx_read_nvram_data, | |
2301 | .write_nvram = qla25xx_write_nvram_data, | |
2302 | .fw_dump = qla25xx_fw_dump, | |
2303 | .beacon_on = qla24xx_beacon_on, | |
2304 | .beacon_off = qla24xx_beacon_off, | |
2305 | .beacon_blink = qla24xx_beacon_blink, | |
338c9161 | 2306 | .read_optrom = qla25xx_read_optrom_data, |
c3a2f0df AV |
2307 | .write_optrom = qla24xx_write_optrom_data, |
2308 | .get_flash_version = qla24xx_get_flash_version, | |
bad75002 | 2309 | .start_scsi = qla24xx_dif_start_scsi, |
d7459527 | 2310 | .start_scsi_mq = qla2xxx_dif_start_scsi_mq, |
a9083016 | 2311 | .abort_isp = qla2x00_abort_isp, |
7ec0effd | 2312 | .iospace_config = qla2x00_iospace_config, |
8ae6d9c7 | 2313 | .initialize_adapter = qla2x00_initialize_adapter, |
c3a2f0df AV |
2314 | }; |
2315 | ||
3a03eb79 AV |
2316 | static struct isp_operations qla81xx_isp_ops = { |
2317 | .pci_config = qla25xx_pci_config, | |
2318 | .reset_chip = qla24xx_reset_chip, | |
2319 | .chip_diag = qla24xx_chip_diag, | |
2320 | .config_rings = qla24xx_config_rings, | |
2321 | .reset_adapter = qla24xx_reset_adapter, | |
2322 | .nvram_config = qla81xx_nvram_config, | |
2323 | .update_fw_options = qla81xx_update_fw_options, | |
eaac30be | 2324 | .load_risc = qla81xx_load_risc, |
3a03eb79 AV |
2325 | .pci_info_str = qla24xx_pci_info_str, |
2326 | .fw_version_str = qla24xx_fw_version_str, | |
2327 | .intr_handler = qla24xx_intr_handler, | |
2328 | .enable_intrs = qla24xx_enable_intrs, | |
2329 | .disable_intrs = qla24xx_disable_intrs, | |
2330 | .abort_command = qla24xx_abort_command, | |
2331 | .target_reset = qla24xx_abort_target, | |
2332 | .lun_reset = qla24xx_lun_reset, | |
2333 | .fabric_login = qla24xx_login_fabric, | |
2334 | .fabric_logout = qla24xx_fabric_logout, | |
2335 | .calc_req_entries = NULL, | |
2336 | .build_iocbs = NULL, | |
2337 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
2338 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
3d79038f AV |
2339 | .read_nvram = NULL, |
2340 | .write_nvram = NULL, | |
3a03eb79 AV |
2341 | .fw_dump = qla81xx_fw_dump, |
2342 | .beacon_on = qla24xx_beacon_on, | |
2343 | .beacon_off = qla24xx_beacon_off, | |
6246b8a1 | 2344 | .beacon_blink = qla83xx_beacon_blink, |
3a03eb79 AV |
2345 | .read_optrom = qla25xx_read_optrom_data, |
2346 | .write_optrom = qla24xx_write_optrom_data, | |
2347 | .get_flash_version = qla24xx_get_flash_version, | |
ba77ef53 | 2348 | .start_scsi = qla24xx_dif_start_scsi, |
d7459527 | 2349 | .start_scsi_mq = qla2xxx_dif_start_scsi_mq, |
a9083016 | 2350 | .abort_isp = qla2x00_abort_isp, |
7ec0effd | 2351 | .iospace_config = qla2x00_iospace_config, |
8ae6d9c7 | 2352 | .initialize_adapter = qla2x00_initialize_adapter, |
a9083016 GM |
2353 | }; |
2354 | ||
2355 | static struct isp_operations qla82xx_isp_ops = { | |
2356 | .pci_config = qla82xx_pci_config, | |
2357 | .reset_chip = qla82xx_reset_chip, | |
2358 | .chip_diag = qla24xx_chip_diag, | |
2359 | .config_rings = qla82xx_config_rings, | |
2360 | .reset_adapter = qla24xx_reset_adapter, | |
2361 | .nvram_config = qla81xx_nvram_config, | |
2362 | .update_fw_options = qla24xx_update_fw_options, | |
2363 | .load_risc = qla82xx_load_risc, | |
9d55ca66 | 2364 | .pci_info_str = qla24xx_pci_info_str, |
a9083016 GM |
2365 | .fw_version_str = qla24xx_fw_version_str, |
2366 | .intr_handler = qla82xx_intr_handler, | |
2367 | .enable_intrs = qla82xx_enable_intrs, | |
2368 | .disable_intrs = qla82xx_disable_intrs, | |
2369 | .abort_command = qla24xx_abort_command, | |
2370 | .target_reset = qla24xx_abort_target, | |
2371 | .lun_reset = qla24xx_lun_reset, | |
2372 | .fabric_login = qla24xx_login_fabric, | |
2373 | .fabric_logout = qla24xx_fabric_logout, | |
2374 | .calc_req_entries = NULL, | |
2375 | .build_iocbs = NULL, | |
2376 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
2377 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
2378 | .read_nvram = qla24xx_read_nvram_data, | |
2379 | .write_nvram = qla24xx_write_nvram_data, | |
a1b23c5a | 2380 | .fw_dump = qla82xx_fw_dump, |
999916dc SK |
2381 | .beacon_on = qla82xx_beacon_on, |
2382 | .beacon_off = qla82xx_beacon_off, | |
2383 | .beacon_blink = NULL, | |
a9083016 GM |
2384 | .read_optrom = qla82xx_read_optrom_data, |
2385 | .write_optrom = qla82xx_write_optrom_data, | |
7ec0effd | 2386 | .get_flash_version = qla82xx_get_flash_version, |
a9083016 | 2387 | .start_scsi = qla82xx_start_scsi, |
d7459527 | 2388 | .start_scsi_mq = NULL, |
a9083016 | 2389 | .abort_isp = qla82xx_abort_isp, |
706f457d | 2390 | .iospace_config = qla82xx_iospace_config, |
8ae6d9c7 | 2391 | .initialize_adapter = qla2x00_initialize_adapter, |
3a03eb79 AV |
2392 | }; |
2393 | ||
7ec0effd AD |
2394 | static struct isp_operations qla8044_isp_ops = { |
2395 | .pci_config = qla82xx_pci_config, | |
2396 | .reset_chip = qla82xx_reset_chip, | |
2397 | .chip_diag = qla24xx_chip_diag, | |
2398 | .config_rings = qla82xx_config_rings, | |
2399 | .reset_adapter = qla24xx_reset_adapter, | |
2400 | .nvram_config = qla81xx_nvram_config, | |
2401 | .update_fw_options = qla24xx_update_fw_options, | |
2402 | .load_risc = qla82xx_load_risc, | |
2403 | .pci_info_str = qla24xx_pci_info_str, | |
2404 | .fw_version_str = qla24xx_fw_version_str, | |
2405 | .intr_handler = qla8044_intr_handler, | |
2406 | .enable_intrs = qla82xx_enable_intrs, | |
2407 | .disable_intrs = qla82xx_disable_intrs, | |
2408 | .abort_command = qla24xx_abort_command, | |
2409 | .target_reset = qla24xx_abort_target, | |
2410 | .lun_reset = qla24xx_lun_reset, | |
2411 | .fabric_login = qla24xx_login_fabric, | |
2412 | .fabric_logout = qla24xx_fabric_logout, | |
2413 | .calc_req_entries = NULL, | |
2414 | .build_iocbs = NULL, | |
2415 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
2416 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
2417 | .read_nvram = NULL, | |
2418 | .write_nvram = NULL, | |
a1b23c5a | 2419 | .fw_dump = qla8044_fw_dump, |
7ec0effd AD |
2420 | .beacon_on = qla82xx_beacon_on, |
2421 | .beacon_off = qla82xx_beacon_off, | |
2422 | .beacon_blink = NULL, | |
888e639d | 2423 | .read_optrom = qla8044_read_optrom_data, |
7ec0effd AD |
2424 | .write_optrom = qla8044_write_optrom_data, |
2425 | .get_flash_version = qla82xx_get_flash_version, | |
2426 | .start_scsi = qla82xx_start_scsi, | |
d7459527 | 2427 | .start_scsi_mq = NULL, |
7ec0effd AD |
2428 | .abort_isp = qla8044_abort_isp, |
2429 | .iospace_config = qla82xx_iospace_config, | |
2430 | .initialize_adapter = qla2x00_initialize_adapter, | |
2431 | }; | |
2432 | ||
6246b8a1 GM |
2433 | static struct isp_operations qla83xx_isp_ops = { |
2434 | .pci_config = qla25xx_pci_config, | |
2435 | .reset_chip = qla24xx_reset_chip, | |
2436 | .chip_diag = qla24xx_chip_diag, | |
2437 | .config_rings = qla24xx_config_rings, | |
2438 | .reset_adapter = qla24xx_reset_adapter, | |
2439 | .nvram_config = qla81xx_nvram_config, | |
2440 | .update_fw_options = qla81xx_update_fw_options, | |
2441 | .load_risc = qla81xx_load_risc, | |
2442 | .pci_info_str = qla24xx_pci_info_str, | |
2443 | .fw_version_str = qla24xx_fw_version_str, | |
2444 | .intr_handler = qla24xx_intr_handler, | |
2445 | .enable_intrs = qla24xx_enable_intrs, | |
2446 | .disable_intrs = qla24xx_disable_intrs, | |
2447 | .abort_command = qla24xx_abort_command, | |
2448 | .target_reset = qla24xx_abort_target, | |
2449 | .lun_reset = qla24xx_lun_reset, | |
2450 | .fabric_login = qla24xx_login_fabric, | |
2451 | .fabric_logout = qla24xx_fabric_logout, | |
2452 | .calc_req_entries = NULL, | |
2453 | .build_iocbs = NULL, | |
2454 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
2455 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
2456 | .read_nvram = NULL, | |
2457 | .write_nvram = NULL, | |
2458 | .fw_dump = qla83xx_fw_dump, | |
2459 | .beacon_on = qla24xx_beacon_on, | |
2460 | .beacon_off = qla24xx_beacon_off, | |
2461 | .beacon_blink = qla83xx_beacon_blink, | |
2462 | .read_optrom = qla25xx_read_optrom_data, | |
2463 | .write_optrom = qla24xx_write_optrom_data, | |
2464 | .get_flash_version = qla24xx_get_flash_version, | |
2465 | .start_scsi = qla24xx_dif_start_scsi, | |
d7459527 | 2466 | .start_scsi_mq = qla2xxx_dif_start_scsi_mq, |
6246b8a1 GM |
2467 | .abort_isp = qla2x00_abort_isp, |
2468 | .iospace_config = qla83xx_iospace_config, | |
8ae6d9c7 GM |
2469 | .initialize_adapter = qla2x00_initialize_adapter, |
2470 | }; | |
2471 | ||
2472 | static struct isp_operations qlafx00_isp_ops = { | |
2473 | .pci_config = qlafx00_pci_config, | |
2474 | .reset_chip = qlafx00_soft_reset, | |
2475 | .chip_diag = qlafx00_chip_diag, | |
2476 | .config_rings = qlafx00_config_rings, | |
2477 | .reset_adapter = qlafx00_soft_reset, | |
2478 | .nvram_config = NULL, | |
2479 | .update_fw_options = NULL, | |
2480 | .load_risc = NULL, | |
2481 | .pci_info_str = qlafx00_pci_info_str, | |
2482 | .fw_version_str = qlafx00_fw_version_str, | |
2483 | .intr_handler = qlafx00_intr_handler, | |
2484 | .enable_intrs = qlafx00_enable_intrs, | |
2485 | .disable_intrs = qlafx00_disable_intrs, | |
4440e46d | 2486 | .abort_command = qla24xx_async_abort_command, |
8ae6d9c7 GM |
2487 | .target_reset = qlafx00_abort_target, |
2488 | .lun_reset = qlafx00_lun_reset, | |
2489 | .fabric_login = NULL, | |
2490 | .fabric_logout = NULL, | |
2491 | .calc_req_entries = NULL, | |
2492 | .build_iocbs = NULL, | |
2493 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
2494 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
2495 | .read_nvram = qla24xx_read_nvram_data, | |
2496 | .write_nvram = qla24xx_write_nvram_data, | |
2497 | .fw_dump = NULL, | |
2498 | .beacon_on = qla24xx_beacon_on, | |
2499 | .beacon_off = qla24xx_beacon_off, | |
2500 | .beacon_blink = NULL, | |
2501 | .read_optrom = qla24xx_read_optrom_data, | |
2502 | .write_optrom = qla24xx_write_optrom_data, | |
2503 | .get_flash_version = qla24xx_get_flash_version, | |
2504 | .start_scsi = qlafx00_start_scsi, | |
d7459527 | 2505 | .start_scsi_mq = NULL, |
8ae6d9c7 GM |
2506 | .abort_isp = qlafx00_abort_isp, |
2507 | .iospace_config = qlafx00_iospace_config, | |
2508 | .initialize_adapter = qlafx00_initialize_adapter, | |
6246b8a1 GM |
2509 | }; |
2510 | ||
f73cb695 CD |
2511 | static struct isp_operations qla27xx_isp_ops = { |
2512 | .pci_config = qla25xx_pci_config, | |
2513 | .reset_chip = qla24xx_reset_chip, | |
2514 | .chip_diag = qla24xx_chip_diag, | |
2515 | .config_rings = qla24xx_config_rings, | |
2516 | .reset_adapter = qla24xx_reset_adapter, | |
2517 | .nvram_config = qla81xx_nvram_config, | |
a36f1443 | 2518 | .update_fw_options = qla24xx_update_fw_options, |
f73cb695 CD |
2519 | .load_risc = qla81xx_load_risc, |
2520 | .pci_info_str = qla24xx_pci_info_str, | |
2521 | .fw_version_str = qla24xx_fw_version_str, | |
2522 | .intr_handler = qla24xx_intr_handler, | |
2523 | .enable_intrs = qla24xx_enable_intrs, | |
2524 | .disable_intrs = qla24xx_disable_intrs, | |
2525 | .abort_command = qla24xx_abort_command, | |
2526 | .target_reset = qla24xx_abort_target, | |
2527 | .lun_reset = qla24xx_lun_reset, | |
2528 | .fabric_login = qla24xx_login_fabric, | |
2529 | .fabric_logout = qla24xx_fabric_logout, | |
2530 | .calc_req_entries = NULL, | |
2531 | .build_iocbs = NULL, | |
2532 | .prep_ms_iocb = qla24xx_prep_ms_iocb, | |
2533 | .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb, | |
2534 | .read_nvram = NULL, | |
2535 | .write_nvram = NULL, | |
2536 | .fw_dump = qla27xx_fwdump, | |
2537 | .beacon_on = qla24xx_beacon_on, | |
2538 | .beacon_off = qla24xx_beacon_off, | |
2539 | .beacon_blink = qla83xx_beacon_blink, | |
2540 | .read_optrom = qla25xx_read_optrom_data, | |
2541 | .write_optrom = qla24xx_write_optrom_data, | |
2542 | .get_flash_version = qla24xx_get_flash_version, | |
2543 | .start_scsi = qla24xx_dif_start_scsi, | |
d7459527 | 2544 | .start_scsi_mq = qla2xxx_dif_start_scsi_mq, |
f73cb695 CD |
2545 | .abort_isp = qla2x00_abort_isp, |
2546 | .iospace_config = qla83xx_iospace_config, | |
2547 | .initialize_adapter = qla2x00_initialize_adapter, | |
2548 | }; | |
2549 | ||
ea5b6382 | 2550 | static inline void |
e315cd28 | 2551 | qla2x00_set_isp_flags(struct qla_hw_data *ha) |
ea5b6382 AV |
2552 | { |
2553 | ha->device_type = DT_EXTENDED_IDS; | |
2554 | switch (ha->pdev->device) { | |
2555 | case PCI_DEVICE_ID_QLOGIC_ISP2100: | |
9e052e2d | 2556 | ha->isp_type |= DT_ISP2100; |
ea5b6382 | 2557 | ha->device_type &= ~DT_EXTENDED_IDS; |
441d1072 | 2558 | ha->fw_srisc_address = RISC_START_ADDRESS_2100; |
ea5b6382 AV |
2559 | break; |
2560 | case PCI_DEVICE_ID_QLOGIC_ISP2200: | |
9e052e2d | 2561 | ha->isp_type |= DT_ISP2200; |
ea5b6382 | 2562 | ha->device_type &= ~DT_EXTENDED_IDS; |
441d1072 | 2563 | ha->fw_srisc_address = RISC_START_ADDRESS_2100; |
ea5b6382 AV |
2564 | break; |
2565 | case PCI_DEVICE_ID_QLOGIC_ISP2300: | |
9e052e2d | 2566 | ha->isp_type |= DT_ISP2300; |
4a59f71d | 2567 | ha->device_type |= DT_ZIO_SUPPORTED; |
441d1072 | 2568 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
2569 | break; |
2570 | case PCI_DEVICE_ID_QLOGIC_ISP2312: | |
9e052e2d | 2571 | ha->isp_type |= DT_ISP2312; |
4a59f71d | 2572 | ha->device_type |= DT_ZIO_SUPPORTED; |
441d1072 | 2573 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
2574 | break; |
2575 | case PCI_DEVICE_ID_QLOGIC_ISP2322: | |
9e052e2d | 2576 | ha->isp_type |= DT_ISP2322; |
4a59f71d | 2577 | ha->device_type |= DT_ZIO_SUPPORTED; |
ea5b6382 AV |
2578 | if (ha->pdev->subsystem_vendor == 0x1028 && |
2579 | ha->pdev->subsystem_device == 0x0170) | |
2580 | ha->device_type |= DT_OEM_001; | |
441d1072 | 2581 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
2582 | break; |
2583 | case PCI_DEVICE_ID_QLOGIC_ISP6312: | |
9e052e2d | 2584 | ha->isp_type |= DT_ISP6312; |
441d1072 | 2585 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
2586 | break; |
2587 | case PCI_DEVICE_ID_QLOGIC_ISP6322: | |
9e052e2d | 2588 | ha->isp_type |= DT_ISP6322; |
441d1072 | 2589 | ha->fw_srisc_address = RISC_START_ADDRESS_2300; |
ea5b6382 AV |
2590 | break; |
2591 | case PCI_DEVICE_ID_QLOGIC_ISP2422: | |
9e052e2d | 2592 | ha->isp_type |= DT_ISP2422; |
4a59f71d | 2593 | ha->device_type |= DT_ZIO_SUPPORTED; |
e428924c | 2594 | ha->device_type |= DT_FWI2; |
c76f2c01 | 2595 | ha->device_type |= DT_IIDMA; |
441d1072 | 2596 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 AV |
2597 | break; |
2598 | case PCI_DEVICE_ID_QLOGIC_ISP2432: | |
9e052e2d | 2599 | ha->isp_type |= DT_ISP2432; |
4a59f71d | 2600 | ha->device_type |= DT_ZIO_SUPPORTED; |
e428924c | 2601 | ha->device_type |= DT_FWI2; |
c76f2c01 | 2602 | ha->device_type |= DT_IIDMA; |
441d1072 | 2603 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 | 2604 | break; |
4d4df193 | 2605 | case PCI_DEVICE_ID_QLOGIC_ISP8432: |
9e052e2d | 2606 | ha->isp_type |= DT_ISP8432; |
4d4df193 HK |
2607 | ha->device_type |= DT_ZIO_SUPPORTED; |
2608 | ha->device_type |= DT_FWI2; | |
2609 | ha->device_type |= DT_IIDMA; | |
2610 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
2611 | break; | |
044cc6c8 | 2612 | case PCI_DEVICE_ID_QLOGIC_ISP5422: |
9e052e2d | 2613 | ha->isp_type |= DT_ISP5422; |
e428924c | 2614 | ha->device_type |= DT_FWI2; |
441d1072 | 2615 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 | 2616 | break; |
044cc6c8 | 2617 | case PCI_DEVICE_ID_QLOGIC_ISP5432: |
9e052e2d | 2618 | ha->isp_type |= DT_ISP5432; |
e428924c | 2619 | ha->device_type |= DT_FWI2; |
441d1072 | 2620 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 | 2621 | break; |
c3a2f0df | 2622 | case PCI_DEVICE_ID_QLOGIC_ISP2532: |
9e052e2d | 2623 | ha->isp_type |= DT_ISP2532; |
c3a2f0df AV |
2624 | ha->device_type |= DT_ZIO_SUPPORTED; |
2625 | ha->device_type |= DT_FWI2; | |
2626 | ha->device_type |= DT_IIDMA; | |
441d1072 | 2627 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
ea5b6382 | 2628 | break; |
3a03eb79 | 2629 | case PCI_DEVICE_ID_QLOGIC_ISP8001: |
9e052e2d | 2630 | ha->isp_type |= DT_ISP8001; |
3a03eb79 AV |
2631 | ha->device_type |= DT_ZIO_SUPPORTED; |
2632 | ha->device_type |= DT_FWI2; | |
2633 | ha->device_type |= DT_IIDMA; | |
2634 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
2635 | break; | |
a9083016 | 2636 | case PCI_DEVICE_ID_QLOGIC_ISP8021: |
9e052e2d | 2637 | ha->isp_type |= DT_ISP8021; |
a9083016 GM |
2638 | ha->device_type |= DT_ZIO_SUPPORTED; |
2639 | ha->device_type |= DT_FWI2; | |
2640 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
2641 | /* Initialize 82XX ISP flags */ | |
2642 | qla82xx_init_flags(ha); | |
2643 | break; | |
7ec0effd | 2644 | case PCI_DEVICE_ID_QLOGIC_ISP8044: |
9e052e2d | 2645 | ha->isp_type |= DT_ISP8044; |
7ec0effd AD |
2646 | ha->device_type |= DT_ZIO_SUPPORTED; |
2647 | ha->device_type |= DT_FWI2; | |
2648 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
2649 | /* Initialize 82XX ISP flags */ | |
2650 | qla82xx_init_flags(ha); | |
2651 | break; | |
6246b8a1 | 2652 | case PCI_DEVICE_ID_QLOGIC_ISP2031: |
9e052e2d | 2653 | ha->isp_type |= DT_ISP2031; |
6246b8a1 GM |
2654 | ha->device_type |= DT_ZIO_SUPPORTED; |
2655 | ha->device_type |= DT_FWI2; | |
2656 | ha->device_type |= DT_IIDMA; | |
2657 | ha->device_type |= DT_T10_PI; | |
2658 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
2659 | break; | |
2660 | case PCI_DEVICE_ID_QLOGIC_ISP8031: | |
9e052e2d | 2661 | ha->isp_type |= DT_ISP8031; |
6246b8a1 GM |
2662 | ha->device_type |= DT_ZIO_SUPPORTED; |
2663 | ha->device_type |= DT_FWI2; | |
2664 | ha->device_type |= DT_IIDMA; | |
2665 | ha->device_type |= DT_T10_PI; | |
2666 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
2667 | break; | |
8ae6d9c7 | 2668 | case PCI_DEVICE_ID_QLOGIC_ISPF001: |
9e052e2d | 2669 | ha->isp_type |= DT_ISPFX00; |
8ae6d9c7 | 2670 | break; |
f73cb695 | 2671 | case PCI_DEVICE_ID_QLOGIC_ISP2071: |
9e052e2d | 2672 | ha->isp_type |= DT_ISP2071; |
f73cb695 CD |
2673 | ha->device_type |= DT_ZIO_SUPPORTED; |
2674 | ha->device_type |= DT_FWI2; | |
2675 | ha->device_type |= DT_IIDMA; | |
8ce3f570 | 2676 | ha->device_type |= DT_T10_PI; |
f73cb695 CD |
2677 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
2678 | break; | |
2c5bbbb2 | 2679 | case PCI_DEVICE_ID_QLOGIC_ISP2271: |
9e052e2d | 2680 | ha->isp_type |= DT_ISP2271; |
2c5bbbb2 JC |
2681 | ha->device_type |= DT_ZIO_SUPPORTED; |
2682 | ha->device_type |= DT_FWI2; | |
2683 | ha->device_type |= DT_IIDMA; | |
8ce3f570 | 2684 | ha->device_type |= DT_T10_PI; |
2c5bbbb2 JC |
2685 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
2686 | break; | |
2b48992f | 2687 | case PCI_DEVICE_ID_QLOGIC_ISP2261: |
9e052e2d | 2688 | ha->isp_type |= DT_ISP2261; |
2b48992f SC |
2689 | ha->device_type |= DT_ZIO_SUPPORTED; |
2690 | ha->device_type |= DT_FWI2; | |
2691 | ha->device_type |= DT_IIDMA; | |
8ce3f570 | 2692 | ha->device_type |= DT_T10_PI; |
2b48992f SC |
2693 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; |
2694 | break; | |
ecc89f25 JC |
2695 | case PCI_DEVICE_ID_QLOGIC_ISP2081: |
2696 | case PCI_DEVICE_ID_QLOGIC_ISP2089: | |
2697 | ha->isp_type |= DT_ISP2081; | |
2698 | ha->device_type |= DT_ZIO_SUPPORTED; | |
2699 | ha->device_type |= DT_FWI2; | |
2700 | ha->device_type |= DT_IIDMA; | |
2701 | ha->device_type |= DT_T10_PI; | |
2702 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
2703 | break; | |
2704 | case PCI_DEVICE_ID_QLOGIC_ISP2281: | |
2705 | case PCI_DEVICE_ID_QLOGIC_ISP2289: | |
2706 | ha->isp_type |= DT_ISP2281; | |
2707 | ha->device_type |= DT_ZIO_SUPPORTED; | |
2708 | ha->device_type |= DT_FWI2; | |
2709 | ha->device_type |= DT_IIDMA; | |
2710 | ha->device_type |= DT_T10_PI; | |
2711 | ha->fw_srisc_address = RISC_START_ADDRESS_2400; | |
2712 | break; | |
ea5b6382 | 2713 | } |
e5b68a61 | 2714 | |
a9083016 | 2715 | if (IS_QLA82XX(ha)) |
43a9c38b | 2716 | ha->port_no = ha->portnum & 1; |
f73cb695 | 2717 | else { |
a9083016 GM |
2718 | /* Get adapter physical port no from interrupt pin register. */ |
2719 | pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no); | |
ecc89f25 JC |
2720 | if (IS_QLA25XX(ha) || IS_QLA2031(ha) || |
2721 | IS_QLA27XX(ha) || IS_QLA28XX(ha)) | |
f73cb695 CD |
2722 | ha->port_no--; |
2723 | else | |
2724 | ha->port_no = !(ha->port_no & 1); | |
2725 | } | |
a9083016 | 2726 | |
7c3df132 | 2727 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b, |
d8424f68 | 2728 | "device_type=0x%x port=%d fw_srisc_address=0x%x.\n", |
f73cb695 | 2729 | ha->device_type, ha->port_no, ha->fw_srisc_address); |
ea5b6382 AV |
2730 | } |
2731 | ||
1e99e33a AV |
2732 | static void |
2733 | qla2xxx_scan_start(struct Scsi_Host *shost) | |
2734 | { | |
e315cd28 | 2735 | scsi_qla_host_t *vha = shost_priv(shost); |
1e99e33a | 2736 | |
cbc8eb67 AV |
2737 | if (vha->hw->flags.running_gold_fw) |
2738 | return; | |
2739 | ||
e315cd28 AC |
2740 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
2741 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | |
2742 | set_bit(RSCN_UPDATE, &vha->dpc_flags); | |
2743 | set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags); | |
1e99e33a AV |
2744 | } |
2745 | ||
2746 | static int | |
2747 | qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time) | |
2748 | { | |
e315cd28 | 2749 | scsi_qla_host_t *vha = shost_priv(shost); |
1e99e33a | 2750 | |
a5dd506e BK |
2751 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
2752 | return 1; | |
e315cd28 | 2753 | if (!vha->host) |
1e99e33a | 2754 | return 1; |
e315cd28 | 2755 | if (time > vha->hw->loop_reset_delay * HZ) |
1e99e33a AV |
2756 | return 1; |
2757 | ||
e315cd28 | 2758 | return atomic_read(&vha->loop_state) == LOOP_READY; |
1e99e33a AV |
2759 | } |
2760 | ||
ec7193e2 QT |
2761 | static void qla2x00_iocb_work_fn(struct work_struct *work) |
2762 | { | |
2763 | struct scsi_qla_host *vha = container_of(work, | |
2764 | struct scsi_qla_host, iocb_work); | |
9b3e0f4d QT |
2765 | struct qla_hw_data *ha = vha->hw; |
2766 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
0aca7784 | 2767 | int i = 2; |
9b3e0f4d QT |
2768 | unsigned long flags; |
2769 | ||
2770 | if (test_bit(UNLOADING, &base_vha->dpc_flags)) | |
2771 | return; | |
ec7193e2 | 2772 | |
9b3e0f4d | 2773 | while (!list_empty(&vha->work_list) && i > 0) { |
ec7193e2 | 2774 | qla2x00_do_work(vha); |
9b3e0f4d | 2775 | i--; |
ec7193e2 | 2776 | } |
9b3e0f4d QT |
2777 | |
2778 | spin_lock_irqsave(&vha->work_lock, flags); | |
2779 | clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags); | |
2780 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
ec7193e2 QT |
2781 | } |
2782 | ||
1da177e4 LT |
2783 | /* |
2784 | * PCI driver interface | |
2785 | */ | |
6f039790 | 2786 | static int |
7ee61397 | 2787 | qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) |
1da177e4 | 2788 | { |
a1541d5a | 2789 | int ret = -ENODEV; |
1da177e4 | 2790 | struct Scsi_Host *host; |
e315cd28 AC |
2791 | scsi_qla_host_t *base_vha = NULL; |
2792 | struct qla_hw_data *ha; | |
29856e28 | 2793 | char pci_info[30]; |
7d613ac6 | 2794 | char fw_str[30], wq_name[30]; |
5433383e | 2795 | struct scsi_host_template *sht; |
642ef983 | 2796 | int bars, mem_only = 0; |
e315cd28 | 2797 | uint16_t req_length = 0, rsp_length = 0; |
73208dfd AC |
2798 | struct req_que *req = NULL; |
2799 | struct rsp_que *rsp = NULL; | |
5601236b | 2800 | int i; |
d7459527 | 2801 | |
285d0321 | 2802 | bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); |
a5326f86 | 2803 | sht = &qla2xxx_driver_template; |
5433383e | 2804 | if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 || |
8bc69e7d | 2805 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 || |
4d4df193 | 2806 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 || |
8bc69e7d | 2807 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 || |
c3a2f0df | 2808 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 || |
3a03eb79 | 2809 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 || |
a9083016 | 2810 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 || |
6246b8a1 GM |
2811 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 || |
2812 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 || | |
8ae6d9c7 | 2813 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 || |
7ec0effd | 2814 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 || |
f73cb695 | 2815 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 || |
2c5bbbb2 | 2816 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 || |
2b48992f | 2817 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 || |
ecc89f25 JC |
2818 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 || |
2819 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 || | |
2820 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 || | |
2821 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 || | |
2822 | pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) { | |
285d0321 | 2823 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
09483916 | 2824 | mem_only = 1; |
7c3df132 SK |
2825 | ql_dbg_pci(ql_dbg_init, pdev, 0x0007, |
2826 | "Mem only adapter.\n"); | |
285d0321 | 2827 | } |
7c3df132 SK |
2828 | ql_dbg_pci(ql_dbg_init, pdev, 0x0008, |
2829 | "Bars=%d.\n", bars); | |
285d0321 | 2830 | |
09483916 BH |
2831 | if (mem_only) { |
2832 | if (pci_enable_device_mem(pdev)) | |
ddff7ed4 | 2833 | return ret; |
09483916 BH |
2834 | } else { |
2835 | if (pci_enable_device(pdev)) | |
ddff7ed4 | 2836 | return ret; |
09483916 | 2837 | } |
285d0321 | 2838 | |
0927678f JB |
2839 | /* This may fail but that's ok */ |
2840 | pci_enable_pcie_error_reporting(pdev); | |
285d0321 | 2841 | |
5da05a26 GM |
2842 | /* Turn off T10-DIF when FC-NVMe is enabled */ |
2843 | if (ql2xnvmeenable) | |
2844 | ql2xenabledif = 0; | |
2845 | ||
e315cd28 AC |
2846 | ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL); |
2847 | if (!ha) { | |
7c3df132 SK |
2848 | ql_log_pci(ql_log_fatal, pdev, 0x0009, |
2849 | "Unable to allocate memory for ha.\n"); | |
ddff7ed4 | 2850 | goto disable_device; |
1da177e4 | 2851 | } |
7c3df132 SK |
2852 | ql_dbg_pci(ql_dbg_init, pdev, 0x000a, |
2853 | "Memory allocated for ha=%p.\n", ha); | |
e315cd28 | 2854 | ha->pdev = pdev; |
33e79977 QT |
2855 | INIT_LIST_HEAD(&ha->tgt.q_full_list); |
2856 | spin_lock_init(&ha->tgt.q_full_lock); | |
7560151b | 2857 | spin_lock_init(&ha->tgt.sess_lock); |
2f424b9b QT |
2858 | spin_lock_init(&ha->tgt.atio_lock); |
2859 | ||
deeae7a6 | 2860 | atomic_set(&ha->nvme_active_aen_cnt, 0); |
1da177e4 LT |
2861 | |
2862 | /* Clear our data area */ | |
285d0321 | 2863 | ha->bars = bars; |
09483916 | 2864 | ha->mem_only = mem_only; |
df4bf0bb | 2865 | spin_lock_init(&ha->hardware_lock); |
339aa70e | 2866 | spin_lock_init(&ha->vport_slock); |
a9b6f722 | 2867 | mutex_init(&ha->selflogin_lock); |
7a8ab9c8 | 2868 | mutex_init(&ha->optrom_mutex); |
1da177e4 | 2869 | |
ea5b6382 AV |
2870 | /* Set ISP-type information. */ |
2871 | qla2x00_set_isp_flags(ha); | |
ca79cf66 DG |
2872 | |
2873 | /* Set EEH reset type to fundamental if required by hba */ | |
95676112 | 2874 | if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) || |
ecc89f25 | 2875 | IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) |
ca79cf66 | 2876 | pdev->needs_freset = 1; |
ca79cf66 | 2877 | |
cba1e47f CD |
2878 | ha->prev_topology = 0; |
2879 | ha->init_cb_size = sizeof(init_cb_t); | |
2880 | ha->link_data_rate = PORT_SPEED_UNKNOWN; | |
2881 | ha->optrom_size = OPTROM_SIZE_2300; | |
d1e3635a | 2882 | ha->max_exchg = FW_MAX_EXCHANGES_CNT; |
b2000805 QT |
2883 | atomic_set(&ha->num_pend_mbx_stage1, 0); |
2884 | atomic_set(&ha->num_pend_mbx_stage2, 0); | |
2885 | atomic_set(&ha->num_pend_mbx_stage3, 0); | |
8b4673ba QT |
2886 | atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD); |
2887 | ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD; | |
cba1e47f | 2888 | |
abbd8870 | 2889 | /* Assign ISP specific operations. */ |
1da177e4 | 2890 | if (IS_QLA2100(ha)) { |
642ef983 | 2891 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100; |
1da177e4 | 2892 | ha->mbx_count = MAILBOX_REGISTER_COUNT_2100; |
e315cd28 AC |
2893 | req_length = REQUEST_ENTRY_CNT_2100; |
2894 | rsp_length = RESPONSE_ENTRY_CNT_2100; | |
2895 | ha->max_loop_id = SNS_LAST_LOOP_ID_2100; | |
abbd8870 | 2896 | ha->gid_list_info_size = 4; |
3a03eb79 AV |
2897 | ha->flash_conf_off = ~0; |
2898 | ha->flash_data_off = ~0; | |
2899 | ha->nvram_conf_off = ~0; | |
2900 | ha->nvram_data_off = ~0; | |
fd34f556 | 2901 | ha->isp_ops = &qla2100_isp_ops; |
1da177e4 | 2902 | } else if (IS_QLA2200(ha)) { |
642ef983 | 2903 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100; |
67ddda35 | 2904 | ha->mbx_count = MAILBOX_REGISTER_COUNT_2200; |
e315cd28 AC |
2905 | req_length = REQUEST_ENTRY_CNT_2200; |
2906 | rsp_length = RESPONSE_ENTRY_CNT_2100; | |
2907 | ha->max_loop_id = SNS_LAST_LOOP_ID_2100; | |
abbd8870 | 2908 | ha->gid_list_info_size = 4; |
3a03eb79 AV |
2909 | ha->flash_conf_off = ~0; |
2910 | ha->flash_data_off = ~0; | |
2911 | ha->nvram_conf_off = ~0; | |
2912 | ha->nvram_data_off = ~0; | |
fd34f556 | 2913 | ha->isp_ops = &qla2100_isp_ops; |
fca29703 | 2914 | } else if (IS_QLA23XX(ha)) { |
642ef983 | 2915 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100; |
1da177e4 | 2916 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
e315cd28 AC |
2917 | req_length = REQUEST_ENTRY_CNT_2200; |
2918 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
2919 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | |
abbd8870 | 2920 | ha->gid_list_info_size = 6; |
854165f4 AV |
2921 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
2922 | ha->optrom_size = OPTROM_SIZE_2322; | |
3a03eb79 AV |
2923 | ha->flash_conf_off = ~0; |
2924 | ha->flash_data_off = ~0; | |
2925 | ha->nvram_conf_off = ~0; | |
2926 | ha->nvram_data_off = ~0; | |
fd34f556 | 2927 | ha->isp_ops = &qla2300_isp_ops; |
4d4df193 | 2928 | } else if (IS_QLA24XX_TYPE(ha)) { |
642ef983 | 2929 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400; |
fca29703 | 2930 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
e315cd28 AC |
2931 | req_length = REQUEST_ENTRY_CNT_24XX; |
2932 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
2d70c103 | 2933 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
e315cd28 | 2934 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
2c3dfe3f | 2935 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
fca29703 | 2936 | ha->gid_list_info_size = 8; |
854165f4 | 2937 | ha->optrom_size = OPTROM_SIZE_24XX; |
73208dfd | 2938 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX; |
fd34f556 | 2939 | ha->isp_ops = &qla24xx_isp_ops; |
3a03eb79 AV |
2940 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; |
2941 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; | |
2942 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; | |
2943 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; | |
c3a2f0df | 2944 | } else if (IS_QLA25XX(ha)) { |
642ef983 | 2945 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400; |
c3a2f0df | 2946 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
e315cd28 AC |
2947 | req_length = REQUEST_ENTRY_CNT_24XX; |
2948 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
2d70c103 | 2949 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
e315cd28 | 2950 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
c3a2f0df | 2951 | ha->init_cb_size = sizeof(struct mid_init_cb_24xx); |
c3a2f0df AV |
2952 | ha->gid_list_info_size = 8; |
2953 | ha->optrom_size = OPTROM_SIZE_25XX; | |
73208dfd | 2954 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; |
c3a2f0df | 2955 | ha->isp_ops = &qla25xx_isp_ops; |
3a03eb79 AV |
2956 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; |
2957 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; | |
2958 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; | |
2959 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; | |
2960 | } else if (IS_QLA81XX(ha)) { | |
642ef983 | 2961 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400; |
3a03eb79 AV |
2962 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
2963 | req_length = REQUEST_ENTRY_CNT_24XX; | |
2964 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
aa230bc5 | 2965 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
3a03eb79 AV |
2966 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
2967 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); | |
2968 | ha->gid_list_info_size = 8; | |
2969 | ha->optrom_size = OPTROM_SIZE_81XX; | |
40859ae5 | 2970 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; |
3a03eb79 AV |
2971 | ha->isp_ops = &qla81xx_isp_ops; |
2972 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX; | |
2973 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX; | |
2974 | ha->nvram_conf_off = ~0; | |
2975 | ha->nvram_data_off = ~0; | |
a9083016 | 2976 | } else if (IS_QLA82XX(ha)) { |
642ef983 | 2977 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400; |
a9083016 GM |
2978 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
2979 | req_length = REQUEST_ENTRY_CNT_82XX; | |
2980 | rsp_length = RESPONSE_ENTRY_CNT_82XX; | |
2981 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | |
2982 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); | |
2983 | ha->gid_list_info_size = 8; | |
2984 | ha->optrom_size = OPTROM_SIZE_82XX; | |
087c621e | 2985 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; |
a9083016 GM |
2986 | ha->isp_ops = &qla82xx_isp_ops; |
2987 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; | |
2988 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; | |
2989 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; | |
2990 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; | |
7ec0effd AD |
2991 | } else if (IS_QLA8044(ha)) { |
2992 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400; | |
2993 | ha->mbx_count = MAILBOX_REGISTER_COUNT; | |
2994 | req_length = REQUEST_ENTRY_CNT_82XX; | |
2995 | rsp_length = RESPONSE_ENTRY_CNT_82XX; | |
2996 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | |
2997 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); | |
2998 | ha->gid_list_info_size = 8; | |
2999 | ha->optrom_size = OPTROM_SIZE_83XX; | |
3000 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; | |
3001 | ha->isp_ops = &qla8044_isp_ops; | |
3002 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF; | |
3003 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA; | |
3004 | ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF; | |
3005 | ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA; | |
6246b8a1 | 3006 | } else if (IS_QLA83XX(ha)) { |
7d613ac6 | 3007 | ha->portnum = PCI_FUNC(ha->pdev->devfn); |
642ef983 | 3008 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400; |
6246b8a1 | 3009 | ha->mbx_count = MAILBOX_REGISTER_COUNT; |
f2ea653f | 3010 | req_length = REQUEST_ENTRY_CNT_83XX; |
e7b42e33 | 3011 | rsp_length = RESPONSE_ENTRY_CNT_83XX; |
b8aa4bdf | 3012 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
6246b8a1 GM |
3013 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
3014 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); | |
3015 | ha->gid_list_info_size = 8; | |
3016 | ha->optrom_size = OPTROM_SIZE_83XX; | |
3017 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; | |
3018 | ha->isp_ops = &qla83xx_isp_ops; | |
3019 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX; | |
3020 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX; | |
3021 | ha->nvram_conf_off = ~0; | |
3022 | ha->nvram_data_off = ~0; | |
8ae6d9c7 GM |
3023 | } else if (IS_QLAFX00(ha)) { |
3024 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00; | |
3025 | ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00; | |
3026 | ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00; | |
3027 | req_length = REQUEST_ENTRY_CNT_FX00; | |
3028 | rsp_length = RESPONSE_ENTRY_CNT_FX00; | |
8ae6d9c7 GM |
3029 | ha->isp_ops = &qlafx00_isp_ops; |
3030 | ha->port_down_retry_count = 30; /* default value */ | |
3031 | ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL; | |
3032 | ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL; | |
71e56003 | 3033 | ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL; |
8ae6d9c7 | 3034 | ha->mr.fw_hbt_en = 1; |
e8f5e95d AB |
3035 | ha->mr.host_info_resend = false; |
3036 | ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL; | |
f73cb695 CD |
3037 | } else if (IS_QLA27XX(ha)) { |
3038 | ha->portnum = PCI_FUNC(ha->pdev->devfn); | |
3039 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400; | |
3040 | ha->mbx_count = MAILBOX_REGISTER_COUNT; | |
e7b42e33 QT |
3041 | req_length = REQUEST_ENTRY_CNT_83XX; |
3042 | rsp_length = RESPONSE_ENTRY_CNT_83XX; | |
b20f02e1 | 3043 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; |
f73cb695 CD |
3044 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; |
3045 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); | |
3046 | ha->gid_list_info_size = 8; | |
3047 | ha->optrom_size = OPTROM_SIZE_83XX; | |
3048 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; | |
3049 | ha->isp_ops = &qla27xx_isp_ops; | |
3050 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX; | |
3051 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX; | |
3052 | ha->nvram_conf_off = ~0; | |
3053 | ha->nvram_data_off = ~0; | |
ecc89f25 JC |
3054 | } else if (IS_QLA28XX(ha)) { |
3055 | ha->portnum = PCI_FUNC(ha->pdev->devfn); | |
3056 | ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400; | |
3057 | ha->mbx_count = MAILBOX_REGISTER_COUNT; | |
3058 | req_length = REQUEST_ENTRY_CNT_24XX; | |
3059 | rsp_length = RESPONSE_ENTRY_CNT_2300; | |
3060 | ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX; | |
3061 | ha->max_loop_id = SNS_LAST_LOOP_ID_2300; | |
3062 | ha->init_cb_size = sizeof(struct mid_init_cb_81xx); | |
3063 | ha->gid_list_info_size = 8; | |
3064 | ha->optrom_size = OPTROM_SIZE_28XX; | |
3065 | ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX; | |
3066 | ha->isp_ops = &qla27xx_isp_ops; | |
3067 | ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX; | |
3068 | ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX; | |
3069 | ha->nvram_conf_off = ~0; | |
3070 | ha->nvram_data_off = ~0; | |
1da177e4 | 3071 | } |
6246b8a1 | 3072 | |
7c3df132 SK |
3073 | ql_dbg_pci(ql_dbg_init, pdev, 0x001e, |
3074 | "mbx_count=%d, req_length=%d, " | |
3075 | "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, " | |
642ef983 CD |
3076 | "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, " |
3077 | "max_fibre_devices=%d.\n", | |
7c3df132 SK |
3078 | ha->mbx_count, req_length, rsp_length, ha->max_loop_id, |
3079 | ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size, | |
642ef983 | 3080 | ha->nvram_npiv_size, ha->max_fibre_devices); |
7c3df132 SK |
3081 | ql_dbg_pci(ql_dbg_init, pdev, 0x001f, |
3082 | "isp_ops=%p, flash_conf_off=%d, " | |
3083 | "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n", | |
3084 | ha->isp_ops, ha->flash_conf_off, ha->flash_data_off, | |
3085 | ha->nvram_conf_off, ha->nvram_data_off); | |
706f457d GM |
3086 | |
3087 | /* Configure PCI I/O space */ | |
3088 | ret = ha->isp_ops->iospace_config(ha); | |
3089 | if (ret) | |
0a63ad12 | 3090 | goto iospace_config_failed; |
706f457d GM |
3091 | |
3092 | ql_log_pci(ql_log_info, pdev, 0x001d, | |
3093 | "Found an ISP%04X irq %d iobase 0x%p.\n", | |
3094 | pdev->device, pdev->irq, ha->iobase); | |
6c2f527c | 3095 | mutex_init(&ha->vport_lock); |
d7459527 | 3096 | mutex_init(&ha->mq_lock); |
0b05a1f0 MB |
3097 | init_completion(&ha->mbx_cmd_comp); |
3098 | complete(&ha->mbx_cmd_comp); | |
3099 | init_completion(&ha->mbx_intr_comp); | |
23f2ebd1 | 3100 | init_completion(&ha->dcbx_comp); |
f356bef1 | 3101 | init_completion(&ha->lb_portup_comp); |
1da177e4 | 3102 | |
2c3dfe3f | 3103 | set_bit(0, (unsigned long *) ha->vp_idx_map); |
1da177e4 | 3104 | |
53303c42 | 3105 | qla2x00_config_dma_addressing(ha); |
7c3df132 SK |
3106 | ql_dbg_pci(ql_dbg_init, pdev, 0x0020, |
3107 | "64 Bit addressing is %s.\n", | |
3108 | ha->flags.enable_64bit_addressing ? "enable" : | |
3109 | "disable"); | |
73208dfd | 3110 | ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp); |
b2a72ec3 | 3111 | if (ret) { |
7c3df132 SK |
3112 | ql_log_pci(ql_log_fatal, pdev, 0x0031, |
3113 | "Failed to allocate memory for adapter, aborting.\n"); | |
1da177e4 | 3114 | |
e315cd28 AC |
3115 | goto probe_hw_failed; |
3116 | } | |
3117 | ||
73208dfd | 3118 | req->max_q_depth = MAX_Q_DEPTH; |
e315cd28 | 3119 | if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU) |
73208dfd AC |
3120 | req->max_q_depth = ql2xmaxqdepth; |
3121 | ||
e315cd28 AC |
3122 | |
3123 | base_vha = qla2x00_create_host(sht, ha); | |
3124 | if (!base_vha) { | |
a1541d5a | 3125 | ret = -ENOMEM; |
e315cd28 | 3126 | goto probe_hw_failed; |
1da177e4 LT |
3127 | } |
3128 | ||
e315cd28 | 3129 | pci_set_drvdata(pdev, base_vha); |
6b383979 | 3130 | set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags); |
e315cd28 | 3131 | |
e315cd28 | 3132 | host = base_vha->host; |
2afa19a9 | 3133 | base_vha->req = req; |
73208dfd | 3134 | if (IS_QLA2XXX_MIDTYPE(ha)) |
f6602f3b QT |
3135 | base_vha->mgmt_svr_loop_id = |
3136 | qla2x00_reserve_mgmt_server_loop_id(base_vha); | |
73208dfd | 3137 | else |
e315cd28 AC |
3138 | base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER + |
3139 | base_vha->vp_idx; | |
58548cb5 | 3140 | |
8ae6d9c7 GM |
3141 | /* Setup fcport template structure. */ |
3142 | ha->mr.fcport.vha = base_vha; | |
3143 | ha->mr.fcport.port_type = FCT_UNKNOWN; | |
3144 | ha->mr.fcport.loop_id = FC_NO_LOOP_ID; | |
3145 | qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED); | |
3146 | ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED; | |
3147 | ha->mr.fcport.scan_state = 1; | |
3148 | ||
58548cb5 GM |
3149 | /* Set the SG table size based on ISP type */ |
3150 | if (!IS_FWI2_CAPABLE(ha)) { | |
3151 | if (IS_QLA2100(ha)) | |
3152 | host->sg_tablesize = 32; | |
3153 | } else { | |
3154 | if (!IS_QLA82XX(ha)) | |
3155 | host->sg_tablesize = QLA_SG_ALL; | |
3156 | } | |
642ef983 | 3157 | host->max_id = ha->max_fibre_devices; |
e315cd28 AC |
3158 | host->cmd_per_lun = 3; |
3159 | host->unique_id = host->host_no; | |
e02587d7 | 3160 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) |
0c470874 AE |
3161 | host->max_cmd_len = 32; |
3162 | else | |
3163 | host->max_cmd_len = MAX_CMDSZ; | |
e315cd28 | 3164 | host->max_channel = MAX_BUSES - 1; |
755f516b HR |
3165 | /* Older HBAs support only 16-bit LUNs */ |
3166 | if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) && | |
3167 | ql2xmaxlun > 0xffff) | |
3168 | host->max_lun = 0xffff; | |
3169 | else | |
3170 | host->max_lun = ql2xmaxlun; | |
e315cd28 | 3171 | host->transportt = qla2xxx_transport_template; |
9a069e19 | 3172 | sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC); |
e315cd28 | 3173 | |
7c3df132 SK |
3174 | ql_dbg(ql_dbg_init, base_vha, 0x0033, |
3175 | "max_id=%d this_id=%d " | |
3176 | "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d " | |
1abf635d | 3177 | "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id, |
7c3df132 SK |
3178 | host->this_id, host->cmd_per_lun, host->unique_id, |
3179 | host->max_cmd_len, host->max_channel, host->max_lun, | |
3180 | host->transportt, sht->vendor_id); | |
3181 | ||
1010f21e HM |
3182 | INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn); |
3183 | ||
d7459527 MH |
3184 | /* Set up the irqs */ |
3185 | ret = qla2x00_request_irqs(ha, rsp); | |
3186 | if (ret) | |
6a2cf8d3 | 3187 | goto probe_failed; |
d7459527 | 3188 | |
9a347ff4 | 3189 | /* Alloc arrays of request and response ring ptrs */ |
6d634067 BK |
3190 | ret = qla2x00_alloc_queues(ha, req, rsp); |
3191 | if (ret) { | |
9a347ff4 CD |
3192 | ql_log(ql_log_fatal, base_vha, 0x003d, |
3193 | "Failed to allocate memory for queue pointers..." | |
3194 | "aborting.\n"); | |
26a77799 | 3195 | ret = -ENODEV; |
6a2cf8d3 | 3196 | goto probe_failed; |
9a347ff4 CD |
3197 | } |
3198 | ||
f664a3cc | 3199 | if (ha->mqenable) { |
5601236b MH |
3200 | /* number of hardware queues supported by blk/scsi-mq*/ |
3201 | host->nr_hw_queues = ha->max_qpairs; | |
3202 | ||
3203 | ql_dbg(ql_dbg_init, base_vha, 0x0192, | |
3204 | "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues); | |
c38d1baf HM |
3205 | } else { |
3206 | if (ql2xnvmeenable) { | |
3207 | host->nr_hw_queues = ha->max_qpairs; | |
3208 | ql_dbg(ql_dbg_init, base_vha, 0x0194, | |
3209 | "FC-NVMe support is enabled, HW queues=%d\n", | |
3210 | host->nr_hw_queues); | |
3211 | } else { | |
3212 | ql_dbg(ql_dbg_init, base_vha, 0x0193, | |
3213 | "blk/scsi-mq disabled.\n"); | |
3214 | } | |
3215 | } | |
5601236b | 3216 | |
2d70c103 | 3217 | qlt_probe_one_stage1(base_vha, ha); |
9a347ff4 | 3218 | |
90a86fc0 JC |
3219 | pci_save_state(pdev); |
3220 | ||
9a347ff4 | 3221 | /* Assign back pointers */ |
2afa19a9 AC |
3222 | rsp->req = req; |
3223 | req->rsp = rsp; | |
9a347ff4 | 3224 | |
8ae6d9c7 GM |
3225 | if (IS_QLAFX00(ha)) { |
3226 | ha->rsp_q_map[0] = rsp; | |
3227 | ha->req_q_map[0] = req; | |
3228 | set_bit(0, ha->req_qid_map); | |
3229 | set_bit(0, ha->rsp_qid_map); | |
3230 | } | |
3231 | ||
08029990 AV |
3232 | /* FWI2-capable only. */ |
3233 | req->req_q_in = &ha->iobase->isp24.req_q_in; | |
3234 | req->req_q_out = &ha->iobase->isp24.req_q_out; | |
3235 | rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in; | |
3236 | rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out; | |
ecc89f25 JC |
3237 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) || |
3238 | IS_QLA28XX(ha)) { | |
08029990 AV |
3239 | req->req_q_in = &ha->mqiobase->isp25mq.req_q_in; |
3240 | req->req_q_out = &ha->mqiobase->isp25mq.req_q_out; | |
3241 | rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in; | |
3242 | rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out; | |
17d98630 AC |
3243 | } |
3244 | ||
8ae6d9c7 GM |
3245 | if (IS_QLAFX00(ha)) { |
3246 | req->req_q_in = &ha->iobase->ispfx00.req_q_in; | |
3247 | req->req_q_out = &ha->iobase->ispfx00.req_q_out; | |
3248 | rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in; | |
3249 | rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out; | |
3250 | } | |
3251 | ||
7ec0effd | 3252 | if (IS_P3P_TYPE(ha)) { |
a9083016 GM |
3253 | req->req_q_out = &ha->iobase->isp82.req_q_out[0]; |
3254 | rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0]; | |
3255 | rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0]; | |
3256 | } | |
3257 | ||
7c3df132 SK |
3258 | ql_dbg(ql_dbg_multiq, base_vha, 0xc009, |
3259 | "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n", | |
3260 | ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp); | |
3261 | ql_dbg(ql_dbg_multiq, base_vha, 0xc00a, | |
3262 | "req->req_q_in=%p req->req_q_out=%p " | |
3263 | "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n", | |
3264 | req->req_q_in, req->req_q_out, | |
3265 | rsp->rsp_q_in, rsp->rsp_q_out); | |
3266 | ql_dbg(ql_dbg_init, base_vha, 0x003e, | |
3267 | "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n", | |
3268 | ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp); | |
3269 | ql_dbg(ql_dbg_init, base_vha, 0x003f, | |
3270 | "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n", | |
3271 | req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out); | |
1da177e4 | 3272 | |
d48cc67c | 3273 | ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0); |
3274 | ||
8ae6d9c7 | 3275 | if (ha->isp_ops->initialize_adapter(base_vha)) { |
7c3df132 SK |
3276 | ql_log(ql_log_fatal, base_vha, 0x00d6, |
3277 | "Failed to initialize adapter - Adapter flags %x.\n", | |
3278 | base_vha->device_flags); | |
1da177e4 | 3279 | |
a9083016 GM |
3280 | if (IS_QLA82XX(ha)) { |
3281 | qla82xx_idc_lock(ha); | |
3282 | qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, | |
7d613ac6 | 3283 | QLA8XXX_DEV_FAILED); |
a9083016 | 3284 | qla82xx_idc_unlock(ha); |
7c3df132 SK |
3285 | ql_log(ql_log_fatal, base_vha, 0x00d7, |
3286 | "HW State: FAILED.\n"); | |
7ec0effd AD |
3287 | } else if (IS_QLA8044(ha)) { |
3288 | qla8044_idc_lock(ha); | |
3289 | qla8044_wr_direct(base_vha, | |
3290 | QLA8044_CRB_DEV_STATE_INDEX, | |
3291 | QLA8XXX_DEV_FAILED); | |
3292 | qla8044_idc_unlock(ha); | |
3293 | ql_log(ql_log_fatal, base_vha, 0x0150, | |
3294 | "HW State: FAILED.\n"); | |
a9083016 GM |
3295 | } |
3296 | ||
a1541d5a | 3297 | ret = -ENODEV; |
1da177e4 LT |
3298 | goto probe_failed; |
3299 | } | |
3300 | ||
3b1bef64 CD |
3301 | if (IS_QLAFX00(ha)) |
3302 | host->can_queue = QLAFX00_MAX_CANQUEUE; | |
3303 | else | |
3304 | host->can_queue = req->num_outstanding_cmds - 10; | |
3305 | ||
3306 | ql_dbg(ql_dbg_init, base_vha, 0x0032, | |
3307 | "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n", | |
3308 | host->can_queue, base_vha->req, | |
3309 | base_vha->mgmt_svr_loop_id, host->sg_tablesize); | |
3310 | ||
e326d22a | 3311 | if (ha->mqenable) { |
e326d22a | 3312 | bool startit = false; |
e326d22a | 3313 | |
f664a3cc | 3314 | if (QLA_TGT_MODE_ENABLED()) |
e326d22a | 3315 | startit = false; |
e326d22a | 3316 | |
f664a3cc | 3317 | if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) |
e326d22a | 3318 | startit = true; |
e326d22a | 3319 | |
f664a3cc JA |
3320 | /* Create start of day qpairs for Block MQ */ |
3321 | for (i = 0; i < ha->max_qpairs; i++) | |
3322 | qla2xxx_create_qpair(base_vha, 5, 0, startit); | |
5601236b | 3323 | } |
68ca949c | 3324 | |
cbc8eb67 AV |
3325 | if (ha->flags.running_gold_fw) |
3326 | goto skip_dpc; | |
3327 | ||
1da177e4 LT |
3328 | /* |
3329 | * Startup the kernel thread for this host adapter | |
3330 | */ | |
39a11240 | 3331 | ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha, |
7c3df132 | 3332 | "%s_dpc", base_vha->host_str); |
39a11240 | 3333 | if (IS_ERR(ha->dpc_thread)) { |
7c3df132 SK |
3334 | ql_log(ql_log_fatal, base_vha, 0x00ed, |
3335 | "Failed to start DPC thread.\n"); | |
39a11240 | 3336 | ret = PTR_ERR(ha->dpc_thread); |
e2532b4a | 3337 | ha->dpc_thread = NULL; |
1da177e4 LT |
3338 | goto probe_failed; |
3339 | } | |
7c3df132 SK |
3340 | ql_dbg(ql_dbg_init, base_vha, 0x00ee, |
3341 | "DPC thread started successfully.\n"); | |
1da177e4 | 3342 | |
2d70c103 NB |
3343 | /* |
3344 | * If we're not coming up in initiator mode, we might sit for | |
3345 | * a while without waking up the dpc thread, which leads to a | |
3346 | * stuck process warning. So just kick the dpc once here and | |
3347 | * let the kthread start (and go back to sleep in qla2x00_do_dpc). | |
3348 | */ | |
3349 | qla2xxx_wake_dpc(base_vha); | |
3350 | ||
f3ddac19 CD |
3351 | INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error); |
3352 | ||
81178772 SK |
3353 | if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) { |
3354 | sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no); | |
3355 | ha->dpc_lp_wq = create_singlethread_workqueue(wq_name); | |
3356 | INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen); | |
3357 | ||
3358 | sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no); | |
3359 | ha->dpc_hp_wq = create_singlethread_workqueue(wq_name); | |
3360 | INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work); | |
3361 | INIT_WORK(&ha->idc_state_handler, | |
3362 | qla83xx_idc_state_handler_work); | |
3363 | INIT_WORK(&ha->nic_core_unrecoverable, | |
3364 | qla83xx_nic_core_unrecoverable_work); | |
3365 | } | |
3366 | ||
cbc8eb67 | 3367 | skip_dpc: |
e315cd28 AC |
3368 | list_add_tail(&base_vha->list, &ha->vp_list); |
3369 | base_vha->host->irq = ha->pdev->irq; | |
1da177e4 LT |
3370 | |
3371 | /* Initialized the timer */ | |
8e5f4ba0 | 3372 | qla2x00_start_timer(base_vha, WATCH_INTERVAL); |
7c3df132 SK |
3373 | ql_dbg(ql_dbg_init, base_vha, 0x00ef, |
3374 | "Started qla2x00_timer with " | |
3375 | "interval=%d.\n", WATCH_INTERVAL); | |
3376 | ql_dbg(ql_dbg_init, base_vha, 0x00f0, | |
3377 | "Detected hba at address=%p.\n", | |
3378 | ha); | |
d19044c3 | 3379 | |
e02587d7 | 3380 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { |
bad75002 | 3381 | if (ha->fw_attributes & BIT_4) { |
9e522cd8 | 3382 | int prot = 0, guard; |
bd432bb5 | 3383 | |
bad75002 | 3384 | base_vha->flags.difdix_supported = 1; |
7c3df132 SK |
3385 | ql_dbg(ql_dbg_init, base_vha, 0x00f1, |
3386 | "Registering for DIF/DIX type 1 and 3 protection.\n"); | |
8cb2049c AE |
3387 | if (ql2xenabledif == 1) |
3388 | prot = SHOST_DIX_TYPE0_PROTECTION; | |
7855d2ba MP |
3389 | if (ql2xprotmask) |
3390 | scsi_host_set_prot(host, ql2xprotmask); | |
3391 | else | |
3392 | scsi_host_set_prot(host, | |
3393 | prot | SHOST_DIF_TYPE1_PROTECTION | |
3394 | | SHOST_DIF_TYPE2_PROTECTION | |
3395 | | SHOST_DIF_TYPE3_PROTECTION | |
3396 | | SHOST_DIX_TYPE1_PROTECTION | |
3397 | | SHOST_DIX_TYPE2_PROTECTION | |
3398 | | SHOST_DIX_TYPE3_PROTECTION); | |
9e522cd8 AE |
3399 | |
3400 | guard = SHOST_DIX_GUARD_CRC; | |
3401 | ||
3402 | if (IS_PI_IPGUARD_CAPABLE(ha) && | |
3403 | (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha))) | |
3404 | guard |= SHOST_DIX_GUARD_IP; | |
3405 | ||
7855d2ba MP |
3406 | if (ql2xprotguard) |
3407 | scsi_host_set_guard(host, ql2xprotguard); | |
3408 | else | |
3409 | scsi_host_set_guard(host, guard); | |
bad75002 AE |
3410 | } else |
3411 | base_vha->flags.difdix_supported = 0; | |
3412 | } | |
3413 | ||
a9083016 GM |
3414 | ha->isp_ops->enable_intrs(ha); |
3415 | ||
1fe19ee4 AB |
3416 | if (IS_QLAFX00(ha)) { |
3417 | ret = qlafx00_fx_disc(base_vha, | |
3418 | &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO); | |
3419 | host->sg_tablesize = (ha->mr.extended_io_enabled) ? | |
3420 | QLA_SG_ALL : 128; | |
3421 | } | |
3422 | ||
a1541d5a AV |
3423 | ret = scsi_add_host(host, &pdev->dev); |
3424 | if (ret) | |
3425 | goto probe_failed; | |
3426 | ||
1486400f MR |
3427 | base_vha->flags.init_done = 1; |
3428 | base_vha->flags.online = 1; | |
edaa5c74 | 3429 | ha->prev_minidump_failed = 0; |
1486400f | 3430 | |
7c3df132 SK |
3431 | ql_dbg(ql_dbg_init, base_vha, 0x00f2, |
3432 | "Init done and hba is online.\n"); | |
3433 | ||
726b8548 QT |
3434 | if (qla_ini_mode_enabled(base_vha) || |
3435 | qla_dual_mode_enabled(base_vha)) | |
2d70c103 NB |
3436 | scsi_scan_host(host); |
3437 | else | |
3438 | ql_dbg(ql_dbg_init, base_vha, 0x0122, | |
3439 | "skipping scsi_scan_host() for non-initiator port\n"); | |
1e99e33a | 3440 | |
e315cd28 | 3441 | qla2x00_alloc_sysfs_attr(base_vha); |
a1541d5a | 3442 | |
8ae6d9c7 | 3443 | if (IS_QLAFX00(ha)) { |
8ae6d9c7 GM |
3444 | ret = qlafx00_fx_disc(base_vha, |
3445 | &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO); | |
3446 | ||
3447 | /* Register system information */ | |
3448 | ret = qlafx00_fx_disc(base_vha, | |
3449 | &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO); | |
3450 | } | |
3451 | ||
e315cd28 | 3452 | qla2x00_init_host_attr(base_vha); |
a1541d5a | 3453 | |
e315cd28 | 3454 | qla2x00_dfs_setup(base_vha); |
df613b96 | 3455 | |
03eb912a AB |
3456 | ql_log(ql_log_info, base_vha, 0x00fb, |
3457 | "QLogic %s - %s.\n", ha->model_number, ha->model_desc); | |
7c3df132 SK |
3458 | ql_log(ql_log_info, base_vha, 0x00fc, |
3459 | "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n", | |
3460 | pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info), | |
3461 | pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-', | |
3462 | base_vha->host_no, | |
df57caba | 3463 | ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str))); |
1da177e4 | 3464 | |
2d70c103 NB |
3465 | qlt_add_target(ha, base_vha); |
3466 | ||
6b383979 | 3467 | clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags); |
a29b3dd7 JC |
3468 | |
3469 | if (test_bit(UNLOADING, &base_vha->dpc_flags)) | |
3470 | return -ENODEV; | |
3471 | ||
e4e3a2ce QT |
3472 | if (ha->flags.detected_lr_sfp) { |
3473 | ql_log(ql_log_info, base_vha, 0xffff, | |
3474 | "Reset chip to pick up LR SFP setting\n"); | |
3475 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); | |
3476 | qla2xxx_wake_dpc(base_vha); | |
3477 | } | |
3478 | ||
1da177e4 LT |
3479 | return 0; |
3480 | ||
3481 | probe_failed: | |
b9978769 AV |
3482 | if (base_vha->timer_active) |
3483 | qla2x00_stop_timer(base_vha); | |
3484 | base_vha->flags.online = 0; | |
3485 | if (ha->dpc_thread) { | |
3486 | struct task_struct *t = ha->dpc_thread; | |
3487 | ||
3488 | ha->dpc_thread = NULL; | |
3489 | kthread_stop(t); | |
3490 | } | |
3491 | ||
e315cd28 | 3492 | qla2x00_free_device(base_vha); |
e315cd28 | 3493 | scsi_host_put(base_vha->host); |
6d634067 BK |
3494 | /* |
3495 | * Need to NULL out local req/rsp after | |
3496 | * qla2x00_free_device => qla2x00_free_queues frees | |
3497 | * what these are pointing to. Or else we'll | |
3498 | * fall over below in qla2x00_free_req/rsp_que. | |
3499 | */ | |
3500 | req = NULL; | |
3501 | rsp = NULL; | |
1da177e4 | 3502 | |
e315cd28 | 3503 | probe_hw_failed: |
d64d6c56 | 3504 | qla2x00_mem_free(ha); |
3505 | qla2x00_free_req_que(ha, req); | |
3506 | qla2x00_free_rsp_que(ha, rsp); | |
1a2fbf18 JL |
3507 | qla2x00_clear_drv_active(ha); |
3508 | ||
0a63ad12 | 3509 | iospace_config_failed: |
7ec0effd | 3510 | if (IS_P3P_TYPE(ha)) { |
0a63ad12 | 3511 | if (!ha->nx_pcibase) |
f73cb695 | 3512 | iounmap((device_reg_t *)ha->nx_pcibase); |
a9083016 | 3513 | if (!ql2xdbwr) |
f73cb695 | 3514 | iounmap((device_reg_t *)ha->nxdb_wr_ptr); |
a9083016 GM |
3515 | } else { |
3516 | if (ha->iobase) | |
3517 | iounmap(ha->iobase); | |
8ae6d9c7 GM |
3518 | if (ha->cregbase) |
3519 | iounmap(ha->cregbase); | |
a9083016 | 3520 | } |
e315cd28 AC |
3521 | pci_release_selected_regions(ha->pdev, ha->bars); |
3522 | kfree(ha); | |
1da177e4 | 3523 | |
ddff7ed4 | 3524 | disable_device: |
e315cd28 | 3525 | pci_disable_device(pdev); |
a1541d5a | 3526 | return ret; |
1da177e4 | 3527 | } |
1da177e4 | 3528 | |
e30d1756 MI |
3529 | static void |
3530 | qla2x00_shutdown(struct pci_dev *pdev) | |
3531 | { | |
3532 | scsi_qla_host_t *vha; | |
3533 | struct qla_hw_data *ha; | |
3534 | ||
3535 | vha = pci_get_drvdata(pdev); | |
3536 | ha = vha->hw; | |
3537 | ||
efdb5760 SC |
3538 | ql_log(ql_log_info, vha, 0xfffa, |
3539 | "Adapter shutdown\n"); | |
3540 | ||
3541 | /* | |
3542 | * Prevent future board_disable and wait | |
3543 | * until any pending board_disable has completed. | |
3544 | */ | |
3545 | set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags); | |
3546 | cancel_work_sync(&ha->board_disable); | |
3547 | ||
3548 | if (!atomic_read(&pdev->enable_cnt)) | |
3549 | return; | |
3550 | ||
42479343 AB |
3551 | /* Notify ISPFX00 firmware */ |
3552 | if (IS_QLAFX00(ha)) | |
3553 | qlafx00_driver_shutdown(vha, 20); | |
3554 | ||
e30d1756 MI |
3555 | /* Turn-off FCE trace */ |
3556 | if (ha->flags.fce_enabled) { | |
3557 | qla2x00_disable_fce_trace(vha, NULL, NULL); | |
3558 | ha->flags.fce_enabled = 0; | |
3559 | } | |
3560 | ||
3561 | /* Turn-off EFT trace */ | |
3562 | if (ha->eft) | |
3563 | qla2x00_disable_eft_trace(vha); | |
3564 | ||
ecc89f25 JC |
3565 | if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) || |
3566 | IS_QLA28XX(ha)) { | |
3407fc37 QT |
3567 | if (ha->flags.fw_started) |
3568 | qla2x00_abort_isp_cleanup(vha); | |
3569 | } else { | |
3570 | /* Stop currently executing firmware. */ | |
3571 | qla2x00_try_to_stop_firmware(vha); | |
3572 | } | |
e30d1756 MI |
3573 | |
3574 | /* Turn adapter off line */ | |
3575 | vha->flags.online = 0; | |
3576 | ||
3577 | /* turn-off interrupts on the card */ | |
3578 | if (ha->interrupts_on) { | |
3579 | vha->flags.init_done = 0; | |
3580 | ha->isp_ops->disable_intrs(ha); | |
3581 | } | |
3582 | ||
3583 | qla2x00_free_irqs(vha); | |
3584 | ||
3585 | qla2x00_free_fw_dump(ha); | |
61d41f61 | 3586 | |
61d41f61 | 3587 | pci_disable_device(pdev); |
efdb5760 SC |
3588 | ql_log(ql_log_info, vha, 0xfffe, |
3589 | "Adapter shutdown successfully.\n"); | |
e30d1756 MI |
3590 | } |
3591 | ||
fe1b806f | 3592 | /* Deletes all the virtual ports for a given ha */ |
4c993f76 | 3593 | static void |
fe1b806f | 3594 | qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha) |
1da177e4 | 3595 | { |
fe1b806f | 3596 | scsi_qla_host_t *vha; |
feafb7b1 | 3597 | unsigned long flags; |
e315cd28 | 3598 | |
43ebf16d AE |
3599 | mutex_lock(&ha->vport_lock); |
3600 | while (ha->cur_vport_count) { | |
43ebf16d | 3601 | spin_lock_irqsave(&ha->vport_slock, flags); |
feafb7b1 | 3602 | |
43ebf16d AE |
3603 | BUG_ON(base_vha->list.next == &ha->vp_list); |
3604 | /* This assumes first entry in ha->vp_list is always base vha */ | |
3605 | vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list); | |
52c82823 | 3606 | scsi_host_get(vha->host); |
feafb7b1 | 3607 | |
43ebf16d AE |
3608 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
3609 | mutex_unlock(&ha->vport_lock); | |
3610 | ||
5e6803b4 HM |
3611 | qla_nvme_delete(vha); |
3612 | ||
43ebf16d AE |
3613 | fc_vport_terminate(vha->fc_vport); |
3614 | scsi_host_put(vha->host); | |
feafb7b1 | 3615 | |
43ebf16d | 3616 | mutex_lock(&ha->vport_lock); |
e315cd28 | 3617 | } |
43ebf16d | 3618 | mutex_unlock(&ha->vport_lock); |
fe1b806f | 3619 | } |
1da177e4 | 3620 | |
fe1b806f CD |
3621 | /* Stops all deferred work threads */ |
3622 | static void | |
3623 | qla2x00_destroy_deferred_work(struct qla_hw_data *ha) | |
3624 | { | |
7d613ac6 SV |
3625 | /* Cancel all work and destroy DPC workqueues */ |
3626 | if (ha->dpc_lp_wq) { | |
3627 | cancel_work_sync(&ha->idc_aen); | |
3628 | destroy_workqueue(ha->dpc_lp_wq); | |
3629 | ha->dpc_lp_wq = NULL; | |
3630 | } | |
3631 | ||
3632 | if (ha->dpc_hp_wq) { | |
3633 | cancel_work_sync(&ha->nic_core_reset); | |
3634 | cancel_work_sync(&ha->idc_state_handler); | |
3635 | cancel_work_sync(&ha->nic_core_unrecoverable); | |
3636 | destroy_workqueue(ha->dpc_hp_wq); | |
3637 | ha->dpc_hp_wq = NULL; | |
3638 | } | |
3639 | ||
b9978769 AV |
3640 | /* Kill the kernel thread for this host */ |
3641 | if (ha->dpc_thread) { | |
3642 | struct task_struct *t = ha->dpc_thread; | |
3643 | ||
3644 | /* | |
3645 | * qla2xxx_wake_dpc checks for ->dpc_thread | |
3646 | * so we need to zero it out. | |
3647 | */ | |
3648 | ha->dpc_thread = NULL; | |
3649 | kthread_stop(t); | |
3650 | } | |
fe1b806f | 3651 | } |
1da177e4 | 3652 | |
fe1b806f CD |
3653 | static void |
3654 | qla2x00_unmap_iobases(struct qla_hw_data *ha) | |
3655 | { | |
a9083016 | 3656 | if (IS_QLA82XX(ha)) { |
b963752f | 3657 | |
f73cb695 | 3658 | iounmap((device_reg_t *)ha->nx_pcibase); |
a9083016 | 3659 | if (!ql2xdbwr) |
f73cb695 | 3660 | iounmap((device_reg_t *)ha->nxdb_wr_ptr); |
a9083016 GM |
3661 | } else { |
3662 | if (ha->iobase) | |
3663 | iounmap(ha->iobase); | |
1da177e4 | 3664 | |
8ae6d9c7 GM |
3665 | if (ha->cregbase) |
3666 | iounmap(ha->cregbase); | |
3667 | ||
a9083016 GM |
3668 | if (ha->mqiobase) |
3669 | iounmap(ha->mqiobase); | |
6246b8a1 | 3670 | |
ecc89f25 JC |
3671 | if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) && |
3672 | ha->msixbase) | |
6246b8a1 | 3673 | iounmap(ha->msixbase); |
a9083016 | 3674 | } |
fe1b806f CD |
3675 | } |
3676 | ||
3677 | static void | |
db7157d4 | 3678 | qla2x00_clear_drv_active(struct qla_hw_data *ha) |
fe1b806f | 3679 | { |
fe1b806f CD |
3680 | if (IS_QLA8044(ha)) { |
3681 | qla8044_idc_lock(ha); | |
c41afc9a | 3682 | qla8044_clear_drv_active(ha); |
fe1b806f CD |
3683 | qla8044_idc_unlock(ha); |
3684 | } else if (IS_QLA82XX(ha)) { | |
3685 | qla82xx_idc_lock(ha); | |
3686 | qla82xx_clear_drv_active(ha); | |
3687 | qla82xx_idc_unlock(ha); | |
3688 | } | |
3689 | } | |
3690 | ||
3691 | static void | |
3692 | qla2x00_remove_one(struct pci_dev *pdev) | |
3693 | { | |
3694 | scsi_qla_host_t *base_vha; | |
3695 | struct qla_hw_data *ha; | |
3696 | ||
beb9e315 JL |
3697 | base_vha = pci_get_drvdata(pdev); |
3698 | ha = base_vha->hw; | |
45235022 QT |
3699 | ql_log(ql_log_info, base_vha, 0xb079, |
3700 | "Removing driver\n"); | |
beb9e315 JL |
3701 | |
3702 | /* Indicate device removal to prevent future board_disable and wait | |
3703 | * until any pending board_disable has completed. */ | |
3704 | set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags); | |
3705 | cancel_work_sync(&ha->board_disable); | |
3706 | ||
fe1b806f | 3707 | /* |
beb9e315 JL |
3708 | * If the PCI device is disabled then there was a PCI-disconnect and |
3709 | * qla2x00_disable_board_on_pci_error has taken care of most of the | |
3710 | * resources. | |
fe1b806f | 3711 | */ |
beb9e315 | 3712 | if (!atomic_read(&pdev->enable_cnt)) { |
726b8548 QT |
3713 | dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size, |
3714 | base_vha->gnl.l, base_vha->gnl.ldma); | |
3715 | ||
beb9e315 JL |
3716 | scsi_host_put(base_vha->host); |
3717 | kfree(ha); | |
3718 | pci_set_drvdata(pdev, NULL); | |
fe1b806f | 3719 | return; |
beb9e315 | 3720 | } |
638a1a01 SC |
3721 | qla2x00_wait_for_hba_ready(base_vha); |
3722 | ||
ecc89f25 JC |
3723 | if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) || |
3724 | IS_QLA28XX(ha)) { | |
45235022 QT |
3725 | if (ha->flags.fw_started) |
3726 | qla2x00_abort_isp_cleanup(base_vha); | |
3727 | } else if (!IS_QLAFX00(ha)) { | |
3728 | if (IS_QLA8031(ha)) { | |
3729 | ql_dbg(ql_dbg_p3p, base_vha, 0xb07e, | |
3730 | "Clearing fcoe driver presence.\n"); | |
3731 | if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS) | |
3732 | ql_dbg(ql_dbg_p3p, base_vha, 0xb079, | |
3733 | "Error while clearing DRV-Presence.\n"); | |
3734 | } | |
3735 | ||
3736 | qla2x00_try_to_stop_firmware(base_vha); | |
3737 | } | |
3738 | ||
2ce87cc5 QT |
3739 | qla2x00_wait_for_sess_deletion(base_vha); |
3740 | ||
726b8548 QT |
3741 | /* |
3742 | * if UNLOAD flag is already set, then continue unload, | |
783e0dc4 SC |
3743 | * where it was set first. |
3744 | */ | |
3745 | if (test_bit(UNLOADING, &base_vha->dpc_flags)) | |
3746 | return; | |
3747 | ||
fe1b806f | 3748 | set_bit(UNLOADING, &base_vha->dpc_flags); |
e84067d7 DG |
3749 | |
3750 | qla_nvme_delete(base_vha); | |
3751 | ||
726b8548 QT |
3752 | dma_free_coherent(&ha->pdev->dev, |
3753 | base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma); | |
fe1b806f | 3754 | |
a4239945 QT |
3755 | vfree(base_vha->scan.l); |
3756 | ||
fe1b806f CD |
3757 | if (IS_QLAFX00(ha)) |
3758 | qlafx00_driver_shutdown(base_vha, 20); | |
3759 | ||
3760 | qla2x00_delete_all_vps(ha, base_vha); | |
3761 | ||
fe1b806f CD |
3762 | qla2x00_dfs_remove(base_vha); |
3763 | ||
3764 | qla84xx_put_chip(base_vha); | |
3765 | ||
3766 | /* Disable timer */ | |
3767 | if (base_vha->timer_active) | |
3768 | qla2x00_stop_timer(base_vha); | |
3769 | ||
3770 | base_vha->flags.online = 0; | |
3771 | ||
b0d6cabd HM |
3772 | /* free DMA memory */ |
3773 | if (ha->exlogin_buf) | |
3774 | qla2x00_free_exlogin_buffer(ha); | |
3775 | ||
2f56a7f1 HM |
3776 | /* free DMA memory */ |
3777 | if (ha->exchoffld_buf) | |
3778 | qla2x00_free_exchoffld_buffer(ha); | |
3779 | ||
fe1b806f CD |
3780 | qla2x00_destroy_deferred_work(ha); |
3781 | ||
3782 | qlt_remove_target(ha, base_vha); | |
3783 | ||
3784 | qla2x00_free_sysfs_attr(base_vha, true); | |
3785 | ||
3786 | fc_remove_host(base_vha->host); | |
482c9dc7 | 3787 | qlt_remove_target_resources(ha); |
fe1b806f CD |
3788 | |
3789 | scsi_remove_host(base_vha->host); | |
3790 | ||
3791 | qla2x00_free_device(base_vha); | |
3792 | ||
db7157d4 | 3793 | qla2x00_clear_drv_active(ha); |
fe1b806f | 3794 | |
d2749ffa AE |
3795 | scsi_host_put(base_vha->host); |
3796 | ||
fe1b806f | 3797 | qla2x00_unmap_iobases(ha); |
73208dfd | 3798 | |
e315cd28 AC |
3799 | pci_release_selected_regions(ha->pdev, ha->bars); |
3800 | kfree(ha); | |
1da177e4 | 3801 | |
90a86fc0 JC |
3802 | pci_disable_pcie_error_reporting(pdev); |
3803 | ||
665db93b | 3804 | pci_disable_device(pdev); |
1da177e4 | 3805 | } |
1da177e4 LT |
3806 | |
3807 | static void | |
e315cd28 | 3808 | qla2x00_free_device(scsi_qla_host_t *vha) |
1da177e4 | 3809 | { |
e315cd28 | 3810 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 3811 | |
85880801 AV |
3812 | qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16); |
3813 | ||
3814 | /* Disable timer */ | |
3815 | if (vha->timer_active) | |
3816 | qla2x00_stop_timer(vha); | |
3817 | ||
2afa19a9 | 3818 | qla25xx_delete_queues(vha); |
85880801 AV |
3819 | vha->flags.online = 0; |
3820 | ||
f6ef3b18 | 3821 | /* turn-off interrupts on the card */ |
a9083016 GM |
3822 | if (ha->interrupts_on) { |
3823 | vha->flags.init_done = 0; | |
fd34f556 | 3824 | ha->isp_ops->disable_intrs(ha); |
a9083016 | 3825 | } |
f6ef3b18 | 3826 | |
093df737 QT |
3827 | qla2x00_free_fcports(vha); |
3828 | ||
e315cd28 | 3829 | qla2x00_free_irqs(vha); |
1da177e4 | 3830 | |
093df737 QT |
3831 | /* Flush the work queue and remove it */ |
3832 | if (ha->wq) { | |
3833 | flush_workqueue(ha->wq); | |
3834 | destroy_workqueue(ha->wq); | |
3835 | ha->wq = NULL; | |
3836 | } | |
3837 | ||
8867048b | 3838 | |
e315cd28 | 3839 | qla2x00_mem_free(ha); |
73208dfd | 3840 | |
08de2844 GM |
3841 | qla82xx_md_free(vha); |
3842 | ||
73208dfd | 3843 | qla2x00_free_queues(ha); |
1da177e4 LT |
3844 | } |
3845 | ||
8867048b CD |
3846 | void qla2x00_free_fcports(struct scsi_qla_host *vha) |
3847 | { | |
3848 | fc_port_t *fcport, *tfcport; | |
3849 | ||
ffbc6476 QT |
3850 | list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) |
3851 | qla2x00_free_fcport(fcport); | |
8867048b CD |
3852 | } |
3853 | ||
d97994dc | 3854 | static inline void |
e315cd28 | 3855 | qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport, |
d97994dc AV |
3856 | int defer) |
3857 | { | |
d97994dc | 3858 | struct fc_rport *rport; |
67becc00 | 3859 | scsi_qla_host_t *base_vha; |
044d78e1 | 3860 | unsigned long flags; |
d97994dc AV |
3861 | |
3862 | if (!fcport->rport) | |
3863 | return; | |
3864 | ||
3865 | rport = fcport->rport; | |
3866 | if (defer) { | |
67becc00 | 3867 | base_vha = pci_get_drvdata(vha->hw->pdev); |
044d78e1 | 3868 | spin_lock_irqsave(vha->host->host_lock, flags); |
d97994dc | 3869 | fcport->drport = rport; |
044d78e1 | 3870 | spin_unlock_irqrestore(vha->host->host_lock, flags); |
df673274 | 3871 | qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen); |
67becc00 AV |
3872 | set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags); |
3873 | qla2xxx_wake_dpc(base_vha); | |
2d70c103 | 3874 | } else { |
df673274 | 3875 | int now; |
bd432bb5 | 3876 | |
726b8548 | 3877 | if (rport) { |
83548fe2 QT |
3878 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2109, |
3879 | "%s %8phN. rport %p roles %x\n", | |
3880 | __func__, fcport->port_name, rport, | |
3881 | rport->roles); | |
d20ed91b | 3882 | fc_remote_port_delete(rport); |
726b8548 | 3883 | } |
df673274 | 3884 | qlt_do_generation_tick(vha, &now); |
2d70c103 | 3885 | } |
d97994dc AV |
3886 | } |
3887 | ||
1da177e4 LT |
3888 | /* |
3889 | * qla2x00_mark_device_lost Updates fcport state when device goes offline. | |
3890 | * | |
3891 | * Input: ha = adapter block pointer. fcport = port structure pointer. | |
3892 | * | |
3893 | * Return: None. | |
3894 | * | |
3895 | * Context: | |
3896 | */ | |
e315cd28 | 3897 | void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport, |
d97994dc | 3898 | int do_login, int defer) |
1da177e4 | 3899 | { |
8ae6d9c7 GM |
3900 | if (IS_QLAFX00(vha->hw)) { |
3901 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); | |
3902 | qla2x00_schedule_rport_del(vha, fcport, defer); | |
3903 | return; | |
3904 | } | |
3905 | ||
2c3dfe3f | 3906 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
c6d39e23 | 3907 | vha->vp_idx == fcport->vha->vp_idx) { |
ec426e10 | 3908 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
e315cd28 AC |
3909 | qla2x00_schedule_rport_del(vha, fcport, defer); |
3910 | } | |
fa2a1ce5 | 3911 | /* |
1da177e4 LT |
3912 | * We may need to retry the login, so don't change the state of the |
3913 | * port but do the retries. | |
3914 | */ | |
3915 | if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD) | |
ec426e10 | 3916 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
1da177e4 LT |
3917 | |
3918 | if (!do_login) | |
3919 | return; | |
3920 | ||
a1d0285e | 3921 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
3922 | } |
3923 | ||
3924 | /* | |
3925 | * qla2x00_mark_all_devices_lost | |
3926 | * Updates fcport state when device goes offline. | |
3927 | * | |
3928 | * Input: | |
3929 | * ha = adapter block pointer. | |
3930 | * fcport = port structure pointer. | |
3931 | * | |
3932 | * Return: | |
3933 | * None. | |
3934 | * | |
3935 | * Context: | |
3936 | */ | |
3937 | void | |
e315cd28 | 3938 | qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer) |
1da177e4 LT |
3939 | { |
3940 | fc_port_t *fcport; | |
3941 | ||
83548fe2 QT |
3942 | ql_dbg(ql_dbg_disc, vha, 0x20f1, |
3943 | "Mark all dev lost\n"); | |
726b8548 | 3944 | |
e315cd28 | 3945 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
726b8548 | 3946 | fcport->scan_state = 0; |
d8630bb9 | 3947 | qlt_schedule_sess_for_deletion(fcport); |
726b8548 | 3948 | |
c6d39e23 | 3949 | if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx) |
1da177e4 | 3950 | continue; |
0d6e61bc | 3951 | |
1da177e4 LT |
3952 | /* |
3953 | * No point in marking the device as lost, if the device is | |
3954 | * already DEAD. | |
3955 | */ | |
3956 | if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) | |
3957 | continue; | |
e315cd28 | 3958 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
ec426e10 | 3959 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
0d6e61bc AV |
3960 | if (defer) |
3961 | qla2x00_schedule_rport_del(vha, fcport, defer); | |
c6d39e23 | 3962 | else if (vha->vp_idx == fcport->vha->vp_idx) |
0d6e61bc AV |
3963 | qla2x00_schedule_rport_del(vha, fcport, defer); |
3964 | } | |
1da177e4 LT |
3965 | } |
3966 | } | |
3967 | ||
0e145a59 BVA |
3968 | static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha) |
3969 | { | |
3970 | int i; | |
3971 | ||
3972 | if (IS_FWI2_CAPABLE(ha)) | |
3973 | return; | |
3974 | ||
3975 | for (i = 0; i < SNS_FIRST_LOOP_ID; i++) | |
3976 | set_bit(i, ha->loop_id_map); | |
3977 | set_bit(MANAGEMENT_SERVER, ha->loop_id_map); | |
3978 | set_bit(BROADCAST, ha->loop_id_map); | |
3979 | } | |
3980 | ||
1da177e4 LT |
3981 | /* |
3982 | * qla2x00_mem_alloc | |
3983 | * Allocates adapter memory. | |
3984 | * | |
3985 | * Returns: | |
3986 | * 0 = success. | |
e8711085 | 3987 | * !0 = failure. |
1da177e4 | 3988 | */ |
e8711085 | 3989 | static int |
73208dfd AC |
3990 | qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len, |
3991 | struct req_que **req, struct rsp_que **rsp) | |
1da177e4 LT |
3992 | { |
3993 | char name[16]; | |
1da177e4 | 3994 | |
e8711085 | 3995 | ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size, |
e315cd28 | 3996 | &ha->init_cb_dma, GFP_KERNEL); |
e8711085 | 3997 | if (!ha->init_cb) |
e315cd28 | 3998 | goto fail; |
e8711085 | 3999 | |
2d70c103 NB |
4000 | if (qlt_mem_alloc(ha) < 0) |
4001 | goto fail_free_init_cb; | |
4002 | ||
642ef983 CD |
4003 | ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, |
4004 | qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL); | |
e315cd28 | 4005 | if (!ha->gid_list) |
2d70c103 | 4006 | goto fail_free_tgt_mem; |
1da177e4 | 4007 | |
e8711085 AV |
4008 | ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
4009 | if (!ha->srb_mempool) | |
e315cd28 | 4010 | goto fail_free_gid_list; |
e8711085 | 4011 | |
7ec0effd | 4012 | if (IS_P3P_TYPE(ha)) { |
a9083016 GM |
4013 | /* Allocate cache for CT6 Ctx. */ |
4014 | if (!ctx_cachep) { | |
4015 | ctx_cachep = kmem_cache_create("qla2xxx_ctx", | |
4016 | sizeof(struct ct6_dsd), 0, | |
4017 | SLAB_HWCACHE_ALIGN, NULL); | |
4018 | if (!ctx_cachep) | |
fc1ffd6c | 4019 | goto fail_free_srb_mempool; |
a9083016 GM |
4020 | } |
4021 | ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ, | |
4022 | ctx_cachep); | |
4023 | if (!ha->ctx_mempool) | |
4024 | goto fail_free_srb_mempool; | |
7c3df132 SK |
4025 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021, |
4026 | "ctx_cachep=%p ctx_mempool=%p.\n", | |
4027 | ctx_cachep, ha->ctx_mempool); | |
a9083016 GM |
4028 | } |
4029 | ||
e8711085 AV |
4030 | /* Get memory for cached NVRAM */ |
4031 | ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL); | |
4032 | if (!ha->nvram) | |
a9083016 | 4033 | goto fail_free_ctx_mempool; |
e8711085 | 4034 | |
e315cd28 AC |
4035 | snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME, |
4036 | ha->pdev->device); | |
4037 | ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev, | |
4038 | DMA_POOL_SIZE, 8, 0); | |
4039 | if (!ha->s_dma_pool) | |
4040 | goto fail_free_nvram; | |
4041 | ||
7c3df132 SK |
4042 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022, |
4043 | "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n", | |
4044 | ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool); | |
4045 | ||
7ec0effd | 4046 | if (IS_P3P_TYPE(ha) || ql2xenabledif) { |
a9083016 GM |
4047 | ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev, |
4048 | DSD_LIST_DMA_POOL_SIZE, 8, 0); | |
4049 | if (!ha->dl_dma_pool) { | |
7c3df132 SK |
4050 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0023, |
4051 | "Failed to allocate memory for dl_dma_pool.\n"); | |
a9083016 GM |
4052 | goto fail_s_dma_pool; |
4053 | } | |
4054 | ||
4055 | ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev, | |
4056 | FCP_CMND_DMA_POOL_SIZE, 8, 0); | |
4057 | if (!ha->fcp_cmnd_dma_pool) { | |
7c3df132 SK |
4058 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0024, |
4059 | "Failed to allocate memory for fcp_cmnd_dma_pool.\n"); | |
a9083016 GM |
4060 | goto fail_dl_dma_pool; |
4061 | } | |
50b81275 GM |
4062 | |
4063 | if (ql2xenabledif) { | |
4064 | u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE; | |
4065 | struct dsd_dma *dsd, *nxt; | |
4066 | uint i; | |
4067 | /* Creata a DMA pool of buffers for DIF bundling */ | |
4068 | ha->dif_bundl_pool = dma_pool_create(name, | |
4069 | &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0); | |
4070 | if (!ha->dif_bundl_pool) { | |
4071 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024, | |
4072 | "%s: failed create dif_bundl_pool\n", | |
4073 | __func__); | |
4074 | goto fail_dif_bundl_dma_pool; | |
4075 | } | |
4076 | ||
4077 | INIT_LIST_HEAD(&ha->pool.good.head); | |
4078 | INIT_LIST_HEAD(&ha->pool.unusable.head); | |
4079 | ha->pool.good.count = 0; | |
4080 | ha->pool.unusable.count = 0; | |
4081 | for (i = 0; i < 128; i++) { | |
4082 | dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC); | |
4083 | if (!dsd) { | |
4084 | ql_dbg_pci(ql_dbg_init, ha->pdev, | |
4085 | 0xe0ee, "%s: failed alloc dsd\n", | |
4086 | __func__); | |
4087 | return 1; | |
4088 | } | |
4089 | ha->dif_bundle_kallocs++; | |
4090 | ||
4091 | dsd->dsd_addr = dma_pool_alloc( | |
4092 | ha->dif_bundl_pool, GFP_ATOMIC, | |
4093 | &dsd->dsd_list_dma); | |
4094 | if (!dsd->dsd_addr) { | |
4095 | ql_dbg_pci(ql_dbg_init, ha->pdev, | |
4096 | 0xe0ee, | |
4097 | "%s: failed alloc ->dsd_addr\n", | |
4098 | __func__); | |
4099 | kfree(dsd); | |
4100 | ha->dif_bundle_kallocs--; | |
4101 | continue; | |
4102 | } | |
4103 | ha->dif_bundle_dma_allocs++; | |
4104 | ||
4105 | /* | |
4106 | * if DMA buffer crosses 4G boundary, | |
4107 | * put it on bad list | |
4108 | */ | |
4109 | if (MSD(dsd->dsd_list_dma) ^ | |
4110 | MSD(dsd->dsd_list_dma + bufsize)) { | |
4111 | list_add_tail(&dsd->list, | |
4112 | &ha->pool.unusable.head); | |
4113 | ha->pool.unusable.count++; | |
4114 | } else { | |
4115 | list_add_tail(&dsd->list, | |
4116 | &ha->pool.good.head); | |
4117 | ha->pool.good.count++; | |
4118 | } | |
4119 | } | |
4120 | ||
4121 | /* return the good ones back to the pool */ | |
4122 | list_for_each_entry_safe(dsd, nxt, | |
4123 | &ha->pool.good.head, list) { | |
4124 | list_del(&dsd->list); | |
4125 | dma_pool_free(ha->dif_bundl_pool, | |
4126 | dsd->dsd_addr, dsd->dsd_list_dma); | |
4127 | ha->dif_bundle_dma_allocs--; | |
4128 | kfree(dsd); | |
4129 | ha->dif_bundle_kallocs--; | |
4130 | } | |
4131 | ||
4132 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024, | |
4133 | "%s: dif dma pool (good=%u unusable=%u)\n", | |
4134 | __func__, ha->pool.good.count, | |
4135 | ha->pool.unusable.count); | |
4136 | } | |
4137 | ||
7c3df132 | 4138 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025, |
50b81275 GM |
4139 | "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n", |
4140 | ha->dl_dma_pool, ha->fcp_cmnd_dma_pool, | |
4141 | ha->dif_bundl_pool); | |
a9083016 GM |
4142 | } |
4143 | ||
e8711085 AV |
4144 | /* Allocate memory for SNS commands */ |
4145 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { | |
e315cd28 | 4146 | /* Get consistent memory allocated for SNS commands */ |
e8711085 | 4147 | ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev, |
e315cd28 | 4148 | sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL); |
e8711085 | 4149 | if (!ha->sns_cmd) |
e315cd28 | 4150 | goto fail_dma_pool; |
7c3df132 | 4151 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026, |
d8424f68 | 4152 | "sns_cmd: %p.\n", ha->sns_cmd); |
e8711085 | 4153 | } else { |
e315cd28 | 4154 | /* Get consistent memory allocated for MS IOCB */ |
e8711085 | 4155 | ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
e315cd28 | 4156 | &ha->ms_iocb_dma); |
e8711085 | 4157 | if (!ha->ms_iocb) |
e315cd28 AC |
4158 | goto fail_dma_pool; |
4159 | /* Get consistent memory allocated for CT SNS commands */ | |
e8711085 | 4160 | ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev, |
e315cd28 | 4161 | sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL); |
e8711085 AV |
4162 | if (!ha->ct_sns) |
4163 | goto fail_free_ms_iocb; | |
7c3df132 SK |
4164 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027, |
4165 | "ms_iocb=%p ct_sns=%p.\n", | |
4166 | ha->ms_iocb, ha->ct_sns); | |
1da177e4 LT |
4167 | } |
4168 | ||
e315cd28 | 4169 | /* Allocate memory for request ring */ |
73208dfd AC |
4170 | *req = kzalloc(sizeof(struct req_que), GFP_KERNEL); |
4171 | if (!*req) { | |
7c3df132 SK |
4172 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0028, |
4173 | "Failed to allocate memory for req.\n"); | |
e315cd28 AC |
4174 | goto fail_req; |
4175 | } | |
73208dfd AC |
4176 | (*req)->length = req_len; |
4177 | (*req)->ring = dma_alloc_coherent(&ha->pdev->dev, | |
4178 | ((*req)->length + 1) * sizeof(request_t), | |
4179 | &(*req)->dma, GFP_KERNEL); | |
4180 | if (!(*req)->ring) { | |
7c3df132 SK |
4181 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0029, |
4182 | "Failed to allocate memory for req_ring.\n"); | |
e315cd28 AC |
4183 | goto fail_req_ring; |
4184 | } | |
4185 | /* Allocate memory for response ring */ | |
73208dfd AC |
4186 | *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL); |
4187 | if (!*rsp) { | |
7c3df132 SK |
4188 | ql_log_pci(ql_log_fatal, ha->pdev, 0x002a, |
4189 | "Failed to allocate memory for rsp.\n"); | |
e315cd28 AC |
4190 | goto fail_rsp; |
4191 | } | |
73208dfd AC |
4192 | (*rsp)->hw = ha; |
4193 | (*rsp)->length = rsp_len; | |
4194 | (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev, | |
4195 | ((*rsp)->length + 1) * sizeof(response_t), | |
4196 | &(*rsp)->dma, GFP_KERNEL); | |
4197 | if (!(*rsp)->ring) { | |
7c3df132 SK |
4198 | ql_log_pci(ql_log_fatal, ha->pdev, 0x002b, |
4199 | "Failed to allocate memory for rsp_ring.\n"); | |
e315cd28 AC |
4200 | goto fail_rsp_ring; |
4201 | } | |
73208dfd AC |
4202 | (*req)->rsp = *rsp; |
4203 | (*rsp)->req = *req; | |
7c3df132 SK |
4204 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c, |
4205 | "req=%p req->length=%d req->ring=%p rsp=%p " | |
4206 | "rsp->length=%d rsp->ring=%p.\n", | |
4207 | *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length, | |
4208 | (*rsp)->ring); | |
73208dfd AC |
4209 | /* Allocate memory for NVRAM data for vports */ |
4210 | if (ha->nvram_npiv_size) { | |
6396bb22 KC |
4211 | ha->npiv_info = kcalloc(ha->nvram_npiv_size, |
4212 | sizeof(struct qla_npiv_entry), | |
4213 | GFP_KERNEL); | |
73208dfd | 4214 | if (!ha->npiv_info) { |
7c3df132 SK |
4215 | ql_log_pci(ql_log_fatal, ha->pdev, 0x002d, |
4216 | "Failed to allocate memory for npiv_info.\n"); | |
73208dfd AC |
4217 | goto fail_npiv_info; |
4218 | } | |
4219 | } else | |
4220 | ha->npiv_info = NULL; | |
e8711085 | 4221 | |
b64b0e8f | 4222 | /* Get consistent memory allocated for EX-INIT-CB. */ |
ecc89f25 JC |
4223 | if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) || |
4224 | IS_QLA28XX(ha)) { | |
b64b0e8f AV |
4225 | ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, |
4226 | &ha->ex_init_cb_dma); | |
4227 | if (!ha->ex_init_cb) | |
4228 | goto fail_ex_init_cb; | |
7c3df132 SK |
4229 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e, |
4230 | "ex_init_cb=%p.\n", ha->ex_init_cb); | |
b64b0e8f AV |
4231 | } |
4232 | ||
a9083016 GM |
4233 | INIT_LIST_HEAD(&ha->gbl_dsd_list); |
4234 | ||
5ff1d584 AV |
4235 | /* Get consistent memory allocated for Async Port-Database. */ |
4236 | if (!IS_FWI2_CAPABLE(ha)) { | |
4237 | ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, | |
4238 | &ha->async_pd_dma); | |
4239 | if (!ha->async_pd) | |
4240 | goto fail_async_pd; | |
7c3df132 SK |
4241 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f, |
4242 | "async_pd=%p.\n", ha->async_pd); | |
5ff1d584 AV |
4243 | } |
4244 | ||
e315cd28 | 4245 | INIT_LIST_HEAD(&ha->vp_list); |
5f16b331 CD |
4246 | |
4247 | /* Allocate memory for our loop_id bitmap */ | |
6396bb22 KC |
4248 | ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE), |
4249 | sizeof(long), | |
4250 | GFP_KERNEL); | |
5f16b331 | 4251 | if (!ha->loop_id_map) |
fc1ffd6c | 4252 | goto fail_loop_id_map; |
5f16b331 CD |
4253 | else { |
4254 | qla2x00_set_reserved_loop_ids(ha); | |
4255 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123, | |
b2a72ec3 | 4256 | "loop_id_map=%p.\n", ha->loop_id_map); |
5f16b331 CD |
4257 | } |
4258 | ||
e4e3a2ce QT |
4259 | ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev, |
4260 | SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL); | |
4261 | if (!ha->sfp_data) { | |
4262 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b, | |
4263 | "Unable to allocate memory for SFP read-data.\n"); | |
4264 | goto fail_sfp_data; | |
4265 | } | |
4266 | ||
3f006ac3 MH |
4267 | ha->flt = dma_alloc_coherent(&ha->pdev->dev, |
4268 | sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma, | |
4269 | GFP_KERNEL); | |
4270 | if (!ha->flt) { | |
4271 | ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b, | |
4272 | "Unable to allocate memory for FLT.\n"); | |
4273 | goto fail_flt_buffer; | |
4274 | } | |
4275 | ||
b2a72ec3 | 4276 | return 0; |
e315cd28 | 4277 | |
3f006ac3 MH |
4278 | fail_flt_buffer: |
4279 | dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, | |
4280 | ha->sfp_data, ha->sfp_data_dma); | |
e4e3a2ce QT |
4281 | fail_sfp_data: |
4282 | kfree(ha->loop_id_map); | |
fc1ffd6c QT |
4283 | fail_loop_id_map: |
4284 | dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma); | |
5ff1d584 AV |
4285 | fail_async_pd: |
4286 | dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma); | |
b64b0e8f AV |
4287 | fail_ex_init_cb: |
4288 | kfree(ha->npiv_info); | |
73208dfd AC |
4289 | fail_npiv_info: |
4290 | dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) * | |
4291 | sizeof(response_t), (*rsp)->ring, (*rsp)->dma); | |
4292 | (*rsp)->ring = NULL; | |
4293 | (*rsp)->dma = 0; | |
e315cd28 | 4294 | fail_rsp_ring: |
73208dfd | 4295 | kfree(*rsp); |
6d634067 | 4296 | *rsp = NULL; |
e315cd28 | 4297 | fail_rsp: |
73208dfd AC |
4298 | dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) * |
4299 | sizeof(request_t), (*req)->ring, (*req)->dma); | |
4300 | (*req)->ring = NULL; | |
4301 | (*req)->dma = 0; | |
e315cd28 | 4302 | fail_req_ring: |
73208dfd | 4303 | kfree(*req); |
6d634067 | 4304 | *req = NULL; |
e315cd28 AC |
4305 | fail_req: |
4306 | dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), | |
4307 | ha->ct_sns, ha->ct_sns_dma); | |
4308 | ha->ct_sns = NULL; | |
4309 | ha->ct_sns_dma = 0; | |
e8711085 AV |
4310 | fail_free_ms_iocb: |
4311 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); | |
4312 | ha->ms_iocb = NULL; | |
4313 | ha->ms_iocb_dma = 0; | |
fc1ffd6c QT |
4314 | |
4315 | if (ha->sns_cmd) | |
4316 | dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), | |
4317 | ha->sns_cmd, ha->sns_cmd_dma); | |
e315cd28 | 4318 | fail_dma_pool: |
50b81275 GM |
4319 | if (ql2xenabledif) { |
4320 | struct dsd_dma *dsd, *nxt; | |
4321 | ||
4322 | list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head, | |
4323 | list) { | |
4324 | list_del(&dsd->list); | |
4325 | dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr, | |
4326 | dsd->dsd_list_dma); | |
4327 | ha->dif_bundle_dma_allocs--; | |
4328 | kfree(dsd); | |
4329 | ha->dif_bundle_kallocs--; | |
4330 | ha->pool.unusable.count--; | |
4331 | } | |
4332 | dma_pool_destroy(ha->dif_bundl_pool); | |
4333 | ha->dif_bundl_pool = NULL; | |
4334 | } | |
4335 | ||
4336 | fail_dif_bundl_dma_pool: | |
bad75002 | 4337 | if (IS_QLA82XX(ha) || ql2xenabledif) { |
a9083016 GM |
4338 | dma_pool_destroy(ha->fcp_cmnd_dma_pool); |
4339 | ha->fcp_cmnd_dma_pool = NULL; | |
4340 | } | |
4341 | fail_dl_dma_pool: | |
bad75002 | 4342 | if (IS_QLA82XX(ha) || ql2xenabledif) { |
a9083016 GM |
4343 | dma_pool_destroy(ha->dl_dma_pool); |
4344 | ha->dl_dma_pool = NULL; | |
4345 | } | |
4346 | fail_s_dma_pool: | |
e315cd28 AC |
4347 | dma_pool_destroy(ha->s_dma_pool); |
4348 | ha->s_dma_pool = NULL; | |
e8711085 AV |
4349 | fail_free_nvram: |
4350 | kfree(ha->nvram); | |
4351 | ha->nvram = NULL; | |
a9083016 | 4352 | fail_free_ctx_mempool: |
75c1d48a | 4353 | mempool_destroy(ha->ctx_mempool); |
a9083016 | 4354 | ha->ctx_mempool = NULL; |
e8711085 | 4355 | fail_free_srb_mempool: |
75c1d48a | 4356 | mempool_destroy(ha->srb_mempool); |
e8711085 | 4357 | ha->srb_mempool = NULL; |
e8711085 | 4358 | fail_free_gid_list: |
642ef983 CD |
4359 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
4360 | ha->gid_list, | |
e315cd28 | 4361 | ha->gid_list_dma); |
e8711085 AV |
4362 | ha->gid_list = NULL; |
4363 | ha->gid_list_dma = 0; | |
2d70c103 NB |
4364 | fail_free_tgt_mem: |
4365 | qlt_mem_free(ha); | |
e315cd28 AC |
4366 | fail_free_init_cb: |
4367 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb, | |
4368 | ha->init_cb_dma); | |
4369 | ha->init_cb = NULL; | |
4370 | ha->init_cb_dma = 0; | |
e8711085 | 4371 | fail: |
7c3df132 SK |
4372 | ql_log(ql_log_fatal, NULL, 0x0030, |
4373 | "Memory allocation failure.\n"); | |
e8711085 | 4374 | return -ENOMEM; |
1da177e4 LT |
4375 | } |
4376 | ||
b0d6cabd HM |
4377 | int |
4378 | qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha) | |
4379 | { | |
4380 | int rval; | |
4381 | uint16_t size, max_cnt, temp; | |
4382 | struct qla_hw_data *ha = vha->hw; | |
4383 | ||
4384 | /* Return if we don't need to alloacate any extended logins */ | |
4385 | if (!ql2xexlogins) | |
4386 | return QLA_SUCCESS; | |
4387 | ||
99e1b683 QT |
4388 | if (!IS_EXLOGIN_OFFLD_CAPABLE(ha)) |
4389 | return QLA_SUCCESS; | |
4390 | ||
b0d6cabd HM |
4391 | ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins); |
4392 | max_cnt = 0; | |
4393 | rval = qla_get_exlogin_status(vha, &size, &max_cnt); | |
4394 | if (rval != QLA_SUCCESS) { | |
4395 | ql_log_pci(ql_log_fatal, ha->pdev, 0xd029, | |
4396 | "Failed to get exlogin status.\n"); | |
4397 | return rval; | |
4398 | } | |
4399 | ||
4400 | temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins; | |
99e1b683 QT |
4401 | temp *= size; |
4402 | ||
4403 | if (temp != ha->exlogin_size) { | |
4404 | qla2x00_free_exlogin_buffer(ha); | |
4405 | ha->exlogin_size = temp; | |
4406 | ||
4407 | ql_log(ql_log_info, vha, 0xd024, | |
4408 | "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n", | |
4409 | max_cnt, size, temp); | |
4410 | ||
4411 | ql_log(ql_log_info, vha, 0xd025, | |
4412 | "EXLOGIN: requested size=0x%x\n", ha->exlogin_size); | |
4413 | ||
4414 | /* Get consistent memory for extended logins */ | |
4415 | ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev, | |
4416 | ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL); | |
4417 | if (!ha->exlogin_buf) { | |
4418 | ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a, | |
b0d6cabd | 4419 | "Failed to allocate memory for exlogin_buf_dma.\n"); |
99e1b683 QT |
4420 | return -ENOMEM; |
4421 | } | |
b0d6cabd HM |
4422 | } |
4423 | ||
4424 | /* Now configure the dma buffer */ | |
4425 | rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma); | |
4426 | if (rval) { | |
83548fe2 | 4427 | ql_log(ql_log_fatal, vha, 0xd033, |
b0d6cabd HM |
4428 | "Setup extended login buffer ****FAILED****.\n"); |
4429 | qla2x00_free_exlogin_buffer(ha); | |
4430 | } | |
4431 | ||
4432 | return rval; | |
4433 | } | |
4434 | ||
4435 | /* | |
4436 | * qla2x00_free_exlogin_buffer | |
4437 | * | |
4438 | * Input: | |
4439 | * ha = adapter block pointer | |
4440 | */ | |
4441 | void | |
4442 | qla2x00_free_exlogin_buffer(struct qla_hw_data *ha) | |
4443 | { | |
4444 | if (ha->exlogin_buf) { | |
4445 | dma_free_coherent(&ha->pdev->dev, ha->exlogin_size, | |
4446 | ha->exlogin_buf, ha->exlogin_buf_dma); | |
4447 | ha->exlogin_buf = NULL; | |
4448 | ha->exlogin_size = 0; | |
4449 | } | |
4450 | } | |
4451 | ||
99e1b683 QT |
4452 | static void |
4453 | qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt) | |
4454 | { | |
4455 | u32 temp; | |
0645cb83 | 4456 | struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb; |
99e1b683 QT |
4457 | *ret_cnt = FW_DEF_EXCHANGES_CNT; |
4458 | ||
d1e3635a QT |
4459 | if (max_cnt > vha->hw->max_exchg) |
4460 | max_cnt = vha->hw->max_exchg; | |
4461 | ||
99e1b683 | 4462 | if (qla_ini_mode_enabled(vha)) { |
0645cb83 QT |
4463 | if (vha->ql2xiniexchg > max_cnt) |
4464 | vha->ql2xiniexchg = max_cnt; | |
4465 | ||
4466 | if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT) | |
4467 | *ret_cnt = vha->ql2xiniexchg; | |
99e1b683 | 4468 | |
99e1b683 | 4469 | } else if (qla_tgt_mode_enabled(vha)) { |
0645cb83 QT |
4470 | if (vha->ql2xexchoffld > max_cnt) { |
4471 | vha->ql2xexchoffld = max_cnt; | |
4472 | icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld); | |
4473 | } | |
99e1b683 | 4474 | |
0645cb83 QT |
4475 | if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT) |
4476 | *ret_cnt = vha->ql2xexchoffld; | |
99e1b683 | 4477 | } else if (qla_dual_mode_enabled(vha)) { |
0645cb83 | 4478 | temp = vha->ql2xiniexchg + vha->ql2xexchoffld; |
99e1b683 | 4479 | if (temp > max_cnt) { |
0645cb83 QT |
4480 | vha->ql2xiniexchg -= (temp - max_cnt)/2; |
4481 | vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1); | |
99e1b683 | 4482 | temp = max_cnt; |
0645cb83 | 4483 | icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
99e1b683 QT |
4484 | } |
4485 | ||
4486 | if (temp > FW_DEF_EXCHANGES_CNT) | |
4487 | *ret_cnt = temp; | |
4488 | } | |
4489 | } | |
4490 | ||
2f56a7f1 HM |
4491 | int |
4492 | qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha) | |
4493 | { | |
4494 | int rval; | |
d1e3635a QT |
4495 | u16 size, max_cnt; |
4496 | u32 actual_cnt, totsz; | |
2f56a7f1 HM |
4497 | struct qla_hw_data *ha = vha->hw; |
4498 | ||
99e1b683 QT |
4499 | if (!ha->flags.exchoffld_enabled) |
4500 | return QLA_SUCCESS; | |
4501 | ||
4502 | if (!IS_EXCHG_OFFLD_CAPABLE(ha)) | |
2f56a7f1 HM |
4503 | return QLA_SUCCESS; |
4504 | ||
2f56a7f1 HM |
4505 | max_cnt = 0; |
4506 | rval = qla_get_exchoffld_status(vha, &size, &max_cnt); | |
4507 | if (rval != QLA_SUCCESS) { | |
4508 | ql_log_pci(ql_log_fatal, ha->pdev, 0xd012, | |
4509 | "Failed to get exlogin status.\n"); | |
4510 | return rval; | |
4511 | } | |
4512 | ||
d1e3635a QT |
4513 | qla2x00_number_of_exch(vha, &actual_cnt, max_cnt); |
4514 | ql_log(ql_log_info, vha, 0xd014, | |
4515 | "Actual exchange offload count: %d.\n", actual_cnt); | |
4516 | ||
4517 | totsz = actual_cnt * size; | |
2f56a7f1 | 4518 | |
d1e3635a | 4519 | if (totsz != ha->exchoffld_size) { |
99e1b683 | 4520 | qla2x00_free_exchoffld_buffer(ha); |
0645cb83 QT |
4521 | if (actual_cnt <= FW_DEF_EXCHANGES_CNT) { |
4522 | ha->exchoffld_size = 0; | |
4523 | ha->flags.exchoffld_enabled = 0; | |
4524 | return QLA_SUCCESS; | |
4525 | } | |
4526 | ||
d1e3635a | 4527 | ha->exchoffld_size = totsz; |
99e1b683 QT |
4528 | |
4529 | ql_log(ql_log_info, vha, 0xd016, | |
d1e3635a QT |
4530 | "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n", |
4531 | max_cnt, actual_cnt, size, totsz); | |
99e1b683 QT |
4532 | |
4533 | ql_log(ql_log_info, vha, 0xd017, | |
4534 | "Exchange Buffers requested size = 0x%x\n", | |
4535 | ha->exchoffld_size); | |
4536 | ||
4537 | /* Get consistent memory for extended logins */ | |
4538 | ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev, | |
4539 | ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL); | |
4540 | if (!ha->exchoffld_buf) { | |
4541 | ql_log_pci(ql_log_fatal, ha->pdev, 0xd013, | |
d1e3635a QT |
4542 | "Failed to allocate memory for Exchange Offload.\n"); |
4543 | ||
4544 | if (ha->max_exchg > | |
4545 | (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) { | |
4546 | ha->max_exchg -= REDUCE_EXCHANGES_CNT; | |
4547 | } else if (ha->max_exchg > | |
4548 | (FW_DEF_EXCHANGES_CNT + 512)) { | |
4549 | ha->max_exchg -= 512; | |
4550 | } else { | |
4551 | ha->flags.exchoffld_enabled = 0; | |
4552 | ql_log_pci(ql_log_fatal, ha->pdev, 0xd013, | |
4553 | "Disabling Exchange offload due to lack of memory\n"); | |
4554 | } | |
4555 | ha->exchoffld_size = 0; | |
4556 | ||
99e1b683 QT |
4557 | return -ENOMEM; |
4558 | } | |
0645cb83 QT |
4559 | } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) { |
4560 | /* pathological case */ | |
4561 | qla2x00_free_exchoffld_buffer(ha); | |
4562 | ha->exchoffld_size = 0; | |
4563 | ha->flags.exchoffld_enabled = 0; | |
4564 | ql_log(ql_log_info, vha, 0xd016, | |
4565 | "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n", | |
4566 | ha->exchoffld_size, actual_cnt, size, totsz); | |
4567 | return 0; | |
2f56a7f1 HM |
4568 | } |
4569 | ||
4570 | /* Now configure the dma buffer */ | |
99e1b683 | 4571 | rval = qla_set_exchoffld_mem_cfg(vha); |
2f56a7f1 HM |
4572 | if (rval) { |
4573 | ql_log(ql_log_fatal, vha, 0xd02e, | |
4574 | "Setup exchange offload buffer ****FAILED****.\n"); | |
4575 | qla2x00_free_exchoffld_buffer(ha); | |
99e1b683 QT |
4576 | } else { |
4577 | /* re-adjust number of target exchange */ | |
4578 | struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb; | |
4579 | ||
4580 | if (qla_ini_mode_enabled(vha)) | |
4581 | icb->exchange_count = 0; | |
4582 | else | |
0645cb83 | 4583 | icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld); |
2f56a7f1 HM |
4584 | } |
4585 | ||
4586 | return rval; | |
4587 | } | |
4588 | ||
4589 | /* | |
4590 | * qla2x00_free_exchoffld_buffer | |
4591 | * | |
4592 | * Input: | |
4593 | * ha = adapter block pointer | |
4594 | */ | |
4595 | void | |
4596 | qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha) | |
4597 | { | |
4598 | if (ha->exchoffld_buf) { | |
4599 | dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size, | |
4600 | ha->exchoffld_buf, ha->exchoffld_buf_dma); | |
4601 | ha->exchoffld_buf = NULL; | |
4602 | ha->exchoffld_size = 0; | |
4603 | } | |
4604 | } | |
4605 | ||
1da177e4 | 4606 | /* |
e30d1756 MI |
4607 | * qla2x00_free_fw_dump |
4608 | * Frees fw dump stuff. | |
1da177e4 LT |
4609 | * |
4610 | * Input: | |
7ec0effd | 4611 | * ha = adapter block pointer |
1da177e4 | 4612 | */ |
a824ebb3 | 4613 | static void |
e30d1756 | 4614 | qla2x00_free_fw_dump(struct qla_hw_data *ha) |
1da177e4 | 4615 | { |
a28d9e4e JC |
4616 | struct fwdt *fwdt = ha->fwdt; |
4617 | uint j; | |
4618 | ||
df613b96 | 4619 | if (ha->fce) |
f73cb695 CD |
4620 | dma_free_coherent(&ha->pdev->dev, |
4621 | FCE_SIZE, ha->fce, ha->fce_dma); | |
df613b96 | 4622 | |
f73cb695 CD |
4623 | if (ha->eft) |
4624 | dma_free_coherent(&ha->pdev->dev, | |
4625 | EFT_SIZE, ha->eft, ha->eft_dma); | |
4626 | ||
4627 | if (ha->fw_dump) | |
a7a167bf | 4628 | vfree(ha->fw_dump); |
f73cb695 | 4629 | |
e30d1756 MI |
4630 | ha->fce = NULL; |
4631 | ha->fce_dma = 0; | |
4632 | ha->eft = NULL; | |
4633 | ha->eft_dma = 0; | |
e30d1756 | 4634 | ha->fw_dumped = 0; |
61f098dd | 4635 | ha->fw_dump_cap_flags = 0; |
e30d1756 | 4636 | ha->fw_dump_reading = 0; |
f73cb695 CD |
4637 | ha->fw_dump = NULL; |
4638 | ha->fw_dump_len = 0; | |
a28d9e4e JC |
4639 | |
4640 | for (j = 0; j < 2; j++, fwdt++) { | |
4641 | if (fwdt->template) | |
4642 | vfree(fwdt->template); | |
4643 | fwdt->template = NULL; | |
4644 | fwdt->length = 0; | |
4645 | } | |
e30d1756 MI |
4646 | } |
4647 | ||
4648 | /* | |
4649 | * qla2x00_mem_free | |
4650 | * Frees all adapter allocated memory. | |
4651 | * | |
4652 | * Input: | |
4653 | * ha = adapter block pointer. | |
4654 | */ | |
4655 | static void | |
4656 | qla2x00_mem_free(struct qla_hw_data *ha) | |
4657 | { | |
4658 | qla2x00_free_fw_dump(ha); | |
4659 | ||
81178772 SK |
4660 | if (ha->mctp_dump) |
4661 | dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump, | |
4662 | ha->mctp_dump_dma); | |
5365bf99 | 4663 | ha->mctp_dump = NULL; |
81178772 | 4664 | |
75c1d48a | 4665 | mempool_destroy(ha->srb_mempool); |
5365bf99 | 4666 | ha->srb_mempool = NULL; |
a7a167bf | 4667 | |
11bbc1d8 AV |
4668 | if (ha->dcbx_tlv) |
4669 | dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE, | |
4670 | ha->dcbx_tlv, ha->dcbx_tlv_dma); | |
5365bf99 | 4671 | ha->dcbx_tlv = NULL; |
11bbc1d8 | 4672 | |
ce0423f4 AV |
4673 | if (ha->xgmac_data) |
4674 | dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE, | |
4675 | ha->xgmac_data, ha->xgmac_data_dma); | |
5365bf99 | 4676 | ha->xgmac_data = NULL; |
ce0423f4 | 4677 | |
1da177e4 LT |
4678 | if (ha->sns_cmd) |
4679 | dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), | |
e315cd28 | 4680 | ha->sns_cmd, ha->sns_cmd_dma); |
5365bf99 BVA |
4681 | ha->sns_cmd = NULL; |
4682 | ha->sns_cmd_dma = 0; | |
1da177e4 LT |
4683 | |
4684 | if (ha->ct_sns) | |
4685 | dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), | |
e315cd28 | 4686 | ha->ct_sns, ha->ct_sns_dma); |
5365bf99 BVA |
4687 | ha->ct_sns = NULL; |
4688 | ha->ct_sns_dma = 0; | |
1da177e4 | 4689 | |
88729e53 | 4690 | if (ha->sfp_data) |
e4e3a2ce QT |
4691 | dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data, |
4692 | ha->sfp_data_dma); | |
5365bf99 | 4693 | ha->sfp_data = NULL; |
88729e53 | 4694 | |
3f006ac3 MH |
4695 | if (ha->flt) |
4696 | dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, | |
4697 | ha->flt, ha->flt_dma); | |
dc035d4e BVA |
4698 | ha->flt = NULL; |
4699 | ha->flt_dma = 0; | |
3f006ac3 | 4700 | |
1da177e4 LT |
4701 | if (ha->ms_iocb) |
4702 | dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); | |
5365bf99 BVA |
4703 | ha->ms_iocb = NULL; |
4704 | ha->ms_iocb_dma = 0; | |
1da177e4 | 4705 | |
b64b0e8f | 4706 | if (ha->ex_init_cb) |
a9083016 GM |
4707 | dma_pool_free(ha->s_dma_pool, |
4708 | ha->ex_init_cb, ha->ex_init_cb_dma); | |
5365bf99 BVA |
4709 | ha->ex_init_cb = NULL; |
4710 | ha->ex_init_cb_dma = 0; | |
b64b0e8f | 4711 | |
5ff1d584 AV |
4712 | if (ha->async_pd) |
4713 | dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma); | |
5365bf99 BVA |
4714 | ha->async_pd = NULL; |
4715 | ha->async_pd_dma = 0; | |
5ff1d584 | 4716 | |
75c1d48a | 4717 | dma_pool_destroy(ha->s_dma_pool); |
5365bf99 | 4718 | ha->s_dma_pool = NULL; |
1da177e4 | 4719 | |
1da177e4 | 4720 | if (ha->gid_list) |
642ef983 CD |
4721 | dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), |
4722 | ha->gid_list, ha->gid_list_dma); | |
5365bf99 BVA |
4723 | ha->gid_list = NULL; |
4724 | ha->gid_list_dma = 0; | |
1da177e4 | 4725 | |
a9083016 GM |
4726 | if (IS_QLA82XX(ha)) { |
4727 | if (!list_empty(&ha->gbl_dsd_list)) { | |
4728 | struct dsd_dma *dsd_ptr, *tdsd_ptr; | |
4729 | ||
4730 | /* clean up allocated prev pool */ | |
4731 | list_for_each_entry_safe(dsd_ptr, | |
4732 | tdsd_ptr, &ha->gbl_dsd_list, list) { | |
4733 | dma_pool_free(ha->dl_dma_pool, | |
4734 | dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma); | |
4735 | list_del(&dsd_ptr->list); | |
4736 | kfree(dsd_ptr); | |
4737 | } | |
4738 | } | |
4739 | } | |
4740 | ||
75c1d48a | 4741 | dma_pool_destroy(ha->dl_dma_pool); |
5365bf99 | 4742 | ha->dl_dma_pool = NULL; |
a9083016 | 4743 | |
75c1d48a | 4744 | dma_pool_destroy(ha->fcp_cmnd_dma_pool); |
5365bf99 | 4745 | ha->fcp_cmnd_dma_pool = NULL; |
a9083016 | 4746 | |
75c1d48a | 4747 | mempool_destroy(ha->ctx_mempool); |
5365bf99 | 4748 | ha->ctx_mempool = NULL; |
a9083016 | 4749 | |
26a77799 | 4750 | if (ql2xenabledif && ha->dif_bundl_pool) { |
50b81275 GM |
4751 | struct dsd_dma *dsd, *nxt; |
4752 | ||
4753 | list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head, | |
4754 | list) { | |
4755 | list_del(&dsd->list); | |
4756 | dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr, | |
4757 | dsd->dsd_list_dma); | |
4758 | ha->dif_bundle_dma_allocs--; | |
4759 | kfree(dsd); | |
4760 | ha->dif_bundle_kallocs--; | |
4761 | ha->pool.unusable.count--; | |
4762 | } | |
4763 | list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) { | |
4764 | list_del(&dsd->list); | |
4765 | dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr, | |
4766 | dsd->dsd_list_dma); | |
4767 | ha->dif_bundle_dma_allocs--; | |
4768 | kfree(dsd); | |
4769 | ha->dif_bundle_kallocs--; | |
4770 | } | |
4771 | } | |
4772 | ||
0b3b6fe2 | 4773 | dma_pool_destroy(ha->dif_bundl_pool); |
dc035d4e | 4774 | ha->dif_bundl_pool = NULL; |
50b81275 | 4775 | |
2d70c103 NB |
4776 | qlt_mem_free(ha); |
4777 | ||
e315cd28 AC |
4778 | if (ha->init_cb) |
4779 | dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, | |
a9083016 | 4780 | ha->init_cb, ha->init_cb_dma); |
5365bf99 BVA |
4781 | ha->init_cb = NULL; |
4782 | ha->init_cb_dma = 0; | |
6a2cf8d3 | 4783 | |
6d634067 | 4784 | vfree(ha->optrom_buffer); |
5365bf99 | 4785 | ha->optrom_buffer = NULL; |
6d634067 | 4786 | kfree(ha->nvram); |
5365bf99 | 4787 | ha->nvram = NULL; |
6d634067 | 4788 | kfree(ha->npiv_info); |
5365bf99 | 4789 | ha->npiv_info = NULL; |
6d634067 | 4790 | kfree(ha->swl); |
5365bf99 | 4791 | ha->swl = NULL; |
6d634067 | 4792 | kfree(ha->loop_id_map); |
6a2cf8d3 | 4793 | ha->loop_id_map = NULL; |
e315cd28 | 4794 | } |
1da177e4 | 4795 | |
e315cd28 AC |
4796 | struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, |
4797 | struct qla_hw_data *ha) | |
4798 | { | |
4799 | struct Scsi_Host *host; | |
4800 | struct scsi_qla_host *vha = NULL; | |
854165f4 | 4801 | |
e315cd28 | 4802 | host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t)); |
41dc529a | 4803 | if (!host) { |
7c3df132 SK |
4804 | ql_log_pci(ql_log_fatal, ha->pdev, 0x0107, |
4805 | "Failed to allocate host from the scsi layer, aborting.\n"); | |
41dc529a | 4806 | return NULL; |
e315cd28 AC |
4807 | } |
4808 | ||
4809 | /* Clear our data area */ | |
4810 | vha = shost_priv(host); | |
4811 | memset(vha, 0, sizeof(scsi_qla_host_t)); | |
4812 | ||
4813 | vha->host = host; | |
4814 | vha->host_no = host->host_no; | |
4815 | vha->hw = ha; | |
4816 | ||
0645cb83 QT |
4817 | vha->qlini_mode = ql2x_ini_mode; |
4818 | vha->ql2xexchoffld = ql2xexchoffld; | |
4819 | vha->ql2xiniexchg = ql2xiniexchg; | |
4820 | ||
e315cd28 AC |
4821 | INIT_LIST_HEAD(&vha->vp_fcports); |
4822 | INIT_LIST_HEAD(&vha->work_list); | |
4823 | INIT_LIST_HEAD(&vha->list); | |
8b2f5ff3 SN |
4824 | INIT_LIST_HEAD(&vha->qla_cmd_list); |
4825 | INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list); | |
71cdc079 | 4826 | INIT_LIST_HEAD(&vha->logo_list); |
b7bd104e | 4827 | INIT_LIST_HEAD(&vha->plogi_ack_list); |
d7459527 | 4828 | INIT_LIST_HEAD(&vha->qp_list); |
41dc529a | 4829 | INIT_LIST_HEAD(&vha->gnl.fcports); |
2d73ac61 | 4830 | INIT_LIST_HEAD(&vha->gpnid_list); |
9b3e0f4d | 4831 | INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn); |
e315cd28 | 4832 | |
f999f4c1 | 4833 | spin_lock_init(&vha->work_lock); |
8b2f5ff3 | 4834 | spin_lock_init(&vha->cmd_list_lock); |
726b8548 | 4835 | init_waitqueue_head(&vha->fcport_waitQ); |
c4a9b538 | 4836 | init_waitqueue_head(&vha->vref_waitq); |
f999f4c1 | 4837 | |
2fdbc65e BVA |
4838 | vha->gnl.size = sizeof(struct get_name_list_extended) * |
4839 | (ha->max_loop_id + 1); | |
41dc529a QT |
4840 | vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev, |
4841 | vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL); | |
4842 | if (!vha->gnl.l) { | |
83548fe2 | 4843 | ql_log(ql_log_fatal, vha, 0xd04a, |
41dc529a | 4844 | "Alloc failed for name list.\n"); |
26a77799 | 4845 | scsi_host_put(vha->host); |
41dc529a QT |
4846 | return NULL; |
4847 | } | |
f999f4c1 | 4848 | |
a4239945 QT |
4849 | /* todo: what about ext login? */ |
4850 | vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp); | |
4851 | vha->scan.l = vmalloc(vha->scan.size); | |
4852 | if (!vha->scan.l) { | |
4853 | ql_log(ql_log_fatal, vha, 0xd04a, | |
4854 | "Alloc failed for scan database.\n"); | |
4855 | dma_free_coherent(&ha->pdev->dev, vha->gnl.size, | |
4856 | vha->gnl.l, vha->gnl.ldma); | |
26a77799 | 4857 | scsi_host_put(vha->host); |
a4239945 QT |
4858 | return NULL; |
4859 | } | |
f352eeb7 | 4860 | INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn); |
a4239945 | 4861 | |
e315cd28 | 4862 | sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no); |
7c3df132 SK |
4863 | ql_dbg(ql_dbg_init, vha, 0x0041, |
4864 | "Allocated the host=%p hw=%p vha=%p dev_name=%s", | |
4865 | vha->host, vha->hw, vha, | |
4866 | dev_name(&(ha->pdev->dev))); | |
4867 | ||
e315cd28 | 4868 | return vha; |
1da177e4 LT |
4869 | } |
4870 | ||
726b8548 | 4871 | struct qla_work_evt * |
f999f4c1 | 4872 | qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type) |
0971de7f AV |
4873 | { |
4874 | struct qla_work_evt *e; | |
feafb7b1 AE |
4875 | uint8_t bail; |
4876 | ||
4877 | QLA_VHA_MARK_BUSY(vha, bail); | |
4878 | if (bail) | |
4879 | return NULL; | |
0971de7f | 4880 | |
f999f4c1 | 4881 | e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC); |
feafb7b1 AE |
4882 | if (!e) { |
4883 | QLA_VHA_MARK_NOT_BUSY(vha); | |
0971de7f | 4884 | return NULL; |
feafb7b1 | 4885 | } |
0971de7f AV |
4886 | |
4887 | INIT_LIST_HEAD(&e->list); | |
4888 | e->type = type; | |
4889 | e->flags = QLA_EVT_FLAG_FREE; | |
4890 | return e; | |
4891 | } | |
4892 | ||
726b8548 | 4893 | int |
f999f4c1 | 4894 | qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e) |
0971de7f | 4895 | { |
f999f4c1 | 4896 | unsigned long flags; |
9b3e0f4d | 4897 | bool q = false; |
0971de7f | 4898 | |
f999f4c1 | 4899 | spin_lock_irqsave(&vha->work_lock, flags); |
e315cd28 | 4900 | list_add_tail(&e->list, &vha->work_list); |
9b3e0f4d QT |
4901 | |
4902 | if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags)) | |
4903 | q = true; | |
4904 | ||
f999f4c1 | 4905 | spin_unlock_irqrestore(&vha->work_lock, flags); |
ec7193e2 | 4906 | |
9b3e0f4d QT |
4907 | if (q) |
4908 | queue_work(vha->hw->wq, &vha->iocb_work); | |
f999f4c1 | 4909 | |
0971de7f AV |
4910 | return QLA_SUCCESS; |
4911 | } | |
4912 | ||
4913 | int | |
e315cd28 | 4914 | qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code, |
0971de7f AV |
4915 | u32 data) |
4916 | { | |
4917 | struct qla_work_evt *e; | |
4918 | ||
f999f4c1 | 4919 | e = qla2x00_alloc_work(vha, QLA_EVT_AEN); |
0971de7f AV |
4920 | if (!e) |
4921 | return QLA_FUNCTION_FAILED; | |
4922 | ||
4923 | e->u.aen.code = code; | |
4924 | e->u.aen.data = data; | |
f999f4c1 | 4925 | return qla2x00_post_work(vha, e); |
0971de7f AV |
4926 | } |
4927 | ||
8a659571 AV |
4928 | int |
4929 | qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb) | |
4930 | { | |
4931 | struct qla_work_evt *e; | |
4932 | ||
f999f4c1 | 4933 | e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK); |
8a659571 AV |
4934 | if (!e) |
4935 | return QLA_FUNCTION_FAILED; | |
4936 | ||
4937 | memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t)); | |
f999f4c1 | 4938 | return qla2x00_post_work(vha, e); |
8a659571 AV |
4939 | } |
4940 | ||
ac280b67 AV |
4941 | #define qla2x00_post_async_work(name, type) \ |
4942 | int qla2x00_post_async_##name##_work( \ | |
4943 | struct scsi_qla_host *vha, \ | |
4944 | fc_port_t *fcport, uint16_t *data) \ | |
4945 | { \ | |
4946 | struct qla_work_evt *e; \ | |
4947 | \ | |
4948 | e = qla2x00_alloc_work(vha, type); \ | |
4949 | if (!e) \ | |
4950 | return QLA_FUNCTION_FAILED; \ | |
4951 | \ | |
4952 | e->u.logio.fcport = fcport; \ | |
4953 | if (data) { \ | |
4954 | e->u.logio.data[0] = data[0]; \ | |
4955 | e->u.logio.data[1] = data[1]; \ | |
4956 | } \ | |
6d674927 | 4957 | fcport->flags |= FCF_ASYNC_ACTIVE; \ |
ac280b67 AV |
4958 | return qla2x00_post_work(vha, e); \ |
4959 | } | |
4960 | ||
4961 | qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN); | |
ac280b67 AV |
4962 | qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT); |
4963 | qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE); | |
5ff1d584 | 4964 | qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC); |
11aea16a QT |
4965 | qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO); |
4966 | qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE); | |
ac280b67 | 4967 | |
3420d36c AV |
4968 | int |
4969 | qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code) | |
4970 | { | |
4971 | struct qla_work_evt *e; | |
4972 | ||
4973 | e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT); | |
4974 | if (!e) | |
4975 | return QLA_FUNCTION_FAILED; | |
4976 | ||
4977 | e->u.uevent.code = code; | |
4978 | return qla2x00_post_work(vha, e); | |
4979 | } | |
4980 | ||
4981 | static void | |
4982 | qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code) | |
4983 | { | |
4984 | char event_string[40]; | |
4985 | char *envp[] = { event_string, NULL }; | |
4986 | ||
4987 | switch (code) { | |
4988 | case QLA_UEVENT_CODE_FW_DUMP: | |
4989 | snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld", | |
4990 | vha->host_no); | |
4991 | break; | |
4992 | default: | |
4993 | /* do nothing */ | |
4994 | break; | |
4995 | } | |
4996 | kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp); | |
4997 | } | |
4998 | ||
8ae6d9c7 GM |
4999 | int |
5000 | qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode, | |
5001 | uint32_t *data, int cnt) | |
5002 | { | |
5003 | struct qla_work_evt *e; | |
5004 | ||
5005 | e = qla2x00_alloc_work(vha, QLA_EVT_AENFX); | |
5006 | if (!e) | |
5007 | return QLA_FUNCTION_FAILED; | |
5008 | ||
5009 | e->u.aenfx.evtcode = evtcode; | |
5010 | e->u.aenfx.count = cnt; | |
5011 | memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt); | |
5012 | return qla2x00_post_work(vha, e); | |
5013 | } | |
5014 | ||
cd4ed6b4 | 5015 | void qla24xx_sched_upd_fcport(fc_port_t *fcport) |
726b8548 | 5016 | { |
cd4ed6b4 | 5017 | unsigned long flags; |
726b8548 | 5018 | |
cd4ed6b4 QT |
5019 | if (IS_SW_RESV_ADDR(fcport->d_id)) |
5020 | return; | |
726b8548 | 5021 | |
cd4ed6b4 QT |
5022 | spin_lock_irqsave(&fcport->vha->work_lock, flags); |
5023 | if (fcport->disc_state == DSC_UPD_FCPORT) { | |
5024 | spin_unlock_irqrestore(&fcport->vha->work_lock, flags); | |
5025 | return; | |
5026 | } | |
5027 | fcport->jiffies_at_registration = jiffies; | |
5028 | fcport->sec_since_registration = 0; | |
5029 | fcport->next_disc_state = DSC_DELETED; | |
5030 | fcport->disc_state = DSC_UPD_FCPORT; | |
5031 | spin_unlock_irqrestore(&fcport->vha->work_lock, flags); | |
5032 | ||
5033 | queue_work(system_unbound_wq, &fcport->reg_work); | |
726b8548 QT |
5034 | } |
5035 | ||
5036 | static | |
5037 | void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e) | |
5038 | { | |
5039 | unsigned long flags; | |
b5d15312 | 5040 | fc_port_t *fcport = NULL, *tfcp; |
726b8548 QT |
5041 | struct qlt_plogi_ack_t *pla = |
5042 | (struct qlt_plogi_ack_t *)e->u.new_sess.pla; | |
b5d15312 | 5043 | uint8_t free_fcport = 0; |
726b8548 | 5044 | |
9cd883f0 QT |
5045 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
5046 | "%s %d %8phC enter\n", | |
5047 | __func__, __LINE__, e->u.new_sess.port_name); | |
5048 | ||
726b8548 QT |
5049 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
5050 | fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1); | |
5051 | if (fcport) { | |
5052 | fcport->d_id = e->u.new_sess.id; | |
5053 | if (pla) { | |
5054 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; | |
9b3e0f4d QT |
5055 | memcpy(fcport->node_name, |
5056 | pla->iocb.u.isp24.u.plogi.node_name, | |
5057 | WWN_SIZE); | |
726b8548 QT |
5058 | qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN); |
5059 | /* we took an extra ref_count to prevent PLOGI ACK when | |
5060 | * fcport/sess has not been created. | |
5061 | */ | |
5062 | pla->ref_count--; | |
5063 | } | |
5064 | } else { | |
b5d15312 | 5065 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
726b8548 QT |
5066 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
5067 | if (fcport) { | |
5068 | fcport->d_id = e->u.new_sess.id; | |
726b8548 QT |
5069 | fcport->flags |= FCF_FABRIC_DEVICE; |
5070 | fcport->fw_login_state = DSC_LS_PLOGI_PEND; | |
c64a87f9 | 5071 | if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP) |
a4239945 | 5072 | fcport->fc4_type = FC4_TYPE_FCP_SCSI; |
726b8548 | 5073 | |
c64a87f9 | 5074 | if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) { |
2b5b9647 DT |
5075 | fcport->fc4_type = FC4_TYPE_OTHER; |
5076 | fcport->fc4f_nvme = FC4_TYPE_NVME; | |
5077 | } | |
33b28357 | 5078 | |
726b8548 QT |
5079 | memcpy(fcport->port_name, e->u.new_sess.port_name, |
5080 | WWN_SIZE); | |
b5d15312 QT |
5081 | } else { |
5082 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
5083 | "%s %8phC mem alloc fail.\n", | |
5084 | __func__, e->u.new_sess.port_name); | |
5085 | ||
1df627b4 BVA |
5086 | if (pla) { |
5087 | list_del(&pla->list); | |
b5d15312 | 5088 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
1df627b4 | 5089 | } |
b5d15312 QT |
5090 | return; |
5091 | } | |
5092 | ||
5093 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); | |
a4239945 | 5094 | /* search again to make sure no one else got ahead */ |
b5d15312 QT |
5095 | tfcp = qla2x00_find_fcport_by_wwpn(vha, |
5096 | e->u.new_sess.port_name, 1); | |
5097 | if (tfcp) { | |
5098 | /* should rarily happen */ | |
5099 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
5100 | "%s %8phC found existing fcport b4 add. DS %d LS %d\n", | |
5101 | __func__, tfcp->port_name, tfcp->disc_state, | |
5102 | tfcp->fw_login_state); | |
5103 | ||
5104 | free_fcport = 1; | |
5105 | } else { | |
726b8548 QT |
5106 | list_add_tail(&fcport->list, &vha->vp_fcports); |
5107 | ||
19759033 QT |
5108 | } |
5109 | if (pla) { | |
5110 | qlt_plogi_ack_link(vha, pla, fcport, | |
5111 | QLT_PLOGI_LINK_SAME_WWN); | |
5112 | pla->ref_count--; | |
726b8548 QT |
5113 | } |
5114 | } | |
5115 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); | |
5116 | ||
5117 | if (fcport) { | |
a4239945 QT |
5118 | fcport->id_changed = 1; |
5119 | fcport->scan_state = QLA_FCPORT_FOUND; | |
8b5292bc | 5120 | fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
a4239945 QT |
5121 | memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE); |
5122 | ||
5ef696aa | 5123 | if (pla) { |
9cd883f0 QT |
5124 | if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) { |
5125 | u16 wd3_lo; | |
5126 | ||
5127 | fcport->fw_login_state = DSC_LS_PRLI_PEND; | |
5128 | fcport->local = 0; | |
5129 | fcport->loop_id = | |
5130 | le16_to_cpu( | |
5131 | pla->iocb.u.isp24.nport_handle); | |
5132 | fcport->fw_login_state = DSC_LS_PRLI_PEND; | |
5133 | wd3_lo = | |
5134 | le16_to_cpu( | |
5135 | pla->iocb.u.isp24.u.prli.wd3_lo); | |
5136 | ||
5137 | if (wd3_lo & BIT_7) | |
5138 | fcport->conf_compl_supported = 1; | |
5139 | ||
5140 | if ((wd3_lo & BIT_4) == 0) | |
5141 | fcport->port_type = FCT_INITIATOR; | |
5142 | else | |
5143 | fcport->port_type = FCT_TARGET; | |
5144 | } | |
726b8548 | 5145 | qlt_plogi_ack_unref(vha, pla); |
5ef696aa | 5146 | } else { |
1c6cacf4 HR |
5147 | fc_port_t *dfcp = NULL; |
5148 | ||
5ef696aa QT |
5149 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
5150 | tfcp = qla2x00_find_fcport_by_nportid(vha, | |
5151 | &e->u.new_sess.id, 1); | |
5152 | if (tfcp && (tfcp != fcport)) { | |
5153 | /* | |
5154 | * We have a conflict fcport with same NportID. | |
5155 | */ | |
5156 | ql_dbg(ql_dbg_disc, vha, 0xffff, | |
5157 | "%s %8phC found conflict b4 add. DS %d LS %d\n", | |
5158 | __func__, tfcp->port_name, tfcp->disc_state, | |
5159 | tfcp->fw_login_state); | |
5160 | ||
5161 | switch (tfcp->disc_state) { | |
5162 | case DSC_DELETED: | |
5163 | break; | |
5164 | case DSC_DELETE_PEND: | |
5165 | fcport->login_pause = 1; | |
5166 | tfcp->conflict = fcport; | |
5167 | break; | |
5168 | default: | |
5169 | fcport->login_pause = 1; | |
5170 | tfcp->conflict = fcport; | |
1c6cacf4 | 5171 | dfcp = tfcp; |
5ef696aa QT |
5172 | break; |
5173 | } | |
5174 | } | |
5175 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); | |
1c6cacf4 HR |
5176 | if (dfcp) |
5177 | qlt_schedule_sess_for_deletion(tfcp); | |
a4239945 | 5178 | |
a4239945 | 5179 | |
8777e431 QT |
5180 | if (N2N_TOPO(vha->hw)) |
5181 | fcport->flags &= ~FCF_FABRIC_DEVICE; | |
5182 | ||
5183 | if (N2N_TOPO(vha->hw)) { | |
5184 | if (vha->flags.nvme_enabled) { | |
5185 | fcport->fc4f_nvme = 1; | |
5186 | fcport->n2n_flag = 1; | |
5187 | } | |
5188 | fcport->fw_login_state = 0; | |
5189 | /* | |
5190 | * wait link init done before sending login | |
5191 | */ | |
5192 | } else { | |
5193 | qla24xx_fcport_handle_login(vha, fcport); | |
5194 | } | |
5ef696aa | 5195 | } |
726b8548 | 5196 | } |
b5d15312 QT |
5197 | |
5198 | if (free_fcport) { | |
5199 | qla2x00_free_fcport(fcport); | |
1df627b4 BVA |
5200 | if (pla) { |
5201 | list_del(&pla->list); | |
b5d15312 | 5202 | kmem_cache_free(qla_tgt_plogi_cachep, pla); |
1df627b4 | 5203 | } |
b5d15312 | 5204 | } |
726b8548 QT |
5205 | } |
5206 | ||
e374f9f5 QT |
5207 | static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e) |
5208 | { | |
5209 | struct srb *sp = e->u.iosb.sp; | |
5210 | int rval; | |
5211 | ||
5212 | rval = qla2x00_start_sp(sp); | |
5213 | if (rval != QLA_SUCCESS) { | |
5214 | ql_dbg(ql_dbg_disc, vha, 0x2043, | |
5215 | "%s: %s: Re-issue IOCB failed (%d).\n", | |
5216 | __func__, sp->name, rval); | |
5217 | qla24xx_sp_unmap(vha, sp); | |
5218 | } | |
5219 | } | |
5220 | ||
ac280b67 | 5221 | void |
e315cd28 | 5222 | qla2x00_do_work(struct scsi_qla_host *vha) |
0971de7f | 5223 | { |
f999f4c1 AV |
5224 | struct qla_work_evt *e, *tmp; |
5225 | unsigned long flags; | |
5226 | LIST_HEAD(work); | |
80676d05 | 5227 | int rc; |
0971de7f | 5228 | |
f999f4c1 AV |
5229 | spin_lock_irqsave(&vha->work_lock, flags); |
5230 | list_splice_init(&vha->work_list, &work); | |
5231 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
5232 | ||
5233 | list_for_each_entry_safe(e, tmp, &work, list) { | |
80676d05 | 5234 | rc = QLA_SUCCESS; |
0971de7f AV |
5235 | switch (e->type) { |
5236 | case QLA_EVT_AEN: | |
e315cd28 | 5237 | fc_host_post_event(vha->host, fc_get_event_number(), |
0971de7f AV |
5238 | e->u.aen.code, e->u.aen.data); |
5239 | break; | |
8a659571 AV |
5240 | case QLA_EVT_IDC_ACK: |
5241 | qla81xx_idc_ack(vha, e->u.idc_ack.mb); | |
5242 | break; | |
ac280b67 AV |
5243 | case QLA_EVT_ASYNC_LOGIN: |
5244 | qla2x00_async_login(vha, e->u.logio.fcport, | |
5245 | e->u.logio.data); | |
5246 | break; | |
ac280b67 | 5247 | case QLA_EVT_ASYNC_LOGOUT: |
80676d05 | 5248 | rc = qla2x00_async_logout(vha, e->u.logio.fcport); |
ac280b67 AV |
5249 | break; |
5250 | case QLA_EVT_ASYNC_LOGOUT_DONE: | |
5251 | qla2x00_async_logout_done(vha, e->u.logio.fcport, | |
5252 | e->u.logio.data); | |
5253 | break; | |
5ff1d584 AV |
5254 | case QLA_EVT_ASYNC_ADISC: |
5255 | qla2x00_async_adisc(vha, e->u.logio.fcport, | |
5256 | e->u.logio.data); | |
5257 | break; | |
3420d36c AV |
5258 | case QLA_EVT_UEVENT: |
5259 | qla2x00_uevent_emit(vha, e->u.uevent.code); | |
5260 | break; | |
8ae6d9c7 GM |
5261 | case QLA_EVT_AENFX: |
5262 | qlafx00_process_aen(vha, e); | |
5263 | break; | |
726b8548 QT |
5264 | case QLA_EVT_GPNID: |
5265 | qla24xx_async_gpnid(vha, &e->u.gpnid.id); | |
5266 | break; | |
e374f9f5 QT |
5267 | case QLA_EVT_UNMAP: |
5268 | qla24xx_sp_unmap(vha, e->u.iosb.sp); | |
726b8548 | 5269 | break; |
9b3e0f4d QT |
5270 | case QLA_EVT_RELOGIN: |
5271 | qla2x00_relogin(vha); | |
5272 | break; | |
726b8548 QT |
5273 | case QLA_EVT_NEW_SESS: |
5274 | qla24xx_create_new_sess(vha, e); | |
5275 | break; | |
5276 | case QLA_EVT_GPDB: | |
5277 | qla24xx_async_gpdb(vha, e->u.fcport.fcport, | |
5278 | e->u.fcport.opt); | |
5279 | break; | |
a5d42f4c DG |
5280 | case QLA_EVT_PRLI: |
5281 | qla24xx_async_prli(vha, e->u.fcport.fcport); | |
5282 | break; | |
726b8548 QT |
5283 | case QLA_EVT_GPSC: |
5284 | qla24xx_async_gpsc(vha, e->u.fcport.fcport); | |
5285 | break; | |
726b8548 QT |
5286 | case QLA_EVT_GNL: |
5287 | qla24xx_async_gnl(vha, e->u.fcport.fcport); | |
5288 | break; | |
5289 | case QLA_EVT_NACK: | |
5290 | qla24xx_do_nack_work(vha, e); | |
5291 | break; | |
11aea16a | 5292 | case QLA_EVT_ASYNC_PRLO: |
80676d05 | 5293 | rc = qla2x00_async_prlo(vha, e->u.logio.fcport); |
11aea16a QT |
5294 | break; |
5295 | case QLA_EVT_ASYNC_PRLO_DONE: | |
5296 | qla2x00_async_prlo_done(vha, e->u.logio.fcport, | |
5297 | e->u.logio.data); | |
5298 | break; | |
a4239945 | 5299 | case QLA_EVT_GPNFT: |
33b28357 QT |
5300 | qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type, |
5301 | e->u.gpnft.sp); | |
a4239945 QT |
5302 | break; |
5303 | case QLA_EVT_GPNFT_DONE: | |
5304 | qla24xx_async_gpnft_done(vha, e->u.iosb.sp); | |
5305 | break; | |
5306 | case QLA_EVT_GNNFT_DONE: | |
5307 | qla24xx_async_gnnft_done(vha, e->u.iosb.sp); | |
5308 | break; | |
5309 | case QLA_EVT_GNNID: | |
5310 | qla24xx_async_gnnid(vha, e->u.fcport.fcport); | |
5311 | break; | |
5312 | case QLA_EVT_GFPNID: | |
5313 | qla24xx_async_gfpnid(vha, e->u.fcport.fcport); | |
5314 | break; | |
e374f9f5 QT |
5315 | case QLA_EVT_SP_RETRY: |
5316 | qla_sp_retry(vha, e); | |
cc28e0ac QT |
5317 | break; |
5318 | case QLA_EVT_IIDMA: | |
5319 | qla_do_iidma_work(vha, e->u.fcport.fcport); | |
5320 | break; | |
8777e431 QT |
5321 | case QLA_EVT_ELS_PLOGI: |
5322 | qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI, | |
5323 | e->u.fcport.fcport, false); | |
5324 | break; | |
0971de7f | 5325 | } |
80676d05 QT |
5326 | |
5327 | if (rc == EAGAIN) { | |
5328 | /* put 'work' at head of 'vha->work_list' */ | |
5329 | spin_lock_irqsave(&vha->work_lock, flags); | |
5330 | list_splice(&work, &vha->work_list); | |
5331 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
5332 | break; | |
5333 | } | |
5334 | list_del_init(&e->list); | |
0971de7f AV |
5335 | if (e->flags & QLA_EVT_FLAG_FREE) |
5336 | kfree(e); | |
feafb7b1 AE |
5337 | |
5338 | /* For each work completed decrement vha ref count */ | |
5339 | QLA_VHA_MARK_NOT_BUSY(vha); | |
e315cd28 | 5340 | } |
e315cd28 | 5341 | } |
f999f4c1 | 5342 | |
9b3e0f4d QT |
5343 | int qla24xx_post_relogin_work(struct scsi_qla_host *vha) |
5344 | { | |
5345 | struct qla_work_evt *e; | |
5346 | ||
5347 | e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN); | |
5348 | ||
5349 | if (!e) { | |
5350 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | |
5351 | return QLA_FUNCTION_FAILED; | |
5352 | } | |
5353 | ||
5354 | return qla2x00_post_work(vha, e); | |
5355 | } | |
5356 | ||
e315cd28 AC |
5357 | /* Relogins all the fcports of a vport |
5358 | * Context: dpc thread | |
5359 | */ | |
5360 | void qla2x00_relogin(struct scsi_qla_host *vha) | |
5361 | { | |
5362 | fc_port_t *fcport; | |
23dd98a6 | 5363 | int status, relogin_needed = 0; |
726b8548 | 5364 | struct event_arg ea; |
e315cd28 AC |
5365 | |
5366 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | |
9cd883f0 QT |
5367 | /* |
5368 | * If the port is not ONLINE then try to login | |
5369 | * to it if we haven't run out of retries. | |
5370 | */ | |
5ff1d584 | 5371 | if (atomic_read(&fcport->state) != FCS_ONLINE && |
23dd98a6 QT |
5372 | fcport->login_retry) { |
5373 | if (fcport->scan_state != QLA_FCPORT_FOUND || | |
5374 | fcport->disc_state == DSC_LOGIN_COMPLETE) | |
5375 | continue; | |
e315cd28 | 5376 | |
23dd98a6 QT |
5377 | if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) || |
5378 | fcport->disc_state == DSC_DELETE_PEND) { | |
5379 | relogin_needed = 1; | |
5380 | } else { | |
5381 | if (vha->hw->current_topology != ISP_CFG_NL) { | |
5382 | memset(&ea, 0, sizeof(ea)); | |
5383 | ea.event = FCME_RELOGIN; | |
5384 | ea.fcport = fcport; | |
5385 | qla2x00_fcport_event_handler(vha, &ea); | |
5386 | } else if (vha->hw->current_topology == | |
5387 | ISP_CFG_NL) { | |
5388 | fcport->login_retry--; | |
5389 | status = | |
5390 | qla2x00_local_device_login(vha, | |
5391 | fcport); | |
5392 | if (status == QLA_SUCCESS) { | |
5393 | fcport->old_loop_id = | |
5394 | fcport->loop_id; | |
5395 | ql_dbg(ql_dbg_disc, vha, 0x2003, | |
5396 | "Port login OK: logged in ID 0x%x.\n", | |
5397 | fcport->loop_id); | |
5398 | qla2x00_update_fcport | |
5399 | (vha, fcport); | |
5400 | } else if (status == 1) { | |
5401 | set_bit(RELOGIN_NEEDED, | |
5402 | &vha->dpc_flags); | |
5403 | /* retry the login again */ | |
5404 | ql_dbg(ql_dbg_disc, vha, 0x2007, | |
5405 | "Retrying %d login again loop_id 0x%x.\n", | |
5406 | fcport->login_retry, | |
5407 | fcport->loop_id); | |
5408 | } else { | |
5409 | fcport->login_retry = 0; | |
5410 | } | |
e315cd28 | 5411 | |
23dd98a6 QT |
5412 | if (fcport->login_retry == 0 && |
5413 | status != QLA_SUCCESS) | |
5414 | qla2x00_clear_loop_id(fcport); | |
5415 | } | |
e315cd28 | 5416 | } |
e315cd28 AC |
5417 | } |
5418 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) | |
5419 | break; | |
0971de7f | 5420 | } |
9b3e0f4d | 5421 | |
23dd98a6 QT |
5422 | if (relogin_needed) |
5423 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | |
5424 | ||
9b3e0f4d QT |
5425 | ql_dbg(ql_dbg_disc, vha, 0x400e, |
5426 | "Relogin end.\n"); | |
0971de7f AV |
5427 | } |
5428 | ||
7d613ac6 SV |
5429 | /* Schedule work on any of the dpc-workqueues */ |
5430 | void | |
5431 | qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code) | |
5432 | { | |
5433 | struct qla_hw_data *ha = base_vha->hw; | |
5434 | ||
5435 | switch (work_code) { | |
5436 | case MBA_IDC_AEN: /* 0x8200 */ | |
5437 | if (ha->dpc_lp_wq) | |
5438 | queue_work(ha->dpc_lp_wq, &ha->idc_aen); | |
5439 | break; | |
5440 | ||
5441 | case QLA83XX_NIC_CORE_RESET: /* 0x1 */ | |
5442 | if (!ha->flags.nic_core_reset_hdlr_active) { | |
5443 | if (ha->dpc_hp_wq) | |
5444 | queue_work(ha->dpc_hp_wq, &ha->nic_core_reset); | |
5445 | } else | |
5446 | ql_dbg(ql_dbg_p3p, base_vha, 0xb05e, | |
5447 | "NIC Core reset is already active. Skip " | |
5448 | "scheduling it again.\n"); | |
5449 | break; | |
5450 | case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */ | |
5451 | if (ha->dpc_hp_wq) | |
5452 | queue_work(ha->dpc_hp_wq, &ha->idc_state_handler); | |
5453 | break; | |
5454 | case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */ | |
5455 | if (ha->dpc_hp_wq) | |
5456 | queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable); | |
5457 | break; | |
5458 | default: | |
5459 | ql_log(ql_log_warn, base_vha, 0xb05f, | |
d939be3a | 5460 | "Unknown work-code=0x%x.\n", work_code); |
7d613ac6 SV |
5461 | } |
5462 | ||
5463 | return; | |
5464 | } | |
5465 | ||
5466 | /* Work: Perform NIC Core Unrecoverable state handling */ | |
5467 | void | |
5468 | qla83xx_nic_core_unrecoverable_work(struct work_struct *work) | |
5469 | { | |
5470 | struct qla_hw_data *ha = | |
2ad1b67c | 5471 | container_of(work, struct qla_hw_data, nic_core_unrecoverable); |
7d613ac6 SV |
5472 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
5473 | uint32_t dev_state = 0; | |
5474 | ||
5475 | qla83xx_idc_lock(base_vha, 0); | |
5476 | qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state); | |
5477 | qla83xx_reset_ownership(base_vha); | |
5478 | if (ha->flags.nic_core_reset_owner) { | |
5479 | ha->flags.nic_core_reset_owner = 0; | |
5480 | qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE, | |
5481 | QLA8XXX_DEV_FAILED); | |
5482 | ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n"); | |
5483 | qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER); | |
5484 | } | |
5485 | qla83xx_idc_unlock(base_vha, 0); | |
5486 | } | |
5487 | ||
5488 | /* Work: Execute IDC state handler */ | |
5489 | void | |
5490 | qla83xx_idc_state_handler_work(struct work_struct *work) | |
5491 | { | |
5492 | struct qla_hw_data *ha = | |
2ad1b67c | 5493 | container_of(work, struct qla_hw_data, idc_state_handler); |
7d613ac6 SV |
5494 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
5495 | uint32_t dev_state = 0; | |
5496 | ||
5497 | qla83xx_idc_lock(base_vha, 0); | |
5498 | qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state); | |
5499 | if (dev_state == QLA8XXX_DEV_FAILED || | |
5500 | dev_state == QLA8XXX_DEV_NEED_QUIESCENT) | |
5501 | qla83xx_idc_state_handler(base_vha); | |
5502 | qla83xx_idc_unlock(base_vha, 0); | |
5503 | } | |
5504 | ||
fa492630 | 5505 | static int |
7d613ac6 SV |
5506 | qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha) |
5507 | { | |
5508 | int rval = QLA_SUCCESS; | |
5509 | unsigned long heart_beat_wait = jiffies + (1 * HZ); | |
5510 | uint32_t heart_beat_counter1, heart_beat_counter2; | |
5511 | ||
5512 | do { | |
5513 | if (time_after(jiffies, heart_beat_wait)) { | |
5514 | ql_dbg(ql_dbg_p3p, base_vha, 0xb07c, | |
5515 | "Nic Core f/w is not alive.\n"); | |
5516 | rval = QLA_FUNCTION_FAILED; | |
5517 | break; | |
5518 | } | |
5519 | ||
5520 | qla83xx_idc_lock(base_vha, 0); | |
5521 | qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT, | |
5522 | &heart_beat_counter1); | |
5523 | qla83xx_idc_unlock(base_vha, 0); | |
5524 | msleep(100); | |
5525 | qla83xx_idc_lock(base_vha, 0); | |
5526 | qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT, | |
5527 | &heart_beat_counter2); | |
5528 | qla83xx_idc_unlock(base_vha, 0); | |
5529 | } while (heart_beat_counter1 == heart_beat_counter2); | |
5530 | ||
5531 | return rval; | |
5532 | } | |
5533 | ||
5534 | /* Work: Perform NIC Core Reset handling */ | |
5535 | void | |
5536 | qla83xx_nic_core_reset_work(struct work_struct *work) | |
5537 | { | |
5538 | struct qla_hw_data *ha = | |
5539 | container_of(work, struct qla_hw_data, nic_core_reset); | |
5540 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
5541 | uint32_t dev_state = 0; | |
5542 | ||
81178772 SK |
5543 | if (IS_QLA2031(ha)) { |
5544 | if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS) | |
5545 | ql_log(ql_log_warn, base_vha, 0xb081, | |
5546 | "Failed to dump mctp\n"); | |
5547 | return; | |
5548 | } | |
5549 | ||
7d613ac6 SV |
5550 | if (!ha->flags.nic_core_reset_hdlr_active) { |
5551 | if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) { | |
5552 | qla83xx_idc_lock(base_vha, 0); | |
5553 | qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, | |
5554 | &dev_state); | |
5555 | qla83xx_idc_unlock(base_vha, 0); | |
5556 | if (dev_state != QLA8XXX_DEV_NEED_RESET) { | |
5557 | ql_dbg(ql_dbg_p3p, base_vha, 0xb07a, | |
5558 | "Nic Core f/w is alive.\n"); | |
5559 | return; | |
5560 | } | |
5561 | } | |
5562 | ||
5563 | ha->flags.nic_core_reset_hdlr_active = 1; | |
5564 | if (qla83xx_nic_core_reset(base_vha)) { | |
5565 | /* NIC Core reset failed. */ | |
5566 | ql_dbg(ql_dbg_p3p, base_vha, 0xb061, | |
5567 | "NIC Core reset failed.\n"); | |
5568 | } | |
5569 | ha->flags.nic_core_reset_hdlr_active = 0; | |
5570 | } | |
5571 | } | |
5572 | ||
5573 | /* Work: Handle 8200 IDC aens */ | |
5574 | void | |
5575 | qla83xx_service_idc_aen(struct work_struct *work) | |
5576 | { | |
5577 | struct qla_hw_data *ha = | |
5578 | container_of(work, struct qla_hw_data, idc_aen); | |
5579 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
5580 | uint32_t dev_state, idc_control; | |
5581 | ||
5582 | qla83xx_idc_lock(base_vha, 0); | |
5583 | qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state); | |
5584 | qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control); | |
5585 | qla83xx_idc_unlock(base_vha, 0); | |
5586 | if (dev_state == QLA8XXX_DEV_NEED_RESET) { | |
5587 | if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) { | |
5588 | ql_dbg(ql_dbg_p3p, base_vha, 0xb062, | |
5589 | "Application requested NIC Core Reset.\n"); | |
5590 | qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET); | |
5591 | } else if (qla83xx_check_nic_core_fw_alive(base_vha) == | |
5592 | QLA_SUCCESS) { | |
5593 | ql_dbg(ql_dbg_p3p, base_vha, 0xb07b, | |
5594 | "Other protocol driver requested NIC Core Reset.\n"); | |
5595 | qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET); | |
5596 | } | |
5597 | } else if (dev_state == QLA8XXX_DEV_FAILED || | |
5598 | dev_state == QLA8XXX_DEV_NEED_QUIESCENT) { | |
5599 | qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER); | |
5600 | } | |
5601 | } | |
5602 | ||
5603 | static void | |
5604 | qla83xx_wait_logic(void) | |
5605 | { | |
5606 | int i; | |
5607 | ||
5608 | /* Yield CPU */ | |
5609 | if (!in_interrupt()) { | |
5610 | /* | |
5611 | * Wait about 200ms before retrying again. | |
5612 | * This controls the number of retries for single | |
5613 | * lock operation. | |
5614 | */ | |
5615 | msleep(100); | |
5616 | schedule(); | |
5617 | } else { | |
5618 | for (i = 0; i < 20; i++) | |
5619 | cpu_relax(); /* This a nop instr on i386 */ | |
5620 | } | |
5621 | } | |
5622 | ||
fa492630 | 5623 | static int |
7d613ac6 SV |
5624 | qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha) |
5625 | { | |
5626 | int rval; | |
5627 | uint32_t data; | |
5628 | uint32_t idc_lck_rcvry_stage_mask = 0x3; | |
5629 | uint32_t idc_lck_rcvry_owner_mask = 0x3c; | |
5630 | struct qla_hw_data *ha = base_vha->hw; | |
bd432bb5 | 5631 | |
6c315553 SK |
5632 | ql_dbg(ql_dbg_p3p, base_vha, 0xb086, |
5633 | "Trying force recovery of the IDC lock.\n"); | |
7d613ac6 SV |
5634 | |
5635 | rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data); | |
5636 | if (rval) | |
5637 | return rval; | |
5638 | ||
5639 | if ((data & idc_lck_rcvry_stage_mask) > 0) { | |
5640 | return QLA_SUCCESS; | |
5641 | } else { | |
5642 | data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2); | |
5643 | rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, | |
5644 | data); | |
5645 | if (rval) | |
5646 | return rval; | |
5647 | ||
5648 | msleep(200); | |
5649 | ||
5650 | rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, | |
5651 | &data); | |
5652 | if (rval) | |
5653 | return rval; | |
5654 | ||
5655 | if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) { | |
5656 | data &= (IDC_LOCK_RECOVERY_STAGE2 | | |
5657 | ~(idc_lck_rcvry_stage_mask)); | |
5658 | rval = qla83xx_wr_reg(base_vha, | |
5659 | QLA83XX_IDC_LOCK_RECOVERY, data); | |
5660 | if (rval) | |
5661 | return rval; | |
5662 | ||
5663 | /* Forcefully perform IDC UnLock */ | |
5664 | rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, | |
5665 | &data); | |
5666 | if (rval) | |
5667 | return rval; | |
5668 | /* Clear lock-id by setting 0xff */ | |
5669 | rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, | |
5670 | 0xff); | |
5671 | if (rval) | |
5672 | return rval; | |
5673 | /* Clear lock-recovery by setting 0x0 */ | |
5674 | rval = qla83xx_wr_reg(base_vha, | |
5675 | QLA83XX_IDC_LOCK_RECOVERY, 0x0); | |
5676 | if (rval) | |
5677 | return rval; | |
5678 | } else | |
5679 | return QLA_SUCCESS; | |
5680 | } | |
5681 | ||
5682 | return rval; | |
5683 | } | |
5684 | ||
fa492630 | 5685 | static int |
7d613ac6 SV |
5686 | qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha) |
5687 | { | |
5688 | int rval = QLA_SUCCESS; | |
5689 | uint32_t o_drv_lockid, n_drv_lockid; | |
5690 | unsigned long lock_recovery_timeout; | |
5691 | ||
5692 | lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT; | |
5693 | retry_lockid: | |
5694 | rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid); | |
5695 | if (rval) | |
5696 | goto exit; | |
5697 | ||
5698 | /* MAX wait time before forcing IDC Lock recovery = 2 secs */ | |
5699 | if (time_after_eq(jiffies, lock_recovery_timeout)) { | |
5700 | if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS) | |
5701 | return QLA_SUCCESS; | |
5702 | else | |
5703 | return QLA_FUNCTION_FAILED; | |
5704 | } | |
5705 | ||
5706 | rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid); | |
5707 | if (rval) | |
5708 | goto exit; | |
5709 | ||
5710 | if (o_drv_lockid == n_drv_lockid) { | |
5711 | qla83xx_wait_logic(); | |
5712 | goto retry_lockid; | |
5713 | } else | |
5714 | return QLA_SUCCESS; | |
5715 | ||
5716 | exit: | |
5717 | return rval; | |
5718 | } | |
5719 | ||
5720 | void | |
5721 | qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id) | |
5722 | { | |
5723 | uint16_t options = (requester_id << 15) | BIT_6; | |
5724 | uint32_t data; | |
6c315553 | 5725 | uint32_t lock_owner; |
7d613ac6 SV |
5726 | struct qla_hw_data *ha = base_vha->hw; |
5727 | ||
5728 | /* IDC-lock implementation using driver-lock/lock-id remote registers */ | |
5729 | retry_lock: | |
5730 | if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data) | |
5731 | == QLA_SUCCESS) { | |
5732 | if (data) { | |
5733 | /* Setting lock-id to our function-number */ | |
5734 | qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, | |
5735 | ha->portnum); | |
5736 | } else { | |
6c315553 SK |
5737 | qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, |
5738 | &lock_owner); | |
7d613ac6 | 5739 | ql_dbg(ql_dbg_p3p, base_vha, 0xb063, |
6c315553 SK |
5740 | "Failed to acquire IDC lock, acquired by %d, " |
5741 | "retrying...\n", lock_owner); | |
7d613ac6 SV |
5742 | |
5743 | /* Retry/Perform IDC-Lock recovery */ | |
5744 | if (qla83xx_idc_lock_recovery(base_vha) | |
5745 | == QLA_SUCCESS) { | |
5746 | qla83xx_wait_logic(); | |
5747 | goto retry_lock; | |
5748 | } else | |
5749 | ql_log(ql_log_warn, base_vha, 0xb075, | |
5750 | "IDC Lock recovery FAILED.\n"); | |
5751 | } | |
5752 | ||
5753 | } | |
5754 | ||
5755 | return; | |
5756 | ||
5757 | /* XXX: IDC-lock implementation using access-control mbx */ | |
5758 | retry_lock2: | |
5759 | if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) { | |
5760 | ql_dbg(ql_dbg_p3p, base_vha, 0xb072, | |
5761 | "Failed to acquire IDC lock. retrying...\n"); | |
5762 | /* Retry/Perform IDC-Lock recovery */ | |
5763 | if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) { | |
5764 | qla83xx_wait_logic(); | |
5765 | goto retry_lock2; | |
5766 | } else | |
5767 | ql_log(ql_log_warn, base_vha, 0xb076, | |
5768 | "IDC Lock recovery FAILED.\n"); | |
5769 | } | |
5770 | ||
5771 | return; | |
5772 | } | |
5773 | ||
5774 | void | |
5775 | qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id) | |
5776 | { | |
5897cb2f BVA |
5777 | #if 0 |
5778 | uint16_t options = (requester_id << 15) | BIT_7; | |
5779 | #endif | |
5780 | uint16_t retry; | |
7d613ac6 SV |
5781 | uint32_t data; |
5782 | struct qla_hw_data *ha = base_vha->hw; | |
5783 | ||
5784 | /* IDC-unlock implementation using driver-unlock/lock-id | |
5785 | * remote registers | |
5786 | */ | |
5787 | retry = 0; | |
5788 | retry_unlock: | |
5789 | if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data) | |
5790 | == QLA_SUCCESS) { | |
5791 | if (data == ha->portnum) { | |
5792 | qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data); | |
5793 | /* Clearing lock-id by setting 0xff */ | |
5794 | qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff); | |
5795 | } else if (retry < 10) { | |
5796 | /* SV: XXX: IDC unlock retrying needed here? */ | |
5797 | ||
5798 | /* Retry for IDC-unlock */ | |
5799 | qla83xx_wait_logic(); | |
5800 | retry++; | |
5801 | ql_dbg(ql_dbg_p3p, base_vha, 0xb064, | |
ee6a8773 | 5802 | "Failed to release IDC lock, retrying=%d\n", retry); |
7d613ac6 SV |
5803 | goto retry_unlock; |
5804 | } | |
5805 | } else if (retry < 10) { | |
5806 | /* Retry for IDC-unlock */ | |
5807 | qla83xx_wait_logic(); | |
5808 | retry++; | |
5809 | ql_dbg(ql_dbg_p3p, base_vha, 0xb065, | |
ee6a8773 | 5810 | "Failed to read drv-lockid, retrying=%d\n", retry); |
7d613ac6 SV |
5811 | goto retry_unlock; |
5812 | } | |
5813 | ||
5814 | return; | |
5815 | ||
5897cb2f | 5816 | #if 0 |
7d613ac6 SV |
5817 | /* XXX: IDC-unlock implementation using access-control mbx */ |
5818 | retry = 0; | |
5819 | retry_unlock2: | |
5820 | if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) { | |
5821 | if (retry < 10) { | |
5822 | /* Retry for IDC-unlock */ | |
5823 | qla83xx_wait_logic(); | |
5824 | retry++; | |
5825 | ql_dbg(ql_dbg_p3p, base_vha, 0xb066, | |
ee6a8773 | 5826 | "Failed to release IDC lock, retrying=%d\n", retry); |
7d613ac6 SV |
5827 | goto retry_unlock2; |
5828 | } | |
5829 | } | |
5830 | ||
5831 | return; | |
5897cb2f | 5832 | #endif |
7d613ac6 SV |
5833 | } |
5834 | ||
5835 | int | |
5836 | __qla83xx_set_drv_presence(scsi_qla_host_t *vha) | |
5837 | { | |
5838 | int rval = QLA_SUCCESS; | |
5839 | struct qla_hw_data *ha = vha->hw; | |
5840 | uint32_t drv_presence; | |
5841 | ||
5842 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); | |
5843 | if (rval == QLA_SUCCESS) { | |
5844 | drv_presence |= (1 << ha->portnum); | |
5845 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE, | |
5846 | drv_presence); | |
5847 | } | |
5848 | ||
5849 | return rval; | |
5850 | } | |
5851 | ||
5852 | int | |
5853 | qla83xx_set_drv_presence(scsi_qla_host_t *vha) | |
5854 | { | |
5855 | int rval = QLA_SUCCESS; | |
5856 | ||
5857 | qla83xx_idc_lock(vha, 0); | |
5858 | rval = __qla83xx_set_drv_presence(vha); | |
5859 | qla83xx_idc_unlock(vha, 0); | |
5860 | ||
5861 | return rval; | |
5862 | } | |
5863 | ||
5864 | int | |
5865 | __qla83xx_clear_drv_presence(scsi_qla_host_t *vha) | |
5866 | { | |
5867 | int rval = QLA_SUCCESS; | |
5868 | struct qla_hw_data *ha = vha->hw; | |
5869 | uint32_t drv_presence; | |
5870 | ||
5871 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); | |
5872 | if (rval == QLA_SUCCESS) { | |
5873 | drv_presence &= ~(1 << ha->portnum); | |
5874 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE, | |
5875 | drv_presence); | |
5876 | } | |
5877 | ||
5878 | return rval; | |
5879 | } | |
5880 | ||
5881 | int | |
5882 | qla83xx_clear_drv_presence(scsi_qla_host_t *vha) | |
5883 | { | |
5884 | int rval = QLA_SUCCESS; | |
5885 | ||
5886 | qla83xx_idc_lock(vha, 0); | |
5887 | rval = __qla83xx_clear_drv_presence(vha); | |
5888 | qla83xx_idc_unlock(vha, 0); | |
5889 | ||
5890 | return rval; | |
5891 | } | |
5892 | ||
fa492630 | 5893 | static void |
7d613ac6 SV |
5894 | qla83xx_need_reset_handler(scsi_qla_host_t *vha) |
5895 | { | |
5896 | struct qla_hw_data *ha = vha->hw; | |
5897 | uint32_t drv_ack, drv_presence; | |
5898 | unsigned long ack_timeout; | |
5899 | ||
5900 | /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */ | |
5901 | ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ); | |
5902 | while (1) { | |
5903 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); | |
5904 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); | |
807fb6d8 | 5905 | if ((drv_ack & drv_presence) == drv_presence) |
7d613ac6 SV |
5906 | break; |
5907 | ||
5908 | if (time_after_eq(jiffies, ack_timeout)) { | |
5909 | ql_log(ql_log_warn, vha, 0xb067, | |
5910 | "RESET ACK TIMEOUT! drv_presence=0x%x " | |
5911 | "drv_ack=0x%x\n", drv_presence, drv_ack); | |
5912 | /* | |
5913 | * The function(s) which did not ack in time are forced | |
5914 | * to withdraw any further participation in the IDC | |
5915 | * reset. | |
5916 | */ | |
5917 | if (drv_ack != drv_presence) | |
5918 | qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE, | |
5919 | drv_ack); | |
5920 | break; | |
5921 | } | |
5922 | ||
5923 | qla83xx_idc_unlock(vha, 0); | |
5924 | msleep(1000); | |
5925 | qla83xx_idc_lock(vha, 0); | |
5926 | } | |
5927 | ||
5928 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD); | |
5929 | ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n"); | |
5930 | } | |
5931 | ||
fa492630 | 5932 | static int |
7d613ac6 SV |
5933 | qla83xx_device_bootstrap(scsi_qla_host_t *vha) |
5934 | { | |
5935 | int rval = QLA_SUCCESS; | |
5936 | uint32_t idc_control; | |
5937 | ||
5938 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING); | |
5939 | ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n"); | |
5940 | ||
5941 | /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */ | |
5942 | __qla83xx_get_idc_control(vha, &idc_control); | |
5943 | idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET; | |
5944 | __qla83xx_set_idc_control(vha, 0); | |
5945 | ||
5946 | qla83xx_idc_unlock(vha, 0); | |
5947 | rval = qla83xx_restart_nic_firmware(vha); | |
5948 | qla83xx_idc_lock(vha, 0); | |
5949 | ||
5950 | if (rval != QLA_SUCCESS) { | |
5951 | ql_log(ql_log_fatal, vha, 0xb06a, | |
5952 | "Failed to restart NIC f/w.\n"); | |
5953 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED); | |
5954 | ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n"); | |
5955 | } else { | |
5956 | ql_dbg(ql_dbg_p3p, vha, 0xb06c, | |
5957 | "Success in restarting nic f/w.\n"); | |
5958 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY); | |
5959 | ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n"); | |
5960 | } | |
5961 | ||
5962 | return rval; | |
5963 | } | |
5964 | ||
5965 | /* Assumes idc_lock always held on entry */ | |
5966 | int | |
5967 | qla83xx_idc_state_handler(scsi_qla_host_t *base_vha) | |
5968 | { | |
5969 | struct qla_hw_data *ha = base_vha->hw; | |
5970 | int rval = QLA_SUCCESS; | |
5971 | unsigned long dev_init_timeout; | |
5972 | uint32_t dev_state; | |
5973 | ||
5974 | /* Wait for MAX-INIT-TIMEOUT for the device to go ready */ | |
5975 | dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ); | |
5976 | ||
5977 | while (1) { | |
5978 | ||
5979 | if (time_after_eq(jiffies, dev_init_timeout)) { | |
5980 | ql_log(ql_log_warn, base_vha, 0xb06e, | |
5981 | "Initialization TIMEOUT!\n"); | |
5982 | /* Init timeout. Disable further NIC Core | |
5983 | * communication. | |
5984 | */ | |
5985 | qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE, | |
5986 | QLA8XXX_DEV_FAILED); | |
5987 | ql_log(ql_log_info, base_vha, 0xb06f, | |
5988 | "HW State: FAILED.\n"); | |
5989 | } | |
5990 | ||
5991 | qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state); | |
5992 | switch (dev_state) { | |
5993 | case QLA8XXX_DEV_READY: | |
5994 | if (ha->flags.nic_core_reset_owner) | |
5995 | qla83xx_idc_audit(base_vha, | |
5996 | IDC_AUDIT_COMPLETION); | |
5997 | ha->flags.nic_core_reset_owner = 0; | |
5998 | ql_dbg(ql_dbg_p3p, base_vha, 0xb070, | |
5999 | "Reset_owner reset by 0x%x.\n", | |
6000 | ha->portnum); | |
6001 | goto exit; | |
6002 | case QLA8XXX_DEV_COLD: | |
6003 | if (ha->flags.nic_core_reset_owner) | |
6004 | rval = qla83xx_device_bootstrap(base_vha); | |
6005 | else { | |
6006 | /* Wait for AEN to change device-state */ | |
6007 | qla83xx_idc_unlock(base_vha, 0); | |
6008 | msleep(1000); | |
6009 | qla83xx_idc_lock(base_vha, 0); | |
6010 | } | |
6011 | break; | |
6012 | case QLA8XXX_DEV_INITIALIZING: | |
6013 | /* Wait for AEN to change device-state */ | |
6014 | qla83xx_idc_unlock(base_vha, 0); | |
6015 | msleep(1000); | |
6016 | qla83xx_idc_lock(base_vha, 0); | |
6017 | break; | |
6018 | case QLA8XXX_DEV_NEED_RESET: | |
6019 | if (!ql2xdontresethba && ha->flags.nic_core_reset_owner) | |
6020 | qla83xx_need_reset_handler(base_vha); | |
6021 | else { | |
6022 | /* Wait for AEN to change device-state */ | |
6023 | qla83xx_idc_unlock(base_vha, 0); | |
6024 | msleep(1000); | |
6025 | qla83xx_idc_lock(base_vha, 0); | |
6026 | } | |
6027 | /* reset timeout value after need reset handler */ | |
6028 | dev_init_timeout = jiffies + | |
6029 | (ha->fcoe_dev_init_timeout * HZ); | |
6030 | break; | |
6031 | case QLA8XXX_DEV_NEED_QUIESCENT: | |
6032 | /* XXX: DEBUG for now */ | |
6033 | qla83xx_idc_unlock(base_vha, 0); | |
6034 | msleep(1000); | |
6035 | qla83xx_idc_lock(base_vha, 0); | |
6036 | break; | |
6037 | case QLA8XXX_DEV_QUIESCENT: | |
6038 | /* XXX: DEBUG for now */ | |
6039 | if (ha->flags.quiesce_owner) | |
6040 | goto exit; | |
6041 | ||
6042 | qla83xx_idc_unlock(base_vha, 0); | |
6043 | msleep(1000); | |
6044 | qla83xx_idc_lock(base_vha, 0); | |
6045 | dev_init_timeout = jiffies + | |
6046 | (ha->fcoe_dev_init_timeout * HZ); | |
6047 | break; | |
6048 | case QLA8XXX_DEV_FAILED: | |
6049 | if (ha->flags.nic_core_reset_owner) | |
6050 | qla83xx_idc_audit(base_vha, | |
6051 | IDC_AUDIT_COMPLETION); | |
6052 | ha->flags.nic_core_reset_owner = 0; | |
6053 | __qla83xx_clear_drv_presence(base_vha); | |
6054 | qla83xx_idc_unlock(base_vha, 0); | |
6055 | qla8xxx_dev_failed_handler(base_vha); | |
6056 | rval = QLA_FUNCTION_FAILED; | |
6057 | qla83xx_idc_lock(base_vha, 0); | |
6058 | goto exit; | |
6059 | case QLA8XXX_BAD_VALUE: | |
6060 | qla83xx_idc_unlock(base_vha, 0); | |
6061 | msleep(1000); | |
6062 | qla83xx_idc_lock(base_vha, 0); | |
6063 | break; | |
6064 | default: | |
6065 | ql_log(ql_log_warn, base_vha, 0xb071, | |
d939be3a | 6066 | "Unknown Device State: %x.\n", dev_state); |
7d613ac6 SV |
6067 | qla83xx_idc_unlock(base_vha, 0); |
6068 | qla8xxx_dev_failed_handler(base_vha); | |
6069 | rval = QLA_FUNCTION_FAILED; | |
6070 | qla83xx_idc_lock(base_vha, 0); | |
6071 | goto exit; | |
6072 | } | |
6073 | } | |
6074 | ||
6075 | exit: | |
6076 | return rval; | |
6077 | } | |
6078 | ||
f3ddac19 CD |
6079 | void |
6080 | qla2x00_disable_board_on_pci_error(struct work_struct *work) | |
6081 | { | |
6082 | struct qla_hw_data *ha = container_of(work, struct qla_hw_data, | |
6083 | board_disable); | |
6084 | struct pci_dev *pdev = ha->pdev; | |
6085 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
6086 | ||
726b8548 QT |
6087 | /* |
6088 | * if UNLOAD flag is already set, then continue unload, | |
783e0dc4 SC |
6089 | * where it was set first. |
6090 | */ | |
6091 | if (test_bit(UNLOADING, &base_vha->dpc_flags)) | |
6092 | return; | |
6093 | ||
f3ddac19 CD |
6094 | ql_log(ql_log_warn, base_vha, 0x015b, |
6095 | "Disabling adapter.\n"); | |
6096 | ||
efdb5760 SC |
6097 | if (!atomic_read(&pdev->enable_cnt)) { |
6098 | ql_log(ql_log_info, base_vha, 0xfffc, | |
6099 | "PCI device disabled, no action req for PCI error=%lx\n", | |
6100 | base_vha->pci_flags); | |
6101 | return; | |
6102 | } | |
6103 | ||
726b8548 QT |
6104 | qla2x00_wait_for_sess_deletion(base_vha); |
6105 | ||
f3ddac19 CD |
6106 | set_bit(UNLOADING, &base_vha->dpc_flags); |
6107 | ||
6108 | qla2x00_delete_all_vps(ha, base_vha); | |
6109 | ||
6110 | qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16); | |
6111 | ||
6112 | qla2x00_dfs_remove(base_vha); | |
6113 | ||
6114 | qla84xx_put_chip(base_vha); | |
6115 | ||
6116 | if (base_vha->timer_active) | |
6117 | qla2x00_stop_timer(base_vha); | |
6118 | ||
6119 | base_vha->flags.online = 0; | |
6120 | ||
6121 | qla2x00_destroy_deferred_work(ha); | |
6122 | ||
6123 | /* | |
6124 | * Do not try to stop beacon blink as it will issue a mailbox | |
6125 | * command. | |
6126 | */ | |
6127 | qla2x00_free_sysfs_attr(base_vha, false); | |
6128 | ||
6129 | fc_remove_host(base_vha->host); | |
6130 | ||
6131 | scsi_remove_host(base_vha->host); | |
6132 | ||
6133 | base_vha->flags.init_done = 0; | |
6134 | qla25xx_delete_queues(base_vha); | |
f3ddac19 | 6135 | qla2x00_free_fcports(base_vha); |
093df737 | 6136 | qla2x00_free_irqs(base_vha); |
f3ddac19 CD |
6137 | qla2x00_mem_free(ha); |
6138 | qla82xx_md_free(base_vha); | |
6139 | qla2x00_free_queues(ha); | |
6140 | ||
f3ddac19 CD |
6141 | qla2x00_unmap_iobases(ha); |
6142 | ||
6143 | pci_release_selected_regions(ha->pdev, ha->bars); | |
f3ddac19 CD |
6144 | pci_disable_pcie_error_reporting(pdev); |
6145 | pci_disable_device(pdev); | |
f3ddac19 | 6146 | |
beb9e315 JL |
6147 | /* |
6148 | * Let qla2x00_remove_one cleanup qla_hw_data on device removal. | |
6149 | */ | |
f3ddac19 CD |
6150 | } |
6151 | ||
1da177e4 LT |
6152 | /************************************************************************** |
6153 | * qla2x00_do_dpc | |
6154 | * This kernel thread is a task that is schedule by the interrupt handler | |
6155 | * to perform the background processing for interrupts. | |
6156 | * | |
6157 | * Notes: | |
6158 | * This task always run in the context of a kernel thread. It | |
6159 | * is kick-off by the driver's detect code and starts up | |
6160 | * up one per adapter. It immediately goes to sleep and waits for | |
6161 | * some fibre event. When either the interrupt handler or | |
6162 | * the timer routine detects a event it will one of the task | |
6163 | * bits then wake us up. | |
6164 | **************************************************************************/ | |
6165 | static int | |
6166 | qla2x00_do_dpc(void *data) | |
6167 | { | |
e315cd28 AC |
6168 | scsi_qla_host_t *base_vha; |
6169 | struct qla_hw_data *ha; | |
d7459527 MH |
6170 | uint32_t online; |
6171 | struct qla_qpair *qpair; | |
1da177e4 | 6172 | |
e315cd28 AC |
6173 | ha = (struct qla_hw_data *)data; |
6174 | base_vha = pci_get_drvdata(ha->pdev); | |
1da177e4 | 6175 | |
8698a745 | 6176 | set_user_nice(current, MIN_NICE); |
1da177e4 | 6177 | |
563585ec | 6178 | set_current_state(TASK_INTERRUPTIBLE); |
39a11240 | 6179 | while (!kthread_should_stop()) { |
7c3df132 SK |
6180 | ql_dbg(ql_dbg_dpc, base_vha, 0x4000, |
6181 | "DPC handler sleeping.\n"); | |
1da177e4 | 6182 | |
39a11240 | 6183 | schedule(); |
1da177e4 | 6184 | |
c142caf0 AV |
6185 | if (!base_vha->flags.init_done || ha->flags.mbox_busy) |
6186 | goto end_loop; | |
1da177e4 | 6187 | |
85880801 | 6188 | if (ha->flags.eeh_busy) { |
7c3df132 SK |
6189 | ql_dbg(ql_dbg_dpc, base_vha, 0x4003, |
6190 | "eeh_busy=%d.\n", ha->flags.eeh_busy); | |
c142caf0 | 6191 | goto end_loop; |
85880801 AV |
6192 | } |
6193 | ||
1da177e4 LT |
6194 | ha->dpc_active = 1; |
6195 | ||
5f28d2d7 SK |
6196 | ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001, |
6197 | "DPC handler waking up, dpc_flags=0x%lx.\n", | |
6198 | base_vha->dpc_flags); | |
1da177e4 | 6199 | |
a29b3dd7 JC |
6200 | if (test_bit(UNLOADING, &base_vha->dpc_flags)) |
6201 | break; | |
6202 | ||
7ec0effd AD |
6203 | if (IS_P3P_TYPE(ha)) { |
6204 | if (IS_QLA8044(ha)) { | |
6205 | if (test_and_clear_bit(ISP_UNRECOVERABLE, | |
6206 | &base_vha->dpc_flags)) { | |
6207 | qla8044_idc_lock(ha); | |
6208 | qla8044_wr_direct(base_vha, | |
6209 | QLA8044_CRB_DEV_STATE_INDEX, | |
6210 | QLA8XXX_DEV_FAILED); | |
6211 | qla8044_idc_unlock(ha); | |
6212 | ql_log(ql_log_info, base_vha, 0x4004, | |
6213 | "HW State: FAILED.\n"); | |
6214 | qla8044_device_state_handler(base_vha); | |
6215 | continue; | |
6216 | } | |
6217 | ||
6218 | } else { | |
6219 | if (test_and_clear_bit(ISP_UNRECOVERABLE, | |
6220 | &base_vha->dpc_flags)) { | |
6221 | qla82xx_idc_lock(ha); | |
6222 | qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, | |
6223 | QLA8XXX_DEV_FAILED); | |
6224 | qla82xx_idc_unlock(ha); | |
6225 | ql_log(ql_log_info, base_vha, 0x0151, | |
6226 | "HW State: FAILED.\n"); | |
6227 | qla82xx_device_state_handler(base_vha); | |
6228 | continue; | |
6229 | } | |
a9083016 GM |
6230 | } |
6231 | ||
6232 | if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED, | |
6233 | &base_vha->dpc_flags)) { | |
6234 | ||
7c3df132 SK |
6235 | ql_dbg(ql_dbg_dpc, base_vha, 0x4005, |
6236 | "FCoE context reset scheduled.\n"); | |
a9083016 GM |
6237 | if (!(test_and_set_bit(ABORT_ISP_ACTIVE, |
6238 | &base_vha->dpc_flags))) { | |
6239 | if (qla82xx_fcoe_ctx_reset(base_vha)) { | |
6240 | /* FCoE-ctx reset failed. | |
6241 | * Escalate to chip-reset | |
6242 | */ | |
6243 | set_bit(ISP_ABORT_NEEDED, | |
6244 | &base_vha->dpc_flags); | |
6245 | } | |
6246 | clear_bit(ABORT_ISP_ACTIVE, | |
6247 | &base_vha->dpc_flags); | |
6248 | } | |
6249 | ||
7c3df132 SK |
6250 | ql_dbg(ql_dbg_dpc, base_vha, 0x4006, |
6251 | "FCoE context reset end.\n"); | |
a9083016 | 6252 | } |
8ae6d9c7 GM |
6253 | } else if (IS_QLAFX00(ha)) { |
6254 | if (test_and_clear_bit(ISP_UNRECOVERABLE, | |
6255 | &base_vha->dpc_flags)) { | |
6256 | ql_dbg(ql_dbg_dpc, base_vha, 0x4020, | |
6257 | "Firmware Reset Recovery\n"); | |
6258 | if (qlafx00_reset_initialize(base_vha)) { | |
6259 | /* Failed. Abort isp later. */ | |
6260 | if (!test_bit(UNLOADING, | |
f92f82d6 | 6261 | &base_vha->dpc_flags)) { |
8ae6d9c7 GM |
6262 | set_bit(ISP_UNRECOVERABLE, |
6263 | &base_vha->dpc_flags); | |
6264 | ql_dbg(ql_dbg_dpc, base_vha, | |
6265 | 0x4021, | |
6266 | "Reset Recovery Failed\n"); | |
f92f82d6 | 6267 | } |
8ae6d9c7 GM |
6268 | } |
6269 | } | |
6270 | ||
6271 | if (test_and_clear_bit(FX00_TARGET_SCAN, | |
6272 | &base_vha->dpc_flags)) { | |
6273 | ql_dbg(ql_dbg_dpc, base_vha, 0x4022, | |
6274 | "ISPFx00 Target Scan scheduled\n"); | |
6275 | if (qlafx00_rescan_isp(base_vha)) { | |
6276 | if (!test_bit(UNLOADING, | |
6277 | &base_vha->dpc_flags)) | |
6278 | set_bit(ISP_UNRECOVERABLE, | |
6279 | &base_vha->dpc_flags); | |
6280 | ql_dbg(ql_dbg_dpc, base_vha, 0x401e, | |
6281 | "ISPFx00 Target Scan Failed\n"); | |
6282 | } | |
6283 | ql_dbg(ql_dbg_dpc, base_vha, 0x401f, | |
6284 | "ISPFx00 Target Scan End\n"); | |
6285 | } | |
e8f5e95d AB |
6286 | if (test_and_clear_bit(FX00_HOST_INFO_RESEND, |
6287 | &base_vha->dpc_flags)) { | |
6288 | ql_dbg(ql_dbg_dpc, base_vha, 0x4023, | |
6289 | "ISPFx00 Host Info resend scheduled\n"); | |
6290 | qlafx00_fx_disc(base_vha, | |
6291 | &base_vha->hw->mr.fcport, | |
6292 | FXDISC_REG_HOST_INFO); | |
6293 | } | |
a9083016 GM |
6294 | } |
6295 | ||
e4e3a2ce QT |
6296 | if (test_and_clear_bit(DETECT_SFP_CHANGE, |
6297 | &base_vha->dpc_flags) && | |
6298 | !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) { | |
6299 | qla24xx_detect_sfp(base_vha); | |
6300 | ||
6301 | if (ha->flags.detected_lr_sfp != | |
6302 | ha->flags.using_lr_setting) | |
6303 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); | |
6304 | } | |
6305 | ||
b08abbd9 QT |
6306 | if (test_and_clear_bit |
6307 | (ISP_ABORT_NEEDED, &base_vha->dpc_flags) && | |
6308 | !test_bit(UNLOADING, &base_vha->dpc_flags)) { | |
93eca613 QT |
6309 | bool do_reset = true; |
6310 | ||
0645cb83 | 6311 | switch (base_vha->qlini_mode) { |
93eca613 QT |
6312 | case QLA2XXX_INI_MODE_ENABLED: |
6313 | break; | |
6314 | case QLA2XXX_INI_MODE_DISABLED: | |
0645cb83 QT |
6315 | if (!qla_tgt_mode_enabled(base_vha) && |
6316 | !ha->flags.fw_started) | |
93eca613 QT |
6317 | do_reset = false; |
6318 | break; | |
6319 | case QLA2XXX_INI_MODE_DUAL: | |
0645cb83 QT |
6320 | if (!qla_dual_mode_enabled(base_vha) && |
6321 | !ha->flags.fw_started) | |
93eca613 QT |
6322 | do_reset = false; |
6323 | break; | |
6324 | default: | |
6325 | break; | |
6326 | } | |
1da177e4 | 6327 | |
93eca613 | 6328 | if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE, |
e315cd28 | 6329 | &base_vha->dpc_flags))) { |
93eca613 QT |
6330 | ql_dbg(ql_dbg_dpc, base_vha, 0x4007, |
6331 | "ISP abort scheduled.\n"); | |
a9083016 | 6332 | if (ha->isp_ops->abort_isp(base_vha)) { |
1da177e4 LT |
6333 | /* failed. retry later */ |
6334 | set_bit(ISP_ABORT_NEEDED, | |
e315cd28 | 6335 | &base_vha->dpc_flags); |
99363ef8 | 6336 | } |
e315cd28 AC |
6337 | clear_bit(ABORT_ISP_ACTIVE, |
6338 | &base_vha->dpc_flags); | |
93eca613 QT |
6339 | ql_dbg(ql_dbg_dpc, base_vha, 0x4008, |
6340 | "ISP abort end.\n"); | |
99363ef8 | 6341 | } |
1da177e4 LT |
6342 | } |
6343 | ||
a394aac8 DJ |
6344 | if (test_and_clear_bit(FCPORT_UPDATE_NEEDED, |
6345 | &base_vha->dpc_flags)) { | |
e315cd28 | 6346 | qla2x00_update_fcports(base_vha); |
c9c5ced9 | 6347 | } |
d97994dc | 6348 | |
8ae6d9c7 GM |
6349 | if (IS_QLAFX00(ha)) |
6350 | goto loop_resync_check; | |
6351 | ||
579d12b5 | 6352 | if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) { |
7c3df132 SK |
6353 | ql_dbg(ql_dbg_dpc, base_vha, 0x4009, |
6354 | "Quiescence mode scheduled.\n"); | |
7ec0effd AD |
6355 | if (IS_P3P_TYPE(ha)) { |
6356 | if (IS_QLA82XX(ha)) | |
6357 | qla82xx_device_state_handler(base_vha); | |
6358 | if (IS_QLA8044(ha)) | |
6359 | qla8044_device_state_handler(base_vha); | |
8fcd6b8b CD |
6360 | clear_bit(ISP_QUIESCE_NEEDED, |
6361 | &base_vha->dpc_flags); | |
6362 | if (!ha->flags.quiesce_owner) { | |
6363 | qla2x00_perform_loop_resync(base_vha); | |
7ec0effd AD |
6364 | if (IS_QLA82XX(ha)) { |
6365 | qla82xx_idc_lock(ha); | |
6366 | qla82xx_clear_qsnt_ready( | |
6367 | base_vha); | |
6368 | qla82xx_idc_unlock(ha); | |
6369 | } else if (IS_QLA8044(ha)) { | |
6370 | qla8044_idc_lock(ha); | |
6371 | qla8044_clear_qsnt_ready( | |
6372 | base_vha); | |
6373 | qla8044_idc_unlock(ha); | |
6374 | } | |
8fcd6b8b CD |
6375 | } |
6376 | } else { | |
6377 | clear_bit(ISP_QUIESCE_NEEDED, | |
6378 | &base_vha->dpc_flags); | |
6379 | qla2x00_quiesce_io(base_vha); | |
579d12b5 | 6380 | } |
7c3df132 SK |
6381 | ql_dbg(ql_dbg_dpc, base_vha, 0x400a, |
6382 | "Quiescence mode end.\n"); | |
579d12b5 SK |
6383 | } |
6384 | ||
e315cd28 | 6385 | if (test_and_clear_bit(RESET_MARKER_NEEDED, |
8ae6d9c7 | 6386 | &base_vha->dpc_flags) && |
e315cd28 | 6387 | (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) { |
1da177e4 | 6388 | |
7c3df132 SK |
6389 | ql_dbg(ql_dbg_dpc, base_vha, 0x400b, |
6390 | "Reset marker scheduled.\n"); | |
e315cd28 AC |
6391 | qla2x00_rst_aen(base_vha); |
6392 | clear_bit(RESET_ACTIVE, &base_vha->dpc_flags); | |
7c3df132 SK |
6393 | ql_dbg(ql_dbg_dpc, base_vha, 0x400c, |
6394 | "Reset marker end.\n"); | |
1da177e4 LT |
6395 | } |
6396 | ||
6397 | /* Retry each device up to login retry count */ | |
4005a995 | 6398 | if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) && |
e315cd28 AC |
6399 | !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) && |
6400 | atomic_read(&base_vha->loop_state) != LOOP_DOWN) { | |
1da177e4 | 6401 | |
4005a995 QT |
6402 | if (!base_vha->relogin_jif || |
6403 | time_after_eq(jiffies, base_vha->relogin_jif)) { | |
6404 | base_vha->relogin_jif = jiffies + HZ; | |
6405 | clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags); | |
6406 | ||
9b3e0f4d | 6407 | ql_dbg(ql_dbg_disc, base_vha, 0x400d, |
4005a995 | 6408 | "Relogin scheduled.\n"); |
9b3e0f4d | 6409 | qla24xx_post_relogin_work(base_vha); |
4005a995 | 6410 | } |
1da177e4 | 6411 | } |
8ae6d9c7 | 6412 | loop_resync_check: |
e315cd28 | 6413 | if (test_and_clear_bit(LOOP_RESYNC_NEEDED, |
8ae6d9c7 | 6414 | &base_vha->dpc_flags)) { |
1da177e4 | 6415 | |
7c3df132 SK |
6416 | ql_dbg(ql_dbg_dpc, base_vha, 0x400f, |
6417 | "Loop resync scheduled.\n"); | |
1da177e4 LT |
6418 | |
6419 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, | |
e315cd28 | 6420 | &base_vha->dpc_flags))) { |
1da177e4 | 6421 | |
52c82823 | 6422 | qla2x00_loop_resync(base_vha); |
1da177e4 | 6423 | |
e315cd28 AC |
6424 | clear_bit(LOOP_RESYNC_ACTIVE, |
6425 | &base_vha->dpc_flags); | |
1da177e4 LT |
6426 | } |
6427 | ||
7c3df132 SK |
6428 | ql_dbg(ql_dbg_dpc, base_vha, 0x4010, |
6429 | "Loop resync end.\n"); | |
1da177e4 LT |
6430 | } |
6431 | ||
8ae6d9c7 GM |
6432 | if (IS_QLAFX00(ha)) |
6433 | goto intr_on_check; | |
6434 | ||
e315cd28 AC |
6435 | if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) && |
6436 | atomic_read(&base_vha->loop_state) == LOOP_READY) { | |
6437 | clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags); | |
6438 | qla2xxx_flash_npiv_conf(base_vha); | |
272976ca AV |
6439 | } |
6440 | ||
8ae6d9c7 | 6441 | intr_on_check: |
1da177e4 | 6442 | if (!ha->interrupts_on) |
fd34f556 | 6443 | ha->isp_ops->enable_intrs(ha); |
1da177e4 | 6444 | |
e315cd28 | 6445 | if (test_and_clear_bit(BEACON_BLINK_NEEDED, |
90b604f2 HM |
6446 | &base_vha->dpc_flags)) { |
6447 | if (ha->beacon_blink_led == 1) | |
6448 | ha->isp_ops->beacon_blink(base_vha); | |
6449 | } | |
f6df144c | 6450 | |
d7459527 MH |
6451 | /* qpair online check */ |
6452 | if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED, | |
6453 | &base_vha->dpc_flags)) { | |
6454 | if (ha->flags.eeh_busy || | |
6455 | ha->flags.pci_channel_io_perm_failure) | |
6456 | online = 0; | |
6457 | else | |
6458 | online = 1; | |
6459 | ||
6460 | mutex_lock(&ha->mq_lock); | |
6461 | list_for_each_entry(qpair, &base_vha->qp_list, | |
6462 | qp_list_elem) | |
6463 | qpair->online = online; | |
6464 | mutex_unlock(&ha->mq_lock); | |
6465 | } | |
6466 | ||
8b4673ba QT |
6467 | if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, |
6468 | &base_vha->dpc_flags)) { | |
deeae7a6 DG |
6469 | ql_log(ql_log_info, base_vha, 0xffffff, |
6470 | "nvme: SET ZIO Activity exchange threshold to %d.\n", | |
6471 | ha->nvme_last_rptd_aen); | |
8b4673ba QT |
6472 | if (qla27xx_set_zio_threshold(base_vha, |
6473 | ha->nvme_last_rptd_aen)) { | |
deeae7a6 | 6474 | ql_log(ql_log_info, base_vha, 0xffffff, |
8b4673ba QT |
6475 | "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n", |
6476 | ha->nvme_last_rptd_aen); | |
deeae7a6 DG |
6477 | } |
6478 | } | |
6479 | ||
8b4673ba QT |
6480 | if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED, |
6481 | &base_vha->dpc_flags)) { | |
6482 | ql_log(ql_log_info, base_vha, 0xffffff, | |
6483 | "SET ZIO Activity exchange threshold to %d.\n", | |
6484 | ha->last_zio_threshold); | |
6485 | qla27xx_set_zio_threshold(base_vha, | |
6486 | ha->last_zio_threshold); | |
6487 | } | |
6488 | ||
8ae6d9c7 GM |
6489 | if (!IS_QLAFX00(ha)) |
6490 | qla2x00_do_dpc_all_vps(base_vha); | |
2c3dfe3f | 6491 | |
48acad09 QT |
6492 | if (test_and_clear_bit(N2N_LINK_RESET, |
6493 | &base_vha->dpc_flags)) { | |
6494 | qla2x00_lip_reset(base_vha); | |
6495 | } | |
6496 | ||
1da177e4 | 6497 | ha->dpc_active = 0; |
c142caf0 | 6498 | end_loop: |
563585ec | 6499 | set_current_state(TASK_INTERRUPTIBLE); |
1da177e4 | 6500 | } /* End of while(1) */ |
563585ec | 6501 | __set_current_state(TASK_RUNNING); |
1da177e4 | 6502 | |
7c3df132 SK |
6503 | ql_dbg(ql_dbg_dpc, base_vha, 0x4011, |
6504 | "DPC handler exiting.\n"); | |
1da177e4 LT |
6505 | |
6506 | /* | |
6507 | * Make sure that nobody tries to wake us up again. | |
6508 | */ | |
1da177e4 LT |
6509 | ha->dpc_active = 0; |
6510 | ||
ac280b67 AV |
6511 | /* Cleanup any residual CTX SRBs. */ |
6512 | qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16); | |
6513 | ||
39a11240 CH |
6514 | return 0; |
6515 | } | |
6516 | ||
6517 | void | |
e315cd28 | 6518 | qla2xxx_wake_dpc(struct scsi_qla_host *vha) |
39a11240 | 6519 | { |
e315cd28 | 6520 | struct qla_hw_data *ha = vha->hw; |
c795c1e4 AV |
6521 | struct task_struct *t = ha->dpc_thread; |
6522 | ||
e315cd28 | 6523 | if (!test_bit(UNLOADING, &vha->dpc_flags) && t) |
c795c1e4 | 6524 | wake_up_process(t); |
1da177e4 LT |
6525 | } |
6526 | ||
1da177e4 LT |
6527 | /* |
6528 | * qla2x00_rst_aen | |
6529 | * Processes asynchronous reset. | |
6530 | * | |
6531 | * Input: | |
6532 | * ha = adapter block pointer. | |
6533 | */ | |
6534 | static void | |
e315cd28 | 6535 | qla2x00_rst_aen(scsi_qla_host_t *vha) |
1da177e4 | 6536 | { |
e315cd28 AC |
6537 | if (vha->flags.online && !vha->flags.reset_active && |
6538 | !atomic_read(&vha->loop_down_timer) && | |
6539 | !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) { | |
1da177e4 | 6540 | do { |
e315cd28 | 6541 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
1da177e4 LT |
6542 | |
6543 | /* | |
6544 | * Issue marker command only when we are going to start | |
6545 | * the I/O. | |
6546 | */ | |
e315cd28 AC |
6547 | vha->marker_needed = 1; |
6548 | } while (!atomic_read(&vha->loop_down_timer) && | |
6549 | (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags))); | |
1da177e4 LT |
6550 | } |
6551 | } | |
6552 | ||
1da177e4 LT |
6553 | /************************************************************************** |
6554 | * qla2x00_timer | |
6555 | * | |
6556 | * Description: | |
6557 | * One second timer | |
6558 | * | |
6559 | * Context: Interrupt | |
6560 | ***************************************************************************/ | |
2c3dfe3f | 6561 | void |
8e5f4ba0 | 6562 | qla2x00_timer(struct timer_list *t) |
1da177e4 | 6563 | { |
8e5f4ba0 | 6564 | scsi_qla_host_t *vha = from_timer(vha, t, timer); |
1da177e4 | 6565 | unsigned long cpu_flags = 0; |
1da177e4 LT |
6566 | int start_dpc = 0; |
6567 | int index; | |
6568 | srb_t *sp; | |
85880801 | 6569 | uint16_t w; |
e315cd28 | 6570 | struct qla_hw_data *ha = vha->hw; |
73208dfd | 6571 | struct req_que *req; |
85880801 | 6572 | |
a5b36321 | 6573 | if (ha->flags.eeh_busy) { |
7c3df132 SK |
6574 | ql_dbg(ql_dbg_timer, vha, 0x6000, |
6575 | "EEH = %d, restarting timer.\n", | |
6576 | ha->flags.eeh_busy); | |
a5b36321 LC |
6577 | qla2x00_restart_timer(vha, WATCH_INTERVAL); |
6578 | return; | |
6579 | } | |
6580 | ||
f3ddac19 CD |
6581 | /* |
6582 | * Hardware read to raise pending EEH errors during mailbox waits. If | |
6583 | * the read returns -1 then disable the board. | |
6584 | */ | |
6585 | if (!pci_channel_offline(ha->pdev)) { | |
85880801 | 6586 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); |
c821e0d5 | 6587 | qla2x00_check_reg16_for_disconnect(vha, w); |
f3ddac19 | 6588 | } |
1da177e4 | 6589 | |
cefcaba6 | 6590 | /* Make sure qla82xx_watchdog is run only for physical port */ |
7ec0effd | 6591 | if (!vha->vp_idx && IS_P3P_TYPE(ha)) { |
579d12b5 SK |
6592 | if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags)) |
6593 | start_dpc++; | |
7ec0effd AD |
6594 | if (IS_QLA82XX(ha)) |
6595 | qla82xx_watchdog(vha); | |
6596 | else if (IS_QLA8044(ha)) | |
6597 | qla8044_watchdog(vha); | |
579d12b5 SK |
6598 | } |
6599 | ||
8ae6d9c7 GM |
6600 | if (!vha->vp_idx && IS_QLAFX00(ha)) |
6601 | qlafx00_timer_routine(vha); | |
6602 | ||
1da177e4 | 6603 | /* Loop down handler. */ |
e315cd28 | 6604 | if (atomic_read(&vha->loop_down_timer) > 0 && |
8f7daead GM |
6605 | !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) && |
6606 | !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags)) | |
e315cd28 | 6607 | && vha->flags.online) { |
1da177e4 | 6608 | |
e315cd28 AC |
6609 | if (atomic_read(&vha->loop_down_timer) == |
6610 | vha->loop_down_abort_time) { | |
1da177e4 | 6611 | |
7c3df132 SK |
6612 | ql_log(ql_log_info, vha, 0x6008, |
6613 | "Loop down - aborting the queues before time expires.\n"); | |
1da177e4 | 6614 | |
e315cd28 AC |
6615 | if (!IS_QLA2100(ha) && vha->link_down_timeout) |
6616 | atomic_set(&vha->loop_state, LOOP_DEAD); | |
1da177e4 | 6617 | |
f08b7251 AV |
6618 | /* |
6619 | * Schedule an ISP abort to return any FCP2-device | |
6620 | * commands. | |
6621 | */ | |
2c3dfe3f | 6622 | /* NPIV - scan physical port only */ |
e315cd28 | 6623 | if (!vha->vp_idx) { |
2c3dfe3f SJ |
6624 | spin_lock_irqsave(&ha->hardware_lock, |
6625 | cpu_flags); | |
73208dfd | 6626 | req = ha->req_q_map[0]; |
2c3dfe3f | 6627 | for (index = 1; |
8d93f550 | 6628 | index < req->num_outstanding_cmds; |
2c3dfe3f SJ |
6629 | index++) { |
6630 | fc_port_t *sfcp; | |
6631 | ||
e315cd28 | 6632 | sp = req->outstanding_cmds[index]; |
2c3dfe3f SJ |
6633 | if (!sp) |
6634 | continue; | |
c5419e26 QT |
6635 | if (sp->cmd_type != TYPE_SRB) |
6636 | continue; | |
9ba56b95 | 6637 | if (sp->type != SRB_SCSI_CMD) |
cf53b069 | 6638 | continue; |
2c3dfe3f | 6639 | sfcp = sp->fcport; |
f08b7251 | 6640 | if (!(sfcp->flags & FCF_FCP2_DEVICE)) |
2c3dfe3f | 6641 | continue; |
bdf79621 | 6642 | |
8f7daead GM |
6643 | if (IS_QLA82XX(ha)) |
6644 | set_bit(FCOE_CTX_RESET_NEEDED, | |
6645 | &vha->dpc_flags); | |
6646 | else | |
6647 | set_bit(ISP_ABORT_NEEDED, | |
e315cd28 | 6648 | &vha->dpc_flags); |
2c3dfe3f SJ |
6649 | break; |
6650 | } | |
6651 | spin_unlock_irqrestore(&ha->hardware_lock, | |
e315cd28 | 6652 | cpu_flags); |
1da177e4 | 6653 | } |
1da177e4 LT |
6654 | start_dpc++; |
6655 | } | |
6656 | ||
6657 | /* if the loop has been down for 4 minutes, reinit adapter */ | |
e315cd28 | 6658 | if (atomic_dec_and_test(&vha->loop_down_timer) != 0) { |
0d6e61bc | 6659 | if (!(vha->device_flags & DFLG_NO_CABLE)) { |
7c3df132 | 6660 | ql_log(ql_log_warn, vha, 0x6009, |
1da177e4 LT |
6661 | "Loop down - aborting ISP.\n"); |
6662 | ||
8f7daead GM |
6663 | if (IS_QLA82XX(ha)) |
6664 | set_bit(FCOE_CTX_RESET_NEEDED, | |
6665 | &vha->dpc_flags); | |
6666 | else | |
6667 | set_bit(ISP_ABORT_NEEDED, | |
6668 | &vha->dpc_flags); | |
1da177e4 LT |
6669 | } |
6670 | } | |
7c3df132 SK |
6671 | ql_dbg(ql_dbg_timer, vha, 0x600a, |
6672 | "Loop down - seconds remaining %d.\n", | |
6673 | atomic_read(&vha->loop_down_timer)); | |
1da177e4 | 6674 | } |
cefcaba6 SK |
6675 | /* Check if beacon LED needs to be blinked for physical host only */ |
6676 | if (!vha->vp_idx && (ha->beacon_blink_led == 1)) { | |
999916dc | 6677 | /* There is no beacon_blink function for ISP82xx */ |
7ec0effd | 6678 | if (!IS_P3P_TYPE(ha)) { |
999916dc SK |
6679 | set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags); |
6680 | start_dpc++; | |
6681 | } | |
f6df144c AV |
6682 | } |
6683 | ||
550bf57d | 6684 | /* Process any deferred work. */ |
9b3e0f4d QT |
6685 | if (!list_empty(&vha->work_list)) { |
6686 | unsigned long flags; | |
6687 | bool q = false; | |
6688 | ||
6689 | spin_lock_irqsave(&vha->work_lock, flags); | |
6690 | if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags)) | |
6691 | q = true; | |
6692 | spin_unlock_irqrestore(&vha->work_lock, flags); | |
6693 | if (q) | |
6694 | queue_work(vha->hw->wq, &vha->iocb_work); | |
6695 | } | |
550bf57d | 6696 | |
7401bc18 DG |
6697 | /* |
6698 | * FC-NVME | |
6699 | * see if the active AEN count has changed from what was last reported. | |
6700 | */ | |
b2d1453a GM |
6701 | if (!vha->vp_idx && |
6702 | (atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen) && | |
6703 | ha->zio_mode == QLA_ZIO_MODE_6 && | |
6704 | !ha->flags.host_shutting_down) { | |
7401bc18 | 6705 | ql_log(ql_log_info, vha, 0x3002, |
8b4673ba QT |
6706 | "nvme: Sched: Set ZIO exchange threshold to %d.\n", |
6707 | ha->nvme_last_rptd_aen); | |
deeae7a6 | 6708 | ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt); |
8b4673ba QT |
6709 | set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags); |
6710 | start_dpc++; | |
6711 | } | |
6712 | ||
6713 | if (!vha->vp_idx && | |
6714 | (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) && | |
6715 | (ha->zio_mode == QLA_ZIO_MODE_6) && | |
ecc89f25 | 6716 | (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) { |
8b4673ba QT |
6717 | ql_log(ql_log_info, vha, 0x3002, |
6718 | "Sched: Set ZIO exchange threshold to %d.\n", | |
6719 | ha->last_zio_threshold); | |
6720 | ha->last_zio_threshold = atomic_read(&ha->zio_threshold); | |
deeae7a6 DG |
6721 | set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags); |
6722 | start_dpc++; | |
7401bc18 DG |
6723 | } |
6724 | ||
1da177e4 | 6725 | /* Schedule the DPC routine if needed */ |
e315cd28 AC |
6726 | if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) || |
6727 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) || | |
6728 | test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) || | |
1da177e4 | 6729 | start_dpc || |
e315cd28 AC |
6730 | test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) || |
6731 | test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) || | |
a9083016 GM |
6732 | test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) || |
6733 | test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) || | |
e315cd28 | 6734 | test_bit(VP_DPC_NEEDED, &vha->dpc_flags) || |
50280c01 | 6735 | test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) { |
7c3df132 SK |
6736 | ql_dbg(ql_dbg_timer, vha, 0x600b, |
6737 | "isp_abort_needed=%d loop_resync_needed=%d " | |
6738 | "fcport_update_needed=%d start_dpc=%d " | |
6739 | "reset_marker_needed=%d", | |
6740 | test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags), | |
6741 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags), | |
6742 | test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags), | |
6743 | start_dpc, | |
6744 | test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)); | |
6745 | ql_dbg(ql_dbg_timer, vha, 0x600c, | |
6746 | "beacon_blink_needed=%d isp_unrecoverable=%d " | |
6747 | "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d " | |
50280c01 | 6748 | "relogin_needed=%d.\n", |
7c3df132 SK |
6749 | test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags), |
6750 | test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags), | |
6751 | test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags), | |
6752 | test_bit(VP_DPC_NEEDED, &vha->dpc_flags), | |
50280c01 | 6753 | test_bit(RELOGIN_NEEDED, &vha->dpc_flags)); |
e315cd28 | 6754 | qla2xxx_wake_dpc(vha); |
7c3df132 | 6755 | } |
1da177e4 | 6756 | |
e315cd28 | 6757 | qla2x00_restart_timer(vha, WATCH_INTERVAL); |
1da177e4 LT |
6758 | } |
6759 | ||
5433383e AV |
6760 | /* Firmware interface routines. */ |
6761 | ||
5433383e AV |
6762 | #define FW_ISP21XX 0 |
6763 | #define FW_ISP22XX 1 | |
6764 | #define FW_ISP2300 2 | |
6765 | #define FW_ISP2322 3 | |
48c02fde | 6766 | #define FW_ISP24XX 4 |
c3a2f0df | 6767 | #define FW_ISP25XX 5 |
3a03eb79 | 6768 | #define FW_ISP81XX 6 |
a9083016 | 6769 | #define FW_ISP82XX 7 |
6246b8a1 GM |
6770 | #define FW_ISP2031 8 |
6771 | #define FW_ISP8031 9 | |
2c5bbbb2 | 6772 | #define FW_ISP27XX 10 |
ecc89f25 | 6773 | #define FW_ISP28XX 11 |
5433383e | 6774 | |
bb8ee499 AV |
6775 | #define FW_FILE_ISP21XX "ql2100_fw.bin" |
6776 | #define FW_FILE_ISP22XX "ql2200_fw.bin" | |
6777 | #define FW_FILE_ISP2300 "ql2300_fw.bin" | |
6778 | #define FW_FILE_ISP2322 "ql2322_fw.bin" | |
6779 | #define FW_FILE_ISP24XX "ql2400_fw.bin" | |
c3a2f0df | 6780 | #define FW_FILE_ISP25XX "ql2500_fw.bin" |
3a03eb79 | 6781 | #define FW_FILE_ISP81XX "ql8100_fw.bin" |
a9083016 | 6782 | #define FW_FILE_ISP82XX "ql8200_fw.bin" |
6246b8a1 GM |
6783 | #define FW_FILE_ISP2031 "ql2600_fw.bin" |
6784 | #define FW_FILE_ISP8031 "ql8300_fw.bin" | |
2c5bbbb2 | 6785 | #define FW_FILE_ISP27XX "ql2700_fw.bin" |
ecc89f25 | 6786 | #define FW_FILE_ISP28XX "ql2800_fw.bin" |
f73cb695 | 6787 | |
bb8ee499 | 6788 | |
e1e82b6f | 6789 | static DEFINE_MUTEX(qla_fw_lock); |
5433383e | 6790 | |
ecc89f25 | 6791 | static struct fw_blob qla_fw_blobs[] = { |
bb8ee499 AV |
6792 | { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, }, |
6793 | { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, }, | |
6794 | { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, }, | |
6795 | { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, }, | |
6796 | { .name = FW_FILE_ISP24XX, }, | |
c3a2f0df | 6797 | { .name = FW_FILE_ISP25XX, }, |
3a03eb79 | 6798 | { .name = FW_FILE_ISP81XX, }, |
a9083016 | 6799 | { .name = FW_FILE_ISP82XX, }, |
6246b8a1 GM |
6800 | { .name = FW_FILE_ISP2031, }, |
6801 | { .name = FW_FILE_ISP8031, }, | |
2c5bbbb2 | 6802 | { .name = FW_FILE_ISP27XX, }, |
ecc89f25 JC |
6803 | { .name = FW_FILE_ISP28XX, }, |
6804 | { .name = NULL, }, | |
5433383e AV |
6805 | }; |
6806 | ||
6807 | struct fw_blob * | |
e315cd28 | 6808 | qla2x00_request_firmware(scsi_qla_host_t *vha) |
5433383e | 6809 | { |
e315cd28 | 6810 | struct qla_hw_data *ha = vha->hw; |
5433383e AV |
6811 | struct fw_blob *blob; |
6812 | ||
5433383e AV |
6813 | if (IS_QLA2100(ha)) { |
6814 | blob = &qla_fw_blobs[FW_ISP21XX]; | |
6815 | } else if (IS_QLA2200(ha)) { | |
6816 | blob = &qla_fw_blobs[FW_ISP22XX]; | |
48c02fde | 6817 | } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
5433383e | 6818 | blob = &qla_fw_blobs[FW_ISP2300]; |
48c02fde | 6819 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) { |
5433383e | 6820 | blob = &qla_fw_blobs[FW_ISP2322]; |
4d4df193 | 6821 | } else if (IS_QLA24XX_TYPE(ha)) { |
5433383e | 6822 | blob = &qla_fw_blobs[FW_ISP24XX]; |
c3a2f0df AV |
6823 | } else if (IS_QLA25XX(ha)) { |
6824 | blob = &qla_fw_blobs[FW_ISP25XX]; | |
3a03eb79 AV |
6825 | } else if (IS_QLA81XX(ha)) { |
6826 | blob = &qla_fw_blobs[FW_ISP81XX]; | |
a9083016 GM |
6827 | } else if (IS_QLA82XX(ha)) { |
6828 | blob = &qla_fw_blobs[FW_ISP82XX]; | |
6246b8a1 GM |
6829 | } else if (IS_QLA2031(ha)) { |
6830 | blob = &qla_fw_blobs[FW_ISP2031]; | |
6831 | } else if (IS_QLA8031(ha)) { | |
6832 | blob = &qla_fw_blobs[FW_ISP8031]; | |
2c5bbbb2 JC |
6833 | } else if (IS_QLA27XX(ha)) { |
6834 | blob = &qla_fw_blobs[FW_ISP27XX]; | |
ecc89f25 JC |
6835 | } else if (IS_QLA28XX(ha)) { |
6836 | blob = &qla_fw_blobs[FW_ISP28XX]; | |
8a655229 DC |
6837 | } else { |
6838 | return NULL; | |
5433383e AV |
6839 | } |
6840 | ||
ecc89f25 JC |
6841 | if (!blob->name) |
6842 | return NULL; | |
6843 | ||
e1e82b6f | 6844 | mutex_lock(&qla_fw_lock); |
5433383e AV |
6845 | if (blob->fw) |
6846 | goto out; | |
6847 | ||
6848 | if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) { | |
7c3df132 SK |
6849 | ql_log(ql_log_warn, vha, 0x0063, |
6850 | "Failed to load firmware image (%s).\n", blob->name); | |
5433383e AV |
6851 | blob->fw = NULL; |
6852 | blob = NULL; | |
5433383e AV |
6853 | } |
6854 | ||
6855 | out: | |
e1e82b6f | 6856 | mutex_unlock(&qla_fw_lock); |
5433383e AV |
6857 | return blob; |
6858 | } | |
6859 | ||
6860 | static void | |
6861 | qla2x00_release_firmware(void) | |
6862 | { | |
ecc89f25 | 6863 | struct fw_blob *blob; |
5433383e | 6864 | |
e1e82b6f | 6865 | mutex_lock(&qla_fw_lock); |
ecc89f25 JC |
6866 | for (blob = qla_fw_blobs; blob->name; blob++) |
6867 | release_firmware(blob->fw); | |
e1e82b6f | 6868 | mutex_unlock(&qla_fw_lock); |
5433383e AV |
6869 | } |
6870 | ||
5386a4e6 QT |
6871 | static void qla_pci_error_cleanup(scsi_qla_host_t *vha) |
6872 | { | |
6873 | struct qla_hw_data *ha = vha->hw; | |
6874 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
6875 | struct qla_qpair *qpair = NULL; | |
6876 | struct scsi_qla_host *vp; | |
6877 | fc_port_t *fcport; | |
6878 | int i; | |
6879 | unsigned long flags; | |
6880 | ||
6881 | ha->chip_reset++; | |
6882 | ||
6883 | ha->base_qpair->chip_reset = ha->chip_reset; | |
6884 | for (i = 0; i < ha->max_qpairs; i++) { | |
6885 | if (ha->queue_pair_map[i]) | |
6886 | ha->queue_pair_map[i]->chip_reset = | |
6887 | ha->base_qpair->chip_reset; | |
6888 | } | |
6889 | ||
6890 | /* purge MBox commands */ | |
6891 | if (atomic_read(&ha->num_pend_mbx_stage3)) { | |
6892 | clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); | |
6893 | complete(&ha->mbx_intr_comp); | |
6894 | } | |
6895 | ||
6896 | i = 0; | |
6897 | ||
6898 | while (atomic_read(&ha->num_pend_mbx_stage3) || | |
6899 | atomic_read(&ha->num_pend_mbx_stage2) || | |
6900 | atomic_read(&ha->num_pend_mbx_stage1)) { | |
6901 | msleep(20); | |
6902 | i++; | |
6903 | if (i > 50) | |
6904 | break; | |
6905 | } | |
6906 | ||
6907 | ha->flags.purge_mbox = 0; | |
6908 | ||
6909 | mutex_lock(&ha->mq_lock); | |
6910 | list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem) | |
6911 | qpair->online = 0; | |
6912 | mutex_unlock(&ha->mq_lock); | |
6913 | ||
6914 | qla2x00_mark_all_devices_lost(vha, 0); | |
6915 | ||
6916 | spin_lock_irqsave(&ha->vport_slock, flags); | |
6917 | list_for_each_entry(vp, &ha->vp_list, list) { | |
6918 | atomic_inc(&vp->vref_count); | |
6919 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
6920 | qla2x00_mark_all_devices_lost(vp, 0); | |
6921 | spin_lock_irqsave(&ha->vport_slock, flags); | |
6922 | atomic_dec(&vp->vref_count); | |
6923 | } | |
6924 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
6925 | ||
6926 | /* Clear all async request states across all VPs. */ | |
6927 | list_for_each_entry(fcport, &vha->vp_fcports, list) | |
6928 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); | |
6929 | ||
6930 | spin_lock_irqsave(&ha->vport_slock, flags); | |
6931 | list_for_each_entry(vp, &ha->vp_list, list) { | |
6932 | atomic_inc(&vp->vref_count); | |
6933 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
6934 | list_for_each_entry(fcport, &vp->vp_fcports, list) | |
6935 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); | |
6936 | spin_lock_irqsave(&ha->vport_slock, flags); | |
6937 | atomic_dec(&vp->vref_count); | |
6938 | } | |
6939 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
6940 | } | |
6941 | ||
6942 | ||
14e660e6 SJ |
6943 | static pci_ers_result_t |
6944 | qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
6945 | { | |
85880801 AV |
6946 | scsi_qla_host_t *vha = pci_get_drvdata(pdev); |
6947 | struct qla_hw_data *ha = vha->hw; | |
6948 | ||
7c3df132 SK |
6949 | ql_dbg(ql_dbg_aer, vha, 0x9000, |
6950 | "PCI error detected, state %x.\n", state); | |
b9b12f73 | 6951 | |
efdb5760 SC |
6952 | if (!atomic_read(&pdev->enable_cnt)) { |
6953 | ql_log(ql_log_info, vha, 0xffff, | |
6954 | "PCI device is disabled,state %x\n", state); | |
6955 | return PCI_ERS_RESULT_NEED_RESET; | |
6956 | } | |
6957 | ||
14e660e6 SJ |
6958 | switch (state) { |
6959 | case pci_channel_io_normal: | |
85880801 | 6960 | ha->flags.eeh_busy = 0; |
c38d1baf | 6961 | if (ql2xmqsupport || ql2xnvmeenable) { |
d7459527 MH |
6962 | set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags); |
6963 | qla2xxx_wake_dpc(vha); | |
6964 | } | |
14e660e6 SJ |
6965 | return PCI_ERS_RESULT_CAN_RECOVER; |
6966 | case pci_channel_io_frozen: | |
85880801 | 6967 | ha->flags.eeh_busy = 1; |
5386a4e6 | 6968 | qla_pci_error_cleanup(vha); |
14e660e6 SJ |
6969 | return PCI_ERS_RESULT_NEED_RESET; |
6970 | case pci_channel_io_perm_failure: | |
85880801 AV |
6971 | ha->flags.pci_channel_io_perm_failure = 1; |
6972 | qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16); | |
c38d1baf | 6973 | if (ql2xmqsupport || ql2xnvmeenable) { |
d7459527 MH |
6974 | set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags); |
6975 | qla2xxx_wake_dpc(vha); | |
6976 | } | |
14e660e6 SJ |
6977 | return PCI_ERS_RESULT_DISCONNECT; |
6978 | } | |
6979 | return PCI_ERS_RESULT_NEED_RESET; | |
6980 | } | |
6981 | ||
6982 | static pci_ers_result_t | |
6983 | qla2xxx_pci_mmio_enabled(struct pci_dev *pdev) | |
6984 | { | |
6985 | int risc_paused = 0; | |
6986 | uint32_t stat; | |
6987 | unsigned long flags; | |
e315cd28 AC |
6988 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
6989 | struct qla_hw_data *ha = base_vha->hw; | |
14e660e6 SJ |
6990 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
6991 | struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24; | |
6992 | ||
bcc5b6d3 SK |
6993 | if (IS_QLA82XX(ha)) |
6994 | return PCI_ERS_RESULT_RECOVERED; | |
6995 | ||
14e660e6 SJ |
6996 | spin_lock_irqsave(&ha->hardware_lock, flags); |
6997 | if (IS_QLA2100(ha) || IS_QLA2200(ha)){ | |
6998 | stat = RD_REG_DWORD(®->hccr); | |
6999 | if (stat & HCCR_RISC_PAUSE) | |
7000 | risc_paused = 1; | |
7001 | } else if (IS_QLA23XX(ha)) { | |
7002 | stat = RD_REG_DWORD(®->u.isp2300.host_status); | |
7003 | if (stat & HSR_RISC_PAUSED) | |
7004 | risc_paused = 1; | |
7005 | } else if (IS_FWI2_CAPABLE(ha)) { | |
7006 | stat = RD_REG_DWORD(®24->host_status); | |
7007 | if (stat & HSRX_RISC_PAUSED) | |
7008 | risc_paused = 1; | |
7009 | } | |
7010 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
7011 | ||
7012 | if (risc_paused) { | |
7c3df132 SK |
7013 | ql_log(ql_log_info, base_vha, 0x9003, |
7014 | "RISC paused -- mmio_enabled, Dumping firmware.\n"); | |
e315cd28 | 7015 | ha->isp_ops->fw_dump(base_vha, 0); |
14e660e6 SJ |
7016 | |
7017 | return PCI_ERS_RESULT_NEED_RESET; | |
7018 | } else | |
7019 | return PCI_ERS_RESULT_RECOVERED; | |
7020 | } | |
7021 | ||
7022 | static pci_ers_result_t | |
7023 | qla2xxx_pci_slot_reset(struct pci_dev *pdev) | |
7024 | { | |
7025 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; | |
e315cd28 AC |
7026 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
7027 | struct qla_hw_data *ha = base_vha->hw; | |
5386a4e6 QT |
7028 | int rc; |
7029 | struct qla_qpair *qpair = NULL; | |
09483916 | 7030 | |
7c3df132 SK |
7031 | ql_dbg(ql_dbg_aer, base_vha, 0x9004, |
7032 | "Slot Reset.\n"); | |
85880801 | 7033 | |
90a86fc0 JC |
7034 | /* Workaround: qla2xxx driver which access hardware earlier |
7035 | * needs error state to be pci_channel_io_online. | |
7036 | * Otherwise mailbox command timesout. | |
7037 | */ | |
7038 | pdev->error_state = pci_channel_io_normal; | |
7039 | ||
7040 | pci_restore_state(pdev); | |
7041 | ||
8c1496bd RL |
7042 | /* pci_restore_state() clears the saved_state flag of the device |
7043 | * save restored state which resets saved_state flag | |
7044 | */ | |
7045 | pci_save_state(pdev); | |
7046 | ||
09483916 BH |
7047 | if (ha->mem_only) |
7048 | rc = pci_enable_device_mem(pdev); | |
7049 | else | |
7050 | rc = pci_enable_device(pdev); | |
14e660e6 | 7051 | |
09483916 | 7052 | if (rc) { |
7c3df132 | 7053 | ql_log(ql_log_warn, base_vha, 0x9005, |
14e660e6 | 7054 | "Can't re-enable PCI device after reset.\n"); |
a5b36321 | 7055 | goto exit_slot_reset; |
14e660e6 | 7056 | } |
14e660e6 | 7057 | |
90a86fc0 | 7058 | |
e315cd28 | 7059 | if (ha->isp_ops->pci_config(base_vha)) |
a5b36321 LC |
7060 | goto exit_slot_reset; |
7061 | ||
5386a4e6 QT |
7062 | mutex_lock(&ha->mq_lock); |
7063 | list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem) | |
7064 | qpair->online = 1; | |
7065 | mutex_unlock(&ha->mq_lock); | |
85880801 | 7066 | |
5386a4e6 | 7067 | base_vha->flags.online = 1; |
e315cd28 | 7068 | set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
a9083016 | 7069 | if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS) |
14e660e6 | 7070 | ret = PCI_ERS_RESULT_RECOVERED; |
e315cd28 | 7071 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
14e660e6 | 7072 | |
90a86fc0 | 7073 | |
a5b36321 | 7074 | exit_slot_reset: |
7c3df132 SK |
7075 | ql_dbg(ql_dbg_aer, base_vha, 0x900e, |
7076 | "slot_reset return %x.\n", ret); | |
85880801 | 7077 | |
14e660e6 SJ |
7078 | return ret; |
7079 | } | |
7080 | ||
7081 | static void | |
7082 | qla2xxx_pci_resume(struct pci_dev *pdev) | |
7083 | { | |
e315cd28 AC |
7084 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); |
7085 | struct qla_hw_data *ha = base_vha->hw; | |
14e660e6 SJ |
7086 | int ret; |
7087 | ||
7c3df132 SK |
7088 | ql_dbg(ql_dbg_aer, base_vha, 0x900f, |
7089 | "pci_resume.\n"); | |
85880801 | 7090 | |
5386a4e6 QT |
7091 | ha->flags.eeh_busy = 0; |
7092 | ||
e315cd28 | 7093 | ret = qla2x00_wait_for_hba_online(base_vha); |
14e660e6 | 7094 | if (ret != QLA_SUCCESS) { |
7c3df132 SK |
7095 | ql_log(ql_log_fatal, base_vha, 0x9002, |
7096 | "The device failed to resume I/O from slot/link_reset.\n"); | |
14e660e6 | 7097 | } |
14e660e6 SJ |
7098 | } |
7099 | ||
590f806d QT |
7100 | static void |
7101 | qla_pci_reset_prepare(struct pci_dev *pdev) | |
7102 | { | |
7103 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); | |
7104 | struct qla_hw_data *ha = base_vha->hw; | |
7105 | struct qla_qpair *qpair; | |
7106 | ||
7107 | ql_log(ql_log_warn, base_vha, 0xffff, | |
7108 | "%s.\n", __func__); | |
7109 | ||
7110 | /* | |
7111 | * PCI FLR/function reset is about to reset the | |
7112 | * slot. Stop the chip to stop all DMA access. | |
7113 | * It is assumed that pci_reset_done will be called | |
7114 | * after FLR to resume Chip operation. | |
7115 | */ | |
7116 | ha->flags.eeh_busy = 1; | |
7117 | mutex_lock(&ha->mq_lock); | |
7118 | list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem) | |
7119 | qpair->online = 0; | |
7120 | mutex_unlock(&ha->mq_lock); | |
7121 | ||
7122 | set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | |
7123 | qla2x00_abort_isp_cleanup(base_vha); | |
7124 | qla2x00_abort_all_cmds(base_vha, DID_RESET << 16); | |
7125 | } | |
7126 | ||
7127 | static void | |
7128 | qla_pci_reset_done(struct pci_dev *pdev) | |
7129 | { | |
7130 | scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); | |
7131 | struct qla_hw_data *ha = base_vha->hw; | |
7132 | struct qla_qpair *qpair; | |
7133 | ||
7134 | ql_log(ql_log_warn, base_vha, 0xffff, | |
7135 | "%s.\n", __func__); | |
7136 | ||
7137 | /* | |
7138 | * FLR just completed by PCI layer. Resume adapter | |
7139 | */ | |
7140 | ha->flags.eeh_busy = 0; | |
7141 | mutex_lock(&ha->mq_lock); | |
7142 | list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem) | |
7143 | qpair->online = 1; | |
7144 | mutex_unlock(&ha->mq_lock); | |
7145 | ||
7146 | base_vha->flags.online = 1; | |
7147 | ha->isp_ops->abort_isp(base_vha); | |
7148 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); | |
7149 | } | |
7150 | ||
5601236b MH |
7151 | static int qla2xxx_map_queues(struct Scsi_Host *shost) |
7152 | { | |
d68b850e | 7153 | int rc; |
5601236b | 7154 | scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata; |
485b0eca | 7155 | struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT]; |
5601236b | 7156 | |
f3e02695 | 7157 | if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase) |
ed76e329 | 7158 | rc = blk_mq_map_queues(qmap); |
d68b850e | 7159 | else |
f0783d43 | 7160 | rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset); |
d68b850e | 7161 | return rc; |
5601236b MH |
7162 | } |
7163 | ||
6515ad71 BVA |
7164 | struct scsi_host_template qla2xxx_driver_template = { |
7165 | .module = THIS_MODULE, | |
7166 | .name = QLA2XXX_DRIVER_NAME, | |
7167 | .queuecommand = qla2xxx_queuecommand, | |
7168 | ||
7169 | .eh_timed_out = fc_eh_timed_out, | |
7170 | .eh_abort_handler = qla2xxx_eh_abort, | |
7171 | .eh_device_reset_handler = qla2xxx_eh_device_reset, | |
7172 | .eh_target_reset_handler = qla2xxx_eh_target_reset, | |
7173 | .eh_bus_reset_handler = qla2xxx_eh_bus_reset, | |
7174 | .eh_host_reset_handler = qla2xxx_eh_host_reset, | |
7175 | ||
7176 | .slave_configure = qla2xxx_slave_configure, | |
7177 | ||
7178 | .slave_alloc = qla2xxx_slave_alloc, | |
7179 | .slave_destroy = qla2xxx_slave_destroy, | |
7180 | .scan_finished = qla2xxx_scan_finished, | |
7181 | .scan_start = qla2xxx_scan_start, | |
7182 | .change_queue_depth = scsi_change_queue_depth, | |
7183 | .map_queues = qla2xxx_map_queues, | |
7184 | .this_id = -1, | |
7185 | .cmd_per_lun = 3, | |
7186 | .sg_tablesize = SG_ALL, | |
7187 | ||
7188 | .max_sectors = 0xFFFF, | |
7189 | .shost_attrs = qla2x00_host_attrs, | |
7190 | ||
7191 | .supported_mode = MODE_INITIATOR, | |
7192 | .track_queue_depth = 1, | |
7193 | }; | |
7194 | ||
a55b2d21 | 7195 | static const struct pci_error_handlers qla2xxx_err_handler = { |
14e660e6 SJ |
7196 | .error_detected = qla2xxx_pci_error_detected, |
7197 | .mmio_enabled = qla2xxx_pci_mmio_enabled, | |
7198 | .slot_reset = qla2xxx_pci_slot_reset, | |
7199 | .resume = qla2xxx_pci_resume, | |
590f806d QT |
7200 | .reset_prepare = qla_pci_reset_prepare, |
7201 | .reset_done = qla_pci_reset_done, | |
14e660e6 SJ |
7202 | }; |
7203 | ||
5433383e | 7204 | static struct pci_device_id qla2xxx_pci_tbl[] = { |
47f5e069 AV |
7205 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) }, |
7206 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) }, | |
7207 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) }, | |
7208 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) }, | |
7209 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) }, | |
7210 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) }, | |
7211 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) }, | |
7212 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) }, | |
7213 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) }, | |
4d4df193 | 7214 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) }, |
47f5e069 AV |
7215 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) }, |
7216 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) }, | |
c3a2f0df | 7217 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) }, |
6246b8a1 | 7218 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) }, |
3a03eb79 | 7219 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) }, |
a9083016 | 7220 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) }, |
650f528f | 7221 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) }, |
8ae6d9c7 | 7222 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) }, |
7ec0effd | 7223 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) }, |
f73cb695 | 7224 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) }, |
2c5bbbb2 | 7225 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) }, |
2b48992f | 7226 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) }, |
ecc89f25 JC |
7227 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) }, |
7228 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) }, | |
7229 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) }, | |
7230 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) }, | |
7231 | { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) }, | |
5433383e AV |
7232 | { 0 }, |
7233 | }; | |
7234 | MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl); | |
7235 | ||
fca29703 | 7236 | static struct pci_driver qla2xxx_pci_driver = { |
cb63067a | 7237 | .name = QLA2XXX_DRIVER_NAME, |
0a21ef1e JB |
7238 | .driver = { |
7239 | .owner = THIS_MODULE, | |
7240 | }, | |
fca29703 | 7241 | .id_table = qla2xxx_pci_tbl, |
7ee61397 | 7242 | .probe = qla2x00_probe_one, |
4c993f76 | 7243 | .remove = qla2x00_remove_one, |
e30d1756 | 7244 | .shutdown = qla2x00_shutdown, |
14e660e6 | 7245 | .err_handler = &qla2xxx_err_handler, |
fca29703 AV |
7246 | }; |
7247 | ||
75ef9de1 | 7248 | static const struct file_operations apidev_fops = { |
6a03b4cd | 7249 | .owner = THIS_MODULE, |
6038f373 | 7250 | .llseek = noop_llseek, |
6a03b4cd HZ |
7251 | }; |
7252 | ||
1da177e4 LT |
7253 | /** |
7254 | * qla2x00_module_init - Module initialization. | |
7255 | **/ | |
7256 | static int __init | |
7257 | qla2x00_module_init(void) | |
7258 | { | |
fca29703 AV |
7259 | int ret = 0; |
7260 | ||
bc04459c BVA |
7261 | BUILD_BUG_ON(sizeof(cmd_entry_t) != 64); |
7262 | BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64); | |
7263 | BUILD_BUG_ON(sizeof(cont_entry_t) != 64); | |
7264 | BUILD_BUG_ON(sizeof(init_cb_t) != 96); | |
7265 | BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64); | |
7266 | BUILD_BUG_ON(sizeof(request_t) != 64); | |
7267 | BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64); | |
7268 | BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64); | |
7269 | BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64); | |
7270 | BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64); | |
7271 | BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64); | |
7272 | BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64); | |
7273 | BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64); | |
7274 | BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64); | |
7275 | BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64); | |
7276 | BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64); | |
7277 | BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64); | |
7278 | BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128); | |
7279 | BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128); | |
7280 | BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64); | |
7281 | BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064); | |
7282 | BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64); | |
7283 | BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56); | |
7284 | ||
1da177e4 | 7285 | /* Allocate cache for SRBs. */ |
354d6b21 | 7286 | srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0, |
20c2df83 | 7287 | SLAB_HWCACHE_ALIGN, NULL); |
1da177e4 | 7288 | if (srb_cachep == NULL) { |
7c3df132 SK |
7289 | ql_log(ql_log_fatal, NULL, 0x0001, |
7290 | "Unable to allocate SRB cache...Failing load!.\n"); | |
1da177e4 LT |
7291 | return -ENOMEM; |
7292 | } | |
7293 | ||
2d70c103 NB |
7294 | /* Initialize target kmem_cache and mem_pools */ |
7295 | ret = qlt_init(); | |
7296 | if (ret < 0) { | |
c794d24e | 7297 | goto destroy_cache; |
2d70c103 NB |
7298 | } else if (ret > 0) { |
7299 | /* | |
7300 | * If initiator mode is explictly disabled by qlt_init(), | |
7301 | * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from | |
7302 | * performing scsi_scan_target() during LOOP UP event. | |
7303 | */ | |
7304 | qla2xxx_transport_functions.disable_target_scan = 1; | |
7305 | qla2xxx_transport_vport_functions.disable_target_scan = 1; | |
7306 | } | |
7307 | ||
1da177e4 LT |
7308 | /* Derive version string. */ |
7309 | strcpy(qla2x00_version_str, QLA2XXX_VERSION); | |
11010fec | 7310 | if (ql2xextended_error_logging) |
0181944f | 7311 | strcat(qla2x00_version_str, "-debug"); |
fed0f68a JC |
7312 | if (ql2xextended_error_logging == 1) |
7313 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; | |
0181944f | 7314 | |
0645cb83 QT |
7315 | if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL) |
7316 | qla_insert_tgt_attrs(); | |
7317 | ||
1c97a12a AV |
7318 | qla2xxx_transport_template = |
7319 | fc_attach_transport(&qla2xxx_transport_functions); | |
2c3dfe3f | 7320 | if (!qla2xxx_transport_template) { |
7c3df132 SK |
7321 | ql_log(ql_log_fatal, NULL, 0x0002, |
7322 | "fc_attach_transport failed...Failing load!.\n"); | |
c794d24e BVA |
7323 | ret = -ENODEV; |
7324 | goto qlt_exit; | |
2c3dfe3f | 7325 | } |
6a03b4cd HZ |
7326 | |
7327 | apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops); | |
7328 | if (apidev_major < 0) { | |
7c3df132 SK |
7329 | ql_log(ql_log_fatal, NULL, 0x0003, |
7330 | "Unable to register char device %s.\n", QLA2XXX_APIDEV); | |
6a03b4cd HZ |
7331 | } |
7332 | ||
2c3dfe3f SJ |
7333 | qla2xxx_transport_vport_template = |
7334 | fc_attach_transport(&qla2xxx_transport_vport_functions); | |
7335 | if (!qla2xxx_transport_vport_template) { | |
7c3df132 SK |
7336 | ql_log(ql_log_fatal, NULL, 0x0004, |
7337 | "fc_attach_transport vport failed...Failing load!.\n"); | |
c794d24e BVA |
7338 | ret = -ENODEV; |
7339 | goto unreg_chrdev; | |
2c3dfe3f | 7340 | } |
7c3df132 SK |
7341 | ql_log(ql_log_info, NULL, 0x0005, |
7342 | "QLogic Fibre Channel HBA Driver: %s.\n", | |
fd9a29f0 | 7343 | qla2x00_version_str); |
7ee61397 | 7344 | ret = pci_register_driver(&qla2xxx_pci_driver); |
fca29703 | 7345 | if (ret) { |
7c3df132 SK |
7346 | ql_log(ql_log_fatal, NULL, 0x0006, |
7347 | "pci_register_driver failed...ret=%d Failing load!.\n", | |
7348 | ret); | |
c794d24e | 7349 | goto release_vport_transport; |
fca29703 AV |
7350 | } |
7351 | return ret; | |
c794d24e BVA |
7352 | |
7353 | release_vport_transport: | |
7354 | fc_release_transport(qla2xxx_transport_vport_template); | |
7355 | ||
7356 | unreg_chrdev: | |
7357 | if (apidev_major >= 0) | |
7358 | unregister_chrdev(apidev_major, QLA2XXX_APIDEV); | |
7359 | fc_release_transport(qla2xxx_transport_template); | |
7360 | ||
7361 | qlt_exit: | |
7362 | qlt_exit(); | |
7363 | ||
7364 | destroy_cache: | |
7365 | kmem_cache_destroy(srb_cachep); | |
7366 | return ret; | |
1da177e4 LT |
7367 | } |
7368 | ||
7369 | /** | |
7370 | * qla2x00_module_exit - Module cleanup. | |
7371 | **/ | |
7372 | static void __exit | |
7373 | qla2x00_module_exit(void) | |
7374 | { | |
7ee61397 | 7375 | pci_unregister_driver(&qla2xxx_pci_driver); |
5433383e | 7376 | qla2x00_release_firmware(); |
75c1d48a | 7377 | kmem_cache_destroy(ctx_cachep); |
2c3dfe3f | 7378 | fc_release_transport(qla2xxx_transport_vport_template); |
59c209a6 BVA |
7379 | if (apidev_major >= 0) |
7380 | unregister_chrdev(apidev_major, QLA2XXX_APIDEV); | |
7381 | fc_release_transport(qla2xxx_transport_template); | |
7382 | qlt_exit(); | |
7383 | kmem_cache_destroy(srb_cachep); | |
1da177e4 LT |
7384 | } |
7385 | ||
7386 | module_init(qla2x00_module_init); | |
7387 | module_exit(qla2x00_module_exit); | |
7388 | ||
7389 | MODULE_AUTHOR("QLogic Corporation"); | |
7390 | MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver"); | |
7391 | MODULE_LICENSE("GPL"); | |
7392 | MODULE_VERSION(QLA2XXX_VERSION); | |
bb8ee499 AV |
7393 | MODULE_FIRMWARE(FW_FILE_ISP21XX); |
7394 | MODULE_FIRMWARE(FW_FILE_ISP22XX); | |
7395 | MODULE_FIRMWARE(FW_FILE_ISP2300); | |
7396 | MODULE_FIRMWARE(FW_FILE_ISP2322); | |
7397 | MODULE_FIRMWARE(FW_FILE_ISP24XX); | |
61623fc3 | 7398 | MODULE_FIRMWARE(FW_FILE_ISP25XX); |