qla_os.c 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/kobject.h>
  14. #include <linux/slab.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/scsicam.h>
  17. #include <scsi/scsi_transport.h>
  18. #include <scsi/scsi_transport_fc.h>
  19. /*
  20. * Driver version
  21. */
  22. char qla2x00_version_str[40];
  23. static int apidev_major;
  24. /*
  25. * SRB allocation cache
  26. */
  27. static struct kmem_cache *srb_cachep;
  28. /*
  29. * CT6 CTX allocation cache
  30. */
  31. static struct kmem_cache *ctx_cachep;
  32. /*
  33. * error level for logging
  34. */
  35. int ql_errlev = ql_log_all;
  36. int ql2xlogintimeout = 20;
  37. module_param(ql2xlogintimeout, int, S_IRUGO);
  38. MODULE_PARM_DESC(ql2xlogintimeout,
  39. "Login timeout value in seconds.");
  40. int qlport_down_retry;
  41. module_param(qlport_down_retry, int, S_IRUGO);
  42. MODULE_PARM_DESC(qlport_down_retry,
  43. "Maximum number of command retries to a port that returns "
  44. "a PORT-DOWN status.");
  45. int ql2xplogiabsentdevice;
  46. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  47. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  48. "Option to enable PLOGI to devices that are not present after "
  49. "a Fabric scan. This is needed for several broken switches. "
  50. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  51. int ql2xloginretrycount = 0;
  52. module_param(ql2xloginretrycount, int, S_IRUGO);
  53. MODULE_PARM_DESC(ql2xloginretrycount,
  54. "Specify an alternate value for the NVRAM login retry count.");
  55. int ql2xallocfwdump = 1;
  56. module_param(ql2xallocfwdump, int, S_IRUGO);
  57. MODULE_PARM_DESC(ql2xallocfwdump,
  58. "Option to enable allocation of memory for a firmware dump "
  59. "during HBA initialization. Memory allocation requirements "
  60. "vary by ISP type. Default is 1 - allocate memory.");
  61. int ql2xextended_error_logging;
  62. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  63. MODULE_PARM_DESC(ql2xextended_error_logging,
  64. "Option to enable extended error logging,\n"
  65. "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
  66. "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
  67. "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
  68. "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
  69. "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
  70. "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
  71. "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
  72. "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
  73. "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
  74. "\t\tDo LOGICAL OR of the value to enable more than one level");
  75. int ql2xshiftctondsd = 6;
  76. module_param(ql2xshiftctondsd, int, S_IRUGO);
  77. MODULE_PARM_DESC(ql2xshiftctondsd,
  78. "Set to control shifting of command type processing "
  79. "based on total number of SG elements.");
  80. static void qla2x00_free_device(scsi_qla_host_t *);
  81. int ql2xfdmienable=1;
  82. module_param(ql2xfdmienable, int, S_IRUGO);
  83. MODULE_PARM_DESC(ql2xfdmienable,
  84. "Enables FDMI registrations. "
  85. "0 - no FDMI. Default is 1 - perform FDMI.");
  86. #define MAX_Q_DEPTH 32
  87. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  88. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  89. MODULE_PARM_DESC(ql2xmaxqdepth,
  90. "Maximum queue depth to report for target devices.");
  91. /* Do not change the value of this after module load */
  92. int ql2xenabledif = 0;
  93. module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR);
  94. MODULE_PARM_DESC(ql2xenabledif,
  95. " Enable T10-CRC-DIF "
  96. " Default is 0 - No DIF Support. 1 - Enable it"
  97. ", 2 - Enable DIF for all types, except Type 0.");
  98. int ql2xenablehba_err_chk = 2;
  99. module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
  100. MODULE_PARM_DESC(ql2xenablehba_err_chk,
  101. " Enable T10-CRC-DIF Error isolation by HBA:\n"
  102. " Default is 1.\n"
  103. " 0 -- Error isolation disabled\n"
  104. " 1 -- Error isolation enabled only for DIX Type 0\n"
  105. " 2 -- Error isolation enabled for all Types\n");
  106. int ql2xiidmaenable=1;
  107. module_param(ql2xiidmaenable, int, S_IRUGO);
  108. MODULE_PARM_DESC(ql2xiidmaenable,
  109. "Enables iIDMA settings "
  110. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  111. int ql2xmaxqueues = 1;
  112. module_param(ql2xmaxqueues, int, S_IRUGO);
  113. MODULE_PARM_DESC(ql2xmaxqueues,
  114. "Enables MQ settings "
  115. "Default is 1 for single queue. Set it to number "
  116. "of queues in MQ mode.");
  117. int ql2xmultique_tag;
  118. module_param(ql2xmultique_tag, int, S_IRUGO);
  119. MODULE_PARM_DESC(ql2xmultique_tag,
  120. "Enables CPU affinity settings for the driver "
  121. "Default is 0 for no affinity of request and response IO. "
  122. "Set it to 1 to turn on the cpu affinity.");
  123. int ql2xfwloadbin;
  124. module_param(ql2xfwloadbin, int, S_IRUGO);
  125. MODULE_PARM_DESC(ql2xfwloadbin,
  126. "Option to specify location from which to load ISP firmware:.\n"
  127. " 2 -- load firmware via the request_firmware() (hotplug).\n"
  128. " interface.\n"
  129. " 1 -- load firmware from flash.\n"
  130. " 0 -- use default semantics.\n");
  131. int ql2xetsenable;
  132. module_param(ql2xetsenable, int, S_IRUGO);
  133. MODULE_PARM_DESC(ql2xetsenable,
  134. "Enables firmware ETS burst."
  135. "Default is 0 - skip ETS enablement.");
  136. int ql2xdbwr = 1;
  137. module_param(ql2xdbwr, int, S_IRUGO);
  138. MODULE_PARM_DESC(ql2xdbwr,
  139. "Option to specify scheme for request queue posting.\n"
  140. " 0 -- Regular doorbell.\n"
  141. " 1 -- CAMRAM doorbell (faster).\n");
  142. int ql2xtargetreset = 1;
  143. module_param(ql2xtargetreset, int, S_IRUGO);
  144. MODULE_PARM_DESC(ql2xtargetreset,
  145. "Enable target reset."
  146. "Default is 1 - use hw defaults.");
  147. int ql2xgffidenable;
  148. module_param(ql2xgffidenable, int, S_IRUGO);
  149. MODULE_PARM_DESC(ql2xgffidenable,
  150. "Enables GFF_ID checks of port type. "
  151. "Default is 0 - Do not use GFF_ID information.");
  152. int ql2xasynctmfenable;
  153. module_param(ql2xasynctmfenable, int, S_IRUGO);
  154. MODULE_PARM_DESC(ql2xasynctmfenable,
  155. "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
  156. "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
  157. int ql2xdontresethba;
  158. module_param(ql2xdontresethba, int, S_IRUGO);
  159. MODULE_PARM_DESC(ql2xdontresethba,
  160. "Option to specify reset behaviour.\n"
  161. " 0 (Default) -- Reset on failure.\n"
  162. " 1 -- Do not reset on failure.\n");
  163. uint ql2xmaxlun = MAX_LUNS;
  164. module_param(ql2xmaxlun, uint, S_IRUGO);
  165. MODULE_PARM_DESC(ql2xmaxlun,
  166. "Defines the maximum LU number to register with the SCSI "
  167. "midlayer. Default is 65535.");
  168. /*
  169. * SCSI host template entry points
  170. */
  171. static int qla2xxx_slave_configure(struct scsi_device * device);
  172. static int qla2xxx_slave_alloc(struct scsi_device *);
  173. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  174. static void qla2xxx_scan_start(struct Scsi_Host *);
  175. static void qla2xxx_slave_destroy(struct scsi_device *);
  176. static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  177. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  178. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  179. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  180. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  181. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  182. static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
  183. static int qla2x00_change_queue_type(struct scsi_device *, int);
  184. struct scsi_host_template qla2xxx_driver_template = {
  185. .module = THIS_MODULE,
  186. .name = QLA2XXX_DRIVER_NAME,
  187. .queuecommand = qla2xxx_queuecommand,
  188. .eh_abort_handler = qla2xxx_eh_abort,
  189. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  190. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  191. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  192. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  193. .slave_configure = qla2xxx_slave_configure,
  194. .slave_alloc = qla2xxx_slave_alloc,
  195. .slave_destroy = qla2xxx_slave_destroy,
  196. .scan_finished = qla2xxx_scan_finished,
  197. .scan_start = qla2xxx_scan_start,
  198. .change_queue_depth = qla2x00_change_queue_depth,
  199. .change_queue_type = qla2x00_change_queue_type,
  200. .this_id = -1,
  201. .cmd_per_lun = 3,
  202. .use_clustering = ENABLE_CLUSTERING,
  203. .sg_tablesize = SG_ALL,
  204. .max_sectors = 0xFFFF,
  205. .shost_attrs = qla2x00_host_attrs,
  206. };
  207. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  208. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  209. /* TODO Convert to inlines
  210. *
  211. * Timer routines
  212. */
  213. __inline__ void
  214. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  215. {
  216. init_timer(&vha->timer);
  217. vha->timer.expires = jiffies + interval * HZ;
  218. vha->timer.data = (unsigned long)vha;
  219. vha->timer.function = (void (*)(unsigned long))func;
  220. add_timer(&vha->timer);
  221. vha->timer_active = 1;
  222. }
  223. static inline void
  224. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  225. {
  226. /* Currently used for 82XX only. */
  227. if (vha->device_flags & DFLG_DEV_FAILED) {
  228. ql_dbg(ql_dbg_timer, vha, 0x600d,
  229. "Device in a failed state, returning.\n");
  230. return;
  231. }
  232. mod_timer(&vha->timer, jiffies + interval * HZ);
  233. }
  234. static __inline__ void
  235. qla2x00_stop_timer(scsi_qla_host_t *vha)
  236. {
  237. del_timer_sync(&vha->timer);
  238. vha->timer_active = 0;
  239. }
  240. static int qla2x00_do_dpc(void *data);
  241. static void qla2x00_rst_aen(scsi_qla_host_t *);
  242. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  243. struct req_que **, struct rsp_que **);
  244. static void qla2x00_free_fw_dump(struct qla_hw_data *);
  245. static void qla2x00_mem_free(struct qla_hw_data *);
  246. static void qla2x00_sp_free_dma(srb_t *);
  247. /* -------------------------------------------------------------------------- */
  248. static int qla2x00_alloc_queues(struct qla_hw_data *ha)
  249. {
  250. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  251. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  252. GFP_KERNEL);
  253. if (!ha->req_q_map) {
  254. ql_log(ql_log_fatal, vha, 0x003b,
  255. "Unable to allocate memory for request queue ptrs.\n");
  256. goto fail_req_map;
  257. }
  258. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  259. GFP_KERNEL);
  260. if (!ha->rsp_q_map) {
  261. ql_log(ql_log_fatal, vha, 0x003c,
  262. "Unable to allocate memory for response queue ptrs.\n");
  263. goto fail_rsp_map;
  264. }
  265. set_bit(0, ha->rsp_qid_map);
  266. set_bit(0, ha->req_qid_map);
  267. return 1;
  268. fail_rsp_map:
  269. kfree(ha->req_q_map);
  270. ha->req_q_map = NULL;
  271. fail_req_map:
  272. return -ENOMEM;
  273. }
  274. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  275. {
  276. if (req && req->ring)
  277. dma_free_coherent(&ha->pdev->dev,
  278. (req->length + 1) * sizeof(request_t),
  279. req->ring, req->dma);
  280. kfree(req);
  281. req = NULL;
  282. }
  283. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  284. {
  285. if (rsp && rsp->ring)
  286. dma_free_coherent(&ha->pdev->dev,
  287. (rsp->length + 1) * sizeof(response_t),
  288. rsp->ring, rsp->dma);
  289. kfree(rsp);
  290. rsp = NULL;
  291. }
  292. static void qla2x00_free_queues(struct qla_hw_data *ha)
  293. {
  294. struct req_que *req;
  295. struct rsp_que *rsp;
  296. int cnt;
  297. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  298. req = ha->req_q_map[cnt];
  299. qla2x00_free_req_que(ha, req);
  300. }
  301. kfree(ha->req_q_map);
  302. ha->req_q_map = NULL;
  303. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  304. rsp = ha->rsp_q_map[cnt];
  305. qla2x00_free_rsp_que(ha, rsp);
  306. }
  307. kfree(ha->rsp_q_map);
  308. ha->rsp_q_map = NULL;
  309. }
  310. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  311. {
  312. uint16_t options = 0;
  313. int ques, req, ret;
  314. struct qla_hw_data *ha = vha->hw;
  315. if (!(ha->fw_attributes & BIT_6)) {
  316. ql_log(ql_log_warn, vha, 0x00d8,
  317. "Firmware is not multi-queue capable.\n");
  318. goto fail;
  319. }
  320. if (ql2xmultique_tag) {
  321. /* create a request queue for IO */
  322. options |= BIT_7;
  323. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  324. QLA_DEFAULT_QUE_QOS);
  325. if (!req) {
  326. ql_log(ql_log_warn, vha, 0x00e0,
  327. "Failed to create request queue.\n");
  328. goto fail;
  329. }
  330. ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
  331. vha->req = ha->req_q_map[req];
  332. options |= BIT_1;
  333. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  334. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  335. if (!ret) {
  336. ql_log(ql_log_warn, vha, 0x00e8,
  337. "Failed to create response queue.\n");
  338. goto fail2;
  339. }
  340. }
  341. ha->flags.cpu_affinity_enabled = 1;
  342. ql_dbg(ql_dbg_multiq, vha, 0xc007,
  343. "CPU affinity mode enalbed, "
  344. "no. of response queues:%d no. of request queues:%d.\n",
  345. ha->max_rsp_queues, ha->max_req_queues);
  346. ql_dbg(ql_dbg_init, vha, 0x00e9,
  347. "CPU affinity mode enalbed, "
  348. "no. of response queues:%d no. of request queues:%d.\n",
  349. ha->max_rsp_queues, ha->max_req_queues);
  350. }
  351. return 0;
  352. fail2:
  353. qla25xx_delete_queues(vha);
  354. destroy_workqueue(ha->wq);
  355. ha->wq = NULL;
  356. fail:
  357. ha->mqenable = 0;
  358. kfree(ha->req_q_map);
  359. kfree(ha->rsp_q_map);
  360. ha->max_req_queues = ha->max_rsp_queues = 1;
  361. return 1;
  362. }
  363. static char *
  364. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  365. {
  366. struct qla_hw_data *ha = vha->hw;
  367. static char *pci_bus_modes[] = {
  368. "33", "66", "100", "133",
  369. };
  370. uint16_t pci_bus;
  371. strcpy(str, "PCI");
  372. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  373. if (pci_bus) {
  374. strcat(str, "-X (");
  375. strcat(str, pci_bus_modes[pci_bus]);
  376. } else {
  377. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  378. strcat(str, " (");
  379. strcat(str, pci_bus_modes[pci_bus]);
  380. }
  381. strcat(str, " MHz)");
  382. return (str);
  383. }
  384. static char *
  385. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  386. {
  387. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  388. struct qla_hw_data *ha = vha->hw;
  389. uint32_t pci_bus;
  390. int pcie_reg;
  391. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  392. if (pcie_reg) {
  393. char lwstr[6];
  394. uint16_t pcie_lstat, lspeed, lwidth;
  395. pcie_reg += 0x12;
  396. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  397. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  398. lwidth = (pcie_lstat &
  399. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  400. strcpy(str, "PCIe (");
  401. if (lspeed == 1)
  402. strcat(str, "2.5GT/s ");
  403. else if (lspeed == 2)
  404. strcat(str, "5.0GT/s ");
  405. else
  406. strcat(str, "<unknown> ");
  407. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  408. strcat(str, lwstr);
  409. return str;
  410. }
  411. strcpy(str, "PCI");
  412. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  413. if (pci_bus == 0 || pci_bus == 8) {
  414. strcat(str, " (");
  415. strcat(str, pci_bus_modes[pci_bus >> 3]);
  416. } else {
  417. strcat(str, "-X ");
  418. if (pci_bus & BIT_2)
  419. strcat(str, "Mode 2");
  420. else
  421. strcat(str, "Mode 1");
  422. strcat(str, " (");
  423. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  424. }
  425. strcat(str, " MHz)");
  426. return str;
  427. }
  428. static char *
  429. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  430. {
  431. char un_str[10];
  432. struct qla_hw_data *ha = vha->hw;
  433. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  434. ha->fw_minor_version,
  435. ha->fw_subminor_version);
  436. if (ha->fw_attributes & BIT_9) {
  437. strcat(str, "FLX");
  438. return (str);
  439. }
  440. switch (ha->fw_attributes & 0xFF) {
  441. case 0x7:
  442. strcat(str, "EF");
  443. break;
  444. case 0x17:
  445. strcat(str, "TP");
  446. break;
  447. case 0x37:
  448. strcat(str, "IP");
  449. break;
  450. case 0x77:
  451. strcat(str, "VI");
  452. break;
  453. default:
  454. sprintf(un_str, "(%x)", ha->fw_attributes);
  455. strcat(str, un_str);
  456. break;
  457. }
  458. if (ha->fw_attributes & 0x100)
  459. strcat(str, "X");
  460. return (str);
  461. }
  462. static char *
  463. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  464. {
  465. struct qla_hw_data *ha = vha->hw;
  466. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  467. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  468. return str;
  469. }
  470. static inline srb_t *
  471. qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
  472. struct scsi_cmnd *cmd)
  473. {
  474. srb_t *sp;
  475. struct qla_hw_data *ha = vha->hw;
  476. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  477. if (!sp) {
  478. ql_log(ql_log_warn, vha, 0x3006,
  479. "Memory allocation failed for sp.\n");
  480. return sp;
  481. }
  482. atomic_set(&sp->ref_count, 1);
  483. sp->fcport = fcport;
  484. sp->cmd = cmd;
  485. sp->flags = 0;
  486. CMD_SP(cmd) = (void *)sp;
  487. sp->ctx = NULL;
  488. return sp;
  489. }
  490. static int
  491. qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  492. {
  493. scsi_qla_host_t *vha = shost_priv(host);
  494. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  495. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  496. struct qla_hw_data *ha = vha->hw;
  497. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  498. srb_t *sp;
  499. int rval;
  500. if (ha->flags.eeh_busy) {
  501. if (ha->flags.pci_channel_io_perm_failure) {
  502. ql_dbg(ql_dbg_io, vha, 0x3001,
  503. "PCI Channel IO permanent failure, exiting "
  504. "cmd=%p.\n", cmd);
  505. cmd->result = DID_NO_CONNECT << 16;
  506. } else {
  507. ql_dbg(ql_dbg_io, vha, 0x3002,
  508. "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
  509. cmd->result = DID_REQUEUE << 16;
  510. }
  511. goto qc24_fail_command;
  512. }
  513. rval = fc_remote_port_chkready(rport);
  514. if (rval) {
  515. cmd->result = rval;
  516. ql_dbg(ql_dbg_io, vha, 0x3003,
  517. "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
  518. cmd, rval);
  519. goto qc24_fail_command;
  520. }
  521. if (!vha->flags.difdix_supported &&
  522. scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  523. ql_dbg(ql_dbg_io, vha, 0x3004,
  524. "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
  525. cmd);
  526. cmd->result = DID_NO_CONNECT << 16;
  527. goto qc24_fail_command;
  528. }
  529. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  530. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  531. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  532. ql_dbg(ql_dbg_io, vha, 0x3005,
  533. "Returning DNC, fcport_state=%d loop_state=%d.\n",
  534. atomic_read(&fcport->state),
  535. atomic_read(&base_vha->loop_state));
  536. cmd->result = DID_NO_CONNECT << 16;
  537. goto qc24_fail_command;
  538. }
  539. goto qc24_target_busy;
  540. }
  541. sp = qla2x00_get_new_sp(base_vha, fcport, cmd);
  542. if (!sp)
  543. goto qc24_host_busy;
  544. rval = ha->isp_ops->start_scsi(sp);
  545. if (rval != QLA_SUCCESS) {
  546. ql_dbg(ql_dbg_io, vha, 0x3013,
  547. "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
  548. goto qc24_host_busy_free_sp;
  549. }
  550. return 0;
  551. qc24_host_busy_free_sp:
  552. qla2x00_sp_free_dma(sp);
  553. mempool_free(sp, ha->srb_mempool);
  554. qc24_host_busy:
  555. return SCSI_MLQUEUE_HOST_BUSY;
  556. qc24_target_busy:
  557. return SCSI_MLQUEUE_TARGET_BUSY;
  558. qc24_fail_command:
  559. cmd->scsi_done(cmd);
  560. return 0;
  561. }
  562. /*
  563. * qla2x00_eh_wait_on_command
  564. * Waits for the command to be returned by the Firmware for some
  565. * max time.
  566. *
  567. * Input:
  568. * cmd = Scsi Command to wait on.
  569. *
  570. * Return:
  571. * Not Found : 0
  572. * Found : 1
  573. */
  574. static int
  575. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  576. {
  577. #define ABORT_POLLING_PERIOD 1000
  578. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  579. unsigned long wait_iter = ABORT_WAIT_ITER;
  580. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  581. struct qla_hw_data *ha = vha->hw;
  582. int ret = QLA_SUCCESS;
  583. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  584. ql_dbg(ql_dbg_taskm, vha, 0x8005,
  585. "Return:eh_wait.\n");
  586. return ret;
  587. }
  588. while (CMD_SP(cmd) && wait_iter--) {
  589. msleep(ABORT_POLLING_PERIOD);
  590. }
  591. if (CMD_SP(cmd))
  592. ret = QLA_FUNCTION_FAILED;
  593. return ret;
  594. }
  595. /*
  596. * qla2x00_wait_for_hba_online
  597. * Wait till the HBA is online after going through
  598. * <= MAX_RETRIES_OF_ISP_ABORT or
  599. * finally HBA is disabled ie marked offline
  600. *
  601. * Input:
  602. * ha - pointer to host adapter structure
  603. *
  604. * Note:
  605. * Does context switching-Release SPIN_LOCK
  606. * (if any) before calling this routine.
  607. *
  608. * Return:
  609. * Success (Adapter is online) : 0
  610. * Failed (Adapter is offline/disabled) : 1
  611. */
  612. int
  613. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  614. {
  615. int return_status;
  616. unsigned long wait_online;
  617. struct qla_hw_data *ha = vha->hw;
  618. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  619. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  620. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  621. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  622. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  623. ha->dpc_active) && time_before(jiffies, wait_online)) {
  624. msleep(1000);
  625. }
  626. if (base_vha->flags.online)
  627. return_status = QLA_SUCCESS;
  628. else
  629. return_status = QLA_FUNCTION_FAILED;
  630. return (return_status);
  631. }
  632. /*
  633. * qla2x00_wait_for_reset_ready
  634. * Wait till the HBA is online after going through
  635. * <= MAX_RETRIES_OF_ISP_ABORT or
  636. * finally HBA is disabled ie marked offline or flash
  637. * operations are in progress.
  638. *
  639. * Input:
  640. * ha - pointer to host adapter structure
  641. *
  642. * Note:
  643. * Does context switching-Release SPIN_LOCK
  644. * (if any) before calling this routine.
  645. *
  646. * Return:
  647. * Success (Adapter is online/no flash ops) : 0
  648. * Failed (Adapter is offline/disabled/flash ops in progress) : 1
  649. */
  650. static int
  651. qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
  652. {
  653. int return_status;
  654. unsigned long wait_online;
  655. struct qla_hw_data *ha = vha->hw;
  656. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  657. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  658. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  659. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  660. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  661. ha->optrom_state != QLA_SWAITING ||
  662. ha->dpc_active) && time_before(jiffies, wait_online))
  663. msleep(1000);
  664. if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
  665. return_status = QLA_SUCCESS;
  666. else
  667. return_status = QLA_FUNCTION_FAILED;
  668. ql_dbg(ql_dbg_taskm, vha, 0x8019,
  669. "%s return status=%d.\n", __func__, return_status);
  670. return return_status;
  671. }
  672. int
  673. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  674. {
  675. int return_status;
  676. unsigned long wait_reset;
  677. struct qla_hw_data *ha = vha->hw;
  678. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  679. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  680. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  681. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  682. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  683. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  684. msleep(1000);
  685. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  686. ha->flags.chip_reset_done)
  687. break;
  688. }
  689. if (ha->flags.chip_reset_done)
  690. return_status = QLA_SUCCESS;
  691. else
  692. return_status = QLA_FUNCTION_FAILED;
  693. return return_status;
  694. }
  695. /*
  696. * qla2x00_wait_for_loop_ready
  697. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  698. * to be in LOOP_READY state.
  699. * Input:
  700. * ha - pointer to host adapter structure
  701. *
  702. * Note:
  703. * Does context switching-Release SPIN_LOCK
  704. * (if any) before calling this routine.
  705. *
  706. *
  707. * Return:
  708. * Success (LOOP_READY) : 0
  709. * Failed (LOOP_NOT_READY) : 1
  710. */
  711. static inline int
  712. qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
  713. {
  714. int return_status = QLA_SUCCESS;
  715. unsigned long loop_timeout ;
  716. struct qla_hw_data *ha = vha->hw;
  717. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  718. /* wait for 5 min at the max for loop to be ready */
  719. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  720. while ((!atomic_read(&base_vha->loop_down_timer) &&
  721. atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
  722. atomic_read(&base_vha->loop_state) != LOOP_READY) {
  723. if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  724. return_status = QLA_FUNCTION_FAILED;
  725. break;
  726. }
  727. msleep(1000);
  728. if (time_after_eq(jiffies, loop_timeout)) {
  729. return_status = QLA_FUNCTION_FAILED;
  730. break;
  731. }
  732. }
  733. return (return_status);
  734. }
  735. static void
  736. sp_get(struct srb *sp)
  737. {
  738. atomic_inc(&sp->ref_count);
  739. }
  740. /**************************************************************************
  741. * qla2xxx_eh_abort
  742. *
  743. * Description:
  744. * The abort function will abort the specified command.
  745. *
  746. * Input:
  747. * cmd = Linux SCSI command packet to be aborted.
  748. *
  749. * Returns:
  750. * Either SUCCESS or FAILED.
  751. *
  752. * Note:
  753. * Only return FAILED if command not returned by firmware.
  754. **************************************************************************/
  755. static int
  756. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  757. {
  758. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  759. srb_t *sp;
  760. int ret;
  761. unsigned int id, lun;
  762. unsigned long flags;
  763. int wait = 0;
  764. struct qla_hw_data *ha = vha->hw;
  765. ql_dbg(ql_dbg_taskm, vha, 0x8000,
  766. "Entered %s for cmd=%p.\n", __func__, cmd);
  767. if (!CMD_SP(cmd))
  768. return SUCCESS;
  769. ret = fc_block_scsi_eh(cmd);
  770. ql_dbg(ql_dbg_taskm, vha, 0x8001,
  771. "Return value of fc_block_scsi_eh=%d.\n", ret);
  772. if (ret != 0)
  773. return ret;
  774. ret = SUCCESS;
  775. id = cmd->device->id;
  776. lun = cmd->device->lun;
  777. spin_lock_irqsave(&ha->hardware_lock, flags);
  778. sp = (srb_t *) CMD_SP(cmd);
  779. if (!sp) {
  780. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  781. return SUCCESS;
  782. }
  783. ql_dbg(ql_dbg_taskm, vha, 0x8002,
  784. "Aborting sp=%p cmd=%p from RISC ", sp, cmd);
  785. /* Get a reference to the sp and drop the lock.*/
  786. sp_get(sp);
  787. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  788. if (ha->isp_ops->abort_command(sp)) {
  789. ql_dbg(ql_dbg_taskm, vha, 0x8003,
  790. "Abort command mbx failed for cmd=%p.\n", cmd);
  791. } else {
  792. ql_dbg(ql_dbg_taskm, vha, 0x8004,
  793. "Abort command mbx success.\n");
  794. wait = 1;
  795. }
  796. spin_lock_irqsave(&ha->hardware_lock, flags);
  797. qla2x00_sp_compl(ha, sp);
  798. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  799. /* Did the command return during mailbox execution? */
  800. if (ret == FAILED && !CMD_SP(cmd))
  801. ret = SUCCESS;
  802. /* Wait for the command to be returned. */
  803. if (wait) {
  804. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  805. ql_log(ql_log_warn, vha, 0x8006,
  806. "Abort handler timed out for cmd=%p.\n", cmd);
  807. ret = FAILED;
  808. }
  809. }
  810. ql_log(ql_log_info, vha, 0x801c,
  811. "Abort command issued -- %d %x.\n", wait, ret);
  812. return ret;
  813. }
  814. int
  815. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  816. unsigned int l, enum nexus_wait_type type)
  817. {
  818. int cnt, match, status;
  819. unsigned long flags;
  820. struct qla_hw_data *ha = vha->hw;
  821. struct req_que *req;
  822. srb_t *sp;
  823. status = QLA_SUCCESS;
  824. spin_lock_irqsave(&ha->hardware_lock, flags);
  825. req = vha->req;
  826. for (cnt = 1; status == QLA_SUCCESS &&
  827. cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  828. sp = req->outstanding_cmds[cnt];
  829. if (!sp)
  830. continue;
  831. if ((sp->ctx) && !IS_PROT_IO(sp))
  832. continue;
  833. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  834. continue;
  835. match = 0;
  836. switch (type) {
  837. case WAIT_HOST:
  838. match = 1;
  839. break;
  840. case WAIT_TARGET:
  841. match = sp->cmd->device->id == t;
  842. break;
  843. case WAIT_LUN:
  844. match = (sp->cmd->device->id == t &&
  845. sp->cmd->device->lun == l);
  846. break;
  847. }
  848. if (!match)
  849. continue;
  850. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  851. status = qla2x00_eh_wait_on_command(sp->cmd);
  852. spin_lock_irqsave(&ha->hardware_lock, flags);
  853. }
  854. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  855. return status;
  856. }
  857. static char *reset_errors[] = {
  858. "HBA not online",
  859. "HBA not ready",
  860. "Task management failed",
  861. "Waiting for command completions",
  862. };
  863. static int
  864. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  865. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
  866. {
  867. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  868. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  869. int err;
  870. if (!fcport) {
  871. ql_log(ql_log_warn, vha, 0x8007,
  872. "fcport is NULL.\n");
  873. return FAILED;
  874. }
  875. err = fc_block_scsi_eh(cmd);
  876. ql_dbg(ql_dbg_taskm, vha, 0x8008,
  877. "fc_block_scsi_eh ret=%d.\n", err);
  878. if (err != 0)
  879. return err;
  880. ql_log(ql_log_info, vha, 0x8009,
  881. "%s RESET ISSUED for id %d lun %d cmd=%p.\n", name,
  882. cmd->device->id, cmd->device->lun, cmd);
  883. err = 0;
  884. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  885. ql_log(ql_log_warn, vha, 0x800a,
  886. "Wait for hba online failed for cmd=%p.\n", cmd);
  887. goto eh_reset_failed;
  888. }
  889. err = 1;
  890. if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS) {
  891. ql_log(ql_log_warn, vha, 0x800b,
  892. "Wait for loop ready failed for cmd=%p.\n", cmd);
  893. goto eh_reset_failed;
  894. }
  895. err = 2;
  896. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  897. != QLA_SUCCESS) {
  898. ql_log(ql_log_warn, vha, 0x800c,
  899. "do_reset failed for cmd=%p.\n", cmd);
  900. goto eh_reset_failed;
  901. }
  902. err = 3;
  903. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  904. cmd->device->lun, type) != QLA_SUCCESS) {
  905. ql_log(ql_log_warn, vha, 0x800d,
  906. "wait for peding cmds failed for cmd=%p.\n", cmd);
  907. goto eh_reset_failed;
  908. }
  909. ql_log(ql_log_info, vha, 0x800e,
  910. "%s RESET SUCCEEDED for id %d lun %d cmd=%p.\n", name,
  911. cmd->device->id, cmd->device->lun, cmd);
  912. return SUCCESS;
  913. eh_reset_failed:
  914. ql_log(ql_log_info, vha, 0x800f,
  915. "%s RESET FAILED: %s for id %d lun %d cmd=%p.\n", name,
  916. reset_errors[err], cmd->device->id, cmd->device->lun);
  917. return FAILED;
  918. }
  919. static int
  920. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  921. {
  922. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  923. struct qla_hw_data *ha = vha->hw;
  924. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  925. ha->isp_ops->lun_reset);
  926. }
  927. static int
  928. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  929. {
  930. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  931. struct qla_hw_data *ha = vha->hw;
  932. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  933. ha->isp_ops->target_reset);
  934. }
  935. /**************************************************************************
  936. * qla2xxx_eh_bus_reset
  937. *
  938. * Description:
  939. * The bus reset function will reset the bus and abort any executing
  940. * commands.
  941. *
  942. * Input:
  943. * cmd = Linux SCSI command packet of the command that cause the
  944. * bus reset.
  945. *
  946. * Returns:
  947. * SUCCESS/FAILURE (defined as macro in scsi.h).
  948. *
  949. **************************************************************************/
  950. static int
  951. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  952. {
  953. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  954. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  955. int ret = FAILED;
  956. unsigned int id, lun;
  957. id = cmd->device->id;
  958. lun = cmd->device->lun;
  959. if (!fcport) {
  960. ql_log(ql_log_warn, vha, 0x8010,
  961. "fcport is NULL.\n");
  962. return ret;
  963. }
  964. ret = fc_block_scsi_eh(cmd);
  965. ql_dbg(ql_dbg_taskm, vha, 0x8011,
  966. "fc_block_scsi_eh ret=%d.\n", ret);
  967. if (ret != 0)
  968. return ret;
  969. ret = FAILED;
  970. ql_log(ql_log_info, vha, 0x8012,
  971. "BUS RESET ISSUED for id %d lun %d.\n", id, lun);
  972. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  973. ql_log(ql_log_fatal, vha, 0x8013,
  974. "Wait for hba online failed board disabled.\n");
  975. goto eh_bus_reset_done;
  976. }
  977. if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
  978. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  979. ret = SUCCESS;
  980. }
  981. if (ret == FAILED)
  982. goto eh_bus_reset_done;
  983. /* Flush outstanding commands. */
  984. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
  985. QLA_SUCCESS) {
  986. ql_log(ql_log_warn, vha, 0x8014,
  987. "Wait for pending commands failed.\n");
  988. ret = FAILED;
  989. }
  990. eh_bus_reset_done:
  991. ql_log(ql_log_warn, vha, 0x802b,
  992. "BUS RESET %s.\n", (ret == FAILED) ? "FAILED" : "SUCCEDED");
  993. return ret;
  994. }
  995. /**************************************************************************
  996. * qla2xxx_eh_host_reset
  997. *
  998. * Description:
  999. * The reset function will reset the Adapter.
  1000. *
  1001. * Input:
  1002. * cmd = Linux SCSI command packet of the command that cause the
  1003. * adapter reset.
  1004. *
  1005. * Returns:
  1006. * Either SUCCESS or FAILED.
  1007. *
  1008. * Note:
  1009. **************************************************************************/
  1010. static int
  1011. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1012. {
  1013. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1014. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  1015. struct qla_hw_data *ha = vha->hw;
  1016. int ret = FAILED;
  1017. unsigned int id, lun;
  1018. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1019. id = cmd->device->id;
  1020. lun = cmd->device->lun;
  1021. if (!fcport) {
  1022. ql_log(ql_log_warn, vha, 0x8016,
  1023. "fcport is NULL.\n");
  1024. return ret;
  1025. }
  1026. ret = fc_block_scsi_eh(cmd);
  1027. ql_dbg(ql_dbg_taskm, vha, 0x8017,
  1028. "fc_block_scsi_eh ret=%d.\n", ret);
  1029. if (ret != 0)
  1030. return ret;
  1031. ret = FAILED;
  1032. ql_log(ql_log_info, vha, 0x8018,
  1033. "ADAPTER RESET ISSUED for id %d lun %d.\n", id, lun);
  1034. if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
  1035. goto eh_host_reset_lock;
  1036. /*
  1037. * Fixme-may be dpc thread is active and processing
  1038. * loop_resync,so wait a while for it to
  1039. * be completed and then issue big hammer.Otherwise
  1040. * it may cause I/O failure as big hammer marks the
  1041. * devices as lost kicking of the port_down_timer
  1042. * while dpc is stuck for the mailbox to complete.
  1043. */
  1044. qla2x00_wait_for_loop_ready(vha);
  1045. if (vha != base_vha) {
  1046. if (qla2x00_vp_abort_isp(vha))
  1047. goto eh_host_reset_lock;
  1048. } else {
  1049. if (IS_QLA82XX(vha->hw)) {
  1050. if (!qla82xx_fcoe_ctx_reset(vha)) {
  1051. /* Ctx reset success */
  1052. ret = SUCCESS;
  1053. goto eh_host_reset_lock;
  1054. }
  1055. /* fall thru if ctx reset failed */
  1056. }
  1057. if (ha->wq)
  1058. flush_workqueue(ha->wq);
  1059. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1060. if (ha->isp_ops->abort_isp(base_vha)) {
  1061. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1062. /* failed. schedule dpc to try */
  1063. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  1064. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1065. ql_log(ql_log_warn, vha, 0x802a,
  1066. "wait for hba online failed.\n");
  1067. goto eh_host_reset_lock;
  1068. }
  1069. }
  1070. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1071. }
  1072. /* Waiting for command to be returned to OS.*/
  1073. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
  1074. QLA_SUCCESS)
  1075. ret = SUCCESS;
  1076. eh_host_reset_lock:
  1077. qla_printk(KERN_INFO, ha, "%s: reset %s.\n", __func__,
  1078. (ret == FAILED) ? "failed" : "succeeded");
  1079. return ret;
  1080. }
  1081. /*
  1082. * qla2x00_loop_reset
  1083. * Issue loop reset.
  1084. *
  1085. * Input:
  1086. * ha = adapter block pointer.
  1087. *
  1088. * Returns:
  1089. * 0 = success
  1090. */
  1091. int
  1092. qla2x00_loop_reset(scsi_qla_host_t *vha)
  1093. {
  1094. int ret;
  1095. struct fc_port *fcport;
  1096. struct qla_hw_data *ha = vha->hw;
  1097. if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
  1098. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1099. if (fcport->port_type != FCT_TARGET)
  1100. continue;
  1101. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  1102. if (ret != QLA_SUCCESS) {
  1103. ql_dbg(ql_dbg_taskm, vha, 0x802c,
  1104. "Bus Reset failed: Target Reset=%d "
  1105. "d_id=%x.\n", ret, fcport->d_id.b24);
  1106. }
  1107. }
  1108. }
  1109. if (ha->flags.enable_lip_full_login && !IS_QLA8XXX_TYPE(ha)) {
  1110. ret = qla2x00_full_login_lip(vha);
  1111. if (ret != QLA_SUCCESS) {
  1112. ql_dbg(ql_dbg_taskm, vha, 0x802d,
  1113. "full_login_lip=%d.\n", ret);
  1114. }
  1115. atomic_set(&vha->loop_state, LOOP_DOWN);
  1116. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  1117. qla2x00_mark_all_devices_lost(vha, 0);
  1118. qla2x00_wait_for_loop_ready(vha);
  1119. }
  1120. if (ha->flags.enable_lip_reset) {
  1121. ret = qla2x00_lip_reset(vha);
  1122. if (ret != QLA_SUCCESS) {
  1123. ql_dbg(ql_dbg_taskm, vha, 0x802e,
  1124. "lip_reset failed (%d).\n", ret);
  1125. } else
  1126. qla2x00_wait_for_loop_ready(vha);
  1127. }
  1128. /* Issue marker command only when we are going to start the I/O */
  1129. vha->marker_needed = 1;
  1130. return QLA_SUCCESS;
  1131. }
  1132. void
  1133. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  1134. {
  1135. int que, cnt;
  1136. unsigned long flags;
  1137. srb_t *sp;
  1138. struct srb_ctx *ctx;
  1139. struct qla_hw_data *ha = vha->hw;
  1140. struct req_que *req;
  1141. spin_lock_irqsave(&ha->hardware_lock, flags);
  1142. for (que = 0; que < ha->max_req_queues; que++) {
  1143. req = ha->req_q_map[que];
  1144. if (!req)
  1145. continue;
  1146. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  1147. sp = req->outstanding_cmds[cnt];
  1148. if (sp) {
  1149. req->outstanding_cmds[cnt] = NULL;
  1150. if (!sp->ctx ||
  1151. (sp->flags & SRB_FCP_CMND_DMA_VALID) ||
  1152. IS_PROT_IO(sp)) {
  1153. sp->cmd->result = res;
  1154. qla2x00_sp_compl(ha, sp);
  1155. } else {
  1156. ctx = sp->ctx;
  1157. if (ctx->type == SRB_ELS_CMD_RPT ||
  1158. ctx->type == SRB_ELS_CMD_HST ||
  1159. ctx->type == SRB_CT_CMD) {
  1160. struct fc_bsg_job *bsg_job =
  1161. ctx->u.bsg_job;
  1162. if (bsg_job->request->msgcode
  1163. == FC_BSG_HST_CT)
  1164. kfree(sp->fcport);
  1165. bsg_job->req->errors = 0;
  1166. bsg_job->reply->result = res;
  1167. bsg_job->job_done(bsg_job);
  1168. kfree(sp->ctx);
  1169. mempool_free(sp,
  1170. ha->srb_mempool);
  1171. } else {
  1172. ctx->u.iocb_cmd->free(sp);
  1173. }
  1174. }
  1175. }
  1176. }
  1177. }
  1178. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1179. }
  1180. static int
  1181. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1182. {
  1183. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1184. if (!rport || fc_remote_port_chkready(rport))
  1185. return -ENXIO;
  1186. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1187. return 0;
  1188. }
  1189. static int
  1190. qla2xxx_slave_configure(struct scsi_device *sdev)
  1191. {
  1192. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1193. struct req_que *req = vha->req;
  1194. if (sdev->tagged_supported)
  1195. scsi_activate_tcq(sdev, req->max_q_depth);
  1196. else
  1197. scsi_deactivate_tcq(sdev, req->max_q_depth);
  1198. return 0;
  1199. }
  1200. static void
  1201. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1202. {
  1203. sdev->hostdata = NULL;
  1204. }
  1205. static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
  1206. {
  1207. fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
  1208. if (!scsi_track_queue_full(sdev, qdepth))
  1209. return;
  1210. ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
  1211. "Queue depth adjusted-down "
  1212. "to %d for scsi(%ld:%d:%d:%d).\n",
  1213. sdev->queue_depth, fcport->vha->host_no,
  1214. sdev->channel, sdev->id, sdev->lun);
  1215. }
  1216. static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
  1217. {
  1218. fc_port_t *fcport = sdev->hostdata;
  1219. struct scsi_qla_host *vha = fcport->vha;
  1220. struct req_que *req = NULL;
  1221. req = vha->req;
  1222. if (!req)
  1223. return;
  1224. if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
  1225. return;
  1226. if (sdev->ordered_tags)
  1227. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
  1228. else
  1229. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
  1230. ql_dbg(ql_dbg_io, vha, 0x302a,
  1231. "Queue depth adjusted-up to %d for "
  1232. "scsi(%ld:%d:%d:%d).\n",
  1233. sdev->queue_depth, fcport->vha->host_no,
  1234. sdev->channel, sdev->id, sdev->lun);
  1235. }
  1236. static int
  1237. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1238. {
  1239. switch (reason) {
  1240. case SCSI_QDEPTH_DEFAULT:
  1241. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1242. break;
  1243. case SCSI_QDEPTH_QFULL:
  1244. qla2x00_handle_queue_full(sdev, qdepth);
  1245. break;
  1246. case SCSI_QDEPTH_RAMP_UP:
  1247. qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
  1248. break;
  1249. default:
  1250. return -EOPNOTSUPP;
  1251. }
  1252. return sdev->queue_depth;
  1253. }
  1254. static int
  1255. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  1256. {
  1257. if (sdev->tagged_supported) {
  1258. scsi_set_tag_type(sdev, tag_type);
  1259. if (tag_type)
  1260. scsi_activate_tcq(sdev, sdev->queue_depth);
  1261. else
  1262. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1263. } else
  1264. tag_type = 0;
  1265. return tag_type;
  1266. }
  1267. /**
  1268. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1269. * @ha: HA context
  1270. *
  1271. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1272. * supported addressing method.
  1273. */
  1274. static void
  1275. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1276. {
  1277. /* Assume a 32bit DMA mask. */
  1278. ha->flags.enable_64bit_addressing = 0;
  1279. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1280. /* Any upper-dword bits set? */
  1281. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1282. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1283. /* Ok, a 64bit DMA mask is applicable. */
  1284. ha->flags.enable_64bit_addressing = 1;
  1285. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1286. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1287. return;
  1288. }
  1289. }
  1290. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1291. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1292. }
  1293. static void
  1294. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1295. {
  1296. unsigned long flags = 0;
  1297. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1298. spin_lock_irqsave(&ha->hardware_lock, flags);
  1299. ha->interrupts_on = 1;
  1300. /* enable risc and host interrupts */
  1301. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1302. RD_REG_WORD(&reg->ictrl);
  1303. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1304. }
  1305. static void
  1306. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1307. {
  1308. unsigned long flags = 0;
  1309. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1310. spin_lock_irqsave(&ha->hardware_lock, flags);
  1311. ha->interrupts_on = 0;
  1312. /* disable risc and host interrupts */
  1313. WRT_REG_WORD(&reg->ictrl, 0);
  1314. RD_REG_WORD(&reg->ictrl);
  1315. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1316. }
  1317. static void
  1318. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1319. {
  1320. unsigned long flags = 0;
  1321. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1322. spin_lock_irqsave(&ha->hardware_lock, flags);
  1323. ha->interrupts_on = 1;
  1324. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1325. RD_REG_DWORD(&reg->ictrl);
  1326. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1327. }
  1328. static void
  1329. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1330. {
  1331. unsigned long flags = 0;
  1332. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1333. if (IS_NOPOLLING_TYPE(ha))
  1334. return;
  1335. spin_lock_irqsave(&ha->hardware_lock, flags);
  1336. ha->interrupts_on = 0;
  1337. WRT_REG_DWORD(&reg->ictrl, 0);
  1338. RD_REG_DWORD(&reg->ictrl);
  1339. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1340. }
  1341. static struct isp_operations qla2100_isp_ops = {
  1342. .pci_config = qla2100_pci_config,
  1343. .reset_chip = qla2x00_reset_chip,
  1344. .chip_diag = qla2x00_chip_diag,
  1345. .config_rings = qla2x00_config_rings,
  1346. .reset_adapter = qla2x00_reset_adapter,
  1347. .nvram_config = qla2x00_nvram_config,
  1348. .update_fw_options = qla2x00_update_fw_options,
  1349. .load_risc = qla2x00_load_risc,
  1350. .pci_info_str = qla2x00_pci_info_str,
  1351. .fw_version_str = qla2x00_fw_version_str,
  1352. .intr_handler = qla2100_intr_handler,
  1353. .enable_intrs = qla2x00_enable_intrs,
  1354. .disable_intrs = qla2x00_disable_intrs,
  1355. .abort_command = qla2x00_abort_command,
  1356. .target_reset = qla2x00_abort_target,
  1357. .lun_reset = qla2x00_lun_reset,
  1358. .fabric_login = qla2x00_login_fabric,
  1359. .fabric_logout = qla2x00_fabric_logout,
  1360. .calc_req_entries = qla2x00_calc_iocbs_32,
  1361. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1362. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1363. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1364. .read_nvram = qla2x00_read_nvram_data,
  1365. .write_nvram = qla2x00_write_nvram_data,
  1366. .fw_dump = qla2100_fw_dump,
  1367. .beacon_on = NULL,
  1368. .beacon_off = NULL,
  1369. .beacon_blink = NULL,
  1370. .read_optrom = qla2x00_read_optrom_data,
  1371. .write_optrom = qla2x00_write_optrom_data,
  1372. .get_flash_version = qla2x00_get_flash_version,
  1373. .start_scsi = qla2x00_start_scsi,
  1374. .abort_isp = qla2x00_abort_isp,
  1375. };
  1376. static struct isp_operations qla2300_isp_ops = {
  1377. .pci_config = qla2300_pci_config,
  1378. .reset_chip = qla2x00_reset_chip,
  1379. .chip_diag = qla2x00_chip_diag,
  1380. .config_rings = qla2x00_config_rings,
  1381. .reset_adapter = qla2x00_reset_adapter,
  1382. .nvram_config = qla2x00_nvram_config,
  1383. .update_fw_options = qla2x00_update_fw_options,
  1384. .load_risc = qla2x00_load_risc,
  1385. .pci_info_str = qla2x00_pci_info_str,
  1386. .fw_version_str = qla2x00_fw_version_str,
  1387. .intr_handler = qla2300_intr_handler,
  1388. .enable_intrs = qla2x00_enable_intrs,
  1389. .disable_intrs = qla2x00_disable_intrs,
  1390. .abort_command = qla2x00_abort_command,
  1391. .target_reset = qla2x00_abort_target,
  1392. .lun_reset = qla2x00_lun_reset,
  1393. .fabric_login = qla2x00_login_fabric,
  1394. .fabric_logout = qla2x00_fabric_logout,
  1395. .calc_req_entries = qla2x00_calc_iocbs_32,
  1396. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1397. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1398. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1399. .read_nvram = qla2x00_read_nvram_data,
  1400. .write_nvram = qla2x00_write_nvram_data,
  1401. .fw_dump = qla2300_fw_dump,
  1402. .beacon_on = qla2x00_beacon_on,
  1403. .beacon_off = qla2x00_beacon_off,
  1404. .beacon_blink = qla2x00_beacon_blink,
  1405. .read_optrom = qla2x00_read_optrom_data,
  1406. .write_optrom = qla2x00_write_optrom_data,
  1407. .get_flash_version = qla2x00_get_flash_version,
  1408. .start_scsi = qla2x00_start_scsi,
  1409. .abort_isp = qla2x00_abort_isp,
  1410. };
  1411. static struct isp_operations qla24xx_isp_ops = {
  1412. .pci_config = qla24xx_pci_config,
  1413. .reset_chip = qla24xx_reset_chip,
  1414. .chip_diag = qla24xx_chip_diag,
  1415. .config_rings = qla24xx_config_rings,
  1416. .reset_adapter = qla24xx_reset_adapter,
  1417. .nvram_config = qla24xx_nvram_config,
  1418. .update_fw_options = qla24xx_update_fw_options,
  1419. .load_risc = qla24xx_load_risc,
  1420. .pci_info_str = qla24xx_pci_info_str,
  1421. .fw_version_str = qla24xx_fw_version_str,
  1422. .intr_handler = qla24xx_intr_handler,
  1423. .enable_intrs = qla24xx_enable_intrs,
  1424. .disable_intrs = qla24xx_disable_intrs,
  1425. .abort_command = qla24xx_abort_command,
  1426. .target_reset = qla24xx_abort_target,
  1427. .lun_reset = qla24xx_lun_reset,
  1428. .fabric_login = qla24xx_login_fabric,
  1429. .fabric_logout = qla24xx_fabric_logout,
  1430. .calc_req_entries = NULL,
  1431. .build_iocbs = NULL,
  1432. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1433. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1434. .read_nvram = qla24xx_read_nvram_data,
  1435. .write_nvram = qla24xx_write_nvram_data,
  1436. .fw_dump = qla24xx_fw_dump,
  1437. .beacon_on = qla24xx_beacon_on,
  1438. .beacon_off = qla24xx_beacon_off,
  1439. .beacon_blink = qla24xx_beacon_blink,
  1440. .read_optrom = qla24xx_read_optrom_data,
  1441. .write_optrom = qla24xx_write_optrom_data,
  1442. .get_flash_version = qla24xx_get_flash_version,
  1443. .start_scsi = qla24xx_start_scsi,
  1444. .abort_isp = qla2x00_abort_isp,
  1445. };
  1446. static struct isp_operations qla25xx_isp_ops = {
  1447. .pci_config = qla25xx_pci_config,
  1448. .reset_chip = qla24xx_reset_chip,
  1449. .chip_diag = qla24xx_chip_diag,
  1450. .config_rings = qla24xx_config_rings,
  1451. .reset_adapter = qla24xx_reset_adapter,
  1452. .nvram_config = qla24xx_nvram_config,
  1453. .update_fw_options = qla24xx_update_fw_options,
  1454. .load_risc = qla24xx_load_risc,
  1455. .pci_info_str = qla24xx_pci_info_str,
  1456. .fw_version_str = qla24xx_fw_version_str,
  1457. .intr_handler = qla24xx_intr_handler,
  1458. .enable_intrs = qla24xx_enable_intrs,
  1459. .disable_intrs = qla24xx_disable_intrs,
  1460. .abort_command = qla24xx_abort_command,
  1461. .target_reset = qla24xx_abort_target,
  1462. .lun_reset = qla24xx_lun_reset,
  1463. .fabric_login = qla24xx_login_fabric,
  1464. .fabric_logout = qla24xx_fabric_logout,
  1465. .calc_req_entries = NULL,
  1466. .build_iocbs = NULL,
  1467. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1468. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1469. .read_nvram = qla25xx_read_nvram_data,
  1470. .write_nvram = qla25xx_write_nvram_data,
  1471. .fw_dump = qla25xx_fw_dump,
  1472. .beacon_on = qla24xx_beacon_on,
  1473. .beacon_off = qla24xx_beacon_off,
  1474. .beacon_blink = qla24xx_beacon_blink,
  1475. .read_optrom = qla25xx_read_optrom_data,
  1476. .write_optrom = qla24xx_write_optrom_data,
  1477. .get_flash_version = qla24xx_get_flash_version,
  1478. .start_scsi = qla24xx_dif_start_scsi,
  1479. .abort_isp = qla2x00_abort_isp,
  1480. };
  1481. static struct isp_operations qla81xx_isp_ops = {
  1482. .pci_config = qla25xx_pci_config,
  1483. .reset_chip = qla24xx_reset_chip,
  1484. .chip_diag = qla24xx_chip_diag,
  1485. .config_rings = qla24xx_config_rings,
  1486. .reset_adapter = qla24xx_reset_adapter,
  1487. .nvram_config = qla81xx_nvram_config,
  1488. .update_fw_options = qla81xx_update_fw_options,
  1489. .load_risc = qla81xx_load_risc,
  1490. .pci_info_str = qla24xx_pci_info_str,
  1491. .fw_version_str = qla24xx_fw_version_str,
  1492. .intr_handler = qla24xx_intr_handler,
  1493. .enable_intrs = qla24xx_enable_intrs,
  1494. .disable_intrs = qla24xx_disable_intrs,
  1495. .abort_command = qla24xx_abort_command,
  1496. .target_reset = qla24xx_abort_target,
  1497. .lun_reset = qla24xx_lun_reset,
  1498. .fabric_login = qla24xx_login_fabric,
  1499. .fabric_logout = qla24xx_fabric_logout,
  1500. .calc_req_entries = NULL,
  1501. .build_iocbs = NULL,
  1502. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1503. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1504. .read_nvram = NULL,
  1505. .write_nvram = NULL,
  1506. .fw_dump = qla81xx_fw_dump,
  1507. .beacon_on = qla24xx_beacon_on,
  1508. .beacon_off = qla24xx_beacon_off,
  1509. .beacon_blink = qla24xx_beacon_blink,
  1510. .read_optrom = qla25xx_read_optrom_data,
  1511. .write_optrom = qla24xx_write_optrom_data,
  1512. .get_flash_version = qla24xx_get_flash_version,
  1513. .start_scsi = qla24xx_dif_start_scsi,
  1514. .abort_isp = qla2x00_abort_isp,
  1515. };
  1516. static struct isp_operations qla82xx_isp_ops = {
  1517. .pci_config = qla82xx_pci_config,
  1518. .reset_chip = qla82xx_reset_chip,
  1519. .chip_diag = qla24xx_chip_diag,
  1520. .config_rings = qla82xx_config_rings,
  1521. .reset_adapter = qla24xx_reset_adapter,
  1522. .nvram_config = qla81xx_nvram_config,
  1523. .update_fw_options = qla24xx_update_fw_options,
  1524. .load_risc = qla82xx_load_risc,
  1525. .pci_info_str = qla82xx_pci_info_str,
  1526. .fw_version_str = qla24xx_fw_version_str,
  1527. .intr_handler = qla82xx_intr_handler,
  1528. .enable_intrs = qla82xx_enable_intrs,
  1529. .disable_intrs = qla82xx_disable_intrs,
  1530. .abort_command = qla24xx_abort_command,
  1531. .target_reset = qla24xx_abort_target,
  1532. .lun_reset = qla24xx_lun_reset,
  1533. .fabric_login = qla24xx_login_fabric,
  1534. .fabric_logout = qla24xx_fabric_logout,
  1535. .calc_req_entries = NULL,
  1536. .build_iocbs = NULL,
  1537. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1538. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1539. .read_nvram = qla24xx_read_nvram_data,
  1540. .write_nvram = qla24xx_write_nvram_data,
  1541. .fw_dump = qla24xx_fw_dump,
  1542. .beacon_on = qla24xx_beacon_on,
  1543. .beacon_off = qla24xx_beacon_off,
  1544. .beacon_blink = qla24xx_beacon_blink,
  1545. .read_optrom = qla82xx_read_optrom_data,
  1546. .write_optrom = qla82xx_write_optrom_data,
  1547. .get_flash_version = qla24xx_get_flash_version,
  1548. .start_scsi = qla82xx_start_scsi,
  1549. .abort_isp = qla82xx_abort_isp,
  1550. };
  1551. static inline void
  1552. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1553. {
  1554. ha->device_type = DT_EXTENDED_IDS;
  1555. switch (ha->pdev->device) {
  1556. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1557. ha->device_type |= DT_ISP2100;
  1558. ha->device_type &= ~DT_EXTENDED_IDS;
  1559. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1560. break;
  1561. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1562. ha->device_type |= DT_ISP2200;
  1563. ha->device_type &= ~DT_EXTENDED_IDS;
  1564. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1565. break;
  1566. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1567. ha->device_type |= DT_ISP2300;
  1568. ha->device_type |= DT_ZIO_SUPPORTED;
  1569. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1570. break;
  1571. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1572. ha->device_type |= DT_ISP2312;
  1573. ha->device_type |= DT_ZIO_SUPPORTED;
  1574. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1575. break;
  1576. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1577. ha->device_type |= DT_ISP2322;
  1578. ha->device_type |= DT_ZIO_SUPPORTED;
  1579. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1580. ha->pdev->subsystem_device == 0x0170)
  1581. ha->device_type |= DT_OEM_001;
  1582. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1583. break;
  1584. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1585. ha->device_type |= DT_ISP6312;
  1586. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1587. break;
  1588. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1589. ha->device_type |= DT_ISP6322;
  1590. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1591. break;
  1592. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1593. ha->device_type |= DT_ISP2422;
  1594. ha->device_type |= DT_ZIO_SUPPORTED;
  1595. ha->device_type |= DT_FWI2;
  1596. ha->device_type |= DT_IIDMA;
  1597. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1598. break;
  1599. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1600. ha->device_type |= DT_ISP2432;
  1601. ha->device_type |= DT_ZIO_SUPPORTED;
  1602. ha->device_type |= DT_FWI2;
  1603. ha->device_type |= DT_IIDMA;
  1604. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1605. break;
  1606. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1607. ha->device_type |= DT_ISP8432;
  1608. ha->device_type |= DT_ZIO_SUPPORTED;
  1609. ha->device_type |= DT_FWI2;
  1610. ha->device_type |= DT_IIDMA;
  1611. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1612. break;
  1613. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1614. ha->device_type |= DT_ISP5422;
  1615. ha->device_type |= DT_FWI2;
  1616. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1617. break;
  1618. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1619. ha->device_type |= DT_ISP5432;
  1620. ha->device_type |= DT_FWI2;
  1621. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1622. break;
  1623. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1624. ha->device_type |= DT_ISP2532;
  1625. ha->device_type |= DT_ZIO_SUPPORTED;
  1626. ha->device_type |= DT_FWI2;
  1627. ha->device_type |= DT_IIDMA;
  1628. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1629. break;
  1630. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1631. ha->device_type |= DT_ISP8001;
  1632. ha->device_type |= DT_ZIO_SUPPORTED;
  1633. ha->device_type |= DT_FWI2;
  1634. ha->device_type |= DT_IIDMA;
  1635. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1636. break;
  1637. case PCI_DEVICE_ID_QLOGIC_ISP8021:
  1638. ha->device_type |= DT_ISP8021;
  1639. ha->device_type |= DT_ZIO_SUPPORTED;
  1640. ha->device_type |= DT_FWI2;
  1641. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1642. /* Initialize 82XX ISP flags */
  1643. qla82xx_init_flags(ha);
  1644. break;
  1645. }
  1646. if (IS_QLA82XX(ha))
  1647. ha->port_no = !(ha->portnum & 1);
  1648. else
  1649. /* Get adapter physical port no from interrupt pin register. */
  1650. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  1651. if (ha->port_no & 1)
  1652. ha->flags.port0 = 1;
  1653. else
  1654. ha->flags.port0 = 0;
  1655. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
  1656. "device_type=0x%x port=%d fw_srisc_address=%p.\n",
  1657. ha->device_type, ha->flags.port0, ha->fw_srisc_address);
  1658. }
  1659. static int
  1660. qla2x00_iospace_config(struct qla_hw_data *ha)
  1661. {
  1662. resource_size_t pio;
  1663. uint16_t msix;
  1664. int cpus;
  1665. if (IS_QLA82XX(ha))
  1666. return qla82xx_iospace_config(ha);
  1667. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1668. QLA2XXX_DRIVER_NAME)) {
  1669. ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
  1670. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1671. pci_name(ha->pdev));
  1672. goto iospace_error_exit;
  1673. }
  1674. if (!(ha->bars & 1))
  1675. goto skip_pio;
  1676. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1677. pio = pci_resource_start(ha->pdev, 0);
  1678. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1679. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1680. ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
  1681. "Invalid pci I/O region size (%s).\n",
  1682. pci_name(ha->pdev));
  1683. pio = 0;
  1684. }
  1685. } else {
  1686. ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
  1687. "Region #0 no a PIO resource (%s).\n",
  1688. pci_name(ha->pdev));
  1689. pio = 0;
  1690. }
  1691. ha->pio_address = pio;
  1692. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
  1693. "PIO address=%p.\n",
  1694. ha->pio_address);
  1695. skip_pio:
  1696. /* Use MMIO operations for all accesses. */
  1697. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1698. ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
  1699. "Region #1 not an MMIO resource (%s), aborting.\n",
  1700. pci_name(ha->pdev));
  1701. goto iospace_error_exit;
  1702. }
  1703. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1704. ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
  1705. "Invalid PCI mem region size (%s), aborting.\n",
  1706. pci_name(ha->pdev));
  1707. goto iospace_error_exit;
  1708. }
  1709. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1710. if (!ha->iobase) {
  1711. ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
  1712. "Cannot remap MMIO (%s), aborting.\n",
  1713. pci_name(ha->pdev));
  1714. goto iospace_error_exit;
  1715. }
  1716. /* Determine queue resources */
  1717. ha->max_req_queues = ha->max_rsp_queues = 1;
  1718. if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
  1719. (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
  1720. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1721. goto mqiobase_exit;
  1722. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1723. pci_resource_len(ha->pdev, 3));
  1724. if (ha->mqiobase) {
  1725. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
  1726. "MQIO Base=%p.\n", ha->mqiobase);
  1727. /* Read MSIX vector size of the board */
  1728. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1729. ha->msix_count = msix;
  1730. /* Max queues are bounded by available msix vectors */
  1731. /* queue 0 uses two msix vectors */
  1732. if (ql2xmultique_tag) {
  1733. cpus = num_online_cpus();
  1734. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1735. (cpus + 1) : (ha->msix_count - 1);
  1736. ha->max_req_queues = 2;
  1737. } else if (ql2xmaxqueues > 1) {
  1738. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1739. QLA_MQ_SIZE : ql2xmaxqueues;
  1740. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
  1741. "QoS mode set, max no of request queues:%d.\n",
  1742. ha->max_req_queues);
  1743. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
  1744. "QoS mode set, max no of request queues:%d.\n",
  1745. ha->max_req_queues);
  1746. }
  1747. ql_log_pci(ql_log_info, ha->pdev, 0x001a,
  1748. "MSI-X vector count: %d.\n", msix);
  1749. } else
  1750. ql_log_pci(ql_log_info, ha->pdev, 0x001b,
  1751. "BAR 3 not enabled.\n");
  1752. mqiobase_exit:
  1753. ha->msix_count = ha->max_rsp_queues + 1;
  1754. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
  1755. "MSIX Count:%d.\n", ha->msix_count);
  1756. return (0);
  1757. iospace_error_exit:
  1758. return (-ENOMEM);
  1759. }
  1760. static void
  1761. qla2xxx_scan_start(struct Scsi_Host *shost)
  1762. {
  1763. scsi_qla_host_t *vha = shost_priv(shost);
  1764. if (vha->hw->flags.running_gold_fw)
  1765. return;
  1766. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  1767. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  1768. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  1769. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  1770. }
  1771. static int
  1772. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1773. {
  1774. scsi_qla_host_t *vha = shost_priv(shost);
  1775. if (!vha->host)
  1776. return 1;
  1777. if (time > vha->hw->loop_reset_delay * HZ)
  1778. return 1;
  1779. return atomic_read(&vha->loop_state) == LOOP_READY;
  1780. }
  1781. /*
  1782. * PCI driver interface
  1783. */
  1784. static int __devinit
  1785. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1786. {
  1787. int ret = -ENODEV;
  1788. struct Scsi_Host *host;
  1789. scsi_qla_host_t *base_vha = NULL;
  1790. struct qla_hw_data *ha;
  1791. char pci_info[30];
  1792. char fw_str[30];
  1793. struct scsi_host_template *sht;
  1794. int bars, max_id, mem_only = 0;
  1795. uint16_t req_length = 0, rsp_length = 0;
  1796. struct req_que *req = NULL;
  1797. struct rsp_que *rsp = NULL;
  1798. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1799. sht = &qla2xxx_driver_template;
  1800. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1801. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1802. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1803. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1804. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1805. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  1806. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
  1807. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021) {
  1808. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1809. mem_only = 1;
  1810. ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
  1811. "Mem only adapter.\n");
  1812. }
  1813. ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
  1814. "Bars=%d.\n", bars);
  1815. if (mem_only) {
  1816. if (pci_enable_device_mem(pdev))
  1817. goto probe_out;
  1818. } else {
  1819. if (pci_enable_device(pdev))
  1820. goto probe_out;
  1821. }
  1822. /* This may fail but that's ok */
  1823. pci_enable_pcie_error_reporting(pdev);
  1824. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  1825. if (!ha) {
  1826. ql_log_pci(ql_log_fatal, pdev, 0x0009,
  1827. "Unable to allocate memory for ha.\n");
  1828. goto probe_out;
  1829. }
  1830. ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
  1831. "Memory allocated for ha=%p.\n", ha);
  1832. ha->pdev = pdev;
  1833. /* Clear our data area */
  1834. ha->bars = bars;
  1835. ha->mem_only = mem_only;
  1836. spin_lock_init(&ha->hardware_lock);
  1837. spin_lock_init(&ha->vport_slock);
  1838. /* Set ISP-type information. */
  1839. qla2x00_set_isp_flags(ha);
  1840. /* Set EEH reset type to fundamental if required by hba */
  1841. if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
  1842. pdev->needs_freset = 1;
  1843. }
  1844. /* Configure PCI I/O space */
  1845. ret = qla2x00_iospace_config(ha);
  1846. if (ret)
  1847. goto probe_hw_failed;
  1848. ql_log_pci(ql_log_info, pdev, 0x001d,
  1849. "Found an ISP%04X irq %d iobase 0x%p.\n",
  1850. pdev->device, pdev->irq, ha->iobase);
  1851. ha->prev_topology = 0;
  1852. ha->init_cb_size = sizeof(init_cb_t);
  1853. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1854. ha->optrom_size = OPTROM_SIZE_2300;
  1855. /* Assign ISP specific operations. */
  1856. max_id = MAX_TARGETS_2200;
  1857. if (IS_QLA2100(ha)) {
  1858. max_id = MAX_TARGETS_2100;
  1859. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1860. req_length = REQUEST_ENTRY_CNT_2100;
  1861. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1862. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1863. ha->gid_list_info_size = 4;
  1864. ha->flash_conf_off = ~0;
  1865. ha->flash_data_off = ~0;
  1866. ha->nvram_conf_off = ~0;
  1867. ha->nvram_data_off = ~0;
  1868. ha->isp_ops = &qla2100_isp_ops;
  1869. } else if (IS_QLA2200(ha)) {
  1870. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1871. req_length = REQUEST_ENTRY_CNT_2200;
  1872. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1873. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1874. ha->gid_list_info_size = 4;
  1875. ha->flash_conf_off = ~0;
  1876. ha->flash_data_off = ~0;
  1877. ha->nvram_conf_off = ~0;
  1878. ha->nvram_data_off = ~0;
  1879. ha->isp_ops = &qla2100_isp_ops;
  1880. } else if (IS_QLA23XX(ha)) {
  1881. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1882. req_length = REQUEST_ENTRY_CNT_2200;
  1883. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1884. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1885. ha->gid_list_info_size = 6;
  1886. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1887. ha->optrom_size = OPTROM_SIZE_2322;
  1888. ha->flash_conf_off = ~0;
  1889. ha->flash_data_off = ~0;
  1890. ha->nvram_conf_off = ~0;
  1891. ha->nvram_data_off = ~0;
  1892. ha->isp_ops = &qla2300_isp_ops;
  1893. } else if (IS_QLA24XX_TYPE(ha)) {
  1894. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1895. req_length = REQUEST_ENTRY_CNT_24XX;
  1896. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1897. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1898. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1899. ha->gid_list_info_size = 8;
  1900. ha->optrom_size = OPTROM_SIZE_24XX;
  1901. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  1902. ha->isp_ops = &qla24xx_isp_ops;
  1903. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1904. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1905. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1906. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1907. } else if (IS_QLA25XX(ha)) {
  1908. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1909. req_length = REQUEST_ENTRY_CNT_24XX;
  1910. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1911. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1912. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1913. ha->gid_list_info_size = 8;
  1914. ha->optrom_size = OPTROM_SIZE_25XX;
  1915. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1916. ha->isp_ops = &qla25xx_isp_ops;
  1917. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1918. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1919. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1920. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1921. } else if (IS_QLA81XX(ha)) {
  1922. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1923. req_length = REQUEST_ENTRY_CNT_24XX;
  1924. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1925. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1926. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1927. ha->gid_list_info_size = 8;
  1928. ha->optrom_size = OPTROM_SIZE_81XX;
  1929. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1930. ha->isp_ops = &qla81xx_isp_ops;
  1931. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  1932. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  1933. ha->nvram_conf_off = ~0;
  1934. ha->nvram_data_off = ~0;
  1935. } else if (IS_QLA82XX(ha)) {
  1936. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1937. req_length = REQUEST_ENTRY_CNT_82XX;
  1938. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  1939. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1940. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1941. ha->gid_list_info_size = 8;
  1942. ha->optrom_size = OPTROM_SIZE_82XX;
  1943. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1944. ha->isp_ops = &qla82xx_isp_ops;
  1945. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1946. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1947. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1948. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1949. }
  1950. ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
  1951. "mbx_count=%d, req_length=%d, "
  1952. "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
  1953. "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, .\n",
  1954. ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
  1955. ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
  1956. ha->nvram_npiv_size);
  1957. ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
  1958. "isp_ops=%p, flash_conf_off=%d, "
  1959. "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
  1960. ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
  1961. ha->nvram_conf_off, ha->nvram_data_off);
  1962. mutex_init(&ha->vport_lock);
  1963. init_completion(&ha->mbx_cmd_comp);
  1964. complete(&ha->mbx_cmd_comp);
  1965. init_completion(&ha->mbx_intr_comp);
  1966. init_completion(&ha->dcbx_comp);
  1967. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1968. qla2x00_config_dma_addressing(ha);
  1969. ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
  1970. "64 Bit addressing is %s.\n",
  1971. ha->flags.enable_64bit_addressing ? "enable" :
  1972. "disable");
  1973. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  1974. if (!ret) {
  1975. ql_log_pci(ql_log_fatal, pdev, 0x0031,
  1976. "Failed to allocate memory for adapter, aborting.\n");
  1977. goto probe_hw_failed;
  1978. }
  1979. req->max_q_depth = MAX_Q_DEPTH;
  1980. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1981. req->max_q_depth = ql2xmaxqdepth;
  1982. base_vha = qla2x00_create_host(sht, ha);
  1983. if (!base_vha) {
  1984. ret = -ENOMEM;
  1985. qla2x00_mem_free(ha);
  1986. qla2x00_free_req_que(ha, req);
  1987. qla2x00_free_rsp_que(ha, rsp);
  1988. goto probe_hw_failed;
  1989. }
  1990. pci_set_drvdata(pdev, base_vha);
  1991. host = base_vha->host;
  1992. base_vha->req = req;
  1993. host->can_queue = req->length + 128;
  1994. if (IS_QLA2XXX_MIDTYPE(ha))
  1995. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  1996. else
  1997. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  1998. base_vha->vp_idx;
  1999. /* Set the SG table size based on ISP type */
  2000. if (!IS_FWI2_CAPABLE(ha)) {
  2001. if (IS_QLA2100(ha))
  2002. host->sg_tablesize = 32;
  2003. } else {
  2004. if (!IS_QLA82XX(ha))
  2005. host->sg_tablesize = QLA_SG_ALL;
  2006. }
  2007. ql_dbg(ql_dbg_init, base_vha, 0x0032,
  2008. "can_queue=%d, req=%p, "
  2009. "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
  2010. host->can_queue, base_vha->req,
  2011. base_vha->mgmt_svr_loop_id, host->sg_tablesize);
  2012. host->max_id = max_id;
  2013. host->this_id = 255;
  2014. host->cmd_per_lun = 3;
  2015. host->unique_id = host->host_no;
  2016. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
  2017. host->max_cmd_len = 32;
  2018. else
  2019. host->max_cmd_len = MAX_CMDSZ;
  2020. host->max_channel = MAX_BUSES - 1;
  2021. host->max_lun = ql2xmaxlun;
  2022. host->transportt = qla2xxx_transport_template;
  2023. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  2024. ql_dbg(ql_dbg_init, base_vha, 0x0033,
  2025. "max_id=%d this_id=%d "
  2026. "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
  2027. "max_lun=%d transportt=%p, vendor_id=%d.\n", host->max_id,
  2028. host->this_id, host->cmd_per_lun, host->unique_id,
  2029. host->max_cmd_len, host->max_channel, host->max_lun,
  2030. host->transportt, sht->vendor_id);
  2031. /* Set up the irqs */
  2032. ret = qla2x00_request_irqs(ha, rsp);
  2033. if (ret)
  2034. goto probe_init_failed;
  2035. pci_save_state(pdev);
  2036. /* Alloc arrays of request and response ring ptrs */
  2037. que_init:
  2038. if (!qla2x00_alloc_queues(ha)) {
  2039. ql_log(ql_log_fatal, base_vha, 0x003d,
  2040. "Failed to allocate memory for queue pointers.. aborting.\n");
  2041. goto probe_init_failed;
  2042. }
  2043. ha->rsp_q_map[0] = rsp;
  2044. ha->req_q_map[0] = req;
  2045. rsp->req = req;
  2046. req->rsp = rsp;
  2047. set_bit(0, ha->req_qid_map);
  2048. set_bit(0, ha->rsp_qid_map);
  2049. /* FWI2-capable only. */
  2050. req->req_q_in = &ha->iobase->isp24.req_q_in;
  2051. req->req_q_out = &ha->iobase->isp24.req_q_out;
  2052. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  2053. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  2054. if (ha->mqenable) {
  2055. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  2056. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  2057. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  2058. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  2059. }
  2060. if (IS_QLA82XX(ha)) {
  2061. req->req_q_out = &ha->iobase->isp82.req_q_out[0];
  2062. rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
  2063. rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
  2064. }
  2065. ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
  2066. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2067. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2068. ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
  2069. "req->req_q_in=%p req->req_q_out=%p "
  2070. "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2071. req->req_q_in, req->req_q_out,
  2072. rsp->rsp_q_in, rsp->rsp_q_out);
  2073. ql_dbg(ql_dbg_init, base_vha, 0x003e,
  2074. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2075. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2076. ql_dbg(ql_dbg_init, base_vha, 0x003f,
  2077. "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2078. req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
  2079. if (qla2x00_initialize_adapter(base_vha)) {
  2080. ql_log(ql_log_fatal, base_vha, 0x00d6,
  2081. "Failed to initialize adapter - Adapter flags %x.\n",
  2082. base_vha->device_flags);
  2083. if (IS_QLA82XX(ha)) {
  2084. qla82xx_idc_lock(ha);
  2085. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2086. QLA82XX_DEV_FAILED);
  2087. qla82xx_idc_unlock(ha);
  2088. ql_log(ql_log_fatal, base_vha, 0x00d7,
  2089. "HW State: FAILED.\n");
  2090. }
  2091. ret = -ENODEV;
  2092. goto probe_failed;
  2093. }
  2094. if (ha->mqenable) {
  2095. if (qla25xx_setup_mode(base_vha)) {
  2096. ql_log(ql_log_warn, base_vha, 0x00ec,
  2097. "Failed to create queues, falling back to single queue mode.\n");
  2098. goto que_init;
  2099. }
  2100. }
  2101. if (ha->flags.running_gold_fw)
  2102. goto skip_dpc;
  2103. /*
  2104. * Startup the kernel thread for this host adapter
  2105. */
  2106. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  2107. "%s_dpc", base_vha->host_str);
  2108. if (IS_ERR(ha->dpc_thread)) {
  2109. ql_log(ql_log_fatal, base_vha, 0x00ed,
  2110. "Failed to start DPC thread.\n");
  2111. ret = PTR_ERR(ha->dpc_thread);
  2112. goto probe_failed;
  2113. }
  2114. ql_dbg(ql_dbg_init, base_vha, 0x00ee,
  2115. "DPC thread started successfully.\n");
  2116. skip_dpc:
  2117. list_add_tail(&base_vha->list, &ha->vp_list);
  2118. base_vha->host->irq = ha->pdev->irq;
  2119. /* Initialized the timer */
  2120. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  2121. ql_dbg(ql_dbg_init, base_vha, 0x00ef,
  2122. "Started qla2x00_timer with "
  2123. "interval=%d.\n", WATCH_INTERVAL);
  2124. ql_dbg(ql_dbg_init, base_vha, 0x00f0,
  2125. "Detected hba at address=%p.\n",
  2126. ha);
  2127. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  2128. if (ha->fw_attributes & BIT_4) {
  2129. int prot = 0;
  2130. base_vha->flags.difdix_supported = 1;
  2131. ql_dbg(ql_dbg_init, base_vha, 0x00f1,
  2132. "Registering for DIF/DIX type 1 and 3 protection.\n");
  2133. if (ql2xenabledif == 1)
  2134. prot = SHOST_DIX_TYPE0_PROTECTION;
  2135. scsi_host_set_prot(host,
  2136. prot | SHOST_DIF_TYPE1_PROTECTION
  2137. | SHOST_DIF_TYPE2_PROTECTION
  2138. | SHOST_DIF_TYPE3_PROTECTION
  2139. | SHOST_DIX_TYPE1_PROTECTION
  2140. | SHOST_DIX_TYPE2_PROTECTION
  2141. | SHOST_DIX_TYPE3_PROTECTION);
  2142. scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
  2143. } else
  2144. base_vha->flags.difdix_supported = 0;
  2145. }
  2146. ha->isp_ops->enable_intrs(ha);
  2147. ret = scsi_add_host(host, &pdev->dev);
  2148. if (ret)
  2149. goto probe_failed;
  2150. base_vha->flags.init_done = 1;
  2151. base_vha->flags.online = 1;
  2152. ql_dbg(ql_dbg_init, base_vha, 0x00f2,
  2153. "Init done and hba is online.\n");
  2154. scsi_scan_host(host);
  2155. qla2x00_alloc_sysfs_attr(base_vha);
  2156. qla2x00_init_host_attr(base_vha);
  2157. qla2x00_dfs_setup(base_vha);
  2158. ql_log(ql_log_info, base_vha, 0x00fa,
  2159. "QLogic Fibre Channed HBA Driver: %s.\n",
  2160. qla2x00_version_str);
  2161. ql_log(ql_log_info, base_vha, 0x00fb,
  2162. "QLogic %s - %s.\n",
  2163. ha->model_number, ha->model_desc ? ha->model_desc : "");
  2164. ql_log(ql_log_info, base_vha, 0x00fc,
  2165. "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
  2166. pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
  2167. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
  2168. base_vha->host_no,
  2169. ha->isp_ops->fw_version_str(base_vha, fw_str));
  2170. return 0;
  2171. probe_init_failed:
  2172. qla2x00_free_req_que(ha, req);
  2173. qla2x00_free_rsp_que(ha, rsp);
  2174. ha->max_req_queues = ha->max_rsp_queues = 0;
  2175. probe_failed:
  2176. if (base_vha->timer_active)
  2177. qla2x00_stop_timer(base_vha);
  2178. base_vha->flags.online = 0;
  2179. if (ha->dpc_thread) {
  2180. struct task_struct *t = ha->dpc_thread;
  2181. ha->dpc_thread = NULL;
  2182. kthread_stop(t);
  2183. }
  2184. qla2x00_free_device(base_vha);
  2185. scsi_host_put(base_vha->host);
  2186. probe_hw_failed:
  2187. if (IS_QLA82XX(ha)) {
  2188. qla82xx_idc_lock(ha);
  2189. qla82xx_clear_drv_active(ha);
  2190. qla82xx_idc_unlock(ha);
  2191. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2192. if (!ql2xdbwr)
  2193. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2194. } else {
  2195. if (ha->iobase)
  2196. iounmap(ha->iobase);
  2197. }
  2198. pci_release_selected_regions(ha->pdev, ha->bars);
  2199. kfree(ha);
  2200. ha = NULL;
  2201. probe_out:
  2202. pci_disable_device(pdev);
  2203. return ret;
  2204. }
  2205. static void
  2206. qla2x00_shutdown(struct pci_dev *pdev)
  2207. {
  2208. scsi_qla_host_t *vha;
  2209. struct qla_hw_data *ha;
  2210. vha = pci_get_drvdata(pdev);
  2211. ha = vha->hw;
  2212. /* Turn-off FCE trace */
  2213. if (ha->flags.fce_enabled) {
  2214. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2215. ha->flags.fce_enabled = 0;
  2216. }
  2217. /* Turn-off EFT trace */
  2218. if (ha->eft)
  2219. qla2x00_disable_eft_trace(vha);
  2220. /* Stop currently executing firmware. */
  2221. qla2x00_try_to_stop_firmware(vha);
  2222. /* Turn adapter off line */
  2223. vha->flags.online = 0;
  2224. /* turn-off interrupts on the card */
  2225. if (ha->interrupts_on) {
  2226. vha->flags.init_done = 0;
  2227. ha->isp_ops->disable_intrs(ha);
  2228. }
  2229. qla2x00_free_irqs(vha);
  2230. qla2x00_free_fw_dump(ha);
  2231. }
  2232. static void
  2233. qla2x00_remove_one(struct pci_dev *pdev)
  2234. {
  2235. scsi_qla_host_t *base_vha, *vha;
  2236. struct qla_hw_data *ha;
  2237. unsigned long flags;
  2238. base_vha = pci_get_drvdata(pdev);
  2239. ha = base_vha->hw;
  2240. mutex_lock(&ha->vport_lock);
  2241. while (ha->cur_vport_count) {
  2242. struct Scsi_Host *scsi_host;
  2243. spin_lock_irqsave(&ha->vport_slock, flags);
  2244. BUG_ON(base_vha->list.next == &ha->vp_list);
  2245. /* This assumes first entry in ha->vp_list is always base vha */
  2246. vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
  2247. scsi_host = scsi_host_get(vha->host);
  2248. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2249. mutex_unlock(&ha->vport_lock);
  2250. fc_vport_terminate(vha->fc_vport);
  2251. scsi_host_put(vha->host);
  2252. mutex_lock(&ha->vport_lock);
  2253. }
  2254. mutex_unlock(&ha->vport_lock);
  2255. set_bit(UNLOADING, &base_vha->dpc_flags);
  2256. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2257. qla2x00_dfs_remove(base_vha);
  2258. qla84xx_put_chip(base_vha);
  2259. /* Disable timer */
  2260. if (base_vha->timer_active)
  2261. qla2x00_stop_timer(base_vha);
  2262. base_vha->flags.online = 0;
  2263. /* Flush the work queue and remove it */
  2264. if (ha->wq) {
  2265. flush_workqueue(ha->wq);
  2266. destroy_workqueue(ha->wq);
  2267. ha->wq = NULL;
  2268. }
  2269. /* Kill the kernel thread for this host */
  2270. if (ha->dpc_thread) {
  2271. struct task_struct *t = ha->dpc_thread;
  2272. /*
  2273. * qla2xxx_wake_dpc checks for ->dpc_thread
  2274. * so we need to zero it out.
  2275. */
  2276. ha->dpc_thread = NULL;
  2277. kthread_stop(t);
  2278. }
  2279. qla2x00_free_sysfs_attr(base_vha);
  2280. fc_remove_host(base_vha->host);
  2281. scsi_remove_host(base_vha->host);
  2282. qla2x00_free_device(base_vha);
  2283. scsi_host_put(base_vha->host);
  2284. if (IS_QLA82XX(ha)) {
  2285. qla82xx_idc_lock(ha);
  2286. qla82xx_clear_drv_active(ha);
  2287. qla82xx_idc_unlock(ha);
  2288. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2289. if (!ql2xdbwr)
  2290. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2291. } else {
  2292. if (ha->iobase)
  2293. iounmap(ha->iobase);
  2294. if (ha->mqiobase)
  2295. iounmap(ha->mqiobase);
  2296. }
  2297. pci_release_selected_regions(ha->pdev, ha->bars);
  2298. kfree(ha);
  2299. ha = NULL;
  2300. pci_disable_pcie_error_reporting(pdev);
  2301. pci_disable_device(pdev);
  2302. pci_set_drvdata(pdev, NULL);
  2303. }
  2304. static void
  2305. qla2x00_free_device(scsi_qla_host_t *vha)
  2306. {
  2307. struct qla_hw_data *ha = vha->hw;
  2308. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2309. /* Disable timer */
  2310. if (vha->timer_active)
  2311. qla2x00_stop_timer(vha);
  2312. /* Kill the kernel thread for this host */
  2313. if (ha->dpc_thread) {
  2314. struct task_struct *t = ha->dpc_thread;
  2315. /*
  2316. * qla2xxx_wake_dpc checks for ->dpc_thread
  2317. * so we need to zero it out.
  2318. */
  2319. ha->dpc_thread = NULL;
  2320. kthread_stop(t);
  2321. }
  2322. qla25xx_delete_queues(vha);
  2323. if (ha->flags.fce_enabled)
  2324. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2325. if (ha->eft)
  2326. qla2x00_disable_eft_trace(vha);
  2327. /* Stop currently executing firmware. */
  2328. qla2x00_try_to_stop_firmware(vha);
  2329. vha->flags.online = 0;
  2330. /* turn-off interrupts on the card */
  2331. if (ha->interrupts_on) {
  2332. vha->flags.init_done = 0;
  2333. ha->isp_ops->disable_intrs(ha);
  2334. }
  2335. qla2x00_free_irqs(vha);
  2336. qla2x00_free_fcports(vha);
  2337. qla2x00_mem_free(ha);
  2338. qla2x00_free_queues(ha);
  2339. }
  2340. void qla2x00_free_fcports(struct scsi_qla_host *vha)
  2341. {
  2342. fc_port_t *fcport, *tfcport;
  2343. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  2344. list_del(&fcport->list);
  2345. kfree(fcport);
  2346. fcport = NULL;
  2347. }
  2348. }
  2349. static inline void
  2350. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  2351. int defer)
  2352. {
  2353. struct fc_rport *rport;
  2354. scsi_qla_host_t *base_vha;
  2355. unsigned long flags;
  2356. if (!fcport->rport)
  2357. return;
  2358. rport = fcport->rport;
  2359. if (defer) {
  2360. base_vha = pci_get_drvdata(vha->hw->pdev);
  2361. spin_lock_irqsave(vha->host->host_lock, flags);
  2362. fcport->drport = rport;
  2363. spin_unlock_irqrestore(vha->host->host_lock, flags);
  2364. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2365. qla2xxx_wake_dpc(base_vha);
  2366. } else
  2367. fc_remote_port_delete(rport);
  2368. }
  2369. /*
  2370. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  2371. *
  2372. * Input: ha = adapter block pointer. fcport = port structure pointer.
  2373. *
  2374. * Return: None.
  2375. *
  2376. * Context:
  2377. */
  2378. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  2379. int do_login, int defer)
  2380. {
  2381. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2382. vha->vp_idx == fcport->vp_idx) {
  2383. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2384. qla2x00_schedule_rport_del(vha, fcport, defer);
  2385. }
  2386. /*
  2387. * We may need to retry the login, so don't change the state of the
  2388. * port but do the retries.
  2389. */
  2390. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  2391. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2392. if (!do_login)
  2393. return;
  2394. if (fcport->login_retry == 0) {
  2395. fcport->login_retry = vha->hw->login_retry_count;
  2396. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2397. ql_dbg(ql_dbg_disc, vha, 0x2067,
  2398. "Port login retry "
  2399. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  2400. "id = 0x%04x retry cnt=%d.\n",
  2401. fcport->port_name[0], fcport->port_name[1],
  2402. fcport->port_name[2], fcport->port_name[3],
  2403. fcport->port_name[4], fcport->port_name[5],
  2404. fcport->port_name[6], fcport->port_name[7],
  2405. fcport->loop_id, fcport->login_retry);
  2406. }
  2407. }
  2408. /*
  2409. * qla2x00_mark_all_devices_lost
  2410. * Updates fcport state when device goes offline.
  2411. *
  2412. * Input:
  2413. * ha = adapter block pointer.
  2414. * fcport = port structure pointer.
  2415. *
  2416. * Return:
  2417. * None.
  2418. *
  2419. * Context:
  2420. */
  2421. void
  2422. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  2423. {
  2424. fc_port_t *fcport;
  2425. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2426. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
  2427. continue;
  2428. /*
  2429. * No point in marking the device as lost, if the device is
  2430. * already DEAD.
  2431. */
  2432. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  2433. continue;
  2434. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2435. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2436. if (defer)
  2437. qla2x00_schedule_rport_del(vha, fcport, defer);
  2438. else if (vha->vp_idx == fcport->vp_idx)
  2439. qla2x00_schedule_rport_del(vha, fcport, defer);
  2440. }
  2441. }
  2442. }
  2443. /*
  2444. * qla2x00_mem_alloc
  2445. * Allocates adapter memory.
  2446. *
  2447. * Returns:
  2448. * 0 = success.
  2449. * !0 = failure.
  2450. */
  2451. static int
  2452. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  2453. struct req_que **req, struct rsp_que **rsp)
  2454. {
  2455. char name[16];
  2456. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  2457. &ha->init_cb_dma, GFP_KERNEL);
  2458. if (!ha->init_cb)
  2459. goto fail;
  2460. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  2461. &ha->gid_list_dma, GFP_KERNEL);
  2462. if (!ha->gid_list)
  2463. goto fail_free_init_cb;
  2464. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  2465. if (!ha->srb_mempool)
  2466. goto fail_free_gid_list;
  2467. if (IS_QLA82XX(ha)) {
  2468. /* Allocate cache for CT6 Ctx. */
  2469. if (!ctx_cachep) {
  2470. ctx_cachep = kmem_cache_create("qla2xxx_ctx",
  2471. sizeof(struct ct6_dsd), 0,
  2472. SLAB_HWCACHE_ALIGN, NULL);
  2473. if (!ctx_cachep)
  2474. goto fail_free_gid_list;
  2475. }
  2476. ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
  2477. ctx_cachep);
  2478. if (!ha->ctx_mempool)
  2479. goto fail_free_srb_mempool;
  2480. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
  2481. "ctx_cachep=%p ctx_mempool=%p.\n",
  2482. ctx_cachep, ha->ctx_mempool);
  2483. }
  2484. /* Get memory for cached NVRAM */
  2485. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  2486. if (!ha->nvram)
  2487. goto fail_free_ctx_mempool;
  2488. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  2489. ha->pdev->device);
  2490. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2491. DMA_POOL_SIZE, 8, 0);
  2492. if (!ha->s_dma_pool)
  2493. goto fail_free_nvram;
  2494. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
  2495. "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
  2496. ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
  2497. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2498. ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2499. DSD_LIST_DMA_POOL_SIZE, 8, 0);
  2500. if (!ha->dl_dma_pool) {
  2501. ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
  2502. "Failed to allocate memory for dl_dma_pool.\n");
  2503. goto fail_s_dma_pool;
  2504. }
  2505. ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2506. FCP_CMND_DMA_POOL_SIZE, 8, 0);
  2507. if (!ha->fcp_cmnd_dma_pool) {
  2508. ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
  2509. "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
  2510. goto fail_dl_dma_pool;
  2511. }
  2512. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
  2513. "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
  2514. ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
  2515. }
  2516. /* Allocate memory for SNS commands */
  2517. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2518. /* Get consistent memory allocated for SNS commands */
  2519. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  2520. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  2521. if (!ha->sns_cmd)
  2522. goto fail_dma_pool;
  2523. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
  2524. "sns_cmd.\n", ha->sns_cmd);
  2525. } else {
  2526. /* Get consistent memory allocated for MS IOCB */
  2527. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2528. &ha->ms_iocb_dma);
  2529. if (!ha->ms_iocb)
  2530. goto fail_dma_pool;
  2531. /* Get consistent memory allocated for CT SNS commands */
  2532. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  2533. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  2534. if (!ha->ct_sns)
  2535. goto fail_free_ms_iocb;
  2536. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
  2537. "ms_iocb=%p ct_sns=%p.\n",
  2538. ha->ms_iocb, ha->ct_sns);
  2539. }
  2540. /* Allocate memory for request ring */
  2541. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  2542. if (!*req) {
  2543. ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
  2544. "Failed to allocate memory for req.\n");
  2545. goto fail_req;
  2546. }
  2547. (*req)->length = req_len;
  2548. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2549. ((*req)->length + 1) * sizeof(request_t),
  2550. &(*req)->dma, GFP_KERNEL);
  2551. if (!(*req)->ring) {
  2552. ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
  2553. "Failed to allocate memory for req_ring.\n");
  2554. goto fail_req_ring;
  2555. }
  2556. /* Allocate memory for response ring */
  2557. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  2558. if (!*rsp) {
  2559. ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
  2560. "Failed to allocate memory for rsp.\n");
  2561. goto fail_rsp;
  2562. }
  2563. (*rsp)->hw = ha;
  2564. (*rsp)->length = rsp_len;
  2565. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  2566. ((*rsp)->length + 1) * sizeof(response_t),
  2567. &(*rsp)->dma, GFP_KERNEL);
  2568. if (!(*rsp)->ring) {
  2569. ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
  2570. "Failed to allocate memory for rsp_ring.\n");
  2571. goto fail_rsp_ring;
  2572. }
  2573. (*req)->rsp = *rsp;
  2574. (*rsp)->req = *req;
  2575. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
  2576. "req=%p req->length=%d req->ring=%p rsp=%p "
  2577. "rsp->length=%d rsp->ring=%p.\n",
  2578. *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
  2579. (*rsp)->ring);
  2580. /* Allocate memory for NVRAM data for vports */
  2581. if (ha->nvram_npiv_size) {
  2582. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  2583. ha->nvram_npiv_size, GFP_KERNEL);
  2584. if (!ha->npiv_info) {
  2585. ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
  2586. "Failed to allocate memory for npiv_info.\n");
  2587. goto fail_npiv_info;
  2588. }
  2589. } else
  2590. ha->npiv_info = NULL;
  2591. /* Get consistent memory allocated for EX-INIT-CB. */
  2592. if (IS_QLA8XXX_TYPE(ha)) {
  2593. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2594. &ha->ex_init_cb_dma);
  2595. if (!ha->ex_init_cb)
  2596. goto fail_ex_init_cb;
  2597. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
  2598. "ex_init_cb=%p.\n", ha->ex_init_cb);
  2599. }
  2600. INIT_LIST_HEAD(&ha->gbl_dsd_list);
  2601. /* Get consistent memory allocated for Async Port-Database. */
  2602. if (!IS_FWI2_CAPABLE(ha)) {
  2603. ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  2604. &ha->async_pd_dma);
  2605. if (!ha->async_pd)
  2606. goto fail_async_pd;
  2607. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
  2608. "async_pd=%p.\n", ha->async_pd);
  2609. }
  2610. INIT_LIST_HEAD(&ha->vp_list);
  2611. return 1;
  2612. fail_async_pd:
  2613. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  2614. fail_ex_init_cb:
  2615. kfree(ha->npiv_info);
  2616. fail_npiv_info:
  2617. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  2618. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  2619. (*rsp)->ring = NULL;
  2620. (*rsp)->dma = 0;
  2621. fail_rsp_ring:
  2622. kfree(*rsp);
  2623. fail_rsp:
  2624. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  2625. sizeof(request_t), (*req)->ring, (*req)->dma);
  2626. (*req)->ring = NULL;
  2627. (*req)->dma = 0;
  2628. fail_req_ring:
  2629. kfree(*req);
  2630. fail_req:
  2631. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2632. ha->ct_sns, ha->ct_sns_dma);
  2633. ha->ct_sns = NULL;
  2634. ha->ct_sns_dma = 0;
  2635. fail_free_ms_iocb:
  2636. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2637. ha->ms_iocb = NULL;
  2638. ha->ms_iocb_dma = 0;
  2639. fail_dma_pool:
  2640. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2641. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  2642. ha->fcp_cmnd_dma_pool = NULL;
  2643. }
  2644. fail_dl_dma_pool:
  2645. if (IS_QLA82XX(ha) || ql2xenabledif) {
  2646. dma_pool_destroy(ha->dl_dma_pool);
  2647. ha->dl_dma_pool = NULL;
  2648. }
  2649. fail_s_dma_pool:
  2650. dma_pool_destroy(ha->s_dma_pool);
  2651. ha->s_dma_pool = NULL;
  2652. fail_free_nvram:
  2653. kfree(ha->nvram);
  2654. ha->nvram = NULL;
  2655. fail_free_ctx_mempool:
  2656. mempool_destroy(ha->ctx_mempool);
  2657. ha->ctx_mempool = NULL;
  2658. fail_free_srb_mempool:
  2659. mempool_destroy(ha->srb_mempool);
  2660. ha->srb_mempool = NULL;
  2661. fail_free_gid_list:
  2662. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2663. ha->gid_list_dma);
  2664. ha->gid_list = NULL;
  2665. ha->gid_list_dma = 0;
  2666. fail_free_init_cb:
  2667. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  2668. ha->init_cb_dma);
  2669. ha->init_cb = NULL;
  2670. ha->init_cb_dma = 0;
  2671. fail:
  2672. ql_log(ql_log_fatal, NULL, 0x0030,
  2673. "Memory allocation failure.\n");
  2674. return -ENOMEM;
  2675. }
  2676. /*
  2677. * qla2x00_free_fw_dump
  2678. * Frees fw dump stuff.
  2679. *
  2680. * Input:
  2681. * ha = adapter block pointer.
  2682. */
  2683. static void
  2684. qla2x00_free_fw_dump(struct qla_hw_data *ha)
  2685. {
  2686. if (ha->fce)
  2687. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  2688. ha->fce_dma);
  2689. if (ha->fw_dump) {
  2690. if (ha->eft)
  2691. dma_free_coherent(&ha->pdev->dev,
  2692. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  2693. vfree(ha->fw_dump);
  2694. }
  2695. ha->fce = NULL;
  2696. ha->fce_dma = 0;
  2697. ha->eft = NULL;
  2698. ha->eft_dma = 0;
  2699. ha->fw_dump = NULL;
  2700. ha->fw_dumped = 0;
  2701. ha->fw_dump_reading = 0;
  2702. }
  2703. /*
  2704. * qla2x00_mem_free
  2705. * Frees all adapter allocated memory.
  2706. *
  2707. * Input:
  2708. * ha = adapter block pointer.
  2709. */
  2710. static void
  2711. qla2x00_mem_free(struct qla_hw_data *ha)
  2712. {
  2713. qla2x00_free_fw_dump(ha);
  2714. if (ha->srb_mempool)
  2715. mempool_destroy(ha->srb_mempool);
  2716. if (ha->dcbx_tlv)
  2717. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  2718. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  2719. if (ha->xgmac_data)
  2720. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  2721. ha->xgmac_data, ha->xgmac_data_dma);
  2722. if (ha->sns_cmd)
  2723. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  2724. ha->sns_cmd, ha->sns_cmd_dma);
  2725. if (ha->ct_sns)
  2726. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2727. ha->ct_sns, ha->ct_sns_dma);
  2728. if (ha->sfp_data)
  2729. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  2730. if (ha->edc_data)
  2731. dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
  2732. if (ha->ms_iocb)
  2733. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2734. if (ha->ex_init_cb)
  2735. dma_pool_free(ha->s_dma_pool,
  2736. ha->ex_init_cb, ha->ex_init_cb_dma);
  2737. if (ha->async_pd)
  2738. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  2739. if (ha->s_dma_pool)
  2740. dma_pool_destroy(ha->s_dma_pool);
  2741. if (ha->gid_list)
  2742. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2743. ha->gid_list_dma);
  2744. if (IS_QLA82XX(ha)) {
  2745. if (!list_empty(&ha->gbl_dsd_list)) {
  2746. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  2747. /* clean up allocated prev pool */
  2748. list_for_each_entry_safe(dsd_ptr,
  2749. tdsd_ptr, &ha->gbl_dsd_list, list) {
  2750. dma_pool_free(ha->dl_dma_pool,
  2751. dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
  2752. list_del(&dsd_ptr->list);
  2753. kfree(dsd_ptr);
  2754. }
  2755. }
  2756. }
  2757. if (ha->dl_dma_pool)
  2758. dma_pool_destroy(ha->dl_dma_pool);
  2759. if (ha->fcp_cmnd_dma_pool)
  2760. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  2761. if (ha->ctx_mempool)
  2762. mempool_destroy(ha->ctx_mempool);
  2763. if (ha->init_cb)
  2764. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  2765. ha->init_cb, ha->init_cb_dma);
  2766. vfree(ha->optrom_buffer);
  2767. kfree(ha->nvram);
  2768. kfree(ha->npiv_info);
  2769. ha->srb_mempool = NULL;
  2770. ha->ctx_mempool = NULL;
  2771. ha->sns_cmd = NULL;
  2772. ha->sns_cmd_dma = 0;
  2773. ha->ct_sns = NULL;
  2774. ha->ct_sns_dma = 0;
  2775. ha->ms_iocb = NULL;
  2776. ha->ms_iocb_dma = 0;
  2777. ha->init_cb = NULL;
  2778. ha->init_cb_dma = 0;
  2779. ha->ex_init_cb = NULL;
  2780. ha->ex_init_cb_dma = 0;
  2781. ha->async_pd = NULL;
  2782. ha->async_pd_dma = 0;
  2783. ha->s_dma_pool = NULL;
  2784. ha->dl_dma_pool = NULL;
  2785. ha->fcp_cmnd_dma_pool = NULL;
  2786. ha->gid_list = NULL;
  2787. ha->gid_list_dma = 0;
  2788. }
  2789. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  2790. struct qla_hw_data *ha)
  2791. {
  2792. struct Scsi_Host *host;
  2793. struct scsi_qla_host *vha = NULL;
  2794. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  2795. if (host == NULL) {
  2796. ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
  2797. "Failed to allocate host from the scsi layer, aborting.\n");
  2798. goto fail;
  2799. }
  2800. /* Clear our data area */
  2801. vha = shost_priv(host);
  2802. memset(vha, 0, sizeof(scsi_qla_host_t));
  2803. vha->host = host;
  2804. vha->host_no = host->host_no;
  2805. vha->hw = ha;
  2806. INIT_LIST_HEAD(&vha->vp_fcports);
  2807. INIT_LIST_HEAD(&vha->work_list);
  2808. INIT_LIST_HEAD(&vha->list);
  2809. spin_lock_init(&vha->work_lock);
  2810. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  2811. ql_dbg(ql_dbg_init, vha, 0x0041,
  2812. "Allocated the host=%p hw=%p vha=%p dev_name=%s",
  2813. vha->host, vha->hw, vha,
  2814. dev_name(&(ha->pdev->dev)));
  2815. return vha;
  2816. fail:
  2817. return vha;
  2818. }
  2819. static struct qla_work_evt *
  2820. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  2821. {
  2822. struct qla_work_evt *e;
  2823. uint8_t bail;
  2824. QLA_VHA_MARK_BUSY(vha, bail);
  2825. if (bail)
  2826. return NULL;
  2827. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  2828. if (!e) {
  2829. QLA_VHA_MARK_NOT_BUSY(vha);
  2830. return NULL;
  2831. }
  2832. INIT_LIST_HEAD(&e->list);
  2833. e->type = type;
  2834. e->flags = QLA_EVT_FLAG_FREE;
  2835. return e;
  2836. }
  2837. static int
  2838. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  2839. {
  2840. unsigned long flags;
  2841. spin_lock_irqsave(&vha->work_lock, flags);
  2842. list_add_tail(&e->list, &vha->work_list);
  2843. spin_unlock_irqrestore(&vha->work_lock, flags);
  2844. qla2xxx_wake_dpc(vha);
  2845. return QLA_SUCCESS;
  2846. }
  2847. int
  2848. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  2849. u32 data)
  2850. {
  2851. struct qla_work_evt *e;
  2852. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  2853. if (!e)
  2854. return QLA_FUNCTION_FAILED;
  2855. e->u.aen.code = code;
  2856. e->u.aen.data = data;
  2857. return qla2x00_post_work(vha, e);
  2858. }
  2859. int
  2860. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  2861. {
  2862. struct qla_work_evt *e;
  2863. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  2864. if (!e)
  2865. return QLA_FUNCTION_FAILED;
  2866. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  2867. return qla2x00_post_work(vha, e);
  2868. }
  2869. #define qla2x00_post_async_work(name, type) \
  2870. int qla2x00_post_async_##name##_work( \
  2871. struct scsi_qla_host *vha, \
  2872. fc_port_t *fcport, uint16_t *data) \
  2873. { \
  2874. struct qla_work_evt *e; \
  2875. \
  2876. e = qla2x00_alloc_work(vha, type); \
  2877. if (!e) \
  2878. return QLA_FUNCTION_FAILED; \
  2879. \
  2880. e->u.logio.fcport = fcport; \
  2881. if (data) { \
  2882. e->u.logio.data[0] = data[0]; \
  2883. e->u.logio.data[1] = data[1]; \
  2884. } \
  2885. return qla2x00_post_work(vha, e); \
  2886. }
  2887. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  2888. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  2889. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  2890. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  2891. qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
  2892. qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
  2893. int
  2894. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  2895. {
  2896. struct qla_work_evt *e;
  2897. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  2898. if (!e)
  2899. return QLA_FUNCTION_FAILED;
  2900. e->u.uevent.code = code;
  2901. return qla2x00_post_work(vha, e);
  2902. }
  2903. static void
  2904. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  2905. {
  2906. char event_string[40];
  2907. char *envp[] = { event_string, NULL };
  2908. switch (code) {
  2909. case QLA_UEVENT_CODE_FW_DUMP:
  2910. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  2911. vha->host_no);
  2912. break;
  2913. default:
  2914. /* do nothing */
  2915. break;
  2916. }
  2917. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  2918. }
  2919. void
  2920. qla2x00_do_work(struct scsi_qla_host *vha)
  2921. {
  2922. struct qla_work_evt *e, *tmp;
  2923. unsigned long flags;
  2924. LIST_HEAD(work);
  2925. spin_lock_irqsave(&vha->work_lock, flags);
  2926. list_splice_init(&vha->work_list, &work);
  2927. spin_unlock_irqrestore(&vha->work_lock, flags);
  2928. list_for_each_entry_safe(e, tmp, &work, list) {
  2929. list_del_init(&e->list);
  2930. switch (e->type) {
  2931. case QLA_EVT_AEN:
  2932. fc_host_post_event(vha->host, fc_get_event_number(),
  2933. e->u.aen.code, e->u.aen.data);
  2934. break;
  2935. case QLA_EVT_IDC_ACK:
  2936. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  2937. break;
  2938. case QLA_EVT_ASYNC_LOGIN:
  2939. qla2x00_async_login(vha, e->u.logio.fcport,
  2940. e->u.logio.data);
  2941. break;
  2942. case QLA_EVT_ASYNC_LOGIN_DONE:
  2943. qla2x00_async_login_done(vha, e->u.logio.fcport,
  2944. e->u.logio.data);
  2945. break;
  2946. case QLA_EVT_ASYNC_LOGOUT:
  2947. qla2x00_async_logout(vha, e->u.logio.fcport);
  2948. break;
  2949. case QLA_EVT_ASYNC_LOGOUT_DONE:
  2950. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  2951. e->u.logio.data);
  2952. break;
  2953. case QLA_EVT_ASYNC_ADISC:
  2954. qla2x00_async_adisc(vha, e->u.logio.fcport,
  2955. e->u.logio.data);
  2956. break;
  2957. case QLA_EVT_ASYNC_ADISC_DONE:
  2958. qla2x00_async_adisc_done(vha, e->u.logio.fcport,
  2959. e->u.logio.data);
  2960. break;
  2961. case QLA_EVT_UEVENT:
  2962. qla2x00_uevent_emit(vha, e->u.uevent.code);
  2963. break;
  2964. }
  2965. if (e->flags & QLA_EVT_FLAG_FREE)
  2966. kfree(e);
  2967. /* For each work completed decrement vha ref count */
  2968. QLA_VHA_MARK_NOT_BUSY(vha);
  2969. }
  2970. }
  2971. /* Relogins all the fcports of a vport
  2972. * Context: dpc thread
  2973. */
  2974. void qla2x00_relogin(struct scsi_qla_host *vha)
  2975. {
  2976. fc_port_t *fcport;
  2977. int status;
  2978. uint16_t next_loopid = 0;
  2979. struct qla_hw_data *ha = vha->hw;
  2980. uint16_t data[2];
  2981. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2982. /*
  2983. * If the port is not ONLINE then try to login
  2984. * to it if we haven't run out of retries.
  2985. */
  2986. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  2987. fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
  2988. fcport->login_retry--;
  2989. if (fcport->flags & FCF_FABRIC_DEVICE) {
  2990. if (fcport->flags & FCF_FCP2_DEVICE)
  2991. ha->isp_ops->fabric_logout(vha,
  2992. fcport->loop_id,
  2993. fcport->d_id.b.domain,
  2994. fcport->d_id.b.area,
  2995. fcport->d_id.b.al_pa);
  2996. if (fcport->loop_id == FC_NO_LOOP_ID) {
  2997. fcport->loop_id = next_loopid =
  2998. ha->min_external_loopid;
  2999. status = qla2x00_find_new_loop_id(
  3000. vha, fcport);
  3001. if (status != QLA_SUCCESS) {
  3002. /* Ran out of IDs to use */
  3003. break;
  3004. }
  3005. }
  3006. if (IS_ALOGIO_CAPABLE(ha)) {
  3007. fcport->flags |= FCF_ASYNC_SENT;
  3008. data[0] = 0;
  3009. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  3010. status = qla2x00_post_async_login_work(
  3011. vha, fcport, data);
  3012. if (status == QLA_SUCCESS)
  3013. continue;
  3014. /* Attempt a retry. */
  3015. status = 1;
  3016. } else
  3017. status = qla2x00_fabric_login(vha,
  3018. fcport, &next_loopid);
  3019. } else
  3020. status = qla2x00_local_device_login(vha,
  3021. fcport);
  3022. if (status == QLA_SUCCESS) {
  3023. fcport->old_loop_id = fcport->loop_id;
  3024. ql_dbg(ql_dbg_disc, vha, 0x2003,
  3025. "Port login OK: logged in ID 0x%x.\n",
  3026. fcport->loop_id);
  3027. qla2x00_update_fcport(vha, fcport);
  3028. } else if (status == 1) {
  3029. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  3030. /* retry the login again */
  3031. ql_dbg(ql_dbg_disc, vha, 0x2007,
  3032. "Retrying %d login again loop_id 0x%x.\n",
  3033. fcport->login_retry, fcport->loop_id);
  3034. } else {
  3035. fcport->login_retry = 0;
  3036. }
  3037. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  3038. fcport->loop_id = FC_NO_LOOP_ID;
  3039. }
  3040. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3041. break;
  3042. }
  3043. }
  3044. /**************************************************************************
  3045. * qla2x00_do_dpc
  3046. * This kernel thread is a task that is schedule by the interrupt handler
  3047. * to perform the background processing for interrupts.
  3048. *
  3049. * Notes:
  3050. * This task always run in the context of a kernel thread. It
  3051. * is kick-off by the driver's detect code and starts up
  3052. * up one per adapter. It immediately goes to sleep and waits for
  3053. * some fibre event. When either the interrupt handler or
  3054. * the timer routine detects a event it will one of the task
  3055. * bits then wake us up.
  3056. **************************************************************************/
  3057. static int
  3058. qla2x00_do_dpc(void *data)
  3059. {
  3060. int rval;
  3061. scsi_qla_host_t *base_vha;
  3062. struct qla_hw_data *ha;
  3063. ha = (struct qla_hw_data *)data;
  3064. base_vha = pci_get_drvdata(ha->pdev);
  3065. set_user_nice(current, -20);
  3066. set_current_state(TASK_INTERRUPTIBLE);
  3067. while (!kthread_should_stop()) {
  3068. ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
  3069. "DPC handler sleeping.\n");
  3070. schedule();
  3071. __set_current_state(TASK_RUNNING);
  3072. ql_dbg(ql_dbg_dpc, base_vha, 0x4001,
  3073. "DPC handler waking up.\n");
  3074. ql_dbg(ql_dbg_dpc, base_vha, 0x4002,
  3075. "dpc_flags=0x%lx.\n", base_vha->dpc_flags);
  3076. /* Initialization not yet finished. Don't do anything yet. */
  3077. if (!base_vha->flags.init_done)
  3078. continue;
  3079. if (ha->flags.eeh_busy) {
  3080. ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
  3081. "eeh_busy=%d.\n", ha->flags.eeh_busy);
  3082. continue;
  3083. }
  3084. ha->dpc_active = 1;
  3085. if (ha->flags.mbox_busy) {
  3086. ha->dpc_active = 0;
  3087. continue;
  3088. }
  3089. qla2x00_do_work(base_vha);
  3090. if (IS_QLA82XX(ha)) {
  3091. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  3092. &base_vha->dpc_flags)) {
  3093. qla82xx_idc_lock(ha);
  3094. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3095. QLA82XX_DEV_FAILED);
  3096. qla82xx_idc_unlock(ha);
  3097. ql_log(ql_log_info, base_vha, 0x4004,
  3098. "HW State: FAILED.\n");
  3099. qla82xx_device_state_handler(base_vha);
  3100. continue;
  3101. }
  3102. if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
  3103. &base_vha->dpc_flags)) {
  3104. ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
  3105. "FCoE context reset scheduled.\n");
  3106. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  3107. &base_vha->dpc_flags))) {
  3108. if (qla82xx_fcoe_ctx_reset(base_vha)) {
  3109. /* FCoE-ctx reset failed.
  3110. * Escalate to chip-reset
  3111. */
  3112. set_bit(ISP_ABORT_NEEDED,
  3113. &base_vha->dpc_flags);
  3114. }
  3115. clear_bit(ABORT_ISP_ACTIVE,
  3116. &base_vha->dpc_flags);
  3117. }
  3118. ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
  3119. "FCoE context reset end.\n");
  3120. }
  3121. }
  3122. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  3123. &base_vha->dpc_flags)) {
  3124. ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
  3125. "ISP abort scheduled.\n");
  3126. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  3127. &base_vha->dpc_flags))) {
  3128. if (ha->isp_ops->abort_isp(base_vha)) {
  3129. /* failed. retry later */
  3130. set_bit(ISP_ABORT_NEEDED,
  3131. &base_vha->dpc_flags);
  3132. }
  3133. clear_bit(ABORT_ISP_ACTIVE,
  3134. &base_vha->dpc_flags);
  3135. }
  3136. ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
  3137. "ISP abort end.\n");
  3138. }
  3139. if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
  3140. qla2x00_update_fcports(base_vha);
  3141. clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  3142. }
  3143. if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
  3144. ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
  3145. "Quiescence mode scheduled.\n");
  3146. qla82xx_device_state_handler(base_vha);
  3147. clear_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags);
  3148. if (!ha->flags.quiesce_owner) {
  3149. qla2x00_perform_loop_resync(base_vha);
  3150. qla82xx_idc_lock(ha);
  3151. qla82xx_clear_qsnt_ready(base_vha);
  3152. qla82xx_idc_unlock(ha);
  3153. }
  3154. ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
  3155. "Quiescence mode end.\n");
  3156. }
  3157. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  3158. &base_vha->dpc_flags) &&
  3159. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  3160. ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
  3161. "Reset marker scheduled.\n");
  3162. qla2x00_rst_aen(base_vha);
  3163. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  3164. ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
  3165. "Reset marker end.\n");
  3166. }
  3167. /* Retry each device up to login retry count */
  3168. if ((test_and_clear_bit(RELOGIN_NEEDED,
  3169. &base_vha->dpc_flags)) &&
  3170. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  3171. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  3172. ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
  3173. "Relogin scheduled.\n");
  3174. qla2x00_relogin(base_vha);
  3175. ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
  3176. "Relogin end.\n");
  3177. }
  3178. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  3179. &base_vha->dpc_flags)) {
  3180. ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
  3181. "Loop resync scheduled.\n");
  3182. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  3183. &base_vha->dpc_flags))) {
  3184. rval = qla2x00_loop_resync(base_vha);
  3185. clear_bit(LOOP_RESYNC_ACTIVE,
  3186. &base_vha->dpc_flags);
  3187. }
  3188. ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
  3189. "Loop resync end.\n");
  3190. }
  3191. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  3192. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  3193. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  3194. qla2xxx_flash_npiv_conf(base_vha);
  3195. }
  3196. if (!ha->interrupts_on)
  3197. ha->isp_ops->enable_intrs(ha);
  3198. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  3199. &base_vha->dpc_flags))
  3200. ha->isp_ops->beacon_blink(base_vha);
  3201. qla2x00_do_dpc_all_vps(base_vha);
  3202. ha->dpc_active = 0;
  3203. set_current_state(TASK_INTERRUPTIBLE);
  3204. } /* End of while(1) */
  3205. __set_current_state(TASK_RUNNING);
  3206. ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
  3207. "DPC handler exiting.\n");
  3208. /*
  3209. * Make sure that nobody tries to wake us up again.
  3210. */
  3211. ha->dpc_active = 0;
  3212. /* Cleanup any residual CTX SRBs. */
  3213. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  3214. return 0;
  3215. }
  3216. void
  3217. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  3218. {
  3219. struct qla_hw_data *ha = vha->hw;
  3220. struct task_struct *t = ha->dpc_thread;
  3221. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  3222. wake_up_process(t);
  3223. }
  3224. /*
  3225. * qla2x00_rst_aen
  3226. * Processes asynchronous reset.
  3227. *
  3228. * Input:
  3229. * ha = adapter block pointer.
  3230. */
  3231. static void
  3232. qla2x00_rst_aen(scsi_qla_host_t *vha)
  3233. {
  3234. if (vha->flags.online && !vha->flags.reset_active &&
  3235. !atomic_read(&vha->loop_down_timer) &&
  3236. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  3237. do {
  3238. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3239. /*
  3240. * Issue marker command only when we are going to start
  3241. * the I/O.
  3242. */
  3243. vha->marker_needed = 1;
  3244. } while (!atomic_read(&vha->loop_down_timer) &&
  3245. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  3246. }
  3247. }
  3248. static void
  3249. qla2x00_sp_free_dma(srb_t *sp)
  3250. {
  3251. struct scsi_cmnd *cmd = sp->cmd;
  3252. struct qla_hw_data *ha = sp->fcport->vha->hw;
  3253. if (sp->flags & SRB_DMA_VALID) {
  3254. scsi_dma_unmap(cmd);
  3255. sp->flags &= ~SRB_DMA_VALID;
  3256. }
  3257. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  3258. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  3259. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  3260. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  3261. }
  3262. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  3263. /* List assured to be having elements */
  3264. qla2x00_clean_dsd_pool(ha, sp);
  3265. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  3266. }
  3267. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  3268. dma_pool_free(ha->dl_dma_pool, sp->ctx,
  3269. ((struct crc_context *)sp->ctx)->crc_ctx_dma);
  3270. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  3271. }
  3272. CMD_SP(cmd) = NULL;
  3273. }
  3274. static void
  3275. qla2x00_sp_final_compl(struct qla_hw_data *ha, srb_t *sp)
  3276. {
  3277. struct scsi_cmnd *cmd = sp->cmd;
  3278. qla2x00_sp_free_dma(sp);
  3279. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  3280. struct ct6_dsd *ctx = sp->ctx;
  3281. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd,
  3282. ctx->fcp_cmnd_dma);
  3283. list_splice(&ctx->dsd_list, &ha->gbl_dsd_list);
  3284. ha->gbl_dsd_inuse -= ctx->dsd_use_cnt;
  3285. ha->gbl_dsd_avail += ctx->dsd_use_cnt;
  3286. mempool_free(sp->ctx, ha->ctx_mempool);
  3287. sp->ctx = NULL;
  3288. }
  3289. mempool_free(sp, ha->srb_mempool);
  3290. cmd->scsi_done(cmd);
  3291. }
  3292. void
  3293. qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
  3294. {
  3295. if (atomic_read(&sp->ref_count) == 0) {
  3296. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
  3297. "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
  3298. sp, sp->cmd);
  3299. if (ql2xextended_error_logging & ql_dbg_io)
  3300. BUG();
  3301. return;
  3302. }
  3303. if (!atomic_dec_and_test(&sp->ref_count))
  3304. return;
  3305. qla2x00_sp_final_compl(ha, sp);
  3306. }
  3307. /**************************************************************************
  3308. * qla2x00_timer
  3309. *
  3310. * Description:
  3311. * One second timer
  3312. *
  3313. * Context: Interrupt
  3314. ***************************************************************************/
  3315. void
  3316. qla2x00_timer(scsi_qla_host_t *vha)
  3317. {
  3318. unsigned long cpu_flags = 0;
  3319. int start_dpc = 0;
  3320. int index;
  3321. srb_t *sp;
  3322. uint16_t w;
  3323. struct qla_hw_data *ha = vha->hw;
  3324. struct req_que *req;
  3325. if (ha->flags.eeh_busy) {
  3326. ql_dbg(ql_dbg_timer, vha, 0x6000,
  3327. "EEH = %d, restarting timer.\n",
  3328. ha->flags.eeh_busy);
  3329. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  3330. return;
  3331. }
  3332. /* Hardware read to raise pending EEH errors during mailbox waits. */
  3333. if (!pci_channel_offline(ha->pdev))
  3334. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  3335. /* Make sure qla82xx_watchdog is run only for physical port */
  3336. if (!vha->vp_idx && IS_QLA82XX(ha)) {
  3337. if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
  3338. start_dpc++;
  3339. qla82xx_watchdog(vha);
  3340. }
  3341. /* Loop down handler. */
  3342. if (atomic_read(&vha->loop_down_timer) > 0 &&
  3343. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
  3344. !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
  3345. && vha->flags.online) {
  3346. if (atomic_read(&vha->loop_down_timer) ==
  3347. vha->loop_down_abort_time) {
  3348. ql_log(ql_log_info, vha, 0x6008,
  3349. "Loop down - aborting the queues before time expires.\n");
  3350. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  3351. atomic_set(&vha->loop_state, LOOP_DEAD);
  3352. /*
  3353. * Schedule an ISP abort to return any FCP2-device
  3354. * commands.
  3355. */
  3356. /* NPIV - scan physical port only */
  3357. if (!vha->vp_idx) {
  3358. spin_lock_irqsave(&ha->hardware_lock,
  3359. cpu_flags);
  3360. req = ha->req_q_map[0];
  3361. for (index = 1;
  3362. index < MAX_OUTSTANDING_COMMANDS;
  3363. index++) {
  3364. fc_port_t *sfcp;
  3365. sp = req->outstanding_cmds[index];
  3366. if (!sp)
  3367. continue;
  3368. if (sp->ctx && !IS_PROT_IO(sp))
  3369. continue;
  3370. sfcp = sp->fcport;
  3371. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  3372. continue;
  3373. if (IS_QLA82XX(ha))
  3374. set_bit(FCOE_CTX_RESET_NEEDED,
  3375. &vha->dpc_flags);
  3376. else
  3377. set_bit(ISP_ABORT_NEEDED,
  3378. &vha->dpc_flags);
  3379. break;
  3380. }
  3381. spin_unlock_irqrestore(&ha->hardware_lock,
  3382. cpu_flags);
  3383. }
  3384. start_dpc++;
  3385. }
  3386. /* if the loop has been down for 4 minutes, reinit adapter */
  3387. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  3388. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  3389. ql_log(ql_log_warn, vha, 0x6009,
  3390. "Loop down - aborting ISP.\n");
  3391. if (IS_QLA82XX(ha))
  3392. set_bit(FCOE_CTX_RESET_NEEDED,
  3393. &vha->dpc_flags);
  3394. else
  3395. set_bit(ISP_ABORT_NEEDED,
  3396. &vha->dpc_flags);
  3397. }
  3398. }
  3399. ql_dbg(ql_dbg_timer, vha, 0x600a,
  3400. "Loop down - seconds remaining %d.\n",
  3401. atomic_read(&vha->loop_down_timer));
  3402. }
  3403. /* Check if beacon LED needs to be blinked for physical host only */
  3404. if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
  3405. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  3406. start_dpc++;
  3407. }
  3408. /* Process any deferred work. */
  3409. if (!list_empty(&vha->work_list))
  3410. start_dpc++;
  3411. /* Schedule the DPC routine if needed */
  3412. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  3413. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  3414. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  3415. start_dpc ||
  3416. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  3417. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  3418. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
  3419. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
  3420. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  3421. test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
  3422. ql_dbg(ql_dbg_timer, vha, 0x600b,
  3423. "isp_abort_needed=%d loop_resync_needed=%d "
  3424. "fcport_update_needed=%d start_dpc=%d "
  3425. "reset_marker_needed=%d",
  3426. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
  3427. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
  3428. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
  3429. start_dpc,
  3430. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
  3431. ql_dbg(ql_dbg_timer, vha, 0x600c,
  3432. "beacon_blink_needed=%d isp_unrecoverable=%d "
  3433. "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
  3434. "relogin_needed=%d.\n",
  3435. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
  3436. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
  3437. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
  3438. test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
  3439. test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
  3440. qla2xxx_wake_dpc(vha);
  3441. }
  3442. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  3443. }
  3444. /* Firmware interface routines. */
  3445. #define FW_BLOBS 8
  3446. #define FW_ISP21XX 0
  3447. #define FW_ISP22XX 1
  3448. #define FW_ISP2300 2
  3449. #define FW_ISP2322 3
  3450. #define FW_ISP24XX 4
  3451. #define FW_ISP25XX 5
  3452. #define FW_ISP81XX 6
  3453. #define FW_ISP82XX 7
  3454. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  3455. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  3456. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  3457. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  3458. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  3459. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  3460. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  3461. #define FW_FILE_ISP82XX "ql8200_fw.bin"
  3462. static DEFINE_MUTEX(qla_fw_lock);
  3463. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  3464. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  3465. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  3466. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  3467. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  3468. { .name = FW_FILE_ISP24XX, },
  3469. { .name = FW_FILE_ISP25XX, },
  3470. { .name = FW_FILE_ISP81XX, },
  3471. { .name = FW_FILE_ISP82XX, },
  3472. };
  3473. struct fw_blob *
  3474. qla2x00_request_firmware(scsi_qla_host_t *vha)
  3475. {
  3476. struct qla_hw_data *ha = vha->hw;
  3477. struct fw_blob *blob;
  3478. blob = NULL;
  3479. if (IS_QLA2100(ha)) {
  3480. blob = &qla_fw_blobs[FW_ISP21XX];
  3481. } else if (IS_QLA2200(ha)) {
  3482. blob = &qla_fw_blobs[FW_ISP22XX];
  3483. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  3484. blob = &qla_fw_blobs[FW_ISP2300];
  3485. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  3486. blob = &qla_fw_blobs[FW_ISP2322];
  3487. } else if (IS_QLA24XX_TYPE(ha)) {
  3488. blob = &qla_fw_blobs[FW_ISP24XX];
  3489. } else if (IS_QLA25XX(ha)) {
  3490. blob = &qla_fw_blobs[FW_ISP25XX];
  3491. } else if (IS_QLA81XX(ha)) {
  3492. blob = &qla_fw_blobs[FW_ISP81XX];
  3493. } else if (IS_QLA82XX(ha)) {
  3494. blob = &qla_fw_blobs[FW_ISP82XX];
  3495. }
  3496. mutex_lock(&qla_fw_lock);
  3497. if (blob->fw)
  3498. goto out;
  3499. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  3500. ql_log(ql_log_warn, vha, 0x0063,
  3501. "Failed to load firmware image (%s).\n", blob->name);
  3502. blob->fw = NULL;
  3503. blob = NULL;
  3504. goto out;
  3505. }
  3506. out:
  3507. mutex_unlock(&qla_fw_lock);
  3508. return blob;
  3509. }
  3510. static void
  3511. qla2x00_release_firmware(void)
  3512. {
  3513. int idx;
  3514. mutex_lock(&qla_fw_lock);
  3515. for (idx = 0; idx < FW_BLOBS; idx++)
  3516. if (qla_fw_blobs[idx].fw)
  3517. release_firmware(qla_fw_blobs[idx].fw);
  3518. mutex_unlock(&qla_fw_lock);
  3519. }
  3520. static pci_ers_result_t
  3521. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  3522. {
  3523. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  3524. struct qla_hw_data *ha = vha->hw;
  3525. ql_dbg(ql_dbg_aer, vha, 0x9000,
  3526. "PCI error detected, state %x.\n", state);
  3527. switch (state) {
  3528. case pci_channel_io_normal:
  3529. ha->flags.eeh_busy = 0;
  3530. return PCI_ERS_RESULT_CAN_RECOVER;
  3531. case pci_channel_io_frozen:
  3532. ha->flags.eeh_busy = 1;
  3533. /* For ISP82XX complete any pending mailbox cmd */
  3534. if (IS_QLA82XX(ha)) {
  3535. ha->flags.isp82xx_fw_hung = 1;
  3536. if (ha->flags.mbox_busy) {
  3537. ha->flags.mbox_int = 1;
  3538. ql_dbg(ql_dbg_aer, vha, 0x9001,
  3539. "Due to pci channel io frozen, doing premature "
  3540. "completion of mbx command.\n");
  3541. complete(&ha->mbx_intr_comp);
  3542. }
  3543. }
  3544. qla2x00_free_irqs(vha);
  3545. pci_disable_device(pdev);
  3546. /* Return back all IOs */
  3547. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  3548. return PCI_ERS_RESULT_NEED_RESET;
  3549. case pci_channel_io_perm_failure:
  3550. ha->flags.pci_channel_io_perm_failure = 1;
  3551. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  3552. return PCI_ERS_RESULT_DISCONNECT;
  3553. }
  3554. return PCI_ERS_RESULT_NEED_RESET;
  3555. }
  3556. static pci_ers_result_t
  3557. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  3558. {
  3559. int risc_paused = 0;
  3560. uint32_t stat;
  3561. unsigned long flags;
  3562. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3563. struct qla_hw_data *ha = base_vha->hw;
  3564. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  3565. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  3566. if (IS_QLA82XX(ha))
  3567. return PCI_ERS_RESULT_RECOVERED;
  3568. spin_lock_irqsave(&ha->hardware_lock, flags);
  3569. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  3570. stat = RD_REG_DWORD(&reg->hccr);
  3571. if (stat & HCCR_RISC_PAUSE)
  3572. risc_paused = 1;
  3573. } else if (IS_QLA23XX(ha)) {
  3574. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  3575. if (stat & HSR_RISC_PAUSED)
  3576. risc_paused = 1;
  3577. } else if (IS_FWI2_CAPABLE(ha)) {
  3578. stat = RD_REG_DWORD(&reg24->host_status);
  3579. if (stat & HSRX_RISC_PAUSED)
  3580. risc_paused = 1;
  3581. }
  3582. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3583. if (risc_paused) {
  3584. ql_log(ql_log_info, base_vha, 0x9003,
  3585. "RISC paused -- mmio_enabled, Dumping firmware.\n");
  3586. ha->isp_ops->fw_dump(base_vha, 0);
  3587. return PCI_ERS_RESULT_NEED_RESET;
  3588. } else
  3589. return PCI_ERS_RESULT_RECOVERED;
  3590. }
  3591. uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
  3592. {
  3593. uint32_t rval = QLA_FUNCTION_FAILED;
  3594. uint32_t drv_active = 0;
  3595. struct qla_hw_data *ha = base_vha->hw;
  3596. int fn;
  3597. struct pci_dev *other_pdev = NULL;
  3598. ql_dbg(ql_dbg_aer, base_vha, 0x9006,
  3599. "Entered %s.\n", __func__);
  3600. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3601. if (base_vha->flags.online) {
  3602. /* Abort all outstanding commands,
  3603. * so as to be requeued later */
  3604. qla2x00_abort_isp_cleanup(base_vha);
  3605. }
  3606. fn = PCI_FUNC(ha->pdev->devfn);
  3607. while (fn > 0) {
  3608. fn--;
  3609. ql_dbg(ql_dbg_aer, base_vha, 0x9007,
  3610. "Finding pci device at function = 0x%x.\n", fn);
  3611. other_pdev =
  3612. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  3613. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  3614. fn));
  3615. if (!other_pdev)
  3616. continue;
  3617. if (atomic_read(&other_pdev->enable_cnt)) {
  3618. ql_dbg(ql_dbg_aer, base_vha, 0x9008,
  3619. "Found PCI func available and enable at 0x%x.\n",
  3620. fn);
  3621. pci_dev_put(other_pdev);
  3622. break;
  3623. }
  3624. pci_dev_put(other_pdev);
  3625. }
  3626. if (!fn) {
  3627. /* Reset owner */
  3628. ql_dbg(ql_dbg_aer, base_vha, 0x9009,
  3629. "This devfn is reset owner = 0x%x.\n",
  3630. ha->pdev->devfn);
  3631. qla82xx_idc_lock(ha);
  3632. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3633. QLA82XX_DEV_INITIALIZING);
  3634. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  3635. QLA82XX_IDC_VERSION);
  3636. drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  3637. ql_dbg(ql_dbg_aer, base_vha, 0x900a,
  3638. "drv_active = 0x%x.\n", drv_active);
  3639. qla82xx_idc_unlock(ha);
  3640. /* Reset if device is not already reset
  3641. * drv_active would be 0 if a reset has already been done
  3642. */
  3643. if (drv_active)
  3644. rval = qla82xx_start_firmware(base_vha);
  3645. else
  3646. rval = QLA_SUCCESS;
  3647. qla82xx_idc_lock(ha);
  3648. if (rval != QLA_SUCCESS) {
  3649. ql_log(ql_log_info, base_vha, 0x900b,
  3650. "HW State: FAILED.\n");
  3651. qla82xx_clear_drv_active(ha);
  3652. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3653. QLA82XX_DEV_FAILED);
  3654. } else {
  3655. ql_log(ql_log_info, base_vha, 0x900c,
  3656. "HW State: READY.\n");
  3657. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  3658. QLA82XX_DEV_READY);
  3659. qla82xx_idc_unlock(ha);
  3660. ha->flags.isp82xx_fw_hung = 0;
  3661. rval = qla82xx_restart_isp(base_vha);
  3662. qla82xx_idc_lock(ha);
  3663. /* Clear driver state register */
  3664. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  3665. qla82xx_set_drv_active(base_vha);
  3666. }
  3667. qla82xx_idc_unlock(ha);
  3668. } else {
  3669. ql_dbg(ql_dbg_aer, base_vha, 0x900d,
  3670. "This devfn is not reset owner = 0x%x.\n",
  3671. ha->pdev->devfn);
  3672. if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  3673. QLA82XX_DEV_READY)) {
  3674. ha->flags.isp82xx_fw_hung = 0;
  3675. rval = qla82xx_restart_isp(base_vha);
  3676. qla82xx_idc_lock(ha);
  3677. qla82xx_set_drv_active(base_vha);
  3678. qla82xx_idc_unlock(ha);
  3679. }
  3680. }
  3681. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3682. return rval;
  3683. }
  3684. static pci_ers_result_t
  3685. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  3686. {
  3687. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  3688. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3689. struct qla_hw_data *ha = base_vha->hw;
  3690. struct rsp_que *rsp;
  3691. int rc, retries = 10;
  3692. ql_dbg(ql_dbg_aer, base_vha, 0x9004,
  3693. "Slot Reset.\n");
  3694. /* Workaround: qla2xxx driver which access hardware earlier
  3695. * needs error state to be pci_channel_io_online.
  3696. * Otherwise mailbox command timesout.
  3697. */
  3698. pdev->error_state = pci_channel_io_normal;
  3699. pci_restore_state(pdev);
  3700. /* pci_restore_state() clears the saved_state flag of the device
  3701. * save restored state which resets saved_state flag
  3702. */
  3703. pci_save_state(pdev);
  3704. if (ha->mem_only)
  3705. rc = pci_enable_device_mem(pdev);
  3706. else
  3707. rc = pci_enable_device(pdev);
  3708. if (rc) {
  3709. ql_log(ql_log_warn, base_vha, 0x9005,
  3710. "Can't re-enable PCI device after reset.\n");
  3711. goto exit_slot_reset;
  3712. }
  3713. rsp = ha->rsp_q_map[0];
  3714. if (qla2x00_request_irqs(ha, rsp))
  3715. goto exit_slot_reset;
  3716. if (ha->isp_ops->pci_config(base_vha))
  3717. goto exit_slot_reset;
  3718. if (IS_QLA82XX(ha)) {
  3719. if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
  3720. ret = PCI_ERS_RESULT_RECOVERED;
  3721. goto exit_slot_reset;
  3722. } else
  3723. goto exit_slot_reset;
  3724. }
  3725. while (ha->flags.mbox_busy && retries--)
  3726. msleep(1000);
  3727. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3728. if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
  3729. ret = PCI_ERS_RESULT_RECOVERED;
  3730. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  3731. exit_slot_reset:
  3732. ql_dbg(ql_dbg_aer, base_vha, 0x900e,
  3733. "slot_reset return %x.\n", ret);
  3734. return ret;
  3735. }
  3736. static void
  3737. qla2xxx_pci_resume(struct pci_dev *pdev)
  3738. {
  3739. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  3740. struct qla_hw_data *ha = base_vha->hw;
  3741. int ret;
  3742. ql_dbg(ql_dbg_aer, base_vha, 0x900f,
  3743. "pci_resume.\n");
  3744. ret = qla2x00_wait_for_hba_online(base_vha);
  3745. if (ret != QLA_SUCCESS) {
  3746. ql_log(ql_log_fatal, base_vha, 0x9002,
  3747. "The device failed to resume I/O from slot/link_reset.\n");
  3748. }
  3749. pci_cleanup_aer_uncorrect_error_status(pdev);
  3750. ha->flags.eeh_busy = 0;
  3751. }
  3752. static struct pci_error_handlers qla2xxx_err_handler = {
  3753. .error_detected = qla2xxx_pci_error_detected,
  3754. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  3755. .slot_reset = qla2xxx_pci_slot_reset,
  3756. .resume = qla2xxx_pci_resume,
  3757. };
  3758. static struct pci_device_id qla2xxx_pci_tbl[] = {
  3759. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  3760. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  3761. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  3762. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  3763. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  3764. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  3765. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  3766. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  3767. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  3768. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  3769. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  3770. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  3771. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  3772. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  3773. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
  3774. { 0 },
  3775. };
  3776. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  3777. static struct pci_driver qla2xxx_pci_driver = {
  3778. .name = QLA2XXX_DRIVER_NAME,
  3779. .driver = {
  3780. .owner = THIS_MODULE,
  3781. },
  3782. .id_table = qla2xxx_pci_tbl,
  3783. .probe = qla2x00_probe_one,
  3784. .remove = qla2x00_remove_one,
  3785. .shutdown = qla2x00_shutdown,
  3786. .err_handler = &qla2xxx_err_handler,
  3787. };
  3788. static struct file_operations apidev_fops = {
  3789. .owner = THIS_MODULE,
  3790. .llseek = noop_llseek,
  3791. };
  3792. /**
  3793. * qla2x00_module_init - Module initialization.
  3794. **/
  3795. static int __init
  3796. qla2x00_module_init(void)
  3797. {
  3798. int ret = 0;
  3799. /* Allocate cache for SRBs. */
  3800. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  3801. SLAB_HWCACHE_ALIGN, NULL);
  3802. if (srb_cachep == NULL) {
  3803. ql_log(ql_log_fatal, NULL, 0x0001,
  3804. "Unable to allocate SRB cache...Failing load!.\n");
  3805. return -ENOMEM;
  3806. }
  3807. /* Derive version string. */
  3808. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  3809. if (ql2xextended_error_logging)
  3810. strcat(qla2x00_version_str, "-debug");
  3811. qla2xxx_transport_template =
  3812. fc_attach_transport(&qla2xxx_transport_functions);
  3813. if (!qla2xxx_transport_template) {
  3814. kmem_cache_destroy(srb_cachep);
  3815. ql_log(ql_log_fatal, NULL, 0x0002,
  3816. "fc_attach_transport failed...Failing load!.\n");
  3817. return -ENODEV;
  3818. }
  3819. apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
  3820. if (apidev_major < 0) {
  3821. ql_log(ql_log_fatal, NULL, 0x0003,
  3822. "Unable to register char device %s.\n", QLA2XXX_APIDEV);
  3823. }
  3824. qla2xxx_transport_vport_template =
  3825. fc_attach_transport(&qla2xxx_transport_vport_functions);
  3826. if (!qla2xxx_transport_vport_template) {
  3827. kmem_cache_destroy(srb_cachep);
  3828. fc_release_transport(qla2xxx_transport_template);
  3829. ql_log(ql_log_fatal, NULL, 0x0004,
  3830. "fc_attach_transport vport failed...Failing load!.\n");
  3831. return -ENODEV;
  3832. }
  3833. ql_log(ql_log_info, NULL, 0x0005,
  3834. "QLogic Fibre Channel HBA Driver: %s.\n",
  3835. qla2x00_version_str);
  3836. ret = pci_register_driver(&qla2xxx_pci_driver);
  3837. if (ret) {
  3838. kmem_cache_destroy(srb_cachep);
  3839. fc_release_transport(qla2xxx_transport_template);
  3840. fc_release_transport(qla2xxx_transport_vport_template);
  3841. ql_log(ql_log_fatal, NULL, 0x0006,
  3842. "pci_register_driver failed...ret=%d Failing load!.\n",
  3843. ret);
  3844. }
  3845. return ret;
  3846. }
  3847. /**
  3848. * qla2x00_module_exit - Module cleanup.
  3849. **/
  3850. static void __exit
  3851. qla2x00_module_exit(void)
  3852. {
  3853. unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
  3854. pci_unregister_driver(&qla2xxx_pci_driver);
  3855. qla2x00_release_firmware();
  3856. kmem_cache_destroy(srb_cachep);
  3857. if (ctx_cachep)
  3858. kmem_cache_destroy(ctx_cachep);
  3859. fc_release_transport(qla2xxx_transport_template);
  3860. fc_release_transport(qla2xxx_transport_vport_template);
  3861. }
  3862. module_init(qla2x00_module_init);
  3863. module_exit(qla2x00_module_exit);
  3864. MODULE_AUTHOR("QLogic Corporation");
  3865. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  3866. MODULE_LICENSE("GPL");
  3867. MODULE_VERSION(QLA2XXX_VERSION);
  3868. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  3869. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  3870. MODULE_FIRMWARE(FW_FILE_ISP2300);
  3871. MODULE_FIRMWARE(FW_FILE_ISP2322);
  3872. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  3873. MODULE_FIRMWARE(FW_FILE_ISP25XX);