bfad_im.c 31 KB

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