lpfc_init.c 285 KB

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