qla_os.c 119 KB

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