zfcp_fsf.c 151 KB

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