qla_os.c 118 KB

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