qla_os.c 123 KB

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