lpfc_scsi.c 45 KB

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