zfcp_fsf.c 151 KB

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