bfad_im.c 30 KB

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