aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/qla2xxx/qla_mid.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/qla2xxx/qla_mid.c')
-rw-r--r--drivers/scsi/qla2xxx/qla_mid.c516
1 files changed, 410 insertions, 106 deletions
diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index 93560cd72784..386ffeae5b5a 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -5,6 +5,7 @@
5 * See LICENSE.qla2xxx for copyright and licensing details. 5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */ 6 */
7#include "qla_def.h" 7#include "qla_def.h"
8#include "qla_gbl.h"
8 9
9#include <linux/moduleparam.h> 10#include <linux/moduleparam.h>
10#include <linux/vmalloc.h> 11#include <linux/vmalloc.h>
@@ -18,7 +19,7 @@
18void 19void
19qla2x00_vp_stop_timer(scsi_qla_host_t *vha) 20qla2x00_vp_stop_timer(scsi_qla_host_t *vha)
20{ 21{
21 if (vha->parent && vha->timer_active) { 22 if (vha->vp_idx && vha->timer_active) {
22 del_timer_sync(&vha->timer); 23 del_timer_sync(&vha->timer);
23 vha->timer_active = 0; 24 vha->timer_active = 0;
24 } 25 }
@@ -28,7 +29,7 @@ static uint32_t
28qla24xx_allocate_vp_id(scsi_qla_host_t *vha) 29qla24xx_allocate_vp_id(scsi_qla_host_t *vha)
29{ 30{
30 uint32_t vp_id; 31 uint32_t vp_id;
31 scsi_qla_host_t *ha = vha->parent; 32 struct qla_hw_data *ha = vha->hw;
32 33
33 /* Find an empty slot and assign an vp_id */ 34 /* Find an empty slot and assign an vp_id */
34 mutex_lock(&ha->vport_lock); 35 mutex_lock(&ha->vport_lock);
@@ -44,7 +45,7 @@ qla24xx_allocate_vp_id(scsi_qla_host_t *vha)
44 ha->num_vhosts++; 45 ha->num_vhosts++;
45 ha->cur_vport_count++; 46 ha->cur_vport_count++;
46 vha->vp_idx = vp_id; 47 vha->vp_idx = vp_id;
47 list_add_tail(&vha->vp_list, &ha->vp_list); 48 list_add_tail(&vha->list, &ha->vp_list);
48 mutex_unlock(&ha->vport_lock); 49 mutex_unlock(&ha->vport_lock);
49 return vp_id; 50 return vp_id;
50} 51}
@@ -53,24 +54,24 @@ void
53qla24xx_deallocate_vp_id(scsi_qla_host_t *vha) 54qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
54{ 55{
55 uint16_t vp_id; 56 uint16_t vp_id;
56 scsi_qla_host_t *ha = vha->parent; 57 struct qla_hw_data *ha = vha->hw;
57 58
58 mutex_lock(&ha->vport_lock); 59 mutex_lock(&ha->vport_lock);
59 vp_id = vha->vp_idx; 60 vp_id = vha->vp_idx;
60 ha->num_vhosts--; 61 ha->num_vhosts--;
61 ha->cur_vport_count--; 62 ha->cur_vport_count--;
62 clear_bit(vp_id, ha->vp_idx_map); 63 clear_bit(vp_id, ha->vp_idx_map);
63 list_del(&vha->vp_list); 64 list_del(&vha->list);
64 mutex_unlock(&ha->vport_lock); 65 mutex_unlock(&ha->vport_lock);
65} 66}
66 67
67static scsi_qla_host_t * 68static scsi_qla_host_t *
68qla24xx_find_vhost_by_name(scsi_qla_host_t *ha, uint8_t *port_name) 69qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name)
69{ 70{
70 scsi_qla_host_t *vha; 71 scsi_qla_host_t *vha;
71 72
72 /* Locate matching device in database. */ 73 /* Locate matching device in database. */
73 list_for_each_entry(vha, &ha->vp_list, vp_list) { 74 list_for_each_entry(vha, &ha->vp_list, list) {
74 if (!memcmp(port_name, vha->port_name, WWN_SIZE)) 75 if (!memcmp(port_name, vha->port_name, WWN_SIZE))
75 return vha; 76 return vha;
76 } 77 }
@@ -94,16 +95,13 @@ static void
94qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha) 95qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha)
95{ 96{
96 fc_port_t *fcport; 97 fc_port_t *fcport;
97 scsi_qla_host_t *pha = to_qla_parent(vha);
98
99 list_for_each_entry(fcport, &pha->fcports, list) {
100 if (fcport->vp_idx != vha->vp_idx)
101 continue;
102 98
99 list_for_each_entry(fcport, &vha->vp_fcports, list) {
103 DEBUG15(printk("scsi(%ld): Marking port dead, " 100 DEBUG15(printk("scsi(%ld): Marking port dead, "
104 "loop_id=0x%04x :%x\n", 101 "loop_id=0x%04x :%x\n",
105 vha->host_no, fcport->loop_id, fcport->vp_idx)); 102 vha->host_no, fcport->loop_id, fcport->vp_idx));
106 103
104 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
107 qla2x00_mark_device_lost(vha, fcport, 0, 0); 105 qla2x00_mark_device_lost(vha, fcport, 0, 0);
108 atomic_set(&fcport->state, FCS_UNCONFIGURED); 106 atomic_set(&fcport->state, FCS_UNCONFIGURED);
109 } 107 }
@@ -118,7 +116,6 @@ qla24xx_disable_vp(scsi_qla_host_t *vha)
118 atomic_set(&vha->loop_state, LOOP_DOWN); 116 atomic_set(&vha->loop_state, LOOP_DOWN);
119 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); 117 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
120 118
121 /* Delete all vp's fcports from parent's list */
122 qla2x00_mark_vp_devices_dead(vha); 119 qla2x00_mark_vp_devices_dead(vha);
123 atomic_set(&vha->vp_state, VP_FAILED); 120 atomic_set(&vha->vp_state, VP_FAILED);
124 vha->flags.management_server_logged_in = 0; 121 vha->flags.management_server_logged_in = 0;
@@ -135,11 +132,12 @@ int
135qla24xx_enable_vp(scsi_qla_host_t *vha) 132qla24xx_enable_vp(scsi_qla_host_t *vha)
136{ 133{
137 int ret; 134 int ret;
138 scsi_qla_host_t *ha = vha->parent; 135 struct qla_hw_data *ha = vha->hw;
136 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
139 137
140 /* Check if physical ha port is Up */ 138 /* Check if physical ha port is Up */
141 if (atomic_read(&ha->loop_state) == LOOP_DOWN || 139 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
142 atomic_read(&ha->loop_state) == LOOP_DEAD ) { 140 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
143 vha->vp_err_state = VP_ERR_PORTDWN; 141 vha->vp_err_state = VP_ERR_PORTDWN;
144 fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN); 142 fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN);
145 goto enable_failed; 143 goto enable_failed;
@@ -177,8 +175,8 @@ qla24xx_configure_vp(scsi_qla_host_t *vha)
177 vha->host_no, __func__)); 175 vha->host_no, __func__));
178 ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx); 176 ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx);
179 if (ret != QLA_SUCCESS) { 177 if (ret != QLA_SUCCESS) {
180 DEBUG15(qla_printk(KERN_ERR, vha, "Failed to enable receiving" 178 DEBUG15(qla_printk(KERN_ERR, vha->hw, "Failed to enable "
181 " of RSCN requests: 0x%x\n", ret)); 179 "receiving of RSCN requests: 0x%x\n", ret));
182 return; 180 return;
183 } else { 181 } else {
184 /* Corresponds to SCR enabled */ 182 /* Corresponds to SCR enabled */
@@ -194,25 +192,14 @@ qla24xx_configure_vp(scsi_qla_host_t *vha)
194} 192}
195 193
196void 194void
197qla2x00_alert_all_vps(scsi_qla_host_t *ha, uint16_t *mb) 195qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
198{ 196{
199 int i, vp_idx_matched;
200 scsi_qla_host_t *vha; 197 scsi_qla_host_t *vha;
198 struct qla_hw_data *ha = rsp->hw;
199 int i = 0;
201 200
202 if (ha->parent) 201 list_for_each_entry(vha, &ha->vp_list, list) {
203 return; 202 if (vha->vp_idx) {
204
205 for_each_mapped_vp_idx(ha, i) {
206 vp_idx_matched = 0;
207
208 list_for_each_entry(vha, &ha->vp_list, vp_list) {
209 if (i == vha->vp_idx) {
210 vp_idx_matched = 1;
211 break;
212 }
213 }
214
215 if (vp_idx_matched) {
216 switch (mb[0]) { 203 switch (mb[0]) {
217 case MBA_LIP_OCCURRED: 204 case MBA_LIP_OCCURRED:
218 case MBA_LOOP_UP: 205 case MBA_LOOP_UP:
@@ -223,16 +210,17 @@ qla2x00_alert_all_vps(scsi_qla_host_t *ha, uint16_t *mb)
223 case MBA_PORT_UPDATE: 210 case MBA_PORT_UPDATE:
224 case MBA_RSCN_UPDATE: 211 case MBA_RSCN_UPDATE:
225 DEBUG15(printk("scsi(%ld)%s: Async_event for" 212 DEBUG15(printk("scsi(%ld)%s: Async_event for"
226 " VP[%d], mb = 0x%x, vha=%p\n", 213 " VP[%d], mb = 0x%x, vha=%p\n",
227 vha->host_no, __func__,i, *mb, vha)); 214 vha->host_no, __func__, i, *mb, vha));
228 qla2x00_async_event(vha, mb); 215 qla2x00_async_event(vha, rsp, mb);
229 break; 216 break;
230 } 217 }
231 } 218 }
219 i++;
232 } 220 }
233} 221}
234 222
235void 223int
236qla2x00_vp_abort_isp(scsi_qla_host_t *vha) 224qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
237{ 225{
238 /* 226 /*
@@ -247,38 +235,56 @@ qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
247 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); 235 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
248 } 236 }
249 237
238 /* To exclusively reset vport, we need to log it out first.*/
239 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
240 qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
241
250 DEBUG15(printk("scsi(%ld): Scheduling enable of Vport %d...\n", 242 DEBUG15(printk("scsi(%ld): Scheduling enable of Vport %d...\n",
251 vha->host_no, vha->vp_idx)); 243 vha->host_no, vha->vp_idx));
252 qla24xx_enable_vp(vha); 244 return qla24xx_enable_vp(vha);
253} 245}
254 246
255static int 247static int
256qla2x00_do_dpc_vp(scsi_qla_host_t *vha) 248qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
257{ 249{
258 scsi_qla_host_t *ha = vha->parent; 250 struct qla_hw_data *ha = vha->hw;
251 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
259 252
260 if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) { 253 if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) {
261 /* VP acquired. complete port configuration */ 254 /* VP acquired. complete port configuration */
262 if (atomic_read(&ha->loop_state) == LOOP_READY) { 255 if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
263 qla24xx_configure_vp(vha); 256 qla24xx_configure_vp(vha);
264 } else { 257 } else {
265 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags); 258 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
266 set_bit(VP_DPC_NEEDED, &ha->dpc_flags); 259 set_bit(VP_DPC_NEEDED, &base_vha->dpc_flags);
267 } 260 }
268 261
269 return 0; 262 return 0;
270 } 263 }
271 264
272 if (test_and_clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) 265 if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) {
273 qla2x00_vp_abort_isp(vha); 266 qla2x00_update_fcports(vha);
267 clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
268 }
269
270 if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) &&
271 !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) &&
272 atomic_read(&vha->loop_state) != LOOP_DOWN) {
273
274 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
275 vha->host_no));
276 qla2x00_relogin(vha);
277
278 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
279 vha->host_no));
280 }
274 281
275 if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) && 282 if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) &&
276 (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) { 283 (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) {
277 clear_bit(RESET_ACTIVE, &vha->dpc_flags); 284 clear_bit(RESET_ACTIVE, &vha->dpc_flags);
278 } 285 }
279 286
280 if (atomic_read(&vha->vp_state) == VP_ACTIVE && 287 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
281 test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
282 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) { 288 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) {
283 qla2x00_loop_resync(vha); 289 qla2x00_loop_resync(vha);
284 clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags); 290 clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags);
@@ -289,38 +295,30 @@ qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
289} 295}
290 296
291void 297void
292qla2x00_do_dpc_all_vps(scsi_qla_host_t *ha) 298qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
293{ 299{
294 int ret; 300 int ret;
295 int i, vp_idx_matched; 301 struct qla_hw_data *ha = vha->hw;
296 scsi_qla_host_t *vha; 302 scsi_qla_host_t *vp;
297 303
298 if (ha->parent) 304 if (vha->vp_idx)
299 return; 305 return;
300 if (list_empty(&ha->vp_list)) 306 if (list_empty(&ha->vp_list))
301 return; 307 return;
302 308
303 clear_bit(VP_DPC_NEEDED, &ha->dpc_flags); 309 clear_bit(VP_DPC_NEEDED, &vha->dpc_flags);
304
305 for_each_mapped_vp_idx(ha, i) {
306 vp_idx_matched = 0;
307
308 list_for_each_entry(vha, &ha->vp_list, vp_list) {
309 if (i == vha->vp_idx) {
310 vp_idx_matched = 1;
311 break;
312 }
313 }
314 310
315 if (vp_idx_matched) 311 list_for_each_entry(vp, &ha->vp_list, list) {
316 ret = qla2x00_do_dpc_vp(vha); 312 if (vp->vp_idx)
313 ret = qla2x00_do_dpc_vp(vp);
317 } 314 }
318} 315}
319 316
320int 317int
321qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport) 318qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
322{ 319{
323 scsi_qla_host_t *ha = shost_priv(fc_vport->shost); 320 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
321 struct qla_hw_data *ha = base_vha->hw;
324 scsi_qla_host_t *vha; 322 scsi_qla_host_t *vha;
325 uint8_t port_name[WWN_SIZE]; 323 uint8_t port_name[WWN_SIZE];
326 324
@@ -337,7 +335,7 @@ qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
337 335
338 /* Check up unique WWPN */ 336 /* Check up unique WWPN */
339 u64_to_wwn(fc_vport->port_name, port_name); 337 u64_to_wwn(fc_vport->port_name, port_name);
340 if (!memcmp(port_name, ha->port_name, WWN_SIZE)) 338 if (!memcmp(port_name, base_vha->port_name, WWN_SIZE))
341 return VPCERR_BAD_WWN; 339 return VPCERR_BAD_WWN;
342 vha = qla24xx_find_vhost_by_name(ha, port_name); 340 vha = qla24xx_find_vhost_by_name(ha, port_name);
343 if (vha) 341 if (vha)
@@ -346,7 +344,7 @@ qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
346 /* Check up max-npiv-supports */ 344 /* Check up max-npiv-supports */
347 if (ha->num_vhosts > ha->max_npiv_vports) { 345 if (ha->num_vhosts > ha->max_npiv_vports) {
348 DEBUG15(printk("scsi(%ld): num_vhosts %ud is bigger than " 346 DEBUG15(printk("scsi(%ld): num_vhosts %ud is bigger than "
349 "max_npv_vports %ud.\n", ha->host_no, 347 "max_npv_vports %ud.\n", base_vha->host_no,
350 ha->num_vhosts, ha->max_npiv_vports)); 348 ha->num_vhosts, ha->max_npiv_vports));
351 return VPCERR_UNSUPPORTED; 349 return VPCERR_UNSUPPORTED;
352 } 350 }
@@ -356,59 +354,34 @@ qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
356scsi_qla_host_t * 354scsi_qla_host_t *
357qla24xx_create_vhost(struct fc_vport *fc_vport) 355qla24xx_create_vhost(struct fc_vport *fc_vport)
358{ 356{
359 scsi_qla_host_t *ha = shost_priv(fc_vport->shost); 357 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
358 struct qla_hw_data *ha = base_vha->hw;
360 scsi_qla_host_t *vha; 359 scsi_qla_host_t *vha;
360 struct scsi_host_template *sht = &qla24xx_driver_template;
361 struct Scsi_Host *host; 361 struct Scsi_Host *host;
362 362
363 host = scsi_host_alloc(&qla24xx_driver_template, 363 vha = qla2x00_create_host(sht, ha);
364 sizeof(scsi_qla_host_t)); 364 if (!vha) {
365 if (!host) { 365 DEBUG(printk("qla2xxx: scsi_host_alloc() failed for vport\n"));
366 printk(KERN_WARNING
367 "qla2xxx: scsi_host_alloc() failed for vport\n");
368 return(NULL); 366 return(NULL);
369 } 367 }
370 368
371 vha = shost_priv(host); 369 host = vha->host;
372
373 /* clone the parent hba */
374 memcpy(vha, ha, sizeof (scsi_qla_host_t));
375
376 fc_vport->dd_data = vha; 370 fc_vport->dd_data = vha;
377
378 vha->node_name = kmalloc(WWN_SIZE * sizeof(char), GFP_KERNEL);
379 if (!vha->node_name)
380 goto create_vhost_failed_1;
381
382 vha->port_name = kmalloc(WWN_SIZE * sizeof(char), GFP_KERNEL);
383 if (!vha->port_name)
384 goto create_vhost_failed_2;
385
386 /* New host info */ 371 /* New host info */
387 u64_to_wwn(fc_vport->node_name, vha->node_name); 372 u64_to_wwn(fc_vport->node_name, vha->node_name);
388 u64_to_wwn(fc_vport->port_name, vha->port_name); 373 u64_to_wwn(fc_vport->port_name, vha->port_name);
389 374
390 vha->host = host;
391 vha->host_no = host->host_no;
392 vha->parent = ha;
393 vha->fc_vport = fc_vport; 375 vha->fc_vport = fc_vport;
394 vha->device_flags = 0; 376 vha->device_flags = 0;
395 vha->vp_idx = qla24xx_allocate_vp_id(vha); 377 vha->vp_idx = qla24xx_allocate_vp_id(vha);
396 if (vha->vp_idx > ha->max_npiv_vports) { 378 if (vha->vp_idx > ha->max_npiv_vports) {
397 DEBUG15(printk("scsi(%ld): Couldn't allocate vp_id.\n", 379 DEBUG15(printk("scsi(%ld): Couldn't allocate vp_id.\n",
398 vha->host_no)); 380 vha->host_no));
399 goto create_vhost_failed_3; 381 goto create_vhost_failed;
400 } 382 }
401 vha->mgmt_svr_loop_id = 10 + vha->vp_idx; 383 vha->mgmt_svr_loop_id = 10 + vha->vp_idx;
402 384
403 init_completion(&vha->mbx_cmd_comp);
404 complete(&vha->mbx_cmd_comp);
405 init_completion(&vha->mbx_intr_comp);
406
407 INIT_LIST_HEAD(&vha->list);
408 INIT_LIST_HEAD(&vha->fcports);
409 INIT_LIST_HEAD(&vha->vp_fcports);
410 INIT_LIST_HEAD(&vha->work_list);
411
412 vha->dpc_flags = 0L; 385 vha->dpc_flags = 0L;
413 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); 386 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
414 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); 387 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
@@ -423,7 +396,9 @@ qla24xx_create_vhost(struct fc_vport *fc_vport)
423 396
424 qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL); 397 qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL);
425 398
426 host->can_queue = vha->request_q_length + 128; 399 memset(vha->req_ques, 0, sizeof(vha->req_ques) * QLA_MAX_HOST_QUES);
400 vha->req_ques[0] = ha->req_q_map[0]->id;
401 host->can_queue = ha->req_q_map[0]->length + 128;
427 host->this_id = 255; 402 host->this_id = 255;
428 host->cmd_per_lun = 3; 403 host->cmd_per_lun = 3;
429 host->max_cmd_len = MAX_CMDSZ; 404 host->max_cmd_len = MAX_CMDSZ;
@@ -440,12 +415,341 @@ qla24xx_create_vhost(struct fc_vport *fc_vport)
440 415
441 return vha; 416 return vha;
442 417
443create_vhost_failed_3: 418create_vhost_failed:
444 kfree(vha->port_name); 419 return NULL;
420}
445 421
446create_vhost_failed_2: 422static void
447 kfree(vha->node_name); 423qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req)
424{
425 struct qla_hw_data *ha = vha->hw;
426 uint16_t que_id = req->id;
427
428 dma_free_coherent(&ha->pdev->dev, (req->length + 1) *
429 sizeof(request_t), req->ring, req->dma);
430 req->ring = NULL;
431 req->dma = 0;
432 if (que_id) {
433 ha->req_q_map[que_id] = NULL;
434 mutex_lock(&ha->vport_lock);
435 clear_bit(que_id, ha->req_qid_map);
436 mutex_unlock(&ha->vport_lock);
437 }
438 kfree(req);
439 req = NULL;
440}
448 441
449create_vhost_failed_1: 442static void
450 return NULL; 443qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
444{
445 struct qla_hw_data *ha = vha->hw;
446 uint16_t que_id = rsp->id;
447
448 if (rsp->msix && rsp->msix->have_irq) {
449 free_irq(rsp->msix->vector, rsp);
450 rsp->msix->have_irq = 0;
451 rsp->msix->rsp = NULL;
452 }
453 dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) *
454 sizeof(response_t), rsp->ring, rsp->dma);
455 rsp->ring = NULL;
456 rsp->dma = 0;
457 if (que_id) {
458 ha->rsp_q_map[que_id] = NULL;
459 mutex_lock(&ha->vport_lock);
460 clear_bit(que_id, ha->rsp_qid_map);
461 mutex_unlock(&ha->vport_lock);
462 }
463 kfree(rsp);
464 rsp = NULL;
465}
466
467int
468qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req)
469{
470 int ret = -1;
471
472 if (req) {
473 req->options |= BIT_0;
474 ret = qla25xx_init_req_que(vha, req, req->options);
475 }
476 if (ret == QLA_SUCCESS)
477 qla25xx_free_req_que(vha, req);
478
479 return ret;
480}
481
482int
483qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
484{
485 int ret = -1;
486
487 if (rsp) {
488 rsp->options |= BIT_0;
489 ret = qla25xx_init_rsp_que(vha, rsp, rsp->options);
490 }
491 if (ret == QLA_SUCCESS)
492 qla25xx_free_rsp_que(vha, rsp);
493
494 return ret;
495}
496
497int qla25xx_update_req_que(struct scsi_qla_host *vha, uint8_t que, uint8_t qos)
498{
499 int ret = 0;
500 struct qla_hw_data *ha = vha->hw;
501 struct req_que *req = ha->req_q_map[que];
502
503 req->options |= BIT_3;
504 req->qos = qos;
505 ret = qla25xx_init_req_que(vha, req, req->options);
506 if (ret != QLA_SUCCESS)
507 DEBUG2_17(printk(KERN_WARNING "%s failed\n", __func__));
508 /* restore options bit */
509 req->options &= ~BIT_3;
510 return ret;
511}
512
513
514/* Delete all queues for a given vhost */
515int
516qla25xx_delete_queues(struct scsi_qla_host *vha, uint8_t que_no)
517{
518 int cnt, ret = 0;
519 struct req_que *req = NULL;
520 struct rsp_que *rsp = NULL;
521 struct qla_hw_data *ha = vha->hw;
522
523 if (que_no) {
524 /* Delete request queue */
525 req = ha->req_q_map[que_no];
526 if (req) {
527 rsp = req->rsp;
528 ret = qla25xx_delete_req_que(vha, req);
529 if (ret != QLA_SUCCESS) {
530 qla_printk(KERN_WARNING, ha,
531 "Couldn't delete req que %d\n", req->id);
532 return ret;
533 }
534 /* Delete associated response queue */
535 if (rsp) {
536 ret = qla25xx_delete_rsp_que(vha, rsp);
537 if (ret != QLA_SUCCESS) {
538 qla_printk(KERN_WARNING, ha,
539 "Couldn't delete rsp que %d\n",
540 rsp->id);
541 return ret;
542 }
543 }
544 }
545 } else { /* delete all queues of this host */
546 for (cnt = 0; cnt < QLA_MAX_HOST_QUES; cnt++) {
547 /* Delete request queues */
548 req = ha->req_q_map[vha->req_ques[cnt]];
549 if (req && req->id) {
550 rsp = req->rsp;
551 ret = qla25xx_delete_req_que(vha, req);
552 if (ret != QLA_SUCCESS) {
553 qla_printk(KERN_WARNING, ha,
554 "Couldn't delete req que %d\n",
555 vha->req_ques[cnt]);
556 return ret;
557 }
558 vha->req_ques[cnt] = ha->req_q_map[0]->id;
559 /* Delete associated response queue */
560 if (rsp && rsp->id) {
561 ret = qla25xx_delete_rsp_que(vha, rsp);
562 if (ret != QLA_SUCCESS) {
563 qla_printk(KERN_WARNING, ha,
564 "Couldn't delete rsp que %d\n",
565 rsp->id);
566 return ret;
567 }
568 }
569 }
570 }
571 }
572 qla_printk(KERN_INFO, ha, "Queues deleted for vport:%d\n",
573 vha->vp_idx);
574 return ret;
575}
576
577int
578qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options,
579 uint8_t vp_idx, uint16_t rid, uint8_t rsp_que, uint8_t qos)
580{
581 int ret = 0;
582 struct req_que *req = NULL;
583 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
584 uint16_t que_id = 0;
585
586 req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
587 if (req == NULL) {
588 qla_printk(KERN_WARNING, ha, "could not allocate memory"
589 "for request que\n");
590 goto que_failed;
591 }
592
593 req->length = REQUEST_ENTRY_CNT_24XX;
594 req->ring = dma_alloc_coherent(&ha->pdev->dev,
595 (req->length + 1) * sizeof(request_t),
596 &req->dma, GFP_KERNEL);
597 if (req->ring == NULL) {
598 qla_printk(KERN_WARNING, ha,
599 "Memory Allocation failed - request_ring\n");
600 goto que_failed;
601 }
602
603 mutex_lock(&ha->vport_lock);
604 que_id = find_first_zero_bit(ha->req_qid_map, ha->max_queues);
605 if (que_id >= ha->max_queues) {
606 mutex_unlock(&ha->vport_lock);
607 qla_printk(KERN_INFO, ha, "No resources to create "
608 "additional request queue\n");
609 goto que_failed;
610 }
611 set_bit(que_id, ha->req_qid_map);
612 ha->req_q_map[que_id] = req;
613 req->rid = rid;
614 req->vp_idx = vp_idx;
615 req->qos = qos;
616
617 if (ha->rsp_q_map[rsp_que])
618 req->rsp = ha->rsp_q_map[rsp_que];
619 /* Use alternate PCI bus number */
620 if (MSB(req->rid))
621 options |= BIT_4;
622 /* Use alternate PCI devfn */
623 if (LSB(req->rid))
624 options |= BIT_5;
625 req->options = options;
626 req->ring_ptr = req->ring;
627 req->ring_index = 0;
628 req->cnt = req->length;
629 req->id = que_id;
630 mutex_unlock(&ha->vport_lock);
631
632 ret = qla25xx_init_req_que(base_vha, req, options);
633 if (ret != QLA_SUCCESS) {
634 qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
635 mutex_lock(&ha->vport_lock);
636 clear_bit(que_id, ha->req_qid_map);
637 mutex_unlock(&ha->vport_lock);
638 goto que_failed;
639 }
640
641 return req->id;
642
643que_failed:
644 qla25xx_free_req_que(base_vha, req);
645 return 0;
646}
647
648/* create response queue */
649int
650qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
651 uint8_t vp_idx, uint16_t rid)
652{
653 int ret = 0;
654 struct rsp_que *rsp = NULL;
655 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
656 uint16_t que_id = 0;;
657
658 rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
659 if (rsp == NULL) {
660 qla_printk(KERN_WARNING, ha, "could not allocate memory for"
661 " response que\n");
662 goto que_failed;
663 }
664
665 rsp->length = RESPONSE_ENTRY_CNT_2300;
666 rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
667 (rsp->length + 1) * sizeof(response_t),
668 &rsp->dma, GFP_KERNEL);
669 if (rsp->ring == NULL) {
670 qla_printk(KERN_WARNING, ha,
671 "Memory Allocation failed - response_ring\n");
672 goto que_failed;
673 }
674
675 mutex_lock(&ha->vport_lock);
676 que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_queues);
677 if (que_id >= ha->max_queues) {
678 mutex_unlock(&ha->vport_lock);
679 qla_printk(KERN_INFO, ha, "No resources to create "
680 "additional response queue\n");
681 goto que_failed;
682 }
683 set_bit(que_id, ha->rsp_qid_map);
684
685 if (ha->flags.msix_enabled)
686 rsp->msix = &ha->msix_entries[que_id + 1];
687 else
688 qla_printk(KERN_WARNING, ha, "msix not enabled\n");
689
690 ha->rsp_q_map[que_id] = rsp;
691 rsp->rid = rid;
692 rsp->vp_idx = vp_idx;
693 rsp->hw = ha;
694 /* Use alternate PCI bus number */
695 if (MSB(rsp->rid))
696 options |= BIT_4;
697 /* Use alternate PCI devfn */
698 if (LSB(rsp->rid))
699 options |= BIT_5;
700 rsp->options = options;
701 rsp->ring_ptr = rsp->ring;
702 rsp->ring_index = 0;
703 rsp->id = que_id;
704 mutex_unlock(&ha->vport_lock);
705
706 ret = qla25xx_request_irq(rsp);
707 if (ret)
708 goto que_failed;
709
710 ret = qla25xx_init_rsp_que(base_vha, rsp, options);
711 if (ret != QLA_SUCCESS) {
712 qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
713 mutex_lock(&ha->vport_lock);
714 clear_bit(que_id, ha->rsp_qid_map);
715 mutex_unlock(&ha->vport_lock);
716 goto que_failed;
717 }
718
719 qla2x00_init_response_q_entries(rsp);
720
721 return rsp->id;
722
723que_failed:
724 qla25xx_free_rsp_que(base_vha, rsp);
725 return 0;
726}
727
728int
729qla25xx_create_queues(struct scsi_qla_host *vha, uint8_t qos)
730{
731 uint16_t options = 0;
732 uint8_t ret = 0;
733 struct qla_hw_data *ha = vha->hw;
734
735 options |= BIT_1;
736 ret = qla25xx_create_rsp_que(ha, options, vha->vp_idx, 0);
737 if (!ret) {
738 qla_printk(KERN_WARNING, ha, "Response Que create failed\n");
739 return ret;
740 } else
741 qla_printk(KERN_INFO, ha, "Response Que:%d created.\n", ret);
742
743 options = 0;
744 if (qos & BIT_7)
745 options |= BIT_8;
746 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, ret,
747 qos & ~BIT_7);
748 if (ret) {
749 vha->req_ques[0] = ret;
750 qla_printk(KERN_INFO, ha, "Request Que:%d created.\n", ret);
751 } else
752 qla_printk(KERN_WARNING, ha, "Request Que create failed\n");
753
754 return ret;
451} 755}