zfcp_fsf.c 152 KB

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