qla_os.c 117 KB

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