zfcp_fsf.c 149 KB

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