bfad_im.c 31 KB

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