]>
Commit | Line | Data |
---|---|---|
2c3dfe3f | 1 | /* |
01e58d8e AV |
2 | * QLogic Fibre Channel HBA Driver |
3 | * Copyright (c) 2003-2008 QLogic Corporation | |
2c3dfe3f | 4 | * |
01e58d8e | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
2c3dfe3f SJ |
6 | */ |
7 | #include "qla_def.h" | |
7b867cf7 | 8 | #include "qla_gbl.h" |
2c3dfe3f | 9 | |
2c3dfe3f SJ |
10 | #include <linux/moduleparam.h> |
11 | #include <linux/vmalloc.h> | |
12 | #include <linux/smp_lock.h> | |
13 | #include <linux/list.h> | |
14 | ||
15 | #include <scsi/scsi_tcq.h> | |
16 | #include <scsi/scsicam.h> | |
17 | #include <linux/delay.h> | |
18 | ||
2c3dfe3f SJ |
19 | void |
20 | qla2x00_vp_stop_timer(scsi_qla_host_t *vha) | |
21 | { | |
7b867cf7 | 22 | if (vha->vp_idx && vha->timer_active) { |
2c3dfe3f SJ |
23 | del_timer_sync(&vha->timer); |
24 | vha->timer_active = 0; | |
25 | } | |
26 | } | |
27 | ||
a824ebb3 | 28 | static uint32_t |
2c3dfe3f SJ |
29 | qla24xx_allocate_vp_id(scsi_qla_host_t *vha) |
30 | { | |
31 | uint32_t vp_id; | |
7b867cf7 | 32 | struct qla_hw_data *ha = vha->hw; |
2c3dfe3f SJ |
33 | |
34 | /* Find an empty slot and assign an vp_id */ | |
6c2f527c | 35 | mutex_lock(&ha->vport_lock); |
eb66dc60 AV |
36 | vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1); |
37 | if (vp_id > ha->max_npiv_vports) { | |
38 | DEBUG15(printk ("vp_id %d is bigger than max-supported %d.\n", | |
39 | vp_id, ha->max_npiv_vports)); | |
6c2f527c | 40 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
41 | return vp_id; |
42 | } | |
43 | ||
eb66dc60 | 44 | set_bit(vp_id, ha->vp_idx_map); |
2c3dfe3f | 45 | ha->num_vhosts++; |
711c1d91 | 46 | ha->cur_vport_count++; |
2c3dfe3f | 47 | vha->vp_idx = vp_id; |
7b867cf7 | 48 | list_add_tail(&vha->list, &ha->vp_list); |
6c2f527c | 49 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
50 | return vp_id; |
51 | } | |
52 | ||
53 | void | |
54 | qla24xx_deallocate_vp_id(scsi_qla_host_t *vha) | |
55 | { | |
56 | uint16_t vp_id; | |
7b867cf7 | 57 | struct qla_hw_data *ha = vha->hw; |
2c3dfe3f | 58 | |
6c2f527c | 59 | mutex_lock(&ha->vport_lock); |
2c3dfe3f SJ |
60 | vp_id = vha->vp_idx; |
61 | ha->num_vhosts--; | |
711c1d91 | 62 | ha->cur_vport_count--; |
eb66dc60 | 63 | clear_bit(vp_id, ha->vp_idx_map); |
7b867cf7 | 64 | list_del(&vha->list); |
6c2f527c | 65 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
66 | } |
67 | ||
a824ebb3 | 68 | static scsi_qla_host_t * |
7b867cf7 | 69 | qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name) |
2c3dfe3f SJ |
70 | { |
71 | scsi_qla_host_t *vha; | |
72 | ||
73 | /* Locate matching device in database. */ | |
7b867cf7 | 74 | list_for_each_entry(vha, &ha->vp_list, list) { |
2c3dfe3f SJ |
75 | if (!memcmp(port_name, vha->port_name, WWN_SIZE)) |
76 | return vha; | |
77 | } | |
78 | return NULL; | |
79 | } | |
80 | ||
81 | /* | |
82 | * qla2x00_mark_vp_devices_dead | |
83 | * Updates fcport state when device goes offline. | |
84 | * | |
85 | * Input: | |
86 | * ha = adapter block pointer. | |
87 | * fcport = port structure pointer. | |
88 | * | |
89 | * Return: | |
90 | * None. | |
91 | * | |
92 | * Context: | |
93 | */ | |
26ff776d | 94 | static void |
2c3dfe3f SJ |
95 | qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha) |
96 | { | |
97 | fc_port_t *fcport; | |
2c3dfe3f | 98 | |
7b867cf7 | 99 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
2c3dfe3f SJ |
100 | DEBUG15(printk("scsi(%ld): Marking port dead, " |
101 | "loop_id=0x%04x :%x\n", | |
102 | vha->host_no, fcport->loop_id, fcport->vp_idx)); | |
103 | ||
2c3dfe3f | 104 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
c9c5ced9 | 105 | atomic_set(&fcport->state, FCS_UNCONFIGURED); |
2c3dfe3f SJ |
106 | } |
107 | } | |
108 | ||
109 | int | |
110 | qla24xx_disable_vp(scsi_qla_host_t *vha) | |
111 | { | |
112 | int ret; | |
113 | ||
114 | ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); | |
115 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
116 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
117 | ||
2c3dfe3f SJ |
118 | qla2x00_mark_vp_devices_dead(vha); |
119 | atomic_set(&vha->vp_state, VP_FAILED); | |
120 | vha->flags.management_server_logged_in = 0; | |
121 | if (ret == QLA_SUCCESS) { | |
122 | fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED); | |
123 | } else { | |
124 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
125 | return -1; | |
126 | } | |
127 | return 0; | |
128 | } | |
129 | ||
130 | int | |
131 | qla24xx_enable_vp(scsi_qla_host_t *vha) | |
132 | { | |
133 | int ret; | |
7b867cf7 AC |
134 | struct qla_hw_data *ha = vha->hw; |
135 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
2c3dfe3f SJ |
136 | |
137 | /* Check if physical ha port is Up */ | |
7b867cf7 AC |
138 | if (atomic_read(&base_vha->loop_state) == LOOP_DOWN || |
139 | atomic_read(&base_vha->loop_state) == LOOP_DEAD) { | |
2c3dfe3f SJ |
140 | vha->vp_err_state = VP_ERR_PORTDWN; |
141 | fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN); | |
142 | goto enable_failed; | |
143 | } | |
144 | ||
145 | /* Initialize the new vport unless it is a persistent port */ | |
6c2f527c | 146 | mutex_lock(&ha->vport_lock); |
2c3dfe3f | 147 | ret = qla24xx_modify_vp_config(vha); |
6c2f527c | 148 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
149 | |
150 | if (ret != QLA_SUCCESS) { | |
151 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
152 | goto enable_failed; | |
153 | } | |
154 | ||
155 | DEBUG15(qla_printk(KERN_INFO, ha, | |
156 | "Virtual port with id: %d - Enabled\n", vha->vp_idx)); | |
157 | return 0; | |
158 | ||
159 | enable_failed: | |
160 | DEBUG15(qla_printk(KERN_INFO, ha, | |
161 | "Virtual port with id: %d - Disabled\n", vha->vp_idx)); | |
162 | return 1; | |
163 | } | |
164 | ||
26ff776d | 165 | static void |
2c3dfe3f SJ |
166 | qla24xx_configure_vp(scsi_qla_host_t *vha) |
167 | { | |
168 | struct fc_vport *fc_vport; | |
169 | int ret; | |
170 | ||
171 | fc_vport = vha->fc_vport; | |
172 | ||
173 | DEBUG15(printk("scsi(%ld): %s: change request #3 for this host.\n", | |
174 | vha->host_no, __func__)); | |
175 | ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx); | |
176 | if (ret != QLA_SUCCESS) { | |
7b867cf7 AC |
177 | DEBUG15(qla_printk(KERN_ERR, vha->hw, "Failed to enable " |
178 | "receiving of RSCN requests: 0x%x\n", ret)); | |
2c3dfe3f SJ |
179 | return; |
180 | } else { | |
181 | /* Corresponds to SCR enabled */ | |
182 | clear_bit(VP_SCR_NEEDED, &vha->vp_flags); | |
183 | } | |
184 | ||
185 | vha->flags.online = 1; | |
186 | if (qla24xx_configure_vhba(vha)) | |
187 | return; | |
188 | ||
189 | atomic_set(&vha->vp_state, VP_ACTIVE); | |
190 | fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); | |
191 | } | |
192 | ||
193 | void | |
7b867cf7 | 194 | qla2x00_alert_all_vps(struct qla_hw_data *ha, uint16_t *mb) |
2c3dfe3f | 195 | { |
2c3dfe3f | 196 | scsi_qla_host_t *vha; |
7b867cf7 | 197 | int i = 0; |
2c3dfe3f | 198 | |
7b867cf7 AC |
199 | list_for_each_entry(vha, &ha->vp_list, list) { |
200 | if (vha->vp_idx) { | |
2c3dfe3f SJ |
201 | switch (mb[0]) { |
202 | case MBA_LIP_OCCURRED: | |
203 | case MBA_LOOP_UP: | |
204 | case MBA_LOOP_DOWN: | |
205 | case MBA_LIP_RESET: | |
206 | case MBA_POINT_TO_POINT: | |
207 | case MBA_CHG_IN_CONNECTION: | |
208 | case MBA_PORT_UPDATE: | |
209 | case MBA_RSCN_UPDATE: | |
210 | DEBUG15(printk("scsi(%ld)%s: Async_event for" | |
7b867cf7 AC |
211 | " VP[%d], mb = 0x%x, vha=%p\n", |
212 | vha->host_no, __func__, i, *mb, vha)); | |
2c3dfe3f SJ |
213 | qla2x00_async_event(vha, mb); |
214 | break; | |
215 | } | |
216 | } | |
7b867cf7 | 217 | i++; |
2c3dfe3f SJ |
218 | } |
219 | } | |
220 | ||
7b867cf7 | 221 | int |
2c3dfe3f SJ |
222 | qla2x00_vp_abort_isp(scsi_qla_host_t *vha) |
223 | { | |
224 | /* | |
225 | * Physical port will do most of the abort and recovery work. We can | |
226 | * just treat it as a loop down | |
227 | */ | |
228 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { | |
229 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
230 | qla2x00_mark_all_devices_lost(vha, 0); | |
231 | } else { | |
232 | if (!atomic_read(&vha->loop_down_timer)) | |
233 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
234 | } | |
235 | ||
7b867cf7 AC |
236 | /* To exclusively reset vport, we need to log it out first.*/ |
237 | if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) | |
238 | qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); | |
239 | ||
2c3dfe3f SJ |
240 | DEBUG15(printk("scsi(%ld): Scheduling enable of Vport %d...\n", |
241 | vha->host_no, vha->vp_idx)); | |
7b867cf7 | 242 | return qla24xx_enable_vp(vha); |
2c3dfe3f SJ |
243 | } |
244 | ||
a824ebb3 | 245 | static int |
2c3dfe3f SJ |
246 | qla2x00_do_dpc_vp(scsi_qla_host_t *vha) |
247 | { | |
7b867cf7 AC |
248 | struct qla_hw_data *ha = vha->hw; |
249 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
221726d4 | 250 | |
2c3dfe3f SJ |
251 | if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) { |
252 | /* VP acquired. complete port configuration */ | |
7b867cf7 | 253 | if (atomic_read(&base_vha->loop_state) == LOOP_READY) { |
221726d4 SJ |
254 | qla24xx_configure_vp(vha); |
255 | } else { | |
256 | set_bit(VP_IDX_ACQUIRED, &vha->vp_flags); | |
7b867cf7 | 257 | set_bit(VP_DPC_NEEDED, &base_vha->dpc_flags); |
221726d4 SJ |
258 | } |
259 | ||
2c3dfe3f SJ |
260 | return 0; |
261 | } | |
262 | ||
7b867cf7 AC |
263 | if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) { |
264 | qla2x00_update_fcports(vha); | |
265 | clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags); | |
266 | } | |
267 | ||
268 | if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) && | |
269 | !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) && | |
270 | atomic_read(&vha->loop_state) != LOOP_DOWN) { | |
271 | ||
272 | DEBUG(printk("scsi(%ld): qla2x00_port_login()\n", | |
273 | vha->host_no)); | |
274 | qla2x00_relogin(vha); | |
275 | ||
276 | DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n", | |
277 | vha->host_no)); | |
278 | } | |
2c3dfe3f SJ |
279 | |
280 | if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) && | |
281 | (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) { | |
282 | clear_bit(RESET_ACTIVE, &vha->dpc_flags); | |
283 | } | |
284 | ||
5de1f70f SJ |
285 | if (atomic_read(&vha->vp_state) == VP_ACTIVE && |
286 | test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { | |
2c3dfe3f SJ |
287 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) { |
288 | qla2x00_loop_resync(vha); | |
289 | clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags); | |
290 | } | |
291 | } | |
292 | ||
293 | return 0; | |
294 | } | |
295 | ||
296 | void | |
7b867cf7 | 297 | qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha) |
2c3dfe3f SJ |
298 | { |
299 | int ret; | |
7b867cf7 AC |
300 | struct qla_hw_data *ha = vha->hw; |
301 | scsi_qla_host_t *vp; | |
2c3dfe3f | 302 | |
7b867cf7 | 303 | if (vha->vp_idx) |
2c3dfe3f SJ |
304 | return; |
305 | if (list_empty(&ha->vp_list)) | |
306 | return; | |
307 | ||
7b867cf7 | 308 | clear_bit(VP_DPC_NEEDED, &vha->dpc_flags); |
2c3dfe3f | 309 | |
7b867cf7 AC |
310 | list_for_each_entry(vp, &ha->vp_list, list) { |
311 | if (vp->vp_idx) | |
312 | ret = qla2x00_do_dpc_vp(vp); | |
2c3dfe3f SJ |
313 | } |
314 | } | |
315 | ||
316 | int | |
317 | qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport) | |
318 | { | |
7b867cf7 AC |
319 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
320 | struct qla_hw_data *ha = base_vha->hw; | |
2c3dfe3f SJ |
321 | scsi_qla_host_t *vha; |
322 | uint8_t port_name[WWN_SIZE]; | |
323 | ||
324 | if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR) | |
325 | return VPCERR_UNSUPPORTED; | |
326 | ||
327 | /* Check up the F/W and H/W support NPIV */ | |
328 | if (!ha->flags.npiv_supported) | |
329 | return VPCERR_UNSUPPORTED; | |
330 | ||
331 | /* Check up whether npiv supported switch presented */ | |
332 | if (!(ha->switch_cap & FLOGI_MID_SUPPORT)) | |
333 | return VPCERR_NO_FABRIC_SUPP; | |
334 | ||
335 | /* Check up unique WWPN */ | |
336 | u64_to_wwn(fc_vport->port_name, port_name); | |
7b867cf7 | 337 | if (!memcmp(port_name, base_vha->port_name, WWN_SIZE)) |
50db6b13 | 338 | return VPCERR_BAD_WWN; |
2c3dfe3f SJ |
339 | vha = qla24xx_find_vhost_by_name(ha, port_name); |
340 | if (vha) | |
341 | return VPCERR_BAD_WWN; | |
342 | ||
343 | /* Check up max-npiv-supports */ | |
344 | if (ha->num_vhosts > ha->max_npiv_vports) { | |
eb66dc60 | 345 | DEBUG15(printk("scsi(%ld): num_vhosts %ud is bigger than " |
7b867cf7 | 346 | "max_npv_vports %ud.\n", base_vha->host_no, |
eb66dc60 | 347 | ha->num_vhosts, ha->max_npiv_vports)); |
2c3dfe3f SJ |
348 | return VPCERR_UNSUPPORTED; |
349 | } | |
350 | return 0; | |
351 | } | |
352 | ||
353 | scsi_qla_host_t * | |
354 | qla24xx_create_vhost(struct fc_vport *fc_vport) | |
355 | { | |
7b867cf7 AC |
356 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
357 | struct qla_hw_data *ha = base_vha->hw; | |
2c3dfe3f | 358 | scsi_qla_host_t *vha; |
7b867cf7 | 359 | struct scsi_host_template *sht = &qla24xx_driver_template; |
2c3dfe3f SJ |
360 | struct Scsi_Host *host; |
361 | ||
7b867cf7 AC |
362 | vha = qla2x00_create_host(sht, ha); |
363 | if (!vha) { | |
364 | DEBUG(printk("qla2xxx: scsi_host_alloc() failed for vport\n")); | |
2c3dfe3f SJ |
365 | return(NULL); |
366 | } | |
367 | ||
7b867cf7 | 368 | host = vha->host; |
2c3dfe3f SJ |
369 | fc_vport->dd_data = vha; |
370 | ||
2c3dfe3f SJ |
371 | /* New host info */ |
372 | u64_to_wwn(fc_vport->node_name, vha->node_name); | |
373 | u64_to_wwn(fc_vport->port_name, vha->port_name); | |
374 | ||
2c3dfe3f SJ |
375 | vha->fc_vport = fc_vport; |
376 | vha->device_flags = 0; | |
2c3dfe3f SJ |
377 | vha->vp_idx = qla24xx_allocate_vp_id(vha); |
378 | if (vha->vp_idx > ha->max_npiv_vports) { | |
379 | DEBUG15(printk("scsi(%ld): Couldn't allocate vp_id.\n", | |
380 | vha->host_no)); | |
7b867cf7 | 381 | goto create_vhost_failed; |
2c3dfe3f SJ |
382 | } |
383 | vha->mgmt_svr_loop_id = 10 + vha->vp_idx; | |
384 | ||
2c3dfe3f SJ |
385 | vha->dpc_flags = 0L; |
386 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); | |
387 | set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); | |
388 | ||
389 | /* | |
390 | * To fix the issue of processing a parent's RSCN for the vport before | |
391 | * its SCR is complete. | |
392 | */ | |
393 | set_bit(VP_SCR_NEEDED, &vha->vp_flags); | |
394 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
395 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
396 | ||
397 | qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL); | |
398 | ||
7b867cf7 | 399 | host->can_queue = ha->req->length + 128; |
2c3dfe3f SJ |
400 | host->this_id = 255; |
401 | host->cmd_per_lun = 3; | |
402 | host->max_cmd_len = MAX_CMDSZ; | |
403 | host->max_channel = MAX_BUSES - 1; | |
404 | host->max_lun = MAX_LUNS; | |
711c1d91 | 405 | host->unique_id = host->host_no; |
2c3dfe3f SJ |
406 | host->max_id = MAX_TARGETS_2200; |
407 | host->transportt = qla2xxx_transport_vport_template; | |
408 | ||
409 | DEBUG15(printk("DEBUG: detect vport hba %ld at address = %p\n", | |
410 | vha->host_no, vha)); | |
411 | ||
412 | vha->flags.init_done = 1; | |
2c3dfe3f SJ |
413 | |
414 | return vha; | |
415 | ||
7b867cf7 | 416 | create_vhost_failed: |
2c3dfe3f SJ |
417 | return NULL; |
418 | } |