blob: 0dff0d4b03c9f0fd0aeec9c7ff38809a53e95760 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
18/**
19 * bfad_im.c Linux driver IM module.
20 */
21
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Jing Huang7725ccf2009-09-23 17:46:15 -070023#include "bfad_drv.h"
24#include "bfad_im.h"
25#include "bfad_trcmod.h"
26#include "bfa_cb_ioim_macros.h"
27#include <fcb/bfa_fcb_fcpim.h>
28
29BFA_TRC_FILE(LDRV, IM);
30
31DEFINE_IDR(bfad_im_port_index);
32struct scsi_transport_template *bfad_im_scsi_transport_template;
Jing Huangb5042932010-03-19 11:05:39 -070033struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
Jing Huang7725ccf2009-09-23 17:46:15 -070034static void bfad_im_itnim_work_handler(struct work_struct *work);
35static int bfad_im_queuecommand(struct scsi_cmnd *cmnd,
36 void (*done)(struct scsi_cmnd *));
37static int bfad_im_slave_alloc(struct scsi_device *sdev);
38
39void
40bfa_cb_ioim_done(void *drv, struct bfad_ioim_s *dio,
41 enum bfi_ioim_status io_status, u8 scsi_status,
42 int sns_len, u8 *sns_info, s32 residue)
43{
44 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
45 struct bfad_s *bfad = drv;
46 struct bfad_itnim_data_s *itnim_data;
47 struct bfad_itnim_s *itnim;
Krishna Gudipati95aa0602010-03-05 19:38:27 -080048 u8 host_status = DID_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -070049
50 switch (io_status) {
51 case BFI_IOIM_STS_OK:
52 bfa_trc(bfad, scsi_status);
Jing Huang7725ccf2009-09-23 17:46:15 -070053 scsi_set_resid(cmnd, 0);
54
55 if (sns_len > 0) {
56 bfa_trc(bfad, sns_len);
57 if (sns_len > SCSI_SENSE_BUFFERSIZE)
58 sns_len = SCSI_SENSE_BUFFERSIZE;
59 memcpy(cmnd->sense_buffer, sns_info, sns_len);
60 }
Krishna Gudipati95aa0602010-03-05 19:38:27 -080061 if (residue > 0) {
62 bfa_trc(bfad, residue);
Jing Huang7725ccf2009-09-23 17:46:15 -070063 scsi_set_resid(cmnd, residue);
Krishna Gudipati95aa0602010-03-05 19:38:27 -080064 if (!sns_len && (scsi_status == SAM_STAT_GOOD) &&
65 (scsi_bufflen(cmnd) - residue) <
66 cmnd->underflow) {
67 bfa_trc(bfad, 0);
68 host_status = DID_ERROR;
69 }
70 }
71 cmnd->result = ScsiResult(host_status, scsi_status);
72
Jing Huang7725ccf2009-09-23 17:46:15 -070073 break;
74
75 case BFI_IOIM_STS_ABORTED:
76 case BFI_IOIM_STS_TIMEDOUT:
77 case BFI_IOIM_STS_PATHTOV:
78 default:
79 cmnd->result = ScsiResult(DID_ERROR, 0);
80 }
81
82 /* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
83 if (cmnd->device->host != NULL)
84 scsi_dma_unmap(cmnd);
85
86 cmnd->host_scribble = NULL;
87 bfa_trc(bfad, cmnd->result);
88
89 itnim_data = cmnd->device->hostdata;
90 if (itnim_data) {
91 itnim = itnim_data->itnim;
92 if (!cmnd->result && itnim &&
93 (bfa_lun_queue_depth > cmnd->device->queue_depth)) {
94 /* Queue depth adjustment for good status completion */
95 bfad_os_ramp_up_qdepth(itnim, cmnd->device);
96 } else if (cmnd->result == SAM_STAT_TASK_SET_FULL && itnim) {
97 /* qfull handling */
98 bfad_os_handle_qfull(itnim, cmnd->device);
99 }
100 }
101
102 cmnd->scsi_done(cmnd);
103}
104
105void
106bfa_cb_ioim_good_comp(void *drv, struct bfad_ioim_s *dio)
107{
108 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
109 struct bfad_itnim_data_s *itnim_data;
110 struct bfad_itnim_s *itnim;
111
112 cmnd->result = ScsiResult(DID_OK, SCSI_STATUS_GOOD);
113
114 /* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
115 if (cmnd->device->host != NULL)
116 scsi_dma_unmap(cmnd);
117
118 cmnd->host_scribble = NULL;
119
120 /* Queue depth adjustment */
121 if (bfa_lun_queue_depth > cmnd->device->queue_depth) {
122 itnim_data = cmnd->device->hostdata;
123 if (itnim_data) {
124 itnim = itnim_data->itnim;
125 if (itnim)
126 bfad_os_ramp_up_qdepth(itnim, cmnd->device);
127 }
128 }
129
130 cmnd->scsi_done(cmnd);
131}
132
133void
134bfa_cb_ioim_abort(void *drv, struct bfad_ioim_s *dio)
135{
136 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
137 struct bfad_s *bfad = drv;
138
139 cmnd->result = ScsiResult(DID_ERROR, 0);
140
141 /* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
142 if (cmnd->device->host != NULL)
143 scsi_dma_unmap(cmnd);
144
145 bfa_trc(bfad, cmnd->result);
146 cmnd->host_scribble = NULL;
147}
148
149void
150bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
151 enum bfi_tskim_status tsk_status)
152{
153 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dtsk;
154 wait_queue_head_t *wq;
155
156 cmnd->SCp.Status |= tsk_status << 1;
157 set_bit(IO_DONE_BIT, (unsigned long *)&cmnd->SCp.Status);
158 wq = (wait_queue_head_t *) cmnd->SCp.ptr;
159 cmnd->SCp.ptr = NULL;
160
161 if (wq)
162 wake_up(wq);
163}
164
165void
166bfa_cb_ioim_resfree(void *drv)
167{
168}
169
170/**
171 * Scsi_Host_template SCSI host template
172 */
173/**
174 * Scsi_Host template entry, returns BFAD PCI info.
175 */
176static const char *
177bfad_im_info(struct Scsi_Host *shost)
178{
179 static char bfa_buf[256];
180 struct bfad_im_port_s *im_port =
181 (struct bfad_im_port_s *) shost->hostdata[0];
Jing Huang7725ccf2009-09-23 17:46:15 -0700182 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800183 char model[BFA_ADAPTER_MODEL_NAME_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700184
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800185 bfa_get_adapter_model(&bfad->bfa, model);
Jing Huang7725ccf2009-09-23 17:46:15 -0700186
187 memset(bfa_buf, 0, sizeof(bfa_buf));
188 snprintf(bfa_buf, sizeof(bfa_buf),
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800189 "Brocade FC/FCOE Adapter, " "model: %s hwpath: %s driver: %s",
190 model, bfad->pci_name, BFAD_DRIVER_VERSION);
Jing Huang7725ccf2009-09-23 17:46:15 -0700191 return bfa_buf;
192}
193
194/**
195 * Scsi_Host template entry, aborts the specified SCSI command.
196 *
197 * Returns: SUCCESS or FAILED.
198 */
199static int
200bfad_im_abort_handler(struct scsi_cmnd *cmnd)
201{
202 struct Scsi_Host *shost = cmnd->device->host;
203 struct bfad_im_port_s *im_port =
204 (struct bfad_im_port_s *) shost->hostdata[0];
205 struct bfad_s *bfad = im_port->bfad;
206 struct bfa_ioim_s *hal_io;
207 unsigned long flags;
208 u32 timeout;
209 int rc = FAILED;
210
211 spin_lock_irqsave(&bfad->bfad_lock, flags);
212 hal_io = (struct bfa_ioim_s *) cmnd->host_scribble;
213 if (!hal_io) {
214 /* IO has been completed, retrun success */
215 rc = SUCCESS;
216 goto out;
217 }
218 if (hal_io->dio != (struct bfad_ioim_s *) cmnd) {
219 rc = FAILED;
220 goto out;
221 }
222
223 bfa_trc(bfad, hal_io->iotag);
224 bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_ABORT,
225 im_port->shost->host_no, cmnd, hal_io->iotag);
226 bfa_ioim_abort(hal_io);
227 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
228
229 /* Need to wait until the command get aborted */
230 timeout = 10;
231 while ((struct bfa_ioim_s *) cmnd->host_scribble == hal_io) {
232 set_current_state(TASK_UNINTERRUPTIBLE);
233 schedule_timeout(timeout);
234 if (timeout < 4 * HZ)
235 timeout *= 2;
236 }
237
238 cmnd->scsi_done(cmnd);
239 bfa_trc(bfad, hal_io->iotag);
240 bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_ABORT_COMP,
241 im_port->shost->host_no, cmnd, hal_io->iotag);
242 return SUCCESS;
243out:
244 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
245 return rc;
246}
247
248static bfa_status_t
249bfad_im_target_reset_send(struct bfad_s *bfad, struct scsi_cmnd *cmnd,
250 struct bfad_itnim_s *itnim)
251{
252 struct bfa_tskim_s *tskim;
253 struct bfa_itnim_s *bfa_itnim;
254 bfa_status_t rc = BFA_STATUS_OK;
255
Jing Huang7725ccf2009-09-23 17:46:15 -0700256 tskim = bfa_tskim_alloc(&bfad->bfa, (struct bfad_tskim_s *) cmnd);
257 if (!tskim) {
258 BFA_DEV_PRINTF(bfad, BFA_ERR,
259 "target reset, fail to allocate tskim\n");
260 rc = BFA_STATUS_FAILED;
261 goto out;
262 }
263
264 /*
265 * Set host_scribble to NULL to avoid aborting a task command if
266 * happens.
267 */
268 cmnd->host_scribble = NULL;
269 cmnd->SCp.Status = 0;
270 bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim->fcs_itnim);
271 bfa_tskim_start(tskim, bfa_itnim, (lun_t)0,
272 FCP_TM_TARGET_RESET, BFAD_TARGET_RESET_TMO);
273out:
274 return rc;
275}
276
277/**
278 * Scsi_Host template entry, resets a LUN and abort its all commands.
279 *
280 * Returns: SUCCESS or FAILED.
281 *
282 */
283static int
284bfad_im_reset_lun_handler(struct scsi_cmnd *cmnd)
285{
286 struct Scsi_Host *shost = cmnd->device->host;
287 struct bfad_im_port_s *im_port =
288 (struct bfad_im_port_s *) shost->hostdata[0];
289 struct bfad_itnim_data_s *itnim_data = cmnd->device->hostdata;
290 struct bfad_s *bfad = im_port->bfad;
291 struct bfa_tskim_s *tskim;
292 struct bfad_itnim_s *itnim;
293 struct bfa_itnim_s *bfa_itnim;
294 DECLARE_WAIT_QUEUE_HEAD(wq);
295 int rc = SUCCESS;
296 unsigned long flags;
297 enum bfi_tskim_status task_status;
298
299 spin_lock_irqsave(&bfad->bfad_lock, flags);
300 itnim = itnim_data->itnim;
301 if (!itnim) {
302 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
303 rc = FAILED;
304 goto out;
305 }
306
307 tskim = bfa_tskim_alloc(&bfad->bfa, (struct bfad_tskim_s *) cmnd);
308 if (!tskim) {
309 BFA_DEV_PRINTF(bfad, BFA_ERR,
310 "LUN reset, fail to allocate tskim");
311 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
312 rc = FAILED;
313 goto out;
314 }
315
316 /**
317 * Set host_scribble to NULL to avoid aborting a task command
318 * if happens.
319 */
320 cmnd->host_scribble = NULL;
321 cmnd->SCp.ptr = (char *)&wq;
322 cmnd->SCp.Status = 0;
323 bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim->fcs_itnim);
324 bfa_tskim_start(tskim, bfa_itnim,
325 bfad_int_to_lun(cmnd->device->lun),
326 FCP_TM_LUN_RESET, BFAD_LUN_RESET_TMO);
327 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
328
329 wait_event(wq, test_bit(IO_DONE_BIT,
330 (unsigned long *)&cmnd->SCp.Status));
331
332 task_status = cmnd->SCp.Status >> 1;
333 if (task_status != BFI_TSKIM_STS_OK) {
334 BFA_DEV_PRINTF(bfad, BFA_ERR, "LUN reset failure, status: %d\n",
335 task_status);
336 rc = FAILED;
337 }
338
339out:
340 return rc;
341}
342
343/**
344 * Scsi_Host template entry, resets the bus and abort all commands.
345 */
346static int
347bfad_im_reset_bus_handler(struct scsi_cmnd *cmnd)
348{
349 struct Scsi_Host *shost = cmnd->device->host;
350 struct bfad_im_port_s *im_port =
351 (struct bfad_im_port_s *) shost->hostdata[0];
352 struct bfad_s *bfad = im_port->bfad;
353 struct bfad_itnim_s *itnim;
354 unsigned long flags;
355 u32 i, rc, err_cnt = 0;
356 DECLARE_WAIT_QUEUE_HEAD(wq);
357 enum bfi_tskim_status task_status;
358
359 spin_lock_irqsave(&bfad->bfad_lock, flags);
360 for (i = 0; i < MAX_FCP_TARGET; i++) {
361 itnim = bfad_os_get_itnim(im_port, i);
362 if (itnim) {
363 cmnd->SCp.ptr = (char *)&wq;
364 rc = bfad_im_target_reset_send(bfad, cmnd, itnim);
365 if (rc != BFA_STATUS_OK) {
366 err_cnt++;
367 continue;
368 }
369
370 /* wait target reset to complete */
371 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
372 wait_event(wq, test_bit(IO_DONE_BIT,
373 (unsigned long *)&cmnd->SCp.Status));
374 spin_lock_irqsave(&bfad->bfad_lock, flags);
375
376 task_status = cmnd->SCp.Status >> 1;
377 if (task_status != BFI_TSKIM_STS_OK) {
378 BFA_DEV_PRINTF(bfad, BFA_ERR,
379 "target reset failure,"
380 " status: %d\n", task_status);
381 err_cnt++;
382 }
383 }
384 }
385 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
386
387 if (err_cnt)
388 return FAILED;
389
390 return SUCCESS;
391}
392
393/**
394 * Scsi_Host template entry slave_destroy.
395 */
396static void
397bfad_im_slave_destroy(struct scsi_device *sdev)
398{
399 sdev->hostdata = NULL;
400 return;
401}
402
403/**
404 * BFA FCS itnim callbacks
405 */
406
407/**
408 * BFA FCS itnim alloc callback, after successful PRLI
409 * Context: Interrupt
410 */
411void
412bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
413 struct bfad_itnim_s **itnim_drv)
414{
415 *itnim_drv = kzalloc(sizeof(struct bfad_itnim_s), GFP_ATOMIC);
416 if (*itnim_drv == NULL)
417 return;
418
419 (*itnim_drv)->im = bfad->im;
420 *itnim = &(*itnim_drv)->fcs_itnim;
421 (*itnim_drv)->state = ITNIM_STATE_NONE;
422
423 /*
424 * Initiaze the itnim_work
425 */
426 INIT_WORK(&(*itnim_drv)->itnim_work, bfad_im_itnim_work_handler);
427 bfad->bfad_flags |= BFAD_RPORT_ONLINE;
428}
429
430/**
431 * BFA FCS itnim free callback.
432 * Context: Interrupt. bfad_lock is held
433 */
434void
435bfa_fcb_itnim_free(struct bfad_s *bfad, struct bfad_itnim_s *itnim_drv)
436{
437 struct bfad_port_s *port;
438 wwn_t wwpn;
439 u32 fcid;
440 char wwpn_str[32], fcid_str[16];
441
442 /* online to free state transtion should not happen */
443 bfa_assert(itnim_drv->state != ITNIM_STATE_ONLINE);
444
445 itnim_drv->queue_work = 1;
446 /* offline request is not yet done, use the same request to free */
447 if (itnim_drv->state == ITNIM_STATE_OFFLINE_PENDING)
448 itnim_drv->queue_work = 0;
449
450 itnim_drv->state = ITNIM_STATE_FREE;
451 port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
452 itnim_drv->im_port = port->im_port;
453 wwpn = bfa_fcs_itnim_get_pwwn(&itnim_drv->fcs_itnim);
454 fcid = bfa_fcs_itnim_get_fcid(&itnim_drv->fcs_itnim);
455 wwn2str(wwpn_str, wwpn);
456 fcid2str(fcid_str, fcid);
457 bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_FREE,
458 port->im_port->shost->host_no,
459 fcid_str, wwpn_str);
460 bfad_os_itnim_process(itnim_drv);
461}
462
463/**
464 * BFA FCS itnim online callback.
465 * Context: Interrupt. bfad_lock is held
466 */
467void
468bfa_fcb_itnim_online(struct bfad_itnim_s *itnim_drv)
469{
470 struct bfad_port_s *port;
471
472 itnim_drv->bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim_drv->fcs_itnim);
473 port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
474 itnim_drv->state = ITNIM_STATE_ONLINE;
475 itnim_drv->queue_work = 1;
476 itnim_drv->im_port = port->im_port;
477 bfad_os_itnim_process(itnim_drv);
478}
479
480/**
481 * BFA FCS itnim offline callback.
482 * Context: Interrupt. bfad_lock is held
483 */
484void
485bfa_fcb_itnim_offline(struct bfad_itnim_s *itnim_drv)
486{
487 struct bfad_port_s *port;
488 struct bfad_s *bfad;
489
490 port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
491 bfad = port->bfad;
492 if ((bfad->pport.flags & BFAD_PORT_DELETE) ||
493 (port->flags & BFAD_PORT_DELETE)) {
494 itnim_drv->state = ITNIM_STATE_OFFLINE;
495 return;
496 }
497 itnim_drv->im_port = port->im_port;
498 itnim_drv->state = ITNIM_STATE_OFFLINE_PENDING;
499 itnim_drv->queue_work = 1;
500 bfad_os_itnim_process(itnim_drv);
501}
502
503/**
504 * BFA FCS itnim timeout callback.
505 * Context: Interrupt. bfad_lock is held
506 */
507void bfa_fcb_itnim_tov(struct bfad_itnim_s *itnim)
508{
509 itnim->state = ITNIM_STATE_TIMEOUT;
510}
511
512/**
Jing Huang7725ccf2009-09-23 17:46:15 -0700513 * Allocate a Scsi_Host for a port.
514 */
515int
Jing Huangb5042932010-03-19 11:05:39 -0700516bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port,
517 struct device *dev)
Jing Huang7725ccf2009-09-23 17:46:15 -0700518{
519 int error = 1;
520
Jing Huang42b426e2010-03-19 11:07:09 -0700521 mutex_lock(&bfad_mutex);
Jing Huang7725ccf2009-09-23 17:46:15 -0700522 if (!idr_pre_get(&bfad_im_port_index, GFP_KERNEL)) {
Jing Huang42b426e2010-03-19 11:07:09 -0700523 mutex_unlock(&bfad_mutex);
Jing Huang7725ccf2009-09-23 17:46:15 -0700524 printk(KERN_WARNING "idr_pre_get failure\n");
525 goto out;
526 }
527
528 error = idr_get_new(&bfad_im_port_index, im_port,
529 &im_port->idr_id);
530 if (error) {
Jing Huang42b426e2010-03-19 11:07:09 -0700531 mutex_unlock(&bfad_mutex);
Jing Huang7725ccf2009-09-23 17:46:15 -0700532 printk(KERN_WARNING "idr_get_new failure\n");
533 goto out;
534 }
535
Jing Huang42b426e2010-03-19 11:07:09 -0700536 mutex_unlock(&bfad_mutex);
537
Jing Huang7725ccf2009-09-23 17:46:15 -0700538 im_port->shost = bfad_os_scsi_host_alloc(im_port, bfad);
539 if (!im_port->shost) {
540 error = 1;
541 goto out_free_idr;
542 }
543
544 im_port->shost->hostdata[0] = (unsigned long)im_port;
545 im_port->shost->unique_id = im_port->idr_id;
546 im_port->shost->this_id = -1;
547 im_port->shost->max_id = MAX_FCP_TARGET;
548 im_port->shost->max_lun = MAX_FCP_LUN;
549 im_port->shost->max_cmd_len = 16;
550 im_port->shost->can_queue = bfad->cfg_data.ioc_queue_depth;
Jing Huangb5042932010-03-19 11:05:39 -0700551 if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
552 im_port->shost->transportt = bfad_im_scsi_transport_template;
553 else
554 im_port->shost->transportt =
555 bfad_im_scsi_vport_transport_template;
Jing Huang7725ccf2009-09-23 17:46:15 -0700556
Jing Huangb5042932010-03-19 11:05:39 -0700557 error = scsi_add_host(im_port->shost, dev);
Jing Huang7725ccf2009-09-23 17:46:15 -0700558 if (error) {
Jing Huangb5042932010-03-19 11:05:39 -0700559 printk(KERN_WARNING "scsi_add_host failure %d\n", error);
Jing Huang7725ccf2009-09-23 17:46:15 -0700560 goto out_fc_rel;
561 }
562
563 /* setup host fixed attribute if the lk supports */
564 bfad_os_fc_host_init(im_port);
565
566 return 0;
567
568out_fc_rel:
569 scsi_host_put(im_port->shost);
Jing Huangd9883542010-07-08 19:46:26 -0700570 im_port->shost = NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700571out_free_idr:
Jing Huang42b426e2010-03-19 11:07:09 -0700572 mutex_lock(&bfad_mutex);
Jing Huang7725ccf2009-09-23 17:46:15 -0700573 idr_remove(&bfad_im_port_index, im_port->idr_id);
Jing Huang42b426e2010-03-19 11:07:09 -0700574 mutex_unlock(&bfad_mutex);
Jing Huang7725ccf2009-09-23 17:46:15 -0700575out:
576 return error;
577}
578
579void
580bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
581{
Jing Huang7725ccf2009-09-23 17:46:15 -0700582 bfa_trc(bfad, bfad->inst_no);
583 bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_HOST_FREE,
584 im_port->shost->host_no);
585
586 fc_remove_host(im_port->shost);
587
588 scsi_remove_host(im_port->shost);
589 scsi_host_put(im_port->shost);
590
Jing Huang42b426e2010-03-19 11:07:09 -0700591 mutex_lock(&bfad_mutex);
Jing Huang7725ccf2009-09-23 17:46:15 -0700592 idr_remove(&bfad_im_port_index, im_port->idr_id);
Jing Huang42b426e2010-03-19 11:07:09 -0700593 mutex_unlock(&bfad_mutex);
Jing Huang7725ccf2009-09-23 17:46:15 -0700594}
595
596static void
597bfad_im_port_delete_handler(struct work_struct *work)
598{
599 struct bfad_im_port_s *im_port =
600 container_of(work, struct bfad_im_port_s, port_delete_work);
601
Jing Huangb5042932010-03-19 11:05:39 -0700602 if (im_port->port->pvb_type != BFAD_PORT_PHYS_BASE) {
603 im_port->flags |= BFAD_PORT_DELETE;
604 fc_vport_terminate(im_port->fc_vport);
605 }
606
Jing Huang7725ccf2009-09-23 17:46:15 -0700607}
608
609bfa_status_t
610bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port)
611{
612 int rc = BFA_STATUS_OK;
613 struct bfad_im_port_s *im_port;
614
615 im_port = kzalloc(sizeof(struct bfad_im_port_s), GFP_ATOMIC);
616 if (im_port == NULL) {
617 rc = BFA_STATUS_ENOMEM;
618 goto ext;
619 }
620 port->im_port = im_port;
621 im_port->port = port;
622 im_port->bfad = bfad;
623
624 INIT_WORK(&im_port->port_delete_work, bfad_im_port_delete_handler);
625 INIT_LIST_HEAD(&im_port->itnim_mapped_list);
626 INIT_LIST_HEAD(&im_port->binding_list);
627
628ext:
629 return rc;
630}
631
632void
633bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port)
634{
635 struct bfad_im_port_s *im_port = port->im_port;
636
637 queue_work(bfad->im->drv_workq,
638 &im_port->port_delete_work);
639}
640
641void
642bfad_im_port_clean(struct bfad_im_port_s *im_port)
643{
644 struct bfad_fcp_binding *bp, *bp_new;
645 unsigned long flags;
646 struct bfad_s *bfad = im_port->bfad;
647
648 spin_lock_irqsave(&bfad->bfad_lock, flags);
649 list_for_each_entry_safe(bp, bp_new, &im_port->binding_list,
650 list_entry) {
651 list_del(&bp->list_entry);
652 kfree(bp);
653 }
654
655 /* the itnim_mapped_list must be empty at this time */
656 bfa_assert(list_empty(&im_port->itnim_mapped_list));
657
658 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
659}
660
661void
662bfad_im_port_online(struct bfad_s *bfad, struct bfad_port_s *port)
663{
664}
665
666void
667bfad_im_port_offline(struct bfad_s *bfad, struct bfad_port_s *port)
668{
669}
670
671bfa_status_t
672bfad_im_probe(struct bfad_s *bfad)
673{
674 struct bfad_im_s *im;
675 bfa_status_t rc = BFA_STATUS_OK;
676
677 im = kzalloc(sizeof(struct bfad_im_s), GFP_KERNEL);
678 if (im == NULL) {
679 rc = BFA_STATUS_ENOMEM;
680 goto ext;
681 }
682
683 bfad->im = im;
684 im->bfad = bfad;
685
686 if (bfad_os_thread_workq(bfad) != BFA_STATUS_OK) {
687 kfree(im);
688 rc = BFA_STATUS_FAILED;
689 }
690
691ext:
692 return rc;
693}
694
695void
696bfad_im_probe_undo(struct bfad_s *bfad)
697{
698 if (bfad->im) {
699 bfad_os_destroy_workq(bfad->im);
700 kfree(bfad->im);
701 bfad->im = NULL;
702 }
703}
704
Jing Huang7725ccf2009-09-23 17:46:15 -0700705struct Scsi_Host *
706bfad_os_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *bfad)
707{
708 struct scsi_host_template *sht;
709
710 if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
711 sht = &bfad_im_scsi_host_template;
712 else
713 sht = &bfad_im_vport_template;
714
715 sht->sg_tablesize = bfad->cfg_data.io_max_sge;
716
717 return scsi_host_alloc(sht, sizeof(unsigned long));
718}
719
720void
721bfad_os_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
722{
Jing Huangb5042932010-03-19 11:05:39 -0700723 if (!(im_port->flags & BFAD_PORT_DELETE))
724 flush_workqueue(bfad->im->drv_workq);
Jing Huang7725ccf2009-09-23 17:46:15 -0700725 bfad_im_scsi_host_free(im_port->bfad, im_port);
726 bfad_im_port_clean(im_port);
727 kfree(im_port);
728}
729
730void
731bfad_os_destroy_workq(struct bfad_im_s *im)
732{
733 if (im && im->drv_workq) {
734 destroy_workqueue(im->drv_workq);
735 im->drv_workq = NULL;
736 }
737}
738
739bfa_status_t
740bfad_os_thread_workq(struct bfad_s *bfad)
741{
742 struct bfad_im_s *im = bfad->im;
743
744 bfa_trc(bfad, 0);
745 snprintf(im->drv_workq_name, BFAD_KOBJ_NAME_LEN, "bfad_wq_%d",
746 bfad->inst_no);
747 im->drv_workq = create_singlethread_workqueue(im->drv_workq_name);
748 if (!im->drv_workq)
749 return BFA_STATUS_FAILED;
750
751 return BFA_STATUS_OK;
752}
753
754/**
755 * Scsi_Host template entry.
756 *
757 * Description:
758 * OS entry point to adjust the queue_depths on a per-device basis.
759 * Called once per device during the bus scan.
760 * Return non-zero if fails.
761 */
762static int
763bfad_im_slave_configure(struct scsi_device *sdev)
764{
765 if (sdev->tagged_supported)
766 scsi_activate_tcq(sdev, bfa_lun_queue_depth);
767 else
768 scsi_deactivate_tcq(sdev, bfa_lun_queue_depth);
769
770 return 0;
771}
772
773struct scsi_host_template bfad_im_scsi_host_template = {
774 .module = THIS_MODULE,
775 .name = BFAD_DRIVER_NAME,
776 .info = bfad_im_info,
777 .queuecommand = bfad_im_queuecommand,
778 .eh_abort_handler = bfad_im_abort_handler,
779 .eh_device_reset_handler = bfad_im_reset_lun_handler,
780 .eh_bus_reset_handler = bfad_im_reset_bus_handler,
781
782 .slave_alloc = bfad_im_slave_alloc,
783 .slave_configure = bfad_im_slave_configure,
784 .slave_destroy = bfad_im_slave_destroy,
785
786 .this_id = -1,
787 .sg_tablesize = BFAD_IO_MAX_SGE,
788 .cmd_per_lun = 3,
789 .use_clustering = ENABLE_CLUSTERING,
790 .shost_attrs = bfad_im_host_attrs,
791 .max_sectors = 0xFFFF,
792};
793
794struct scsi_host_template bfad_im_vport_template = {
795 .module = THIS_MODULE,
796 .name = BFAD_DRIVER_NAME,
797 .info = bfad_im_info,
798 .queuecommand = bfad_im_queuecommand,
799 .eh_abort_handler = bfad_im_abort_handler,
800 .eh_device_reset_handler = bfad_im_reset_lun_handler,
801 .eh_bus_reset_handler = bfad_im_reset_bus_handler,
802
803 .slave_alloc = bfad_im_slave_alloc,
804 .slave_configure = bfad_im_slave_configure,
805 .slave_destroy = bfad_im_slave_destroy,
806
807 .this_id = -1,
808 .sg_tablesize = BFAD_IO_MAX_SGE,
809 .cmd_per_lun = 3,
810 .use_clustering = ENABLE_CLUSTERING,
811 .shost_attrs = bfad_im_vport_attrs,
812 .max_sectors = 0xFFFF,
813};
814
815void
816bfad_im_probe_post(struct bfad_im_s *im)
817{
818 flush_workqueue(im->drv_workq);
819}
820
821bfa_status_t
822bfad_im_module_init(void)
823{
824 bfad_im_scsi_transport_template =
825 fc_attach_transport(&bfad_im_fc_function_template);
826 if (!bfad_im_scsi_transport_template)
827 return BFA_STATUS_ENOMEM;
828
Jing Huangb5042932010-03-19 11:05:39 -0700829 bfad_im_scsi_vport_transport_template =
830 fc_attach_transport(&bfad_im_vport_fc_function_template);
831 if (!bfad_im_scsi_vport_transport_template) {
832 fc_release_transport(bfad_im_scsi_transport_template);
833 return BFA_STATUS_ENOMEM;
834 }
835
Jing Huang7725ccf2009-09-23 17:46:15 -0700836 return BFA_STATUS_OK;
837}
838
839void
840bfad_im_module_exit(void)
841{
842 if (bfad_im_scsi_transport_template)
843 fc_release_transport(bfad_im_scsi_transport_template);
Jing Huangb5042932010-03-19 11:05:39 -0700844 if (bfad_im_scsi_vport_transport_template)
845 fc_release_transport(bfad_im_scsi_vport_transport_template);
Jing Huang7725ccf2009-09-23 17:46:15 -0700846}
847
848void
849bfad_os_itnim_process(struct bfad_itnim_s *itnim_drv)
850{
851 struct bfad_im_s *im = itnim_drv->im;
852
853 if (itnim_drv->queue_work)
854 queue_work(im->drv_workq, &itnim_drv->itnim_work);
855}
856
857void
858bfad_os_ramp_up_qdepth(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
859{
860 struct scsi_device *tmp_sdev;
861
862 if (((jiffies - itnim->last_ramp_up_time) >
863 BFA_QUEUE_FULL_RAMP_UP_TIME * HZ) &&
864 ((jiffies - itnim->last_queue_full_time) >
865 BFA_QUEUE_FULL_RAMP_UP_TIME * HZ)) {
866 shost_for_each_device(tmp_sdev, sdev->host) {
867 if (bfa_lun_queue_depth > tmp_sdev->queue_depth) {
868 if (tmp_sdev->id != sdev->id)
869 continue;
870 if (tmp_sdev->ordered_tags)
871 scsi_adjust_queue_depth(tmp_sdev,
872 MSG_ORDERED_TAG,
873 tmp_sdev->queue_depth + 1);
874 else
875 scsi_adjust_queue_depth(tmp_sdev,
876 MSG_SIMPLE_TAG,
877 tmp_sdev->queue_depth + 1);
878
879 itnim->last_ramp_up_time = jiffies;
880 }
881 }
882 }
883}
884
885void
886bfad_os_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
887{
888 struct scsi_device *tmp_sdev;
889
890 itnim->last_queue_full_time = jiffies;
891
892 shost_for_each_device(tmp_sdev, sdev->host) {
893 if (tmp_sdev->id != sdev->id)
894 continue;
895 scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
896 }
897}
898
899
900
901
902struct bfad_itnim_s *
903bfad_os_get_itnim(struct bfad_im_port_s *im_port, int id)
904{
905 struct bfad_itnim_s *itnim = NULL;
906
907 /* Search the mapped list for this target ID */
908 list_for_each_entry(itnim, &im_port->itnim_mapped_list, list_entry) {
909 if (id == itnim->scsi_tgt_id)
910 return itnim;
911 }
912
913 return NULL;
914}
915
916/**
917 * Scsi_Host template entry slave_alloc
918 */
919static int
920bfad_im_slave_alloc(struct scsi_device *sdev)
921{
922 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
923
924 if (!rport || fc_remote_port_chkready(rport))
925 return -ENXIO;
926
927 sdev->hostdata = rport->dd_data;
928
929 return 0;
930}
931
932void
933bfad_os_fc_host_init(struct bfad_im_port_s *im_port)
934{
935 struct Scsi_Host *host = im_port->shost;
936 struct bfad_s *bfad = im_port->bfad;
937 struct bfad_port_s *port = im_port->port;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800938 struct bfa_pport_attr_s pattr;
939 char model[BFA_ADAPTER_MODEL_NAME_LEN];
940 char fw_ver[BFA_VERSION_LEN];
Jing Huang7725ccf2009-09-23 17:46:15 -0700941
942 fc_host_node_name(host) =
943 bfa_os_htonll((bfa_fcs_port_get_nwwn(port->fcs_port)));
944 fc_host_port_name(host) =
945 bfa_os_htonll((bfa_fcs_port_get_pwwn(port->fcs_port)));
Jing Huangb5042932010-03-19 11:05:39 -0700946 fc_host_max_npiv_vports(host) = bfa_lps_get_max_vport(&bfad->bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -0700947
948 fc_host_supported_classes(host) = FC_COS_CLASS3;
949
950 memset(fc_host_supported_fc4s(host), 0,
951 sizeof(fc_host_supported_fc4s(host)));
952 if (bfad_supported_fc4s & (BFA_PORT_ROLE_FCP_IM | BFA_PORT_ROLE_FCP_TM))
953 /* For FCP type 0x08 */
954 fc_host_supported_fc4s(host)[2] = 1;
Roel Kluin7542fa72009-10-15 20:15:17 +0200955 if (bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IPFC)
Jing Huang7725ccf2009-09-23 17:46:15 -0700956 /* For LLC/SNAP type 0x05 */
957 fc_host_supported_fc4s(host)[3] = 0x20;
958 /* For fibre channel services type 0x20 */
959 fc_host_supported_fc4s(host)[7] = 1;
960
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800961 bfa_get_adapter_model(&bfad->bfa, model);
962 bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -0700963 sprintf(fc_host_symbolic_name(host), "Brocade %s FV%s DV%s",
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800964 model, fw_ver, BFAD_DRIVER_VERSION);
Jing Huang7725ccf2009-09-23 17:46:15 -0700965
966 fc_host_supported_speeds(host) = 0;
967 fc_host_supported_speeds(host) |=
968 FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
969 FC_PORTSPEED_1GBIT;
970
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -0800971 bfa_fcport_get_attr(&bfad->bfa, &pattr);
972 fc_host_maxframe_size(host) = pattr.pport_cfg.maxfrsize;
Jing Huang7725ccf2009-09-23 17:46:15 -0700973}
974
975static void
976bfad_im_fc_rport_add(struct bfad_im_port_s *im_port, struct bfad_itnim_s *itnim)
977{
978 struct fc_rport_identifiers rport_ids;
979 struct fc_rport *fc_rport;
980 struct bfad_itnim_data_s *itnim_data;
981
982 rport_ids.node_name =
983 bfa_os_htonll(bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim));
984 rport_ids.port_name =
985 bfa_os_htonll(bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
986 rport_ids.port_id =
987 bfa_os_hton3b(bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim));
988 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
989
990 itnim->fc_rport = fc_rport =
991 fc_remote_port_add(im_port->shost, 0, &rport_ids);
992
993 if (!fc_rport)
994 return;
995
996 fc_rport->maxframe_size =
997 bfa_fcs_itnim_get_maxfrsize(&itnim->fcs_itnim);
998 fc_rport->supported_classes = bfa_fcs_itnim_get_cos(&itnim->fcs_itnim);
999
1000 itnim_data = fc_rport->dd_data;
1001 itnim_data->itnim = itnim;
1002
1003 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1004
1005 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1006 fc_remote_port_rolechg(fc_rport, rport_ids.roles);
1007
1008 if ((fc_rport->scsi_target_id != -1)
1009 && (fc_rport->scsi_target_id < MAX_FCP_TARGET))
1010 itnim->scsi_tgt_id = fc_rport->scsi_target_id;
1011
1012 return;
1013}
1014
1015/**
1016 * Work queue handler using FC transport service
1017* Context: kernel
1018 */
1019static void
1020bfad_im_itnim_work_handler(struct work_struct *work)
1021{
1022 struct bfad_itnim_s *itnim = container_of(work, struct bfad_itnim_s,
1023 itnim_work);
1024 struct bfad_im_s *im = itnim->im;
1025 struct bfad_s *bfad = im->bfad;
1026 struct bfad_im_port_s *im_port;
1027 unsigned long flags;
1028 struct fc_rport *fc_rport;
1029 wwn_t wwpn;
1030 u32 fcid;
1031 char wwpn_str[32], fcid_str[16];
1032
1033 spin_lock_irqsave(&bfad->bfad_lock, flags);
1034 im_port = itnim->im_port;
1035 bfa_trc(bfad, itnim->state);
1036 switch (itnim->state) {
1037 case ITNIM_STATE_ONLINE:
1038 if (!itnim->fc_rport) {
1039 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1040 bfad_im_fc_rport_add(im_port, itnim);
1041 spin_lock_irqsave(&bfad->bfad_lock, flags);
1042 wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
1043 fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
1044 wwn2str(wwpn_str, wwpn);
1045 fcid2str(fcid_str, fcid);
1046 list_add_tail(&itnim->list_entry,
1047 &im_port->itnim_mapped_list);
1048 bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_ONLINE,
1049 im_port->shost->host_no,
1050 itnim->scsi_tgt_id,
1051 fcid_str, wwpn_str);
1052 } else {
1053 printk(KERN_WARNING
1054 "%s: itnim %llx is already in online state\n",
Jing Huangf8ceafd2009-09-25 12:29:54 -07001055 __func__,
Jing Huang7725ccf2009-09-23 17:46:15 -07001056 bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
1057 }
1058
1059 break;
1060 case ITNIM_STATE_OFFLINE_PENDING:
1061 itnim->state = ITNIM_STATE_OFFLINE;
1062 if (itnim->fc_rport) {
1063 fc_rport = itnim->fc_rport;
1064 ((struct bfad_itnim_data_s *)
1065 fc_rport->dd_data)->itnim = NULL;
1066 itnim->fc_rport = NULL;
1067 if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
1068 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1069 fc_rport->dev_loss_tmo =
1070 bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
1071 fc_remote_port_delete(fc_rport);
1072 spin_lock_irqsave(&bfad->bfad_lock, flags);
1073 }
1074 wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
1075 fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
1076 wwn2str(wwpn_str, wwpn);
1077 fcid2str(fcid_str, fcid);
1078 list_del(&itnim->list_entry);
1079 bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_OFFLINE,
1080 im_port->shost->host_no,
1081 itnim->scsi_tgt_id,
1082 fcid_str, wwpn_str);
1083 }
1084 break;
1085 case ITNIM_STATE_FREE:
1086 if (itnim->fc_rport) {
1087 fc_rport = itnim->fc_rport;
1088 ((struct bfad_itnim_data_s *)
1089 fc_rport->dd_data)->itnim = NULL;
1090 itnim->fc_rport = NULL;
1091 if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
1092 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1093 fc_rport->dev_loss_tmo =
1094 bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
1095 fc_remote_port_delete(fc_rport);
1096 spin_lock_irqsave(&bfad->bfad_lock, flags);
1097 }
1098 list_del(&itnim->list_entry);
1099 }
1100
1101 kfree(itnim);
1102 break;
1103 default:
1104 bfa_assert(0);
1105 break;
1106 }
1107
1108 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1109}
1110
1111/**
1112 * Scsi_Host template entry, queue a SCSI command to the BFAD.
1113 */
1114static int
1115bfad_im_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
1116{
1117 struct bfad_im_port_s *im_port =
1118 (struct bfad_im_port_s *) cmnd->device->host->hostdata[0];
1119 struct bfad_s *bfad = im_port->bfad;
1120 struct bfad_itnim_data_s *itnim_data = cmnd->device->hostdata;
1121 struct bfad_itnim_s *itnim;
1122 struct bfa_ioim_s *hal_io;
1123 unsigned long flags;
1124 int rc;
1125 s16 sg_cnt = 0;
1126 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
1127
1128 rc = fc_remote_port_chkready(rport);
1129 if (rc) {
1130 cmnd->result = rc;
1131 done(cmnd);
1132 return 0;
1133 }
1134
1135 sg_cnt = scsi_dma_map(cmnd);
1136
1137 if (sg_cnt < 0)
1138 return SCSI_MLQUEUE_HOST_BUSY;
1139
1140 cmnd->scsi_done = done;
1141
1142 spin_lock_irqsave(&bfad->bfad_lock, flags);
1143 if (!(bfad->bfad_flags & BFAD_HAL_START_DONE)) {
1144 printk(KERN_WARNING
1145 "bfad%d, queuecommand %p %x failed, BFA stopped\n",
1146 bfad->inst_no, cmnd, cmnd->cmnd[0]);
1147 cmnd->result = ScsiResult(DID_NO_CONNECT, 0);
1148 goto out_fail_cmd;
1149 }
1150
1151 itnim = itnim_data->itnim;
1152 if (!itnim) {
1153 cmnd->result = ScsiResult(DID_IMM_RETRY, 0);
1154 goto out_fail_cmd;
1155 }
1156
1157 hal_io = bfa_ioim_alloc(&bfad->bfa, (struct bfad_ioim_s *) cmnd,
1158 itnim->bfa_itnim, sg_cnt);
1159 if (!hal_io) {
1160 printk(KERN_WARNING "hal_io failure\n");
1161 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1162 scsi_dma_unmap(cmnd);
1163 return SCSI_MLQUEUE_HOST_BUSY;
1164 }
1165
1166 cmnd->host_scribble = (char *)hal_io;
1167 bfa_trc_fp(bfad, hal_io->iotag);
1168 bfa_ioim_start(hal_io);
1169 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1170
1171 return 0;
1172
1173out_fail_cmd:
1174 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1175 scsi_dma_unmap(cmnd);
1176 if (done)
1177 done(cmnd);
1178
1179 return 0;
1180}
1181
1182void
1183bfad_os_rport_online_wait(struct bfad_s *bfad)
1184{
1185 int i;
1186 int rport_delay = 10;
1187
1188 for (i = 0; !(bfad->bfad_flags & BFAD_PORT_ONLINE)
1189 && i < bfa_linkup_delay; i++)
1190 schedule_timeout_uninterruptible(HZ);
1191
1192 if (bfad->bfad_flags & BFAD_PORT_ONLINE) {
1193 rport_delay = rport_delay < bfa_linkup_delay ?
1194 rport_delay : bfa_linkup_delay;
1195 for (i = 0; !(bfad->bfad_flags & BFAD_RPORT_ONLINE)
1196 && i < rport_delay; i++)
1197 schedule_timeout_uninterruptible(HZ);
1198
1199 if (rport_delay > 0 && (bfad->bfad_flags & BFAD_RPORT_ONLINE))
1200 schedule_timeout_uninterruptible(rport_delay * HZ);
1201 }
1202}
1203
1204int
1205bfad_os_get_linkup_delay(struct bfad_s *bfad)
1206{
1207
1208 u8 nwwns = 0;
1209 wwn_t *wwns;
1210 int ldelay;
1211
1212 /*
1213 * Querying for the boot target port wwns
1214 * -- read from boot information in flash.
1215 * If nwwns > 0 => boot over SAN and set bfa_linkup_delay = 30
1216 * else => local boot machine set bfa_linkup_delay = 10
1217 */
1218
1219 bfa_iocfc_get_bootwwns(&bfad->bfa, &nwwns, &wwns);
1220
1221 if (nwwns > 0) {
1222 /* If boot over SAN; linkup_delay = 30sec */
1223 ldelay = 30;
1224 } else {
1225 /* If local boot; linkup_delay = 10sec */
1226 ldelay = 0;
1227 }
1228
1229 return ldelay;
1230}
1231
1232