lpfc_scsi.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556
  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_TRANSPORT_DISRUPTED, 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_TRANSPORT_DISRUPTED,
  611. SAM_STAT_BUSY);
  612. } else {
  613. cmd->result = ScsiResult(DID_OK, 0);
  614. }
  615. if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
  616. uint32_t *lp = (uint32_t *)cmd->sense_buffer;
  617. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  618. "0710 Iodone <%d/%d> cmd %p, error "
  619. "x%x SNS x%x x%x Data: x%x x%x\n",
  620. cmd->device->id, cmd->device->lun, cmd,
  621. cmd->result, *lp, *(lp + 3), cmd->retries,
  622. scsi_get_resid(cmd));
  623. }
  624. result = cmd->result;
  625. sdev = cmd->device;
  626. lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
  627. cmd->scsi_done(cmd);
  628. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  629. /*
  630. * If there is a thread waiting for command completion
  631. * wake up the thread.
  632. */
  633. spin_lock_irqsave(sdev->host->host_lock, flags);
  634. lpfc_cmd->pCmd = NULL;
  635. if (lpfc_cmd->waitq)
  636. wake_up(lpfc_cmd->waitq);
  637. spin_unlock_irqrestore(sdev->host->host_lock, flags);
  638. lpfc_release_scsi_buf(phba, lpfc_cmd);
  639. return;
  640. }
  641. if (!result)
  642. lpfc_rampup_queue_depth(vport, sdev);
  643. if (!result && pnode && NLP_CHK_NODE_ACT(pnode) &&
  644. ((jiffies - pnode->last_ramp_up_time) >
  645. LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
  646. ((jiffies - pnode->last_q_full_time) >
  647. LPFC_Q_RAMP_UP_INTERVAL * HZ) &&
  648. (vport->cfg_lun_queue_depth > sdev->queue_depth)) {
  649. shost_for_each_device(tmp_sdev, sdev->host) {
  650. if (vport->cfg_lun_queue_depth > tmp_sdev->queue_depth){
  651. if (tmp_sdev->id != sdev->id)
  652. continue;
  653. if (tmp_sdev->ordered_tags)
  654. scsi_adjust_queue_depth(tmp_sdev,
  655. MSG_ORDERED_TAG,
  656. tmp_sdev->queue_depth+1);
  657. else
  658. scsi_adjust_queue_depth(tmp_sdev,
  659. MSG_SIMPLE_TAG,
  660. tmp_sdev->queue_depth+1);
  661. pnode->last_ramp_up_time = jiffies;
  662. }
  663. }
  664. }
  665. /*
  666. * Check for queue full. If the lun is reporting queue full, then
  667. * back off the lun queue depth to prevent target overloads.
  668. */
  669. if (result == SAM_STAT_TASK_SET_FULL && pnode &&
  670. NLP_CHK_NODE_ACT(pnode)) {
  671. pnode->last_q_full_time = jiffies;
  672. shost_for_each_device(tmp_sdev, sdev->host) {
  673. if (tmp_sdev->id != sdev->id)
  674. continue;
  675. depth = scsi_track_queue_full(tmp_sdev,
  676. tmp_sdev->queue_depth - 1);
  677. }
  678. /*
  679. * The queue depth cannot be lowered any more.
  680. * Modify the returned error code to store
  681. * the final depth value set by
  682. * scsi_track_queue_full.
  683. */
  684. if (depth == -1)
  685. depth = sdev->host->cmd_per_lun;
  686. if (depth) {
  687. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  688. "0711 detected queue full - lun queue "
  689. "depth adjusted to %d.\n", depth);
  690. }
  691. }
  692. /*
  693. * If there is a thread waiting for command completion
  694. * wake up the thread.
  695. */
  696. spin_lock_irqsave(sdev->host->host_lock, flags);
  697. lpfc_cmd->pCmd = NULL;
  698. if (lpfc_cmd->waitq)
  699. wake_up(lpfc_cmd->waitq);
  700. spin_unlock_irqrestore(sdev->host->host_lock, flags);
  701. lpfc_release_scsi_buf(phba, lpfc_cmd);
  702. }
  703. /**
  704. * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB.
  705. * @data: A pointer to the immediate command data portion of the IOCB.
  706. * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
  707. *
  708. * The routine copies the entire FCP command from @fcp_cmnd to @data while
  709. * byte swapping the data to big endian format for transmission on the wire.
  710. **/
  711. static void
  712. lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
  713. {
  714. int i, j;
  715. for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
  716. i += sizeof(uint32_t), j++) {
  717. ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
  718. }
  719. }
  720. static void
  721. lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
  722. struct lpfc_nodelist *pnode)
  723. {
  724. struct lpfc_hba *phba = vport->phba;
  725. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  726. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  727. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  728. struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
  729. int datadir = scsi_cmnd->sc_data_direction;
  730. char tag[2];
  731. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  732. return;
  733. lpfc_cmd->fcp_rsp->rspSnsLen = 0;
  734. /* clear task management bits */
  735. lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
  736. int_to_scsilun(lpfc_cmd->pCmd->device->lun,
  737. &lpfc_cmd->fcp_cmnd->fcp_lun);
  738. memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
  739. if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
  740. switch (tag[0]) {
  741. case HEAD_OF_QUEUE_TAG:
  742. fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
  743. break;
  744. case ORDERED_QUEUE_TAG:
  745. fcp_cmnd->fcpCntl1 = ORDERED_Q;
  746. break;
  747. default:
  748. fcp_cmnd->fcpCntl1 = SIMPLE_Q;
  749. break;
  750. }
  751. } else
  752. fcp_cmnd->fcpCntl1 = 0;
  753. /*
  754. * There are three possibilities here - use scatter-gather segment, use
  755. * the single mapping, or neither. Start the lpfc command prep by
  756. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  757. * data bde entry.
  758. */
  759. if (scsi_sg_count(scsi_cmnd)) {
  760. if (datadir == DMA_TO_DEVICE) {
  761. iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
  762. iocb_cmd->un.fcpi.fcpi_parm = 0;
  763. iocb_cmd->ulpPU = 0;
  764. fcp_cmnd->fcpCntl3 = WRITE_DATA;
  765. phba->fc4OutputRequests++;
  766. } else {
  767. iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
  768. iocb_cmd->ulpPU = PARM_READ_CHECK;
  769. iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
  770. fcp_cmnd->fcpCntl3 = READ_DATA;
  771. phba->fc4InputRequests++;
  772. }
  773. } else {
  774. iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
  775. iocb_cmd->un.fcpi.fcpi_parm = 0;
  776. iocb_cmd->ulpPU = 0;
  777. fcp_cmnd->fcpCntl3 = 0;
  778. phba->fc4ControlRequests++;
  779. }
  780. if (phba->sli_rev == 3)
  781. lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
  782. /*
  783. * Finish initializing those IOCB fields that are independent
  784. * of the scsi_cmnd request_buffer
  785. */
  786. piocbq->iocb.ulpContext = pnode->nlp_rpi;
  787. if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
  788. piocbq->iocb.ulpFCP2Rcvy = 1;
  789. else
  790. piocbq->iocb.ulpFCP2Rcvy = 0;
  791. piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
  792. piocbq->context1 = lpfc_cmd;
  793. piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
  794. piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
  795. piocbq->vport = vport;
  796. }
  797. static int
  798. lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
  799. struct lpfc_scsi_buf *lpfc_cmd,
  800. unsigned int lun,
  801. uint8_t task_mgmt_cmd)
  802. {
  803. struct lpfc_iocbq *piocbq;
  804. IOCB_t *piocb;
  805. struct fcp_cmnd *fcp_cmnd;
  806. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  807. struct lpfc_nodelist *ndlp = rdata->pnode;
  808. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
  809. ndlp->nlp_state != NLP_STE_MAPPED_NODE)
  810. return 0;
  811. piocbq = &(lpfc_cmd->cur_iocbq);
  812. piocbq->vport = vport;
  813. piocb = &piocbq->iocb;
  814. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  815. /* Clear out any old data in the FCP command area */
  816. memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
  817. int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
  818. fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
  819. if (vport->phba->sli_rev == 3)
  820. lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
  821. piocb->ulpCommand = CMD_FCP_ICMND64_CR;
  822. piocb->ulpContext = ndlp->nlp_rpi;
  823. if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
  824. piocb->ulpFCP2Rcvy = 1;
  825. }
  826. piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
  827. /* ulpTimeout is only one byte */
  828. if (lpfc_cmd->timeout > 0xff) {
  829. /*
  830. * Do not timeout the command at the firmware level.
  831. * The driver will provide the timeout mechanism.
  832. */
  833. piocb->ulpTimeout = 0;
  834. } else {
  835. piocb->ulpTimeout = lpfc_cmd->timeout;
  836. }
  837. return 1;
  838. }
  839. static void
  840. lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
  841. struct lpfc_iocbq *cmdiocbq,
  842. struct lpfc_iocbq *rspiocbq)
  843. {
  844. struct lpfc_scsi_buf *lpfc_cmd =
  845. (struct lpfc_scsi_buf *) cmdiocbq->context1;
  846. if (lpfc_cmd)
  847. lpfc_release_scsi_buf(phba, lpfc_cmd);
  848. return;
  849. }
  850. static int
  851. lpfc_scsi_tgt_reset(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_vport *vport,
  852. unsigned tgt_id, unsigned int lun,
  853. struct lpfc_rport_data *rdata)
  854. {
  855. struct lpfc_hba *phba = vport->phba;
  856. struct lpfc_iocbq *iocbq;
  857. struct lpfc_iocbq *iocbqrsp;
  858. int ret;
  859. int status;
  860. if (!rdata->pnode || !NLP_CHK_NODE_ACT(rdata->pnode))
  861. return FAILED;
  862. lpfc_cmd->rdata = rdata;
  863. status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun,
  864. FCP_TARGET_RESET);
  865. if (!status)
  866. return FAILED;
  867. iocbq = &lpfc_cmd->cur_iocbq;
  868. iocbqrsp = lpfc_sli_get_iocbq(phba);
  869. if (!iocbqrsp)
  870. return FAILED;
  871. /* Issue Target Reset to TGT <num> */
  872. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  873. "0702 Issue Target Reset to TGT %d Data: x%x x%x\n",
  874. tgt_id, rdata->pnode->nlp_rpi, rdata->pnode->nlp_flag);
  875. status = lpfc_sli_issue_iocb_wait(phba,
  876. &phba->sli.ring[phba->sli.fcp_ring],
  877. iocbq, iocbqrsp, lpfc_cmd->timeout);
  878. if (status != IOCB_SUCCESS) {
  879. if (status == IOCB_TIMEDOUT) {
  880. iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
  881. ret = TIMEOUT_ERROR;
  882. } else
  883. ret = FAILED;
  884. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  885. } else {
  886. ret = SUCCESS;
  887. lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
  888. lpfc_cmd->status = iocbqrsp->iocb.ulpStatus;
  889. if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
  890. (lpfc_cmd->result & IOERR_DRVR_MASK))
  891. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  892. }
  893. lpfc_sli_release_iocbq(phba, iocbqrsp);
  894. return ret;
  895. }
  896. const char *
  897. lpfc_info(struct Scsi_Host *host)
  898. {
  899. struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
  900. struct lpfc_hba *phba = vport->phba;
  901. int len;
  902. static char lpfcinfobuf[384];
  903. memset(lpfcinfobuf,0,384);
  904. if (phba && phba->pcidev){
  905. strncpy(lpfcinfobuf, phba->ModelDesc, 256);
  906. len = strlen(lpfcinfobuf);
  907. snprintf(lpfcinfobuf + len,
  908. 384-len,
  909. " on PCI bus %02x device %02x irq %d",
  910. phba->pcidev->bus->number,
  911. phba->pcidev->devfn,
  912. phba->pcidev->irq);
  913. len = strlen(lpfcinfobuf);
  914. if (phba->Port[0]) {
  915. snprintf(lpfcinfobuf + len,
  916. 384-len,
  917. " port %s",
  918. phba->Port);
  919. }
  920. }
  921. return lpfcinfobuf;
  922. }
  923. static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
  924. {
  925. unsigned long poll_tmo_expires =
  926. (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
  927. if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
  928. mod_timer(&phba->fcp_poll_timer,
  929. poll_tmo_expires);
  930. }
  931. void lpfc_poll_start_timer(struct lpfc_hba * phba)
  932. {
  933. lpfc_poll_rearm_timer(phba);
  934. }
  935. void lpfc_poll_timeout(unsigned long ptr)
  936. {
  937. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  938. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  939. lpfc_sli_poll_fcp_ring (phba);
  940. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  941. lpfc_poll_rearm_timer(phba);
  942. }
  943. }
  944. static int
  945. lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
  946. {
  947. struct Scsi_Host *shost = cmnd->device->host;
  948. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  949. struct lpfc_hba *phba = vport->phba;
  950. struct lpfc_sli *psli = &phba->sli;
  951. struct lpfc_rport_data *rdata = cmnd->device->hostdata;
  952. struct lpfc_nodelist *ndlp = rdata->pnode;
  953. struct lpfc_scsi_buf *lpfc_cmd;
  954. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  955. int err;
  956. err = fc_remote_port_chkready(rport);
  957. if (err) {
  958. cmnd->result = err;
  959. goto out_fail_command;
  960. }
  961. /*
  962. * Catch race where our node has transitioned, but the
  963. * transport is still transitioning.
  964. */
  965. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  966. cmnd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
  967. goto out_fail_command;
  968. }
  969. lpfc_cmd = lpfc_get_scsi_buf(phba);
  970. if (lpfc_cmd == NULL) {
  971. lpfc_adjust_queue_depth(phba);
  972. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  973. "0707 driver's buffer pool is empty, "
  974. "IO busied\n");
  975. goto out_host_busy;
  976. }
  977. /*
  978. * Store the midlayer's command structure for the completion phase
  979. * and complete the command initialization.
  980. */
  981. lpfc_cmd->pCmd = cmnd;
  982. lpfc_cmd->rdata = rdata;
  983. lpfc_cmd->timeout = 0;
  984. cmnd->host_scribble = (unsigned char *)lpfc_cmd;
  985. cmnd->scsi_done = done;
  986. err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
  987. if (err)
  988. goto out_host_busy_free_buf;
  989. lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
  990. err = lpfc_sli_issue_iocb(phba, &phba->sli.ring[psli->fcp_ring],
  991. &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
  992. if (err)
  993. goto out_host_busy_free_buf;
  994. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  995. lpfc_sli_poll_fcp_ring(phba);
  996. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  997. lpfc_poll_rearm_timer(phba);
  998. }
  999. return 0;
  1000. out_host_busy_free_buf:
  1001. lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
  1002. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1003. out_host_busy:
  1004. return SCSI_MLQUEUE_HOST_BUSY;
  1005. out_fail_command:
  1006. done(cmnd);
  1007. return 0;
  1008. }
  1009. static void
  1010. lpfc_block_error_handler(struct scsi_cmnd *cmnd)
  1011. {
  1012. struct Scsi_Host *shost = cmnd->device->host;
  1013. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  1014. spin_lock_irq(shost->host_lock);
  1015. while (rport->port_state == FC_PORTSTATE_BLOCKED) {
  1016. spin_unlock_irq(shost->host_lock);
  1017. msleep(1000);
  1018. spin_lock_irq(shost->host_lock);
  1019. }
  1020. spin_unlock_irq(shost->host_lock);
  1021. return;
  1022. }
  1023. static int
  1024. lpfc_abort_handler(struct scsi_cmnd *cmnd)
  1025. {
  1026. struct Scsi_Host *shost = cmnd->device->host;
  1027. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1028. struct lpfc_hba *phba = vport->phba;
  1029. struct lpfc_sli_ring *pring = &phba->sli.ring[phba->sli.fcp_ring];
  1030. struct lpfc_iocbq *iocb;
  1031. struct lpfc_iocbq *abtsiocb;
  1032. struct lpfc_scsi_buf *lpfc_cmd;
  1033. IOCB_t *cmd, *icmd;
  1034. int ret = SUCCESS;
  1035. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
  1036. lpfc_block_error_handler(cmnd);
  1037. lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
  1038. BUG_ON(!lpfc_cmd);
  1039. /*
  1040. * If pCmd field of the corresponding lpfc_scsi_buf structure
  1041. * points to a different SCSI command, then the driver has
  1042. * already completed this command, but the midlayer did not
  1043. * see the completion before the eh fired. Just return
  1044. * SUCCESS.
  1045. */
  1046. iocb = &lpfc_cmd->cur_iocbq;
  1047. if (lpfc_cmd->pCmd != cmnd)
  1048. goto out;
  1049. BUG_ON(iocb->context1 != lpfc_cmd);
  1050. abtsiocb = lpfc_sli_get_iocbq(phba);
  1051. if (abtsiocb == NULL) {
  1052. ret = FAILED;
  1053. goto out;
  1054. }
  1055. /*
  1056. * The scsi command can not be in txq and it is in flight because the
  1057. * pCmd is still pointig at the SCSI command we have to abort. There
  1058. * is no need to search the txcmplq. Just send an abort to the FW.
  1059. */
  1060. cmd = &iocb->iocb;
  1061. icmd = &abtsiocb->iocb;
  1062. icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
  1063. icmd->un.acxri.abortContextTag = cmd->ulpContext;
  1064. icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
  1065. icmd->ulpLe = 1;
  1066. icmd->ulpClass = cmd->ulpClass;
  1067. if (lpfc_is_link_up(phba))
  1068. icmd->ulpCommand = CMD_ABORT_XRI_CN;
  1069. else
  1070. icmd->ulpCommand = CMD_CLOSE_XRI_CN;
  1071. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  1072. abtsiocb->vport = vport;
  1073. if (lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0) == IOCB_ERROR) {
  1074. lpfc_sli_release_iocbq(phba, abtsiocb);
  1075. ret = FAILED;
  1076. goto out;
  1077. }
  1078. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  1079. lpfc_sli_poll_fcp_ring (phba);
  1080. lpfc_cmd->waitq = &waitq;
  1081. /* Wait for abort to complete */
  1082. wait_event_timeout(waitq,
  1083. (lpfc_cmd->pCmd != cmnd),
  1084. (2*vport->cfg_devloss_tmo*HZ));
  1085. spin_lock_irq(shost->host_lock);
  1086. lpfc_cmd->waitq = NULL;
  1087. spin_unlock_irq(shost->host_lock);
  1088. if (lpfc_cmd->pCmd == cmnd) {
  1089. ret = FAILED;
  1090. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1091. "0748 abort handler timed out waiting "
  1092. "for abort to complete: ret %#x, ID %d, "
  1093. "LUN %d, snum %#lx\n",
  1094. ret, cmnd->device->id, cmnd->device->lun,
  1095. cmnd->serial_number);
  1096. }
  1097. out:
  1098. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  1099. "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
  1100. "LUN %d snum %#lx\n", ret, cmnd->device->id,
  1101. cmnd->device->lun, cmnd->serial_number);
  1102. return ret;
  1103. }
  1104. static int
  1105. lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
  1106. {
  1107. struct Scsi_Host *shost = cmnd->device->host;
  1108. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1109. struct lpfc_hba *phba = vport->phba;
  1110. struct lpfc_scsi_buf *lpfc_cmd;
  1111. struct lpfc_iocbq *iocbq, *iocbqrsp;
  1112. struct lpfc_rport_data *rdata = cmnd->device->hostdata;
  1113. struct lpfc_nodelist *pnode = rdata->pnode;
  1114. unsigned long later;
  1115. int ret = SUCCESS;
  1116. int status;
  1117. int cnt;
  1118. lpfc_block_error_handler(cmnd);
  1119. /*
  1120. * If target is not in a MAPPED state, delay the reset until
  1121. * target is rediscovered or devloss timeout expires.
  1122. */
  1123. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  1124. while (time_after(later, jiffies)) {
  1125. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  1126. return FAILED;
  1127. if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
  1128. break;
  1129. schedule_timeout_uninterruptible(msecs_to_jiffies(500));
  1130. rdata = cmnd->device->hostdata;
  1131. if (!rdata)
  1132. break;
  1133. pnode = rdata->pnode;
  1134. }
  1135. if (!rdata || pnode->nlp_state != NLP_STE_MAPPED_NODE) {
  1136. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1137. "0721 LUN Reset rport "
  1138. "failure: msec x%x rdata x%p\n",
  1139. jiffies_to_msecs(jiffies - later), rdata);
  1140. return FAILED;
  1141. }
  1142. lpfc_cmd = lpfc_get_scsi_buf(phba);
  1143. if (lpfc_cmd == NULL)
  1144. return FAILED;
  1145. lpfc_cmd->timeout = 60;
  1146. lpfc_cmd->rdata = rdata;
  1147. status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd,
  1148. cmnd->device->lun,
  1149. FCP_TARGET_RESET);
  1150. if (!status) {
  1151. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1152. return FAILED;
  1153. }
  1154. iocbq = &lpfc_cmd->cur_iocbq;
  1155. /* get a buffer for this IOCB command response */
  1156. iocbqrsp = lpfc_sli_get_iocbq(phba);
  1157. if (iocbqrsp == NULL) {
  1158. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1159. return FAILED;
  1160. }
  1161. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  1162. "0703 Issue target reset to TGT %d LUN %d "
  1163. "rpi x%x nlp_flag x%x\n", cmnd->device->id,
  1164. cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
  1165. status = lpfc_sli_issue_iocb_wait(phba,
  1166. &phba->sli.ring[phba->sli.fcp_ring],
  1167. iocbq, iocbqrsp, lpfc_cmd->timeout);
  1168. if (status == IOCB_TIMEDOUT) {
  1169. iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
  1170. ret = TIMEOUT_ERROR;
  1171. } else {
  1172. if (status != IOCB_SUCCESS)
  1173. ret = FAILED;
  1174. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1175. }
  1176. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1177. "0713 SCSI layer issued device reset (%d, %d) "
  1178. "return x%x status x%x result x%x\n",
  1179. cmnd->device->id, cmnd->device->lun, ret,
  1180. iocbqrsp->iocb.ulpStatus,
  1181. iocbqrsp->iocb.un.ulpWord[4]);
  1182. lpfc_sli_release_iocbq(phba, iocbqrsp);
  1183. cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id, cmnd->device->lun,
  1184. LPFC_CTX_TGT);
  1185. if (cnt)
  1186. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  1187. cmnd->device->id, cmnd->device->lun,
  1188. LPFC_CTX_TGT);
  1189. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  1190. while (time_after(later, jiffies) && cnt) {
  1191. schedule_timeout_uninterruptible(msecs_to_jiffies(20));
  1192. cnt = lpfc_sli_sum_iocb(vport, cmnd->device->id,
  1193. cmnd->device->lun, LPFC_CTX_TGT);
  1194. }
  1195. if (cnt) {
  1196. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1197. "0719 device reset I/O flush failure: "
  1198. "cnt x%x\n", cnt);
  1199. ret = FAILED;
  1200. }
  1201. return ret;
  1202. }
  1203. static int
  1204. lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
  1205. {
  1206. struct Scsi_Host *shost = cmnd->device->host;
  1207. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1208. struct lpfc_hba *phba = vport->phba;
  1209. struct lpfc_nodelist *ndlp = NULL;
  1210. int match;
  1211. int ret = SUCCESS, status = SUCCESS, i;
  1212. int cnt;
  1213. struct lpfc_scsi_buf * lpfc_cmd;
  1214. unsigned long later;
  1215. lpfc_block_error_handler(cmnd);
  1216. /*
  1217. * Since the driver manages a single bus device, reset all
  1218. * targets known to the driver. Should any target reset
  1219. * fail, this routine returns failure to the midlayer.
  1220. */
  1221. for (i = 0; i < LPFC_MAX_TARGET; i++) {
  1222. /* Search for mapped node by target ID */
  1223. match = 0;
  1224. spin_lock_irq(shost->host_lock);
  1225. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  1226. if (!NLP_CHK_NODE_ACT(ndlp))
  1227. continue;
  1228. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  1229. ndlp->nlp_sid == i &&
  1230. ndlp->rport) {
  1231. match = 1;
  1232. break;
  1233. }
  1234. }
  1235. spin_unlock_irq(shost->host_lock);
  1236. if (!match)
  1237. continue;
  1238. lpfc_cmd = lpfc_get_scsi_buf(phba);
  1239. if (lpfc_cmd) {
  1240. lpfc_cmd->timeout = 60;
  1241. status = lpfc_scsi_tgt_reset(lpfc_cmd, vport, i,
  1242. cmnd->device->lun,
  1243. ndlp->rport->dd_data);
  1244. if (status != TIMEOUT_ERROR)
  1245. lpfc_release_scsi_buf(phba, lpfc_cmd);
  1246. }
  1247. if (!lpfc_cmd || status != SUCCESS) {
  1248. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1249. "0700 Bus Reset on target %d failed\n",
  1250. i);
  1251. ret = FAILED;
  1252. }
  1253. }
  1254. /*
  1255. * All outstanding txcmplq I/Os should have been aborted by
  1256. * the targets. Unfortunately, some targets do not abide by
  1257. * this forcing the driver to double check.
  1258. */
  1259. cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
  1260. if (cnt)
  1261. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  1262. 0, 0, LPFC_CTX_HOST);
  1263. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  1264. while (time_after(later, jiffies) && cnt) {
  1265. schedule_timeout_uninterruptible(msecs_to_jiffies(20));
  1266. cnt = lpfc_sli_sum_iocb(vport, 0, 0, LPFC_CTX_HOST);
  1267. }
  1268. if (cnt) {
  1269. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1270. "0715 Bus Reset I/O flush failure: "
  1271. "cnt x%x left x%x\n", cnt, i);
  1272. ret = FAILED;
  1273. }
  1274. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1275. "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
  1276. return ret;
  1277. }
  1278. static int
  1279. lpfc_slave_alloc(struct scsi_device *sdev)
  1280. {
  1281. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  1282. struct lpfc_hba *phba = vport->phba;
  1283. struct lpfc_scsi_buf *scsi_buf = NULL;
  1284. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1285. uint32_t total = 0, i;
  1286. uint32_t num_to_alloc = 0;
  1287. unsigned long flags;
  1288. if (!rport || fc_remote_port_chkready(rport))
  1289. return -ENXIO;
  1290. sdev->hostdata = rport->dd_data;
  1291. /*
  1292. * Populate the cmds_per_lun count scsi_bufs into this host's globally
  1293. * available list of scsi buffers. Don't allocate more than the
  1294. * HBA limit conveyed to the midlayer via the host structure. The
  1295. * formula accounts for the lun_queue_depth + error handlers + 1
  1296. * extra. This list of scsi bufs exists for the lifetime of the driver.
  1297. */
  1298. total = phba->total_scsi_bufs;
  1299. num_to_alloc = vport->cfg_lun_queue_depth + 2;
  1300. /* Allow some exchanges to be available always to complete discovery */
  1301. if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
  1302. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  1303. "0704 At limitation of %d preallocated "
  1304. "command buffers\n", total);
  1305. return 0;
  1306. /* Allow some exchanges to be available always to complete discovery */
  1307. } else if (total + num_to_alloc >
  1308. phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
  1309. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  1310. "0705 Allocation request of %d "
  1311. "command buffers will exceed max of %d. "
  1312. "Reducing allocation request to %d.\n",
  1313. num_to_alloc, phba->cfg_hba_queue_depth,
  1314. (phba->cfg_hba_queue_depth - total));
  1315. num_to_alloc = phba->cfg_hba_queue_depth - total;
  1316. }
  1317. for (i = 0; i < num_to_alloc; i++) {
  1318. scsi_buf = lpfc_new_scsi_buf(vport);
  1319. if (!scsi_buf) {
  1320. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  1321. "0706 Failed to allocate "
  1322. "command buffer\n");
  1323. break;
  1324. }
  1325. spin_lock_irqsave(&phba->scsi_buf_list_lock, flags);
  1326. phba->total_scsi_bufs++;
  1327. list_add_tail(&scsi_buf->list, &phba->lpfc_scsi_buf_list);
  1328. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, flags);
  1329. }
  1330. return 0;
  1331. }
  1332. static int
  1333. lpfc_slave_configure(struct scsi_device *sdev)
  1334. {
  1335. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  1336. struct lpfc_hba *phba = vport->phba;
  1337. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  1338. if (sdev->tagged_supported)
  1339. scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
  1340. else
  1341. scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
  1342. /*
  1343. * Initialize the fc transport attributes for the target
  1344. * containing this scsi device. Also note that the driver's
  1345. * target pointer is stored in the starget_data for the
  1346. * driver's sysfs entry point functions.
  1347. */
  1348. rport->dev_loss_tmo = vport->cfg_devloss_tmo;
  1349. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  1350. lpfc_sli_poll_fcp_ring(phba);
  1351. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  1352. lpfc_poll_rearm_timer(phba);
  1353. }
  1354. return 0;
  1355. }
  1356. static void
  1357. lpfc_slave_destroy(struct scsi_device *sdev)
  1358. {
  1359. sdev->hostdata = NULL;
  1360. return;
  1361. }
  1362. struct scsi_host_template lpfc_template = {
  1363. .module = THIS_MODULE,
  1364. .name = LPFC_DRIVER_NAME,
  1365. .info = lpfc_info,
  1366. .queuecommand = lpfc_queuecommand,
  1367. .eh_abort_handler = lpfc_abort_handler,
  1368. .eh_device_reset_handler= lpfc_device_reset_handler,
  1369. .eh_bus_reset_handler = lpfc_bus_reset_handler,
  1370. .slave_alloc = lpfc_slave_alloc,
  1371. .slave_configure = lpfc_slave_configure,
  1372. .slave_destroy = lpfc_slave_destroy,
  1373. .scan_finished = lpfc_scan_finished,
  1374. .this_id = -1,
  1375. .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
  1376. .cmd_per_lun = LPFC_CMD_PER_LUN,
  1377. .use_clustering = ENABLE_CLUSTERING,
  1378. .shost_attrs = lpfc_hba_attrs,
  1379. .max_sectors = 0xFFFF,
  1380. };
  1381. struct scsi_host_template lpfc_vport_template = {
  1382. .module = THIS_MODULE,
  1383. .name = LPFC_DRIVER_NAME,
  1384. .info = lpfc_info,
  1385. .queuecommand = lpfc_queuecommand,
  1386. .eh_abort_handler = lpfc_abort_handler,
  1387. .eh_device_reset_handler= lpfc_device_reset_handler,
  1388. .eh_bus_reset_handler = lpfc_bus_reset_handler,
  1389. .slave_alloc = lpfc_slave_alloc,
  1390. .slave_configure = lpfc_slave_configure,
  1391. .slave_destroy = lpfc_slave_destroy,
  1392. .scan_finished = lpfc_scan_finished,
  1393. .this_id = -1,
  1394. .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
  1395. .cmd_per_lun = LPFC_CMD_PER_LUN,
  1396. .use_clustering = ENABLE_CLUSTERING,
  1397. .shost_attrs = lpfc_vport_attrs,
  1398. .max_sectors = 0xFFFF,
  1399. };