lpfc_init.c 243 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kthread.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/ctype.h>
  30. #include <linux/aer.h>
  31. #include <scsi/scsi.h>
  32. #include <scsi/scsi_device.h>
  33. #include <scsi/scsi_host.h>
  34. #include <scsi/scsi_transport_fc.h>
  35. #include "lpfc_hw4.h"
  36. #include "lpfc_hw.h"
  37. #include "lpfc_sli.h"
  38. #include "lpfc_sli4.h"
  39. #include "lpfc_nl.h"
  40. #include "lpfc_disc.h"
  41. #include "lpfc_scsi.h"
  42. #include "lpfc.h"
  43. #include "lpfc_logmsg.h"
  44. #include "lpfc_crtn.h"
  45. #include "lpfc_vport.h"
  46. #include "lpfc_version.h"
  47. char *_dump_buf_data;
  48. unsigned long _dump_buf_data_order;
  49. char *_dump_buf_dif;
  50. unsigned long _dump_buf_dif_order;
  51. spinlock_t _dump_buf_lock;
  52. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  53. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  54. static int lpfc_sli4_queue_create(struct lpfc_hba *);
  55. static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
  56. static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
  57. static int lpfc_setup_endian_order(struct lpfc_hba *);
  58. static int lpfc_sli4_read_config(struct lpfc_hba *);
  59. static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
  60. static void lpfc_free_sgl_list(struct lpfc_hba *);
  61. static int lpfc_init_sgl_list(struct lpfc_hba *);
  62. static int lpfc_init_active_sgl_array(struct lpfc_hba *);
  63. static void lpfc_free_active_sgl(struct lpfc_hba *);
  64. static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
  65. static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
  66. static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
  67. static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
  68. static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
  69. static struct scsi_transport_template *lpfc_transport_template = NULL;
  70. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  71. static DEFINE_IDR(lpfc_hba_index);
  72. /**
  73. * lpfc_config_port_prep - Perform lpfc initialization prior to config port
  74. * @phba: pointer to lpfc hba data structure.
  75. *
  76. * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
  77. * mailbox command. It retrieves the revision information from the HBA and
  78. * collects the Vital Product Data (VPD) about the HBA for preparing the
  79. * configuration of the HBA.
  80. *
  81. * Return codes:
  82. * 0 - success.
  83. * -ERESTART - requests the SLI layer to reset the HBA and try again.
  84. * Any other value - indicates an error.
  85. **/
  86. int
  87. lpfc_config_port_prep(struct lpfc_hba *phba)
  88. {
  89. lpfc_vpd_t *vp = &phba->vpd;
  90. int i = 0, rc;
  91. LPFC_MBOXQ_t *pmb;
  92. MAILBOX_t *mb;
  93. char *lpfc_vpd_data = NULL;
  94. uint16_t offset = 0;
  95. static char licensed[56] =
  96. "key unlock for use with gnu public licensed code only\0";
  97. static int init_key = 1;
  98. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  99. if (!pmb) {
  100. phba->link_state = LPFC_HBA_ERROR;
  101. return -ENOMEM;
  102. }
  103. mb = &pmb->u.mb;
  104. phba->link_state = LPFC_INIT_MBX_CMDS;
  105. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  106. if (init_key) {
  107. uint32_t *ptext = (uint32_t *) licensed;
  108. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  109. *ptext = cpu_to_be32(*ptext);
  110. init_key = 0;
  111. }
  112. lpfc_read_nv(phba, pmb);
  113. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  114. sizeof (mb->un.varRDnvp.rsvd3));
  115. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  116. sizeof (licensed));
  117. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  118. if (rc != MBX_SUCCESS) {
  119. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  120. "0324 Config Port initialization "
  121. "error, mbxCmd x%x READ_NVPARM, "
  122. "mbxStatus x%x\n",
  123. mb->mbxCommand, mb->mbxStatus);
  124. mempool_free(pmb, phba->mbox_mem_pool);
  125. return -ERESTART;
  126. }
  127. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  128. sizeof(phba->wwnn));
  129. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  130. sizeof(phba->wwpn));
  131. }
  132. phba->sli3_options = 0x0;
  133. /* Setup and issue mailbox READ REV command */
  134. lpfc_read_rev(phba, pmb);
  135. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  136. if (rc != MBX_SUCCESS) {
  137. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  138. "0439 Adapter failed to init, mbxCmd x%x "
  139. "READ_REV, mbxStatus x%x\n",
  140. mb->mbxCommand, mb->mbxStatus);
  141. mempool_free( pmb, phba->mbox_mem_pool);
  142. return -ERESTART;
  143. }
  144. /*
  145. * The value of rr must be 1 since the driver set the cv field to 1.
  146. * This setting requires the FW to set all revision fields.
  147. */
  148. if (mb->un.varRdRev.rr == 0) {
  149. vp->rev.rBit = 0;
  150. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  151. "0440 Adapter failed to init, READ_REV has "
  152. "missing revision information.\n");
  153. mempool_free(pmb, phba->mbox_mem_pool);
  154. return -ERESTART;
  155. }
  156. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) {
  157. mempool_free(pmb, phba->mbox_mem_pool);
  158. return -EINVAL;
  159. }
  160. /* Save information as VPD data */
  161. vp->rev.rBit = 1;
  162. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  163. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  164. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  165. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  166. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  167. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  168. vp->rev.smRev = mb->un.varRdRev.smRev;
  169. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  170. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  171. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  172. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  173. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  174. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  175. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  176. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  177. /* If the sli feature level is less then 9, we must
  178. * tear down all RPIs and VPIs on link down if NPIV
  179. * is enabled.
  180. */
  181. if (vp->rev.feaLevelHigh < 9)
  182. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  183. if (lpfc_is_LC_HBA(phba->pcidev->device))
  184. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  185. sizeof (phba->RandomData));
  186. /* Get adapter VPD information */
  187. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  188. if (!lpfc_vpd_data)
  189. goto out_free_mbox;
  190. do {
  191. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD);
  192. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  193. if (rc != MBX_SUCCESS) {
  194. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  195. "0441 VPD not present on adapter, "
  196. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  197. mb->mbxCommand, mb->mbxStatus);
  198. mb->un.varDmp.word_cnt = 0;
  199. }
  200. /* dump mem may return a zero when finished or we got a
  201. * mailbox error, either way we are done.
  202. */
  203. if (mb->un.varDmp.word_cnt == 0)
  204. break;
  205. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  206. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  207. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  208. lpfc_vpd_data + offset,
  209. mb->un.varDmp.word_cnt);
  210. offset += mb->un.varDmp.word_cnt;
  211. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  212. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  213. kfree(lpfc_vpd_data);
  214. out_free_mbox:
  215. mempool_free(pmb, phba->mbox_mem_pool);
  216. return 0;
  217. }
  218. /**
  219. * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
  220. * @phba: pointer to lpfc hba data structure.
  221. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  222. *
  223. * This is the completion handler for driver's configuring asynchronous event
  224. * mailbox command to the device. If the mailbox command returns successfully,
  225. * it will set internal async event support flag to 1; otherwise, it will
  226. * set internal async event support flag to 0.
  227. **/
  228. static void
  229. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  230. {
  231. if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS)
  232. phba->temp_sensor_support = 1;
  233. else
  234. phba->temp_sensor_support = 0;
  235. mempool_free(pmboxq, phba->mbox_mem_pool);
  236. return;
  237. }
  238. /**
  239. * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
  240. * @phba: pointer to lpfc hba data structure.
  241. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  242. *
  243. * This is the completion handler for dump mailbox command for getting
  244. * wake up parameters. When this command complete, the response contain
  245. * Option rom version of the HBA. This function translate the version number
  246. * into a human readable string and store it in OptionROMVersion.
  247. **/
  248. static void
  249. lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  250. {
  251. struct prog_id *prg;
  252. uint32_t prog_id_word;
  253. char dist = ' ';
  254. /* character array used for decoding dist type. */
  255. char dist_char[] = "nabx";
  256. if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) {
  257. mempool_free(pmboxq, phba->mbox_mem_pool);
  258. return;
  259. }
  260. prg = (struct prog_id *) &prog_id_word;
  261. /* word 7 contain option rom version */
  262. prog_id_word = pmboxq->u.mb.un.varWords[7];
  263. /* Decode the Option rom version word to a readable string */
  264. if (prg->dist < 4)
  265. dist = dist_char[prg->dist];
  266. if ((prg->dist == 3) && (prg->num == 0))
  267. sprintf(phba->OptionROMVersion, "%d.%d%d",
  268. prg->ver, prg->rev, prg->lev);
  269. else
  270. sprintf(phba->OptionROMVersion, "%d.%d%d%c%d",
  271. prg->ver, prg->rev, prg->lev,
  272. dist, prg->num);
  273. mempool_free(pmboxq, phba->mbox_mem_pool);
  274. return;
  275. }
  276. /**
  277. * lpfc_config_port_post - Perform lpfc initialization after config port
  278. * @phba: pointer to lpfc hba data structure.
  279. *
  280. * This routine will do LPFC initialization after the CONFIG_PORT mailbox
  281. * command call. It performs all internal resource and state setups on the
  282. * port: post IOCB buffers, enable appropriate host interrupt attentions,
  283. * ELS ring timers, etc.
  284. *
  285. * Return codes
  286. * 0 - success.
  287. * Any other value - error.
  288. **/
  289. int
  290. lpfc_config_port_post(struct lpfc_hba *phba)
  291. {
  292. struct lpfc_vport *vport = phba->pport;
  293. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  294. LPFC_MBOXQ_t *pmb;
  295. MAILBOX_t *mb;
  296. struct lpfc_dmabuf *mp;
  297. struct lpfc_sli *psli = &phba->sli;
  298. uint32_t status, timeout;
  299. int i, j;
  300. int rc;
  301. spin_lock_irq(&phba->hbalock);
  302. /*
  303. * If the Config port completed correctly the HBA is not
  304. * over heated any more.
  305. */
  306. if (phba->over_temp_state == HBA_OVER_TEMP)
  307. phba->over_temp_state = HBA_NORMAL_TEMP;
  308. spin_unlock_irq(&phba->hbalock);
  309. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  310. if (!pmb) {
  311. phba->link_state = LPFC_HBA_ERROR;
  312. return -ENOMEM;
  313. }
  314. mb = &pmb->u.mb;
  315. /* Get login parameters for NID. */
  316. lpfc_read_sparam(phba, pmb, 0);
  317. pmb->vport = vport;
  318. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  319. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  320. "0448 Adapter failed init, mbxCmd x%x "
  321. "READ_SPARM mbxStatus x%x\n",
  322. mb->mbxCommand, mb->mbxStatus);
  323. phba->link_state = LPFC_HBA_ERROR;
  324. mp = (struct lpfc_dmabuf *) pmb->context1;
  325. mempool_free( pmb, phba->mbox_mem_pool);
  326. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  327. kfree(mp);
  328. return -EIO;
  329. }
  330. mp = (struct lpfc_dmabuf *) pmb->context1;
  331. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  332. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  333. kfree(mp);
  334. pmb->context1 = NULL;
  335. if (phba->cfg_soft_wwnn)
  336. u64_to_wwn(phba->cfg_soft_wwnn,
  337. vport->fc_sparam.nodeName.u.wwn);
  338. if (phba->cfg_soft_wwpn)
  339. u64_to_wwn(phba->cfg_soft_wwpn,
  340. vport->fc_sparam.portName.u.wwn);
  341. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  342. sizeof (struct lpfc_name));
  343. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  344. sizeof (struct lpfc_name));
  345. /* Update the fc_host data structures with new wwn. */
  346. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  347. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  348. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  349. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  350. /* This should be consolidated into parse_vpd ? - mr */
  351. if (phba->SerialNumber[0] == 0) {
  352. uint8_t *outptr;
  353. outptr = &vport->fc_nodename.u.s.IEEE[0];
  354. for (i = 0; i < 12; i++) {
  355. status = *outptr++;
  356. j = ((status & 0xf0) >> 4);
  357. if (j <= 9)
  358. phba->SerialNumber[i] =
  359. (char)((uint8_t) 0x30 + (uint8_t) j);
  360. else
  361. phba->SerialNumber[i] =
  362. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  363. i++;
  364. j = (status & 0xf);
  365. if (j <= 9)
  366. phba->SerialNumber[i] =
  367. (char)((uint8_t) 0x30 + (uint8_t) j);
  368. else
  369. phba->SerialNumber[i] =
  370. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  371. }
  372. }
  373. lpfc_read_config(phba, pmb);
  374. pmb->vport = vport;
  375. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  376. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  377. "0453 Adapter failed to init, mbxCmd x%x "
  378. "READ_CONFIG, mbxStatus x%x\n",
  379. mb->mbxCommand, mb->mbxStatus);
  380. phba->link_state = LPFC_HBA_ERROR;
  381. mempool_free( pmb, phba->mbox_mem_pool);
  382. return -EIO;
  383. }
  384. /* Check if the port is disabled */
  385. lpfc_sli_read_link_ste(phba);
  386. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  387. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  388. phba->cfg_hba_queue_depth =
  389. (mb->un.varRdConfig.max_xri + 1) -
  390. lpfc_sli4_get_els_iocb_cnt(phba);
  391. phba->lmt = mb->un.varRdConfig.lmt;
  392. /* Get the default values for Model Name and Description */
  393. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  394. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  395. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  396. && !(phba->lmt & LMT_1Gb))
  397. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  398. && !(phba->lmt & LMT_2Gb))
  399. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  400. && !(phba->lmt & LMT_4Gb))
  401. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  402. && !(phba->lmt & LMT_8Gb))
  403. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  404. && !(phba->lmt & LMT_10Gb))) {
  405. /* Reset link speed to auto */
  406. lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
  407. "1302 Invalid speed for this board: "
  408. "Reset link speed to auto: x%x\n",
  409. phba->cfg_link_speed);
  410. phba->cfg_link_speed = LINK_SPEED_AUTO;
  411. }
  412. phba->link_state = LPFC_LINK_DOWN;
  413. /* Only process IOCBs on ELS ring till hba_state is READY */
  414. if (psli->ring[psli->extra_ring].cmdringaddr)
  415. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  416. if (psli->ring[psli->fcp_ring].cmdringaddr)
  417. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  418. if (psli->ring[psli->next_ring].cmdringaddr)
  419. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  420. /* Post receive buffers for desired rings */
  421. if (phba->sli_rev != 3)
  422. lpfc_post_rcv_buf(phba);
  423. /*
  424. * Configure HBA MSI-X attention conditions to messages if MSI-X mode
  425. */
  426. if (phba->intr_type == MSIX) {
  427. rc = lpfc_config_msi(phba, pmb);
  428. if (rc) {
  429. mempool_free(pmb, phba->mbox_mem_pool);
  430. return -EIO;
  431. }
  432. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  433. if (rc != MBX_SUCCESS) {
  434. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  435. "0352 Config MSI mailbox command "
  436. "failed, mbxCmd x%x, mbxStatus x%x\n",
  437. pmb->u.mb.mbxCommand,
  438. pmb->u.mb.mbxStatus);
  439. mempool_free(pmb, phba->mbox_mem_pool);
  440. return -EIO;
  441. }
  442. }
  443. spin_lock_irq(&phba->hbalock);
  444. /* Initialize ERATT handling flag */
  445. phba->hba_flag &= ~HBA_ERATT_HANDLED;
  446. /* Enable appropriate host interrupts */
  447. status = readl(phba->HCregaddr);
  448. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  449. if (psli->num_rings > 0)
  450. status |= HC_R0INT_ENA;
  451. if (psli->num_rings > 1)
  452. status |= HC_R1INT_ENA;
  453. if (psli->num_rings > 2)
  454. status |= HC_R2INT_ENA;
  455. if (psli->num_rings > 3)
  456. status |= HC_R3INT_ENA;
  457. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  458. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  459. status &= ~(HC_R0INT_ENA);
  460. writel(status, phba->HCregaddr);
  461. readl(phba->HCregaddr); /* flush */
  462. spin_unlock_irq(&phba->hbalock);
  463. /* Set up ring-0 (ELS) timer */
  464. timeout = phba->fc_ratov * 2;
  465. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  466. /* Set up heart beat (HB) timer */
  467. mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  468. phba->hb_outstanding = 0;
  469. phba->last_completion_time = jiffies;
  470. /* Set up error attention (ERATT) polling timer */
  471. mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL);
  472. if (phba->hba_flag & LINK_DISABLED) {
  473. lpfc_printf_log(phba,
  474. KERN_ERR, LOG_INIT,
  475. "2598 Adapter Link is disabled.\n");
  476. lpfc_down_link(phba, pmb);
  477. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  478. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  479. if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
  480. lpfc_printf_log(phba,
  481. KERN_ERR, LOG_INIT,
  482. "2599 Adapter failed to issue DOWN_LINK"
  483. " mbox command rc 0x%x\n", rc);
  484. mempool_free(pmb, phba->mbox_mem_pool);
  485. return -EIO;
  486. }
  487. } else {
  488. lpfc_init_link(phba, pmb, phba->cfg_topology,
  489. phba->cfg_link_speed);
  490. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  491. lpfc_set_loopback_flag(phba);
  492. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  493. if (rc != MBX_SUCCESS) {
  494. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  495. "0454 Adapter failed to init, mbxCmd x%x "
  496. "INIT_LINK, mbxStatus x%x\n",
  497. mb->mbxCommand, mb->mbxStatus);
  498. /* Clear all interrupt enable conditions */
  499. writel(0, phba->HCregaddr);
  500. readl(phba->HCregaddr); /* flush */
  501. /* Clear all pending interrupts */
  502. writel(0xffffffff, phba->HAregaddr);
  503. readl(phba->HAregaddr); /* flush */
  504. phba->link_state = LPFC_HBA_ERROR;
  505. if (rc != MBX_BUSY)
  506. mempool_free(pmb, phba->mbox_mem_pool);
  507. return -EIO;
  508. }
  509. }
  510. /* MBOX buffer will be freed in mbox compl */
  511. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  512. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  513. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  514. pmb->vport = phba->pport;
  515. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  516. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  517. lpfc_printf_log(phba,
  518. KERN_ERR,
  519. LOG_INIT,
  520. "0456 Adapter failed to issue "
  521. "ASYNCEVT_ENABLE mbox status x%x\n",
  522. rc);
  523. mempool_free(pmb, phba->mbox_mem_pool);
  524. }
  525. /* Get Option rom version */
  526. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  527. lpfc_dump_wakeup_param(phba, pmb);
  528. pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl;
  529. pmb->vport = phba->pport;
  530. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  531. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  532. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed "
  533. "to get Option ROM version status x%x\n", rc);
  534. mempool_free(pmb, phba->mbox_mem_pool);
  535. }
  536. return 0;
  537. }
  538. /**
  539. * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
  540. * @phba: pointer to lpfc HBA data structure.
  541. *
  542. * This routine will do LPFC uninitialization before the HBA is reset when
  543. * bringing down the SLI Layer.
  544. *
  545. * Return codes
  546. * 0 - success.
  547. * Any other value - error.
  548. **/
  549. int
  550. lpfc_hba_down_prep(struct lpfc_hba *phba)
  551. {
  552. struct lpfc_vport **vports;
  553. int i;
  554. if (phba->sli_rev <= LPFC_SLI_REV3) {
  555. /* Disable interrupts */
  556. writel(0, phba->HCregaddr);
  557. readl(phba->HCregaddr); /* flush */
  558. }
  559. if (phba->pport->load_flag & FC_UNLOADING)
  560. lpfc_cleanup_discovery_resources(phba->pport);
  561. else {
  562. vports = lpfc_create_vport_work_array(phba);
  563. if (vports != NULL)
  564. for (i = 0; i <= phba->max_vports &&
  565. vports[i] != NULL; i++)
  566. lpfc_cleanup_discovery_resources(vports[i]);
  567. lpfc_destroy_vport_work_array(phba, vports);
  568. }
  569. return 0;
  570. }
  571. /**
  572. * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
  573. * @phba: pointer to lpfc HBA data structure.
  574. *
  575. * This routine will do uninitialization after the HBA is reset when bring
  576. * down the SLI Layer.
  577. *
  578. * Return codes
  579. * 0 - success.
  580. * Any other value - error.
  581. **/
  582. static int
  583. lpfc_hba_down_post_s3(struct lpfc_hba *phba)
  584. {
  585. struct lpfc_sli *psli = &phba->sli;
  586. struct lpfc_sli_ring *pring;
  587. struct lpfc_dmabuf *mp, *next_mp;
  588. LIST_HEAD(completions);
  589. int i;
  590. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  591. lpfc_sli_hbqbuf_free_all(phba);
  592. else {
  593. /* Cleanup preposted buffers on the ELS ring */
  594. pring = &psli->ring[LPFC_ELS_RING];
  595. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  596. list_del(&mp->list);
  597. pring->postbufq_cnt--;
  598. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  599. kfree(mp);
  600. }
  601. }
  602. spin_lock_irq(&phba->hbalock);
  603. for (i = 0; i < psli->num_rings; i++) {
  604. pring = &psli->ring[i];
  605. /* At this point in time the HBA is either reset or DOA. Either
  606. * way, nothing should be on txcmplq as it will NEVER complete.
  607. */
  608. list_splice_init(&pring->txcmplq, &completions);
  609. pring->txcmplq_cnt = 0;
  610. spin_unlock_irq(&phba->hbalock);
  611. /* Cancel all the IOCBs from the completions list */
  612. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  613. IOERR_SLI_ABORTED);
  614. lpfc_sli_abort_iocb_ring(phba, pring);
  615. spin_lock_irq(&phba->hbalock);
  616. }
  617. spin_unlock_irq(&phba->hbalock);
  618. return 0;
  619. }
  620. /**
  621. * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
  622. * @phba: pointer to lpfc HBA data structure.
  623. *
  624. * This routine will do uninitialization after the HBA is reset when bring
  625. * down the SLI Layer.
  626. *
  627. * Return codes
  628. * 0 - success.
  629. * Any other value - error.
  630. **/
  631. static int
  632. lpfc_hba_down_post_s4(struct lpfc_hba *phba)
  633. {
  634. struct lpfc_scsi_buf *psb, *psb_next;
  635. LIST_HEAD(aborts);
  636. int ret;
  637. unsigned long iflag = 0;
  638. ret = lpfc_hba_down_post_s3(phba);
  639. if (ret)
  640. return ret;
  641. /* At this point in time the HBA is either reset or DOA. Either
  642. * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
  643. * on the lpfc_sgl_list so that it can either be freed if the
  644. * driver is unloading or reposted if the driver is restarting
  645. * the port.
  646. */
  647. spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
  648. /* scsl_buf_list */
  649. /* abts_sgl_list_lock required because worker thread uses this
  650. * list.
  651. */
  652. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  653. list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
  654. &phba->sli4_hba.lpfc_sgl_list);
  655. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  656. /* abts_scsi_buf_list_lock required because worker thread uses this
  657. * list.
  658. */
  659. spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  660. list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
  661. &aborts);
  662. spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
  663. spin_unlock_irq(&phba->hbalock);
  664. list_for_each_entry_safe(psb, psb_next, &aborts, list) {
  665. psb->pCmd = NULL;
  666. psb->status = IOSTAT_SUCCESS;
  667. }
  668. spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
  669. list_splice(&aborts, &phba->lpfc_scsi_buf_list);
  670. spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
  671. return 0;
  672. }
  673. /**
  674. * lpfc_hba_down_post - Wrapper func for hba down post routine
  675. * @phba: pointer to lpfc HBA data structure.
  676. *
  677. * This routine wraps the actual SLI3 or SLI4 routine for performing
  678. * uninitialization after the HBA is reset when bring down the SLI Layer.
  679. *
  680. * Return codes
  681. * 0 - success.
  682. * Any other value - error.
  683. **/
  684. int
  685. lpfc_hba_down_post(struct lpfc_hba *phba)
  686. {
  687. return (*phba->lpfc_hba_down_post)(phba);
  688. }
  689. /**
  690. * lpfc_hb_timeout - The HBA-timer timeout handler
  691. * @ptr: unsigned long holds the pointer to lpfc hba data structure.
  692. *
  693. * This is the HBA-timer timeout handler registered to the lpfc driver. When
  694. * this timer fires, a HBA timeout event shall be posted to the lpfc driver
  695. * work-port-events bitmap and the worker thread is notified. This timeout
  696. * event will be used by the worker thread to invoke the actual timeout
  697. * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
  698. * be performed in the timeout handler and the HBA timeout event bit shall
  699. * be cleared by the worker thread after it has taken the event bitmap out.
  700. **/
  701. static void
  702. lpfc_hb_timeout(unsigned long ptr)
  703. {
  704. struct lpfc_hba *phba;
  705. uint32_t tmo_posted;
  706. unsigned long iflag;
  707. phba = (struct lpfc_hba *)ptr;
  708. /* Check for heart beat timeout conditions */
  709. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  710. tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO;
  711. if (!tmo_posted)
  712. phba->pport->work_port_events |= WORKER_HB_TMO;
  713. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  714. /* Tell the worker thread there is work to do */
  715. if (!tmo_posted)
  716. lpfc_worker_wake_up(phba);
  717. return;
  718. }
  719. /**
  720. * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
  721. * @phba: pointer to lpfc hba data structure.
  722. * @pmboxq: pointer to the driver internal queue element for mailbox command.
  723. *
  724. * This is the callback function to the lpfc heart-beat mailbox command.
  725. * If configured, the lpfc driver issues the heart-beat mailbox command to
  726. * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
  727. * heart-beat mailbox command is issued, the driver shall set up heart-beat
  728. * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
  729. * heart-beat outstanding state. Once the mailbox command comes back and
  730. * no error conditions detected, the heart-beat mailbox command timer is
  731. * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
  732. * state is cleared for the next heart-beat. If the timer expired with the
  733. * heart-beat outstanding state set, the driver will put the HBA offline.
  734. **/
  735. static void
  736. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  737. {
  738. unsigned long drvr_flag;
  739. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  740. phba->hb_outstanding = 0;
  741. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  742. /* Check and reset heart-beat timer is necessary */
  743. mempool_free(pmboxq, phba->mbox_mem_pool);
  744. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  745. !(phba->link_state == LPFC_HBA_ERROR) &&
  746. !(phba->pport->load_flag & FC_UNLOADING))
  747. mod_timer(&phba->hb_tmofunc,
  748. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  749. return;
  750. }
  751. /**
  752. * lpfc_hb_timeout_handler - The HBA-timer timeout handler
  753. * @phba: pointer to lpfc hba data structure.
  754. *
  755. * This is the actual HBA-timer timeout handler to be invoked by the worker
  756. * thread whenever the HBA timer fired and HBA-timeout event posted. This
  757. * handler performs any periodic operations needed for the device. If such
  758. * periodic event has already been attended to either in the interrupt handler
  759. * or by processing slow-ring or fast-ring events within the HBA-timer
  760. * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
  761. * the timer for the next timeout period. If lpfc heart-beat mailbox command
  762. * is configured and there is no heart-beat mailbox command outstanding, a
  763. * heart-beat mailbox is issued and timer set properly. Otherwise, if there
  764. * has been a heart-beat mailbox command outstanding, the HBA shall be put
  765. * to offline.
  766. **/
  767. void
  768. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  769. {
  770. struct lpfc_vport **vports;
  771. LPFC_MBOXQ_t *pmboxq;
  772. struct lpfc_dmabuf *buf_ptr;
  773. int retval, i;
  774. struct lpfc_sli *psli = &phba->sli;
  775. LIST_HEAD(completions);
  776. vports = lpfc_create_vport_work_array(phba);
  777. if (vports != NULL)
  778. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  779. lpfc_rcv_seq_check_edtov(vports[i]);
  780. lpfc_destroy_vport_work_array(phba, vports);
  781. if ((phba->link_state == LPFC_HBA_ERROR) ||
  782. (phba->pport->load_flag & FC_UNLOADING) ||
  783. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  784. return;
  785. spin_lock_irq(&phba->pport->work_port_lock);
  786. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  787. jiffies)) {
  788. spin_unlock_irq(&phba->pport->work_port_lock);
  789. if (!phba->hb_outstanding)
  790. mod_timer(&phba->hb_tmofunc,
  791. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  792. else
  793. mod_timer(&phba->hb_tmofunc,
  794. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  795. return;
  796. }
  797. spin_unlock_irq(&phba->pport->work_port_lock);
  798. if (phba->elsbuf_cnt &&
  799. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  800. spin_lock_irq(&phba->hbalock);
  801. list_splice_init(&phba->elsbuf, &completions);
  802. phba->elsbuf_cnt = 0;
  803. phba->elsbuf_prev_cnt = 0;
  804. spin_unlock_irq(&phba->hbalock);
  805. while (!list_empty(&completions)) {
  806. list_remove_head(&completions, buf_ptr,
  807. struct lpfc_dmabuf, list);
  808. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  809. kfree(buf_ptr);
  810. }
  811. }
  812. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  813. /* If there is no heart beat outstanding, issue a heartbeat command */
  814. if (phba->cfg_enable_hba_heartbeat) {
  815. if (!phba->hb_outstanding) {
  816. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  817. if (!pmboxq) {
  818. mod_timer(&phba->hb_tmofunc,
  819. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  820. return;
  821. }
  822. lpfc_heart_beat(phba, pmboxq);
  823. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  824. pmboxq->vport = phba->pport;
  825. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  826. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  827. mempool_free(pmboxq, phba->mbox_mem_pool);
  828. mod_timer(&phba->hb_tmofunc,
  829. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  830. return;
  831. }
  832. mod_timer(&phba->hb_tmofunc,
  833. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  834. phba->hb_outstanding = 1;
  835. return;
  836. } else {
  837. /*
  838. * If heart beat timeout called with hb_outstanding set
  839. * we need to take the HBA offline.
  840. */
  841. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  842. "0459 Adapter heartbeat failure, "
  843. "taking this port offline.\n");
  844. spin_lock_irq(&phba->hbalock);
  845. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  846. spin_unlock_irq(&phba->hbalock);
  847. lpfc_offline_prep(phba);
  848. lpfc_offline(phba);
  849. lpfc_unblock_mgmt_io(phba);
  850. phba->link_state = LPFC_HBA_ERROR;
  851. lpfc_hba_down_post(phba);
  852. }
  853. }
  854. }
  855. /**
  856. * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
  857. * @phba: pointer to lpfc hba data structure.
  858. *
  859. * This routine is called to bring the HBA offline when HBA hardware error
  860. * other than Port Error 6 has been detected.
  861. **/
  862. static void
  863. lpfc_offline_eratt(struct lpfc_hba *phba)
  864. {
  865. struct lpfc_sli *psli = &phba->sli;
  866. spin_lock_irq(&phba->hbalock);
  867. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  868. spin_unlock_irq(&phba->hbalock);
  869. lpfc_offline_prep(phba);
  870. lpfc_offline(phba);
  871. lpfc_reset_barrier(phba);
  872. spin_lock_irq(&phba->hbalock);
  873. lpfc_sli_brdreset(phba);
  874. spin_unlock_irq(&phba->hbalock);
  875. lpfc_hba_down_post(phba);
  876. lpfc_sli_brdready(phba, HS_MBRDY);
  877. lpfc_unblock_mgmt_io(phba);
  878. phba->link_state = LPFC_HBA_ERROR;
  879. return;
  880. }
  881. /**
  882. * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
  883. * @phba: pointer to lpfc hba data structure.
  884. *
  885. * This routine is called to bring a SLI4 HBA offline when HBA hardware error
  886. * other than Port Error 6 has been detected.
  887. **/
  888. static void
  889. lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
  890. {
  891. lpfc_offline_prep(phba);
  892. lpfc_offline(phba);
  893. lpfc_sli4_brdreset(phba);
  894. lpfc_hba_down_post(phba);
  895. lpfc_sli4_post_status_check(phba);
  896. lpfc_unblock_mgmt_io(phba);
  897. phba->link_state = LPFC_HBA_ERROR;
  898. }
  899. /**
  900. * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
  901. * @phba: pointer to lpfc hba data structure.
  902. *
  903. * This routine is invoked to handle the deferred HBA hardware error
  904. * conditions. This type of error is indicated by HBA by setting ER1
  905. * and another ER bit in the host status register. The driver will
  906. * wait until the ER1 bit clears before handling the error condition.
  907. **/
  908. static void
  909. lpfc_handle_deferred_eratt(struct lpfc_hba *phba)
  910. {
  911. uint32_t old_host_status = phba->work_hs;
  912. struct lpfc_sli_ring *pring;
  913. struct lpfc_sli *psli = &phba->sli;
  914. /* If the pci channel is offline, ignore possible errors,
  915. * since we cannot communicate with the pci card anyway.
  916. */
  917. if (pci_channel_offline(phba->pcidev)) {
  918. spin_lock_irq(&phba->hbalock);
  919. phba->hba_flag &= ~DEFER_ERATT;
  920. spin_unlock_irq(&phba->hbalock);
  921. return;
  922. }
  923. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  924. "0479 Deferred Adapter Hardware Error "
  925. "Data: x%x x%x x%x\n",
  926. phba->work_hs,
  927. phba->work_status[0], phba->work_status[1]);
  928. spin_lock_irq(&phba->hbalock);
  929. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  930. spin_unlock_irq(&phba->hbalock);
  931. /*
  932. * Firmware stops when it triggred erratt. That could cause the I/Os
  933. * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
  934. * SCSI layer retry it after re-establishing link.
  935. */
  936. pring = &psli->ring[psli->fcp_ring];
  937. lpfc_sli_abort_iocb_ring(phba, pring);
  938. /*
  939. * There was a firmware error. Take the hba offline and then
  940. * attempt to restart it.
  941. */
  942. lpfc_offline_prep(phba);
  943. lpfc_offline(phba);
  944. /* Wait for the ER1 bit to clear.*/
  945. while (phba->work_hs & HS_FFER1) {
  946. msleep(100);
  947. phba->work_hs = readl(phba->HSregaddr);
  948. /* If driver is unloading let the worker thread continue */
  949. if (phba->pport->load_flag & FC_UNLOADING) {
  950. phba->work_hs = 0;
  951. break;
  952. }
  953. }
  954. /*
  955. * This is to ptrotect against a race condition in which
  956. * first write to the host attention register clear the
  957. * host status register.
  958. */
  959. if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING)))
  960. phba->work_hs = old_host_status & ~HS_FFER1;
  961. spin_lock_irq(&phba->hbalock);
  962. phba->hba_flag &= ~DEFER_ERATT;
  963. spin_unlock_irq(&phba->hbalock);
  964. phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
  965. phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
  966. }
  967. static void
  968. lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba)
  969. {
  970. struct lpfc_board_event_header board_event;
  971. struct Scsi_Host *shost;
  972. board_event.event_type = FC_REG_BOARD_EVENT;
  973. board_event.subcategory = LPFC_EVENT_PORTINTERR;
  974. shost = lpfc_shost_from_vport(phba->pport);
  975. fc_host_post_vendor_event(shost, fc_get_event_number(),
  976. sizeof(board_event),
  977. (char *) &board_event,
  978. LPFC_NL_VENDOR_ID);
  979. }
  980. /**
  981. * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
  982. * @phba: pointer to lpfc hba data structure.
  983. *
  984. * This routine is invoked to handle the following HBA hardware error
  985. * conditions:
  986. * 1 - HBA error attention interrupt
  987. * 2 - DMA ring index out of range
  988. * 3 - Mailbox command came back as unknown
  989. **/
  990. static void
  991. lpfc_handle_eratt_s3(struct lpfc_hba *phba)
  992. {
  993. struct lpfc_vport *vport = phba->pport;
  994. struct lpfc_sli *psli = &phba->sli;
  995. struct lpfc_sli_ring *pring;
  996. uint32_t event_data;
  997. unsigned long temperature;
  998. struct temp_event temp_event_data;
  999. struct Scsi_Host *shost;
  1000. /* If the pci channel is offline, ignore possible errors,
  1001. * since we cannot communicate with the pci card anyway.
  1002. */
  1003. if (pci_channel_offline(phba->pcidev)) {
  1004. spin_lock_irq(&phba->hbalock);
  1005. phba->hba_flag &= ~DEFER_ERATT;
  1006. spin_unlock_irq(&phba->hbalock);
  1007. return;
  1008. }
  1009. /* If resets are disabled then leave the HBA alone and return */
  1010. if (!phba->cfg_enable_hba_reset)
  1011. return;
  1012. /* Send an internal error event to mgmt application */
  1013. lpfc_board_errevt_to_mgmt(phba);
  1014. if (phba->hba_flag & DEFER_ERATT)
  1015. lpfc_handle_deferred_eratt(phba);
  1016. if (phba->work_hs & HS_FFER6) {
  1017. /* Re-establishing Link */
  1018. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1019. "1301 Re-establishing Link "
  1020. "Data: x%x x%x x%x\n",
  1021. phba->work_hs,
  1022. phba->work_status[0], phba->work_status[1]);
  1023. spin_lock_irq(&phba->hbalock);
  1024. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  1025. spin_unlock_irq(&phba->hbalock);
  1026. /*
  1027. * Firmware stops when it triggled erratt with HS_FFER6.
  1028. * That could cause the I/Os dropped by the firmware.
  1029. * Error iocb (I/O) on txcmplq and let the SCSI layer
  1030. * retry it after re-establishing link.
  1031. */
  1032. pring = &psli->ring[psli->fcp_ring];
  1033. lpfc_sli_abort_iocb_ring(phba, pring);
  1034. /*
  1035. * There was a firmware error. Take the hba offline and then
  1036. * attempt to restart it.
  1037. */
  1038. lpfc_offline_prep(phba);
  1039. lpfc_offline(phba);
  1040. lpfc_sli_brdrestart(phba);
  1041. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  1042. lpfc_unblock_mgmt_io(phba);
  1043. return;
  1044. }
  1045. lpfc_unblock_mgmt_io(phba);
  1046. } else if (phba->work_hs & HS_CRIT_TEMP) {
  1047. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  1048. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  1049. temp_event_data.event_code = LPFC_CRIT_TEMP;
  1050. temp_event_data.data = (uint32_t)temperature;
  1051. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1052. "0406 Adapter maximum temperature exceeded "
  1053. "(%ld), taking this port offline "
  1054. "Data: x%x x%x x%x\n",
  1055. temperature, phba->work_hs,
  1056. phba->work_status[0], phba->work_status[1]);
  1057. shost = lpfc_shost_from_vport(phba->pport);
  1058. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1059. sizeof(temp_event_data),
  1060. (char *) &temp_event_data,
  1061. SCSI_NL_VID_TYPE_PCI
  1062. | PCI_VENDOR_ID_EMULEX);
  1063. spin_lock_irq(&phba->hbalock);
  1064. phba->over_temp_state = HBA_OVER_TEMP;
  1065. spin_unlock_irq(&phba->hbalock);
  1066. lpfc_offline_eratt(phba);
  1067. } else {
  1068. /* The if clause above forces this code path when the status
  1069. * failure is a value other than FFER6. Do not call the offline
  1070. * twice. This is the adapter hardware error path.
  1071. */
  1072. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1073. "0457 Adapter Hardware Error "
  1074. "Data: x%x x%x x%x\n",
  1075. phba->work_hs,
  1076. phba->work_status[0], phba->work_status[1]);
  1077. event_data = FC_REG_DUMP_EVENT;
  1078. shost = lpfc_shost_from_vport(vport);
  1079. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1080. sizeof(event_data), (char *) &event_data,
  1081. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1082. lpfc_offline_eratt(phba);
  1083. }
  1084. return;
  1085. }
  1086. /**
  1087. * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
  1088. * @phba: pointer to lpfc hba data structure.
  1089. *
  1090. * This routine is invoked to handle the SLI4 HBA hardware error attention
  1091. * conditions.
  1092. **/
  1093. static void
  1094. lpfc_handle_eratt_s4(struct lpfc_hba *phba)
  1095. {
  1096. struct lpfc_vport *vport = phba->pport;
  1097. uint32_t event_data;
  1098. struct Scsi_Host *shost;
  1099. /* If the pci channel is offline, ignore possible errors, since
  1100. * we cannot communicate with the pci card anyway.
  1101. */
  1102. if (pci_channel_offline(phba->pcidev))
  1103. return;
  1104. /* If resets are disabled then leave the HBA alone and return */
  1105. if (!phba->cfg_enable_hba_reset)
  1106. return;
  1107. /* Send an internal error event to mgmt application */
  1108. lpfc_board_errevt_to_mgmt(phba);
  1109. /* For now, the actual action for SLI4 device handling is not
  1110. * specified yet, just treated it as adaptor hardware failure
  1111. */
  1112. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1113. "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n",
  1114. phba->work_status[0], phba->work_status[1]);
  1115. event_data = FC_REG_DUMP_EVENT;
  1116. shost = lpfc_shost_from_vport(vport);
  1117. fc_host_post_vendor_event(shost, fc_get_event_number(),
  1118. sizeof(event_data), (char *) &event_data,
  1119. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  1120. lpfc_sli4_offline_eratt(phba);
  1121. }
  1122. /**
  1123. * lpfc_handle_eratt - Wrapper func for handling hba error attention
  1124. * @phba: pointer to lpfc HBA data structure.
  1125. *
  1126. * This routine wraps the actual SLI3 or SLI4 hba error attention handling
  1127. * routine from the API jump table function pointer from the lpfc_hba struct.
  1128. *
  1129. * Return codes
  1130. * 0 - success.
  1131. * Any other value - error.
  1132. **/
  1133. void
  1134. lpfc_handle_eratt(struct lpfc_hba *phba)
  1135. {
  1136. (*phba->lpfc_handle_eratt)(phba);
  1137. }
  1138. /**
  1139. * lpfc_handle_latt - The HBA link event handler
  1140. * @phba: pointer to lpfc hba data structure.
  1141. *
  1142. * This routine is invoked from the worker thread to handle a HBA host
  1143. * attention link event.
  1144. **/
  1145. void
  1146. lpfc_handle_latt(struct lpfc_hba *phba)
  1147. {
  1148. struct lpfc_vport *vport = phba->pport;
  1149. struct lpfc_sli *psli = &phba->sli;
  1150. LPFC_MBOXQ_t *pmb;
  1151. volatile uint32_t control;
  1152. struct lpfc_dmabuf *mp;
  1153. int rc = 0;
  1154. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1155. if (!pmb) {
  1156. rc = 1;
  1157. goto lpfc_handle_latt_err_exit;
  1158. }
  1159. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1160. if (!mp) {
  1161. rc = 2;
  1162. goto lpfc_handle_latt_free_pmb;
  1163. }
  1164. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1165. if (!mp->virt) {
  1166. rc = 3;
  1167. goto lpfc_handle_latt_free_mp;
  1168. }
  1169. /* Cleanup any outstanding ELS commands */
  1170. lpfc_els_flush_all_cmd(phba);
  1171. psli->slistat.link_event++;
  1172. lpfc_read_la(phba, pmb, mp);
  1173. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  1174. pmb->vport = vport;
  1175. /* Block ELS IOCBs until we have processed this mbox command */
  1176. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  1177. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  1178. if (rc == MBX_NOT_FINISHED) {
  1179. rc = 4;
  1180. goto lpfc_handle_latt_free_mbuf;
  1181. }
  1182. /* Clear Link Attention in HA REG */
  1183. spin_lock_irq(&phba->hbalock);
  1184. writel(HA_LATT, phba->HAregaddr);
  1185. readl(phba->HAregaddr); /* flush */
  1186. spin_unlock_irq(&phba->hbalock);
  1187. return;
  1188. lpfc_handle_latt_free_mbuf:
  1189. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1190. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1191. lpfc_handle_latt_free_mp:
  1192. kfree(mp);
  1193. lpfc_handle_latt_free_pmb:
  1194. mempool_free(pmb, phba->mbox_mem_pool);
  1195. lpfc_handle_latt_err_exit:
  1196. /* Enable Link attention interrupts */
  1197. spin_lock_irq(&phba->hbalock);
  1198. psli->sli_flag |= LPFC_PROCESS_LA;
  1199. control = readl(phba->HCregaddr);
  1200. control |= HC_LAINT_ENA;
  1201. writel(control, phba->HCregaddr);
  1202. readl(phba->HCregaddr); /* flush */
  1203. /* Clear Link Attention in HA REG */
  1204. writel(HA_LATT, phba->HAregaddr);
  1205. readl(phba->HAregaddr); /* flush */
  1206. spin_unlock_irq(&phba->hbalock);
  1207. lpfc_linkdown(phba);
  1208. phba->link_state = LPFC_HBA_ERROR;
  1209. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1210. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  1211. return;
  1212. }
  1213. /**
  1214. * lpfc_parse_vpd - Parse VPD (Vital Product Data)
  1215. * @phba: pointer to lpfc hba data structure.
  1216. * @vpd: pointer to the vital product data.
  1217. * @len: length of the vital product data in bytes.
  1218. *
  1219. * This routine parses the Vital Product Data (VPD). The VPD is treated as
  1220. * an array of characters. In this routine, the ModelName, ProgramType, and
  1221. * ModelDesc, etc. fields of the phba data structure will be populated.
  1222. *
  1223. * Return codes
  1224. * 0 - pointer to the VPD passed in is NULL
  1225. * 1 - success
  1226. **/
  1227. int
  1228. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  1229. {
  1230. uint8_t lenlo, lenhi;
  1231. int Length;
  1232. int i, j;
  1233. int finished = 0;
  1234. int index = 0;
  1235. if (!vpd)
  1236. return 0;
  1237. /* Vital Product */
  1238. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1239. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  1240. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  1241. (uint32_t) vpd[3]);
  1242. while (!finished && (index < (len - 4))) {
  1243. switch (vpd[index]) {
  1244. case 0x82:
  1245. case 0x91:
  1246. index += 1;
  1247. lenlo = vpd[index];
  1248. index += 1;
  1249. lenhi = vpd[index];
  1250. index += 1;
  1251. i = ((((unsigned short)lenhi) << 8) + lenlo);
  1252. index += i;
  1253. break;
  1254. case 0x90:
  1255. index += 1;
  1256. lenlo = vpd[index];
  1257. index += 1;
  1258. lenhi = vpd[index];
  1259. index += 1;
  1260. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  1261. if (Length > len - index)
  1262. Length = len - index;
  1263. while (Length > 0) {
  1264. /* Look for Serial Number */
  1265. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  1266. index += 2;
  1267. i = vpd[index];
  1268. index += 1;
  1269. j = 0;
  1270. Length -= (3+i);
  1271. while(i--) {
  1272. phba->SerialNumber[j++] = vpd[index++];
  1273. if (j == 31)
  1274. break;
  1275. }
  1276. phba->SerialNumber[j] = 0;
  1277. continue;
  1278. }
  1279. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  1280. phba->vpd_flag |= VPD_MODEL_DESC;
  1281. index += 2;
  1282. i = vpd[index];
  1283. index += 1;
  1284. j = 0;
  1285. Length -= (3+i);
  1286. while(i--) {
  1287. phba->ModelDesc[j++] = vpd[index++];
  1288. if (j == 255)
  1289. break;
  1290. }
  1291. phba->ModelDesc[j] = 0;
  1292. continue;
  1293. }
  1294. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  1295. phba->vpd_flag |= VPD_MODEL_NAME;
  1296. index += 2;
  1297. i = vpd[index];
  1298. index += 1;
  1299. j = 0;
  1300. Length -= (3+i);
  1301. while(i--) {
  1302. phba->ModelName[j++] = vpd[index++];
  1303. if (j == 79)
  1304. break;
  1305. }
  1306. phba->ModelName[j] = 0;
  1307. continue;
  1308. }
  1309. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  1310. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  1311. index += 2;
  1312. i = vpd[index];
  1313. index += 1;
  1314. j = 0;
  1315. Length -= (3+i);
  1316. while(i--) {
  1317. phba->ProgramType[j++] = vpd[index++];
  1318. if (j == 255)
  1319. break;
  1320. }
  1321. phba->ProgramType[j] = 0;
  1322. continue;
  1323. }
  1324. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  1325. phba->vpd_flag |= VPD_PORT;
  1326. index += 2;
  1327. i = vpd[index];
  1328. index += 1;
  1329. j = 0;
  1330. Length -= (3+i);
  1331. while(i--) {
  1332. phba->Port[j++] = vpd[index++];
  1333. if (j == 19)
  1334. break;
  1335. }
  1336. phba->Port[j] = 0;
  1337. continue;
  1338. }
  1339. else {
  1340. index += 2;
  1341. i = vpd[index];
  1342. index += 1;
  1343. index += i;
  1344. Length -= (3 + i);
  1345. }
  1346. }
  1347. finished = 0;
  1348. break;
  1349. case 0x78:
  1350. finished = 1;
  1351. break;
  1352. default:
  1353. index ++;
  1354. break;
  1355. }
  1356. }
  1357. return(1);
  1358. }
  1359. /**
  1360. * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
  1361. * @phba: pointer to lpfc hba data structure.
  1362. * @mdp: pointer to the data structure to hold the derived model name.
  1363. * @descp: pointer to the data structure to hold the derived description.
  1364. *
  1365. * This routine retrieves HBA's description based on its registered PCI device
  1366. * ID. The @descp passed into this function points to an array of 256 chars. It
  1367. * shall be returned with the model name, maximum speed, and the host bus type.
  1368. * The @mdp passed into this function points to an array of 80 chars. When the
  1369. * function returns, the @mdp will be filled with the model name.
  1370. **/
  1371. static void
  1372. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  1373. {
  1374. lpfc_vpd_t *vp;
  1375. uint16_t dev_id = phba->pcidev->device;
  1376. int max_speed;
  1377. int GE = 0;
  1378. int oneConnect = 0; /* default is not a oneConnect */
  1379. struct {
  1380. char *name;
  1381. char *bus;
  1382. char *function;
  1383. } m = {"<Unknown>", "", ""};
  1384. if (mdp && mdp[0] != '\0'
  1385. && descp && descp[0] != '\0')
  1386. return;
  1387. if (phba->lmt & LMT_10Gb)
  1388. max_speed = 10;
  1389. else if (phba->lmt & LMT_8Gb)
  1390. max_speed = 8;
  1391. else if (phba->lmt & LMT_4Gb)
  1392. max_speed = 4;
  1393. else if (phba->lmt & LMT_2Gb)
  1394. max_speed = 2;
  1395. else
  1396. max_speed = 1;
  1397. vp = &phba->vpd;
  1398. switch (dev_id) {
  1399. case PCI_DEVICE_ID_FIREFLY:
  1400. m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"};
  1401. break;
  1402. case PCI_DEVICE_ID_SUPERFLY:
  1403. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  1404. m = (typeof(m)){"LP7000", "PCI",
  1405. "Fibre Channel Adapter"};
  1406. else
  1407. m = (typeof(m)){"LP7000E", "PCI",
  1408. "Fibre Channel Adapter"};
  1409. break;
  1410. case PCI_DEVICE_ID_DRAGONFLY:
  1411. m = (typeof(m)){"LP8000", "PCI",
  1412. "Fibre Channel Adapter"};
  1413. break;
  1414. case PCI_DEVICE_ID_CENTAUR:
  1415. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  1416. m = (typeof(m)){"LP9002", "PCI",
  1417. "Fibre Channel Adapter"};
  1418. else
  1419. m = (typeof(m)){"LP9000", "PCI",
  1420. "Fibre Channel Adapter"};
  1421. break;
  1422. case PCI_DEVICE_ID_RFLY:
  1423. m = (typeof(m)){"LP952", "PCI",
  1424. "Fibre Channel Adapter"};
  1425. break;
  1426. case PCI_DEVICE_ID_PEGASUS:
  1427. m = (typeof(m)){"LP9802", "PCI-X",
  1428. "Fibre Channel Adapter"};
  1429. break;
  1430. case PCI_DEVICE_ID_THOR:
  1431. m = (typeof(m)){"LP10000", "PCI-X",
  1432. "Fibre Channel Adapter"};
  1433. break;
  1434. case PCI_DEVICE_ID_VIPER:
  1435. m = (typeof(m)){"LPX1000", "PCI-X",
  1436. "Fibre Channel Adapter"};
  1437. break;
  1438. case PCI_DEVICE_ID_PFLY:
  1439. m = (typeof(m)){"LP982", "PCI-X",
  1440. "Fibre Channel Adapter"};
  1441. break;
  1442. case PCI_DEVICE_ID_TFLY:
  1443. m = (typeof(m)){"LP1050", "PCI-X",
  1444. "Fibre Channel Adapter"};
  1445. break;
  1446. case PCI_DEVICE_ID_HELIOS:
  1447. m = (typeof(m)){"LP11000", "PCI-X2",
  1448. "Fibre Channel Adapter"};
  1449. break;
  1450. case PCI_DEVICE_ID_HELIOS_SCSP:
  1451. m = (typeof(m)){"LP11000-SP", "PCI-X2",
  1452. "Fibre Channel Adapter"};
  1453. break;
  1454. case PCI_DEVICE_ID_HELIOS_DCSP:
  1455. m = (typeof(m)){"LP11002-SP", "PCI-X2",
  1456. "Fibre Channel Adapter"};
  1457. break;
  1458. case PCI_DEVICE_ID_NEPTUNE:
  1459. m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
  1460. break;
  1461. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1462. m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
  1463. break;
  1464. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1465. m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
  1466. break;
  1467. case PCI_DEVICE_ID_BMID:
  1468. m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
  1469. break;
  1470. case PCI_DEVICE_ID_BSMB:
  1471. m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
  1472. break;
  1473. case PCI_DEVICE_ID_ZEPHYR:
  1474. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1475. break;
  1476. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1477. m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
  1478. break;
  1479. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1480. m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"};
  1481. GE = 1;
  1482. break;
  1483. case PCI_DEVICE_ID_ZMID:
  1484. m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
  1485. break;
  1486. case PCI_DEVICE_ID_ZSMB:
  1487. m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"};
  1488. break;
  1489. case PCI_DEVICE_ID_LP101:
  1490. m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"};
  1491. break;
  1492. case PCI_DEVICE_ID_LP10000S:
  1493. m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
  1494. break;
  1495. case PCI_DEVICE_ID_LP11000S:
  1496. m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
  1497. break;
  1498. case PCI_DEVICE_ID_LPE11000S:
  1499. m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
  1500. break;
  1501. case PCI_DEVICE_ID_SAT:
  1502. m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
  1503. break;
  1504. case PCI_DEVICE_ID_SAT_MID:
  1505. m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
  1506. break;
  1507. case PCI_DEVICE_ID_SAT_SMB:
  1508. m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"};
  1509. break;
  1510. case PCI_DEVICE_ID_SAT_DCSP:
  1511. m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
  1512. break;
  1513. case PCI_DEVICE_ID_SAT_SCSP:
  1514. m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
  1515. break;
  1516. case PCI_DEVICE_ID_SAT_S:
  1517. m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
  1518. break;
  1519. case PCI_DEVICE_ID_HORNET:
  1520. m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"};
  1521. GE = 1;
  1522. break;
  1523. case PCI_DEVICE_ID_PROTEUS_VF:
  1524. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1525. "Fibre Channel Adapter"};
  1526. break;
  1527. case PCI_DEVICE_ID_PROTEUS_PF:
  1528. m = (typeof(m)){"LPev12000", "PCIe IOV",
  1529. "Fibre Channel Adapter"};
  1530. break;
  1531. case PCI_DEVICE_ID_PROTEUS_S:
  1532. m = (typeof(m)){"LPemv12002-S", "PCIe IOV",
  1533. "Fibre Channel Adapter"};
  1534. break;
  1535. case PCI_DEVICE_ID_TIGERSHARK:
  1536. oneConnect = 1;
  1537. m = (typeof(m)){"OCe10100", "PCIe", "FCoE"};
  1538. break;
  1539. case PCI_DEVICE_ID_TOMCAT:
  1540. oneConnect = 1;
  1541. m = (typeof(m)){"OCe11100", "PCIe", "FCoE"};
  1542. break;
  1543. case PCI_DEVICE_ID_FALCON:
  1544. m = (typeof(m)){"LPSe12002-ML1-E", "PCIe",
  1545. "EmulexSecure Fibre"};
  1546. break;
  1547. default:
  1548. m = (typeof(m)){"Unknown", "", ""};
  1549. break;
  1550. }
  1551. if (mdp && mdp[0] == '\0')
  1552. snprintf(mdp, 79,"%s", m.name);
  1553. /* oneConnect hba requires special processing, they are all initiators
  1554. * and we put the port number on the end
  1555. */
  1556. if (descp && descp[0] == '\0') {
  1557. if (oneConnect)
  1558. snprintf(descp, 255,
  1559. "Emulex OneConnect %s, %s Initiator, Port %s",
  1560. m.name, m.function,
  1561. phba->Port);
  1562. else
  1563. snprintf(descp, 255,
  1564. "Emulex %s %d%s %s %s",
  1565. m.name, max_speed, (GE) ? "GE" : "Gb",
  1566. m.bus, m.function);
  1567. }
  1568. }
  1569. /**
  1570. * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
  1571. * @phba: pointer to lpfc hba data structure.
  1572. * @pring: pointer to a IOCB ring.
  1573. * @cnt: the number of IOCBs to be posted to the IOCB ring.
  1574. *
  1575. * This routine posts a given number of IOCBs with the associated DMA buffer
  1576. * descriptors specified by the cnt argument to the given IOCB ring.
  1577. *
  1578. * Return codes
  1579. * The number of IOCBs NOT able to be posted to the IOCB ring.
  1580. **/
  1581. int
  1582. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt)
  1583. {
  1584. IOCB_t *icmd;
  1585. struct lpfc_iocbq *iocb;
  1586. struct lpfc_dmabuf *mp1, *mp2;
  1587. cnt += pring->missbufcnt;
  1588. /* While there are buffers to post */
  1589. while (cnt > 0) {
  1590. /* Allocate buffer for command iocb */
  1591. iocb = lpfc_sli_get_iocbq(phba);
  1592. if (iocb == NULL) {
  1593. pring->missbufcnt = cnt;
  1594. return cnt;
  1595. }
  1596. icmd = &iocb->iocb;
  1597. /* 2 buffers can be posted per command */
  1598. /* Allocate buffer to post */
  1599. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1600. if (mp1)
  1601. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1602. if (!mp1 || !mp1->virt) {
  1603. kfree(mp1);
  1604. lpfc_sli_release_iocbq(phba, iocb);
  1605. pring->missbufcnt = cnt;
  1606. return cnt;
  1607. }
  1608. INIT_LIST_HEAD(&mp1->list);
  1609. /* Allocate buffer to post */
  1610. if (cnt > 1) {
  1611. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1612. if (mp2)
  1613. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1614. &mp2->phys);
  1615. if (!mp2 || !mp2->virt) {
  1616. kfree(mp2);
  1617. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1618. kfree(mp1);
  1619. lpfc_sli_release_iocbq(phba, iocb);
  1620. pring->missbufcnt = cnt;
  1621. return cnt;
  1622. }
  1623. INIT_LIST_HEAD(&mp2->list);
  1624. } else {
  1625. mp2 = NULL;
  1626. }
  1627. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1628. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1629. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1630. icmd->ulpBdeCount = 1;
  1631. cnt--;
  1632. if (mp2) {
  1633. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1634. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1635. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1636. cnt--;
  1637. icmd->ulpBdeCount = 2;
  1638. }
  1639. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1640. icmd->ulpLe = 1;
  1641. if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) ==
  1642. IOCB_ERROR) {
  1643. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1644. kfree(mp1);
  1645. cnt++;
  1646. if (mp2) {
  1647. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1648. kfree(mp2);
  1649. cnt++;
  1650. }
  1651. lpfc_sli_release_iocbq(phba, iocb);
  1652. pring->missbufcnt = cnt;
  1653. return cnt;
  1654. }
  1655. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1656. if (mp2)
  1657. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1658. }
  1659. pring->missbufcnt = 0;
  1660. return 0;
  1661. }
  1662. /**
  1663. * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
  1664. * @phba: pointer to lpfc hba data structure.
  1665. *
  1666. * This routine posts initial receive IOCB buffers to the ELS ring. The
  1667. * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
  1668. * set to 64 IOCBs.
  1669. *
  1670. * Return codes
  1671. * 0 - success (currently always success)
  1672. **/
  1673. static int
  1674. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1675. {
  1676. struct lpfc_sli *psli = &phba->sli;
  1677. /* Ring 0, ELS / CT buffers */
  1678. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0);
  1679. /* Ring 2 - FCP no buffers needed */
  1680. return 0;
  1681. }
  1682. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1683. /**
  1684. * lpfc_sha_init - Set up initial array of hash table entries
  1685. * @HashResultPointer: pointer to an array as hash table.
  1686. *
  1687. * This routine sets up the initial values to the array of hash table entries
  1688. * for the LC HBAs.
  1689. **/
  1690. static void
  1691. lpfc_sha_init(uint32_t * HashResultPointer)
  1692. {
  1693. HashResultPointer[0] = 0x67452301;
  1694. HashResultPointer[1] = 0xEFCDAB89;
  1695. HashResultPointer[2] = 0x98BADCFE;
  1696. HashResultPointer[3] = 0x10325476;
  1697. HashResultPointer[4] = 0xC3D2E1F0;
  1698. }
  1699. /**
  1700. * lpfc_sha_iterate - Iterate initial hash table with the working hash table
  1701. * @HashResultPointer: pointer to an initial/result hash table.
  1702. * @HashWorkingPointer: pointer to an working hash table.
  1703. *
  1704. * This routine iterates an initial hash table pointed by @HashResultPointer
  1705. * with the values from the working hash table pointeed by @HashWorkingPointer.
  1706. * The results are putting back to the initial hash table, returned through
  1707. * the @HashResultPointer as the result hash table.
  1708. **/
  1709. static void
  1710. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1711. {
  1712. int t;
  1713. uint32_t TEMP;
  1714. uint32_t A, B, C, D, E;
  1715. t = 16;
  1716. do {
  1717. HashWorkingPointer[t] =
  1718. S(1,
  1719. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1720. 8] ^
  1721. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1722. } while (++t <= 79);
  1723. t = 0;
  1724. A = HashResultPointer[0];
  1725. B = HashResultPointer[1];
  1726. C = HashResultPointer[2];
  1727. D = HashResultPointer[3];
  1728. E = HashResultPointer[4];
  1729. do {
  1730. if (t < 20) {
  1731. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1732. } else if (t < 40) {
  1733. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1734. } else if (t < 60) {
  1735. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1736. } else {
  1737. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1738. }
  1739. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1740. E = D;
  1741. D = C;
  1742. C = S(30, B);
  1743. B = A;
  1744. A = TEMP;
  1745. } while (++t <= 79);
  1746. HashResultPointer[0] += A;
  1747. HashResultPointer[1] += B;
  1748. HashResultPointer[2] += C;
  1749. HashResultPointer[3] += D;
  1750. HashResultPointer[4] += E;
  1751. }
  1752. /**
  1753. * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
  1754. * @RandomChallenge: pointer to the entry of host challenge random number array.
  1755. * @HashWorking: pointer to the entry of the working hash array.
  1756. *
  1757. * This routine calculates the working hash array referred by @HashWorking
  1758. * from the challenge random numbers associated with the host, referred by
  1759. * @RandomChallenge. The result is put into the entry of the working hash
  1760. * array and returned by reference through @HashWorking.
  1761. **/
  1762. static void
  1763. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1764. {
  1765. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1766. }
  1767. /**
  1768. * lpfc_hba_init - Perform special handling for LC HBA initialization
  1769. * @phba: pointer to lpfc hba data structure.
  1770. * @hbainit: pointer to an array of unsigned 32-bit integers.
  1771. *
  1772. * This routine performs the special handling for LC HBA initialization.
  1773. **/
  1774. void
  1775. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1776. {
  1777. int t;
  1778. uint32_t *HashWorking;
  1779. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1780. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1781. if (!HashWorking)
  1782. return;
  1783. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1784. HashWorking[1] = HashWorking[79] = *pwwnn;
  1785. for (t = 0; t < 7; t++)
  1786. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1787. lpfc_sha_init(hbainit);
  1788. lpfc_sha_iterate(hbainit, HashWorking);
  1789. kfree(HashWorking);
  1790. }
  1791. /**
  1792. * lpfc_cleanup - Performs vport cleanups before deleting a vport
  1793. * @vport: pointer to a virtual N_Port data structure.
  1794. *
  1795. * This routine performs the necessary cleanups before deleting the @vport.
  1796. * It invokes the discovery state machine to perform necessary state
  1797. * transitions and to release the ndlps associated with the @vport. Note,
  1798. * the physical port is treated as @vport 0.
  1799. **/
  1800. void
  1801. lpfc_cleanup(struct lpfc_vport *vport)
  1802. {
  1803. struct lpfc_hba *phba = vport->phba;
  1804. struct lpfc_nodelist *ndlp, *next_ndlp;
  1805. int i = 0;
  1806. if (phba->link_state > LPFC_LINK_DOWN)
  1807. lpfc_port_link_failure(vport);
  1808. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1809. if (!NLP_CHK_NODE_ACT(ndlp)) {
  1810. ndlp = lpfc_enable_node(vport, ndlp,
  1811. NLP_STE_UNUSED_NODE);
  1812. if (!ndlp)
  1813. continue;
  1814. spin_lock_irq(&phba->ndlp_lock);
  1815. NLP_SET_FREE_REQ(ndlp);
  1816. spin_unlock_irq(&phba->ndlp_lock);
  1817. /* Trigger the release of the ndlp memory */
  1818. lpfc_nlp_put(ndlp);
  1819. continue;
  1820. }
  1821. spin_lock_irq(&phba->ndlp_lock);
  1822. if (NLP_CHK_FREE_REQ(ndlp)) {
  1823. /* The ndlp should not be in memory free mode already */
  1824. spin_unlock_irq(&phba->ndlp_lock);
  1825. continue;
  1826. } else
  1827. /* Indicate request for freeing ndlp memory */
  1828. NLP_SET_FREE_REQ(ndlp);
  1829. spin_unlock_irq(&phba->ndlp_lock);
  1830. if (vport->port_type != LPFC_PHYSICAL_PORT &&
  1831. ndlp->nlp_DID == Fabric_DID) {
  1832. /* Just free up ndlp with Fabric_DID for vports */
  1833. lpfc_nlp_put(ndlp);
  1834. continue;
  1835. }
  1836. if (ndlp->nlp_type & NLP_FABRIC)
  1837. lpfc_disc_state_machine(vport, ndlp, NULL,
  1838. NLP_EVT_DEVICE_RECOVERY);
  1839. lpfc_disc_state_machine(vport, ndlp, NULL,
  1840. NLP_EVT_DEVICE_RM);
  1841. }
  1842. /* At this point, ALL ndlp's should be gone
  1843. * because of the previous NLP_EVT_DEVICE_RM.
  1844. * Lets wait for this to happen, if needed.
  1845. */
  1846. while (!list_empty(&vport->fc_nodes)) {
  1847. if (i++ > 3000) {
  1848. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1849. "0233 Nodelist not empty\n");
  1850. list_for_each_entry_safe(ndlp, next_ndlp,
  1851. &vport->fc_nodes, nlp_listp) {
  1852. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  1853. LOG_NODE,
  1854. "0282 did:x%x ndlp:x%p "
  1855. "usgmap:x%x refcnt:%d\n",
  1856. ndlp->nlp_DID, (void *)ndlp,
  1857. ndlp->nlp_usg_map,
  1858. atomic_read(
  1859. &ndlp->kref.refcount));
  1860. }
  1861. break;
  1862. }
  1863. /* Wait for any activity on ndlps to settle */
  1864. msleep(10);
  1865. }
  1866. }
  1867. /**
  1868. * lpfc_stop_vport_timers - Stop all the timers associated with a vport
  1869. * @vport: pointer to a virtual N_Port data structure.
  1870. *
  1871. * This routine stops all the timers associated with a @vport. This function
  1872. * is invoked before disabling or deleting a @vport. Note that the physical
  1873. * port is treated as @vport 0.
  1874. **/
  1875. void
  1876. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  1877. {
  1878. del_timer_sync(&vport->els_tmofunc);
  1879. del_timer_sync(&vport->fc_fdmitmo);
  1880. lpfc_can_disctmo(vport);
  1881. return;
  1882. }
  1883. /**
  1884. * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
  1885. * @phba: pointer to lpfc hba data structure.
  1886. *
  1887. * This routine stops all the timers associated with a HBA. This function is
  1888. * invoked before either putting a HBA offline or unloading the driver.
  1889. **/
  1890. void
  1891. lpfc_stop_hba_timers(struct lpfc_hba *phba)
  1892. {
  1893. lpfc_stop_vport_timers(phba->pport);
  1894. del_timer_sync(&phba->sli.mbox_tmo);
  1895. del_timer_sync(&phba->fabric_block_timer);
  1896. del_timer_sync(&phba->eratt_poll);
  1897. del_timer_sync(&phba->hb_tmofunc);
  1898. phba->hb_outstanding = 0;
  1899. switch (phba->pci_dev_grp) {
  1900. case LPFC_PCI_DEV_LP:
  1901. /* Stop any LightPulse device specific driver timers */
  1902. del_timer_sync(&phba->fcp_poll_timer);
  1903. break;
  1904. case LPFC_PCI_DEV_OC:
  1905. /* Stop any OneConnect device sepcific driver timers */
  1906. break;
  1907. default:
  1908. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1909. "0297 Invalid device group (x%x)\n",
  1910. phba->pci_dev_grp);
  1911. break;
  1912. }
  1913. return;
  1914. }
  1915. /**
  1916. * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
  1917. * @phba: pointer to lpfc hba data structure.
  1918. *
  1919. * This routine marks a HBA's management interface as blocked. Once the HBA's
  1920. * management interface is marked as blocked, all the user space access to
  1921. * the HBA, whether they are from sysfs interface or libdfc interface will
  1922. * all be blocked. The HBA is set to block the management interface when the
  1923. * driver prepares the HBA interface for online or offline.
  1924. **/
  1925. static void
  1926. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  1927. {
  1928. unsigned long iflag;
  1929. spin_lock_irqsave(&phba->hbalock, iflag);
  1930. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  1931. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1932. }
  1933. /**
  1934. * lpfc_online - Initialize and bring a HBA online
  1935. * @phba: pointer to lpfc hba data structure.
  1936. *
  1937. * This routine initializes the HBA and brings a HBA online. During this
  1938. * process, the management interface is blocked to prevent user space access
  1939. * to the HBA interfering with the driver initialization.
  1940. *
  1941. * Return codes
  1942. * 0 - successful
  1943. * 1 - failed
  1944. **/
  1945. int
  1946. lpfc_online(struct lpfc_hba *phba)
  1947. {
  1948. struct lpfc_vport *vport;
  1949. struct lpfc_vport **vports;
  1950. int i;
  1951. if (!phba)
  1952. return 0;
  1953. vport = phba->pport;
  1954. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  1955. return 0;
  1956. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1957. "0458 Bring Adapter online\n");
  1958. lpfc_block_mgmt_io(phba);
  1959. if (!lpfc_sli_queue_setup(phba)) {
  1960. lpfc_unblock_mgmt_io(phba);
  1961. return 1;
  1962. }
  1963. if (phba->sli_rev == LPFC_SLI_REV4) {
  1964. if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
  1965. lpfc_unblock_mgmt_io(phba);
  1966. return 1;
  1967. }
  1968. } else {
  1969. if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
  1970. lpfc_unblock_mgmt_io(phba);
  1971. return 1;
  1972. }
  1973. }
  1974. vports = lpfc_create_vport_work_array(phba);
  1975. if (vports != NULL)
  1976. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  1977. struct Scsi_Host *shost;
  1978. shost = lpfc_shost_from_vport(vports[i]);
  1979. spin_lock_irq(shost->host_lock);
  1980. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  1981. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  1982. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1983. if (phba->sli_rev == LPFC_SLI_REV4)
  1984. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  1985. spin_unlock_irq(shost->host_lock);
  1986. }
  1987. lpfc_destroy_vport_work_array(phba, vports);
  1988. lpfc_unblock_mgmt_io(phba);
  1989. return 0;
  1990. }
  1991. /**
  1992. * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
  1993. * @phba: pointer to lpfc hba data structure.
  1994. *
  1995. * This routine marks a HBA's management interface as not blocked. Once the
  1996. * HBA's management interface is marked as not blocked, all the user space
  1997. * access to the HBA, whether they are from sysfs interface or libdfc
  1998. * interface will be allowed. The HBA is set to block the management interface
  1999. * when the driver prepares the HBA interface for online or offline and then
  2000. * set to unblock the management interface afterwards.
  2001. **/
  2002. void
  2003. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  2004. {
  2005. unsigned long iflag;
  2006. spin_lock_irqsave(&phba->hbalock, iflag);
  2007. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  2008. spin_unlock_irqrestore(&phba->hbalock, iflag);
  2009. }
  2010. /**
  2011. * lpfc_offline_prep - Prepare a HBA to be brought offline
  2012. * @phba: pointer to lpfc hba data structure.
  2013. *
  2014. * This routine is invoked to prepare a HBA to be brought offline. It performs
  2015. * unregistration login to all the nodes on all vports and flushes the mailbox
  2016. * queue to make it ready to be brought offline.
  2017. **/
  2018. void
  2019. lpfc_offline_prep(struct lpfc_hba * phba)
  2020. {
  2021. struct lpfc_vport *vport = phba->pport;
  2022. struct lpfc_nodelist *ndlp, *next_ndlp;
  2023. struct lpfc_vport **vports;
  2024. int i;
  2025. if (vport->fc_flag & FC_OFFLINE_MODE)
  2026. return;
  2027. lpfc_block_mgmt_io(phba);
  2028. lpfc_linkdown(phba);
  2029. /* Issue an unreg_login to all nodes on all vports */
  2030. vports = lpfc_create_vport_work_array(phba);
  2031. if (vports != NULL) {
  2032. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2033. struct Scsi_Host *shost;
  2034. if (vports[i]->load_flag & FC_UNLOADING)
  2035. continue;
  2036. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  2037. shost = lpfc_shost_from_vport(vports[i]);
  2038. list_for_each_entry_safe(ndlp, next_ndlp,
  2039. &vports[i]->fc_nodes,
  2040. nlp_listp) {
  2041. if (!NLP_CHK_NODE_ACT(ndlp))
  2042. continue;
  2043. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2044. continue;
  2045. if (ndlp->nlp_type & NLP_FABRIC) {
  2046. lpfc_disc_state_machine(vports[i], ndlp,
  2047. NULL, NLP_EVT_DEVICE_RECOVERY);
  2048. lpfc_disc_state_machine(vports[i], ndlp,
  2049. NULL, NLP_EVT_DEVICE_RM);
  2050. }
  2051. spin_lock_irq(shost->host_lock);
  2052. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2053. spin_unlock_irq(shost->host_lock);
  2054. lpfc_unreg_rpi(vports[i], ndlp);
  2055. }
  2056. }
  2057. }
  2058. lpfc_destroy_vport_work_array(phba, vports);
  2059. lpfc_sli_mbox_sys_shutdown(phba);
  2060. }
  2061. /**
  2062. * lpfc_offline - Bring a HBA offline
  2063. * @phba: pointer to lpfc hba data structure.
  2064. *
  2065. * This routine actually brings a HBA offline. It stops all the timers
  2066. * associated with the HBA, brings down the SLI layer, and eventually
  2067. * marks the HBA as in offline state for the upper layer protocol.
  2068. **/
  2069. void
  2070. lpfc_offline(struct lpfc_hba *phba)
  2071. {
  2072. struct Scsi_Host *shost;
  2073. struct lpfc_vport **vports;
  2074. int i;
  2075. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  2076. return;
  2077. /* stop port and all timers associated with this hba */
  2078. lpfc_stop_port(phba);
  2079. vports = lpfc_create_vport_work_array(phba);
  2080. if (vports != NULL)
  2081. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  2082. lpfc_stop_vport_timers(vports[i]);
  2083. lpfc_destroy_vport_work_array(phba, vports);
  2084. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2085. "0460 Bring Adapter offline\n");
  2086. /* Bring down the SLI Layer and cleanup. The HBA is offline
  2087. now. */
  2088. lpfc_sli_hba_down(phba);
  2089. spin_lock_irq(&phba->hbalock);
  2090. phba->work_ha = 0;
  2091. spin_unlock_irq(&phba->hbalock);
  2092. vports = lpfc_create_vport_work_array(phba);
  2093. if (vports != NULL)
  2094. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2095. shost = lpfc_shost_from_vport(vports[i]);
  2096. spin_lock_irq(shost->host_lock);
  2097. vports[i]->work_port_events = 0;
  2098. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  2099. spin_unlock_irq(shost->host_lock);
  2100. }
  2101. lpfc_destroy_vport_work_array(phba, vports);
  2102. }
  2103. /**
  2104. * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
  2105. * @phba: pointer to lpfc hba data structure.
  2106. *
  2107. * This routine is to free all the SCSI buffers and IOCBs from the driver
  2108. * list back to kernel. It is called from lpfc_pci_remove_one to free
  2109. * the internal resources before the device is removed from the system.
  2110. *
  2111. * Return codes
  2112. * 0 - successful (for now, it always returns 0)
  2113. **/
  2114. static int
  2115. lpfc_scsi_free(struct lpfc_hba *phba)
  2116. {
  2117. struct lpfc_scsi_buf *sb, *sb_next;
  2118. struct lpfc_iocbq *io, *io_next;
  2119. spin_lock_irq(&phba->hbalock);
  2120. /* Release all the lpfc_scsi_bufs maintained by this host. */
  2121. spin_lock(&phba->scsi_buf_list_lock);
  2122. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  2123. list_del(&sb->list);
  2124. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  2125. sb->dma_handle);
  2126. kfree(sb);
  2127. phba->total_scsi_bufs--;
  2128. }
  2129. spin_unlock(&phba->scsi_buf_list_lock);
  2130. /* Release all the lpfc_iocbq entries maintained by this host. */
  2131. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  2132. list_del(&io->list);
  2133. kfree(io);
  2134. phba->total_iocbq_bufs--;
  2135. }
  2136. spin_unlock_irq(&phba->hbalock);
  2137. return 0;
  2138. }
  2139. /**
  2140. * lpfc_create_port - Create an FC port
  2141. * @phba: pointer to lpfc hba data structure.
  2142. * @instance: a unique integer ID to this FC port.
  2143. * @dev: pointer to the device data structure.
  2144. *
  2145. * This routine creates a FC port for the upper layer protocol. The FC port
  2146. * can be created on top of either a physical port or a virtual port provided
  2147. * by the HBA. This routine also allocates a SCSI host data structure (shost)
  2148. * and associates the FC port created before adding the shost into the SCSI
  2149. * layer.
  2150. *
  2151. * Return codes
  2152. * @vport - pointer to the virtual N_Port data structure.
  2153. * NULL - port create failed.
  2154. **/
  2155. struct lpfc_vport *
  2156. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  2157. {
  2158. struct lpfc_vport *vport;
  2159. struct Scsi_Host *shost;
  2160. int error = 0;
  2161. if (dev != &phba->pcidev->dev)
  2162. shost = scsi_host_alloc(&lpfc_vport_template,
  2163. sizeof(struct lpfc_vport));
  2164. else
  2165. shost = scsi_host_alloc(&lpfc_template,
  2166. sizeof(struct lpfc_vport));
  2167. if (!shost)
  2168. goto out;
  2169. vport = (struct lpfc_vport *) shost->hostdata;
  2170. vport->phba = phba;
  2171. vport->load_flag |= FC_LOADING;
  2172. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2173. vport->fc_rscn_flush = 0;
  2174. lpfc_get_vport_cfgparam(vport);
  2175. shost->unique_id = instance;
  2176. shost->max_id = LPFC_MAX_TARGET;
  2177. shost->max_lun = vport->cfg_max_luns;
  2178. shost->this_id = -1;
  2179. shost->max_cmd_len = 16;
  2180. if (phba->sli_rev == LPFC_SLI_REV4) {
  2181. shost->dma_boundary = LPFC_SLI4_MAX_SEGMENT_SIZE;
  2182. shost->sg_tablesize = phba->cfg_sg_seg_cnt;
  2183. }
  2184. /*
  2185. * Set initial can_queue value since 0 is no longer supported and
  2186. * scsi_add_host will fail. This will be adjusted later based on the
  2187. * max xri value determined in hba setup.
  2188. */
  2189. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  2190. if (dev != &phba->pcidev->dev) {
  2191. shost->transportt = lpfc_vport_transport_template;
  2192. vport->port_type = LPFC_NPIV_PORT;
  2193. } else {
  2194. shost->transportt = lpfc_transport_template;
  2195. vport->port_type = LPFC_PHYSICAL_PORT;
  2196. }
  2197. /* Initialize all internally managed lists. */
  2198. INIT_LIST_HEAD(&vport->fc_nodes);
  2199. INIT_LIST_HEAD(&vport->rcv_buffer_list);
  2200. spin_lock_init(&vport->work_port_lock);
  2201. init_timer(&vport->fc_disctmo);
  2202. vport->fc_disctmo.function = lpfc_disc_timeout;
  2203. vport->fc_disctmo.data = (unsigned long)vport;
  2204. init_timer(&vport->fc_fdmitmo);
  2205. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  2206. vport->fc_fdmitmo.data = (unsigned long)vport;
  2207. init_timer(&vport->els_tmofunc);
  2208. vport->els_tmofunc.function = lpfc_els_timeout;
  2209. vport->els_tmofunc.data = (unsigned long)vport;
  2210. error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
  2211. if (error)
  2212. goto out_put_shost;
  2213. spin_lock_irq(&phba->hbalock);
  2214. list_add_tail(&vport->listentry, &phba->port_list);
  2215. spin_unlock_irq(&phba->hbalock);
  2216. return vport;
  2217. out_put_shost:
  2218. scsi_host_put(shost);
  2219. out:
  2220. return NULL;
  2221. }
  2222. /**
  2223. * destroy_port - destroy an FC port
  2224. * @vport: pointer to an lpfc virtual N_Port data structure.
  2225. *
  2226. * This routine destroys a FC port from the upper layer protocol. All the
  2227. * resources associated with the port are released.
  2228. **/
  2229. void
  2230. destroy_port(struct lpfc_vport *vport)
  2231. {
  2232. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2233. struct lpfc_hba *phba = vport->phba;
  2234. lpfc_debugfs_terminate(vport);
  2235. fc_remove_host(shost);
  2236. scsi_remove_host(shost);
  2237. spin_lock_irq(&phba->hbalock);
  2238. list_del_init(&vport->listentry);
  2239. spin_unlock_irq(&phba->hbalock);
  2240. lpfc_cleanup(vport);
  2241. return;
  2242. }
  2243. /**
  2244. * lpfc_get_instance - Get a unique integer ID
  2245. *
  2246. * This routine allocates a unique integer ID from lpfc_hba_index pool. It
  2247. * uses the kernel idr facility to perform the task.
  2248. *
  2249. * Return codes:
  2250. * instance - a unique integer ID allocated as the new instance.
  2251. * -1 - lpfc get instance failed.
  2252. **/
  2253. int
  2254. lpfc_get_instance(void)
  2255. {
  2256. int instance = 0;
  2257. /* Assign an unused number */
  2258. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  2259. return -1;
  2260. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  2261. return -1;
  2262. return instance;
  2263. }
  2264. /**
  2265. * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
  2266. * @shost: pointer to SCSI host data structure.
  2267. * @time: elapsed time of the scan in jiffies.
  2268. *
  2269. * This routine is called by the SCSI layer with a SCSI host to determine
  2270. * whether the scan host is finished.
  2271. *
  2272. * Note: there is no scan_start function as adapter initialization will have
  2273. * asynchronously kicked off the link initialization.
  2274. *
  2275. * Return codes
  2276. * 0 - SCSI host scan is not over yet.
  2277. * 1 - SCSI host scan is over.
  2278. **/
  2279. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2280. {
  2281. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2282. struct lpfc_hba *phba = vport->phba;
  2283. int stat = 0;
  2284. spin_lock_irq(shost->host_lock);
  2285. if (vport->load_flag & FC_UNLOADING) {
  2286. stat = 1;
  2287. goto finished;
  2288. }
  2289. if (time >= 30 * HZ) {
  2290. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2291. "0461 Scanning longer than 30 "
  2292. "seconds. Continuing initialization\n");
  2293. stat = 1;
  2294. goto finished;
  2295. }
  2296. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  2297. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2298. "0465 Link down longer than 15 "
  2299. "seconds. Continuing initialization\n");
  2300. stat = 1;
  2301. goto finished;
  2302. }
  2303. if (vport->port_state != LPFC_VPORT_READY)
  2304. goto finished;
  2305. if (vport->num_disc_nodes || vport->fc_prli_sent)
  2306. goto finished;
  2307. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  2308. goto finished;
  2309. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  2310. goto finished;
  2311. stat = 1;
  2312. finished:
  2313. spin_unlock_irq(shost->host_lock);
  2314. return stat;
  2315. }
  2316. /**
  2317. * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
  2318. * @shost: pointer to SCSI host data structure.
  2319. *
  2320. * This routine initializes a given SCSI host attributes on a FC port. The
  2321. * SCSI host can be either on top of a physical port or a virtual port.
  2322. **/
  2323. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  2324. {
  2325. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2326. struct lpfc_hba *phba = vport->phba;
  2327. /*
  2328. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  2329. */
  2330. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  2331. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  2332. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  2333. memset(fc_host_supported_fc4s(shost), 0,
  2334. sizeof(fc_host_supported_fc4s(shost)));
  2335. fc_host_supported_fc4s(shost)[2] = 1;
  2336. fc_host_supported_fc4s(shost)[7] = 1;
  2337. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  2338. sizeof fc_host_symbolic_name(shost));
  2339. fc_host_supported_speeds(shost) = 0;
  2340. if (phba->lmt & LMT_10Gb)
  2341. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  2342. if (phba->lmt & LMT_8Gb)
  2343. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  2344. if (phba->lmt & LMT_4Gb)
  2345. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  2346. if (phba->lmt & LMT_2Gb)
  2347. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  2348. if (phba->lmt & LMT_1Gb)
  2349. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  2350. fc_host_maxframe_size(shost) =
  2351. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  2352. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  2353. /* This value is also unchanging */
  2354. memset(fc_host_active_fc4s(shost), 0,
  2355. sizeof(fc_host_active_fc4s(shost)));
  2356. fc_host_active_fc4s(shost)[2] = 1;
  2357. fc_host_active_fc4s(shost)[7] = 1;
  2358. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  2359. spin_lock_irq(shost->host_lock);
  2360. vport->load_flag &= ~FC_LOADING;
  2361. spin_unlock_irq(shost->host_lock);
  2362. }
  2363. /**
  2364. * lpfc_stop_port_s3 - Stop SLI3 device port
  2365. * @phba: pointer to lpfc hba data structure.
  2366. *
  2367. * This routine is invoked to stop an SLI3 device port, it stops the device
  2368. * from generating interrupts and stops the device driver's timers for the
  2369. * device.
  2370. **/
  2371. static void
  2372. lpfc_stop_port_s3(struct lpfc_hba *phba)
  2373. {
  2374. /* Clear all interrupt enable conditions */
  2375. writel(0, phba->HCregaddr);
  2376. readl(phba->HCregaddr); /* flush */
  2377. /* Clear all pending interrupts */
  2378. writel(0xffffffff, phba->HAregaddr);
  2379. readl(phba->HAregaddr); /* flush */
  2380. /* Reset some HBA SLI setup states */
  2381. lpfc_stop_hba_timers(phba);
  2382. phba->pport->work_port_events = 0;
  2383. }
  2384. /**
  2385. * lpfc_stop_port_s4 - Stop SLI4 device port
  2386. * @phba: pointer to lpfc hba data structure.
  2387. *
  2388. * This routine is invoked to stop an SLI4 device port, it stops the device
  2389. * from generating interrupts and stops the device driver's timers for the
  2390. * device.
  2391. **/
  2392. static void
  2393. lpfc_stop_port_s4(struct lpfc_hba *phba)
  2394. {
  2395. /* Reset some HBA SLI4 setup states */
  2396. lpfc_stop_hba_timers(phba);
  2397. phba->pport->work_port_events = 0;
  2398. phba->sli4_hba.intr_enable = 0;
  2399. /* Hard clear it for now, shall have more graceful way to wait later */
  2400. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  2401. }
  2402. /**
  2403. * lpfc_stop_port - Wrapper function for stopping hba port
  2404. * @phba: Pointer to HBA context object.
  2405. *
  2406. * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
  2407. * the API jump table function pointer from the lpfc_hba struct.
  2408. **/
  2409. void
  2410. lpfc_stop_port(struct lpfc_hba *phba)
  2411. {
  2412. phba->lpfc_stop_port(phba);
  2413. }
  2414. /**
  2415. * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port.
  2416. * @phba: pointer to lpfc hba data structure.
  2417. *
  2418. * This routine is invoked to remove the driver default fcf record from
  2419. * the port. This routine currently acts on FCF Index 0.
  2420. *
  2421. **/
  2422. void
  2423. lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba)
  2424. {
  2425. int rc = 0;
  2426. LPFC_MBOXQ_t *mboxq;
  2427. struct lpfc_mbx_del_fcf_tbl_entry *del_fcf_record;
  2428. uint32_t mbox_tmo, req_len;
  2429. uint32_t shdr_status, shdr_add_status;
  2430. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2431. if (!mboxq) {
  2432. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2433. "2020 Failed to allocate mbox for ADD_FCF cmd\n");
  2434. return;
  2435. }
  2436. req_len = sizeof(struct lpfc_mbx_del_fcf_tbl_entry) -
  2437. sizeof(struct lpfc_sli4_cfg_mhdr);
  2438. rc = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  2439. LPFC_MBOX_OPCODE_FCOE_DELETE_FCF,
  2440. req_len, LPFC_SLI4_MBX_EMBED);
  2441. /*
  2442. * In phase 1, there is a single FCF index, 0. In phase2, the driver
  2443. * supports multiple FCF indices.
  2444. */
  2445. del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry;
  2446. bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1);
  2447. bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record,
  2448. phba->fcf.fcf_indx);
  2449. if (!phba->sli4_hba.intr_enable)
  2450. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  2451. else {
  2452. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  2453. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  2454. }
  2455. /* The IOCTL status is embedded in the mailbox subheader. */
  2456. shdr_status = bf_get(lpfc_mbox_hdr_status,
  2457. &del_fcf_record->header.cfg_shdr.response);
  2458. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  2459. &del_fcf_record->header.cfg_shdr.response);
  2460. if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) {
  2461. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2462. "2516 DEL FCF of default FCF Index failed "
  2463. "mbx status x%x, status x%x add_status x%x\n",
  2464. rc, shdr_status, shdr_add_status);
  2465. }
  2466. if (rc != MBX_TIMEOUT)
  2467. mempool_free(mboxq, phba->mbox_mem_pool);
  2468. }
  2469. /**
  2470. * lpfc_sli4_fw_cfg_check - Read the firmware config and verify FCoE support
  2471. * @phba: pointer to lpfc hba data structure.
  2472. *
  2473. * This function uses the QUERY_FW_CFG mailbox command to determine if the
  2474. * firmware loaded supports FCoE. A return of zero indicates that the mailbox
  2475. * was successful and the firmware supports FCoE. Any other return indicates
  2476. * a error. It is assumed that this function will be called before interrupts
  2477. * are enabled.
  2478. **/
  2479. static int
  2480. lpfc_sli4_fw_cfg_check(struct lpfc_hba *phba)
  2481. {
  2482. int rc = 0;
  2483. LPFC_MBOXQ_t *mboxq;
  2484. struct lpfc_mbx_query_fw_cfg *query_fw_cfg;
  2485. uint32_t length;
  2486. uint32_t shdr_status, shdr_add_status;
  2487. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2488. if (!mboxq) {
  2489. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2490. "2621 Failed to allocate mbox for "
  2491. "query firmware config cmd\n");
  2492. return -ENOMEM;
  2493. }
  2494. query_fw_cfg = &mboxq->u.mqe.un.query_fw_cfg;
  2495. length = (sizeof(struct lpfc_mbx_query_fw_cfg) -
  2496. sizeof(struct lpfc_sli4_cfg_mhdr));
  2497. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  2498. LPFC_MBOX_OPCODE_QUERY_FW_CFG,
  2499. length, LPFC_SLI4_MBX_EMBED);
  2500. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  2501. /* The IOCTL status is embedded in the mailbox subheader. */
  2502. shdr_status = bf_get(lpfc_mbox_hdr_status,
  2503. &query_fw_cfg->header.cfg_shdr.response);
  2504. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  2505. &query_fw_cfg->header.cfg_shdr.response);
  2506. if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) {
  2507. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2508. "2622 Query Firmware Config failed "
  2509. "mbx status x%x, status x%x add_status x%x\n",
  2510. rc, shdr_status, shdr_add_status);
  2511. return -EINVAL;
  2512. }
  2513. if (!bf_get(lpfc_function_mode_fcoe_i, query_fw_cfg)) {
  2514. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2515. "2623 FCoE Function not supported by firmware. "
  2516. "Function mode = %08x\n",
  2517. query_fw_cfg->function_mode);
  2518. return -EINVAL;
  2519. }
  2520. if (rc != MBX_TIMEOUT)
  2521. mempool_free(mboxq, phba->mbox_mem_pool);
  2522. return 0;
  2523. }
  2524. /**
  2525. * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
  2526. * @phba: pointer to lpfc hba data structure.
  2527. * @acqe_link: pointer to the async link completion queue entry.
  2528. *
  2529. * This routine is to parse the SLI4 link-attention link fault code and
  2530. * translate it into the base driver's read link attention mailbox command
  2531. * status.
  2532. *
  2533. * Return: Link-attention status in terms of base driver's coding.
  2534. **/
  2535. static uint16_t
  2536. lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
  2537. struct lpfc_acqe_link *acqe_link)
  2538. {
  2539. uint16_t latt_fault;
  2540. switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
  2541. case LPFC_ASYNC_LINK_FAULT_NONE:
  2542. case LPFC_ASYNC_LINK_FAULT_LOCAL:
  2543. case LPFC_ASYNC_LINK_FAULT_REMOTE:
  2544. latt_fault = 0;
  2545. break;
  2546. default:
  2547. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2548. "0398 Invalid link fault code: x%x\n",
  2549. bf_get(lpfc_acqe_link_fault, acqe_link));
  2550. latt_fault = MBXERR_ERROR;
  2551. break;
  2552. }
  2553. return latt_fault;
  2554. }
  2555. /**
  2556. * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
  2557. * @phba: pointer to lpfc hba data structure.
  2558. * @acqe_link: pointer to the async link completion queue entry.
  2559. *
  2560. * This routine is to parse the SLI4 link attention type and translate it
  2561. * into the base driver's link attention type coding.
  2562. *
  2563. * Return: Link attention type in terms of base driver's coding.
  2564. **/
  2565. static uint8_t
  2566. lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
  2567. struct lpfc_acqe_link *acqe_link)
  2568. {
  2569. uint8_t att_type;
  2570. switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
  2571. case LPFC_ASYNC_LINK_STATUS_DOWN:
  2572. case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
  2573. att_type = AT_LINK_DOWN;
  2574. break;
  2575. case LPFC_ASYNC_LINK_STATUS_UP:
  2576. /* Ignore physical link up events - wait for logical link up */
  2577. att_type = AT_RESERVED;
  2578. break;
  2579. case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
  2580. att_type = AT_LINK_UP;
  2581. break;
  2582. default:
  2583. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2584. "0399 Invalid link attention type: x%x\n",
  2585. bf_get(lpfc_acqe_link_status, acqe_link));
  2586. att_type = AT_RESERVED;
  2587. break;
  2588. }
  2589. return att_type;
  2590. }
  2591. /**
  2592. * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
  2593. * @phba: pointer to lpfc hba data structure.
  2594. * @acqe_link: pointer to the async link completion queue entry.
  2595. *
  2596. * This routine is to parse the SLI4 link-attention link speed and translate
  2597. * it into the base driver's link-attention link speed coding.
  2598. *
  2599. * Return: Link-attention link speed in terms of base driver's coding.
  2600. **/
  2601. static uint8_t
  2602. lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
  2603. struct lpfc_acqe_link *acqe_link)
  2604. {
  2605. uint8_t link_speed;
  2606. switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
  2607. case LPFC_ASYNC_LINK_SPEED_ZERO:
  2608. link_speed = LA_UNKNW_LINK;
  2609. break;
  2610. case LPFC_ASYNC_LINK_SPEED_10MBPS:
  2611. link_speed = LA_UNKNW_LINK;
  2612. break;
  2613. case LPFC_ASYNC_LINK_SPEED_100MBPS:
  2614. link_speed = LA_UNKNW_LINK;
  2615. break;
  2616. case LPFC_ASYNC_LINK_SPEED_1GBPS:
  2617. link_speed = LA_1GHZ_LINK;
  2618. break;
  2619. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  2620. link_speed = LA_10GHZ_LINK;
  2621. break;
  2622. default:
  2623. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2624. "0483 Invalid link-attention link speed: x%x\n",
  2625. bf_get(lpfc_acqe_link_speed, acqe_link));
  2626. link_speed = LA_UNKNW_LINK;
  2627. break;
  2628. }
  2629. return link_speed;
  2630. }
  2631. /**
  2632. * lpfc_sli4_async_link_evt - Process the asynchronous link event
  2633. * @phba: pointer to lpfc hba data structure.
  2634. * @acqe_link: pointer to the async link completion queue entry.
  2635. *
  2636. * This routine is to handle the SLI4 asynchronous link event.
  2637. **/
  2638. static void
  2639. lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
  2640. struct lpfc_acqe_link *acqe_link)
  2641. {
  2642. struct lpfc_dmabuf *mp;
  2643. LPFC_MBOXQ_t *pmb;
  2644. MAILBOX_t *mb;
  2645. READ_LA_VAR *la;
  2646. uint8_t att_type;
  2647. att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
  2648. if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP)
  2649. return;
  2650. phba->fcoe_eventtag = acqe_link->event_tag;
  2651. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2652. if (!pmb) {
  2653. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2654. "0395 The mboxq allocation failed\n");
  2655. return;
  2656. }
  2657. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  2658. if (!mp) {
  2659. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2660. "0396 The lpfc_dmabuf allocation failed\n");
  2661. goto out_free_pmb;
  2662. }
  2663. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  2664. if (!mp->virt) {
  2665. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2666. "0397 The mbuf allocation failed\n");
  2667. goto out_free_dmabuf;
  2668. }
  2669. /* Cleanup any outstanding ELS commands */
  2670. lpfc_els_flush_all_cmd(phba);
  2671. /* Block ELS IOCBs until we have done process link event */
  2672. phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
  2673. /* Update link event statistics */
  2674. phba->sli.slistat.link_event++;
  2675. /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */
  2676. lpfc_read_la(phba, pmb, mp);
  2677. pmb->vport = phba->pport;
  2678. /* Parse and translate status field */
  2679. mb = &pmb->u.mb;
  2680. mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
  2681. /* Parse and translate link attention fields */
  2682. la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
  2683. la->eventTag = acqe_link->event_tag;
  2684. la->attType = att_type;
  2685. la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link);
  2686. /* Fake the the following irrelvant fields */
  2687. la->topology = TOPOLOGY_PT_PT;
  2688. la->granted_AL_PA = 0;
  2689. la->il = 0;
  2690. la->pb = 0;
  2691. la->fa = 0;
  2692. la->mm = 0;
  2693. /* Keep the link status for extra SLI4 state machine reference */
  2694. phba->sli4_hba.link_state.speed =
  2695. bf_get(lpfc_acqe_link_speed, acqe_link);
  2696. phba->sli4_hba.link_state.duplex =
  2697. bf_get(lpfc_acqe_link_duplex, acqe_link);
  2698. phba->sli4_hba.link_state.status =
  2699. bf_get(lpfc_acqe_link_status, acqe_link);
  2700. phba->sli4_hba.link_state.physical =
  2701. bf_get(lpfc_acqe_link_physical, acqe_link);
  2702. phba->sli4_hba.link_state.fault =
  2703. bf_get(lpfc_acqe_link_fault, acqe_link);
  2704. /* Invoke the lpfc_handle_latt mailbox command callback function */
  2705. lpfc_mbx_cmpl_read_la(phba, pmb);
  2706. return;
  2707. out_free_dmabuf:
  2708. kfree(mp);
  2709. out_free_pmb:
  2710. mempool_free(pmb, phba->mbox_mem_pool);
  2711. }
  2712. /**
  2713. * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event
  2714. * @phba: pointer to lpfc hba data structure.
  2715. * @acqe_link: pointer to the async fcoe completion queue entry.
  2716. *
  2717. * This routine is to handle the SLI4 asynchronous fcoe event.
  2718. **/
  2719. static void
  2720. lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
  2721. struct lpfc_acqe_fcoe *acqe_fcoe)
  2722. {
  2723. uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe);
  2724. int rc;
  2725. struct lpfc_vport *vport;
  2726. struct lpfc_nodelist *ndlp;
  2727. struct Scsi_Host *shost;
  2728. uint32_t link_state;
  2729. phba->fc_eventTag = acqe_fcoe->event_tag;
  2730. phba->fcoe_eventtag = acqe_fcoe->event_tag;
  2731. switch (event_type) {
  2732. case LPFC_FCOE_EVENT_TYPE_NEW_FCF:
  2733. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2734. "2546 New FCF found index 0x%x tag 0x%x\n",
  2735. acqe_fcoe->index,
  2736. acqe_fcoe->event_tag);
  2737. /*
  2738. * If the current FCF is in discovered state, or
  2739. * FCF discovery is in progress do nothing.
  2740. */
  2741. spin_lock_irq(&phba->hbalock);
  2742. if ((phba->fcf.fcf_flag & FCF_DISCOVERED) ||
  2743. (phba->hba_flag & FCF_DISC_INPROGRESS)) {
  2744. spin_unlock_irq(&phba->hbalock);
  2745. break;
  2746. }
  2747. spin_unlock_irq(&phba->hbalock);
  2748. /* Read the FCF table and re-discover SAN. */
  2749. rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  2750. if (rc)
  2751. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2752. "2547 Read FCF record failed 0x%x\n",
  2753. rc);
  2754. break;
  2755. case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL:
  2756. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2757. "2548 FCF Table full count 0x%x tag 0x%x\n",
  2758. bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe),
  2759. acqe_fcoe->event_tag);
  2760. break;
  2761. case LPFC_FCOE_EVENT_TYPE_FCF_DEAD:
  2762. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2763. "2549 FCF disconnected from network index 0x%x"
  2764. " tag 0x%x\n", acqe_fcoe->index,
  2765. acqe_fcoe->event_tag);
  2766. /* If the event is not for currently used fcf do nothing */
  2767. if (phba->fcf.fcf_indx != acqe_fcoe->index)
  2768. break;
  2769. /*
  2770. * Currently, driver support only one FCF - so treat this as
  2771. * a link down, but save the link state because we don't want
  2772. * it to be changed to Link Down unless it is already down.
  2773. */
  2774. link_state = phba->link_state;
  2775. lpfc_linkdown(phba);
  2776. phba->link_state = link_state;
  2777. /* Unregister FCF if no devices connected to it */
  2778. lpfc_unregister_unused_fcf(phba);
  2779. break;
  2780. case LPFC_FCOE_EVENT_TYPE_CVL:
  2781. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2782. "2718 Clear Virtual Link Received for VPI 0x%x"
  2783. " tag 0x%x\n", acqe_fcoe->index, acqe_fcoe->event_tag);
  2784. vport = lpfc_find_vport_by_vpid(phba,
  2785. acqe_fcoe->index - phba->vpi_base);
  2786. if (!vport)
  2787. break;
  2788. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  2789. if (!ndlp)
  2790. break;
  2791. shost = lpfc_shost_from_vport(vport);
  2792. lpfc_linkdown_port(vport);
  2793. if (vport->port_type != LPFC_NPIV_PORT) {
  2794. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  2795. spin_lock_irq(shost->host_lock);
  2796. ndlp->nlp_flag |= NLP_DELAY_TMO;
  2797. spin_unlock_irq(shost->host_lock);
  2798. ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
  2799. vport->port_state = LPFC_FLOGI;
  2800. }
  2801. break;
  2802. default:
  2803. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2804. "0288 Unknown FCoE event type 0x%x event tag "
  2805. "0x%x\n", event_type, acqe_fcoe->event_tag);
  2806. break;
  2807. }
  2808. }
  2809. /**
  2810. * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
  2811. * @phba: pointer to lpfc hba data structure.
  2812. * @acqe_link: pointer to the async dcbx completion queue entry.
  2813. *
  2814. * This routine is to handle the SLI4 asynchronous dcbx event.
  2815. **/
  2816. static void
  2817. lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
  2818. struct lpfc_acqe_dcbx *acqe_dcbx)
  2819. {
  2820. phba->fc_eventTag = acqe_dcbx->event_tag;
  2821. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2822. "0290 The SLI4 DCBX asynchronous event is not "
  2823. "handled yet\n");
  2824. }
  2825. /**
  2826. * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
  2827. * @phba: pointer to lpfc hba data structure.
  2828. *
  2829. * This routine is invoked by the worker thread to process all the pending
  2830. * SLI4 asynchronous events.
  2831. **/
  2832. void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
  2833. {
  2834. struct lpfc_cq_event *cq_event;
  2835. /* First, declare the async event has been handled */
  2836. spin_lock_irq(&phba->hbalock);
  2837. phba->hba_flag &= ~ASYNC_EVENT;
  2838. spin_unlock_irq(&phba->hbalock);
  2839. /* Now, handle all the async events */
  2840. while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
  2841. /* Get the first event from the head of the event queue */
  2842. spin_lock_irq(&phba->hbalock);
  2843. list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
  2844. cq_event, struct lpfc_cq_event, list);
  2845. spin_unlock_irq(&phba->hbalock);
  2846. /* Process the asynchronous event */
  2847. switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
  2848. case LPFC_TRAILER_CODE_LINK:
  2849. lpfc_sli4_async_link_evt(phba,
  2850. &cq_event->cqe.acqe_link);
  2851. break;
  2852. case LPFC_TRAILER_CODE_FCOE:
  2853. lpfc_sli4_async_fcoe_evt(phba,
  2854. &cq_event->cqe.acqe_fcoe);
  2855. break;
  2856. case LPFC_TRAILER_CODE_DCBX:
  2857. lpfc_sli4_async_dcbx_evt(phba,
  2858. &cq_event->cqe.acqe_dcbx);
  2859. break;
  2860. default:
  2861. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  2862. "1804 Invalid asynchrous event code: "
  2863. "x%x\n", bf_get(lpfc_trailer_code,
  2864. &cq_event->cqe.mcqe_cmpl));
  2865. break;
  2866. }
  2867. /* Free the completion event processed to the free pool */
  2868. lpfc_sli4_cq_event_release(phba, cq_event);
  2869. }
  2870. }
  2871. /**
  2872. * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
  2873. * @phba: pointer to lpfc hba data structure.
  2874. * @dev_grp: The HBA PCI-Device group number.
  2875. *
  2876. * This routine is invoked to set up the per HBA PCI-Device group function
  2877. * API jump table entries.
  2878. *
  2879. * Return: 0 if success, otherwise -ENODEV
  2880. **/
  2881. int
  2882. lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  2883. {
  2884. int rc;
  2885. /* Set up lpfc PCI-device group */
  2886. phba->pci_dev_grp = dev_grp;
  2887. /* The LPFC_PCI_DEV_OC uses SLI4 */
  2888. if (dev_grp == LPFC_PCI_DEV_OC)
  2889. phba->sli_rev = LPFC_SLI_REV4;
  2890. /* Set up device INIT API function jump table */
  2891. rc = lpfc_init_api_table_setup(phba, dev_grp);
  2892. if (rc)
  2893. return -ENODEV;
  2894. /* Set up SCSI API function jump table */
  2895. rc = lpfc_scsi_api_table_setup(phba, dev_grp);
  2896. if (rc)
  2897. return -ENODEV;
  2898. /* Set up SLI API function jump table */
  2899. rc = lpfc_sli_api_table_setup(phba, dev_grp);
  2900. if (rc)
  2901. return -ENODEV;
  2902. /* Set up MBOX API function jump table */
  2903. rc = lpfc_mbox_api_table_setup(phba, dev_grp);
  2904. if (rc)
  2905. return -ENODEV;
  2906. return 0;
  2907. }
  2908. /**
  2909. * lpfc_log_intr_mode - Log the active interrupt mode
  2910. * @phba: pointer to lpfc hba data structure.
  2911. * @intr_mode: active interrupt mode adopted.
  2912. *
  2913. * This routine it invoked to log the currently used active interrupt mode
  2914. * to the device.
  2915. **/
  2916. static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode)
  2917. {
  2918. switch (intr_mode) {
  2919. case 0:
  2920. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2921. "0470 Enable INTx interrupt mode.\n");
  2922. break;
  2923. case 1:
  2924. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2925. "0481 Enabled MSI interrupt mode.\n");
  2926. break;
  2927. case 2:
  2928. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  2929. "0480 Enabled MSI-X interrupt mode.\n");
  2930. break;
  2931. default:
  2932. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2933. "0482 Illegal interrupt mode.\n");
  2934. break;
  2935. }
  2936. return;
  2937. }
  2938. /**
  2939. * lpfc_enable_pci_dev - Enable a generic PCI device.
  2940. * @phba: pointer to lpfc hba data structure.
  2941. *
  2942. * This routine is invoked to enable the PCI device that is common to all
  2943. * PCI devices.
  2944. *
  2945. * Return codes
  2946. * 0 - successful
  2947. * other values - error
  2948. **/
  2949. static int
  2950. lpfc_enable_pci_dev(struct lpfc_hba *phba)
  2951. {
  2952. struct pci_dev *pdev;
  2953. int bars;
  2954. /* Obtain PCI device reference */
  2955. if (!phba->pcidev)
  2956. goto out_error;
  2957. else
  2958. pdev = phba->pcidev;
  2959. /* Select PCI BARs */
  2960. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2961. /* Enable PCI device */
  2962. if (pci_enable_device_mem(pdev))
  2963. goto out_error;
  2964. /* Request PCI resource for the device */
  2965. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  2966. goto out_disable_device;
  2967. /* Set up device as PCI master and save state for EEH */
  2968. pci_set_master(pdev);
  2969. pci_try_set_mwi(pdev);
  2970. pci_save_state(pdev);
  2971. return 0;
  2972. out_disable_device:
  2973. pci_disable_device(pdev);
  2974. out_error:
  2975. return -ENODEV;
  2976. }
  2977. /**
  2978. * lpfc_disable_pci_dev - Disable a generic PCI device.
  2979. * @phba: pointer to lpfc hba data structure.
  2980. *
  2981. * This routine is invoked to disable the PCI device that is common to all
  2982. * PCI devices.
  2983. **/
  2984. static void
  2985. lpfc_disable_pci_dev(struct lpfc_hba *phba)
  2986. {
  2987. struct pci_dev *pdev;
  2988. int bars;
  2989. /* Obtain PCI device reference */
  2990. if (!phba->pcidev)
  2991. return;
  2992. else
  2993. pdev = phba->pcidev;
  2994. /* Select PCI BARs */
  2995. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2996. /* Release PCI resource and disable PCI device */
  2997. pci_release_selected_regions(pdev, bars);
  2998. pci_disable_device(pdev);
  2999. /* Null out PCI private reference to driver */
  3000. pci_set_drvdata(pdev, NULL);
  3001. return;
  3002. }
  3003. /**
  3004. * lpfc_reset_hba - Reset a hba
  3005. * @phba: pointer to lpfc hba data structure.
  3006. *
  3007. * This routine is invoked to reset a hba device. It brings the HBA
  3008. * offline, performs a board restart, and then brings the board back
  3009. * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
  3010. * on outstanding mailbox commands.
  3011. **/
  3012. void
  3013. lpfc_reset_hba(struct lpfc_hba *phba)
  3014. {
  3015. /* If resets are disabled then set error state and return. */
  3016. if (!phba->cfg_enable_hba_reset) {
  3017. phba->link_state = LPFC_HBA_ERROR;
  3018. return;
  3019. }
  3020. lpfc_offline_prep(phba);
  3021. lpfc_offline(phba);
  3022. lpfc_sli_brdrestart(phba);
  3023. lpfc_online(phba);
  3024. lpfc_unblock_mgmt_io(phba);
  3025. }
  3026. /**
  3027. * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
  3028. * @phba: pointer to lpfc hba data structure.
  3029. *
  3030. * This routine is invoked to set up the driver internal resources specific to
  3031. * support the SLI-3 HBA device it attached to.
  3032. *
  3033. * Return codes
  3034. * 0 - successful
  3035. * other values - error
  3036. **/
  3037. static int
  3038. lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
  3039. {
  3040. struct lpfc_sli *psli;
  3041. /*
  3042. * Initialize timers used by driver
  3043. */
  3044. /* Heartbeat timer */
  3045. init_timer(&phba->hb_tmofunc);
  3046. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3047. phba->hb_tmofunc.data = (unsigned long)phba;
  3048. psli = &phba->sli;
  3049. /* MBOX heartbeat timer */
  3050. init_timer(&psli->mbox_tmo);
  3051. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3052. psli->mbox_tmo.data = (unsigned long) phba;
  3053. /* FCP polling mode timer */
  3054. init_timer(&phba->fcp_poll_timer);
  3055. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  3056. phba->fcp_poll_timer.data = (unsigned long) phba;
  3057. /* Fabric block timer */
  3058. init_timer(&phba->fabric_block_timer);
  3059. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3060. phba->fabric_block_timer.data = (unsigned long) phba;
  3061. /* EA polling mode timer */
  3062. init_timer(&phba->eratt_poll);
  3063. phba->eratt_poll.function = lpfc_poll_eratt;
  3064. phba->eratt_poll.data = (unsigned long) phba;
  3065. /* Host attention work mask setup */
  3066. phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT);
  3067. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  3068. /* Get all the module params for configuring this host */
  3069. lpfc_get_cfgparam(phba);
  3070. /*
  3071. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3072. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3073. * 2 segments are added since the IOCB needs a command and response bde.
  3074. */
  3075. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  3076. sizeof(struct fcp_rsp) +
  3077. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  3078. if (phba->cfg_enable_bg) {
  3079. phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT;
  3080. phba->cfg_sg_dma_buf_size +=
  3081. phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64);
  3082. }
  3083. /* Also reinitialize the host templates with new values. */
  3084. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3085. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  3086. phba->max_vpi = LPFC_MAX_VPI;
  3087. /* This will be set to correct value after config_port mbox */
  3088. phba->max_vports = 0;
  3089. /*
  3090. * Initialize the SLI Layer to run with lpfc HBAs.
  3091. */
  3092. lpfc_sli_setup(phba);
  3093. lpfc_sli_queue_setup(phba);
  3094. /* Allocate device driver memory */
  3095. if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ))
  3096. return -ENOMEM;
  3097. return 0;
  3098. }
  3099. /**
  3100. * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
  3101. * @phba: pointer to lpfc hba data structure.
  3102. *
  3103. * This routine is invoked to unset the driver internal resources set up
  3104. * specific for supporting the SLI-3 HBA device it attached to.
  3105. **/
  3106. static void
  3107. lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
  3108. {
  3109. /* Free device driver memory allocated */
  3110. lpfc_mem_free_all(phba);
  3111. return;
  3112. }
  3113. /**
  3114. * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
  3115. * @phba: pointer to lpfc hba data structure.
  3116. *
  3117. * This routine is invoked to set up the driver internal resources specific to
  3118. * support the SLI-4 HBA device it attached to.
  3119. *
  3120. * Return codes
  3121. * 0 - successful
  3122. * other values - error
  3123. **/
  3124. static int
  3125. lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
  3126. {
  3127. struct lpfc_sli *psli;
  3128. int rc;
  3129. int i, hbq_count;
  3130. /* Before proceed, wait for POST done and device ready */
  3131. rc = lpfc_sli4_post_status_check(phba);
  3132. if (rc)
  3133. return -ENODEV;
  3134. /*
  3135. * Initialize timers used by driver
  3136. */
  3137. /* Heartbeat timer */
  3138. init_timer(&phba->hb_tmofunc);
  3139. phba->hb_tmofunc.function = lpfc_hb_timeout;
  3140. phba->hb_tmofunc.data = (unsigned long)phba;
  3141. psli = &phba->sli;
  3142. /* MBOX heartbeat timer */
  3143. init_timer(&psli->mbox_tmo);
  3144. psli->mbox_tmo.function = lpfc_mbox_timeout;
  3145. psli->mbox_tmo.data = (unsigned long) phba;
  3146. /* Fabric block timer */
  3147. init_timer(&phba->fabric_block_timer);
  3148. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  3149. phba->fabric_block_timer.data = (unsigned long) phba;
  3150. /* EA polling mode timer */
  3151. init_timer(&phba->eratt_poll);
  3152. phba->eratt_poll.function = lpfc_poll_eratt;
  3153. phba->eratt_poll.data = (unsigned long) phba;
  3154. /*
  3155. * We need to do a READ_CONFIG mailbox command here before
  3156. * calling lpfc_get_cfgparam. For VFs this will report the
  3157. * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
  3158. * All of the resources allocated
  3159. * for this Port are tied to these values.
  3160. */
  3161. /* Get all the module params for configuring this host */
  3162. lpfc_get_cfgparam(phba);
  3163. phba->max_vpi = LPFC_MAX_VPI;
  3164. /* This will be set to correct value after the read_config mbox */
  3165. phba->max_vports = 0;
  3166. /* Program the default value of vlan_id and fc_map */
  3167. phba->valid_vlan = 0;
  3168. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  3169. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  3170. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  3171. /*
  3172. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  3173. * used to create the sg_dma_buf_pool must be dynamically calculated.
  3174. * 2 segments are added since the IOCB needs a command and response bde.
  3175. * To insure that the scsi sgl does not cross a 4k page boundary only
  3176. * sgl sizes of 1k, 2k, 4k, and 8k are supported.
  3177. * Table of sgl sizes and seg_cnt:
  3178. * sgl size, sg_seg_cnt total seg
  3179. * 1k 50 52
  3180. * 2k 114 116
  3181. * 4k 242 244
  3182. * 8k 498 500
  3183. * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024
  3184. * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048
  3185. * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096
  3186. * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192
  3187. */
  3188. if (phba->cfg_sg_seg_cnt <= LPFC_DEFAULT_SG_SEG_CNT)
  3189. phba->cfg_sg_seg_cnt = 50;
  3190. else if (phba->cfg_sg_seg_cnt <= 114)
  3191. phba->cfg_sg_seg_cnt = 114;
  3192. else if (phba->cfg_sg_seg_cnt <= 242)
  3193. phba->cfg_sg_seg_cnt = 242;
  3194. else
  3195. phba->cfg_sg_seg_cnt = 498;
  3196. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd)
  3197. + sizeof(struct fcp_rsp);
  3198. phba->cfg_sg_dma_buf_size +=
  3199. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
  3200. /* Initialize buffer queue management fields */
  3201. hbq_count = lpfc_sli_hbq_count();
  3202. for (i = 0; i < hbq_count; ++i)
  3203. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  3204. INIT_LIST_HEAD(&phba->rb_pend_list);
  3205. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
  3206. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
  3207. /*
  3208. * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
  3209. */
  3210. /* Initialize the Abort scsi buffer list used by driver */
  3211. spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
  3212. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
  3213. /* This abort list used by worker thread */
  3214. spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
  3215. /*
  3216. * Initialize dirver internal slow-path work queues
  3217. */
  3218. /* Driver internel slow-path CQ Event pool */
  3219. INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
  3220. /* Response IOCB work queue list */
  3221. INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event);
  3222. /* Asynchronous event CQ Event work queue list */
  3223. INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
  3224. /* Fast-path XRI aborted CQ Event work queue list */
  3225. INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
  3226. /* Slow-path XRI aborted CQ Event work queue list */
  3227. INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
  3228. /* Receive queue CQ Event work queue list */
  3229. INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
  3230. /* Initialize the driver internal SLI layer lists. */
  3231. lpfc_sli_setup(phba);
  3232. lpfc_sli_queue_setup(phba);
  3233. /* Allocate device driver memory */
  3234. rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
  3235. if (rc)
  3236. return -ENOMEM;
  3237. /* Create the bootstrap mailbox command */
  3238. rc = lpfc_create_bootstrap_mbox(phba);
  3239. if (unlikely(rc))
  3240. goto out_free_mem;
  3241. /* Set up the host's endian order with the device. */
  3242. rc = lpfc_setup_endian_order(phba);
  3243. if (unlikely(rc))
  3244. goto out_free_bsmbx;
  3245. rc = lpfc_sli4_fw_cfg_check(phba);
  3246. if (unlikely(rc))
  3247. goto out_free_bsmbx;
  3248. /* Set up the hba's configuration parameters. */
  3249. rc = lpfc_sli4_read_config(phba);
  3250. if (unlikely(rc))
  3251. goto out_free_bsmbx;
  3252. /* Perform a function reset */
  3253. rc = lpfc_pci_function_reset(phba);
  3254. if (unlikely(rc))
  3255. goto out_free_bsmbx;
  3256. /* Create all the SLI4 queues */
  3257. rc = lpfc_sli4_queue_create(phba);
  3258. if (rc)
  3259. goto out_free_bsmbx;
  3260. /* Create driver internal CQE event pool */
  3261. rc = lpfc_sli4_cq_event_pool_create(phba);
  3262. if (rc)
  3263. goto out_destroy_queue;
  3264. /* Initialize and populate the iocb list per host */
  3265. rc = lpfc_init_sgl_list(phba);
  3266. if (rc) {
  3267. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3268. "1400 Failed to initialize sgl list.\n");
  3269. goto out_destroy_cq_event_pool;
  3270. }
  3271. rc = lpfc_init_active_sgl_array(phba);
  3272. if (rc) {
  3273. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3274. "1430 Failed to initialize sgl list.\n");
  3275. goto out_free_sgl_list;
  3276. }
  3277. rc = lpfc_sli4_init_rpi_hdrs(phba);
  3278. if (rc) {
  3279. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3280. "1432 Failed to initialize rpi headers.\n");
  3281. goto out_free_active_sgl;
  3282. }
  3283. phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
  3284. phba->cfg_fcp_eq_count), GFP_KERNEL);
  3285. if (!phba->sli4_hba.fcp_eq_hdl) {
  3286. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3287. "2572 Failed allocate memory for fast-path "
  3288. "per-EQ handle array\n");
  3289. goto out_remove_rpi_hdrs;
  3290. }
  3291. phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
  3292. phba->sli4_hba.cfg_eqn), GFP_KERNEL);
  3293. if (!phba->sli4_hba.msix_entries) {
  3294. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3295. "2573 Failed allocate memory for msi-x "
  3296. "interrupt vector entries\n");
  3297. goto out_free_fcp_eq_hdl;
  3298. }
  3299. return rc;
  3300. out_free_fcp_eq_hdl:
  3301. kfree(phba->sli4_hba.fcp_eq_hdl);
  3302. out_remove_rpi_hdrs:
  3303. lpfc_sli4_remove_rpi_hdrs(phba);
  3304. out_free_active_sgl:
  3305. lpfc_free_active_sgl(phba);
  3306. out_free_sgl_list:
  3307. lpfc_free_sgl_list(phba);
  3308. out_destroy_cq_event_pool:
  3309. lpfc_sli4_cq_event_pool_destroy(phba);
  3310. out_destroy_queue:
  3311. lpfc_sli4_queue_destroy(phba);
  3312. out_free_bsmbx:
  3313. lpfc_destroy_bootstrap_mbox(phba);
  3314. out_free_mem:
  3315. lpfc_mem_free(phba);
  3316. return rc;
  3317. }
  3318. /**
  3319. * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
  3320. * @phba: pointer to lpfc hba data structure.
  3321. *
  3322. * This routine is invoked to unset the driver internal resources set up
  3323. * specific for supporting the SLI-4 HBA device it attached to.
  3324. **/
  3325. static void
  3326. lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
  3327. {
  3328. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  3329. /* unregister default FCFI from the HBA */
  3330. lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
  3331. /* Free the default FCR table */
  3332. lpfc_sli_remove_dflt_fcf(phba);
  3333. /* Free memory allocated for msi-x interrupt vector entries */
  3334. kfree(phba->sli4_hba.msix_entries);
  3335. /* Free memory allocated for fast-path work queue handles */
  3336. kfree(phba->sli4_hba.fcp_eq_hdl);
  3337. /* Free the allocated rpi headers. */
  3338. lpfc_sli4_remove_rpi_hdrs(phba);
  3339. lpfc_sli4_remove_rpis(phba);
  3340. /* Free the ELS sgl list */
  3341. lpfc_free_active_sgl(phba);
  3342. lpfc_free_sgl_list(phba);
  3343. /* Free the SCSI sgl management array */
  3344. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  3345. /* Free the SLI4 queues */
  3346. lpfc_sli4_queue_destroy(phba);
  3347. /* Free the completion queue EQ event pool */
  3348. lpfc_sli4_cq_event_release_all(phba);
  3349. lpfc_sli4_cq_event_pool_destroy(phba);
  3350. /* Reset SLI4 HBA FCoE function */
  3351. lpfc_pci_function_reset(phba);
  3352. /* Free the bsmbx region. */
  3353. lpfc_destroy_bootstrap_mbox(phba);
  3354. /* Free the SLI Layer memory with SLI4 HBAs */
  3355. lpfc_mem_free_all(phba);
  3356. /* Free the current connect table */
  3357. list_for_each_entry_safe(conn_entry, next_conn_entry,
  3358. &phba->fcf_conn_rec_list, list) {
  3359. list_del_init(&conn_entry->list);
  3360. kfree(conn_entry);
  3361. }
  3362. return;
  3363. }
  3364. /**
  3365. * lpfc_init_api_table_setup - Set up init api fucntion jump table
  3366. * @phba: The hba struct for which this call is being executed.
  3367. * @dev_grp: The HBA PCI-Device group number.
  3368. *
  3369. * This routine sets up the device INIT interface API function jump table
  3370. * in @phba struct.
  3371. *
  3372. * Returns: 0 - success, -ENODEV - failure.
  3373. **/
  3374. int
  3375. lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  3376. {
  3377. switch (dev_grp) {
  3378. case LPFC_PCI_DEV_LP:
  3379. phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
  3380. phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
  3381. phba->lpfc_stop_port = lpfc_stop_port_s3;
  3382. break;
  3383. case LPFC_PCI_DEV_OC:
  3384. phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
  3385. phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
  3386. phba->lpfc_stop_port = lpfc_stop_port_s4;
  3387. break;
  3388. default:
  3389. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3390. "1431 Invalid HBA PCI-device group: 0x%x\n",
  3391. dev_grp);
  3392. return -ENODEV;
  3393. break;
  3394. }
  3395. return 0;
  3396. }
  3397. /**
  3398. * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
  3399. * @phba: pointer to lpfc hba data structure.
  3400. *
  3401. * This routine is invoked to set up the driver internal resources before the
  3402. * device specific resource setup to support the HBA device it attached to.
  3403. *
  3404. * Return codes
  3405. * 0 - successful
  3406. * other values - error
  3407. **/
  3408. static int
  3409. lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
  3410. {
  3411. /*
  3412. * Driver resources common to all SLI revisions
  3413. */
  3414. atomic_set(&phba->fast_event_count, 0);
  3415. spin_lock_init(&phba->hbalock);
  3416. /* Initialize ndlp management spinlock */
  3417. spin_lock_init(&phba->ndlp_lock);
  3418. INIT_LIST_HEAD(&phba->port_list);
  3419. INIT_LIST_HEAD(&phba->work_list);
  3420. init_waitqueue_head(&phba->wait_4_mlo_m_q);
  3421. /* Initialize the wait queue head for the kernel thread */
  3422. init_waitqueue_head(&phba->work_waitq);
  3423. /* Initialize the scsi buffer list used by driver for scsi IO */
  3424. spin_lock_init(&phba->scsi_buf_list_lock);
  3425. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  3426. /* Initialize the fabric iocb list */
  3427. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  3428. /* Initialize list to save ELS buffers */
  3429. INIT_LIST_HEAD(&phba->elsbuf);
  3430. /* Initialize FCF connection rec list */
  3431. INIT_LIST_HEAD(&phba->fcf_conn_rec_list);
  3432. return 0;
  3433. }
  3434. /**
  3435. * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
  3436. * @phba: pointer to lpfc hba data structure.
  3437. *
  3438. * This routine is invoked to set up the driver internal resources after the
  3439. * device specific resource setup to support the HBA device it attached to.
  3440. *
  3441. * Return codes
  3442. * 0 - successful
  3443. * other values - error
  3444. **/
  3445. static int
  3446. lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba)
  3447. {
  3448. int error;
  3449. /* Startup the kernel thread for this host adapter. */
  3450. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  3451. "lpfc_worker_%d", phba->brd_no);
  3452. if (IS_ERR(phba->worker_thread)) {
  3453. error = PTR_ERR(phba->worker_thread);
  3454. return error;
  3455. }
  3456. return 0;
  3457. }
  3458. /**
  3459. * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
  3460. * @phba: pointer to lpfc hba data structure.
  3461. *
  3462. * This routine is invoked to unset the driver internal resources set up after
  3463. * the device specific resource setup for supporting the HBA device it
  3464. * attached to.
  3465. **/
  3466. static void
  3467. lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba)
  3468. {
  3469. /* Stop kernel worker thread */
  3470. kthread_stop(phba->worker_thread);
  3471. }
  3472. /**
  3473. * lpfc_free_iocb_list - Free iocb list.
  3474. * @phba: pointer to lpfc hba data structure.
  3475. *
  3476. * This routine is invoked to free the driver's IOCB list and memory.
  3477. **/
  3478. static void
  3479. lpfc_free_iocb_list(struct lpfc_hba *phba)
  3480. {
  3481. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  3482. spin_lock_irq(&phba->hbalock);
  3483. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  3484. &phba->lpfc_iocb_list, list) {
  3485. list_del(&iocbq_entry->list);
  3486. kfree(iocbq_entry);
  3487. phba->total_iocbq_bufs--;
  3488. }
  3489. spin_unlock_irq(&phba->hbalock);
  3490. return;
  3491. }
  3492. /**
  3493. * lpfc_init_iocb_list - Allocate and initialize iocb list.
  3494. * @phba: pointer to lpfc hba data structure.
  3495. *
  3496. * This routine is invoked to allocate and initizlize the driver's IOCB
  3497. * list and set up the IOCB tag array accordingly.
  3498. *
  3499. * Return codes
  3500. * 0 - successful
  3501. * other values - error
  3502. **/
  3503. static int
  3504. lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count)
  3505. {
  3506. struct lpfc_iocbq *iocbq_entry = NULL;
  3507. uint16_t iotag;
  3508. int i;
  3509. /* Initialize and populate the iocb list per host. */
  3510. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  3511. for (i = 0; i < iocb_count; i++) {
  3512. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  3513. if (iocbq_entry == NULL) {
  3514. printk(KERN_ERR "%s: only allocated %d iocbs of "
  3515. "expected %d count. Unloading driver.\n",
  3516. __func__, i, LPFC_IOCB_LIST_CNT);
  3517. goto out_free_iocbq;
  3518. }
  3519. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  3520. if (iotag == 0) {
  3521. kfree(iocbq_entry);
  3522. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  3523. "Unloading driver.\n", __func__);
  3524. goto out_free_iocbq;
  3525. }
  3526. iocbq_entry->sli4_xritag = NO_XRI;
  3527. spin_lock_irq(&phba->hbalock);
  3528. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  3529. phba->total_iocbq_bufs++;
  3530. spin_unlock_irq(&phba->hbalock);
  3531. }
  3532. return 0;
  3533. out_free_iocbq:
  3534. lpfc_free_iocb_list(phba);
  3535. return -ENOMEM;
  3536. }
  3537. /**
  3538. * lpfc_free_sgl_list - Free sgl list.
  3539. * @phba: pointer to lpfc hba data structure.
  3540. *
  3541. * This routine is invoked to free the driver's sgl list and memory.
  3542. **/
  3543. static void
  3544. lpfc_free_sgl_list(struct lpfc_hba *phba)
  3545. {
  3546. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  3547. LIST_HEAD(sglq_list);
  3548. int rc = 0;
  3549. spin_lock_irq(&phba->hbalock);
  3550. list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
  3551. spin_unlock_irq(&phba->hbalock);
  3552. list_for_each_entry_safe(sglq_entry, sglq_next,
  3553. &sglq_list, list) {
  3554. list_del(&sglq_entry->list);
  3555. lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
  3556. kfree(sglq_entry);
  3557. phba->sli4_hba.total_sglq_bufs--;
  3558. }
  3559. rc = lpfc_sli4_remove_all_sgl_pages(phba);
  3560. if (rc) {
  3561. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3562. "2005 Unable to deregister pages from HBA: %x\n", rc);
  3563. }
  3564. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  3565. }
  3566. /**
  3567. * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
  3568. * @phba: pointer to lpfc hba data structure.
  3569. *
  3570. * This routine is invoked to allocate the driver's active sgl memory.
  3571. * This array will hold the sglq_entry's for active IOs.
  3572. **/
  3573. static int
  3574. lpfc_init_active_sgl_array(struct lpfc_hba *phba)
  3575. {
  3576. int size;
  3577. size = sizeof(struct lpfc_sglq *);
  3578. size *= phba->sli4_hba.max_cfg_param.max_xri;
  3579. phba->sli4_hba.lpfc_sglq_active_list =
  3580. kzalloc(size, GFP_KERNEL);
  3581. if (!phba->sli4_hba.lpfc_sglq_active_list)
  3582. return -ENOMEM;
  3583. return 0;
  3584. }
  3585. /**
  3586. * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
  3587. * @phba: pointer to lpfc hba data structure.
  3588. *
  3589. * This routine is invoked to walk through the array of active sglq entries
  3590. * and free all of the resources.
  3591. * This is just a place holder for now.
  3592. **/
  3593. static void
  3594. lpfc_free_active_sgl(struct lpfc_hba *phba)
  3595. {
  3596. kfree(phba->sli4_hba.lpfc_sglq_active_list);
  3597. }
  3598. /**
  3599. * lpfc_init_sgl_list - Allocate and initialize sgl list.
  3600. * @phba: pointer to lpfc hba data structure.
  3601. *
  3602. * This routine is invoked to allocate and initizlize the driver's sgl
  3603. * list and set up the sgl xritag tag array accordingly.
  3604. *
  3605. * Return codes
  3606. * 0 - successful
  3607. * other values - error
  3608. **/
  3609. static int
  3610. lpfc_init_sgl_list(struct lpfc_hba *phba)
  3611. {
  3612. struct lpfc_sglq *sglq_entry = NULL;
  3613. int i;
  3614. int els_xri_cnt;
  3615. els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
  3616. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3617. "2400 lpfc_init_sgl_list els %d.\n",
  3618. els_xri_cnt);
  3619. /* Initialize and populate the sglq list per host/VF. */
  3620. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
  3621. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
  3622. /* Sanity check on XRI management */
  3623. if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
  3624. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3625. "2562 No room left for SCSI XRI allocation: "
  3626. "max_xri=%d, els_xri=%d\n",
  3627. phba->sli4_hba.max_cfg_param.max_xri,
  3628. els_xri_cnt);
  3629. return -ENOMEM;
  3630. }
  3631. /* Allocate memory for the ELS XRI management array */
  3632. phba->sli4_hba.lpfc_els_sgl_array =
  3633. kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
  3634. GFP_KERNEL);
  3635. if (!phba->sli4_hba.lpfc_els_sgl_array) {
  3636. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3637. "2401 Failed to allocate memory for ELS "
  3638. "XRI management array of size %d.\n",
  3639. els_xri_cnt);
  3640. return -ENOMEM;
  3641. }
  3642. /* Keep the SCSI XRI into the XRI management array */
  3643. phba->sli4_hba.scsi_xri_max =
  3644. phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
  3645. phba->sli4_hba.scsi_xri_cnt = 0;
  3646. phba->sli4_hba.lpfc_scsi_psb_array =
  3647. kzalloc((sizeof(struct lpfc_scsi_buf *) *
  3648. phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
  3649. if (!phba->sli4_hba.lpfc_scsi_psb_array) {
  3650. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  3651. "2563 Failed to allocate memory for SCSI "
  3652. "XRI management array of size %d.\n",
  3653. phba->sli4_hba.scsi_xri_max);
  3654. kfree(phba->sli4_hba.lpfc_els_sgl_array);
  3655. return -ENOMEM;
  3656. }
  3657. for (i = 0; i < els_xri_cnt; i++) {
  3658. sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
  3659. if (sglq_entry == NULL) {
  3660. printk(KERN_ERR "%s: only allocated %d sgls of "
  3661. "expected %d count. Unloading driver.\n",
  3662. __func__, i, els_xri_cnt);
  3663. goto out_free_mem;
  3664. }
  3665. sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba);
  3666. if (sglq_entry->sli4_xritag == NO_XRI) {
  3667. kfree(sglq_entry);
  3668. printk(KERN_ERR "%s: failed to allocate XRI.\n"
  3669. "Unloading driver.\n", __func__);
  3670. goto out_free_mem;
  3671. }
  3672. sglq_entry->buff_type = GEN_BUFF_TYPE;
  3673. sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
  3674. if (sglq_entry->virt == NULL) {
  3675. kfree(sglq_entry);
  3676. printk(KERN_ERR "%s: failed to allocate mbuf.\n"
  3677. "Unloading driver.\n", __func__);
  3678. goto out_free_mem;
  3679. }
  3680. sglq_entry->sgl = sglq_entry->virt;
  3681. memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
  3682. /* The list order is used by later block SGL registraton */
  3683. spin_lock_irq(&phba->hbalock);
  3684. list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
  3685. phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
  3686. phba->sli4_hba.total_sglq_bufs++;
  3687. spin_unlock_irq(&phba->hbalock);
  3688. }
  3689. return 0;
  3690. out_free_mem:
  3691. kfree(phba->sli4_hba.lpfc_scsi_psb_array);
  3692. lpfc_free_sgl_list(phba);
  3693. return -ENOMEM;
  3694. }
  3695. /**
  3696. * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
  3697. * @phba: pointer to lpfc hba data structure.
  3698. *
  3699. * This routine is invoked to post rpi header templates to the
  3700. * HBA consistent with the SLI-4 interface spec. This routine
  3701. * posts a PAGE_SIZE memory region to the port to hold up to
  3702. * PAGE_SIZE modulo 64 rpi context headers.
  3703. * No locks are held here because this is an initialization routine
  3704. * called only from probe or lpfc_online when interrupts are not
  3705. * enabled and the driver is reinitializing the device.
  3706. *
  3707. * Return codes
  3708. * 0 - successful
  3709. * ENOMEM - No availble memory
  3710. * EIO - The mailbox failed to complete successfully.
  3711. **/
  3712. int
  3713. lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
  3714. {
  3715. int rc = 0;
  3716. int longs;
  3717. uint16_t rpi_count;
  3718. struct lpfc_rpi_hdr *rpi_hdr;
  3719. INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
  3720. /*
  3721. * Provision an rpi bitmask range for discovery. The total count
  3722. * is the difference between max and base + 1.
  3723. */
  3724. rpi_count = phba->sli4_hba.max_cfg_param.rpi_base +
  3725. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  3726. longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  3727. phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long),
  3728. GFP_KERNEL);
  3729. if (!phba->sli4_hba.rpi_bmask)
  3730. return -ENOMEM;
  3731. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  3732. if (!rpi_hdr) {
  3733. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  3734. "0391 Error during rpi post operation\n");
  3735. lpfc_sli4_remove_rpis(phba);
  3736. rc = -ENODEV;
  3737. }
  3738. return rc;
  3739. }
  3740. /**
  3741. * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
  3742. * @phba: pointer to lpfc hba data structure.
  3743. *
  3744. * This routine is invoked to allocate a single 4KB memory region to
  3745. * support rpis and stores them in the phba. This single region
  3746. * provides support for up to 64 rpis. The region is used globally
  3747. * by the device.
  3748. *
  3749. * Returns:
  3750. * A valid rpi hdr on success.
  3751. * A NULL pointer on any failure.
  3752. **/
  3753. struct lpfc_rpi_hdr *
  3754. lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
  3755. {
  3756. uint16_t rpi_limit, curr_rpi_range;
  3757. struct lpfc_dmabuf *dmabuf;
  3758. struct lpfc_rpi_hdr *rpi_hdr;
  3759. rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
  3760. phba->sli4_hba.max_cfg_param.max_rpi - 1;
  3761. spin_lock_irq(&phba->hbalock);
  3762. curr_rpi_range = phba->sli4_hba.next_rpi;
  3763. spin_unlock_irq(&phba->hbalock);
  3764. /*
  3765. * The port has a limited number of rpis. The increment here
  3766. * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
  3767. * and to allow the full max_rpi range per port.
  3768. */
  3769. if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
  3770. return NULL;
  3771. /*
  3772. * First allocate the protocol header region for the port. The
  3773. * port expects a 4KB DMA-mapped memory region that is 4K aligned.
  3774. */
  3775. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  3776. if (!dmabuf)
  3777. return NULL;
  3778. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  3779. LPFC_HDR_TEMPLATE_SIZE,
  3780. &dmabuf->phys,
  3781. GFP_KERNEL);
  3782. if (!dmabuf->virt) {
  3783. rpi_hdr = NULL;
  3784. goto err_free_dmabuf;
  3785. }
  3786. memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
  3787. if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
  3788. rpi_hdr = NULL;
  3789. goto err_free_coherent;
  3790. }
  3791. /* Save the rpi header data for cleanup later. */
  3792. rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
  3793. if (!rpi_hdr)
  3794. goto err_free_coherent;
  3795. rpi_hdr->dmabuf = dmabuf;
  3796. rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
  3797. rpi_hdr->page_count = 1;
  3798. spin_lock_irq(&phba->hbalock);
  3799. rpi_hdr->start_rpi = phba->sli4_hba.next_rpi;
  3800. list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
  3801. /*
  3802. * The next_rpi stores the next module-64 rpi value to post
  3803. * in any subsequent rpi memory region postings.
  3804. */
  3805. phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT;
  3806. spin_unlock_irq(&phba->hbalock);
  3807. return rpi_hdr;
  3808. err_free_coherent:
  3809. dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
  3810. dmabuf->virt, dmabuf->phys);
  3811. err_free_dmabuf:
  3812. kfree(dmabuf);
  3813. return NULL;
  3814. }
  3815. /**
  3816. * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
  3817. * @phba: pointer to lpfc hba data structure.
  3818. *
  3819. * This routine is invoked to remove all memory resources allocated
  3820. * to support rpis. This routine presumes the caller has released all
  3821. * rpis consumed by fabric or port logins and is prepared to have
  3822. * the header pages removed.
  3823. **/
  3824. void
  3825. lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
  3826. {
  3827. struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
  3828. list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
  3829. &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  3830. list_del(&rpi_hdr->list);
  3831. dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
  3832. rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
  3833. kfree(rpi_hdr->dmabuf);
  3834. kfree(rpi_hdr);
  3835. }
  3836. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  3837. memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask));
  3838. }
  3839. /**
  3840. * lpfc_hba_alloc - Allocate driver hba data structure for a device.
  3841. * @pdev: pointer to pci device data structure.
  3842. *
  3843. * This routine is invoked to allocate the driver hba data structure for an
  3844. * HBA device. If the allocation is successful, the phba reference to the
  3845. * PCI device data structure is set.
  3846. *
  3847. * Return codes
  3848. * pointer to @phba - successful
  3849. * NULL - error
  3850. **/
  3851. static struct lpfc_hba *
  3852. lpfc_hba_alloc(struct pci_dev *pdev)
  3853. {
  3854. struct lpfc_hba *phba;
  3855. /* Allocate memory for HBA structure */
  3856. phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL);
  3857. if (!phba) {
  3858. dev_err(&pdev->dev, "failed to allocate hba struct\n");
  3859. return NULL;
  3860. }
  3861. /* Set reference to PCI device in HBA structure */
  3862. phba->pcidev = pdev;
  3863. /* Assign an unused board number */
  3864. phba->brd_no = lpfc_get_instance();
  3865. if (phba->brd_no < 0) {
  3866. kfree(phba);
  3867. return NULL;
  3868. }
  3869. mutex_init(&phba->ct_event_mutex);
  3870. INIT_LIST_HEAD(&phba->ct_ev_waiters);
  3871. return phba;
  3872. }
  3873. /**
  3874. * lpfc_hba_free - Free driver hba data structure with a device.
  3875. * @phba: pointer to lpfc hba data structure.
  3876. *
  3877. * This routine is invoked to free the driver hba data structure with an
  3878. * HBA device.
  3879. **/
  3880. static void
  3881. lpfc_hba_free(struct lpfc_hba *phba)
  3882. {
  3883. /* Release the driver assigned board number */
  3884. idr_remove(&lpfc_hba_index, phba->brd_no);
  3885. kfree(phba);
  3886. return;
  3887. }
  3888. /**
  3889. * lpfc_create_shost - Create hba physical port with associated scsi host.
  3890. * @phba: pointer to lpfc hba data structure.
  3891. *
  3892. * This routine is invoked to create HBA physical port and associate a SCSI
  3893. * host with it.
  3894. *
  3895. * Return codes
  3896. * 0 - successful
  3897. * other values - error
  3898. **/
  3899. static int
  3900. lpfc_create_shost(struct lpfc_hba *phba)
  3901. {
  3902. struct lpfc_vport *vport;
  3903. struct Scsi_Host *shost;
  3904. /* Initialize HBA FC structure */
  3905. phba->fc_edtov = FF_DEF_EDTOV;
  3906. phba->fc_ratov = FF_DEF_RATOV;
  3907. phba->fc_altov = FF_DEF_ALTOV;
  3908. phba->fc_arbtov = FF_DEF_ARBTOV;
  3909. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  3910. if (!vport)
  3911. return -ENODEV;
  3912. shost = lpfc_shost_from_vport(vport);
  3913. phba->pport = vport;
  3914. lpfc_debugfs_initialize(vport);
  3915. /* Put reference to SCSI host to driver's device private data */
  3916. pci_set_drvdata(phba->pcidev, shost);
  3917. return 0;
  3918. }
  3919. /**
  3920. * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
  3921. * @phba: pointer to lpfc hba data structure.
  3922. *
  3923. * This routine is invoked to destroy HBA physical port and the associated
  3924. * SCSI host.
  3925. **/
  3926. static void
  3927. lpfc_destroy_shost(struct lpfc_hba *phba)
  3928. {
  3929. struct lpfc_vport *vport = phba->pport;
  3930. /* Destroy physical port that associated with the SCSI host */
  3931. destroy_port(vport);
  3932. return;
  3933. }
  3934. /**
  3935. * lpfc_setup_bg - Setup Block guard structures and debug areas.
  3936. * @phba: pointer to lpfc hba data structure.
  3937. * @shost: the shost to be used to detect Block guard settings.
  3938. *
  3939. * This routine sets up the local Block guard protocol settings for @shost.
  3940. * This routine also allocates memory for debugging bg buffers.
  3941. **/
  3942. static void
  3943. lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost)
  3944. {
  3945. int pagecnt = 10;
  3946. if (lpfc_prot_mask && lpfc_prot_guard) {
  3947. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  3948. "1478 Registering BlockGuard with the "
  3949. "SCSI layer\n");
  3950. scsi_host_set_prot(shost, lpfc_prot_mask);
  3951. scsi_host_set_guard(shost, lpfc_prot_guard);
  3952. }
  3953. if (!_dump_buf_data) {
  3954. while (pagecnt) {
  3955. spin_lock_init(&_dump_buf_lock);
  3956. _dump_buf_data =
  3957. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  3958. if (_dump_buf_data) {
  3959. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3960. "9043 BLKGRD: allocated %d pages for "
  3961. "_dump_buf_data at 0x%p\n",
  3962. (1 << pagecnt), _dump_buf_data);
  3963. _dump_buf_data_order = pagecnt;
  3964. memset(_dump_buf_data, 0,
  3965. ((1 << PAGE_SHIFT) << pagecnt));
  3966. break;
  3967. } else
  3968. --pagecnt;
  3969. }
  3970. if (!_dump_buf_data_order)
  3971. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3972. "9044 BLKGRD: ERROR unable to allocate "
  3973. "memory for hexdump\n");
  3974. } else
  3975. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3976. "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
  3977. "\n", _dump_buf_data);
  3978. if (!_dump_buf_dif) {
  3979. while (pagecnt) {
  3980. _dump_buf_dif =
  3981. (char *) __get_free_pages(GFP_KERNEL, pagecnt);
  3982. if (_dump_buf_dif) {
  3983. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3984. "9046 BLKGRD: allocated %d pages for "
  3985. "_dump_buf_dif at 0x%p\n",
  3986. (1 << pagecnt), _dump_buf_dif);
  3987. _dump_buf_dif_order = pagecnt;
  3988. memset(_dump_buf_dif, 0,
  3989. ((1 << PAGE_SHIFT) << pagecnt));
  3990. break;
  3991. } else
  3992. --pagecnt;
  3993. }
  3994. if (!_dump_buf_dif_order)
  3995. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  3996. "9047 BLKGRD: ERROR unable to allocate "
  3997. "memory for hexdump\n");
  3998. } else
  3999. lpfc_printf_log(phba, KERN_ERR, LOG_BG,
  4000. "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
  4001. _dump_buf_dif);
  4002. }
  4003. /**
  4004. * lpfc_post_init_setup - Perform necessary device post initialization setup.
  4005. * @phba: pointer to lpfc hba data structure.
  4006. *
  4007. * This routine is invoked to perform all the necessary post initialization
  4008. * setup for the device.
  4009. **/
  4010. static void
  4011. lpfc_post_init_setup(struct lpfc_hba *phba)
  4012. {
  4013. struct Scsi_Host *shost;
  4014. struct lpfc_adapter_event_header adapter_event;
  4015. /* Get the default values for Model Name and Description */
  4016. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  4017. /*
  4018. * hba setup may have changed the hba_queue_depth so we need to
  4019. * adjust the value of can_queue.
  4020. */
  4021. shost = pci_get_drvdata(phba->pcidev);
  4022. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  4023. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  4024. lpfc_setup_bg(phba, shost);
  4025. lpfc_host_attrib_init(shost);
  4026. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  4027. spin_lock_irq(shost->host_lock);
  4028. lpfc_poll_start_timer(phba);
  4029. spin_unlock_irq(shost->host_lock);
  4030. }
  4031. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4032. "0428 Perform SCSI scan\n");
  4033. /* Send board arrival event to upper layer */
  4034. adapter_event.event_type = FC_REG_ADAPTER_EVENT;
  4035. adapter_event.subcategory = LPFC_EVENT_ARRIVAL;
  4036. fc_host_post_vendor_event(shost, fc_get_event_number(),
  4037. sizeof(adapter_event),
  4038. (char *) &adapter_event,
  4039. LPFC_NL_VENDOR_ID);
  4040. return;
  4041. }
  4042. /**
  4043. * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
  4044. * @phba: pointer to lpfc hba data structure.
  4045. *
  4046. * This routine is invoked to set up the PCI device memory space for device
  4047. * with SLI-3 interface spec.
  4048. *
  4049. * Return codes
  4050. * 0 - successful
  4051. * other values - error
  4052. **/
  4053. static int
  4054. lpfc_sli_pci_mem_setup(struct lpfc_hba *phba)
  4055. {
  4056. struct pci_dev *pdev;
  4057. unsigned long bar0map_len, bar2map_len;
  4058. int i, hbq_count;
  4059. void *ptr;
  4060. int error = -ENODEV;
  4061. /* Obtain PCI device reference */
  4062. if (!phba->pcidev)
  4063. return error;
  4064. else
  4065. pdev = phba->pcidev;
  4066. /* Set the device DMA mask size */
  4067. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  4068. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  4069. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  4070. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  4071. return error;
  4072. }
  4073. }
  4074. /* Get the bus address of Bar0 and Bar2 and the number of bytes
  4075. * required by each mapping.
  4076. */
  4077. phba->pci_bar0_map = pci_resource_start(pdev, 0);
  4078. bar0map_len = pci_resource_len(pdev, 0);
  4079. phba->pci_bar2_map = pci_resource_start(pdev, 2);
  4080. bar2map_len = pci_resource_len(pdev, 2);
  4081. /* Map HBA SLIM to a kernel virtual address. */
  4082. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  4083. if (!phba->slim_memmap_p) {
  4084. dev_printk(KERN_ERR, &pdev->dev,
  4085. "ioremap failed for SLIM memory.\n");
  4086. goto out;
  4087. }
  4088. /* Map HBA Control Registers to a kernel virtual address. */
  4089. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  4090. if (!phba->ctrl_regs_memmap_p) {
  4091. dev_printk(KERN_ERR, &pdev->dev,
  4092. "ioremap failed for HBA control registers.\n");
  4093. goto out_iounmap_slim;
  4094. }
  4095. /* Allocate memory for SLI-2 structures */
  4096. phba->slim2p.virt = dma_alloc_coherent(&pdev->dev,
  4097. SLI2_SLIM_SIZE,
  4098. &phba->slim2p.phys,
  4099. GFP_KERNEL);
  4100. if (!phba->slim2p.virt)
  4101. goto out_iounmap;
  4102. memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE);
  4103. phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx);
  4104. phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb));
  4105. phba->IOCBs = (phba->slim2p.virt +
  4106. offsetof(struct lpfc_sli2_slim, IOCBs));
  4107. phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev,
  4108. lpfc_sli_hbq_size(),
  4109. &phba->hbqslimp.phys,
  4110. GFP_KERNEL);
  4111. if (!phba->hbqslimp.virt)
  4112. goto out_free_slim;
  4113. hbq_count = lpfc_sli_hbq_count();
  4114. ptr = phba->hbqslimp.virt;
  4115. for (i = 0; i < hbq_count; ++i) {
  4116. phba->hbqs[i].hbq_virt = ptr;
  4117. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  4118. ptr += (lpfc_hbq_defs[i]->entry_count *
  4119. sizeof(struct lpfc_hbq_entry));
  4120. }
  4121. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  4122. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  4123. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  4124. INIT_LIST_HEAD(&phba->rb_pend_list);
  4125. phba->MBslimaddr = phba->slim_memmap_p;
  4126. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  4127. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  4128. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  4129. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  4130. return 0;
  4131. out_free_slim:
  4132. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4133. phba->slim2p.virt, phba->slim2p.phys);
  4134. out_iounmap:
  4135. iounmap(phba->ctrl_regs_memmap_p);
  4136. out_iounmap_slim:
  4137. iounmap(phba->slim_memmap_p);
  4138. out:
  4139. return error;
  4140. }
  4141. /**
  4142. * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
  4143. * @phba: pointer to lpfc hba data structure.
  4144. *
  4145. * This routine is invoked to unset the PCI device memory space for device
  4146. * with SLI-3 interface spec.
  4147. **/
  4148. static void
  4149. lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
  4150. {
  4151. struct pci_dev *pdev;
  4152. /* Obtain PCI device reference */
  4153. if (!phba->pcidev)
  4154. return;
  4155. else
  4156. pdev = phba->pcidev;
  4157. /* Free coherent DMA memory allocated */
  4158. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  4159. phba->hbqslimp.virt, phba->hbqslimp.phys);
  4160. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  4161. phba->slim2p.virt, phba->slim2p.phys);
  4162. /* I/O memory unmap */
  4163. iounmap(phba->ctrl_regs_memmap_p);
  4164. iounmap(phba->slim_memmap_p);
  4165. return;
  4166. }
  4167. /**
  4168. * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
  4169. * @phba: pointer to lpfc hba data structure.
  4170. *
  4171. * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
  4172. * done and check status.
  4173. *
  4174. * Return 0 if successful, otherwise -ENODEV.
  4175. **/
  4176. int
  4177. lpfc_sli4_post_status_check(struct lpfc_hba *phba)
  4178. {
  4179. struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg, scratchpad;
  4180. int i, port_error = -ENODEV;
  4181. if (!phba->sli4_hba.STAregaddr)
  4182. return -ENODEV;
  4183. /* Wait up to 30 seconds for the SLI Port POST done and ready */
  4184. for (i = 0; i < 3000; i++) {
  4185. sta_reg.word0 = readl(phba->sli4_hba.STAregaddr);
  4186. /* Encounter fatal POST error, break out */
  4187. if (bf_get(lpfc_hst_state_perr, &sta_reg)) {
  4188. port_error = -ENODEV;
  4189. break;
  4190. }
  4191. if (LPFC_POST_STAGE_ARMFW_READY ==
  4192. bf_get(lpfc_hst_state_port_status, &sta_reg)) {
  4193. port_error = 0;
  4194. break;
  4195. }
  4196. msleep(10);
  4197. }
  4198. if (port_error)
  4199. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4200. "1408 Failure HBA POST Status: sta_reg=0x%x, "
  4201. "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
  4202. "dl=x%x, pstatus=x%x\n", sta_reg.word0,
  4203. bf_get(lpfc_hst_state_perr, &sta_reg),
  4204. bf_get(lpfc_hst_state_sfi, &sta_reg),
  4205. bf_get(lpfc_hst_state_nip, &sta_reg),
  4206. bf_get(lpfc_hst_state_ipc, &sta_reg),
  4207. bf_get(lpfc_hst_state_xrom, &sta_reg),
  4208. bf_get(lpfc_hst_state_dl, &sta_reg),
  4209. bf_get(lpfc_hst_state_port_status, &sta_reg));
  4210. /* Log device information */
  4211. scratchpad.word0 = readl(phba->sli4_hba.SCRATCHPADregaddr);
  4212. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4213. "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
  4214. "FeatureL1=0x%x, FeatureL2=0x%x\n",
  4215. bf_get(lpfc_scratchpad_chiptype, &scratchpad),
  4216. bf_get(lpfc_scratchpad_slirev, &scratchpad),
  4217. bf_get(lpfc_scratchpad_featurelevel1, &scratchpad),
  4218. bf_get(lpfc_scratchpad_featurelevel2, &scratchpad));
  4219. phba->sli4_hba.ue_mask_lo = readl(phba->sli4_hba.UEMASKLOregaddr);
  4220. phba->sli4_hba.ue_mask_hi = readl(phba->sli4_hba.UEMASKHIregaddr);
  4221. /* With uncoverable error, log the error message and return error */
  4222. uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr);
  4223. uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr);
  4224. if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) ||
  4225. (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) {
  4226. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4227. "1422 HBA Unrecoverable error: "
  4228. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  4229. "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
  4230. uerrlo_reg.word0, uerrhi_reg.word0,
  4231. phba->sli4_hba.ue_mask_lo,
  4232. phba->sli4_hba.ue_mask_hi);
  4233. return -ENODEV;
  4234. }
  4235. return port_error;
  4236. }
  4237. /**
  4238. * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
  4239. * @phba: pointer to lpfc hba data structure.
  4240. *
  4241. * This routine is invoked to set up SLI4 BAR0 PCI config space register
  4242. * memory map.
  4243. **/
  4244. static void
  4245. lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba)
  4246. {
  4247. phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4248. LPFC_UERR_STATUS_LO;
  4249. phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4250. LPFC_UERR_STATUS_HI;
  4251. phba->sli4_hba.UEMASKLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4252. LPFC_UE_MASK_LO;
  4253. phba->sli4_hba.UEMASKHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4254. LPFC_UE_MASK_HI;
  4255. phba->sli4_hba.SCRATCHPADregaddr = phba->sli4_hba.conf_regs_memmap_p +
  4256. LPFC_SCRATCHPAD;
  4257. }
  4258. /**
  4259. * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
  4260. * @phba: pointer to lpfc hba data structure.
  4261. *
  4262. * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
  4263. * memory map.
  4264. **/
  4265. static void
  4266. lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
  4267. {
  4268. phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4269. LPFC_HST_STATE;
  4270. phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4271. LPFC_HST_ISR0;
  4272. phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4273. LPFC_HST_IMR0;
  4274. phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
  4275. LPFC_HST_ISCR0;
  4276. return;
  4277. }
  4278. /**
  4279. * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
  4280. * @phba: pointer to lpfc hba data structure.
  4281. * @vf: virtual function number
  4282. *
  4283. * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
  4284. * based on the given viftual function number, @vf.
  4285. *
  4286. * Return 0 if successful, otherwise -ENODEV.
  4287. **/
  4288. static int
  4289. lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
  4290. {
  4291. if (vf > LPFC_VIR_FUNC_MAX)
  4292. return -ENODEV;
  4293. phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4294. vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
  4295. phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4296. vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
  4297. phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4298. vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
  4299. phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4300. vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
  4301. phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
  4302. vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
  4303. return 0;
  4304. }
  4305. /**
  4306. * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
  4307. * @phba: pointer to lpfc hba data structure.
  4308. *
  4309. * This routine is invoked to create the bootstrap mailbox
  4310. * region consistent with the SLI-4 interface spec. This
  4311. * routine allocates all memory necessary to communicate
  4312. * mailbox commands to the port and sets up all alignment
  4313. * needs. No locks are expected to be held when calling
  4314. * this routine.
  4315. *
  4316. * Return codes
  4317. * 0 - successful
  4318. * ENOMEM - could not allocated memory.
  4319. **/
  4320. static int
  4321. lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
  4322. {
  4323. uint32_t bmbx_size;
  4324. struct lpfc_dmabuf *dmabuf;
  4325. struct dma_address *dma_address;
  4326. uint32_t pa_addr;
  4327. uint64_t phys_addr;
  4328. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  4329. if (!dmabuf)
  4330. return -ENOMEM;
  4331. /*
  4332. * The bootstrap mailbox region is comprised of 2 parts
  4333. * plus an alignment restriction of 16 bytes.
  4334. */
  4335. bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
  4336. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  4337. bmbx_size,
  4338. &dmabuf->phys,
  4339. GFP_KERNEL);
  4340. if (!dmabuf->virt) {
  4341. kfree(dmabuf);
  4342. return -ENOMEM;
  4343. }
  4344. memset(dmabuf->virt, 0, bmbx_size);
  4345. /*
  4346. * Initialize the bootstrap mailbox pointers now so that the register
  4347. * operations are simple later. The mailbox dma address is required
  4348. * to be 16-byte aligned. Also align the virtual memory as each
  4349. * maibox is copied into the bmbx mailbox region before issuing the
  4350. * command to the port.
  4351. */
  4352. phba->sli4_hba.bmbx.dmabuf = dmabuf;
  4353. phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
  4354. phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
  4355. LPFC_ALIGN_16_BYTE);
  4356. phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
  4357. LPFC_ALIGN_16_BYTE);
  4358. /*
  4359. * Set the high and low physical addresses now. The SLI4 alignment
  4360. * requirement is 16 bytes and the mailbox is posted to the port
  4361. * as two 30-bit addresses. The other data is a bit marking whether
  4362. * the 30-bit address is the high or low address.
  4363. * Upcast bmbx aphys to 64bits so shift instruction compiles
  4364. * clean on 32 bit machines.
  4365. */
  4366. dma_address = &phba->sli4_hba.bmbx.dma_address;
  4367. phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
  4368. pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
  4369. dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
  4370. LPFC_BMBX_BIT1_ADDR_HI);
  4371. pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
  4372. dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
  4373. LPFC_BMBX_BIT1_ADDR_LO);
  4374. return 0;
  4375. }
  4376. /**
  4377. * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
  4378. * @phba: pointer to lpfc hba data structure.
  4379. *
  4380. * This routine is invoked to teardown the bootstrap mailbox
  4381. * region and release all host resources. This routine requires
  4382. * the caller to ensure all mailbox commands recovered, no
  4383. * additional mailbox comands are sent, and interrupts are disabled
  4384. * before calling this routine.
  4385. *
  4386. **/
  4387. static void
  4388. lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
  4389. {
  4390. dma_free_coherent(&phba->pcidev->dev,
  4391. phba->sli4_hba.bmbx.bmbx_size,
  4392. phba->sli4_hba.bmbx.dmabuf->virt,
  4393. phba->sli4_hba.bmbx.dmabuf->phys);
  4394. kfree(phba->sli4_hba.bmbx.dmabuf);
  4395. memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
  4396. }
  4397. /**
  4398. * lpfc_sli4_read_config - Get the config parameters.
  4399. * @phba: pointer to lpfc hba data structure.
  4400. *
  4401. * This routine is invoked to read the configuration parameters from the HBA.
  4402. * The configuration parameters are used to set the base and maximum values
  4403. * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
  4404. * allocation for the port.
  4405. *
  4406. * Return codes
  4407. * 0 - successful
  4408. * ENOMEM - No availble memory
  4409. * EIO - The mailbox failed to complete successfully.
  4410. **/
  4411. static int
  4412. lpfc_sli4_read_config(struct lpfc_hba *phba)
  4413. {
  4414. LPFC_MBOXQ_t *pmb;
  4415. struct lpfc_mbx_read_config *rd_config;
  4416. uint32_t rc = 0;
  4417. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4418. if (!pmb) {
  4419. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4420. "2011 Unable to allocate memory for issuing "
  4421. "SLI_CONFIG_SPECIAL mailbox command\n");
  4422. return -ENOMEM;
  4423. }
  4424. lpfc_read_config(phba, pmb);
  4425. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  4426. if (rc != MBX_SUCCESS) {
  4427. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4428. "2012 Mailbox failed , mbxCmd x%x "
  4429. "READ_CONFIG, mbxStatus x%x\n",
  4430. bf_get(lpfc_mqe_command, &pmb->u.mqe),
  4431. bf_get(lpfc_mqe_status, &pmb->u.mqe));
  4432. rc = -EIO;
  4433. } else {
  4434. rd_config = &pmb->u.mqe.un.rd_config;
  4435. phba->sli4_hba.max_cfg_param.max_xri =
  4436. bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  4437. phba->sli4_hba.max_cfg_param.xri_base =
  4438. bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
  4439. phba->sli4_hba.max_cfg_param.max_vpi =
  4440. bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
  4441. phba->sli4_hba.max_cfg_param.vpi_base =
  4442. bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
  4443. phba->sli4_hba.max_cfg_param.max_rpi =
  4444. bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  4445. phba->sli4_hba.max_cfg_param.rpi_base =
  4446. bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
  4447. phba->sli4_hba.max_cfg_param.max_vfi =
  4448. bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
  4449. phba->sli4_hba.max_cfg_param.vfi_base =
  4450. bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
  4451. phba->sli4_hba.max_cfg_param.max_fcfi =
  4452. bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
  4453. phba->sli4_hba.max_cfg_param.fcfi_base =
  4454. bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config);
  4455. phba->sli4_hba.max_cfg_param.max_eq =
  4456. bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
  4457. phba->sli4_hba.max_cfg_param.max_rq =
  4458. bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
  4459. phba->sli4_hba.max_cfg_param.max_wq =
  4460. bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
  4461. phba->sli4_hba.max_cfg_param.max_cq =
  4462. bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
  4463. phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
  4464. phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
  4465. phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
  4466. phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
  4467. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
  4468. phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ?
  4469. (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0;
  4470. phba->max_vports = phba->max_vpi;
  4471. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4472. "2003 cfg params XRI(B:%d M:%d), "
  4473. "VPI(B:%d M:%d) "
  4474. "VFI(B:%d M:%d) "
  4475. "RPI(B:%d M:%d) "
  4476. "FCFI(B:%d M:%d)\n",
  4477. phba->sli4_hba.max_cfg_param.xri_base,
  4478. phba->sli4_hba.max_cfg_param.max_xri,
  4479. phba->sli4_hba.max_cfg_param.vpi_base,
  4480. phba->sli4_hba.max_cfg_param.max_vpi,
  4481. phba->sli4_hba.max_cfg_param.vfi_base,
  4482. phba->sli4_hba.max_cfg_param.max_vfi,
  4483. phba->sli4_hba.max_cfg_param.rpi_base,
  4484. phba->sli4_hba.max_cfg_param.max_rpi,
  4485. phba->sli4_hba.max_cfg_param.fcfi_base,
  4486. phba->sli4_hba.max_cfg_param.max_fcfi);
  4487. }
  4488. mempool_free(pmb, phba->mbox_mem_pool);
  4489. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  4490. if (phba->cfg_hba_queue_depth > (phba->sli4_hba.max_cfg_param.max_xri))
  4491. phba->cfg_hba_queue_depth =
  4492. phba->sli4_hba.max_cfg_param.max_xri;
  4493. return rc;
  4494. }
  4495. /**
  4496. * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
  4497. * @phba: pointer to lpfc hba data structure.
  4498. *
  4499. * This routine is invoked to setup the host-side endian order to the
  4500. * HBA consistent with the SLI-4 interface spec.
  4501. *
  4502. * Return codes
  4503. * 0 - successful
  4504. * ENOMEM - No availble memory
  4505. * EIO - The mailbox failed to complete successfully.
  4506. **/
  4507. static int
  4508. lpfc_setup_endian_order(struct lpfc_hba *phba)
  4509. {
  4510. LPFC_MBOXQ_t *mboxq;
  4511. uint32_t rc = 0;
  4512. uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
  4513. HOST_ENDIAN_HIGH_WORD1};
  4514. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4515. if (!mboxq) {
  4516. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4517. "0492 Unable to allocate memory for issuing "
  4518. "SLI_CONFIG_SPECIAL mailbox command\n");
  4519. return -ENOMEM;
  4520. }
  4521. /*
  4522. * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
  4523. * words to contain special data values and no other data.
  4524. */
  4525. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  4526. memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
  4527. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  4528. if (rc != MBX_SUCCESS) {
  4529. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4530. "0493 SLI_CONFIG_SPECIAL mailbox failed with "
  4531. "status x%x\n",
  4532. rc);
  4533. rc = -EIO;
  4534. }
  4535. mempool_free(mboxq, phba->mbox_mem_pool);
  4536. return rc;
  4537. }
  4538. /**
  4539. * lpfc_sli4_queue_create - Create all the SLI4 queues
  4540. * @phba: pointer to lpfc hba data structure.
  4541. *
  4542. * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
  4543. * operation. For each SLI4 queue type, the parameters such as queue entry
  4544. * count (queue depth) shall be taken from the module parameter. For now,
  4545. * we just use some constant number as place holder.
  4546. *
  4547. * Return codes
  4548. * 0 - successful
  4549. * ENOMEM - No availble memory
  4550. * EIO - The mailbox failed to complete successfully.
  4551. **/
  4552. static int
  4553. lpfc_sli4_queue_create(struct lpfc_hba *phba)
  4554. {
  4555. struct lpfc_queue *qdesc;
  4556. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  4557. int cfg_fcp_wq_count;
  4558. int cfg_fcp_eq_count;
  4559. /*
  4560. * Sanity check for confiugred queue parameters against the run-time
  4561. * device parameters
  4562. */
  4563. /* Sanity check on FCP fast-path WQ parameters */
  4564. cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
  4565. if (cfg_fcp_wq_count >
  4566. (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
  4567. cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
  4568. LPFC_SP_WQN_DEF;
  4569. if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
  4570. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4571. "2581 Not enough WQs (%d) from "
  4572. "the pci function for supporting "
  4573. "FCP WQs (%d)\n",
  4574. phba->sli4_hba.max_cfg_param.max_wq,
  4575. phba->cfg_fcp_wq_count);
  4576. goto out_error;
  4577. }
  4578. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4579. "2582 Not enough WQs (%d) from the pci "
  4580. "function for supporting the requested "
  4581. "FCP WQs (%d), the actual FCP WQs can "
  4582. "be supported: %d\n",
  4583. phba->sli4_hba.max_cfg_param.max_wq,
  4584. phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
  4585. }
  4586. /* The actual number of FCP work queues adopted */
  4587. phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
  4588. /* Sanity check on FCP fast-path EQ parameters */
  4589. cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
  4590. if (cfg_fcp_eq_count >
  4591. (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
  4592. cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
  4593. LPFC_SP_EQN_DEF;
  4594. if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
  4595. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4596. "2574 Not enough EQs (%d) from the "
  4597. "pci function for supporting FCP "
  4598. "EQs (%d)\n",
  4599. phba->sli4_hba.max_cfg_param.max_eq,
  4600. phba->cfg_fcp_eq_count);
  4601. goto out_error;
  4602. }
  4603. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4604. "2575 Not enough EQs (%d) from the pci "
  4605. "function for supporting the requested "
  4606. "FCP EQs (%d), the actual FCP EQs can "
  4607. "be supported: %d\n",
  4608. phba->sli4_hba.max_cfg_param.max_eq,
  4609. phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
  4610. }
  4611. /* It does not make sense to have more EQs than WQs */
  4612. if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
  4613. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  4614. "2593 The FCP EQ count(%d) cannot be greater "
  4615. "than the FCP WQ count(%d), limiting the "
  4616. "FCP EQ count to %d\n", cfg_fcp_eq_count,
  4617. phba->cfg_fcp_wq_count,
  4618. phba->cfg_fcp_wq_count);
  4619. cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
  4620. }
  4621. /* The actual number of FCP event queues adopted */
  4622. phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
  4623. /* The overall number of event queues used */
  4624. phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
  4625. /*
  4626. * Create Event Queues (EQs)
  4627. */
  4628. /* Get EQ depth from module parameter, fake the default for now */
  4629. phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
  4630. phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
  4631. /* Create slow path event queue */
  4632. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  4633. phba->sli4_hba.eq_ecount);
  4634. if (!qdesc) {
  4635. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4636. "0496 Failed allocate slow-path EQ\n");
  4637. goto out_error;
  4638. }
  4639. phba->sli4_hba.sp_eq = qdesc;
  4640. /* Create fast-path FCP Event Queue(s) */
  4641. phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
  4642. phba->cfg_fcp_eq_count), GFP_KERNEL);
  4643. if (!phba->sli4_hba.fp_eq) {
  4644. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4645. "2576 Failed allocate memory for fast-path "
  4646. "EQ record array\n");
  4647. goto out_free_sp_eq;
  4648. }
  4649. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  4650. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
  4651. phba->sli4_hba.eq_ecount);
  4652. if (!qdesc) {
  4653. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4654. "0497 Failed allocate fast-path EQ\n");
  4655. goto out_free_fp_eq;
  4656. }
  4657. phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
  4658. }
  4659. /*
  4660. * Create Complete Queues (CQs)
  4661. */
  4662. /* Get CQ depth from module parameter, fake the default for now */
  4663. phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
  4664. phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
  4665. /* Create slow-path Mailbox Command Complete Queue */
  4666. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4667. phba->sli4_hba.cq_ecount);
  4668. if (!qdesc) {
  4669. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4670. "0500 Failed allocate slow-path mailbox CQ\n");
  4671. goto out_free_fp_eq;
  4672. }
  4673. phba->sli4_hba.mbx_cq = qdesc;
  4674. /* Create slow-path ELS Complete Queue */
  4675. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4676. phba->sli4_hba.cq_ecount);
  4677. if (!qdesc) {
  4678. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4679. "0501 Failed allocate slow-path ELS CQ\n");
  4680. goto out_free_mbx_cq;
  4681. }
  4682. phba->sli4_hba.els_cq = qdesc;
  4683. /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
  4684. phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
  4685. phba->cfg_fcp_eq_count), GFP_KERNEL);
  4686. if (!phba->sli4_hba.fcp_cq) {
  4687. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4688. "2577 Failed allocate memory for fast-path "
  4689. "CQ record array\n");
  4690. goto out_free_els_cq;
  4691. }
  4692. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  4693. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
  4694. phba->sli4_hba.cq_ecount);
  4695. if (!qdesc) {
  4696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4697. "0499 Failed allocate fast-path FCP "
  4698. "CQ (%d)\n", fcp_cqidx);
  4699. goto out_free_fcp_cq;
  4700. }
  4701. phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
  4702. }
  4703. /* Create Mailbox Command Queue */
  4704. phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
  4705. phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
  4706. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
  4707. phba->sli4_hba.mq_ecount);
  4708. if (!qdesc) {
  4709. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4710. "0505 Failed allocate slow-path MQ\n");
  4711. goto out_free_fcp_cq;
  4712. }
  4713. phba->sli4_hba.mbx_wq = qdesc;
  4714. /*
  4715. * Create all the Work Queues (WQs)
  4716. */
  4717. phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
  4718. phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
  4719. /* Create slow-path ELS Work Queue */
  4720. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  4721. phba->sli4_hba.wq_ecount);
  4722. if (!qdesc) {
  4723. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4724. "0504 Failed allocate slow-path ELS WQ\n");
  4725. goto out_free_mbx_wq;
  4726. }
  4727. phba->sli4_hba.els_wq = qdesc;
  4728. /* Create fast-path FCP Work Queue(s) */
  4729. phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
  4730. phba->cfg_fcp_wq_count), GFP_KERNEL);
  4731. if (!phba->sli4_hba.fcp_wq) {
  4732. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4733. "2578 Failed allocate memory for fast-path "
  4734. "WQ record array\n");
  4735. goto out_free_els_wq;
  4736. }
  4737. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  4738. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
  4739. phba->sli4_hba.wq_ecount);
  4740. if (!qdesc) {
  4741. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4742. "0503 Failed allocate fast-path FCP "
  4743. "WQ (%d)\n", fcp_wqidx);
  4744. goto out_free_fcp_wq;
  4745. }
  4746. phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
  4747. }
  4748. /*
  4749. * Create Receive Queue (RQ)
  4750. */
  4751. phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
  4752. phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
  4753. /* Create Receive Queue for header */
  4754. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  4755. phba->sli4_hba.rq_ecount);
  4756. if (!qdesc) {
  4757. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4758. "0506 Failed allocate receive HRQ\n");
  4759. goto out_free_fcp_wq;
  4760. }
  4761. phba->sli4_hba.hdr_rq = qdesc;
  4762. /* Create Receive Queue for data */
  4763. qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
  4764. phba->sli4_hba.rq_ecount);
  4765. if (!qdesc) {
  4766. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4767. "0507 Failed allocate receive DRQ\n");
  4768. goto out_free_hdr_rq;
  4769. }
  4770. phba->sli4_hba.dat_rq = qdesc;
  4771. return 0;
  4772. out_free_hdr_rq:
  4773. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  4774. phba->sli4_hba.hdr_rq = NULL;
  4775. out_free_fcp_wq:
  4776. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
  4777. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
  4778. phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
  4779. }
  4780. kfree(phba->sli4_hba.fcp_wq);
  4781. out_free_els_wq:
  4782. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  4783. phba->sli4_hba.els_wq = NULL;
  4784. out_free_mbx_wq:
  4785. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  4786. phba->sli4_hba.mbx_wq = NULL;
  4787. out_free_fcp_cq:
  4788. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
  4789. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
  4790. phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
  4791. }
  4792. kfree(phba->sli4_hba.fcp_cq);
  4793. out_free_els_cq:
  4794. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  4795. phba->sli4_hba.els_cq = NULL;
  4796. out_free_mbx_cq:
  4797. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  4798. phba->sli4_hba.mbx_cq = NULL;
  4799. out_free_fp_eq:
  4800. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
  4801. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
  4802. phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
  4803. }
  4804. kfree(phba->sli4_hba.fp_eq);
  4805. out_free_sp_eq:
  4806. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  4807. phba->sli4_hba.sp_eq = NULL;
  4808. out_error:
  4809. return -ENOMEM;
  4810. }
  4811. /**
  4812. * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
  4813. * @phba: pointer to lpfc hba data structure.
  4814. *
  4815. * This routine is invoked to release all the SLI4 queues with the FCoE HBA
  4816. * operation.
  4817. *
  4818. * Return codes
  4819. * 0 - successful
  4820. * ENOMEM - No availble memory
  4821. * EIO - The mailbox failed to complete successfully.
  4822. **/
  4823. static void
  4824. lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
  4825. {
  4826. int fcp_qidx;
  4827. /* Release mailbox command work queue */
  4828. lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
  4829. phba->sli4_hba.mbx_wq = NULL;
  4830. /* Release ELS work queue */
  4831. lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
  4832. phba->sli4_hba.els_wq = NULL;
  4833. /* Release FCP work queue */
  4834. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  4835. lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
  4836. kfree(phba->sli4_hba.fcp_wq);
  4837. phba->sli4_hba.fcp_wq = NULL;
  4838. /* Release unsolicited receive queue */
  4839. lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
  4840. phba->sli4_hba.hdr_rq = NULL;
  4841. lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
  4842. phba->sli4_hba.dat_rq = NULL;
  4843. /* Release ELS complete queue */
  4844. lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
  4845. phba->sli4_hba.els_cq = NULL;
  4846. /* Release mailbox command complete queue */
  4847. lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
  4848. phba->sli4_hba.mbx_cq = NULL;
  4849. /* Release FCP response complete queue */
  4850. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  4851. lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
  4852. kfree(phba->sli4_hba.fcp_cq);
  4853. phba->sli4_hba.fcp_cq = NULL;
  4854. /* Release fast-path event queue */
  4855. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  4856. lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
  4857. kfree(phba->sli4_hba.fp_eq);
  4858. phba->sli4_hba.fp_eq = NULL;
  4859. /* Release slow-path event queue */
  4860. lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
  4861. phba->sli4_hba.sp_eq = NULL;
  4862. return;
  4863. }
  4864. /**
  4865. * lpfc_sli4_queue_setup - Set up all the SLI4 queues
  4866. * @phba: pointer to lpfc hba data structure.
  4867. *
  4868. * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
  4869. * operation.
  4870. *
  4871. * Return codes
  4872. * 0 - successful
  4873. * ENOMEM - No availble memory
  4874. * EIO - The mailbox failed to complete successfully.
  4875. **/
  4876. int
  4877. lpfc_sli4_queue_setup(struct lpfc_hba *phba)
  4878. {
  4879. int rc = -ENOMEM;
  4880. int fcp_eqidx, fcp_cqidx, fcp_wqidx;
  4881. int fcp_cq_index = 0;
  4882. /*
  4883. * Set up Event Queues (EQs)
  4884. */
  4885. /* Set up slow-path event queue */
  4886. if (!phba->sli4_hba.sp_eq) {
  4887. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4888. "0520 Slow-path EQ not allocated\n");
  4889. goto out_error;
  4890. }
  4891. rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
  4892. LPFC_SP_DEF_IMAX);
  4893. if (rc) {
  4894. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4895. "0521 Failed setup of slow-path EQ: "
  4896. "rc = 0x%x\n", rc);
  4897. goto out_error;
  4898. }
  4899. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4900. "2583 Slow-path EQ setup: queue-id=%d\n",
  4901. phba->sli4_hba.sp_eq->queue_id);
  4902. /* Set up fast-path event queue */
  4903. for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
  4904. if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
  4905. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4906. "0522 Fast-path EQ (%d) not "
  4907. "allocated\n", fcp_eqidx);
  4908. goto out_destroy_fp_eq;
  4909. }
  4910. rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
  4911. phba->cfg_fcp_imax);
  4912. if (rc) {
  4913. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4914. "0523 Failed setup of fast-path EQ "
  4915. "(%d), rc = 0x%x\n", fcp_eqidx, rc);
  4916. goto out_destroy_fp_eq;
  4917. }
  4918. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4919. "2584 Fast-path EQ setup: "
  4920. "queue[%d]-id=%d\n", fcp_eqidx,
  4921. phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
  4922. }
  4923. /*
  4924. * Set up Complete Queues (CQs)
  4925. */
  4926. /* Set up slow-path MBOX Complete Queue as the first CQ */
  4927. if (!phba->sli4_hba.mbx_cq) {
  4928. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4929. "0528 Mailbox CQ not allocated\n");
  4930. goto out_destroy_fp_eq;
  4931. }
  4932. rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
  4933. LPFC_MCQ, LPFC_MBOX);
  4934. if (rc) {
  4935. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4936. "0529 Failed setup of slow-path mailbox CQ: "
  4937. "rc = 0x%x\n", rc);
  4938. goto out_destroy_fp_eq;
  4939. }
  4940. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4941. "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
  4942. phba->sli4_hba.mbx_cq->queue_id,
  4943. phba->sli4_hba.sp_eq->queue_id);
  4944. /* Set up slow-path ELS Complete Queue */
  4945. if (!phba->sli4_hba.els_cq) {
  4946. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4947. "0530 ELS CQ not allocated\n");
  4948. goto out_destroy_mbx_cq;
  4949. }
  4950. rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
  4951. LPFC_WCQ, LPFC_ELS);
  4952. if (rc) {
  4953. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4954. "0531 Failed setup of slow-path ELS CQ: "
  4955. "rc = 0x%x\n", rc);
  4956. goto out_destroy_mbx_cq;
  4957. }
  4958. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4959. "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
  4960. phba->sli4_hba.els_cq->queue_id,
  4961. phba->sli4_hba.sp_eq->queue_id);
  4962. /* Set up fast-path FCP Response Complete Queue */
  4963. for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
  4964. if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
  4965. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4966. "0526 Fast-path FCP CQ (%d) not "
  4967. "allocated\n", fcp_cqidx);
  4968. goto out_destroy_fcp_cq;
  4969. }
  4970. rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
  4971. phba->sli4_hba.fp_eq[fcp_cqidx],
  4972. LPFC_WCQ, LPFC_FCP);
  4973. if (rc) {
  4974. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4975. "0527 Failed setup of fast-path FCP "
  4976. "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
  4977. goto out_destroy_fcp_cq;
  4978. }
  4979. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4980. "2588 FCP CQ setup: cq[%d]-id=%d, "
  4981. "parent eq[%d]-id=%d\n",
  4982. fcp_cqidx,
  4983. phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
  4984. fcp_cqidx,
  4985. phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id);
  4986. }
  4987. /*
  4988. * Set up all the Work Queues (WQs)
  4989. */
  4990. /* Set up Mailbox Command Queue */
  4991. if (!phba->sli4_hba.mbx_wq) {
  4992. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4993. "0538 Slow-path MQ not allocated\n");
  4994. goto out_destroy_fcp_cq;
  4995. }
  4996. rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
  4997. phba->sli4_hba.mbx_cq, LPFC_MBOX);
  4998. if (rc) {
  4999. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5000. "0539 Failed setup of slow-path MQ: "
  5001. "rc = 0x%x\n", rc);
  5002. goto out_destroy_fcp_cq;
  5003. }
  5004. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5005. "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
  5006. phba->sli4_hba.mbx_wq->queue_id,
  5007. phba->sli4_hba.mbx_cq->queue_id);
  5008. /* Set up slow-path ELS Work Queue */
  5009. if (!phba->sli4_hba.els_wq) {
  5010. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5011. "0536 Slow-path ELS WQ not allocated\n");
  5012. goto out_destroy_mbx_wq;
  5013. }
  5014. rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
  5015. phba->sli4_hba.els_cq, LPFC_ELS);
  5016. if (rc) {
  5017. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5018. "0537 Failed setup of slow-path ELS WQ: "
  5019. "rc = 0x%x\n", rc);
  5020. goto out_destroy_mbx_wq;
  5021. }
  5022. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5023. "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
  5024. phba->sli4_hba.els_wq->queue_id,
  5025. phba->sli4_hba.els_cq->queue_id);
  5026. /* Set up fast-path FCP Work Queue */
  5027. for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
  5028. if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
  5029. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5030. "0534 Fast-path FCP WQ (%d) not "
  5031. "allocated\n", fcp_wqidx);
  5032. goto out_destroy_fcp_wq;
  5033. }
  5034. rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
  5035. phba->sli4_hba.fcp_cq[fcp_cq_index],
  5036. LPFC_FCP);
  5037. if (rc) {
  5038. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5039. "0535 Failed setup of fast-path FCP "
  5040. "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
  5041. goto out_destroy_fcp_wq;
  5042. }
  5043. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5044. "2591 FCP WQ setup: wq[%d]-id=%d, "
  5045. "parent cq[%d]-id=%d\n",
  5046. fcp_wqidx,
  5047. phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
  5048. fcp_cq_index,
  5049. phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
  5050. /* Round robin FCP Work Queue's Completion Queue assignment */
  5051. fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count);
  5052. }
  5053. /*
  5054. * Create Receive Queue (RQ)
  5055. */
  5056. if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
  5057. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5058. "0540 Receive Queue not allocated\n");
  5059. goto out_destroy_fcp_wq;
  5060. }
  5061. rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
  5062. phba->sli4_hba.els_cq, LPFC_USOL);
  5063. if (rc) {
  5064. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5065. "0541 Failed setup of Receive Queue: "
  5066. "rc = 0x%x\n", rc);
  5067. goto out_destroy_fcp_wq;
  5068. }
  5069. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5070. "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
  5071. "parent cq-id=%d\n",
  5072. phba->sli4_hba.hdr_rq->queue_id,
  5073. phba->sli4_hba.dat_rq->queue_id,
  5074. phba->sli4_hba.els_cq->queue_id);
  5075. return 0;
  5076. out_destroy_fcp_wq:
  5077. for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
  5078. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
  5079. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  5080. out_destroy_mbx_wq:
  5081. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  5082. out_destroy_fcp_cq:
  5083. for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
  5084. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
  5085. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5086. out_destroy_mbx_cq:
  5087. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5088. out_destroy_fp_eq:
  5089. for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
  5090. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
  5091. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5092. out_error:
  5093. return rc;
  5094. }
  5095. /**
  5096. * lpfc_sli4_queue_unset - Unset all the SLI4 queues
  5097. * @phba: pointer to lpfc hba data structure.
  5098. *
  5099. * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
  5100. * operation.
  5101. *
  5102. * Return codes
  5103. * 0 - successful
  5104. * ENOMEM - No availble memory
  5105. * EIO - The mailbox failed to complete successfully.
  5106. **/
  5107. void
  5108. lpfc_sli4_queue_unset(struct lpfc_hba *phba)
  5109. {
  5110. int fcp_qidx;
  5111. /* Unset mailbox command work queue */
  5112. lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
  5113. /* Unset ELS work queue */
  5114. lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
  5115. /* Unset unsolicited receive queue */
  5116. lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
  5117. /* Unset FCP work queue */
  5118. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
  5119. lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
  5120. /* Unset mailbox command complete queue */
  5121. lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
  5122. /* Unset ELS complete queue */
  5123. lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
  5124. /* Unset FCP response complete queue */
  5125. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5126. lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
  5127. /* Unset fast-path event queue */
  5128. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
  5129. lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
  5130. /* Unset slow-path event queue */
  5131. lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
  5132. }
  5133. /**
  5134. * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
  5135. * @phba: pointer to lpfc hba data structure.
  5136. *
  5137. * This routine is invoked to allocate and set up a pool of completion queue
  5138. * events. The body of the completion queue event is a completion queue entry
  5139. * CQE. For now, this pool is used for the interrupt service routine to queue
  5140. * the following HBA completion queue events for the worker thread to process:
  5141. * - Mailbox asynchronous events
  5142. * - Receive queue completion unsolicited events
  5143. * Later, this can be used for all the slow-path events.
  5144. *
  5145. * Return codes
  5146. * 0 - successful
  5147. * -ENOMEM - No availble memory
  5148. **/
  5149. static int
  5150. lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
  5151. {
  5152. struct lpfc_cq_event *cq_event;
  5153. int i;
  5154. for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
  5155. cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
  5156. if (!cq_event)
  5157. goto out_pool_create_fail;
  5158. list_add_tail(&cq_event->list,
  5159. &phba->sli4_hba.sp_cqe_event_pool);
  5160. }
  5161. return 0;
  5162. out_pool_create_fail:
  5163. lpfc_sli4_cq_event_pool_destroy(phba);
  5164. return -ENOMEM;
  5165. }
  5166. /**
  5167. * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
  5168. * @phba: pointer to lpfc hba data structure.
  5169. *
  5170. * This routine is invoked to free the pool of completion queue events at
  5171. * driver unload time. Note that, it is the responsibility of the driver
  5172. * cleanup routine to free all the outstanding completion-queue events
  5173. * allocated from this pool back into the pool before invoking this routine
  5174. * to destroy the pool.
  5175. **/
  5176. static void
  5177. lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
  5178. {
  5179. struct lpfc_cq_event *cq_event, *next_cq_event;
  5180. list_for_each_entry_safe(cq_event, next_cq_event,
  5181. &phba->sli4_hba.sp_cqe_event_pool, list) {
  5182. list_del(&cq_event->list);
  5183. kfree(cq_event);
  5184. }
  5185. }
  5186. /**
  5187. * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5188. * @phba: pointer to lpfc hba data structure.
  5189. *
  5190. * This routine is the lock free version of the API invoked to allocate a
  5191. * completion-queue event from the free pool.
  5192. *
  5193. * Return: Pointer to the newly allocated completion-queue event if successful
  5194. * NULL otherwise.
  5195. **/
  5196. struct lpfc_cq_event *
  5197. __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5198. {
  5199. struct lpfc_cq_event *cq_event = NULL;
  5200. list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
  5201. struct lpfc_cq_event, list);
  5202. return cq_event;
  5203. }
  5204. /**
  5205. * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
  5206. * @phba: pointer to lpfc hba data structure.
  5207. *
  5208. * This routine is the lock version of the API invoked to allocate a
  5209. * completion-queue event from the free pool.
  5210. *
  5211. * Return: Pointer to the newly allocated completion-queue event if successful
  5212. * NULL otherwise.
  5213. **/
  5214. struct lpfc_cq_event *
  5215. lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
  5216. {
  5217. struct lpfc_cq_event *cq_event;
  5218. unsigned long iflags;
  5219. spin_lock_irqsave(&phba->hbalock, iflags);
  5220. cq_event = __lpfc_sli4_cq_event_alloc(phba);
  5221. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5222. return cq_event;
  5223. }
  5224. /**
  5225. * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  5226. * @phba: pointer to lpfc hba data structure.
  5227. * @cq_event: pointer to the completion queue event to be freed.
  5228. *
  5229. * This routine is the lock free version of the API invoked to release a
  5230. * completion-queue event back into the free pool.
  5231. **/
  5232. void
  5233. __lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  5234. struct lpfc_cq_event *cq_event)
  5235. {
  5236. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
  5237. }
  5238. /**
  5239. * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
  5240. * @phba: pointer to lpfc hba data structure.
  5241. * @cq_event: pointer to the completion queue event to be freed.
  5242. *
  5243. * This routine is the lock version of the API invoked to release a
  5244. * completion-queue event back into the free pool.
  5245. **/
  5246. void
  5247. lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
  5248. struct lpfc_cq_event *cq_event)
  5249. {
  5250. unsigned long iflags;
  5251. spin_lock_irqsave(&phba->hbalock, iflags);
  5252. __lpfc_sli4_cq_event_release(phba, cq_event);
  5253. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5254. }
  5255. /**
  5256. * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
  5257. * @phba: pointer to lpfc hba data structure.
  5258. *
  5259. * This routine is to free all the pending completion-queue events to the
  5260. * back into the free pool for device reset.
  5261. **/
  5262. static void
  5263. lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
  5264. {
  5265. LIST_HEAD(cqelist);
  5266. struct lpfc_cq_event *cqe;
  5267. unsigned long iflags;
  5268. /* Retrieve all the pending WCQEs from pending WCQE lists */
  5269. spin_lock_irqsave(&phba->hbalock, iflags);
  5270. /* Pending FCP XRI abort events */
  5271. list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
  5272. &cqelist);
  5273. /* Pending ELS XRI abort events */
  5274. list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  5275. &cqelist);
  5276. /* Pending asynnc events */
  5277. list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
  5278. &cqelist);
  5279. spin_unlock_irqrestore(&phba->hbalock, iflags);
  5280. while (!list_empty(&cqelist)) {
  5281. list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
  5282. lpfc_sli4_cq_event_release(phba, cqe);
  5283. }
  5284. }
  5285. /**
  5286. * lpfc_pci_function_reset - Reset pci function.
  5287. * @phba: pointer to lpfc hba data structure.
  5288. *
  5289. * This routine is invoked to request a PCI function reset. It will destroys
  5290. * all resources assigned to the PCI function which originates this request.
  5291. *
  5292. * Return codes
  5293. * 0 - successful
  5294. * ENOMEM - No availble memory
  5295. * EIO - The mailbox failed to complete successfully.
  5296. **/
  5297. int
  5298. lpfc_pci_function_reset(struct lpfc_hba *phba)
  5299. {
  5300. LPFC_MBOXQ_t *mboxq;
  5301. uint32_t rc = 0;
  5302. uint32_t shdr_status, shdr_add_status;
  5303. union lpfc_sli4_cfg_shdr *shdr;
  5304. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5305. if (!mboxq) {
  5306. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5307. "0494 Unable to allocate memory for issuing "
  5308. "SLI_FUNCTION_RESET mailbox command\n");
  5309. return -ENOMEM;
  5310. }
  5311. /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
  5312. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5313. LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
  5314. LPFC_SLI4_MBX_EMBED);
  5315. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5316. shdr = (union lpfc_sli4_cfg_shdr *)
  5317. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  5318. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5319. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5320. if (rc != MBX_TIMEOUT)
  5321. mempool_free(mboxq, phba->mbox_mem_pool);
  5322. if (shdr_status || shdr_add_status || rc) {
  5323. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5324. "0495 SLI_FUNCTION_RESET mailbox failed with "
  5325. "status x%x add_status x%x, mbx status x%x\n",
  5326. shdr_status, shdr_add_status, rc);
  5327. rc = -ENXIO;
  5328. }
  5329. return rc;
  5330. }
  5331. /**
  5332. * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
  5333. * @phba: pointer to lpfc hba data structure.
  5334. * @cnt: number of nop mailbox commands to send.
  5335. *
  5336. * This routine is invoked to send a number @cnt of NOP mailbox command and
  5337. * wait for each command to complete.
  5338. *
  5339. * Return: the number of NOP mailbox command completed.
  5340. **/
  5341. static int
  5342. lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
  5343. {
  5344. LPFC_MBOXQ_t *mboxq;
  5345. int length, cmdsent;
  5346. uint32_t mbox_tmo;
  5347. uint32_t rc = 0;
  5348. uint32_t shdr_status, shdr_add_status;
  5349. union lpfc_sli4_cfg_shdr *shdr;
  5350. if (cnt == 0) {
  5351. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5352. "2518 Requested to send 0 NOP mailbox cmd\n");
  5353. return cnt;
  5354. }
  5355. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5356. if (!mboxq) {
  5357. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5358. "2519 Unable to allocate memory for issuing "
  5359. "NOP mailbox command\n");
  5360. return 0;
  5361. }
  5362. /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
  5363. length = (sizeof(struct lpfc_mbx_nop) -
  5364. sizeof(struct lpfc_sli4_cfg_mhdr));
  5365. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5366. LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
  5367. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  5368. for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
  5369. if (!phba->sli4_hba.intr_enable)
  5370. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5371. else
  5372. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  5373. if (rc == MBX_TIMEOUT)
  5374. break;
  5375. /* Check return status */
  5376. shdr = (union lpfc_sli4_cfg_shdr *)
  5377. &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
  5378. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5379. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  5380. &shdr->response);
  5381. if (shdr_status || shdr_add_status || rc) {
  5382. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5383. "2520 NOP mailbox command failed "
  5384. "status x%x add_status x%x mbx "
  5385. "status x%x\n", shdr_status,
  5386. shdr_add_status, rc);
  5387. break;
  5388. }
  5389. }
  5390. if (rc != MBX_TIMEOUT)
  5391. mempool_free(mboxq, phba->mbox_mem_pool);
  5392. return cmdsent;
  5393. }
  5394. /**
  5395. * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
  5396. * @phba: pointer to lpfc hba data structure.
  5397. * @fcfi: fcf index.
  5398. *
  5399. * This routine is invoked to unregister a FCFI from device.
  5400. **/
  5401. void
  5402. lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi)
  5403. {
  5404. LPFC_MBOXQ_t *mbox;
  5405. uint32_t mbox_tmo;
  5406. int rc;
  5407. unsigned long flags;
  5408. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5409. if (!mbox)
  5410. return;
  5411. lpfc_unreg_fcfi(mbox, fcfi);
  5412. if (!phba->sli4_hba.intr_enable)
  5413. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5414. else {
  5415. mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
  5416. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5417. }
  5418. if (rc != MBX_TIMEOUT)
  5419. mempool_free(mbox, phba->mbox_mem_pool);
  5420. if (rc != MBX_SUCCESS)
  5421. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5422. "2517 Unregister FCFI command failed "
  5423. "status %d, mbxStatus x%x\n", rc,
  5424. bf_get(lpfc_mqe_status, &mbox->u.mqe));
  5425. else {
  5426. spin_lock_irqsave(&phba->hbalock, flags);
  5427. /* Mark the FCFI is no longer registered */
  5428. phba->fcf.fcf_flag &=
  5429. ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_DISCOVERED);
  5430. spin_unlock_irqrestore(&phba->hbalock, flags);
  5431. }
  5432. }
  5433. /**
  5434. * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
  5435. * @phba: pointer to lpfc hba data structure.
  5436. *
  5437. * This routine is invoked to set up the PCI device memory space for device
  5438. * with SLI-4 interface spec.
  5439. *
  5440. * Return codes
  5441. * 0 - successful
  5442. * other values - error
  5443. **/
  5444. static int
  5445. lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
  5446. {
  5447. struct pci_dev *pdev;
  5448. unsigned long bar0map_len, bar1map_len, bar2map_len;
  5449. int error = -ENODEV;
  5450. /* Obtain PCI device reference */
  5451. if (!phba->pcidev)
  5452. return error;
  5453. else
  5454. pdev = phba->pcidev;
  5455. /* Set the device DMA mask size */
  5456. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0
  5457. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) {
  5458. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0
  5459. || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) {
  5460. return error;
  5461. }
  5462. }
  5463. /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
  5464. * number of bytes required by each mapping. They are actually
  5465. * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device.
  5466. */
  5467. phba->pci_bar0_map = pci_resource_start(pdev, LPFC_SLI4_BAR0);
  5468. bar0map_len = pci_resource_len(pdev, LPFC_SLI4_BAR0);
  5469. phba->pci_bar1_map = pci_resource_start(pdev, LPFC_SLI4_BAR1);
  5470. bar1map_len = pci_resource_len(pdev, LPFC_SLI4_BAR1);
  5471. phba->pci_bar2_map = pci_resource_start(pdev, LPFC_SLI4_BAR2);
  5472. bar2map_len = pci_resource_len(pdev, LPFC_SLI4_BAR2);
  5473. /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
  5474. phba->sli4_hba.conf_regs_memmap_p =
  5475. ioremap(phba->pci_bar0_map, bar0map_len);
  5476. if (!phba->sli4_hba.conf_regs_memmap_p) {
  5477. dev_printk(KERN_ERR, &pdev->dev,
  5478. "ioremap failed for SLI4 PCI config registers.\n");
  5479. goto out;
  5480. }
  5481. /* Map SLI4 HBA Control Register base to a kernel virtual address. */
  5482. phba->sli4_hba.ctrl_regs_memmap_p =
  5483. ioremap(phba->pci_bar1_map, bar1map_len);
  5484. if (!phba->sli4_hba.ctrl_regs_memmap_p) {
  5485. dev_printk(KERN_ERR, &pdev->dev,
  5486. "ioremap failed for SLI4 HBA control registers.\n");
  5487. goto out_iounmap_conf;
  5488. }
  5489. /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
  5490. phba->sli4_hba.drbl_regs_memmap_p =
  5491. ioremap(phba->pci_bar2_map, bar2map_len);
  5492. if (!phba->sli4_hba.drbl_regs_memmap_p) {
  5493. dev_printk(KERN_ERR, &pdev->dev,
  5494. "ioremap failed for SLI4 HBA doorbell registers.\n");
  5495. goto out_iounmap_ctrl;
  5496. }
  5497. /* Set up BAR0 PCI config space register memory map */
  5498. lpfc_sli4_bar0_register_memmap(phba);
  5499. /* Set up BAR1 register memory map */
  5500. lpfc_sli4_bar1_register_memmap(phba);
  5501. /* Set up BAR2 register memory map */
  5502. error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
  5503. if (error)
  5504. goto out_iounmap_all;
  5505. return 0;
  5506. out_iounmap_all:
  5507. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  5508. out_iounmap_ctrl:
  5509. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  5510. out_iounmap_conf:
  5511. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  5512. out:
  5513. return error;
  5514. }
  5515. /**
  5516. * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
  5517. * @phba: pointer to lpfc hba data structure.
  5518. *
  5519. * This routine is invoked to unset the PCI device memory space for device
  5520. * with SLI-4 interface spec.
  5521. **/
  5522. static void
  5523. lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
  5524. {
  5525. struct pci_dev *pdev;
  5526. /* Obtain PCI device reference */
  5527. if (!phba->pcidev)
  5528. return;
  5529. else
  5530. pdev = phba->pcidev;
  5531. /* Free coherent DMA memory allocated */
  5532. /* Unmap I/O memory space */
  5533. iounmap(phba->sli4_hba.drbl_regs_memmap_p);
  5534. iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
  5535. iounmap(phba->sli4_hba.conf_regs_memmap_p);
  5536. return;
  5537. }
  5538. /**
  5539. * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
  5540. * @phba: pointer to lpfc hba data structure.
  5541. *
  5542. * This routine is invoked to enable the MSI-X interrupt vectors to device
  5543. * with SLI-3 interface specs. The kernel function pci_enable_msix() is
  5544. * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
  5545. * invoked, enables either all or nothing, depending on the current
  5546. * availability of PCI vector resources. The device driver is responsible
  5547. * for calling the individual request_irq() to register each MSI-X vector
  5548. * with a interrupt handler, which is done in this function. Note that
  5549. * later when device is unloading, the driver should always call free_irq()
  5550. * on all MSI-X vectors it has done request_irq() on before calling
  5551. * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
  5552. * will be left with MSI-X enabled and leaks its vectors.
  5553. *
  5554. * Return codes
  5555. * 0 - successful
  5556. * other values - error
  5557. **/
  5558. static int
  5559. lpfc_sli_enable_msix(struct lpfc_hba *phba)
  5560. {
  5561. int rc, i;
  5562. LPFC_MBOXQ_t *pmb;
  5563. /* Set up MSI-X multi-message vectors */
  5564. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5565. phba->msix_entries[i].entry = i;
  5566. /* Configure MSI-X capability structure */
  5567. rc = pci_enable_msix(phba->pcidev, phba->msix_entries,
  5568. ARRAY_SIZE(phba->msix_entries));
  5569. if (rc) {
  5570. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5571. "0420 PCI enable MSI-X failed (%d)\n", rc);
  5572. goto msi_fail_out;
  5573. }
  5574. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5575. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5576. "0477 MSI-X entry[%d]: vector=x%x "
  5577. "message=%d\n", i,
  5578. phba->msix_entries[i].vector,
  5579. phba->msix_entries[i].entry);
  5580. /*
  5581. * Assign MSI-X vectors to interrupt handlers
  5582. */
  5583. /* vector-0 is associated to slow-path handler */
  5584. rc = request_irq(phba->msix_entries[0].vector,
  5585. &lpfc_sli_sp_intr_handler, IRQF_SHARED,
  5586. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  5587. if (rc) {
  5588. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5589. "0421 MSI-X slow-path request_irq failed "
  5590. "(%d)\n", rc);
  5591. goto msi_fail_out;
  5592. }
  5593. /* vector-1 is associated to fast-path handler */
  5594. rc = request_irq(phba->msix_entries[1].vector,
  5595. &lpfc_sli_fp_intr_handler, IRQF_SHARED,
  5596. LPFC_FP_DRIVER_HANDLER_NAME, phba);
  5597. if (rc) {
  5598. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5599. "0429 MSI-X fast-path request_irq failed "
  5600. "(%d)\n", rc);
  5601. goto irq_fail_out;
  5602. }
  5603. /*
  5604. * Configure HBA MSI-X attention conditions to messages
  5605. */
  5606. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5607. if (!pmb) {
  5608. rc = -ENOMEM;
  5609. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5610. "0474 Unable to allocate memory for issuing "
  5611. "MBOX_CONFIG_MSI command\n");
  5612. goto mem_fail_out;
  5613. }
  5614. rc = lpfc_config_msi(phba, pmb);
  5615. if (rc)
  5616. goto mbx_fail_out;
  5617. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5618. if (rc != MBX_SUCCESS) {
  5619. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  5620. "0351 Config MSI mailbox command failed, "
  5621. "mbxCmd x%x, mbxStatus x%x\n",
  5622. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus);
  5623. goto mbx_fail_out;
  5624. }
  5625. /* Free memory allocated for mailbox command */
  5626. mempool_free(pmb, phba->mbox_mem_pool);
  5627. return rc;
  5628. mbx_fail_out:
  5629. /* Free memory allocated for mailbox command */
  5630. mempool_free(pmb, phba->mbox_mem_pool);
  5631. mem_fail_out:
  5632. /* free the irq already requested */
  5633. free_irq(phba->msix_entries[1].vector, phba);
  5634. irq_fail_out:
  5635. /* free the irq already requested */
  5636. free_irq(phba->msix_entries[0].vector, phba);
  5637. msi_fail_out:
  5638. /* Unconfigure MSI-X capability structure */
  5639. pci_disable_msix(phba->pcidev);
  5640. return rc;
  5641. }
  5642. /**
  5643. * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
  5644. * @phba: pointer to lpfc hba data structure.
  5645. *
  5646. * This routine is invoked to release the MSI-X vectors and then disable the
  5647. * MSI-X interrupt mode to device with SLI-3 interface spec.
  5648. **/
  5649. static void
  5650. lpfc_sli_disable_msix(struct lpfc_hba *phba)
  5651. {
  5652. int i;
  5653. /* Free up MSI-X multi-message vectors */
  5654. for (i = 0; i < LPFC_MSIX_VECTORS; i++)
  5655. free_irq(phba->msix_entries[i].vector, phba);
  5656. /* Disable MSI-X */
  5657. pci_disable_msix(phba->pcidev);
  5658. return;
  5659. }
  5660. /**
  5661. * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
  5662. * @phba: pointer to lpfc hba data structure.
  5663. *
  5664. * This routine is invoked to enable the MSI interrupt mode to device with
  5665. * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
  5666. * enable the MSI vector. The device driver is responsible for calling the
  5667. * request_irq() to register MSI vector with a interrupt the handler, which
  5668. * is done in this function.
  5669. *
  5670. * Return codes
  5671. * 0 - successful
  5672. * other values - error
  5673. */
  5674. static int
  5675. lpfc_sli_enable_msi(struct lpfc_hba *phba)
  5676. {
  5677. int rc;
  5678. rc = pci_enable_msi(phba->pcidev);
  5679. if (!rc)
  5680. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5681. "0462 PCI enable MSI mode success.\n");
  5682. else {
  5683. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5684. "0471 PCI enable MSI mode failed (%d)\n", rc);
  5685. return rc;
  5686. }
  5687. rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  5688. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5689. if (rc) {
  5690. pci_disable_msi(phba->pcidev);
  5691. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5692. "0478 MSI request_irq failed (%d)\n", rc);
  5693. }
  5694. return rc;
  5695. }
  5696. /**
  5697. * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
  5698. * @phba: pointer to lpfc hba data structure.
  5699. *
  5700. * This routine is invoked to disable the MSI interrupt mode to device with
  5701. * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
  5702. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  5703. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  5704. * its vector.
  5705. */
  5706. static void
  5707. lpfc_sli_disable_msi(struct lpfc_hba *phba)
  5708. {
  5709. free_irq(phba->pcidev->irq, phba);
  5710. pci_disable_msi(phba->pcidev);
  5711. return;
  5712. }
  5713. /**
  5714. * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
  5715. * @phba: pointer to lpfc hba data structure.
  5716. *
  5717. * This routine is invoked to enable device interrupt and associate driver's
  5718. * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
  5719. * spec. Depends on the interrupt mode configured to the driver, the driver
  5720. * will try to fallback from the configured interrupt mode to an interrupt
  5721. * mode which is supported by the platform, kernel, and device in the order
  5722. * of:
  5723. * MSI-X -> MSI -> IRQ.
  5724. *
  5725. * Return codes
  5726. * 0 - successful
  5727. * other values - error
  5728. **/
  5729. static uint32_t
  5730. lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  5731. {
  5732. uint32_t intr_mode = LPFC_INTR_ERROR;
  5733. int retval;
  5734. if (cfg_mode == 2) {
  5735. /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
  5736. retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  5737. if (!retval) {
  5738. /* Now, try to enable MSI-X interrupt mode */
  5739. retval = lpfc_sli_enable_msix(phba);
  5740. if (!retval) {
  5741. /* Indicate initialization to MSI-X mode */
  5742. phba->intr_type = MSIX;
  5743. intr_mode = 2;
  5744. }
  5745. }
  5746. }
  5747. /* Fallback to MSI if MSI-X initialization failed */
  5748. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  5749. retval = lpfc_sli_enable_msi(phba);
  5750. if (!retval) {
  5751. /* Indicate initialization to MSI mode */
  5752. phba->intr_type = MSI;
  5753. intr_mode = 1;
  5754. }
  5755. }
  5756. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  5757. if (phba->intr_type == NONE) {
  5758. retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler,
  5759. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5760. if (!retval) {
  5761. /* Indicate initialization to INTx mode */
  5762. phba->intr_type = INTx;
  5763. intr_mode = 0;
  5764. }
  5765. }
  5766. return intr_mode;
  5767. }
  5768. /**
  5769. * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
  5770. * @phba: pointer to lpfc hba data structure.
  5771. *
  5772. * This routine is invoked to disable device interrupt and disassociate the
  5773. * driver's interrupt handler(s) from interrupt vector(s) to device with
  5774. * SLI-3 interface spec. Depending on the interrupt mode, the driver will
  5775. * release the interrupt vector(s) for the message signaled interrupt.
  5776. **/
  5777. static void
  5778. lpfc_sli_disable_intr(struct lpfc_hba *phba)
  5779. {
  5780. /* Disable the currently initialized interrupt mode */
  5781. if (phba->intr_type == MSIX)
  5782. lpfc_sli_disable_msix(phba);
  5783. else if (phba->intr_type == MSI)
  5784. lpfc_sli_disable_msi(phba);
  5785. else if (phba->intr_type == INTx)
  5786. free_irq(phba->pcidev->irq, phba);
  5787. /* Reset interrupt management states */
  5788. phba->intr_type = NONE;
  5789. phba->sli.slistat.sli_intr = 0;
  5790. return;
  5791. }
  5792. /**
  5793. * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
  5794. * @phba: pointer to lpfc hba data structure.
  5795. *
  5796. * This routine is invoked to enable the MSI-X interrupt vectors to device
  5797. * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
  5798. * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
  5799. * enables either all or nothing, depending on the current availability of
  5800. * PCI vector resources. The device driver is responsible for calling the
  5801. * individual request_irq() to register each MSI-X vector with a interrupt
  5802. * handler, which is done in this function. Note that later when device is
  5803. * unloading, the driver should always call free_irq() on all MSI-X vectors
  5804. * it has done request_irq() on before calling pci_disable_msix(). Failure
  5805. * to do so results in a BUG_ON() and a device will be left with MSI-X
  5806. * enabled and leaks its vectors.
  5807. *
  5808. * Return codes
  5809. * 0 - successful
  5810. * other values - error
  5811. **/
  5812. static int
  5813. lpfc_sli4_enable_msix(struct lpfc_hba *phba)
  5814. {
  5815. int rc, index;
  5816. /* Set up MSI-X multi-message vectors */
  5817. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  5818. phba->sli4_hba.msix_entries[index].entry = index;
  5819. /* Configure MSI-X capability structure */
  5820. rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
  5821. phba->sli4_hba.cfg_eqn);
  5822. if (rc) {
  5823. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5824. "0484 PCI enable MSI-X failed (%d)\n", rc);
  5825. goto msi_fail_out;
  5826. }
  5827. /* Log MSI-X vector assignment */
  5828. for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
  5829. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5830. "0489 MSI-X entry[%d]: vector=x%x "
  5831. "message=%d\n", index,
  5832. phba->sli4_hba.msix_entries[index].vector,
  5833. phba->sli4_hba.msix_entries[index].entry);
  5834. /*
  5835. * Assign MSI-X vectors to interrupt handlers
  5836. */
  5837. /* The first vector must associated to slow-path handler for MQ */
  5838. rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
  5839. &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
  5840. LPFC_SP_DRIVER_HANDLER_NAME, phba);
  5841. if (rc) {
  5842. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5843. "0485 MSI-X slow-path request_irq failed "
  5844. "(%d)\n", rc);
  5845. goto msi_fail_out;
  5846. }
  5847. /* The rest of the vector(s) are associated to fast-path handler(s) */
  5848. for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) {
  5849. phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
  5850. phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
  5851. rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
  5852. &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
  5853. LPFC_FP_DRIVER_HANDLER_NAME,
  5854. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5855. if (rc) {
  5856. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5857. "0486 MSI-X fast-path (%d) "
  5858. "request_irq failed (%d)\n", index, rc);
  5859. goto cfg_fail_out;
  5860. }
  5861. }
  5862. return rc;
  5863. cfg_fail_out:
  5864. /* free the irq already requested */
  5865. for (--index; index >= 1; index--)
  5866. free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
  5867. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5868. /* free the irq already requested */
  5869. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  5870. msi_fail_out:
  5871. /* Unconfigure MSI-X capability structure */
  5872. pci_disable_msix(phba->pcidev);
  5873. return rc;
  5874. }
  5875. /**
  5876. * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
  5877. * @phba: pointer to lpfc hba data structure.
  5878. *
  5879. * This routine is invoked to release the MSI-X vectors and then disable the
  5880. * MSI-X interrupt mode to device with SLI-4 interface spec.
  5881. **/
  5882. static void
  5883. lpfc_sli4_disable_msix(struct lpfc_hba *phba)
  5884. {
  5885. int index;
  5886. /* Free up MSI-X multi-message vectors */
  5887. free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
  5888. for (index = 1; index < phba->sli4_hba.cfg_eqn; index++)
  5889. free_irq(phba->sli4_hba.msix_entries[index].vector,
  5890. &phba->sli4_hba.fcp_eq_hdl[index - 1]);
  5891. /* Disable MSI-X */
  5892. pci_disable_msix(phba->pcidev);
  5893. return;
  5894. }
  5895. /**
  5896. * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
  5897. * @phba: pointer to lpfc hba data structure.
  5898. *
  5899. * This routine is invoked to enable the MSI interrupt mode to device with
  5900. * SLI-4 interface spec. The kernel function pci_enable_msi() is called
  5901. * to enable the MSI vector. The device driver is responsible for calling
  5902. * the request_irq() to register MSI vector with a interrupt the handler,
  5903. * which is done in this function.
  5904. *
  5905. * Return codes
  5906. * 0 - successful
  5907. * other values - error
  5908. **/
  5909. static int
  5910. lpfc_sli4_enable_msi(struct lpfc_hba *phba)
  5911. {
  5912. int rc, index;
  5913. rc = pci_enable_msi(phba->pcidev);
  5914. if (!rc)
  5915. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5916. "0487 PCI enable MSI mode success.\n");
  5917. else {
  5918. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5919. "0488 PCI enable MSI mode failed (%d)\n", rc);
  5920. return rc;
  5921. }
  5922. rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  5923. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5924. if (rc) {
  5925. pci_disable_msi(phba->pcidev);
  5926. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5927. "0490 MSI request_irq failed (%d)\n", rc);
  5928. }
  5929. for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
  5930. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  5931. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  5932. }
  5933. return rc;
  5934. }
  5935. /**
  5936. * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
  5937. * @phba: pointer to lpfc hba data structure.
  5938. *
  5939. * This routine is invoked to disable the MSI interrupt mode to device with
  5940. * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
  5941. * done request_irq() on before calling pci_disable_msi(). Failure to do so
  5942. * results in a BUG_ON() and a device will be left with MSI enabled and leaks
  5943. * its vector.
  5944. **/
  5945. static void
  5946. lpfc_sli4_disable_msi(struct lpfc_hba *phba)
  5947. {
  5948. free_irq(phba->pcidev->irq, phba);
  5949. pci_disable_msi(phba->pcidev);
  5950. return;
  5951. }
  5952. /**
  5953. * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
  5954. * @phba: pointer to lpfc hba data structure.
  5955. *
  5956. * This routine is invoked to enable device interrupt and associate driver's
  5957. * interrupt handler(s) to interrupt vector(s) to device with SLI-4
  5958. * interface spec. Depends on the interrupt mode configured to the driver,
  5959. * the driver will try to fallback from the configured interrupt mode to an
  5960. * interrupt mode which is supported by the platform, kernel, and device in
  5961. * the order of:
  5962. * MSI-X -> MSI -> IRQ.
  5963. *
  5964. * Return codes
  5965. * 0 - successful
  5966. * other values - error
  5967. **/
  5968. static uint32_t
  5969. lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
  5970. {
  5971. uint32_t intr_mode = LPFC_INTR_ERROR;
  5972. int retval, index;
  5973. if (cfg_mode == 2) {
  5974. /* Preparation before conf_msi mbox cmd */
  5975. retval = 0;
  5976. if (!retval) {
  5977. /* Now, try to enable MSI-X interrupt mode */
  5978. retval = lpfc_sli4_enable_msix(phba);
  5979. if (!retval) {
  5980. /* Indicate initialization to MSI-X mode */
  5981. phba->intr_type = MSIX;
  5982. intr_mode = 2;
  5983. }
  5984. }
  5985. }
  5986. /* Fallback to MSI if MSI-X initialization failed */
  5987. if (cfg_mode >= 1 && phba->intr_type == NONE) {
  5988. retval = lpfc_sli4_enable_msi(phba);
  5989. if (!retval) {
  5990. /* Indicate initialization to MSI mode */
  5991. phba->intr_type = MSI;
  5992. intr_mode = 1;
  5993. }
  5994. }
  5995. /* Fallback to INTx if both MSI-X/MSI initalization failed */
  5996. if (phba->intr_type == NONE) {
  5997. retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
  5998. IRQF_SHARED, LPFC_DRIVER_NAME, phba);
  5999. if (!retval) {
  6000. /* Indicate initialization to INTx mode */
  6001. phba->intr_type = INTx;
  6002. intr_mode = 0;
  6003. for (index = 0; index < phba->cfg_fcp_eq_count;
  6004. index++) {
  6005. phba->sli4_hba.fcp_eq_hdl[index].idx = index;
  6006. phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
  6007. }
  6008. }
  6009. }
  6010. return intr_mode;
  6011. }
  6012. /**
  6013. * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
  6014. * @phba: pointer to lpfc hba data structure.
  6015. *
  6016. * This routine is invoked to disable device interrupt and disassociate
  6017. * the driver's interrupt handler(s) from interrupt vector(s) to device
  6018. * with SLI-4 interface spec. Depending on the interrupt mode, the driver
  6019. * will release the interrupt vector(s) for the message signaled interrupt.
  6020. **/
  6021. static void
  6022. lpfc_sli4_disable_intr(struct lpfc_hba *phba)
  6023. {
  6024. /* Disable the currently initialized interrupt mode */
  6025. if (phba->intr_type == MSIX)
  6026. lpfc_sli4_disable_msix(phba);
  6027. else if (phba->intr_type == MSI)
  6028. lpfc_sli4_disable_msi(phba);
  6029. else if (phba->intr_type == INTx)
  6030. free_irq(phba->pcidev->irq, phba);
  6031. /* Reset interrupt management states */
  6032. phba->intr_type = NONE;
  6033. phba->sli.slistat.sli_intr = 0;
  6034. return;
  6035. }
  6036. /**
  6037. * lpfc_unset_hba - Unset SLI3 hba device initialization
  6038. * @phba: pointer to lpfc hba data structure.
  6039. *
  6040. * This routine is invoked to unset the HBA device initialization steps to
  6041. * a device with SLI-3 interface spec.
  6042. **/
  6043. static void
  6044. lpfc_unset_hba(struct lpfc_hba *phba)
  6045. {
  6046. struct lpfc_vport *vport = phba->pport;
  6047. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6048. spin_lock_irq(shost->host_lock);
  6049. vport->load_flag |= FC_UNLOADING;
  6050. spin_unlock_irq(shost->host_lock);
  6051. lpfc_stop_hba_timers(phba);
  6052. phba->pport->work_port_events = 0;
  6053. lpfc_sli_hba_down(phba);
  6054. lpfc_sli_brdrestart(phba);
  6055. lpfc_sli_disable_intr(phba);
  6056. return;
  6057. }
  6058. /**
  6059. * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
  6060. * @phba: pointer to lpfc hba data structure.
  6061. *
  6062. * This routine is invoked to unset the HBA device initialization steps to
  6063. * a device with SLI-4 interface spec.
  6064. **/
  6065. static void
  6066. lpfc_sli4_unset_hba(struct lpfc_hba *phba)
  6067. {
  6068. struct lpfc_vport *vport = phba->pport;
  6069. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6070. spin_lock_irq(shost->host_lock);
  6071. vport->load_flag |= FC_UNLOADING;
  6072. spin_unlock_irq(shost->host_lock);
  6073. phba->pport->work_port_events = 0;
  6074. lpfc_sli4_hba_down(phba);
  6075. lpfc_sli4_disable_intr(phba);
  6076. return;
  6077. }
  6078. /**
  6079. * lpfc_sli4_hba_unset - Unset the fcoe hba
  6080. * @phba: Pointer to HBA context object.
  6081. *
  6082. * This function is called in the SLI4 code path to reset the HBA's FCoE
  6083. * function. The caller is not required to hold any lock. This routine
  6084. * issues PCI function reset mailbox command to reset the FCoE function.
  6085. * At the end of the function, it calls lpfc_hba_down_post function to
  6086. * free any pending commands.
  6087. **/
  6088. static void
  6089. lpfc_sli4_hba_unset(struct lpfc_hba *phba)
  6090. {
  6091. int wait_cnt = 0;
  6092. LPFC_MBOXQ_t *mboxq;
  6093. lpfc_stop_hba_timers(phba);
  6094. phba->sli4_hba.intr_enable = 0;
  6095. /*
  6096. * Gracefully wait out the potential current outstanding asynchronous
  6097. * mailbox command.
  6098. */
  6099. /* First, block any pending async mailbox command from posted */
  6100. spin_lock_irq(&phba->hbalock);
  6101. phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  6102. spin_unlock_irq(&phba->hbalock);
  6103. /* Now, trying to wait it out if we can */
  6104. while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6105. msleep(10);
  6106. if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
  6107. break;
  6108. }
  6109. /* Forcefully release the outstanding mailbox command if timed out */
  6110. if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  6111. spin_lock_irq(&phba->hbalock);
  6112. mboxq = phba->sli.mbox_active;
  6113. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  6114. __lpfc_mbox_cmpl_put(phba, mboxq);
  6115. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  6116. phba->sli.mbox_active = NULL;
  6117. spin_unlock_irq(&phba->hbalock);
  6118. }
  6119. /* Tear down the queues in the HBA */
  6120. lpfc_sli4_queue_unset(phba);
  6121. /* Disable PCI subsystem interrupt */
  6122. lpfc_sli4_disable_intr(phba);
  6123. /* Stop kthread signal shall trigger work_done one more time */
  6124. kthread_stop(phba->worker_thread);
  6125. /* Stop the SLI4 device port */
  6126. phba->pport->work_port_events = 0;
  6127. }
  6128. /**
  6129. * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
  6130. * @pdev: pointer to PCI device
  6131. * @pid: pointer to PCI device identifier
  6132. *
  6133. * This routine is to be called to attach a device with SLI-3 interface spec
  6134. * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  6135. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  6136. * information of the device and driver to see if the driver state that it can
  6137. * support this kind of device. If the match is successful, the driver core
  6138. * invokes this routine. If this routine determines it can claim the HBA, it
  6139. * does all the initialization that it needs to do to handle the HBA properly.
  6140. *
  6141. * Return code
  6142. * 0 - driver can claim the device
  6143. * negative value - driver can not claim the device
  6144. **/
  6145. static int __devinit
  6146. lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid)
  6147. {
  6148. struct lpfc_hba *phba;
  6149. struct lpfc_vport *vport = NULL;
  6150. struct Scsi_Host *shost = NULL;
  6151. int error;
  6152. uint32_t cfg_mode, intr_mode;
  6153. /* Allocate memory for HBA structure */
  6154. phba = lpfc_hba_alloc(pdev);
  6155. if (!phba)
  6156. return -ENOMEM;
  6157. /* Perform generic PCI device enabling operation */
  6158. error = lpfc_enable_pci_dev(phba);
  6159. if (error) {
  6160. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6161. "1401 Failed to enable pci device.\n");
  6162. goto out_free_phba;
  6163. }
  6164. /* Set up SLI API function jump table for PCI-device group-0 HBAs */
  6165. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP);
  6166. if (error)
  6167. goto out_disable_pci_dev;
  6168. /* Set up SLI-3 specific device PCI memory space */
  6169. error = lpfc_sli_pci_mem_setup(phba);
  6170. if (error) {
  6171. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6172. "1402 Failed to set up pci memory space.\n");
  6173. goto out_disable_pci_dev;
  6174. }
  6175. /* Set up phase-1 common device driver resources */
  6176. error = lpfc_setup_driver_resource_phase1(phba);
  6177. if (error) {
  6178. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6179. "1403 Failed to set up driver resource.\n");
  6180. goto out_unset_pci_mem_s3;
  6181. }
  6182. /* Set up SLI-3 specific device driver resources */
  6183. error = lpfc_sli_driver_resource_setup(phba);
  6184. if (error) {
  6185. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6186. "1404 Failed to set up driver resource.\n");
  6187. goto out_unset_pci_mem_s3;
  6188. }
  6189. /* Initialize and populate the iocb list per host */
  6190. error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT);
  6191. if (error) {
  6192. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6193. "1405 Failed to initialize iocb list.\n");
  6194. goto out_unset_driver_resource_s3;
  6195. }
  6196. /* Set up common device driver resources */
  6197. error = lpfc_setup_driver_resource_phase2(phba);
  6198. if (error) {
  6199. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6200. "1406 Failed to set up driver resource.\n");
  6201. goto out_free_iocb_list;
  6202. }
  6203. /* Create SCSI host to the physical port */
  6204. error = lpfc_create_shost(phba);
  6205. if (error) {
  6206. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6207. "1407 Failed to create scsi host.\n");
  6208. goto out_unset_driver_resource;
  6209. }
  6210. /* Configure sysfs attributes */
  6211. vport = phba->pport;
  6212. error = lpfc_alloc_sysfs_attr(vport);
  6213. if (error) {
  6214. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6215. "1476 Failed to allocate sysfs attr\n");
  6216. goto out_destroy_shost;
  6217. }
  6218. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  6219. /* Now, trying to enable interrupt and bring up the device */
  6220. cfg_mode = phba->cfg_use_msi;
  6221. while (true) {
  6222. /* Put device to a known state before enabling interrupt */
  6223. lpfc_stop_port(phba);
  6224. /* Configure and enable interrupt */
  6225. intr_mode = lpfc_sli_enable_intr(phba, cfg_mode);
  6226. if (intr_mode == LPFC_INTR_ERROR) {
  6227. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6228. "0431 Failed to enable interrupt.\n");
  6229. error = -ENODEV;
  6230. goto out_free_sysfs_attr;
  6231. }
  6232. /* SLI-3 HBA setup */
  6233. if (lpfc_sli_hba_setup(phba)) {
  6234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6235. "1477 Failed to set up hba\n");
  6236. error = -ENODEV;
  6237. goto out_remove_device;
  6238. }
  6239. /* Wait 50ms for the interrupts of previous mailbox commands */
  6240. msleep(50);
  6241. /* Check active interrupts on message signaled interrupts */
  6242. if (intr_mode == 0 ||
  6243. phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) {
  6244. /* Log the current active interrupt mode */
  6245. phba->intr_mode = intr_mode;
  6246. lpfc_log_intr_mode(phba, intr_mode);
  6247. break;
  6248. } else {
  6249. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6250. "0447 Configure interrupt mode (%d) "
  6251. "failed active interrupt test.\n",
  6252. intr_mode);
  6253. /* Disable the current interrupt mode */
  6254. lpfc_sli_disable_intr(phba);
  6255. /* Try next level of interrupt mode */
  6256. cfg_mode = --intr_mode;
  6257. }
  6258. }
  6259. /* Perform post initialization setup */
  6260. lpfc_post_init_setup(phba);
  6261. /* Check if there are static vports to be created. */
  6262. lpfc_create_static_vport(phba);
  6263. return 0;
  6264. out_remove_device:
  6265. lpfc_unset_hba(phba);
  6266. out_free_sysfs_attr:
  6267. lpfc_free_sysfs_attr(vport);
  6268. out_destroy_shost:
  6269. lpfc_destroy_shost(phba);
  6270. out_unset_driver_resource:
  6271. lpfc_unset_driver_resource_phase2(phba);
  6272. out_free_iocb_list:
  6273. lpfc_free_iocb_list(phba);
  6274. out_unset_driver_resource_s3:
  6275. lpfc_sli_driver_resource_unset(phba);
  6276. out_unset_pci_mem_s3:
  6277. lpfc_sli_pci_mem_unset(phba);
  6278. out_disable_pci_dev:
  6279. lpfc_disable_pci_dev(phba);
  6280. if (shost)
  6281. scsi_host_put(shost);
  6282. out_free_phba:
  6283. lpfc_hba_free(phba);
  6284. return error;
  6285. }
  6286. /**
  6287. * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
  6288. * @pdev: pointer to PCI device
  6289. *
  6290. * This routine is to be called to disattach a device with SLI-3 interface
  6291. * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
  6292. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  6293. * device to be removed from the PCI subsystem properly.
  6294. **/
  6295. static void __devexit
  6296. lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  6297. {
  6298. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6299. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6300. struct lpfc_vport **vports;
  6301. struct lpfc_hba *phba = vport->phba;
  6302. int i;
  6303. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  6304. spin_lock_irq(&phba->hbalock);
  6305. vport->load_flag |= FC_UNLOADING;
  6306. spin_unlock_irq(&phba->hbalock);
  6307. lpfc_free_sysfs_attr(vport);
  6308. /* Release all the vports against this physical port */
  6309. vports = lpfc_create_vport_work_array(phba);
  6310. if (vports != NULL)
  6311. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  6312. fc_vport_terminate(vports[i]->fc_vport);
  6313. lpfc_destroy_vport_work_array(phba, vports);
  6314. /* Remove FC host and then SCSI host with the physical port */
  6315. fc_remove_host(shost);
  6316. scsi_remove_host(shost);
  6317. lpfc_cleanup(vport);
  6318. /*
  6319. * Bring down the SLI Layer. This step disable all interrupts,
  6320. * clears the rings, discards all mailbox commands, and resets
  6321. * the HBA.
  6322. */
  6323. /* HBA interrupt will be diabled after this call */
  6324. lpfc_sli_hba_down(phba);
  6325. /* Stop kthread signal shall trigger work_done one more time */
  6326. kthread_stop(phba->worker_thread);
  6327. /* Final cleanup of txcmplq and reset the HBA */
  6328. lpfc_sli_brdrestart(phba);
  6329. lpfc_stop_hba_timers(phba);
  6330. spin_lock_irq(&phba->hbalock);
  6331. list_del_init(&vport->listentry);
  6332. spin_unlock_irq(&phba->hbalock);
  6333. lpfc_debugfs_terminate(vport);
  6334. /* Disable interrupt */
  6335. lpfc_sli_disable_intr(phba);
  6336. pci_set_drvdata(pdev, NULL);
  6337. scsi_host_put(shost);
  6338. /*
  6339. * Call scsi_free before mem_free since scsi bufs are released to their
  6340. * corresponding pools here.
  6341. */
  6342. lpfc_scsi_free(phba);
  6343. lpfc_mem_free_all(phba);
  6344. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(),
  6345. phba->hbqslimp.virt, phba->hbqslimp.phys);
  6346. /* Free resources associated with SLI2 interface */
  6347. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  6348. phba->slim2p.virt, phba->slim2p.phys);
  6349. /* unmap adapter SLIM and Control Registers */
  6350. iounmap(phba->ctrl_regs_memmap_p);
  6351. iounmap(phba->slim_memmap_p);
  6352. lpfc_hba_free(phba);
  6353. pci_release_selected_regions(pdev, bars);
  6354. pci_disable_device(pdev);
  6355. }
  6356. /**
  6357. * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
  6358. * @pdev: pointer to PCI device
  6359. * @msg: power management message
  6360. *
  6361. * This routine is to be called from the kernel's PCI subsystem to support
  6362. * system Power Management (PM) to device with SLI-3 interface spec. When
  6363. * PM invokes this method, it quiesces the device by stopping the driver's
  6364. * worker thread for the device, turning off device's interrupt and DMA,
  6365. * and bring the device offline. Note that as the driver implements the
  6366. * minimum PM requirements to a power-aware driver's PM support for the
  6367. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  6368. * to the suspend() method call will be treated as SUSPEND and the driver will
  6369. * fully reinitialize its device during resume() method call, the driver will
  6370. * set device to PCI_D3hot state in PCI config space instead of setting it
  6371. * according to the @msg provided by the PM.
  6372. *
  6373. * Return code
  6374. * 0 - driver suspended the device
  6375. * Error otherwise
  6376. **/
  6377. static int
  6378. lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
  6379. {
  6380. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6381. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6382. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6383. "0473 PCI device Power Management suspend.\n");
  6384. /* Bring down the device */
  6385. lpfc_offline_prep(phba);
  6386. lpfc_offline(phba);
  6387. kthread_stop(phba->worker_thread);
  6388. /* Disable interrupt from device */
  6389. lpfc_sli_disable_intr(phba);
  6390. /* Save device state to PCI config space */
  6391. pci_save_state(pdev);
  6392. pci_set_power_state(pdev, PCI_D3hot);
  6393. return 0;
  6394. }
  6395. /**
  6396. * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
  6397. * @pdev: pointer to PCI device
  6398. *
  6399. * This routine is to be called from the kernel's PCI subsystem to support
  6400. * system Power Management (PM) to device with SLI-3 interface spec. When PM
  6401. * invokes this method, it restores the device's PCI config space state and
  6402. * fully reinitializes the device and brings it online. Note that as the
  6403. * driver implements the minimum PM requirements to a power-aware driver's
  6404. * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
  6405. * FREEZE) to the suspend() method call will be treated as SUSPEND and the
  6406. * driver will fully reinitialize its device during resume() method call,
  6407. * the device will be set to PCI_D0 directly in PCI config space before
  6408. * restoring the state.
  6409. *
  6410. * Return code
  6411. * 0 - driver suspended the device
  6412. * Error otherwise
  6413. **/
  6414. static int
  6415. lpfc_pci_resume_one_s3(struct pci_dev *pdev)
  6416. {
  6417. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6418. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6419. uint32_t intr_mode;
  6420. int error;
  6421. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6422. "0452 PCI device Power Management resume.\n");
  6423. /* Restore device state from PCI config space */
  6424. pci_set_power_state(pdev, PCI_D0);
  6425. pci_restore_state(pdev);
  6426. if (pdev->is_busmaster)
  6427. pci_set_master(pdev);
  6428. /* Startup the kernel thread for this host adapter. */
  6429. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  6430. "lpfc_worker_%d", phba->brd_no);
  6431. if (IS_ERR(phba->worker_thread)) {
  6432. error = PTR_ERR(phba->worker_thread);
  6433. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6434. "0434 PM resume failed to start worker "
  6435. "thread: error=x%x.\n", error);
  6436. return error;
  6437. }
  6438. /* Configure and enable interrupt */
  6439. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  6440. if (intr_mode == LPFC_INTR_ERROR) {
  6441. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6442. "0430 PM resume Failed to enable interrupt\n");
  6443. return -EIO;
  6444. } else
  6445. phba->intr_mode = intr_mode;
  6446. /* Restart HBA and bring it online */
  6447. lpfc_sli_brdrestart(phba);
  6448. lpfc_online(phba);
  6449. /* Log the current active interrupt mode */
  6450. lpfc_log_intr_mode(phba, phba->intr_mode);
  6451. return 0;
  6452. }
  6453. /**
  6454. * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
  6455. * @phba: pointer to lpfc hba data structure.
  6456. *
  6457. * This routine is called to prepare the SLI3 device for PCI slot recover. It
  6458. * aborts and stops all the on-going I/Os on the pci device.
  6459. **/
  6460. static void
  6461. lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba)
  6462. {
  6463. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6464. "2723 PCI channel I/O abort preparing for recovery\n");
  6465. /* Prepare for bringing HBA offline */
  6466. lpfc_offline_prep(phba);
  6467. /* Clear sli active flag to prevent sysfs access to HBA */
  6468. spin_lock_irq(&phba->hbalock);
  6469. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  6470. spin_unlock_irq(&phba->hbalock);
  6471. /* Stop and flush all I/Os and bring HBA offline */
  6472. lpfc_offline(phba);
  6473. }
  6474. /**
  6475. * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
  6476. * @phba: pointer to lpfc hba data structure.
  6477. *
  6478. * This routine is called to prepare the SLI3 device for PCI slot reset. It
  6479. * disables the device interrupt and pci device, and aborts the internal FCP
  6480. * pending I/Os.
  6481. **/
  6482. static void
  6483. lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
  6484. {
  6485. struct lpfc_sli *psli = &phba->sli;
  6486. struct lpfc_sli_ring *pring;
  6487. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6488. "2710 PCI channel disable preparing for reset\n");
  6489. /* Disable interrupt and pci device */
  6490. lpfc_sli_disable_intr(phba);
  6491. pci_disable_device(phba->pcidev);
  6492. /*
  6493. * There may be I/Os dropped by the firmware.
  6494. * Error iocb (I/O) on txcmplq and let the SCSI layer
  6495. * retry it after re-establishing link.
  6496. */
  6497. pring = &psli->ring[psli->fcp_ring];
  6498. lpfc_sli_abort_iocb_ring(phba, pring);
  6499. }
  6500. /**
  6501. * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
  6502. * @phba: pointer to lpfc hba data structure.
  6503. *
  6504. * This routine is called to prepare the SLI3 device for PCI slot permanently
  6505. * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
  6506. * pending I/Os.
  6507. **/
  6508. static void
  6509. lpfc_prep_dev_for_perm_failure(struct lpfc_hba *phba)
  6510. {
  6511. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6512. "2711 PCI channel permanent disable for failure\n");
  6513. /* Clean up all driver's outstanding SCSI I/Os */
  6514. lpfc_sli_flush_fcp_rings(phba);
  6515. }
  6516. /**
  6517. * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
  6518. * @pdev: pointer to PCI device.
  6519. * @state: the current PCI connection state.
  6520. *
  6521. * This routine is called from the PCI subsystem for I/O error handling to
  6522. * device with SLI-3 interface spec. This function is called by the PCI
  6523. * subsystem after a PCI bus error affecting this device has been detected.
  6524. * When this function is invoked, it will need to stop all the I/Os and
  6525. * interrupt(s) to the device. Once that is done, it will return
  6526. * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
  6527. * as desired.
  6528. *
  6529. * Return codes
  6530. * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
  6531. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  6532. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6533. **/
  6534. static pci_ers_result_t
  6535. lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state)
  6536. {
  6537. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6538. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6539. /* Block all SCSI devices' I/Os on the host */
  6540. lpfc_scsi_dev_block(phba);
  6541. switch (state) {
  6542. case pci_channel_io_normal:
  6543. /* Non-fatal error, prepare for recovery */
  6544. lpfc_sli_prep_dev_for_recover(phba);
  6545. return PCI_ERS_RESULT_CAN_RECOVER;
  6546. case pci_channel_io_frozen:
  6547. /* Fatal error, prepare for slot reset */
  6548. lpfc_sli_prep_dev_for_reset(phba);
  6549. return PCI_ERS_RESULT_NEED_RESET;
  6550. case pci_channel_io_perm_failure:
  6551. /* Permanent failure, prepare for device down */
  6552. lpfc_prep_dev_for_perm_failure(phba);
  6553. return PCI_ERS_RESULT_DISCONNECT;
  6554. default:
  6555. /* Unknown state, prepare and request slot reset */
  6556. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6557. "0472 Unknown PCI error state: x%x\n", state);
  6558. lpfc_sli_prep_dev_for_reset(phba);
  6559. return PCI_ERS_RESULT_NEED_RESET;
  6560. }
  6561. }
  6562. /**
  6563. * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
  6564. * @pdev: pointer to PCI device.
  6565. *
  6566. * This routine is called from the PCI subsystem for error handling to
  6567. * device with SLI-3 interface spec. This is called after PCI bus has been
  6568. * reset to restart the PCI card from scratch, as if from a cold-boot.
  6569. * During the PCI subsystem error recovery, after driver returns
  6570. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  6571. * recovery and then call this routine before calling the .resume method
  6572. * to recover the device. This function will initialize the HBA device,
  6573. * enable the interrupt, but it will just put the HBA to offline state
  6574. * without passing any I/O traffic.
  6575. *
  6576. * Return codes
  6577. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  6578. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6579. */
  6580. static pci_ers_result_t
  6581. lpfc_io_slot_reset_s3(struct pci_dev *pdev)
  6582. {
  6583. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6584. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6585. struct lpfc_sli *psli = &phba->sli;
  6586. uint32_t intr_mode;
  6587. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  6588. if (pci_enable_device_mem(pdev)) {
  6589. printk(KERN_ERR "lpfc: Cannot re-enable "
  6590. "PCI device after reset.\n");
  6591. return PCI_ERS_RESULT_DISCONNECT;
  6592. }
  6593. pci_restore_state(pdev);
  6594. if (pdev->is_busmaster)
  6595. pci_set_master(pdev);
  6596. spin_lock_irq(&phba->hbalock);
  6597. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  6598. spin_unlock_irq(&phba->hbalock);
  6599. /* Configure and enable interrupt */
  6600. intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode);
  6601. if (intr_mode == LPFC_INTR_ERROR) {
  6602. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6603. "0427 Cannot re-enable interrupt after "
  6604. "slot reset.\n");
  6605. return PCI_ERS_RESULT_DISCONNECT;
  6606. } else
  6607. phba->intr_mode = intr_mode;
  6608. /* Take device offline; this will perform cleanup */
  6609. lpfc_offline(phba);
  6610. lpfc_sli_brdrestart(phba);
  6611. /* Log the current active interrupt mode */
  6612. lpfc_log_intr_mode(phba, phba->intr_mode);
  6613. return PCI_ERS_RESULT_RECOVERED;
  6614. }
  6615. /**
  6616. * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
  6617. * @pdev: pointer to PCI device
  6618. *
  6619. * This routine is called from the PCI subsystem for error handling to device
  6620. * with SLI-3 interface spec. It is called when kernel error recovery tells
  6621. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  6622. * error recovery. After this call, traffic can start to flow from this device
  6623. * again.
  6624. */
  6625. static void
  6626. lpfc_io_resume_s3(struct pci_dev *pdev)
  6627. {
  6628. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6629. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6630. /* Bring the device online */
  6631. lpfc_online(phba);
  6632. /* Clean up Advanced Error Reporting (AER) if needed */
  6633. if (phba->hba_flag & HBA_AER_ENABLED)
  6634. pci_cleanup_aer_uncorrect_error_status(pdev);
  6635. }
  6636. /**
  6637. * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
  6638. * @phba: pointer to lpfc hba data structure.
  6639. *
  6640. * returns the number of ELS/CT IOCBs to reserve
  6641. **/
  6642. int
  6643. lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
  6644. {
  6645. int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
  6646. if (phba->sli_rev == LPFC_SLI_REV4) {
  6647. if (max_xri <= 100)
  6648. return 10;
  6649. else if (max_xri <= 256)
  6650. return 25;
  6651. else if (max_xri <= 512)
  6652. return 50;
  6653. else if (max_xri <= 1024)
  6654. return 100;
  6655. else
  6656. return 150;
  6657. } else
  6658. return 0;
  6659. }
  6660. /**
  6661. * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
  6662. * @pdev: pointer to PCI device
  6663. * @pid: pointer to PCI device identifier
  6664. *
  6665. * This routine is called from the kernel's PCI subsystem to device with
  6666. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  6667. * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
  6668. * information of the device and driver to see if the driver state that it
  6669. * can support this kind of device. If the match is successful, the driver
  6670. * core invokes this routine. If this routine determines it can claim the HBA,
  6671. * it does all the initialization that it needs to do to handle the HBA
  6672. * properly.
  6673. *
  6674. * Return code
  6675. * 0 - driver can claim the device
  6676. * negative value - driver can not claim the device
  6677. **/
  6678. static int __devinit
  6679. lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
  6680. {
  6681. struct lpfc_hba *phba;
  6682. struct lpfc_vport *vport = NULL;
  6683. struct Scsi_Host *shost = NULL;
  6684. int error;
  6685. uint32_t cfg_mode, intr_mode;
  6686. int mcnt;
  6687. /* Allocate memory for HBA structure */
  6688. phba = lpfc_hba_alloc(pdev);
  6689. if (!phba)
  6690. return -ENOMEM;
  6691. /* Perform generic PCI device enabling operation */
  6692. error = lpfc_enable_pci_dev(phba);
  6693. if (error) {
  6694. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6695. "1409 Failed to enable pci device.\n");
  6696. goto out_free_phba;
  6697. }
  6698. /* Set up SLI API function jump table for PCI-device group-1 HBAs */
  6699. error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
  6700. if (error)
  6701. goto out_disable_pci_dev;
  6702. /* Set up SLI-4 specific device PCI memory space */
  6703. error = lpfc_sli4_pci_mem_setup(phba);
  6704. if (error) {
  6705. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6706. "1410 Failed to set up pci memory space.\n");
  6707. goto out_disable_pci_dev;
  6708. }
  6709. /* Set up phase-1 common device driver resources */
  6710. error = lpfc_setup_driver_resource_phase1(phba);
  6711. if (error) {
  6712. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6713. "1411 Failed to set up driver resource.\n");
  6714. goto out_unset_pci_mem_s4;
  6715. }
  6716. /* Set up SLI-4 Specific device driver resources */
  6717. error = lpfc_sli4_driver_resource_setup(phba);
  6718. if (error) {
  6719. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6720. "1412 Failed to set up driver resource.\n");
  6721. goto out_unset_pci_mem_s4;
  6722. }
  6723. /* Initialize and populate the iocb list per host */
  6724. error = lpfc_init_iocb_list(phba,
  6725. phba->sli4_hba.max_cfg_param.max_xri);
  6726. if (error) {
  6727. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6728. "1413 Failed to initialize iocb list.\n");
  6729. goto out_unset_driver_resource_s4;
  6730. }
  6731. /* Set up common device driver resources */
  6732. error = lpfc_setup_driver_resource_phase2(phba);
  6733. if (error) {
  6734. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6735. "1414 Failed to set up driver resource.\n");
  6736. goto out_free_iocb_list;
  6737. }
  6738. /* Create SCSI host to the physical port */
  6739. error = lpfc_create_shost(phba);
  6740. if (error) {
  6741. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6742. "1415 Failed to create scsi host.\n");
  6743. goto out_unset_driver_resource;
  6744. }
  6745. /* Configure sysfs attributes */
  6746. vport = phba->pport;
  6747. error = lpfc_alloc_sysfs_attr(vport);
  6748. if (error) {
  6749. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6750. "1416 Failed to allocate sysfs attr\n");
  6751. goto out_destroy_shost;
  6752. }
  6753. shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */
  6754. /* Now, trying to enable interrupt and bring up the device */
  6755. cfg_mode = phba->cfg_use_msi;
  6756. while (true) {
  6757. /* Put device to a known state before enabling interrupt */
  6758. lpfc_stop_port(phba);
  6759. /* Configure and enable interrupt */
  6760. intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
  6761. if (intr_mode == LPFC_INTR_ERROR) {
  6762. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6763. "0426 Failed to enable interrupt.\n");
  6764. error = -ENODEV;
  6765. goto out_free_sysfs_attr;
  6766. }
  6767. /* Default to single FCP EQ for non-MSI-X */
  6768. if (phba->intr_type != MSIX)
  6769. phba->cfg_fcp_eq_count = 1;
  6770. /* Set up SLI-4 HBA */
  6771. if (lpfc_sli4_hba_setup(phba)) {
  6772. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6773. "1421 Failed to set up hba\n");
  6774. error = -ENODEV;
  6775. goto out_disable_intr;
  6776. }
  6777. /* Send NOP mbx cmds for non-INTx mode active interrupt test */
  6778. if (intr_mode != 0)
  6779. mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
  6780. LPFC_ACT_INTR_CNT);
  6781. /* Check active interrupts received only for MSI/MSI-X */
  6782. if (intr_mode == 0 ||
  6783. phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
  6784. /* Log the current active interrupt mode */
  6785. phba->intr_mode = intr_mode;
  6786. lpfc_log_intr_mode(phba, intr_mode);
  6787. break;
  6788. }
  6789. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6790. "0451 Configure interrupt mode (%d) "
  6791. "failed active interrupt test.\n",
  6792. intr_mode);
  6793. /* Unset the preivous SLI-4 HBA setup */
  6794. lpfc_sli4_unset_hba(phba);
  6795. /* Try next level of interrupt mode */
  6796. cfg_mode = --intr_mode;
  6797. }
  6798. /* Perform post initialization setup */
  6799. lpfc_post_init_setup(phba);
  6800. /* Check if there are static vports to be created. */
  6801. lpfc_create_static_vport(phba);
  6802. return 0;
  6803. out_disable_intr:
  6804. lpfc_sli4_disable_intr(phba);
  6805. out_free_sysfs_attr:
  6806. lpfc_free_sysfs_attr(vport);
  6807. out_destroy_shost:
  6808. lpfc_destroy_shost(phba);
  6809. out_unset_driver_resource:
  6810. lpfc_unset_driver_resource_phase2(phba);
  6811. out_free_iocb_list:
  6812. lpfc_free_iocb_list(phba);
  6813. out_unset_driver_resource_s4:
  6814. lpfc_sli4_driver_resource_unset(phba);
  6815. out_unset_pci_mem_s4:
  6816. lpfc_sli4_pci_mem_unset(phba);
  6817. out_disable_pci_dev:
  6818. lpfc_disable_pci_dev(phba);
  6819. if (shost)
  6820. scsi_host_put(shost);
  6821. out_free_phba:
  6822. lpfc_hba_free(phba);
  6823. return error;
  6824. }
  6825. /**
  6826. * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
  6827. * @pdev: pointer to PCI device
  6828. *
  6829. * This routine is called from the kernel's PCI subsystem to device with
  6830. * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
  6831. * removed from PCI bus, it performs all the necessary cleanup for the HBA
  6832. * device to be removed from the PCI subsystem properly.
  6833. **/
  6834. static void __devexit
  6835. lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  6836. {
  6837. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6838. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  6839. struct lpfc_vport **vports;
  6840. struct lpfc_hba *phba = vport->phba;
  6841. int i;
  6842. /* Mark the device unloading flag */
  6843. spin_lock_irq(&phba->hbalock);
  6844. vport->load_flag |= FC_UNLOADING;
  6845. spin_unlock_irq(&phba->hbalock);
  6846. /* Free the HBA sysfs attributes */
  6847. lpfc_free_sysfs_attr(vport);
  6848. /* Release all the vports against this physical port */
  6849. vports = lpfc_create_vport_work_array(phba);
  6850. if (vports != NULL)
  6851. for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
  6852. fc_vport_terminate(vports[i]->fc_vport);
  6853. lpfc_destroy_vport_work_array(phba, vports);
  6854. /* Remove FC host and then SCSI host with the physical port */
  6855. fc_remove_host(shost);
  6856. scsi_remove_host(shost);
  6857. /* Perform cleanup on the physical port */
  6858. lpfc_cleanup(vport);
  6859. /*
  6860. * Bring down the SLI Layer. This step disables all interrupts,
  6861. * clears the rings, discards all mailbox commands, and resets
  6862. * the HBA FCoE function.
  6863. */
  6864. lpfc_debugfs_terminate(vport);
  6865. lpfc_sli4_hba_unset(phba);
  6866. spin_lock_irq(&phba->hbalock);
  6867. list_del_init(&vport->listentry);
  6868. spin_unlock_irq(&phba->hbalock);
  6869. /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
  6870. * buffers are released to their corresponding pools here.
  6871. */
  6872. lpfc_scsi_free(phba);
  6873. lpfc_sli4_driver_resource_unset(phba);
  6874. /* Unmap adapter Control and Doorbell registers */
  6875. lpfc_sli4_pci_mem_unset(phba);
  6876. /* Release PCI resources and disable device's PCI function */
  6877. scsi_host_put(shost);
  6878. lpfc_disable_pci_dev(phba);
  6879. /* Finally, free the driver's device data structure */
  6880. lpfc_hba_free(phba);
  6881. return;
  6882. }
  6883. /**
  6884. * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
  6885. * @pdev: pointer to PCI device
  6886. * @msg: power management message
  6887. *
  6888. * This routine is called from the kernel's PCI subsystem to support system
  6889. * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
  6890. * this method, it quiesces the device by stopping the driver's worker
  6891. * thread for the device, turning off device's interrupt and DMA, and bring
  6892. * the device offline. Note that as the driver implements the minimum PM
  6893. * requirements to a power-aware driver's PM support for suspend/resume -- all
  6894. * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
  6895. * method call will be treated as SUSPEND and the driver will fully
  6896. * reinitialize its device during resume() method call, the driver will set
  6897. * device to PCI_D3hot state in PCI config space instead of setting it
  6898. * according to the @msg provided by the PM.
  6899. *
  6900. * Return code
  6901. * 0 - driver suspended the device
  6902. * Error otherwise
  6903. **/
  6904. static int
  6905. lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
  6906. {
  6907. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6908. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6909. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6910. "0298 PCI device Power Management suspend.\n");
  6911. /* Bring down the device */
  6912. lpfc_offline_prep(phba);
  6913. lpfc_offline(phba);
  6914. kthread_stop(phba->worker_thread);
  6915. /* Disable interrupt from device */
  6916. lpfc_sli4_disable_intr(phba);
  6917. /* Save device state to PCI config space */
  6918. pci_save_state(pdev);
  6919. pci_set_power_state(pdev, PCI_D3hot);
  6920. return 0;
  6921. }
  6922. /**
  6923. * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
  6924. * @pdev: pointer to PCI device
  6925. *
  6926. * This routine is called from the kernel's PCI subsystem to support system
  6927. * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
  6928. * this method, it restores the device's PCI config space state and fully
  6929. * reinitializes the device and brings it online. Note that as the driver
  6930. * implements the minimum PM requirements to a power-aware driver's PM for
  6931. * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
  6932. * to the suspend() method call will be treated as SUSPEND and the driver
  6933. * will fully reinitialize its device during resume() method call, the device
  6934. * will be set to PCI_D0 directly in PCI config space before restoring the
  6935. * state.
  6936. *
  6937. * Return code
  6938. * 0 - driver suspended the device
  6939. * Error otherwise
  6940. **/
  6941. static int
  6942. lpfc_pci_resume_one_s4(struct pci_dev *pdev)
  6943. {
  6944. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6945. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  6946. uint32_t intr_mode;
  6947. int error;
  6948. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  6949. "0292 PCI device Power Management resume.\n");
  6950. /* Restore device state from PCI config space */
  6951. pci_set_power_state(pdev, PCI_D0);
  6952. pci_restore_state(pdev);
  6953. if (pdev->is_busmaster)
  6954. pci_set_master(pdev);
  6955. /* Startup the kernel thread for this host adapter. */
  6956. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  6957. "lpfc_worker_%d", phba->brd_no);
  6958. if (IS_ERR(phba->worker_thread)) {
  6959. error = PTR_ERR(phba->worker_thread);
  6960. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6961. "0293 PM resume failed to start worker "
  6962. "thread: error=x%x.\n", error);
  6963. return error;
  6964. }
  6965. /* Configure and enable interrupt */
  6966. intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
  6967. if (intr_mode == LPFC_INTR_ERROR) {
  6968. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  6969. "0294 PM resume Failed to enable interrupt\n");
  6970. return -EIO;
  6971. } else
  6972. phba->intr_mode = intr_mode;
  6973. /* Restart HBA and bring it online */
  6974. lpfc_sli_brdrestart(phba);
  6975. lpfc_online(phba);
  6976. /* Log the current active interrupt mode */
  6977. lpfc_log_intr_mode(phba, phba->intr_mode);
  6978. return 0;
  6979. }
  6980. /**
  6981. * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
  6982. * @pdev: pointer to PCI device.
  6983. * @state: the current PCI connection state.
  6984. *
  6985. * This routine is called from the PCI subsystem for error handling to device
  6986. * with SLI-4 interface spec. This function is called by the PCI subsystem
  6987. * after a PCI bus error affecting this device has been detected. When this
  6988. * function is invoked, it will need to stop all the I/Os and interrupt(s)
  6989. * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
  6990. * for the PCI subsystem to perform proper recovery as desired.
  6991. *
  6992. * Return codes
  6993. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  6994. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  6995. **/
  6996. static pci_ers_result_t
  6997. lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
  6998. {
  6999. return PCI_ERS_RESULT_NEED_RESET;
  7000. }
  7001. /**
  7002. * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
  7003. * @pdev: pointer to PCI device.
  7004. *
  7005. * This routine is called from the PCI subsystem for error handling to device
  7006. * with SLI-4 interface spec. It is called after PCI bus has been reset to
  7007. * restart the PCI card from scratch, as if from a cold-boot. During the
  7008. * PCI subsystem error recovery, after the driver returns
  7009. * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
  7010. * recovery and then call this routine before calling the .resume method to
  7011. * recover the device. This function will initialize the HBA device, enable
  7012. * the interrupt, but it will just put the HBA to offline state without
  7013. * passing any I/O traffic.
  7014. *
  7015. * Return codes
  7016. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  7017. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7018. */
  7019. static pci_ers_result_t
  7020. lpfc_io_slot_reset_s4(struct pci_dev *pdev)
  7021. {
  7022. return PCI_ERS_RESULT_RECOVERED;
  7023. }
  7024. /**
  7025. * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
  7026. * @pdev: pointer to PCI device
  7027. *
  7028. * This routine is called from the PCI subsystem for error handling to device
  7029. * with SLI-4 interface spec. It is called when kernel error recovery tells
  7030. * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
  7031. * error recovery. After this call, traffic can start to flow from this device
  7032. * again.
  7033. **/
  7034. static void
  7035. lpfc_io_resume_s4(struct pci_dev *pdev)
  7036. {
  7037. return;
  7038. }
  7039. /**
  7040. * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
  7041. * @pdev: pointer to PCI device
  7042. * @pid: pointer to PCI device identifier
  7043. *
  7044. * This routine is to be registered to the kernel's PCI subsystem. When an
  7045. * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
  7046. * at PCI device-specific information of the device and driver to see if the
  7047. * driver state that it can support this kind of device. If the match is
  7048. * successful, the driver core invokes this routine. This routine dispatches
  7049. * the action to the proper SLI-3 or SLI-4 device probing routine, which will
  7050. * do all the initialization that it needs to do to handle the HBA device
  7051. * properly.
  7052. *
  7053. * Return code
  7054. * 0 - driver can claim the device
  7055. * negative value - driver can not claim the device
  7056. **/
  7057. static int __devinit
  7058. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  7059. {
  7060. int rc;
  7061. struct lpfc_sli_intf intf;
  7062. if (pci_read_config_dword(pdev, LPFC_SLIREV_CONF_WORD, &intf.word0))
  7063. return -ENODEV;
  7064. if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
  7065. (bf_get(lpfc_sli_intf_rev, &intf) == LPFC_SLIREV_CONF_SLI4))
  7066. rc = lpfc_pci_probe_one_s4(pdev, pid);
  7067. else
  7068. rc = lpfc_pci_probe_one_s3(pdev, pid);
  7069. return rc;
  7070. }
  7071. /**
  7072. * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
  7073. * @pdev: pointer to PCI device
  7074. *
  7075. * This routine is to be registered to the kernel's PCI subsystem. When an
  7076. * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
  7077. * This routine dispatches the action to the proper SLI-3 or SLI-4 device
  7078. * remove routine, which will perform all the necessary cleanup for the
  7079. * device to be removed from the PCI subsystem properly.
  7080. **/
  7081. static void __devexit
  7082. lpfc_pci_remove_one(struct pci_dev *pdev)
  7083. {
  7084. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7085. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7086. switch (phba->pci_dev_grp) {
  7087. case LPFC_PCI_DEV_LP:
  7088. lpfc_pci_remove_one_s3(pdev);
  7089. break;
  7090. case LPFC_PCI_DEV_OC:
  7091. lpfc_pci_remove_one_s4(pdev);
  7092. break;
  7093. default:
  7094. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7095. "1424 Invalid PCI device group: 0x%x\n",
  7096. phba->pci_dev_grp);
  7097. break;
  7098. }
  7099. return;
  7100. }
  7101. /**
  7102. * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
  7103. * @pdev: pointer to PCI device
  7104. * @msg: power management message
  7105. *
  7106. * This routine is to be registered to the kernel's PCI subsystem to support
  7107. * system Power Management (PM). When PM invokes this method, it dispatches
  7108. * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
  7109. * suspend the device.
  7110. *
  7111. * Return code
  7112. * 0 - driver suspended the device
  7113. * Error otherwise
  7114. **/
  7115. static int
  7116. lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
  7117. {
  7118. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7119. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7120. int rc = -ENODEV;
  7121. switch (phba->pci_dev_grp) {
  7122. case LPFC_PCI_DEV_LP:
  7123. rc = lpfc_pci_suspend_one_s3(pdev, msg);
  7124. break;
  7125. case LPFC_PCI_DEV_OC:
  7126. rc = lpfc_pci_suspend_one_s4(pdev, msg);
  7127. break;
  7128. default:
  7129. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7130. "1425 Invalid PCI device group: 0x%x\n",
  7131. phba->pci_dev_grp);
  7132. break;
  7133. }
  7134. return rc;
  7135. }
  7136. /**
  7137. * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
  7138. * @pdev: pointer to PCI device
  7139. *
  7140. * This routine is to be registered to the kernel's PCI subsystem to support
  7141. * system Power Management (PM). When PM invokes this method, it dispatches
  7142. * the action to the proper SLI-3 or SLI-4 device resume routine, which will
  7143. * resume the device.
  7144. *
  7145. * Return code
  7146. * 0 - driver suspended the device
  7147. * Error otherwise
  7148. **/
  7149. static int
  7150. lpfc_pci_resume_one(struct pci_dev *pdev)
  7151. {
  7152. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7153. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7154. int rc = -ENODEV;
  7155. switch (phba->pci_dev_grp) {
  7156. case LPFC_PCI_DEV_LP:
  7157. rc = lpfc_pci_resume_one_s3(pdev);
  7158. break;
  7159. case LPFC_PCI_DEV_OC:
  7160. rc = lpfc_pci_resume_one_s4(pdev);
  7161. break;
  7162. default:
  7163. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7164. "1426 Invalid PCI device group: 0x%x\n",
  7165. phba->pci_dev_grp);
  7166. break;
  7167. }
  7168. return rc;
  7169. }
  7170. /**
  7171. * lpfc_io_error_detected - lpfc method for handling PCI I/O error
  7172. * @pdev: pointer to PCI device.
  7173. * @state: the current PCI connection state.
  7174. *
  7175. * This routine is registered to the PCI subsystem for error handling. This
  7176. * function is called by the PCI subsystem after a PCI bus error affecting
  7177. * this device has been detected. When this routine is invoked, it dispatches
  7178. * the action to the proper SLI-3 or SLI-4 device error detected handling
  7179. * routine, which will perform the proper error detected operation.
  7180. *
  7181. * Return codes
  7182. * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
  7183. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7184. **/
  7185. static pci_ers_result_t
  7186. lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  7187. {
  7188. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7189. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7190. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  7191. switch (phba->pci_dev_grp) {
  7192. case LPFC_PCI_DEV_LP:
  7193. rc = lpfc_io_error_detected_s3(pdev, state);
  7194. break;
  7195. case LPFC_PCI_DEV_OC:
  7196. rc = lpfc_io_error_detected_s4(pdev, state);
  7197. break;
  7198. default:
  7199. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7200. "1427 Invalid PCI device group: 0x%x\n",
  7201. phba->pci_dev_grp);
  7202. break;
  7203. }
  7204. return rc;
  7205. }
  7206. /**
  7207. * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
  7208. * @pdev: pointer to PCI device.
  7209. *
  7210. * This routine is registered to the PCI subsystem for error handling. This
  7211. * function is called after PCI bus has been reset to restart the PCI card
  7212. * from scratch, as if from a cold-boot. When this routine is invoked, it
  7213. * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
  7214. * routine, which will perform the proper device reset.
  7215. *
  7216. * Return codes
  7217. * PCI_ERS_RESULT_RECOVERED - the device has been recovered
  7218. * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
  7219. **/
  7220. static pci_ers_result_t
  7221. lpfc_io_slot_reset(struct pci_dev *pdev)
  7222. {
  7223. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7224. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7225. pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT;
  7226. switch (phba->pci_dev_grp) {
  7227. case LPFC_PCI_DEV_LP:
  7228. rc = lpfc_io_slot_reset_s3(pdev);
  7229. break;
  7230. case LPFC_PCI_DEV_OC:
  7231. rc = lpfc_io_slot_reset_s4(pdev);
  7232. break;
  7233. default:
  7234. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7235. "1428 Invalid PCI device group: 0x%x\n",
  7236. phba->pci_dev_grp);
  7237. break;
  7238. }
  7239. return rc;
  7240. }
  7241. /**
  7242. * lpfc_io_resume - lpfc method for resuming PCI I/O operation
  7243. * @pdev: pointer to PCI device
  7244. *
  7245. * This routine is registered to the PCI subsystem for error handling. It
  7246. * is called when kernel error recovery tells the lpfc driver that it is
  7247. * OK to resume normal PCI operation after PCI bus error recovery. When
  7248. * this routine is invoked, it dispatches the action to the proper SLI-3
  7249. * or SLI-4 device io_resume routine, which will resume the device operation.
  7250. **/
  7251. static void
  7252. lpfc_io_resume(struct pci_dev *pdev)
  7253. {
  7254. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7255. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  7256. switch (phba->pci_dev_grp) {
  7257. case LPFC_PCI_DEV_LP:
  7258. lpfc_io_resume_s3(pdev);
  7259. break;
  7260. case LPFC_PCI_DEV_OC:
  7261. lpfc_io_resume_s4(pdev);
  7262. break;
  7263. default:
  7264. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7265. "1429 Invalid PCI device group: 0x%x\n",
  7266. phba->pci_dev_grp);
  7267. break;
  7268. }
  7269. return;
  7270. }
  7271. static struct pci_device_id lpfc_id_table[] = {
  7272. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  7273. PCI_ANY_ID, PCI_ANY_ID, },
  7274. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  7275. PCI_ANY_ID, PCI_ANY_ID, },
  7276. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  7277. PCI_ANY_ID, PCI_ANY_ID, },
  7278. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  7279. PCI_ANY_ID, PCI_ANY_ID, },
  7280. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  7281. PCI_ANY_ID, PCI_ANY_ID, },
  7282. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  7283. PCI_ANY_ID, PCI_ANY_ID, },
  7284. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  7285. PCI_ANY_ID, PCI_ANY_ID, },
  7286. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  7287. PCI_ANY_ID, PCI_ANY_ID, },
  7288. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  7289. PCI_ANY_ID, PCI_ANY_ID, },
  7290. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  7291. PCI_ANY_ID, PCI_ANY_ID, },
  7292. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  7293. PCI_ANY_ID, PCI_ANY_ID, },
  7294. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  7295. PCI_ANY_ID, PCI_ANY_ID, },
  7296. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  7297. PCI_ANY_ID, PCI_ANY_ID, },
  7298. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  7299. PCI_ANY_ID, PCI_ANY_ID, },
  7300. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  7301. PCI_ANY_ID, PCI_ANY_ID, },
  7302. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  7303. PCI_ANY_ID, PCI_ANY_ID, },
  7304. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  7305. PCI_ANY_ID, PCI_ANY_ID, },
  7306. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  7307. PCI_ANY_ID, PCI_ANY_ID, },
  7308. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET,
  7309. PCI_ANY_ID, PCI_ANY_ID, },
  7310. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  7311. PCI_ANY_ID, PCI_ANY_ID, },
  7312. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  7313. PCI_ANY_ID, PCI_ANY_ID, },
  7314. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  7315. PCI_ANY_ID, PCI_ANY_ID, },
  7316. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  7317. PCI_ANY_ID, PCI_ANY_ID, },
  7318. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  7319. PCI_ANY_ID, PCI_ANY_ID, },
  7320. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  7321. PCI_ANY_ID, PCI_ANY_ID, },
  7322. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  7323. PCI_ANY_ID, PCI_ANY_ID, },
  7324. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  7325. PCI_ANY_ID, PCI_ANY_ID, },
  7326. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  7327. PCI_ANY_ID, PCI_ANY_ID, },
  7328. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  7329. PCI_ANY_ID, PCI_ANY_ID, },
  7330. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  7331. PCI_ANY_ID, PCI_ANY_ID, },
  7332. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  7333. PCI_ANY_ID, PCI_ANY_ID, },
  7334. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  7335. PCI_ANY_ID, PCI_ANY_ID, },
  7336. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  7337. PCI_ANY_ID, PCI_ANY_ID, },
  7338. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  7339. PCI_ANY_ID, PCI_ANY_ID, },
  7340. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF,
  7341. PCI_ANY_ID, PCI_ANY_ID, },
  7342. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF,
  7343. PCI_ANY_ID, PCI_ANY_ID, },
  7344. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S,
  7345. PCI_ANY_ID, PCI_ANY_ID, },
  7346. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK,
  7347. PCI_ANY_ID, PCI_ANY_ID, },
  7348. {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT,
  7349. PCI_ANY_ID, PCI_ANY_ID, },
  7350. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON,
  7351. PCI_ANY_ID, PCI_ANY_ID, },
  7352. { 0 }
  7353. };
  7354. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  7355. static struct pci_error_handlers lpfc_err_handler = {
  7356. .error_detected = lpfc_io_error_detected,
  7357. .slot_reset = lpfc_io_slot_reset,
  7358. .resume = lpfc_io_resume,
  7359. };
  7360. static struct pci_driver lpfc_driver = {
  7361. .name = LPFC_DRIVER_NAME,
  7362. .id_table = lpfc_id_table,
  7363. .probe = lpfc_pci_probe_one,
  7364. .remove = __devexit_p(lpfc_pci_remove_one),
  7365. .suspend = lpfc_pci_suspend_one,
  7366. .resume = lpfc_pci_resume_one,
  7367. .err_handler = &lpfc_err_handler,
  7368. };
  7369. /**
  7370. * lpfc_init - lpfc module initialization routine
  7371. *
  7372. * This routine is to be invoked when the lpfc module is loaded into the
  7373. * kernel. The special kernel macro module_init() is used to indicate the
  7374. * role of this routine to the kernel as lpfc module entry point.
  7375. *
  7376. * Return codes
  7377. * 0 - successful
  7378. * -ENOMEM - FC attach transport failed
  7379. * all others - failed
  7380. */
  7381. static int __init
  7382. lpfc_init(void)
  7383. {
  7384. int error = 0;
  7385. printk(LPFC_MODULE_DESC "\n");
  7386. printk(LPFC_COPYRIGHT "\n");
  7387. if (lpfc_enable_npiv) {
  7388. lpfc_transport_functions.vport_create = lpfc_vport_create;
  7389. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  7390. }
  7391. lpfc_transport_template =
  7392. fc_attach_transport(&lpfc_transport_functions);
  7393. if (lpfc_transport_template == NULL)
  7394. return -ENOMEM;
  7395. if (lpfc_enable_npiv) {
  7396. lpfc_vport_transport_template =
  7397. fc_attach_transport(&lpfc_vport_transport_functions);
  7398. if (lpfc_vport_transport_template == NULL) {
  7399. fc_release_transport(lpfc_transport_template);
  7400. return -ENOMEM;
  7401. }
  7402. }
  7403. error = pci_register_driver(&lpfc_driver);
  7404. if (error) {
  7405. fc_release_transport(lpfc_transport_template);
  7406. if (lpfc_enable_npiv)
  7407. fc_release_transport(lpfc_vport_transport_template);
  7408. }
  7409. return error;
  7410. }
  7411. /**
  7412. * lpfc_exit - lpfc module removal routine
  7413. *
  7414. * This routine is invoked when the lpfc module is removed from the kernel.
  7415. * The special kernel macro module_exit() is used to indicate the role of
  7416. * this routine to the kernel as lpfc module exit point.
  7417. */
  7418. static void __exit
  7419. lpfc_exit(void)
  7420. {
  7421. pci_unregister_driver(&lpfc_driver);
  7422. fc_release_transport(lpfc_transport_template);
  7423. if (lpfc_enable_npiv)
  7424. fc_release_transport(lpfc_vport_transport_template);
  7425. if (_dump_buf_data) {
  7426. printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for "
  7427. "_dump_buf_data at 0x%p\n",
  7428. (1L << _dump_buf_data_order), _dump_buf_data);
  7429. free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order);
  7430. }
  7431. if (_dump_buf_dif) {
  7432. printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for "
  7433. "_dump_buf_dif at 0x%p\n",
  7434. (1L << _dump_buf_dif_order), _dump_buf_dif);
  7435. free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order);
  7436. }
  7437. }
  7438. module_init(lpfc_init);
  7439. module_exit(lpfc_exit);
  7440. MODULE_LICENSE("GPL");
  7441. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  7442. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  7443. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);