qla_os.c 125 KB

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