bfad_im.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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(im_port->shost, 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. if (im_port->port->pvb_type != BFAD_PORT_PHYS_BASE) {
  522. im_port->flags |= BFAD_PORT_DELETE;
  523. fc_vport_terminate(im_port->fc_vport);
  524. }
  525. }
  526. bfa_status_t
  527. bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port)
  528. {
  529. int rc = BFA_STATUS_OK;
  530. struct bfad_im_port_s *im_port;
  531. im_port = kzalloc(sizeof(struct bfad_im_port_s), GFP_ATOMIC);
  532. if (im_port == NULL) {
  533. rc = BFA_STATUS_ENOMEM;
  534. goto ext;
  535. }
  536. port->im_port = im_port;
  537. im_port->port = port;
  538. im_port->bfad = bfad;
  539. INIT_WORK(&im_port->port_delete_work, bfad_im_port_delete_handler);
  540. INIT_LIST_HEAD(&im_port->itnim_mapped_list);
  541. INIT_LIST_HEAD(&im_port->binding_list);
  542. ext:
  543. return rc;
  544. }
  545. void
  546. bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port)
  547. {
  548. struct bfad_im_port_s *im_port = port->im_port;
  549. queue_work(bfad->im->drv_workq,
  550. &im_port->port_delete_work);
  551. }
  552. void
  553. bfad_im_port_clean(struct bfad_im_port_s *im_port)
  554. {
  555. struct bfad_fcp_binding *bp, *bp_new;
  556. unsigned long flags;
  557. struct bfad_s *bfad = im_port->bfad;
  558. spin_lock_irqsave(&bfad->bfad_lock, flags);
  559. list_for_each_entry_safe(bp, bp_new, &im_port->binding_list,
  560. list_entry) {
  561. list_del(&bp->list_entry);
  562. kfree(bp);
  563. }
  564. /* the itnim_mapped_list must be empty at this time */
  565. bfa_assert(list_empty(&im_port->itnim_mapped_list));
  566. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  567. }
  568. void
  569. bfad_im_port_online(struct bfad_s *bfad, struct bfad_port_s *port)
  570. {
  571. }
  572. void
  573. bfad_im_port_offline(struct bfad_s *bfad, struct bfad_port_s *port)
  574. {
  575. }
  576. bfa_status_t
  577. bfad_im_probe(struct bfad_s *bfad)
  578. {
  579. struct bfad_im_s *im;
  580. bfa_status_t rc = BFA_STATUS_OK;
  581. im = kzalloc(sizeof(struct bfad_im_s), GFP_KERNEL);
  582. if (im == NULL) {
  583. rc = BFA_STATUS_ENOMEM;
  584. goto ext;
  585. }
  586. bfad->im = im;
  587. im->bfad = bfad;
  588. if (bfad_os_thread_workq(bfad) != BFA_STATUS_OK) {
  589. kfree(im);
  590. rc = BFA_STATUS_FAILED;
  591. }
  592. ext:
  593. return rc;
  594. }
  595. void
  596. bfad_im_probe_undo(struct bfad_s *bfad)
  597. {
  598. if (bfad->im) {
  599. bfad_os_destroy_workq(bfad->im);
  600. kfree(bfad->im);
  601. bfad->im = NULL;
  602. }
  603. }
  604. /**
  605. * Call back function to handle IO redirection state change
  606. */
  607. void
  608. bfa_cb_ioredirect_state_change(void *hcb_bfad, bfa_boolean_t ioredirect)
  609. {
  610. /* Do nothing */
  611. }
  612. struct Scsi_Host *
  613. bfad_os_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *bfad)
  614. {
  615. struct scsi_host_template *sht;
  616. if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
  617. sht = &bfad_im_scsi_host_template;
  618. else
  619. sht = &bfad_im_vport_template;
  620. sht->sg_tablesize = bfad->cfg_data.io_max_sge;
  621. return scsi_host_alloc(sht, sizeof(unsigned long));
  622. }
  623. void
  624. bfad_os_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
  625. {
  626. if (!(im_port->flags & BFAD_PORT_DELETE))
  627. flush_workqueue(bfad->im->drv_workq);
  628. bfad_im_scsi_host_free(im_port->bfad, im_port);
  629. bfad_im_port_clean(im_port);
  630. kfree(im_port);
  631. }
  632. void
  633. bfad_os_destroy_workq(struct bfad_im_s *im)
  634. {
  635. if (im && im->drv_workq) {
  636. destroy_workqueue(im->drv_workq);
  637. im->drv_workq = NULL;
  638. }
  639. }
  640. bfa_status_t
  641. bfad_os_thread_workq(struct bfad_s *bfad)
  642. {
  643. struct bfad_im_s *im = bfad->im;
  644. bfa_trc(bfad, 0);
  645. snprintf(im->drv_workq_name, BFAD_KOBJ_NAME_LEN, "bfad_wq_%d",
  646. bfad->inst_no);
  647. im->drv_workq = create_singlethread_workqueue(im->drv_workq_name);
  648. if (!im->drv_workq)
  649. return BFA_STATUS_FAILED;
  650. return BFA_STATUS_OK;
  651. }
  652. /**
  653. * Scsi_Host template entry.
  654. *
  655. * Description:
  656. * OS entry point to adjust the queue_depths on a per-device basis.
  657. * Called once per device during the bus scan.
  658. * Return non-zero if fails.
  659. */
  660. static int
  661. bfad_im_slave_configure(struct scsi_device *sdev)
  662. {
  663. if (sdev->tagged_supported)
  664. scsi_activate_tcq(sdev, bfa_lun_queue_depth);
  665. else
  666. scsi_deactivate_tcq(sdev, bfa_lun_queue_depth);
  667. return 0;
  668. }
  669. struct scsi_host_template bfad_im_scsi_host_template = {
  670. .module = THIS_MODULE,
  671. .name = BFAD_DRIVER_NAME,
  672. .info = bfad_im_info,
  673. .queuecommand = bfad_im_queuecommand,
  674. .eh_abort_handler = bfad_im_abort_handler,
  675. .eh_device_reset_handler = bfad_im_reset_lun_handler,
  676. .eh_bus_reset_handler = bfad_im_reset_bus_handler,
  677. .slave_alloc = bfad_im_slave_alloc,
  678. .slave_configure = bfad_im_slave_configure,
  679. .slave_destroy = bfad_im_slave_destroy,
  680. .this_id = -1,
  681. .sg_tablesize = BFAD_IO_MAX_SGE,
  682. .cmd_per_lun = 3,
  683. .use_clustering = ENABLE_CLUSTERING,
  684. .shost_attrs = bfad_im_host_attrs,
  685. .max_sectors = 0xFFFF,
  686. };
  687. struct scsi_host_template bfad_im_vport_template = {
  688. .module = THIS_MODULE,
  689. .name = BFAD_DRIVER_NAME,
  690. .info = bfad_im_info,
  691. .queuecommand = bfad_im_queuecommand,
  692. .eh_abort_handler = bfad_im_abort_handler,
  693. .eh_device_reset_handler = bfad_im_reset_lun_handler,
  694. .eh_bus_reset_handler = bfad_im_reset_bus_handler,
  695. .slave_alloc = bfad_im_slave_alloc,
  696. .slave_configure = bfad_im_slave_configure,
  697. .slave_destroy = bfad_im_slave_destroy,
  698. .this_id = -1,
  699. .sg_tablesize = BFAD_IO_MAX_SGE,
  700. .cmd_per_lun = 3,
  701. .use_clustering = ENABLE_CLUSTERING,
  702. .shost_attrs = bfad_im_vport_attrs,
  703. .max_sectors = 0xFFFF,
  704. };
  705. void
  706. bfad_im_probe_post(struct bfad_im_s *im)
  707. {
  708. flush_workqueue(im->drv_workq);
  709. }
  710. bfa_status_t
  711. bfad_im_module_init(void)
  712. {
  713. bfad_im_scsi_transport_template =
  714. fc_attach_transport(&bfad_im_fc_function_template);
  715. if (!bfad_im_scsi_transport_template)
  716. return BFA_STATUS_ENOMEM;
  717. bfad_im_scsi_vport_transport_template =
  718. fc_attach_transport(&bfad_im_vport_fc_function_template);
  719. if (!bfad_im_scsi_vport_transport_template) {
  720. fc_release_transport(bfad_im_scsi_transport_template);
  721. return BFA_STATUS_ENOMEM;
  722. }
  723. return BFA_STATUS_OK;
  724. }
  725. void
  726. bfad_im_module_exit(void)
  727. {
  728. if (bfad_im_scsi_transport_template)
  729. fc_release_transport(bfad_im_scsi_transport_template);
  730. if (bfad_im_scsi_vport_transport_template)
  731. fc_release_transport(bfad_im_scsi_vport_transport_template);
  732. }
  733. void
  734. bfad_os_itnim_process(struct bfad_itnim_s *itnim_drv)
  735. {
  736. struct bfad_im_s *im = itnim_drv->im;
  737. if (itnim_drv->queue_work)
  738. queue_work(im->drv_workq, &itnim_drv->itnim_work);
  739. }
  740. void
  741. bfad_os_ramp_up_qdepth(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
  742. {
  743. struct scsi_device *tmp_sdev;
  744. if (((jiffies - itnim->last_ramp_up_time) >
  745. BFA_QUEUE_FULL_RAMP_UP_TIME * HZ) &&
  746. ((jiffies - itnim->last_queue_full_time) >
  747. BFA_QUEUE_FULL_RAMP_UP_TIME * HZ)) {
  748. shost_for_each_device(tmp_sdev, sdev->host) {
  749. if (bfa_lun_queue_depth > tmp_sdev->queue_depth) {
  750. if (tmp_sdev->id != sdev->id)
  751. continue;
  752. if (tmp_sdev->ordered_tags)
  753. scsi_adjust_queue_depth(tmp_sdev,
  754. MSG_ORDERED_TAG,
  755. tmp_sdev->queue_depth + 1);
  756. else
  757. scsi_adjust_queue_depth(tmp_sdev,
  758. MSG_SIMPLE_TAG,
  759. tmp_sdev->queue_depth + 1);
  760. itnim->last_ramp_up_time = jiffies;
  761. }
  762. }
  763. }
  764. }
  765. void
  766. bfad_os_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
  767. {
  768. struct scsi_device *tmp_sdev;
  769. itnim->last_queue_full_time = jiffies;
  770. shost_for_each_device(tmp_sdev, sdev->host) {
  771. if (tmp_sdev->id != sdev->id)
  772. continue;
  773. scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
  774. }
  775. }
  776. struct bfad_itnim_s *
  777. bfad_os_get_itnim(struct bfad_im_port_s *im_port, int id)
  778. {
  779. struct bfad_itnim_s *itnim = NULL;
  780. /* Search the mapped list for this target ID */
  781. list_for_each_entry(itnim, &im_port->itnim_mapped_list, list_entry) {
  782. if (id == itnim->scsi_tgt_id)
  783. return itnim;
  784. }
  785. return NULL;
  786. }
  787. /**
  788. * Scsi_Host template entry slave_alloc
  789. */
  790. static int
  791. bfad_im_slave_alloc(struct scsi_device *sdev)
  792. {
  793. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  794. if (!rport || fc_remote_port_chkready(rport))
  795. return -ENXIO;
  796. sdev->hostdata = rport->dd_data;
  797. return 0;
  798. }
  799. void
  800. bfad_os_fc_host_init(struct bfad_im_port_s *im_port)
  801. {
  802. struct Scsi_Host *host = im_port->shost;
  803. struct bfad_s *bfad = im_port->bfad;
  804. struct bfad_port_s *port = im_port->port;
  805. struct bfa_pport_attr_s pattr;
  806. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  807. char fw_ver[BFA_VERSION_LEN];
  808. fc_host_node_name(host) =
  809. bfa_os_htonll((bfa_fcs_port_get_nwwn(port->fcs_port)));
  810. fc_host_port_name(host) =
  811. bfa_os_htonll((bfa_fcs_port_get_pwwn(port->fcs_port)));
  812. fc_host_max_npiv_vports(host) = bfa_lps_get_max_vport(&bfad->bfa);
  813. fc_host_supported_classes(host) = FC_COS_CLASS3;
  814. memset(fc_host_supported_fc4s(host), 0,
  815. sizeof(fc_host_supported_fc4s(host)));
  816. if (bfad_supported_fc4s & (BFA_PORT_ROLE_FCP_IM | BFA_PORT_ROLE_FCP_TM))
  817. /* For FCP type 0x08 */
  818. fc_host_supported_fc4s(host)[2] = 1;
  819. if (bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IPFC)
  820. /* For LLC/SNAP type 0x05 */
  821. fc_host_supported_fc4s(host)[3] = 0x20;
  822. /* For fibre channel services type 0x20 */
  823. fc_host_supported_fc4s(host)[7] = 1;
  824. bfa_get_adapter_model(&bfad->bfa, model);
  825. bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
  826. sprintf(fc_host_symbolic_name(host), "Brocade %s FV%s DV%s",
  827. model, fw_ver, BFAD_DRIVER_VERSION);
  828. fc_host_supported_speeds(host) = 0;
  829. fc_host_supported_speeds(host) |=
  830. FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  831. FC_PORTSPEED_1GBIT;
  832. bfa_fcport_get_attr(&bfad->bfa, &pattr);
  833. fc_host_maxframe_size(host) = pattr.pport_cfg.maxfrsize;
  834. }
  835. static void
  836. bfad_im_fc_rport_add(struct bfad_im_port_s *im_port, struct bfad_itnim_s *itnim)
  837. {
  838. struct fc_rport_identifiers rport_ids;
  839. struct fc_rport *fc_rport;
  840. struct bfad_itnim_data_s *itnim_data;
  841. rport_ids.node_name =
  842. bfa_os_htonll(bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim));
  843. rport_ids.port_name =
  844. bfa_os_htonll(bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
  845. rport_ids.port_id =
  846. bfa_os_hton3b(bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim));
  847. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  848. itnim->fc_rport = fc_rport =
  849. fc_remote_port_add(im_port->shost, 0, &rport_ids);
  850. if (!fc_rport)
  851. return;
  852. fc_rport->maxframe_size =
  853. bfa_fcs_itnim_get_maxfrsize(&itnim->fcs_itnim);
  854. fc_rport->supported_classes = bfa_fcs_itnim_get_cos(&itnim->fcs_itnim);
  855. itnim_data = fc_rport->dd_data;
  856. itnim_data->itnim = itnim;
  857. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  858. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  859. fc_remote_port_rolechg(fc_rport, rport_ids.roles);
  860. if ((fc_rport->scsi_target_id != -1)
  861. && (fc_rport->scsi_target_id < MAX_FCP_TARGET))
  862. itnim->scsi_tgt_id = fc_rport->scsi_target_id;
  863. return;
  864. }
  865. /**
  866. * Work queue handler using FC transport service
  867. * Context: kernel
  868. */
  869. static void
  870. bfad_im_itnim_work_handler(struct work_struct *work)
  871. {
  872. struct bfad_itnim_s *itnim = container_of(work, struct bfad_itnim_s,
  873. itnim_work);
  874. struct bfad_im_s *im = itnim->im;
  875. struct bfad_s *bfad = im->bfad;
  876. struct bfad_im_port_s *im_port;
  877. unsigned long flags;
  878. struct fc_rport *fc_rport;
  879. wwn_t wwpn;
  880. u32 fcid;
  881. char wwpn_str[32], fcid_str[16];
  882. spin_lock_irqsave(&bfad->bfad_lock, flags);
  883. im_port = itnim->im_port;
  884. bfa_trc(bfad, itnim->state);
  885. switch (itnim->state) {
  886. case ITNIM_STATE_ONLINE:
  887. if (!itnim->fc_rport) {
  888. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  889. bfad_im_fc_rport_add(im_port, itnim);
  890. spin_lock_irqsave(&bfad->bfad_lock, flags);
  891. wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
  892. fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
  893. wwn2str(wwpn_str, wwpn);
  894. fcid2str(fcid_str, fcid);
  895. list_add_tail(&itnim->list_entry,
  896. &im_port->itnim_mapped_list);
  897. bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_ONLINE,
  898. im_port->shost->host_no,
  899. itnim->scsi_tgt_id,
  900. fcid_str, wwpn_str);
  901. } else {
  902. printk(KERN_WARNING
  903. "%s: itnim %llx is already in online state\n",
  904. __func__,
  905. bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
  906. }
  907. break;
  908. case ITNIM_STATE_OFFLINE_PENDING:
  909. itnim->state = ITNIM_STATE_OFFLINE;
  910. if (itnim->fc_rport) {
  911. fc_rport = itnim->fc_rport;
  912. ((struct bfad_itnim_data_s *)
  913. fc_rport->dd_data)->itnim = NULL;
  914. itnim->fc_rport = NULL;
  915. if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
  916. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  917. fc_rport->dev_loss_tmo =
  918. bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
  919. fc_remote_port_delete(fc_rport);
  920. spin_lock_irqsave(&bfad->bfad_lock, flags);
  921. }
  922. wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
  923. fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
  924. wwn2str(wwpn_str, wwpn);
  925. fcid2str(fcid_str, fcid);
  926. list_del(&itnim->list_entry);
  927. bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_OFFLINE,
  928. im_port->shost->host_no,
  929. itnim->scsi_tgt_id,
  930. fcid_str, wwpn_str);
  931. }
  932. break;
  933. case ITNIM_STATE_FREE:
  934. if (itnim->fc_rport) {
  935. fc_rport = itnim->fc_rport;
  936. ((struct bfad_itnim_data_s *)
  937. fc_rport->dd_data)->itnim = NULL;
  938. itnim->fc_rport = NULL;
  939. if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
  940. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  941. fc_rport->dev_loss_tmo =
  942. bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
  943. fc_remote_port_delete(fc_rport);
  944. spin_lock_irqsave(&bfad->bfad_lock, flags);
  945. }
  946. list_del(&itnim->list_entry);
  947. }
  948. kfree(itnim);
  949. break;
  950. default:
  951. bfa_assert(0);
  952. break;
  953. }
  954. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  955. }
  956. /**
  957. * Scsi_Host template entry, queue a SCSI command to the BFAD.
  958. */
  959. static int
  960. bfad_im_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
  961. {
  962. struct bfad_im_port_s *im_port =
  963. (struct bfad_im_port_s *) cmnd->device->host->hostdata[0];
  964. struct bfad_s *bfad = im_port->bfad;
  965. struct bfad_itnim_data_s *itnim_data = cmnd->device->hostdata;
  966. struct bfad_itnim_s *itnim;
  967. struct bfa_ioim_s *hal_io;
  968. unsigned long flags;
  969. int rc;
  970. s16 sg_cnt = 0;
  971. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  972. rc = fc_remote_port_chkready(rport);
  973. if (rc) {
  974. cmnd->result = rc;
  975. done(cmnd);
  976. return 0;
  977. }
  978. sg_cnt = scsi_dma_map(cmnd);
  979. if (sg_cnt < 0)
  980. return SCSI_MLQUEUE_HOST_BUSY;
  981. cmnd->scsi_done = done;
  982. spin_lock_irqsave(&bfad->bfad_lock, flags);
  983. if (!(bfad->bfad_flags & BFAD_HAL_START_DONE)) {
  984. printk(KERN_WARNING
  985. "bfad%d, queuecommand %p %x failed, BFA stopped\n",
  986. bfad->inst_no, cmnd, cmnd->cmnd[0]);
  987. cmnd->result = ScsiResult(DID_NO_CONNECT, 0);
  988. goto out_fail_cmd;
  989. }
  990. itnim = itnim_data->itnim;
  991. if (!itnim) {
  992. cmnd->result = ScsiResult(DID_IMM_RETRY, 0);
  993. goto out_fail_cmd;
  994. }
  995. hal_io = bfa_ioim_alloc(&bfad->bfa, (struct bfad_ioim_s *) cmnd,
  996. itnim->bfa_itnim, sg_cnt);
  997. if (!hal_io) {
  998. printk(KERN_WARNING "hal_io failure\n");
  999. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1000. scsi_dma_unmap(cmnd);
  1001. return SCSI_MLQUEUE_HOST_BUSY;
  1002. }
  1003. cmnd->host_scribble = (char *)hal_io;
  1004. bfa_trc_fp(bfad, hal_io->iotag);
  1005. bfa_ioim_start(hal_io);
  1006. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1007. return 0;
  1008. out_fail_cmd:
  1009. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  1010. scsi_dma_unmap(cmnd);
  1011. if (done)
  1012. done(cmnd);
  1013. return 0;
  1014. }
  1015. void
  1016. bfad_os_rport_online_wait(struct bfad_s *bfad)
  1017. {
  1018. int i;
  1019. int rport_delay = 10;
  1020. for (i = 0; !(bfad->bfad_flags & BFAD_PORT_ONLINE)
  1021. && i < bfa_linkup_delay; i++)
  1022. schedule_timeout_uninterruptible(HZ);
  1023. if (bfad->bfad_flags & BFAD_PORT_ONLINE) {
  1024. rport_delay = rport_delay < bfa_linkup_delay ?
  1025. rport_delay : bfa_linkup_delay;
  1026. for (i = 0; !(bfad->bfad_flags & BFAD_RPORT_ONLINE)
  1027. && i < rport_delay; i++)
  1028. schedule_timeout_uninterruptible(HZ);
  1029. if (rport_delay > 0 && (bfad->bfad_flags & BFAD_RPORT_ONLINE))
  1030. schedule_timeout_uninterruptible(rport_delay * HZ);
  1031. }
  1032. }
  1033. int
  1034. bfad_os_get_linkup_delay(struct bfad_s *bfad)
  1035. {
  1036. u8 nwwns = 0;
  1037. wwn_t wwns[BFA_PREBOOT_BOOTLUN_MAX];
  1038. int ldelay;
  1039. /*
  1040. * Querying for the boot target port wwns
  1041. * -- read from boot information in flash.
  1042. * If nwwns > 0 => boot over SAN and set bfa_linkup_delay = 30
  1043. * else => local boot machine set bfa_linkup_delay = 10
  1044. */
  1045. bfa_iocfc_get_bootwwns(&bfad->bfa, &nwwns, wwns);
  1046. if (nwwns > 0) {
  1047. /* If boot over SAN; linkup_delay = 30sec */
  1048. ldelay = 30;
  1049. } else {
  1050. /* If local boot; linkup_delay = 10sec */
  1051. ldelay = 0;
  1052. }
  1053. return ldelay;
  1054. }