lpfc_scsi.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/pci.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/delay.h>
  24. #include <scsi/scsi.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_tcq.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include "lpfc_version.h"
  30. #include "lpfc_hw.h"
  31. #include "lpfc_sli.h"
  32. #include "lpfc_disc.h"
  33. #include "lpfc_scsi.h"
  34. #include "lpfc.h"
  35. #include "lpfc_logmsg.h"
  36. #include "lpfc_crtn.h"
  37. #include "lpfc_vport.h"
  38. #define LPFC_RESET_WAIT 2
  39. #define LPFC_ABORT_WAIT 2
  40. /*
  41. * This function is called with no lock held when there is a resource
  42. * error in driver or in firmware.
  43. */
  44. void
  45. lpfc_adjust_queue_depth(struct lpfc_hba *phba)
  46. {
  47. unsigned long flags;
  48. uint32_t evt_posted;
  49. spin_lock_irqsave(&phba->hbalock, flags);
  50. atomic_inc(&phba->num_rsrc_err);
  51. phba->last_rsrc_error_time = jiffies;
  52. if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
  53. spin_unlock_irqrestore(&phba->hbalock, flags);
  54. return;
  55. }
  56. phba->last_ramp_down_time = jiffies;
  57. spin_unlock_irqrestore(&phba->hbalock, flags);
  58. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  59. evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
  60. if (!evt_posted)
  61. phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
  62. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  63. if (!evt_posted)
  64. lpfc_worker_wake_up(phba);
  65. return;
  66. }
  67. /*
  68. * This function is called with no lock held when there is a successful
  69. * SCSI command completion.
  70. */
  71. static inline void
  72. lpfc_rampup_queue_depth(struct lpfc_vport *vport,
  73. struct scsi_device *sdev)
  74. {
  75. unsigned long flags;
  76. struct lpfc_hba *phba = vport->phba;
  77. uint32_t evt_posted;
  78. atomic_inc(&phba->num_cmd_success);
  79. if (vport->cfg_lun_queue_depth <= sdev->queue_depth)
  80. return;
  81. spin_lock_irqsave(&phba->hbalock, flags);
  82. if (((phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) > jiffies) ||
  83. ((phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL ) > jiffies)) {
  84. spin_unlock_irqrestore(&phba->hbalock, flags);
  85. return;
  86. }
  87. phba->last_ramp_up_time = jiffies;
  88. spin_unlock_irqrestore(&phba->hbalock, flags);
  89. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  90. evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE;
  91. if (!evt_posted)
  92. phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
  93. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  94. if (!evt_posted)
  95. lpfc_worker_wake_up(phba);
  96. return;
  97. }
  98. void
  99. lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
  100. {
  101. struct lpfc_vport **vports;
  102. struct Scsi_Host *shost;
  103. struct scsi_device *sdev;
  104. unsigned long new_queue_depth;
  105. unsigned long num_rsrc_err, num_cmd_success;
  106. int i;
  107. num_rsrc_err = atomic_read(&phba->num_rsrc_err);
  108. num_cmd_success = atomic_read(&phba->num_cmd_success);
  109. vports = lpfc_create_vport_work_array(phba);
  110. if (vports != NULL)
  111. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  112. shost = lpfc_shost_from_vport(vports[i]);
  113. shost_for_each_device(sdev, shost) {
  114. new_queue_depth =
  115. sdev->queue_depth * num_rsrc_err /
  116. (num_rsrc_err + num_cmd_success);
  117. if (!new_queue_depth)
  118. new_queue_depth = sdev->queue_depth - 1;
  119. else
  120. new_queue_depth = sdev->queue_depth -
  121. new_queue_depth;
  122. if (sdev->ordered_tags)
  123. scsi_adjust_queue_depth(sdev,
  124. MSG_ORDERED_TAG,
  125. new_queue_depth);
  126. else
  127. scsi_adjust_queue_depth(sdev,
  128. MSG_SIMPLE_TAG,
  129. new_queue_depth);
  130. }
  131. }
  132. lpfc_destroy_vport_work_array(phba, vports);
  133. atomic_set(&phba->num_rsrc_err, 0);
  134. atomic_set(&phba->num_cmd_success, 0);
  135. }
  136. void
  137. lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
  138. {
  139. struct lpfc_vport **vports;
  140. struct Scsi_Host *shost;
  141. struct scsi_device *sdev;
  142. int i;
  143. vports = lpfc_create_vport_work_array(phba);
  144. if (vports != NULL)
  145. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  146. shost = lpfc_shost_from_vport(vports[i]);
  147. shost_for_each_device(sdev, shost) {
  148. if (vports[i]->cfg_lun_queue_depth <=
  149. sdev->queue_depth)
  150. continue;
  151. if (sdev->ordered_tags)
  152. scsi_adjust_queue_depth(sdev,
  153. MSG_ORDERED_TAG,
  154. sdev->queue_depth+1);
  155. else
  156. scsi_adjust_queue_depth(sdev,
  157. MSG_SIMPLE_TAG,
  158. sdev->queue_depth+1);
  159. }
  160. }
  161. lpfc_destroy_vport_work_array(phba, vports);
  162. atomic_set(&phba->num_rsrc_err, 0);
  163. atomic_set(&phba->num_cmd_success, 0);
  164. }
  165. /**
  166. * lpfc_scsi_dev_block: set all scsi hosts to block state.
  167. * @phba: Pointer to HBA context object.
  168. *
  169. * This function walks vport list and set each SCSI host to block state
  170. * by invoking fc_remote_port_delete() routine. This function is invoked
  171. * with EEH when device's PCI slot has been permanently disabled.
  172. **/
  173. void
  174. lpfc_scsi_dev_block(struct lpfc_hba *phba)
  175. {
  176. struct lpfc_vport **vports;
  177. struct Scsi_Host *shost;
  178. struct scsi_device *sdev;
  179. struct fc_rport *rport;
  180. int i;
  181. vports = lpfc_create_vport_work_array(phba);
  182. if (vports != NULL)
  183. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  184. shost = lpfc_shost_from_vport(vports[i]);
  185. shost_for_each_device(sdev, shost) {
  186. rport = starget_to_rport(scsi_target(sdev));
  187. fc_remote_port_delete(rport);
  188. }
  189. }
  190. lpfc_destroy_vport_work_array(phba, vports);
  191. }
  192. /*
  193. * This routine allocates a scsi buffer, which contains all the necessary
  194. * information needed to initiate a SCSI I/O. The non-DMAable buffer region
  195. * contains information to build the IOCB. The DMAable region contains
  196. * memory for the FCP CMND, FCP RSP, and the inital BPL. In addition to
  197. * allocating memeory, the FCP CMND and FCP RSP BDEs are setup in the BPL
  198. * and the BPL BDE is setup in the IOCB.
  199. */
  200. static struct lpfc_scsi_buf *
  201. lpfc_new_scsi_buf(struct lpfc_vport *vport)
  202. {
  203. struct lpfc_hba *phba = vport->phba;
  204. struct lpfc_scsi_buf *psb;
  205. struct ulp_bde64 *bpl;
  206. IOCB_t *iocb;
  207. dma_addr_t pdma_phys_fcp_cmd;
  208. dma_addr_t pdma_phys_fcp_rsp;
  209. dma_addr_t pdma_phys_bpl;
  210. uint16_t iotag;
  211. psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
  212. if (!psb)
  213. return NULL;
  214. /*
  215. * Get memory from the pci pool to map the virt space to pci bus space
  216. * for an I/O. The DMA buffer includes space for the struct fcp_cmnd,
  217. * struct fcp_rsp and the number of bde's necessary to support the
  218. * sg_tablesize.
  219. */
  220. psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool, GFP_KERNEL,
  221. &psb->dma_handle);
  222. if (!psb->data) {
  223. kfree(psb);
  224. return NULL;
  225. }
  226. /* Initialize virtual ptrs to dma_buf region. */
  227. memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
  228. /* Allocate iotag for psb->cur_iocbq. */
  229. iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
  230. if (iotag == 0) {
  231. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  232. psb->data, psb->dma_handle);
  233. kfree (psb);
  234. return NULL;
  235. }
  236. psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
  237. psb->fcp_cmnd = psb->data;
  238. psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
  239. psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
  240. sizeof(struct fcp_rsp);
  241. /* Initialize local short-hand pointers. */
  242. bpl = psb->fcp_bpl;
  243. pdma_phys_fcp_cmd = psb->dma_handle;
  244. pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
  245. pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) +
  246. sizeof(struct fcp_rsp);
  247. /*
  248. * The first two bdes are the FCP_CMD and FCP_RSP. The balance are sg
  249. * list bdes. Initialize the first two and leave the rest for
  250. * queuecommand.
  251. */
  252. bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
  253. bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
  254. bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
  255. bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  256. bpl[0].tus.w = le32_to_cpu(bpl->tus.w);
  257. /* Setup the physical region for the FCP RSP */
  258. bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
  259. bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
  260. bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
  261. bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  262. bpl[1].tus.w = le32_to_cpu(bpl->tus.w);
  263. /*
  264. * Since the IOCB for the FCP I/O is built into this lpfc_scsi_buf,
  265. * initialize it with all known data now.
  266. */
  267. iocb = &psb->cur_iocbq.iocb;
  268. iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
  269. if (phba->sli_rev == 3) {
  270. /* fill in immediate fcp command BDE */
  271. iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
  272. iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
  273. iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
  274. unsli3.fcp_ext.icd);
  275. iocb->un.fcpi64.bdl.addrHigh = 0;
  276. iocb->ulpBdeCount = 0;
  277. iocb->ulpLe = 0;
  278. /* fill in responce BDE */
  279. iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  280. iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
  281. sizeof(struct fcp_rsp);
  282. iocb->unsli3.fcp_ext.rbde.addrLow =
  283. putPaddrLow(pdma_phys_fcp_rsp);
  284. iocb->unsli3.fcp_ext.rbde.addrHigh =
  285. putPaddrHigh(pdma_phys_fcp_rsp);
  286. } else {
  287. iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  288. iocb->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  289. iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_bpl);
  290. iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_bpl);
  291. iocb->ulpBdeCount = 1;
  292. iocb->ulpLe = 1;
  293. }
  294. iocb->ulpClass = CLASS3;
  295. return psb;
  296. }
  297. static struct lpfc_scsi_buf*
  298. lpfc_get_scsi_buf(struct lpfc_hba * phba)
  299. {
  300. struct lpfc_scsi_buf * lpfc_cmd = NULL;
  301. struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
  302. unsigned long iflag = 0;
  303. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  304. list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
  305. if (lpfc_cmd) {
  306. lpfc_cmd->seg_cnt = 0;
  307. lpfc_cmd->nonsg_phys = 0;
  308. }
  309. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  310. return lpfc_cmd;
  311. }
  312. static void
  313. lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  314. {
  315. unsigned long iflag = 0;
  316. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  317. psb->pCmd = NULL;
  318. list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
  319. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  320. }
  321. static int
  322. lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  323. {
  324. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  325. struct scatterlist *sgel = NULL;
  326. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  327. struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
  328. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  329. struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
  330. dma_addr_t physaddr;
  331. uint32_t num_bde = 0;
  332. int nseg, datadir = scsi_cmnd->sc_data_direction;
  333. /*
  334. * There are three possibilities here - use scatter-gather segment, use
  335. * the single mapping, or neither. Start the lpfc command prep by
  336. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  337. * data bde entry.
  338. */
  339. bpl += 2;
  340. if (scsi_sg_count(scsi_cmnd)) {
  341. /*
  342. * The driver stores the segment count returned from pci_map_sg
  343. * because this a count of dma-mappings used to map the use_sg
  344. * pages. They are not guaranteed to be the same for those
  345. * architectures that implement an IOMMU.
  346. */
  347. nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
  348. scsi_sg_count(scsi_cmnd), datadir);
  349. if (unlikely(!nseg))
  350. return 1;
  351. lpfc_cmd->seg_cnt = nseg;
  352. if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
  353. printk(KERN_ERR "%s: Too many sg segments from "
  354. "dma_map_sg. Config %d, seg_cnt %d",
  355. __func__, phba->cfg_sg_seg_cnt,
  356. lpfc_cmd->seg_cnt);
  357. scsi_dma_unmap(scsi_cmnd);
  358. return 1;
  359. }
  360. /*
  361. * The driver established a maximum scatter-gather segment count
  362. * during probe that limits the number of sg elements in any
  363. * single scsi command. Just run through the seg_cnt and format
  364. * the bde's.
  365. * When using SLI-3 the driver will try to fit all the BDEs into
  366. * the IOCB. If it can't then the BDEs get added to a BPL as it
  367. * does for SLI-2 mode.
  368. */
  369. scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
  370. physaddr = sg_dma_address(sgel);
  371. if (phba->sli_rev == 3 &&
  372. nseg <= LPFC_EXT_DATA_BDE_COUNT) {
  373. data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  374. data_bde->tus.f.bdeSize = sg_dma_len(sgel);
  375. data_bde->addrLow = putPaddrLow(physaddr);
  376. data_bde->addrHigh = putPaddrHigh(physaddr);
  377. data_bde++;
  378. } else {
  379. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  380. bpl->tus.f.bdeSize = sg_dma_len(sgel);
  381. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  382. bpl->addrLow =
  383. le32_to_cpu(putPaddrLow(physaddr));
  384. bpl->addrHigh =
  385. le32_to_cpu(putPaddrHigh(physaddr));
  386. bpl++;
  387. }
  388. }
  389. }
  390. /*
  391. * Finish initializing those IOCB fields that are dependent on the
  392. * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
  393. * explicitly reinitialized and for SLI-3 the extended bde count is
  394. * explicitly reinitialized since all iocb memory resources are reused.
  395. */
  396. if (phba->sli_rev == 3) {
  397. if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
  398. /*
  399. * The extended IOCB format can only fit 3 BDE or a BPL.
  400. * This I/O has more than 3 BDE so the 1st data bde will
  401. * be a BPL that is filled in here.
  402. */
  403. physaddr = lpfc_cmd->dma_handle;
  404. data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
  405. data_bde->tus.f.bdeSize = (num_bde *
  406. sizeof(struct ulp_bde64));
  407. physaddr += (sizeof(struct fcp_cmnd) +
  408. sizeof(struct fcp_rsp) +
  409. (2 * sizeof(struct ulp_bde64)));
  410. data_bde->addrHigh = putPaddrHigh(physaddr);
  411. data_bde->addrLow = putPaddrLow(physaddr);
  412. /* ebde count includes the responce bde and data bpl */
  413. iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
  414. } else {
  415. /* ebde count includes the responce bde and data bdes */
  416. iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
  417. }
  418. } else {
  419. iocb_cmd->un.fcpi64.bdl.bdeSize =
  420. ((num_bde + 2) * sizeof(struct ulp_bde64));
  421. }
  422. fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
  423. return 0;
  424. }
  425. static void
  426. lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
  427. {
  428. /*
  429. * There are only two special cases to consider. (1) the scsi command
  430. * requested scatter-gather usage or (2) the scsi command allocated
  431. * a request buffer, but did not request use_sg. There is a third
  432. * case, but it does not require resource deallocation.
  433. */
  434. if (psb->seg_cnt > 0)
  435. scsi_dma_unmap(psb->pCmd);
  436. }
  437. static void
  438. lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
  439. struct lpfc_iocbq *rsp_iocb)
  440. {
  441. struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
  442. struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
  443. struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
  444. uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
  445. uint32_t resp_info = fcprsp->rspStatus2;
  446. uint32_t scsi_status = fcprsp->rspStatus3;
  447. uint32_t *lp;
  448. uint32_t host_status = DID_OK;
  449. uint32_t rsplen = 0;
  450. uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
  451. /*
  452. * If this is a task management command, there is no
  453. * scsi packet associated with this lpfc_cmd. The driver
  454. * consumes it.
  455. */
  456. if (fcpcmd->fcpCntl2) {
  457. scsi_status = 0;
  458. goto out;
  459. }
  460. if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
  461. uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
  462. if (snslen > SCSI_SENSE_BUFFERSIZE)
  463. snslen = SCSI_SENSE_BUFFERSIZE;
  464. if (resp_info & RSP_LEN_VALID)
  465. rsplen = be32_to_cpu(fcprsp->rspRspLen);
  466. memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
  467. }
  468. lp = (uint32_t *)cmnd->sense_buffer;
  469. if (!scsi_status && (resp_info & RESID_UNDER))
  470. logit = LOG_FCP;
  471. lpfc_printf_vlog(vport, KERN_WARNING, logit,
  472. "0730 FCP command x%x failed: x%x SNS x%x x%x "
  473. "Data: x%x x%x x%x x%x x%x\n",
  474. cmnd->cmnd[0], scsi_status,
  475. be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
  476. be32_to_cpu(fcprsp->rspResId),
  477. be32_to_cpu(fcprsp->rspSnsLen),
  478. be32_to_cpu(fcprsp->rspRspLen),
  479. fcprsp->rspInfo3);
  480. if (resp_info & RSP_LEN_VALID) {
  481. rsplen = be32_to_cpu(fcprsp->rspRspLen);
  482. if ((rsplen != 0 && rsplen != 4 && rsplen != 8) ||
  483. (fcprsp->rspInfo3 != RSP_NO_FAILURE)) {
  484. host_status = DID_ERROR;
  485. goto out;
  486. }
  487. }
  488. scsi_set_resid(cmnd, 0);
  489. if (resp_info & RESID_UNDER) {
  490. scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
  491. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  492. "0716 FCP Read Underrun, expected %d, "
  493. "residual %d Data: x%x x%x x%x\n",
  494. be32_to_cpu(fcpcmd->fcpDl),
  495. scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
  496. cmnd->underflow);
  497. /*
  498. * If there is an under run check if under run reported by
  499. * storage array is same as the under run reported by HBA.
  500. * If this is not same, there is a dropped frame.
  501. */
  502. if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
  503. fcpi_parm &&
  504. (scsi_get_resid(cmnd) != fcpi_parm)) {
  505. lpfc_printf_vlog(vport, KERN_WARNING,
  506. LOG_FCP | LOG_FCP_ERROR,
  507. "0735 FCP Read Check Error "
  508. "and Underrun Data: x%x x%x x%x x%x\n",
  509. be32_to_cpu(fcpcmd->fcpDl),
  510. scsi_get_resid(cmnd), fcpi_parm,
  511. cmnd->cmnd[0]);
  512. scsi_set_resid(cmnd, scsi_bufflen(cmnd));
  513. host_status = DID_ERROR;
  514. }
  515. /*
  516. * The cmnd->underflow is the minimum number of bytes that must
  517. * be transfered for this command. Provided a sense condition
  518. * is not present, make sure the actual amount transferred is at
  519. * least the underflow value or fail.
  520. */
  521. if (!(resp_info & SNS_LEN_VALID) &&
  522. (scsi_status == SAM_STAT_GOOD) &&
  523. (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
  524. < cmnd->underflow)) {
  525. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  526. "0717 FCP command x%x residual "
  527. "underrun converted to error "
  528. "Data: x%x x%x x%x\n",
  529. cmnd->cmnd[0], scsi_bufflen(cmnd),
  530. scsi_get_resid(cmnd), cmnd->underflow);
  531. host_status = DID_ERROR;
  532. }
  533. } else if (resp_info & RESID_OVER) {
  534. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  535. "0720 FCP command x%x residual overrun error. "
  536. "Data: x%x x%x \n", cmnd->cmnd[0],
  537. scsi_bufflen(cmnd), scsi_get_resid(cmnd));
  538. host_status = DID_ERROR;
  539. /*
  540. * Check SLI validation that all the transfer was actually done
  541. * (fcpi_parm should be zero). Apply check only to reads.
  542. */
  543. } else if ((scsi_status == SAM_STAT_GOOD) && fcpi_parm &&
  544. (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
  545. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
  546. "0734 FCP Read Check Error Data: "
  547. "x%x x%x x%x x%x\n",
  548. be32_to_cpu(fcpcmd->fcpDl),
  549. be32_to_cpu(fcprsp->rspResId),
  550. fcpi_parm, cmnd->cmnd[0]);
  551. host_status = DID_ERROR;
  552. scsi_set_resid(cmnd, scsi_bufflen(cmnd));
  553. }
  554. out:
  555. cmnd->result = ScsiResult(host_status, scsi_status);
  556. }
  557. static void
  558. lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
  559. struct lpfc_iocbq *pIocbOut)
  560. {
  561. struct lpfc_scsi_buf *lpfc_cmd =
  562. (struct lpfc_scsi_buf *) pIocbIn->context1;
  563. struct lpfc_vport *vport = pIocbIn->vport;
  564. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  565. struct lpfc_nodelist *pnode = rdata->pnode;
  566. struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
  567. int result;
  568. struct scsi_device *sdev, *tmp_sdev;
  569. int depth = 0;
  570. unsigned long flags;
  571. lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
  572. lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
  573. if (lpfc_cmd->status) {
  574. if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
  575. (lpfc_cmd->result & IOERR_DRVR_MASK))
  576. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  577. else if (lpfc_cmd->status >= IOSTAT_CNT)
  578. lpfc_cmd->status = IOSTAT_DEFAULT;
  579. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  580. "0729 FCP cmd x%x failed <%d/%d> "
  581. "status: x%x result: x%x Data: x%x x%x\n",
  582. cmd->cmnd[0],
  583. cmd->device ? cmd->device->id : 0xffff,
  584. cmd->device ? cmd->device->lun : 0xffff,
  585. lpfc_cmd->status, lpfc_cmd->result,
  586. pIocbOut->iocb.ulpContext,
  587. lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
  588. switch (lpfc_cmd->status) {
  589. case IOSTAT_FCP_RSP_ERROR:
  590. /* Call FCP RSP handler to determine result */
  591. lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
  592. break;
  593. case IOSTAT_NPORT_BSY:
  594. case IOSTAT_FABRIC_BSY:
  595. cmd->result = ScsiResult(DID_BUS_BUSY, 0);
  596. break;
  597. case IOSTAT_LOCAL_REJECT:
  598. if (lpfc_cmd->result == IOERR_INVALID_RPI ||
  599. lpfc_cmd->result == IOERR_NO_RESOURCES ||
  600. lpfc_cmd->result == IOERR_ABORT_REQUESTED) {
  601. cmd->result = ScsiResult(DID_REQUEUE, 0);
  602. break;
  603. } /* else: fall through */
  604. default:
  605. cmd->result = ScsiResult(DID_ERROR, 0);
  606. break;
  607. }
  608. if (!pnode || !NLP_CHK_NODE_ACT(pnode)
  609. || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
  610. cmd->result = ScsiResult(DID_BUS_BUSY, SAM_STAT_BUSY);
  611. } else {
  612. cmd->result = ScsiResult(DID_OK, 0);
  613. }
  614. if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
  615. uint32_t *lp = (uint32_t *)cmd->sense_buffer;
  616. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  617. "0710 Iodone <%d/%d> cmd %p, error "
  618. "x%x SNS x%x x%x Data: x%x x%x\n",
  619. cmd->device->id, cmd->device->lun, cmd,
  620. cmd->result, *lp, *(lp + 3), cmd->retries,
  621. scsi_get_resid(cmd));
  622. }
  623. result = cmd->result;
  624. sdev = cmd->device;
  625. lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
  626. cmd->scsi_done(cmd);
  627. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  628. /*
  629. * If there is a thread waiting for command completion
  630. * wake up the thread.
  631. */
  632. spin_lock_irqsave(sdev->host->host_lock, flags);
  633. lpfc_cmd->pCmd = NULL;
  634. if (lpfc_cmd->waitq)
  635. wake_up(lpfc_cmd->waitq);
  636. spin_unlock_irqrestore(sdev->host->host_lock, flags);
  637. lpfc_release_scsi_buf(phba, lpfc_cmd);
  638. return;
  639. }
  640. if (!result)
  641. lpfc_rampup_queue_depth(vport, sdev);
  642. if (!result && pnode && NLP_CHK_NODE_ACT(pnode) &&
  643. ((jiffies - pnode->last_ramp_up_time) >
  644. LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
  645. ((jiffies - pnode->last_q_full_time) >
  646. LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
  647. (vport->cfg_lun_queue_depth > sdev->queue_depth)) {
  648. shost_for_each_device(tmp_sdev, sdev->host) {
  649. if (vport->cfg_lun_queue_depth > tmp_sdev->queue_depth){
  650. if (tmp_sdev->id != sdev->id)
  651. continue;
  652. if (tmp_sdev->ordered_tags)
  653. scsi_adjust_queue_depth(tmp_sdev,
  654. MSG_ORDERED_TAG,
  655. tmp_sdev->queue_depth+1);
  656. else
  657. scsi_adjust_queue_depth(tmp_sdev,
  658. MSG_SIMPLE_TAG,
  659. tmp_sdev->queue_depth+1);
  660. pnode->last_ramp_up_time = jiffies;
  661. }
  662. }
  663. }
  664. /*
  665. * Check for queue full. If the lun is reporting queue full, then
  666. * back off the lun queue depth to prevent target overloads.
  667. */
  668. if (result == SAM_STAT_TASK_SET_FULL && pnode &&
  669. NLP_CHK_NODE_ACT(pnode)) {
  670. pnode->last_q_full_time = jiffies;
  671. shost_for_each_device(tmp_sdev, sdev->host) {
  672. if (tmp_sdev->id != sdev->id)
  673. continue;
  674. depth = scsi_track_queue_full(tmp_sdev,
  675. tmp_sdev->queue_depth - 1);
  676. }
  677. /*
  678. * The queue depth cannot be lowered any more.
  679. * Modify the returned error code to store
  680. * the final depth value set by
  681. * scsi_track_queue_full.
  682. */
  683. if (depth == -1)
  684. depth = sdev->host->cmd_per_lun;
  685. if (depth) {
  686. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  687. "0711 detected queue full - lun queue "
  688. "depth adjusted to %d.\n", depth);
  689. }
  690. }
  691. /*
  692. * If there is a thread waiting for command completion
  693. * wake up the thread.
  694. */
  695. spin_lock_irqsave(sdev->host->host_lock, flags);
  696. lpfc_cmd->pCmd = NULL;
  697. if (lpfc_cmd->waitq)
  698. wake_up(lpfc_cmd->waitq);
  699. spin_unlock_irqrestore(sdev->host->host_lock, flags);
  700. lpfc_release_scsi_buf(phba, lpfc_cmd);
  701. }
  702. /**
  703. * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB.
  704. * @data: A pointer to the immediate command data portion of the IOCB.
  705. * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
  706. *
  707. * The routine copies the entire FCP command from @fcp_cmnd to @data while
  708. * byte swapping the data to big endian format for transmission on the wire.
  709. **/
  710. static void
  711. lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
  712. {
  713. int i, j;
  714. for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
  715. i += sizeof(uint32_t), j++) {
  716. ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
  717. }
  718. }
  719. static void
  720. lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
  721. struct lpfc_nodelist *pnode)
  722. {
  723. struct lpfc_hba *phba = vport->phba;
  724. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  725. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  726. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  727. struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
  728. int datadir = scsi_cmnd->sc_data_direction;
  729. char tag[2];
  730. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  731. return;
  732. lpfc_cmd->fcp_rsp->rspSnsLen = 0;
  733. /* clear task management bits */
  734. lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
  735. int_to_scsilun(lpfc_cmd->pCmd->device->lun,
  736. &lpfc_cmd->fcp_cmnd->fcp_lun);
  737. memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
  738. if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
  739. switch (tag[0]) {
  740. case HEAD_OF_QUEUE_TAG:
  741. fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
  742. break;
  743. case ORDERED_QUEUE_TAG:
  744. fcp_cmnd->fcpCntl1 = ORDERED_Q;
  745. break;
  746. default:
  747. fcp_cmnd->fcpCntl1 = SIMPLE_Q;
  748. break;
  749. }
  750. } else
  751. fcp_cmnd->fcpCntl1 = 0;
  752. /*
  753. * There are three possibilities here - use scatter-gather segment, use
  754. * the single mapping, or neither. Start the lpfc command prep by
  755. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  756. * data bde entry.
  757. */
  758. if (scsi_sg_count(scsi_cmnd)) {
  759. if (datadir == DMA_TO_DEVICE) {
  760. iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
  761. iocb_cmd->un.fcpi.fcpi_parm = 0;
  762. iocb_cmd->ulpPU = 0;
  763. fcp_cmnd->fcpCntl3 = WRITE_DATA;
  764. phba->fc4OutputRequests++;
  765. } else {
  766. iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
  767. iocb_cmd->ulpPU = PARM_READ_CHECK;
  768. iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
  769. fcp_cmnd->fcpCntl3 = READ_DATA;
  770. phba->fc4InputRequests++;
  771. }
  772. } else {
  773. iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
  774. iocb_cmd->un.fcpi.fcpi_parm = 0;
  775. iocb_cmd->ulpPU = 0;
  776. fcp_cmnd->fcpCntl3 = 0;
  777. phba->fc4ControlRequests++;
  778. }
  779. if (phba->sli_rev == 3)
  780. lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
  781. /*
  782. * Finish initializing those IOCB fields that are independent
  783. * of the scsi_cmnd request_buffer
  784. */
  785. piocbq->iocb.ulpContext = pnode->nlp_rpi;
  786. if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
  787. piocbq->iocb.ulpFCP2Rcvy = 1;
  788. else
  789. piocbq->iocb.ulpFCP2Rcvy = 0;
  790. piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
  791. piocbq->context1 = lpfc_cmd;
  792. piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
  793. piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
  794. piocbq->vport = vport;
  795. }
  796. static int
  797. lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
  798. struct lpfc_scsi_buf *lpfc_cmd,
  799. unsigned int lun,
  800. uint8_t task_mgmt_cmd)
  801. {
  802. struct lpfc_iocbq *piocbq;
  803. IOCB_t *piocb;
  804. struct fcp_cmnd *fcp_cmnd;
  805. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  806. struct lpfc_nodelist *ndlp = rdata->pnode;
  807. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
  808. ndlp->nlp_state != NLP_STE_MAPPED_NODE)
  809. return 0;
  810. piocbq = &(lpfc_cmd->cur_iocbq);
  811. piocbq->vport = vport;
  812. piocb = &piocbq->iocb;
  813. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  814. /* Clear out any old data in the FCP command area */
  815. memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
  816. int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
  817. fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
  818. if (vport->phba->sli_rev == 3)
  819. lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
  820. piocb->ulpCommand = CMD_FCP_ICMND64_CR;
  821. piocb->ulpContext = ndlp->nlp_rpi;
  822. if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
  823. piocb->ulpFCP2Rcvy = 1;
  824. }
  825. piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
  826. /* ulpTimeout is only one byte */
  827. if (lpfc_cmd->timeout > 0xff) {
  828. /*
  829. * Do not timeout the command at the firmware level.
  830. * The driver will provide the timeout mechanism.
  831. */
  832. piocb->ulpTimeout = 0;
  833. } else {
  834. piocb->ulpTimeout = lpfc_cmd->timeout;
  835. }
  836. return 1;
  837. }
  838. static void
  839. lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
  840. struct lpfc_iocbq *cmdiocbq,
  841. struct lpfc_iocbq *rspiocbq)
  842. {
  843. struct lpfc_scsi_buf *lpfc_cmd =
  844. (struct lpfc_scsi_buf *) cmdiocbq->context1;
  845. if (lpfc_cmd)
  846. lpfc_release_scsi_buf(phba, lpfc_cmd);
  847. return;
  848. }
  849. static int
  850. lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
  851. unsigned tgt_id, unsigned int lun,
  852. struct lpfc_rport_data *rdata)
  853. {
  854. struct lpfc_hba *phba = vport->phba;
  855. struct lpfc_iocbq *iocbq;
  856. struct lpfc_iocbq *iocbqrsp;
  857. int ret;
  858. int status;
  859. if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
  860. return FAILED;
  861. lpfc_cmd->rdata = rdata;
  862. status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
  863. FCP_TARGET_RESET);
  864. if (!status)
  865. return FAILED;
  866. iocbq = &lpfc_cmd->cur_iocbq;
  867. iocbqrsp = lpfc_sli_get_iocbq(phba);
  868. if (!iocbqrsp)
  869. return FAILED;
  870. /* Issue Target Reset to TGT <num> */
  871. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  872. "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
  873. tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
  874. status = lpfc_sli_issue_iocb_wait(phba,
  875. &phba->sli.ring[phba->sli.fcp_ring],
  876. iocbq, iocbqrsp, lpfc_cmd->timeout);
  877. if (status != IOCB_SUCCESS) {
  878. if (status == IOCB_TIMEDOUT) {
  879. iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
  880. ret = TIMEOUT_ERROR;
  881. } else
  882. ret = FAILED;
  883. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  884. } else {
  885. ret = SUCCESS;
  886. lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
  887. lpfc_cmd->status = iocbqrsp->iocb.ulpStatus;
  888. if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
  889. (lpfc_cmd->result & IOERR_DRVR_MASK))
  890. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  891. }
  892. lpfc_sli_release_iocbq(phba, iocbqrsp);
  893. return ret;
  894. }
  895. const char *
  896. lpfc_info(struct Scsi_Host *host)
  897. {
  898. struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
  899. struct lpfc_hba *phba = vport->phba;
  900. int len;
  901. static char lpfcinfobuf[384];
  902. memset(lpfcinfobuf,0,384);
  903. if (phba && phba->pcidev){
  904. strncpy(lpfcinfobuf, phba->ModelDesc, 256);
  905. len = strlen(lpfcinfobuf);
  906. snprintf(lpfcinfobuf + len,
  907. 384-len,
  908. " on PCI bus %02x device %02x irq %d",
  909. phba->pcidev->bus->number,
  910. phba->pcidev->devfn,
  911. phba->pcidev->irq);
  912. len = strlen(lpfcinfobuf);
  913. if (phba->Port[0]) {
  914. snprintf(lpfcinfobuf + len,
  915. 384-len,
  916. " port %s",
  917. phba->Port);
  918. }
  919. }
  920. return lpfcinfobuf;
  921. }
  922. static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
  923. {
  924. unsigned long poll_tmo_expires =
  925. (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
  926. if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
  927. mod_timer(&phba->fcp_poll_timer,
  928. poll_tmo_expires);
  929. }
  930. void lpfc_poll_start_timer(struct lpfc_hba * phba)
  931. {
  932. lpfc_poll_rearm_timer(phba);
  933. }
  934. void lpfc_poll_timeout(unsigned long ptr)
  935. {
  936. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  937. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  938. lpfc_sli_poll_fcp_ring (phba);
  939. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  940. lpfc_poll_rearm_timer(phba);
  941. }
  942. }
  943. static int
  944. lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
  945. {
  946. struct Scsi_Host *shost = cmnd->device->host;
  947. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  948. struct lpfc_hba *phba = vport->phba;
  949. struct lpfc_sli *psli = &phba->sli;
  950. struct lpfc_rport_data *rdata = cmnd->device->hostdata;
  951. struct lpfc_nodelist *ndlp = rdata->pnode;
  952. struct lpfc_scsi_buf *lpfc_cmd;
  953. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  954. int err;
  955. err = fc_remote_port_chkready(rport);
  956. if (err) {
  957. cmnd->result = err;
  958. goto out_fail_command;
  959. }
  960. /*
  961. * Catch race where our node has transitioned, but the
  962. * transport is still transitioning.
  963. */
  964. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  965. goto out_target_busy;
  966. lpfc_cmd = lpfc_get_scsi_buf(phba);
  967. if (lpfc_cmd == NULL) {
  968. lpfc_adjust_queue_depth(phba);
  969. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  970. "0707 driver's buffer pool is empty, "
  971. "IO busied\n");
  972. goto out_host_busy;
  973. }
  974. /*
  975. * Store the midlayer's command structure for the completion phase
  976. * and complete the command initialization.
  977. */
  978. lpfc_cmd->pCmd = cmnd;
  979. lpfc_cmd->rdata = rdata;
  980. lpfc_cmd->timeout = 0;
  981. cmnd->host_scribble = (unsigned char *)lpfc_cmd;
  982. cmnd->scsi_done = done;
  983. err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
  984. if (err)
  985. goto out_host_busy_free_buf;
  986. lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
  987. err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring],
  988. &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
  989. if (err)
  990. goto out_host_busy_free_buf;
  991. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  992. lpfc_sli_poll_fcp_ring(phba);
  993. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  994. lpfc_poll_rearm_timer(phba);
  995. }
  996. return 0;
  997. out_host_busy_free_buf:
  998. lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
  999. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1000. out_host_busy:
  1001. return SCSI_MLQUEUE_HOST_BUSY;
  1002. out_target_busy:
  1003. return SCSI_MLQUEUE_TARGET_BUSY;
  1004. out_fail_command:
  1005. done(cmnd);
  1006. return 0;
  1007. }
  1008. static void
  1009. lpfc_block_error_handler(struct scsi_cmnd *cmnd)
  1010. {
  1011. struct Scsi_Host *shost = cmnd->device->host;
  1012. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  1013. spin_lock_irq(shost->host_lock);
  1014. while (rport->port_state == FC_PORTSTATE_BLOCKED) {
  1015. spin_unlock_irq(shost->host_lock);
  1016. msleep(1000);
  1017. spin_lock_irq(shost->host_lock);
  1018. }
  1019. spin_unlock_irq(shost->host_lock);
  1020. return;
  1021. }
  1022. static int
  1023. lpfc_abort_handler(struct scsi_cmnd *cmnd)
  1024. {
  1025. struct Scsi_Host *shost = cmnd->device->host;
  1026. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1027. struct lpfc_hba *phba = vport->phba;
  1028. struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
  1029. struct lpfc_iocbq *iocb;
  1030. struct lpfc_iocbq *abtsiocb;
  1031. struct lpfc_scsi_buf *lpfc_cmd;
  1032. IOCB_t *cmd, *icmd;
  1033. int ret = SUCCESS;
  1034. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
  1035. lpfc_block_error_handler(cmnd);
  1036. lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
  1037. BUG_ON(!lpfc_cmd);
  1038. /*
  1039. * If pCmd field of the corresponding lpfc_scsi_buf structure
  1040. * points to a different SCSI command, then the driver has
  1041. * already completed this command, but the midlayer did not
  1042. * see the completion before the eh fired. Just return
  1043. * SUCCESS.
  1044. */
  1045. iocb = &lpfc_cmd->cur_iocbq;
  1046. if (lpfc_cmd->pCmd != cmnd)
  1047. goto out;
  1048. BUG_ON(iocb->context1 != lpfc_cmd);
  1049. abtsiocb = lpfc_sli_get_iocbq(phba);
  1050. if (abtsiocb == NULL) {
  1051. ret = FAILED;
  1052. goto out;
  1053. }
  1054. /*
  1055. * The scsi command can not be in txq and it is in flight because the
  1056. * pCmd is still pointig at the SCSI command we have to abort. There
  1057. * is no need to search the txcmplq. Just send an abort to the FW.
  1058. */
  1059. cmd = &iocb->iocb;
  1060. icmd = &abtsiocb->iocb;
  1061. icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
  1062. icmd->un.acxri.abortContextTag = cmd->ulpContext;
  1063. icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
  1064. icmd->ulpLe = 1;
  1065. icmd->ulpClass = cmd->ulpClass;
  1066. if (lpfc_is_link_up(phba))
  1067. icmd->ulpCommand = CMD_ABORT_XRI_CN;
  1068. else
  1069. icmd->ulpCommand = CMD_CLOSE_XRI_CN;
  1070. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  1071. abtsiocb->vport = vport;
  1072. if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) {
  1073. lpfc_sli_release_iocbq(phba, abtsiocb);
  1074. ret = FAILED;
  1075. goto out;
  1076. }
  1077. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  1078. lpfc_sli_poll_fcp_ring (phba);
  1079. lpfc_cmd->waitq = &waitq;
  1080. /* Wait for abort to complete */
  1081. wait_event_timeout(waitq,
  1082. (lpfc_cmd->pCmd != cmnd),
  1083. (2*vport->cfg_devloss_tmo*HZ));
  1084. spin_lock_irq(shost->host_lock);
  1085. lpfc_cmd->waitq = NULL;
  1086. spin_unlock_irq(shost->host_lock);
  1087. if (lpfc_cmd->pCmd == cmnd) {
  1088. ret = FAILED;
  1089. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1090. "0748 abort handler timed out waiting "
  1091. "for abort to complete: ret %#x, ID %d, "
  1092. "LUN %d, snum %#lx\n",
  1093. ret, cmnd->device->id, cmnd->device->lun,
  1094. cmnd->serial_number);
  1095. }
  1096. out:
  1097. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  1098. "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
  1099. "LUN %d snum %#lx\n", ret, cmnd->device->id,
  1100. cmnd->device->lun, cmnd->serial_number);
  1101. return ret;
  1102. }
  1103. static int
  1104. lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
  1105. {
  1106. struct Scsi_Host *shost = cmnd->device->host;
  1107. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1108. struct lpfc_hba *phba = vport->phba;
  1109. struct lpfc_scsi_buf *lpfc_cmd;
  1110. struct lpfc_iocbq *iocbq, *iocbqrsp;
  1111. struct lpfc_rport_data *rdata = cmnd->device->hostdata;
  1112. struct lpfc_nodelist *pnode = rdata->pnode;
  1113. unsigned long later;
  1114. int ret = SUCCESS;
  1115. int status;
  1116. int cnt;
  1117. lpfc_block_error_handler(cmnd);
  1118. /*
  1119. * If target is not in a MAPPED state, delay the reset until
  1120. * target is rediscovered or devloss timeout expires.
  1121. */
  1122. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  1123. while (time_after(later, jiffies)) {
  1124. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  1125. return FAILED;
  1126. if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
  1127. break;
  1128. schedule_timeout_uninterruptible(msecs_to_jiffies(500));
  1129. rdata = cmnd->device->hostdata;
  1130. if (!rdata)
  1131. break;
  1132. pnode = rdata->pnode;
  1133. }
  1134. if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) {
  1135. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1136. "0721 LUN Reset rport "
  1137. "failure: msec x%x rdata x%p\n",
  1138. jiffies_to_msecs(jiffies - later), rdata);
  1139. return FAILED;
  1140. }
  1141. lpfc_cmd = lpfc_get_scsi_buf(phba);
  1142. if (lpfc_cmd == NULL)
  1143. return FAILED;
  1144. lpfc_cmd->timeout = 60;
  1145. lpfc_cmd->rdata = rdata;
  1146. status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd,
  1147. cmnd->device->lun,
  1148. FCP_TARGET_RESET);
  1149. if (!status) {
  1150. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1151. return FAILED;
  1152. }
  1153. iocbq = &lpfc_cmd->cur_iocbq;
  1154. /* get a buffer for this IOCB command response */
  1155. iocbqrsp = lpfc_sli_get_iocbq(phba);
  1156. if (iocbqrsp == NULL) {
  1157. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1158. return FAILED;
  1159. }
  1160. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  1161. "0703 Issue target reset to TGT %d LUN %d "
  1162. "rpi x%x nlp_flag x%x\n", cmnd->device->id,
  1163. cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
  1164. status = lpfc_sli_issue_iocb_wait(phba,
  1165. &phba->sli.ring[phba->sli.fcp_ring],
  1166. iocbq, iocbqrsp, lpfc_cmd->timeout);
  1167. if (status == IOCB_TIMEDOUT) {
  1168. iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
  1169. ret = TIMEOUT_ERROR;
  1170. } else {
  1171. if (status != IOCB_SUCCESS)
  1172. ret = FAILED;
  1173. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1174. }
  1175. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1176. "0713 SCSI layer issued device reset (%d, %d) "
  1177. "return x%x status x%x result x%x\n",
  1178. cmnd->device->id, cmnd->device->lun, ret,
  1179. iocbqrsp->iocb.ulpStatus,
  1180. iocbqrsp->iocb.un.ulpWord[4]);
  1181. lpfc_sli_release_iocbq(phba, iocbqrsp);
  1182. cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun,
  1183. LPFC_CTX_TGT);
  1184. if (cnt)
  1185. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  1186. cmnd->device->id, cmnd->device->lun,
  1187. LPFC_CTX_TGT);
  1188. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  1189. while (time_after(later, jiffies) && cnt) {
  1190. schedule_timeout_uninterruptible(msecs_to_jiffies(20));
  1191. cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id,
  1192. cmnd->device->lun, LPFC_CTX_TGT);
  1193. }
  1194. if (cnt) {
  1195. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1196. "0719 device reset I/O flush failure: "
  1197. "cnt x%x\n", cnt);
  1198. ret = FAILED;
  1199. }
  1200. return ret;
  1201. }
  1202. static int
  1203. lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
  1204. {
  1205. struct Scsi_Host *shost = cmnd->device->host;
  1206. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1207. struct lpfc_hba *phba = vport->phba;
  1208. struct lpfc_nodelist *ndlp = NULL;
  1209. int match;
  1210. int ret = SUCCESS, status = SUCCESS, i;
  1211. int cnt;
  1212. struct lpfc_scsi_buf * lpfc_cmd;
  1213. unsigned long later;
  1214. lpfc_block_error_handler(cmnd);
  1215. /*
  1216. * Since the driver manages a single bus device, reset all
  1217. * targets known to the driver. Should any target reset
  1218. * fail, this routine returns failure to the midlayer.
  1219. */
  1220. for (i = 0; i < LPFC_MAX_TARGET; i++) {
  1221. /* Search for mapped node by target ID */
  1222. match = 0;
  1223. spin_lock_irq(shost->host_lock);
  1224. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  1225. if (!NLP_CHK_NODE_ACT(ndlp))
  1226. continue;
  1227. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  1228. ndlp->nlp_sid == i &&
  1229. ndlp->rport) {
  1230. match = 1;
  1231. break;
  1232. }
  1233. }
  1234. spin_unlock_irq(shost->host_lock);
  1235. if (!match)
  1236. continue;
  1237. lpfc_cmd = lpfc_get_scsi_buf(phba);
  1238. if (lpfc_cmd) {
  1239. lpfc_cmd->timeout = 60;
  1240. status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
  1241. cmnd->device->lun,
  1242. ndlp->rport->dd_data);
  1243. if (status != TIMEOUT_ERROR)
  1244. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1245. }
  1246. if (!lpfc_cmd || status != SUCCESS) {
  1247. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1248. "0700 Bus Reset on target %d failed\n",
  1249. i);
  1250. ret = FAILED;
  1251. }
  1252. }
  1253. /*
  1254. * All outstanding txcmplq I/Os should have been aborted by
  1255. * the targets. Unfortunately, some targets do not abide by
  1256. * this forcing the driver to double check.
  1257. */
  1258. cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
  1259. if (cnt)
  1260. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  1261. 0, 0, LPFC_CTX_HOST);
  1262. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  1263. while (time_after(later, jiffies) && cnt) {
  1264. schedule_timeout_uninterruptible(msecs_to_jiffies(20));
  1265. cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
  1266. }
  1267. if (cnt) {
  1268. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1269. "0715 Bus Reset I/O flush failure: "
  1270. "cnt x%x left x%x\n", cnt, i);
  1271. ret = FAILED;
  1272. }
  1273. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1274. "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
  1275. return ret;
  1276. }
  1277. static int
  1278. lpfc_slave_alloc(struct scsi_device *sdev)
  1279. {
  1280. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  1281. struct lpfc_hba *phba = vport->phba;
  1282. struct lpfc_scsi_buf *scsi_buf = NULL;
  1283. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1284. uint32_t total = 0, i;
  1285. uint32_t num_to_alloc = 0;
  1286. unsigned long flags;
  1287. if (!rport || fc_remote_port_chkready(rport))
  1288. return -ENXIO;
  1289. sdev->hostdata = rport->dd_data;
  1290. /*
  1291. * Populate the cmds_per_lun count scsi_bufs into this host's globally
  1292. * available list of scsi buffers. Don't allocate more than the
  1293. * HBA limit conveyed to the midlayer via the host structure. The
  1294. * formula accounts for the lun_queue_depth + error handlers + 1
  1295. * extra. This list of scsi bufs exists for the lifetime of the driver.
  1296. */
  1297. total = phba->total_scsi_bufs;
  1298. num_to_alloc = vport->cfg_lun_queue_depth + 2;
  1299. /* Allow some exchanges to be available always to complete discovery */
  1300. if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
  1301. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  1302. "0704 At limitation of %d preallocated "
  1303. "command buffers\n", total);
  1304. return 0;
  1305. /* Allow some exchanges to be available always to complete discovery */
  1306. } else if (total + num_to_alloc >
  1307. phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
  1308. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  1309. "0705 Allocation request of %d "
  1310. "command buffers will exceed max of %d. "
  1311. "Reducing allocation request to %d.\n",
  1312. num_to_alloc, phba->cfg_hba_queue_depth,
  1313. (phba->cfg_hba_queue_depth - total));
  1314. num_to_alloc = phba->cfg_hba_queue_depth - total;
  1315. }
  1316. for (i = 0; i < num_to_alloc; i++) {
  1317. scsi_buf = lpfc_new_scsi_buf(vport);
  1318. if (!scsi_buf) {
  1319. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1320. "0706 Failed to allocate "
  1321. "command buffer\n");
  1322. break;
  1323. }
  1324. spin_lock_irqsave(&phba->scsi_buf_list_lock, flags);
  1325. phba->total_scsi_bufs++;
  1326. list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list);
  1327. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags);
  1328. }
  1329. return 0;
  1330. }
  1331. static int
  1332. lpfc_slave_configure(struct scsi_device *sdev)
  1333. {
  1334. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  1335. struct lpfc_hba *phba = vport->phba;
  1336. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  1337. if (sdev->tagged_supported)
  1338. scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
  1339. else
  1340. scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
  1341. /*
  1342. * Initialize the fc transport attributes for the target
  1343. * containing this scsi device. Also note that the driver's
  1344. * target pointer is stored in the starget_data for the
  1345. * driver's sysfs entry point functions.
  1346. */
  1347. rport->dev_loss_tmo = vport->cfg_devloss_tmo;
  1348. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  1349. lpfc_sli_poll_fcp_ring(phba);
  1350. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  1351. lpfc_poll_rearm_timer(phba);
  1352. }
  1353. return 0;
  1354. }
  1355. static void
  1356. lpfc_slave_destroy(struct scsi_device *sdev)
  1357. {
  1358. sdev->hostdata = NULL;
  1359. return;
  1360. }
  1361. struct scsi_host_template lpfc_template = {
  1362. .module = THIS_MODULE,
  1363. .name = LPFC_DRIVER_NAME,
  1364. .info = lpfc_info,
  1365. .queuecommand = lpfc_queuecommand,
  1366. .eh_abort_handler = lpfc_abort_handler,
  1367. .eh_device_reset_handler= lpfc_device_reset_handler,
  1368. .eh_bus_reset_handler = lpfc_bus_reset_handler,
  1369. .slave_alloc = lpfc_slave_alloc,
  1370. .slave_configure = lpfc_slave_configure,
  1371. .slave_destroy = lpfc_slave_destroy,
  1372. .scan_finished = lpfc_scan_finished,
  1373. .this_id = -1,
  1374. .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
  1375. .cmd_per_lun = LPFC_CMD_PER_LUN,
  1376. .use_clustering = ENABLE_CLUSTERING,
  1377. .shost_attrs = lpfc_hba_attrs,
  1378. .max_sectors = 0xFFFF,
  1379. };
  1380. struct scsi_host_template lpfc_vport_template = {
  1381. .module = THIS_MODULE,
  1382. .name = LPFC_DRIVER_NAME,
  1383. .info = lpfc_info,
  1384. .queuecommand = lpfc_queuecommand,
  1385. .eh_abort_handler = lpfc_abort_handler,
  1386. .eh_device_reset_handler= lpfc_device_reset_handler,
  1387. .eh_bus_reset_handler = lpfc_bus_reset_handler,
  1388. .slave_alloc = lpfc_slave_alloc,
  1389. .slave_configure = lpfc_slave_configure,
  1390. .slave_destroy = lpfc_slave_destroy,
  1391. .scan_finished = lpfc_scan_finished,
  1392. .this_id = -1,
  1393. .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
  1394. .cmd_per_lun = LPFC_CMD_PER_LUN,
  1395. .use_clustering = ENABLE_CLUSTERING,
  1396. .shost_attrs = lpfc_vport_attrs,
  1397. .max_sectors = 0xFFFF,
  1398. };