zfcp_fsf.c 137 KB

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