zfcp_fsf.c 150 KB

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