lpfc_init.c 306 KB

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