qla_os.c 118 KB

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