bfad_im.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  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. static void bfad_im_itnim_work_handler(struct work_struct *work);
  30. static int bfad_im_queuecommand(struct scsi_cmnd *cmnd,
  31. void (*done)(struct scsi_cmnd *));
  32. static int bfad_im_slave_alloc(struct scsi_device *sdev);
  33. void
  34. bfa_cb_ioim_done(void *drv, struct bfad_ioim_s *dio,
  35. enum bfi_ioim_status io_status, u8 scsi_status,
  36. int sns_len, u8 *sns_info, s32 residue)
  37. {
  38. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  39. struct bfad_s *bfad = drv;
  40. struct bfad_itnim_data_s *itnim_data;
  41. struct bfad_itnim_s *itnim;
  42. u8 host_status = DID_OK;
  43. switch (io_status) {
  44. case BFI_IOIM_STS_OK:
  45. bfa_trc(bfad, scsi_status);
  46. scsi_set_resid(cmnd, 0);
  47. if (sns_len > 0) {
  48. bfa_trc(bfad, sns_len);
  49. if (sns_len > SCSI_SENSE_BUFFERSIZE)
  50. sns_len = SCSI_SENSE_BUFFERSIZE;
  51. memcpy(cmnd->sense_buffer, sns_info, sns_len);
  52. }
  53. if (residue > 0) {
  54. bfa_trc(bfad, residue);
  55. scsi_set_resid(cmnd, residue);
  56. if (!sns_len && (scsi_status == SAM_STAT_GOOD) &&
  57. (scsi_bufflen(cmnd) - residue) <
  58. cmnd->underflow) {
  59. bfa_trc(bfad, 0);
  60. host_status = DID_ERROR;
  61. }
  62. }
  63. cmnd->result = ScsiResult(host_status, scsi_status);
  64. break;
  65. case BFI_IOIM_STS_ABORTED:
  66. case BFI_IOIM_STS_TIMEDOUT:
  67. case BFI_IOIM_STS_PATHTOV:
  68. default:
  69. cmnd->result = ScsiResult(DID_ERROR, 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_os_ramp_up_qdepth(itnim, cmnd->device);
  83. } else if (cmnd->result == SAM_STAT_TASK_SET_FULL && itnim) {
  84. /* qfull handling */
  85. bfad_os_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_os_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. void
  138. bfa_cb_ioim_resfree(void *drv)
  139. {
  140. }
  141. /**
  142. * Scsi_Host_template SCSI host template
  143. */
  144. /**
  145. * Scsi_Host template entry, returns BFAD PCI info.
  146. */
  147. static const char *
  148. bfad_im_info(struct Scsi_Host *shost)
  149. {
  150. static char bfa_buf[256];
  151. struct bfad_im_port_s *im_port =
  152. (struct bfad_im_port_s *) shost->hostdata[0];
  153. struct bfad_s *bfad = im_port->bfad;
  154. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  155. bfa_get_adapter_model(&bfad->bfa, model);
  156. memset(bfa_buf, 0, sizeof(bfa_buf));
  157. snprintf(bfa_buf, sizeof(bfa_buf),
  158. "Brocade FC/FCOE Adapter, " "model: %s hwpath: %s driver: %s",
  159. model, bfad->pci_name, BFAD_DRIVER_VERSION);
  160. return bfa_buf;
  161. }
  162. /**
  163. * Scsi_Host template entry, aborts the specified SCSI command.
  164. *
  165. * Returns: SUCCESS or FAILED.
  166. */
  167. static int
  168. bfad_im_abort_handler(struct scsi_cmnd *cmnd)
  169. {
  170. struct Scsi_Host *shost = cmnd->device->host;
  171. struct bfad_im_port_s *im_port =
  172. (struct bfad_im_port_s *) shost->hostdata[0];
  173. struct bfad_s *bfad = im_port->bfad;
  174. struct bfa_ioim_s *hal_io;
  175. unsigned long flags;
  176. u32 timeout;
  177. int rc = FAILED;
  178. spin_lock_irqsave(&bfad->bfad_lock, flags);
  179. hal_io = (struct bfa_ioim_s *) cmnd->host_scribble;
  180. if (!hal_io) {
  181. /* IO has been completed, retrun success */
  182. rc = SUCCESS;
  183. goto out;
  184. }
  185. if (hal_io->dio != (struct bfad_ioim_s *) cmnd) {
  186. rc = FAILED;
  187. goto out;
  188. }
  189. bfa_trc(bfad, hal_io->iotag);
  190. bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_ABORT,
  191. im_port->shost->host_no, cmnd, hal_io->iotag);
  192. bfa_ioim_abort(hal_io);
  193. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  194. /* Need to wait until the command get aborted */
  195. timeout = 10;
  196. while ((struct bfa_ioim_s *) cmnd->host_scribble == hal_io) {
  197. set_current_state(TASK_UNINTERRUPTIBLE);
  198. schedule_timeout(timeout);
  199. if (timeout < 4 * HZ)
  200. timeout *= 2;
  201. }
  202. cmnd->scsi_done(cmnd);
  203. bfa_trc(bfad, hal_io->iotag);
  204. bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_ABORT_COMP,
  205. im_port->shost->host_no, cmnd, hal_io->iotag);
  206. return SUCCESS;
  207. out:
  208. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  209. return rc;
  210. }
  211. static bfa_status_t
  212. bfad_im_target_reset_send(struct bfad_s *bfad, struct scsi_cmnd *cmnd,
  213. struct bfad_itnim_s *itnim)
  214. {
  215. struct bfa_tskim_s *tskim;
  216. struct bfa_itnim_s *bfa_itnim;
  217. bfa_status_t rc = BFA_STATUS_OK;
  218. bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim->fcs_itnim);
  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. {
  452. int error = 1;
  453. if (!idr_pre_get(&bfad_im_port_index, GFP_KERNEL)) {
  454. printk(KERN_WARNING "idr_pre_get failure\n");
  455. goto out;
  456. }
  457. error = idr_get_new(&bfad_im_port_index, im_port,
  458. &im_port->idr_id);
  459. if (error) {
  460. printk(KERN_WARNING "idr_get_new failure\n");
  461. goto out;
  462. }
  463. im_port->shost = bfad_os_scsi_host_alloc(im_port, bfad);
  464. if (!im_port->shost) {
  465. error = 1;
  466. goto out_free_idr;
  467. }
  468. im_port->shost->hostdata[0] = (unsigned long)im_port;
  469. im_port->shost->unique_id = im_port->idr_id;
  470. im_port->shost->this_id = -1;
  471. im_port->shost->max_id = MAX_FCP_TARGET;
  472. im_port->shost->max_lun = MAX_FCP_LUN;
  473. im_port->shost->max_cmd_len = 16;
  474. im_port->shost->can_queue = bfad->cfg_data.ioc_queue_depth;
  475. im_port->shost->transportt = bfad_im_scsi_transport_template;
  476. error = bfad_os_scsi_add_host(im_port->shost, im_port, bfad);
  477. if (error) {
  478. printk(KERN_WARNING "bfad_os_scsi_add_host failure %d\n",
  479. error);
  480. goto out_fc_rel;
  481. }
  482. /* setup host fixed attribute if the lk supports */
  483. bfad_os_fc_host_init(im_port);
  484. return 0;
  485. out_fc_rel:
  486. scsi_host_put(im_port->shost);
  487. out_free_idr:
  488. idr_remove(&bfad_im_port_index, im_port->idr_id);
  489. out:
  490. return error;
  491. }
  492. void
  493. bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
  494. {
  495. unsigned long flags;
  496. bfa_trc(bfad, bfad->inst_no);
  497. bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_HOST_FREE,
  498. im_port->shost->host_no);
  499. fc_remove_host(im_port->shost);
  500. scsi_remove_host(im_port->shost);
  501. scsi_host_put(im_port->shost);
  502. spin_lock_irqsave(&bfad->bfad_lock, flags);
  503. idr_remove(&bfad_im_port_index, im_port->idr_id);
  504. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  505. }
  506. static void
  507. bfad_im_port_delete_handler(struct work_struct *work)
  508. {
  509. struct bfad_im_port_s *im_port =
  510. container_of(work, struct bfad_im_port_s, port_delete_work);
  511. bfad_im_scsi_host_free(im_port->bfad, im_port);
  512. bfad_im_port_clean(im_port);
  513. kfree(im_port);
  514. }
  515. bfa_status_t
  516. bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port)
  517. {
  518. int rc = BFA_STATUS_OK;
  519. struct bfad_im_port_s *im_port;
  520. im_port = kzalloc(sizeof(struct bfad_im_port_s), GFP_ATOMIC);
  521. if (im_port == NULL) {
  522. rc = BFA_STATUS_ENOMEM;
  523. goto ext;
  524. }
  525. port->im_port = im_port;
  526. im_port->port = port;
  527. im_port->bfad = bfad;
  528. INIT_WORK(&im_port->port_delete_work, bfad_im_port_delete_handler);
  529. INIT_LIST_HEAD(&im_port->itnim_mapped_list);
  530. INIT_LIST_HEAD(&im_port->binding_list);
  531. ext:
  532. return rc;
  533. }
  534. void
  535. bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port)
  536. {
  537. struct bfad_im_port_s *im_port = port->im_port;
  538. queue_work(bfad->im->drv_workq,
  539. &im_port->port_delete_work);
  540. }
  541. void
  542. bfad_im_port_clean(struct bfad_im_port_s *im_port)
  543. {
  544. struct bfad_fcp_binding *bp, *bp_new;
  545. unsigned long flags;
  546. struct bfad_s *bfad = im_port->bfad;
  547. spin_lock_irqsave(&bfad->bfad_lock, flags);
  548. list_for_each_entry_safe(bp, bp_new, &im_port->binding_list,
  549. list_entry) {
  550. list_del(&bp->list_entry);
  551. kfree(bp);
  552. }
  553. /* the itnim_mapped_list must be empty at this time */
  554. bfa_assert(list_empty(&im_port->itnim_mapped_list));
  555. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  556. }
  557. void
  558. bfad_im_port_online(struct bfad_s *bfad, struct bfad_port_s *port)
  559. {
  560. }
  561. void
  562. bfad_im_port_offline(struct bfad_s *bfad, struct bfad_port_s *port)
  563. {
  564. }
  565. bfa_status_t
  566. bfad_im_probe(struct bfad_s *bfad)
  567. {
  568. struct bfad_im_s *im;
  569. bfa_status_t rc = BFA_STATUS_OK;
  570. im = kzalloc(sizeof(struct bfad_im_s), GFP_KERNEL);
  571. if (im == NULL) {
  572. rc = BFA_STATUS_ENOMEM;
  573. goto ext;
  574. }
  575. bfad->im = im;
  576. im->bfad = bfad;
  577. if (bfad_os_thread_workq(bfad) != BFA_STATUS_OK) {
  578. kfree(im);
  579. rc = BFA_STATUS_FAILED;
  580. }
  581. ext:
  582. return rc;
  583. }
  584. void
  585. bfad_im_probe_undo(struct bfad_s *bfad)
  586. {
  587. if (bfad->im) {
  588. bfad_os_destroy_workq(bfad->im);
  589. kfree(bfad->im);
  590. bfad->im = NULL;
  591. }
  592. }
  593. int
  594. bfad_os_scsi_add_host(struct Scsi_Host *shost, struct bfad_im_port_s *im_port,
  595. struct bfad_s *bfad)
  596. {
  597. struct device *dev;
  598. if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
  599. dev = &bfad->pcidev->dev;
  600. else
  601. dev = &bfad->pport.im_port->shost->shost_gendev;
  602. return scsi_add_host(shost, dev);
  603. }
  604. struct Scsi_Host *
  605. bfad_os_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *bfad)
  606. {
  607. struct scsi_host_template *sht;
  608. if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
  609. sht = &bfad_im_scsi_host_template;
  610. else
  611. sht = &bfad_im_vport_template;
  612. sht->sg_tablesize = bfad->cfg_data.io_max_sge;
  613. return scsi_host_alloc(sht, sizeof(unsigned long));
  614. }
  615. void
  616. bfad_os_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
  617. {
  618. flush_workqueue(bfad->im->drv_workq);
  619. bfad_im_scsi_host_free(im_port->bfad, im_port);
  620. bfad_im_port_clean(im_port);
  621. kfree(im_port);
  622. }
  623. void
  624. bfad_os_destroy_workq(struct bfad_im_s *im)
  625. {
  626. if (im && im->drv_workq) {
  627. destroy_workqueue(im->drv_workq);
  628. im->drv_workq = NULL;
  629. }
  630. }
  631. bfa_status_t
  632. bfad_os_thread_workq(struct bfad_s *bfad)
  633. {
  634. struct bfad_im_s *im = bfad->im;
  635. bfa_trc(bfad, 0);
  636. snprintf(im->drv_workq_name, BFAD_KOBJ_NAME_LEN, "bfad_wq_%d",
  637. bfad->inst_no);
  638. im->drv_workq = create_singlethread_workqueue(im->drv_workq_name);
  639. if (!im->drv_workq)
  640. return BFA_STATUS_FAILED;
  641. return BFA_STATUS_OK;
  642. }
  643. /**
  644. * Scsi_Host template entry.
  645. *
  646. * Description:
  647. * OS entry point to adjust the queue_depths on a per-device basis.
  648. * Called once per device during the bus scan.
  649. * Return non-zero if fails.
  650. */
  651. static int
  652. bfad_im_slave_configure(struct scsi_device *sdev)
  653. {
  654. if (sdev->tagged_supported)
  655. scsi_activate_tcq(sdev, bfa_lun_queue_depth);
  656. else
  657. scsi_deactivate_tcq(sdev, bfa_lun_queue_depth);
  658. return 0;
  659. }
  660. struct scsi_host_template bfad_im_scsi_host_template = {
  661. .module = THIS_MODULE,
  662. .name = BFAD_DRIVER_NAME,
  663. .info = bfad_im_info,
  664. .queuecommand = bfad_im_queuecommand,
  665. .eh_abort_handler = bfad_im_abort_handler,
  666. .eh_device_reset_handler = bfad_im_reset_lun_handler,
  667. .eh_bus_reset_handler = bfad_im_reset_bus_handler,
  668. .slave_alloc = bfad_im_slave_alloc,
  669. .slave_configure = bfad_im_slave_configure,
  670. .slave_destroy = bfad_im_slave_destroy,
  671. .this_id = -1,
  672. .sg_tablesize = BFAD_IO_MAX_SGE,
  673. .cmd_per_lun = 3,
  674. .use_clustering = ENABLE_CLUSTERING,
  675. .shost_attrs = bfad_im_host_attrs,
  676. .max_sectors = 0xFFFF,
  677. };
  678. struct scsi_host_template bfad_im_vport_template = {
  679. .module = THIS_MODULE,
  680. .name = BFAD_DRIVER_NAME,
  681. .info = bfad_im_info,
  682. .queuecommand = bfad_im_queuecommand,
  683. .eh_abort_handler = bfad_im_abort_handler,
  684. .eh_device_reset_handler = bfad_im_reset_lun_handler,
  685. .eh_bus_reset_handler = bfad_im_reset_bus_handler,
  686. .slave_alloc = bfad_im_slave_alloc,
  687. .slave_configure = bfad_im_slave_configure,
  688. .slave_destroy = bfad_im_slave_destroy,
  689. .this_id = -1,
  690. .sg_tablesize = BFAD_IO_MAX_SGE,
  691. .cmd_per_lun = 3,
  692. .use_clustering = ENABLE_CLUSTERING,
  693. .shost_attrs = bfad_im_vport_attrs,
  694. .max_sectors = 0xFFFF,
  695. };
  696. void
  697. bfad_im_probe_post(struct bfad_im_s *im)
  698. {
  699. flush_workqueue(im->drv_workq);
  700. }
  701. bfa_status_t
  702. bfad_im_module_init(void)
  703. {
  704. bfad_im_scsi_transport_template =
  705. fc_attach_transport(&bfad_im_fc_function_template);
  706. if (!bfad_im_scsi_transport_template)
  707. return BFA_STATUS_ENOMEM;
  708. return BFA_STATUS_OK;
  709. }
  710. void
  711. bfad_im_module_exit(void)
  712. {
  713. if (bfad_im_scsi_transport_template)
  714. fc_release_transport(bfad_im_scsi_transport_template);
  715. }
  716. void
  717. bfad_os_itnim_process(struct bfad_itnim_s *itnim_drv)
  718. {
  719. struct bfad_im_s *im = itnim_drv->im;
  720. if (itnim_drv->queue_work)
  721. queue_work(im->drv_workq, &itnim_drv->itnim_work);
  722. }
  723. void
  724. bfad_os_ramp_up_qdepth(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
  725. {
  726. struct scsi_device *tmp_sdev;
  727. if (((jiffies - itnim->last_ramp_up_time) >
  728. BFA_QUEUE_FULL_RAMP_UP_TIME * HZ) &&
  729. ((jiffies - itnim->last_queue_full_time) >
  730. BFA_QUEUE_FULL_RAMP_UP_TIME * HZ)) {
  731. shost_for_each_device(tmp_sdev, sdev->host) {
  732. if (bfa_lun_queue_depth > tmp_sdev->queue_depth) {
  733. if (tmp_sdev->id != sdev->id)
  734. continue;
  735. if (tmp_sdev->ordered_tags)
  736. scsi_adjust_queue_depth(tmp_sdev,
  737. MSG_ORDERED_TAG,
  738. tmp_sdev->queue_depth + 1);
  739. else
  740. scsi_adjust_queue_depth(tmp_sdev,
  741. MSG_SIMPLE_TAG,
  742. tmp_sdev->queue_depth + 1);
  743. itnim->last_ramp_up_time = jiffies;
  744. }
  745. }
  746. }
  747. }
  748. void
  749. bfad_os_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
  750. {
  751. struct scsi_device *tmp_sdev;
  752. itnim->last_queue_full_time = jiffies;
  753. shost_for_each_device(tmp_sdev, sdev->host) {
  754. if (tmp_sdev->id != sdev->id)
  755. continue;
  756. scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
  757. }
  758. }
  759. struct bfad_itnim_s *
  760. bfad_os_get_itnim(struct bfad_im_port_s *im_port, int id)
  761. {
  762. struct bfad_itnim_s *itnim = NULL;
  763. /* Search the mapped list for this target ID */
  764. list_for_each_entry(itnim, &im_port->itnim_mapped_list, list_entry) {
  765. if (id == itnim->scsi_tgt_id)
  766. return itnim;
  767. }
  768. return NULL;
  769. }
  770. /**
  771. * Scsi_Host template entry slave_alloc
  772. */
  773. static int
  774. bfad_im_slave_alloc(struct scsi_device *sdev)
  775. {
  776. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  777. if (!rport || fc_remote_port_chkready(rport))
  778. return -ENXIO;
  779. sdev->hostdata = rport->dd_data;
  780. return 0;
  781. }
  782. void
  783. bfad_os_fc_host_init(struct bfad_im_port_s *im_port)
  784. {
  785. struct Scsi_Host *host = im_port->shost;
  786. struct bfad_s *bfad = im_port->bfad;
  787. struct bfad_port_s *port = im_port->port;
  788. struct bfa_pport_attr_s pattr;
  789. char model[BFA_ADAPTER_MODEL_NAME_LEN];
  790. char fw_ver[BFA_VERSION_LEN];
  791. fc_host_node_name(host) =
  792. bfa_os_htonll((bfa_fcs_port_get_nwwn(port->fcs_port)));
  793. fc_host_port_name(host) =
  794. bfa_os_htonll((bfa_fcs_port_get_pwwn(port->fcs_port)));
  795. fc_host_supported_classes(host) = FC_COS_CLASS3;
  796. memset(fc_host_supported_fc4s(host), 0,
  797. sizeof(fc_host_supported_fc4s(host)));
  798. if (bfad_supported_fc4s & (BFA_PORT_ROLE_FCP_IM | BFA_PORT_ROLE_FCP_TM))
  799. /* For FCP type 0x08 */
  800. fc_host_supported_fc4s(host)[2] = 1;
  801. if (bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IPFC)
  802. /* For LLC/SNAP type 0x05 */
  803. fc_host_supported_fc4s(host)[3] = 0x20;
  804. /* For fibre channel services type 0x20 */
  805. fc_host_supported_fc4s(host)[7] = 1;
  806. bfa_get_adapter_model(&bfad->bfa, model);
  807. bfa_get_adapter_fw_ver(&bfad->bfa, fw_ver);
  808. sprintf(fc_host_symbolic_name(host), "Brocade %s FV%s DV%s",
  809. model, fw_ver, BFAD_DRIVER_VERSION);
  810. fc_host_supported_speeds(host) = 0;
  811. fc_host_supported_speeds(host) |=
  812. FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  813. FC_PORTSPEED_1GBIT;
  814. bfa_fcport_get_attr(&bfad->bfa, &pattr);
  815. fc_host_maxframe_size(host) = pattr.pport_cfg.maxfrsize;
  816. }
  817. static void
  818. bfad_im_fc_rport_add(struct bfad_im_port_s *im_port, struct bfad_itnim_s *itnim)
  819. {
  820. struct fc_rport_identifiers rport_ids;
  821. struct fc_rport *fc_rport;
  822. struct bfad_itnim_data_s *itnim_data;
  823. rport_ids.node_name =
  824. bfa_os_htonll(bfa_fcs_itnim_get_nwwn(&itnim->fcs_itnim));
  825. rport_ids.port_name =
  826. bfa_os_htonll(bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
  827. rport_ids.port_id =
  828. bfa_os_hton3b(bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim));
  829. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  830. itnim->fc_rport = fc_rport =
  831. fc_remote_port_add(im_port->shost, 0, &rport_ids);
  832. if (!fc_rport)
  833. return;
  834. fc_rport->maxframe_size =
  835. bfa_fcs_itnim_get_maxfrsize(&itnim->fcs_itnim);
  836. fc_rport->supported_classes = bfa_fcs_itnim_get_cos(&itnim->fcs_itnim);
  837. itnim_data = fc_rport->dd_data;
  838. itnim_data->itnim = itnim;
  839. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  840. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  841. fc_remote_port_rolechg(fc_rport, rport_ids.roles);
  842. if ((fc_rport->scsi_target_id != -1)
  843. && (fc_rport->scsi_target_id < MAX_FCP_TARGET))
  844. itnim->scsi_tgt_id = fc_rport->scsi_target_id;
  845. return;
  846. }
  847. /**
  848. * Work queue handler using FC transport service
  849. * Context: kernel
  850. */
  851. static void
  852. bfad_im_itnim_work_handler(struct work_struct *work)
  853. {
  854. struct bfad_itnim_s *itnim = container_of(work, struct bfad_itnim_s,
  855. itnim_work);
  856. struct bfad_im_s *im = itnim->im;
  857. struct bfad_s *bfad = im->bfad;
  858. struct bfad_im_port_s *im_port;
  859. unsigned long flags;
  860. struct fc_rport *fc_rport;
  861. wwn_t wwpn;
  862. u32 fcid;
  863. char wwpn_str[32], fcid_str[16];
  864. spin_lock_irqsave(&bfad->bfad_lock, flags);
  865. im_port = itnim->im_port;
  866. bfa_trc(bfad, itnim->state);
  867. switch (itnim->state) {
  868. case ITNIM_STATE_ONLINE:
  869. if (!itnim->fc_rport) {
  870. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  871. bfad_im_fc_rport_add(im_port, itnim);
  872. spin_lock_irqsave(&bfad->bfad_lock, flags);
  873. wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
  874. fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
  875. wwn2str(wwpn_str, wwpn);
  876. fcid2str(fcid_str, fcid);
  877. list_add_tail(&itnim->list_entry,
  878. &im_port->itnim_mapped_list);
  879. bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_ONLINE,
  880. im_port->shost->host_no,
  881. itnim->scsi_tgt_id,
  882. fcid_str, wwpn_str);
  883. } else {
  884. printk(KERN_WARNING
  885. "%s: itnim %llx is already in online state\n",
  886. __func__,
  887. bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim));
  888. }
  889. break;
  890. case ITNIM_STATE_OFFLINE_PENDING:
  891. itnim->state = ITNIM_STATE_OFFLINE;
  892. if (itnim->fc_rport) {
  893. fc_rport = itnim->fc_rport;
  894. ((struct bfad_itnim_data_s *)
  895. fc_rport->dd_data)->itnim = NULL;
  896. itnim->fc_rport = NULL;
  897. if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
  898. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  899. fc_rport->dev_loss_tmo =
  900. bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
  901. fc_remote_port_delete(fc_rport);
  902. spin_lock_irqsave(&bfad->bfad_lock, flags);
  903. }
  904. wwpn = bfa_fcs_itnim_get_pwwn(&itnim->fcs_itnim);
  905. fcid = bfa_fcs_itnim_get_fcid(&itnim->fcs_itnim);
  906. wwn2str(wwpn_str, wwpn);
  907. fcid2str(fcid_str, fcid);
  908. list_del(&itnim->list_entry);
  909. bfa_log(bfad->logmod, BFA_LOG_LINUX_ITNIM_OFFLINE,
  910. im_port->shost->host_no,
  911. itnim->scsi_tgt_id,
  912. fcid_str, wwpn_str);
  913. }
  914. break;
  915. case ITNIM_STATE_FREE:
  916. if (itnim->fc_rport) {
  917. fc_rport = itnim->fc_rport;
  918. ((struct bfad_itnim_data_s *)
  919. fc_rport->dd_data)->itnim = NULL;
  920. itnim->fc_rport = NULL;
  921. if (!(im_port->port->flags & BFAD_PORT_DELETE)) {
  922. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  923. fc_rport->dev_loss_tmo =
  924. bfa_fcpim_path_tov_get(&bfad->bfa) + 1;
  925. fc_remote_port_delete(fc_rport);
  926. spin_lock_irqsave(&bfad->bfad_lock, flags);
  927. }
  928. list_del(&itnim->list_entry);
  929. }
  930. kfree(itnim);
  931. break;
  932. default:
  933. bfa_assert(0);
  934. break;
  935. }
  936. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  937. }
  938. /**
  939. * Scsi_Host template entry, queue a SCSI command to the BFAD.
  940. */
  941. static int
  942. bfad_im_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
  943. {
  944. struct bfad_im_port_s *im_port =
  945. (struct bfad_im_port_s *) cmnd->device->host->hostdata[0];
  946. struct bfad_s *bfad = im_port->bfad;
  947. struct bfad_itnim_data_s *itnim_data = cmnd->device->hostdata;
  948. struct bfad_itnim_s *itnim;
  949. struct bfa_ioim_s *hal_io;
  950. unsigned long flags;
  951. int rc;
  952. s16 sg_cnt = 0;
  953. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  954. rc = fc_remote_port_chkready(rport);
  955. if (rc) {
  956. cmnd->result = rc;
  957. done(cmnd);
  958. return 0;
  959. }
  960. sg_cnt = scsi_dma_map(cmnd);
  961. if (sg_cnt < 0)
  962. return SCSI_MLQUEUE_HOST_BUSY;
  963. cmnd->scsi_done = done;
  964. spin_lock_irqsave(&bfad->bfad_lock, flags);
  965. if (!(bfad->bfad_flags & BFAD_HAL_START_DONE)) {
  966. printk(KERN_WARNING
  967. "bfad%d, queuecommand %p %x failed, BFA stopped\n",
  968. bfad->inst_no, cmnd, cmnd->cmnd[0]);
  969. cmnd->result = ScsiResult(DID_NO_CONNECT, 0);
  970. goto out_fail_cmd;
  971. }
  972. itnim = itnim_data->itnim;
  973. if (!itnim) {
  974. cmnd->result = ScsiResult(DID_IMM_RETRY, 0);
  975. goto out_fail_cmd;
  976. }
  977. hal_io = bfa_ioim_alloc(&bfad->bfa, (struct bfad_ioim_s *) cmnd,
  978. itnim->bfa_itnim, sg_cnt);
  979. if (!hal_io) {
  980. printk(KERN_WARNING "hal_io failure\n");
  981. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  982. scsi_dma_unmap(cmnd);
  983. return SCSI_MLQUEUE_HOST_BUSY;
  984. }
  985. cmnd->host_scribble = (char *)hal_io;
  986. bfa_trc_fp(bfad, hal_io->iotag);
  987. bfa_ioim_start(hal_io);
  988. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  989. return 0;
  990. out_fail_cmd:
  991. spin_unlock_irqrestore(&bfad->bfad_lock, flags);
  992. scsi_dma_unmap(cmnd);
  993. if (done)
  994. done(cmnd);
  995. return 0;
  996. }
  997. void
  998. bfad_os_rport_online_wait(struct bfad_s *bfad)
  999. {
  1000. int i;
  1001. int rport_delay = 10;
  1002. for (i = 0; !(bfad->bfad_flags & BFAD_PORT_ONLINE)
  1003. && i < bfa_linkup_delay; i++)
  1004. schedule_timeout_uninterruptible(HZ);
  1005. if (bfad->bfad_flags & BFAD_PORT_ONLINE) {
  1006. rport_delay = rport_delay < bfa_linkup_delay ?
  1007. rport_delay : bfa_linkup_delay;
  1008. for (i = 0; !(bfad->bfad_flags & BFAD_RPORT_ONLINE)
  1009. && i < rport_delay; i++)
  1010. schedule_timeout_uninterruptible(HZ);
  1011. if (rport_delay > 0 && (bfad->bfad_flags & BFAD_RPORT_ONLINE))
  1012. schedule_timeout_uninterruptible(rport_delay * HZ);
  1013. }
  1014. }
  1015. int
  1016. bfad_os_get_linkup_delay(struct bfad_s *bfad)
  1017. {
  1018. u8 nwwns = 0;
  1019. wwn_t *wwns;
  1020. int ldelay;
  1021. /*
  1022. * Querying for the boot target port wwns
  1023. * -- read from boot information in flash.
  1024. * If nwwns > 0 => boot over SAN and set bfa_linkup_delay = 30
  1025. * else => local boot machine set bfa_linkup_delay = 10
  1026. */
  1027. bfa_iocfc_get_bootwwns(&bfad->bfa, &nwwns, &wwns);
  1028. if (nwwns > 0) {
  1029. /* If boot over SAN; linkup_delay = 30sec */
  1030. ldelay = 30;
  1031. } else {
  1032. /* If local boot; linkup_delay = 10sec */
  1033. ldelay = 0;
  1034. }
  1035. return ldelay;
  1036. }