zfcp_fsf.c 150 KB

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