zfcp_fsf.c 150 KB

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