lpfc_init.c 236 KB

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