zfcp_fsf.c 146 KB

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