zfcp_fsf.c 145 KB

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