qla_os.c 172 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 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 <linux/blk-mq-pci.h>
  16. #include <scsi/scsi_tcq.h>
  17. #include <scsi/scsicam.h>
  18. #include <scsi/scsi_transport.h>
  19. #include <scsi/scsi_transport_fc.h>
  20. #include "qla_target.h"
  21. /*
  22. * Driver version
  23. */
  24. char qla2x00_version_str[40];
  25. static int apidev_major;
  26. /*
  27. * SRB allocation cache
  28. */
  29. struct kmem_cache *srb_cachep;
  30. /*
  31. * CT6 CTX allocation cache
  32. */
  33. static struct kmem_cache *ctx_cachep;
  34. /*
  35. * error level for logging
  36. */
  37. int ql_errlev = ql_log_all;
  38. static int ql2xenableclass2;
  39. module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
  40. MODULE_PARM_DESC(ql2xenableclass2,
  41. "Specify if Class 2 operations are supported from the very "
  42. "beginning. Default is 0 - class 2 not supported.");
  43. int ql2xlogintimeout = 20;
  44. module_param(ql2xlogintimeout, int, S_IRUGO);
  45. MODULE_PARM_DESC(ql2xlogintimeout,
  46. "Login timeout value in seconds.");
  47. int qlport_down_retry;
  48. module_param(qlport_down_retry, int, S_IRUGO);
  49. MODULE_PARM_DESC(qlport_down_retry,
  50. "Maximum number of command retries to a port that returns "
  51. "a PORT-DOWN status.");
  52. int ql2xplogiabsentdevice;
  53. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  54. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  55. "Option to enable PLOGI to devices that are not present after "
  56. "a Fabric scan. This is needed for several broken switches. "
  57. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  58. int ql2xloginretrycount = 0;
  59. module_param(ql2xloginretrycount, int, S_IRUGO);
  60. MODULE_PARM_DESC(ql2xloginretrycount,
  61. "Specify an alternate value for the NVRAM login retry count.");
  62. int ql2xallocfwdump = 1;
  63. module_param(ql2xallocfwdump, int, S_IRUGO);
  64. MODULE_PARM_DESC(ql2xallocfwdump,
  65. "Option to enable allocation of memory for a firmware dump "
  66. "during HBA initialization. Memory allocation requirements "
  67. "vary by ISP type. Default is 1 - allocate memory.");
  68. int ql2xextended_error_logging;
  69. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  70. module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  71. MODULE_PARM_DESC(ql2xextended_error_logging,
  72. "Option to enable extended error logging,\n"
  73. "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
  74. "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
  75. "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
  76. "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
  77. "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
  78. "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
  79. "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
  80. "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
  81. "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
  82. "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
  83. "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
  84. "\t\t0x1e400000 - Preferred value for capturing essential "
  85. "debug information (equivalent to old "
  86. "ql2xextended_error_logging=1).\n"
  87. "\t\tDo LOGICAL OR of the value to enable more than one level");
  88. int ql2xshiftctondsd = 6;
  89. module_param(ql2xshiftctondsd, int, S_IRUGO);
  90. MODULE_PARM_DESC(ql2xshiftctondsd,
  91. "Set to control shifting of command type processing "
  92. "based on total number of SG elements.");
  93. int ql2xfdmienable=1;
  94. module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
  95. module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
  96. MODULE_PARM_DESC(ql2xfdmienable,
  97. "Enables FDMI registrations. "
  98. "0 - no FDMI. Default is 1 - perform FDMI.");
  99. #define MAX_Q_DEPTH 32
  100. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  101. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  102. MODULE_PARM_DESC(ql2xmaxqdepth,
  103. "Maximum queue depth to set for each LUN. "
  104. "Default is 32.");
  105. int ql2xenabledif = 2;
  106. module_param(ql2xenabledif, int, S_IRUGO);
  107. MODULE_PARM_DESC(ql2xenabledif,
  108. " Enable T10-CRC-DIF:\n"
  109. " Default is 2.\n"
  110. " 0 -- No DIF Support\n"
  111. " 1 -- Enable DIF for all types\n"
  112. " 2 -- Enable DIF for all types, except Type 0.\n");
  113. int ql2xenablehba_err_chk = 2;
  114. module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
  115. MODULE_PARM_DESC(ql2xenablehba_err_chk,
  116. " Enable T10-CRC-DIF Error isolation by HBA:\n"
  117. " Default is 2.\n"
  118. " 0 -- Error isolation disabled\n"
  119. " 1 -- Error isolation enabled only for DIX Type 0\n"
  120. " 2 -- Error isolation enabled for all Types\n");
  121. int ql2xiidmaenable=1;
  122. module_param(ql2xiidmaenable, int, S_IRUGO);
  123. MODULE_PARM_DESC(ql2xiidmaenable,
  124. "Enables iIDMA settings "
  125. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  126. int ql2xmqsupport = 1;
  127. module_param(ql2xmqsupport, int, S_IRUGO);
  128. MODULE_PARM_DESC(ql2xmqsupport,
  129. "Enable on demand multiple queue pairs support "
  130. "Default is 1 for supported. "
  131. "Set it to 0 to turn off mq qpair support.");
  132. int ql2xfwloadbin;
  133. module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
  134. module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
  135. MODULE_PARM_DESC(ql2xfwloadbin,
  136. "Option to specify location from which to load ISP firmware:.\n"
  137. " 2 -- load firmware via the request_firmware() (hotplug).\n"
  138. " interface.\n"
  139. " 1 -- load firmware from flash.\n"
  140. " 0 -- use default semantics.\n");
  141. int ql2xetsenable;
  142. module_param(ql2xetsenable, int, S_IRUGO);
  143. MODULE_PARM_DESC(ql2xetsenable,
  144. "Enables firmware ETS burst."
  145. "Default is 0 - skip ETS enablement.");
  146. int ql2xdbwr = 1;
  147. module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
  148. MODULE_PARM_DESC(ql2xdbwr,
  149. "Option to specify scheme for request queue posting.\n"
  150. " 0 -- Regular doorbell.\n"
  151. " 1 -- CAMRAM doorbell (faster).\n");
  152. int ql2xtargetreset = 1;
  153. module_param(ql2xtargetreset, int, S_IRUGO);
  154. MODULE_PARM_DESC(ql2xtargetreset,
  155. "Enable target reset."
  156. "Default is 1 - use hw defaults.");
  157. int ql2xgffidenable;
  158. module_param(ql2xgffidenable, int, S_IRUGO);
  159. MODULE_PARM_DESC(ql2xgffidenable,
  160. "Enables GFF_ID checks of port type. "
  161. "Default is 0 - Do not use GFF_ID information.");
  162. int ql2xasynctmfenable;
  163. module_param(ql2xasynctmfenable, int, S_IRUGO);
  164. MODULE_PARM_DESC(ql2xasynctmfenable,
  165. "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
  166. "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
  167. int ql2xdontresethba;
  168. module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
  169. MODULE_PARM_DESC(ql2xdontresethba,
  170. "Option to specify reset behaviour.\n"
  171. " 0 (Default) -- Reset on failure.\n"
  172. " 1 -- Do not reset on failure.\n");
  173. uint64_t ql2xmaxlun = MAX_LUNS;
  174. module_param(ql2xmaxlun, ullong, S_IRUGO);
  175. MODULE_PARM_DESC(ql2xmaxlun,
  176. "Defines the maximum LU number to register with the SCSI "
  177. "midlayer. Default is 65535.");
  178. int ql2xmdcapmask = 0x1F;
  179. module_param(ql2xmdcapmask, int, S_IRUGO);
  180. MODULE_PARM_DESC(ql2xmdcapmask,
  181. "Set the Minidump driver capture mask level. "
  182. "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
  183. int ql2xmdenable = 1;
  184. module_param(ql2xmdenable, int, S_IRUGO);
  185. MODULE_PARM_DESC(ql2xmdenable,
  186. "Enable/disable MiniDump. "
  187. "0 - MiniDump disabled. "
  188. "1 (Default) - MiniDump enabled.");
  189. int ql2xexlogins = 0;
  190. module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
  191. MODULE_PARM_DESC(ql2xexlogins,
  192. "Number of extended Logins. "
  193. "0 (Default)- Disabled.");
  194. int ql2xexchoffld = 0;
  195. module_param(ql2xexchoffld, uint, S_IRUGO|S_IWUSR);
  196. MODULE_PARM_DESC(ql2xexchoffld,
  197. "Number of exchanges to offload. "
  198. "0 (Default)- Disabled.");
  199. int ql2xfwholdabts = 0;
  200. module_param(ql2xfwholdabts, int, S_IRUGO);
  201. MODULE_PARM_DESC(ql2xfwholdabts,
  202. "Allow FW to hold status IOCB until ABTS rsp received. "
  203. "0 (Default) Do not set fw option. "
  204. "1 - Set fw option to hold ABTS.");
  205. /*
  206. * SCSI host template entry points
  207. */
  208. static int qla2xxx_slave_configure(struct scsi_device * device);
  209. static int qla2xxx_slave_alloc(struct scsi_device *);
  210. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  211. static void qla2xxx_scan_start(struct Scsi_Host *);
  212. static void qla2xxx_slave_destroy(struct scsi_device *);
  213. static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  214. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  215. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  216. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  217. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  218. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  219. static void qla2x00_clear_drv_active(struct qla_hw_data *);
  220. static void qla2x00_free_device(scsi_qla_host_t *);
  221. static void qla83xx_disable_laser(scsi_qla_host_t *vha);
  222. static int qla2xxx_map_queues(struct Scsi_Host *shost);
  223. struct scsi_host_template qla2xxx_driver_template = {
  224. .module = THIS_MODULE,
  225. .name = QLA2XXX_DRIVER_NAME,
  226. .queuecommand = qla2xxx_queuecommand,
  227. .eh_abort_handler = qla2xxx_eh_abort,
  228. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  229. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  230. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  231. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  232. .slave_configure = qla2xxx_slave_configure,
  233. .slave_alloc = qla2xxx_slave_alloc,
  234. .slave_destroy = qla2xxx_slave_destroy,
  235. .scan_finished = qla2xxx_scan_finished,
  236. .scan_start = qla2xxx_scan_start,
  237. .change_queue_depth = scsi_change_queue_depth,
  238. .map_queues = qla2xxx_map_queues,
  239. .this_id = -1,
  240. .cmd_per_lun = 3,
  241. .use_clustering = ENABLE_CLUSTERING,
  242. .sg_tablesize = SG_ALL,
  243. .max_sectors = 0xFFFF,
  244. .shost_attrs = qla2x00_host_attrs,
  245. .supported_mode = MODE_INITIATOR,
  246. .track_queue_depth = 1,
  247. };
  248. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  249. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  250. /* TODO Convert to inlines
  251. *
  252. * Timer routines
  253. */
  254. __inline__ void
  255. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  256. {
  257. init_timer(&vha->timer);
  258. vha->timer.expires = jiffies + interval * HZ;
  259. vha->timer.data = (unsigned long)vha;
  260. vha->timer.function = (void (*)(unsigned long))func;
  261. add_timer(&vha->timer);
  262. vha->timer_active = 1;
  263. }
  264. static inline void
  265. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  266. {
  267. /* Currently used for 82XX only. */
  268. if (vha->device_flags & DFLG_DEV_FAILED) {
  269. ql_dbg(ql_dbg_timer, vha, 0x600d,
  270. "Device in a failed state, returning.\n");
  271. return;
  272. }
  273. mod_timer(&vha->timer, jiffies + interval * HZ);
  274. }
  275. static __inline__ void
  276. qla2x00_stop_timer(scsi_qla_host_t *vha)
  277. {
  278. del_timer_sync(&vha->timer);
  279. vha->timer_active = 0;
  280. }
  281. static int qla2x00_do_dpc(void *data);
  282. static void qla2x00_rst_aen(scsi_qla_host_t *);
  283. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  284. struct req_que **, struct rsp_que **);
  285. static void qla2x00_free_fw_dump(struct qla_hw_data *);
  286. static void qla2x00_mem_free(struct qla_hw_data *);
  287. int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
  288. struct qla_qpair *qpair);
  289. /* -------------------------------------------------------------------------- */
  290. static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
  291. struct rsp_que *rsp)
  292. {
  293. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  294. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  295. GFP_KERNEL);
  296. if (!ha->req_q_map) {
  297. ql_log(ql_log_fatal, vha, 0x003b,
  298. "Unable to allocate memory for request queue ptrs.\n");
  299. goto fail_req_map;
  300. }
  301. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  302. GFP_KERNEL);
  303. if (!ha->rsp_q_map) {
  304. ql_log(ql_log_fatal, vha, 0x003c,
  305. "Unable to allocate memory for response queue ptrs.\n");
  306. goto fail_rsp_map;
  307. }
  308. if (ql2xmqsupport && ha->max_qpairs) {
  309. ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
  310. GFP_KERNEL);
  311. if (!ha->queue_pair_map) {
  312. ql_log(ql_log_fatal, vha, 0x0180,
  313. "Unable to allocate memory for queue pair ptrs.\n");
  314. goto fail_qpair_map;
  315. }
  316. ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
  317. if (ha->base_qpair == NULL) {
  318. ql_log(ql_log_warn, vha, 0x0182,
  319. "Failed to allocate base queue pair memory.\n");
  320. goto fail_base_qpair;
  321. }
  322. ha->base_qpair->req = req;
  323. ha->base_qpair->rsp = rsp;
  324. }
  325. /*
  326. * Make sure we record at least the request and response queue zero in
  327. * case we need to free them if part of the probe fails.
  328. */
  329. ha->rsp_q_map[0] = rsp;
  330. ha->req_q_map[0] = req;
  331. set_bit(0, ha->rsp_qid_map);
  332. set_bit(0, ha->req_qid_map);
  333. return 1;
  334. fail_base_qpair:
  335. kfree(ha->queue_pair_map);
  336. fail_qpair_map:
  337. kfree(ha->rsp_q_map);
  338. ha->rsp_q_map = NULL;
  339. fail_rsp_map:
  340. kfree(ha->req_q_map);
  341. ha->req_q_map = NULL;
  342. fail_req_map:
  343. return -ENOMEM;
  344. }
  345. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  346. {
  347. if (IS_QLAFX00(ha)) {
  348. if (req && req->ring_fx00)
  349. dma_free_coherent(&ha->pdev->dev,
  350. (req->length_fx00 + 1) * sizeof(request_t),
  351. req->ring_fx00, req->dma_fx00);
  352. } else if (req && req->ring)
  353. dma_free_coherent(&ha->pdev->dev,
  354. (req->length + 1) * sizeof(request_t),
  355. req->ring, req->dma);
  356. if (req)
  357. kfree(req->outstanding_cmds);
  358. kfree(req);
  359. req = NULL;
  360. }
  361. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  362. {
  363. if (IS_QLAFX00(ha)) {
  364. if (rsp && rsp->ring)
  365. dma_free_coherent(&ha->pdev->dev,
  366. (rsp->length_fx00 + 1) * sizeof(request_t),
  367. rsp->ring_fx00, rsp->dma_fx00);
  368. } else if (rsp && rsp->ring) {
  369. dma_free_coherent(&ha->pdev->dev,
  370. (rsp->length + 1) * sizeof(response_t),
  371. rsp->ring, rsp->dma);
  372. }
  373. kfree(rsp);
  374. rsp = NULL;
  375. }
  376. static void qla2x00_free_queues(struct qla_hw_data *ha)
  377. {
  378. struct req_que *req;
  379. struct rsp_que *rsp;
  380. int cnt;
  381. unsigned long flags;
  382. spin_lock_irqsave(&ha->hardware_lock, flags);
  383. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  384. if (!test_bit(cnt, ha->req_qid_map))
  385. continue;
  386. req = ha->req_q_map[cnt];
  387. clear_bit(cnt, ha->req_qid_map);
  388. ha->req_q_map[cnt] = NULL;
  389. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  390. qla2x00_free_req_que(ha, req);
  391. spin_lock_irqsave(&ha->hardware_lock, flags);
  392. }
  393. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  394. kfree(ha->req_q_map);
  395. ha->req_q_map = NULL;
  396. spin_lock_irqsave(&ha->hardware_lock, flags);
  397. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  398. if (!test_bit(cnt, ha->rsp_qid_map))
  399. continue;
  400. rsp = ha->rsp_q_map[cnt];
  401. clear_bit(cnt, ha->req_qid_map);
  402. ha->rsp_q_map[cnt] = NULL;
  403. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  404. qla2x00_free_rsp_que(ha, rsp);
  405. spin_lock_irqsave(&ha->hardware_lock, flags);
  406. }
  407. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  408. kfree(ha->rsp_q_map);
  409. ha->rsp_q_map = NULL;
  410. }
  411. static char *
  412. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  413. {
  414. struct qla_hw_data *ha = vha->hw;
  415. static char *pci_bus_modes[] = {
  416. "33", "66", "100", "133",
  417. };
  418. uint16_t pci_bus;
  419. strcpy(str, "PCI");
  420. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  421. if (pci_bus) {
  422. strcat(str, "-X (");
  423. strcat(str, pci_bus_modes[pci_bus]);
  424. } else {
  425. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  426. strcat(str, " (");
  427. strcat(str, pci_bus_modes[pci_bus]);
  428. }
  429. strcat(str, " MHz)");
  430. return (str);
  431. }
  432. static char *
  433. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  434. {
  435. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  436. struct qla_hw_data *ha = vha->hw;
  437. uint32_t pci_bus;
  438. if (pci_is_pcie(ha->pdev)) {
  439. char lwstr[6];
  440. uint32_t lstat, lspeed, lwidth;
  441. pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
  442. lspeed = lstat & PCI_EXP_LNKCAP_SLS;
  443. lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
  444. strcpy(str, "PCIe (");
  445. switch (lspeed) {
  446. case 1:
  447. strcat(str, "2.5GT/s ");
  448. break;
  449. case 2:
  450. strcat(str, "5.0GT/s ");
  451. break;
  452. case 3:
  453. strcat(str, "8.0GT/s ");
  454. break;
  455. default:
  456. strcat(str, "<unknown> ");
  457. break;
  458. }
  459. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  460. strcat(str, lwstr);
  461. return str;
  462. }
  463. strcpy(str, "PCI");
  464. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  465. if (pci_bus == 0 || pci_bus == 8) {
  466. strcat(str, " (");
  467. strcat(str, pci_bus_modes[pci_bus >> 3]);
  468. } else {
  469. strcat(str, "-X ");
  470. if (pci_bus & BIT_2)
  471. strcat(str, "Mode 2");
  472. else
  473. strcat(str, "Mode 1");
  474. strcat(str, " (");
  475. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  476. }
  477. strcat(str, " MHz)");
  478. return str;
  479. }
  480. static char *
  481. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
  482. {
  483. char un_str[10];
  484. struct qla_hw_data *ha = vha->hw;
  485. snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
  486. ha->fw_minor_version, ha->fw_subminor_version);
  487. if (ha->fw_attributes & BIT_9) {
  488. strcat(str, "FLX");
  489. return (str);
  490. }
  491. switch (ha->fw_attributes & 0xFF) {
  492. case 0x7:
  493. strcat(str, "EF");
  494. break;
  495. case 0x17:
  496. strcat(str, "TP");
  497. break;
  498. case 0x37:
  499. strcat(str, "IP");
  500. break;
  501. case 0x77:
  502. strcat(str, "VI");
  503. break;
  504. default:
  505. sprintf(un_str, "(%x)", ha->fw_attributes);
  506. strcat(str, un_str);
  507. break;
  508. }
  509. if (ha->fw_attributes & 0x100)
  510. strcat(str, "X");
  511. return (str);
  512. }
  513. static char *
  514. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
  515. {
  516. struct qla_hw_data *ha = vha->hw;
  517. snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
  518. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  519. return str;
  520. }
  521. void
  522. qla2x00_sp_free_dma(void *vha, void *ptr)
  523. {
  524. srb_t *sp = (srb_t *)ptr;
  525. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  526. struct qla_hw_data *ha = sp->fcport->vha->hw;
  527. void *ctx = GET_CMD_CTX_SP(sp);
  528. if (sp->flags & SRB_DMA_VALID) {
  529. scsi_dma_unmap(cmd);
  530. sp->flags &= ~SRB_DMA_VALID;
  531. }
  532. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  533. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  534. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  535. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  536. }
  537. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  538. /* List assured to be having elements */
  539. qla2x00_clean_dsd_pool(ha, sp, NULL);
  540. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  541. }
  542. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  543. dma_pool_free(ha->dl_dma_pool, ctx,
  544. ((struct crc_context *)ctx)->crc_ctx_dma);
  545. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  546. }
  547. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  548. struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
  549. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
  550. ctx1->fcp_cmnd_dma);
  551. list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
  552. ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
  553. ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
  554. mempool_free(ctx1, ha->ctx_mempool);
  555. ctx1 = NULL;
  556. }
  557. CMD_SP(cmd) = NULL;
  558. qla2x00_rel_sp(sp->fcport->vha, sp);
  559. }
  560. void
  561. qla2x00_sp_compl(void *data, void *ptr, int res)
  562. {
  563. struct qla_hw_data *ha = (struct qla_hw_data *)data;
  564. srb_t *sp = (srb_t *)ptr;
  565. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  566. cmd->result = res;
  567. if (atomic_read(&sp->ref_count) == 0) {
  568. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
  569. "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
  570. sp, GET_CMD_SP(sp));
  571. if (ql2xextended_error_logging & ql_dbg_io)
  572. WARN_ON(atomic_read(&sp->ref_count) == 0);
  573. return;
  574. }
  575. if (!atomic_dec_and_test(&sp->ref_count))
  576. return;
  577. qla2x00_sp_free_dma(ha, sp);
  578. cmd->scsi_done(cmd);
  579. }
  580. void
  581. qla2xxx_qpair_sp_free_dma(void *vha, void *ptr)
  582. {
  583. srb_t *sp = (srb_t *)ptr;
  584. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  585. struct qla_hw_data *ha = sp->fcport->vha->hw;
  586. void *ctx = GET_CMD_CTX_SP(sp);
  587. if (sp->flags & SRB_DMA_VALID) {
  588. scsi_dma_unmap(cmd);
  589. sp->flags &= ~SRB_DMA_VALID;
  590. }
  591. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  592. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  593. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  594. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  595. }
  596. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  597. /* List assured to be having elements */
  598. qla2x00_clean_dsd_pool(ha, sp, NULL);
  599. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  600. }
  601. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  602. dma_pool_free(ha->dl_dma_pool, ctx,
  603. ((struct crc_context *)ctx)->crc_ctx_dma);
  604. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  605. }
  606. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  607. struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
  608. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
  609. ctx1->fcp_cmnd_dma);
  610. list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
  611. ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
  612. ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
  613. mempool_free(ctx1, ha->ctx_mempool);
  614. }
  615. CMD_SP(cmd) = NULL;
  616. qla2xxx_rel_qpair_sp(sp->qpair, sp);
  617. }
  618. void
  619. qla2xxx_qpair_sp_compl(void *data, void *ptr, int res)
  620. {
  621. srb_t *sp = (srb_t *)ptr;
  622. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  623. cmd->result = res;
  624. if (atomic_read(&sp->ref_count) == 0) {
  625. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
  626. "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
  627. sp, GET_CMD_SP(sp));
  628. if (ql2xextended_error_logging & ql_dbg_io)
  629. WARN_ON(atomic_read(&sp->ref_count) == 0);
  630. return;
  631. }
  632. if (!atomic_dec_and_test(&sp->ref_count))
  633. return;
  634. qla2xxx_qpair_sp_free_dma(sp->fcport->vha, sp);
  635. cmd->scsi_done(cmd);
  636. }
  637. /* If we are SP1 here, we need to still take and release the host_lock as SP1
  638. * does not have the changes necessary to avoid taking host->host_lock.
  639. */
  640. static int
  641. qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  642. {
  643. scsi_qla_host_t *vha = shost_priv(host);
  644. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  645. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  646. struct qla_hw_data *ha = vha->hw;
  647. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  648. srb_t *sp;
  649. int rval;
  650. struct qla_qpair *qpair = NULL;
  651. uint32_t tag;
  652. uint16_t hwq;
  653. if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
  654. cmd->result = DID_NO_CONNECT << 16;
  655. goto qc24_fail_command;
  656. }
  657. if (ha->mqenable) {
  658. if (shost_use_blk_mq(vha->host)) {
  659. tag = blk_mq_unique_tag(cmd->request);
  660. hwq = blk_mq_unique_tag_to_hwq(tag);
  661. qpair = ha->queue_pair_map[hwq];
  662. } else if (vha->vp_idx && vha->qpair) {
  663. qpair = vha->qpair;
  664. }
  665. if (qpair)
  666. return qla2xxx_mqueuecommand(host, cmd, qpair);
  667. }
  668. if (ha->flags.eeh_busy) {
  669. if (ha->flags.pci_channel_io_perm_failure) {
  670. ql_dbg(ql_dbg_aer, vha, 0x9010,
  671. "PCI Channel IO permanent failure, exiting "
  672. "cmd=%p.\n", cmd);
  673. cmd->result = DID_NO_CONNECT << 16;
  674. } else {
  675. ql_dbg(ql_dbg_aer, vha, 0x9011,
  676. "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
  677. cmd->result = DID_REQUEUE << 16;
  678. }
  679. goto qc24_fail_command;
  680. }
  681. rval = fc_remote_port_chkready(rport);
  682. if (rval) {
  683. cmd->result = rval;
  684. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
  685. "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
  686. cmd, rval);
  687. goto qc24_fail_command;
  688. }
  689. if (!vha->flags.difdix_supported &&
  690. scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  691. ql_dbg(ql_dbg_io, vha, 0x3004,
  692. "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
  693. cmd);
  694. cmd->result = DID_NO_CONNECT << 16;
  695. goto qc24_fail_command;
  696. }
  697. if (!fcport) {
  698. cmd->result = DID_NO_CONNECT << 16;
  699. goto qc24_fail_command;
  700. }
  701. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  702. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  703. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  704. ql_dbg(ql_dbg_io, vha, 0x3005,
  705. "Returning DNC, fcport_state=%d loop_state=%d.\n",
  706. atomic_read(&fcport->state),
  707. atomic_read(&base_vha->loop_state));
  708. cmd->result = DID_NO_CONNECT << 16;
  709. goto qc24_fail_command;
  710. }
  711. goto qc24_target_busy;
  712. }
  713. /*
  714. * Return target busy if we've received a non-zero retry_delay_timer
  715. * in a FCP_RSP.
  716. */
  717. if (fcport->retry_delay_timestamp == 0) {
  718. /* retry delay not set */
  719. } else if (time_after(jiffies, fcport->retry_delay_timestamp))
  720. fcport->retry_delay_timestamp = 0;
  721. else
  722. goto qc24_target_busy;
  723. sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
  724. if (!sp)
  725. goto qc24_host_busy;
  726. sp->u.scmd.cmd = cmd;
  727. sp->type = SRB_SCSI_CMD;
  728. atomic_set(&sp->ref_count, 1);
  729. CMD_SP(cmd) = (void *)sp;
  730. sp->free = qla2x00_sp_free_dma;
  731. sp->done = qla2x00_sp_compl;
  732. rval = ha->isp_ops->start_scsi(sp);
  733. if (rval != QLA_SUCCESS) {
  734. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
  735. "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
  736. goto qc24_host_busy_free_sp;
  737. }
  738. return 0;
  739. qc24_host_busy_free_sp:
  740. qla2x00_sp_free_dma(ha, sp);
  741. qc24_host_busy:
  742. return SCSI_MLQUEUE_HOST_BUSY;
  743. qc24_target_busy:
  744. return SCSI_MLQUEUE_TARGET_BUSY;
  745. qc24_fail_command:
  746. cmd->scsi_done(cmd);
  747. return 0;
  748. }
  749. /* For MQ supported I/O */
  750. int
  751. qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
  752. struct qla_qpair *qpair)
  753. {
  754. scsi_qla_host_t *vha = shost_priv(host);
  755. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  756. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  757. struct qla_hw_data *ha = vha->hw;
  758. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  759. srb_t *sp;
  760. int rval;
  761. rval = fc_remote_port_chkready(rport);
  762. if (rval) {
  763. cmd->result = rval;
  764. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
  765. "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
  766. cmd, rval);
  767. goto qc24_fail_command;
  768. }
  769. if (!fcport) {
  770. cmd->result = DID_NO_CONNECT << 16;
  771. goto qc24_fail_command;
  772. }
  773. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  774. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  775. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  776. ql_dbg(ql_dbg_io, vha, 0x3077,
  777. "Returning DNC, fcport_state=%d loop_state=%d.\n",
  778. atomic_read(&fcport->state),
  779. atomic_read(&base_vha->loop_state));
  780. cmd->result = DID_NO_CONNECT << 16;
  781. goto qc24_fail_command;
  782. }
  783. goto qc24_target_busy;
  784. }
  785. /*
  786. * Return target busy if we've received a non-zero retry_delay_timer
  787. * in a FCP_RSP.
  788. */
  789. if (fcport->retry_delay_timestamp == 0) {
  790. /* retry delay not set */
  791. } else if (time_after(jiffies, fcport->retry_delay_timestamp))
  792. fcport->retry_delay_timestamp = 0;
  793. else
  794. goto qc24_target_busy;
  795. sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
  796. if (!sp)
  797. goto qc24_host_busy;
  798. sp->u.scmd.cmd = cmd;
  799. sp->type = SRB_SCSI_CMD;
  800. atomic_set(&sp->ref_count, 1);
  801. CMD_SP(cmd) = (void *)sp;
  802. sp->free = qla2xxx_qpair_sp_free_dma;
  803. sp->done = qla2xxx_qpair_sp_compl;
  804. sp->qpair = qpair;
  805. rval = ha->isp_ops->start_scsi_mq(sp);
  806. if (rval != QLA_SUCCESS) {
  807. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
  808. "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
  809. if (rval == QLA_INTERFACE_ERROR)
  810. goto qc24_fail_command;
  811. goto qc24_host_busy_free_sp;
  812. }
  813. return 0;
  814. qc24_host_busy_free_sp:
  815. qla2xxx_qpair_sp_free_dma(vha, sp);
  816. qc24_host_busy:
  817. return SCSI_MLQUEUE_HOST_BUSY;
  818. qc24_target_busy:
  819. return SCSI_MLQUEUE_TARGET_BUSY;
  820. qc24_fail_command:
  821. cmd->scsi_done(cmd);
  822. return 0;
  823. }
  824. /*
  825. * qla2x00_eh_wait_on_command
  826. * Waits for the command to be returned by the Firmware for some
  827. * max time.
  828. *
  829. * Input:
  830. * cmd = Scsi Command to wait on.
  831. *
  832. * Return:
  833. * Not Found : 0
  834. * Found : 1
  835. */
  836. static int
  837. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  838. {
  839. #define ABORT_POLLING_PERIOD 1000
  840. #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
  841. unsigned long wait_iter = ABORT_WAIT_ITER;
  842. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  843. struct qla_hw_data *ha = vha->hw;
  844. int ret = QLA_SUCCESS;
  845. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  846. ql_dbg(ql_dbg_taskm, vha, 0x8005,
  847. "Return:eh_wait.\n");
  848. return ret;
  849. }
  850. while (CMD_SP(cmd) && wait_iter--) {
  851. msleep(ABORT_POLLING_PERIOD);
  852. }
  853. if (CMD_SP(cmd))
  854. ret = QLA_FUNCTION_FAILED;
  855. return ret;
  856. }
  857. /*
  858. * qla2x00_wait_for_hba_online
  859. * Wait till the HBA is online after going through
  860. * <= MAX_RETRIES_OF_ISP_ABORT or
  861. * finally HBA is disabled ie marked offline
  862. *
  863. * Input:
  864. * ha - pointer to host adapter structure
  865. *
  866. * Note:
  867. * Does context switching-Release SPIN_LOCK
  868. * (if any) before calling this routine.
  869. *
  870. * Return:
  871. * Success (Adapter is online) : 0
  872. * Failed (Adapter is offline/disabled) : 1
  873. */
  874. int
  875. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  876. {
  877. int return_status;
  878. unsigned long wait_online;
  879. struct qla_hw_data *ha = vha->hw;
  880. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  881. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  882. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  883. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  884. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  885. ha->dpc_active) && time_before(jiffies, wait_online)) {
  886. msleep(1000);
  887. }
  888. if (base_vha->flags.online)
  889. return_status = QLA_SUCCESS;
  890. else
  891. return_status = QLA_FUNCTION_FAILED;
  892. return (return_status);
  893. }
  894. /*
  895. * qla2x00_wait_for_hba_ready
  896. * Wait till the HBA is ready before doing driver unload
  897. *
  898. * Input:
  899. * ha - pointer to host adapter structure
  900. *
  901. * Note:
  902. * Does context switching-Release SPIN_LOCK
  903. * (if any) before calling this routine.
  904. *
  905. */
  906. static void
  907. qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
  908. {
  909. struct qla_hw_data *ha = vha->hw;
  910. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  911. while ((qla2x00_reset_active(vha) || ha->dpc_active ||
  912. ha->flags.mbox_busy) ||
  913. test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
  914. test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
  915. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  916. break;
  917. msleep(1000);
  918. }
  919. }
  920. int
  921. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  922. {
  923. int return_status;
  924. unsigned long wait_reset;
  925. struct qla_hw_data *ha = vha->hw;
  926. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  927. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  928. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  929. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  930. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  931. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  932. msleep(1000);
  933. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  934. ha->flags.chip_reset_done)
  935. break;
  936. }
  937. if (ha->flags.chip_reset_done)
  938. return_status = QLA_SUCCESS;
  939. else
  940. return_status = QLA_FUNCTION_FAILED;
  941. return return_status;
  942. }
  943. static void
  944. sp_get(struct srb *sp)
  945. {
  946. atomic_inc(&sp->ref_count);
  947. }
  948. #define ISP_REG_DISCONNECT 0xffffffffU
  949. /**************************************************************************
  950. * qla2x00_isp_reg_stat
  951. *
  952. * Description:
  953. * Read the host status register of ISP before aborting the command.
  954. *
  955. * Input:
  956. * ha = pointer to host adapter structure.
  957. *
  958. *
  959. * Returns:
  960. * Either true or false.
  961. *
  962. * Note: Return true if there is register disconnect.
  963. **************************************************************************/
  964. static inline
  965. uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
  966. {
  967. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  968. return ((RD_REG_DWORD(&reg->host_status)) == ISP_REG_DISCONNECT);
  969. }
  970. /**************************************************************************
  971. * qla2xxx_eh_abort
  972. *
  973. * Description:
  974. * The abort function will abort the specified command.
  975. *
  976. * Input:
  977. * cmd = Linux SCSI command packet to be aborted.
  978. *
  979. * Returns:
  980. * Either SUCCESS or FAILED.
  981. *
  982. * Note:
  983. * Only return FAILED if command not returned by firmware.
  984. **************************************************************************/
  985. static int
  986. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  987. {
  988. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  989. srb_t *sp;
  990. int ret;
  991. unsigned int id;
  992. uint64_t lun;
  993. unsigned long flags;
  994. int rval, wait = 0;
  995. struct qla_hw_data *ha = vha->hw;
  996. if (qla2x00_isp_reg_stat(ha)) {
  997. ql_log(ql_log_info, vha, 0x8042,
  998. "PCI/Register disconnect, exiting.\n");
  999. return FAILED;
  1000. }
  1001. if (!CMD_SP(cmd))
  1002. return SUCCESS;
  1003. ret = fc_block_scsi_eh(cmd);
  1004. if (ret != 0)
  1005. return ret;
  1006. ret = SUCCESS;
  1007. id = cmd->device->id;
  1008. lun = cmd->device->lun;
  1009. spin_lock_irqsave(&ha->hardware_lock, flags);
  1010. sp = (srb_t *) CMD_SP(cmd);
  1011. if (!sp) {
  1012. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1013. return SUCCESS;
  1014. }
  1015. ql_dbg(ql_dbg_taskm, vha, 0x8002,
  1016. "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
  1017. vha->host_no, id, lun, sp, cmd, sp->handle);
  1018. /* Get a reference to the sp and drop the lock.*/
  1019. sp_get(sp);
  1020. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1021. rval = ha->isp_ops->abort_command(sp);
  1022. if (rval) {
  1023. if (rval == QLA_FUNCTION_PARAMETER_ERROR)
  1024. ret = SUCCESS;
  1025. else
  1026. ret = FAILED;
  1027. ql_dbg(ql_dbg_taskm, vha, 0x8003,
  1028. "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
  1029. } else {
  1030. ql_dbg(ql_dbg_taskm, vha, 0x8004,
  1031. "Abort command mbx success cmd=%p.\n", cmd);
  1032. wait = 1;
  1033. }
  1034. spin_lock_irqsave(&ha->hardware_lock, flags);
  1035. sp->done(ha, sp, 0);
  1036. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1037. /* Did the command return during mailbox execution? */
  1038. if (ret == FAILED && !CMD_SP(cmd))
  1039. ret = SUCCESS;
  1040. /* Wait for the command to be returned. */
  1041. if (wait) {
  1042. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  1043. ql_log(ql_log_warn, vha, 0x8006,
  1044. "Abort handler timed out cmd=%p.\n", cmd);
  1045. ret = FAILED;
  1046. }
  1047. }
  1048. ql_log(ql_log_info, vha, 0x801c,
  1049. "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
  1050. vha->host_no, id, lun, wait, ret);
  1051. return ret;
  1052. }
  1053. int
  1054. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  1055. uint64_t l, enum nexus_wait_type type)
  1056. {
  1057. int cnt, match, status;
  1058. unsigned long flags;
  1059. struct qla_hw_data *ha = vha->hw;
  1060. struct req_que *req;
  1061. srb_t *sp;
  1062. struct scsi_cmnd *cmd;
  1063. status = QLA_SUCCESS;
  1064. spin_lock_irqsave(&ha->hardware_lock, flags);
  1065. req = vha->req;
  1066. for (cnt = 1; status == QLA_SUCCESS &&
  1067. cnt < req->num_outstanding_cmds; cnt++) {
  1068. sp = req->outstanding_cmds[cnt];
  1069. if (!sp)
  1070. continue;
  1071. if (sp->type != SRB_SCSI_CMD)
  1072. continue;
  1073. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  1074. continue;
  1075. match = 0;
  1076. cmd = GET_CMD_SP(sp);
  1077. switch (type) {
  1078. case WAIT_HOST:
  1079. match = 1;
  1080. break;
  1081. case WAIT_TARGET:
  1082. match = cmd->device->id == t;
  1083. break;
  1084. case WAIT_LUN:
  1085. match = (cmd->device->id == t &&
  1086. cmd->device->lun == l);
  1087. break;
  1088. }
  1089. if (!match)
  1090. continue;
  1091. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1092. status = qla2x00_eh_wait_on_command(cmd);
  1093. spin_lock_irqsave(&ha->hardware_lock, flags);
  1094. }
  1095. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1096. return status;
  1097. }
  1098. static char *reset_errors[] = {
  1099. "HBA not online",
  1100. "HBA not ready",
  1101. "Task management failed",
  1102. "Waiting for command completions",
  1103. };
  1104. static int
  1105. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  1106. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
  1107. {
  1108. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1109. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  1110. int err;
  1111. if (!fcport) {
  1112. return FAILED;
  1113. }
  1114. err = fc_block_scsi_eh(cmd);
  1115. if (err != 0)
  1116. return err;
  1117. ql_log(ql_log_info, vha, 0x8009,
  1118. "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
  1119. cmd->device->id, cmd->device->lun, cmd);
  1120. err = 0;
  1121. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1122. ql_log(ql_log_warn, vha, 0x800a,
  1123. "Wait for hba online failed for cmd=%p.\n", cmd);
  1124. goto eh_reset_failed;
  1125. }
  1126. err = 2;
  1127. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  1128. != QLA_SUCCESS) {
  1129. ql_log(ql_log_warn, vha, 0x800c,
  1130. "do_reset failed for cmd=%p.\n", cmd);
  1131. goto eh_reset_failed;
  1132. }
  1133. err = 3;
  1134. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  1135. cmd->device->lun, type) != QLA_SUCCESS) {
  1136. ql_log(ql_log_warn, vha, 0x800d,
  1137. "wait for pending cmds failed for cmd=%p.\n", cmd);
  1138. goto eh_reset_failed;
  1139. }
  1140. ql_log(ql_log_info, vha, 0x800e,
  1141. "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
  1142. vha->host_no, cmd->device->id, cmd->device->lun, cmd);
  1143. return SUCCESS;
  1144. eh_reset_failed:
  1145. ql_log(ql_log_info, vha, 0x800f,
  1146. "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
  1147. reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
  1148. cmd);
  1149. return FAILED;
  1150. }
  1151. static int
  1152. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  1153. {
  1154. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1155. struct qla_hw_data *ha = vha->hw;
  1156. if (qla2x00_isp_reg_stat(ha)) {
  1157. ql_log(ql_log_info, vha, 0x803e,
  1158. "PCI/Register disconnect, exiting.\n");
  1159. return FAILED;
  1160. }
  1161. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  1162. ha->isp_ops->lun_reset);
  1163. }
  1164. static int
  1165. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  1166. {
  1167. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1168. struct qla_hw_data *ha = vha->hw;
  1169. if (qla2x00_isp_reg_stat(ha)) {
  1170. ql_log(ql_log_info, vha, 0x803f,
  1171. "PCI/Register disconnect, exiting.\n");
  1172. return FAILED;
  1173. }
  1174. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  1175. ha->isp_ops->target_reset);
  1176. }
  1177. /**************************************************************************
  1178. * qla2xxx_eh_bus_reset
  1179. *
  1180. * Description:
  1181. * The bus reset function will reset the bus and abort any executing
  1182. * commands.
  1183. *
  1184. * Input:
  1185. * cmd = Linux SCSI command packet of the command that cause the
  1186. * bus reset.
  1187. *
  1188. * Returns:
  1189. * SUCCESS/FAILURE (defined as macro in scsi.h).
  1190. *
  1191. **************************************************************************/
  1192. static int
  1193. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  1194. {
  1195. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1196. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  1197. int ret = FAILED;
  1198. unsigned int id;
  1199. uint64_t lun;
  1200. struct qla_hw_data *ha = vha->hw;
  1201. if (qla2x00_isp_reg_stat(ha)) {
  1202. ql_log(ql_log_info, vha, 0x8040,
  1203. "PCI/Register disconnect, exiting.\n");
  1204. return FAILED;
  1205. }
  1206. id = cmd->device->id;
  1207. lun = cmd->device->lun;
  1208. if (!fcport) {
  1209. return ret;
  1210. }
  1211. ret = fc_block_scsi_eh(cmd);
  1212. if (ret != 0)
  1213. return ret;
  1214. ret = FAILED;
  1215. ql_log(ql_log_info, vha, 0x8012,
  1216. "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
  1217. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1218. ql_log(ql_log_fatal, vha, 0x8013,
  1219. "Wait for hba online failed board disabled.\n");
  1220. goto eh_bus_reset_done;
  1221. }
  1222. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  1223. ret = SUCCESS;
  1224. if (ret == FAILED)
  1225. goto eh_bus_reset_done;
  1226. /* Flush outstanding commands. */
  1227. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
  1228. QLA_SUCCESS) {
  1229. ql_log(ql_log_warn, vha, 0x8014,
  1230. "Wait for pending commands failed.\n");
  1231. ret = FAILED;
  1232. }
  1233. eh_bus_reset_done:
  1234. ql_log(ql_log_warn, vha, 0x802b,
  1235. "BUS RESET %s nexus=%ld:%d:%llu.\n",
  1236. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1237. return ret;
  1238. }
  1239. /**************************************************************************
  1240. * qla2xxx_eh_host_reset
  1241. *
  1242. * Description:
  1243. * The reset function will reset the Adapter.
  1244. *
  1245. * Input:
  1246. * cmd = Linux SCSI command packet of the command that cause the
  1247. * adapter reset.
  1248. *
  1249. * Returns:
  1250. * Either SUCCESS or FAILED.
  1251. *
  1252. * Note:
  1253. **************************************************************************/
  1254. static int
  1255. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1256. {
  1257. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1258. struct qla_hw_data *ha = vha->hw;
  1259. int ret = FAILED;
  1260. unsigned int id;
  1261. uint64_t lun;
  1262. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1263. if (qla2x00_isp_reg_stat(ha)) {
  1264. ql_log(ql_log_info, vha, 0x8041,
  1265. "PCI/Register disconnect, exiting.\n");
  1266. schedule_work(&ha->board_disable);
  1267. return SUCCESS;
  1268. }
  1269. id = cmd->device->id;
  1270. lun = cmd->device->lun;
  1271. ql_log(ql_log_info, vha, 0x8018,
  1272. "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
  1273. /*
  1274. * No point in issuing another reset if one is active. Also do not
  1275. * attempt a reset if we are updating flash.
  1276. */
  1277. if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
  1278. goto eh_host_reset_lock;
  1279. if (vha != base_vha) {
  1280. if (qla2x00_vp_abort_isp(vha))
  1281. goto eh_host_reset_lock;
  1282. } else {
  1283. if (IS_P3P_TYPE(vha->hw)) {
  1284. if (!qla82xx_fcoe_ctx_reset(vha)) {
  1285. /* Ctx reset success */
  1286. ret = SUCCESS;
  1287. goto eh_host_reset_lock;
  1288. }
  1289. /* fall thru if ctx reset failed */
  1290. }
  1291. if (ha->wq)
  1292. flush_workqueue(ha->wq);
  1293. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1294. if (ha->isp_ops->abort_isp(base_vha)) {
  1295. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1296. /* failed. schedule dpc to try */
  1297. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  1298. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1299. ql_log(ql_log_warn, vha, 0x802a,
  1300. "wait for hba online failed.\n");
  1301. goto eh_host_reset_lock;
  1302. }
  1303. }
  1304. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1305. }
  1306. /* Waiting for command to be returned to OS.*/
  1307. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
  1308. QLA_SUCCESS)
  1309. ret = SUCCESS;
  1310. eh_host_reset_lock:
  1311. ql_log(ql_log_info, vha, 0x8017,
  1312. "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
  1313. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1314. return ret;
  1315. }
  1316. /*
  1317. * qla2x00_loop_reset
  1318. * Issue loop reset.
  1319. *
  1320. * Input:
  1321. * ha = adapter block pointer.
  1322. *
  1323. * Returns:
  1324. * 0 = success
  1325. */
  1326. int
  1327. qla2x00_loop_reset(scsi_qla_host_t *vha)
  1328. {
  1329. int ret;
  1330. struct fc_port *fcport;
  1331. struct qla_hw_data *ha = vha->hw;
  1332. if (IS_QLAFX00(ha)) {
  1333. return qlafx00_loop_reset(vha);
  1334. }
  1335. if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
  1336. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1337. if (fcport->port_type != FCT_TARGET)
  1338. continue;
  1339. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  1340. if (ret != QLA_SUCCESS) {
  1341. ql_dbg(ql_dbg_taskm, vha, 0x802c,
  1342. "Bus Reset failed: Reset=%d "
  1343. "d_id=%x.\n", ret, fcport->d_id.b24);
  1344. }
  1345. }
  1346. }
  1347. if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
  1348. atomic_set(&vha->loop_state, LOOP_DOWN);
  1349. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  1350. qla2x00_mark_all_devices_lost(vha, 0);
  1351. ret = qla2x00_full_login_lip(vha);
  1352. if (ret != QLA_SUCCESS) {
  1353. ql_dbg(ql_dbg_taskm, vha, 0x802d,
  1354. "full_login_lip=%d.\n", ret);
  1355. }
  1356. }
  1357. if (ha->flags.enable_lip_reset) {
  1358. ret = qla2x00_lip_reset(vha);
  1359. if (ret != QLA_SUCCESS)
  1360. ql_dbg(ql_dbg_taskm, vha, 0x802e,
  1361. "lip_reset failed (%d).\n", ret);
  1362. }
  1363. /* Issue marker command only when we are going to start the I/O */
  1364. vha->marker_needed = 1;
  1365. return QLA_SUCCESS;
  1366. }
  1367. void
  1368. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  1369. {
  1370. int que, cnt;
  1371. unsigned long flags;
  1372. srb_t *sp;
  1373. struct qla_hw_data *ha = vha->hw;
  1374. struct req_que *req;
  1375. qlt_host_reset_handler(ha);
  1376. spin_lock_irqsave(&ha->hardware_lock, flags);
  1377. for (que = 0; que < ha->max_req_queues; que++) {
  1378. req = ha->req_q_map[que];
  1379. if (!req)
  1380. continue;
  1381. if (!req->outstanding_cmds)
  1382. continue;
  1383. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
  1384. sp = req->outstanding_cmds[cnt];
  1385. if (sp) {
  1386. /* Don't abort commands in adapter during EEH
  1387. * recovery as it's not accessible/responding.
  1388. */
  1389. if (!ha->flags.eeh_busy) {
  1390. /* Get a reference to the sp and drop the lock.
  1391. * The reference ensures this sp->done() call
  1392. * - and not the call in qla2xxx_eh_abort() -
  1393. * ends the SCSI command (with result 'res').
  1394. */
  1395. sp_get(sp);
  1396. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1397. qla2xxx_eh_abort(GET_CMD_SP(sp));
  1398. spin_lock_irqsave(&ha->hardware_lock, flags);
  1399. }
  1400. req->outstanding_cmds[cnt] = NULL;
  1401. sp->done(vha, sp, res);
  1402. }
  1403. }
  1404. }
  1405. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1406. }
  1407. static int
  1408. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1409. {
  1410. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1411. if (!rport || fc_remote_port_chkready(rport))
  1412. return -ENXIO;
  1413. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1414. return 0;
  1415. }
  1416. static int
  1417. qla2xxx_slave_configure(struct scsi_device *sdev)
  1418. {
  1419. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1420. struct req_que *req = vha->req;
  1421. if (IS_T10_PI_CAPABLE(vha->hw))
  1422. blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
  1423. scsi_change_queue_depth(sdev, req->max_q_depth);
  1424. return 0;
  1425. }
  1426. static void
  1427. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1428. {
  1429. sdev->hostdata = NULL;
  1430. }
  1431. /**
  1432. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1433. * @ha: HA context
  1434. *
  1435. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1436. * supported addressing method.
  1437. */
  1438. static void
  1439. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1440. {
  1441. /* Assume a 32bit DMA mask. */
  1442. ha->flags.enable_64bit_addressing = 0;
  1443. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1444. /* Any upper-dword bits set? */
  1445. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1446. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1447. /* Ok, a 64bit DMA mask is applicable. */
  1448. ha->flags.enable_64bit_addressing = 1;
  1449. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1450. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1451. return;
  1452. }
  1453. }
  1454. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1455. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1456. }
  1457. static void
  1458. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1459. {
  1460. unsigned long flags = 0;
  1461. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1462. spin_lock_irqsave(&ha->hardware_lock, flags);
  1463. ha->interrupts_on = 1;
  1464. /* enable risc and host interrupts */
  1465. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1466. RD_REG_WORD(&reg->ictrl);
  1467. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1468. }
  1469. static void
  1470. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1471. {
  1472. unsigned long flags = 0;
  1473. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1474. spin_lock_irqsave(&ha->hardware_lock, flags);
  1475. ha->interrupts_on = 0;
  1476. /* disable risc and host interrupts */
  1477. WRT_REG_WORD(&reg->ictrl, 0);
  1478. RD_REG_WORD(&reg->ictrl);
  1479. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1480. }
  1481. static void
  1482. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1483. {
  1484. unsigned long flags = 0;
  1485. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1486. spin_lock_irqsave(&ha->hardware_lock, flags);
  1487. ha->interrupts_on = 1;
  1488. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1489. RD_REG_DWORD(&reg->ictrl);
  1490. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1491. }
  1492. static void
  1493. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1494. {
  1495. unsigned long flags = 0;
  1496. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1497. if (IS_NOPOLLING_TYPE(ha))
  1498. return;
  1499. spin_lock_irqsave(&ha->hardware_lock, flags);
  1500. ha->interrupts_on = 0;
  1501. WRT_REG_DWORD(&reg->ictrl, 0);
  1502. RD_REG_DWORD(&reg->ictrl);
  1503. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1504. }
  1505. static int
  1506. qla2x00_iospace_config(struct qla_hw_data *ha)
  1507. {
  1508. resource_size_t pio;
  1509. uint16_t msix;
  1510. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1511. QLA2XXX_DRIVER_NAME)) {
  1512. ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
  1513. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1514. pci_name(ha->pdev));
  1515. goto iospace_error_exit;
  1516. }
  1517. if (!(ha->bars & 1))
  1518. goto skip_pio;
  1519. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1520. pio = pci_resource_start(ha->pdev, 0);
  1521. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1522. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1523. ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
  1524. "Invalid pci I/O region size (%s).\n",
  1525. pci_name(ha->pdev));
  1526. pio = 0;
  1527. }
  1528. } else {
  1529. ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
  1530. "Region #0 no a PIO resource (%s).\n",
  1531. pci_name(ha->pdev));
  1532. pio = 0;
  1533. }
  1534. ha->pio_address = pio;
  1535. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
  1536. "PIO address=%llu.\n",
  1537. (unsigned long long)ha->pio_address);
  1538. skip_pio:
  1539. /* Use MMIO operations for all accesses. */
  1540. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1541. ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
  1542. "Region #1 not an MMIO resource (%s), aborting.\n",
  1543. pci_name(ha->pdev));
  1544. goto iospace_error_exit;
  1545. }
  1546. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1547. ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
  1548. "Invalid PCI mem region size (%s), aborting.\n",
  1549. pci_name(ha->pdev));
  1550. goto iospace_error_exit;
  1551. }
  1552. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1553. if (!ha->iobase) {
  1554. ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
  1555. "Cannot remap MMIO (%s), aborting.\n",
  1556. pci_name(ha->pdev));
  1557. goto iospace_error_exit;
  1558. }
  1559. /* Determine queue resources */
  1560. ha->max_req_queues = ha->max_rsp_queues = 1;
  1561. if (!ql2xmqsupport || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1562. goto mqiobase_exit;
  1563. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1564. pci_resource_len(ha->pdev, 3));
  1565. if (ha->mqiobase) {
  1566. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
  1567. "MQIO Base=%p.\n", ha->mqiobase);
  1568. /* Read MSIX vector size of the board */
  1569. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1570. ha->msix_count = msix + 1;
  1571. /* Max queues are bounded by available msix vectors */
  1572. /* MB interrupt uses 1 vector */
  1573. ha->max_req_queues = ha->msix_count - 1;
  1574. ha->max_rsp_queues = ha->max_req_queues;
  1575. /* Queue pairs is the max value minus the base queue pair */
  1576. ha->max_qpairs = ha->max_rsp_queues - 1;
  1577. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
  1578. "Max no of queues pairs: %d.\n", ha->max_qpairs);
  1579. ql_log_pci(ql_log_info, ha->pdev, 0x001a,
  1580. "MSI-X vector count: %d.\n", ha->msix_count);
  1581. } else
  1582. ql_log_pci(ql_log_info, ha->pdev, 0x001b,
  1583. "BAR 3 not enabled.\n");
  1584. mqiobase_exit:
  1585. ha->msix_count = ha->max_rsp_queues + 1;
  1586. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
  1587. "MSIX Count:%d.\n", ha->msix_count);
  1588. return (0);
  1589. iospace_error_exit:
  1590. return (-ENOMEM);
  1591. }
  1592. static int
  1593. qla83xx_iospace_config(struct qla_hw_data *ha)
  1594. {
  1595. uint16_t msix;
  1596. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1597. QLA2XXX_DRIVER_NAME)) {
  1598. ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
  1599. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1600. pci_name(ha->pdev));
  1601. goto iospace_error_exit;
  1602. }
  1603. /* Use MMIO operations for all accesses. */
  1604. if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
  1605. ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
  1606. "Invalid pci I/O region size (%s).\n",
  1607. pci_name(ha->pdev));
  1608. goto iospace_error_exit;
  1609. }
  1610. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1611. ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
  1612. "Invalid PCI mem region size (%s), aborting\n",
  1613. pci_name(ha->pdev));
  1614. goto iospace_error_exit;
  1615. }
  1616. ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
  1617. if (!ha->iobase) {
  1618. ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
  1619. "Cannot remap MMIO (%s), aborting.\n",
  1620. pci_name(ha->pdev));
  1621. goto iospace_error_exit;
  1622. }
  1623. /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
  1624. /* 83XX 26XX always use MQ type access for queues
  1625. * - mbar 2, a.k.a region 4 */
  1626. ha->max_req_queues = ha->max_rsp_queues = 1;
  1627. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
  1628. pci_resource_len(ha->pdev, 4));
  1629. if (!ha->mqiobase) {
  1630. ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
  1631. "BAR2/region4 not enabled\n");
  1632. goto mqiobase_exit;
  1633. }
  1634. ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
  1635. pci_resource_len(ha->pdev, 2));
  1636. if (ha->msixbase) {
  1637. /* Read MSIX vector size of the board */
  1638. pci_read_config_word(ha->pdev,
  1639. QLA_83XX_PCI_MSIX_CONTROL, &msix);
  1640. ha->msix_count = msix + 1;
  1641. /*
  1642. * By default, driver uses at least two msix vectors
  1643. * (default & rspq)
  1644. */
  1645. if (ql2xmqsupport) {
  1646. /* MB interrupt uses 1 vector */
  1647. ha->max_req_queues = ha->msix_count - 1;
  1648. ha->max_rsp_queues = ha->max_req_queues;
  1649. /* ATIOQ needs 1 vector. That's 1 less QPair */
  1650. if (QLA_TGT_MODE_ENABLED())
  1651. ha->max_req_queues--;
  1652. /* Queue pairs is the max value minus
  1653. * the base queue pair */
  1654. ha->max_qpairs = ha->max_req_queues - 1;
  1655. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0190,
  1656. "Max no of queues pairs: %d.\n", ha->max_qpairs);
  1657. }
  1658. ql_log_pci(ql_log_info, ha->pdev, 0x011c,
  1659. "MSI-X vector count: %d.\n", ha->msix_count);
  1660. } else
  1661. ql_log_pci(ql_log_info, ha->pdev, 0x011e,
  1662. "BAR 1 not enabled.\n");
  1663. mqiobase_exit:
  1664. ha->msix_count = ha->max_rsp_queues + 1;
  1665. if (QLA_TGT_MODE_ENABLED())
  1666. ha->msix_count++;
  1667. qlt_83xx_iospace_config(ha);
  1668. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
  1669. "MSIX Count:%d.\n", ha->msix_count);
  1670. return 0;
  1671. iospace_error_exit:
  1672. return -ENOMEM;
  1673. }
  1674. static struct isp_operations qla2100_isp_ops = {
  1675. .pci_config = qla2100_pci_config,
  1676. .reset_chip = qla2x00_reset_chip,
  1677. .chip_diag = qla2x00_chip_diag,
  1678. .config_rings = qla2x00_config_rings,
  1679. .reset_adapter = qla2x00_reset_adapter,
  1680. .nvram_config = qla2x00_nvram_config,
  1681. .update_fw_options = qla2x00_update_fw_options,
  1682. .load_risc = qla2x00_load_risc,
  1683. .pci_info_str = qla2x00_pci_info_str,
  1684. .fw_version_str = qla2x00_fw_version_str,
  1685. .intr_handler = qla2100_intr_handler,
  1686. .enable_intrs = qla2x00_enable_intrs,
  1687. .disable_intrs = qla2x00_disable_intrs,
  1688. .abort_command = qla2x00_abort_command,
  1689. .target_reset = qla2x00_abort_target,
  1690. .lun_reset = qla2x00_lun_reset,
  1691. .fabric_login = qla2x00_login_fabric,
  1692. .fabric_logout = qla2x00_fabric_logout,
  1693. .calc_req_entries = qla2x00_calc_iocbs_32,
  1694. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1695. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1696. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1697. .read_nvram = qla2x00_read_nvram_data,
  1698. .write_nvram = qla2x00_write_nvram_data,
  1699. .fw_dump = qla2100_fw_dump,
  1700. .beacon_on = NULL,
  1701. .beacon_off = NULL,
  1702. .beacon_blink = NULL,
  1703. .read_optrom = qla2x00_read_optrom_data,
  1704. .write_optrom = qla2x00_write_optrom_data,
  1705. .get_flash_version = qla2x00_get_flash_version,
  1706. .start_scsi = qla2x00_start_scsi,
  1707. .start_scsi_mq = NULL,
  1708. .abort_isp = qla2x00_abort_isp,
  1709. .iospace_config = qla2x00_iospace_config,
  1710. .initialize_adapter = qla2x00_initialize_adapter,
  1711. };
  1712. static struct isp_operations qla2300_isp_ops = {
  1713. .pci_config = qla2300_pci_config,
  1714. .reset_chip = qla2x00_reset_chip,
  1715. .chip_diag = qla2x00_chip_diag,
  1716. .config_rings = qla2x00_config_rings,
  1717. .reset_adapter = qla2x00_reset_adapter,
  1718. .nvram_config = qla2x00_nvram_config,
  1719. .update_fw_options = qla2x00_update_fw_options,
  1720. .load_risc = qla2x00_load_risc,
  1721. .pci_info_str = qla2x00_pci_info_str,
  1722. .fw_version_str = qla2x00_fw_version_str,
  1723. .intr_handler = qla2300_intr_handler,
  1724. .enable_intrs = qla2x00_enable_intrs,
  1725. .disable_intrs = qla2x00_disable_intrs,
  1726. .abort_command = qla2x00_abort_command,
  1727. .target_reset = qla2x00_abort_target,
  1728. .lun_reset = qla2x00_lun_reset,
  1729. .fabric_login = qla2x00_login_fabric,
  1730. .fabric_logout = qla2x00_fabric_logout,
  1731. .calc_req_entries = qla2x00_calc_iocbs_32,
  1732. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1733. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1734. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1735. .read_nvram = qla2x00_read_nvram_data,
  1736. .write_nvram = qla2x00_write_nvram_data,
  1737. .fw_dump = qla2300_fw_dump,
  1738. .beacon_on = qla2x00_beacon_on,
  1739. .beacon_off = qla2x00_beacon_off,
  1740. .beacon_blink = qla2x00_beacon_blink,
  1741. .read_optrom = qla2x00_read_optrom_data,
  1742. .write_optrom = qla2x00_write_optrom_data,
  1743. .get_flash_version = qla2x00_get_flash_version,
  1744. .start_scsi = qla2x00_start_scsi,
  1745. .start_scsi_mq = NULL,
  1746. .abort_isp = qla2x00_abort_isp,
  1747. .iospace_config = qla2x00_iospace_config,
  1748. .initialize_adapter = qla2x00_initialize_adapter,
  1749. };
  1750. static struct isp_operations qla24xx_isp_ops = {
  1751. .pci_config = qla24xx_pci_config,
  1752. .reset_chip = qla24xx_reset_chip,
  1753. .chip_diag = qla24xx_chip_diag,
  1754. .config_rings = qla24xx_config_rings,
  1755. .reset_adapter = qla24xx_reset_adapter,
  1756. .nvram_config = qla24xx_nvram_config,
  1757. .update_fw_options = qla24xx_update_fw_options,
  1758. .load_risc = qla24xx_load_risc,
  1759. .pci_info_str = qla24xx_pci_info_str,
  1760. .fw_version_str = qla24xx_fw_version_str,
  1761. .intr_handler = qla24xx_intr_handler,
  1762. .enable_intrs = qla24xx_enable_intrs,
  1763. .disable_intrs = qla24xx_disable_intrs,
  1764. .abort_command = qla24xx_abort_command,
  1765. .target_reset = qla24xx_abort_target,
  1766. .lun_reset = qla24xx_lun_reset,
  1767. .fabric_login = qla24xx_login_fabric,
  1768. .fabric_logout = qla24xx_fabric_logout,
  1769. .calc_req_entries = NULL,
  1770. .build_iocbs = NULL,
  1771. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1772. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1773. .read_nvram = qla24xx_read_nvram_data,
  1774. .write_nvram = qla24xx_write_nvram_data,
  1775. .fw_dump = qla24xx_fw_dump,
  1776. .beacon_on = qla24xx_beacon_on,
  1777. .beacon_off = qla24xx_beacon_off,
  1778. .beacon_blink = qla24xx_beacon_blink,
  1779. .read_optrom = qla24xx_read_optrom_data,
  1780. .write_optrom = qla24xx_write_optrom_data,
  1781. .get_flash_version = qla24xx_get_flash_version,
  1782. .start_scsi = qla24xx_start_scsi,
  1783. .start_scsi_mq = NULL,
  1784. .abort_isp = qla2x00_abort_isp,
  1785. .iospace_config = qla2x00_iospace_config,
  1786. .initialize_adapter = qla2x00_initialize_adapter,
  1787. };
  1788. static struct isp_operations qla25xx_isp_ops = {
  1789. .pci_config = qla25xx_pci_config,
  1790. .reset_chip = qla24xx_reset_chip,
  1791. .chip_diag = qla24xx_chip_diag,
  1792. .config_rings = qla24xx_config_rings,
  1793. .reset_adapter = qla24xx_reset_adapter,
  1794. .nvram_config = qla24xx_nvram_config,
  1795. .update_fw_options = qla24xx_update_fw_options,
  1796. .load_risc = qla24xx_load_risc,
  1797. .pci_info_str = qla24xx_pci_info_str,
  1798. .fw_version_str = qla24xx_fw_version_str,
  1799. .intr_handler = qla24xx_intr_handler,
  1800. .enable_intrs = qla24xx_enable_intrs,
  1801. .disable_intrs = qla24xx_disable_intrs,
  1802. .abort_command = qla24xx_abort_command,
  1803. .target_reset = qla24xx_abort_target,
  1804. .lun_reset = qla24xx_lun_reset,
  1805. .fabric_login = qla24xx_login_fabric,
  1806. .fabric_logout = qla24xx_fabric_logout,
  1807. .calc_req_entries = NULL,
  1808. .build_iocbs = NULL,
  1809. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1810. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1811. .read_nvram = qla25xx_read_nvram_data,
  1812. .write_nvram = qla25xx_write_nvram_data,
  1813. .fw_dump = qla25xx_fw_dump,
  1814. .beacon_on = qla24xx_beacon_on,
  1815. .beacon_off = qla24xx_beacon_off,
  1816. .beacon_blink = qla24xx_beacon_blink,
  1817. .read_optrom = qla25xx_read_optrom_data,
  1818. .write_optrom = qla24xx_write_optrom_data,
  1819. .get_flash_version = qla24xx_get_flash_version,
  1820. .start_scsi = qla24xx_dif_start_scsi,
  1821. .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
  1822. .abort_isp = qla2x00_abort_isp,
  1823. .iospace_config = qla2x00_iospace_config,
  1824. .initialize_adapter = qla2x00_initialize_adapter,
  1825. };
  1826. static struct isp_operations qla81xx_isp_ops = {
  1827. .pci_config = qla25xx_pci_config,
  1828. .reset_chip = qla24xx_reset_chip,
  1829. .chip_diag = qla24xx_chip_diag,
  1830. .config_rings = qla24xx_config_rings,
  1831. .reset_adapter = qla24xx_reset_adapter,
  1832. .nvram_config = qla81xx_nvram_config,
  1833. .update_fw_options = qla81xx_update_fw_options,
  1834. .load_risc = qla81xx_load_risc,
  1835. .pci_info_str = qla24xx_pci_info_str,
  1836. .fw_version_str = qla24xx_fw_version_str,
  1837. .intr_handler = qla24xx_intr_handler,
  1838. .enable_intrs = qla24xx_enable_intrs,
  1839. .disable_intrs = qla24xx_disable_intrs,
  1840. .abort_command = qla24xx_abort_command,
  1841. .target_reset = qla24xx_abort_target,
  1842. .lun_reset = qla24xx_lun_reset,
  1843. .fabric_login = qla24xx_login_fabric,
  1844. .fabric_logout = qla24xx_fabric_logout,
  1845. .calc_req_entries = NULL,
  1846. .build_iocbs = NULL,
  1847. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1848. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1849. .read_nvram = NULL,
  1850. .write_nvram = NULL,
  1851. .fw_dump = qla81xx_fw_dump,
  1852. .beacon_on = qla24xx_beacon_on,
  1853. .beacon_off = qla24xx_beacon_off,
  1854. .beacon_blink = qla83xx_beacon_blink,
  1855. .read_optrom = qla25xx_read_optrom_data,
  1856. .write_optrom = qla24xx_write_optrom_data,
  1857. .get_flash_version = qla24xx_get_flash_version,
  1858. .start_scsi = qla24xx_dif_start_scsi,
  1859. .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
  1860. .abort_isp = qla2x00_abort_isp,
  1861. .iospace_config = qla2x00_iospace_config,
  1862. .initialize_adapter = qla2x00_initialize_adapter,
  1863. };
  1864. static struct isp_operations qla82xx_isp_ops = {
  1865. .pci_config = qla82xx_pci_config,
  1866. .reset_chip = qla82xx_reset_chip,
  1867. .chip_diag = qla24xx_chip_diag,
  1868. .config_rings = qla82xx_config_rings,
  1869. .reset_adapter = qla24xx_reset_adapter,
  1870. .nvram_config = qla81xx_nvram_config,
  1871. .update_fw_options = qla24xx_update_fw_options,
  1872. .load_risc = qla82xx_load_risc,
  1873. .pci_info_str = qla24xx_pci_info_str,
  1874. .fw_version_str = qla24xx_fw_version_str,
  1875. .intr_handler = qla82xx_intr_handler,
  1876. .enable_intrs = qla82xx_enable_intrs,
  1877. .disable_intrs = qla82xx_disable_intrs,
  1878. .abort_command = qla24xx_abort_command,
  1879. .target_reset = qla24xx_abort_target,
  1880. .lun_reset = qla24xx_lun_reset,
  1881. .fabric_login = qla24xx_login_fabric,
  1882. .fabric_logout = qla24xx_fabric_logout,
  1883. .calc_req_entries = NULL,
  1884. .build_iocbs = NULL,
  1885. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1886. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1887. .read_nvram = qla24xx_read_nvram_data,
  1888. .write_nvram = qla24xx_write_nvram_data,
  1889. .fw_dump = qla82xx_fw_dump,
  1890. .beacon_on = qla82xx_beacon_on,
  1891. .beacon_off = qla82xx_beacon_off,
  1892. .beacon_blink = NULL,
  1893. .read_optrom = qla82xx_read_optrom_data,
  1894. .write_optrom = qla82xx_write_optrom_data,
  1895. .get_flash_version = qla82xx_get_flash_version,
  1896. .start_scsi = qla82xx_start_scsi,
  1897. .start_scsi_mq = NULL,
  1898. .abort_isp = qla82xx_abort_isp,
  1899. .iospace_config = qla82xx_iospace_config,
  1900. .initialize_adapter = qla2x00_initialize_adapter,
  1901. };
  1902. static struct isp_operations qla8044_isp_ops = {
  1903. .pci_config = qla82xx_pci_config,
  1904. .reset_chip = qla82xx_reset_chip,
  1905. .chip_diag = qla24xx_chip_diag,
  1906. .config_rings = qla82xx_config_rings,
  1907. .reset_adapter = qla24xx_reset_adapter,
  1908. .nvram_config = qla81xx_nvram_config,
  1909. .update_fw_options = qla24xx_update_fw_options,
  1910. .load_risc = qla82xx_load_risc,
  1911. .pci_info_str = qla24xx_pci_info_str,
  1912. .fw_version_str = qla24xx_fw_version_str,
  1913. .intr_handler = qla8044_intr_handler,
  1914. .enable_intrs = qla82xx_enable_intrs,
  1915. .disable_intrs = qla82xx_disable_intrs,
  1916. .abort_command = qla24xx_abort_command,
  1917. .target_reset = qla24xx_abort_target,
  1918. .lun_reset = qla24xx_lun_reset,
  1919. .fabric_login = qla24xx_login_fabric,
  1920. .fabric_logout = qla24xx_fabric_logout,
  1921. .calc_req_entries = NULL,
  1922. .build_iocbs = NULL,
  1923. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1924. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1925. .read_nvram = NULL,
  1926. .write_nvram = NULL,
  1927. .fw_dump = qla8044_fw_dump,
  1928. .beacon_on = qla82xx_beacon_on,
  1929. .beacon_off = qla82xx_beacon_off,
  1930. .beacon_blink = NULL,
  1931. .read_optrom = qla8044_read_optrom_data,
  1932. .write_optrom = qla8044_write_optrom_data,
  1933. .get_flash_version = qla82xx_get_flash_version,
  1934. .start_scsi = qla82xx_start_scsi,
  1935. .start_scsi_mq = NULL,
  1936. .abort_isp = qla8044_abort_isp,
  1937. .iospace_config = qla82xx_iospace_config,
  1938. .initialize_adapter = qla2x00_initialize_adapter,
  1939. };
  1940. static struct isp_operations qla83xx_isp_ops = {
  1941. .pci_config = qla25xx_pci_config,
  1942. .reset_chip = qla24xx_reset_chip,
  1943. .chip_diag = qla24xx_chip_diag,
  1944. .config_rings = qla24xx_config_rings,
  1945. .reset_adapter = qla24xx_reset_adapter,
  1946. .nvram_config = qla81xx_nvram_config,
  1947. .update_fw_options = qla81xx_update_fw_options,
  1948. .load_risc = qla81xx_load_risc,
  1949. .pci_info_str = qla24xx_pci_info_str,
  1950. .fw_version_str = qla24xx_fw_version_str,
  1951. .intr_handler = qla24xx_intr_handler,
  1952. .enable_intrs = qla24xx_enable_intrs,
  1953. .disable_intrs = qla24xx_disable_intrs,
  1954. .abort_command = qla24xx_abort_command,
  1955. .target_reset = qla24xx_abort_target,
  1956. .lun_reset = qla24xx_lun_reset,
  1957. .fabric_login = qla24xx_login_fabric,
  1958. .fabric_logout = qla24xx_fabric_logout,
  1959. .calc_req_entries = NULL,
  1960. .build_iocbs = NULL,
  1961. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1962. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1963. .read_nvram = NULL,
  1964. .write_nvram = NULL,
  1965. .fw_dump = qla83xx_fw_dump,
  1966. .beacon_on = qla24xx_beacon_on,
  1967. .beacon_off = qla24xx_beacon_off,
  1968. .beacon_blink = qla83xx_beacon_blink,
  1969. .read_optrom = qla25xx_read_optrom_data,
  1970. .write_optrom = qla24xx_write_optrom_data,
  1971. .get_flash_version = qla24xx_get_flash_version,
  1972. .start_scsi = qla24xx_dif_start_scsi,
  1973. .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
  1974. .abort_isp = qla2x00_abort_isp,
  1975. .iospace_config = qla83xx_iospace_config,
  1976. .initialize_adapter = qla2x00_initialize_adapter,
  1977. };
  1978. static struct isp_operations qlafx00_isp_ops = {
  1979. .pci_config = qlafx00_pci_config,
  1980. .reset_chip = qlafx00_soft_reset,
  1981. .chip_diag = qlafx00_chip_diag,
  1982. .config_rings = qlafx00_config_rings,
  1983. .reset_adapter = qlafx00_soft_reset,
  1984. .nvram_config = NULL,
  1985. .update_fw_options = NULL,
  1986. .load_risc = NULL,
  1987. .pci_info_str = qlafx00_pci_info_str,
  1988. .fw_version_str = qlafx00_fw_version_str,
  1989. .intr_handler = qlafx00_intr_handler,
  1990. .enable_intrs = qlafx00_enable_intrs,
  1991. .disable_intrs = qlafx00_disable_intrs,
  1992. .abort_command = qla24xx_async_abort_command,
  1993. .target_reset = qlafx00_abort_target,
  1994. .lun_reset = qlafx00_lun_reset,
  1995. .fabric_login = NULL,
  1996. .fabric_logout = NULL,
  1997. .calc_req_entries = NULL,
  1998. .build_iocbs = NULL,
  1999. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  2000. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  2001. .read_nvram = qla24xx_read_nvram_data,
  2002. .write_nvram = qla24xx_write_nvram_data,
  2003. .fw_dump = NULL,
  2004. .beacon_on = qla24xx_beacon_on,
  2005. .beacon_off = qla24xx_beacon_off,
  2006. .beacon_blink = NULL,
  2007. .read_optrom = qla24xx_read_optrom_data,
  2008. .write_optrom = qla24xx_write_optrom_data,
  2009. .get_flash_version = qla24xx_get_flash_version,
  2010. .start_scsi = qlafx00_start_scsi,
  2011. .start_scsi_mq = NULL,
  2012. .abort_isp = qlafx00_abort_isp,
  2013. .iospace_config = qlafx00_iospace_config,
  2014. .initialize_adapter = qlafx00_initialize_adapter,
  2015. };
  2016. static struct isp_operations qla27xx_isp_ops = {
  2017. .pci_config = qla25xx_pci_config,
  2018. .reset_chip = qla24xx_reset_chip,
  2019. .chip_diag = qla24xx_chip_diag,
  2020. .config_rings = qla24xx_config_rings,
  2021. .reset_adapter = qla24xx_reset_adapter,
  2022. .nvram_config = qla81xx_nvram_config,
  2023. .update_fw_options = qla81xx_update_fw_options,
  2024. .load_risc = qla81xx_load_risc,
  2025. .pci_info_str = qla24xx_pci_info_str,
  2026. .fw_version_str = qla24xx_fw_version_str,
  2027. .intr_handler = qla24xx_intr_handler,
  2028. .enable_intrs = qla24xx_enable_intrs,
  2029. .disable_intrs = qla24xx_disable_intrs,
  2030. .abort_command = qla24xx_abort_command,
  2031. .target_reset = qla24xx_abort_target,
  2032. .lun_reset = qla24xx_lun_reset,
  2033. .fabric_login = qla24xx_login_fabric,
  2034. .fabric_logout = qla24xx_fabric_logout,
  2035. .calc_req_entries = NULL,
  2036. .build_iocbs = NULL,
  2037. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  2038. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  2039. .read_nvram = NULL,
  2040. .write_nvram = NULL,
  2041. .fw_dump = qla27xx_fwdump,
  2042. .beacon_on = qla24xx_beacon_on,
  2043. .beacon_off = qla24xx_beacon_off,
  2044. .beacon_blink = qla83xx_beacon_blink,
  2045. .read_optrom = qla25xx_read_optrom_data,
  2046. .write_optrom = qla24xx_write_optrom_data,
  2047. .get_flash_version = qla24xx_get_flash_version,
  2048. .start_scsi = qla24xx_dif_start_scsi,
  2049. .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
  2050. .abort_isp = qla2x00_abort_isp,
  2051. .iospace_config = qla83xx_iospace_config,
  2052. .initialize_adapter = qla2x00_initialize_adapter,
  2053. };
  2054. static inline void
  2055. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  2056. {
  2057. ha->device_type = DT_EXTENDED_IDS;
  2058. switch (ha->pdev->device) {
  2059. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  2060. ha->isp_type |= DT_ISP2100;
  2061. ha->device_type &= ~DT_EXTENDED_IDS;
  2062. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  2063. break;
  2064. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  2065. ha->isp_type |= DT_ISP2200;
  2066. ha->device_type &= ~DT_EXTENDED_IDS;
  2067. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  2068. break;
  2069. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  2070. ha->isp_type |= DT_ISP2300;
  2071. ha->device_type |= DT_ZIO_SUPPORTED;
  2072. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  2073. break;
  2074. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  2075. ha->isp_type |= DT_ISP2312;
  2076. ha->device_type |= DT_ZIO_SUPPORTED;
  2077. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  2078. break;
  2079. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  2080. ha->isp_type |= DT_ISP2322;
  2081. ha->device_type |= DT_ZIO_SUPPORTED;
  2082. if (ha->pdev->subsystem_vendor == 0x1028 &&
  2083. ha->pdev->subsystem_device == 0x0170)
  2084. ha->device_type |= DT_OEM_001;
  2085. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  2086. break;
  2087. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  2088. ha->isp_type |= DT_ISP6312;
  2089. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  2090. break;
  2091. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  2092. ha->isp_type |= DT_ISP6322;
  2093. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  2094. break;
  2095. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  2096. ha->isp_type |= DT_ISP2422;
  2097. ha->device_type |= DT_ZIO_SUPPORTED;
  2098. ha->device_type |= DT_FWI2;
  2099. ha->device_type |= DT_IIDMA;
  2100. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2101. break;
  2102. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  2103. ha->isp_type |= DT_ISP2432;
  2104. ha->device_type |= DT_ZIO_SUPPORTED;
  2105. ha->device_type |= DT_FWI2;
  2106. ha->device_type |= DT_IIDMA;
  2107. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2108. break;
  2109. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  2110. ha->isp_type |= DT_ISP8432;
  2111. ha->device_type |= DT_ZIO_SUPPORTED;
  2112. ha->device_type |= DT_FWI2;
  2113. ha->device_type |= DT_IIDMA;
  2114. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2115. break;
  2116. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  2117. ha->isp_type |= DT_ISP5422;
  2118. ha->device_type |= DT_FWI2;
  2119. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2120. break;
  2121. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  2122. ha->isp_type |= DT_ISP5432;
  2123. ha->device_type |= DT_FWI2;
  2124. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2125. break;
  2126. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  2127. ha->isp_type |= DT_ISP2532;
  2128. ha->device_type |= DT_ZIO_SUPPORTED;
  2129. ha->device_type |= DT_FWI2;
  2130. ha->device_type |= DT_IIDMA;
  2131. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2132. break;
  2133. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  2134. ha->isp_type |= DT_ISP8001;
  2135. ha->device_type |= DT_ZIO_SUPPORTED;
  2136. ha->device_type |= DT_FWI2;
  2137. ha->device_type |= DT_IIDMA;
  2138. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2139. break;
  2140. case PCI_DEVICE_ID_QLOGIC_ISP8021:
  2141. ha->isp_type |= DT_ISP8021;
  2142. ha->device_type |= DT_ZIO_SUPPORTED;
  2143. ha->device_type |= DT_FWI2;
  2144. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2145. /* Initialize 82XX ISP flags */
  2146. qla82xx_init_flags(ha);
  2147. break;
  2148. case PCI_DEVICE_ID_QLOGIC_ISP8044:
  2149. ha->isp_type |= DT_ISP8044;
  2150. ha->device_type |= DT_ZIO_SUPPORTED;
  2151. ha->device_type |= DT_FWI2;
  2152. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2153. /* Initialize 82XX ISP flags */
  2154. qla82xx_init_flags(ha);
  2155. break;
  2156. case PCI_DEVICE_ID_QLOGIC_ISP2031:
  2157. ha->isp_type |= DT_ISP2031;
  2158. ha->device_type |= DT_ZIO_SUPPORTED;
  2159. ha->device_type |= DT_FWI2;
  2160. ha->device_type |= DT_IIDMA;
  2161. ha->device_type |= DT_T10_PI;
  2162. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2163. break;
  2164. case PCI_DEVICE_ID_QLOGIC_ISP8031:
  2165. ha->isp_type |= DT_ISP8031;
  2166. ha->device_type |= DT_ZIO_SUPPORTED;
  2167. ha->device_type |= DT_FWI2;
  2168. ha->device_type |= DT_IIDMA;
  2169. ha->device_type |= DT_T10_PI;
  2170. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2171. break;
  2172. case PCI_DEVICE_ID_QLOGIC_ISPF001:
  2173. ha->isp_type |= DT_ISPFX00;
  2174. break;
  2175. case PCI_DEVICE_ID_QLOGIC_ISP2071:
  2176. ha->isp_type |= DT_ISP2071;
  2177. ha->device_type |= DT_ZIO_SUPPORTED;
  2178. ha->device_type |= DT_FWI2;
  2179. ha->device_type |= DT_IIDMA;
  2180. ha->device_type |= DT_T10_PI;
  2181. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2182. break;
  2183. case PCI_DEVICE_ID_QLOGIC_ISP2271:
  2184. ha->isp_type |= DT_ISP2271;
  2185. ha->device_type |= DT_ZIO_SUPPORTED;
  2186. ha->device_type |= DT_FWI2;
  2187. ha->device_type |= DT_IIDMA;
  2188. ha->device_type |= DT_T10_PI;
  2189. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2190. break;
  2191. case PCI_DEVICE_ID_QLOGIC_ISP2261:
  2192. ha->isp_type |= DT_ISP2261;
  2193. ha->device_type |= DT_ZIO_SUPPORTED;
  2194. ha->device_type |= DT_FWI2;
  2195. ha->device_type |= DT_IIDMA;
  2196. ha->device_type |= DT_T10_PI;
  2197. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2198. break;
  2199. }
  2200. if (IS_QLA82XX(ha))
  2201. ha->port_no = ha->portnum & 1;
  2202. else {
  2203. /* Get adapter physical port no from interrupt pin register. */
  2204. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  2205. if (IS_QLA27XX(ha))
  2206. ha->port_no--;
  2207. else
  2208. ha->port_no = !(ha->port_no & 1);
  2209. }
  2210. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
  2211. "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
  2212. ha->device_type, ha->port_no, ha->fw_srisc_address);
  2213. }
  2214. static void
  2215. qla2xxx_scan_start(struct Scsi_Host *shost)
  2216. {
  2217. scsi_qla_host_t *vha = shost_priv(shost);
  2218. if (vha->hw->flags.running_gold_fw)
  2219. return;
  2220. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2221. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2222. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2223. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  2224. }
  2225. static int
  2226. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2227. {
  2228. scsi_qla_host_t *vha = shost_priv(shost);
  2229. if (test_bit(UNLOADING, &vha->dpc_flags))
  2230. return 1;
  2231. if (!vha->host)
  2232. return 1;
  2233. if (time > vha->hw->loop_reset_delay * HZ)
  2234. return 1;
  2235. return atomic_read(&vha->loop_state) == LOOP_READY;
  2236. }
  2237. /*
  2238. * PCI driver interface
  2239. */
  2240. static int
  2241. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2242. {
  2243. int ret = -ENODEV;
  2244. struct Scsi_Host *host;
  2245. scsi_qla_host_t *base_vha = NULL;
  2246. struct qla_hw_data *ha;
  2247. char pci_info[30];
  2248. char fw_str[30], wq_name[30];
  2249. struct scsi_host_template *sht;
  2250. int bars, mem_only = 0;
  2251. uint16_t req_length = 0, rsp_length = 0;
  2252. struct req_que *req = NULL;
  2253. struct rsp_que *rsp = NULL;
  2254. int i;
  2255. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  2256. sht = &qla2xxx_driver_template;
  2257. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  2258. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  2259. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  2260. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  2261. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  2262. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  2263. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
  2264. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
  2265. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
  2266. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
  2267. pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
  2268. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
  2269. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
  2270. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
  2271. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
  2272. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2273. mem_only = 1;
  2274. ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
  2275. "Mem only adapter.\n");
  2276. }
  2277. ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
  2278. "Bars=%d.\n", bars);
  2279. if (mem_only) {
  2280. if (pci_enable_device_mem(pdev))
  2281. goto probe_out;
  2282. } else {
  2283. if (pci_enable_device(pdev))
  2284. goto probe_out;
  2285. }
  2286. /* This may fail but that's ok */
  2287. pci_enable_pcie_error_reporting(pdev);
  2288. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  2289. if (!ha) {
  2290. ql_log_pci(ql_log_fatal, pdev, 0x0009,
  2291. "Unable to allocate memory for ha.\n");
  2292. goto probe_out;
  2293. }
  2294. ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
  2295. "Memory allocated for ha=%p.\n", ha);
  2296. ha->pdev = pdev;
  2297. ha->tgt.enable_class_2 = ql2xenableclass2;
  2298. INIT_LIST_HEAD(&ha->tgt.q_full_list);
  2299. spin_lock_init(&ha->tgt.q_full_lock);
  2300. spin_lock_init(&ha->tgt.sess_lock);
  2301. spin_lock_init(&ha->tgt.atio_lock);
  2302. /* Clear our data area */
  2303. ha->bars = bars;
  2304. ha->mem_only = mem_only;
  2305. spin_lock_init(&ha->hardware_lock);
  2306. spin_lock_init(&ha->vport_slock);
  2307. mutex_init(&ha->selflogin_lock);
  2308. mutex_init(&ha->optrom_mutex);
  2309. /* Set ISP-type information. */
  2310. qla2x00_set_isp_flags(ha);
  2311. /* Set EEH reset type to fundamental if required by hba */
  2312. if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
  2313. IS_QLA83XX(ha) || IS_QLA27XX(ha))
  2314. pdev->needs_freset = 1;
  2315. ha->prev_topology = 0;
  2316. ha->init_cb_size = sizeof(init_cb_t);
  2317. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  2318. ha->optrom_size = OPTROM_SIZE_2300;
  2319. /* Assign ISP specific operations. */
  2320. if (IS_QLA2100(ha)) {
  2321. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2322. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  2323. req_length = REQUEST_ENTRY_CNT_2100;
  2324. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2325. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2326. ha->gid_list_info_size = 4;
  2327. ha->flash_conf_off = ~0;
  2328. ha->flash_data_off = ~0;
  2329. ha->nvram_conf_off = ~0;
  2330. ha->nvram_data_off = ~0;
  2331. ha->isp_ops = &qla2100_isp_ops;
  2332. } else if (IS_QLA2200(ha)) {
  2333. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2334. ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
  2335. req_length = REQUEST_ENTRY_CNT_2200;
  2336. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2337. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2338. ha->gid_list_info_size = 4;
  2339. ha->flash_conf_off = ~0;
  2340. ha->flash_data_off = ~0;
  2341. ha->nvram_conf_off = ~0;
  2342. ha->nvram_data_off = ~0;
  2343. ha->isp_ops = &qla2100_isp_ops;
  2344. } else if (IS_QLA23XX(ha)) {
  2345. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2346. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2347. req_length = REQUEST_ENTRY_CNT_2200;
  2348. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2349. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2350. ha->gid_list_info_size = 6;
  2351. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  2352. ha->optrom_size = OPTROM_SIZE_2322;
  2353. ha->flash_conf_off = ~0;
  2354. ha->flash_data_off = ~0;
  2355. ha->nvram_conf_off = ~0;
  2356. ha->nvram_data_off = ~0;
  2357. ha->isp_ops = &qla2300_isp_ops;
  2358. } else if (IS_QLA24XX_TYPE(ha)) {
  2359. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2360. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2361. req_length = REQUEST_ENTRY_CNT_24XX;
  2362. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2363. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2364. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2365. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2366. ha->gid_list_info_size = 8;
  2367. ha->optrom_size = OPTROM_SIZE_24XX;
  2368. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  2369. ha->isp_ops = &qla24xx_isp_ops;
  2370. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2371. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2372. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2373. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2374. } else if (IS_QLA25XX(ha)) {
  2375. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2376. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2377. req_length = REQUEST_ENTRY_CNT_24XX;
  2378. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2379. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2380. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2381. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2382. ha->gid_list_info_size = 8;
  2383. ha->optrom_size = OPTROM_SIZE_25XX;
  2384. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2385. ha->isp_ops = &qla25xx_isp_ops;
  2386. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2387. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2388. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2389. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2390. } else if (IS_QLA81XX(ha)) {
  2391. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2392. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2393. req_length = REQUEST_ENTRY_CNT_24XX;
  2394. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2395. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2396. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2397. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2398. ha->gid_list_info_size = 8;
  2399. ha->optrom_size = OPTROM_SIZE_81XX;
  2400. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2401. ha->isp_ops = &qla81xx_isp_ops;
  2402. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2403. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2404. ha->nvram_conf_off = ~0;
  2405. ha->nvram_data_off = ~0;
  2406. } else if (IS_QLA82XX(ha)) {
  2407. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2408. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2409. req_length = REQUEST_ENTRY_CNT_82XX;
  2410. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2411. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2412. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2413. ha->gid_list_info_size = 8;
  2414. ha->optrom_size = OPTROM_SIZE_82XX;
  2415. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2416. ha->isp_ops = &qla82xx_isp_ops;
  2417. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2418. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2419. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2420. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2421. } else if (IS_QLA8044(ha)) {
  2422. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2423. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2424. req_length = REQUEST_ENTRY_CNT_82XX;
  2425. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2426. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2427. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2428. ha->gid_list_info_size = 8;
  2429. ha->optrom_size = OPTROM_SIZE_83XX;
  2430. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2431. ha->isp_ops = &qla8044_isp_ops;
  2432. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2433. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2434. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2435. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2436. } else if (IS_QLA83XX(ha)) {
  2437. ha->portnum = PCI_FUNC(ha->pdev->devfn);
  2438. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2439. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2440. req_length = REQUEST_ENTRY_CNT_83XX;
  2441. rsp_length = RESPONSE_ENTRY_CNT_83XX;
  2442. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2443. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2444. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2445. ha->gid_list_info_size = 8;
  2446. ha->optrom_size = OPTROM_SIZE_83XX;
  2447. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2448. ha->isp_ops = &qla83xx_isp_ops;
  2449. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2450. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2451. ha->nvram_conf_off = ~0;
  2452. ha->nvram_data_off = ~0;
  2453. } else if (IS_QLAFX00(ha)) {
  2454. ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
  2455. ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
  2456. ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
  2457. req_length = REQUEST_ENTRY_CNT_FX00;
  2458. rsp_length = RESPONSE_ENTRY_CNT_FX00;
  2459. ha->isp_ops = &qlafx00_isp_ops;
  2460. ha->port_down_retry_count = 30; /* default value */
  2461. ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
  2462. ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
  2463. ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
  2464. ha->mr.fw_hbt_en = 1;
  2465. ha->mr.host_info_resend = false;
  2466. ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
  2467. } else if (IS_QLA27XX(ha)) {
  2468. ha->portnum = PCI_FUNC(ha->pdev->devfn);
  2469. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2470. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2471. req_length = REQUEST_ENTRY_CNT_83XX;
  2472. rsp_length = RESPONSE_ENTRY_CNT_83XX;
  2473. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2474. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2475. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2476. ha->gid_list_info_size = 8;
  2477. ha->optrom_size = OPTROM_SIZE_83XX;
  2478. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2479. ha->isp_ops = &qla27xx_isp_ops;
  2480. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2481. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2482. ha->nvram_conf_off = ~0;
  2483. ha->nvram_data_off = ~0;
  2484. }
  2485. ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
  2486. "mbx_count=%d, req_length=%d, "
  2487. "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
  2488. "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
  2489. "max_fibre_devices=%d.\n",
  2490. ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
  2491. ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
  2492. ha->nvram_npiv_size, ha->max_fibre_devices);
  2493. ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
  2494. "isp_ops=%p, flash_conf_off=%d, "
  2495. "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
  2496. ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
  2497. ha->nvram_conf_off, ha->nvram_data_off);
  2498. /* Configure PCI I/O space */
  2499. ret = ha->isp_ops->iospace_config(ha);
  2500. if (ret)
  2501. goto iospace_config_failed;
  2502. ql_log_pci(ql_log_info, pdev, 0x001d,
  2503. "Found an ISP%04X irq %d iobase 0x%p.\n",
  2504. pdev->device, pdev->irq, ha->iobase);
  2505. mutex_init(&ha->vport_lock);
  2506. mutex_init(&ha->mq_lock);
  2507. init_completion(&ha->mbx_cmd_comp);
  2508. complete(&ha->mbx_cmd_comp);
  2509. init_completion(&ha->mbx_intr_comp);
  2510. init_completion(&ha->dcbx_comp);
  2511. init_completion(&ha->lb_portup_comp);
  2512. set_bit(0, (unsigned long *) ha->vp_idx_map);
  2513. qla2x00_config_dma_addressing(ha);
  2514. ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
  2515. "64 Bit addressing is %s.\n",
  2516. ha->flags.enable_64bit_addressing ? "enable" :
  2517. "disable");
  2518. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  2519. if (ret) {
  2520. ql_log_pci(ql_log_fatal, pdev, 0x0031,
  2521. "Failed to allocate memory for adapter, aborting.\n");
  2522. goto probe_hw_failed;
  2523. }
  2524. req->max_q_depth = MAX_Q_DEPTH;
  2525. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  2526. req->max_q_depth = ql2xmaxqdepth;
  2527. base_vha = qla2x00_create_host(sht, ha);
  2528. if (!base_vha) {
  2529. ret = -ENOMEM;
  2530. qla2x00_mem_free(ha);
  2531. qla2x00_free_req_que(ha, req);
  2532. qla2x00_free_rsp_que(ha, rsp);
  2533. goto probe_hw_failed;
  2534. }
  2535. pci_set_drvdata(pdev, base_vha);
  2536. set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
  2537. host = base_vha->host;
  2538. base_vha->req = req;
  2539. if (IS_QLA2XXX_MIDTYPE(ha))
  2540. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  2541. else
  2542. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  2543. base_vha->vp_idx;
  2544. /* Setup fcport template structure. */
  2545. ha->mr.fcport.vha = base_vha;
  2546. ha->mr.fcport.port_type = FCT_UNKNOWN;
  2547. ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
  2548. qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
  2549. ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
  2550. ha->mr.fcport.scan_state = 1;
  2551. /* Set the SG table size based on ISP type */
  2552. if (!IS_FWI2_CAPABLE(ha)) {
  2553. if (IS_QLA2100(ha))
  2554. host->sg_tablesize = 32;
  2555. } else {
  2556. if (!IS_QLA82XX(ha))
  2557. host->sg_tablesize = QLA_SG_ALL;
  2558. }
  2559. host->max_id = ha->max_fibre_devices;
  2560. host->cmd_per_lun = 3;
  2561. host->unique_id = host->host_no;
  2562. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
  2563. host->max_cmd_len = 32;
  2564. else
  2565. host->max_cmd_len = MAX_CMDSZ;
  2566. host->max_channel = MAX_BUSES - 1;
  2567. /* Older HBAs support only 16-bit LUNs */
  2568. if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
  2569. ql2xmaxlun > 0xffff)
  2570. host->max_lun = 0xffff;
  2571. else
  2572. host->max_lun = ql2xmaxlun;
  2573. host->transportt = qla2xxx_transport_template;
  2574. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  2575. ql_dbg(ql_dbg_init, base_vha, 0x0033,
  2576. "max_id=%d this_id=%d "
  2577. "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
  2578. "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
  2579. host->this_id, host->cmd_per_lun, host->unique_id,
  2580. host->max_cmd_len, host->max_channel, host->max_lun,
  2581. host->transportt, sht->vendor_id);
  2582. /* Set up the irqs */
  2583. ret = qla2x00_request_irqs(ha, rsp);
  2584. if (ret)
  2585. goto probe_init_failed;
  2586. /* Alloc arrays of request and response ring ptrs */
  2587. if (!qla2x00_alloc_queues(ha, req, rsp)) {
  2588. ql_log(ql_log_fatal, base_vha, 0x003d,
  2589. "Failed to allocate memory for queue pointers..."
  2590. "aborting.\n");
  2591. goto probe_init_failed;
  2592. }
  2593. if (ha->mqenable && shost_use_blk_mq(host)) {
  2594. /* number of hardware queues supported by blk/scsi-mq*/
  2595. host->nr_hw_queues = ha->max_qpairs;
  2596. ql_dbg(ql_dbg_init, base_vha, 0x0192,
  2597. "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
  2598. } else
  2599. ql_dbg(ql_dbg_init, base_vha, 0x0193,
  2600. "blk/scsi-mq disabled.\n");
  2601. qlt_probe_one_stage1(base_vha, ha);
  2602. pci_save_state(pdev);
  2603. /* Assign back pointers */
  2604. rsp->req = req;
  2605. req->rsp = rsp;
  2606. if (IS_QLAFX00(ha)) {
  2607. ha->rsp_q_map[0] = rsp;
  2608. ha->req_q_map[0] = req;
  2609. set_bit(0, ha->req_qid_map);
  2610. set_bit(0, ha->rsp_qid_map);
  2611. }
  2612. /* FWI2-capable only. */
  2613. req->req_q_in = &ha->iobase->isp24.req_q_in;
  2614. req->req_q_out = &ha->iobase->isp24.req_q_out;
  2615. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  2616. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  2617. if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  2618. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  2619. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  2620. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  2621. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  2622. }
  2623. if (IS_QLAFX00(ha)) {
  2624. req->req_q_in = &ha->iobase->ispfx00.req_q_in;
  2625. req->req_q_out = &ha->iobase->ispfx00.req_q_out;
  2626. rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
  2627. rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
  2628. }
  2629. if (IS_P3P_TYPE(ha)) {
  2630. req->req_q_out = &ha->iobase->isp82.req_q_out[0];
  2631. rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
  2632. rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
  2633. }
  2634. ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
  2635. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2636. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2637. ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
  2638. "req->req_q_in=%p req->req_q_out=%p "
  2639. "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2640. req->req_q_in, req->req_q_out,
  2641. rsp->rsp_q_in, rsp->rsp_q_out);
  2642. ql_dbg(ql_dbg_init, base_vha, 0x003e,
  2643. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2644. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2645. ql_dbg(ql_dbg_init, base_vha, 0x003f,
  2646. "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2647. req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
  2648. if (ha->isp_ops->initialize_adapter(base_vha)) {
  2649. ql_log(ql_log_fatal, base_vha, 0x00d6,
  2650. "Failed to initialize adapter - Adapter flags %x.\n",
  2651. base_vha->device_flags);
  2652. if (IS_QLA82XX(ha)) {
  2653. qla82xx_idc_lock(ha);
  2654. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2655. QLA8XXX_DEV_FAILED);
  2656. qla82xx_idc_unlock(ha);
  2657. ql_log(ql_log_fatal, base_vha, 0x00d7,
  2658. "HW State: FAILED.\n");
  2659. } else if (IS_QLA8044(ha)) {
  2660. qla8044_idc_lock(ha);
  2661. qla8044_wr_direct(base_vha,
  2662. QLA8044_CRB_DEV_STATE_INDEX,
  2663. QLA8XXX_DEV_FAILED);
  2664. qla8044_idc_unlock(ha);
  2665. ql_log(ql_log_fatal, base_vha, 0x0150,
  2666. "HW State: FAILED.\n");
  2667. }
  2668. ret = -ENODEV;
  2669. goto probe_failed;
  2670. }
  2671. if (IS_QLAFX00(ha))
  2672. host->can_queue = QLAFX00_MAX_CANQUEUE;
  2673. else
  2674. host->can_queue = req->num_outstanding_cmds - 10;
  2675. ql_dbg(ql_dbg_init, base_vha, 0x0032,
  2676. "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
  2677. host->can_queue, base_vha->req,
  2678. base_vha->mgmt_svr_loop_id, host->sg_tablesize);
  2679. if (ha->mqenable && qla_ini_mode_enabled(base_vha)) {
  2680. ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
  2681. /* Create start of day qpairs for Block MQ */
  2682. if (shost_use_blk_mq(host)) {
  2683. for (i = 0; i < ha->max_qpairs; i++)
  2684. qla2xxx_create_qpair(base_vha, 5, 0);
  2685. }
  2686. }
  2687. if (ha->flags.running_gold_fw)
  2688. goto skip_dpc;
  2689. /*
  2690. * Startup the kernel thread for this host adapter
  2691. */
  2692. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  2693. "%s_dpc", base_vha->host_str);
  2694. if (IS_ERR(ha->dpc_thread)) {
  2695. ql_log(ql_log_fatal, base_vha, 0x00ed,
  2696. "Failed to start DPC thread.\n");
  2697. ret = PTR_ERR(ha->dpc_thread);
  2698. goto probe_failed;
  2699. }
  2700. ql_dbg(ql_dbg_init, base_vha, 0x00ee,
  2701. "DPC thread started successfully.\n");
  2702. /*
  2703. * If we're not coming up in initiator mode, we might sit for
  2704. * a while without waking up the dpc thread, which leads to a
  2705. * stuck process warning. So just kick the dpc once here and
  2706. * let the kthread start (and go back to sleep in qla2x00_do_dpc).
  2707. */
  2708. qla2xxx_wake_dpc(base_vha);
  2709. INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
  2710. if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
  2711. sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
  2712. ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
  2713. INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
  2714. sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
  2715. ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
  2716. INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
  2717. INIT_WORK(&ha->idc_state_handler,
  2718. qla83xx_idc_state_handler_work);
  2719. INIT_WORK(&ha->nic_core_unrecoverable,
  2720. qla83xx_nic_core_unrecoverable_work);
  2721. }
  2722. skip_dpc:
  2723. list_add_tail(&base_vha->list, &ha->vp_list);
  2724. base_vha->host->irq = ha->pdev->irq;
  2725. /* Initialized the timer */
  2726. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  2727. ql_dbg(ql_dbg_init, base_vha, 0x00ef,
  2728. "Started qla2x00_timer with "
  2729. "interval=%d.\n", WATCH_INTERVAL);
  2730. ql_dbg(ql_dbg_init, base_vha, 0x00f0,
  2731. "Detected hba at address=%p.\n",
  2732. ha);
  2733. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  2734. if (ha->fw_attributes & BIT_4) {
  2735. int prot = 0, guard;
  2736. base_vha->flags.difdix_supported = 1;
  2737. ql_dbg(ql_dbg_init, base_vha, 0x00f1,
  2738. "Registering for DIF/DIX type 1 and 3 protection.\n");
  2739. if (ql2xenabledif == 1)
  2740. prot = SHOST_DIX_TYPE0_PROTECTION;
  2741. scsi_host_set_prot(host,
  2742. prot | SHOST_DIF_TYPE1_PROTECTION
  2743. | SHOST_DIF_TYPE2_PROTECTION
  2744. | SHOST_DIF_TYPE3_PROTECTION
  2745. | SHOST_DIX_TYPE1_PROTECTION
  2746. | SHOST_DIX_TYPE2_PROTECTION
  2747. | SHOST_DIX_TYPE3_PROTECTION);
  2748. guard = SHOST_DIX_GUARD_CRC;
  2749. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  2750. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  2751. guard |= SHOST_DIX_GUARD_IP;
  2752. scsi_host_set_guard(host, guard);
  2753. } else
  2754. base_vha->flags.difdix_supported = 0;
  2755. }
  2756. ha->isp_ops->enable_intrs(ha);
  2757. if (IS_QLAFX00(ha)) {
  2758. ret = qlafx00_fx_disc(base_vha,
  2759. &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
  2760. host->sg_tablesize = (ha->mr.extended_io_enabled) ?
  2761. QLA_SG_ALL : 128;
  2762. }
  2763. ret = scsi_add_host(host, &pdev->dev);
  2764. if (ret)
  2765. goto probe_failed;
  2766. base_vha->flags.init_done = 1;
  2767. base_vha->flags.online = 1;
  2768. ha->prev_minidump_failed = 0;
  2769. ql_dbg(ql_dbg_init, base_vha, 0x00f2,
  2770. "Init done and hba is online.\n");
  2771. if (qla_ini_mode_enabled(base_vha))
  2772. scsi_scan_host(host);
  2773. else
  2774. ql_dbg(ql_dbg_init, base_vha, 0x0122,
  2775. "skipping scsi_scan_host() for non-initiator port\n");
  2776. qla2x00_alloc_sysfs_attr(base_vha);
  2777. if (IS_QLAFX00(ha)) {
  2778. ret = qlafx00_fx_disc(base_vha,
  2779. &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
  2780. /* Register system information */
  2781. ret = qlafx00_fx_disc(base_vha,
  2782. &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
  2783. }
  2784. qla2x00_init_host_attr(base_vha);
  2785. qla2x00_dfs_setup(base_vha);
  2786. ql_log(ql_log_info, base_vha, 0x00fb,
  2787. "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
  2788. ql_log(ql_log_info, base_vha, 0x00fc,
  2789. "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
  2790. pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
  2791. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
  2792. base_vha->host_no,
  2793. ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
  2794. qlt_add_target(ha, base_vha);
  2795. clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
  2796. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  2797. return -ENODEV;
  2798. return 0;
  2799. probe_init_failed:
  2800. qla2x00_free_req_que(ha, req);
  2801. ha->req_q_map[0] = NULL;
  2802. clear_bit(0, ha->req_qid_map);
  2803. qla2x00_free_rsp_que(ha, rsp);
  2804. ha->rsp_q_map[0] = NULL;
  2805. clear_bit(0, ha->rsp_qid_map);
  2806. ha->max_req_queues = ha->max_rsp_queues = 0;
  2807. probe_failed:
  2808. if (base_vha->timer_active)
  2809. qla2x00_stop_timer(base_vha);
  2810. base_vha->flags.online = 0;
  2811. if (ha->dpc_thread) {
  2812. struct task_struct *t = ha->dpc_thread;
  2813. ha->dpc_thread = NULL;
  2814. kthread_stop(t);
  2815. }
  2816. qla2x00_free_device(base_vha);
  2817. scsi_host_put(base_vha->host);
  2818. probe_hw_failed:
  2819. qla2x00_clear_drv_active(ha);
  2820. iospace_config_failed:
  2821. if (IS_P3P_TYPE(ha)) {
  2822. if (!ha->nx_pcibase)
  2823. iounmap((device_reg_t *)ha->nx_pcibase);
  2824. if (!ql2xdbwr)
  2825. iounmap((device_reg_t *)ha->nxdb_wr_ptr);
  2826. } else {
  2827. if (ha->iobase)
  2828. iounmap(ha->iobase);
  2829. if (ha->cregbase)
  2830. iounmap(ha->cregbase);
  2831. }
  2832. pci_release_selected_regions(ha->pdev, ha->bars);
  2833. kfree(ha);
  2834. ha = NULL;
  2835. probe_out:
  2836. pci_disable_device(pdev);
  2837. return ret;
  2838. }
  2839. static void
  2840. qla2x00_shutdown(struct pci_dev *pdev)
  2841. {
  2842. scsi_qla_host_t *vha;
  2843. struct qla_hw_data *ha;
  2844. if (!atomic_read(&pdev->enable_cnt))
  2845. return;
  2846. vha = pci_get_drvdata(pdev);
  2847. ha = vha->hw;
  2848. /* Notify ISPFX00 firmware */
  2849. if (IS_QLAFX00(ha))
  2850. qlafx00_driver_shutdown(vha, 20);
  2851. /* Turn-off FCE trace */
  2852. if (ha->flags.fce_enabled) {
  2853. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2854. ha->flags.fce_enabled = 0;
  2855. }
  2856. /* Turn-off EFT trace */
  2857. if (ha->eft)
  2858. qla2x00_disable_eft_trace(vha);
  2859. /* Stop currently executing firmware. */
  2860. qla2x00_try_to_stop_firmware(vha);
  2861. /* Turn adapter off line */
  2862. vha->flags.online = 0;
  2863. /* turn-off interrupts on the card */
  2864. if (ha->interrupts_on) {
  2865. vha->flags.init_done = 0;
  2866. ha->isp_ops->disable_intrs(ha);
  2867. }
  2868. qla2x00_free_irqs(vha);
  2869. qla2x00_free_fw_dump(ha);
  2870. pci_disable_pcie_error_reporting(pdev);
  2871. pci_disable_device(pdev);
  2872. }
  2873. /* Deletes all the virtual ports for a given ha */
  2874. static void
  2875. qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
  2876. {
  2877. scsi_qla_host_t *vha;
  2878. unsigned long flags;
  2879. mutex_lock(&ha->vport_lock);
  2880. while (ha->cur_vport_count) {
  2881. spin_lock_irqsave(&ha->vport_slock, flags);
  2882. BUG_ON(base_vha->list.next == &ha->vp_list);
  2883. /* This assumes first entry in ha->vp_list is always base vha */
  2884. vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
  2885. scsi_host_get(vha->host);
  2886. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2887. mutex_unlock(&ha->vport_lock);
  2888. fc_vport_terminate(vha->fc_vport);
  2889. scsi_host_put(vha->host);
  2890. mutex_lock(&ha->vport_lock);
  2891. }
  2892. mutex_unlock(&ha->vport_lock);
  2893. }
  2894. /* Stops all deferred work threads */
  2895. static void
  2896. qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
  2897. {
  2898. /* Cancel all work and destroy DPC workqueues */
  2899. if (ha->dpc_lp_wq) {
  2900. cancel_work_sync(&ha->idc_aen);
  2901. destroy_workqueue(ha->dpc_lp_wq);
  2902. ha->dpc_lp_wq = NULL;
  2903. }
  2904. if (ha->dpc_hp_wq) {
  2905. cancel_work_sync(&ha->nic_core_reset);
  2906. cancel_work_sync(&ha->idc_state_handler);
  2907. cancel_work_sync(&ha->nic_core_unrecoverable);
  2908. destroy_workqueue(ha->dpc_hp_wq);
  2909. ha->dpc_hp_wq = NULL;
  2910. }
  2911. /* Kill the kernel thread for this host */
  2912. if (ha->dpc_thread) {
  2913. struct task_struct *t = ha->dpc_thread;
  2914. /*
  2915. * qla2xxx_wake_dpc checks for ->dpc_thread
  2916. * so we need to zero it out.
  2917. */
  2918. ha->dpc_thread = NULL;
  2919. kthread_stop(t);
  2920. }
  2921. }
  2922. static void
  2923. qla2x00_unmap_iobases(struct qla_hw_data *ha)
  2924. {
  2925. if (IS_QLA82XX(ha)) {
  2926. iounmap((device_reg_t *)ha->nx_pcibase);
  2927. if (!ql2xdbwr)
  2928. iounmap((device_reg_t *)ha->nxdb_wr_ptr);
  2929. } else {
  2930. if (ha->iobase)
  2931. iounmap(ha->iobase);
  2932. if (ha->cregbase)
  2933. iounmap(ha->cregbase);
  2934. if (ha->mqiobase)
  2935. iounmap(ha->mqiobase);
  2936. if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
  2937. iounmap(ha->msixbase);
  2938. }
  2939. }
  2940. static void
  2941. qla2x00_clear_drv_active(struct qla_hw_data *ha)
  2942. {
  2943. if (IS_QLA8044(ha)) {
  2944. qla8044_idc_lock(ha);
  2945. qla8044_clear_drv_active(ha);
  2946. qla8044_idc_unlock(ha);
  2947. } else if (IS_QLA82XX(ha)) {
  2948. qla82xx_idc_lock(ha);
  2949. qla82xx_clear_drv_active(ha);
  2950. qla82xx_idc_unlock(ha);
  2951. }
  2952. }
  2953. static void
  2954. qla2x00_remove_one(struct pci_dev *pdev)
  2955. {
  2956. scsi_qla_host_t *base_vha;
  2957. struct qla_hw_data *ha;
  2958. base_vha = pci_get_drvdata(pdev);
  2959. ha = base_vha->hw;
  2960. /* Indicate device removal to prevent future board_disable and wait
  2961. * until any pending board_disable has completed. */
  2962. set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
  2963. cancel_work_sync(&ha->board_disable);
  2964. /*
  2965. * If the PCI device is disabled then there was a PCI-disconnect and
  2966. * qla2x00_disable_board_on_pci_error has taken care of most of the
  2967. * resources.
  2968. */
  2969. if (!atomic_read(&pdev->enable_cnt)) {
  2970. scsi_host_put(base_vha->host);
  2971. kfree(ha);
  2972. pci_set_drvdata(pdev, NULL);
  2973. return;
  2974. }
  2975. qla2x00_wait_for_hba_ready(base_vha);
  2976. /* if UNLOAD flag is already set, then continue unload,
  2977. * where it was set first.
  2978. */
  2979. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  2980. return;
  2981. set_bit(UNLOADING, &base_vha->dpc_flags);
  2982. if (IS_QLAFX00(ha))
  2983. qlafx00_driver_shutdown(base_vha, 20);
  2984. qla2x00_delete_all_vps(ha, base_vha);
  2985. if (IS_QLA8031(ha)) {
  2986. ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
  2987. "Clearing fcoe driver presence.\n");
  2988. if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
  2989. ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
  2990. "Error while clearing DRV-Presence.\n");
  2991. }
  2992. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2993. qla2x00_dfs_remove(base_vha);
  2994. qla84xx_put_chip(base_vha);
  2995. /* Laser should be disabled only for ISP2031 */
  2996. if (IS_QLA2031(ha))
  2997. qla83xx_disable_laser(base_vha);
  2998. /* Disable timer */
  2999. if (base_vha->timer_active)
  3000. qla2x00_stop_timer(base_vha);
  3001. base_vha->flags.online = 0;
  3002. /* free DMA memory */
  3003. if (ha->exlogin_buf)
  3004. qla2x00_free_exlogin_buffer(ha);
  3005. /* free DMA memory */
  3006. if (ha->exchoffld_buf)
  3007. qla2x00_free_exchoffld_buffer(ha);
  3008. qla2x00_destroy_deferred_work(ha);
  3009. qlt_remove_target(ha, base_vha);
  3010. qla2x00_free_sysfs_attr(base_vha, true);
  3011. fc_remove_host(base_vha->host);
  3012. scsi_remove_host(base_vha->host);
  3013. qla2x00_free_device(base_vha);
  3014. qla2x00_clear_drv_active(ha);
  3015. scsi_host_put(base_vha->host);
  3016. qla2x00_unmap_iobases(ha);
  3017. pci_release_selected_regions(ha->pdev, ha->bars);
  3018. kfree(ha);
  3019. ha = NULL;
  3020. pci_disable_pcie_error_reporting(pdev);
  3021. pci_disable_device(pdev);
  3022. }
  3023. static void
  3024. qla2x00_free_device(scsi_qla_host_t *vha)
  3025. {
  3026. struct qla_hw_data *ha = vha->hw;
  3027. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  3028. /* Disable timer */
  3029. if (vha->timer_active)
  3030. qla2x00_stop_timer(vha);
  3031. qla25xx_delete_queues(vha);
  3032. if (ha->flags.fce_enabled)
  3033. qla2x00_disable_fce_trace(vha, NULL, NULL);
  3034. if (ha->eft)
  3035. qla2x00_disable_eft_trace(vha);
  3036. /* Stop currently executing firmware. */
  3037. qla2x00_try_to_stop_firmware(vha);
  3038. vha->flags.online = 0;
  3039. /* turn-off interrupts on the card */
  3040. if (ha->interrupts_on) {
  3041. vha->flags.init_done = 0;
  3042. ha->isp_ops->disable_intrs(ha);
  3043. }
  3044. qla2x00_free_fcports(vha);
  3045. qla2x00_free_irqs(vha);
  3046. /* Flush the work queue and remove it */
  3047. if (ha->wq) {
  3048. flush_workqueue(ha->wq);
  3049. destroy_workqueue(ha->wq);
  3050. ha->wq = NULL;
  3051. }
  3052. qla2x00_mem_free(ha);
  3053. qla82xx_md_free(vha);
  3054. qla2x00_free_queues(ha);
  3055. }
  3056. void qla2x00_free_fcports(struct scsi_qla_host *vha)
  3057. {
  3058. fc_port_t *fcport, *tfcport;
  3059. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  3060. list_del(&fcport->list);
  3061. qla2x00_clear_loop_id(fcport);
  3062. kfree(fcport);
  3063. fcport = NULL;
  3064. }
  3065. }
  3066. static inline void
  3067. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  3068. int defer)
  3069. {
  3070. struct fc_rport *rport;
  3071. scsi_qla_host_t *base_vha;
  3072. unsigned long flags;
  3073. if (!fcport->rport)
  3074. return;
  3075. rport = fcport->rport;
  3076. if (defer) {
  3077. base_vha = pci_get_drvdata(vha->hw->pdev);
  3078. spin_lock_irqsave(vha->host->host_lock, flags);
  3079. fcport->drport = rport;
  3080. spin_unlock_irqrestore(vha->host->host_lock, flags);
  3081. qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
  3082. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  3083. qla2xxx_wake_dpc(base_vha);
  3084. } else {
  3085. int now;
  3086. if (rport)
  3087. fc_remote_port_delete(rport);
  3088. qlt_do_generation_tick(vha, &now);
  3089. qlt_fc_port_deleted(vha, fcport, now);
  3090. }
  3091. }
  3092. /*
  3093. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  3094. *
  3095. * Input: ha = adapter block pointer. fcport = port structure pointer.
  3096. *
  3097. * Return: None.
  3098. *
  3099. * Context:
  3100. */
  3101. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  3102. int do_login, int defer)
  3103. {
  3104. if (IS_QLAFX00(vha->hw)) {
  3105. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  3106. qla2x00_schedule_rport_del(vha, fcport, defer);
  3107. return;
  3108. }
  3109. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  3110. vha->vp_idx == fcport->vha->vp_idx) {
  3111. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  3112. qla2x00_schedule_rport_del(vha, fcport, defer);
  3113. }
  3114. /*
  3115. * We may need to retry the login, so don't change the state of the
  3116. * port but do the retries.
  3117. */
  3118. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  3119. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  3120. if (!do_login)
  3121. return;
  3122. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  3123. if (fcport->login_retry == 0) {
  3124. fcport->login_retry = vha->hw->login_retry_count;
  3125. ql_dbg(ql_dbg_disc, vha, 0x2067,
  3126. "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
  3127. fcport->port_name, fcport->loop_id, fcport->login_retry);
  3128. }
  3129. }
  3130. /*
  3131. * qla2x00_mark_all_devices_lost
  3132. * Updates fcport state when device goes offline.
  3133. *
  3134. * Input:
  3135. * ha = adapter block pointer.
  3136. * fcport = port structure pointer.
  3137. *
  3138. * Return:
  3139. * None.
  3140. *
  3141. * Context:
  3142. */
  3143. void
  3144. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  3145. {
  3146. fc_port_t *fcport;
  3147. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3148. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
  3149. continue;
  3150. /*
  3151. * No point in marking the device as lost, if the device is
  3152. * already DEAD.
  3153. */
  3154. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  3155. continue;
  3156. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  3157. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  3158. if (defer)
  3159. qla2x00_schedule_rport_del(vha, fcport, defer);
  3160. else if (vha->vp_idx == fcport->vha->vp_idx)
  3161. qla2x00_schedule_rport_del(vha, fcport, defer);
  3162. }
  3163. }
  3164. }
  3165. /*
  3166. * qla2x00_mem_alloc
  3167. * Allocates adapter memory.
  3168. *
  3169. * Returns:
  3170. * 0 = success.
  3171. * !0 = failure.
  3172. */
  3173. static int
  3174. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  3175. struct req_que **req, struct rsp_que **rsp)
  3176. {
  3177. char name[16];
  3178. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  3179. &ha->init_cb_dma, GFP_KERNEL);
  3180. if (!ha->init_cb)
  3181. goto fail;
  3182. if (qlt_mem_alloc(ha) < 0)
  3183. goto fail_free_init_cb;
  3184. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
  3185. qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
  3186. if (!ha->gid_list)
  3187. goto fail_free_tgt_mem;
  3188. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  3189. if (!ha->srb_mempool)
  3190. goto fail_free_gid_list;
  3191. if (IS_P3P_TYPE(ha)) {
  3192. /* Allocate cache for CT6 Ctx. */
  3193. if (!ctx_cachep) {
  3194. ctx_cachep = kmem_cache_create("qla2xxx_ctx",
  3195. sizeof(struct ct6_dsd), 0,
  3196. SLAB_HWCACHE_ALIGN, NULL);
  3197. if (!ctx_cachep)
  3198. goto fail_free_gid_list;
  3199. }
  3200. ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
  3201. ctx_cachep);
  3202. if (!ha->ctx_mempool)
  3203. goto fail_free_srb_mempool;
  3204. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
  3205. "ctx_cachep=%p ctx_mempool=%p.\n",
  3206. ctx_cachep, ha->ctx_mempool);
  3207. }
  3208. /* Get memory for cached NVRAM */
  3209. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  3210. if (!ha->nvram)
  3211. goto fail_free_ctx_mempool;
  3212. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  3213. ha->pdev->device);
  3214. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  3215. DMA_POOL_SIZE, 8, 0);
  3216. if (!ha->s_dma_pool)
  3217. goto fail_free_nvram;
  3218. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
  3219. "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
  3220. ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
  3221. if (IS_P3P_TYPE(ha) || ql2xenabledif) {
  3222. ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  3223. DSD_LIST_DMA_POOL_SIZE, 8, 0);
  3224. if (!ha->dl_dma_pool) {
  3225. ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
  3226. "Failed to allocate memory for dl_dma_pool.\n");
  3227. goto fail_s_dma_pool;
  3228. }
  3229. ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  3230. FCP_CMND_DMA_POOL_SIZE, 8, 0);
  3231. if (!ha->fcp_cmnd_dma_pool) {
  3232. ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
  3233. "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
  3234. goto fail_dl_dma_pool;
  3235. }
  3236. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
  3237. "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
  3238. ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
  3239. }
  3240. /* Allocate memory for SNS commands */
  3241. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  3242. /* Get consistent memory allocated for SNS commands */
  3243. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  3244. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  3245. if (!ha->sns_cmd)
  3246. goto fail_dma_pool;
  3247. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
  3248. "sns_cmd: %p.\n", ha->sns_cmd);
  3249. } else {
  3250. /* Get consistent memory allocated for MS IOCB */
  3251. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3252. &ha->ms_iocb_dma);
  3253. if (!ha->ms_iocb)
  3254. goto fail_dma_pool;
  3255. /* Get consistent memory allocated for CT SNS commands */
  3256. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  3257. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  3258. if (!ha->ct_sns)
  3259. goto fail_free_ms_iocb;
  3260. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
  3261. "ms_iocb=%p ct_sns=%p.\n",
  3262. ha->ms_iocb, ha->ct_sns);
  3263. }
  3264. /* Allocate memory for request ring */
  3265. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  3266. if (!*req) {
  3267. ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
  3268. "Failed to allocate memory for req.\n");
  3269. goto fail_req;
  3270. }
  3271. (*req)->length = req_len;
  3272. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3273. ((*req)->length + 1) * sizeof(request_t),
  3274. &(*req)->dma, GFP_KERNEL);
  3275. if (!(*req)->ring) {
  3276. ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
  3277. "Failed to allocate memory for req_ring.\n");
  3278. goto fail_req_ring;
  3279. }
  3280. /* Allocate memory for response ring */
  3281. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  3282. if (!*rsp) {
  3283. ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
  3284. "Failed to allocate memory for rsp.\n");
  3285. goto fail_rsp;
  3286. }
  3287. (*rsp)->hw = ha;
  3288. (*rsp)->length = rsp_len;
  3289. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3290. ((*rsp)->length + 1) * sizeof(response_t),
  3291. &(*rsp)->dma, GFP_KERNEL);
  3292. if (!(*rsp)->ring) {
  3293. ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
  3294. "Failed to allocate memory for rsp_ring.\n");
  3295. goto fail_rsp_ring;
  3296. }
  3297. (*req)->rsp = *rsp;
  3298. (*rsp)->req = *req;
  3299. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
  3300. "req=%p req->length=%d req->ring=%p rsp=%p "
  3301. "rsp->length=%d rsp->ring=%p.\n",
  3302. *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
  3303. (*rsp)->ring);
  3304. /* Allocate memory for NVRAM data for vports */
  3305. if (ha->nvram_npiv_size) {
  3306. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  3307. ha->nvram_npiv_size, GFP_KERNEL);
  3308. if (!ha->npiv_info) {
  3309. ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
  3310. "Failed to allocate memory for npiv_info.\n");
  3311. goto fail_npiv_info;
  3312. }
  3313. } else
  3314. ha->npiv_info = NULL;
  3315. /* Get consistent memory allocated for EX-INIT-CB. */
  3316. if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
  3317. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3318. &ha->ex_init_cb_dma);
  3319. if (!ha->ex_init_cb)
  3320. goto fail_ex_init_cb;
  3321. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
  3322. "ex_init_cb=%p.\n", ha->ex_init_cb);
  3323. }
  3324. INIT_LIST_HEAD(&ha->gbl_dsd_list);
  3325. /* Get consistent memory allocated for Async Port-Database. */
  3326. if (!IS_FWI2_CAPABLE(ha)) {
  3327. ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3328. &ha->async_pd_dma);
  3329. if (!ha->async_pd)
  3330. goto fail_async_pd;
  3331. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
  3332. "async_pd=%p.\n", ha->async_pd);
  3333. }
  3334. INIT_LIST_HEAD(&ha->vp_list);
  3335. /* Allocate memory for our loop_id bitmap */
  3336. ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
  3337. GFP_KERNEL);
  3338. if (!ha->loop_id_map)
  3339. goto fail_async_pd;
  3340. else {
  3341. qla2x00_set_reserved_loop_ids(ha);
  3342. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
  3343. "loop_id_map=%p.\n", ha->loop_id_map);
  3344. }
  3345. return 0;
  3346. fail_async_pd:
  3347. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  3348. fail_ex_init_cb:
  3349. kfree(ha->npiv_info);
  3350. fail_npiv_info:
  3351. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  3352. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  3353. (*rsp)->ring = NULL;
  3354. (*rsp)->dma = 0;
  3355. fail_rsp_ring:
  3356. kfree(*rsp);
  3357. fail_rsp:
  3358. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  3359. sizeof(request_t), (*req)->ring, (*req)->dma);
  3360. (*req)->ring = NULL;
  3361. (*req)->dma = 0;
  3362. fail_req_ring:
  3363. kfree(*req);
  3364. fail_req:
  3365. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3366. ha->ct_sns, ha->ct_sns_dma);
  3367. ha->ct_sns = NULL;
  3368. ha->ct_sns_dma = 0;
  3369. fail_free_ms_iocb:
  3370. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3371. ha->ms_iocb = NULL;
  3372. ha->ms_iocb_dma = 0;
  3373. fail_dma_pool:
  3374. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3375. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3376. ha->fcp_cmnd_dma_pool = NULL;
  3377. }
  3378. fail_dl_dma_pool:
  3379. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3380. dma_pool_destroy(ha->dl_dma_pool);
  3381. ha->dl_dma_pool = NULL;
  3382. }
  3383. fail_s_dma_pool:
  3384. dma_pool_destroy(ha->s_dma_pool);
  3385. ha->s_dma_pool = NULL;
  3386. fail_free_nvram:
  3387. kfree(ha->nvram);
  3388. ha->nvram = NULL;
  3389. fail_free_ctx_mempool:
  3390. mempool_destroy(ha->ctx_mempool);
  3391. ha->ctx_mempool = NULL;
  3392. fail_free_srb_mempool:
  3393. mempool_destroy(ha->srb_mempool);
  3394. ha->srb_mempool = NULL;
  3395. fail_free_gid_list:
  3396. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3397. ha->gid_list,
  3398. ha->gid_list_dma);
  3399. ha->gid_list = NULL;
  3400. ha->gid_list_dma = 0;
  3401. fail_free_tgt_mem:
  3402. qlt_mem_free(ha);
  3403. fail_free_init_cb:
  3404. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  3405. ha->init_cb_dma);
  3406. ha->init_cb = NULL;
  3407. ha->init_cb_dma = 0;
  3408. fail:
  3409. ql_log(ql_log_fatal, NULL, 0x0030,
  3410. "Memory allocation failure.\n");
  3411. return -ENOMEM;
  3412. }
  3413. int
  3414. qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
  3415. {
  3416. int rval;
  3417. uint16_t size, max_cnt, temp;
  3418. struct qla_hw_data *ha = vha->hw;
  3419. /* Return if we don't need to alloacate any extended logins */
  3420. if (!ql2xexlogins)
  3421. return QLA_SUCCESS;
  3422. ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
  3423. max_cnt = 0;
  3424. rval = qla_get_exlogin_status(vha, &size, &max_cnt);
  3425. if (rval != QLA_SUCCESS) {
  3426. ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
  3427. "Failed to get exlogin status.\n");
  3428. return rval;
  3429. }
  3430. temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
  3431. ha->exlogin_size = (size * temp);
  3432. ql_log(ql_log_info, vha, 0xd024,
  3433. "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
  3434. max_cnt, size, temp);
  3435. ql_log(ql_log_info, vha, 0xd025, "EXLOGIN: requested size=0x%x\n",
  3436. ha->exlogin_size);
  3437. /* Get consistent memory for extended logins */
  3438. ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
  3439. ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
  3440. if (!ha->exlogin_buf) {
  3441. ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
  3442. "Failed to allocate memory for exlogin_buf_dma.\n");
  3443. return -ENOMEM;
  3444. }
  3445. /* Now configure the dma buffer */
  3446. rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
  3447. if (rval) {
  3448. ql_log(ql_log_fatal, vha, 0x00cf,
  3449. "Setup extended login buffer ****FAILED****.\n");
  3450. qla2x00_free_exlogin_buffer(ha);
  3451. }
  3452. return rval;
  3453. }
  3454. /*
  3455. * qla2x00_free_exlogin_buffer
  3456. *
  3457. * Input:
  3458. * ha = adapter block pointer
  3459. */
  3460. void
  3461. qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
  3462. {
  3463. if (ha->exlogin_buf) {
  3464. dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
  3465. ha->exlogin_buf, ha->exlogin_buf_dma);
  3466. ha->exlogin_buf = NULL;
  3467. ha->exlogin_size = 0;
  3468. }
  3469. }
  3470. int
  3471. qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
  3472. {
  3473. int rval;
  3474. uint16_t size, max_cnt, temp;
  3475. struct qla_hw_data *ha = vha->hw;
  3476. /* Return if we don't need to alloacate any extended logins */
  3477. if (!ql2xexchoffld)
  3478. return QLA_SUCCESS;
  3479. ql_log(ql_log_info, vha, 0xd014,
  3480. "Exchange offload count: %d.\n", ql2xexlogins);
  3481. max_cnt = 0;
  3482. rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
  3483. if (rval != QLA_SUCCESS) {
  3484. ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
  3485. "Failed to get exlogin status.\n");
  3486. return rval;
  3487. }
  3488. temp = (ql2xexchoffld > max_cnt) ? max_cnt : ql2xexchoffld;
  3489. ha->exchoffld_size = (size * temp);
  3490. ql_log(ql_log_info, vha, 0xd016,
  3491. "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
  3492. max_cnt, size, temp);
  3493. ql_log(ql_log_info, vha, 0xd017,
  3494. "Exchange Buffers requested size = 0x%x\n", ha->exchoffld_size);
  3495. /* Get consistent memory for extended logins */
  3496. ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
  3497. ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
  3498. if (!ha->exchoffld_buf) {
  3499. ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
  3500. "Failed to allocate memory for exchoffld_buf_dma.\n");
  3501. return -ENOMEM;
  3502. }
  3503. /* Now configure the dma buffer */
  3504. rval = qla_set_exchoffld_mem_cfg(vha, ha->exchoffld_buf_dma);
  3505. if (rval) {
  3506. ql_log(ql_log_fatal, vha, 0xd02e,
  3507. "Setup exchange offload buffer ****FAILED****.\n");
  3508. qla2x00_free_exchoffld_buffer(ha);
  3509. }
  3510. return rval;
  3511. }
  3512. /*
  3513. * qla2x00_free_exchoffld_buffer
  3514. *
  3515. * Input:
  3516. * ha = adapter block pointer
  3517. */
  3518. void
  3519. qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
  3520. {
  3521. if (ha->exchoffld_buf) {
  3522. dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
  3523. ha->exchoffld_buf, ha->exchoffld_buf_dma);
  3524. ha->exchoffld_buf = NULL;
  3525. ha->exchoffld_size = 0;
  3526. }
  3527. }
  3528. /*
  3529. * qla2x00_free_fw_dump
  3530. * Frees fw dump stuff.
  3531. *
  3532. * Input:
  3533. * ha = adapter block pointer
  3534. */
  3535. static void
  3536. qla2x00_free_fw_dump(struct qla_hw_data *ha)
  3537. {
  3538. if (ha->fce)
  3539. dma_free_coherent(&ha->pdev->dev,
  3540. FCE_SIZE, ha->fce, ha->fce_dma);
  3541. if (ha->eft)
  3542. dma_free_coherent(&ha->pdev->dev,
  3543. EFT_SIZE, ha->eft, ha->eft_dma);
  3544. if (ha->fw_dump)
  3545. vfree(ha->fw_dump);
  3546. if (ha->fw_dump_template)
  3547. vfree(ha->fw_dump_template);
  3548. ha->fce = NULL;
  3549. ha->fce_dma = 0;
  3550. ha->eft = NULL;
  3551. ha->eft_dma = 0;
  3552. ha->fw_dumped = 0;
  3553. ha->fw_dump_cap_flags = 0;
  3554. ha->fw_dump_reading = 0;
  3555. ha->fw_dump = NULL;
  3556. ha->fw_dump_len = 0;
  3557. ha->fw_dump_template = NULL;
  3558. ha->fw_dump_template_len = 0;
  3559. }
  3560. /*
  3561. * qla2x00_mem_free
  3562. * Frees all adapter allocated memory.
  3563. *
  3564. * Input:
  3565. * ha = adapter block pointer.
  3566. */
  3567. static void
  3568. qla2x00_mem_free(struct qla_hw_data *ha)
  3569. {
  3570. qla2x00_free_fw_dump(ha);
  3571. if (ha->mctp_dump)
  3572. dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
  3573. ha->mctp_dump_dma);
  3574. if (ha->srb_mempool)
  3575. mempool_destroy(ha->srb_mempool);
  3576. if (ha->dcbx_tlv)
  3577. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  3578. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  3579. if (ha->xgmac_data)
  3580. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  3581. ha->xgmac_data, ha->xgmac_data_dma);
  3582. if (ha->sns_cmd)
  3583. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  3584. ha->sns_cmd, ha->sns_cmd_dma);
  3585. if (ha->ct_sns)
  3586. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3587. ha->ct_sns, ha->ct_sns_dma);
  3588. if (ha->sfp_data)
  3589. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  3590. if (ha->ms_iocb)
  3591. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3592. if (ha->ex_init_cb)
  3593. dma_pool_free(ha->s_dma_pool,
  3594. ha->ex_init_cb, ha->ex_init_cb_dma);
  3595. if (ha->async_pd)
  3596. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  3597. if (ha->s_dma_pool)
  3598. dma_pool_destroy(ha->s_dma_pool);
  3599. if (ha->gid_list)
  3600. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3601. ha->gid_list, ha->gid_list_dma);
  3602. if (IS_QLA82XX(ha)) {
  3603. if (!list_empty(&ha->gbl_dsd_list)) {
  3604. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  3605. /* clean up allocated prev pool */
  3606. list_for_each_entry_safe(dsd_ptr,
  3607. tdsd_ptr, &ha->gbl_dsd_list, list) {
  3608. dma_pool_free(ha->dl_dma_pool,
  3609. dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
  3610. list_del(&dsd_ptr->list);
  3611. kfree(dsd_ptr);
  3612. }
  3613. }
  3614. }
  3615. if (ha->dl_dma_pool)
  3616. dma_pool_destroy(ha->dl_dma_pool);
  3617. if (ha->fcp_cmnd_dma_pool)
  3618. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3619. if (ha->ctx_mempool)
  3620. mempool_destroy(ha->ctx_mempool);
  3621. qlt_mem_free(ha);
  3622. if (ha->init_cb)
  3623. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  3624. ha->init_cb, ha->init_cb_dma);
  3625. vfree(ha->optrom_buffer);
  3626. kfree(ha->nvram);
  3627. kfree(ha->npiv_info);
  3628. kfree(ha->swl);
  3629. kfree(ha->loop_id_map);
  3630. ha->srb_mempool = NULL;
  3631. ha->ctx_mempool = NULL;
  3632. ha->sns_cmd = NULL;
  3633. ha->sns_cmd_dma = 0;
  3634. ha->ct_sns = NULL;
  3635. ha->ct_sns_dma = 0;
  3636. ha->ms_iocb = NULL;
  3637. ha->ms_iocb_dma = 0;
  3638. ha->init_cb = NULL;
  3639. ha->init_cb_dma = 0;
  3640. ha->ex_init_cb = NULL;
  3641. ha->ex_init_cb_dma = 0;
  3642. ha->async_pd = NULL;
  3643. ha->async_pd_dma = 0;
  3644. ha->s_dma_pool = NULL;
  3645. ha->dl_dma_pool = NULL;
  3646. ha->fcp_cmnd_dma_pool = NULL;
  3647. ha->gid_list = NULL;
  3648. ha->gid_list_dma = 0;
  3649. ha->tgt.atio_ring = NULL;
  3650. ha->tgt.atio_dma = 0;
  3651. ha->tgt.tgt_vp_map = NULL;
  3652. }
  3653. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  3654. struct qla_hw_data *ha)
  3655. {
  3656. struct Scsi_Host *host;
  3657. struct scsi_qla_host *vha = NULL;
  3658. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  3659. if (host == NULL) {
  3660. ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
  3661. "Failed to allocate host from the scsi layer, aborting.\n");
  3662. goto fail;
  3663. }
  3664. /* Clear our data area */
  3665. vha = shost_priv(host);
  3666. memset(vha, 0, sizeof(scsi_qla_host_t));
  3667. vha->host = host;
  3668. vha->host_no = host->host_no;
  3669. vha->hw = ha;
  3670. INIT_LIST_HEAD(&vha->vp_fcports);
  3671. INIT_LIST_HEAD(&vha->work_list);
  3672. INIT_LIST_HEAD(&vha->list);
  3673. INIT_LIST_HEAD(&vha->qla_cmd_list);
  3674. INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
  3675. INIT_LIST_HEAD(&vha->logo_list);
  3676. INIT_LIST_HEAD(&vha->plogi_ack_list);
  3677. INIT_LIST_HEAD(&vha->qp_list);
  3678. spin_lock_init(&vha->work_lock);
  3679. spin_lock_init(&vha->cmd_list_lock);
  3680. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  3681. ql_dbg(ql_dbg_init, vha, 0x0041,
  3682. "Allocated the host=%p hw=%p vha=%p dev_name=%s",
  3683. vha->host, vha->hw, vha,
  3684. dev_name(&(ha->pdev->dev)));
  3685. return vha;
  3686. fail:
  3687. return vha;
  3688. }
  3689. static struct qla_work_evt *
  3690. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  3691. {
  3692. struct qla_work_evt *e;
  3693. uint8_t bail;
  3694. QLA_VHA_MARK_BUSY(vha, bail);
  3695. if (bail)
  3696. return NULL;
  3697. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  3698. if (!e) {
  3699. QLA_VHA_MARK_NOT_BUSY(vha);
  3700. return NULL;
  3701. }
  3702. INIT_LIST_HEAD(&e->list);
  3703. e->type = type;
  3704. e->flags = QLA_EVT_FLAG_FREE;
  3705. return e;
  3706. }
  3707. static int
  3708. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  3709. {
  3710. unsigned long flags;
  3711. spin_lock_irqsave(&vha->work_lock, flags);
  3712. list_add_tail(&e->list, &vha->work_list);
  3713. spin_unlock_irqrestore(&vha->work_lock, flags);
  3714. qla2xxx_wake_dpc(vha);
  3715. return QLA_SUCCESS;
  3716. }
  3717. int
  3718. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  3719. u32 data)
  3720. {
  3721. struct qla_work_evt *e;
  3722. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  3723. if (!e)
  3724. return QLA_FUNCTION_FAILED;
  3725. e->u.aen.code = code;
  3726. e->u.aen.data = data;
  3727. return qla2x00_post_work(vha, e);
  3728. }
  3729. int
  3730. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  3731. {
  3732. struct qla_work_evt *e;
  3733. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  3734. if (!e)
  3735. return QLA_FUNCTION_FAILED;
  3736. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  3737. return qla2x00_post_work(vha, e);
  3738. }
  3739. #define qla2x00_post_async_work(name, type) \
  3740. int qla2x00_post_async_##name##_work( \
  3741. struct scsi_qla_host *vha, \
  3742. fc_port_t *fcport, uint16_t *data) \
  3743. { \
  3744. struct qla_work_evt *e; \
  3745. \
  3746. e = qla2x00_alloc_work(vha, type); \
  3747. if (!e) \
  3748. return QLA_FUNCTION_FAILED; \
  3749. \
  3750. e->u.logio.fcport = fcport; \
  3751. if (data) { \
  3752. e->u.logio.data[0] = data[0]; \
  3753. e->u.logio.data[1] = data[1]; \
  3754. } \
  3755. return qla2x00_post_work(vha, e); \
  3756. }
  3757. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  3758. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  3759. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  3760. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  3761. qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
  3762. qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
  3763. int
  3764. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  3765. {
  3766. struct qla_work_evt *e;
  3767. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  3768. if (!e)
  3769. return QLA_FUNCTION_FAILED;
  3770. e->u.uevent.code = code;
  3771. return qla2x00_post_work(vha, e);
  3772. }
  3773. static void
  3774. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  3775. {
  3776. char event_string[40];
  3777. char *envp[] = { event_string, NULL };
  3778. switch (code) {
  3779. case QLA_UEVENT_CODE_FW_DUMP:
  3780. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  3781. vha->host_no);
  3782. break;
  3783. default:
  3784. /* do nothing */
  3785. break;
  3786. }
  3787. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  3788. }
  3789. int
  3790. qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
  3791. uint32_t *data, int cnt)
  3792. {
  3793. struct qla_work_evt *e;
  3794. e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
  3795. if (!e)
  3796. return QLA_FUNCTION_FAILED;
  3797. e->u.aenfx.evtcode = evtcode;
  3798. e->u.aenfx.count = cnt;
  3799. memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
  3800. return qla2x00_post_work(vha, e);
  3801. }
  3802. void
  3803. qla2x00_do_work(struct scsi_qla_host *vha)
  3804. {
  3805. struct qla_work_evt *e, *tmp;
  3806. unsigned long flags;
  3807. LIST_HEAD(work);
  3808. spin_lock_irqsave(&vha->work_lock, flags);
  3809. list_splice_init(&vha->work_list, &work);
  3810. spin_unlock_irqrestore(&vha->work_lock, flags);
  3811. list_for_each_entry_safe(e, tmp, &work, list) {
  3812. list_del_init(&e->list);
  3813. switch (e->type) {
  3814. case QLA_EVT_AEN:
  3815. fc_host_post_event(vha->host, fc_get_event_number(),
  3816. e->u.aen.code, e->u.aen.data);
  3817. break;
  3818. case QLA_EVT_IDC_ACK:
  3819. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  3820. break;
  3821. case QLA_EVT_ASYNC_LOGIN:
  3822. qla2x00_async_login(vha, e->u.logio.fcport,
  3823. e->u.logio.data);
  3824. break;
  3825. case QLA_EVT_ASYNC_LOGIN_DONE:
  3826. qla2x00_async_login_done(vha, e->u.logio.fcport,
  3827. e->u.logio.data);
  3828. break;
  3829. case QLA_EVT_ASYNC_LOGOUT:
  3830. qla2x00_async_logout(vha, e->u.logio.fcport);
  3831. break;
  3832. case QLA_EVT_ASYNC_LOGOUT_DONE:
  3833. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  3834. e->u.logio.data);
  3835. break;
  3836. case QLA_EVT_ASYNC_ADISC:
  3837. qla2x00_async_adisc(vha, e->u.logio.fcport,
  3838. e->u.logio.data);
  3839. break;
  3840. case QLA_EVT_ASYNC_ADISC_DONE:
  3841. qla2x00_async_adisc_done(vha, e->u.logio.fcport,
  3842. e->u.logio.data);
  3843. break;
  3844. case QLA_EVT_UEVENT:
  3845. qla2x00_uevent_emit(vha, e->u.uevent.code);
  3846. break;
  3847. case QLA_EVT_AENFX:
  3848. qlafx00_process_aen(vha, e);
  3849. break;
  3850. }
  3851. if (e->flags & QLA_EVT_FLAG_FREE)
  3852. kfree(e);
  3853. /* For each work completed decrement vha ref count */
  3854. QLA_VHA_MARK_NOT_BUSY(vha);
  3855. }
  3856. }
  3857. /* Relogins all the fcports of a vport
  3858. * Context: dpc thread
  3859. */
  3860. void qla2x00_relogin(struct scsi_qla_host *vha)
  3861. {
  3862. fc_port_t *fcport;
  3863. int status;
  3864. uint16_t next_loopid = 0;
  3865. struct qla_hw_data *ha = vha->hw;
  3866. uint16_t data[2];
  3867. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3868. /*
  3869. * If the port is not ONLINE then try to login
  3870. * to it if we haven't run out of retries.
  3871. */
  3872. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  3873. fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
  3874. fcport->login_retry--;
  3875. if (fcport->flags & FCF_FABRIC_DEVICE) {
  3876. if (fcport->flags & FCF_FCP2_DEVICE)
  3877. ha->isp_ops->fabric_logout(vha,
  3878. fcport->loop_id,
  3879. fcport->d_id.b.domain,
  3880. fcport->d_id.b.area,
  3881. fcport->d_id.b.al_pa);
  3882. if (fcport->loop_id == FC_NO_LOOP_ID) {
  3883. fcport->loop_id = next_loopid =
  3884. ha->min_external_loopid;
  3885. status = qla2x00_find_new_loop_id(
  3886. vha, fcport);
  3887. if (status != QLA_SUCCESS) {
  3888. /* Ran out of IDs to use */
  3889. break;
  3890. }
  3891. }
  3892. if (IS_ALOGIO_CAPABLE(ha)) {
  3893. fcport->flags |= FCF_ASYNC_SENT;
  3894. data[0] = 0;
  3895. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  3896. status = qla2x00_post_async_login_work(
  3897. vha, fcport, data);
  3898. if (status == QLA_SUCCESS)
  3899. continue;
  3900. /* Attempt a retry. */
  3901. status = 1;
  3902. } else {
  3903. status = qla2x00_fabric_login(vha,
  3904. fcport, &next_loopid);
  3905. if (status == QLA_SUCCESS) {
  3906. int status2;
  3907. uint8_t opts;
  3908. opts = 0;
  3909. if (fcport->flags &
  3910. FCF_FCP2_DEVICE)
  3911. opts |= BIT_1;
  3912. status2 =
  3913. qla2x00_get_port_database(
  3914. vha, fcport, opts);
  3915. if (status2 != QLA_SUCCESS)
  3916. status = 1;
  3917. }
  3918. }
  3919. } else
  3920. status = qla2x00_local_device_login(vha,
  3921. fcport);
  3922. if (status == QLA_SUCCESS) {
  3923. fcport->old_loop_id = fcport->loop_id;
  3924. ql_dbg(ql_dbg_disc, vha, 0x2003,
  3925. "Port login OK: logged in ID 0x%x.\n",
  3926. fcport->loop_id);
  3927. qla2x00_update_fcport(vha, fcport);
  3928. } else if (status == 1) {
  3929. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  3930. /* retry the login again */
  3931. ql_dbg(ql_dbg_disc, vha, 0x2007,
  3932. "Retrying %d login again loop_id 0x%x.\n",
  3933. fcport->login_retry, fcport->loop_id);
  3934. } else {
  3935. fcport->login_retry = 0;
  3936. }
  3937. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  3938. qla2x00_clear_loop_id(fcport);
  3939. }
  3940. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3941. break;
  3942. }
  3943. }
  3944. /* Schedule work on any of the dpc-workqueues */
  3945. void
  3946. qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
  3947. {
  3948. struct qla_hw_data *ha = base_vha->hw;
  3949. switch (work_code) {
  3950. case MBA_IDC_AEN: /* 0x8200 */
  3951. if (ha->dpc_lp_wq)
  3952. queue_work(ha->dpc_lp_wq, &ha->idc_aen);
  3953. break;
  3954. case QLA83XX_NIC_CORE_RESET: /* 0x1 */
  3955. if (!ha->flags.nic_core_reset_hdlr_active) {
  3956. if (ha->dpc_hp_wq)
  3957. queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
  3958. } else
  3959. ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
  3960. "NIC Core reset is already active. Skip "
  3961. "scheduling it again.\n");
  3962. break;
  3963. case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
  3964. if (ha->dpc_hp_wq)
  3965. queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
  3966. break;
  3967. case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
  3968. if (ha->dpc_hp_wq)
  3969. queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
  3970. break;
  3971. default:
  3972. ql_log(ql_log_warn, base_vha, 0xb05f,
  3973. "Unknown work-code=0x%x.\n", work_code);
  3974. }
  3975. return;
  3976. }
  3977. /* Work: Perform NIC Core Unrecoverable state handling */
  3978. void
  3979. qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
  3980. {
  3981. struct qla_hw_data *ha =
  3982. container_of(work, struct qla_hw_data, nic_core_unrecoverable);
  3983. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3984. uint32_t dev_state = 0;
  3985. qla83xx_idc_lock(base_vha, 0);
  3986. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3987. qla83xx_reset_ownership(base_vha);
  3988. if (ha->flags.nic_core_reset_owner) {
  3989. ha->flags.nic_core_reset_owner = 0;
  3990. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3991. QLA8XXX_DEV_FAILED);
  3992. ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
  3993. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3994. }
  3995. qla83xx_idc_unlock(base_vha, 0);
  3996. }
  3997. /* Work: Execute IDC state handler */
  3998. void
  3999. qla83xx_idc_state_handler_work(struct work_struct *work)
  4000. {
  4001. struct qla_hw_data *ha =
  4002. container_of(work, struct qla_hw_data, idc_state_handler);
  4003. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  4004. uint32_t dev_state = 0;
  4005. qla83xx_idc_lock(base_vha, 0);
  4006. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  4007. if (dev_state == QLA8XXX_DEV_FAILED ||
  4008. dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
  4009. qla83xx_idc_state_handler(base_vha);
  4010. qla83xx_idc_unlock(base_vha, 0);
  4011. }
  4012. static int
  4013. qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
  4014. {
  4015. int rval = QLA_SUCCESS;
  4016. unsigned long heart_beat_wait = jiffies + (1 * HZ);
  4017. uint32_t heart_beat_counter1, heart_beat_counter2;
  4018. do {
  4019. if (time_after(jiffies, heart_beat_wait)) {
  4020. ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
  4021. "Nic Core f/w is not alive.\n");
  4022. rval = QLA_FUNCTION_FAILED;
  4023. break;
  4024. }
  4025. qla83xx_idc_lock(base_vha, 0);
  4026. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  4027. &heart_beat_counter1);
  4028. qla83xx_idc_unlock(base_vha, 0);
  4029. msleep(100);
  4030. qla83xx_idc_lock(base_vha, 0);
  4031. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  4032. &heart_beat_counter2);
  4033. qla83xx_idc_unlock(base_vha, 0);
  4034. } while (heart_beat_counter1 == heart_beat_counter2);
  4035. return rval;
  4036. }
  4037. /* Work: Perform NIC Core Reset handling */
  4038. void
  4039. qla83xx_nic_core_reset_work(struct work_struct *work)
  4040. {
  4041. struct qla_hw_data *ha =
  4042. container_of(work, struct qla_hw_data, nic_core_reset);
  4043. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  4044. uint32_t dev_state = 0;
  4045. if (IS_QLA2031(ha)) {
  4046. if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
  4047. ql_log(ql_log_warn, base_vha, 0xb081,
  4048. "Failed to dump mctp\n");
  4049. return;
  4050. }
  4051. if (!ha->flags.nic_core_reset_hdlr_active) {
  4052. if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
  4053. qla83xx_idc_lock(base_vha, 0);
  4054. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  4055. &dev_state);
  4056. qla83xx_idc_unlock(base_vha, 0);
  4057. if (dev_state != QLA8XXX_DEV_NEED_RESET) {
  4058. ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
  4059. "Nic Core f/w is alive.\n");
  4060. return;
  4061. }
  4062. }
  4063. ha->flags.nic_core_reset_hdlr_active = 1;
  4064. if (qla83xx_nic_core_reset(base_vha)) {
  4065. /* NIC Core reset failed. */
  4066. ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
  4067. "NIC Core reset failed.\n");
  4068. }
  4069. ha->flags.nic_core_reset_hdlr_active = 0;
  4070. }
  4071. }
  4072. /* Work: Handle 8200 IDC aens */
  4073. void
  4074. qla83xx_service_idc_aen(struct work_struct *work)
  4075. {
  4076. struct qla_hw_data *ha =
  4077. container_of(work, struct qla_hw_data, idc_aen);
  4078. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  4079. uint32_t dev_state, idc_control;
  4080. qla83xx_idc_lock(base_vha, 0);
  4081. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  4082. qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
  4083. qla83xx_idc_unlock(base_vha, 0);
  4084. if (dev_state == QLA8XXX_DEV_NEED_RESET) {
  4085. if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
  4086. ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
  4087. "Application requested NIC Core Reset.\n");
  4088. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  4089. } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
  4090. QLA_SUCCESS) {
  4091. ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
  4092. "Other protocol driver requested NIC Core Reset.\n");
  4093. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  4094. }
  4095. } else if (dev_state == QLA8XXX_DEV_FAILED ||
  4096. dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
  4097. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  4098. }
  4099. }
  4100. static void
  4101. qla83xx_wait_logic(void)
  4102. {
  4103. int i;
  4104. /* Yield CPU */
  4105. if (!in_interrupt()) {
  4106. /*
  4107. * Wait about 200ms before retrying again.
  4108. * This controls the number of retries for single
  4109. * lock operation.
  4110. */
  4111. msleep(100);
  4112. schedule();
  4113. } else {
  4114. for (i = 0; i < 20; i++)
  4115. cpu_relax(); /* This a nop instr on i386 */
  4116. }
  4117. }
  4118. static int
  4119. qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
  4120. {
  4121. int rval;
  4122. uint32_t data;
  4123. uint32_t idc_lck_rcvry_stage_mask = 0x3;
  4124. uint32_t idc_lck_rcvry_owner_mask = 0x3c;
  4125. struct qla_hw_data *ha = base_vha->hw;
  4126. ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
  4127. "Trying force recovery of the IDC lock.\n");
  4128. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
  4129. if (rval)
  4130. return rval;
  4131. if ((data & idc_lck_rcvry_stage_mask) > 0) {
  4132. return QLA_SUCCESS;
  4133. } else {
  4134. data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
  4135. rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  4136. data);
  4137. if (rval)
  4138. return rval;
  4139. msleep(200);
  4140. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  4141. &data);
  4142. if (rval)
  4143. return rval;
  4144. if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
  4145. data &= (IDC_LOCK_RECOVERY_STAGE2 |
  4146. ~(idc_lck_rcvry_stage_mask));
  4147. rval = qla83xx_wr_reg(base_vha,
  4148. QLA83XX_IDC_LOCK_RECOVERY, data);
  4149. if (rval)
  4150. return rval;
  4151. /* Forcefully perform IDC UnLock */
  4152. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
  4153. &data);
  4154. if (rval)
  4155. return rval;
  4156. /* Clear lock-id by setting 0xff */
  4157. rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  4158. 0xff);
  4159. if (rval)
  4160. return rval;
  4161. /* Clear lock-recovery by setting 0x0 */
  4162. rval = qla83xx_wr_reg(base_vha,
  4163. QLA83XX_IDC_LOCK_RECOVERY, 0x0);
  4164. if (rval)
  4165. return rval;
  4166. } else
  4167. return QLA_SUCCESS;
  4168. }
  4169. return rval;
  4170. }
  4171. static int
  4172. qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
  4173. {
  4174. int rval = QLA_SUCCESS;
  4175. uint32_t o_drv_lockid, n_drv_lockid;
  4176. unsigned long lock_recovery_timeout;
  4177. lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
  4178. retry_lockid:
  4179. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
  4180. if (rval)
  4181. goto exit;
  4182. /* MAX wait time before forcing IDC Lock recovery = 2 secs */
  4183. if (time_after_eq(jiffies, lock_recovery_timeout)) {
  4184. if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
  4185. return QLA_SUCCESS;
  4186. else
  4187. return QLA_FUNCTION_FAILED;
  4188. }
  4189. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
  4190. if (rval)
  4191. goto exit;
  4192. if (o_drv_lockid == n_drv_lockid) {
  4193. qla83xx_wait_logic();
  4194. goto retry_lockid;
  4195. } else
  4196. return QLA_SUCCESS;
  4197. exit:
  4198. return rval;
  4199. }
  4200. void
  4201. qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  4202. {
  4203. uint16_t options = (requester_id << 15) | BIT_6;
  4204. uint32_t data;
  4205. uint32_t lock_owner;
  4206. struct qla_hw_data *ha = base_vha->hw;
  4207. /* IDC-lock implementation using driver-lock/lock-id remote registers */
  4208. retry_lock:
  4209. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
  4210. == QLA_SUCCESS) {
  4211. if (data) {
  4212. /* Setting lock-id to our function-number */
  4213. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  4214. ha->portnum);
  4215. } else {
  4216. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  4217. &lock_owner);
  4218. ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
  4219. "Failed to acquire IDC lock, acquired by %d, "
  4220. "retrying...\n", lock_owner);
  4221. /* Retry/Perform IDC-Lock recovery */
  4222. if (qla83xx_idc_lock_recovery(base_vha)
  4223. == QLA_SUCCESS) {
  4224. qla83xx_wait_logic();
  4225. goto retry_lock;
  4226. } else
  4227. ql_log(ql_log_warn, base_vha, 0xb075,
  4228. "IDC Lock recovery FAILED.\n");
  4229. }
  4230. }
  4231. return;
  4232. /* XXX: IDC-lock implementation using access-control mbx */
  4233. retry_lock2:
  4234. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  4235. ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
  4236. "Failed to acquire IDC lock. retrying...\n");
  4237. /* Retry/Perform IDC-Lock recovery */
  4238. if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
  4239. qla83xx_wait_logic();
  4240. goto retry_lock2;
  4241. } else
  4242. ql_log(ql_log_warn, base_vha, 0xb076,
  4243. "IDC Lock recovery FAILED.\n");
  4244. }
  4245. return;
  4246. }
  4247. void
  4248. qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  4249. {
  4250. #if 0
  4251. uint16_t options = (requester_id << 15) | BIT_7;
  4252. #endif
  4253. uint16_t retry;
  4254. uint32_t data;
  4255. struct qla_hw_data *ha = base_vha->hw;
  4256. /* IDC-unlock implementation using driver-unlock/lock-id
  4257. * remote registers
  4258. */
  4259. retry = 0;
  4260. retry_unlock:
  4261. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
  4262. == QLA_SUCCESS) {
  4263. if (data == ha->portnum) {
  4264. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
  4265. /* Clearing lock-id by setting 0xff */
  4266. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
  4267. } else if (retry < 10) {
  4268. /* SV: XXX: IDC unlock retrying needed here? */
  4269. /* Retry for IDC-unlock */
  4270. qla83xx_wait_logic();
  4271. retry++;
  4272. ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
  4273. "Failed to release IDC lock, retrying=%d\n", retry);
  4274. goto retry_unlock;
  4275. }
  4276. } else if (retry < 10) {
  4277. /* Retry for IDC-unlock */
  4278. qla83xx_wait_logic();
  4279. retry++;
  4280. ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
  4281. "Failed to read drv-lockid, retrying=%d\n", retry);
  4282. goto retry_unlock;
  4283. }
  4284. return;
  4285. #if 0
  4286. /* XXX: IDC-unlock implementation using access-control mbx */
  4287. retry = 0;
  4288. retry_unlock2:
  4289. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  4290. if (retry < 10) {
  4291. /* Retry for IDC-unlock */
  4292. qla83xx_wait_logic();
  4293. retry++;
  4294. ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
  4295. "Failed to release IDC lock, retrying=%d\n", retry);
  4296. goto retry_unlock2;
  4297. }
  4298. }
  4299. return;
  4300. #endif
  4301. }
  4302. int
  4303. __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  4304. {
  4305. int rval = QLA_SUCCESS;
  4306. struct qla_hw_data *ha = vha->hw;
  4307. uint32_t drv_presence;
  4308. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  4309. if (rval == QLA_SUCCESS) {
  4310. drv_presence |= (1 << ha->portnum);
  4311. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4312. drv_presence);
  4313. }
  4314. return rval;
  4315. }
  4316. int
  4317. qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  4318. {
  4319. int rval = QLA_SUCCESS;
  4320. qla83xx_idc_lock(vha, 0);
  4321. rval = __qla83xx_set_drv_presence(vha);
  4322. qla83xx_idc_unlock(vha, 0);
  4323. return rval;
  4324. }
  4325. int
  4326. __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  4327. {
  4328. int rval = QLA_SUCCESS;
  4329. struct qla_hw_data *ha = vha->hw;
  4330. uint32_t drv_presence;
  4331. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  4332. if (rval == QLA_SUCCESS) {
  4333. drv_presence &= ~(1 << ha->portnum);
  4334. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4335. drv_presence);
  4336. }
  4337. return rval;
  4338. }
  4339. int
  4340. qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  4341. {
  4342. int rval = QLA_SUCCESS;
  4343. qla83xx_idc_lock(vha, 0);
  4344. rval = __qla83xx_clear_drv_presence(vha);
  4345. qla83xx_idc_unlock(vha, 0);
  4346. return rval;
  4347. }
  4348. static void
  4349. qla83xx_need_reset_handler(scsi_qla_host_t *vha)
  4350. {
  4351. struct qla_hw_data *ha = vha->hw;
  4352. uint32_t drv_ack, drv_presence;
  4353. unsigned long ack_timeout;
  4354. /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
  4355. ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
  4356. while (1) {
  4357. qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  4358. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  4359. if ((drv_ack & drv_presence) == drv_presence)
  4360. break;
  4361. if (time_after_eq(jiffies, ack_timeout)) {
  4362. ql_log(ql_log_warn, vha, 0xb067,
  4363. "RESET ACK TIMEOUT! drv_presence=0x%x "
  4364. "drv_ack=0x%x\n", drv_presence, drv_ack);
  4365. /*
  4366. * The function(s) which did not ack in time are forced
  4367. * to withdraw any further participation in the IDC
  4368. * reset.
  4369. */
  4370. if (drv_ack != drv_presence)
  4371. qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4372. drv_ack);
  4373. break;
  4374. }
  4375. qla83xx_idc_unlock(vha, 0);
  4376. msleep(1000);
  4377. qla83xx_idc_lock(vha, 0);
  4378. }
  4379. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
  4380. ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
  4381. }
  4382. static int
  4383. qla83xx_device_bootstrap(scsi_qla_host_t *vha)
  4384. {
  4385. int rval = QLA_SUCCESS;
  4386. uint32_t idc_control;
  4387. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
  4388. ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
  4389. /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
  4390. __qla83xx_get_idc_control(vha, &idc_control);
  4391. idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
  4392. __qla83xx_set_idc_control(vha, 0);
  4393. qla83xx_idc_unlock(vha, 0);
  4394. rval = qla83xx_restart_nic_firmware(vha);
  4395. qla83xx_idc_lock(vha, 0);
  4396. if (rval != QLA_SUCCESS) {
  4397. ql_log(ql_log_fatal, vha, 0xb06a,
  4398. "Failed to restart NIC f/w.\n");
  4399. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
  4400. ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
  4401. } else {
  4402. ql_dbg(ql_dbg_p3p, vha, 0xb06c,
  4403. "Success in restarting nic f/w.\n");
  4404. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
  4405. ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
  4406. }
  4407. return rval;
  4408. }
  4409. /* Assumes idc_lock always held on entry */
  4410. int
  4411. qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
  4412. {
  4413. struct qla_hw_data *ha = base_vha->hw;
  4414. int rval = QLA_SUCCESS;
  4415. unsigned long dev_init_timeout;
  4416. uint32_t dev_state;
  4417. /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
  4418. dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
  4419. while (1) {
  4420. if (time_after_eq(jiffies, dev_init_timeout)) {
  4421. ql_log(ql_log_warn, base_vha, 0xb06e,
  4422. "Initialization TIMEOUT!\n");
  4423. /* Init timeout. Disable further NIC Core
  4424. * communication.
  4425. */
  4426. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  4427. QLA8XXX_DEV_FAILED);
  4428. ql_log(ql_log_info, base_vha, 0xb06f,
  4429. "HW State: FAILED.\n");
  4430. }
  4431. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  4432. switch (dev_state) {
  4433. case QLA8XXX_DEV_READY:
  4434. if (ha->flags.nic_core_reset_owner)
  4435. qla83xx_idc_audit(base_vha,
  4436. IDC_AUDIT_COMPLETION);
  4437. ha->flags.nic_core_reset_owner = 0;
  4438. ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
  4439. "Reset_owner reset by 0x%x.\n",
  4440. ha->portnum);
  4441. goto exit;
  4442. case QLA8XXX_DEV_COLD:
  4443. if (ha->flags.nic_core_reset_owner)
  4444. rval = qla83xx_device_bootstrap(base_vha);
  4445. else {
  4446. /* Wait for AEN to change device-state */
  4447. qla83xx_idc_unlock(base_vha, 0);
  4448. msleep(1000);
  4449. qla83xx_idc_lock(base_vha, 0);
  4450. }
  4451. break;
  4452. case QLA8XXX_DEV_INITIALIZING:
  4453. /* Wait for AEN to change device-state */
  4454. qla83xx_idc_unlock(base_vha, 0);
  4455. msleep(1000);
  4456. qla83xx_idc_lock(base_vha, 0);
  4457. break;
  4458. case QLA8XXX_DEV_NEED_RESET:
  4459. if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
  4460. qla83xx_need_reset_handler(base_vha);
  4461. else {
  4462. /* Wait for AEN to change device-state */
  4463. qla83xx_idc_unlock(base_vha, 0);
  4464. msleep(1000);
  4465. qla83xx_idc_lock(base_vha, 0);
  4466. }
  4467. /* reset timeout value after need reset handler */
  4468. dev_init_timeout = jiffies +
  4469. (ha->fcoe_dev_init_timeout * HZ);
  4470. break;
  4471. case QLA8XXX_DEV_NEED_QUIESCENT:
  4472. /* XXX: DEBUG for now */
  4473. qla83xx_idc_unlock(base_vha, 0);
  4474. msleep(1000);
  4475. qla83xx_idc_lock(base_vha, 0);
  4476. break;
  4477. case QLA8XXX_DEV_QUIESCENT:
  4478. /* XXX: DEBUG for now */
  4479. if (ha->flags.quiesce_owner)
  4480. goto exit;
  4481. qla83xx_idc_unlock(base_vha, 0);
  4482. msleep(1000);
  4483. qla83xx_idc_lock(base_vha, 0);
  4484. dev_init_timeout = jiffies +
  4485. (ha->fcoe_dev_init_timeout * HZ);
  4486. break;
  4487. case QLA8XXX_DEV_FAILED:
  4488. if (ha->flags.nic_core_reset_owner)
  4489. qla83xx_idc_audit(base_vha,
  4490. IDC_AUDIT_COMPLETION);
  4491. ha->flags.nic_core_reset_owner = 0;
  4492. __qla83xx_clear_drv_presence(base_vha);
  4493. qla83xx_idc_unlock(base_vha, 0);
  4494. qla8xxx_dev_failed_handler(base_vha);
  4495. rval = QLA_FUNCTION_FAILED;
  4496. qla83xx_idc_lock(base_vha, 0);
  4497. goto exit;
  4498. case QLA8XXX_BAD_VALUE:
  4499. qla83xx_idc_unlock(base_vha, 0);
  4500. msleep(1000);
  4501. qla83xx_idc_lock(base_vha, 0);
  4502. break;
  4503. default:
  4504. ql_log(ql_log_warn, base_vha, 0xb071,
  4505. "Unknown Device State: %x.\n", dev_state);
  4506. qla83xx_idc_unlock(base_vha, 0);
  4507. qla8xxx_dev_failed_handler(base_vha);
  4508. rval = QLA_FUNCTION_FAILED;
  4509. qla83xx_idc_lock(base_vha, 0);
  4510. goto exit;
  4511. }
  4512. }
  4513. exit:
  4514. return rval;
  4515. }
  4516. void
  4517. qla2x00_disable_board_on_pci_error(struct work_struct *work)
  4518. {
  4519. struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
  4520. board_disable);
  4521. struct pci_dev *pdev = ha->pdev;
  4522. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  4523. /* if UNLOAD flag is already set, then continue unload,
  4524. * where it was set first.
  4525. */
  4526. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  4527. return;
  4528. ql_log(ql_log_warn, base_vha, 0x015b,
  4529. "Disabling adapter.\n");
  4530. set_bit(UNLOADING, &base_vha->dpc_flags);
  4531. qla2x00_delete_all_vps(ha, base_vha);
  4532. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  4533. qla2x00_dfs_remove(base_vha);
  4534. qla84xx_put_chip(base_vha);
  4535. if (base_vha->timer_active)
  4536. qla2x00_stop_timer(base_vha);
  4537. base_vha->flags.online = 0;
  4538. qla2x00_destroy_deferred_work(ha);
  4539. /*
  4540. * Do not try to stop beacon blink as it will issue a mailbox
  4541. * command.
  4542. */
  4543. qla2x00_free_sysfs_attr(base_vha, false);
  4544. fc_remove_host(base_vha->host);
  4545. scsi_remove_host(base_vha->host);
  4546. base_vha->flags.init_done = 0;
  4547. qla25xx_delete_queues(base_vha);
  4548. qla2x00_free_fcports(base_vha);
  4549. qla2x00_free_irqs(base_vha);
  4550. qla2x00_mem_free(ha);
  4551. qla82xx_md_free(base_vha);
  4552. qla2x00_free_queues(ha);
  4553. qla2x00_unmap_iobases(ha);
  4554. pci_release_selected_regions(ha->pdev, ha->bars);
  4555. pci_disable_pcie_error_reporting(pdev);
  4556. pci_disable_device(pdev);
  4557. /*
  4558. * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
  4559. */
  4560. }
  4561. /**************************************************************************
  4562. * qla2x00_do_dpc
  4563. * This kernel thread is a task that is schedule by the interrupt handler
  4564. * to perform the background processing for interrupts.
  4565. *
  4566. * Notes:
  4567. * This task always run in the context of a kernel thread. It
  4568. * is kick-off by the driver's detect code and starts up
  4569. * up one per adapter. It immediately goes to sleep and waits for
  4570. * some fibre event. When either the interrupt handler or
  4571. * the timer routine detects a event it will one of the task
  4572. * bits then wake us up.
  4573. **************************************************************************/
  4574. static int
  4575. qla2x00_do_dpc(void *data)
  4576. {
  4577. scsi_qla_host_t *base_vha;
  4578. struct qla_hw_data *ha;
  4579. uint32_t online;
  4580. struct qla_qpair *qpair;
  4581. ha = (struct qla_hw_data *)data;
  4582. base_vha = pci_get_drvdata(ha->pdev);
  4583. set_user_nice(current, MIN_NICE);
  4584. set_current_state(TASK_INTERRUPTIBLE);
  4585. while (!kthread_should_stop()) {
  4586. ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
  4587. "DPC handler sleeping.\n");
  4588. schedule();
  4589. if (!base_vha->flags.init_done || ha->flags.mbox_busy)
  4590. goto end_loop;
  4591. if (ha->flags.eeh_busy) {
  4592. ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
  4593. "eeh_busy=%d.\n", ha->flags.eeh_busy);
  4594. goto end_loop;
  4595. }
  4596. ha->dpc_active = 1;
  4597. ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
  4598. "DPC handler waking up, dpc_flags=0x%lx.\n",
  4599. base_vha->dpc_flags);
  4600. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  4601. break;
  4602. qla2x00_do_work(base_vha);
  4603. if (IS_P3P_TYPE(ha)) {
  4604. if (IS_QLA8044(ha)) {
  4605. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4606. &base_vha->dpc_flags)) {
  4607. qla8044_idc_lock(ha);
  4608. qla8044_wr_direct(base_vha,
  4609. QLA8044_CRB_DEV_STATE_INDEX,
  4610. QLA8XXX_DEV_FAILED);
  4611. qla8044_idc_unlock(ha);
  4612. ql_log(ql_log_info, base_vha, 0x4004,
  4613. "HW State: FAILED.\n");
  4614. qla8044_device_state_handler(base_vha);
  4615. continue;
  4616. }
  4617. } else {
  4618. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4619. &base_vha->dpc_flags)) {
  4620. qla82xx_idc_lock(ha);
  4621. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4622. QLA8XXX_DEV_FAILED);
  4623. qla82xx_idc_unlock(ha);
  4624. ql_log(ql_log_info, base_vha, 0x0151,
  4625. "HW State: FAILED.\n");
  4626. qla82xx_device_state_handler(base_vha);
  4627. continue;
  4628. }
  4629. }
  4630. if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
  4631. &base_vha->dpc_flags)) {
  4632. ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
  4633. "FCoE context reset scheduled.\n");
  4634. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4635. &base_vha->dpc_flags))) {
  4636. if (qla82xx_fcoe_ctx_reset(base_vha)) {
  4637. /* FCoE-ctx reset failed.
  4638. * Escalate to chip-reset
  4639. */
  4640. set_bit(ISP_ABORT_NEEDED,
  4641. &base_vha->dpc_flags);
  4642. }
  4643. clear_bit(ABORT_ISP_ACTIVE,
  4644. &base_vha->dpc_flags);
  4645. }
  4646. ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
  4647. "FCoE context reset end.\n");
  4648. }
  4649. } else if (IS_QLAFX00(ha)) {
  4650. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4651. &base_vha->dpc_flags)) {
  4652. ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
  4653. "Firmware Reset Recovery\n");
  4654. if (qlafx00_reset_initialize(base_vha)) {
  4655. /* Failed. Abort isp later. */
  4656. if (!test_bit(UNLOADING,
  4657. &base_vha->dpc_flags)) {
  4658. set_bit(ISP_UNRECOVERABLE,
  4659. &base_vha->dpc_flags);
  4660. ql_dbg(ql_dbg_dpc, base_vha,
  4661. 0x4021,
  4662. "Reset Recovery Failed\n");
  4663. }
  4664. }
  4665. }
  4666. if (test_and_clear_bit(FX00_TARGET_SCAN,
  4667. &base_vha->dpc_flags)) {
  4668. ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
  4669. "ISPFx00 Target Scan scheduled\n");
  4670. if (qlafx00_rescan_isp(base_vha)) {
  4671. if (!test_bit(UNLOADING,
  4672. &base_vha->dpc_flags))
  4673. set_bit(ISP_UNRECOVERABLE,
  4674. &base_vha->dpc_flags);
  4675. ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
  4676. "ISPFx00 Target Scan Failed\n");
  4677. }
  4678. ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
  4679. "ISPFx00 Target Scan End\n");
  4680. }
  4681. if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
  4682. &base_vha->dpc_flags)) {
  4683. ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
  4684. "ISPFx00 Host Info resend scheduled\n");
  4685. qlafx00_fx_disc(base_vha,
  4686. &base_vha->hw->mr.fcport,
  4687. FXDISC_REG_HOST_INFO);
  4688. }
  4689. }
  4690. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  4691. &base_vha->dpc_flags)) {
  4692. ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
  4693. "ISP abort scheduled.\n");
  4694. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4695. &base_vha->dpc_flags))) {
  4696. if (ha->isp_ops->abort_isp(base_vha)) {
  4697. /* failed. retry later */
  4698. set_bit(ISP_ABORT_NEEDED,
  4699. &base_vha->dpc_flags);
  4700. }
  4701. clear_bit(ABORT_ISP_ACTIVE,
  4702. &base_vha->dpc_flags);
  4703. }
  4704. ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
  4705. "ISP abort end.\n");
  4706. }
  4707. if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
  4708. &base_vha->dpc_flags)) {
  4709. qla2x00_update_fcports(base_vha);
  4710. }
  4711. if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
  4712. int ret;
  4713. ret = qla2x00_send_change_request(base_vha, 0x3, 0);
  4714. if (ret != QLA_SUCCESS)
  4715. ql_log(ql_log_warn, base_vha, 0x121,
  4716. "Failed to enable receiving of RSCN "
  4717. "requests: 0x%x.\n", ret);
  4718. clear_bit(SCR_PENDING, &base_vha->dpc_flags);
  4719. }
  4720. if (IS_QLAFX00(ha))
  4721. goto loop_resync_check;
  4722. if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
  4723. ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
  4724. "Quiescence mode scheduled.\n");
  4725. if (IS_P3P_TYPE(ha)) {
  4726. if (IS_QLA82XX(ha))
  4727. qla82xx_device_state_handler(base_vha);
  4728. if (IS_QLA8044(ha))
  4729. qla8044_device_state_handler(base_vha);
  4730. clear_bit(ISP_QUIESCE_NEEDED,
  4731. &base_vha->dpc_flags);
  4732. if (!ha->flags.quiesce_owner) {
  4733. qla2x00_perform_loop_resync(base_vha);
  4734. if (IS_QLA82XX(ha)) {
  4735. qla82xx_idc_lock(ha);
  4736. qla82xx_clear_qsnt_ready(
  4737. base_vha);
  4738. qla82xx_idc_unlock(ha);
  4739. } else if (IS_QLA8044(ha)) {
  4740. qla8044_idc_lock(ha);
  4741. qla8044_clear_qsnt_ready(
  4742. base_vha);
  4743. qla8044_idc_unlock(ha);
  4744. }
  4745. }
  4746. } else {
  4747. clear_bit(ISP_QUIESCE_NEEDED,
  4748. &base_vha->dpc_flags);
  4749. qla2x00_quiesce_io(base_vha);
  4750. }
  4751. ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
  4752. "Quiescence mode end.\n");
  4753. }
  4754. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  4755. &base_vha->dpc_flags) &&
  4756. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  4757. ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
  4758. "Reset marker scheduled.\n");
  4759. qla2x00_rst_aen(base_vha);
  4760. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  4761. ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
  4762. "Reset marker end.\n");
  4763. }
  4764. /* Retry each device up to login retry count */
  4765. if ((test_and_clear_bit(RELOGIN_NEEDED,
  4766. &base_vha->dpc_flags)) &&
  4767. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  4768. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  4769. ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
  4770. "Relogin scheduled.\n");
  4771. qla2x00_relogin(base_vha);
  4772. ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
  4773. "Relogin end.\n");
  4774. }
  4775. loop_resync_check:
  4776. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  4777. &base_vha->dpc_flags)) {
  4778. ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
  4779. "Loop resync scheduled.\n");
  4780. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  4781. &base_vha->dpc_flags))) {
  4782. qla2x00_loop_resync(base_vha);
  4783. clear_bit(LOOP_RESYNC_ACTIVE,
  4784. &base_vha->dpc_flags);
  4785. }
  4786. ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
  4787. "Loop resync end.\n");
  4788. }
  4789. if (IS_QLAFX00(ha))
  4790. goto intr_on_check;
  4791. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  4792. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  4793. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  4794. qla2xxx_flash_npiv_conf(base_vha);
  4795. }
  4796. intr_on_check:
  4797. if (!ha->interrupts_on)
  4798. ha->isp_ops->enable_intrs(ha);
  4799. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  4800. &base_vha->dpc_flags)) {
  4801. if (ha->beacon_blink_led == 1)
  4802. ha->isp_ops->beacon_blink(base_vha);
  4803. }
  4804. /* qpair online check */
  4805. if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
  4806. &base_vha->dpc_flags)) {
  4807. if (ha->flags.eeh_busy ||
  4808. ha->flags.pci_channel_io_perm_failure)
  4809. online = 0;
  4810. else
  4811. online = 1;
  4812. mutex_lock(&ha->mq_lock);
  4813. list_for_each_entry(qpair, &base_vha->qp_list,
  4814. qp_list_elem)
  4815. qpair->online = online;
  4816. mutex_unlock(&ha->mq_lock);
  4817. }
  4818. if (!IS_QLAFX00(ha))
  4819. qla2x00_do_dpc_all_vps(base_vha);
  4820. ha->dpc_active = 0;
  4821. end_loop:
  4822. set_current_state(TASK_INTERRUPTIBLE);
  4823. } /* End of while(1) */
  4824. __set_current_state(TASK_RUNNING);
  4825. ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
  4826. "DPC handler exiting.\n");
  4827. /*
  4828. * Make sure that nobody tries to wake us up again.
  4829. */
  4830. ha->dpc_active = 0;
  4831. /* Cleanup any residual CTX SRBs. */
  4832. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  4833. return 0;
  4834. }
  4835. void
  4836. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  4837. {
  4838. struct qla_hw_data *ha = vha->hw;
  4839. struct task_struct *t = ha->dpc_thread;
  4840. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  4841. wake_up_process(t);
  4842. }
  4843. /*
  4844. * qla2x00_rst_aen
  4845. * Processes asynchronous reset.
  4846. *
  4847. * Input:
  4848. * ha = adapter block pointer.
  4849. */
  4850. static void
  4851. qla2x00_rst_aen(scsi_qla_host_t *vha)
  4852. {
  4853. if (vha->flags.online && !vha->flags.reset_active &&
  4854. !atomic_read(&vha->loop_down_timer) &&
  4855. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  4856. do {
  4857. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4858. /*
  4859. * Issue marker command only when we are going to start
  4860. * the I/O.
  4861. */
  4862. vha->marker_needed = 1;
  4863. } while (!atomic_read(&vha->loop_down_timer) &&
  4864. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  4865. }
  4866. }
  4867. /**************************************************************************
  4868. * qla2x00_timer
  4869. *
  4870. * Description:
  4871. * One second timer
  4872. *
  4873. * Context: Interrupt
  4874. ***************************************************************************/
  4875. void
  4876. qla2x00_timer(scsi_qla_host_t *vha)
  4877. {
  4878. unsigned long cpu_flags = 0;
  4879. int start_dpc = 0;
  4880. int index;
  4881. srb_t *sp;
  4882. uint16_t w;
  4883. struct qla_hw_data *ha = vha->hw;
  4884. struct req_que *req;
  4885. if (ha->flags.eeh_busy) {
  4886. ql_dbg(ql_dbg_timer, vha, 0x6000,
  4887. "EEH = %d, restarting timer.\n",
  4888. ha->flags.eeh_busy);
  4889. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4890. return;
  4891. }
  4892. /*
  4893. * Hardware read to raise pending EEH errors during mailbox waits. If
  4894. * the read returns -1 then disable the board.
  4895. */
  4896. if (!pci_channel_offline(ha->pdev)) {
  4897. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  4898. qla2x00_check_reg16_for_disconnect(vha, w);
  4899. }
  4900. /* Make sure qla82xx_watchdog is run only for physical port */
  4901. if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
  4902. if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
  4903. start_dpc++;
  4904. if (IS_QLA82XX(ha))
  4905. qla82xx_watchdog(vha);
  4906. else if (IS_QLA8044(ha))
  4907. qla8044_watchdog(vha);
  4908. }
  4909. if (!vha->vp_idx && IS_QLAFX00(ha))
  4910. qlafx00_timer_routine(vha);
  4911. /* Loop down handler. */
  4912. if (atomic_read(&vha->loop_down_timer) > 0 &&
  4913. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
  4914. !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
  4915. && vha->flags.online) {
  4916. if (atomic_read(&vha->loop_down_timer) ==
  4917. vha->loop_down_abort_time) {
  4918. ql_log(ql_log_info, vha, 0x6008,
  4919. "Loop down - aborting the queues before time expires.\n");
  4920. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  4921. atomic_set(&vha->loop_state, LOOP_DEAD);
  4922. /*
  4923. * Schedule an ISP abort to return any FCP2-device
  4924. * commands.
  4925. */
  4926. /* NPIV - scan physical port only */
  4927. if (!vha->vp_idx) {
  4928. spin_lock_irqsave(&ha->hardware_lock,
  4929. cpu_flags);
  4930. req = ha->req_q_map[0];
  4931. for (index = 1;
  4932. index < req->num_outstanding_cmds;
  4933. index++) {
  4934. fc_port_t *sfcp;
  4935. sp = req->outstanding_cmds[index];
  4936. if (!sp)
  4937. continue;
  4938. if (sp->type != SRB_SCSI_CMD)
  4939. continue;
  4940. sfcp = sp->fcport;
  4941. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  4942. continue;
  4943. if (IS_QLA82XX(ha))
  4944. set_bit(FCOE_CTX_RESET_NEEDED,
  4945. &vha->dpc_flags);
  4946. else
  4947. set_bit(ISP_ABORT_NEEDED,
  4948. &vha->dpc_flags);
  4949. break;
  4950. }
  4951. spin_unlock_irqrestore(&ha->hardware_lock,
  4952. cpu_flags);
  4953. }
  4954. start_dpc++;
  4955. }
  4956. /* if the loop has been down for 4 minutes, reinit adapter */
  4957. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  4958. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  4959. ql_log(ql_log_warn, vha, 0x6009,
  4960. "Loop down - aborting ISP.\n");
  4961. if (IS_QLA82XX(ha))
  4962. set_bit(FCOE_CTX_RESET_NEEDED,
  4963. &vha->dpc_flags);
  4964. else
  4965. set_bit(ISP_ABORT_NEEDED,
  4966. &vha->dpc_flags);
  4967. }
  4968. }
  4969. ql_dbg(ql_dbg_timer, vha, 0x600a,
  4970. "Loop down - seconds remaining %d.\n",
  4971. atomic_read(&vha->loop_down_timer));
  4972. }
  4973. /* Check if beacon LED needs to be blinked for physical host only */
  4974. if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
  4975. /* There is no beacon_blink function for ISP82xx */
  4976. if (!IS_P3P_TYPE(ha)) {
  4977. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  4978. start_dpc++;
  4979. }
  4980. }
  4981. /* Process any deferred work. */
  4982. if (!list_empty(&vha->work_list))
  4983. start_dpc++;
  4984. /* Schedule the DPC routine if needed */
  4985. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  4986. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  4987. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  4988. start_dpc ||
  4989. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  4990. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  4991. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
  4992. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
  4993. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  4994. test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
  4995. ql_dbg(ql_dbg_timer, vha, 0x600b,
  4996. "isp_abort_needed=%d loop_resync_needed=%d "
  4997. "fcport_update_needed=%d start_dpc=%d "
  4998. "reset_marker_needed=%d",
  4999. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
  5000. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
  5001. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
  5002. start_dpc,
  5003. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
  5004. ql_dbg(ql_dbg_timer, vha, 0x600c,
  5005. "beacon_blink_needed=%d isp_unrecoverable=%d "
  5006. "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
  5007. "relogin_needed=%d.\n",
  5008. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
  5009. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
  5010. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
  5011. test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
  5012. test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
  5013. qla2xxx_wake_dpc(vha);
  5014. }
  5015. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  5016. }
  5017. /* Firmware interface routines. */
  5018. #define FW_BLOBS 11
  5019. #define FW_ISP21XX 0
  5020. #define FW_ISP22XX 1
  5021. #define FW_ISP2300 2
  5022. #define FW_ISP2322 3
  5023. #define FW_ISP24XX 4
  5024. #define FW_ISP25XX 5
  5025. #define FW_ISP81XX 6
  5026. #define FW_ISP82XX 7
  5027. #define FW_ISP2031 8
  5028. #define FW_ISP8031 9
  5029. #define FW_ISP27XX 10
  5030. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  5031. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  5032. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  5033. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  5034. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  5035. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  5036. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  5037. #define FW_FILE_ISP82XX "ql8200_fw.bin"
  5038. #define FW_FILE_ISP2031 "ql2600_fw.bin"
  5039. #define FW_FILE_ISP8031 "ql8300_fw.bin"
  5040. #define FW_FILE_ISP27XX "ql2700_fw.bin"
  5041. static DEFINE_MUTEX(qla_fw_lock);
  5042. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  5043. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  5044. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  5045. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  5046. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  5047. { .name = FW_FILE_ISP24XX, },
  5048. { .name = FW_FILE_ISP25XX, },
  5049. { .name = FW_FILE_ISP81XX, },
  5050. { .name = FW_FILE_ISP82XX, },
  5051. { .name = FW_FILE_ISP2031, },
  5052. { .name = FW_FILE_ISP8031, },
  5053. { .name = FW_FILE_ISP27XX, },
  5054. };
  5055. struct fw_blob *
  5056. qla2x00_request_firmware(scsi_qla_host_t *vha)
  5057. {
  5058. struct qla_hw_data *ha = vha->hw;
  5059. struct fw_blob *blob;
  5060. if (IS_QLA2100(ha)) {
  5061. blob = &qla_fw_blobs[FW_ISP21XX];
  5062. } else if (IS_QLA2200(ha)) {
  5063. blob = &qla_fw_blobs[FW_ISP22XX];
  5064. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  5065. blob = &qla_fw_blobs[FW_ISP2300];
  5066. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  5067. blob = &qla_fw_blobs[FW_ISP2322];
  5068. } else if (IS_QLA24XX_TYPE(ha)) {
  5069. blob = &qla_fw_blobs[FW_ISP24XX];
  5070. } else if (IS_QLA25XX(ha)) {
  5071. blob = &qla_fw_blobs[FW_ISP25XX];
  5072. } else if (IS_QLA81XX(ha)) {
  5073. blob = &qla_fw_blobs[FW_ISP81XX];
  5074. } else if (IS_QLA82XX(ha)) {
  5075. blob = &qla_fw_blobs[FW_ISP82XX];
  5076. } else if (IS_QLA2031(ha)) {
  5077. blob = &qla_fw_blobs[FW_ISP2031];
  5078. } else if (IS_QLA8031(ha)) {
  5079. blob = &qla_fw_blobs[FW_ISP8031];
  5080. } else if (IS_QLA27XX(ha)) {
  5081. blob = &qla_fw_blobs[FW_ISP27XX];
  5082. } else {
  5083. return NULL;
  5084. }
  5085. mutex_lock(&qla_fw_lock);
  5086. if (blob->fw)
  5087. goto out;
  5088. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  5089. ql_log(ql_log_warn, vha, 0x0063,
  5090. "Failed to load firmware image (%s).\n", blob->name);
  5091. blob->fw = NULL;
  5092. blob = NULL;
  5093. goto out;
  5094. }
  5095. out:
  5096. mutex_unlock(&qla_fw_lock);
  5097. return blob;
  5098. }
  5099. static void
  5100. qla2x00_release_firmware(void)
  5101. {
  5102. int idx;
  5103. mutex_lock(&qla_fw_lock);
  5104. for (idx = 0; idx < FW_BLOBS; idx++)
  5105. release_firmware(qla_fw_blobs[idx].fw);
  5106. mutex_unlock(&qla_fw_lock);
  5107. }
  5108. static pci_ers_result_t
  5109. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  5110. {
  5111. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  5112. struct qla_hw_data *ha = vha->hw;
  5113. ql_dbg(ql_dbg_aer, vha, 0x9000,
  5114. "PCI error detected, state %x.\n", state);
  5115. switch (state) {
  5116. case pci_channel_io_normal:
  5117. ha->flags.eeh_busy = 0;
  5118. if (ql2xmqsupport) {
  5119. set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
  5120. qla2xxx_wake_dpc(vha);
  5121. }
  5122. return PCI_ERS_RESULT_CAN_RECOVER;
  5123. case pci_channel_io_frozen:
  5124. ha->flags.eeh_busy = 1;
  5125. /* For ISP82XX complete any pending mailbox cmd */
  5126. if (IS_QLA82XX(ha)) {
  5127. ha->flags.isp82xx_fw_hung = 1;
  5128. ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
  5129. qla82xx_clear_pending_mbx(vha);
  5130. }
  5131. qla2x00_free_irqs(vha);
  5132. pci_disable_device(pdev);
  5133. /* Return back all IOs */
  5134. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  5135. if (ql2xmqsupport) {
  5136. set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
  5137. qla2xxx_wake_dpc(vha);
  5138. }
  5139. return PCI_ERS_RESULT_NEED_RESET;
  5140. case pci_channel_io_perm_failure:
  5141. ha->flags.pci_channel_io_perm_failure = 1;
  5142. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  5143. if (ql2xmqsupport) {
  5144. set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
  5145. qla2xxx_wake_dpc(vha);
  5146. }
  5147. return PCI_ERS_RESULT_DISCONNECT;
  5148. }
  5149. return PCI_ERS_RESULT_NEED_RESET;
  5150. }
  5151. static pci_ers_result_t
  5152. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  5153. {
  5154. int risc_paused = 0;
  5155. uint32_t stat;
  5156. unsigned long flags;
  5157. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  5158. struct qla_hw_data *ha = base_vha->hw;
  5159. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  5160. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  5161. if (IS_QLA82XX(ha))
  5162. return PCI_ERS_RESULT_RECOVERED;
  5163. spin_lock_irqsave(&ha->hardware_lock, flags);
  5164. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  5165. stat = RD_REG_DWORD(&reg->hccr);
  5166. if (stat & HCCR_RISC_PAUSE)
  5167. risc_paused = 1;
  5168. } else if (IS_QLA23XX(ha)) {
  5169. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  5170. if (stat & HSR_RISC_PAUSED)
  5171. risc_paused = 1;
  5172. } else if (IS_FWI2_CAPABLE(ha)) {
  5173. stat = RD_REG_DWORD(&reg24->host_status);
  5174. if (stat & HSRX_RISC_PAUSED)
  5175. risc_paused = 1;
  5176. }
  5177. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  5178. if (risc_paused) {
  5179. ql_log(ql_log_info, base_vha, 0x9003,
  5180. "RISC paused -- mmio_enabled, Dumping firmware.\n");
  5181. ha->isp_ops->fw_dump(base_vha, 0);
  5182. return PCI_ERS_RESULT_NEED_RESET;
  5183. } else
  5184. return PCI_ERS_RESULT_RECOVERED;
  5185. }
  5186. static uint32_t
  5187. qla82xx_error_recovery(scsi_qla_host_t *base_vha)
  5188. {
  5189. uint32_t rval = QLA_FUNCTION_FAILED;
  5190. uint32_t drv_active = 0;
  5191. struct qla_hw_data *ha = base_vha->hw;
  5192. int fn;
  5193. struct pci_dev *other_pdev = NULL;
  5194. ql_dbg(ql_dbg_aer, base_vha, 0x9006,
  5195. "Entered %s.\n", __func__);
  5196. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  5197. if (base_vha->flags.online) {
  5198. /* Abort all outstanding commands,
  5199. * so as to be requeued later */
  5200. qla2x00_abort_isp_cleanup(base_vha);
  5201. }
  5202. fn = PCI_FUNC(ha->pdev->devfn);
  5203. while (fn > 0) {
  5204. fn--;
  5205. ql_dbg(ql_dbg_aer, base_vha, 0x9007,
  5206. "Finding pci device at function = 0x%x.\n", fn);
  5207. other_pdev =
  5208. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  5209. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  5210. fn));
  5211. if (!other_pdev)
  5212. continue;
  5213. if (atomic_read(&other_pdev->enable_cnt)) {
  5214. ql_dbg(ql_dbg_aer, base_vha, 0x9008,
  5215. "Found PCI func available and enable at 0x%x.\n",
  5216. fn);
  5217. pci_dev_put(other_pdev);
  5218. break;
  5219. }
  5220. pci_dev_put(other_pdev);
  5221. }
  5222. if (!fn) {
  5223. /* Reset owner */
  5224. ql_dbg(ql_dbg_aer, base_vha, 0x9009,
  5225. "This devfn is reset owner = 0x%x.\n",
  5226. ha->pdev->devfn);
  5227. qla82xx_idc_lock(ha);
  5228. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5229. QLA8XXX_DEV_INITIALIZING);
  5230. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  5231. QLA82XX_IDC_VERSION);
  5232. drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  5233. ql_dbg(ql_dbg_aer, base_vha, 0x900a,
  5234. "drv_active = 0x%x.\n", drv_active);
  5235. qla82xx_idc_unlock(ha);
  5236. /* Reset if device is not already reset
  5237. * drv_active would be 0 if a reset has already been done
  5238. */
  5239. if (drv_active)
  5240. rval = qla82xx_start_firmware(base_vha);
  5241. else
  5242. rval = QLA_SUCCESS;
  5243. qla82xx_idc_lock(ha);
  5244. if (rval != QLA_SUCCESS) {
  5245. ql_log(ql_log_info, base_vha, 0x900b,
  5246. "HW State: FAILED.\n");
  5247. qla82xx_clear_drv_active(ha);
  5248. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5249. QLA8XXX_DEV_FAILED);
  5250. } else {
  5251. ql_log(ql_log_info, base_vha, 0x900c,
  5252. "HW State: READY.\n");
  5253. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5254. QLA8XXX_DEV_READY);
  5255. qla82xx_idc_unlock(ha);
  5256. ha->flags.isp82xx_fw_hung = 0;
  5257. rval = qla82xx_restart_isp(base_vha);
  5258. qla82xx_idc_lock(ha);
  5259. /* Clear driver state register */
  5260. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  5261. qla82xx_set_drv_active(base_vha);
  5262. }
  5263. qla82xx_idc_unlock(ha);
  5264. } else {
  5265. ql_dbg(ql_dbg_aer, base_vha, 0x900d,
  5266. "This devfn is not reset owner = 0x%x.\n",
  5267. ha->pdev->devfn);
  5268. if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  5269. QLA8XXX_DEV_READY)) {
  5270. ha->flags.isp82xx_fw_hung = 0;
  5271. rval = qla82xx_restart_isp(base_vha);
  5272. qla82xx_idc_lock(ha);
  5273. qla82xx_set_drv_active(base_vha);
  5274. qla82xx_idc_unlock(ha);
  5275. }
  5276. }
  5277. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  5278. return rval;
  5279. }
  5280. static pci_ers_result_t
  5281. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  5282. {
  5283. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  5284. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  5285. struct qla_hw_data *ha = base_vha->hw;
  5286. struct rsp_que *rsp;
  5287. int rc, retries = 10;
  5288. ql_dbg(ql_dbg_aer, base_vha, 0x9004,
  5289. "Slot Reset.\n");
  5290. /* Workaround: qla2xxx driver which access hardware earlier
  5291. * needs error state to be pci_channel_io_online.
  5292. * Otherwise mailbox command timesout.
  5293. */
  5294. pdev->error_state = pci_channel_io_normal;
  5295. pci_restore_state(pdev);
  5296. /* pci_restore_state() clears the saved_state flag of the device
  5297. * save restored state which resets saved_state flag
  5298. */
  5299. pci_save_state(pdev);
  5300. if (ha->mem_only)
  5301. rc = pci_enable_device_mem(pdev);
  5302. else
  5303. rc = pci_enable_device(pdev);
  5304. if (rc) {
  5305. ql_log(ql_log_warn, base_vha, 0x9005,
  5306. "Can't re-enable PCI device after reset.\n");
  5307. goto exit_slot_reset;
  5308. }
  5309. rsp = ha->rsp_q_map[0];
  5310. if (qla2x00_request_irqs(ha, rsp))
  5311. goto exit_slot_reset;
  5312. if (ha->isp_ops->pci_config(base_vha))
  5313. goto exit_slot_reset;
  5314. if (IS_QLA82XX(ha)) {
  5315. if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
  5316. ret = PCI_ERS_RESULT_RECOVERED;
  5317. goto exit_slot_reset;
  5318. } else
  5319. goto exit_slot_reset;
  5320. }
  5321. while (ha->flags.mbox_busy && retries--)
  5322. msleep(1000);
  5323. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  5324. if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
  5325. ret = PCI_ERS_RESULT_RECOVERED;
  5326. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  5327. exit_slot_reset:
  5328. ql_dbg(ql_dbg_aer, base_vha, 0x900e,
  5329. "slot_reset return %x.\n", ret);
  5330. return ret;
  5331. }
  5332. static void
  5333. qla2xxx_pci_resume(struct pci_dev *pdev)
  5334. {
  5335. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  5336. struct qla_hw_data *ha = base_vha->hw;
  5337. int ret;
  5338. ql_dbg(ql_dbg_aer, base_vha, 0x900f,
  5339. "pci_resume.\n");
  5340. ret = qla2x00_wait_for_hba_online(base_vha);
  5341. if (ret != QLA_SUCCESS) {
  5342. ql_log(ql_log_fatal, base_vha, 0x9002,
  5343. "The device failed to resume I/O from slot/link_reset.\n");
  5344. }
  5345. pci_cleanup_aer_uncorrect_error_status(pdev);
  5346. ha->flags.eeh_busy = 0;
  5347. }
  5348. static void
  5349. qla83xx_disable_laser(scsi_qla_host_t *vha)
  5350. {
  5351. uint32_t reg, data, fn;
  5352. struct qla_hw_data *ha = vha->hw;
  5353. struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
  5354. /* pci func #/port # */
  5355. ql_dbg(ql_dbg_init, vha, 0x004b,
  5356. "Disabling Laser for hba: %p\n", vha);
  5357. fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
  5358. (BIT_15|BIT_14|BIT_13|BIT_12));
  5359. fn = (fn >> 12);
  5360. if (fn & 1)
  5361. reg = PORT_1_2031;
  5362. else
  5363. reg = PORT_0_2031;
  5364. data = LASER_OFF_2031;
  5365. qla83xx_wr_reg(vha, reg, data);
  5366. }
  5367. static int qla2xxx_map_queues(struct Scsi_Host *shost)
  5368. {
  5369. scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
  5370. return blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev);
  5371. }
  5372. static const struct pci_error_handlers qla2xxx_err_handler = {
  5373. .error_detected = qla2xxx_pci_error_detected,
  5374. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  5375. .slot_reset = qla2xxx_pci_slot_reset,
  5376. .resume = qla2xxx_pci_resume,
  5377. };
  5378. static struct pci_device_id qla2xxx_pci_tbl[] = {
  5379. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  5380. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  5381. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  5382. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  5383. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  5384. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  5385. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  5386. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  5387. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  5388. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  5389. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  5390. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  5391. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  5392. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
  5393. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  5394. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
  5395. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
  5396. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
  5397. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
  5398. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
  5399. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
  5400. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
  5401. { 0 },
  5402. };
  5403. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  5404. static struct pci_driver qla2xxx_pci_driver = {
  5405. .name = QLA2XXX_DRIVER_NAME,
  5406. .driver = {
  5407. .owner = THIS_MODULE,
  5408. },
  5409. .id_table = qla2xxx_pci_tbl,
  5410. .probe = qla2x00_probe_one,
  5411. .remove = qla2x00_remove_one,
  5412. .shutdown = qla2x00_shutdown,
  5413. .err_handler = &qla2xxx_err_handler,
  5414. };
  5415. static const struct file_operations apidev_fops = {
  5416. .owner = THIS_MODULE,
  5417. .llseek = noop_llseek,
  5418. };
  5419. /**
  5420. * qla2x00_module_init - Module initialization.
  5421. **/
  5422. static int __init
  5423. qla2x00_module_init(void)
  5424. {
  5425. int ret = 0;
  5426. /* Allocate cache for SRBs. */
  5427. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  5428. SLAB_HWCACHE_ALIGN, NULL);
  5429. if (srb_cachep == NULL) {
  5430. ql_log(ql_log_fatal, NULL, 0x0001,
  5431. "Unable to allocate SRB cache...Failing load!.\n");
  5432. return -ENOMEM;
  5433. }
  5434. /* Initialize target kmem_cache and mem_pools */
  5435. ret = qlt_init();
  5436. if (ret < 0) {
  5437. kmem_cache_destroy(srb_cachep);
  5438. return ret;
  5439. } else if (ret > 0) {
  5440. /*
  5441. * If initiator mode is explictly disabled by qlt_init(),
  5442. * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
  5443. * performing scsi_scan_target() during LOOP UP event.
  5444. */
  5445. qla2xxx_transport_functions.disable_target_scan = 1;
  5446. qla2xxx_transport_vport_functions.disable_target_scan = 1;
  5447. }
  5448. /* Derive version string. */
  5449. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  5450. if (ql2xextended_error_logging)
  5451. strcat(qla2x00_version_str, "-debug");
  5452. qla2xxx_transport_template =
  5453. fc_attach_transport(&qla2xxx_transport_functions);
  5454. if (!qla2xxx_transport_template) {
  5455. kmem_cache_destroy(srb_cachep);
  5456. ql_log(ql_log_fatal, NULL, 0x0002,
  5457. "fc_attach_transport failed...Failing load!.\n");
  5458. qlt_exit();
  5459. return -ENODEV;
  5460. }
  5461. apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
  5462. if (apidev_major < 0) {
  5463. ql_log(ql_log_fatal, NULL, 0x0003,
  5464. "Unable to register char device %s.\n", QLA2XXX_APIDEV);
  5465. }
  5466. qla2xxx_transport_vport_template =
  5467. fc_attach_transport(&qla2xxx_transport_vport_functions);
  5468. if (!qla2xxx_transport_vport_template) {
  5469. kmem_cache_destroy(srb_cachep);
  5470. qlt_exit();
  5471. fc_release_transport(qla2xxx_transport_template);
  5472. ql_log(ql_log_fatal, NULL, 0x0004,
  5473. "fc_attach_transport vport failed...Failing load!.\n");
  5474. return -ENODEV;
  5475. }
  5476. ql_log(ql_log_info, NULL, 0x0005,
  5477. "QLogic Fibre Channel HBA Driver: %s.\n",
  5478. qla2x00_version_str);
  5479. ret = pci_register_driver(&qla2xxx_pci_driver);
  5480. if (ret) {
  5481. kmem_cache_destroy(srb_cachep);
  5482. qlt_exit();
  5483. fc_release_transport(qla2xxx_transport_template);
  5484. fc_release_transport(qla2xxx_transport_vport_template);
  5485. ql_log(ql_log_fatal, NULL, 0x0006,
  5486. "pci_register_driver failed...ret=%d Failing load!.\n",
  5487. ret);
  5488. }
  5489. return ret;
  5490. }
  5491. /**
  5492. * qla2x00_module_exit - Module cleanup.
  5493. **/
  5494. static void __exit
  5495. qla2x00_module_exit(void)
  5496. {
  5497. unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
  5498. pci_unregister_driver(&qla2xxx_pci_driver);
  5499. qla2x00_release_firmware();
  5500. kmem_cache_destroy(srb_cachep);
  5501. qlt_exit();
  5502. if (ctx_cachep)
  5503. kmem_cache_destroy(ctx_cachep);
  5504. fc_release_transport(qla2xxx_transport_template);
  5505. fc_release_transport(qla2xxx_transport_vport_template);
  5506. }
  5507. module_init(qla2x00_module_init);
  5508. module_exit(qla2x00_module_exit);
  5509. MODULE_AUTHOR("QLogic Corporation");
  5510. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  5511. MODULE_LICENSE("GPL");
  5512. MODULE_VERSION(QLA2XXX_VERSION);
  5513. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  5514. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  5515. MODULE_FIRMWARE(FW_FILE_ISP2300);
  5516. MODULE_FIRMWARE(FW_FILE_ISP2322);
  5517. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  5518. MODULE_FIRMWARE(FW_FILE_ISP25XX);