zfcp_fsf.c 151 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859
  1. /*
  2. * This file is part of the zfcp device driver for
  3. * FCP adapters for IBM System z9 and zSeries.
  4. *
  5. * (C) Copyright IBM Corp. 2002, 2006
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include "zfcp_ext.h"
  22. static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
  23. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
  24. static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
  25. static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
  26. static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
  27. static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
  28. static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
  29. static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
  30. static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
  31. static int zfcp_fsf_send_fcp_command_task_management_handler(
  32. struct zfcp_fsf_req *);
  33. static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
  34. static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
  35. static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
  36. static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
  37. static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
  38. static inline int zfcp_fsf_req_sbal_check(
  39. unsigned long *, struct zfcp_qdio_queue *, int);
  40. static inline int zfcp_use_one_sbal(
  41. struct scatterlist *, int, struct scatterlist *, int);
  42. static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
  43. static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
  44. static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
  45. static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
  46. static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
  47. static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *,
  48. struct fsf_link_down_info *);
  49. static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
  50. /* association between FSF command and FSF QTCB type */
  51. static u32 fsf_qtcb_type[] = {
  52. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  53. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  54. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  55. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  56. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  57. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  58. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  59. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  60. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  61. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  62. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  63. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  64. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  65. };
  66. static const char zfcp_act_subtable_type[5][8] = {
  67. "unknown", "OS", "WWPN", "DID", "LUN"
  68. };
  69. /****************************************************************/
  70. /*************** FSF related Functions *************************/
  71. /****************************************************************/
  72. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
  73. /*
  74. * function: zfcp_fsf_req_alloc
  75. *
  76. * purpose: Obtains an fsf_req and potentially a qtcb (for all but
  77. * unsolicited requests) via helper functions
  78. * Does some initial fsf request set-up.
  79. *
  80. * returns: pointer to allocated fsf_req if successfull
  81. * NULL otherwise
  82. *
  83. * locks: none
  84. *
  85. */
  86. static struct zfcp_fsf_req *
  87. zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
  88. {
  89. size_t size;
  90. void *ptr;
  91. struct zfcp_fsf_req *fsf_req = NULL;
  92. if (req_flags & ZFCP_REQ_NO_QTCB)
  93. size = sizeof(struct zfcp_fsf_req);
  94. else
  95. size = sizeof(struct zfcp_fsf_req_pool_element);
  96. if (likely(pool != NULL))
  97. ptr = mempool_alloc(pool, GFP_ATOMIC);
  98. else
  99. ptr = kmalloc(size, GFP_ATOMIC);
  100. if (unlikely(NULL == ptr))
  101. goto out;
  102. memset(ptr, 0, size);
  103. if (req_flags & ZFCP_REQ_NO_QTCB) {
  104. fsf_req = (struct zfcp_fsf_req *) ptr;
  105. } else {
  106. fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
  107. fsf_req->qtcb =
  108. &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
  109. }
  110. fsf_req->pool = pool;
  111. out:
  112. return fsf_req;
  113. }
  114. /*
  115. * function: zfcp_fsf_req_free
  116. *
  117. * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
  118. * returns it into the pool via helper functions.
  119. *
  120. * returns: sod all
  121. *
  122. * locks: none
  123. */
  124. void
  125. zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
  126. {
  127. if (likely(fsf_req->pool != NULL))
  128. mempool_free(fsf_req, fsf_req->pool);
  129. else
  130. kfree(fsf_req);
  131. }
  132. /**
  133. * zfcp_fsf_req_dismiss - dismiss a single fsf request
  134. */
  135. static void zfcp_fsf_req_dismiss(struct zfcp_adapter *adapter,
  136. struct zfcp_fsf_req *fsf_req,
  137. unsigned int counter)
  138. {
  139. u64 dbg_tmp[2];
  140. dbg_tmp[0] = (u64) atomic_read(&adapter->reqs_active);
  141. dbg_tmp[1] = (u64) counter;
  142. debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
  143. list_del(&fsf_req->list);
  144. fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  145. zfcp_fsf_req_complete(fsf_req);
  146. }
  147. /**
  148. * zfcp_fsf_req_dismiss_all - dismiss all remaining fsf requests
  149. */
  150. int zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  151. {
  152. struct zfcp_fsf_req *request, *tmp;
  153. unsigned long flags;
  154. unsigned int i, counter;
  155. spin_lock_irqsave(&adapter->req_list_lock, flags);
  156. atomic_set(&adapter->reqs_active, 0);
  157. for (i=0; i<REQUEST_LIST_SIZE; i++) {
  158. if (list_empty(&adapter->req_list[i]))
  159. continue;
  160. counter = 0;
  161. list_for_each_entry_safe(request, tmp,
  162. &adapter->req_list[i], list) {
  163. zfcp_fsf_req_dismiss(adapter, request, counter);
  164. counter++;
  165. }
  166. }
  167. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  168. return 0;
  169. }
  170. /*
  171. * function: zfcp_fsf_req_complete
  172. *
  173. * purpose: Updates active counts and timers for openfcp-reqs
  174. * May cleanup request after req_eval returns
  175. *
  176. * returns: 0 - success
  177. * !0 - failure
  178. *
  179. * context:
  180. */
  181. int
  182. zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
  183. {
  184. int retval = 0;
  185. int cleanup;
  186. if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  187. ZFCP_LOG_DEBUG("Status read response received\n");
  188. /*
  189. * Note: all cleanup handling is done in the callchain of
  190. * the function call-chain below.
  191. */
  192. zfcp_fsf_status_read_handler(fsf_req);
  193. goto out;
  194. } else
  195. zfcp_fsf_protstatus_eval(fsf_req);
  196. /*
  197. * fsf_req may be deleted due to waking up functions, so
  198. * cleanup is saved here and used later
  199. */
  200. if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  201. cleanup = 1;
  202. else
  203. cleanup = 0;
  204. fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  205. /* cleanup request if requested by initiator */
  206. if (likely(cleanup)) {
  207. ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
  208. /*
  209. * lock must not be held here since it will be
  210. * grabed by the called routine, too
  211. */
  212. zfcp_fsf_req_free(fsf_req);
  213. } else {
  214. /* notify initiator waiting for the requests completion */
  215. ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
  216. /*
  217. * FIXME: Race! We must not access fsf_req here as it might have been
  218. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  219. * flag. It's an improbable case. But, we have the same paranoia for
  220. * the cleanup flag already.
  221. * Might better be handled using complete()?
  222. * (setting the flag and doing wakeup ought to be atomic
  223. * with regard to checking the flag as long as waitqueue is
  224. * part of the to be released structure)
  225. */
  226. wake_up(&fsf_req->completion_wq);
  227. }
  228. out:
  229. return retval;
  230. }
  231. /*
  232. * function: zfcp_fsf_protstatus_eval
  233. *
  234. * purpose: evaluates the QTCB of the finished FSF request
  235. * and initiates appropriate actions
  236. * (usually calling FSF command specific handlers)
  237. *
  238. * returns:
  239. *
  240. * context:
  241. *
  242. * locks:
  243. */
  244. static int
  245. zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
  246. {
  247. int retval = 0;
  248. struct zfcp_adapter *adapter = fsf_req->adapter;
  249. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  250. union fsf_prot_status_qual *prot_status_qual =
  251. &qtcb->prefix.prot_status_qual;
  252. zfcp_hba_dbf_event_fsf_response(fsf_req);
  253. if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  254. ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
  255. (unsigned long) fsf_req);
  256. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  257. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  258. goto skip_protstatus;
  259. }
  260. /* log additional information provided by FSF (if any) */
  261. if (unlikely(qtcb->header.log_length)) {
  262. /* do not trust them ;-) */
  263. if (qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
  264. ZFCP_LOG_NORMAL
  265. ("bug: ULP (FSF logging) log data starts "
  266. "beyond end of packet header. Ignored. "
  267. "(start=%i, size=%li)\n",
  268. qtcb->header.log_start,
  269. sizeof(struct fsf_qtcb));
  270. goto forget_log;
  271. }
  272. if ((size_t) (qtcb->header.log_start + qtcb->header.log_length)
  273. > sizeof(struct fsf_qtcb)) {
  274. ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
  275. "beyond end of packet header. Ignored. "
  276. "(start=%i, length=%i, size=%li)\n",
  277. qtcb->header.log_start,
  278. qtcb->header.log_length,
  279. sizeof(struct fsf_qtcb));
  280. goto forget_log;
  281. }
  282. ZFCP_LOG_TRACE("ULP log data: \n");
  283. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
  284. (char *) qtcb + qtcb->header.log_start,
  285. qtcb->header.log_length);
  286. }
  287. forget_log:
  288. /* evaluate FSF Protocol Status */
  289. switch (qtcb->prefix.prot_status) {
  290. case FSF_PROT_GOOD:
  291. case FSF_PROT_FSF_STATUS_PRESENTED:
  292. break;
  293. case FSF_PROT_QTCB_VERSION_ERROR:
  294. ZFCP_LOG_NORMAL("error: The adapter %s contains "
  295. "microcode of version 0x%x, the device driver "
  296. "only supports 0x%x. Aborting.\n",
  297. zfcp_get_busid_by_adapter(adapter),
  298. prot_status_qual->version_error.fsf_version,
  299. ZFCP_QTCB_VERSION);
  300. zfcp_erp_adapter_shutdown(adapter, 0);
  301. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  302. break;
  303. case FSF_PROT_SEQ_NUMB_ERROR:
  304. ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
  305. "driver (0x%x) and adapter %s (0x%x). "
  306. "Restarting all operations on this adapter.\n",
  307. qtcb->prefix.req_seq_no,
  308. zfcp_get_busid_by_adapter(adapter),
  309. prot_status_qual->sequence_error.exp_req_seq_no);
  310. zfcp_erp_adapter_reopen(adapter, 0);
  311. fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  312. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  313. break;
  314. case FSF_PROT_UNSUPP_QTCB_TYPE:
  315. ZFCP_LOG_NORMAL("error: Packet header type used by the "
  316. "device driver is incompatible with "
  317. "that used on adapter %s. "
  318. "Stopping all operations on this adapter.\n",
  319. zfcp_get_busid_by_adapter(adapter));
  320. zfcp_erp_adapter_shutdown(adapter, 0);
  321. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  322. break;
  323. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  324. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  325. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  326. &(adapter->status));
  327. break;
  328. case FSF_PROT_DUPLICATE_REQUEST_ID:
  329. ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
  330. "to the adapter %s is ambiguous. "
  331. "Stopping all operations on this adapter.\n",
  332. *(unsigned long long*)
  333. (&qtcb->bottom.support.req_handle),
  334. zfcp_get_busid_by_adapter(adapter));
  335. zfcp_erp_adapter_shutdown(adapter, 0);
  336. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  337. break;
  338. case FSF_PROT_LINK_DOWN:
  339. zfcp_fsf_link_down_info_eval(adapter,
  340. &prot_status_qual->link_down_info);
  341. zfcp_erp_adapter_reopen(adapter, 0);
  342. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  343. break;
  344. case FSF_PROT_REEST_QUEUE:
  345. ZFCP_LOG_NORMAL("The local link to adapter with "
  346. "%s was re-plugged. "
  347. "Re-starting operations on this adapter.\n",
  348. zfcp_get_busid_by_adapter(adapter));
  349. /* All ports should be marked as ready to run again */
  350. zfcp_erp_modify_adapter_status(adapter,
  351. ZFCP_STATUS_COMMON_RUNNING,
  352. ZFCP_SET);
  353. zfcp_erp_adapter_reopen(adapter,
  354. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
  355. | ZFCP_STATUS_COMMON_ERP_FAILED);
  356. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  357. break;
  358. case FSF_PROT_ERROR_STATE:
  359. ZFCP_LOG_NORMAL("error: The adapter %s "
  360. "has entered the error state. "
  361. "Restarting all operations on this "
  362. "adapter.\n",
  363. zfcp_get_busid_by_adapter(adapter));
  364. zfcp_erp_adapter_reopen(adapter, 0);
  365. fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  366. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  367. break;
  368. default:
  369. ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
  370. "provided by the adapter %s "
  371. "is not compatible with the device driver. "
  372. "Stopping all operations on this adapter. "
  373. "(debug info 0x%x).\n",
  374. zfcp_get_busid_by_adapter(adapter),
  375. qtcb->prefix.prot_status);
  376. zfcp_erp_adapter_shutdown(adapter, 0);
  377. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  378. }
  379. skip_protstatus:
  380. /*
  381. * always call specific handlers to give them a chance to do
  382. * something meaningful even in error cases
  383. */
  384. zfcp_fsf_fsfstatus_eval(fsf_req);
  385. return retval;
  386. }
  387. /*
  388. * function: zfcp_fsf_fsfstatus_eval
  389. *
  390. * purpose: evaluates FSF status of completed FSF request
  391. * and acts accordingly
  392. *
  393. * returns:
  394. */
  395. static int
  396. zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
  397. {
  398. int retval = 0;
  399. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  400. goto skip_fsfstatus;
  401. }
  402. /* evaluate FSF Status */
  403. switch (fsf_req->qtcb->header.fsf_status) {
  404. case FSF_UNKNOWN_COMMAND:
  405. ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
  406. "not known by the adapter %s "
  407. "Stopping all operations on this adapter. "
  408. "(debug info 0x%x).\n",
  409. zfcp_get_busid_by_adapter(fsf_req->adapter),
  410. fsf_req->qtcb->header.fsf_command);
  411. zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
  412. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  413. break;
  414. case FSF_FCP_RSP_AVAILABLE:
  415. ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
  416. "SCSI stack.\n");
  417. break;
  418. case FSF_ADAPTER_STATUS_AVAILABLE:
  419. zfcp_fsf_fsfstatus_qual_eval(fsf_req);
  420. break;
  421. }
  422. skip_fsfstatus:
  423. /*
  424. * always call specific handlers to give them a chance to do
  425. * something meaningful even in error cases
  426. */
  427. zfcp_fsf_req_dispatch(fsf_req);
  428. return retval;
  429. }
  430. /*
  431. * function: zfcp_fsf_fsfstatus_qual_eval
  432. *
  433. * purpose: evaluates FSF status-qualifier of completed FSF request
  434. * and acts accordingly
  435. *
  436. * returns:
  437. */
  438. static int
  439. zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
  440. {
  441. int retval = 0;
  442. switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  443. case FSF_SQ_FCP_RSP_AVAILABLE:
  444. break;
  445. case FSF_SQ_RETRY_IF_POSSIBLE:
  446. /* The SCSI-stack may now issue retries or escalate */
  447. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  448. break;
  449. case FSF_SQ_COMMAND_ABORTED:
  450. /* Carry the aborted state on to upper layer */
  451. fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  452. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  453. break;
  454. case FSF_SQ_NO_RECOM:
  455. ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
  456. "problem on the adapter %s "
  457. "Stopping all operations on this adapter. ",
  458. zfcp_get_busid_by_adapter(fsf_req->adapter));
  459. zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
  460. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  461. break;
  462. case FSF_SQ_ULP_PROGRAMMING_ERROR:
  463. ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
  464. "(adapter %s)\n",
  465. zfcp_get_busid_by_adapter(fsf_req->adapter));
  466. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  467. break;
  468. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  469. case FSF_SQ_NO_RETRY_POSSIBLE:
  470. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  471. /* dealt with in the respective functions */
  472. break;
  473. default:
  474. ZFCP_LOG_NORMAL("bug: Additional status info could "
  475. "not be interpreted properly.\n");
  476. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
  477. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  478. sizeof (union fsf_status_qual));
  479. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  480. break;
  481. }
  482. return retval;
  483. }
  484. /**
  485. * zfcp_fsf_link_down_info_eval - evaluate link down information block
  486. */
  487. static void
  488. zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
  489. struct fsf_link_down_info *link_down)
  490. {
  491. if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  492. &adapter->status))
  493. return;
  494. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  495. if (link_down == NULL)
  496. goto out;
  497. switch (link_down->error_code) {
  498. case FSF_PSQ_LINK_NO_LIGHT:
  499. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  500. "(no light detected)\n",
  501. zfcp_get_busid_by_adapter(adapter));
  502. break;
  503. case FSF_PSQ_LINK_WRAP_PLUG:
  504. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  505. "(wrap plug detected)\n",
  506. zfcp_get_busid_by_adapter(adapter));
  507. break;
  508. case FSF_PSQ_LINK_NO_FCP:
  509. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  510. "(adjacent node on link does not support FCP)\n",
  511. zfcp_get_busid_by_adapter(adapter));
  512. break;
  513. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  514. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  515. "(firmware update in progress)\n",
  516. zfcp_get_busid_by_adapter(adapter));
  517. break;
  518. case FSF_PSQ_LINK_INVALID_WWPN:
  519. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  520. "(duplicate or invalid WWPN detected)\n",
  521. zfcp_get_busid_by_adapter(adapter));
  522. break;
  523. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  524. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  525. "(no support for NPIV by Fabric)\n",
  526. zfcp_get_busid_by_adapter(adapter));
  527. break;
  528. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  529. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  530. "(out of resource in FCP daughtercard)\n",
  531. zfcp_get_busid_by_adapter(adapter));
  532. break;
  533. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  534. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  535. "(out of resource in Fabric)\n",
  536. zfcp_get_busid_by_adapter(adapter));
  537. break;
  538. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  539. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  540. "(unable to Fabric login)\n",
  541. zfcp_get_busid_by_adapter(adapter));
  542. break;
  543. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  544. ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
  545. zfcp_get_busid_by_adapter(adapter));
  546. break;
  547. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  548. ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
  549. zfcp_get_busid_by_adapter(adapter));
  550. break;
  551. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  552. ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
  553. zfcp_get_busid_by_adapter(adapter));
  554. break;
  555. default:
  556. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  557. "(warning: unknown reason code %d)\n",
  558. zfcp_get_busid_by_adapter(adapter),
  559. link_down->error_code);
  560. }
  561. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  562. ZFCP_LOG_DEBUG("Debug information to link down: "
  563. "primary_status=0x%02x "
  564. "ioerr_code=0x%02x "
  565. "action_code=0x%02x "
  566. "reason_code=0x%02x "
  567. "explanation_code=0x%02x "
  568. "vendor_specific_code=0x%02x\n",
  569. link_down->primary_status,
  570. link_down->ioerr_code,
  571. link_down->action_code,
  572. link_down->reason_code,
  573. link_down->explanation_code,
  574. link_down->vendor_specific_code);
  575. out:
  576. zfcp_erp_adapter_failed(adapter);
  577. }
  578. /*
  579. * function: zfcp_fsf_req_dispatch
  580. *
  581. * purpose: calls the appropriate command specific handler
  582. *
  583. * returns:
  584. */
  585. static int
  586. zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
  587. {
  588. struct zfcp_erp_action *erp_action = fsf_req->erp_action;
  589. struct zfcp_adapter *adapter = fsf_req->adapter;
  590. int retval = 0;
  591. switch (fsf_req->fsf_command) {
  592. case FSF_QTCB_FCP_CMND:
  593. zfcp_fsf_send_fcp_command_handler(fsf_req);
  594. break;
  595. case FSF_QTCB_ABORT_FCP_CMND:
  596. zfcp_fsf_abort_fcp_command_handler(fsf_req);
  597. break;
  598. case FSF_QTCB_SEND_GENERIC:
  599. zfcp_fsf_send_ct_handler(fsf_req);
  600. break;
  601. case FSF_QTCB_OPEN_PORT_WITH_DID:
  602. zfcp_fsf_open_port_handler(fsf_req);
  603. break;
  604. case FSF_QTCB_OPEN_LUN:
  605. zfcp_fsf_open_unit_handler(fsf_req);
  606. break;
  607. case FSF_QTCB_CLOSE_LUN:
  608. zfcp_fsf_close_unit_handler(fsf_req);
  609. break;
  610. case FSF_QTCB_CLOSE_PORT:
  611. zfcp_fsf_close_port_handler(fsf_req);
  612. break;
  613. case FSF_QTCB_CLOSE_PHYSICAL_PORT:
  614. zfcp_fsf_close_physical_port_handler(fsf_req);
  615. break;
  616. case FSF_QTCB_EXCHANGE_CONFIG_DATA:
  617. zfcp_fsf_exchange_config_data_handler(fsf_req);
  618. break;
  619. case FSF_QTCB_EXCHANGE_PORT_DATA:
  620. zfcp_fsf_exchange_port_data_handler(fsf_req);
  621. break;
  622. case FSF_QTCB_SEND_ELS:
  623. zfcp_fsf_send_els_handler(fsf_req);
  624. break;
  625. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  626. zfcp_fsf_control_file_handler(fsf_req);
  627. break;
  628. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  629. zfcp_fsf_control_file_handler(fsf_req);
  630. break;
  631. default:
  632. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  633. ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
  634. "not supported by the adapter %s\n",
  635. zfcp_get_busid_by_adapter(adapter));
  636. if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
  637. ZFCP_LOG_NORMAL
  638. ("bug: Command issued by the device driver differs "
  639. "from the command returned by the adapter %s "
  640. "(debug info 0x%x, 0x%x).\n",
  641. zfcp_get_busid_by_adapter(adapter),
  642. fsf_req->fsf_command,
  643. fsf_req->qtcb->header.fsf_command);
  644. }
  645. if (!erp_action)
  646. return retval;
  647. zfcp_erp_async_handler(erp_action, 0);
  648. return retval;
  649. }
  650. /*
  651. * function: zfcp_fsf_status_read
  652. *
  653. * purpose: initiates a Status Read command at the specified adapter
  654. *
  655. * returns:
  656. */
  657. int
  658. zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
  659. {
  660. struct zfcp_fsf_req *fsf_req;
  661. struct fsf_status_read_buffer *status_buffer;
  662. unsigned long lock_flags;
  663. volatile struct qdio_buffer_element *sbale;
  664. int retval = 0;
  665. /* setup new FSF request */
  666. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  667. req_flags | ZFCP_REQ_NO_QTCB,
  668. adapter->pool.fsf_req_status_read,
  669. &lock_flags, &fsf_req);
  670. if (retval < 0) {
  671. ZFCP_LOG_INFO("error: Could not create unsolicited status "
  672. "buffer for adapter %s.\n",
  673. zfcp_get_busid_by_adapter(adapter));
  674. goto failed_req_create;
  675. }
  676. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  677. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  678. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  679. fsf_req->sbale_curr = 2;
  680. status_buffer =
  681. mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  682. if (!status_buffer) {
  683. ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
  684. goto failed_buf;
  685. }
  686. memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
  687. fsf_req->data = (unsigned long) status_buffer;
  688. /* insert pointer to respective buffer */
  689. sbale = zfcp_qdio_sbale_curr(fsf_req);
  690. sbale->addr = (void *) status_buffer;
  691. sbale->length = sizeof(struct fsf_status_read_buffer);
  692. /* start QDIO request for this FSF request */
  693. retval = zfcp_fsf_req_send(fsf_req, NULL);
  694. if (retval) {
  695. ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
  696. "environment.\n");
  697. goto failed_req_send;
  698. }
  699. ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
  700. zfcp_get_busid_by_adapter(adapter));
  701. goto out;
  702. failed_req_send:
  703. mempool_free(status_buffer, adapter->pool.data_status_read);
  704. failed_buf:
  705. zfcp_fsf_req_free(fsf_req);
  706. failed_req_create:
  707. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  708. out:
  709. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  710. return retval;
  711. }
  712. static int
  713. zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
  714. {
  715. struct fsf_status_read_buffer *status_buffer;
  716. struct zfcp_adapter *adapter;
  717. struct zfcp_port *port;
  718. unsigned long flags;
  719. status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
  720. adapter = fsf_req->adapter;
  721. read_lock_irqsave(&zfcp_data.config_lock, flags);
  722. list_for_each_entry(port, &adapter->port_list_head, list)
  723. if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
  724. break;
  725. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  726. if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
  727. ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
  728. "nonexisting port with d_id 0x%08x on "
  729. "adapter %s. Ignored.\n",
  730. status_buffer->d_id & ZFCP_DID_MASK,
  731. zfcp_get_busid_by_adapter(adapter));
  732. goto out;
  733. }
  734. switch (status_buffer->status_subtype) {
  735. case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
  736. debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
  737. zfcp_erp_port_reopen(port, 0);
  738. break;
  739. case FSF_STATUS_READ_SUB_ERROR_PORT:
  740. debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
  741. zfcp_erp_port_shutdown(port, 0);
  742. break;
  743. default:
  744. debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
  745. debug_exception(adapter->erp_dbf, 0,
  746. &status_buffer->status_subtype, sizeof (u32));
  747. ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
  748. "for a reopen indication on port with "
  749. "d_id 0x%08x on the adapter %s. "
  750. "Ignored. (debug info 0x%x)\n",
  751. status_buffer->d_id,
  752. zfcp_get_busid_by_adapter(adapter),
  753. status_buffer->status_subtype);
  754. }
  755. out:
  756. return 0;
  757. }
  758. /*
  759. * function: zfcp_fsf_status_read_handler
  760. *
  761. * purpose: is called for finished Open Port command
  762. *
  763. * returns:
  764. */
  765. static int
  766. zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
  767. {
  768. int retval = 0;
  769. struct zfcp_adapter *adapter = fsf_req->adapter;
  770. struct fsf_status_read_buffer *status_buffer =
  771. (struct fsf_status_read_buffer *) fsf_req->data;
  772. struct fsf_bit_error_payload *fsf_bit_error;
  773. if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  774. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
  775. mempool_free(status_buffer, adapter->pool.data_status_read);
  776. zfcp_fsf_req_free(fsf_req);
  777. goto out;
  778. }
  779. zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
  780. switch (status_buffer->status_type) {
  781. case FSF_STATUS_READ_PORT_CLOSED:
  782. zfcp_fsf_status_read_port_closed(fsf_req);
  783. break;
  784. case FSF_STATUS_READ_INCOMING_ELS:
  785. zfcp_fsf_incoming_els(fsf_req);
  786. break;
  787. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  788. ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
  789. zfcp_get_busid_by_adapter(adapter));
  790. break;
  791. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  792. fsf_bit_error = (struct fsf_bit_error_payload *)
  793. status_buffer->payload;
  794. ZFCP_LOG_NORMAL("Warning: bit error threshold data "
  795. "received (adapter %s, "
  796. "link failures = %i, loss of sync errors = %i, "
  797. "loss of signal errors = %i, "
  798. "primitive sequence errors = %i, "
  799. "invalid transmission word errors = %i, "
  800. "CRC errors = %i)\n",
  801. zfcp_get_busid_by_adapter(adapter),
  802. fsf_bit_error->link_failure_error_count,
  803. fsf_bit_error->loss_of_sync_error_count,
  804. fsf_bit_error->loss_of_signal_error_count,
  805. fsf_bit_error->primitive_sequence_error_count,
  806. fsf_bit_error->invalid_transmission_word_error_count,
  807. fsf_bit_error->crc_error_count);
  808. ZFCP_LOG_INFO("Additional bit error threshold data "
  809. "(adapter %s, "
  810. "primitive sequence event time-outs = %i, "
  811. "elastic buffer overrun errors = %i, "
  812. "advertised receive buffer-to-buffer credit = %i, "
  813. "current receice buffer-to-buffer credit = %i, "
  814. "advertised transmit buffer-to-buffer credit = %i, "
  815. "current transmit buffer-to-buffer credit = %i)\n",
  816. zfcp_get_busid_by_adapter(adapter),
  817. fsf_bit_error->primitive_sequence_event_timeout_count,
  818. fsf_bit_error->elastic_buffer_overrun_error_count,
  819. fsf_bit_error->advertised_receive_b2b_credit,
  820. fsf_bit_error->current_receive_b2b_credit,
  821. fsf_bit_error->advertised_transmit_b2b_credit,
  822. fsf_bit_error->current_transmit_b2b_credit);
  823. break;
  824. case FSF_STATUS_READ_LINK_DOWN:
  825. switch (status_buffer->status_subtype) {
  826. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  827. ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
  828. zfcp_get_busid_by_adapter(adapter));
  829. zfcp_fsf_link_down_info_eval(adapter,
  830. (struct fsf_link_down_info *)
  831. &status_buffer->payload);
  832. break;
  833. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  834. ZFCP_LOG_INFO("Local link to adapter %s is down "
  835. "due to failed FDISC login\n",
  836. zfcp_get_busid_by_adapter(adapter));
  837. zfcp_fsf_link_down_info_eval(adapter,
  838. (struct fsf_link_down_info *)
  839. &status_buffer->payload);
  840. break;
  841. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  842. ZFCP_LOG_INFO("Local link to adapter %s is down "
  843. "due to firmware update on adapter\n",
  844. zfcp_get_busid_by_adapter(adapter));
  845. zfcp_fsf_link_down_info_eval(adapter, NULL);
  846. break;
  847. default:
  848. ZFCP_LOG_INFO("Local link to adapter %s is down "
  849. "due to unknown reason\n",
  850. zfcp_get_busid_by_adapter(adapter));
  851. zfcp_fsf_link_down_info_eval(adapter, NULL);
  852. };
  853. break;
  854. case FSF_STATUS_READ_LINK_UP:
  855. ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
  856. "Restarting operations on this adapter\n",
  857. zfcp_get_busid_by_adapter(adapter));
  858. /* All ports should be marked as ready to run again */
  859. zfcp_erp_modify_adapter_status(adapter,
  860. ZFCP_STATUS_COMMON_RUNNING,
  861. ZFCP_SET);
  862. zfcp_erp_adapter_reopen(adapter,
  863. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
  864. | ZFCP_STATUS_COMMON_ERP_FAILED);
  865. break;
  866. case FSF_STATUS_READ_NOTIFICATION_LOST:
  867. ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
  868. "adapter %s%s%s%s%s%s%s%s%s\n",
  869. zfcp_get_busid_by_adapter(adapter),
  870. (status_buffer->status_subtype &
  871. FSF_STATUS_READ_SUB_INCOMING_ELS) ?
  872. ", incoming ELS" : "",
  873. (status_buffer->status_subtype &
  874. FSF_STATUS_READ_SUB_SENSE_DATA) ?
  875. ", sense data" : "",
  876. (status_buffer->status_subtype &
  877. FSF_STATUS_READ_SUB_LINK_STATUS) ?
  878. ", link status change" : "",
  879. (status_buffer->status_subtype &
  880. FSF_STATUS_READ_SUB_PORT_CLOSED) ?
  881. ", port close" : "",
  882. (status_buffer->status_subtype &
  883. FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
  884. ", bit error exception" : "",
  885. (status_buffer->status_subtype &
  886. FSF_STATUS_READ_SUB_ACT_UPDATED) ?
  887. ", ACT update" : "",
  888. (status_buffer->status_subtype &
  889. FSF_STATUS_READ_SUB_ACT_HARDENED) ?
  890. ", ACT hardening" : "",
  891. (status_buffer->status_subtype &
  892. FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
  893. ", adapter feature change" : "");
  894. if (status_buffer->status_subtype &
  895. FSF_STATUS_READ_SUB_ACT_UPDATED)
  896. zfcp_erp_adapter_access_changed(adapter);
  897. break;
  898. case FSF_STATUS_READ_CFDC_UPDATED:
  899. ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
  900. zfcp_get_busid_by_adapter(adapter));
  901. zfcp_erp_adapter_access_changed(adapter);
  902. break;
  903. case FSF_STATUS_READ_CFDC_HARDENED:
  904. switch (status_buffer->status_subtype) {
  905. case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
  906. ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
  907. zfcp_get_busid_by_adapter(adapter));
  908. break;
  909. case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
  910. ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
  911. "to the secondary SE\n",
  912. zfcp_get_busid_by_adapter(adapter));
  913. break;
  914. default:
  915. ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
  916. zfcp_get_busid_by_adapter(adapter));
  917. }
  918. break;
  919. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  920. debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
  921. ZFCP_LOG_INFO("List of supported features on adapter %s has "
  922. "been changed from 0x%08X to 0x%08X\n",
  923. zfcp_get_busid_by_adapter(adapter),
  924. *(u32*) (status_buffer->payload + 4),
  925. *(u32*) (status_buffer->payload));
  926. adapter->adapter_features = *(u32*) status_buffer->payload;
  927. break;
  928. default:
  929. ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
  930. "type was received (debug info 0x%x)\n",
  931. status_buffer->status_type);
  932. ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
  933. status_buffer);
  934. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  935. (char *) status_buffer,
  936. sizeof (struct fsf_status_read_buffer));
  937. break;
  938. }
  939. mempool_free(status_buffer, adapter->pool.data_status_read);
  940. zfcp_fsf_req_free(fsf_req);
  941. /*
  942. * recycle buffer and start new request repeat until outbound
  943. * queue is empty or adapter shutdown is requested
  944. */
  945. /*
  946. * FIXME(qdio):
  947. * we may wait in the req_create for 5s during shutdown, so
  948. * qdio_cleanup will have to wait at least that long before returning
  949. * with failure to allow us a proper cleanup under all circumstances
  950. */
  951. /*
  952. * FIXME:
  953. * allocation failure possible? (Is this code needed?)
  954. */
  955. retval = zfcp_fsf_status_read(adapter, 0);
  956. if (retval < 0) {
  957. ZFCP_LOG_INFO("Failed to create unsolicited status read "
  958. "request for the adapter %s.\n",
  959. zfcp_get_busid_by_adapter(adapter));
  960. /* temporary fix to avoid status read buffer shortage */
  961. adapter->status_read_failed++;
  962. if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
  963. < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
  964. ZFCP_LOG_INFO("restart adapter %s due to status read "
  965. "buffer shortage\n",
  966. zfcp_get_busid_by_adapter(adapter));
  967. zfcp_erp_adapter_reopen(adapter, 0);
  968. }
  969. }
  970. out:
  971. return retval;
  972. }
  973. /*
  974. * function: zfcp_fsf_abort_fcp_command
  975. *
  976. * purpose: tells FSF to abort a running SCSI command
  977. *
  978. * returns: address of initiated FSF request
  979. * NULL - request could not be initiated
  980. *
  981. * FIXME(design): should be watched by a timeout !!!
  982. * FIXME(design) shouldn't this be modified to return an int
  983. * also...don't know how though
  984. */
  985. struct zfcp_fsf_req *
  986. zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  987. struct zfcp_adapter *adapter,
  988. struct zfcp_unit *unit, int req_flags)
  989. {
  990. volatile struct qdio_buffer_element *sbale;
  991. unsigned long lock_flags;
  992. struct zfcp_fsf_req *fsf_req = NULL;
  993. int retval = 0;
  994. /* setup new FSF request */
  995. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  996. req_flags, adapter->pool.fsf_req_abort,
  997. &lock_flags, &fsf_req);
  998. if (retval < 0) {
  999. ZFCP_LOG_INFO("error: Failed to create an abort command "
  1000. "request for lun 0x%016Lx on port 0x%016Lx "
  1001. "on adapter %s.\n",
  1002. unit->fcp_lun,
  1003. unit->port->wwpn,
  1004. zfcp_get_busid_by_adapter(adapter));
  1005. goto out;
  1006. }
  1007. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1008. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1009. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1010. fsf_req->data = (unsigned long) unit;
  1011. /* set handles of unit and its parent port in QTCB */
  1012. fsf_req->qtcb->header.lun_handle = unit->handle;
  1013. fsf_req->qtcb->header.port_handle = unit->port->handle;
  1014. /* set handle of request which should be aborted */
  1015. fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  1016. /* start QDIO request for this FSF request */
  1017. zfcp_fsf_start_scsi_er_timer(adapter);
  1018. retval = zfcp_fsf_req_send(fsf_req, NULL);
  1019. if (retval) {
  1020. del_timer(&adapter->scsi_er_timer);
  1021. ZFCP_LOG_INFO("error: Failed to send abort command request "
  1022. "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
  1023. zfcp_get_busid_by_adapter(adapter),
  1024. unit->port->wwpn, unit->fcp_lun);
  1025. zfcp_fsf_req_free(fsf_req);
  1026. fsf_req = NULL;
  1027. goto out;
  1028. }
  1029. ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
  1030. "(adapter%s, port d_id=0x%08x, "
  1031. "unit x%016Lx, old_req_id=0x%lx)\n",
  1032. zfcp_get_busid_by_adapter(adapter),
  1033. unit->port->d_id,
  1034. unit->fcp_lun, old_req_id);
  1035. out:
  1036. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  1037. return fsf_req;
  1038. }
  1039. /*
  1040. * function: zfcp_fsf_abort_fcp_command_handler
  1041. *
  1042. * purpose: is called for finished Abort FCP Command request
  1043. *
  1044. * returns:
  1045. */
  1046. static int
  1047. zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
  1048. {
  1049. int retval = -EINVAL;
  1050. struct zfcp_unit *unit;
  1051. unsigned char status_qual =
  1052. new_fsf_req->qtcb->header.fsf_status_qual.word[0];
  1053. del_timer(&new_fsf_req->adapter->scsi_er_timer);
  1054. if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1055. /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
  1056. goto skip_fsfstatus;
  1057. }
  1058. unit = (struct zfcp_unit *) new_fsf_req->data;
  1059. /* evaluate FSF status in QTCB */
  1060. switch (new_fsf_req->qtcb->header.fsf_status) {
  1061. case FSF_PORT_HANDLE_NOT_VALID:
  1062. if (status_qual >> 4 != status_qual % 0xf) {
  1063. debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
  1064. "fsf_s_phand_nv0");
  1065. /*
  1066. * In this case a command that was sent prior to a port
  1067. * reopen was aborted (handles are different). This is
  1068. * fine.
  1069. */
  1070. } else {
  1071. ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
  1072. "port 0x%016Lx on adapter %s invalid. "
  1073. "This may happen occasionally.\n",
  1074. unit->port->handle,
  1075. unit->port->wwpn,
  1076. zfcp_get_busid_by_unit(unit));
  1077. ZFCP_LOG_INFO("status qualifier:\n");
  1078. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1079. (char *) &new_fsf_req->qtcb->header.
  1080. fsf_status_qual,
  1081. sizeof (union fsf_status_qual));
  1082. /* Let's hope this sorts out the mess */
  1083. debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
  1084. "fsf_s_phand_nv1");
  1085. zfcp_erp_adapter_reopen(unit->port->adapter, 0);
  1086. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1087. }
  1088. break;
  1089. case FSF_LUN_HANDLE_NOT_VALID:
  1090. if (status_qual >> 4 != status_qual % 0xf) {
  1091. /* 2 */
  1092. debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
  1093. "fsf_s_lhand_nv0");
  1094. /*
  1095. * In this case a command that was sent prior to a unit
  1096. * reopen was aborted (handles are different).
  1097. * This is fine.
  1098. */
  1099. } else {
  1100. ZFCP_LOG_INFO
  1101. ("Warning: Temporary LUN identifier 0x%x of LUN "
  1102. "0x%016Lx on port 0x%016Lx on adapter %s is "
  1103. "invalid. This may happen in rare cases. "
  1104. "Trying to re-establish link.\n",
  1105. unit->handle,
  1106. unit->fcp_lun,
  1107. unit->port->wwpn,
  1108. zfcp_get_busid_by_unit(unit));
  1109. ZFCP_LOG_DEBUG("Status qualifier data:\n");
  1110. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  1111. (char *) &new_fsf_req->qtcb->header.
  1112. fsf_status_qual,
  1113. sizeof (union fsf_status_qual));
  1114. /* Let's hope this sorts out the mess */
  1115. debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
  1116. "fsf_s_lhand_nv1");
  1117. zfcp_erp_port_reopen(unit->port, 0);
  1118. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1119. }
  1120. break;
  1121. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  1122. retval = 0;
  1123. debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
  1124. "fsf_s_no_exist");
  1125. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  1126. break;
  1127. case FSF_PORT_BOXED:
  1128. ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
  1129. "be reopened\n", unit->port->wwpn,
  1130. zfcp_get_busid_by_unit(unit));
  1131. debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
  1132. "fsf_s_pboxed");
  1133. zfcp_erp_port_boxed(unit->port);
  1134. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1135. | ZFCP_STATUS_FSFREQ_RETRY;
  1136. break;
  1137. case FSF_LUN_BOXED:
  1138. ZFCP_LOG_INFO(
  1139. "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
  1140. "to be reopened\n",
  1141. unit->fcp_lun, unit->port->wwpn,
  1142. zfcp_get_busid_by_unit(unit));
  1143. debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
  1144. zfcp_erp_unit_boxed(unit);
  1145. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1146. | ZFCP_STATUS_FSFREQ_RETRY;
  1147. break;
  1148. case FSF_ADAPTER_STATUS_AVAILABLE:
  1149. switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  1150. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1151. debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
  1152. "fsf_sq_ltest");
  1153. zfcp_test_link(unit->port);
  1154. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1155. break;
  1156. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1157. /* SCSI stack will escalate */
  1158. debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
  1159. "fsf_sq_ulp");
  1160. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1161. break;
  1162. default:
  1163. ZFCP_LOG_NORMAL
  1164. ("bug: Wrong status qualifier 0x%x arrived.\n",
  1165. new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
  1166. debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
  1167. "fsf_sq_inval:");
  1168. debug_exception(new_fsf_req->adapter->erp_dbf, 0,
  1169. &new_fsf_req->qtcb->header.
  1170. fsf_status_qual.word[0], sizeof (u32));
  1171. break;
  1172. }
  1173. break;
  1174. case FSF_GOOD:
  1175. retval = 0;
  1176. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  1177. break;
  1178. default:
  1179. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  1180. "(debug info 0x%x)\n",
  1181. new_fsf_req->qtcb->header.fsf_status);
  1182. debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
  1183. "fsf_s_inval:");
  1184. debug_exception(new_fsf_req->adapter->erp_dbf, 0,
  1185. &new_fsf_req->qtcb->header.fsf_status,
  1186. sizeof (u32));
  1187. break;
  1188. }
  1189. skip_fsfstatus:
  1190. return retval;
  1191. }
  1192. /**
  1193. * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
  1194. * one SBALE
  1195. * Two scatter-gather lists are passed, one for the reqeust and one for the
  1196. * response.
  1197. */
  1198. static inline int
  1199. zfcp_use_one_sbal(struct scatterlist *req, int req_count,
  1200. struct scatterlist *resp, int resp_count)
  1201. {
  1202. return ((req_count == 1) &&
  1203. (resp_count == 1) &&
  1204. (((unsigned long) zfcp_sg_to_address(&req[0]) &
  1205. PAGE_MASK) ==
  1206. ((unsigned long) (zfcp_sg_to_address(&req[0]) +
  1207. req[0].length - 1) & PAGE_MASK)) &&
  1208. (((unsigned long) zfcp_sg_to_address(&resp[0]) &
  1209. PAGE_MASK) ==
  1210. ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
  1211. resp[0].length - 1) & PAGE_MASK)));
  1212. }
  1213. /**
  1214. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  1215. * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
  1216. * the request
  1217. * @pool: pointer to memory pool, if non-null this pool is used to allocate
  1218. * a struct zfcp_fsf_req
  1219. * @erp_action: pointer to erp_action, if non-null the Generic Service request
  1220. * is sent within error recovery
  1221. */
  1222. int
  1223. zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  1224. struct zfcp_erp_action *erp_action)
  1225. {
  1226. volatile struct qdio_buffer_element *sbale;
  1227. struct zfcp_port *port;
  1228. struct zfcp_adapter *adapter;
  1229. struct zfcp_fsf_req *fsf_req;
  1230. unsigned long lock_flags;
  1231. int bytes;
  1232. int ret = 0;
  1233. port = ct->port;
  1234. adapter = port->adapter;
  1235. ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  1236. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  1237. pool, &lock_flags, &fsf_req);
  1238. if (ret < 0) {
  1239. ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
  1240. "adapter: %s\n",
  1241. zfcp_get_busid_by_adapter(adapter));
  1242. goto failed_req;
  1243. }
  1244. if (erp_action != NULL) {
  1245. erp_action->fsf_req = fsf_req;
  1246. fsf_req->erp_action = erp_action;
  1247. }
  1248. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1249. if (zfcp_use_one_sbal(ct->req, ct->req_count,
  1250. ct->resp, ct->resp_count)){
  1251. /* both request buffer and response buffer
  1252. fit into one sbale each */
  1253. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  1254. sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
  1255. sbale[2].length = ct->req[0].length;
  1256. sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
  1257. sbale[3].length = ct->resp[0].length;
  1258. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  1259. } else if (adapter->adapter_features &
  1260. FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
  1261. /* try to use chained SBALs */
  1262. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1263. SBAL_FLAGS0_TYPE_WRITE_READ,
  1264. ct->req, ct->req_count,
  1265. ZFCP_MAX_SBALS_PER_CT_REQ);
  1266. if (bytes <= 0) {
  1267. ZFCP_LOG_INFO("error: creation of CT request failed "
  1268. "on adapter %s\n",
  1269. zfcp_get_busid_by_adapter(adapter));
  1270. if (bytes == 0)
  1271. ret = -ENOMEM;
  1272. else
  1273. ret = bytes;
  1274. goto failed_send;
  1275. }
  1276. fsf_req->qtcb->bottom.support.req_buf_length = bytes;
  1277. fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  1278. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1279. SBAL_FLAGS0_TYPE_WRITE_READ,
  1280. ct->resp, ct->resp_count,
  1281. ZFCP_MAX_SBALS_PER_CT_REQ);
  1282. if (bytes <= 0) {
  1283. ZFCP_LOG_INFO("error: creation of CT request failed "
  1284. "on adapter %s\n",
  1285. zfcp_get_busid_by_adapter(adapter));
  1286. if (bytes == 0)
  1287. ret = -ENOMEM;
  1288. else
  1289. ret = bytes;
  1290. goto failed_send;
  1291. }
  1292. fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
  1293. } else {
  1294. /* reject send generic request */
  1295. ZFCP_LOG_INFO(
  1296. "error: microcode does not support chained SBALs,"
  1297. "CT request too big (adapter %s)\n",
  1298. zfcp_get_busid_by_adapter(adapter));
  1299. ret = -EOPNOTSUPP;
  1300. goto failed_send;
  1301. }
  1302. /* settings in QTCB */
  1303. fsf_req->qtcb->header.port_handle = port->handle;
  1304. fsf_req->qtcb->bottom.support.service_class =
  1305. ZFCP_FC_SERVICE_CLASS_DEFAULT;
  1306. fsf_req->qtcb->bottom.support.timeout = ct->timeout;
  1307. fsf_req->data = (unsigned long) ct;
  1308. zfcp_san_dbf_event_ct_request(fsf_req);
  1309. /* start QDIO request for this FSF request */
  1310. ret = zfcp_fsf_req_send(fsf_req, ct->timer);
  1311. if (ret) {
  1312. ZFCP_LOG_DEBUG("error: initiation of CT request failed "
  1313. "(adapter %s, port 0x%016Lx)\n",
  1314. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  1315. goto failed_send;
  1316. }
  1317. ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
  1318. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  1319. goto out;
  1320. failed_send:
  1321. zfcp_fsf_req_free(fsf_req);
  1322. if (erp_action != NULL) {
  1323. erp_action->fsf_req = NULL;
  1324. }
  1325. failed_req:
  1326. out:
  1327. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1328. lock_flags);
  1329. return ret;
  1330. }
  1331. /**
  1332. * zfcp_fsf_send_ct_handler - handler for Generic Service requests
  1333. * @fsf_req: pointer to struct zfcp_fsf_req
  1334. *
  1335. * Data specific for the Generic Service request is passed using
  1336. * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
  1337. * Usually a specific handler for the CT request is called which is
  1338. * found in this structure.
  1339. */
  1340. static int
  1341. zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
  1342. {
  1343. struct zfcp_port *port;
  1344. struct zfcp_adapter *adapter;
  1345. struct zfcp_send_ct *send_ct;
  1346. struct fsf_qtcb_header *header;
  1347. struct fsf_qtcb_bottom_support *bottom;
  1348. int retval = -EINVAL;
  1349. u16 subtable, rule, counter;
  1350. adapter = fsf_req->adapter;
  1351. send_ct = (struct zfcp_send_ct *) fsf_req->data;
  1352. port = send_ct->port;
  1353. header = &fsf_req->qtcb->header;
  1354. bottom = &fsf_req->qtcb->bottom.support;
  1355. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1356. goto skip_fsfstatus;
  1357. /* evaluate FSF status in QTCB */
  1358. switch (header->fsf_status) {
  1359. case FSF_GOOD:
  1360. zfcp_san_dbf_event_ct_response(fsf_req);
  1361. retval = 0;
  1362. break;
  1363. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1364. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  1365. "class %d.\n",
  1366. zfcp_get_busid_by_port(port),
  1367. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  1368. /* stop operation for this adapter */
  1369. debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
  1370. zfcp_erp_adapter_shutdown(adapter, 0);
  1371. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1372. break;
  1373. case FSF_ADAPTER_STATUS_AVAILABLE:
  1374. switch (header->fsf_status_qual.word[0]){
  1375. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1376. /* reopening link to port */
  1377. debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
  1378. zfcp_test_link(port);
  1379. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1380. break;
  1381. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1382. /* ERP strategy will escalate */
  1383. debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
  1384. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1385. break;
  1386. default:
  1387. ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
  1388. "arrived.\n",
  1389. header->fsf_status_qual.word[0]);
  1390. break;
  1391. }
  1392. break;
  1393. case FSF_ACCESS_DENIED:
  1394. ZFCP_LOG_NORMAL("access denied, cannot send generic service "
  1395. "command (adapter %s, port d_id=0x%08x)\n",
  1396. zfcp_get_busid_by_port(port), port->d_id);
  1397. for (counter = 0; counter < 2; counter++) {
  1398. subtable = header->fsf_status_qual.halfword[counter * 2];
  1399. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  1400. switch (subtable) {
  1401. case FSF_SQ_CFDC_SUBTABLE_OS:
  1402. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  1403. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  1404. case FSF_SQ_CFDC_SUBTABLE_LUN:
  1405. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  1406. zfcp_act_subtable_type[subtable], rule);
  1407. break;
  1408. }
  1409. }
  1410. debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
  1411. zfcp_erp_port_access_denied(port);
  1412. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1413. break;
  1414. case FSF_GENERIC_COMMAND_REJECTED:
  1415. ZFCP_LOG_INFO("generic service command rejected "
  1416. "(adapter %s, port d_id=0x%08x)\n",
  1417. zfcp_get_busid_by_port(port), port->d_id);
  1418. ZFCP_LOG_INFO("status qualifier:\n");
  1419. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1420. (char *) &header->fsf_status_qual,
  1421. sizeof (union fsf_status_qual));
  1422. debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
  1423. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1424. break;
  1425. case FSF_PORT_HANDLE_NOT_VALID:
  1426. ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
  1427. "0x%016Lx on adapter %s invalid. This may "
  1428. "happen occasionally.\n", port->handle,
  1429. port->wwpn, zfcp_get_busid_by_port(port));
  1430. ZFCP_LOG_INFO("status qualifier:\n");
  1431. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1432. (char *) &header->fsf_status_qual,
  1433. sizeof (union fsf_status_qual));
  1434. debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
  1435. zfcp_erp_adapter_reopen(adapter, 0);
  1436. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1437. break;
  1438. case FSF_PORT_BOXED:
  1439. ZFCP_LOG_INFO("port needs to be reopened "
  1440. "(adapter %s, port d_id=0x%08x)\n",
  1441. zfcp_get_busid_by_port(port), port->d_id);
  1442. debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
  1443. zfcp_erp_port_boxed(port);
  1444. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1445. | ZFCP_STATUS_FSFREQ_RETRY;
  1446. break;
  1447. /* following states should never occure, all cases avoided
  1448. in zfcp_fsf_send_ct - but who knows ... */
  1449. case FSF_PAYLOAD_SIZE_MISMATCH:
  1450. ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
  1451. "req_buf_length=%d, resp_buf_length=%d)\n",
  1452. zfcp_get_busid_by_adapter(adapter),
  1453. bottom->req_buf_length, bottom->resp_buf_length);
  1454. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1455. break;
  1456. case FSF_REQUEST_SIZE_TOO_LARGE:
  1457. ZFCP_LOG_INFO("request size too large (adapter: %s, "
  1458. "req_buf_length=%d)\n",
  1459. zfcp_get_busid_by_adapter(adapter),
  1460. bottom->req_buf_length);
  1461. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1462. break;
  1463. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1464. ZFCP_LOG_INFO("response size too large (adapter: %s, "
  1465. "resp_buf_length=%d)\n",
  1466. zfcp_get_busid_by_adapter(adapter),
  1467. bottom->resp_buf_length);
  1468. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1469. break;
  1470. case FSF_SBAL_MISMATCH:
  1471. ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
  1472. "resp_buf_length=%d)\n",
  1473. zfcp_get_busid_by_adapter(adapter),
  1474. bottom->req_buf_length, bottom->resp_buf_length);
  1475. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1476. break;
  1477. default:
  1478. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  1479. "(debug info 0x%x)\n", header->fsf_status);
  1480. debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
  1481. debug_exception(adapter->erp_dbf, 0,
  1482. &header->fsf_status_qual.word[0], sizeof (u32));
  1483. break;
  1484. }
  1485. skip_fsfstatus:
  1486. send_ct->status = retval;
  1487. if (send_ct->handler != NULL)
  1488. send_ct->handler(send_ct->handler_data);
  1489. return retval;
  1490. }
  1491. /**
  1492. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1493. * @els: pointer to struct zfcp_send_els which contains all needed data for
  1494. * the command.
  1495. */
  1496. int
  1497. zfcp_fsf_send_els(struct zfcp_send_els *els)
  1498. {
  1499. volatile struct qdio_buffer_element *sbale;
  1500. struct zfcp_fsf_req *fsf_req;
  1501. u32 d_id;
  1502. struct zfcp_adapter *adapter;
  1503. unsigned long lock_flags;
  1504. int bytes;
  1505. int ret = 0;
  1506. d_id = els->d_id;
  1507. adapter = els->adapter;
  1508. ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1509. ZFCP_REQ_AUTO_CLEANUP,
  1510. NULL, &lock_flags, &fsf_req);
  1511. if (ret < 0) {
  1512. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1513. "(adapter %s, port d_id: 0x%08x)\n",
  1514. zfcp_get_busid_by_adapter(adapter), d_id);
  1515. goto failed_req;
  1516. }
  1517. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1518. if (zfcp_use_one_sbal(els->req, els->req_count,
  1519. els->resp, els->resp_count)){
  1520. /* both request buffer and response buffer
  1521. fit into one sbale each */
  1522. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  1523. sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
  1524. sbale[2].length = els->req[0].length;
  1525. sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
  1526. sbale[3].length = els->resp[0].length;
  1527. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  1528. } else if (adapter->adapter_features &
  1529. FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
  1530. /* try to use chained SBALs */
  1531. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1532. SBAL_FLAGS0_TYPE_WRITE_READ,
  1533. els->req, els->req_count,
  1534. ZFCP_MAX_SBALS_PER_ELS_REQ);
  1535. if (bytes <= 0) {
  1536. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1537. "(adapter %s, port d_id: 0x%08x)\n",
  1538. zfcp_get_busid_by_adapter(adapter), d_id);
  1539. if (bytes == 0) {
  1540. ret = -ENOMEM;
  1541. } else {
  1542. ret = bytes;
  1543. }
  1544. goto failed_send;
  1545. }
  1546. fsf_req->qtcb->bottom.support.req_buf_length = bytes;
  1547. fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  1548. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1549. SBAL_FLAGS0_TYPE_WRITE_READ,
  1550. els->resp, els->resp_count,
  1551. ZFCP_MAX_SBALS_PER_ELS_REQ);
  1552. if (bytes <= 0) {
  1553. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1554. "(adapter %s, port d_id: 0x%08x)\n",
  1555. zfcp_get_busid_by_adapter(adapter), d_id);
  1556. if (bytes == 0) {
  1557. ret = -ENOMEM;
  1558. } else {
  1559. ret = bytes;
  1560. }
  1561. goto failed_send;
  1562. }
  1563. fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
  1564. } else {
  1565. /* reject request */
  1566. ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
  1567. ", ELS request too big (adapter %s, "
  1568. "port d_id: 0x%08x)\n",
  1569. zfcp_get_busid_by_adapter(adapter), d_id);
  1570. ret = -EOPNOTSUPP;
  1571. goto failed_send;
  1572. }
  1573. /* settings in QTCB */
  1574. fsf_req->qtcb->bottom.support.d_id = d_id;
  1575. fsf_req->qtcb->bottom.support.service_class =
  1576. ZFCP_FC_SERVICE_CLASS_DEFAULT;
  1577. fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
  1578. fsf_req->data = (unsigned long) els;
  1579. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1580. zfcp_san_dbf_event_els_request(fsf_req);
  1581. /* start QDIO request for this FSF request */
  1582. ret = zfcp_fsf_req_send(fsf_req, els->timer);
  1583. if (ret) {
  1584. ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
  1585. "(adapter %s, port d_id: 0x%08x)\n",
  1586. zfcp_get_busid_by_adapter(adapter), d_id);
  1587. goto failed_send;
  1588. }
  1589. ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
  1590. "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
  1591. goto out;
  1592. failed_send:
  1593. zfcp_fsf_req_free(fsf_req);
  1594. failed_req:
  1595. out:
  1596. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1597. lock_flags);
  1598. return ret;
  1599. }
  1600. /**
  1601. * zfcp_fsf_send_els_handler - handler for ELS commands
  1602. * @fsf_req: pointer to struct zfcp_fsf_req
  1603. *
  1604. * Data specific for the ELS command is passed using
  1605. * fsf_req->data. There we find the pointer to struct zfcp_send_els.
  1606. * Usually a specific handler for the ELS command is called which is
  1607. * found in this structure.
  1608. */
  1609. static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
  1610. {
  1611. struct zfcp_adapter *adapter;
  1612. struct zfcp_port *port;
  1613. u32 d_id;
  1614. struct fsf_qtcb_header *header;
  1615. struct fsf_qtcb_bottom_support *bottom;
  1616. struct zfcp_send_els *send_els;
  1617. int retval = -EINVAL;
  1618. u16 subtable, rule, counter;
  1619. send_els = (struct zfcp_send_els *) fsf_req->data;
  1620. adapter = send_els->adapter;
  1621. port = send_els->port;
  1622. d_id = send_els->d_id;
  1623. header = &fsf_req->qtcb->header;
  1624. bottom = &fsf_req->qtcb->bottom.support;
  1625. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1626. goto skip_fsfstatus;
  1627. switch (header->fsf_status) {
  1628. case FSF_GOOD:
  1629. zfcp_san_dbf_event_els_response(fsf_req);
  1630. retval = 0;
  1631. break;
  1632. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1633. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  1634. "class %d.\n",
  1635. zfcp_get_busid_by_adapter(adapter),
  1636. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  1637. /* stop operation for this adapter */
  1638. debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
  1639. zfcp_erp_adapter_shutdown(adapter, 0);
  1640. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1641. break;
  1642. case FSF_ADAPTER_STATUS_AVAILABLE:
  1643. switch (header->fsf_status_qual.word[0]){
  1644. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1645. debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
  1646. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  1647. zfcp_test_link(port);
  1648. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1649. break;
  1650. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1651. debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
  1652. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1653. retval =
  1654. zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
  1655. (struct zfcp_ls_rjt_par *)
  1656. &header->fsf_status_qual.word[2]);
  1657. break;
  1658. case FSF_SQ_RETRY_IF_POSSIBLE:
  1659. debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
  1660. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1661. break;
  1662. default:
  1663. ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
  1664. header->fsf_status_qual.word[0]);
  1665. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1666. (char*)header->fsf_status_qual.word, 16);
  1667. }
  1668. break;
  1669. case FSF_ELS_COMMAND_REJECTED:
  1670. ZFCP_LOG_INFO("ELS has been rejected because command filter "
  1671. "prohibited sending "
  1672. "(adapter: %s, port d_id: 0x%08x)\n",
  1673. zfcp_get_busid_by_adapter(adapter), d_id);
  1674. break;
  1675. case FSF_PAYLOAD_SIZE_MISMATCH:
  1676. ZFCP_LOG_INFO(
  1677. "ELS request size and ELS response size must be either "
  1678. "both 0, or both greater than 0 "
  1679. "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
  1680. zfcp_get_busid_by_adapter(adapter),
  1681. bottom->req_buf_length,
  1682. bottom->resp_buf_length);
  1683. break;
  1684. case FSF_REQUEST_SIZE_TOO_LARGE:
  1685. ZFCP_LOG_INFO(
  1686. "Length of the ELS request buffer, "
  1687. "specified in QTCB bottom, "
  1688. "exceeds the size of the buffers "
  1689. "that have been allocated for ELS request data "
  1690. "(adapter: %s, req_buf_length=%d)\n",
  1691. zfcp_get_busid_by_adapter(adapter),
  1692. bottom->req_buf_length);
  1693. break;
  1694. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1695. ZFCP_LOG_INFO(
  1696. "Length of the ELS response buffer, "
  1697. "specified in QTCB bottom, "
  1698. "exceeds the size of the buffers "
  1699. "that have been allocated for ELS response data "
  1700. "(adapter: %s, resp_buf_length=%d)\n",
  1701. zfcp_get_busid_by_adapter(adapter),
  1702. bottom->resp_buf_length);
  1703. break;
  1704. case FSF_SBAL_MISMATCH:
  1705. /* should never occure, avoided in zfcp_fsf_send_els */
  1706. ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
  1707. "resp_buf_length=%d)\n",
  1708. zfcp_get_busid_by_adapter(adapter),
  1709. bottom->req_buf_length, bottom->resp_buf_length);
  1710. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1711. break;
  1712. case FSF_ACCESS_DENIED:
  1713. ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
  1714. "(adapter %s, port d_id=0x%08x)\n",
  1715. zfcp_get_busid_by_adapter(adapter), d_id);
  1716. for (counter = 0; counter < 2; counter++) {
  1717. subtable = header->fsf_status_qual.halfword[counter * 2];
  1718. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  1719. switch (subtable) {
  1720. case FSF_SQ_CFDC_SUBTABLE_OS:
  1721. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  1722. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  1723. case FSF_SQ_CFDC_SUBTABLE_LUN:
  1724. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  1725. zfcp_act_subtable_type[subtable], rule);
  1726. break;
  1727. }
  1728. }
  1729. debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
  1730. if (port != NULL)
  1731. zfcp_erp_port_access_denied(port);
  1732. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1733. break;
  1734. default:
  1735. ZFCP_LOG_NORMAL(
  1736. "bug: An unknown FSF Status was presented "
  1737. "(adapter: %s, fsf_status=0x%08x)\n",
  1738. zfcp_get_busid_by_adapter(adapter),
  1739. header->fsf_status);
  1740. debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
  1741. debug_exception(adapter->erp_dbf, 0,
  1742. &header->fsf_status_qual.word[0], sizeof(u32));
  1743. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1744. break;
  1745. }
  1746. skip_fsfstatus:
  1747. send_els->status = retval;
  1748. if (send_els->handler != 0)
  1749. send_els->handler(send_els->handler_data);
  1750. return retval;
  1751. }
  1752. int
  1753. zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1754. {
  1755. volatile struct qdio_buffer_element *sbale;
  1756. unsigned long lock_flags;
  1757. int retval = 0;
  1758. /* setup new FSF request */
  1759. retval = zfcp_fsf_req_create(erp_action->adapter,
  1760. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1761. ZFCP_REQ_AUTO_CLEANUP,
  1762. erp_action->adapter->pool.fsf_req_erp,
  1763. &lock_flags, &(erp_action->fsf_req));
  1764. if (retval < 0) {
  1765. ZFCP_LOG_INFO("error: Could not create exchange configuration "
  1766. "data request for adapter %s.\n",
  1767. zfcp_get_busid_by_adapter(erp_action->adapter));
  1768. goto out;
  1769. }
  1770. sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
  1771. erp_action->fsf_req->sbal_curr, 0);
  1772. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1773. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1774. erp_action->fsf_req->erp_action = erp_action;
  1775. erp_action->fsf_req->qtcb->bottom.config.feature_selection =
  1776. FSF_FEATURE_CFDC |
  1777. FSF_FEATURE_LUN_SHARING |
  1778. FSF_FEATURE_NOTIFICATION_LOST |
  1779. FSF_FEATURE_UPDATE_ALERT;
  1780. /* start QDIO request for this FSF request */
  1781. retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
  1782. if (retval) {
  1783. ZFCP_LOG_INFO
  1784. ("error: Could not send exchange configuration data "
  1785. "command on the adapter %s\n",
  1786. zfcp_get_busid_by_adapter(erp_action->adapter));
  1787. zfcp_fsf_req_free(erp_action->fsf_req);
  1788. erp_action->fsf_req = NULL;
  1789. goto out;
  1790. }
  1791. ZFCP_LOG_DEBUG("exchange configuration data request initiated "
  1792. "(adapter %s)\n",
  1793. zfcp_get_busid_by_adapter(erp_action->adapter));
  1794. out:
  1795. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  1796. lock_flags);
  1797. return retval;
  1798. }
  1799. /**
  1800. * zfcp_fsf_exchange_config_evaluate
  1801. * @fsf_req: fsf_req which belongs to xchg config data request
  1802. * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
  1803. *
  1804. * returns: -EIO on error, 0 otherwise
  1805. */
  1806. static int
  1807. zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
  1808. {
  1809. struct fsf_qtcb_bottom_config *bottom;
  1810. struct zfcp_adapter *adapter = fsf_req->adapter;
  1811. struct Scsi_Host *shost = adapter->scsi_host;
  1812. bottom = &fsf_req->qtcb->bottom.config;
  1813. ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
  1814. bottom->low_qtcb_version, bottom->high_qtcb_version);
  1815. adapter->fsf_lic_version = bottom->lic_version;
  1816. adapter->adapter_features = bottom->adapter_features;
  1817. adapter->connection_features = bottom->connection_features;
  1818. adapter->peer_wwpn = 0;
  1819. adapter->peer_wwnn = 0;
  1820. adapter->peer_d_id = 0;
  1821. if (xchg_ok) {
  1822. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  1823. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  1824. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  1825. fc_host_speed(shost) = bottom->fc_link_speed;
  1826. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  1827. adapter->hydra_version = bottom->adapter_type;
  1828. if (fc_host_permanent_port_name(shost) == -1)
  1829. fc_host_permanent_port_name(shost) =
  1830. fc_host_port_name(shost);
  1831. if (bottom->fc_topology == FSF_TOPO_P2P) {
  1832. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  1833. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  1834. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  1835. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  1836. } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
  1837. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  1838. else if (bottom->fc_topology == FSF_TOPO_AL)
  1839. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  1840. else
  1841. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1842. } else {
  1843. fc_host_node_name(shost) = 0;
  1844. fc_host_port_name(shost) = 0;
  1845. fc_host_port_id(shost) = 0;
  1846. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1847. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1848. adapter->hydra_version = 0;
  1849. }
  1850. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  1851. adapter->hardware_version = bottom->hardware_version;
  1852. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  1853. min(FC_SERIAL_NUMBER_SIZE, 17));
  1854. EBCASC(fc_host_serial_number(shost),
  1855. min(FC_SERIAL_NUMBER_SIZE, 17));
  1856. }
  1857. ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
  1858. "WWNN 0x%016Lx, "
  1859. "WWPN 0x%016Lx, "
  1860. "S_ID 0x%08x,\n"
  1861. "adapter version 0x%x, "
  1862. "LIC version 0x%x, "
  1863. "FC link speed %d Gb/s\n",
  1864. zfcp_get_busid_by_adapter(adapter),
  1865. (wwn_t) fc_host_node_name(shost),
  1866. (wwn_t) fc_host_port_name(shost),
  1867. fc_host_port_id(shost),
  1868. adapter->hydra_version,
  1869. adapter->fsf_lic_version,
  1870. fc_host_speed(shost));
  1871. if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
  1872. ZFCP_LOG_NORMAL("error: the adapter %s "
  1873. "only supports newer control block "
  1874. "versions in comparison to this device "
  1875. "driver (try updated device driver)\n",
  1876. zfcp_get_busid_by_adapter(adapter));
  1877. debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
  1878. zfcp_erp_adapter_shutdown(adapter, 0);
  1879. return -EIO;
  1880. }
  1881. if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
  1882. ZFCP_LOG_NORMAL("error: the adapter %s "
  1883. "only supports older control block "
  1884. "versions than this device driver uses"
  1885. "(consider a microcode upgrade)\n",
  1886. zfcp_get_busid_by_adapter(adapter));
  1887. debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
  1888. zfcp_erp_adapter_shutdown(adapter, 0);
  1889. return -EIO;
  1890. }
  1891. return 0;
  1892. }
  1893. /*
  1894. * function: zfcp_fsf_exchange_config_data_handler
  1895. *
  1896. * purpose: is called for finished Exchange Configuration Data command
  1897. *
  1898. * returns:
  1899. */
  1900. static int
  1901. zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
  1902. {
  1903. struct fsf_qtcb_bottom_config *bottom;
  1904. struct zfcp_adapter *adapter = fsf_req->adapter;
  1905. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  1906. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1907. return -EIO;
  1908. switch (qtcb->header.fsf_status) {
  1909. case FSF_GOOD:
  1910. if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
  1911. return -EIO;
  1912. switch (fc_host_port_type(adapter->scsi_host)) {
  1913. case FC_PORTTYPE_PTP:
  1914. ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
  1915. "configuration detected at adapter %s\n"
  1916. "Peer WWNN 0x%016llx, "
  1917. "peer WWPN 0x%016llx, "
  1918. "peer d_id 0x%06x\n",
  1919. zfcp_get_busid_by_adapter(adapter),
  1920. adapter->peer_wwnn,
  1921. adapter->peer_wwpn,
  1922. adapter->peer_d_id);
  1923. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  1924. "top-p-to-p");
  1925. break;
  1926. case FC_PORTTYPE_NLPORT:
  1927. ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
  1928. "topology detected at adapter %s "
  1929. "unsupported, shutting down adapter\n",
  1930. zfcp_get_busid_by_adapter(adapter));
  1931. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  1932. "top-al");
  1933. zfcp_erp_adapter_shutdown(adapter, 0);
  1934. return -EIO;
  1935. case FC_PORTTYPE_NPORT:
  1936. ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
  1937. "network detected at adapter %s.\n",
  1938. zfcp_get_busid_by_adapter(adapter));
  1939. break;
  1940. default:
  1941. ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
  1942. "reported by the exchange "
  1943. "configuration command for "
  1944. "the adapter %s is not "
  1945. "of a type known to the zfcp "
  1946. "driver, shutting down adapter\n",
  1947. zfcp_get_busid_by_adapter(adapter));
  1948. debug_text_exception(fsf_req->adapter->erp_dbf, 0,
  1949. "unknown-topo");
  1950. zfcp_erp_adapter_shutdown(adapter, 0);
  1951. return -EIO;
  1952. }
  1953. bottom = &qtcb->bottom.config;
  1954. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  1955. ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
  1956. "allowed by the adapter %s "
  1957. "is lower than the minimum "
  1958. "required by the driver (%ld bytes).\n",
  1959. bottom->max_qtcb_size,
  1960. zfcp_get_busid_by_adapter(adapter),
  1961. sizeof(struct fsf_qtcb));
  1962. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  1963. "qtcb-size");
  1964. debug_event(fsf_req->adapter->erp_dbf, 0,
  1965. &bottom->max_qtcb_size, sizeof (u32));
  1966. zfcp_erp_adapter_shutdown(adapter, 0);
  1967. return -EIO;
  1968. }
  1969. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  1970. &adapter->status);
  1971. break;
  1972. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  1973. debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
  1974. if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
  1975. return -EIO;
  1976. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  1977. zfcp_fsf_link_down_info_eval(adapter,
  1978. &qtcb->header.fsf_status_qual.link_down_info);
  1979. break;
  1980. default:
  1981. debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
  1982. debug_event(fsf_req->adapter->erp_dbf, 0,
  1983. &fsf_req->qtcb->header.fsf_status, sizeof (u32));
  1984. zfcp_erp_adapter_shutdown(adapter, 0);
  1985. return -EIO;
  1986. }
  1987. return 0;
  1988. }
  1989. /**
  1990. * zfcp_fsf_exchange_port_data - request information about local port
  1991. * @erp_action: ERP action for the adapter for which port data is requested
  1992. * @adapter: for which port data is requested
  1993. * @data: response to exchange port data request
  1994. */
  1995. int
  1996. zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
  1997. struct zfcp_adapter *adapter,
  1998. struct fsf_qtcb_bottom_port *data)
  1999. {
  2000. volatile struct qdio_buffer_element *sbale;
  2001. int retval = 0;
  2002. unsigned long lock_flags;
  2003. struct zfcp_fsf_req *fsf_req;
  2004. struct timer_list *timer;
  2005. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
  2006. ZFCP_LOG_INFO("error: exchange port data "
  2007. "command not supported by adapter %s\n",
  2008. zfcp_get_busid_by_adapter(adapter));
  2009. return -EOPNOTSUPP;
  2010. }
  2011. /* setup new FSF request */
  2012. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  2013. erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
  2014. NULL, &lock_flags, &fsf_req);
  2015. if (retval < 0) {
  2016. ZFCP_LOG_INFO("error: Out of resources. Could not create an "
  2017. "exchange port data request for"
  2018. "the adapter %s.\n",
  2019. zfcp_get_busid_by_adapter(adapter));
  2020. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  2021. lock_flags);
  2022. return retval;
  2023. }
  2024. if (data)
  2025. fsf_req->data = (unsigned long) data;
  2026. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2027. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2028. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2029. if (erp_action) {
  2030. erp_action->fsf_req = fsf_req;
  2031. fsf_req->erp_action = erp_action;
  2032. timer = &erp_action->timer;
  2033. } else {
  2034. timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
  2035. if (!timer) {
  2036. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  2037. lock_flags);
  2038. zfcp_fsf_req_free(fsf_req);
  2039. return -ENOMEM;
  2040. }
  2041. init_timer(timer);
  2042. timer->function = zfcp_fsf_request_timeout_handler;
  2043. timer->data = (unsigned long) adapter;
  2044. timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
  2045. }
  2046. retval = zfcp_fsf_req_send(fsf_req, timer);
  2047. if (retval) {
  2048. ZFCP_LOG_INFO("error: Could not send an exchange port data "
  2049. "command on the adapter %s\n",
  2050. zfcp_get_busid_by_adapter(adapter));
  2051. zfcp_fsf_req_free(fsf_req);
  2052. if (erp_action)
  2053. erp_action->fsf_req = NULL;
  2054. else
  2055. kfree(timer);
  2056. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  2057. lock_flags);
  2058. return retval;
  2059. }
  2060. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  2061. if (!erp_action) {
  2062. wait_event(fsf_req->completion_wq,
  2063. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2064. del_timer_sync(timer);
  2065. zfcp_fsf_req_free(fsf_req);
  2066. kfree(timer);
  2067. }
  2068. return retval;
  2069. }
  2070. /**
  2071. * zfcp_fsf_exchange_port_evaluate
  2072. * @fsf_req: fsf_req which belongs to xchg port data request
  2073. * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
  2074. */
  2075. static void
  2076. zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
  2077. {
  2078. struct zfcp_adapter *adapter;
  2079. struct fsf_qtcb *qtcb;
  2080. struct fsf_qtcb_bottom_port *bottom, *data;
  2081. struct Scsi_Host *shost;
  2082. adapter = fsf_req->adapter;
  2083. qtcb = fsf_req->qtcb;
  2084. bottom = &qtcb->bottom.port;
  2085. shost = adapter->scsi_host;
  2086. data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
  2087. if (data)
  2088. memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
  2089. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  2090. fc_host_permanent_port_name(shost) = bottom->wwpn;
  2091. else
  2092. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  2093. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  2094. fc_host_supported_speeds(shost) = bottom->supported_speed;
  2095. }
  2096. /**
  2097. * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
  2098. * @fsf_req: pointer to struct zfcp_fsf_req
  2099. */
  2100. static void
  2101. zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
  2102. {
  2103. struct zfcp_adapter *adapter;
  2104. struct fsf_qtcb *qtcb;
  2105. adapter = fsf_req->adapter;
  2106. qtcb = fsf_req->qtcb;
  2107. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  2108. return;
  2109. switch (qtcb->header.fsf_status) {
  2110. case FSF_GOOD:
  2111. zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
  2112. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  2113. break;
  2114. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  2115. zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
  2116. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  2117. zfcp_fsf_link_down_info_eval(adapter,
  2118. &qtcb->header.fsf_status_qual.link_down_info);
  2119. break;
  2120. default:
  2121. debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
  2122. debug_event(adapter->erp_dbf, 0,
  2123. &fsf_req->qtcb->header.fsf_status, sizeof(u32));
  2124. }
  2125. }
  2126. /*
  2127. * function: zfcp_fsf_open_port
  2128. *
  2129. * purpose:
  2130. *
  2131. * returns: address of initiated FSF request
  2132. * NULL - request could not be initiated
  2133. */
  2134. int
  2135. zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  2136. {
  2137. volatile struct qdio_buffer_element *sbale;
  2138. unsigned long lock_flags;
  2139. int retval = 0;
  2140. /* setup new FSF request */
  2141. retval = zfcp_fsf_req_create(erp_action->adapter,
  2142. FSF_QTCB_OPEN_PORT_WITH_DID,
  2143. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2144. erp_action->adapter->pool.fsf_req_erp,
  2145. &lock_flags, &(erp_action->fsf_req));
  2146. if (retval < 0) {
  2147. ZFCP_LOG_INFO("error: Could not create open port request "
  2148. "for port 0x%016Lx on adapter %s.\n",
  2149. erp_action->port->wwpn,
  2150. zfcp_get_busid_by_adapter(erp_action->adapter));
  2151. goto out;
  2152. }
  2153. sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
  2154. erp_action->fsf_req->sbal_curr, 0);
  2155. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2156. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2157. erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  2158. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
  2159. erp_action->fsf_req->data = (unsigned long) erp_action->port;
  2160. erp_action->fsf_req->erp_action = erp_action;
  2161. /* start QDIO request for this FSF request */
  2162. retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
  2163. if (retval) {
  2164. ZFCP_LOG_INFO("error: Could not send open port request for "
  2165. "port 0x%016Lx on adapter %s.\n",
  2166. erp_action->port->wwpn,
  2167. zfcp_get_busid_by_adapter(erp_action->adapter));
  2168. zfcp_fsf_req_free(erp_action->fsf_req);
  2169. erp_action->fsf_req = NULL;
  2170. goto out;
  2171. }
  2172. ZFCP_LOG_DEBUG("open port request initiated "
  2173. "(adapter %s, port 0x%016Lx)\n",
  2174. zfcp_get_busid_by_adapter(erp_action->adapter),
  2175. erp_action->port->wwpn);
  2176. out:
  2177. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2178. lock_flags);
  2179. return retval;
  2180. }
  2181. /*
  2182. * function: zfcp_fsf_open_port_handler
  2183. *
  2184. * purpose: is called for finished Open Port command
  2185. *
  2186. * returns:
  2187. */
  2188. static int
  2189. zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
  2190. {
  2191. int retval = -EINVAL;
  2192. struct zfcp_port *port;
  2193. struct fsf_plogi *plogi;
  2194. struct fsf_qtcb_header *header;
  2195. u16 subtable, rule, counter;
  2196. port = (struct zfcp_port *) fsf_req->data;
  2197. header = &fsf_req->qtcb->header;
  2198. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2199. /* don't change port status in our bookkeeping */
  2200. goto skip_fsfstatus;
  2201. }
  2202. /* evaluate FSF status in QTCB */
  2203. switch (header->fsf_status) {
  2204. case FSF_PORT_ALREADY_OPEN:
  2205. ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
  2206. "is already open.\n",
  2207. port->wwpn, zfcp_get_busid_by_port(port));
  2208. debug_text_exception(fsf_req->adapter->erp_dbf, 0,
  2209. "fsf_s_popen");
  2210. /*
  2211. * This is a bug, however operation should continue normally
  2212. * if it is simply ignored
  2213. */
  2214. break;
  2215. case FSF_ACCESS_DENIED:
  2216. ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
  2217. "on adapter %s\n",
  2218. port->wwpn, zfcp_get_busid_by_port(port));
  2219. for (counter = 0; counter < 2; counter++) {
  2220. subtable = header->fsf_status_qual.halfword[counter * 2];
  2221. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2222. switch (subtable) {
  2223. case FSF_SQ_CFDC_SUBTABLE_OS:
  2224. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2225. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2226. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2227. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2228. zfcp_act_subtable_type[subtable], rule);
  2229. break;
  2230. }
  2231. }
  2232. debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
  2233. zfcp_erp_port_access_denied(port);
  2234. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2235. break;
  2236. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  2237. ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
  2238. "The remote port 0x%016Lx on adapter %s "
  2239. "could not be opened. Disabling it.\n",
  2240. port->wwpn, zfcp_get_busid_by_port(port));
  2241. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  2242. "fsf_s_max_ports");
  2243. zfcp_erp_port_failed(port);
  2244. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2245. break;
  2246. case FSF_ADAPTER_STATUS_AVAILABLE:
  2247. switch (header->fsf_status_qual.word[0]) {
  2248. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2249. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  2250. "fsf_sq_ltest");
  2251. /* ERP strategy will escalate */
  2252. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2253. break;
  2254. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2255. /* ERP strategy will escalate */
  2256. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  2257. "fsf_sq_ulp");
  2258. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2259. break;
  2260. case FSF_SQ_NO_RETRY_POSSIBLE:
  2261. ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
  2262. "adapter %s could not be opened. "
  2263. "Disabling it.\n",
  2264. port->wwpn,
  2265. zfcp_get_busid_by_port(port));
  2266. debug_text_exception(fsf_req->adapter->erp_dbf, 0,
  2267. "fsf_sq_no_retry");
  2268. zfcp_erp_port_failed(port);
  2269. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2270. break;
  2271. default:
  2272. ZFCP_LOG_NORMAL
  2273. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2274. header->fsf_status_qual.word[0]);
  2275. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  2276. "fsf_sq_inval:");
  2277. debug_exception(
  2278. fsf_req->adapter->erp_dbf, 0,
  2279. &header->fsf_status_qual.word[0],
  2280. sizeof (u32));
  2281. break;
  2282. }
  2283. break;
  2284. case FSF_GOOD:
  2285. /* save port handle assigned by FSF */
  2286. port->handle = header->port_handle;
  2287. ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
  2288. "was opened, it's port handle is 0x%x\n",
  2289. port->wwpn, zfcp_get_busid_by_port(port),
  2290. port->handle);
  2291. /* mark port as open */
  2292. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  2293. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  2294. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2295. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  2296. &port->status);
  2297. retval = 0;
  2298. /* check whether D_ID has changed during open */
  2299. /*
  2300. * FIXME: This check is not airtight, as the FCP channel does
  2301. * not monitor closures of target port connections caused on
  2302. * the remote side. Thus, they might miss out on invalidating
  2303. * locally cached WWPNs (and other N_Port parameters) of gone
  2304. * target ports. So, our heroic attempt to make things safe
  2305. * could be undermined by 'open port' response data tagged with
  2306. * obsolete WWPNs. Another reason to monitor potential
  2307. * connection closures ourself at least (by interpreting
  2308. * incoming ELS' and unsolicited status). It just crosses my
  2309. * mind that one should be able to cross-check by means of
  2310. * another GID_PN straight after a port has been opened.
  2311. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  2312. */
  2313. plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
  2314. if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
  2315. {
  2316. if (fsf_req->qtcb->bottom.support.els1_length <
  2317. sizeof (struct fsf_plogi)) {
  2318. ZFCP_LOG_INFO(
  2319. "warning: insufficient length of "
  2320. "PLOGI payload (%i)\n",
  2321. fsf_req->qtcb->bottom.support.els1_length);
  2322. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  2323. "fsf_s_short_plogi:");
  2324. /* skip sanity check and assume wwpn is ok */
  2325. } else {
  2326. if (plogi->serv_param.wwpn != port->wwpn) {
  2327. ZFCP_LOG_INFO("warning: d_id of port "
  2328. "0x%016Lx changed during "
  2329. "open\n", port->wwpn);
  2330. debug_text_event(
  2331. fsf_req->adapter->erp_dbf, 0,
  2332. "fsf_s_did_change:");
  2333. atomic_clear_mask(
  2334. ZFCP_STATUS_PORT_DID_DID,
  2335. &port->status);
  2336. } else {
  2337. port->wwnn = plogi->serv_param.wwnn;
  2338. zfcp_plogi_evaluate(port, plogi);
  2339. }
  2340. }
  2341. }
  2342. break;
  2343. case FSF_UNKNOWN_OP_SUBTYPE:
  2344. /* should never occure, subtype not set in zfcp_fsf_open_port */
  2345. ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
  2346. "op_subtype=0x%x)\n",
  2347. zfcp_get_busid_by_port(port),
  2348. fsf_req->qtcb->bottom.support.operation_subtype);
  2349. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2350. break;
  2351. default:
  2352. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2353. "(debug info 0x%x)\n",
  2354. header->fsf_status);
  2355. debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
  2356. debug_exception(fsf_req->adapter->erp_dbf, 0,
  2357. &header->fsf_status, sizeof (u32));
  2358. break;
  2359. }
  2360. skip_fsfstatus:
  2361. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
  2362. return retval;
  2363. }
  2364. /*
  2365. * function: zfcp_fsf_close_port
  2366. *
  2367. * purpose: submit FSF command "close port"
  2368. *
  2369. * returns: address of initiated FSF request
  2370. * NULL - request could not be initiated
  2371. */
  2372. int
  2373. zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  2374. {
  2375. volatile struct qdio_buffer_element *sbale;
  2376. unsigned long lock_flags;
  2377. int retval = 0;
  2378. /* setup new FSF request */
  2379. retval = zfcp_fsf_req_create(erp_action->adapter,
  2380. FSF_QTCB_CLOSE_PORT,
  2381. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2382. erp_action->adapter->pool.fsf_req_erp,
  2383. &lock_flags, &(erp_action->fsf_req));
  2384. if (retval < 0) {
  2385. ZFCP_LOG_INFO("error: Could not create a close port request "
  2386. "for port 0x%016Lx on adapter %s.\n",
  2387. erp_action->port->wwpn,
  2388. zfcp_get_busid_by_adapter(erp_action->adapter));
  2389. goto out;
  2390. }
  2391. sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
  2392. erp_action->fsf_req->sbal_curr, 0);
  2393. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2394. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2395. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
  2396. erp_action->fsf_req->data = (unsigned long) erp_action->port;
  2397. erp_action->fsf_req->erp_action = erp_action;
  2398. erp_action->fsf_req->qtcb->header.port_handle =
  2399. erp_action->port->handle;
  2400. /* start QDIO request for this FSF request */
  2401. retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
  2402. if (retval) {
  2403. ZFCP_LOG_INFO("error: Could not send a close port request for "
  2404. "port 0x%016Lx on adapter %s.\n",
  2405. erp_action->port->wwpn,
  2406. zfcp_get_busid_by_adapter(erp_action->adapter));
  2407. zfcp_fsf_req_free(erp_action->fsf_req);
  2408. erp_action->fsf_req = NULL;
  2409. goto out;
  2410. }
  2411. ZFCP_LOG_TRACE("close port request initiated "
  2412. "(adapter %s, port 0x%016Lx)\n",
  2413. zfcp_get_busid_by_adapter(erp_action->adapter),
  2414. erp_action->port->wwpn);
  2415. out:
  2416. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2417. lock_flags);
  2418. return retval;
  2419. }
  2420. /*
  2421. * function: zfcp_fsf_close_port_handler
  2422. *
  2423. * purpose: is called for finished Close Port FSF command
  2424. *
  2425. * returns:
  2426. */
  2427. static int
  2428. zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
  2429. {
  2430. int retval = -EINVAL;
  2431. struct zfcp_port *port;
  2432. port = (struct zfcp_port *) fsf_req->data;
  2433. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2434. /* don't change port status in our bookkeeping */
  2435. goto skip_fsfstatus;
  2436. }
  2437. /* evaluate FSF status in QTCB */
  2438. switch (fsf_req->qtcb->header.fsf_status) {
  2439. case FSF_PORT_HANDLE_NOT_VALID:
  2440. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  2441. "0x%016Lx on adapter %s invalid. This may happen "
  2442. "occasionally.\n", port->handle,
  2443. port->wwpn, zfcp_get_busid_by_port(port));
  2444. ZFCP_LOG_DEBUG("status qualifier:\n");
  2445. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2446. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  2447. sizeof (union fsf_status_qual));
  2448. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  2449. "fsf_s_phand_nv");
  2450. zfcp_erp_adapter_reopen(port->adapter, 0);
  2451. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2452. break;
  2453. case FSF_ADAPTER_STATUS_AVAILABLE:
  2454. /* Note: FSF has actually closed the port in this case.
  2455. * The status code is just daft. Fingers crossed for a change
  2456. */
  2457. retval = 0;
  2458. break;
  2459. case FSF_GOOD:
  2460. ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
  2461. "port handle 0x%x\n", port->wwpn,
  2462. zfcp_get_busid_by_port(port), port->handle);
  2463. zfcp_erp_modify_port_status(port,
  2464. ZFCP_STATUS_COMMON_OPEN,
  2465. ZFCP_CLEAR);
  2466. retval = 0;
  2467. break;
  2468. default:
  2469. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2470. "(debug info 0x%x)\n",
  2471. fsf_req->qtcb->header.fsf_status);
  2472. debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
  2473. debug_exception(fsf_req->adapter->erp_dbf, 0,
  2474. &fsf_req->qtcb->header.fsf_status,
  2475. sizeof (u32));
  2476. break;
  2477. }
  2478. skip_fsfstatus:
  2479. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
  2480. return retval;
  2481. }
  2482. /*
  2483. * function: zfcp_fsf_close_physical_port
  2484. *
  2485. * purpose: submit FSF command "close physical port"
  2486. *
  2487. * returns: address of initiated FSF request
  2488. * NULL - request could not be initiated
  2489. */
  2490. int
  2491. zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  2492. {
  2493. int retval = 0;
  2494. unsigned long lock_flags;
  2495. volatile struct qdio_buffer_element *sbale;
  2496. /* setup new FSF request */
  2497. retval = zfcp_fsf_req_create(erp_action->adapter,
  2498. FSF_QTCB_CLOSE_PHYSICAL_PORT,
  2499. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2500. erp_action->adapter->pool.fsf_req_erp,
  2501. &lock_flags, &erp_action->fsf_req);
  2502. if (retval < 0) {
  2503. ZFCP_LOG_INFO("error: Could not create close physical port "
  2504. "request (adapter %s, port 0x%016Lx)\n",
  2505. zfcp_get_busid_by_adapter(erp_action->adapter),
  2506. erp_action->port->wwpn);
  2507. goto out;
  2508. }
  2509. sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
  2510. erp_action->fsf_req->sbal_curr, 0);
  2511. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2512. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2513. /* mark port as being closed */
  2514. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  2515. &erp_action->port->status);
  2516. /* save a pointer to this port */
  2517. erp_action->fsf_req->data = (unsigned long) erp_action->port;
  2518. /* port to be closed */
  2519. erp_action->fsf_req->qtcb->header.port_handle =
  2520. erp_action->port->handle;
  2521. erp_action->fsf_req->erp_action = erp_action;
  2522. /* start QDIO request for this FSF request */
  2523. retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
  2524. if (retval) {
  2525. ZFCP_LOG_INFO("error: Could not send close physical port "
  2526. "request (adapter %s, port 0x%016Lx)\n",
  2527. zfcp_get_busid_by_adapter(erp_action->adapter),
  2528. erp_action->port->wwpn);
  2529. zfcp_fsf_req_free(erp_action->fsf_req);
  2530. erp_action->fsf_req = NULL;
  2531. goto out;
  2532. }
  2533. ZFCP_LOG_TRACE("close physical port request initiated "
  2534. "(adapter %s, port 0x%016Lx)\n",
  2535. zfcp_get_busid_by_adapter(erp_action->adapter),
  2536. erp_action->port->wwpn);
  2537. out:
  2538. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2539. lock_flags);
  2540. return retval;
  2541. }
  2542. /*
  2543. * function: zfcp_fsf_close_physical_port_handler
  2544. *
  2545. * purpose: is called for finished Close Physical Port FSF command
  2546. *
  2547. * returns:
  2548. */
  2549. static int
  2550. zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
  2551. {
  2552. int retval = -EINVAL;
  2553. struct zfcp_port *port;
  2554. struct zfcp_unit *unit;
  2555. struct fsf_qtcb_header *header;
  2556. u16 subtable, rule, counter;
  2557. port = (struct zfcp_port *) fsf_req->data;
  2558. header = &fsf_req->qtcb->header;
  2559. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2560. /* don't change port status in our bookkeeping */
  2561. goto skip_fsfstatus;
  2562. }
  2563. /* evaluate FSF status in QTCB */
  2564. switch (header->fsf_status) {
  2565. case FSF_PORT_HANDLE_NOT_VALID:
  2566. ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
  2567. "(adapter %s, port 0x%016Lx). "
  2568. "This may happen occasionally.\n",
  2569. port->handle,
  2570. zfcp_get_busid_by_port(port),
  2571. port->wwpn);
  2572. ZFCP_LOG_DEBUG("status qualifier:\n");
  2573. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2574. (char *) &header->fsf_status_qual,
  2575. sizeof (union fsf_status_qual));
  2576. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  2577. "fsf_s_phand_nv");
  2578. zfcp_erp_adapter_reopen(port->adapter, 0);
  2579. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2580. break;
  2581. case FSF_ACCESS_DENIED:
  2582. ZFCP_LOG_NORMAL("Access denied, cannot close "
  2583. "physical port 0x%016Lx on adapter %s\n",
  2584. port->wwpn, zfcp_get_busid_by_port(port));
  2585. for (counter = 0; counter < 2; counter++) {
  2586. subtable = header->fsf_status_qual.halfword[counter * 2];
  2587. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2588. switch (subtable) {
  2589. case FSF_SQ_CFDC_SUBTABLE_OS:
  2590. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2591. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2592. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2593. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2594. zfcp_act_subtable_type[subtable], rule);
  2595. break;
  2596. }
  2597. }
  2598. debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
  2599. zfcp_erp_port_access_denied(port);
  2600. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2601. break;
  2602. case FSF_PORT_BOXED:
  2603. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
  2604. "%s needs to be reopened but it was attempted "
  2605. "to close it physically.\n",
  2606. port->wwpn,
  2607. zfcp_get_busid_by_port(port));
  2608. debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
  2609. zfcp_erp_port_boxed(port);
  2610. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2611. ZFCP_STATUS_FSFREQ_RETRY;
  2612. break;
  2613. case FSF_ADAPTER_STATUS_AVAILABLE:
  2614. switch (header->fsf_status_qual.word[0]) {
  2615. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2616. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  2617. "fsf_sq_ltest");
  2618. /* This will now be escalated by ERP */
  2619. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2620. break;
  2621. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2622. /* ERP strategy will escalate */
  2623. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  2624. "fsf_sq_ulp");
  2625. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2626. break;
  2627. default:
  2628. ZFCP_LOG_NORMAL
  2629. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2630. header->fsf_status_qual.word[0]);
  2631. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  2632. "fsf_sq_inval:");
  2633. debug_exception(
  2634. fsf_req->adapter->erp_dbf, 0,
  2635. &header->fsf_status_qual.word[0], sizeof (u32));
  2636. break;
  2637. }
  2638. break;
  2639. case FSF_GOOD:
  2640. ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
  2641. "physically closed, port handle 0x%x\n",
  2642. port->wwpn,
  2643. zfcp_get_busid_by_port(port), port->handle);
  2644. /* can't use generic zfcp_erp_modify_port_status because
  2645. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  2646. */
  2647. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  2648. list_for_each_entry(unit, &port->unit_list_head, list)
  2649. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  2650. retval = 0;
  2651. break;
  2652. default:
  2653. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2654. "(debug info 0x%x)\n",
  2655. header->fsf_status);
  2656. debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
  2657. debug_exception(fsf_req->adapter->erp_dbf, 0,
  2658. &header->fsf_status, sizeof (u32));
  2659. break;
  2660. }
  2661. skip_fsfstatus:
  2662. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  2663. return retval;
  2664. }
  2665. /*
  2666. * function: zfcp_fsf_open_unit
  2667. *
  2668. * purpose:
  2669. *
  2670. * returns:
  2671. *
  2672. * assumptions: This routine does not check whether the associated
  2673. * remote port has already been opened. This should be
  2674. * done by calling routines. Otherwise some status
  2675. * may be presented by FSF
  2676. */
  2677. int
  2678. zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  2679. {
  2680. volatile struct qdio_buffer_element *sbale;
  2681. unsigned long lock_flags;
  2682. int retval = 0;
  2683. /* setup new FSF request */
  2684. retval = zfcp_fsf_req_create(erp_action->adapter,
  2685. FSF_QTCB_OPEN_LUN,
  2686. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2687. erp_action->adapter->pool.fsf_req_erp,
  2688. &lock_flags, &(erp_action->fsf_req));
  2689. if (retval < 0) {
  2690. ZFCP_LOG_INFO("error: Could not create open unit request for "
  2691. "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
  2692. erp_action->unit->fcp_lun,
  2693. erp_action->unit->port->wwpn,
  2694. zfcp_get_busid_by_adapter(erp_action->adapter));
  2695. goto out;
  2696. }
  2697. sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
  2698. erp_action->fsf_req->sbal_curr, 0);
  2699. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2700. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2701. erp_action->fsf_req->qtcb->header.port_handle =
  2702. erp_action->port->handle;
  2703. erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
  2704. erp_action->unit->fcp_lun;
  2705. if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  2706. erp_action->fsf_req->qtcb->bottom.support.option =
  2707. FSF_OPEN_LUN_SUPPRESS_BOXING;
  2708. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
  2709. erp_action->fsf_req->data = (unsigned long) erp_action->unit;
  2710. erp_action->fsf_req->erp_action = erp_action;
  2711. /* start QDIO request for this FSF request */
  2712. retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
  2713. if (retval) {
  2714. ZFCP_LOG_INFO("error: Could not send an open unit request "
  2715. "on the adapter %s, port 0x%016Lx for "
  2716. "unit 0x%016Lx\n",
  2717. zfcp_get_busid_by_adapter(erp_action->adapter),
  2718. erp_action->port->wwpn,
  2719. erp_action->unit->fcp_lun);
  2720. zfcp_fsf_req_free(erp_action->fsf_req);
  2721. erp_action->fsf_req = NULL;
  2722. goto out;
  2723. }
  2724. ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
  2725. "port 0x%016Lx, unit 0x%016Lx)\n",
  2726. zfcp_get_busid_by_adapter(erp_action->adapter),
  2727. erp_action->port->wwpn, erp_action->unit->fcp_lun);
  2728. out:
  2729. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2730. lock_flags);
  2731. return retval;
  2732. }
  2733. /*
  2734. * function: zfcp_fsf_open_unit_handler
  2735. *
  2736. * purpose: is called for finished Open LUN command
  2737. *
  2738. * returns:
  2739. */
  2740. static int
  2741. zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
  2742. {
  2743. int retval = -EINVAL;
  2744. struct zfcp_adapter *adapter;
  2745. struct zfcp_unit *unit;
  2746. struct fsf_qtcb_header *header;
  2747. struct fsf_qtcb_bottom_support *bottom;
  2748. struct fsf_queue_designator *queue_designator;
  2749. u16 subtable, rule, counter;
  2750. int exclusive, readwrite;
  2751. unit = (struct zfcp_unit *) fsf_req->data;
  2752. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2753. /* don't change unit status in our bookkeeping */
  2754. goto skip_fsfstatus;
  2755. }
  2756. adapter = fsf_req->adapter;
  2757. header = &fsf_req->qtcb->header;
  2758. bottom = &fsf_req->qtcb->bottom.support;
  2759. queue_designator = &header->fsf_status_qual.fsf_queue_designator;
  2760. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2761. ZFCP_STATUS_UNIT_SHARED |
  2762. ZFCP_STATUS_UNIT_READONLY,
  2763. &unit->status);
  2764. /* evaluate FSF status in QTCB */
  2765. switch (header->fsf_status) {
  2766. case FSF_PORT_HANDLE_NOT_VALID:
  2767. ZFCP_LOG_INFO("Temporary port identifier 0x%x "
  2768. "for port 0x%016Lx on adapter %s invalid "
  2769. "This may happen occasionally\n",
  2770. unit->port->handle,
  2771. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2772. ZFCP_LOG_DEBUG("status qualifier:\n");
  2773. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2774. (char *) &header->fsf_status_qual,
  2775. sizeof (union fsf_status_qual));
  2776. debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
  2777. zfcp_erp_adapter_reopen(unit->port->adapter, 0);
  2778. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2779. break;
  2780. case FSF_LUN_ALREADY_OPEN:
  2781. ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
  2782. "remote port 0x%016Lx on adapter %s twice.\n",
  2783. unit->fcp_lun,
  2784. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2785. debug_text_exception(adapter->erp_dbf, 0,
  2786. "fsf_s_uopen");
  2787. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2788. break;
  2789. case FSF_ACCESS_DENIED:
  2790. ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
  2791. "remote port 0x%016Lx on adapter %s\n",
  2792. unit->fcp_lun, unit->port->wwpn,
  2793. zfcp_get_busid_by_unit(unit));
  2794. for (counter = 0; counter < 2; counter++) {
  2795. subtable = header->fsf_status_qual.halfword[counter * 2];
  2796. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2797. switch (subtable) {
  2798. case FSF_SQ_CFDC_SUBTABLE_OS:
  2799. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2800. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2801. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2802. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2803. zfcp_act_subtable_type[subtable], rule);
  2804. break;
  2805. }
  2806. }
  2807. debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
  2808. zfcp_erp_unit_access_denied(unit);
  2809. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  2810. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  2811. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2812. break;
  2813. case FSF_PORT_BOXED:
  2814. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  2815. "needs to be reopened\n",
  2816. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2817. debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
  2818. zfcp_erp_port_boxed(unit->port);
  2819. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2820. ZFCP_STATUS_FSFREQ_RETRY;
  2821. break;
  2822. case FSF_LUN_SHARING_VIOLATION:
  2823. if (header->fsf_status_qual.word[0] != 0) {
  2824. ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
  2825. "with WWPN 0x%Lx "
  2826. "connected to the adapter %s "
  2827. "is already in use in LPAR%d, CSS%d\n",
  2828. unit->fcp_lun,
  2829. unit->port->wwpn,
  2830. zfcp_get_busid_by_unit(unit),
  2831. queue_designator->hla,
  2832. queue_designator->cssid);
  2833. } else {
  2834. subtable = header->fsf_status_qual.halfword[4];
  2835. rule = header->fsf_status_qual.halfword[5];
  2836. switch (subtable) {
  2837. case FSF_SQ_CFDC_SUBTABLE_OS:
  2838. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2839. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2840. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2841. ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
  2842. "remote port with WWPN 0x%Lx "
  2843. "connected to the adapter %s "
  2844. "is denied (%s rule %d)\n",
  2845. unit->fcp_lun,
  2846. unit->port->wwpn,
  2847. zfcp_get_busid_by_unit(unit),
  2848. zfcp_act_subtable_type[subtable],
  2849. rule);
  2850. break;
  2851. }
  2852. }
  2853. ZFCP_LOG_DEBUG("status qualifier:\n");
  2854. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2855. (char *) &header->fsf_status_qual,
  2856. sizeof (union fsf_status_qual));
  2857. debug_text_event(adapter->erp_dbf, 2,
  2858. "fsf_s_l_sh_vio");
  2859. zfcp_erp_unit_access_denied(unit);
  2860. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  2861. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  2862. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2863. break;
  2864. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  2865. ZFCP_LOG_INFO("error: The adapter ran out of resources. "
  2866. "There is no handle (temporary port identifier) "
  2867. "available for unit 0x%016Lx on port 0x%016Lx "
  2868. "on adapter %s\n",
  2869. unit->fcp_lun,
  2870. unit->port->wwpn,
  2871. zfcp_get_busid_by_unit(unit));
  2872. debug_text_event(adapter->erp_dbf, 1,
  2873. "fsf_s_max_units");
  2874. zfcp_erp_unit_failed(unit);
  2875. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2876. break;
  2877. case FSF_ADAPTER_STATUS_AVAILABLE:
  2878. switch (header->fsf_status_qual.word[0]) {
  2879. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2880. /* Re-establish link to port */
  2881. debug_text_event(adapter->erp_dbf, 1,
  2882. "fsf_sq_ltest");
  2883. zfcp_test_link(unit->port);
  2884. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2885. break;
  2886. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2887. /* ERP strategy will escalate */
  2888. debug_text_event(adapter->erp_dbf, 1,
  2889. "fsf_sq_ulp");
  2890. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2891. break;
  2892. default:
  2893. ZFCP_LOG_NORMAL
  2894. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2895. header->fsf_status_qual.word[0]);
  2896. debug_text_event(adapter->erp_dbf, 0,
  2897. "fsf_sq_inval:");
  2898. debug_exception(adapter->erp_dbf, 0,
  2899. &header->fsf_status_qual.word[0],
  2900. sizeof (u32));
  2901. }
  2902. break;
  2903. case FSF_INVALID_COMMAND_OPTION:
  2904. ZFCP_LOG_NORMAL(
  2905. "Invalid option 0x%x has been specified "
  2906. "in QTCB bottom sent to the adapter %s\n",
  2907. bottom->option,
  2908. zfcp_get_busid_by_adapter(adapter));
  2909. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2910. retval = -EINVAL;
  2911. break;
  2912. case FSF_GOOD:
  2913. /* save LUN handle assigned by FSF */
  2914. unit->handle = header->lun_handle;
  2915. ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
  2916. "adapter %s opened, port handle 0x%x\n",
  2917. unit->fcp_lun,
  2918. unit->port->wwpn,
  2919. zfcp_get_busid_by_unit(unit),
  2920. unit->handle);
  2921. /* mark unit as open */
  2922. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  2923. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  2924. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  2925. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  2926. exclusive = (bottom->lun_access_info &
  2927. FSF_UNIT_ACCESS_EXCLUSIVE);
  2928. readwrite = (bottom->lun_access_info &
  2929. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  2930. if (!exclusive)
  2931. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  2932. &unit->status);
  2933. if (!readwrite) {
  2934. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  2935. &unit->status);
  2936. ZFCP_LOG_NORMAL("read-only access for unit "
  2937. "(adapter %s, wwpn=0x%016Lx, "
  2938. "fcp_lun=0x%016Lx)\n",
  2939. zfcp_get_busid_by_unit(unit),
  2940. unit->port->wwpn,
  2941. unit->fcp_lun);
  2942. }
  2943. if (exclusive && !readwrite) {
  2944. ZFCP_LOG_NORMAL("exclusive access of read-only "
  2945. "unit not supported\n");
  2946. zfcp_erp_unit_failed(unit);
  2947. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2948. zfcp_erp_unit_shutdown(unit, 0);
  2949. } else if (!exclusive && readwrite) {
  2950. ZFCP_LOG_NORMAL("shared access of read-write "
  2951. "unit not supported\n");
  2952. zfcp_erp_unit_failed(unit);
  2953. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2954. zfcp_erp_unit_shutdown(unit, 0);
  2955. }
  2956. }
  2957. retval = 0;
  2958. break;
  2959. default:
  2960. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2961. "(debug info 0x%x)\n",
  2962. header->fsf_status);
  2963. debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
  2964. debug_exception(adapter->erp_dbf, 0,
  2965. &header->fsf_status, sizeof (u32));
  2966. break;
  2967. }
  2968. skip_fsfstatus:
  2969. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
  2970. return retval;
  2971. }
  2972. /*
  2973. * function: zfcp_fsf_close_unit
  2974. *
  2975. * purpose:
  2976. *
  2977. * returns: address of fsf_req - request successfully initiated
  2978. * NULL -
  2979. *
  2980. * assumptions: This routine does not check whether the associated
  2981. * remote port/lun has already been opened. This should be
  2982. * done by calling routines. Otherwise some status
  2983. * may be presented by FSF
  2984. */
  2985. int
  2986. zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  2987. {
  2988. volatile struct qdio_buffer_element *sbale;
  2989. unsigned long lock_flags;
  2990. int retval = 0;
  2991. /* setup new FSF request */
  2992. retval = zfcp_fsf_req_create(erp_action->adapter,
  2993. FSF_QTCB_CLOSE_LUN,
  2994. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2995. erp_action->adapter->pool.fsf_req_erp,
  2996. &lock_flags, &(erp_action->fsf_req));
  2997. if (retval < 0) {
  2998. ZFCP_LOG_INFO("error: Could not create close unit request for "
  2999. "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
  3000. erp_action->unit->fcp_lun,
  3001. erp_action->port->wwpn,
  3002. zfcp_get_busid_by_adapter(erp_action->adapter));
  3003. goto out;
  3004. }
  3005. sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
  3006. erp_action->fsf_req->sbal_curr, 0);
  3007. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  3008. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  3009. erp_action->fsf_req->qtcb->header.port_handle =
  3010. erp_action->port->handle;
  3011. erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
  3012. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
  3013. erp_action->fsf_req->data = (unsigned long) erp_action->unit;
  3014. erp_action->fsf_req->erp_action = erp_action;
  3015. /* start QDIO request for this FSF request */
  3016. retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
  3017. if (retval) {
  3018. ZFCP_LOG_INFO("error: Could not send a close unit request for "
  3019. "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
  3020. erp_action->unit->fcp_lun,
  3021. erp_action->port->wwpn,
  3022. zfcp_get_busid_by_adapter(erp_action->adapter));
  3023. zfcp_fsf_req_free(erp_action->fsf_req);
  3024. erp_action->fsf_req = NULL;
  3025. goto out;
  3026. }
  3027. ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
  3028. "port 0x%016Lx, unit 0x%016Lx)\n",
  3029. zfcp_get_busid_by_adapter(erp_action->adapter),
  3030. erp_action->port->wwpn, erp_action->unit->fcp_lun);
  3031. out:
  3032. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  3033. lock_flags);
  3034. return retval;
  3035. }
  3036. /*
  3037. * function: zfcp_fsf_close_unit_handler
  3038. *
  3039. * purpose: is called for finished Close LUN FSF command
  3040. *
  3041. * returns:
  3042. */
  3043. static int
  3044. zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
  3045. {
  3046. int retval = -EINVAL;
  3047. struct zfcp_unit *unit;
  3048. unit = (struct zfcp_unit *) fsf_req->data;
  3049. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  3050. /* don't change unit status in our bookkeeping */
  3051. goto skip_fsfstatus;
  3052. }
  3053. /* evaluate FSF status in QTCB */
  3054. switch (fsf_req->qtcb->header.fsf_status) {
  3055. case FSF_PORT_HANDLE_NOT_VALID:
  3056. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  3057. "0x%016Lx on adapter %s invalid. This may "
  3058. "happen in rare circumstances\n",
  3059. unit->port->handle,
  3060. unit->port->wwpn,
  3061. zfcp_get_busid_by_unit(unit));
  3062. ZFCP_LOG_DEBUG("status qualifier:\n");
  3063. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3064. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  3065. sizeof (union fsf_status_qual));
  3066. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3067. "fsf_s_phand_nv");
  3068. zfcp_erp_adapter_reopen(unit->port->adapter, 0);
  3069. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3070. break;
  3071. case FSF_LUN_HANDLE_NOT_VALID:
  3072. ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
  3073. "0x%016Lx on port 0x%016Lx on adapter %s is "
  3074. "invalid. This may happen occasionally.\n",
  3075. unit->handle,
  3076. unit->fcp_lun,
  3077. unit->port->wwpn,
  3078. zfcp_get_busid_by_unit(unit));
  3079. ZFCP_LOG_DEBUG("Status qualifier data:\n");
  3080. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3081. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  3082. sizeof (union fsf_status_qual));
  3083. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3084. "fsf_s_lhand_nv");
  3085. zfcp_erp_port_reopen(unit->port, 0);
  3086. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3087. break;
  3088. case FSF_PORT_BOXED:
  3089. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  3090. "needs to be reopened\n",
  3091. unit->port->wwpn,
  3092. zfcp_get_busid_by_unit(unit));
  3093. debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
  3094. zfcp_erp_port_boxed(unit->port);
  3095. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  3096. ZFCP_STATUS_FSFREQ_RETRY;
  3097. break;
  3098. case FSF_ADAPTER_STATUS_AVAILABLE:
  3099. switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  3100. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  3101. /* re-establish link to port */
  3102. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3103. "fsf_sq_ltest");
  3104. zfcp_test_link(unit->port);
  3105. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3106. break;
  3107. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  3108. /* ERP strategy will escalate */
  3109. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3110. "fsf_sq_ulp");
  3111. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3112. break;
  3113. default:
  3114. ZFCP_LOG_NORMAL
  3115. ("bug: Wrong status qualifier 0x%x arrived.\n",
  3116. fsf_req->qtcb->header.fsf_status_qual.word[0]);
  3117. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  3118. "fsf_sq_inval:");
  3119. debug_exception(
  3120. fsf_req->adapter->erp_dbf, 0,
  3121. &fsf_req->qtcb->header.fsf_status_qual.word[0],
  3122. sizeof (u32));
  3123. break;
  3124. }
  3125. break;
  3126. case FSF_GOOD:
  3127. ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
  3128. "closed, port handle 0x%x\n",
  3129. unit->fcp_lun,
  3130. unit->port->wwpn,
  3131. zfcp_get_busid_by_unit(unit),
  3132. unit->handle);
  3133. /* mark unit as closed */
  3134. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  3135. retval = 0;
  3136. break;
  3137. default:
  3138. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  3139. "(debug info 0x%x)\n",
  3140. fsf_req->qtcb->header.fsf_status);
  3141. debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
  3142. debug_exception(fsf_req->adapter->erp_dbf, 0,
  3143. &fsf_req->qtcb->header.fsf_status,
  3144. sizeof (u32));
  3145. break;
  3146. }
  3147. skip_fsfstatus:
  3148. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
  3149. return retval;
  3150. }
  3151. /**
  3152. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  3153. * @adapter: adapter where scsi command is issued
  3154. * @unit: unit where command is sent to
  3155. * @scsi_cmnd: scsi command to be sent
  3156. * @timer: timer to be started when request is initiated
  3157. * @req_flags: flags for fsf_request
  3158. */
  3159. int
  3160. zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  3161. struct zfcp_unit *unit,
  3162. struct scsi_cmnd * scsi_cmnd,
  3163. struct timer_list *timer, int req_flags)
  3164. {
  3165. struct zfcp_fsf_req *fsf_req = NULL;
  3166. struct fcp_cmnd_iu *fcp_cmnd_iu;
  3167. unsigned int sbtype;
  3168. unsigned long lock_flags;
  3169. int real_bytes = 0;
  3170. int retval = 0;
  3171. int mask;
  3172. /* setup new FSF request */
  3173. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  3174. adapter->pool.fsf_req_scsi,
  3175. &lock_flags, &fsf_req);
  3176. if (unlikely(retval < 0)) {
  3177. ZFCP_LOG_DEBUG("error: Could not create FCP command request "
  3178. "for unit 0x%016Lx on port 0x%016Lx on "
  3179. "adapter %s\n",
  3180. unit->fcp_lun,
  3181. unit->port->wwpn,
  3182. zfcp_get_busid_by_adapter(adapter));
  3183. goto failed_req_create;
  3184. }
  3185. zfcp_unit_get(unit);
  3186. fsf_req->unit = unit;
  3187. /* associate FSF request with SCSI request (for look up on abort) */
  3188. scsi_cmnd->host_scribble = (char *) fsf_req;
  3189. /* associate SCSI command with FSF request */
  3190. fsf_req->data = (unsigned long) scsi_cmnd;
  3191. /* set handles of unit and its parent port in QTCB */
  3192. fsf_req->qtcb->header.lun_handle = unit->handle;
  3193. fsf_req->qtcb->header.port_handle = unit->port->handle;
  3194. /* FSF does not define the structure of the FCP_CMND IU */
  3195. fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3196. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3197. /*
  3198. * set depending on data direction:
  3199. * data direction bits in SBALE (SB Type)
  3200. * data direction bits in QTCB
  3201. * data direction bits in FCP_CMND IU
  3202. */
  3203. switch (scsi_cmnd->sc_data_direction) {
  3204. case DMA_NONE:
  3205. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  3206. /*
  3207. * FIXME(qdio):
  3208. * what is the correct type for commands
  3209. * without 'real' data buffers?
  3210. */
  3211. sbtype = SBAL_FLAGS0_TYPE_READ;
  3212. break;
  3213. case DMA_FROM_DEVICE:
  3214. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  3215. sbtype = SBAL_FLAGS0_TYPE_READ;
  3216. fcp_cmnd_iu->rddata = 1;
  3217. break;
  3218. case DMA_TO_DEVICE:
  3219. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  3220. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  3221. fcp_cmnd_iu->wddata = 1;
  3222. break;
  3223. case DMA_BIDIRECTIONAL:
  3224. default:
  3225. /*
  3226. * dummy, catch this condition earlier
  3227. * in zfcp_scsi_queuecommand
  3228. */
  3229. goto failed_scsi_cmnd;
  3230. }
  3231. /* set FC service class in QTCB (3 per default) */
  3232. fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  3233. /* set FCP_LUN in FCP_CMND IU in QTCB */
  3234. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  3235. mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
  3236. /* set task attributes in FCP_CMND IU in QTCB */
  3237. if (likely((scsi_cmnd->device->simple_tags) ||
  3238. (atomic_test_mask(mask, &unit->status))))
  3239. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  3240. else
  3241. fcp_cmnd_iu->task_attribute = UNTAGGED;
  3242. /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
  3243. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
  3244. fcp_cmnd_iu->add_fcp_cdb_length
  3245. = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  3246. ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
  3247. "additional FCP_CDB length is 0x%x "
  3248. "(shifted right 2 bits)\n",
  3249. scsi_cmnd->cmd_len,
  3250. fcp_cmnd_iu->add_fcp_cdb_length);
  3251. }
  3252. /*
  3253. * copy SCSI CDB (including additional length, if any) to
  3254. * FCP_CDB in FCP_CMND IU in QTCB
  3255. */
  3256. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  3257. /* FCP CMND IU length in QTCB */
  3258. fsf_req->qtcb->bottom.io.fcp_cmnd_length =
  3259. sizeof (struct fcp_cmnd_iu) +
  3260. fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
  3261. /* generate SBALEs from data buffer */
  3262. real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
  3263. if (unlikely(real_bytes < 0)) {
  3264. if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
  3265. ZFCP_LOG_DEBUG(
  3266. "Data did not fit into available buffer(s), "
  3267. "waiting for more...\n");
  3268. retval = -EIO;
  3269. } else {
  3270. ZFCP_LOG_NORMAL("error: No truncation implemented but "
  3271. "required. Shutting down unit "
  3272. "(adapter %s, port 0x%016Lx, "
  3273. "unit 0x%016Lx)\n",
  3274. zfcp_get_busid_by_unit(unit),
  3275. unit->port->wwpn,
  3276. unit->fcp_lun);
  3277. zfcp_erp_unit_shutdown(unit, 0);
  3278. retval = -EINVAL;
  3279. }
  3280. goto no_fit;
  3281. }
  3282. /* set length of FCP data length in FCP_CMND IU in QTCB */
  3283. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  3284. ZFCP_LOG_DEBUG("Sending SCSI command:\n");
  3285. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3286. (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  3287. /*
  3288. * start QDIO request for this FSF request
  3289. * covered by an SBALE)
  3290. */
  3291. retval = zfcp_fsf_req_send(fsf_req, timer);
  3292. if (unlikely(retval < 0)) {
  3293. ZFCP_LOG_INFO("error: Could not send FCP command request "
  3294. "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
  3295. zfcp_get_busid_by_adapter(adapter),
  3296. unit->port->wwpn,
  3297. unit->fcp_lun);
  3298. goto send_failed;
  3299. }
  3300. ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
  3301. "port 0x%016Lx, unit 0x%016Lx)\n",
  3302. zfcp_get_busid_by_adapter(adapter),
  3303. unit->port->wwpn,
  3304. unit->fcp_lun);
  3305. goto success;
  3306. send_failed:
  3307. no_fit:
  3308. failed_scsi_cmnd:
  3309. zfcp_unit_put(unit);
  3310. zfcp_fsf_req_free(fsf_req);
  3311. fsf_req = NULL;
  3312. scsi_cmnd->host_scribble = NULL;
  3313. success:
  3314. failed_req_create:
  3315. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3316. return retval;
  3317. }
  3318. struct zfcp_fsf_req *
  3319. zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
  3320. struct zfcp_unit *unit,
  3321. u8 tm_flags, int req_flags)
  3322. {
  3323. struct zfcp_fsf_req *fsf_req = NULL;
  3324. int retval = 0;
  3325. struct fcp_cmnd_iu *fcp_cmnd_iu;
  3326. unsigned long lock_flags;
  3327. volatile struct qdio_buffer_element *sbale;
  3328. /* setup new FSF request */
  3329. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  3330. adapter->pool.fsf_req_scsi,
  3331. &lock_flags, &fsf_req);
  3332. if (retval < 0) {
  3333. ZFCP_LOG_INFO("error: Could not create FCP command (task "
  3334. "management) request for adapter %s, port "
  3335. " 0x%016Lx, unit 0x%016Lx.\n",
  3336. zfcp_get_busid_by_adapter(adapter),
  3337. unit->port->wwpn, unit->fcp_lun);
  3338. goto out;
  3339. }
  3340. /*
  3341. * Used to decide on proper handler in the return path,
  3342. * could be either zfcp_fsf_send_fcp_command_task_handler or
  3343. * zfcp_fsf_send_fcp_command_task_management_handler */
  3344. fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  3345. /*
  3346. * hold a pointer to the unit being target of this
  3347. * task management request
  3348. */
  3349. fsf_req->data = (unsigned long) unit;
  3350. /* set FSF related fields in QTCB */
  3351. fsf_req->qtcb->header.lun_handle = unit->handle;
  3352. fsf_req->qtcb->header.port_handle = unit->port->handle;
  3353. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  3354. fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  3355. fsf_req->qtcb->bottom.io.fcp_cmnd_length =
  3356. sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
  3357. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  3358. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  3359. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  3360. /* set FCP related fields in FCP_CMND IU in QTCB */
  3361. fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3362. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3363. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  3364. fcp_cmnd_iu->task_management_flags = tm_flags;
  3365. /* start QDIO request for this FSF request */
  3366. zfcp_fsf_start_scsi_er_timer(adapter);
  3367. retval = zfcp_fsf_req_send(fsf_req, NULL);
  3368. if (retval) {
  3369. del_timer(&adapter->scsi_er_timer);
  3370. ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
  3371. "management) on adapter %s, port 0x%016Lx for "
  3372. "unit LUN 0x%016Lx\n",
  3373. zfcp_get_busid_by_adapter(adapter),
  3374. unit->port->wwpn,
  3375. unit->fcp_lun);
  3376. zfcp_fsf_req_free(fsf_req);
  3377. fsf_req = NULL;
  3378. goto out;
  3379. }
  3380. ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
  3381. "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
  3382. "tm_flags=0x%x)\n",
  3383. zfcp_get_busid_by_adapter(adapter),
  3384. unit->port->wwpn,
  3385. unit->fcp_lun,
  3386. tm_flags);
  3387. out:
  3388. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3389. return fsf_req;
  3390. }
  3391. /*
  3392. * function: zfcp_fsf_send_fcp_command_handler
  3393. *
  3394. * purpose: is called for finished Send FCP Command
  3395. *
  3396. * returns:
  3397. */
  3398. static int
  3399. zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
  3400. {
  3401. int retval = -EINVAL;
  3402. struct zfcp_unit *unit;
  3403. struct fsf_qtcb_header *header;
  3404. u16 subtable, rule, counter;
  3405. header = &fsf_req->qtcb->header;
  3406. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  3407. unit = (struct zfcp_unit *) fsf_req->data;
  3408. else
  3409. unit = fsf_req->unit;
  3410. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  3411. /* go directly to calls of special handlers */
  3412. goto skip_fsfstatus;
  3413. }
  3414. /* evaluate FSF status in QTCB */
  3415. switch (header->fsf_status) {
  3416. case FSF_PORT_HANDLE_NOT_VALID:
  3417. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  3418. "0x%016Lx on adapter %s invalid\n",
  3419. unit->port->handle,
  3420. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  3421. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3422. (char *) &header->fsf_status_qual,
  3423. sizeof (union fsf_status_qual));
  3424. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3425. "fsf_s_phand_nv");
  3426. zfcp_erp_adapter_reopen(unit->port->adapter, 0);
  3427. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3428. break;
  3429. case FSF_LUN_HANDLE_NOT_VALID:
  3430. ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
  3431. "0x%016Lx on port 0x%016Lx on adapter %s is "
  3432. "invalid. This may happen occasionally.\n",
  3433. unit->handle,
  3434. unit->fcp_lun,
  3435. unit->port->wwpn,
  3436. zfcp_get_busid_by_unit(unit));
  3437. ZFCP_LOG_NORMAL("Status qualifier data:\n");
  3438. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
  3439. (char *) &header->fsf_status_qual,
  3440. sizeof (union fsf_status_qual));
  3441. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3442. "fsf_s_uhand_nv");
  3443. zfcp_erp_port_reopen(unit->port, 0);
  3444. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3445. break;
  3446. case FSF_HANDLE_MISMATCH:
  3447. ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
  3448. "unexpectedly. (adapter %s, port 0x%016Lx, "
  3449. "unit 0x%016Lx)\n",
  3450. unit->port->handle,
  3451. zfcp_get_busid_by_unit(unit),
  3452. unit->port->wwpn,
  3453. unit->fcp_lun);
  3454. ZFCP_LOG_NORMAL("status qualifier:\n");
  3455. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
  3456. (char *) &header->fsf_status_qual,
  3457. sizeof (union fsf_status_qual));
  3458. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3459. "fsf_s_hand_mis");
  3460. zfcp_erp_adapter_reopen(unit->port->adapter, 0);
  3461. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3462. break;
  3463. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  3464. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  3465. "class %d.\n",
  3466. zfcp_get_busid_by_unit(unit),
  3467. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  3468. /* stop operation for this adapter */
  3469. debug_text_exception(fsf_req->adapter->erp_dbf, 0,
  3470. "fsf_s_class_nsup");
  3471. zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
  3472. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3473. break;
  3474. case FSF_FCPLUN_NOT_VALID:
  3475. ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
  3476. "adapter %s does not have correct unit "
  3477. "handle 0x%x\n",
  3478. unit->fcp_lun,
  3479. unit->port->wwpn,
  3480. zfcp_get_busid_by_unit(unit),
  3481. unit->handle);
  3482. ZFCP_LOG_DEBUG("status qualifier:\n");
  3483. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3484. (char *) &header->fsf_status_qual,
  3485. sizeof (union fsf_status_qual));
  3486. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3487. "fsf_s_fcp_lun_nv");
  3488. zfcp_erp_port_reopen(unit->port, 0);
  3489. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3490. break;
  3491. case FSF_ACCESS_DENIED:
  3492. ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
  3493. "unit 0x%016Lx on port 0x%016Lx on "
  3494. "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
  3495. zfcp_get_busid_by_unit(unit));
  3496. for (counter = 0; counter < 2; counter++) {
  3497. subtable = header->fsf_status_qual.halfword[counter * 2];
  3498. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  3499. switch (subtable) {
  3500. case FSF_SQ_CFDC_SUBTABLE_OS:
  3501. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  3502. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  3503. case FSF_SQ_CFDC_SUBTABLE_LUN:
  3504. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  3505. zfcp_act_subtable_type[subtable], rule);
  3506. break;
  3507. }
  3508. }
  3509. debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
  3510. zfcp_erp_unit_access_denied(unit);
  3511. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3512. break;
  3513. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  3514. ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
  3515. "0x%016Lx on port 0x%016Lx on adapter %s "
  3516. "(debug info %d)\n",
  3517. unit->fcp_lun,
  3518. unit->port->wwpn,
  3519. zfcp_get_busid_by_unit(unit),
  3520. fsf_req->qtcb->bottom.io.data_direction);
  3521. /* stop operation for this adapter */
  3522. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  3523. "fsf_s_dir_ind_nv");
  3524. zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
  3525. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3526. break;
  3527. case FSF_CMND_LENGTH_NOT_VALID:
  3528. ZFCP_LOG_NORMAL
  3529. ("bug: An invalid control-data-block length field "
  3530. "was found in a command for unit 0x%016Lx on port "
  3531. "0x%016Lx on adapter %s " "(debug info %d)\n",
  3532. unit->fcp_lun, unit->port->wwpn,
  3533. zfcp_get_busid_by_unit(unit),
  3534. fsf_req->qtcb->bottom.io.fcp_cmnd_length);
  3535. /* stop operation for this adapter */
  3536. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  3537. "fsf_s_cmd_len_nv");
  3538. zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
  3539. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3540. break;
  3541. case FSF_PORT_BOXED:
  3542. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  3543. "needs to be reopened\n",
  3544. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  3545. debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
  3546. zfcp_erp_port_boxed(unit->port);
  3547. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  3548. ZFCP_STATUS_FSFREQ_RETRY;
  3549. break;
  3550. case FSF_LUN_BOXED:
  3551. ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
  3552. "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
  3553. zfcp_get_busid_by_unit(unit),
  3554. unit->port->wwpn, unit->fcp_lun);
  3555. debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
  3556. zfcp_erp_unit_boxed(unit);
  3557. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  3558. | ZFCP_STATUS_FSFREQ_RETRY;
  3559. break;
  3560. case FSF_ADAPTER_STATUS_AVAILABLE:
  3561. switch (header->fsf_status_qual.word[0]) {
  3562. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  3563. /* re-establish link to port */
  3564. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3565. "fsf_sq_ltest");
  3566. zfcp_test_link(unit->port);
  3567. break;
  3568. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  3569. /* FIXME(hw) need proper specs for proper action */
  3570. /* let scsi stack deal with retries and escalation */
  3571. debug_text_event(fsf_req->adapter->erp_dbf, 1,
  3572. "fsf_sq_ulp");
  3573. break;
  3574. default:
  3575. ZFCP_LOG_NORMAL
  3576. ("Unknown status qualifier 0x%x arrived.\n",
  3577. header->fsf_status_qual.word[0]);
  3578. debug_text_event(fsf_req->adapter->erp_dbf, 0,
  3579. "fsf_sq_inval:");
  3580. debug_exception(fsf_req->adapter->erp_dbf, 0,
  3581. &header->fsf_status_qual.word[0],
  3582. sizeof(u32));
  3583. break;
  3584. }
  3585. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3586. break;
  3587. case FSF_GOOD:
  3588. break;
  3589. case FSF_FCP_RSP_AVAILABLE:
  3590. break;
  3591. default:
  3592. debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
  3593. debug_exception(fsf_req->adapter->erp_dbf, 0,
  3594. &header->fsf_status, sizeof(u32));
  3595. break;
  3596. }
  3597. skip_fsfstatus:
  3598. if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
  3599. retval =
  3600. zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
  3601. } else {
  3602. retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
  3603. fsf_req->unit = NULL;
  3604. zfcp_unit_put(unit);
  3605. }
  3606. return retval;
  3607. }
  3608. /*
  3609. * function: zfcp_fsf_send_fcp_command_task_handler
  3610. *
  3611. * purpose: evaluates FCP_RSP IU
  3612. *
  3613. * returns:
  3614. */
  3615. static int
  3616. zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
  3617. {
  3618. int retval = 0;
  3619. struct scsi_cmnd *scpnt;
  3620. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  3621. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  3622. struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3623. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3624. u32 sns_len;
  3625. char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
  3626. unsigned long flags;
  3627. struct zfcp_unit *unit = fsf_req->unit;
  3628. read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
  3629. scpnt = (struct scsi_cmnd *) fsf_req->data;
  3630. if (unlikely(!scpnt)) {
  3631. ZFCP_LOG_DEBUG
  3632. ("Command with fsf_req %p is not associated to "
  3633. "a scsi command anymore. Aborted?\n", fsf_req);
  3634. goto out;
  3635. }
  3636. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  3637. /* FIXME: (design) mid-layer should handle DID_ABORT like
  3638. * DID_SOFT_ERROR by retrying the request for devices
  3639. * that allow retries.
  3640. */
  3641. ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
  3642. set_host_byte(&scpnt->result, DID_SOFT_ERROR);
  3643. set_driver_byte(&scpnt->result, SUGGEST_RETRY);
  3644. goto skip_fsfstatus;
  3645. }
  3646. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  3647. ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
  3648. set_host_byte(&scpnt->result, DID_ERROR);
  3649. goto skip_fsfstatus;
  3650. }
  3651. /* set message byte of result in SCSI command */
  3652. scpnt->result |= COMMAND_COMPLETE << 8;
  3653. /*
  3654. * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
  3655. * of result in SCSI command
  3656. */
  3657. scpnt->result |= fcp_rsp_iu->scsi_status;
  3658. if (unlikely(fcp_rsp_iu->scsi_status)) {
  3659. /* DEBUG */
  3660. ZFCP_LOG_DEBUG("status for SCSI Command:\n");
  3661. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3662. scpnt->cmnd, scpnt->cmd_len);
  3663. ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
  3664. fcp_rsp_iu->scsi_status);
  3665. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3666. (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
  3667. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3668. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
  3669. fcp_rsp_iu->fcp_sns_len);
  3670. }
  3671. /* check FCP_RSP_INFO */
  3672. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  3673. ZFCP_LOG_DEBUG("rsp_len is valid\n");
  3674. switch (fcp_rsp_info[3]) {
  3675. case RSP_CODE_GOOD:
  3676. /* ok, continue */
  3677. ZFCP_LOG_TRACE("no failure or Task Management "
  3678. "Function complete\n");
  3679. set_host_byte(&scpnt->result, DID_OK);
  3680. break;
  3681. case RSP_CODE_LENGTH_MISMATCH:
  3682. /* hardware bug */
  3683. ZFCP_LOG_NORMAL("bug: FCP response code indictates "
  3684. "that the fibrechannel protocol data "
  3685. "length differs from the burst length. "
  3686. "The problem occured on unit 0x%016Lx "
  3687. "on port 0x%016Lx on adapter %s",
  3688. unit->fcp_lun,
  3689. unit->port->wwpn,
  3690. zfcp_get_busid_by_unit(unit));
  3691. /* dump SCSI CDB as prepared by zfcp */
  3692. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3693. (char *) &fsf_req->qtcb->
  3694. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3695. set_host_byte(&scpnt->result, DID_ERROR);
  3696. goto skip_fsfstatus;
  3697. case RSP_CODE_FIELD_INVALID:
  3698. /* driver or hardware bug */
  3699. ZFCP_LOG_NORMAL("bug: FCP response code indictates "
  3700. "that the fibrechannel protocol data "
  3701. "fields were incorrectly set up. "
  3702. "The problem occured on the unit "
  3703. "0x%016Lx on port 0x%016Lx on "
  3704. "adapter %s",
  3705. unit->fcp_lun,
  3706. unit->port->wwpn,
  3707. zfcp_get_busid_by_unit(unit));
  3708. /* dump SCSI CDB as prepared by zfcp */
  3709. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3710. (char *) &fsf_req->qtcb->
  3711. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3712. set_host_byte(&scpnt->result, DID_ERROR);
  3713. goto skip_fsfstatus;
  3714. case RSP_CODE_RO_MISMATCH:
  3715. /* hardware bug */
  3716. ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
  3717. "that conflicting values for the "
  3718. "fibrechannel payload offset from the "
  3719. "header were found. "
  3720. "The problem occured on unit 0x%016Lx "
  3721. "on port 0x%016Lx on adapter %s.\n",
  3722. unit->fcp_lun,
  3723. unit->port->wwpn,
  3724. zfcp_get_busid_by_unit(unit));
  3725. /* dump SCSI CDB as prepared by zfcp */
  3726. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3727. (char *) &fsf_req->qtcb->
  3728. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3729. set_host_byte(&scpnt->result, DID_ERROR);
  3730. goto skip_fsfstatus;
  3731. default:
  3732. ZFCP_LOG_NORMAL("bug: An invalid FCP response "
  3733. "code was detected for a command. "
  3734. "The problem occured on the unit "
  3735. "0x%016Lx on port 0x%016Lx on "
  3736. "adapter %s (debug info 0x%x)\n",
  3737. unit->fcp_lun,
  3738. unit->port->wwpn,
  3739. zfcp_get_busid_by_unit(unit),
  3740. fcp_rsp_info[3]);
  3741. /* dump SCSI CDB as prepared by zfcp */
  3742. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3743. (char *) &fsf_req->qtcb->
  3744. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3745. set_host_byte(&scpnt->result, DID_ERROR);
  3746. goto skip_fsfstatus;
  3747. }
  3748. }
  3749. /* check for sense data */
  3750. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  3751. sns_len = FSF_FCP_RSP_SIZE -
  3752. sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
  3753. ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
  3754. sns_len);
  3755. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  3756. ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
  3757. SCSI_SENSE_BUFFERSIZE);
  3758. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  3759. ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
  3760. scpnt->result);
  3761. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
  3762. (void *) &scpnt->cmnd, scpnt->cmd_len);
  3763. ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
  3764. fcp_rsp_iu->fcp_sns_len);
  3765. memcpy(&scpnt->sense_buffer,
  3766. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  3767. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
  3768. (void *) &scpnt->sense_buffer, sns_len);
  3769. }
  3770. /* check for overrun */
  3771. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
  3772. ZFCP_LOG_INFO("A data overrun was detected for a command. "
  3773. "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
  3774. "The response data length is "
  3775. "%d, the original length was %d.\n",
  3776. unit->fcp_lun,
  3777. unit->port->wwpn,
  3778. zfcp_get_busid_by_unit(unit),
  3779. fcp_rsp_iu->fcp_resid,
  3780. (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
  3781. }
  3782. /* check for underrun */
  3783. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  3784. ZFCP_LOG_INFO("A data underrun was detected for a command. "
  3785. "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
  3786. "The response data length is "
  3787. "%d, the original length was %d.\n",
  3788. unit->fcp_lun,
  3789. unit->port->wwpn,
  3790. zfcp_get_busid_by_unit(unit),
  3791. fcp_rsp_iu->fcp_resid,
  3792. (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
  3793. scpnt->resid = fcp_rsp_iu->fcp_resid;
  3794. if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
  3795. set_host_byte(&scpnt->result, DID_ERROR);
  3796. }
  3797. skip_fsfstatus:
  3798. ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
  3799. if (scpnt->result != 0)
  3800. zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
  3801. else if (scpnt->retries > 0)
  3802. zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
  3803. else
  3804. zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
  3805. /* cleanup pointer (need this especially for abort) */
  3806. scpnt->host_scribble = NULL;
  3807. /* always call back */
  3808. (scpnt->scsi_done) (scpnt);
  3809. /*
  3810. * We must hold this lock until scsi_done has been called.
  3811. * Otherwise we may call scsi_done after abort regarding this
  3812. * command has completed.
  3813. * Note: scsi_done must not block!
  3814. */
  3815. out:
  3816. read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
  3817. return retval;
  3818. }
  3819. /*
  3820. * function: zfcp_fsf_send_fcp_command_task_management_handler
  3821. *
  3822. * purpose: evaluates FCP_RSP IU
  3823. *
  3824. * returns:
  3825. */
  3826. static int
  3827. zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
  3828. {
  3829. int retval = 0;
  3830. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  3831. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  3832. char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
  3833. struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
  3834. del_timer(&fsf_req->adapter->scsi_er_timer);
  3835. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  3836. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3837. goto skip_fsfstatus;
  3838. }
  3839. /* check FCP_RSP_INFO */
  3840. switch (fcp_rsp_info[3]) {
  3841. case RSP_CODE_GOOD:
  3842. /* ok, continue */
  3843. ZFCP_LOG_DEBUG("no failure or Task Management "
  3844. "Function complete\n");
  3845. break;
  3846. case RSP_CODE_TASKMAN_UNSUPP:
  3847. ZFCP_LOG_NORMAL("bug: A reuested task management function "
  3848. "is not supported on the target device "
  3849. "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
  3850. unit->fcp_lun,
  3851. unit->port->wwpn,
  3852. zfcp_get_busid_by_unit(unit));
  3853. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
  3854. break;
  3855. case RSP_CODE_TASKMAN_FAILED:
  3856. ZFCP_LOG_NORMAL("bug: A reuested task management function "
  3857. "failed to complete successfully. "
  3858. "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
  3859. unit->fcp_lun,
  3860. unit->port->wwpn,
  3861. zfcp_get_busid_by_unit(unit));
  3862. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3863. break;
  3864. default:
  3865. ZFCP_LOG_NORMAL("bug: An invalid FCP response "
  3866. "code was detected for a command. "
  3867. "unit 0x%016Lx, port 0x%016Lx, adapter %s "
  3868. "(debug info 0x%x)\n",
  3869. unit->fcp_lun,
  3870. unit->port->wwpn,
  3871. zfcp_get_busid_by_unit(unit),
  3872. fcp_rsp_info[3]);
  3873. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3874. }
  3875. skip_fsfstatus:
  3876. return retval;
  3877. }
  3878. /*
  3879. * function: zfcp_fsf_control_file
  3880. *
  3881. * purpose: Initiator of the control file upload/download FSF requests
  3882. *
  3883. * returns: 0 - FSF request is successfuly created and queued
  3884. * -EOPNOTSUPP - The FCP adapter does not have Control File support
  3885. * -EINVAL - Invalid direction specified
  3886. * -ENOMEM - Insufficient memory
  3887. * -EPERM - Cannot create FSF request or place it in QDIO queue
  3888. */
  3889. int
  3890. zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  3891. struct zfcp_fsf_req **fsf_req_ptr,
  3892. u32 fsf_command,
  3893. u32 option,
  3894. struct zfcp_sg_list *sg_list)
  3895. {
  3896. struct zfcp_fsf_req *fsf_req;
  3897. struct fsf_qtcb_bottom_support *bottom;
  3898. volatile struct qdio_buffer_element *sbale;
  3899. struct timer_list *timer;
  3900. unsigned long lock_flags;
  3901. int req_flags = 0;
  3902. int direction;
  3903. int retval = 0;
  3904. if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
  3905. ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
  3906. zfcp_get_busid_by_adapter(adapter));
  3907. retval = -EOPNOTSUPP;
  3908. goto out;
  3909. }
  3910. switch (fsf_command) {
  3911. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  3912. direction = SBAL_FLAGS0_TYPE_WRITE;
  3913. if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
  3914. (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
  3915. req_flags = ZFCP_WAIT_FOR_SBAL;
  3916. break;
  3917. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  3918. direction = SBAL_FLAGS0_TYPE_READ;
  3919. break;
  3920. default:
  3921. ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
  3922. retval = -EINVAL;
  3923. goto out;
  3924. }
  3925. timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
  3926. if (!timer) {
  3927. retval = -ENOMEM;
  3928. goto out;
  3929. }
  3930. retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
  3931. NULL, &lock_flags, &fsf_req);
  3932. if (retval < 0) {
  3933. ZFCP_LOG_INFO("error: Could not create FSF request for the "
  3934. "adapter %s\n",
  3935. zfcp_get_busid_by_adapter(adapter));
  3936. retval = -EPERM;
  3937. goto unlock_queue_lock;
  3938. }
  3939. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  3940. sbale[0].flags |= direction;
  3941. bottom = &fsf_req->qtcb->bottom.support;
  3942. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  3943. bottom->option = option;
  3944. if (sg_list->count > 0) {
  3945. int bytes;
  3946. bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
  3947. sg_list->sg, sg_list->count,
  3948. ZFCP_MAX_SBALS_PER_REQ);
  3949. if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
  3950. ZFCP_LOG_INFO(
  3951. "error: Could not create sufficient number of "
  3952. "SBALS for an FSF request to the adapter %s\n",
  3953. zfcp_get_busid_by_adapter(adapter));
  3954. retval = -ENOMEM;
  3955. goto free_fsf_req;
  3956. }
  3957. } else
  3958. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  3959. init_timer(timer);
  3960. timer->function = zfcp_fsf_request_timeout_handler;
  3961. timer->data = (unsigned long) adapter;
  3962. timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
  3963. retval = zfcp_fsf_req_send(fsf_req, timer);
  3964. if (retval < 0) {
  3965. ZFCP_LOG_INFO("initiation of cfdc up/download failed"
  3966. "(adapter %s)\n",
  3967. zfcp_get_busid_by_adapter(adapter));
  3968. retval = -EPERM;
  3969. goto free_fsf_req;
  3970. }
  3971. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3972. ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
  3973. "adapter %s\n",
  3974. fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
  3975. "download" : "upload",
  3976. zfcp_get_busid_by_adapter(adapter));
  3977. wait_event(fsf_req->completion_wq,
  3978. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  3979. *fsf_req_ptr = fsf_req;
  3980. del_timer_sync(timer);
  3981. goto free_timer;
  3982. free_fsf_req:
  3983. zfcp_fsf_req_free(fsf_req);
  3984. unlock_queue_lock:
  3985. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3986. free_timer:
  3987. kfree(timer);
  3988. out:
  3989. return retval;
  3990. }
  3991. /*
  3992. * function: zfcp_fsf_control_file_handler
  3993. *
  3994. * purpose: Handler of the control file upload/download FSF requests
  3995. *
  3996. * returns: 0 - FSF request successfuly processed
  3997. * -EAGAIN - Operation has to be repeated because of a temporary problem
  3998. * -EACCES - There is no permission to execute an operation
  3999. * -EPERM - The control file is not in a right format
  4000. * -EIO - There is a problem with the FCP adapter
  4001. * -EINVAL - Invalid operation
  4002. * -EFAULT - User space memory I/O operation fault
  4003. */
  4004. static int
  4005. zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
  4006. {
  4007. struct zfcp_adapter *adapter = fsf_req->adapter;
  4008. struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
  4009. struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
  4010. int retval = 0;
  4011. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  4012. retval = -EINVAL;
  4013. goto skip_fsfstatus;
  4014. }
  4015. switch (header->fsf_status) {
  4016. case FSF_GOOD:
  4017. ZFCP_LOG_NORMAL(
  4018. "The FSF request has been successfully completed "
  4019. "on the adapter %s\n",
  4020. zfcp_get_busid_by_adapter(adapter));
  4021. break;
  4022. case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
  4023. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
  4024. switch (header->fsf_status_qual.word[0]) {
  4025. case FSF_SQ_CFDC_HARDENED_ON_SE:
  4026. ZFCP_LOG_NORMAL(
  4027. "CFDC on the adapter %s has being "
  4028. "hardened on primary and secondary SE\n",
  4029. zfcp_get_busid_by_adapter(adapter));
  4030. break;
  4031. case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
  4032. ZFCP_LOG_NORMAL(
  4033. "CFDC of the adapter %s could not "
  4034. "be saved on the SE\n",
  4035. zfcp_get_busid_by_adapter(adapter));
  4036. break;
  4037. case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
  4038. ZFCP_LOG_NORMAL(
  4039. "CFDC of the adapter %s could not "
  4040. "be copied to the secondary SE\n",
  4041. zfcp_get_busid_by_adapter(adapter));
  4042. break;
  4043. default:
  4044. ZFCP_LOG_NORMAL(
  4045. "CFDC could not be hardened "
  4046. "on the adapter %s\n",
  4047. zfcp_get_busid_by_adapter(adapter));
  4048. }
  4049. }
  4050. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4051. retval = -EAGAIN;
  4052. break;
  4053. case FSF_AUTHORIZATION_FAILURE:
  4054. ZFCP_LOG_NORMAL(
  4055. "Adapter %s does not accept privileged commands\n",
  4056. zfcp_get_busid_by_adapter(adapter));
  4057. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4058. retval = -EACCES;
  4059. break;
  4060. case FSF_CFDC_ERROR_DETECTED:
  4061. ZFCP_LOG_NORMAL(
  4062. "Error at position %d in the CFDC, "
  4063. "CFDC is discarded by the adapter %s\n",
  4064. header->fsf_status_qual.word[0],
  4065. zfcp_get_busid_by_adapter(adapter));
  4066. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4067. retval = -EPERM;
  4068. break;
  4069. case FSF_CONTROL_FILE_UPDATE_ERROR:
  4070. ZFCP_LOG_NORMAL(
  4071. "Adapter %s cannot harden the control file, "
  4072. "file is discarded\n",
  4073. zfcp_get_busid_by_adapter(adapter));
  4074. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4075. retval = -EIO;
  4076. break;
  4077. case FSF_CONTROL_FILE_TOO_LARGE:
  4078. ZFCP_LOG_NORMAL(
  4079. "Control file is too large, file is discarded "
  4080. "by the adapter %s\n",
  4081. zfcp_get_busid_by_adapter(adapter));
  4082. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4083. retval = -EIO;
  4084. break;
  4085. case FSF_ACCESS_CONFLICT_DETECTED:
  4086. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
  4087. ZFCP_LOG_NORMAL(
  4088. "CFDC has been discarded by the adapter %s, "
  4089. "because activation would impact "
  4090. "%d active connection(s)\n",
  4091. zfcp_get_busid_by_adapter(adapter),
  4092. header->fsf_status_qual.word[0]);
  4093. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4094. retval = -EIO;
  4095. break;
  4096. case FSF_CONFLICTS_OVERRULED:
  4097. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
  4098. ZFCP_LOG_NORMAL(
  4099. "CFDC has been activated on the adapter %s, "
  4100. "but activation has impacted "
  4101. "%d active connection(s)\n",
  4102. zfcp_get_busid_by_adapter(adapter),
  4103. header->fsf_status_qual.word[0]);
  4104. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4105. retval = -EIO;
  4106. break;
  4107. case FSF_UNKNOWN_OP_SUBTYPE:
  4108. ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
  4109. "op_subtype=0x%x)\n",
  4110. zfcp_get_busid_by_adapter(adapter),
  4111. bottom->operation_subtype);
  4112. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4113. retval = -EINVAL;
  4114. break;
  4115. case FSF_INVALID_COMMAND_OPTION:
  4116. ZFCP_LOG_NORMAL(
  4117. "Invalid option 0x%x has been specified "
  4118. "in QTCB bottom sent to the adapter %s\n",
  4119. bottom->option,
  4120. zfcp_get_busid_by_adapter(adapter));
  4121. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4122. retval = -EINVAL;
  4123. break;
  4124. default:
  4125. ZFCP_LOG_NORMAL(
  4126. "bug: An unknown/unexpected FSF status 0x%08x "
  4127. "was presented on the adapter %s\n",
  4128. header->fsf_status,
  4129. zfcp_get_busid_by_adapter(adapter));
  4130. debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
  4131. debug_exception(fsf_req->adapter->erp_dbf, 0,
  4132. &header->fsf_status_qual.word[0], sizeof(u32));
  4133. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4134. retval = -EINVAL;
  4135. break;
  4136. }
  4137. skip_fsfstatus:
  4138. return retval;
  4139. }
  4140. static inline int
  4141. zfcp_fsf_req_sbal_check(unsigned long *flags,
  4142. struct zfcp_qdio_queue *queue, int needed)
  4143. {
  4144. write_lock_irqsave(&queue->queue_lock, *flags);
  4145. if (likely(atomic_read(&queue->free_count) >= needed))
  4146. return 1;
  4147. write_unlock_irqrestore(&queue->queue_lock, *flags);
  4148. return 0;
  4149. }
  4150. /*
  4151. * set qtcb pointer in fsf_req and initialize QTCB
  4152. */
  4153. static inline void
  4154. zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
  4155. {
  4156. if (likely(fsf_req->qtcb != NULL)) {
  4157. fsf_req->qtcb->prefix.req_seq_no =
  4158. fsf_req->adapter->fsf_req_seq_no;
  4159. fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
  4160. fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
  4161. fsf_req->qtcb->prefix.qtcb_type =
  4162. fsf_qtcb_type[fsf_req->fsf_command];
  4163. fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
  4164. fsf_req->qtcb->header.req_handle = fsf_req->req_id;
  4165. fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
  4166. }
  4167. }
  4168. /**
  4169. * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
  4170. * @adapter: adapter for which request queue is examined
  4171. * @req_flags: flags indicating whether to wait for needed SBAL or not
  4172. * @lock_flags: lock_flags if queue_lock is taken
  4173. * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
  4174. * Locks: lock adapter->request_queue->queue_lock on success
  4175. */
  4176. static int
  4177. zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
  4178. unsigned long *lock_flags)
  4179. {
  4180. long ret;
  4181. struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
  4182. if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
  4183. ret = wait_event_interruptible_timeout(adapter->request_wq,
  4184. zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
  4185. ZFCP_SBAL_TIMEOUT);
  4186. if (ret < 0)
  4187. return ret;
  4188. if (!ret)
  4189. return -EIO;
  4190. } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
  4191. return -EIO;
  4192. return 0;
  4193. }
  4194. /*
  4195. * function: zfcp_fsf_req_create
  4196. *
  4197. * purpose: create an FSF request at the specified adapter and
  4198. * setup common fields
  4199. *
  4200. * returns: -ENOMEM if there was insufficient memory for a request
  4201. * -EIO if no qdio buffers could be allocate to the request
  4202. * -EINVAL/-EPERM on bug conditions in req_dequeue
  4203. * 0 in success
  4204. *
  4205. * note: The created request is returned by reference.
  4206. *
  4207. * locks: lock of concerned request queue must not be held,
  4208. * but is held on completion (write, irqsave)
  4209. */
  4210. int
  4211. zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
  4212. mempool_t *pool, unsigned long *lock_flags,
  4213. struct zfcp_fsf_req **fsf_req_p)
  4214. {
  4215. volatile struct qdio_buffer_element *sbale;
  4216. struct zfcp_fsf_req *fsf_req = NULL;
  4217. unsigned long flags;
  4218. int ret = 0;
  4219. struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
  4220. /* allocate new FSF request */
  4221. fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
  4222. if (unlikely(NULL == fsf_req)) {
  4223. ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
  4224. "the outbound (send) queue.\n");
  4225. ret = -ENOMEM;
  4226. goto failed_fsf_req;
  4227. }
  4228. fsf_req->adapter = adapter;
  4229. fsf_req->fsf_command = fsf_cmd;
  4230. INIT_LIST_HEAD(&fsf_req->list);
  4231. /* unique request id */
  4232. spin_lock_irqsave(&adapter->req_list_lock, flags);
  4233. fsf_req->req_id = adapter->req_no++;
  4234. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  4235. zfcp_fsf_req_qtcb_init(fsf_req);
  4236. /* initialize waitqueue which may be used to wait on
  4237. this request completion */
  4238. init_waitqueue_head(&fsf_req->completion_wq);
  4239. ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
  4240. if(ret < 0) {
  4241. goto failed_sbals;
  4242. }
  4243. /*
  4244. * We hold queue_lock here. Check if QDIOUP is set and let request fail
  4245. * if it is not set (see also *_open_qdio and *_close_qdio).
  4246. */
  4247. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  4248. write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
  4249. ret = -EIO;
  4250. goto failed_sbals;
  4251. }
  4252. if (fsf_req->qtcb) {
  4253. fsf_req->seq_no = adapter->fsf_req_seq_no;
  4254. fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  4255. }
  4256. fsf_req->sbal_number = 1;
  4257. fsf_req->sbal_first = req_queue->free_index;
  4258. fsf_req->sbal_curr = req_queue->free_index;
  4259. fsf_req->sbale_curr = 1;
  4260. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
  4261. fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  4262. }
  4263. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  4264. /* setup common SBALE fields */
  4265. sbale[0].addr = (void *) fsf_req->req_id;
  4266. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  4267. if (likely(fsf_req->qtcb != NULL)) {
  4268. sbale[1].addr = (void *) fsf_req->qtcb;
  4269. sbale[1].length = sizeof(struct fsf_qtcb);
  4270. }
  4271. ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
  4272. fsf_req->sbal_number, fsf_req->sbal_first);
  4273. goto success;
  4274. failed_sbals:
  4275. /* dequeue new FSF request previously enqueued */
  4276. zfcp_fsf_req_free(fsf_req);
  4277. fsf_req = NULL;
  4278. failed_fsf_req:
  4279. write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
  4280. success:
  4281. *fsf_req_p = fsf_req;
  4282. return ret;
  4283. }
  4284. /*
  4285. * function: zfcp_fsf_req_send
  4286. *
  4287. * purpose: start transfer of FSF request via QDIO
  4288. *
  4289. * returns: 0 - request transfer succesfully started
  4290. * !0 - start of request transfer failed
  4291. */
  4292. static int
  4293. zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
  4294. {
  4295. struct zfcp_adapter *adapter;
  4296. struct zfcp_qdio_queue *req_queue;
  4297. volatile struct qdio_buffer_element *sbale;
  4298. int inc_seq_no;
  4299. int new_distance_from_int;
  4300. u64 dbg_tmp[2];
  4301. int retval = 0;
  4302. adapter = fsf_req->adapter;
  4303. req_queue = &adapter->request_queue,
  4304. /* FIXME(debug): remove it later */
  4305. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
  4306. ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
  4307. ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
  4308. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
  4309. sbale[1].length);
  4310. /* put allocated FSF request into hash table */
  4311. spin_lock(&adapter->req_list_lock);
  4312. zfcp_reqlist_add(adapter, fsf_req);
  4313. spin_unlock(&adapter->req_list_lock);
  4314. inc_seq_no = (fsf_req->qtcb != NULL);
  4315. /* figure out expiration time of timeout and start timeout */
  4316. if (unlikely(timer)) {
  4317. timer->expires += jiffies;
  4318. add_timer(timer);
  4319. }
  4320. ZFCP_LOG_TRACE("request queue of adapter %s: "
  4321. "next free SBAL is %i, %i free SBALs\n",
  4322. zfcp_get_busid_by_adapter(adapter),
  4323. req_queue->free_index,
  4324. atomic_read(&req_queue->free_count));
  4325. ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
  4326. "index_in_queue=%i, count=%i, buffers=%p\n",
  4327. zfcp_get_busid_by_adapter(adapter),
  4328. QDIO_FLAG_SYNC_OUTPUT,
  4329. 0, fsf_req->sbal_first, fsf_req->sbal_number,
  4330. &req_queue->buffer[fsf_req->sbal_first]);
  4331. /*
  4332. * adjust the number of free SBALs in request queue as well as
  4333. * position of first one
  4334. */
  4335. atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
  4336. ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
  4337. req_queue->free_index += fsf_req->sbal_number; /* increase */
  4338. req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
  4339. new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
  4340. fsf_req->issued = get_clock();
  4341. retval = do_QDIO(adapter->ccw_device,
  4342. QDIO_FLAG_SYNC_OUTPUT,
  4343. 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
  4344. dbg_tmp[0] = (unsigned long) sbale[0].addr;
  4345. dbg_tmp[1] = (u64) retval;
  4346. debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
  4347. if (unlikely(retval)) {
  4348. /* Queues are down..... */
  4349. retval = -EIO;
  4350. /*
  4351. * FIXME(potential race):
  4352. * timer might be expired (absolutely unlikely)
  4353. */
  4354. if (timer)
  4355. del_timer(timer);
  4356. spin_lock(&adapter->req_list_lock);
  4357. zfcp_reqlist_remove(adapter, fsf_req->req_id);
  4358. spin_unlock(&adapter->req_list_lock);
  4359. /* undo changes in request queue made for this request */
  4360. zfcp_qdio_zero_sbals(req_queue->buffer,
  4361. fsf_req->sbal_first, fsf_req->sbal_number);
  4362. atomic_add(fsf_req->sbal_number, &req_queue->free_count);
  4363. req_queue->free_index -= fsf_req->sbal_number;
  4364. req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
  4365. req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
  4366. zfcp_erp_adapter_reopen(adapter, 0);
  4367. } else {
  4368. req_queue->distance_from_int = new_distance_from_int;
  4369. /*
  4370. * increase FSF sequence counter -
  4371. * this must only be done for request successfully enqueued to
  4372. * QDIO this rejected requests may be cleaned up by calling
  4373. * routines resulting in missing sequence counter values
  4374. * otherwise,
  4375. */
  4376. /* Don't increase for unsolicited status */
  4377. if (inc_seq_no)
  4378. adapter->fsf_req_seq_no++;
  4379. /* count FSF requests pending */
  4380. atomic_inc(&adapter->reqs_active);
  4381. }
  4382. return retval;
  4383. }
  4384. #undef ZFCP_LOG_AREA