lpfc_scsi.c 149 KB

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