lpfc_scsi.c 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2011 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/slab.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/delay.h>
  25. #include <asm/unaligned.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_eh.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_tcq.h>
  31. #include <scsi/scsi_transport_fc.h>
  32. #include "lpfc_version.h"
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_logmsg.h"
  42. #include "lpfc_crtn.h"
  43. #include "lpfc_vport.h"
  44. #define LPFC_RESET_WAIT 2
  45. #define LPFC_ABORT_WAIT 2
  46. int _dump_buf_done;
  47. static char *dif_op_str[] = {
  48. "SCSI_PROT_NORMAL",
  49. "SCSI_PROT_READ_INSERT",
  50. "SCSI_PROT_WRITE_STRIP",
  51. "SCSI_PROT_READ_STRIP",
  52. "SCSI_PROT_WRITE_INSERT",
  53. "SCSI_PROT_READ_PASS",
  54. "SCSI_PROT_WRITE_PASS",
  55. };
  56. static void
  57. lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
  58. static void
  59. lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb);
  60. static void
  61. lpfc_debug_save_data(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
  62. {
  63. void *src, *dst;
  64. struct scatterlist *sgde = scsi_sglist(cmnd);
  65. if (!_dump_buf_data) {
  66. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  67. "9050 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
  68. __func__);
  69. return;
  70. }
  71. if (!sgde) {
  72. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  73. "9051 BLKGRD: ERROR: data scatterlist is null\n");
  74. return;
  75. }
  76. dst = (void *) _dump_buf_data;
  77. while (sgde) {
  78. src = sg_virt(sgde);
  79. memcpy(dst, src, sgde->length);
  80. dst += sgde->length;
  81. sgde = sg_next(sgde);
  82. }
  83. }
  84. static void
  85. lpfc_debug_save_dif(struct lpfc_hba *phba, struct scsi_cmnd *cmnd)
  86. {
  87. void *src, *dst;
  88. struct scatterlist *sgde = scsi_prot_sglist(cmnd);
  89. if (!_dump_buf_dif) {
  90. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  91. "9052 BLKGRD: ERROR %s _dump_buf_data is NULL\n",
  92. __func__);
  93. return;
  94. }
  95. if (!sgde) {
  96. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  97. "9053 BLKGRD: ERROR: prot scatterlist is null\n");
  98. return;
  99. }
  100. dst = _dump_buf_dif;
  101. while (sgde) {
  102. src = sg_virt(sgde);
  103. memcpy(dst, src, sgde->length);
  104. dst += sgde->length;
  105. sgde = sg_next(sgde);
  106. }
  107. }
  108. /**
  109. * lpfc_sli4_set_rsp_sgl_last - Set the last bit in the response sge.
  110. * @phba: Pointer to HBA object.
  111. * @lpfc_cmd: lpfc scsi command object pointer.
  112. *
  113. * This function is called from the lpfc_prep_task_mgmt_cmd function to
  114. * set the last bit in the response sge entry.
  115. **/
  116. static void
  117. lpfc_sli4_set_rsp_sgl_last(struct lpfc_hba *phba,
  118. struct lpfc_scsi_buf *lpfc_cmd)
  119. {
  120. struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  121. if (sgl) {
  122. sgl += 1;
  123. sgl->word2 = le32_to_cpu(sgl->word2);
  124. bf_set(lpfc_sli4_sge_last, sgl, 1);
  125. sgl->word2 = cpu_to_le32(sgl->word2);
  126. }
  127. }
  128. /**
  129. * lpfc_update_stats - Update statistical data for the command completion
  130. * @phba: Pointer to HBA object.
  131. * @lpfc_cmd: lpfc scsi command object pointer.
  132. *
  133. * This function is called when there is a command completion and this
  134. * function updates the statistical data for the command completion.
  135. **/
  136. static void
  137. lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  138. {
  139. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  140. struct lpfc_nodelist *pnode = rdata->pnode;
  141. struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
  142. unsigned long flags;
  143. struct Scsi_Host *shost = cmd->device->host;
  144. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  145. unsigned long latency;
  146. int i;
  147. if (cmd->result)
  148. return;
  149. latency = jiffies_to_msecs((long)jiffies - (long)lpfc_cmd->start_time);
  150. spin_lock_irqsave(shost->host_lock, flags);
  151. if (!vport->stat_data_enabled ||
  152. vport->stat_data_blocked ||
  153. !pnode ||
  154. !pnode->lat_data ||
  155. (phba->bucket_type == LPFC_NO_BUCKET)) {
  156. spin_unlock_irqrestore(shost->host_lock, flags);
  157. return;
  158. }
  159. if (phba->bucket_type == LPFC_LINEAR_BUCKET) {
  160. i = (latency + phba->bucket_step - 1 - phba->bucket_base)/
  161. phba->bucket_step;
  162. /* check array subscript bounds */
  163. if (i < 0)
  164. i = 0;
  165. else if (i >= LPFC_MAX_BUCKET_COUNT)
  166. i = LPFC_MAX_BUCKET_COUNT - 1;
  167. } else {
  168. for (i = 0; i < LPFC_MAX_BUCKET_COUNT-1; i++)
  169. if (latency <= (phba->bucket_base +
  170. ((1<<i)*phba->bucket_step)))
  171. break;
  172. }
  173. pnode->lat_data[i].cmd_count++;
  174. spin_unlock_irqrestore(shost->host_lock, flags);
  175. }
  176. /**
  177. * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event
  178. * @phba: Pointer to HBA context object.
  179. * @vport: Pointer to vport object.
  180. * @ndlp: Pointer to FC node associated with the target.
  181. * @lun: Lun number of the scsi device.
  182. * @old_val: Old value of the queue depth.
  183. * @new_val: New value of the queue depth.
  184. *
  185. * This function sends an event to the mgmt application indicating
  186. * there is a change in the scsi device queue depth.
  187. **/
  188. static void
  189. lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba,
  190. struct lpfc_vport *vport,
  191. struct lpfc_nodelist *ndlp,
  192. uint32_t lun,
  193. uint32_t old_val,
  194. uint32_t new_val)
  195. {
  196. struct lpfc_fast_path_event *fast_path_evt;
  197. unsigned long flags;
  198. fast_path_evt = lpfc_alloc_fast_evt(phba);
  199. if (!fast_path_evt)
  200. return;
  201. fast_path_evt->un.queue_depth_evt.scsi_event.event_type =
  202. FC_REG_SCSI_EVENT;
  203. fast_path_evt->un.queue_depth_evt.scsi_event.subcategory =
  204. LPFC_EVENT_VARQUEDEPTH;
  205. /* Report all luns with change in queue depth */
  206. fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun;
  207. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  208. memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn,
  209. &ndlp->nlp_portname, sizeof(struct lpfc_name));
  210. memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn,
  211. &ndlp->nlp_nodename, sizeof(struct lpfc_name));
  212. }
  213. fast_path_evt->un.queue_depth_evt.oldval = old_val;
  214. fast_path_evt->un.queue_depth_evt.newval = new_val;
  215. fast_path_evt->vport = vport;
  216. fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
  217. spin_lock_irqsave(&phba->hbalock, flags);
  218. list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
  219. spin_unlock_irqrestore(&phba->hbalock, flags);
  220. lpfc_worker_wake_up(phba);
  221. return;
  222. }
  223. /**
  224. * lpfc_change_queue_depth - Alter scsi device queue depth
  225. * @sdev: Pointer the scsi device on which to change the queue depth.
  226. * @qdepth: New queue depth to set the sdev to.
  227. * @reason: The reason for the queue depth change.
  228. *
  229. * This function is called by the midlayer and the LLD to alter the queue
  230. * depth for a scsi device. This function sets the queue depth to the new
  231. * value and sends an event out to log the queue depth change.
  232. **/
  233. int
  234. lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  235. {
  236. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  237. struct lpfc_hba *phba = vport->phba;
  238. struct lpfc_rport_data *rdata;
  239. unsigned long new_queue_depth, old_queue_depth;
  240. old_queue_depth = sdev->queue_depth;
  241. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  242. new_queue_depth = sdev->queue_depth;
  243. rdata = sdev->hostdata;
  244. if (rdata)
  245. lpfc_send_sdev_queuedepth_change_event(phba, vport,
  246. rdata->pnode, sdev->lun,
  247. old_queue_depth,
  248. new_queue_depth);
  249. return sdev->queue_depth;
  250. }
  251. /**
  252. * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
  253. * @phba: The Hba for which this call is being executed.
  254. *
  255. * This routine is called when there is resource error in driver or firmware.
  256. * This routine posts WORKER_RAMP_DOWN_QUEUE event for @phba. This routine
  257. * posts at most 1 event each second. This routine wakes up worker thread of
  258. * @phba to process WORKER_RAM_DOWN_EVENT event.
  259. *
  260. * This routine should be called with no lock held.
  261. **/
  262. void
  263. lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
  264. {
  265. unsigned long flags;
  266. uint32_t evt_posted;
  267. spin_lock_irqsave(&phba->hbalock, flags);
  268. atomic_inc(&phba->num_rsrc_err);
  269. phba->last_rsrc_error_time = jiffies;
  270. if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
  271. spin_unlock_irqrestore(&phba->hbalock, flags);
  272. return;
  273. }
  274. phba->last_ramp_down_time = jiffies;
  275. spin_unlock_irqrestore(&phba->hbalock, flags);
  276. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  277. evt_posted = phba->pport->work_port_events & WORKER_RAMP_DOWN_QUEUE;
  278. if (!evt_posted)
  279. phba->pport->work_port_events |= WORKER_RAMP_DOWN_QUEUE;
  280. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  281. if (!evt_posted)
  282. lpfc_worker_wake_up(phba);
  283. return;
  284. }
  285. /**
  286. * lpfc_rampup_queue_depth - Post RAMP_UP_QUEUE event for worker thread
  287. * @phba: The Hba for which this call is being executed.
  288. *
  289. * This routine post WORKER_RAMP_UP_QUEUE event for @phba vport. This routine
  290. * post at most 1 event every 5 minute after last_ramp_up_time or
  291. * last_rsrc_error_time. This routine wakes up worker thread of @phba
  292. * to process WORKER_RAM_DOWN_EVENT event.
  293. *
  294. * This routine should be called with no lock held.
  295. **/
  296. static inline void
  297. lpfc_rampup_queue_depth(struct lpfc_vport *vport,
  298. uint32_t queue_depth)
  299. {
  300. unsigned long flags;
  301. struct lpfc_hba *phba = vport->phba;
  302. uint32_t evt_posted;
  303. atomic_inc(&phba->num_cmd_success);
  304. if (vport->cfg_lun_queue_depth <= queue_depth)
  305. return;
  306. spin_lock_irqsave(&phba->hbalock, flags);
  307. if (time_before(jiffies,
  308. phba->last_ramp_up_time + QUEUE_RAMP_UP_INTERVAL) ||
  309. time_before(jiffies,
  310. phba->last_rsrc_error_time + QUEUE_RAMP_UP_INTERVAL)) {
  311. spin_unlock_irqrestore(&phba->hbalock, flags);
  312. return;
  313. }
  314. phba->last_ramp_up_time = jiffies;
  315. spin_unlock_irqrestore(&phba->hbalock, flags);
  316. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  317. evt_posted = phba->pport->work_port_events & WORKER_RAMP_UP_QUEUE;
  318. if (!evt_posted)
  319. phba->pport->work_port_events |= WORKER_RAMP_UP_QUEUE;
  320. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  321. if (!evt_posted)
  322. lpfc_worker_wake_up(phba);
  323. return;
  324. }
  325. /**
  326. * lpfc_ramp_down_queue_handler - WORKER_RAMP_DOWN_QUEUE event handler
  327. * @phba: The Hba for which this call is being executed.
  328. *
  329. * This routine is called to process WORKER_RAMP_DOWN_QUEUE event for worker
  330. * thread.This routine reduces queue depth for all scsi device on each vport
  331. * associated with @phba.
  332. **/
  333. void
  334. lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
  335. {
  336. struct lpfc_vport **vports;
  337. struct Scsi_Host *shost;
  338. struct scsi_device *sdev;
  339. unsigned long new_queue_depth;
  340. unsigned long num_rsrc_err, num_cmd_success;
  341. int i;
  342. num_rsrc_err = atomic_read(&phba->num_rsrc_err);
  343. num_cmd_success = atomic_read(&phba->num_cmd_success);
  344. vports = lpfc_create_vport_work_array(phba);
  345. if (vports != NULL)
  346. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  347. shost = lpfc_shost_from_vport(vports[i]);
  348. shost_for_each_device(sdev, shost) {
  349. new_queue_depth =
  350. sdev->queue_depth * num_rsrc_err /
  351. (num_rsrc_err + num_cmd_success);
  352. if (!new_queue_depth)
  353. new_queue_depth = sdev->queue_depth - 1;
  354. else
  355. new_queue_depth = sdev->queue_depth -
  356. new_queue_depth;
  357. lpfc_change_queue_depth(sdev, new_queue_depth,
  358. SCSI_QDEPTH_DEFAULT);
  359. }
  360. }
  361. lpfc_destroy_vport_work_array(phba, vports);
  362. atomic_set(&phba->num_rsrc_err, 0);
  363. atomic_set(&phba->num_cmd_success, 0);
  364. }
  365. /**
  366. * lpfc_ramp_up_queue_handler - WORKER_RAMP_UP_QUEUE event handler
  367. * @phba: The Hba for which this call is being executed.
  368. *
  369. * This routine is called to process WORKER_RAMP_UP_QUEUE event for worker
  370. * thread.This routine increases queue depth for all scsi device on each vport
  371. * associated with @phba by 1. This routine also sets @phba num_rsrc_err and
  372. * num_cmd_success to zero.
  373. **/
  374. void
  375. lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
  376. {
  377. struct lpfc_vport **vports;
  378. struct Scsi_Host *shost;
  379. struct scsi_device *sdev;
  380. int i;
  381. vports = lpfc_create_vport_work_array(phba);
  382. if (vports != NULL)
  383. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  384. shost = lpfc_shost_from_vport(vports[i]);
  385. shost_for_each_device(sdev, shost) {
  386. if (vports[i]->cfg_lun_queue_depth <=
  387. sdev->queue_depth)
  388. continue;
  389. lpfc_change_queue_depth(sdev,
  390. sdev->queue_depth+1,
  391. SCSI_QDEPTH_RAMP_UP);
  392. }
  393. }
  394. lpfc_destroy_vport_work_array(phba, vports);
  395. atomic_set(&phba->num_rsrc_err, 0);
  396. atomic_set(&phba->num_cmd_success, 0);
  397. }
  398. /**
  399. * lpfc_scsi_dev_block - set all scsi hosts to block state
  400. * @phba: Pointer to HBA context object.
  401. *
  402. * This function walks vport list and set each SCSI host to block state
  403. * by invoking fc_remote_port_delete() routine. This function is invoked
  404. * with EEH when device's PCI slot has been permanently disabled.
  405. **/
  406. void
  407. lpfc_scsi_dev_block(struct lpfc_hba *phba)
  408. {
  409. struct lpfc_vport **vports;
  410. struct Scsi_Host *shost;
  411. struct scsi_device *sdev;
  412. struct fc_rport *rport;
  413. int i;
  414. vports = lpfc_create_vport_work_array(phba);
  415. if (vports != NULL)
  416. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  417. shost = lpfc_shost_from_vport(vports[i]);
  418. shost_for_each_device(sdev, shost) {
  419. rport = starget_to_rport(scsi_target(sdev));
  420. fc_remote_port_delete(rport);
  421. }
  422. }
  423. lpfc_destroy_vport_work_array(phba, vports);
  424. }
  425. /**
  426. * lpfc_new_scsi_buf_s3 - Scsi buffer allocator for HBA with SLI3 IF spec
  427. * @vport: The virtual port for which this call being executed.
  428. * @num_to_allocate: The requested number of buffers to allocate.
  429. *
  430. * This routine allocates a scsi buffer for device with SLI-3 interface spec,
  431. * the scsi buffer contains all the necessary information needed to initiate
  432. * a SCSI I/O. The non-DMAable buffer region contains information to build
  433. * the IOCB. The DMAable region contains memory for the FCP CMND, FCP RSP,
  434. * and the initial BPL. In addition to allocating memory, the FCP CMND and
  435. * FCP RSP BDEs are setup in the BPL and the BPL BDE is setup in the IOCB.
  436. *
  437. * Return codes:
  438. * int - number of scsi buffers that were allocated.
  439. * 0 = failure, less than num_to_alloc is a partial failure.
  440. **/
  441. static int
  442. lpfc_new_scsi_buf_s3(struct lpfc_vport *vport, int num_to_alloc)
  443. {
  444. struct lpfc_hba *phba = vport->phba;
  445. struct lpfc_scsi_buf *psb;
  446. struct ulp_bde64 *bpl;
  447. IOCB_t *iocb;
  448. dma_addr_t pdma_phys_fcp_cmd;
  449. dma_addr_t pdma_phys_fcp_rsp;
  450. dma_addr_t pdma_phys_bpl;
  451. uint16_t iotag;
  452. int bcnt;
  453. for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
  454. psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
  455. if (!psb)
  456. break;
  457. /*
  458. * Get memory from the pci pool to map the virt space to pci
  459. * bus space for an I/O. The DMA buffer includes space for the
  460. * struct fcp_cmnd, struct fcp_rsp and the number of bde's
  461. * necessary to support the sg_tablesize.
  462. */
  463. psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
  464. GFP_KERNEL, &psb->dma_handle);
  465. if (!psb->data) {
  466. kfree(psb);
  467. break;
  468. }
  469. /* Initialize virtual ptrs to dma_buf region. */
  470. memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
  471. /* Allocate iotag for psb->cur_iocbq. */
  472. iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
  473. if (iotag == 0) {
  474. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  475. psb->data, psb->dma_handle);
  476. kfree(psb);
  477. break;
  478. }
  479. psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
  480. psb->fcp_cmnd = psb->data;
  481. psb->fcp_rsp = psb->data + sizeof(struct fcp_cmnd);
  482. psb->fcp_bpl = psb->data + sizeof(struct fcp_cmnd) +
  483. sizeof(struct fcp_rsp);
  484. /* Initialize local short-hand pointers. */
  485. bpl = psb->fcp_bpl;
  486. pdma_phys_fcp_cmd = psb->dma_handle;
  487. pdma_phys_fcp_rsp = psb->dma_handle + sizeof(struct fcp_cmnd);
  488. pdma_phys_bpl = psb->dma_handle + sizeof(struct fcp_cmnd) +
  489. sizeof(struct fcp_rsp);
  490. /*
  491. * The first two bdes are the FCP_CMD and FCP_RSP. The balance
  492. * are sg list bdes. Initialize the first two and leave the
  493. * rest for queuecommand.
  494. */
  495. bpl[0].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_cmd));
  496. bpl[0].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_cmd));
  497. bpl[0].tus.f.bdeSize = sizeof(struct fcp_cmnd);
  498. bpl[0].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  499. bpl[0].tus.w = le32_to_cpu(bpl[0].tus.w);
  500. /* Setup the physical region for the FCP RSP */
  501. bpl[1].addrHigh = le32_to_cpu(putPaddrHigh(pdma_phys_fcp_rsp));
  502. bpl[1].addrLow = le32_to_cpu(putPaddrLow(pdma_phys_fcp_rsp));
  503. bpl[1].tus.f.bdeSize = sizeof(struct fcp_rsp);
  504. bpl[1].tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  505. bpl[1].tus.w = le32_to_cpu(bpl[1].tus.w);
  506. /*
  507. * Since the IOCB for the FCP I/O is built into this
  508. * lpfc_scsi_buf, initialize it with all known data now.
  509. */
  510. iocb = &psb->cur_iocbq.iocb;
  511. iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
  512. if ((phba->sli_rev == 3) &&
  513. !(phba->sli3_options & LPFC_SLI3_BG_ENABLED)) {
  514. /* fill in immediate fcp command BDE */
  515. iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_IMMED;
  516. iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
  517. iocb->un.fcpi64.bdl.addrLow = offsetof(IOCB_t,
  518. unsli3.fcp_ext.icd);
  519. iocb->un.fcpi64.bdl.addrHigh = 0;
  520. iocb->ulpBdeCount = 0;
  521. iocb->ulpLe = 0;
  522. /* fill in response BDE */
  523. iocb->unsli3.fcp_ext.rbde.tus.f.bdeFlags =
  524. BUFF_TYPE_BDE_64;
  525. iocb->unsli3.fcp_ext.rbde.tus.f.bdeSize =
  526. sizeof(struct fcp_rsp);
  527. iocb->unsli3.fcp_ext.rbde.addrLow =
  528. putPaddrLow(pdma_phys_fcp_rsp);
  529. iocb->unsli3.fcp_ext.rbde.addrHigh =
  530. putPaddrHigh(pdma_phys_fcp_rsp);
  531. } else {
  532. iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  533. iocb->un.fcpi64.bdl.bdeSize =
  534. (2 * sizeof(struct ulp_bde64));
  535. iocb->un.fcpi64.bdl.addrLow =
  536. putPaddrLow(pdma_phys_bpl);
  537. iocb->un.fcpi64.bdl.addrHigh =
  538. putPaddrHigh(pdma_phys_bpl);
  539. iocb->ulpBdeCount = 1;
  540. iocb->ulpLe = 1;
  541. }
  542. iocb->ulpClass = CLASS3;
  543. psb->status = IOSTAT_SUCCESS;
  544. /* Put it back into the SCSI buffer list */
  545. psb->cur_iocbq.context1 = psb;
  546. lpfc_release_scsi_buf_s3(phba, psb);
  547. }
  548. return bcnt;
  549. }
  550. /**
  551. * lpfc_sli4_vport_delete_fcp_xri_aborted -Remove all ndlp references for vport
  552. * @vport: pointer to lpfc vport data structure.
  553. *
  554. * This routine is invoked by the vport cleanup for deletions and the cleanup
  555. * for an ndlp on removal.
  556. **/
  557. void
  558. lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *vport)
  559. {
  560. struct lpfc_hba *phba = vport->phba;
  561. struct lpfc_scsi_buf *psb, *next_psb;
  562. unsigned long iflag = 0;
  563. spin_lock_irqsave(&phba->hbalock, iflag);
  564. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  565. list_for_each_entry_safe(psb, next_psb,
  566. &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
  567. if (psb->rdata && psb->rdata->pnode
  568. && psb->rdata->pnode->vport == vport)
  569. psb->rdata = NULL;
  570. }
  571. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  572. spin_unlock_irqrestore(&phba->hbalock, iflag);
  573. }
  574. /**
  575. * lpfc_sli4_fcp_xri_aborted - Fast-path process of fcp xri abort
  576. * @phba: pointer to lpfc hba data structure.
  577. * @axri: pointer to the fcp xri abort wcqe structure.
  578. *
  579. * This routine is invoked by the worker thread to process a SLI4 fast-path
  580. * FCP aborted xri.
  581. **/
  582. void
  583. lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
  584. struct sli4_wcqe_xri_aborted *axri)
  585. {
  586. uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
  587. uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
  588. struct lpfc_scsi_buf *psb, *next_psb;
  589. unsigned long iflag = 0;
  590. struct lpfc_iocbq *iocbq;
  591. int i;
  592. struct lpfc_nodelist *ndlp;
  593. int rrq_empty = 0;
  594. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  595. spin_lock_irqsave(&phba->hbalock, iflag);
  596. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  597. list_for_each_entry_safe(psb, next_psb,
  598. &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
  599. if (psb->cur_iocbq.sli4_xritag == xri) {
  600. list_del(&psb->list);
  601. psb->exch_busy = 0;
  602. psb->status = IOSTAT_SUCCESS;
  603. spin_unlock(
  604. &phba->sli4_hba.abts_scsi_buf_list_lock);
  605. if (psb->rdata && psb->rdata->pnode)
  606. ndlp = psb->rdata->pnode;
  607. else
  608. ndlp = NULL;
  609. rrq_empty = list_empty(&phba->active_rrq_list);
  610. spin_unlock_irqrestore(&phba->hbalock, iflag);
  611. if (ndlp)
  612. lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
  613. lpfc_release_scsi_buf_s4(phba, psb);
  614. if (rrq_empty)
  615. lpfc_worker_wake_up(phba);
  616. return;
  617. }
  618. }
  619. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  620. for (i = 1; i <= phba->sli.last_iotag; i++) {
  621. iocbq = phba->sli.iocbq_lookup[i];
  622. if (!(iocbq->iocb_flag & LPFC_IO_FCP) ||
  623. (iocbq->iocb_flag & LPFC_IO_LIBDFC))
  624. continue;
  625. if (iocbq->sli4_xritag != xri)
  626. continue;
  627. psb = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
  628. psb->exch_busy = 0;
  629. spin_unlock_irqrestore(&phba->hbalock, iflag);
  630. if (pring->txq_cnt)
  631. lpfc_worker_wake_up(phba);
  632. return;
  633. }
  634. spin_unlock_irqrestore(&phba->hbalock, iflag);
  635. }
  636. /**
  637. * lpfc_sli4_repost_scsi_sgl_list - Repsot the Scsi buffers sgl pages as block
  638. * @phba: pointer to lpfc hba data structure.
  639. *
  640. * This routine walks the list of scsi buffers that have been allocated and
  641. * repost them to the HBA by using SGL block post. This is needed after a
  642. * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
  643. * is responsible for moving all scsi buffers on the lpfc_abts_scsi_sgl_list
  644. * to the lpfc_scsi_buf_list. If the repost fails, reject all scsi buffers.
  645. *
  646. * Returns: 0 = success, non-zero failure.
  647. **/
  648. int
  649. lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba)
  650. {
  651. struct lpfc_scsi_buf *psb;
  652. int index, status, bcnt = 0, rcnt = 0, rc = 0;
  653. LIST_HEAD(sblist);
  654. for (index = 0; index < phba->sli4_hba.scsi_xri_cnt; index++) {
  655. psb = phba->sli4_hba.lpfc_scsi_psb_array[index];
  656. if (psb) {
  657. /* Remove from SCSI buffer list */
  658. list_del(&psb->list);
  659. /* Add it to a local SCSI buffer list */
  660. list_add_tail(&psb->list, &sblist);
  661. if (++rcnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  662. bcnt = rcnt;
  663. rcnt = 0;
  664. }
  665. } else
  666. /* A hole present in the XRI array, need to skip */
  667. bcnt = rcnt;
  668. if (index == phba->sli4_hba.scsi_xri_cnt - 1)
  669. /* End of XRI array for SCSI buffer, complete */
  670. bcnt = rcnt;
  671. /* Continue until collect up to a nembed page worth of sgls */
  672. if (bcnt == 0)
  673. continue;
  674. /* Now, post the SCSI buffer list sgls as a block */
  675. if (!phba->sli4_hba.extents_in_use)
  676. status = lpfc_sli4_post_scsi_sgl_block(phba,
  677. &sblist,
  678. bcnt);
  679. else
  680. status = lpfc_sli4_post_scsi_sgl_blk_ext(phba,
  681. &sblist,
  682. bcnt);
  683. /* Reset SCSI buffer count for next round of posting */
  684. bcnt = 0;
  685. while (!list_empty(&sblist)) {
  686. list_remove_head(&sblist, psb, struct lpfc_scsi_buf,
  687. list);
  688. if (status) {
  689. /* Put this back on the abort scsi list */
  690. psb->exch_busy = 1;
  691. rc++;
  692. } else {
  693. psb->exch_busy = 0;
  694. psb->status = IOSTAT_SUCCESS;
  695. }
  696. /* Put it back into the SCSI buffer list */
  697. lpfc_release_scsi_buf_s4(phba, psb);
  698. }
  699. }
  700. return rc;
  701. }
  702. /**
  703. * lpfc_new_scsi_buf_s4 - Scsi buffer allocator for HBA with SLI4 IF spec
  704. * @vport: The virtual port for which this call being executed.
  705. * @num_to_allocate: The requested number of buffers to allocate.
  706. *
  707. * This routine allocates a scsi buffer for device with SLI-4 interface spec,
  708. * the scsi buffer contains all the necessary information needed to initiate
  709. * a SCSI I/O.
  710. *
  711. * Return codes:
  712. * int - number of scsi buffers that were allocated.
  713. * 0 = failure, less than num_to_alloc is a partial failure.
  714. **/
  715. static int
  716. lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
  717. {
  718. struct lpfc_hba *phba = vport->phba;
  719. struct lpfc_scsi_buf *psb;
  720. struct sli4_sge *sgl;
  721. IOCB_t *iocb;
  722. dma_addr_t pdma_phys_fcp_cmd;
  723. dma_addr_t pdma_phys_fcp_rsp;
  724. dma_addr_t pdma_phys_bpl, pdma_phys_bpl1;
  725. uint16_t iotag, last_xritag = NO_XRI, lxri = 0;
  726. int status = 0, index;
  727. int bcnt;
  728. int non_sequential_xri = 0;
  729. LIST_HEAD(sblist);
  730. for (bcnt = 0; bcnt < num_to_alloc; bcnt++) {
  731. psb = kzalloc(sizeof(struct lpfc_scsi_buf), GFP_KERNEL);
  732. if (!psb)
  733. break;
  734. /*
  735. * Get memory from the pci pool to map the virt space to pci bus
  736. * space for an I/O. The DMA buffer includes space for the
  737. * struct fcp_cmnd, struct fcp_rsp and the number of bde's
  738. * necessary to support the sg_tablesize.
  739. */
  740. psb->data = pci_pool_alloc(phba->lpfc_scsi_dma_buf_pool,
  741. GFP_KERNEL, &psb->dma_handle);
  742. if (!psb->data) {
  743. kfree(psb);
  744. break;
  745. }
  746. /* Initialize virtual ptrs to dma_buf region. */
  747. memset(psb->data, 0, phba->cfg_sg_dma_buf_size);
  748. /* Allocate iotag for psb->cur_iocbq. */
  749. iotag = lpfc_sli_next_iotag(phba, &psb->cur_iocbq);
  750. if (iotag == 0) {
  751. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  752. psb->data, psb->dma_handle);
  753. kfree(psb);
  754. break;
  755. }
  756. lxri = lpfc_sli4_next_xritag(phba);
  757. if (lxri == NO_XRI) {
  758. pci_pool_free(phba->lpfc_scsi_dma_buf_pool,
  759. psb->data, psb->dma_handle);
  760. kfree(psb);
  761. break;
  762. }
  763. psb->cur_iocbq.sli4_lxritag = lxri;
  764. psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
  765. if (last_xritag != NO_XRI
  766. && psb->cur_iocbq.sli4_xritag != (last_xritag+1)) {
  767. non_sequential_xri = 1;
  768. } else
  769. list_add_tail(&psb->list, &sblist);
  770. last_xritag = psb->cur_iocbq.sli4_xritag;
  771. index = phba->sli4_hba.scsi_xri_cnt++;
  772. psb->cur_iocbq.iocb_flag |= LPFC_IO_FCP;
  773. psb->fcp_bpl = psb->data;
  774. psb->fcp_cmnd = (psb->data + phba->cfg_sg_dma_buf_size)
  775. - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
  776. psb->fcp_rsp = (struct fcp_rsp *)((uint8_t *)psb->fcp_cmnd +
  777. sizeof(struct fcp_cmnd));
  778. /* Initialize local short-hand pointers. */
  779. sgl = (struct sli4_sge *)psb->fcp_bpl;
  780. pdma_phys_bpl = psb->dma_handle;
  781. pdma_phys_fcp_cmd =
  782. (psb->dma_handle + phba->cfg_sg_dma_buf_size)
  783. - (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp));
  784. pdma_phys_fcp_rsp = pdma_phys_fcp_cmd + sizeof(struct fcp_cmnd);
  785. /*
  786. * The first two bdes are the FCP_CMD and FCP_RSP. The balance
  787. * are sg list bdes. Initialize the first two and leave the
  788. * rest for queuecommand.
  789. */
  790. sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
  791. sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
  792. sgl->word2 = le32_to_cpu(sgl->word2);
  793. bf_set(lpfc_sli4_sge_last, sgl, 0);
  794. sgl->word2 = cpu_to_le32(sgl->word2);
  795. sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
  796. sgl++;
  797. /* Setup the physical region for the FCP RSP */
  798. sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
  799. sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
  800. sgl->word2 = le32_to_cpu(sgl->word2);
  801. bf_set(lpfc_sli4_sge_last, sgl, 1);
  802. sgl->word2 = cpu_to_le32(sgl->word2);
  803. sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
  804. /*
  805. * Since the IOCB for the FCP I/O is built into this
  806. * lpfc_scsi_buf, initialize it with all known data now.
  807. */
  808. iocb = &psb->cur_iocbq.iocb;
  809. iocb->un.fcpi64.bdl.ulpIoTag32 = 0;
  810. iocb->un.fcpi64.bdl.bdeFlags = BUFF_TYPE_BDE_64;
  811. /* setting the BLP size to 2 * sizeof BDE may not be correct.
  812. * We are setting the bpl to point to out sgl. An sgl's
  813. * entries are 16 bytes, a bpl entries are 12 bytes.
  814. */
  815. iocb->un.fcpi64.bdl.bdeSize = sizeof(struct fcp_cmnd);
  816. iocb->un.fcpi64.bdl.addrLow = putPaddrLow(pdma_phys_fcp_cmd);
  817. iocb->un.fcpi64.bdl.addrHigh = putPaddrHigh(pdma_phys_fcp_cmd);
  818. iocb->ulpBdeCount = 1;
  819. iocb->ulpLe = 1;
  820. iocb->ulpClass = CLASS3;
  821. psb->cur_iocbq.context1 = psb;
  822. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  823. pdma_phys_bpl1 = pdma_phys_bpl + SGL_PAGE_SIZE;
  824. else
  825. pdma_phys_bpl1 = 0;
  826. psb->dma_phys_bpl = pdma_phys_bpl;
  827. phba->sli4_hba.lpfc_scsi_psb_array[index] = psb;
  828. if (non_sequential_xri) {
  829. status = lpfc_sli4_post_sgl(phba, pdma_phys_bpl,
  830. pdma_phys_bpl1,
  831. psb->cur_iocbq.sli4_xritag);
  832. if (status) {
  833. /* Put this back on the abort scsi list */
  834. psb->exch_busy = 1;
  835. } else {
  836. psb->exch_busy = 0;
  837. psb->status = IOSTAT_SUCCESS;
  838. }
  839. /* Put it back into the SCSI buffer list */
  840. lpfc_release_scsi_buf_s4(phba, psb);
  841. break;
  842. }
  843. }
  844. if (bcnt) {
  845. if (!phba->sli4_hba.extents_in_use)
  846. status = lpfc_sli4_post_scsi_sgl_block(phba,
  847. &sblist,
  848. bcnt);
  849. else
  850. status = lpfc_sli4_post_scsi_sgl_blk_ext(phba,
  851. &sblist,
  852. bcnt);
  853. if (status) {
  854. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  855. "3021 SCSI SGL post error %d\n",
  856. status);
  857. bcnt = 0;
  858. }
  859. /* Reset SCSI buffer count for next round of posting */
  860. while (!list_empty(&sblist)) {
  861. list_remove_head(&sblist, psb, struct lpfc_scsi_buf,
  862. list);
  863. if (status) {
  864. /* Put this back on the abort scsi list */
  865. psb->exch_busy = 1;
  866. } else {
  867. psb->exch_busy = 0;
  868. psb->status = IOSTAT_SUCCESS;
  869. }
  870. /* Put it back into the SCSI buffer list */
  871. lpfc_release_scsi_buf_s4(phba, psb);
  872. }
  873. }
  874. return bcnt + non_sequential_xri;
  875. }
  876. /**
  877. * lpfc_new_scsi_buf - Wrapper funciton for scsi buffer allocator
  878. * @vport: The virtual port for which this call being executed.
  879. * @num_to_allocate: The requested number of buffers to allocate.
  880. *
  881. * This routine wraps the actual SCSI buffer allocator function pointer from
  882. * the lpfc_hba struct.
  883. *
  884. * Return codes:
  885. * int - number of scsi buffers that were allocated.
  886. * 0 = failure, less than num_to_alloc is a partial failure.
  887. **/
  888. static inline int
  889. lpfc_new_scsi_buf(struct lpfc_vport *vport, int num_to_alloc)
  890. {
  891. return vport->phba->lpfc_new_scsi_buf(vport, num_to_alloc);
  892. }
  893. /**
  894. * lpfc_get_scsi_buf_s3 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
  895. * @phba: The HBA for which this call is being executed.
  896. *
  897. * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
  898. * and returns to caller.
  899. *
  900. * Return codes:
  901. * NULL - Error
  902. * Pointer to lpfc_scsi_buf - Success
  903. **/
  904. static struct lpfc_scsi_buf*
  905. lpfc_get_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  906. {
  907. struct lpfc_scsi_buf * lpfc_cmd = NULL;
  908. struct list_head *scsi_buf_list = &phba->lpfc_scsi_buf_list;
  909. unsigned long iflag = 0;
  910. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  911. list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
  912. if (lpfc_cmd) {
  913. lpfc_cmd->seg_cnt = 0;
  914. lpfc_cmd->nonsg_phys = 0;
  915. lpfc_cmd->prot_seg_cnt = 0;
  916. }
  917. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  918. return lpfc_cmd;
  919. }
  920. /**
  921. * lpfc_get_scsi_buf_s4 - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
  922. * @phba: The HBA for which this call is being executed.
  923. *
  924. * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
  925. * and returns to caller.
  926. *
  927. * Return codes:
  928. * NULL - Error
  929. * Pointer to lpfc_scsi_buf - Success
  930. **/
  931. static struct lpfc_scsi_buf*
  932. lpfc_get_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  933. {
  934. struct lpfc_scsi_buf *lpfc_cmd ;
  935. unsigned long iflag = 0;
  936. int found = 0;
  937. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  938. list_for_each_entry(lpfc_cmd, &phba->lpfc_scsi_buf_list,
  939. list) {
  940. if (lpfc_test_rrq_active(phba, ndlp,
  941. lpfc_cmd->cur_iocbq.sli4_xritag))
  942. continue;
  943. list_del(&lpfc_cmd->list);
  944. found = 1;
  945. lpfc_cmd->seg_cnt = 0;
  946. lpfc_cmd->nonsg_phys = 0;
  947. lpfc_cmd->prot_seg_cnt = 0;
  948. break;
  949. }
  950. spin_unlock_irqrestore(&phba->scsi_buf_list_lock,
  951. iflag);
  952. if (!found)
  953. return NULL;
  954. else
  955. return lpfc_cmd;
  956. }
  957. /**
  958. * lpfc_get_scsi_buf - Get a scsi buffer from lpfc_scsi_buf_list of the HBA
  959. * @phba: The HBA for which this call is being executed.
  960. *
  961. * This routine removes a scsi buffer from head of @phba lpfc_scsi_buf_list list
  962. * and returns to caller.
  963. *
  964. * Return codes:
  965. * NULL - Error
  966. * Pointer to lpfc_scsi_buf - Success
  967. **/
  968. static struct lpfc_scsi_buf*
  969. lpfc_get_scsi_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  970. {
  971. return phba->lpfc_get_scsi_buf(phba, ndlp);
  972. }
  973. /**
  974. * lpfc_release_scsi_buf - Return a scsi buffer back to hba scsi buf list
  975. * @phba: The Hba for which this call is being executed.
  976. * @psb: The scsi buffer which is being released.
  977. *
  978. * This routine releases @psb scsi buffer by adding it to tail of @phba
  979. * lpfc_scsi_buf_list list.
  980. **/
  981. static void
  982. lpfc_release_scsi_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  983. {
  984. unsigned long iflag = 0;
  985. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  986. psb->pCmd = NULL;
  987. list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
  988. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  989. }
  990. /**
  991. * lpfc_release_scsi_buf_s4: Return a scsi buffer back to hba scsi buf list.
  992. * @phba: The Hba for which this call is being executed.
  993. * @psb: The scsi buffer which is being released.
  994. *
  995. * This routine releases @psb scsi buffer by adding it to tail of @phba
  996. * lpfc_scsi_buf_list list. For SLI4 XRI's are tied to the scsi buffer
  997. * and cannot be reused for at least RA_TOV amount of time if it was
  998. * aborted.
  999. **/
  1000. static void
  1001. lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  1002. {
  1003. unsigned long iflag = 0;
  1004. if (psb->exch_busy) {
  1005. spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock,
  1006. iflag);
  1007. psb->pCmd = NULL;
  1008. list_add_tail(&psb->list,
  1009. &phba->sli4_hba.lpfc_abts_scsi_buf_list);
  1010. spin_unlock_irqrestore(&phba->sli4_hba.abts_scsi_buf_list_lock,
  1011. iflag);
  1012. } else {
  1013. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  1014. psb->pCmd = NULL;
  1015. list_add_tail(&psb->list, &phba->lpfc_scsi_buf_list);
  1016. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  1017. }
  1018. }
  1019. /**
  1020. * lpfc_release_scsi_buf: Return a scsi buffer back to hba scsi buf list.
  1021. * @phba: The Hba for which this call is being executed.
  1022. * @psb: The scsi buffer which is being released.
  1023. *
  1024. * This routine releases @psb scsi buffer by adding it to tail of @phba
  1025. * lpfc_scsi_buf_list list.
  1026. **/
  1027. static void
  1028. lpfc_release_scsi_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  1029. {
  1030. phba->lpfc_release_scsi_buf(phba, psb);
  1031. }
  1032. /**
  1033. * lpfc_scsi_prep_dma_buf_s3 - DMA mapping for scsi buffer to SLI3 IF spec
  1034. * @phba: The Hba for which this call is being executed.
  1035. * @lpfc_cmd: The scsi buffer which is going to be mapped.
  1036. *
  1037. * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
  1038. * field of @lpfc_cmd for device with SLI-3 interface spec. This routine scans
  1039. * through sg elements and format the bdea. This routine also initializes all
  1040. * IOCB fields which are dependent on scsi command request buffer.
  1041. *
  1042. * Return codes:
  1043. * 1 - Error
  1044. * 0 - Success
  1045. **/
  1046. static int
  1047. lpfc_scsi_prep_dma_buf_s3(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  1048. {
  1049. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  1050. struct scatterlist *sgel = NULL;
  1051. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  1052. struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
  1053. struct lpfc_iocbq *iocbq = &lpfc_cmd->cur_iocbq;
  1054. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  1055. struct ulp_bde64 *data_bde = iocb_cmd->unsli3.fcp_ext.dbde;
  1056. dma_addr_t physaddr;
  1057. uint32_t num_bde = 0;
  1058. int nseg, datadir = scsi_cmnd->sc_data_direction;
  1059. /*
  1060. * There are three possibilities here - use scatter-gather segment, use
  1061. * the single mapping, or neither. Start the lpfc command prep by
  1062. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  1063. * data bde entry.
  1064. */
  1065. bpl += 2;
  1066. if (scsi_sg_count(scsi_cmnd)) {
  1067. /*
  1068. * The driver stores the segment count returned from pci_map_sg
  1069. * because this a count of dma-mappings used to map the use_sg
  1070. * pages. They are not guaranteed to be the same for those
  1071. * architectures that implement an IOMMU.
  1072. */
  1073. nseg = dma_map_sg(&phba->pcidev->dev, scsi_sglist(scsi_cmnd),
  1074. scsi_sg_count(scsi_cmnd), datadir);
  1075. if (unlikely(!nseg))
  1076. return 1;
  1077. lpfc_cmd->seg_cnt = nseg;
  1078. if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
  1079. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1080. "9064 BLKGRD: %s: Too many sg segments from "
  1081. "dma_map_sg. Config %d, seg_cnt %d\n",
  1082. __func__, phba->cfg_sg_seg_cnt,
  1083. lpfc_cmd->seg_cnt);
  1084. scsi_dma_unmap(scsi_cmnd);
  1085. return 1;
  1086. }
  1087. /*
  1088. * The driver established a maximum scatter-gather segment count
  1089. * during probe that limits the number of sg elements in any
  1090. * single scsi command. Just run through the seg_cnt and format
  1091. * the bde's.
  1092. * When using SLI-3 the driver will try to fit all the BDEs into
  1093. * the IOCB. If it can't then the BDEs get added to a BPL as it
  1094. * does for SLI-2 mode.
  1095. */
  1096. scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
  1097. physaddr = sg_dma_address(sgel);
  1098. if (phba->sli_rev == 3 &&
  1099. !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
  1100. !(iocbq->iocb_flag & DSS_SECURITY_OP) &&
  1101. nseg <= LPFC_EXT_DATA_BDE_COUNT) {
  1102. data_bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1103. data_bde->tus.f.bdeSize = sg_dma_len(sgel);
  1104. data_bde->addrLow = putPaddrLow(physaddr);
  1105. data_bde->addrHigh = putPaddrHigh(physaddr);
  1106. data_bde++;
  1107. } else {
  1108. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1109. bpl->tus.f.bdeSize = sg_dma_len(sgel);
  1110. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1111. bpl->addrLow =
  1112. le32_to_cpu(putPaddrLow(physaddr));
  1113. bpl->addrHigh =
  1114. le32_to_cpu(putPaddrHigh(physaddr));
  1115. bpl++;
  1116. }
  1117. }
  1118. }
  1119. /*
  1120. * Finish initializing those IOCB fields that are dependent on the
  1121. * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
  1122. * explicitly reinitialized and for SLI-3 the extended bde count is
  1123. * explicitly reinitialized since all iocb memory resources are reused.
  1124. */
  1125. if (phba->sli_rev == 3 &&
  1126. !(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
  1127. !(iocbq->iocb_flag & DSS_SECURITY_OP)) {
  1128. if (num_bde > LPFC_EXT_DATA_BDE_COUNT) {
  1129. /*
  1130. * The extended IOCB format can only fit 3 BDE or a BPL.
  1131. * This I/O has more than 3 BDE so the 1st data bde will
  1132. * be a BPL that is filled in here.
  1133. */
  1134. physaddr = lpfc_cmd->dma_handle;
  1135. data_bde->tus.f.bdeFlags = BUFF_TYPE_BLP_64;
  1136. data_bde->tus.f.bdeSize = (num_bde *
  1137. sizeof(struct ulp_bde64));
  1138. physaddr += (sizeof(struct fcp_cmnd) +
  1139. sizeof(struct fcp_rsp) +
  1140. (2 * sizeof(struct ulp_bde64)));
  1141. data_bde->addrHigh = putPaddrHigh(physaddr);
  1142. data_bde->addrLow = putPaddrLow(physaddr);
  1143. /* ebde count includes the response bde and data bpl */
  1144. iocb_cmd->unsli3.fcp_ext.ebde_count = 2;
  1145. } else {
  1146. /* ebde count includes the response bde and data bdes */
  1147. iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
  1148. }
  1149. } else {
  1150. iocb_cmd->un.fcpi64.bdl.bdeSize =
  1151. ((num_bde + 2) * sizeof(struct ulp_bde64));
  1152. iocb_cmd->unsli3.fcp_ext.ebde_count = (num_bde + 1);
  1153. }
  1154. fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
  1155. /*
  1156. * Due to difference in data length between DIF/non-DIF paths,
  1157. * we need to set word 4 of IOCB here
  1158. */
  1159. iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
  1160. return 0;
  1161. }
  1162. /*
  1163. * Given a scsi cmnd, determine the BlockGuard opcodes to be used with it
  1164. * @sc: The SCSI command to examine
  1165. * @txopt: (out) BlockGuard operation for transmitted data
  1166. * @rxopt: (out) BlockGuard operation for received data
  1167. *
  1168. * Returns: zero on success; non-zero if tx and/or rx op cannot be determined
  1169. *
  1170. */
  1171. static int
  1172. lpfc_sc_to_bg_opcodes(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  1173. uint8_t *txop, uint8_t *rxop)
  1174. {
  1175. uint8_t guard_type = scsi_host_get_guard(sc->device->host);
  1176. uint8_t ret = 0;
  1177. if (guard_type == SHOST_DIX_GUARD_IP) {
  1178. switch (scsi_get_prot_op(sc)) {
  1179. case SCSI_PROT_READ_INSERT:
  1180. case SCSI_PROT_WRITE_STRIP:
  1181. *txop = BG_OP_IN_CSUM_OUT_NODIF;
  1182. *rxop = BG_OP_IN_NODIF_OUT_CSUM;
  1183. break;
  1184. case SCSI_PROT_READ_STRIP:
  1185. case SCSI_PROT_WRITE_INSERT:
  1186. *txop = BG_OP_IN_NODIF_OUT_CRC;
  1187. *rxop = BG_OP_IN_CRC_OUT_NODIF;
  1188. break;
  1189. case SCSI_PROT_READ_PASS:
  1190. case SCSI_PROT_WRITE_PASS:
  1191. *txop = BG_OP_IN_CSUM_OUT_CRC;
  1192. *rxop = BG_OP_IN_CRC_OUT_CSUM;
  1193. break;
  1194. case SCSI_PROT_NORMAL:
  1195. default:
  1196. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1197. "9063 BLKGRD: Bad op/guard:%d/%d combination\n",
  1198. scsi_get_prot_op(sc), guard_type);
  1199. ret = 1;
  1200. break;
  1201. }
  1202. } else if (guard_type == SHOST_DIX_GUARD_CRC) {
  1203. switch (scsi_get_prot_op(sc)) {
  1204. case SCSI_PROT_READ_STRIP:
  1205. case SCSI_PROT_WRITE_INSERT:
  1206. *txop = BG_OP_IN_NODIF_OUT_CRC;
  1207. *rxop = BG_OP_IN_CRC_OUT_NODIF;
  1208. break;
  1209. case SCSI_PROT_READ_PASS:
  1210. case SCSI_PROT_WRITE_PASS:
  1211. *txop = BG_OP_IN_CRC_OUT_CRC;
  1212. *rxop = BG_OP_IN_CRC_OUT_CRC;
  1213. break;
  1214. case SCSI_PROT_READ_INSERT:
  1215. case SCSI_PROT_WRITE_STRIP:
  1216. case SCSI_PROT_NORMAL:
  1217. default:
  1218. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1219. "9075 BLKGRD: Bad op/guard:%d/%d combination\n",
  1220. scsi_get_prot_op(sc), guard_type);
  1221. ret = 1;
  1222. break;
  1223. }
  1224. } else {
  1225. /* unsupported format */
  1226. BUG();
  1227. }
  1228. return ret;
  1229. }
  1230. struct scsi_dif_tuple {
  1231. __be16 guard_tag; /* Checksum */
  1232. __be16 app_tag; /* Opaque storage */
  1233. __be32 ref_tag; /* Target LBA or indirect LBA */
  1234. };
  1235. static inline unsigned
  1236. lpfc_cmd_blksize(struct scsi_cmnd *sc)
  1237. {
  1238. return sc->device->sector_size;
  1239. }
  1240. /**
  1241. * lpfc_get_cmd_dif_parms - Extract DIF parameters from SCSI command
  1242. * @sc: in: SCSI command
  1243. * @apptagmask: out: app tag mask
  1244. * @apptagval: out: app tag value
  1245. * @reftag: out: ref tag (reference tag)
  1246. *
  1247. * Description:
  1248. * Extract DIF parameters from the command if possible. Otherwise,
  1249. * use default parameters.
  1250. *
  1251. **/
  1252. static inline void
  1253. lpfc_get_cmd_dif_parms(struct scsi_cmnd *sc, uint16_t *apptagmask,
  1254. uint16_t *apptagval, uint32_t *reftag)
  1255. {
  1256. struct scsi_dif_tuple *spt;
  1257. unsigned char op = scsi_get_prot_op(sc);
  1258. unsigned int protcnt = scsi_prot_sg_count(sc);
  1259. static int cnt;
  1260. if (protcnt && (op == SCSI_PROT_WRITE_STRIP ||
  1261. op == SCSI_PROT_WRITE_PASS)) {
  1262. cnt++;
  1263. spt = page_address(sg_page(scsi_prot_sglist(sc))) +
  1264. scsi_prot_sglist(sc)[0].offset;
  1265. *apptagmask = 0;
  1266. *apptagval = 0;
  1267. *reftag = cpu_to_be32(spt->ref_tag);
  1268. } else {
  1269. /* SBC defines ref tag to be lower 32bits of LBA */
  1270. *reftag = (uint32_t) (0xffffffff & scsi_get_lba(sc));
  1271. *apptagmask = 0;
  1272. *apptagval = 0;
  1273. }
  1274. }
  1275. /*
  1276. * This function sets up buffer list for protection groups of
  1277. * type LPFC_PG_TYPE_NO_DIF
  1278. *
  1279. * This is usually used when the HBA is instructed to generate
  1280. * DIFs and insert them into data stream (or strip DIF from
  1281. * incoming data stream)
  1282. *
  1283. * The buffer list consists of just one protection group described
  1284. * below:
  1285. * +-------------------------+
  1286. * start of prot group --> | PDE_5 |
  1287. * +-------------------------+
  1288. * | PDE_6 |
  1289. * +-------------------------+
  1290. * | Data BDE |
  1291. * +-------------------------+
  1292. * |more Data BDE's ... (opt)|
  1293. * +-------------------------+
  1294. *
  1295. * @sc: pointer to scsi command we're working on
  1296. * @bpl: pointer to buffer list for protection groups
  1297. * @datacnt: number of segments of data that have been dma mapped
  1298. *
  1299. * Note: Data s/g buffers have been dma mapped
  1300. */
  1301. static int
  1302. lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  1303. struct ulp_bde64 *bpl, int datasegcnt)
  1304. {
  1305. struct scatterlist *sgde = NULL; /* s/g data entry */
  1306. struct lpfc_pde5 *pde5 = NULL;
  1307. struct lpfc_pde6 *pde6 = NULL;
  1308. dma_addr_t physaddr;
  1309. int i = 0, num_bde = 0, status;
  1310. int datadir = sc->sc_data_direction;
  1311. unsigned blksize;
  1312. uint32_t reftag;
  1313. uint16_t apptagmask, apptagval;
  1314. uint8_t txop, rxop;
  1315. status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
  1316. if (status)
  1317. goto out;
  1318. /* extract some info from the scsi command for pde*/
  1319. blksize = lpfc_cmd_blksize(sc);
  1320. lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag);
  1321. /* setup PDE5 with what we have */
  1322. pde5 = (struct lpfc_pde5 *) bpl;
  1323. memset(pde5, 0, sizeof(struct lpfc_pde5));
  1324. bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
  1325. pde5->reftag = reftag;
  1326. /* Endianness conversion if necessary for PDE5 */
  1327. pde5->word0 = cpu_to_le32(pde5->word0);
  1328. pde5->reftag = cpu_to_le32(pde5->reftag);
  1329. /* advance bpl and increment bde count */
  1330. num_bde++;
  1331. bpl++;
  1332. pde6 = (struct lpfc_pde6 *) bpl;
  1333. /* setup PDE6 with the rest of the info */
  1334. memset(pde6, 0, sizeof(struct lpfc_pde6));
  1335. bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
  1336. bf_set(pde6_optx, pde6, txop);
  1337. bf_set(pde6_oprx, pde6, rxop);
  1338. if (datadir == DMA_FROM_DEVICE) {
  1339. bf_set(pde6_ce, pde6, 1);
  1340. bf_set(pde6_re, pde6, 1);
  1341. bf_set(pde6_ae, pde6, 1);
  1342. }
  1343. bf_set(pde6_ai, pde6, 1);
  1344. bf_set(pde6_apptagval, pde6, apptagval);
  1345. /* Endianness conversion if necessary for PDE6 */
  1346. pde6->word0 = cpu_to_le32(pde6->word0);
  1347. pde6->word1 = cpu_to_le32(pde6->word1);
  1348. pde6->word2 = cpu_to_le32(pde6->word2);
  1349. /* advance bpl and increment bde count */
  1350. num_bde++;
  1351. bpl++;
  1352. /* assumption: caller has already run dma_map_sg on command data */
  1353. scsi_for_each_sg(sc, sgde, datasegcnt, i) {
  1354. physaddr = sg_dma_address(sgde);
  1355. bpl->addrLow = le32_to_cpu(putPaddrLow(physaddr));
  1356. bpl->addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  1357. bpl->tus.f.bdeSize = sg_dma_len(sgde);
  1358. if (datadir == DMA_TO_DEVICE)
  1359. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1360. else
  1361. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  1362. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1363. bpl++;
  1364. num_bde++;
  1365. }
  1366. out:
  1367. return num_bde;
  1368. }
  1369. /*
  1370. * This function sets up buffer list for protection groups of
  1371. * type LPFC_PG_TYPE_DIF_BUF
  1372. *
  1373. * This is usually used when DIFs are in their own buffers,
  1374. * separate from the data. The HBA can then by instructed
  1375. * to place the DIFs in the outgoing stream. For read operations,
  1376. * The HBA could extract the DIFs and place it in DIF buffers.
  1377. *
  1378. * The buffer list for this type consists of one or more of the
  1379. * protection groups described below:
  1380. * +-------------------------+
  1381. * start of first prot group --> | PDE_5 |
  1382. * +-------------------------+
  1383. * | PDE_6 |
  1384. * +-------------------------+
  1385. * | PDE_7 (Prot BDE) |
  1386. * +-------------------------+
  1387. * | Data BDE |
  1388. * +-------------------------+
  1389. * |more Data BDE's ... (opt)|
  1390. * +-------------------------+
  1391. * start of new prot group --> | PDE_5 |
  1392. * +-------------------------+
  1393. * | ... |
  1394. * +-------------------------+
  1395. *
  1396. * @sc: pointer to scsi command we're working on
  1397. * @bpl: pointer to buffer list for protection groups
  1398. * @datacnt: number of segments of data that have been dma mapped
  1399. * @protcnt: number of segment of protection data that have been dma mapped
  1400. *
  1401. * Note: It is assumed that both data and protection s/g buffers have been
  1402. * mapped for DMA
  1403. */
  1404. static int
  1405. lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
  1406. struct ulp_bde64 *bpl, int datacnt, int protcnt)
  1407. {
  1408. struct scatterlist *sgde = NULL; /* s/g data entry */
  1409. struct scatterlist *sgpe = NULL; /* s/g prot entry */
  1410. struct lpfc_pde5 *pde5 = NULL;
  1411. struct lpfc_pde6 *pde6 = NULL;
  1412. struct lpfc_pde7 *pde7 = NULL;
  1413. dma_addr_t dataphysaddr, protphysaddr;
  1414. unsigned short curr_data = 0, curr_prot = 0;
  1415. unsigned int split_offset;
  1416. unsigned int protgroup_len, protgroup_offset = 0, protgroup_remainder;
  1417. unsigned int protgrp_blks, protgrp_bytes;
  1418. unsigned int remainder, subtotal;
  1419. int status;
  1420. int datadir = sc->sc_data_direction;
  1421. unsigned char pgdone = 0, alldone = 0;
  1422. unsigned blksize;
  1423. uint32_t reftag;
  1424. uint16_t apptagmask, apptagval;
  1425. uint8_t txop, rxop;
  1426. int num_bde = 0;
  1427. sgpe = scsi_prot_sglist(sc);
  1428. sgde = scsi_sglist(sc);
  1429. if (!sgpe || !sgde) {
  1430. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  1431. "9020 Invalid s/g entry: data=0x%p prot=0x%p\n",
  1432. sgpe, sgde);
  1433. return 0;
  1434. }
  1435. status = lpfc_sc_to_bg_opcodes(phba, sc, &txop, &rxop);
  1436. if (status)
  1437. goto out;
  1438. /* extract some info from the scsi command */
  1439. blksize = lpfc_cmd_blksize(sc);
  1440. lpfc_get_cmd_dif_parms(sc, &apptagmask, &apptagval, &reftag);
  1441. split_offset = 0;
  1442. do {
  1443. /* setup PDE5 with what we have */
  1444. pde5 = (struct lpfc_pde5 *) bpl;
  1445. memset(pde5, 0, sizeof(struct lpfc_pde5));
  1446. bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
  1447. pde5->reftag = reftag;
  1448. /* Endianness conversion if necessary for PDE5 */
  1449. pde5->word0 = cpu_to_le32(pde5->word0);
  1450. pde5->reftag = cpu_to_le32(pde5->reftag);
  1451. /* advance bpl and increment bde count */
  1452. num_bde++;
  1453. bpl++;
  1454. pde6 = (struct lpfc_pde6 *) bpl;
  1455. /* setup PDE6 with the rest of the info */
  1456. memset(pde6, 0, sizeof(struct lpfc_pde6));
  1457. bf_set(pde6_type, pde6, LPFC_PDE6_DESCRIPTOR);
  1458. bf_set(pde6_optx, pde6, txop);
  1459. bf_set(pde6_oprx, pde6, rxop);
  1460. bf_set(pde6_ce, pde6, 1);
  1461. bf_set(pde6_re, pde6, 1);
  1462. bf_set(pde6_ae, pde6, 1);
  1463. bf_set(pde6_ai, pde6, 1);
  1464. bf_set(pde6_apptagval, pde6, apptagval);
  1465. /* Endianness conversion if necessary for PDE6 */
  1466. pde6->word0 = cpu_to_le32(pde6->word0);
  1467. pde6->word1 = cpu_to_le32(pde6->word1);
  1468. pde6->word2 = cpu_to_le32(pde6->word2);
  1469. /* advance bpl and increment bde count */
  1470. num_bde++;
  1471. bpl++;
  1472. /* setup the first BDE that points to protection buffer */
  1473. protphysaddr = sg_dma_address(sgpe) + protgroup_offset;
  1474. protgroup_len = sg_dma_len(sgpe) - protgroup_offset;
  1475. /* must be integer multiple of the DIF block length */
  1476. BUG_ON(protgroup_len % 8);
  1477. pde7 = (struct lpfc_pde7 *) bpl;
  1478. memset(pde7, 0, sizeof(struct lpfc_pde7));
  1479. bf_set(pde7_type, pde7, LPFC_PDE7_DESCRIPTOR);
  1480. pde7->addrHigh = le32_to_cpu(putPaddrLow(protphysaddr));
  1481. pde7->addrLow = le32_to_cpu(putPaddrHigh(protphysaddr));
  1482. protgrp_blks = protgroup_len / 8;
  1483. protgrp_bytes = protgrp_blks * blksize;
  1484. /* check if this pde is crossing the 4K boundary; if so split */
  1485. if ((pde7->addrLow & 0xfff) + protgroup_len > 0x1000) {
  1486. protgroup_remainder = 0x1000 - (pde7->addrLow & 0xfff);
  1487. protgroup_offset += protgroup_remainder;
  1488. protgrp_blks = protgroup_remainder / 8;
  1489. protgrp_bytes = protgroup_remainder * blksize;
  1490. } else {
  1491. protgroup_offset = 0;
  1492. curr_prot++;
  1493. }
  1494. num_bde++;
  1495. /* setup BDE's for data blocks associated with DIF data */
  1496. pgdone = 0;
  1497. subtotal = 0; /* total bytes processed for current prot grp */
  1498. while (!pgdone) {
  1499. if (!sgde) {
  1500. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1501. "9065 BLKGRD:%s Invalid data segment\n",
  1502. __func__);
  1503. return 0;
  1504. }
  1505. bpl++;
  1506. dataphysaddr = sg_dma_address(sgde) + split_offset;
  1507. bpl->addrLow = le32_to_cpu(putPaddrLow(dataphysaddr));
  1508. bpl->addrHigh = le32_to_cpu(putPaddrHigh(dataphysaddr));
  1509. remainder = sg_dma_len(sgde) - split_offset;
  1510. if ((subtotal + remainder) <= protgrp_bytes) {
  1511. /* we can use this whole buffer */
  1512. bpl->tus.f.bdeSize = remainder;
  1513. split_offset = 0;
  1514. if ((subtotal + remainder) == protgrp_bytes)
  1515. pgdone = 1;
  1516. } else {
  1517. /* must split this buffer with next prot grp */
  1518. bpl->tus.f.bdeSize = protgrp_bytes - subtotal;
  1519. split_offset += bpl->tus.f.bdeSize;
  1520. }
  1521. subtotal += bpl->tus.f.bdeSize;
  1522. if (datadir == DMA_TO_DEVICE)
  1523. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1524. else
  1525. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  1526. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1527. num_bde++;
  1528. curr_data++;
  1529. if (split_offset)
  1530. break;
  1531. /* Move to the next s/g segment if possible */
  1532. sgde = sg_next(sgde);
  1533. }
  1534. if (protgroup_offset) {
  1535. /* update the reference tag */
  1536. reftag += protgrp_blks;
  1537. bpl++;
  1538. continue;
  1539. }
  1540. /* are we done ? */
  1541. if (curr_prot == protcnt) {
  1542. alldone = 1;
  1543. } else if (curr_prot < protcnt) {
  1544. /* advance to next prot buffer */
  1545. sgpe = sg_next(sgpe);
  1546. bpl++;
  1547. /* update the reference tag */
  1548. reftag += protgrp_blks;
  1549. } else {
  1550. /* if we're here, we have a bug */
  1551. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1552. "9054 BLKGRD: bug in %s\n", __func__);
  1553. }
  1554. } while (!alldone);
  1555. out:
  1556. return num_bde;
  1557. }
  1558. /*
  1559. * Given a SCSI command that supports DIF, determine composition of protection
  1560. * groups involved in setting up buffer lists
  1561. *
  1562. * Returns:
  1563. * for DIF (for both read and write)
  1564. * */
  1565. static int
  1566. lpfc_prot_group_type(struct lpfc_hba *phba, struct scsi_cmnd *sc)
  1567. {
  1568. int ret = LPFC_PG_TYPE_INVALID;
  1569. unsigned char op = scsi_get_prot_op(sc);
  1570. switch (op) {
  1571. case SCSI_PROT_READ_STRIP:
  1572. case SCSI_PROT_WRITE_INSERT:
  1573. ret = LPFC_PG_TYPE_NO_DIF;
  1574. break;
  1575. case SCSI_PROT_READ_INSERT:
  1576. case SCSI_PROT_WRITE_STRIP:
  1577. case SCSI_PROT_READ_PASS:
  1578. case SCSI_PROT_WRITE_PASS:
  1579. ret = LPFC_PG_TYPE_DIF_BUF;
  1580. break;
  1581. default:
  1582. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  1583. "9021 Unsupported protection op:%d\n", op);
  1584. break;
  1585. }
  1586. return ret;
  1587. }
  1588. /*
  1589. * This is the protection/DIF aware version of
  1590. * lpfc_scsi_prep_dma_buf(). It may be a good idea to combine the
  1591. * two functions eventually, but for now, it's here
  1592. */
  1593. static int
  1594. lpfc_bg_scsi_prep_dma_buf(struct lpfc_hba *phba,
  1595. struct lpfc_scsi_buf *lpfc_cmd)
  1596. {
  1597. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  1598. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  1599. struct ulp_bde64 *bpl = lpfc_cmd->fcp_bpl;
  1600. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  1601. uint32_t num_bde = 0;
  1602. int datasegcnt, protsegcnt, datadir = scsi_cmnd->sc_data_direction;
  1603. int prot_group_type = 0;
  1604. int diflen, fcpdl;
  1605. unsigned blksize;
  1606. /*
  1607. * Start the lpfc command prep by bumping the bpl beyond fcp_cmnd
  1608. * fcp_rsp regions to the first data bde entry
  1609. */
  1610. bpl += 2;
  1611. if (scsi_sg_count(scsi_cmnd)) {
  1612. /*
  1613. * The driver stores the segment count returned from pci_map_sg
  1614. * because this a count of dma-mappings used to map the use_sg
  1615. * pages. They are not guaranteed to be the same for those
  1616. * architectures that implement an IOMMU.
  1617. */
  1618. datasegcnt = dma_map_sg(&phba->pcidev->dev,
  1619. scsi_sglist(scsi_cmnd),
  1620. scsi_sg_count(scsi_cmnd), datadir);
  1621. if (unlikely(!datasegcnt))
  1622. return 1;
  1623. lpfc_cmd->seg_cnt = datasegcnt;
  1624. if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
  1625. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1626. "9067 BLKGRD: %s: Too many sg segments"
  1627. " from dma_map_sg. Config %d, seg_cnt"
  1628. " %d\n",
  1629. __func__, phba->cfg_sg_seg_cnt,
  1630. lpfc_cmd->seg_cnt);
  1631. scsi_dma_unmap(scsi_cmnd);
  1632. return 1;
  1633. }
  1634. prot_group_type = lpfc_prot_group_type(phba, scsi_cmnd);
  1635. switch (prot_group_type) {
  1636. case LPFC_PG_TYPE_NO_DIF:
  1637. num_bde = lpfc_bg_setup_bpl(phba, scsi_cmnd, bpl,
  1638. datasegcnt);
  1639. /* we should have 2 or more entries in buffer list */
  1640. if (num_bde < 2)
  1641. goto err;
  1642. break;
  1643. case LPFC_PG_TYPE_DIF_BUF:{
  1644. /*
  1645. * This type indicates that protection buffers are
  1646. * passed to the driver, so that needs to be prepared
  1647. * for DMA
  1648. */
  1649. protsegcnt = dma_map_sg(&phba->pcidev->dev,
  1650. scsi_prot_sglist(scsi_cmnd),
  1651. scsi_prot_sg_count(scsi_cmnd), datadir);
  1652. if (unlikely(!protsegcnt)) {
  1653. scsi_dma_unmap(scsi_cmnd);
  1654. return 1;
  1655. }
  1656. lpfc_cmd->prot_seg_cnt = protsegcnt;
  1657. if (lpfc_cmd->prot_seg_cnt
  1658. > phba->cfg_prot_sg_seg_cnt) {
  1659. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1660. "9068 BLKGRD: %s: Too many prot sg "
  1661. "segments from dma_map_sg. Config %d,"
  1662. "prot_seg_cnt %d\n", __func__,
  1663. phba->cfg_prot_sg_seg_cnt,
  1664. lpfc_cmd->prot_seg_cnt);
  1665. dma_unmap_sg(&phba->pcidev->dev,
  1666. scsi_prot_sglist(scsi_cmnd),
  1667. scsi_prot_sg_count(scsi_cmnd),
  1668. datadir);
  1669. scsi_dma_unmap(scsi_cmnd);
  1670. return 1;
  1671. }
  1672. num_bde = lpfc_bg_setup_bpl_prot(phba, scsi_cmnd, bpl,
  1673. datasegcnt, protsegcnt);
  1674. /* we should have 3 or more entries in buffer list */
  1675. if (num_bde < 3)
  1676. goto err;
  1677. break;
  1678. }
  1679. case LPFC_PG_TYPE_INVALID:
  1680. default:
  1681. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  1682. "9022 Unexpected protection group %i\n",
  1683. prot_group_type);
  1684. return 1;
  1685. }
  1686. }
  1687. /*
  1688. * Finish initializing those IOCB fields that are dependent on the
  1689. * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
  1690. * reinitialized since all iocb memory resources are used many times
  1691. * for transmit, receive, and continuation bpl's.
  1692. */
  1693. iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  1694. iocb_cmd->un.fcpi64.bdl.bdeSize += (num_bde * sizeof(struct ulp_bde64));
  1695. iocb_cmd->ulpBdeCount = 1;
  1696. iocb_cmd->ulpLe = 1;
  1697. fcpdl = scsi_bufflen(scsi_cmnd);
  1698. if (scsi_get_prot_type(scsi_cmnd) == SCSI_PROT_DIF_TYPE1) {
  1699. /*
  1700. * We are in DIF Type 1 mode
  1701. * Every data block has a 8 byte DIF (trailer)
  1702. * attached to it. Must ajust FCP data length
  1703. */
  1704. blksize = lpfc_cmd_blksize(scsi_cmnd);
  1705. diflen = (fcpdl / blksize) * 8;
  1706. fcpdl += diflen;
  1707. }
  1708. fcp_cmnd->fcpDl = be32_to_cpu(fcpdl);
  1709. /*
  1710. * Due to difference in data length between DIF/non-DIF paths,
  1711. * we need to set word 4 of IOCB here
  1712. */
  1713. iocb_cmd->un.fcpi.fcpi_parm = fcpdl;
  1714. return 0;
  1715. err:
  1716. lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
  1717. "9023 Could not setup all needed BDE's"
  1718. "prot_group_type=%d, num_bde=%d\n",
  1719. prot_group_type, num_bde);
  1720. return 1;
  1721. }
  1722. /*
  1723. * This function checks for BlockGuard errors detected by
  1724. * the HBA. In case of errors, the ASC/ASCQ fields in the
  1725. * sense buffer will be set accordingly, paired with
  1726. * ILLEGAL_REQUEST to signal to the kernel that the HBA
  1727. * detected corruption.
  1728. *
  1729. * Returns:
  1730. * 0 - No error found
  1731. * 1 - BlockGuard error found
  1732. * -1 - Internal error (bad profile, ...etc)
  1733. */
  1734. static int
  1735. lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
  1736. struct lpfc_iocbq *pIocbOut)
  1737. {
  1738. struct scsi_cmnd *cmd = lpfc_cmd->pCmd;
  1739. struct sli3_bg_fields *bgf = &pIocbOut->iocb.unsli3.sli3_bg;
  1740. int ret = 0;
  1741. uint32_t bghm = bgf->bghm;
  1742. uint32_t bgstat = bgf->bgstat;
  1743. uint64_t failing_sector = 0;
  1744. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9069 BLKGRD: BG ERROR in cmd"
  1745. " 0x%x lba 0x%llx blk cnt 0x%x "
  1746. "bgstat=0x%x bghm=0x%x\n",
  1747. cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd),
  1748. blk_rq_sectors(cmd->request), bgstat, bghm);
  1749. spin_lock(&_dump_buf_lock);
  1750. if (!_dump_buf_done) {
  1751. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9070 BLKGRD: Saving"
  1752. " Data for %u blocks to debugfs\n",
  1753. (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
  1754. lpfc_debug_save_data(phba, cmd);
  1755. /* If we have a prot sgl, save the DIF buffer */
  1756. if (lpfc_prot_group_type(phba, cmd) ==
  1757. LPFC_PG_TYPE_DIF_BUF) {
  1758. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9071 BLKGRD: "
  1759. "Saving DIF for %u blocks to debugfs\n",
  1760. (cmd->cmnd[7] << 8 | cmd->cmnd[8]));
  1761. lpfc_debug_save_dif(phba, cmd);
  1762. }
  1763. _dump_buf_done = 1;
  1764. }
  1765. spin_unlock(&_dump_buf_lock);
  1766. if (lpfc_bgs_get_invalid_prof(bgstat)) {
  1767. cmd->result = ScsiResult(DID_ERROR, 0);
  1768. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9072 BLKGRD: Invalid"
  1769. " BlockGuard profile. bgstat:0x%x\n",
  1770. bgstat);
  1771. ret = (-1);
  1772. goto out;
  1773. }
  1774. if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
  1775. cmd->result = ScsiResult(DID_ERROR, 0);
  1776. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9073 BLKGRD: "
  1777. "Invalid BlockGuard DIF Block. bgstat:0x%x\n",
  1778. bgstat);
  1779. ret = (-1);
  1780. goto out;
  1781. }
  1782. if (lpfc_bgs_get_guard_err(bgstat)) {
  1783. ret = 1;
  1784. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  1785. 0x10, 0x1);
  1786. cmd->result = DRIVER_SENSE << 24
  1787. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  1788. phba->bg_guard_err_cnt++;
  1789. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1790. "9055 BLKGRD: guard_tag error\n");
  1791. }
  1792. if (lpfc_bgs_get_reftag_err(bgstat)) {
  1793. ret = 1;
  1794. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  1795. 0x10, 0x3);
  1796. cmd->result = DRIVER_SENSE << 24
  1797. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  1798. phba->bg_reftag_err_cnt++;
  1799. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1800. "9056 BLKGRD: ref_tag error\n");
  1801. }
  1802. if (lpfc_bgs_get_apptag_err(bgstat)) {
  1803. ret = 1;
  1804. scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
  1805. 0x10, 0x2);
  1806. cmd->result = DRIVER_SENSE << 24
  1807. | ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
  1808. phba->bg_apptag_err_cnt++;
  1809. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1810. "9061 BLKGRD: app_tag error\n");
  1811. }
  1812. if (lpfc_bgs_get_hi_water_mark_present(bgstat)) {
  1813. /*
  1814. * setup sense data descriptor 0 per SPC-4 as an information
  1815. * field, and put the failing LBA in it
  1816. */
  1817. cmd->sense_buffer[8] = 0; /* Information */
  1818. cmd->sense_buffer[9] = 0xa; /* Add. length */
  1819. bghm /= cmd->device->sector_size;
  1820. failing_sector = scsi_get_lba(cmd);
  1821. failing_sector += bghm;
  1822. put_unaligned_be64(failing_sector, &cmd->sense_buffer[10]);
  1823. }
  1824. if (!ret) {
  1825. /* No error was reported - problem in FW? */
  1826. cmd->result = ScsiResult(DID_ERROR, 0);
  1827. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  1828. "9057 BLKGRD: no errors reported!\n");
  1829. }
  1830. out:
  1831. return ret;
  1832. }
  1833. /**
  1834. * lpfc_scsi_prep_dma_buf_s4 - DMA mapping for scsi buffer to SLI4 IF spec
  1835. * @phba: The Hba for which this call is being executed.
  1836. * @lpfc_cmd: The scsi buffer which is going to be mapped.
  1837. *
  1838. * This routine does the pci dma mapping for scatter-gather list of scsi cmnd
  1839. * field of @lpfc_cmd for device with SLI-4 interface spec.
  1840. *
  1841. * Return codes:
  1842. * 1 - Error
  1843. * 0 - Success
  1844. **/
  1845. static int
  1846. lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  1847. {
  1848. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  1849. struct scatterlist *sgel = NULL;
  1850. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  1851. struct sli4_sge *sgl = (struct sli4_sge *)lpfc_cmd->fcp_bpl;
  1852. struct sli4_sge *first_data_sgl;
  1853. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  1854. dma_addr_t physaddr;
  1855. uint32_t num_bde = 0;
  1856. uint32_t dma_len;
  1857. uint32_t dma_offset = 0;
  1858. int nseg;
  1859. struct ulp_bde64 *bde;
  1860. /*
  1861. * There are three possibilities here - use scatter-gather segment, use
  1862. * the single mapping, or neither. Start the lpfc command prep by
  1863. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  1864. * data bde entry.
  1865. */
  1866. if (scsi_sg_count(scsi_cmnd)) {
  1867. /*
  1868. * The driver stores the segment count returned from pci_map_sg
  1869. * because this a count of dma-mappings used to map the use_sg
  1870. * pages. They are not guaranteed to be the same for those
  1871. * architectures that implement an IOMMU.
  1872. */
  1873. nseg = scsi_dma_map(scsi_cmnd);
  1874. if (unlikely(!nseg))
  1875. return 1;
  1876. sgl += 1;
  1877. /* clear the last flag in the fcp_rsp map entry */
  1878. sgl->word2 = le32_to_cpu(sgl->word2);
  1879. bf_set(lpfc_sli4_sge_last, sgl, 0);
  1880. sgl->word2 = cpu_to_le32(sgl->word2);
  1881. sgl += 1;
  1882. first_data_sgl = sgl;
  1883. lpfc_cmd->seg_cnt = nseg;
  1884. if (lpfc_cmd->seg_cnt > phba->cfg_sg_seg_cnt) {
  1885. lpfc_printf_log(phba, KERN_ERR, LOG_BG, "9074 BLKGRD:"
  1886. " %s: Too many sg segments from "
  1887. "dma_map_sg. Config %d, seg_cnt %d\n",
  1888. __func__, phba->cfg_sg_seg_cnt,
  1889. lpfc_cmd->seg_cnt);
  1890. scsi_dma_unmap(scsi_cmnd);
  1891. return 1;
  1892. }
  1893. /*
  1894. * The driver established a maximum scatter-gather segment count
  1895. * during probe that limits the number of sg elements in any
  1896. * single scsi command. Just run through the seg_cnt and format
  1897. * the sge's.
  1898. * When using SLI-3 the driver will try to fit all the BDEs into
  1899. * the IOCB. If it can't then the BDEs get added to a BPL as it
  1900. * does for SLI-2 mode.
  1901. */
  1902. scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
  1903. physaddr = sg_dma_address(sgel);
  1904. dma_len = sg_dma_len(sgel);
  1905. sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
  1906. sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
  1907. sgl->word2 = le32_to_cpu(sgl->word2);
  1908. if ((num_bde + 1) == nseg)
  1909. bf_set(lpfc_sli4_sge_last, sgl, 1);
  1910. else
  1911. bf_set(lpfc_sli4_sge_last, sgl, 0);
  1912. bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
  1913. sgl->word2 = cpu_to_le32(sgl->word2);
  1914. sgl->sge_len = cpu_to_le32(dma_len);
  1915. dma_offset += dma_len;
  1916. sgl++;
  1917. }
  1918. /* setup the performance hint (first data BDE) if enabled */
  1919. if (phba->sli3_options & LPFC_SLI4_PERFH_ENABLED) {
  1920. bde = (struct ulp_bde64 *)
  1921. &(iocb_cmd->unsli3.sli3Words[5]);
  1922. bde->addrLow = first_data_sgl->addr_lo;
  1923. bde->addrHigh = first_data_sgl->addr_hi;
  1924. bde->tus.f.bdeSize =
  1925. le32_to_cpu(first_data_sgl->sge_len);
  1926. bde->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1927. bde->tus.w = cpu_to_le32(bde->tus.w);
  1928. }
  1929. } else {
  1930. sgl += 1;
  1931. /* clear the last flag in the fcp_rsp map entry */
  1932. sgl->word2 = le32_to_cpu(sgl->word2);
  1933. bf_set(lpfc_sli4_sge_last, sgl, 1);
  1934. sgl->word2 = cpu_to_le32(sgl->word2);
  1935. }
  1936. /*
  1937. * Finish initializing those IOCB fields that are dependent on the
  1938. * scsi_cmnd request_buffer. Note that for SLI-2 the bdeSize is
  1939. * explicitly reinitialized.
  1940. * all iocb memory resources are reused.
  1941. */
  1942. fcp_cmnd->fcpDl = cpu_to_be32(scsi_bufflen(scsi_cmnd));
  1943. /*
  1944. * Due to difference in data length between DIF/non-DIF paths,
  1945. * we need to set word 4 of IOCB here
  1946. */
  1947. iocb_cmd->un.fcpi.fcpi_parm = scsi_bufflen(scsi_cmnd);
  1948. return 0;
  1949. }
  1950. /**
  1951. * lpfc_scsi_prep_dma_buf - Wrapper function for DMA mapping of scsi buffer
  1952. * @phba: The Hba for which this call is being executed.
  1953. * @lpfc_cmd: The scsi buffer which is going to be mapped.
  1954. *
  1955. * This routine wraps the actual DMA mapping function pointer from the
  1956. * lpfc_hba struct.
  1957. *
  1958. * Return codes:
  1959. * 1 - Error
  1960. * 0 - Success
  1961. **/
  1962. static inline int
  1963. lpfc_scsi_prep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
  1964. {
  1965. return phba->lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
  1966. }
  1967. /**
  1968. * lpfc_send_scsi_error_event - Posts an event when there is SCSI error
  1969. * @phba: Pointer to hba context object.
  1970. * @vport: Pointer to vport object.
  1971. * @lpfc_cmd: Pointer to lpfc scsi command which reported the error.
  1972. * @rsp_iocb: Pointer to response iocb object which reported error.
  1973. *
  1974. * This function posts an event when there is a SCSI command reporting
  1975. * error from the scsi device.
  1976. **/
  1977. static void
  1978. lpfc_send_scsi_error_event(struct lpfc_hba *phba, struct lpfc_vport *vport,
  1979. struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb) {
  1980. struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
  1981. struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
  1982. uint32_t resp_info = fcprsp->rspStatus2;
  1983. uint32_t scsi_status = fcprsp->rspStatus3;
  1984. uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
  1985. struct lpfc_fast_path_event *fast_path_evt = NULL;
  1986. struct lpfc_nodelist *pnode = lpfc_cmd->rdata->pnode;
  1987. unsigned long flags;
  1988. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  1989. return;
  1990. /* If there is queuefull or busy condition send a scsi event */
  1991. if ((cmnd->result == SAM_STAT_TASK_SET_FULL) ||
  1992. (cmnd->result == SAM_STAT_BUSY)) {
  1993. fast_path_evt = lpfc_alloc_fast_evt(phba);
  1994. if (!fast_path_evt)
  1995. return;
  1996. fast_path_evt->un.scsi_evt.event_type =
  1997. FC_REG_SCSI_EVENT;
  1998. fast_path_evt->un.scsi_evt.subcategory =
  1999. (cmnd->result == SAM_STAT_TASK_SET_FULL) ?
  2000. LPFC_EVENT_QFULL : LPFC_EVENT_DEVBSY;
  2001. fast_path_evt->un.scsi_evt.lun = cmnd->device->lun;
  2002. memcpy(&fast_path_evt->un.scsi_evt.wwpn,
  2003. &pnode->nlp_portname, sizeof(struct lpfc_name));
  2004. memcpy(&fast_path_evt->un.scsi_evt.wwnn,
  2005. &pnode->nlp_nodename, sizeof(struct lpfc_name));
  2006. } else if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen &&
  2007. ((cmnd->cmnd[0] == READ_10) || (cmnd->cmnd[0] == WRITE_10))) {
  2008. fast_path_evt = lpfc_alloc_fast_evt(phba);
  2009. if (!fast_path_evt)
  2010. return;
  2011. fast_path_evt->un.check_cond_evt.scsi_event.event_type =
  2012. FC_REG_SCSI_EVENT;
  2013. fast_path_evt->un.check_cond_evt.scsi_event.subcategory =
  2014. LPFC_EVENT_CHECK_COND;
  2015. fast_path_evt->un.check_cond_evt.scsi_event.lun =
  2016. cmnd->device->lun;
  2017. memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwpn,
  2018. &pnode->nlp_portname, sizeof(struct lpfc_name));
  2019. memcpy(&fast_path_evt->un.check_cond_evt.scsi_event.wwnn,
  2020. &pnode->nlp_nodename, sizeof(struct lpfc_name));
  2021. fast_path_evt->un.check_cond_evt.sense_key =
  2022. cmnd->sense_buffer[2] & 0xf;
  2023. fast_path_evt->un.check_cond_evt.asc = cmnd->sense_buffer[12];
  2024. fast_path_evt->un.check_cond_evt.ascq = cmnd->sense_buffer[13];
  2025. } else if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
  2026. fcpi_parm &&
  2027. ((be32_to_cpu(fcprsp->rspResId) != fcpi_parm) ||
  2028. ((scsi_status == SAM_STAT_GOOD) &&
  2029. !(resp_info & (RESID_UNDER | RESID_OVER))))) {
  2030. /*
  2031. * If status is good or resid does not match with fcp_param and
  2032. * there is valid fcpi_parm, then there is a read_check error
  2033. */
  2034. fast_path_evt = lpfc_alloc_fast_evt(phba);
  2035. if (!fast_path_evt)
  2036. return;
  2037. fast_path_evt->un.read_check_error.header.event_type =
  2038. FC_REG_FABRIC_EVENT;
  2039. fast_path_evt->un.read_check_error.header.subcategory =
  2040. LPFC_EVENT_FCPRDCHKERR;
  2041. memcpy(&fast_path_evt->un.read_check_error.header.wwpn,
  2042. &pnode->nlp_portname, sizeof(struct lpfc_name));
  2043. memcpy(&fast_path_evt->un.read_check_error.header.wwnn,
  2044. &pnode->nlp_nodename, sizeof(struct lpfc_name));
  2045. fast_path_evt->un.read_check_error.lun = cmnd->device->lun;
  2046. fast_path_evt->un.read_check_error.opcode = cmnd->cmnd[0];
  2047. fast_path_evt->un.read_check_error.fcpiparam =
  2048. fcpi_parm;
  2049. } else
  2050. return;
  2051. fast_path_evt->vport = vport;
  2052. spin_lock_irqsave(&phba->hbalock, flags);
  2053. list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
  2054. spin_unlock_irqrestore(&phba->hbalock, flags);
  2055. lpfc_worker_wake_up(phba);
  2056. return;
  2057. }
  2058. /**
  2059. * lpfc_scsi_unprep_dma_buf - Un-map DMA mapping of SG-list for dev
  2060. * @phba: The HBA for which this call is being executed.
  2061. * @psb: The scsi buffer which is going to be un-mapped.
  2062. *
  2063. * This routine does DMA un-mapping of scatter gather list of scsi command
  2064. * field of @lpfc_cmd for device with SLI-3 interface spec.
  2065. **/
  2066. static void
  2067. lpfc_scsi_unprep_dma_buf(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
  2068. {
  2069. /*
  2070. * There are only two special cases to consider. (1) the scsi command
  2071. * requested scatter-gather usage or (2) the scsi command allocated
  2072. * a request buffer, but did not request use_sg. There is a third
  2073. * case, but it does not require resource deallocation.
  2074. */
  2075. if (psb->seg_cnt > 0)
  2076. scsi_dma_unmap(psb->pCmd);
  2077. if (psb->prot_seg_cnt > 0)
  2078. dma_unmap_sg(&phba->pcidev->dev, scsi_prot_sglist(psb->pCmd),
  2079. scsi_prot_sg_count(psb->pCmd),
  2080. psb->pCmd->sc_data_direction);
  2081. }
  2082. /**
  2083. * lpfc_handler_fcp_err - FCP response handler
  2084. * @vport: The virtual port for which this call is being executed.
  2085. * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
  2086. * @rsp_iocb: The response IOCB which contains FCP error.
  2087. *
  2088. * This routine is called to process response IOCB with status field
  2089. * IOSTAT_FCP_RSP_ERROR. This routine sets result field of scsi command
  2090. * based upon SCSI and FCP error.
  2091. **/
  2092. static void
  2093. lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
  2094. struct lpfc_iocbq *rsp_iocb)
  2095. {
  2096. struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
  2097. struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
  2098. struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
  2099. uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
  2100. uint32_t resp_info = fcprsp->rspStatus2;
  2101. uint32_t scsi_status = fcprsp->rspStatus3;
  2102. uint32_t *lp;
  2103. uint32_t host_status = DID_OK;
  2104. uint32_t rsplen = 0;
  2105. uint32_t logit = LOG_FCP | LOG_FCP_ERROR;
  2106. /*
  2107. * If this is a task management command, there is no
  2108. * scsi packet associated with this lpfc_cmd. The driver
  2109. * consumes it.
  2110. */
  2111. if (fcpcmd->fcpCntl2) {
  2112. scsi_status = 0;
  2113. goto out;
  2114. }
  2115. if (resp_info & RSP_LEN_VALID) {
  2116. rsplen = be32_to_cpu(fcprsp->rspRspLen);
  2117. if (rsplen != 0 && rsplen != 4 && rsplen != 8) {
  2118. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  2119. "2719 Invalid response length: "
  2120. "tgt x%x lun x%x cmnd x%x rsplen x%x\n",
  2121. cmnd->device->id,
  2122. cmnd->device->lun, cmnd->cmnd[0],
  2123. rsplen);
  2124. host_status = DID_ERROR;
  2125. goto out;
  2126. }
  2127. if (fcprsp->rspInfo3 != RSP_NO_FAILURE) {
  2128. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  2129. "2757 Protocol failure detected during "
  2130. "processing of FCP I/O op: "
  2131. "tgt x%x lun x%x cmnd x%x rspInfo3 x%x\n",
  2132. cmnd->device->id,
  2133. cmnd->device->lun, cmnd->cmnd[0],
  2134. fcprsp->rspInfo3);
  2135. host_status = DID_ERROR;
  2136. goto out;
  2137. }
  2138. }
  2139. if ((resp_info & SNS_LEN_VALID) && fcprsp->rspSnsLen) {
  2140. uint32_t snslen = be32_to_cpu(fcprsp->rspSnsLen);
  2141. if (snslen > SCSI_SENSE_BUFFERSIZE)
  2142. snslen = SCSI_SENSE_BUFFERSIZE;
  2143. if (resp_info & RSP_LEN_VALID)
  2144. rsplen = be32_to_cpu(fcprsp->rspRspLen);
  2145. memcpy(cmnd->sense_buffer, &fcprsp->rspInfo0 + rsplen, snslen);
  2146. }
  2147. lp = (uint32_t *)cmnd->sense_buffer;
  2148. if (!scsi_status && (resp_info & RESID_UNDER))
  2149. logit = LOG_FCP;
  2150. lpfc_printf_vlog(vport, KERN_WARNING, logit,
  2151. "9024 FCP command x%x failed: x%x SNS x%x x%x "
  2152. "Data: x%x x%x x%x x%x x%x\n",
  2153. cmnd->cmnd[0], scsi_status,
  2154. be32_to_cpu(*lp), be32_to_cpu(*(lp + 3)), resp_info,
  2155. be32_to_cpu(fcprsp->rspResId),
  2156. be32_to_cpu(fcprsp->rspSnsLen),
  2157. be32_to_cpu(fcprsp->rspRspLen),
  2158. fcprsp->rspInfo3);
  2159. scsi_set_resid(cmnd, 0);
  2160. if (resp_info & RESID_UNDER) {
  2161. scsi_set_resid(cmnd, be32_to_cpu(fcprsp->rspResId));
  2162. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  2163. "9025 FCP Read Underrun, expected %d, "
  2164. "residual %d Data: x%x x%x x%x\n",
  2165. be32_to_cpu(fcpcmd->fcpDl),
  2166. scsi_get_resid(cmnd), fcpi_parm, cmnd->cmnd[0],
  2167. cmnd->underflow);
  2168. /*
  2169. * If there is an under run check if under run reported by
  2170. * storage array is same as the under run reported by HBA.
  2171. * If this is not same, there is a dropped frame.
  2172. */
  2173. if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
  2174. fcpi_parm &&
  2175. (scsi_get_resid(cmnd) != fcpi_parm)) {
  2176. lpfc_printf_vlog(vport, KERN_WARNING,
  2177. LOG_FCP | LOG_FCP_ERROR,
  2178. "9026 FCP Read Check Error "
  2179. "and Underrun Data: x%x x%x x%x x%x\n",
  2180. be32_to_cpu(fcpcmd->fcpDl),
  2181. scsi_get_resid(cmnd), fcpi_parm,
  2182. cmnd->cmnd[0]);
  2183. scsi_set_resid(cmnd, scsi_bufflen(cmnd));
  2184. host_status = DID_ERROR;
  2185. }
  2186. /*
  2187. * The cmnd->underflow is the minimum number of bytes that must
  2188. * be transferred for this command. Provided a sense condition
  2189. * is not present, make sure the actual amount transferred is at
  2190. * least the underflow value or fail.
  2191. */
  2192. if (!(resp_info & SNS_LEN_VALID) &&
  2193. (scsi_status == SAM_STAT_GOOD) &&
  2194. (scsi_bufflen(cmnd) - scsi_get_resid(cmnd)
  2195. < cmnd->underflow)) {
  2196. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  2197. "9027 FCP command x%x residual "
  2198. "underrun converted to error "
  2199. "Data: x%x x%x x%x\n",
  2200. cmnd->cmnd[0], scsi_bufflen(cmnd),
  2201. scsi_get_resid(cmnd), cmnd->underflow);
  2202. host_status = DID_ERROR;
  2203. }
  2204. } else if (resp_info & RESID_OVER) {
  2205. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  2206. "9028 FCP command x%x residual overrun error. "
  2207. "Data: x%x x%x\n", cmnd->cmnd[0],
  2208. scsi_bufflen(cmnd), scsi_get_resid(cmnd));
  2209. host_status = DID_ERROR;
  2210. /*
  2211. * Check SLI validation that all the transfer was actually done
  2212. * (fcpi_parm should be zero). Apply check only to reads.
  2213. */
  2214. } else if (fcpi_parm && (cmnd->sc_data_direction == DMA_FROM_DEVICE)) {
  2215. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP | LOG_FCP_ERROR,
  2216. "9029 FCP Read Check Error Data: "
  2217. "x%x x%x x%x x%x x%x\n",
  2218. be32_to_cpu(fcpcmd->fcpDl),
  2219. be32_to_cpu(fcprsp->rspResId),
  2220. fcpi_parm, cmnd->cmnd[0], scsi_status);
  2221. switch (scsi_status) {
  2222. case SAM_STAT_GOOD:
  2223. case SAM_STAT_CHECK_CONDITION:
  2224. /* Fabric dropped a data frame. Fail any successful
  2225. * command in which we detected dropped frames.
  2226. * A status of good or some check conditions could
  2227. * be considered a successful command.
  2228. */
  2229. host_status = DID_ERROR;
  2230. break;
  2231. }
  2232. scsi_set_resid(cmnd, scsi_bufflen(cmnd));
  2233. }
  2234. out:
  2235. cmnd->result = ScsiResult(host_status, scsi_status);
  2236. lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
  2237. }
  2238. /**
  2239. * lpfc_scsi_cmd_iocb_cmpl - Scsi cmnd IOCB completion routine
  2240. * @phba: The Hba for which this call is being executed.
  2241. * @pIocbIn: The command IOCBQ for the scsi cmnd.
  2242. * @pIocbOut: The response IOCBQ for the scsi cmnd.
  2243. *
  2244. * This routine assigns scsi command result by looking into response IOCB
  2245. * status field appropriately. This routine handles QUEUE FULL condition as
  2246. * well by ramping down device queue depth.
  2247. **/
  2248. static void
  2249. lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
  2250. struct lpfc_iocbq *pIocbOut)
  2251. {
  2252. struct lpfc_scsi_buf *lpfc_cmd =
  2253. (struct lpfc_scsi_buf *) pIocbIn->context1;
  2254. struct lpfc_vport *vport = pIocbIn->vport;
  2255. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  2256. struct lpfc_nodelist *pnode = rdata->pnode;
  2257. struct scsi_cmnd *cmd;
  2258. int result;
  2259. struct scsi_device *tmp_sdev;
  2260. int depth;
  2261. unsigned long flags;
  2262. struct lpfc_fast_path_event *fast_path_evt;
  2263. struct Scsi_Host *shost;
  2264. uint32_t queue_depth, scsi_id;
  2265. /* Sanity check on return of outstanding command */
  2266. if (!(lpfc_cmd->pCmd))
  2267. return;
  2268. cmd = lpfc_cmd->pCmd;
  2269. shost = cmd->device->host;
  2270. lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
  2271. lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
  2272. /* pick up SLI4 exhange busy status from HBA */
  2273. lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
  2274. if (pnode && NLP_CHK_NODE_ACT(pnode))
  2275. atomic_dec(&pnode->cmd_pending);
  2276. if (lpfc_cmd->status) {
  2277. if (lpfc_cmd->status == IOSTAT_LOCAL_REJECT &&
  2278. (lpfc_cmd->result & IOERR_DRVR_MASK))
  2279. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  2280. else if (lpfc_cmd->status >= IOSTAT_CNT)
  2281. lpfc_cmd->status = IOSTAT_DEFAULT;
  2282. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  2283. "9030 FCP cmd x%x failed <%d/%d> "
  2284. "status: x%x result: x%x Data: x%x x%x\n",
  2285. cmd->cmnd[0],
  2286. cmd->device ? cmd->device->id : 0xffff,
  2287. cmd->device ? cmd->device->lun : 0xffff,
  2288. lpfc_cmd->status, lpfc_cmd->result,
  2289. pIocbOut->iocb.ulpContext,
  2290. lpfc_cmd->cur_iocbq.iocb.ulpIoTag);
  2291. switch (lpfc_cmd->status) {
  2292. case IOSTAT_FCP_RSP_ERROR:
  2293. /* Call FCP RSP handler to determine result */
  2294. lpfc_handle_fcp_err(vport, lpfc_cmd, pIocbOut);
  2295. break;
  2296. case IOSTAT_NPORT_BSY:
  2297. case IOSTAT_FABRIC_BSY:
  2298. cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
  2299. fast_path_evt = lpfc_alloc_fast_evt(phba);
  2300. if (!fast_path_evt)
  2301. break;
  2302. fast_path_evt->un.fabric_evt.event_type =
  2303. FC_REG_FABRIC_EVENT;
  2304. fast_path_evt->un.fabric_evt.subcategory =
  2305. (lpfc_cmd->status == IOSTAT_NPORT_BSY) ?
  2306. LPFC_EVENT_PORT_BUSY : LPFC_EVENT_FABRIC_BUSY;
  2307. if (pnode && NLP_CHK_NODE_ACT(pnode)) {
  2308. memcpy(&fast_path_evt->un.fabric_evt.wwpn,
  2309. &pnode->nlp_portname,
  2310. sizeof(struct lpfc_name));
  2311. memcpy(&fast_path_evt->un.fabric_evt.wwnn,
  2312. &pnode->nlp_nodename,
  2313. sizeof(struct lpfc_name));
  2314. }
  2315. fast_path_evt->vport = vport;
  2316. fast_path_evt->work_evt.evt =
  2317. LPFC_EVT_FASTPATH_MGMT_EVT;
  2318. spin_lock_irqsave(&phba->hbalock, flags);
  2319. list_add_tail(&fast_path_evt->work_evt.evt_listp,
  2320. &phba->work_list);
  2321. spin_unlock_irqrestore(&phba->hbalock, flags);
  2322. lpfc_worker_wake_up(phba);
  2323. break;
  2324. case IOSTAT_LOCAL_REJECT:
  2325. case IOSTAT_REMOTE_STOP:
  2326. if (lpfc_cmd->result == IOERR_ELXSEC_KEY_UNWRAP_ERROR ||
  2327. lpfc_cmd->result ==
  2328. IOERR_ELXSEC_KEY_UNWRAP_COMPARE_ERROR ||
  2329. lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
  2330. lpfc_cmd->result ==
  2331. IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
  2332. cmd->result = ScsiResult(DID_NO_CONNECT, 0);
  2333. break;
  2334. }
  2335. if (lpfc_cmd->result == IOERR_INVALID_RPI ||
  2336. lpfc_cmd->result == IOERR_NO_RESOURCES ||
  2337. lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
  2338. lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
  2339. cmd->result = ScsiResult(DID_REQUEUE, 0);
  2340. break;
  2341. }
  2342. if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
  2343. lpfc_cmd->result == IOERR_TX_DMA_FAILED) &&
  2344. pIocbOut->iocb.unsli3.sli3_bg.bgstat) {
  2345. if (scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  2346. /*
  2347. * This is a response for a BG enabled
  2348. * cmd. Parse BG error
  2349. */
  2350. lpfc_parse_bg_err(phba, lpfc_cmd,
  2351. pIocbOut);
  2352. break;
  2353. } else {
  2354. lpfc_printf_vlog(vport, KERN_WARNING,
  2355. LOG_BG,
  2356. "9031 non-zero BGSTAT "
  2357. "on unprotected cmd\n");
  2358. }
  2359. }
  2360. if ((lpfc_cmd->status == IOSTAT_REMOTE_STOP)
  2361. && (phba->sli_rev == LPFC_SLI_REV4)
  2362. && (pnode && NLP_CHK_NODE_ACT(pnode))) {
  2363. /* This IO was aborted by the target, we don't
  2364. * know the rxid and because we did not send the
  2365. * ABTS we cannot generate and RRQ.
  2366. */
  2367. lpfc_set_rrq_active(phba, pnode,
  2368. lpfc_cmd->cur_iocbq.sli4_xritag,
  2369. 0, 0);
  2370. }
  2371. /* else: fall through */
  2372. default:
  2373. cmd->result = ScsiResult(DID_ERROR, 0);
  2374. break;
  2375. }
  2376. if (!pnode || !NLP_CHK_NODE_ACT(pnode)
  2377. || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
  2378. cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
  2379. SAM_STAT_BUSY);
  2380. } else
  2381. cmd->result = ScsiResult(DID_OK, 0);
  2382. if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
  2383. uint32_t *lp = (uint32_t *)cmd->sense_buffer;
  2384. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  2385. "0710 Iodone <%d/%d> cmd %p, error "
  2386. "x%x SNS x%x x%x Data: x%x x%x\n",
  2387. cmd->device->id, cmd->device->lun, cmd,
  2388. cmd->result, *lp, *(lp + 3), cmd->retries,
  2389. scsi_get_resid(cmd));
  2390. }
  2391. lpfc_update_stats(phba, lpfc_cmd);
  2392. result = cmd->result;
  2393. if (vport->cfg_max_scsicmpl_time &&
  2394. time_after(jiffies, lpfc_cmd->start_time +
  2395. msecs_to_jiffies(vport->cfg_max_scsicmpl_time))) {
  2396. spin_lock_irqsave(shost->host_lock, flags);
  2397. if (pnode && NLP_CHK_NODE_ACT(pnode)) {
  2398. if (pnode->cmd_qdepth >
  2399. atomic_read(&pnode->cmd_pending) &&
  2400. (atomic_read(&pnode->cmd_pending) >
  2401. LPFC_MIN_TGT_QDEPTH) &&
  2402. ((cmd->cmnd[0] == READ_10) ||
  2403. (cmd->cmnd[0] == WRITE_10)))
  2404. pnode->cmd_qdepth =
  2405. atomic_read(&pnode->cmd_pending);
  2406. pnode->last_change_time = jiffies;
  2407. }
  2408. spin_unlock_irqrestore(shost->host_lock, flags);
  2409. } else if (pnode && NLP_CHK_NODE_ACT(pnode)) {
  2410. if ((pnode->cmd_qdepth < vport->cfg_tgt_queue_depth) &&
  2411. time_after(jiffies, pnode->last_change_time +
  2412. msecs_to_jiffies(LPFC_TGTQ_INTERVAL))) {
  2413. spin_lock_irqsave(shost->host_lock, flags);
  2414. depth = pnode->cmd_qdepth * LPFC_TGTQ_RAMPUP_PCENT
  2415. / 100;
  2416. depth = depth ? depth : 1;
  2417. pnode->cmd_qdepth += depth;
  2418. if (pnode->cmd_qdepth > vport->cfg_tgt_queue_depth)
  2419. pnode->cmd_qdepth = vport->cfg_tgt_queue_depth;
  2420. pnode->last_change_time = jiffies;
  2421. spin_unlock_irqrestore(shost->host_lock, flags);
  2422. }
  2423. }
  2424. lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
  2425. /* The sdev is not guaranteed to be valid post scsi_done upcall. */
  2426. queue_depth = cmd->device->queue_depth;
  2427. scsi_id = cmd->device->id;
  2428. cmd->scsi_done(cmd);
  2429. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  2430. /*
  2431. * If there is a thread waiting for command completion
  2432. * wake up the thread.
  2433. */
  2434. spin_lock_irqsave(shost->host_lock, flags);
  2435. lpfc_cmd->pCmd = NULL;
  2436. if (lpfc_cmd->waitq)
  2437. wake_up(lpfc_cmd->waitq);
  2438. spin_unlock_irqrestore(shost->host_lock, flags);
  2439. lpfc_release_scsi_buf(phba, lpfc_cmd);
  2440. return;
  2441. }
  2442. if (!result)
  2443. lpfc_rampup_queue_depth(vport, queue_depth);
  2444. /*
  2445. * Check for queue full. If the lun is reporting queue full, then
  2446. * back off the lun queue depth to prevent target overloads.
  2447. */
  2448. if (result == SAM_STAT_TASK_SET_FULL && pnode &&
  2449. NLP_CHK_NODE_ACT(pnode)) {
  2450. shost_for_each_device(tmp_sdev, shost) {
  2451. if (tmp_sdev->id != scsi_id)
  2452. continue;
  2453. depth = scsi_track_queue_full(tmp_sdev,
  2454. tmp_sdev->queue_depth-1);
  2455. if (depth <= 0)
  2456. continue;
  2457. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  2458. "0711 detected queue full - lun queue "
  2459. "depth adjusted to %d.\n", depth);
  2460. lpfc_send_sdev_queuedepth_change_event(phba, vport,
  2461. pnode,
  2462. tmp_sdev->lun,
  2463. depth+1, depth);
  2464. }
  2465. }
  2466. /*
  2467. * If there is a thread waiting for command completion
  2468. * wake up the thread.
  2469. */
  2470. spin_lock_irqsave(shost->host_lock, flags);
  2471. lpfc_cmd->pCmd = NULL;
  2472. if (lpfc_cmd->waitq)
  2473. wake_up(lpfc_cmd->waitq);
  2474. spin_unlock_irqrestore(shost->host_lock, flags);
  2475. lpfc_release_scsi_buf(phba, lpfc_cmd);
  2476. }
  2477. /**
  2478. * lpfc_fcpcmd_to_iocb - copy the fcp_cmd data into the IOCB
  2479. * @data: A pointer to the immediate command data portion of the IOCB.
  2480. * @fcp_cmnd: The FCP Command that is provided by the SCSI layer.
  2481. *
  2482. * The routine copies the entire FCP command from @fcp_cmnd to @data while
  2483. * byte swapping the data to big endian format for transmission on the wire.
  2484. **/
  2485. static void
  2486. lpfc_fcpcmd_to_iocb(uint8_t *data, struct fcp_cmnd *fcp_cmnd)
  2487. {
  2488. int i, j;
  2489. for (i = 0, j = 0; i < sizeof(struct fcp_cmnd);
  2490. i += sizeof(uint32_t), j++) {
  2491. ((uint32_t *)data)[j] = cpu_to_be32(((uint32_t *)fcp_cmnd)[j]);
  2492. }
  2493. }
  2494. /**
  2495. * lpfc_scsi_prep_cmnd - Wrapper func for convert scsi cmnd to FCP info unit
  2496. * @vport: The virtual port for which this call is being executed.
  2497. * @lpfc_cmd: The scsi command which needs to send.
  2498. * @pnode: Pointer to lpfc_nodelist.
  2499. *
  2500. * This routine initializes fcp_cmnd and iocb data structure from scsi command
  2501. * to transfer for device with SLI3 interface spec.
  2502. **/
  2503. static void
  2504. lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
  2505. struct lpfc_nodelist *pnode)
  2506. {
  2507. struct lpfc_hba *phba = vport->phba;
  2508. struct scsi_cmnd *scsi_cmnd = lpfc_cmd->pCmd;
  2509. struct fcp_cmnd *fcp_cmnd = lpfc_cmd->fcp_cmnd;
  2510. IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
  2511. struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
  2512. int datadir = scsi_cmnd->sc_data_direction;
  2513. char tag[2];
  2514. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  2515. return;
  2516. lpfc_cmd->fcp_rsp->rspSnsLen = 0;
  2517. /* clear task management bits */
  2518. lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
  2519. int_to_scsilun(lpfc_cmd->pCmd->device->lun,
  2520. &lpfc_cmd->fcp_cmnd->fcp_lun);
  2521. memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
  2522. if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
  2523. switch (tag[0]) {
  2524. case HEAD_OF_QUEUE_TAG:
  2525. fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
  2526. break;
  2527. case ORDERED_QUEUE_TAG:
  2528. fcp_cmnd->fcpCntl1 = ORDERED_Q;
  2529. break;
  2530. default:
  2531. fcp_cmnd->fcpCntl1 = SIMPLE_Q;
  2532. break;
  2533. }
  2534. } else
  2535. fcp_cmnd->fcpCntl1 = 0;
  2536. /*
  2537. * There are three possibilities here - use scatter-gather segment, use
  2538. * the single mapping, or neither. Start the lpfc command prep by
  2539. * bumping the bpl beyond the fcp_cmnd and fcp_rsp regions to the first
  2540. * data bde entry.
  2541. */
  2542. if (scsi_sg_count(scsi_cmnd)) {
  2543. if (datadir == DMA_TO_DEVICE) {
  2544. iocb_cmd->ulpCommand = CMD_FCP_IWRITE64_CR;
  2545. if (phba->sli_rev < LPFC_SLI_REV4) {
  2546. iocb_cmd->un.fcpi.fcpi_parm = 0;
  2547. iocb_cmd->ulpPU = 0;
  2548. } else
  2549. iocb_cmd->ulpPU = PARM_READ_CHECK;
  2550. fcp_cmnd->fcpCntl3 = WRITE_DATA;
  2551. phba->fc4OutputRequests++;
  2552. } else {
  2553. iocb_cmd->ulpCommand = CMD_FCP_IREAD64_CR;
  2554. iocb_cmd->ulpPU = PARM_READ_CHECK;
  2555. fcp_cmnd->fcpCntl3 = READ_DATA;
  2556. phba->fc4InputRequests++;
  2557. }
  2558. } else {
  2559. iocb_cmd->ulpCommand = CMD_FCP_ICMND64_CR;
  2560. iocb_cmd->un.fcpi.fcpi_parm = 0;
  2561. iocb_cmd->ulpPU = 0;
  2562. fcp_cmnd->fcpCntl3 = 0;
  2563. phba->fc4ControlRequests++;
  2564. }
  2565. if (phba->sli_rev == 3 &&
  2566. !(phba->sli3_options & LPFC_SLI3_BG_ENABLED))
  2567. lpfc_fcpcmd_to_iocb(iocb_cmd->unsli3.fcp_ext.icd, fcp_cmnd);
  2568. /*
  2569. * Finish initializing those IOCB fields that are independent
  2570. * of the scsi_cmnd request_buffer
  2571. */
  2572. piocbq->iocb.ulpContext = pnode->nlp_rpi;
  2573. if (phba->sli_rev == LPFC_SLI_REV4)
  2574. piocbq->iocb.ulpContext =
  2575. phba->sli4_hba.rpi_ids[pnode->nlp_rpi];
  2576. if (pnode->nlp_fcp_info & NLP_FCP_2_DEVICE)
  2577. piocbq->iocb.ulpFCP2Rcvy = 1;
  2578. else
  2579. piocbq->iocb.ulpFCP2Rcvy = 0;
  2580. piocbq->iocb.ulpClass = (pnode->nlp_fcp_info & 0x0f);
  2581. piocbq->context1 = lpfc_cmd;
  2582. piocbq->iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
  2583. piocbq->iocb.ulpTimeout = lpfc_cmd->timeout;
  2584. piocbq->vport = vport;
  2585. }
  2586. /**
  2587. * lpfc_scsi_prep_task_mgmt_cmd - Convert SLI3 scsi TM cmd to FCP info unit
  2588. * @vport: The virtual port for which this call is being executed.
  2589. * @lpfc_cmd: Pointer to lpfc_scsi_buf data structure.
  2590. * @lun: Logical unit number.
  2591. * @task_mgmt_cmd: SCSI task management command.
  2592. *
  2593. * This routine creates FCP information unit corresponding to @task_mgmt_cmd
  2594. * for device with SLI-3 interface spec.
  2595. *
  2596. * Return codes:
  2597. * 0 - Error
  2598. * 1 - Success
  2599. **/
  2600. static int
  2601. lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_vport *vport,
  2602. struct lpfc_scsi_buf *lpfc_cmd,
  2603. unsigned int lun,
  2604. uint8_t task_mgmt_cmd)
  2605. {
  2606. struct lpfc_iocbq *piocbq;
  2607. IOCB_t *piocb;
  2608. struct fcp_cmnd *fcp_cmnd;
  2609. struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
  2610. struct lpfc_nodelist *ndlp = rdata->pnode;
  2611. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) ||
  2612. ndlp->nlp_state != NLP_STE_MAPPED_NODE)
  2613. return 0;
  2614. piocbq = &(lpfc_cmd->cur_iocbq);
  2615. piocbq->vport = vport;
  2616. piocb = &piocbq->iocb;
  2617. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  2618. /* Clear out any old data in the FCP command area */
  2619. memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
  2620. int_to_scsilun(lun, &fcp_cmnd->fcp_lun);
  2621. fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
  2622. if (vport->phba->sli_rev == 3 &&
  2623. !(vport->phba->sli3_options & LPFC_SLI3_BG_ENABLED))
  2624. lpfc_fcpcmd_to_iocb(piocb->unsli3.fcp_ext.icd, fcp_cmnd);
  2625. piocb->ulpCommand = CMD_FCP_ICMND64_CR;
  2626. piocb->ulpContext = ndlp->nlp_rpi;
  2627. if (vport->phba->sli_rev == LPFC_SLI_REV4) {
  2628. piocb->ulpContext =
  2629. vport->phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  2630. }
  2631. if (ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
  2632. piocb->ulpFCP2Rcvy = 1;
  2633. }
  2634. piocb->ulpClass = (ndlp->nlp_fcp_info & 0x0f);
  2635. /* ulpTimeout is only one byte */
  2636. if (lpfc_cmd->timeout > 0xff) {
  2637. /*
  2638. * Do not timeout the command at the firmware level.
  2639. * The driver will provide the timeout mechanism.
  2640. */
  2641. piocb->ulpTimeout = 0;
  2642. } else
  2643. piocb->ulpTimeout = lpfc_cmd->timeout;
  2644. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  2645. lpfc_sli4_set_rsp_sgl_last(vport->phba, lpfc_cmd);
  2646. return 1;
  2647. }
  2648. /**
  2649. * lpfc_scsi_api_table_setup - Set up scsi api function jump table
  2650. * @phba: The hba struct for which this call is being executed.
  2651. * @dev_grp: The HBA PCI-Device group number.
  2652. *
  2653. * This routine sets up the SCSI interface API function jump table in @phba
  2654. * struct.
  2655. * Returns: 0 - success, -ENODEV - failure.
  2656. **/
  2657. int
  2658. lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  2659. {
  2660. phba->lpfc_scsi_unprep_dma_buf = lpfc_scsi_unprep_dma_buf;
  2661. phba->lpfc_scsi_prep_cmnd = lpfc_scsi_prep_cmnd;
  2662. switch (dev_grp) {
  2663. case LPFC_PCI_DEV_LP:
  2664. phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s3;
  2665. phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s3;
  2666. phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s3;
  2667. phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s3;
  2668. break;
  2669. case LPFC_PCI_DEV_OC:
  2670. phba->lpfc_new_scsi_buf = lpfc_new_scsi_buf_s4;
  2671. phba->lpfc_scsi_prep_dma_buf = lpfc_scsi_prep_dma_buf_s4;
  2672. phba->lpfc_release_scsi_buf = lpfc_release_scsi_buf_s4;
  2673. phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf_s4;
  2674. break;
  2675. default:
  2676. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2677. "1418 Invalid HBA PCI-device group: 0x%x\n",
  2678. dev_grp);
  2679. return -ENODEV;
  2680. break;
  2681. }
  2682. phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
  2683. phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
  2684. return 0;
  2685. }
  2686. /**
  2687. * lpfc_taskmgmt_def_cmpl - IOCB completion routine for task management command
  2688. * @phba: The Hba for which this call is being executed.
  2689. * @cmdiocbq: Pointer to lpfc_iocbq data structure.
  2690. * @rspiocbq: Pointer to lpfc_iocbq data structure.
  2691. *
  2692. * This routine is IOCB completion routine for device reset and target reset
  2693. * routine. This routine release scsi buffer associated with lpfc_cmd.
  2694. **/
  2695. static void
  2696. lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
  2697. struct lpfc_iocbq *cmdiocbq,
  2698. struct lpfc_iocbq *rspiocbq)
  2699. {
  2700. struct lpfc_scsi_buf *lpfc_cmd =
  2701. (struct lpfc_scsi_buf *) cmdiocbq->context1;
  2702. if (lpfc_cmd)
  2703. lpfc_release_scsi_buf(phba, lpfc_cmd);
  2704. return;
  2705. }
  2706. /**
  2707. * lpfc_info - Info entry point of scsi_host_template data structure
  2708. * @host: The scsi host for which this call is being executed.
  2709. *
  2710. * This routine provides module information about hba.
  2711. *
  2712. * Reutrn code:
  2713. * Pointer to char - Success.
  2714. **/
  2715. const char *
  2716. lpfc_info(struct Scsi_Host *host)
  2717. {
  2718. struct lpfc_vport *vport = (struct lpfc_vport *) host->hostdata;
  2719. struct lpfc_hba *phba = vport->phba;
  2720. int len;
  2721. static char lpfcinfobuf[384];
  2722. memset(lpfcinfobuf,0,384);
  2723. if (phba && phba->pcidev){
  2724. strncpy(lpfcinfobuf, phba->ModelDesc, 256);
  2725. len = strlen(lpfcinfobuf);
  2726. snprintf(lpfcinfobuf + len,
  2727. 384-len,
  2728. " on PCI bus %02x device %02x irq %d",
  2729. phba->pcidev->bus->number,
  2730. phba->pcidev->devfn,
  2731. phba->pcidev->irq);
  2732. len = strlen(lpfcinfobuf);
  2733. if (phba->Port[0]) {
  2734. snprintf(lpfcinfobuf + len,
  2735. 384-len,
  2736. " port %s",
  2737. phba->Port);
  2738. }
  2739. len = strlen(lpfcinfobuf);
  2740. if (phba->sli4_hba.link_state.logical_speed) {
  2741. snprintf(lpfcinfobuf + len,
  2742. 384-len,
  2743. " Logical Link Speed: %d Mbps",
  2744. phba->sli4_hba.link_state.logical_speed * 10);
  2745. }
  2746. }
  2747. return lpfcinfobuf;
  2748. }
  2749. /**
  2750. * lpfc_poll_rearm_time - Routine to modify fcp_poll timer of hba
  2751. * @phba: The Hba for which this call is being executed.
  2752. *
  2753. * This routine modifies fcp_poll_timer field of @phba by cfg_poll_tmo.
  2754. * The default value of cfg_poll_tmo is 10 milliseconds.
  2755. **/
  2756. static __inline__ void lpfc_poll_rearm_timer(struct lpfc_hba * phba)
  2757. {
  2758. unsigned long poll_tmo_expires =
  2759. (jiffies + msecs_to_jiffies(phba->cfg_poll_tmo));
  2760. if (phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt)
  2761. mod_timer(&phba->fcp_poll_timer,
  2762. poll_tmo_expires);
  2763. }
  2764. /**
  2765. * lpfc_poll_start_timer - Routine to start fcp_poll_timer of HBA
  2766. * @phba: The Hba for which this call is being executed.
  2767. *
  2768. * This routine starts the fcp_poll_timer of @phba.
  2769. **/
  2770. void lpfc_poll_start_timer(struct lpfc_hba * phba)
  2771. {
  2772. lpfc_poll_rearm_timer(phba);
  2773. }
  2774. /**
  2775. * lpfc_poll_timeout - Restart polling timer
  2776. * @ptr: Map to lpfc_hba data structure pointer.
  2777. *
  2778. * This routine restarts fcp_poll timer, when FCP ring polling is enable
  2779. * and FCP Ring interrupt is disable.
  2780. **/
  2781. void lpfc_poll_timeout(unsigned long ptr)
  2782. {
  2783. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  2784. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  2785. lpfc_sli_handle_fast_ring_event(phba,
  2786. &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
  2787. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  2788. lpfc_poll_rearm_timer(phba);
  2789. }
  2790. }
  2791. /**
  2792. * lpfc_queuecommand - scsi_host_template queuecommand entry point
  2793. * @cmnd: Pointer to scsi_cmnd data structure.
  2794. * @done: Pointer to done routine.
  2795. *
  2796. * Driver registers this routine to scsi midlayer to submit a @cmd to process.
  2797. * This routine prepares an IOCB from scsi command and provides to firmware.
  2798. * The @done callback is invoked after driver finished processing the command.
  2799. *
  2800. * Return value :
  2801. * 0 - Success
  2802. * SCSI_MLQUEUE_HOST_BUSY - Block all devices served by this host temporarily.
  2803. **/
  2804. static int
  2805. lpfc_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
  2806. {
  2807. struct Scsi_Host *shost = cmnd->device->host;
  2808. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2809. struct lpfc_hba *phba = vport->phba;
  2810. struct lpfc_rport_data *rdata = cmnd->device->hostdata;
  2811. struct lpfc_nodelist *ndlp;
  2812. struct lpfc_scsi_buf *lpfc_cmd;
  2813. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  2814. int err;
  2815. err = fc_remote_port_chkready(rport);
  2816. if (err) {
  2817. cmnd->result = err;
  2818. goto out_fail_command;
  2819. }
  2820. ndlp = rdata->pnode;
  2821. if (!(phba->sli3_options & LPFC_SLI3_BG_ENABLED) &&
  2822. scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
  2823. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  2824. "9058 BLKGRD: ERROR: rcvd protected cmd:%02x"
  2825. " op:%02x str=%s without registering for"
  2826. " BlockGuard - Rejecting command\n",
  2827. cmnd->cmnd[0], scsi_get_prot_op(cmnd),
  2828. dif_op_str[scsi_get_prot_op(cmnd)]);
  2829. goto out_fail_command;
  2830. }
  2831. /*
  2832. * Catch race where our node has transitioned, but the
  2833. * transport is still transitioning.
  2834. */
  2835. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  2836. cmnd->result = ScsiResult(DID_IMM_RETRY, 0);
  2837. goto out_fail_command;
  2838. }
  2839. if (atomic_read(&ndlp->cmd_pending) >= ndlp->cmd_qdepth)
  2840. goto out_tgt_busy;
  2841. lpfc_cmd = lpfc_get_scsi_buf(phba, ndlp);
  2842. if (lpfc_cmd == NULL) {
  2843. lpfc_rampdown_queue_depth(phba);
  2844. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  2845. "0707 driver's buffer pool is empty, "
  2846. "IO busied\n");
  2847. goto out_host_busy;
  2848. }
  2849. /*
  2850. * Store the midlayer's command structure for the completion phase
  2851. * and complete the command initialization.
  2852. */
  2853. lpfc_cmd->pCmd = cmnd;
  2854. lpfc_cmd->rdata = rdata;
  2855. lpfc_cmd->timeout = 0;
  2856. lpfc_cmd->start_time = jiffies;
  2857. cmnd->host_scribble = (unsigned char *)lpfc_cmd;
  2858. cmnd->scsi_done = done;
  2859. if (scsi_get_prot_op(cmnd) != SCSI_PROT_NORMAL) {
  2860. if (vport->phba->cfg_enable_bg) {
  2861. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2862. "9033 BLKGRD: rcvd protected cmd:%02x op:%02x "
  2863. "str=%s\n",
  2864. cmnd->cmnd[0], scsi_get_prot_op(cmnd),
  2865. dif_op_str[scsi_get_prot_op(cmnd)]);
  2866. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2867. "9034 BLKGRD: CDB: %02x %02x %02x %02x %02x "
  2868. "%02x %02x %02x %02x %02x\n",
  2869. cmnd->cmnd[0], cmnd->cmnd[1], cmnd->cmnd[2],
  2870. cmnd->cmnd[3], cmnd->cmnd[4], cmnd->cmnd[5],
  2871. cmnd->cmnd[6], cmnd->cmnd[7], cmnd->cmnd[8],
  2872. cmnd->cmnd[9]);
  2873. if (cmnd->cmnd[0] == READ_10)
  2874. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2875. "9035 BLKGRD: READ @ sector %llu, "
  2876. "count %u\n",
  2877. (unsigned long long)scsi_get_lba(cmnd),
  2878. blk_rq_sectors(cmnd->request));
  2879. else if (cmnd->cmnd[0] == WRITE_10)
  2880. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2881. "9036 BLKGRD: WRITE @ sector %llu, "
  2882. "count %u cmd=%p\n",
  2883. (unsigned long long)scsi_get_lba(cmnd),
  2884. blk_rq_sectors(cmnd->request),
  2885. cmnd);
  2886. }
  2887. err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
  2888. } else {
  2889. if (vport->phba->cfg_enable_bg) {
  2890. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2891. "9038 BLKGRD: rcvd unprotected cmd:"
  2892. "%02x op:%02x str=%s\n",
  2893. cmnd->cmnd[0], scsi_get_prot_op(cmnd),
  2894. dif_op_str[scsi_get_prot_op(cmnd)]);
  2895. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2896. "9039 BLKGRD: CDB: %02x %02x %02x "
  2897. "%02x %02x %02x %02x %02x %02x %02x\n",
  2898. cmnd->cmnd[0], cmnd->cmnd[1],
  2899. cmnd->cmnd[2], cmnd->cmnd[3],
  2900. cmnd->cmnd[4], cmnd->cmnd[5],
  2901. cmnd->cmnd[6], cmnd->cmnd[7],
  2902. cmnd->cmnd[8], cmnd->cmnd[9]);
  2903. if (cmnd->cmnd[0] == READ_10)
  2904. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2905. "9040 dbg: READ @ sector %llu, "
  2906. "count %u\n",
  2907. (unsigned long long)scsi_get_lba(cmnd),
  2908. blk_rq_sectors(cmnd->request));
  2909. else if (cmnd->cmnd[0] == WRITE_10)
  2910. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2911. "9041 dbg: WRITE @ sector %llu, "
  2912. "count %u cmd=%p\n",
  2913. (unsigned long long)scsi_get_lba(cmnd),
  2914. blk_rq_sectors(cmnd->request), cmnd);
  2915. else
  2916. lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
  2917. "9042 dbg: parser not implemented\n");
  2918. }
  2919. err = lpfc_scsi_prep_dma_buf(phba, lpfc_cmd);
  2920. }
  2921. if (err)
  2922. goto out_host_busy_free_buf;
  2923. lpfc_scsi_prep_cmnd(vport, lpfc_cmd, ndlp);
  2924. atomic_inc(&ndlp->cmd_pending);
  2925. err = lpfc_sli_issue_iocb(phba, LPFC_FCP_RING,
  2926. &lpfc_cmd->cur_iocbq, SLI_IOCB_RET_IOCB);
  2927. if (err) {
  2928. atomic_dec(&ndlp->cmd_pending);
  2929. goto out_host_busy_free_buf;
  2930. }
  2931. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  2932. spin_unlock(shost->host_lock);
  2933. lpfc_sli_handle_fast_ring_event(phba,
  2934. &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
  2935. spin_lock(shost->host_lock);
  2936. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  2937. lpfc_poll_rearm_timer(phba);
  2938. }
  2939. return 0;
  2940. out_host_busy_free_buf:
  2941. lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
  2942. lpfc_release_scsi_buf(phba, lpfc_cmd);
  2943. out_host_busy:
  2944. return SCSI_MLQUEUE_HOST_BUSY;
  2945. out_tgt_busy:
  2946. return SCSI_MLQUEUE_TARGET_BUSY;
  2947. out_fail_command:
  2948. done(cmnd);
  2949. return 0;
  2950. }
  2951. static DEF_SCSI_QCMD(lpfc_queuecommand)
  2952. /**
  2953. * lpfc_abort_handler - scsi_host_template eh_abort_handler entry point
  2954. * @cmnd: Pointer to scsi_cmnd data structure.
  2955. *
  2956. * This routine aborts @cmnd pending in base driver.
  2957. *
  2958. * Return code :
  2959. * 0x2003 - Error
  2960. * 0x2002 - Success
  2961. **/
  2962. static int
  2963. lpfc_abort_handler(struct scsi_cmnd *cmnd)
  2964. {
  2965. struct Scsi_Host *shost = cmnd->device->host;
  2966. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2967. struct lpfc_hba *phba = vport->phba;
  2968. struct lpfc_iocbq *iocb;
  2969. struct lpfc_iocbq *abtsiocb;
  2970. struct lpfc_scsi_buf *lpfc_cmd;
  2971. IOCB_t *cmd, *icmd;
  2972. int ret = SUCCESS;
  2973. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waitq);
  2974. ret = fc_block_scsi_eh(cmnd);
  2975. if (ret)
  2976. return ret;
  2977. lpfc_cmd = (struct lpfc_scsi_buf *)cmnd->host_scribble;
  2978. if (!lpfc_cmd) {
  2979. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  2980. "2873 SCSI Layer I/O Abort Request IO CMPL Status "
  2981. "x%x ID %d LUN %d\n",
  2982. ret, cmnd->device->id, cmnd->device->lun);
  2983. return SUCCESS;
  2984. }
  2985. /*
  2986. * If pCmd field of the corresponding lpfc_scsi_buf structure
  2987. * points to a different SCSI command, then the driver has
  2988. * already completed this command, but the midlayer did not
  2989. * see the completion before the eh fired. Just return
  2990. * SUCCESS.
  2991. */
  2992. iocb = &lpfc_cmd->cur_iocbq;
  2993. if (lpfc_cmd->pCmd != cmnd)
  2994. goto out;
  2995. BUG_ON(iocb->context1 != lpfc_cmd);
  2996. abtsiocb = lpfc_sli_get_iocbq(phba);
  2997. if (abtsiocb == NULL) {
  2998. ret = FAILED;
  2999. goto out;
  3000. }
  3001. /*
  3002. * The scsi command can not be in txq and it is in flight because the
  3003. * pCmd is still pointig at the SCSI command we have to abort. There
  3004. * is no need to search the txcmplq. Just send an abort to the FW.
  3005. */
  3006. cmd = &iocb->iocb;
  3007. icmd = &abtsiocb->iocb;
  3008. icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
  3009. icmd->un.acxri.abortContextTag = cmd->ulpContext;
  3010. if (phba->sli_rev == LPFC_SLI_REV4)
  3011. icmd->un.acxri.abortIoTag = iocb->sli4_xritag;
  3012. else
  3013. icmd->un.acxri.abortIoTag = cmd->ulpIoTag;
  3014. icmd->ulpLe = 1;
  3015. icmd->ulpClass = cmd->ulpClass;
  3016. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  3017. abtsiocb->fcp_wqidx = iocb->fcp_wqidx;
  3018. abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
  3019. if (lpfc_is_link_up(phba))
  3020. icmd->ulpCommand = CMD_ABORT_XRI_CN;
  3021. else
  3022. icmd->ulpCommand = CMD_CLOSE_XRI_CN;
  3023. abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
  3024. abtsiocb->vport = vport;
  3025. if (lpfc_sli_issue_iocb(phba, LPFC_FCP_RING, abtsiocb, 0) ==
  3026. IOCB_ERROR) {
  3027. lpfc_sli_release_iocbq(phba, abtsiocb);
  3028. ret = FAILED;
  3029. goto out;
  3030. }
  3031. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  3032. lpfc_sli_handle_fast_ring_event(phba,
  3033. &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
  3034. lpfc_cmd->waitq = &waitq;
  3035. /* Wait for abort to complete */
  3036. wait_event_timeout(waitq,
  3037. (lpfc_cmd->pCmd != cmnd),
  3038. (2*vport->cfg_devloss_tmo*HZ));
  3039. spin_lock_irq(shost->host_lock);
  3040. lpfc_cmd->waitq = NULL;
  3041. spin_unlock_irq(shost->host_lock);
  3042. if (lpfc_cmd->pCmd == cmnd) {
  3043. ret = FAILED;
  3044. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3045. "0748 abort handler timed out waiting "
  3046. "for abort to complete: ret %#x, ID %d, "
  3047. "LUN %d\n",
  3048. ret, cmnd->device->id, cmnd->device->lun);
  3049. }
  3050. out:
  3051. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  3052. "0749 SCSI Layer I/O Abort Request Status x%x ID %d "
  3053. "LUN %d\n", ret, cmnd->device->id,
  3054. cmnd->device->lun);
  3055. return ret;
  3056. }
  3057. static char *
  3058. lpfc_taskmgmt_name(uint8_t task_mgmt_cmd)
  3059. {
  3060. switch (task_mgmt_cmd) {
  3061. case FCP_ABORT_TASK_SET:
  3062. return "ABORT_TASK_SET";
  3063. case FCP_CLEAR_TASK_SET:
  3064. return "FCP_CLEAR_TASK_SET";
  3065. case FCP_BUS_RESET:
  3066. return "FCP_BUS_RESET";
  3067. case FCP_LUN_RESET:
  3068. return "FCP_LUN_RESET";
  3069. case FCP_TARGET_RESET:
  3070. return "FCP_TARGET_RESET";
  3071. case FCP_CLEAR_ACA:
  3072. return "FCP_CLEAR_ACA";
  3073. case FCP_TERMINATE_TASK:
  3074. return "FCP_TERMINATE_TASK";
  3075. default:
  3076. return "unknown";
  3077. }
  3078. }
  3079. /**
  3080. * lpfc_send_taskmgmt - Generic SCSI Task Mgmt Handler
  3081. * @vport: The virtual port for which this call is being executed.
  3082. * @rdata: Pointer to remote port local data
  3083. * @tgt_id: Target ID of remote device.
  3084. * @lun_id: Lun number for the TMF
  3085. * @task_mgmt_cmd: type of TMF to send
  3086. *
  3087. * This routine builds and sends a TMF (SCSI Task Mgmt Function) to
  3088. * a remote port.
  3089. *
  3090. * Return Code:
  3091. * 0x2003 - Error
  3092. * 0x2002 - Success.
  3093. **/
  3094. static int
  3095. lpfc_send_taskmgmt(struct lpfc_vport *vport, struct lpfc_rport_data *rdata,
  3096. unsigned tgt_id, unsigned int lun_id,
  3097. uint8_t task_mgmt_cmd)
  3098. {
  3099. struct lpfc_hba *phba = vport->phba;
  3100. struct lpfc_scsi_buf *lpfc_cmd;
  3101. struct lpfc_iocbq *iocbq;
  3102. struct lpfc_iocbq *iocbqrsp;
  3103. struct lpfc_nodelist *pnode = rdata->pnode;
  3104. int ret;
  3105. int status;
  3106. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  3107. return FAILED;
  3108. lpfc_cmd = lpfc_get_scsi_buf(phba, rdata->pnode);
  3109. if (lpfc_cmd == NULL)
  3110. return FAILED;
  3111. lpfc_cmd->timeout = 60;
  3112. lpfc_cmd->rdata = rdata;
  3113. status = lpfc_scsi_prep_task_mgmt_cmd(vport, lpfc_cmd, lun_id,
  3114. task_mgmt_cmd);
  3115. if (!status) {
  3116. lpfc_release_scsi_buf(phba, lpfc_cmd);
  3117. return FAILED;
  3118. }
  3119. iocbq = &lpfc_cmd->cur_iocbq;
  3120. iocbqrsp = lpfc_sli_get_iocbq(phba);
  3121. if (iocbqrsp == NULL) {
  3122. lpfc_release_scsi_buf(phba, lpfc_cmd);
  3123. return FAILED;
  3124. }
  3125. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  3126. "0702 Issue %s to TGT %d LUN %d "
  3127. "rpi x%x nlp_flag x%x Data: x%x x%x\n",
  3128. lpfc_taskmgmt_name(task_mgmt_cmd), tgt_id, lun_id,
  3129. pnode->nlp_rpi, pnode->nlp_flag, iocbq->sli4_xritag,
  3130. iocbq->iocb_flag);
  3131. status = lpfc_sli_issue_iocb_wait(phba, LPFC_FCP_RING,
  3132. iocbq, iocbqrsp, lpfc_cmd->timeout);
  3133. if (status != IOCB_SUCCESS) {
  3134. if (status == IOCB_TIMEDOUT) {
  3135. iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
  3136. ret = TIMEOUT_ERROR;
  3137. } else
  3138. ret = FAILED;
  3139. lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
  3140. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3141. "0727 TMF %s to TGT %d LUN %d failed (%d, %d) "
  3142. "iocb_flag x%x\n",
  3143. lpfc_taskmgmt_name(task_mgmt_cmd),
  3144. tgt_id, lun_id, iocbqrsp->iocb.ulpStatus,
  3145. iocbqrsp->iocb.un.ulpWord[4],
  3146. iocbq->iocb_flag);
  3147. } else if (status == IOCB_BUSY)
  3148. ret = FAILED;
  3149. else
  3150. ret = SUCCESS;
  3151. lpfc_sli_release_iocbq(phba, iocbqrsp);
  3152. if (ret != TIMEOUT_ERROR)
  3153. lpfc_release_scsi_buf(phba, lpfc_cmd);
  3154. return ret;
  3155. }
  3156. /**
  3157. * lpfc_chk_tgt_mapped -
  3158. * @vport: The virtual port to check on
  3159. * @cmnd: Pointer to scsi_cmnd data structure.
  3160. *
  3161. * This routine delays until the scsi target (aka rport) for the
  3162. * command exists (is present and logged in) or we declare it non-existent.
  3163. *
  3164. * Return code :
  3165. * 0x2003 - Error
  3166. * 0x2002 - Success
  3167. **/
  3168. static int
  3169. lpfc_chk_tgt_mapped(struct lpfc_vport *vport, struct scsi_cmnd *cmnd)
  3170. {
  3171. struct lpfc_rport_data *rdata = cmnd->device->hostdata;
  3172. struct lpfc_nodelist *pnode;
  3173. unsigned long later;
  3174. if (!rdata) {
  3175. lpfc_printf_vlog(vport, KERN_INFO, LOG_FCP,
  3176. "0797 Tgt Map rport failure: rdata x%p\n", rdata);
  3177. return FAILED;
  3178. }
  3179. pnode = rdata->pnode;
  3180. /*
  3181. * If target is not in a MAPPED state, delay until
  3182. * target is rediscovered or devloss timeout expires.
  3183. */
  3184. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  3185. while (time_after(later, jiffies)) {
  3186. if (!pnode || !NLP_CHK_NODE_ACT(pnode))
  3187. return FAILED;
  3188. if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
  3189. return SUCCESS;
  3190. schedule_timeout_uninterruptible(msecs_to_jiffies(500));
  3191. rdata = cmnd->device->hostdata;
  3192. if (!rdata)
  3193. return FAILED;
  3194. pnode = rdata->pnode;
  3195. }
  3196. if (!pnode || !NLP_CHK_NODE_ACT(pnode) ||
  3197. (pnode->nlp_state != NLP_STE_MAPPED_NODE))
  3198. return FAILED;
  3199. return SUCCESS;
  3200. }
  3201. /**
  3202. * lpfc_reset_flush_io_context -
  3203. * @vport: The virtual port (scsi_host) for the flush context
  3204. * @tgt_id: If aborting by Target contect - specifies the target id
  3205. * @lun_id: If aborting by Lun context - specifies the lun id
  3206. * @context: specifies the context level to flush at.
  3207. *
  3208. * After a reset condition via TMF, we need to flush orphaned i/o
  3209. * contexts from the adapter. This routine aborts any contexts
  3210. * outstanding, then waits for their completions. The wait is
  3211. * bounded by devloss_tmo though.
  3212. *
  3213. * Return code :
  3214. * 0x2003 - Error
  3215. * 0x2002 - Success
  3216. **/
  3217. static int
  3218. lpfc_reset_flush_io_context(struct lpfc_vport *vport, uint16_t tgt_id,
  3219. uint64_t lun_id, lpfc_ctx_cmd context)
  3220. {
  3221. struct lpfc_hba *phba = vport->phba;
  3222. unsigned long later;
  3223. int cnt;
  3224. cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
  3225. if (cnt)
  3226. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  3227. tgt_id, lun_id, context);
  3228. later = msecs_to_jiffies(2 * vport->cfg_devloss_tmo * 1000) + jiffies;
  3229. while (time_after(later, jiffies) && cnt) {
  3230. schedule_timeout_uninterruptible(msecs_to_jiffies(20));
  3231. cnt = lpfc_sli_sum_iocb(vport, tgt_id, lun_id, context);
  3232. }
  3233. if (cnt) {
  3234. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3235. "0724 I/O flush failure for context %s : cnt x%x\n",
  3236. ((context == LPFC_CTX_LUN) ? "LUN" :
  3237. ((context == LPFC_CTX_TGT) ? "TGT" :
  3238. ((context == LPFC_CTX_HOST) ? "HOST" : "Unknown"))),
  3239. cnt);
  3240. return FAILED;
  3241. }
  3242. return SUCCESS;
  3243. }
  3244. /**
  3245. * lpfc_device_reset_handler - scsi_host_template eh_device_reset entry point
  3246. * @cmnd: Pointer to scsi_cmnd data structure.
  3247. *
  3248. * This routine does a device reset by sending a LUN_RESET task management
  3249. * command.
  3250. *
  3251. * Return code :
  3252. * 0x2003 - Error
  3253. * 0x2002 - Success
  3254. **/
  3255. static int
  3256. lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
  3257. {
  3258. struct Scsi_Host *shost = cmnd->device->host;
  3259. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3260. struct lpfc_rport_data *rdata = cmnd->device->hostdata;
  3261. struct lpfc_nodelist *pnode;
  3262. unsigned tgt_id = cmnd->device->id;
  3263. unsigned int lun_id = cmnd->device->lun;
  3264. struct lpfc_scsi_event_header scsi_event;
  3265. int status;
  3266. if (!rdata) {
  3267. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3268. "0798 Device Reset rport failure: rdata x%p\n", rdata);
  3269. return FAILED;
  3270. }
  3271. pnode = rdata->pnode;
  3272. status = fc_block_scsi_eh(cmnd);
  3273. if (status)
  3274. return status;
  3275. status = lpfc_chk_tgt_mapped(vport, cmnd);
  3276. if (status == FAILED) {
  3277. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3278. "0721 Device Reset rport failure: rdata x%p\n", rdata);
  3279. return FAILED;
  3280. }
  3281. scsi_event.event_type = FC_REG_SCSI_EVENT;
  3282. scsi_event.subcategory = LPFC_EVENT_LUNRESET;
  3283. scsi_event.lun = lun_id;
  3284. memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
  3285. memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
  3286. fc_host_post_vendor_event(shost, fc_get_event_number(),
  3287. sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
  3288. status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
  3289. FCP_LUN_RESET);
  3290. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3291. "0713 SCSI layer issued Device Reset (%d, %d) "
  3292. "return x%x\n", tgt_id, lun_id, status);
  3293. /*
  3294. * We have to clean up i/o as : they may be orphaned by the TMF;
  3295. * or if the TMF failed, they may be in an indeterminate state.
  3296. * So, continue on.
  3297. * We will report success if all the i/o aborts successfully.
  3298. */
  3299. status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
  3300. LPFC_CTX_LUN);
  3301. return status;
  3302. }
  3303. /**
  3304. * lpfc_target_reset_handler - scsi_host_template eh_target_reset entry point
  3305. * @cmnd: Pointer to scsi_cmnd data structure.
  3306. *
  3307. * This routine does a target reset by sending a TARGET_RESET task management
  3308. * command.
  3309. *
  3310. * Return code :
  3311. * 0x2003 - Error
  3312. * 0x2002 - Success
  3313. **/
  3314. static int
  3315. lpfc_target_reset_handler(struct scsi_cmnd *cmnd)
  3316. {
  3317. struct Scsi_Host *shost = cmnd->device->host;
  3318. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3319. struct lpfc_rport_data *rdata = cmnd->device->hostdata;
  3320. struct lpfc_nodelist *pnode;
  3321. unsigned tgt_id = cmnd->device->id;
  3322. unsigned int lun_id = cmnd->device->lun;
  3323. struct lpfc_scsi_event_header scsi_event;
  3324. int status;
  3325. if (!rdata) {
  3326. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3327. "0799 Target Reset rport failure: rdata x%p\n", rdata);
  3328. return FAILED;
  3329. }
  3330. pnode = rdata->pnode;
  3331. status = fc_block_scsi_eh(cmnd);
  3332. if (status)
  3333. return status;
  3334. status = lpfc_chk_tgt_mapped(vport, cmnd);
  3335. if (status == FAILED) {
  3336. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3337. "0722 Target Reset rport failure: rdata x%p\n", rdata);
  3338. return FAILED;
  3339. }
  3340. scsi_event.event_type = FC_REG_SCSI_EVENT;
  3341. scsi_event.subcategory = LPFC_EVENT_TGTRESET;
  3342. scsi_event.lun = 0;
  3343. memcpy(scsi_event.wwpn, &pnode->nlp_portname, sizeof(struct lpfc_name));
  3344. memcpy(scsi_event.wwnn, &pnode->nlp_nodename, sizeof(struct lpfc_name));
  3345. fc_host_post_vendor_event(shost, fc_get_event_number(),
  3346. sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
  3347. status = lpfc_send_taskmgmt(vport, rdata, tgt_id, lun_id,
  3348. FCP_TARGET_RESET);
  3349. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3350. "0723 SCSI layer issued Target Reset (%d, %d) "
  3351. "return x%x\n", tgt_id, lun_id, status);
  3352. /*
  3353. * We have to clean up i/o as : they may be orphaned by the TMF;
  3354. * or if the TMF failed, they may be in an indeterminate state.
  3355. * So, continue on.
  3356. * We will report success if all the i/o aborts successfully.
  3357. */
  3358. status = lpfc_reset_flush_io_context(vport, tgt_id, lun_id,
  3359. LPFC_CTX_TGT);
  3360. return status;
  3361. }
  3362. /**
  3363. * lpfc_bus_reset_handler - scsi_host_template eh_bus_reset_handler entry point
  3364. * @cmnd: Pointer to scsi_cmnd data structure.
  3365. *
  3366. * This routine does target reset to all targets on @cmnd->device->host.
  3367. * This emulates Parallel SCSI Bus Reset Semantics.
  3368. *
  3369. * Return code :
  3370. * 0x2003 - Error
  3371. * 0x2002 - Success
  3372. **/
  3373. static int
  3374. lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
  3375. {
  3376. struct Scsi_Host *shost = cmnd->device->host;
  3377. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3378. struct lpfc_nodelist *ndlp = NULL;
  3379. struct lpfc_scsi_event_header scsi_event;
  3380. int match;
  3381. int ret = SUCCESS, status, i;
  3382. scsi_event.event_type = FC_REG_SCSI_EVENT;
  3383. scsi_event.subcategory = LPFC_EVENT_BUSRESET;
  3384. scsi_event.lun = 0;
  3385. memcpy(scsi_event.wwpn, &vport->fc_portname, sizeof(struct lpfc_name));
  3386. memcpy(scsi_event.wwnn, &vport->fc_nodename, sizeof(struct lpfc_name));
  3387. fc_host_post_vendor_event(shost, fc_get_event_number(),
  3388. sizeof(scsi_event), (char *)&scsi_event, LPFC_NL_VENDOR_ID);
  3389. ret = fc_block_scsi_eh(cmnd);
  3390. if (ret)
  3391. return ret;
  3392. /*
  3393. * Since the driver manages a single bus device, reset all
  3394. * targets known to the driver. Should any target reset
  3395. * fail, this routine returns failure to the midlayer.
  3396. */
  3397. for (i = 0; i < LPFC_MAX_TARGET; i++) {
  3398. /* Search for mapped node by target ID */
  3399. match = 0;
  3400. spin_lock_irq(shost->host_lock);
  3401. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3402. if (!NLP_CHK_NODE_ACT(ndlp))
  3403. continue;
  3404. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  3405. ndlp->nlp_sid == i &&
  3406. ndlp->rport) {
  3407. match = 1;
  3408. break;
  3409. }
  3410. }
  3411. spin_unlock_irq(shost->host_lock);
  3412. if (!match)
  3413. continue;
  3414. status = lpfc_send_taskmgmt(vport, ndlp->rport->dd_data,
  3415. i, 0, FCP_TARGET_RESET);
  3416. if (status != SUCCESS) {
  3417. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3418. "0700 Bus Reset on target %d failed\n",
  3419. i);
  3420. ret = FAILED;
  3421. }
  3422. }
  3423. /*
  3424. * We have to clean up i/o as : they may be orphaned by the TMFs
  3425. * above; or if any of the TMFs failed, they may be in an
  3426. * indeterminate state.
  3427. * We will report success if all the i/o aborts successfully.
  3428. */
  3429. status = lpfc_reset_flush_io_context(vport, 0, 0, LPFC_CTX_HOST);
  3430. if (status != SUCCESS)
  3431. ret = FAILED;
  3432. lpfc_printf_vlog(vport, KERN_ERR, LOG_FCP,
  3433. "0714 SCSI layer issued Bus Reset Data: x%x\n", ret);
  3434. return ret;
  3435. }
  3436. /**
  3437. * lpfc_slave_alloc - scsi_host_template slave_alloc entry point
  3438. * @sdev: Pointer to scsi_device.
  3439. *
  3440. * This routine populates the cmds_per_lun count + 2 scsi_bufs into this host's
  3441. * globally available list of scsi buffers. This routine also makes sure scsi
  3442. * buffer is not allocated more than HBA limit conveyed to midlayer. This list
  3443. * of scsi buffer exists for the lifetime of the driver.
  3444. *
  3445. * Return codes:
  3446. * non-0 - Error
  3447. * 0 - Success
  3448. **/
  3449. static int
  3450. lpfc_slave_alloc(struct scsi_device *sdev)
  3451. {
  3452. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  3453. struct lpfc_hba *phba = vport->phba;
  3454. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  3455. uint32_t total = 0;
  3456. uint32_t num_to_alloc = 0;
  3457. int num_allocated = 0;
  3458. uint32_t sdev_cnt;
  3459. if (!rport || fc_remote_port_chkready(rport))
  3460. return -ENXIO;
  3461. sdev->hostdata = rport->dd_data;
  3462. sdev_cnt = atomic_inc_return(&phba->sdev_cnt);
  3463. /*
  3464. * Populate the cmds_per_lun count scsi_bufs into this host's globally
  3465. * available list of scsi buffers. Don't allocate more than the
  3466. * HBA limit conveyed to the midlayer via the host structure. The
  3467. * formula accounts for the lun_queue_depth + error handlers + 1
  3468. * extra. This list of scsi bufs exists for the lifetime of the driver.
  3469. */
  3470. total = phba->total_scsi_bufs;
  3471. num_to_alloc = vport->cfg_lun_queue_depth + 2;
  3472. /* If allocated buffers are enough do nothing */
  3473. if ((sdev_cnt * (vport->cfg_lun_queue_depth + 2)) < total)
  3474. return 0;
  3475. /* Allow some exchanges to be available always to complete discovery */
  3476. if (total >= phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
  3477. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  3478. "0704 At limitation of %d preallocated "
  3479. "command buffers\n", total);
  3480. return 0;
  3481. /* Allow some exchanges to be available always to complete discovery */
  3482. } else if (total + num_to_alloc >
  3483. phba->cfg_hba_queue_depth - LPFC_DISC_IOCB_BUFF_COUNT ) {
  3484. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  3485. "0705 Allocation request of %d "
  3486. "command buffers will exceed max of %d. "
  3487. "Reducing allocation request to %d.\n",
  3488. num_to_alloc, phba->cfg_hba_queue_depth,
  3489. (phba->cfg_hba_queue_depth - total));
  3490. num_to_alloc = phba->cfg_hba_queue_depth - total;
  3491. }
  3492. num_allocated = lpfc_new_scsi_buf(vport, num_to_alloc);
  3493. if (num_to_alloc != num_allocated) {
  3494. lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
  3495. "0708 Allocation request of %d "
  3496. "command buffers did not succeed. "
  3497. "Allocated %d buffers.\n",
  3498. num_to_alloc, num_allocated);
  3499. }
  3500. if (num_allocated > 0)
  3501. phba->total_scsi_bufs += num_allocated;
  3502. return 0;
  3503. }
  3504. /**
  3505. * lpfc_slave_configure - scsi_host_template slave_configure entry point
  3506. * @sdev: Pointer to scsi_device.
  3507. *
  3508. * This routine configures following items
  3509. * - Tag command queuing support for @sdev if supported.
  3510. * - Enable SLI polling for fcp ring if ENABLE_FCP_RING_POLLING flag is set.
  3511. *
  3512. * Return codes:
  3513. * 0 - Success
  3514. **/
  3515. static int
  3516. lpfc_slave_configure(struct scsi_device *sdev)
  3517. {
  3518. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  3519. struct lpfc_hba *phba = vport->phba;
  3520. if (sdev->tagged_supported)
  3521. scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
  3522. else
  3523. scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
  3524. if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
  3525. lpfc_sli_handle_fast_ring_event(phba,
  3526. &phba->sli.ring[LPFC_FCP_RING], HA_R0RE_REQ);
  3527. if (phba->cfg_poll & DISABLE_FCP_RING_INT)
  3528. lpfc_poll_rearm_timer(phba);
  3529. }
  3530. return 0;
  3531. }
  3532. /**
  3533. * lpfc_slave_destroy - slave_destroy entry point of SHT data structure
  3534. * @sdev: Pointer to scsi_device.
  3535. *
  3536. * This routine sets @sdev hostatdata filed to null.
  3537. **/
  3538. static void
  3539. lpfc_slave_destroy(struct scsi_device *sdev)
  3540. {
  3541. struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
  3542. struct lpfc_hba *phba = vport->phba;
  3543. atomic_dec(&phba->sdev_cnt);
  3544. sdev->hostdata = NULL;
  3545. return;
  3546. }
  3547. struct scsi_host_template lpfc_template = {
  3548. .module = THIS_MODULE,
  3549. .name = LPFC_DRIVER_NAME,
  3550. .info = lpfc_info,
  3551. .queuecommand = lpfc_queuecommand,
  3552. .eh_abort_handler = lpfc_abort_handler,
  3553. .eh_device_reset_handler = lpfc_device_reset_handler,
  3554. .eh_target_reset_handler = lpfc_target_reset_handler,
  3555. .eh_bus_reset_handler = lpfc_bus_reset_handler,
  3556. .slave_alloc = lpfc_slave_alloc,
  3557. .slave_configure = lpfc_slave_configure,
  3558. .slave_destroy = lpfc_slave_destroy,
  3559. .scan_finished = lpfc_scan_finished,
  3560. .this_id = -1,
  3561. .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
  3562. .cmd_per_lun = LPFC_CMD_PER_LUN,
  3563. .use_clustering = ENABLE_CLUSTERING,
  3564. .shost_attrs = lpfc_hba_attrs,
  3565. .max_sectors = 0xFFFF,
  3566. .vendor_id = LPFC_NL_VENDOR_ID,
  3567. .change_queue_depth = lpfc_change_queue_depth,
  3568. };
  3569. struct scsi_host_template lpfc_vport_template = {
  3570. .module = THIS_MODULE,
  3571. .name = LPFC_DRIVER_NAME,
  3572. .info = lpfc_info,
  3573. .queuecommand = lpfc_queuecommand,
  3574. .eh_abort_handler = lpfc_abort_handler,
  3575. .eh_device_reset_handler = lpfc_device_reset_handler,
  3576. .eh_target_reset_handler = lpfc_target_reset_handler,
  3577. .eh_bus_reset_handler = lpfc_bus_reset_handler,
  3578. .slave_alloc = lpfc_slave_alloc,
  3579. .slave_configure = lpfc_slave_configure,
  3580. .slave_destroy = lpfc_slave_destroy,
  3581. .scan_finished = lpfc_scan_finished,
  3582. .this_id = -1,
  3583. .sg_tablesize = LPFC_DEFAULT_SG_SEG_CNT,
  3584. .cmd_per_lun = LPFC_CMD_PER_LUN,
  3585. .use_clustering = ENABLE_CLUSTERING,
  3586. .shost_attrs = lpfc_vport_attrs,
  3587. .max_sectors = 0xFFFF,
  3588. .change_queue_depth = lpfc_change_queue_depth,
  3589. };