bfad_im.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  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. * bfad_im.c Linux driver IM module.
  19. */
  20. #include <linux/slab.h>
  21. #include "bfad_drv.h"
  22. #include "bfad_im.h"
  23. #include "bfad_trcmod.h"
  24. #include "bfa_cb_ioim_macros.h"
  25. #include <fcb/bfa_fcb_fcpim.h>
  26. BFA_TRC_FILE(LDRV, IM);
  27. DEFINE_IDR(bfad_im_port_index);
  28. struct scsi_transport_template *bfad_im_scsi_transport_template;
  29. struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
  30. static void bfad_im_itnim_work_handler(struct work_struct *work);
  31. static int bfad_im_queuecommand(struct scsi_cmnd *cmnd,
  32. void (*done)(struct scsi_cmnd *));
  33. static int bfad_im_slave_alloc(struct scsi_device *sdev);
  34. void
  35. bfa_cb_ioim_done(void *drv, struct bfad_ioim_s *dio,
  36. enum bfi_ioim_status io_status, u8 scsi_status,
  37. int sns_len, u8 *sns_info, s32 residue)
  38. {
  39. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  40. struct bfad_s *bfad = drv;
  41. struct bfad_itnim_data_s *itnim_data;
  42. struct bfad_itnim_s *itnim;
  43. u8 host_status = DID_OK;
  44. switch (io_status) {
  45. case BFI_IOIM_STS_OK:
  46. bfa_trc(bfad, scsi_status);
  47. scsi_set_resid(cmnd, 0);
  48. if (sns_len > 0) {
  49. bfa_trc(bfad, sns_len);
  50. if (sns_len > SCSI_SENSE_BUFFERSIZE)
  51. sns_len = SCSI_SENSE_BUFFERSIZE;
  52. memcpy(cmnd->sense_buffer, sns_info, sns_len);
  53. }
  54. if (residue > 0) {
  55. bfa_trc(bfad, residue);
  56. scsi_set_resid(cmnd, residue);
  57. if (!sns_len && (scsi_status == SAM_STAT_GOOD) &&
  58. (scsi_bufflen(cmnd) - residue) <
  59. cmnd->underflow) {
  60. bfa_trc(bfad, 0);
  61. host_status = DID_ERROR;
  62. }
  63. }
  64. cmnd->result = ScsiResult(host_status, scsi_status);
  65. break;
  66. case BFI_IOIM_STS_ABORTED:
  67. case BFI_IOIM_STS_TIMEDOUT:
  68. case BFI_IOIM_STS_PATHTOV:
  69. default:
  70. cmnd->result = ScsiResult(DID_ERROR, 0);
  71. }
  72. /* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
  73. if (cmnd->device->host != NULL)
  74. scsi_dma_unmap(cmnd);
  75. cmnd->host_scribble = NULL;
  76. bfa_trc(bfad, cmnd->result);
  77. itnim_data = cmnd->device->hostdata;
  78. if (itnim_data) {
  79. itnim = itnim_data->itnim;
  80. if (!cmnd->result && itnim &&
  81. (bfa_lun_queue_depth > cmnd->device->queue_depth)) {
  82. /* Queue depth adjustment for good status completion */
  83. bfad_os_ramp_up_qdepth(itnim, cmnd->device);
  84. } else if (cmnd->result == SAM_STAT_TASK_SET_FULL && itnim) {
  85. /* qfull handling */
  86. bfad_os_handle_qfull(itnim, cmnd->device);
  87. }
  88. }
  89. cmnd->scsi_done(cmnd);
  90. }
  91. void
  92. bfa_cb_ioim_good_comp(void *drv, struct bfad_ioim_s *dio)
  93. {
  94. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  95. struct bfad_itnim_data_s *itnim_data;
  96. struct bfad_itnim_s *itnim;
  97. cmnd->result = ScsiResult(DID_OK, SCSI_STATUS_GOOD);
  98. /* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
  99. if (cmnd->device->host != NULL)
  100. scsi_dma_unmap(cmnd);
  101. cmnd->host_scribble = NULL;
  102. /* Queue depth adjustment */
  103. if (bfa_lun_queue_depth > cmnd->device->queue_depth) {
  104. itnim_data = cmnd->device->hostdata;
  105. if (itnim_data) {
  106. itnim = itnim_data->itnim;
  107. if (itnim)
  108. bfad_os_ramp_up_qdepth(itnim, cmnd->device);
  109. }
  110. }
  111. cmnd->scsi_done(cmnd);
  112. }
  113. void
  114. bfa_cb_ioim_abort(void *drv, struct bfad_ioim_s *dio)
  115. {
  116. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  117. struct bfad_s *bfad = drv;
  118. cmnd->result = ScsiResult(DID_ERROR, 0);
  119. /* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
  120. if (cmnd->device->host != NULL)
  121. scsi_dma_unmap(cmnd);
  122. bfa_trc(bfad, cmnd->result);
  123. cmnd->host_scribble = NULL;
  124. }
  125. void
  126. bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
  127. enum bfi_tskim_status tsk_status)
  128. {
  129. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dtsk;
  130. wait_queue_head_t *wq;
  131. cmnd->SCp.Status |= tsk_status << 1;
  132. set_bit(IO_DONE_BIT, (unsigned long *)&cmnd->SCp.Status);
  133. wq = (wait_queue_head_t *) cmnd->SCp.ptr;
  134. cmnd->SCp.ptr = NULL;
  135. if (wq)
  136. wake_up(wq);
  137. }
  138. void
  139. bfa_cb_ioim_resfree(void *drv)
  140. {
  141. }
  142. /**
  143. * Scsi_Host_template SCSI host template
  144. */
  145. /**
  146. * Scsi_Host template entry, returns BFAD PCI info.
  147. */
  148. static const char *
  149. bfad_im_info(struct Scsi_Host *shost)
  150. {
  151. static char bfa_buf[256];
  152. struct bfad_im_port_s *im_port =
  153. (struct bfad_im_port_s *) shost->hostdata[0];
  154. struct bfad_s *bfad = im_port->bfad;
  155. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  156. bfa_get_adapter_model(&bfad->bfa, model);
  157. memset(bfa_buf, 0, sizeof(bfa_buf));
  158. snprintf(bfa_buf, sizeof(bfa_buf),
  159. "Brocade FC/FCOE Adapter, " "model: %s hwpath: %s driver: %s",
  160. model, bfad->pci_name, BFAD_DRIVER_VERSION);
  161. return bfa_buf;
  162. }
  163. /**
  164. * Scsi_Host template entry, aborts the specified SCSI command.
  165. *
  166. * Returns: SUCCESS or FAILED.
  167. */
  168. static int
  169. bfad_im_abort_handler(struct scsi_cmnd *cmnd)
  170. {
  171. struct Scsi_Host *shost = cmnd->device->host;
  172. struct bfad_im_port_s *im_port =
  173. (struct bfad_im_port_s *) shost->hostdata[0];
  174. struct bfad_s *bfad = im_port->bfad;
  175. struct bfa_ioim_s *hal_io;
  176. unsigned long flags;
  177. u32 timeout;
  178. int rc = FAILED;
  179. spin_lock_irqsave(&bfad->bfad_lock, flags);
  180. hal_io = (struct bfa_ioim_s *) cmnd->host_scribble;
  181. if (!hal_io) {
  182. /* IO has been completed, retrun success */
  183. rc = SUCCESS;
  184. goto out;
  185. }
  186. if (hal_io->dio != (struct bfad_ioim_s *) cmnd) {
  187. rc = FAILED;
  188. goto out;
  189. }
  190. bfa_trc(bfad, hal_io->iotag);
  191. bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_ABORT,
  192. im_port->shost->host_no, cmnd, hal_io->iotag);
  193. bfa_ioim_abort(hal_io);
  194. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  195. /* Need to wait until the command get aborted */
  196. timeout = 10;
  197. while ((struct bfa_ioim_s *) cmnd->host_scribble == hal_io) {
  198. set_current_state(TASK_UNINTERRUPTIBLE);
  199. schedule_timeout(timeout);
  200. if (timeout < 4 * HZ)
  201. timeout *= 2;
  202. }
  203. cmnd->scsi_done(cmnd);
  204. bfa_trc(bfad, hal_io->iotag);
  205. bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_ABORT_COMP,
  206. im_port->shost->host_no, cmnd, hal_io->iotag);
  207. return SUCCESS;
  208. out:
  209. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  210. return rc;
  211. }
  212. static bfa_status_t
  213. bfad_im_target_reset_send(struct bfad_s *bfad, struct scsi_cmnd *cmnd,
  214. struct bfad_itnim_s *itnim)
  215. {
  216. struct bfa_tskim_s *tskim;
  217. struct bfa_itnim_s *bfa_itnim;
  218. bfa_status_t rc = BFA_STATUS_OK;
  219. tskim = bfa_tskim_alloc(&bfad->bfa, (struct bfad_tskim_s *) cmnd);
  220. if (!tskim) {
  221. BFA_DEV_PRINTF(bfad, BFA_ERR,
  222. "target reset, fail to allocate tskim\n");
  223. rc = BFA_STATUS_FAILED;
  224. goto out;
  225. }
  226. /*
  227. * Set host_scribble to NULL to avoid aborting a task command if
  228. * happens.
  229. */
  230. cmnd->host_scribble = NULL;
  231. cmnd->SCp.Status = 0;
  232. bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim->fcs_itnim);
  233. bfa_tskim_start(tskim, bfa_itnim, (lun_t)0,
  234. FCP_TM_TARGET_RESET, BFAD_TARGET_RESET_TMO);
  235. out:
  236. return rc;
  237. }
  238. /**
  239. * Scsi_Host template entry, resets a LUN and abort its all commands.
  240. *
  241. * Returns: SUCCESS or FAILED.
  242. *
  243. */
  244. static int
  245. bfad_im_reset_lun_handler(struct scsi_cmnd *cmnd)
  246. {
  247. struct Scsi_Host *shost = cmnd->device->host;
  248. struct bfad_im_port_s *im_port =
  249. (struct bfad_im_port_s *) shost->hostdata[0];
  250. struct bfad_itnim_data_s *itnim_data = cmnd->device->hostdata;
  251. struct bfad_s *bfad = im_port->bfad;
  252. struct bfa_tskim_s *tskim;
  253. struct bfad_itnim_s *itnim;
  254. struct bfa_itnim_s *bfa_itnim;
  255. DECLARE_WAIT_QUEUE_HEAD(wq);
  256. int rc = SUCCESS;
  257. unsigned long flags;
  258. enum bfi_tskim_status task_status;
  259. spin_lock_irqsave(&bfad->bfad_lock, flags);
  260. itnim = itnim_data->itnim;
  261. if (!itnim) {
  262. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  263. rc = FAILED;
  264. goto out;
  265. }
  266. tskim = bfa_tskim_alloc(&bfad->bfa, (struct bfad_tskim_s *) cmnd);
  267. if (!tskim) {
  268. BFA_DEV_PRINTF(bfad, BFA_ERR,
  269. "LUN reset, fail to allocate tskim");
  270. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  271. rc = FAILED;
  272. goto out;
  273. }
  274. /**
  275. * Set host_scribble to NULL to avoid aborting a task command
  276. * if happens.
  277. */
  278. cmnd->host_scribble = NULL;
  279. cmnd->SCp.ptr = (char *)&wq;
  280. cmnd->SCp.Status = 0;
  281. bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim->fcs_itnim);
  282. bfa_tskim_start(tskim, bfa_itnim,
  283. bfad_int_to_lun(cmnd->device->lun),
  284. FCP_TM_LUN_RESET, BFAD_LUN_RESET_TMO);
  285. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  286. wait_event(wq, test_bit(IO_DONE_BIT,
  287. (unsigned long *)&cmnd->SCp.Status));
  288. task_status = cmnd->SCp.Status >> 1;
  289. if (task_status != BFI_TSKIM_STS_OK) {
  290. BFA_DEV_PRINTF(bfad, BFA_ERR, "LUN reset failure, status: %d\n",
  291. task_status);
  292. rc = FAILED;
  293. }
  294. out:
  295. return rc;
  296. }
  297. /**
  298. * Scsi_Host template entry, resets the bus and abort all commands.
  299. */
  300. static int
  301. bfad_im_reset_bus_handler(struct scsi_cmnd *cmnd)
  302. {
  303. struct Scsi_Host *shost = cmnd->device->host;
  304. struct bfad_im_port_s *im_port =
  305. (struct bfad_im_port_s *) shost->hostdata[0];
  306. struct bfad_s *bfad = im_port->bfad;
  307. struct bfad_itnim_s *itnim;
  308. unsigned long flags;
  309. u32 i, rc, err_cnt = 0;
  310. DECLARE_WAIT_QUEUE_HEAD(wq);
  311. enum bfi_tskim_status task_status;
  312. spin_lock_irqsave(&bfad->bfad_lock, flags);
  313. for (i = 0; i < MAX_FCP_TARGET; i++) {
  314. itnim = bfad_os_get_itnim(im_port, i);
  315. if (itnim) {
  316. cmnd->SCp.ptr = (char *)&wq;
  317. rc = bfad_im_target_reset_send(bfad, cmnd, itnim);
  318. if (rc != BFA_STATUS_OK) {
  319. err_cnt++;
  320. continue;
  321. }
  322. /* wait target reset to complete */
  323. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  324. wait_event(wq, test_bit(IO_DONE_BIT,
  325. (unsigned long *)&cmnd->SCp.Status));
  326. spin_lock_irqsave(&bfad->bfad_lock, flags);
  327. task_status = cmnd->SCp.Status >> 1;
  328. if (task_status != BFI_TSKIM_STS_OK) {
  329. BFA_DEV_PRINTF(bfad, BFA_ERR,
  330. "target reset failure,"
  331. " status: %d\n", task_status);
  332. err_cnt++;
  333. }
  334. }
  335. }
  336. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  337. if (err_cnt)
  338. return FAILED;
  339. return SUCCESS;
  340. }
  341. /**
  342. * Scsi_Host template entry slave_destroy.
  343. */
  344. static void
  345. bfad_im_slave_destroy(struct scsi_device *sdev)
  346. {
  347. sdev->hostdata = NULL;
  348. return;
  349. }
  350. /**
  351. * BFA FCS itnim callbacks
  352. */
  353. /**
  354. * BFA FCS itnim alloc callback, after successful PRLI
  355. * Context: Interrupt
  356. */
  357. void
  358. bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
  359. struct bfad_itnim_s **itnim_drv)
  360. {
  361. *itnim_drv = kzalloc(sizeof(struct bfad_itnim_s), GFP_ATOMIC);
  362. if (*itnim_drv == NULL)
  363. return;
  364. (*itnim_drv)->im = bfad->im;
  365. *itnim = &(*itnim_drv)->fcs_itnim;
  366. (*itnim_drv)->state = ITNIM_STATE_NONE;
  367. /*
  368. * Initiaze the itnim_work
  369. */
  370. INIT_WORK(&(*itnim_drv)->itnim_work, bfad_im_itnim_work_handler);
  371. bfad->bfad_flags |= BFAD_RPORT_ONLINE;
  372. }
  373. /**
  374. * BFA FCS itnim free callback.
  375. * Context: Interrupt. bfad_lock is held
  376. */
  377. void
  378. bfa_fcb_itnim_free(struct bfad_s *bfad, struct bfad_itnim_s *itnim_drv)
  379. {
  380. struct bfad_port_s *port;
  381. wwn_t wwpn;
  382. u32 fcid;
  383. char wwpn_str[32], fcid_str[16];
  384. /* online to free state transtion should not happen */
  385. bfa_assert(itnim_drv->state != ITNIM_STATE_ONLINE);
  386. itnim_drv->queue_work = 1;
  387. /* offline request is not yet done, use the same request to free */
  388. if (itnim_drv->state == ITNIM_STATE_OFFLINE_PENDING)
  389. itnim_drv->queue_work = 0;
  390. itnim_drv->state = ITNIM_STATE_FREE;
  391. port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
  392. itnim_drv->im_port = port->im_port;
  393. wwpn = bfa_fcs_itnim_get_pwwn(&itnim_drv->fcs_itnim);
  394. fcid = bfa_fcs_itnim_get_fcid(&itnim_drv->fcs_itnim);
  395. wwn2str(wwpn_str, wwpn);
  396. fcid2str(fcid_str, fcid);
  397. bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_FREE,
  398. port->im_port->shost->host_no,
  399. fcid_str, wwpn_str);
  400. bfad_os_itnim_process(itnim_drv);
  401. }
  402. /**
  403. * BFA FCS itnim online callback.
  404. * Context: Interrupt. bfad_lock is held
  405. */
  406. void
  407. bfa_fcb_itnim_online(struct bfad_itnim_s *itnim_drv)
  408. {
  409. struct bfad_port_s *port;
  410. itnim_drv->bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim_drv->fcs_itnim);
  411. port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
  412. itnim_drv->state = ITNIM_STATE_ONLINE;
  413. itnim_drv->queue_work = 1;
  414. itnim_drv->im_port = port->im_port;
  415. bfad_os_itnim_process(itnim_drv);
  416. }
  417. /**
  418. * BFA FCS itnim offline callback.
  419. * Context: Interrupt. bfad_lock is held
  420. */
  421. void
  422. bfa_fcb_itnim_offline(struct bfad_itnim_s *itnim_drv)
  423. {
  424. struct bfad_port_s *port;
  425. struct bfad_s *bfad;
  426. port = bfa_fcs_itnim_get_drvport(&itnim_drv->fcs_itnim);
  427. bfad = port->bfad;
  428. if ((bfad->pport.flags & BFAD_PORT_DELETE) ||
  429. (port->flags & BFAD_PORT_DELETE)) {
  430. itnim_drv->state = ITNIM_STATE_OFFLINE;
  431. return;
  432. }
  433. itnim_drv->im_port = port->im_port;
  434. itnim_drv->state = ITNIM_STATE_OFFLINE_PENDING;
  435. itnim_drv->queue_work = 1;
  436. bfad_os_itnim_process(itnim_drv);
  437. }
  438. /**
  439. * BFA FCS itnim timeout callback.
  440. * Context: Interrupt. bfad_lock is held
  441. */
  442. void bfa_fcb_itnim_tov(struct bfad_itnim_s *itnim)
  443. {
  444. itnim->state = ITNIM_STATE_TIMEOUT;
  445. }
  446. /**
  447. * Allocate a Scsi_Host for a port.
  448. */
  449. int
  450. bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port,
  451. struct device *dev)
  452. {
  453. int error = 1;
  454. mutex_lock(&bfad_mutex);
  455. if (!idr_pre_get(&bfad_im_port_index, GFP_KERNEL)) {
  456. mutex_unlock(&bfad_mutex);
  457. printk(KERN_WARNING "idr_pre_get failure\n");
  458. goto out;
  459. }
  460. error = idr_get_new(&bfad_im_port_index, im_port,
  461. &im_port->idr_id);
  462. if (error) {
  463. mutex_unlock(&bfad_mutex);
  464. printk(KERN_WARNING "idr_get_new failure\n");
  465. goto out;
  466. }
  467. mutex_unlock(&bfad_mutex);
  468. im_port->shost = bfad_os_scsi_host_alloc(im_port, bfad);
  469. if (!im_port->shost) {
  470. error = 1;
  471. goto out_free_idr;
  472. }
  473. im_port->shost->hostdata[0] = (unsigned long)im_port;
  474. im_port->shost->unique_id = im_port->idr_id;
  475. im_port->shost->this_id = -1;
  476. im_port->shost->max_id = MAX_FCP_TARGET;
  477. im_port->shost->max_lun = MAX_FCP_LUN;
  478. im_port->shost->max_cmd_len = 16;
  479. im_port->shost->can_queue = bfad->cfg_data.ioc_queue_depth;
  480. if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
  481. im_port->shost->transportt = bfad_im_scsi_transport_template;
  482. else
  483. im_port->shost->transportt =
  484. bfad_im_scsi_vport_transport_template;
  485. error = scsi_add_host_with_dma(im_port->shost, dev, &bfad->pcidev->dev);
  486. if (error) {
  487. printk(KERN_WARNING "scsi_add_host failure %d\n", error);
  488. goto out_fc_rel;
  489. }
  490. /* setup host fixed attribute if the lk supports */
  491. bfad_os_fc_host_init(im_port);
  492. return 0;
  493. out_fc_rel:
  494. scsi_host_put(im_port->shost);
  495. im_port->shost = NULL;
  496. out_free_idr:
  497. mutex_lock(&bfad_mutex);
  498. idr_remove(&bfad_im_port_index, im_port->idr_id);
  499. mutex_unlock(&bfad_mutex);
  500. out:
  501. return error;
  502. }
  503. void
  504. bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
  505. {
  506. bfa_trc(bfad, bfad->inst_no);
  507. bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_HOST_FREE,
  508. im_port->shost->host_no);
  509. fc_remove_host(im_port->shost);
  510. scsi_remove_host(im_port->shost);
  511. scsi_host_put(im_port->shost);
  512. mutex_lock(&bfad_mutex);
  513. idr_remove(&bfad_im_port_index, im_port->idr_id);
  514. mutex_unlock(&bfad_mutex);
  515. }
  516. static void
  517. bfad_im_port_delete_handler(struct work_struct *work)
  518. {
  519. struct bfad_im_port_s *im_port =
  520. container_of(work, struct bfad_im_port_s, port_delete_work);
  521. struct bfad_s *bfad = im_port->bfad;
  522. if (im_port->port->pvb_type != BFAD_PORT_PHYS_BASE) {
  523. im_port->flags |= BFAD_PORT_DELETE;
  524. fc_vport_terminate(im_port->fc_vport);
  525. atomic_dec(&bfad->wq_reqcnt);
  526. }
  527. }
  528. bfa_status_t
  529. bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port)
  530. {
  531. int rc = BFA_STATUS_OK;
  532. struct bfad_im_port_s *im_port;
  533. im_port = kzalloc(sizeof(struct bfad_im_port_s), GFP_ATOMIC);
  534. if (im_port == NULL) {
  535. rc = BFA_STATUS_ENOMEM;
  536. goto ext;
  537. }
  538. port->im_port = im_port;
  539. im_port->port = port;
  540. im_port->bfad = bfad;
  541. INIT_WORK(&im_port->port_delete_work, bfad_im_port_delete_handler);
  542. INIT_LIST_HEAD(&im_port->itnim_mapped_list);
  543. INIT_LIST_HEAD(&im_port->binding_list);
  544. ext:
  545. return rc;
  546. }
  547. void
  548. bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port)
  549. {
  550. struct bfad_im_port_s *im_port = port->im_port;
  551. if (im_port->port->pvb_type != BFAD_PORT_PHYS_BASE) {
  552. atomic_inc(&bfad->wq_reqcnt);
  553. queue_work(bfad->im->drv_workq,
  554. &im_port->port_delete_work);
  555. }
  556. }
  557. void
  558. bfad_im_port_clean(struct bfad_im_port_s *im_port)
  559. {
  560. struct bfad_fcp_binding *bp, *bp_new;
  561. unsigned long flags;
  562. struct bfad_s *bfad = im_port->bfad;
  563. spin_lock_irqsave(&bfad->bfad_lock, flags);
  564. list_for_each_entry_safe(bp, bp_new, &im_port->binding_list,
  565. list_entry) {
  566. list_del(&bp->list_entry);
  567. kfree(bp);
  568. }
  569. /* the itnim_mapped_list must be empty at this time */
  570. bfa_assert(list_empty(&im_port->itnim_mapped_list));
  571. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  572. }
  573. void
  574. bfad_im_port_online(struct bfad_s *bfad, struct bfad_port_s *port)
  575. {
  576. }
  577. void
  578. bfad_im_port_offline(struct bfad_s *bfad, struct bfad_port_s *port)
  579. {
  580. }
  581. bfa_status_t
  582. bfad_im_probe(struct bfad_s *bfad)
  583. {
  584. struct bfad_im_s *im;
  585. bfa_status_t rc = BFA_STATUS_OK;
  586. im = kzalloc(sizeof(struct bfad_im_s), GFP_KERNEL);
  587. if (im == NULL) {
  588. rc = BFA_STATUS_ENOMEM;
  589. goto ext;
  590. }
  591. bfad->im = im;
  592. im->bfad = bfad;
  593. if (bfad_os_thread_workq(bfad) != BFA_STATUS_OK) {
  594. kfree(im);
  595. rc = BFA_STATUS_FAILED;
  596. }
  597. ext:
  598. return rc;
  599. }
  600. void
  601. bfad_im_probe_undo(struct bfad_s *bfad)
  602. {
  603. if (bfad->im) {
  604. while (atomic_read(&bfad->wq_reqcnt)) {
  605. printk(KERN_INFO "bfa %s: waiting workq processing,"
  606. " wq_reqcnt:%x\n", bfad->pci_name,
  607. atomic_read(&bfad->wq_reqcnt));
  608. schedule_timeout_uninterruptible(HZ);
  609. }
  610. bfad_os_destroy_workq(bfad->im);
  611. kfree(bfad->im);
  612. bfad->im = NULL;
  613. }
  614. }
  615. /**
  616. * Call back function to handle IO redirection state change
  617. */
  618. void
  619. bfa_cb_ioredirect_state_change(void *hcb_bfad, bfa_boolean_t ioredirect)
  620. {
  621. /* Do nothing */
  622. }
  623. struct Scsi_Host *
  624. bfad_os_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *bfad)
  625. {
  626. struct scsi_host_template *sht;
  627. if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
  628. sht = &bfad_im_scsi_host_template;
  629. else
  630. sht = &bfad_im_vport_template;
  631. sht->sg_tablesize = bfad->cfg_data.io_max_sge;
  632. return scsi_host_alloc(sht, sizeof(unsigned long));
  633. }
  634. void
  635. bfad_os_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
  636. {
  637. if (!(im_port->flags & BFAD_PORT_DELETE))
  638. flush_workqueue(bfad->im->drv_workq);
  639. bfad_im_scsi_host_free(im_port->bfad, im_port);
  640. bfad_im_port_clean(im_port);
  641. kfree(im_port);
  642. }
  643. void
  644. bfad_os_destroy_workq(struct bfad_im_s *im)
  645. {
  646. if (im && im->drv_workq) {
  647. destroy_workqueue(im->drv_workq);
  648. im->drv_workq = NULL;
  649. }
  650. }
  651. bfa_status_t
  652. bfad_os_thread_workq(struct bfad_s *bfad)
  653. {
  654. struct bfad_im_s *im = bfad->im;
  655. bfa_trc(bfad, 0);
  656. snprintf(im->drv_workq_name, BFAD_KOBJ_NAME_LEN, "bfad_wq_%d",
  657. bfad->inst_no);
  658. im->drv_workq = create_singlethread_workqueue(im->drv_workq_name);
  659. if (!im->drv_workq)
  660. return BFA_STATUS_FAILED;
  661. return BFA_STATUS_OK;
  662. }
  663. /**
  664. * Scsi_Host template entry.
  665. *
  666. * Description:
  667. * OS entry point to adjust the queue_depths on a per-device basis.
  668. * Called once per device during the bus scan.
  669. * Return non-zero if fails.
  670. */
  671. static int
  672. bfad_im_slave_configure(struct scsi_device *sdev)
  673. {
  674. if (sdev->tagged_supported)
  675. scsi_activate_tcq(sdev, bfa_lun_queue_depth);
  676. else
  677. scsi_deactivate_tcq(sdev, bfa_lun_queue_depth);
  678. return 0;
  679. }
  680. struct scsi_host_template bfad_im_scsi_host_template = {
  681. .module = THIS_MODULE,
  682. .name = BFAD_DRIVER_NAME,
  683. .info = bfad_im_info,
  684. .queuecommand = bfad_im_queuecommand,
  685. .eh_abort_handler = bfad_im_abort_handler,
  686. .eh_device_reset_handler = bfad_im_reset_lun_handler,
  687. .eh_bus_reset_handler = bfad_im_reset_bus_handler,
  688. .slave_alloc = bfad_im_slave_alloc,
  689. .slave_configure = bfad_im_slave_configure,
  690. .slave_destroy = bfad_im_slave_destroy,
  691. .this_id = -1,
  692. .sg_tablesize = BFAD_IO_MAX_SGE,
  693. .cmd_per_lun = 3,
  694. .use_clustering = ENABLE_CLUSTERING,
  695. .shost_attrs = bfad_im_host_attrs,
  696. .max_sectors = 0xFFFF,
  697. };
  698. struct scsi_host_template bfad_im_vport_template = {
  699. .module = THIS_MODULE,
  700. .name = BFAD_DRIVER_NAME,
  701. .info = bfad_im_info,
  702. .queuecommand = bfad_im_queuecommand,
  703. .eh_abort_handler = bfad_im_abort_handler,
  704. .eh_device_reset_handler = bfad_im_reset_lun_handler,
  705. .eh_bus_reset_handler = bfad_im_reset_bus_handler,
  706. .slave_alloc = bfad_im_slave_alloc,
  707. .slave_configure = bfad_im_slave_configure,
  708. .slave_destroy = bfad_im_slave_destroy,
  709. .this_id = -1,
  710. .sg_tablesize = BFAD_IO_MAX_SGE,
  711. .cmd_per_lun = 3,
  712. .use_clustering = ENABLE_CLUSTERING,
  713. .shost_attrs = bfad_im_vport_attrs,
  714. .max_sectors = 0xFFFF,
  715. };
  716. void
  717. bfad_im_probe_post(struct bfad_im_s *im)
  718. {
  719. flush_workqueue(im->drv_workq);
  720. }
  721. bfa_status_t
  722. bfad_im_module_init(void)
  723. {
  724. bfad_im_scsi_transport_template =
  725. fc_attach_transport(&bfad_im_fc_function_template);
  726. if (!bfad_im_scsi_transport_template)
  727. return BFA_STATUS_ENOMEM;
  728. bfad_im_scsi_vport_transport_template =
  729. fc_attach_transport(&bfad_im_vport_fc_function_template);
  730. if (!bfad_im_scsi_vport_transport_template) {
  731. fc_release_transport(bfad_im_scsi_transport_template);
  732. return BFA_STATUS_ENOMEM;
  733. }
  734. return BFA_STATUS_OK;
  735. }
  736. void
  737. bfad_im_module_exit(void)
  738. {
  739. if (bfad_im_scsi_transport_template)
  740. fc_release_transport(bfad_im_scsi_transport_template);
  741. if (bfad_im_scsi_vport_transport_template)
  742. fc_release_transport(bfad_im_scsi_vport_transport_template);
  743. }
  744. void
  745. bfad_os_itnim_process(struct bfad_itnim_s *itnim_drv)
  746. {
  747. struct bfad_im_s *im = itnim_drv->im;
  748. if (itnim_drv->queue_work)
  749. queue_work(im->drv_workq, &itnim_drv->itnim_work);
  750. }
  751. void
  752. bfad_os_ramp_up_qdepth(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
  753. {
  754. struct scsi_device *tmp_sdev;
  755. if (((jiffies - itnim->last_ramp_up_time) >
  756. BFA_QUEUE_FULL_RAMP_UP_TIME * HZ) &&
  757. ((jiffies - itnim->last_queue_full_time) >
  758. BFA_QUEUE_FULL_RAMP_UP_TIME * HZ)) {
  759. shost_for_each_device(tmp_sdev, sdev->host) {
  760. if (bfa_lun_queue_depth > tmp_sdev->queue_depth) {
  761. if (tmp_sdev->id != sdev->id)
  762. continue;
  763. if (tmp_sdev->ordered_tags)
  764. scsi_adjust_queue_depth(tmp_sdev,
  765. MSG_ORDERED_TAG,
  766. tmp_sdev->queue_depth + 1);
  767. else
  768. scsi_adjust_queue_depth(tmp_sdev,
  769. MSG_SIMPLE_TAG,
  770. tmp_sdev->queue_depth + 1);
  771. itnim->last_ramp_up_time = jiffies;
  772. }
  773. }
  774. }
  775. }
  776. void
  777. bfad_os_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
  778. {
  779. struct scsi_device *tmp_sdev;
  780. itnim->last_queue_full_time = jiffies;
  781. shost_for_each_device(tmp_sdev, sdev->host) {
  782. if (tmp_sdev->id != sdev->id)
  783. continue;
  784. scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
  785. }
  786. }
  787. struct bfad_itnim_s *
  788. bfad_os_get_itnim(struct bfad_im_port_s *im_port, int id)
  789. {
  790. struct bfad_itnim_s *itnim = NULL;
  791. /* Search the mapped list for this target ID */
  792. list_for_each_entry(itnim, &im_port->itnim_mapped_list, list_entry) {
  793. if (id == itnim->scsi_tgt_id)
  794. return itnim;
  795. }
  796. return NULL;
  797. }
  798. /**
  799. * Scsi_Host template entry slave_alloc
  800. */
  801. static int
  802. bfad_im_slave_alloc(struct scsi_device *sdev)
  803. {
  804. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  805. if (!rport || fc_remote_port_chkready(rport))
  806. return -ENXIO;
  807. sdev->hostdata = rport->dd_data;
  808. return 0;
  809. }
  810. void
  811. bfad_os_fc_host_init(struct bfad_im_port_s *im_port)
  812. {
  813. struct Scsi_Host *host = im_port->shost;
  814. struct bfad_s *bfad = im_port->bfad;
  815. struct bfad_port_s *port = im_port->port;
  816. struct bfa_pport_attr_s pattr;
  817. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  818. char fw_ver[BFA_VERSION_LEN];
  819. fc_host_node_name(host) =
  820. bfa_os_htonll((bfa_fcs_port_get_nwwn(port->fcs_port)));
  821. fc_host_port_name(host) =
  822. bfa_os_htonll((bfa_fcs_port_get_pwwn(port->fcs_port)));
  823. fc_host_max_npiv_vports(host) = bfa_lps_get_max_vport(&bfad->bfa);
  824. fc_host_supported_classes(host) = FC_COS_CLASS3;
  825. memset(fc_host_supported_fc4s(host), 0,
  826. sizeof(fc_host_supported_fc4s(host)));
  827. if (bfad_supported_fc4s & (BFA_PORT_ROLE_FCP_IM | BFA_PORT_ROLE_FCP_TM))
  828. /* For FCP type 0x08 */
  829. fc_host_supported_fc4s(host)[2] = 1;
  830. if (bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IPFC)
  831. /* For LLC/SNAP type 0x05 */
  832. fc_host_supported_fc4s(host)[3] = 0x20;
  833. /* For fibre channel services type 0x20 */
  834. fc_host_supported_fc4s(host)[7] = 1;
  835. bfa_get_adapter_model(&bfad->bfa, model);
  836. bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
  837. sprintf(fc_host_symbolic_name(host), "Brocade %s FV%s DV%s",
  838. model, fw_ver, BFAD_DRIVER_VERSION);
  839. fc_host_supported_speeds(host) = 0;
  840. fc_host_supported_speeds(host) |=
  841. FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  842. FC_PORTSPEED_1GBIT;
  843. bfa_fcport_get_attr(&bfad->bfa, &pattr);
  844. fc_host_maxframe_size(host) = pattr.pport_cfg.maxfrsize;
  845. }
  846. static void
  847. bfad_im_fc_rport_add(struct bfad_im_port_s *im_port, struct bfad_itnim_s *itnim)
  848. {
  849. struct fc_rport_identifiers rport_ids;
  850. struct fc_rport *fc_rport;
  851. struct bfad_itnim_data_s *itnim_data;
  852. rport_ids.node_name =
  853. bfa_os_htonll(bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim));
  854. rport_ids.port_name =
  855. bfa_os_htonll(bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
  856. rport_ids.port_id =
  857. bfa_os_hton3b(bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim));
  858. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  859. itnim->fc_rport = fc_rport =
  860. fc_remote_port_add(im_port->shost, 0, &rport_ids);
  861. if (!fc_rport)
  862. return;
  863. fc_rport->maxframe_size =
  864. bfa_fcs_itnim_get_maxfrsize(&itnim->fcs_itnim);
  865. fc_rport->supported_classes = bfa_fcs_itnim_get_cos(&itnim->fcs_itnim);
  866. itnim_data = fc_rport->dd_data;
  867. itnim_data->itnim = itnim;
  868. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  869. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  870. fc_remote_port_rolechg(fc_rport, rport_ids.roles);
  871. if ((fc_rport->scsi_target_id != -1)
  872. && (fc_rport->scsi_target_id < MAX_FCP_TARGET))
  873. itnim->scsi_tgt_id = fc_rport->scsi_target_id;
  874. return;
  875. }
  876. /**
  877. * Work queue handler using FC transport service
  878. * Context: kernel
  879. */
  880. static void
  881. bfad_im_itnim_work_handler(struct work_struct *work)
  882. {
  883. struct bfad_itnim_s *itnim = container_of(work, struct bfad_itnim_s,
  884. itnim_work);
  885. struct bfad_im_s *im = itnim->im;
  886. struct bfad_s *bfad = im->bfad;
  887. struct bfad_im_port_s *im_port;
  888. unsigned long flags;
  889. struct fc_rport *fc_rport;
  890. wwn_t wwpn;
  891. u32 fcid;
  892. char wwpn_str[32], fcid_str[16];
  893. spin_lock_irqsave(&bfad->bfad_lock, flags);
  894. im_port = itnim->im_port;
  895. bfa_trc(bfad, itnim->state);
  896. switch (itnim->state) {
  897. case ITNIM_STATE_ONLINE:
  898. if (!itnim->fc_rport) {
  899. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  900. bfad_im_fc_rport_add(im_port, itnim);
  901. spin_lock_irqsave(&bfad->bfad_lock, flags);
  902. wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
  903. fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
  904. wwn2str(wwpn_str, wwpn);
  905. fcid2str(fcid_str, fcid);
  906. list_add_tail(&itnim->list_entry,
  907. &im_port->itnim_mapped_list);
  908. bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_ONLINE,
  909. im_port->shost->host_no,
  910. itnim->scsi_tgt_id,
  911. fcid_str, wwpn_str);
  912. } else {
  913. printk(KERN_WARNING
  914. "%s: itnim %llx is already in online state\n",
  915. __func__,
  916. bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
  917. }
  918. break;
  919. case ITNIM_STATE_OFFLINE_PENDING:
  920. itnim->state = ITNIM_STATE_OFFLINE;
  921. if (itnim->fc_rport) {
  922. fc_rport = itnim->fc_rport;
  923. ((struct bfad_itnim_data_s *)
  924. fc_rport->dd_data)->itnim = NULL;
  925. itnim->fc_rport = NULL;
  926. if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
  927. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  928. fc_rport->dev_loss_tmo =
  929. bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
  930. fc_remote_port_delete(fc_rport);
  931. spin_lock_irqsave(&bfad->bfad_lock, flags);
  932. }
  933. wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
  934. fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
  935. wwn2str(wwpn_str, wwpn);
  936. fcid2str(fcid_str, fcid);
  937. list_del(&itnim->list_entry);
  938. bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_OFFLINE,
  939. im_port->shost->host_no,
  940. itnim->scsi_tgt_id,
  941. fcid_str, wwpn_str);
  942. }
  943. break;
  944. case ITNIM_STATE_FREE:
  945. if (itnim->fc_rport) {
  946. fc_rport = itnim->fc_rport;
  947. ((struct bfad_itnim_data_s *)
  948. fc_rport->dd_data)->itnim = NULL;
  949. itnim->fc_rport = NULL;
  950. if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
  951. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  952. fc_rport->dev_loss_tmo =
  953. bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
  954. fc_remote_port_delete(fc_rport);
  955. spin_lock_irqsave(&bfad->bfad_lock, flags);
  956. }
  957. list_del(&itnim->list_entry);
  958. }
  959. kfree(itnim);
  960. break;
  961. default:
  962. bfa_assert(0);
  963. break;
  964. }
  965. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  966. }
  967. /**
  968. * Scsi_Host template entry, queue a SCSI command to the BFAD.
  969. */
  970. static int
  971. bfad_im_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
  972. {
  973. struct bfad_im_port_s *im_port =
  974. (struct bfad_im_port_s *) cmnd->device->host->hostdata[0];
  975. struct bfad_s *bfad = im_port->bfad;
  976. struct bfad_itnim_data_s *itnim_data = cmnd->device->hostdata;
  977. struct bfad_itnim_s *itnim;
  978. struct bfa_ioim_s *hal_io;
  979. unsigned long flags;
  980. int rc;
  981. s16 sg_cnt = 0;
  982. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  983. rc = fc_remote_port_chkready(rport);
  984. if (rc) {
  985. cmnd->result = rc;
  986. done(cmnd);
  987. return 0;
  988. }
  989. sg_cnt = scsi_dma_map(cmnd);
  990. if (sg_cnt < 0)
  991. return SCSI_MLQUEUE_HOST_BUSY;
  992. cmnd->scsi_done = done;
  993. spin_lock_irqsave(&bfad->bfad_lock, flags);
  994. if (!(bfad->bfad_flags & BFAD_HAL_START_DONE)) {
  995. printk(KERN_WARNING
  996. "bfad%d, queuecommand %p %x failed, BFA stopped\n",
  997. bfad->inst_no, cmnd, cmnd->cmnd[0]);
  998. cmnd->result = ScsiResult(DID_NO_CONNECT, 0);
  999. goto out_fail_cmd;
  1000. }
  1001. itnim = itnim_data->itnim;
  1002. if (!itnim) {
  1003. cmnd->result = ScsiResult(DID_IMM_RETRY, 0);
  1004. goto out_fail_cmd;
  1005. }
  1006. hal_io = bfa_ioim_alloc(&bfad->bfa, (struct bfad_ioim_s *) cmnd,
  1007. itnim->bfa_itnim, sg_cnt);
  1008. if (!hal_io) {
  1009. printk(KERN_WARNING "hal_io failure\n");
  1010. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1011. scsi_dma_unmap(cmnd);
  1012. return SCSI_MLQUEUE_HOST_BUSY;
  1013. }
  1014. cmnd->host_scribble = (char *)hal_io;
  1015. bfa_trc_fp(bfad, hal_io->iotag);
  1016. bfa_ioim_start(hal_io);
  1017. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1018. return 0;
  1019. out_fail_cmd:
  1020. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1021. scsi_dma_unmap(cmnd);
  1022. if (done)
  1023. done(cmnd);
  1024. return 0;
  1025. }
  1026. void
  1027. bfad_os_rport_online_wait(struct bfad_s *bfad)
  1028. {
  1029. int i;
  1030. int rport_delay = 10;
  1031. for (i = 0; !(bfad->bfad_flags & BFAD_PORT_ONLINE)
  1032. && i < bfa_linkup_delay; i++)
  1033. schedule_timeout_uninterruptible(HZ);
  1034. if (bfad->bfad_flags & BFAD_PORT_ONLINE) {
  1035. rport_delay = rport_delay < bfa_linkup_delay ?
  1036. rport_delay : bfa_linkup_delay;
  1037. for (i = 0; !(bfad->bfad_flags & BFAD_RPORT_ONLINE)
  1038. && i < rport_delay; i++)
  1039. schedule_timeout_uninterruptible(HZ);
  1040. if (rport_delay > 0 && (bfad->bfad_flags & BFAD_RPORT_ONLINE))
  1041. schedule_timeout_uninterruptible(rport_delay * HZ);
  1042. }
  1043. }
  1044. int
  1045. bfad_os_get_linkup_delay(struct bfad_s *bfad)
  1046. {
  1047. u8 nwwns = 0;
  1048. wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
  1049. int ldelay;
  1050. /*
  1051. * Querying for the boot target port wwns
  1052. * -- read from boot information in flash.
  1053. * If nwwns > 0 => boot over SAN and set bfa_linkup_delay = 30
  1054. * else => local boot machine set bfa_linkup_delay = 10
  1055. */
  1056. bfa_iocfc_get_bootwwns(&bfad->bfa, &nwwns, wwns);
  1057. if (nwwns > 0) {
  1058. /* If boot over SAN; linkup_delay = 30sec */
  1059. ldelay = 30;
  1060. } else {
  1061. /* If local boot; linkup_delay = 10sec */
  1062. ldelay = 0;
  1063. }
  1064. return ldelay;
  1065. }