zfcp_fsf.c 145 KB

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