ql4_os.c 284 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/slab.h>
  9. #include <linux/blkdev.h>
  10. #include <linux/iscsi_boot_sysfs.h>
  11. #include <linux/inet.h>
  12. #include <scsi/scsi_tcq.h>
  13. #include <scsi/scsicam.h>
  14. #include "ql4_def.h"
  15. #include "ql4_version.h"
  16. #include "ql4_glbl.h"
  17. #include "ql4_dbg.h"
  18. #include "ql4_inline.h"
  19. #include "ql4_83xx.h"
  20. /*
  21. * Driver version
  22. */
  23. static char qla4xxx_version_str[40];
  24. /*
  25. * SRB allocation cache
  26. */
  27. static struct kmem_cache *srb_cachep;
  28. /*
  29. * Module parameter information and variables
  30. */
  31. static int ql4xdisablesysfsboot = 1;
  32. module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
  33. MODULE_PARM_DESC(ql4xdisablesysfsboot,
  34. " Set to disable exporting boot targets to sysfs.\n"
  35. "\t\t 0 - Export boot targets\n"
  36. "\t\t 1 - Do not export boot targets (Default)");
  37. int ql4xdontresethba;
  38. module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
  39. MODULE_PARM_DESC(ql4xdontresethba,
  40. " Don't reset the HBA for driver recovery.\n"
  41. "\t\t 0 - It will reset HBA (Default)\n"
  42. "\t\t 1 - It will NOT reset HBA");
  43. int ql4xextended_error_logging;
  44. module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
  45. MODULE_PARM_DESC(ql4xextended_error_logging,
  46. " Option to enable extended error logging.\n"
  47. "\t\t 0 - no logging (Default)\n"
  48. "\t\t 2 - debug logging");
  49. int ql4xenablemsix = 1;
  50. module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
  51. MODULE_PARM_DESC(ql4xenablemsix,
  52. " Set to enable MSI or MSI-X interrupt mechanism.\n"
  53. "\t\t 0 = enable INTx interrupt mechanism.\n"
  54. "\t\t 1 = enable MSI-X interrupt mechanism (Default).\n"
  55. "\t\t 2 = enable MSI interrupt mechanism.");
  56. #define QL4_DEF_QDEPTH 32
  57. static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
  58. module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
  59. MODULE_PARM_DESC(ql4xmaxqdepth,
  60. " Maximum queue depth to report for target devices.\n"
  61. "\t\t Default: 32.");
  62. static int ql4xqfulltracking = 1;
  63. module_param(ql4xqfulltracking, int, S_IRUGO | S_IWUSR);
  64. MODULE_PARM_DESC(ql4xqfulltracking,
  65. " Enable or disable dynamic tracking and adjustment of\n"
  66. "\t\t scsi device queue depth.\n"
  67. "\t\t 0 - Disable.\n"
  68. "\t\t 1 - Enable. (Default)");
  69. static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
  70. module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
  71. MODULE_PARM_DESC(ql4xsess_recovery_tmo,
  72. " Target Session Recovery Timeout.\n"
  73. "\t\t Default: 120 sec.");
  74. int ql4xmdcapmask = 0;
  75. module_param(ql4xmdcapmask, int, S_IRUGO);
  76. MODULE_PARM_DESC(ql4xmdcapmask,
  77. " Set the Minidump driver capture mask level.\n"
  78. "\t\t Default is 0 (firmware default capture mask)\n"
  79. "\t\t Can be set to 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF");
  80. int ql4xenablemd = 1;
  81. module_param(ql4xenablemd, int, S_IRUGO | S_IWUSR);
  82. MODULE_PARM_DESC(ql4xenablemd,
  83. " Set to enable minidump.\n"
  84. "\t\t 0 - disable minidump\n"
  85. "\t\t 1 - enable minidump (Default)");
  86. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
  87. /*
  88. * SCSI host template entry points
  89. */
  90. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
  91. /*
  92. * iSCSI template entry points
  93. */
  94. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  95. enum iscsi_param param, char *buf);
  96. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
  97. enum iscsi_param param, char *buf);
  98. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  99. enum iscsi_host_param param, char *buf);
  100. static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
  101. uint32_t len);
  102. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  103. enum iscsi_param_type param_type,
  104. int param, char *buf);
  105. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
  106. static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
  107. struct sockaddr *dst_addr,
  108. int non_blocking);
  109. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
  110. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
  111. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  112. enum iscsi_param param, char *buf);
  113. static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
  114. static struct iscsi_cls_conn *
  115. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
  116. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  117. struct iscsi_cls_conn *cls_conn,
  118. uint64_t transport_fd, int is_leading);
  119. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
  120. static struct iscsi_cls_session *
  121. qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
  122. uint16_t qdepth, uint32_t initial_cmdsn);
  123. static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
  124. static void qla4xxx_task_work(struct work_struct *wdata);
  125. static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
  126. static int qla4xxx_task_xmit(struct iscsi_task *);
  127. static void qla4xxx_task_cleanup(struct iscsi_task *);
  128. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
  129. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  130. struct iscsi_stats *stats);
  131. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  132. uint32_t iface_type, uint32_t payload_size,
  133. uint32_t pid, struct sockaddr *dst_addr);
  134. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  135. uint32_t *num_entries, char *buf);
  136. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx);
  137. static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data,
  138. int len);
  139. static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len);
  140. /*
  141. * SCSI host template entry points
  142. */
  143. static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  144. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
  145. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
  146. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
  147. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
  148. static int qla4xxx_slave_alloc(struct scsi_device *device);
  149. static umode_t qla4_attr_is_visible(int param_type, int param);
  150. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
  151. /*
  152. * iSCSI Flash DDB sysfs entry points
  153. */
  154. static int
  155. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  156. struct iscsi_bus_flash_conn *fnode_conn,
  157. void *data, int len);
  158. static int
  159. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  160. int param, char *buf);
  161. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  162. int len);
  163. static int
  164. qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess);
  165. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  166. struct iscsi_bus_flash_conn *fnode_conn);
  167. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  168. struct iscsi_bus_flash_conn *fnode_conn);
  169. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess);
  170. static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
  171. QLA82XX_LEGACY_INTR_CONFIG;
  172. static struct scsi_host_template qla4xxx_driver_template = {
  173. .module = THIS_MODULE,
  174. .name = DRIVER_NAME,
  175. .proc_name = DRIVER_NAME,
  176. .queuecommand = qla4xxx_queuecommand,
  177. .eh_abort_handler = qla4xxx_eh_abort,
  178. .eh_device_reset_handler = qla4xxx_eh_device_reset,
  179. .eh_target_reset_handler = qla4xxx_eh_target_reset,
  180. .eh_host_reset_handler = qla4xxx_eh_host_reset,
  181. .eh_timed_out = qla4xxx_eh_cmd_timed_out,
  182. .slave_alloc = qla4xxx_slave_alloc,
  183. .change_queue_depth = scsi_change_queue_depth,
  184. .this_id = -1,
  185. .cmd_per_lun = 3,
  186. .use_clustering = ENABLE_CLUSTERING,
  187. .sg_tablesize = SG_ALL,
  188. .max_sectors = 0xFFFF,
  189. .shost_attrs = qla4xxx_host_attrs,
  190. .host_reset = qla4xxx_host_reset,
  191. .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
  192. };
  193. static struct iscsi_transport qla4xxx_iscsi_transport = {
  194. .owner = THIS_MODULE,
  195. .name = DRIVER_NAME,
  196. .caps = CAP_TEXT_NEGO |
  197. CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
  198. CAP_DATADGST | CAP_LOGIN_OFFLOAD |
  199. CAP_MULTI_R2T,
  200. .attr_is_visible = qla4_attr_is_visible,
  201. .create_session = qla4xxx_session_create,
  202. .destroy_session = qla4xxx_session_destroy,
  203. .start_conn = qla4xxx_conn_start,
  204. .create_conn = qla4xxx_conn_create,
  205. .bind_conn = qla4xxx_conn_bind,
  206. .stop_conn = iscsi_conn_stop,
  207. .destroy_conn = qla4xxx_conn_destroy,
  208. .set_param = iscsi_set_param,
  209. .get_conn_param = qla4xxx_conn_get_param,
  210. .get_session_param = qla4xxx_session_get_param,
  211. .get_ep_param = qla4xxx_get_ep_param,
  212. .ep_connect = qla4xxx_ep_connect,
  213. .ep_poll = qla4xxx_ep_poll,
  214. .ep_disconnect = qla4xxx_ep_disconnect,
  215. .get_stats = qla4xxx_conn_get_stats,
  216. .send_pdu = iscsi_conn_send_pdu,
  217. .xmit_task = qla4xxx_task_xmit,
  218. .cleanup_task = qla4xxx_task_cleanup,
  219. .alloc_pdu = qla4xxx_alloc_pdu,
  220. .get_host_param = qla4xxx_host_get_param,
  221. .set_iface_param = qla4xxx_iface_set_param,
  222. .get_iface_param = qla4xxx_get_iface_param,
  223. .bsg_request = qla4xxx_bsg_request,
  224. .send_ping = qla4xxx_send_ping,
  225. .get_chap = qla4xxx_get_chap_list,
  226. .delete_chap = qla4xxx_delete_chap,
  227. .set_chap = qla4xxx_set_chap_entry,
  228. .get_flashnode_param = qla4xxx_sysfs_ddb_get_param,
  229. .set_flashnode_param = qla4xxx_sysfs_ddb_set_param,
  230. .new_flashnode = qla4xxx_sysfs_ddb_add,
  231. .del_flashnode = qla4xxx_sysfs_ddb_delete,
  232. .login_flashnode = qla4xxx_sysfs_ddb_login,
  233. .logout_flashnode = qla4xxx_sysfs_ddb_logout,
  234. .logout_flashnode_sid = qla4xxx_sysfs_ddb_logout_sid,
  235. .get_host_stats = qla4xxx_get_host_stats,
  236. };
  237. static struct scsi_transport_template *qla4xxx_scsi_transport;
  238. static int qla4xxx_isp_check_reg(struct scsi_qla_host *ha)
  239. {
  240. u32 reg_val = 0;
  241. int rval = QLA_SUCCESS;
  242. if (is_qla8022(ha))
  243. reg_val = readl(&ha->qla4_82xx_reg->host_status);
  244. else if (is_qla8032(ha) || is_qla8042(ha))
  245. reg_val = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
  246. else
  247. reg_val = readw(&ha->reg->ctrl_status);
  248. if (reg_val == QL4_ISP_REG_DISCONNECT)
  249. rval = QLA_ERROR;
  250. return rval;
  251. }
  252. static int qla4xxx_send_ping(struct Scsi_Host *shost, uint32_t iface_num,
  253. uint32_t iface_type, uint32_t payload_size,
  254. uint32_t pid, struct sockaddr *dst_addr)
  255. {
  256. struct scsi_qla_host *ha = to_qla_host(shost);
  257. struct sockaddr_in *addr;
  258. struct sockaddr_in6 *addr6;
  259. uint32_t options = 0;
  260. uint8_t ipaddr[IPv6_ADDR_LEN];
  261. int rval;
  262. memset(ipaddr, 0, IPv6_ADDR_LEN);
  263. /* IPv4 to IPv4 */
  264. if ((iface_type == ISCSI_IFACE_TYPE_IPV4) &&
  265. (dst_addr->sa_family == AF_INET)) {
  266. addr = (struct sockaddr_in *)dst_addr;
  267. memcpy(ipaddr, &addr->sin_addr.s_addr, IP_ADDR_LEN);
  268. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv4 Ping src: %pI4 "
  269. "dest: %pI4\n", __func__,
  270. &ha->ip_config.ip_address, ipaddr));
  271. rval = qla4xxx_ping_iocb(ha, options, payload_size, pid,
  272. ipaddr);
  273. if (rval)
  274. rval = -EINVAL;
  275. } else if ((iface_type == ISCSI_IFACE_TYPE_IPV6) &&
  276. (dst_addr->sa_family == AF_INET6)) {
  277. /* IPv6 to IPv6 */
  278. addr6 = (struct sockaddr_in6 *)dst_addr;
  279. memcpy(ipaddr, &addr6->sin6_addr.in6_u.u6_addr8, IPv6_ADDR_LEN);
  280. options |= PING_IPV6_PROTOCOL_ENABLE;
  281. /* Ping using LinkLocal address */
  282. if ((iface_num == 0) || (iface_num == 1)) {
  283. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: LinkLocal Ping "
  284. "src: %pI6 dest: %pI6\n", __func__,
  285. &ha->ip_config.ipv6_link_local_addr,
  286. ipaddr));
  287. options |= PING_IPV6_LINKLOCAL_ADDR;
  288. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  289. pid, ipaddr);
  290. } else {
  291. ql4_printk(KERN_WARNING, ha, "%s: iface num = %d "
  292. "not supported\n", __func__, iface_num);
  293. rval = -ENOSYS;
  294. goto exit_send_ping;
  295. }
  296. /*
  297. * If ping using LinkLocal address fails, try ping using
  298. * IPv6 address
  299. */
  300. if (rval != QLA_SUCCESS) {
  301. options &= ~PING_IPV6_LINKLOCAL_ADDR;
  302. if (iface_num == 0) {
  303. options |= PING_IPV6_ADDR0;
  304. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  305. "Ping src: %pI6 "
  306. "dest: %pI6\n", __func__,
  307. &ha->ip_config.ipv6_addr0,
  308. ipaddr));
  309. } else if (iface_num == 1) {
  310. options |= PING_IPV6_ADDR1;
  311. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: IPv6 "
  312. "Ping src: %pI6 "
  313. "dest: %pI6\n", __func__,
  314. &ha->ip_config.ipv6_addr1,
  315. ipaddr));
  316. }
  317. rval = qla4xxx_ping_iocb(ha, options, payload_size,
  318. pid, ipaddr);
  319. if (rval)
  320. rval = -EINVAL;
  321. }
  322. } else
  323. rval = -ENOSYS;
  324. exit_send_ping:
  325. return rval;
  326. }
  327. static umode_t qla4_attr_is_visible(int param_type, int param)
  328. {
  329. switch (param_type) {
  330. case ISCSI_HOST_PARAM:
  331. switch (param) {
  332. case ISCSI_HOST_PARAM_HWADDRESS:
  333. case ISCSI_HOST_PARAM_IPADDRESS:
  334. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  335. case ISCSI_HOST_PARAM_PORT_STATE:
  336. case ISCSI_HOST_PARAM_PORT_SPEED:
  337. return S_IRUGO;
  338. default:
  339. return 0;
  340. }
  341. case ISCSI_PARAM:
  342. switch (param) {
  343. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  344. case ISCSI_PARAM_PERSISTENT_PORT:
  345. case ISCSI_PARAM_CONN_ADDRESS:
  346. case ISCSI_PARAM_CONN_PORT:
  347. case ISCSI_PARAM_TARGET_NAME:
  348. case ISCSI_PARAM_TPGT:
  349. case ISCSI_PARAM_TARGET_ALIAS:
  350. case ISCSI_PARAM_MAX_BURST:
  351. case ISCSI_PARAM_MAX_R2T:
  352. case ISCSI_PARAM_FIRST_BURST:
  353. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  354. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  355. case ISCSI_PARAM_IFACE_NAME:
  356. case ISCSI_PARAM_CHAP_OUT_IDX:
  357. case ISCSI_PARAM_CHAP_IN_IDX:
  358. case ISCSI_PARAM_USERNAME:
  359. case ISCSI_PARAM_PASSWORD:
  360. case ISCSI_PARAM_USERNAME_IN:
  361. case ISCSI_PARAM_PASSWORD_IN:
  362. case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
  363. case ISCSI_PARAM_DISCOVERY_SESS:
  364. case ISCSI_PARAM_PORTAL_TYPE:
  365. case ISCSI_PARAM_CHAP_AUTH_EN:
  366. case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
  367. case ISCSI_PARAM_BIDI_CHAP_EN:
  368. case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
  369. case ISCSI_PARAM_DEF_TIME2WAIT:
  370. case ISCSI_PARAM_DEF_TIME2RETAIN:
  371. case ISCSI_PARAM_HDRDGST_EN:
  372. case ISCSI_PARAM_DATADGST_EN:
  373. case ISCSI_PARAM_INITIAL_R2T_EN:
  374. case ISCSI_PARAM_IMM_DATA_EN:
  375. case ISCSI_PARAM_PDU_INORDER_EN:
  376. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  377. case ISCSI_PARAM_MAX_SEGMENT_SIZE:
  378. case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
  379. case ISCSI_PARAM_TCP_WSF_DISABLE:
  380. case ISCSI_PARAM_TCP_NAGLE_DISABLE:
  381. case ISCSI_PARAM_TCP_TIMER_SCALE:
  382. case ISCSI_PARAM_TCP_TIMESTAMP_EN:
  383. case ISCSI_PARAM_TCP_XMIT_WSF:
  384. case ISCSI_PARAM_TCP_RECV_WSF:
  385. case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
  386. case ISCSI_PARAM_IPV4_TOS:
  387. case ISCSI_PARAM_IPV6_TC:
  388. case ISCSI_PARAM_IPV6_FLOW_LABEL:
  389. case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
  390. case ISCSI_PARAM_KEEPALIVE_TMO:
  391. case ISCSI_PARAM_LOCAL_PORT:
  392. case ISCSI_PARAM_ISID:
  393. case ISCSI_PARAM_TSID:
  394. case ISCSI_PARAM_DEF_TASKMGMT_TMO:
  395. case ISCSI_PARAM_ERL:
  396. case ISCSI_PARAM_STATSN:
  397. case ISCSI_PARAM_EXP_STATSN:
  398. case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
  399. case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
  400. case ISCSI_PARAM_LOCAL_IPADDR:
  401. return S_IRUGO;
  402. default:
  403. return 0;
  404. }
  405. case ISCSI_NET_PARAM:
  406. switch (param) {
  407. case ISCSI_NET_PARAM_IPV4_ADDR:
  408. case ISCSI_NET_PARAM_IPV4_SUBNET:
  409. case ISCSI_NET_PARAM_IPV4_GW:
  410. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  411. case ISCSI_NET_PARAM_IFACE_ENABLE:
  412. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  413. case ISCSI_NET_PARAM_IPV6_ADDR:
  414. case ISCSI_NET_PARAM_IPV6_ROUTER:
  415. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  416. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  417. case ISCSI_NET_PARAM_VLAN_ID:
  418. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  419. case ISCSI_NET_PARAM_VLAN_ENABLED:
  420. case ISCSI_NET_PARAM_MTU:
  421. case ISCSI_NET_PARAM_PORT:
  422. case ISCSI_NET_PARAM_IPADDR_STATE:
  423. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
  424. case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
  425. case ISCSI_NET_PARAM_DELAYED_ACK_EN:
  426. case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
  427. case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
  428. case ISCSI_NET_PARAM_TCP_WSF:
  429. case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
  430. case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
  431. case ISCSI_NET_PARAM_CACHE_ID:
  432. case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
  433. case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
  434. case ISCSI_NET_PARAM_IPV4_TOS_EN:
  435. case ISCSI_NET_PARAM_IPV4_TOS:
  436. case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
  437. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
  438. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
  439. case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
  440. case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
  441. case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
  442. case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
  443. case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
  444. case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
  445. case ISCSI_NET_PARAM_REDIRECT_EN:
  446. case ISCSI_NET_PARAM_IPV4_TTL:
  447. case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
  448. case ISCSI_NET_PARAM_IPV6_MLD_EN:
  449. case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
  450. case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
  451. case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
  452. case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
  453. case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
  454. case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
  455. case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
  456. case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
  457. return S_IRUGO;
  458. default:
  459. return 0;
  460. }
  461. case ISCSI_IFACE_PARAM:
  462. switch (param) {
  463. case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
  464. case ISCSI_IFACE_PARAM_HDRDGST_EN:
  465. case ISCSI_IFACE_PARAM_DATADGST_EN:
  466. case ISCSI_IFACE_PARAM_IMM_DATA_EN:
  467. case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
  468. case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
  469. case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
  470. case ISCSI_IFACE_PARAM_ERL:
  471. case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
  472. case ISCSI_IFACE_PARAM_FIRST_BURST:
  473. case ISCSI_IFACE_PARAM_MAX_R2T:
  474. case ISCSI_IFACE_PARAM_MAX_BURST:
  475. case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
  476. case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
  477. case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
  478. case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
  479. case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
  480. case ISCSI_IFACE_PARAM_INITIATOR_NAME:
  481. return S_IRUGO;
  482. default:
  483. return 0;
  484. }
  485. case ISCSI_FLASHNODE_PARAM:
  486. switch (param) {
  487. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  488. case ISCSI_FLASHNODE_PORTAL_TYPE:
  489. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  490. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  491. case ISCSI_FLASHNODE_ENTRY_EN:
  492. case ISCSI_FLASHNODE_HDR_DGST_EN:
  493. case ISCSI_FLASHNODE_DATA_DGST_EN:
  494. case ISCSI_FLASHNODE_IMM_DATA_EN:
  495. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  496. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  497. case ISCSI_FLASHNODE_PDU_INORDER:
  498. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  499. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  500. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  501. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  502. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  503. case ISCSI_FLASHNODE_ERL:
  504. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  505. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  506. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  507. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  508. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  509. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  510. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  511. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  512. case ISCSI_FLASHNODE_FIRST_BURST:
  513. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  514. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  515. case ISCSI_FLASHNODE_MAX_R2T:
  516. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  517. case ISCSI_FLASHNODE_ISID:
  518. case ISCSI_FLASHNODE_TSID:
  519. case ISCSI_FLASHNODE_PORT:
  520. case ISCSI_FLASHNODE_MAX_BURST:
  521. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  522. case ISCSI_FLASHNODE_IPADDR:
  523. case ISCSI_FLASHNODE_ALIAS:
  524. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  525. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  526. case ISCSI_FLASHNODE_LOCAL_PORT:
  527. case ISCSI_FLASHNODE_IPV4_TOS:
  528. case ISCSI_FLASHNODE_IPV6_TC:
  529. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  530. case ISCSI_FLASHNODE_NAME:
  531. case ISCSI_FLASHNODE_TPGT:
  532. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  533. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  534. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  535. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  536. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  537. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  538. case ISCSI_FLASHNODE_USERNAME:
  539. case ISCSI_FLASHNODE_PASSWORD:
  540. case ISCSI_FLASHNODE_STATSN:
  541. case ISCSI_FLASHNODE_EXP_STATSN:
  542. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  543. return S_IRUGO;
  544. default:
  545. return 0;
  546. }
  547. }
  548. return 0;
  549. }
  550. /**
  551. * qla4xxx_create chap_list - Create CHAP list from FLASH
  552. * @ha: pointer to adapter structure
  553. *
  554. * Read flash and make a list of CHAP entries, during login when a CHAP entry
  555. * is received, it will be checked in this list. If entry exist then the CHAP
  556. * entry index is set in the DDB. If CHAP entry does not exist in this list
  557. * then a new entry is added in FLASH in CHAP table and the index obtained is
  558. * used in the DDB.
  559. **/
  560. static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
  561. {
  562. int rval = 0;
  563. uint8_t *chap_flash_data = NULL;
  564. uint32_t offset;
  565. dma_addr_t chap_dma;
  566. uint32_t chap_size = 0;
  567. if (is_qla40XX(ha))
  568. chap_size = MAX_CHAP_ENTRIES_40XX *
  569. sizeof(struct ql4_chap_table);
  570. else /* Single region contains CHAP info for both
  571. * ports which is divided into half for each port.
  572. */
  573. chap_size = ha->hw.flt_chap_size / 2;
  574. chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
  575. &chap_dma, GFP_KERNEL);
  576. if (!chap_flash_data) {
  577. ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
  578. return;
  579. }
  580. if (is_qla40XX(ha)) {
  581. offset = FLASH_CHAP_OFFSET;
  582. } else {
  583. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  584. if (ha->port_num == 1)
  585. offset += chap_size;
  586. }
  587. rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  588. if (rval != QLA_SUCCESS)
  589. goto exit_chap_list;
  590. if (ha->chap_list == NULL)
  591. ha->chap_list = vmalloc(chap_size);
  592. if (ha->chap_list == NULL) {
  593. ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
  594. goto exit_chap_list;
  595. }
  596. memset(ha->chap_list, 0, chap_size);
  597. memcpy(ha->chap_list, chap_flash_data, chap_size);
  598. exit_chap_list:
  599. dma_free_coherent(&ha->pdev->dev, chap_size, chap_flash_data, chap_dma);
  600. }
  601. static int qla4xxx_get_chap_by_index(struct scsi_qla_host *ha,
  602. int16_t chap_index,
  603. struct ql4_chap_table **chap_entry)
  604. {
  605. int rval = QLA_ERROR;
  606. int max_chap_entries;
  607. if (!ha->chap_list) {
  608. ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
  609. rval = QLA_ERROR;
  610. goto exit_get_chap;
  611. }
  612. if (is_qla80XX(ha))
  613. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  614. sizeof(struct ql4_chap_table);
  615. else
  616. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  617. if (chap_index > max_chap_entries) {
  618. ql4_printk(KERN_ERR, ha, "Invalid Chap index\n");
  619. rval = QLA_ERROR;
  620. goto exit_get_chap;
  621. }
  622. *chap_entry = (struct ql4_chap_table *)ha->chap_list + chap_index;
  623. if ((*chap_entry)->cookie !=
  624. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  625. rval = QLA_ERROR;
  626. *chap_entry = NULL;
  627. } else {
  628. rval = QLA_SUCCESS;
  629. }
  630. exit_get_chap:
  631. return rval;
  632. }
  633. /**
  634. * qla4xxx_find_free_chap_index - Find the first free chap index
  635. * @ha: pointer to adapter structure
  636. * @chap_index: CHAP index to be returned
  637. *
  638. * Find the first free chap index available in the chap table
  639. *
  640. * Note: Caller should acquire the chap lock before getting here.
  641. **/
  642. static int qla4xxx_find_free_chap_index(struct scsi_qla_host *ha,
  643. uint16_t *chap_index)
  644. {
  645. int i, rval;
  646. int free_index = -1;
  647. int max_chap_entries = 0;
  648. struct ql4_chap_table *chap_table;
  649. if (is_qla80XX(ha))
  650. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  651. sizeof(struct ql4_chap_table);
  652. else
  653. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  654. if (!ha->chap_list) {
  655. ql4_printk(KERN_ERR, ha, "CHAP table cache is empty!\n");
  656. rval = QLA_ERROR;
  657. goto exit_find_chap;
  658. }
  659. for (i = 0; i < max_chap_entries; i++) {
  660. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  661. if ((chap_table->cookie !=
  662. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) &&
  663. (i > MAX_RESRV_CHAP_IDX)) {
  664. free_index = i;
  665. break;
  666. }
  667. }
  668. if (free_index != -1) {
  669. *chap_index = free_index;
  670. rval = QLA_SUCCESS;
  671. } else {
  672. rval = QLA_ERROR;
  673. }
  674. exit_find_chap:
  675. return rval;
  676. }
  677. static int qla4xxx_get_chap_list(struct Scsi_Host *shost, uint16_t chap_tbl_idx,
  678. uint32_t *num_entries, char *buf)
  679. {
  680. struct scsi_qla_host *ha = to_qla_host(shost);
  681. struct ql4_chap_table *chap_table;
  682. struct iscsi_chap_rec *chap_rec;
  683. int max_chap_entries = 0;
  684. int valid_chap_entries = 0;
  685. int ret = 0, i;
  686. if (is_qla80XX(ha))
  687. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  688. sizeof(struct ql4_chap_table);
  689. else
  690. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  691. ql4_printk(KERN_INFO, ha, "%s: num_entries = %d, CHAP idx = %d\n",
  692. __func__, *num_entries, chap_tbl_idx);
  693. if (!buf) {
  694. ret = -ENOMEM;
  695. goto exit_get_chap_list;
  696. }
  697. qla4xxx_create_chap_list(ha);
  698. chap_rec = (struct iscsi_chap_rec *) buf;
  699. mutex_lock(&ha->chap_sem);
  700. for (i = chap_tbl_idx; i < max_chap_entries; i++) {
  701. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  702. if (chap_table->cookie !=
  703. __constant_cpu_to_le16(CHAP_VALID_COOKIE))
  704. continue;
  705. chap_rec->chap_tbl_idx = i;
  706. strlcpy(chap_rec->username, chap_table->name,
  707. ISCSI_CHAP_AUTH_NAME_MAX_LEN);
  708. strlcpy(chap_rec->password, chap_table->secret,
  709. QL4_CHAP_MAX_SECRET_LEN);
  710. chap_rec->password_length = chap_table->secret_len;
  711. if (chap_table->flags & BIT_7) /* local */
  712. chap_rec->chap_type = CHAP_TYPE_OUT;
  713. if (chap_table->flags & BIT_6) /* peer */
  714. chap_rec->chap_type = CHAP_TYPE_IN;
  715. chap_rec++;
  716. valid_chap_entries++;
  717. if (valid_chap_entries == *num_entries)
  718. break;
  719. else
  720. continue;
  721. }
  722. mutex_unlock(&ha->chap_sem);
  723. exit_get_chap_list:
  724. ql4_printk(KERN_INFO, ha, "%s: Valid CHAP Entries = %d\n",
  725. __func__, valid_chap_entries);
  726. *num_entries = valid_chap_entries;
  727. return ret;
  728. }
  729. static int __qla4xxx_is_chap_active(struct device *dev, void *data)
  730. {
  731. int ret = 0;
  732. uint16_t *chap_tbl_idx = (uint16_t *) data;
  733. struct iscsi_cls_session *cls_session;
  734. struct iscsi_session *sess;
  735. struct ddb_entry *ddb_entry;
  736. if (!iscsi_is_session_dev(dev))
  737. goto exit_is_chap_active;
  738. cls_session = iscsi_dev_to_session(dev);
  739. sess = cls_session->dd_data;
  740. ddb_entry = sess->dd_data;
  741. if (iscsi_session_chkready(cls_session))
  742. goto exit_is_chap_active;
  743. if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
  744. ret = 1;
  745. exit_is_chap_active:
  746. return ret;
  747. }
  748. static int qla4xxx_is_chap_active(struct Scsi_Host *shost,
  749. uint16_t chap_tbl_idx)
  750. {
  751. int ret = 0;
  752. ret = device_for_each_child(&shost->shost_gendev, &chap_tbl_idx,
  753. __qla4xxx_is_chap_active);
  754. return ret;
  755. }
  756. static int qla4xxx_delete_chap(struct Scsi_Host *shost, uint16_t chap_tbl_idx)
  757. {
  758. struct scsi_qla_host *ha = to_qla_host(shost);
  759. struct ql4_chap_table *chap_table;
  760. dma_addr_t chap_dma;
  761. int max_chap_entries = 0;
  762. uint32_t offset = 0;
  763. uint32_t chap_size;
  764. int ret = 0;
  765. chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
  766. if (chap_table == NULL)
  767. return -ENOMEM;
  768. memset(chap_table, 0, sizeof(struct ql4_chap_table));
  769. if (is_qla80XX(ha))
  770. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  771. sizeof(struct ql4_chap_table);
  772. else
  773. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  774. if (chap_tbl_idx > max_chap_entries) {
  775. ret = -EINVAL;
  776. goto exit_delete_chap;
  777. }
  778. /* Check if chap index is in use.
  779. * If chap is in use don't delet chap entry */
  780. ret = qla4xxx_is_chap_active(shost, chap_tbl_idx);
  781. if (ret) {
  782. ql4_printk(KERN_INFO, ha, "CHAP entry %d is in use, cannot "
  783. "delete from flash\n", chap_tbl_idx);
  784. ret = -EBUSY;
  785. goto exit_delete_chap;
  786. }
  787. chap_size = sizeof(struct ql4_chap_table);
  788. if (is_qla40XX(ha))
  789. offset = FLASH_CHAP_OFFSET | (chap_tbl_idx * chap_size);
  790. else {
  791. offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
  792. /* flt_chap_size is CHAP table size for both ports
  793. * so divide it by 2 to calculate the offset for second port
  794. */
  795. if (ha->port_num == 1)
  796. offset += (ha->hw.flt_chap_size / 2);
  797. offset += (chap_tbl_idx * chap_size);
  798. }
  799. ret = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
  800. if (ret != QLA_SUCCESS) {
  801. ret = -EINVAL;
  802. goto exit_delete_chap;
  803. }
  804. DEBUG2(ql4_printk(KERN_INFO, ha, "Chap Cookie: x%x\n",
  805. __le16_to_cpu(chap_table->cookie)));
  806. if (__le16_to_cpu(chap_table->cookie) != CHAP_VALID_COOKIE) {
  807. ql4_printk(KERN_ERR, ha, "No valid chap entry found\n");
  808. goto exit_delete_chap;
  809. }
  810. chap_table->cookie = __constant_cpu_to_le16(0xFFFF);
  811. offset = FLASH_CHAP_OFFSET |
  812. (chap_tbl_idx * sizeof(struct ql4_chap_table));
  813. ret = qla4xxx_set_flash(ha, chap_dma, offset, chap_size,
  814. FLASH_OPT_RMW_COMMIT);
  815. if (ret == QLA_SUCCESS && ha->chap_list) {
  816. mutex_lock(&ha->chap_sem);
  817. /* Update ha chap_list cache */
  818. memcpy((struct ql4_chap_table *)ha->chap_list + chap_tbl_idx,
  819. chap_table, sizeof(struct ql4_chap_table));
  820. mutex_unlock(&ha->chap_sem);
  821. }
  822. if (ret != QLA_SUCCESS)
  823. ret = -EINVAL;
  824. exit_delete_chap:
  825. dma_pool_free(ha->chap_dma_pool, chap_table, chap_dma);
  826. return ret;
  827. }
  828. /**
  829. * qla4xxx_set_chap_entry - Make chap entry with given information
  830. * @shost: pointer to host
  831. * @data: chap info - credentials, index and type to make chap entry
  832. * @len: length of data
  833. *
  834. * Add or update chap entry with the given information
  835. **/
  836. static int qla4xxx_set_chap_entry(struct Scsi_Host *shost, void *data, int len)
  837. {
  838. struct scsi_qla_host *ha = to_qla_host(shost);
  839. struct iscsi_chap_rec chap_rec;
  840. struct ql4_chap_table *chap_entry = NULL;
  841. struct iscsi_param_info *param_info;
  842. struct nlattr *attr;
  843. int max_chap_entries = 0;
  844. int type;
  845. int rem = len;
  846. int rc = 0;
  847. int size;
  848. memset(&chap_rec, 0, sizeof(chap_rec));
  849. nla_for_each_attr(attr, data, len, rem) {
  850. param_info = nla_data(attr);
  851. switch (param_info->param) {
  852. case ISCSI_CHAP_PARAM_INDEX:
  853. chap_rec.chap_tbl_idx = *(uint16_t *)param_info->value;
  854. break;
  855. case ISCSI_CHAP_PARAM_CHAP_TYPE:
  856. chap_rec.chap_type = param_info->value[0];
  857. break;
  858. case ISCSI_CHAP_PARAM_USERNAME:
  859. size = min_t(size_t, sizeof(chap_rec.username),
  860. param_info->len);
  861. memcpy(chap_rec.username, param_info->value, size);
  862. break;
  863. case ISCSI_CHAP_PARAM_PASSWORD:
  864. size = min_t(size_t, sizeof(chap_rec.password),
  865. param_info->len);
  866. memcpy(chap_rec.password, param_info->value, size);
  867. break;
  868. case ISCSI_CHAP_PARAM_PASSWORD_LEN:
  869. chap_rec.password_length = param_info->value[0];
  870. break;
  871. default:
  872. ql4_printk(KERN_ERR, ha,
  873. "%s: No such sysfs attribute\n", __func__);
  874. rc = -ENOSYS;
  875. goto exit_set_chap;
  876. };
  877. }
  878. if (chap_rec.chap_type == CHAP_TYPE_IN)
  879. type = BIDI_CHAP;
  880. else
  881. type = LOCAL_CHAP;
  882. if (is_qla80XX(ha))
  883. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  884. sizeof(struct ql4_chap_table);
  885. else
  886. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  887. mutex_lock(&ha->chap_sem);
  888. if (chap_rec.chap_tbl_idx < max_chap_entries) {
  889. rc = qla4xxx_get_chap_by_index(ha, chap_rec.chap_tbl_idx,
  890. &chap_entry);
  891. if (!rc) {
  892. if (!(type == qla4xxx_get_chap_type(chap_entry))) {
  893. ql4_printk(KERN_INFO, ha,
  894. "Type mismatch for CHAP entry %d\n",
  895. chap_rec.chap_tbl_idx);
  896. rc = -EINVAL;
  897. goto exit_unlock_chap;
  898. }
  899. /* If chap index is in use then don't modify it */
  900. rc = qla4xxx_is_chap_active(shost,
  901. chap_rec.chap_tbl_idx);
  902. if (rc) {
  903. ql4_printk(KERN_INFO, ha,
  904. "CHAP entry %d is in use\n",
  905. chap_rec.chap_tbl_idx);
  906. rc = -EBUSY;
  907. goto exit_unlock_chap;
  908. }
  909. }
  910. } else {
  911. rc = qla4xxx_find_free_chap_index(ha, &chap_rec.chap_tbl_idx);
  912. if (rc) {
  913. ql4_printk(KERN_INFO, ha, "CHAP entry not available\n");
  914. rc = -EBUSY;
  915. goto exit_unlock_chap;
  916. }
  917. }
  918. rc = qla4xxx_set_chap(ha, chap_rec.username, chap_rec.password,
  919. chap_rec.chap_tbl_idx, type);
  920. exit_unlock_chap:
  921. mutex_unlock(&ha->chap_sem);
  922. exit_set_chap:
  923. return rc;
  924. }
  925. static int qla4xxx_get_host_stats(struct Scsi_Host *shost, char *buf, int len)
  926. {
  927. struct scsi_qla_host *ha = to_qla_host(shost);
  928. struct iscsi_offload_host_stats *host_stats = NULL;
  929. int host_stats_size;
  930. int ret = 0;
  931. int ddb_idx = 0;
  932. struct ql_iscsi_stats *ql_iscsi_stats = NULL;
  933. int stats_size;
  934. dma_addr_t iscsi_stats_dma;
  935. DEBUG2(ql4_printk(KERN_INFO, ha, "Func: %s\n", __func__));
  936. host_stats_size = sizeof(struct iscsi_offload_host_stats);
  937. if (host_stats_size != len) {
  938. ql4_printk(KERN_INFO, ha, "%s: host_stats size mismatch expected = %d, is = %d\n",
  939. __func__, len, host_stats_size);
  940. ret = -EINVAL;
  941. goto exit_host_stats;
  942. }
  943. host_stats = (struct iscsi_offload_host_stats *)buf;
  944. if (!buf) {
  945. ret = -ENOMEM;
  946. goto exit_host_stats;
  947. }
  948. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  949. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  950. &iscsi_stats_dma, GFP_KERNEL);
  951. if (!ql_iscsi_stats) {
  952. ql4_printk(KERN_ERR, ha,
  953. "Unable to allocate memory for iscsi stats\n");
  954. ret = -ENOMEM;
  955. goto exit_host_stats;
  956. }
  957. ret = qla4xxx_get_mgmt_data(ha, ddb_idx, stats_size,
  958. iscsi_stats_dma);
  959. if (ret != QLA_SUCCESS) {
  960. ql4_printk(KERN_ERR, ha,
  961. "Unable to retrieve iscsi stats\n");
  962. ret = -EIO;
  963. goto exit_host_stats;
  964. }
  965. host_stats->mactx_frames = le64_to_cpu(ql_iscsi_stats->mac_tx_frames);
  966. host_stats->mactx_bytes = le64_to_cpu(ql_iscsi_stats->mac_tx_bytes);
  967. host_stats->mactx_multicast_frames =
  968. le64_to_cpu(ql_iscsi_stats->mac_tx_multicast_frames);
  969. host_stats->mactx_broadcast_frames =
  970. le64_to_cpu(ql_iscsi_stats->mac_tx_broadcast_frames);
  971. host_stats->mactx_pause_frames =
  972. le64_to_cpu(ql_iscsi_stats->mac_tx_pause_frames);
  973. host_stats->mactx_control_frames =
  974. le64_to_cpu(ql_iscsi_stats->mac_tx_control_frames);
  975. host_stats->mactx_deferral =
  976. le64_to_cpu(ql_iscsi_stats->mac_tx_deferral);
  977. host_stats->mactx_excess_deferral =
  978. le64_to_cpu(ql_iscsi_stats->mac_tx_excess_deferral);
  979. host_stats->mactx_late_collision =
  980. le64_to_cpu(ql_iscsi_stats->mac_tx_late_collision);
  981. host_stats->mactx_abort = le64_to_cpu(ql_iscsi_stats->mac_tx_abort);
  982. host_stats->mactx_single_collision =
  983. le64_to_cpu(ql_iscsi_stats->mac_tx_single_collision);
  984. host_stats->mactx_multiple_collision =
  985. le64_to_cpu(ql_iscsi_stats->mac_tx_multiple_collision);
  986. host_stats->mactx_collision =
  987. le64_to_cpu(ql_iscsi_stats->mac_tx_collision);
  988. host_stats->mactx_frames_dropped =
  989. le64_to_cpu(ql_iscsi_stats->mac_tx_frames_dropped);
  990. host_stats->mactx_jumbo_frames =
  991. le64_to_cpu(ql_iscsi_stats->mac_tx_jumbo_frames);
  992. host_stats->macrx_frames = le64_to_cpu(ql_iscsi_stats->mac_rx_frames);
  993. host_stats->macrx_bytes = le64_to_cpu(ql_iscsi_stats->mac_rx_bytes);
  994. host_stats->macrx_unknown_control_frames =
  995. le64_to_cpu(ql_iscsi_stats->mac_rx_unknown_control_frames);
  996. host_stats->macrx_pause_frames =
  997. le64_to_cpu(ql_iscsi_stats->mac_rx_pause_frames);
  998. host_stats->macrx_control_frames =
  999. le64_to_cpu(ql_iscsi_stats->mac_rx_control_frames);
  1000. host_stats->macrx_dribble =
  1001. le64_to_cpu(ql_iscsi_stats->mac_rx_dribble);
  1002. host_stats->macrx_frame_length_error =
  1003. le64_to_cpu(ql_iscsi_stats->mac_rx_frame_length_error);
  1004. host_stats->macrx_jabber = le64_to_cpu(ql_iscsi_stats->mac_rx_jabber);
  1005. host_stats->macrx_carrier_sense_error =
  1006. le64_to_cpu(ql_iscsi_stats->mac_rx_carrier_sense_error);
  1007. host_stats->macrx_frame_discarded =
  1008. le64_to_cpu(ql_iscsi_stats->mac_rx_frame_discarded);
  1009. host_stats->macrx_frames_dropped =
  1010. le64_to_cpu(ql_iscsi_stats->mac_rx_frames_dropped);
  1011. host_stats->mac_crc_error = le64_to_cpu(ql_iscsi_stats->mac_crc_error);
  1012. host_stats->mac_encoding_error =
  1013. le64_to_cpu(ql_iscsi_stats->mac_encoding_error);
  1014. host_stats->macrx_length_error_large =
  1015. le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_large);
  1016. host_stats->macrx_length_error_small =
  1017. le64_to_cpu(ql_iscsi_stats->mac_rx_length_error_small);
  1018. host_stats->macrx_multicast_frames =
  1019. le64_to_cpu(ql_iscsi_stats->mac_rx_multicast_frames);
  1020. host_stats->macrx_broadcast_frames =
  1021. le64_to_cpu(ql_iscsi_stats->mac_rx_broadcast_frames);
  1022. host_stats->iptx_packets = le64_to_cpu(ql_iscsi_stats->ip_tx_packets);
  1023. host_stats->iptx_bytes = le64_to_cpu(ql_iscsi_stats->ip_tx_bytes);
  1024. host_stats->iptx_fragments =
  1025. le64_to_cpu(ql_iscsi_stats->ip_tx_fragments);
  1026. host_stats->iprx_packets = le64_to_cpu(ql_iscsi_stats->ip_rx_packets);
  1027. host_stats->iprx_bytes = le64_to_cpu(ql_iscsi_stats->ip_rx_bytes);
  1028. host_stats->iprx_fragments =
  1029. le64_to_cpu(ql_iscsi_stats->ip_rx_fragments);
  1030. host_stats->ip_datagram_reassembly =
  1031. le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly);
  1032. host_stats->ip_invalid_address_error =
  1033. le64_to_cpu(ql_iscsi_stats->ip_invalid_address_error);
  1034. host_stats->ip_error_packets =
  1035. le64_to_cpu(ql_iscsi_stats->ip_error_packets);
  1036. host_stats->ip_fragrx_overlap =
  1037. le64_to_cpu(ql_iscsi_stats->ip_fragrx_overlap);
  1038. host_stats->ip_fragrx_outoforder =
  1039. le64_to_cpu(ql_iscsi_stats->ip_fragrx_outoforder);
  1040. host_stats->ip_datagram_reassembly_timeout =
  1041. le64_to_cpu(ql_iscsi_stats->ip_datagram_reassembly_timeout);
  1042. host_stats->ipv6tx_packets =
  1043. le64_to_cpu(ql_iscsi_stats->ipv6_tx_packets);
  1044. host_stats->ipv6tx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_tx_bytes);
  1045. host_stats->ipv6tx_fragments =
  1046. le64_to_cpu(ql_iscsi_stats->ipv6_tx_fragments);
  1047. host_stats->ipv6rx_packets =
  1048. le64_to_cpu(ql_iscsi_stats->ipv6_rx_packets);
  1049. host_stats->ipv6rx_bytes = le64_to_cpu(ql_iscsi_stats->ipv6_rx_bytes);
  1050. host_stats->ipv6rx_fragments =
  1051. le64_to_cpu(ql_iscsi_stats->ipv6_rx_fragments);
  1052. host_stats->ipv6_datagram_reassembly =
  1053. le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly);
  1054. host_stats->ipv6_invalid_address_error =
  1055. le64_to_cpu(ql_iscsi_stats->ipv6_invalid_address_error);
  1056. host_stats->ipv6_error_packets =
  1057. le64_to_cpu(ql_iscsi_stats->ipv6_error_packets);
  1058. host_stats->ipv6_fragrx_overlap =
  1059. le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_overlap);
  1060. host_stats->ipv6_fragrx_outoforder =
  1061. le64_to_cpu(ql_iscsi_stats->ipv6_fragrx_outoforder);
  1062. host_stats->ipv6_datagram_reassembly_timeout =
  1063. le64_to_cpu(ql_iscsi_stats->ipv6_datagram_reassembly_timeout);
  1064. host_stats->tcptx_segments =
  1065. le64_to_cpu(ql_iscsi_stats->tcp_tx_segments);
  1066. host_stats->tcptx_bytes = le64_to_cpu(ql_iscsi_stats->tcp_tx_bytes);
  1067. host_stats->tcprx_segments =
  1068. le64_to_cpu(ql_iscsi_stats->tcp_rx_segments);
  1069. host_stats->tcprx_byte = le64_to_cpu(ql_iscsi_stats->tcp_rx_byte);
  1070. host_stats->tcp_duplicate_ack_retx =
  1071. le64_to_cpu(ql_iscsi_stats->tcp_duplicate_ack_retx);
  1072. host_stats->tcp_retx_timer_expired =
  1073. le64_to_cpu(ql_iscsi_stats->tcp_retx_timer_expired);
  1074. host_stats->tcprx_duplicate_ack =
  1075. le64_to_cpu(ql_iscsi_stats->tcp_rx_duplicate_ack);
  1076. host_stats->tcprx_pure_ackr =
  1077. le64_to_cpu(ql_iscsi_stats->tcp_rx_pure_ackr);
  1078. host_stats->tcptx_delayed_ack =
  1079. le64_to_cpu(ql_iscsi_stats->tcp_tx_delayed_ack);
  1080. host_stats->tcptx_pure_ack =
  1081. le64_to_cpu(ql_iscsi_stats->tcp_tx_pure_ack);
  1082. host_stats->tcprx_segment_error =
  1083. le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_error);
  1084. host_stats->tcprx_segment_outoforder =
  1085. le64_to_cpu(ql_iscsi_stats->tcp_rx_segment_outoforder);
  1086. host_stats->tcprx_window_probe =
  1087. le64_to_cpu(ql_iscsi_stats->tcp_rx_window_probe);
  1088. host_stats->tcprx_window_update =
  1089. le64_to_cpu(ql_iscsi_stats->tcp_rx_window_update);
  1090. host_stats->tcptx_window_probe_persist =
  1091. le64_to_cpu(ql_iscsi_stats->tcp_tx_window_probe_persist);
  1092. host_stats->ecc_error_correction =
  1093. le64_to_cpu(ql_iscsi_stats->ecc_error_correction);
  1094. host_stats->iscsi_pdu_tx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_tx);
  1095. host_stats->iscsi_data_bytes_tx =
  1096. le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_tx);
  1097. host_stats->iscsi_pdu_rx = le64_to_cpu(ql_iscsi_stats->iscsi_pdu_rx);
  1098. host_stats->iscsi_data_bytes_rx =
  1099. le64_to_cpu(ql_iscsi_stats->iscsi_data_bytes_rx);
  1100. host_stats->iscsi_io_completed =
  1101. le64_to_cpu(ql_iscsi_stats->iscsi_io_completed);
  1102. host_stats->iscsi_unexpected_io_rx =
  1103. le64_to_cpu(ql_iscsi_stats->iscsi_unexpected_io_rx);
  1104. host_stats->iscsi_format_error =
  1105. le64_to_cpu(ql_iscsi_stats->iscsi_format_error);
  1106. host_stats->iscsi_hdr_digest_error =
  1107. le64_to_cpu(ql_iscsi_stats->iscsi_hdr_digest_error);
  1108. host_stats->iscsi_data_digest_error =
  1109. le64_to_cpu(ql_iscsi_stats->iscsi_data_digest_error);
  1110. host_stats->iscsi_sequence_error =
  1111. le64_to_cpu(ql_iscsi_stats->iscsi_sequence_error);
  1112. exit_host_stats:
  1113. if (ql_iscsi_stats)
  1114. dma_free_coherent(&ha->pdev->dev, host_stats_size,
  1115. ql_iscsi_stats, iscsi_stats_dma);
  1116. ql4_printk(KERN_INFO, ha, "%s: Get host stats done\n",
  1117. __func__);
  1118. return ret;
  1119. }
  1120. static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
  1121. enum iscsi_param_type param_type,
  1122. int param, char *buf)
  1123. {
  1124. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  1125. struct scsi_qla_host *ha = to_qla_host(shost);
  1126. int ival;
  1127. char *pval = NULL;
  1128. int len = -ENOSYS;
  1129. if (param_type == ISCSI_NET_PARAM) {
  1130. switch (param) {
  1131. case ISCSI_NET_PARAM_IPV4_ADDR:
  1132. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  1133. break;
  1134. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1135. len = sprintf(buf, "%pI4\n",
  1136. &ha->ip_config.subnet_mask);
  1137. break;
  1138. case ISCSI_NET_PARAM_IPV4_GW:
  1139. len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
  1140. break;
  1141. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1142. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1143. OP_STATE(ha->ip_config.ipv4_options,
  1144. IPOPT_IPV4_PROTOCOL_ENABLE, pval);
  1145. } else {
  1146. OP_STATE(ha->ip_config.ipv6_options,
  1147. IPV6_OPT_IPV6_PROTOCOL_ENABLE, pval);
  1148. }
  1149. len = sprintf(buf, "%s\n", pval);
  1150. break;
  1151. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1152. len = sprintf(buf, "%s\n",
  1153. (ha->ip_config.tcp_options &
  1154. TCPOPT_DHCP_ENABLE) ?
  1155. "dhcp" : "static");
  1156. break;
  1157. case ISCSI_NET_PARAM_IPV6_ADDR:
  1158. if (iface->iface_num == 0)
  1159. len = sprintf(buf, "%pI6\n",
  1160. &ha->ip_config.ipv6_addr0);
  1161. if (iface->iface_num == 1)
  1162. len = sprintf(buf, "%pI6\n",
  1163. &ha->ip_config.ipv6_addr1);
  1164. break;
  1165. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  1166. len = sprintf(buf, "%pI6\n",
  1167. &ha->ip_config.ipv6_link_local_addr);
  1168. break;
  1169. case ISCSI_NET_PARAM_IPV6_ROUTER:
  1170. len = sprintf(buf, "%pI6\n",
  1171. &ha->ip_config.ipv6_default_router_addr);
  1172. break;
  1173. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  1174. pval = (ha->ip_config.ipv6_addl_options &
  1175. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
  1176. "nd" : "static";
  1177. len = sprintf(buf, "%s\n", pval);
  1178. break;
  1179. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  1180. pval = (ha->ip_config.ipv6_addl_options &
  1181. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
  1182. "auto" : "static";
  1183. len = sprintf(buf, "%s\n", pval);
  1184. break;
  1185. case ISCSI_NET_PARAM_VLAN_ID:
  1186. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1187. ival = ha->ip_config.ipv4_vlan_tag &
  1188. ISCSI_MAX_VLAN_ID;
  1189. else
  1190. ival = ha->ip_config.ipv6_vlan_tag &
  1191. ISCSI_MAX_VLAN_ID;
  1192. len = sprintf(buf, "%d\n", ival);
  1193. break;
  1194. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  1195. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1196. ival = (ha->ip_config.ipv4_vlan_tag >> 13) &
  1197. ISCSI_MAX_VLAN_PRIORITY;
  1198. else
  1199. ival = (ha->ip_config.ipv6_vlan_tag >> 13) &
  1200. ISCSI_MAX_VLAN_PRIORITY;
  1201. len = sprintf(buf, "%d\n", ival);
  1202. break;
  1203. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1204. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1205. OP_STATE(ha->ip_config.ipv4_options,
  1206. IPOPT_VLAN_TAGGING_ENABLE, pval);
  1207. } else {
  1208. OP_STATE(ha->ip_config.ipv6_options,
  1209. IPV6_OPT_VLAN_TAGGING_ENABLE, pval);
  1210. }
  1211. len = sprintf(buf, "%s\n", pval);
  1212. break;
  1213. case ISCSI_NET_PARAM_MTU:
  1214. len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
  1215. break;
  1216. case ISCSI_NET_PARAM_PORT:
  1217. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1218. len = sprintf(buf, "%d\n",
  1219. ha->ip_config.ipv4_port);
  1220. else
  1221. len = sprintf(buf, "%d\n",
  1222. ha->ip_config.ipv6_port);
  1223. break;
  1224. case ISCSI_NET_PARAM_IPADDR_STATE:
  1225. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1226. pval = iscsi_get_ipaddress_state_name(
  1227. ha->ip_config.ipv4_addr_state);
  1228. } else {
  1229. if (iface->iface_num == 0)
  1230. pval = iscsi_get_ipaddress_state_name(
  1231. ha->ip_config.ipv6_addr0_state);
  1232. else if (iface->iface_num == 1)
  1233. pval = iscsi_get_ipaddress_state_name(
  1234. ha->ip_config.ipv6_addr1_state);
  1235. }
  1236. len = sprintf(buf, "%s\n", pval);
  1237. break;
  1238. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_STATE:
  1239. pval = iscsi_get_ipaddress_state_name(
  1240. ha->ip_config.ipv6_link_local_state);
  1241. len = sprintf(buf, "%s\n", pval);
  1242. break;
  1243. case ISCSI_NET_PARAM_IPV6_ROUTER_STATE:
  1244. pval = iscsi_get_router_state_name(
  1245. ha->ip_config.ipv6_default_router_state);
  1246. len = sprintf(buf, "%s\n", pval);
  1247. break;
  1248. case ISCSI_NET_PARAM_DELAYED_ACK_EN:
  1249. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1250. OP_STATE(~ha->ip_config.tcp_options,
  1251. TCPOPT_DELAYED_ACK_DISABLE, pval);
  1252. } else {
  1253. OP_STATE(~ha->ip_config.ipv6_tcp_options,
  1254. IPV6_TCPOPT_DELAYED_ACK_DISABLE, pval);
  1255. }
  1256. len = sprintf(buf, "%s\n", pval);
  1257. break;
  1258. case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
  1259. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1260. OP_STATE(~ha->ip_config.tcp_options,
  1261. TCPOPT_NAGLE_ALGO_DISABLE, pval);
  1262. } else {
  1263. OP_STATE(~ha->ip_config.ipv6_tcp_options,
  1264. IPV6_TCPOPT_NAGLE_ALGO_DISABLE, pval);
  1265. }
  1266. len = sprintf(buf, "%s\n", pval);
  1267. break;
  1268. case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
  1269. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1270. OP_STATE(~ha->ip_config.tcp_options,
  1271. TCPOPT_WINDOW_SCALE_DISABLE, pval);
  1272. } else {
  1273. OP_STATE(~ha->ip_config.ipv6_tcp_options,
  1274. IPV6_TCPOPT_WINDOW_SCALE_DISABLE,
  1275. pval);
  1276. }
  1277. len = sprintf(buf, "%s\n", pval);
  1278. break;
  1279. case ISCSI_NET_PARAM_TCP_WSF:
  1280. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1281. len = sprintf(buf, "%d\n",
  1282. ha->ip_config.tcp_wsf);
  1283. else
  1284. len = sprintf(buf, "%d\n",
  1285. ha->ip_config.ipv6_tcp_wsf);
  1286. break;
  1287. case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
  1288. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1289. ival = (ha->ip_config.tcp_options &
  1290. TCPOPT_TIMER_SCALE) >> 1;
  1291. else
  1292. ival = (ha->ip_config.ipv6_tcp_options &
  1293. IPV6_TCPOPT_TIMER_SCALE) >> 1;
  1294. len = sprintf(buf, "%d\n", ival);
  1295. break;
  1296. case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
  1297. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1298. OP_STATE(ha->ip_config.tcp_options,
  1299. TCPOPT_TIMESTAMP_ENABLE, pval);
  1300. } else {
  1301. OP_STATE(ha->ip_config.ipv6_tcp_options,
  1302. IPV6_TCPOPT_TIMESTAMP_EN, pval);
  1303. }
  1304. len = sprintf(buf, "%s\n", pval);
  1305. break;
  1306. case ISCSI_NET_PARAM_CACHE_ID:
  1307. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  1308. len = sprintf(buf, "%d\n",
  1309. ha->ip_config.ipv4_cache_id);
  1310. else
  1311. len = sprintf(buf, "%d\n",
  1312. ha->ip_config.ipv6_cache_id);
  1313. break;
  1314. case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
  1315. OP_STATE(ha->ip_config.tcp_options,
  1316. TCPOPT_DNS_SERVER_IP_EN, pval);
  1317. len = sprintf(buf, "%s\n", pval);
  1318. break;
  1319. case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
  1320. OP_STATE(ha->ip_config.tcp_options,
  1321. TCPOPT_SLP_DA_INFO_EN, pval);
  1322. len = sprintf(buf, "%s\n", pval);
  1323. break;
  1324. case ISCSI_NET_PARAM_IPV4_TOS_EN:
  1325. OP_STATE(ha->ip_config.ipv4_options,
  1326. IPOPT_IPV4_TOS_EN, pval);
  1327. len = sprintf(buf, "%s\n", pval);
  1328. break;
  1329. case ISCSI_NET_PARAM_IPV4_TOS:
  1330. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_tos);
  1331. break;
  1332. case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
  1333. OP_STATE(ha->ip_config.ipv4_options,
  1334. IPOPT_GRAT_ARP_EN, pval);
  1335. len = sprintf(buf, "%s\n", pval);
  1336. break;
  1337. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
  1338. OP_STATE(ha->ip_config.ipv4_options, IPOPT_ALT_CID_EN,
  1339. pval);
  1340. len = sprintf(buf, "%s\n", pval);
  1341. break;
  1342. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
  1343. pval = (ha->ip_config.ipv4_alt_cid_len) ?
  1344. (char *)ha->ip_config.ipv4_alt_cid : "";
  1345. len = sprintf(buf, "%s\n", pval);
  1346. break;
  1347. case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
  1348. OP_STATE(ha->ip_config.ipv4_options,
  1349. IPOPT_REQ_VID_EN, pval);
  1350. len = sprintf(buf, "%s\n", pval);
  1351. break;
  1352. case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
  1353. OP_STATE(ha->ip_config.ipv4_options,
  1354. IPOPT_USE_VID_EN, pval);
  1355. len = sprintf(buf, "%s\n", pval);
  1356. break;
  1357. case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
  1358. pval = (ha->ip_config.ipv4_vid_len) ?
  1359. (char *)ha->ip_config.ipv4_vid : "";
  1360. len = sprintf(buf, "%s\n", pval);
  1361. break;
  1362. case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
  1363. OP_STATE(ha->ip_config.ipv4_options,
  1364. IPOPT_LEARN_IQN_EN, pval);
  1365. len = sprintf(buf, "%s\n", pval);
  1366. break;
  1367. case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
  1368. OP_STATE(~ha->ip_config.ipv4_options,
  1369. IPOPT_FRAGMENTATION_DISABLE, pval);
  1370. len = sprintf(buf, "%s\n", pval);
  1371. break;
  1372. case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
  1373. OP_STATE(ha->ip_config.ipv4_options,
  1374. IPOPT_IN_FORWARD_EN, pval);
  1375. len = sprintf(buf, "%s\n", pval);
  1376. break;
  1377. case ISCSI_NET_PARAM_REDIRECT_EN:
  1378. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) {
  1379. OP_STATE(ha->ip_config.ipv4_options,
  1380. IPOPT_ARP_REDIRECT_EN, pval);
  1381. } else {
  1382. OP_STATE(ha->ip_config.ipv6_options,
  1383. IPV6_OPT_REDIRECT_EN, pval);
  1384. }
  1385. len = sprintf(buf, "%s\n", pval);
  1386. break;
  1387. case ISCSI_NET_PARAM_IPV4_TTL:
  1388. len = sprintf(buf, "%d\n", ha->ip_config.ipv4_ttl);
  1389. break;
  1390. case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
  1391. OP_STATE(ha->ip_config.ipv6_options,
  1392. IPV6_OPT_GRAT_NEIGHBOR_ADV_EN, pval);
  1393. len = sprintf(buf, "%s\n", pval);
  1394. break;
  1395. case ISCSI_NET_PARAM_IPV6_MLD_EN:
  1396. OP_STATE(ha->ip_config.ipv6_addl_options,
  1397. IPV6_ADDOPT_MLD_EN, pval);
  1398. len = sprintf(buf, "%s\n", pval);
  1399. break;
  1400. case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
  1401. len = sprintf(buf, "%u\n", ha->ip_config.ipv6_flow_lbl);
  1402. break;
  1403. case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
  1404. len = sprintf(buf, "%d\n",
  1405. ha->ip_config.ipv6_traffic_class);
  1406. break;
  1407. case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
  1408. len = sprintf(buf, "%d\n",
  1409. ha->ip_config.ipv6_hop_limit);
  1410. break;
  1411. case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
  1412. len = sprintf(buf, "%d\n",
  1413. ha->ip_config.ipv6_nd_reach_time);
  1414. break;
  1415. case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
  1416. len = sprintf(buf, "%d\n",
  1417. ha->ip_config.ipv6_nd_rexmit_timer);
  1418. break;
  1419. case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
  1420. len = sprintf(buf, "%d\n",
  1421. ha->ip_config.ipv6_nd_stale_timeout);
  1422. break;
  1423. case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
  1424. len = sprintf(buf, "%d\n",
  1425. ha->ip_config.ipv6_dup_addr_detect_count);
  1426. break;
  1427. case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
  1428. len = sprintf(buf, "%d\n",
  1429. ha->ip_config.ipv6_gw_advrt_mtu);
  1430. break;
  1431. default:
  1432. len = -ENOSYS;
  1433. }
  1434. } else if (param_type == ISCSI_IFACE_PARAM) {
  1435. switch (param) {
  1436. case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
  1437. len = sprintf(buf, "%d\n", ha->ip_config.def_timeout);
  1438. break;
  1439. case ISCSI_IFACE_PARAM_HDRDGST_EN:
  1440. OP_STATE(ha->ip_config.iscsi_options,
  1441. ISCSIOPTS_HEADER_DIGEST_EN, pval);
  1442. len = sprintf(buf, "%s\n", pval);
  1443. break;
  1444. case ISCSI_IFACE_PARAM_DATADGST_EN:
  1445. OP_STATE(ha->ip_config.iscsi_options,
  1446. ISCSIOPTS_DATA_DIGEST_EN, pval);
  1447. len = sprintf(buf, "%s\n", pval);
  1448. break;
  1449. case ISCSI_IFACE_PARAM_IMM_DATA_EN:
  1450. OP_STATE(ha->ip_config.iscsi_options,
  1451. ISCSIOPTS_IMMEDIATE_DATA_EN, pval);
  1452. len = sprintf(buf, "%s\n", pval);
  1453. break;
  1454. case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
  1455. OP_STATE(ha->ip_config.iscsi_options,
  1456. ISCSIOPTS_INITIAL_R2T_EN, pval);
  1457. len = sprintf(buf, "%s\n", pval);
  1458. break;
  1459. case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
  1460. OP_STATE(ha->ip_config.iscsi_options,
  1461. ISCSIOPTS_DATA_SEQ_INORDER_EN, pval);
  1462. len = sprintf(buf, "%s\n", pval);
  1463. break;
  1464. case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
  1465. OP_STATE(ha->ip_config.iscsi_options,
  1466. ISCSIOPTS_DATA_PDU_INORDER_EN, pval);
  1467. len = sprintf(buf, "%s\n", pval);
  1468. break;
  1469. case ISCSI_IFACE_PARAM_ERL:
  1470. len = sprintf(buf, "%d\n",
  1471. (ha->ip_config.iscsi_options &
  1472. ISCSIOPTS_ERL));
  1473. break;
  1474. case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
  1475. len = sprintf(buf, "%u\n",
  1476. ha->ip_config.iscsi_max_pdu_size *
  1477. BYTE_UNITS);
  1478. break;
  1479. case ISCSI_IFACE_PARAM_FIRST_BURST:
  1480. len = sprintf(buf, "%u\n",
  1481. ha->ip_config.iscsi_first_burst_len *
  1482. BYTE_UNITS);
  1483. break;
  1484. case ISCSI_IFACE_PARAM_MAX_R2T:
  1485. len = sprintf(buf, "%d\n",
  1486. ha->ip_config.iscsi_max_outstnd_r2t);
  1487. break;
  1488. case ISCSI_IFACE_PARAM_MAX_BURST:
  1489. len = sprintf(buf, "%u\n",
  1490. ha->ip_config.iscsi_max_burst_len *
  1491. BYTE_UNITS);
  1492. break;
  1493. case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
  1494. OP_STATE(ha->ip_config.iscsi_options,
  1495. ISCSIOPTS_CHAP_AUTH_EN, pval);
  1496. len = sprintf(buf, "%s\n", pval);
  1497. break;
  1498. case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
  1499. OP_STATE(ha->ip_config.iscsi_options,
  1500. ISCSIOPTS_BIDI_CHAP_EN, pval);
  1501. len = sprintf(buf, "%s\n", pval);
  1502. break;
  1503. case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
  1504. OP_STATE(ha->ip_config.iscsi_options,
  1505. ISCSIOPTS_DISCOVERY_AUTH_EN, pval);
  1506. len = sprintf(buf, "%s\n", pval);
  1507. break;
  1508. case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
  1509. OP_STATE(ha->ip_config.iscsi_options,
  1510. ISCSIOPTS_DISCOVERY_LOGOUT_EN, pval);
  1511. len = sprintf(buf, "%s\n", pval);
  1512. break;
  1513. case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
  1514. OP_STATE(ha->ip_config.iscsi_options,
  1515. ISCSIOPTS_STRICT_LOGIN_COMP_EN, pval);
  1516. len = sprintf(buf, "%s\n", pval);
  1517. break;
  1518. case ISCSI_IFACE_PARAM_INITIATOR_NAME:
  1519. len = sprintf(buf, "%s\n", ha->ip_config.iscsi_name);
  1520. break;
  1521. default:
  1522. len = -ENOSYS;
  1523. }
  1524. }
  1525. return len;
  1526. }
  1527. static struct iscsi_endpoint *
  1528. qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  1529. int non_blocking)
  1530. {
  1531. int ret;
  1532. struct iscsi_endpoint *ep;
  1533. struct qla_endpoint *qla_ep;
  1534. struct scsi_qla_host *ha;
  1535. struct sockaddr_in *addr;
  1536. struct sockaddr_in6 *addr6;
  1537. if (!shost) {
  1538. ret = -ENXIO;
  1539. pr_err("%s: shost is NULL\n", __func__);
  1540. return ERR_PTR(ret);
  1541. }
  1542. ha = iscsi_host_priv(shost);
  1543. ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
  1544. if (!ep) {
  1545. ret = -ENOMEM;
  1546. return ERR_PTR(ret);
  1547. }
  1548. qla_ep = ep->dd_data;
  1549. memset(qla_ep, 0, sizeof(struct qla_endpoint));
  1550. if (dst_addr->sa_family == AF_INET) {
  1551. memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
  1552. addr = (struct sockaddr_in *)&qla_ep->dst_addr;
  1553. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
  1554. (char *)&addr->sin_addr));
  1555. } else if (dst_addr->sa_family == AF_INET6) {
  1556. memcpy(&qla_ep->dst_addr, dst_addr,
  1557. sizeof(struct sockaddr_in6));
  1558. addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
  1559. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
  1560. (char *)&addr6->sin6_addr));
  1561. } else {
  1562. ql4_printk(KERN_WARNING, ha, "%s: Invalid endpoint\n",
  1563. __func__);
  1564. }
  1565. qla_ep->host = shost;
  1566. return ep;
  1567. }
  1568. static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  1569. {
  1570. struct qla_endpoint *qla_ep;
  1571. struct scsi_qla_host *ha;
  1572. int ret = 0;
  1573. qla_ep = ep->dd_data;
  1574. ha = to_qla_host(qla_ep->host);
  1575. DEBUG2(pr_info_ratelimited("%s: host: %ld\n", __func__, ha->host_no));
  1576. if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
  1577. ret = 1;
  1578. return ret;
  1579. }
  1580. static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
  1581. {
  1582. struct qla_endpoint *qla_ep;
  1583. struct scsi_qla_host *ha;
  1584. qla_ep = ep->dd_data;
  1585. ha = to_qla_host(qla_ep->host);
  1586. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  1587. ha->host_no));
  1588. iscsi_destroy_endpoint(ep);
  1589. }
  1590. static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
  1591. enum iscsi_param param,
  1592. char *buf)
  1593. {
  1594. struct qla_endpoint *qla_ep = ep->dd_data;
  1595. struct sockaddr *dst_addr;
  1596. struct scsi_qla_host *ha;
  1597. if (!qla_ep)
  1598. return -ENOTCONN;
  1599. ha = to_qla_host(qla_ep->host);
  1600. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  1601. ha->host_no));
  1602. switch (param) {
  1603. case ISCSI_PARAM_CONN_PORT:
  1604. case ISCSI_PARAM_CONN_ADDRESS:
  1605. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  1606. if (!dst_addr)
  1607. return -ENOTCONN;
  1608. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  1609. &qla_ep->dst_addr, param, buf);
  1610. default:
  1611. return -ENOSYS;
  1612. }
  1613. }
  1614. static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  1615. struct iscsi_stats *stats)
  1616. {
  1617. struct iscsi_session *sess;
  1618. struct iscsi_cls_session *cls_sess;
  1619. struct ddb_entry *ddb_entry;
  1620. struct scsi_qla_host *ha;
  1621. struct ql_iscsi_stats *ql_iscsi_stats;
  1622. int stats_size;
  1623. int ret;
  1624. dma_addr_t iscsi_stats_dma;
  1625. cls_sess = iscsi_conn_to_session(cls_conn);
  1626. sess = cls_sess->dd_data;
  1627. ddb_entry = sess->dd_data;
  1628. ha = ddb_entry->ha;
  1629. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  1630. ha->host_no));
  1631. stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
  1632. /* Allocate memory */
  1633. ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
  1634. &iscsi_stats_dma, GFP_KERNEL);
  1635. if (!ql_iscsi_stats) {
  1636. ql4_printk(KERN_ERR, ha,
  1637. "Unable to allocate memory for iscsi stats\n");
  1638. goto exit_get_stats;
  1639. }
  1640. ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
  1641. iscsi_stats_dma);
  1642. if (ret != QLA_SUCCESS) {
  1643. ql4_printk(KERN_ERR, ha,
  1644. "Unable to retrieve iscsi stats\n");
  1645. goto free_stats;
  1646. }
  1647. /* octets */
  1648. stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
  1649. stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
  1650. /* xmit pdus */
  1651. stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
  1652. stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
  1653. stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
  1654. stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
  1655. stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
  1656. stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
  1657. stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
  1658. stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
  1659. /* recv pdus */
  1660. stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
  1661. stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
  1662. stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
  1663. stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
  1664. stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
  1665. stats->logoutrsp_pdus =
  1666. le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
  1667. stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
  1668. stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
  1669. stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
  1670. free_stats:
  1671. dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
  1672. iscsi_stats_dma);
  1673. exit_get_stats:
  1674. return;
  1675. }
  1676. static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
  1677. {
  1678. struct iscsi_cls_session *session;
  1679. struct iscsi_session *sess;
  1680. unsigned long flags;
  1681. enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
  1682. session = starget_to_session(scsi_target(sc->device));
  1683. sess = session->dd_data;
  1684. spin_lock_irqsave(&session->lock, flags);
  1685. if (session->state == ISCSI_SESSION_FAILED)
  1686. ret = BLK_EH_RESET_TIMER;
  1687. spin_unlock_irqrestore(&session->lock, flags);
  1688. return ret;
  1689. }
  1690. static void qla4xxx_set_port_speed(struct Scsi_Host *shost)
  1691. {
  1692. struct scsi_qla_host *ha = to_qla_host(shost);
  1693. struct iscsi_cls_host *ihost = shost->shost_data;
  1694. uint32_t speed = ISCSI_PORT_SPEED_UNKNOWN;
  1695. qla4xxx_get_firmware_state(ha);
  1696. switch (ha->addl_fw_state & 0x0F00) {
  1697. case FW_ADDSTATE_LINK_SPEED_10MBPS:
  1698. speed = ISCSI_PORT_SPEED_10MBPS;
  1699. break;
  1700. case FW_ADDSTATE_LINK_SPEED_100MBPS:
  1701. speed = ISCSI_PORT_SPEED_100MBPS;
  1702. break;
  1703. case FW_ADDSTATE_LINK_SPEED_1GBPS:
  1704. speed = ISCSI_PORT_SPEED_1GBPS;
  1705. break;
  1706. case FW_ADDSTATE_LINK_SPEED_10GBPS:
  1707. speed = ISCSI_PORT_SPEED_10GBPS;
  1708. break;
  1709. }
  1710. ihost->port_speed = speed;
  1711. }
  1712. static void qla4xxx_set_port_state(struct Scsi_Host *shost)
  1713. {
  1714. struct scsi_qla_host *ha = to_qla_host(shost);
  1715. struct iscsi_cls_host *ihost = shost->shost_data;
  1716. uint32_t state = ISCSI_PORT_STATE_DOWN;
  1717. if (test_bit(AF_LINK_UP, &ha->flags))
  1718. state = ISCSI_PORT_STATE_UP;
  1719. ihost->port_state = state;
  1720. }
  1721. static int qla4xxx_host_get_param(struct Scsi_Host *shost,
  1722. enum iscsi_host_param param, char *buf)
  1723. {
  1724. struct scsi_qla_host *ha = to_qla_host(shost);
  1725. int len;
  1726. switch (param) {
  1727. case ISCSI_HOST_PARAM_HWADDRESS:
  1728. len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
  1729. break;
  1730. case ISCSI_HOST_PARAM_IPADDRESS:
  1731. len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
  1732. break;
  1733. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  1734. len = sprintf(buf, "%s\n", ha->name_string);
  1735. break;
  1736. case ISCSI_HOST_PARAM_PORT_STATE:
  1737. qla4xxx_set_port_state(shost);
  1738. len = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  1739. break;
  1740. case ISCSI_HOST_PARAM_PORT_SPEED:
  1741. qla4xxx_set_port_speed(shost);
  1742. len = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  1743. break;
  1744. default:
  1745. return -ENOSYS;
  1746. }
  1747. return len;
  1748. }
  1749. static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
  1750. {
  1751. if (ha->iface_ipv4)
  1752. return;
  1753. /* IPv4 */
  1754. ha->iface_ipv4 = iscsi_create_iface(ha->host,
  1755. &qla4xxx_iscsi_transport,
  1756. ISCSI_IFACE_TYPE_IPV4, 0, 0);
  1757. if (!ha->iface_ipv4)
  1758. ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
  1759. "iface0.\n");
  1760. }
  1761. static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
  1762. {
  1763. if (!ha->iface_ipv6_0)
  1764. /* IPv6 iface-0 */
  1765. ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
  1766. &qla4xxx_iscsi_transport,
  1767. ISCSI_IFACE_TYPE_IPV6, 0,
  1768. 0);
  1769. if (!ha->iface_ipv6_0)
  1770. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  1771. "iface0.\n");
  1772. if (!ha->iface_ipv6_1)
  1773. /* IPv6 iface-1 */
  1774. ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
  1775. &qla4xxx_iscsi_transport,
  1776. ISCSI_IFACE_TYPE_IPV6, 1,
  1777. 0);
  1778. if (!ha->iface_ipv6_1)
  1779. ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
  1780. "iface1.\n");
  1781. }
  1782. static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
  1783. {
  1784. if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
  1785. qla4xxx_create_ipv4_iface(ha);
  1786. if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
  1787. qla4xxx_create_ipv6_iface(ha);
  1788. }
  1789. static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
  1790. {
  1791. if (ha->iface_ipv4) {
  1792. iscsi_destroy_iface(ha->iface_ipv4);
  1793. ha->iface_ipv4 = NULL;
  1794. }
  1795. }
  1796. static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
  1797. {
  1798. if (ha->iface_ipv6_0) {
  1799. iscsi_destroy_iface(ha->iface_ipv6_0);
  1800. ha->iface_ipv6_0 = NULL;
  1801. }
  1802. if (ha->iface_ipv6_1) {
  1803. iscsi_destroy_iface(ha->iface_ipv6_1);
  1804. ha->iface_ipv6_1 = NULL;
  1805. }
  1806. }
  1807. static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
  1808. {
  1809. qla4xxx_destroy_ipv4_iface(ha);
  1810. qla4xxx_destroy_ipv6_iface(ha);
  1811. }
  1812. static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
  1813. struct iscsi_iface_param_info *iface_param,
  1814. struct addr_ctrl_blk *init_fw_cb)
  1815. {
  1816. /*
  1817. * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
  1818. * iface_num 1 is valid only for IPv6 Addr.
  1819. */
  1820. switch (iface_param->param) {
  1821. case ISCSI_NET_PARAM_IPV6_ADDR:
  1822. if (iface_param->iface_num & 0x1)
  1823. /* IPv6 Addr 1 */
  1824. memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
  1825. sizeof(init_fw_cb->ipv6_addr1));
  1826. else
  1827. /* IPv6 Addr 0 */
  1828. memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
  1829. sizeof(init_fw_cb->ipv6_addr0));
  1830. break;
  1831. case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
  1832. if (iface_param->iface_num & 0x1)
  1833. break;
  1834. memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
  1835. sizeof(init_fw_cb->ipv6_if_id));
  1836. break;
  1837. case ISCSI_NET_PARAM_IPV6_ROUTER:
  1838. if (iface_param->iface_num & 0x1)
  1839. break;
  1840. memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
  1841. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  1842. break;
  1843. case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
  1844. /* Autocfg applies to even interface */
  1845. if (iface_param->iface_num & 0x1)
  1846. break;
  1847. if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
  1848. init_fw_cb->ipv6_addtl_opts &=
  1849. cpu_to_le16(
  1850. ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  1851. else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
  1852. init_fw_cb->ipv6_addtl_opts |=
  1853. cpu_to_le16(
  1854. IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
  1855. else
  1856. ql4_printk(KERN_ERR, ha,
  1857. "Invalid autocfg setting for IPv6 addr\n");
  1858. break;
  1859. case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
  1860. /* Autocfg applies to even interface */
  1861. if (iface_param->iface_num & 0x1)
  1862. break;
  1863. if (iface_param->value[0] ==
  1864. ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
  1865. init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
  1866. IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  1867. else if (iface_param->value[0] ==
  1868. ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
  1869. init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
  1870. ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
  1871. else
  1872. ql4_printk(KERN_ERR, ha,
  1873. "Invalid autocfg setting for IPv6 linklocal addr\n");
  1874. break;
  1875. case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
  1876. /* Autocfg applies to even interface */
  1877. if (iface_param->iface_num & 0x1)
  1878. break;
  1879. if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
  1880. memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
  1881. sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
  1882. break;
  1883. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1884. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  1885. init_fw_cb->ipv6_opts |=
  1886. cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
  1887. qla4xxx_create_ipv6_iface(ha);
  1888. } else {
  1889. init_fw_cb->ipv6_opts &=
  1890. cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
  1891. 0xFFFF);
  1892. qla4xxx_destroy_ipv6_iface(ha);
  1893. }
  1894. break;
  1895. case ISCSI_NET_PARAM_VLAN_TAG:
  1896. if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
  1897. break;
  1898. init_fw_cb->ipv6_vlan_tag =
  1899. cpu_to_be16(*(uint16_t *)iface_param->value);
  1900. break;
  1901. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1902. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  1903. init_fw_cb->ipv6_opts |=
  1904. cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
  1905. else
  1906. init_fw_cb->ipv6_opts &=
  1907. cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
  1908. break;
  1909. case ISCSI_NET_PARAM_MTU:
  1910. init_fw_cb->eth_mtu_size =
  1911. cpu_to_le16(*(uint16_t *)iface_param->value);
  1912. break;
  1913. case ISCSI_NET_PARAM_PORT:
  1914. /* Autocfg applies to even interface */
  1915. if (iface_param->iface_num & 0x1)
  1916. break;
  1917. init_fw_cb->ipv6_port =
  1918. cpu_to_le16(*(uint16_t *)iface_param->value);
  1919. break;
  1920. case ISCSI_NET_PARAM_DELAYED_ACK_EN:
  1921. if (iface_param->iface_num & 0x1)
  1922. break;
  1923. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  1924. init_fw_cb->ipv6_tcp_opts |=
  1925. cpu_to_le16(IPV6_TCPOPT_DELAYED_ACK_DISABLE);
  1926. else
  1927. init_fw_cb->ipv6_tcp_opts &=
  1928. cpu_to_le16(~IPV6_TCPOPT_DELAYED_ACK_DISABLE &
  1929. 0xFFFF);
  1930. break;
  1931. case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
  1932. if (iface_param->iface_num & 0x1)
  1933. break;
  1934. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  1935. init_fw_cb->ipv6_tcp_opts |=
  1936. cpu_to_le16(IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
  1937. else
  1938. init_fw_cb->ipv6_tcp_opts &=
  1939. cpu_to_le16(~IPV6_TCPOPT_NAGLE_ALGO_DISABLE);
  1940. break;
  1941. case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
  1942. if (iface_param->iface_num & 0x1)
  1943. break;
  1944. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  1945. init_fw_cb->ipv6_tcp_opts |=
  1946. cpu_to_le16(IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
  1947. else
  1948. init_fw_cb->ipv6_tcp_opts &=
  1949. cpu_to_le16(~IPV6_TCPOPT_WINDOW_SCALE_DISABLE);
  1950. break;
  1951. case ISCSI_NET_PARAM_TCP_WSF:
  1952. if (iface_param->iface_num & 0x1)
  1953. break;
  1954. init_fw_cb->ipv6_tcp_wsf = iface_param->value[0];
  1955. break;
  1956. case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
  1957. if (iface_param->iface_num & 0x1)
  1958. break;
  1959. init_fw_cb->ipv6_tcp_opts &=
  1960. cpu_to_le16(~IPV6_TCPOPT_TIMER_SCALE);
  1961. init_fw_cb->ipv6_tcp_opts |=
  1962. cpu_to_le16((iface_param->value[0] << 1) &
  1963. IPV6_TCPOPT_TIMER_SCALE);
  1964. break;
  1965. case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
  1966. if (iface_param->iface_num & 0x1)
  1967. break;
  1968. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  1969. init_fw_cb->ipv6_tcp_opts |=
  1970. cpu_to_le16(IPV6_TCPOPT_TIMESTAMP_EN);
  1971. else
  1972. init_fw_cb->ipv6_tcp_opts &=
  1973. cpu_to_le16(~IPV6_TCPOPT_TIMESTAMP_EN);
  1974. break;
  1975. case ISCSI_NET_PARAM_IPV6_GRAT_NEIGHBOR_ADV_EN:
  1976. if (iface_param->iface_num & 0x1)
  1977. break;
  1978. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  1979. init_fw_cb->ipv6_opts |=
  1980. cpu_to_le16(IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
  1981. else
  1982. init_fw_cb->ipv6_opts &=
  1983. cpu_to_le16(~IPV6_OPT_GRAT_NEIGHBOR_ADV_EN);
  1984. break;
  1985. case ISCSI_NET_PARAM_REDIRECT_EN:
  1986. if (iface_param->iface_num & 0x1)
  1987. break;
  1988. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  1989. init_fw_cb->ipv6_opts |=
  1990. cpu_to_le16(IPV6_OPT_REDIRECT_EN);
  1991. else
  1992. init_fw_cb->ipv6_opts &=
  1993. cpu_to_le16(~IPV6_OPT_REDIRECT_EN);
  1994. break;
  1995. case ISCSI_NET_PARAM_IPV6_MLD_EN:
  1996. if (iface_param->iface_num & 0x1)
  1997. break;
  1998. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  1999. init_fw_cb->ipv6_addtl_opts |=
  2000. cpu_to_le16(IPV6_ADDOPT_MLD_EN);
  2001. else
  2002. init_fw_cb->ipv6_addtl_opts &=
  2003. cpu_to_le16(~IPV6_ADDOPT_MLD_EN);
  2004. break;
  2005. case ISCSI_NET_PARAM_IPV6_FLOW_LABEL:
  2006. if (iface_param->iface_num & 0x1)
  2007. break;
  2008. init_fw_cb->ipv6_flow_lbl =
  2009. cpu_to_le16(*(uint16_t *)iface_param->value);
  2010. break;
  2011. case ISCSI_NET_PARAM_IPV6_TRAFFIC_CLASS:
  2012. if (iface_param->iface_num & 0x1)
  2013. break;
  2014. init_fw_cb->ipv6_traffic_class = iface_param->value[0];
  2015. break;
  2016. case ISCSI_NET_PARAM_IPV6_HOP_LIMIT:
  2017. if (iface_param->iface_num & 0x1)
  2018. break;
  2019. init_fw_cb->ipv6_hop_limit = iface_param->value[0];
  2020. break;
  2021. case ISCSI_NET_PARAM_IPV6_ND_REACHABLE_TMO:
  2022. if (iface_param->iface_num & 0x1)
  2023. break;
  2024. init_fw_cb->ipv6_nd_reach_time =
  2025. cpu_to_le32(*(uint32_t *)iface_param->value);
  2026. break;
  2027. case ISCSI_NET_PARAM_IPV6_ND_REXMIT_TIME:
  2028. if (iface_param->iface_num & 0x1)
  2029. break;
  2030. init_fw_cb->ipv6_nd_rexmit_timer =
  2031. cpu_to_le32(*(uint32_t *)iface_param->value);
  2032. break;
  2033. case ISCSI_NET_PARAM_IPV6_ND_STALE_TMO:
  2034. if (iface_param->iface_num & 0x1)
  2035. break;
  2036. init_fw_cb->ipv6_nd_stale_timeout =
  2037. cpu_to_le32(*(uint32_t *)iface_param->value);
  2038. break;
  2039. case ISCSI_NET_PARAM_IPV6_DUP_ADDR_DETECT_CNT:
  2040. if (iface_param->iface_num & 0x1)
  2041. break;
  2042. init_fw_cb->ipv6_dup_addr_detect_count = iface_param->value[0];
  2043. break;
  2044. case ISCSI_NET_PARAM_IPV6_RTR_ADV_LINK_MTU:
  2045. if (iface_param->iface_num & 0x1)
  2046. break;
  2047. init_fw_cb->ipv6_gw_advrt_mtu =
  2048. cpu_to_le32(*(uint32_t *)iface_param->value);
  2049. break;
  2050. default:
  2051. ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
  2052. iface_param->param);
  2053. break;
  2054. }
  2055. }
  2056. static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
  2057. struct iscsi_iface_param_info *iface_param,
  2058. struct addr_ctrl_blk *init_fw_cb)
  2059. {
  2060. switch (iface_param->param) {
  2061. case ISCSI_NET_PARAM_IPV4_ADDR:
  2062. memcpy(init_fw_cb->ipv4_addr, iface_param->value,
  2063. sizeof(init_fw_cb->ipv4_addr));
  2064. break;
  2065. case ISCSI_NET_PARAM_IPV4_SUBNET:
  2066. memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
  2067. sizeof(init_fw_cb->ipv4_subnet));
  2068. break;
  2069. case ISCSI_NET_PARAM_IPV4_GW:
  2070. memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
  2071. sizeof(init_fw_cb->ipv4_gw_addr));
  2072. break;
  2073. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  2074. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  2075. init_fw_cb->ipv4_tcp_opts |=
  2076. cpu_to_le16(TCPOPT_DHCP_ENABLE);
  2077. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  2078. init_fw_cb->ipv4_tcp_opts &=
  2079. cpu_to_le16(~TCPOPT_DHCP_ENABLE);
  2080. else
  2081. ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
  2082. break;
  2083. case ISCSI_NET_PARAM_IFACE_ENABLE:
  2084. if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
  2085. init_fw_cb->ipv4_ip_opts |=
  2086. cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
  2087. qla4xxx_create_ipv4_iface(ha);
  2088. } else {
  2089. init_fw_cb->ipv4_ip_opts &=
  2090. cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
  2091. 0xFFFF);
  2092. qla4xxx_destroy_ipv4_iface(ha);
  2093. }
  2094. break;
  2095. case ISCSI_NET_PARAM_VLAN_TAG:
  2096. if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
  2097. break;
  2098. init_fw_cb->ipv4_vlan_tag =
  2099. cpu_to_be16(*(uint16_t *)iface_param->value);
  2100. break;
  2101. case ISCSI_NET_PARAM_VLAN_ENABLED:
  2102. if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
  2103. init_fw_cb->ipv4_ip_opts |=
  2104. cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
  2105. else
  2106. init_fw_cb->ipv4_ip_opts &=
  2107. cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
  2108. break;
  2109. case ISCSI_NET_PARAM_MTU:
  2110. init_fw_cb->eth_mtu_size =
  2111. cpu_to_le16(*(uint16_t *)iface_param->value);
  2112. break;
  2113. case ISCSI_NET_PARAM_PORT:
  2114. init_fw_cb->ipv4_port =
  2115. cpu_to_le16(*(uint16_t *)iface_param->value);
  2116. break;
  2117. case ISCSI_NET_PARAM_DELAYED_ACK_EN:
  2118. if (iface_param->iface_num & 0x1)
  2119. break;
  2120. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  2121. init_fw_cb->ipv4_tcp_opts |=
  2122. cpu_to_le16(TCPOPT_DELAYED_ACK_DISABLE);
  2123. else
  2124. init_fw_cb->ipv4_tcp_opts &=
  2125. cpu_to_le16(~TCPOPT_DELAYED_ACK_DISABLE &
  2126. 0xFFFF);
  2127. break;
  2128. case ISCSI_NET_PARAM_TCP_NAGLE_DISABLE:
  2129. if (iface_param->iface_num & 0x1)
  2130. break;
  2131. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  2132. init_fw_cb->ipv4_tcp_opts |=
  2133. cpu_to_le16(TCPOPT_NAGLE_ALGO_DISABLE);
  2134. else
  2135. init_fw_cb->ipv4_tcp_opts &=
  2136. cpu_to_le16(~TCPOPT_NAGLE_ALGO_DISABLE);
  2137. break;
  2138. case ISCSI_NET_PARAM_TCP_WSF_DISABLE:
  2139. if (iface_param->iface_num & 0x1)
  2140. break;
  2141. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  2142. init_fw_cb->ipv4_tcp_opts |=
  2143. cpu_to_le16(TCPOPT_WINDOW_SCALE_DISABLE);
  2144. else
  2145. init_fw_cb->ipv4_tcp_opts &=
  2146. cpu_to_le16(~TCPOPT_WINDOW_SCALE_DISABLE);
  2147. break;
  2148. case ISCSI_NET_PARAM_TCP_WSF:
  2149. if (iface_param->iface_num & 0x1)
  2150. break;
  2151. init_fw_cb->ipv4_tcp_wsf = iface_param->value[0];
  2152. break;
  2153. case ISCSI_NET_PARAM_TCP_TIMER_SCALE:
  2154. if (iface_param->iface_num & 0x1)
  2155. break;
  2156. init_fw_cb->ipv4_tcp_opts &= cpu_to_le16(~TCPOPT_TIMER_SCALE);
  2157. init_fw_cb->ipv4_tcp_opts |=
  2158. cpu_to_le16((iface_param->value[0] << 1) &
  2159. TCPOPT_TIMER_SCALE);
  2160. break;
  2161. case ISCSI_NET_PARAM_TCP_TIMESTAMP_EN:
  2162. if (iface_param->iface_num & 0x1)
  2163. break;
  2164. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2165. init_fw_cb->ipv4_tcp_opts |=
  2166. cpu_to_le16(TCPOPT_TIMESTAMP_ENABLE);
  2167. else
  2168. init_fw_cb->ipv4_tcp_opts &=
  2169. cpu_to_le16(~TCPOPT_TIMESTAMP_ENABLE);
  2170. break;
  2171. case ISCSI_NET_PARAM_IPV4_DHCP_DNS_ADDR_EN:
  2172. if (iface_param->iface_num & 0x1)
  2173. break;
  2174. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2175. init_fw_cb->ipv4_tcp_opts |=
  2176. cpu_to_le16(TCPOPT_DNS_SERVER_IP_EN);
  2177. else
  2178. init_fw_cb->ipv4_tcp_opts &=
  2179. cpu_to_le16(~TCPOPT_DNS_SERVER_IP_EN);
  2180. break;
  2181. case ISCSI_NET_PARAM_IPV4_DHCP_SLP_DA_EN:
  2182. if (iface_param->iface_num & 0x1)
  2183. break;
  2184. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2185. init_fw_cb->ipv4_tcp_opts |=
  2186. cpu_to_le16(TCPOPT_SLP_DA_INFO_EN);
  2187. else
  2188. init_fw_cb->ipv4_tcp_opts &=
  2189. cpu_to_le16(~TCPOPT_SLP_DA_INFO_EN);
  2190. break;
  2191. case ISCSI_NET_PARAM_IPV4_TOS_EN:
  2192. if (iface_param->iface_num & 0x1)
  2193. break;
  2194. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2195. init_fw_cb->ipv4_ip_opts |=
  2196. cpu_to_le16(IPOPT_IPV4_TOS_EN);
  2197. else
  2198. init_fw_cb->ipv4_ip_opts &=
  2199. cpu_to_le16(~IPOPT_IPV4_TOS_EN);
  2200. break;
  2201. case ISCSI_NET_PARAM_IPV4_TOS:
  2202. if (iface_param->iface_num & 0x1)
  2203. break;
  2204. init_fw_cb->ipv4_tos = iface_param->value[0];
  2205. break;
  2206. case ISCSI_NET_PARAM_IPV4_GRAT_ARP_EN:
  2207. if (iface_param->iface_num & 0x1)
  2208. break;
  2209. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2210. init_fw_cb->ipv4_ip_opts |=
  2211. cpu_to_le16(IPOPT_GRAT_ARP_EN);
  2212. else
  2213. init_fw_cb->ipv4_ip_opts &=
  2214. cpu_to_le16(~IPOPT_GRAT_ARP_EN);
  2215. break;
  2216. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID_EN:
  2217. if (iface_param->iface_num & 0x1)
  2218. break;
  2219. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2220. init_fw_cb->ipv4_ip_opts |=
  2221. cpu_to_le16(IPOPT_ALT_CID_EN);
  2222. else
  2223. init_fw_cb->ipv4_ip_opts &=
  2224. cpu_to_le16(~IPOPT_ALT_CID_EN);
  2225. break;
  2226. case ISCSI_NET_PARAM_IPV4_DHCP_ALT_CLIENT_ID:
  2227. if (iface_param->iface_num & 0x1)
  2228. break;
  2229. memcpy(init_fw_cb->ipv4_dhcp_alt_cid, iface_param->value,
  2230. (sizeof(init_fw_cb->ipv4_dhcp_alt_cid) - 1));
  2231. init_fw_cb->ipv4_dhcp_alt_cid_len =
  2232. strlen(init_fw_cb->ipv4_dhcp_alt_cid);
  2233. break;
  2234. case ISCSI_NET_PARAM_IPV4_DHCP_REQ_VENDOR_ID_EN:
  2235. if (iface_param->iface_num & 0x1)
  2236. break;
  2237. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2238. init_fw_cb->ipv4_ip_opts |=
  2239. cpu_to_le16(IPOPT_REQ_VID_EN);
  2240. else
  2241. init_fw_cb->ipv4_ip_opts &=
  2242. cpu_to_le16(~IPOPT_REQ_VID_EN);
  2243. break;
  2244. case ISCSI_NET_PARAM_IPV4_DHCP_USE_VENDOR_ID_EN:
  2245. if (iface_param->iface_num & 0x1)
  2246. break;
  2247. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2248. init_fw_cb->ipv4_ip_opts |=
  2249. cpu_to_le16(IPOPT_USE_VID_EN);
  2250. else
  2251. init_fw_cb->ipv4_ip_opts &=
  2252. cpu_to_le16(~IPOPT_USE_VID_EN);
  2253. break;
  2254. case ISCSI_NET_PARAM_IPV4_DHCP_VENDOR_ID:
  2255. if (iface_param->iface_num & 0x1)
  2256. break;
  2257. memcpy(init_fw_cb->ipv4_dhcp_vid, iface_param->value,
  2258. (sizeof(init_fw_cb->ipv4_dhcp_vid) - 1));
  2259. init_fw_cb->ipv4_dhcp_vid_len =
  2260. strlen(init_fw_cb->ipv4_dhcp_vid);
  2261. break;
  2262. case ISCSI_NET_PARAM_IPV4_DHCP_LEARN_IQN_EN:
  2263. if (iface_param->iface_num & 0x1)
  2264. break;
  2265. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2266. init_fw_cb->ipv4_ip_opts |=
  2267. cpu_to_le16(IPOPT_LEARN_IQN_EN);
  2268. else
  2269. init_fw_cb->ipv4_ip_opts &=
  2270. cpu_to_le16(~IPOPT_LEARN_IQN_EN);
  2271. break;
  2272. case ISCSI_NET_PARAM_IPV4_FRAGMENT_DISABLE:
  2273. if (iface_param->iface_num & 0x1)
  2274. break;
  2275. if (iface_param->value[0] == ISCSI_NET_PARAM_DISABLE)
  2276. init_fw_cb->ipv4_ip_opts |=
  2277. cpu_to_le16(IPOPT_FRAGMENTATION_DISABLE);
  2278. else
  2279. init_fw_cb->ipv4_ip_opts &=
  2280. cpu_to_le16(~IPOPT_FRAGMENTATION_DISABLE);
  2281. break;
  2282. case ISCSI_NET_PARAM_IPV4_IN_FORWARD_EN:
  2283. if (iface_param->iface_num & 0x1)
  2284. break;
  2285. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2286. init_fw_cb->ipv4_ip_opts |=
  2287. cpu_to_le16(IPOPT_IN_FORWARD_EN);
  2288. else
  2289. init_fw_cb->ipv4_ip_opts &=
  2290. cpu_to_le16(~IPOPT_IN_FORWARD_EN);
  2291. break;
  2292. case ISCSI_NET_PARAM_REDIRECT_EN:
  2293. if (iface_param->iface_num & 0x1)
  2294. break;
  2295. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2296. init_fw_cb->ipv4_ip_opts |=
  2297. cpu_to_le16(IPOPT_ARP_REDIRECT_EN);
  2298. else
  2299. init_fw_cb->ipv4_ip_opts &=
  2300. cpu_to_le16(~IPOPT_ARP_REDIRECT_EN);
  2301. break;
  2302. case ISCSI_NET_PARAM_IPV4_TTL:
  2303. if (iface_param->iface_num & 0x1)
  2304. break;
  2305. init_fw_cb->ipv4_ttl = iface_param->value[0];
  2306. break;
  2307. default:
  2308. ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
  2309. iface_param->param);
  2310. break;
  2311. }
  2312. }
  2313. static void qla4xxx_set_iscsi_param(struct scsi_qla_host *ha,
  2314. struct iscsi_iface_param_info *iface_param,
  2315. struct addr_ctrl_blk *init_fw_cb)
  2316. {
  2317. switch (iface_param->param) {
  2318. case ISCSI_IFACE_PARAM_DEF_TASKMGMT_TMO:
  2319. if (iface_param->iface_num & 0x1)
  2320. break;
  2321. init_fw_cb->def_timeout =
  2322. cpu_to_le16(*(uint16_t *)iface_param->value);
  2323. break;
  2324. case ISCSI_IFACE_PARAM_HDRDGST_EN:
  2325. if (iface_param->iface_num & 0x1)
  2326. break;
  2327. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2328. init_fw_cb->iscsi_opts |=
  2329. cpu_to_le16(ISCSIOPTS_HEADER_DIGEST_EN);
  2330. else
  2331. init_fw_cb->iscsi_opts &=
  2332. cpu_to_le16(~ISCSIOPTS_HEADER_DIGEST_EN);
  2333. break;
  2334. case ISCSI_IFACE_PARAM_DATADGST_EN:
  2335. if (iface_param->iface_num & 0x1)
  2336. break;
  2337. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2338. init_fw_cb->iscsi_opts |=
  2339. cpu_to_le16(ISCSIOPTS_DATA_DIGEST_EN);
  2340. else
  2341. init_fw_cb->iscsi_opts &=
  2342. cpu_to_le16(~ISCSIOPTS_DATA_DIGEST_EN);
  2343. break;
  2344. case ISCSI_IFACE_PARAM_IMM_DATA_EN:
  2345. if (iface_param->iface_num & 0x1)
  2346. break;
  2347. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2348. init_fw_cb->iscsi_opts |=
  2349. cpu_to_le16(ISCSIOPTS_IMMEDIATE_DATA_EN);
  2350. else
  2351. init_fw_cb->iscsi_opts &=
  2352. cpu_to_le16(~ISCSIOPTS_IMMEDIATE_DATA_EN);
  2353. break;
  2354. case ISCSI_IFACE_PARAM_INITIAL_R2T_EN:
  2355. if (iface_param->iface_num & 0x1)
  2356. break;
  2357. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2358. init_fw_cb->iscsi_opts |=
  2359. cpu_to_le16(ISCSIOPTS_INITIAL_R2T_EN);
  2360. else
  2361. init_fw_cb->iscsi_opts &=
  2362. cpu_to_le16(~ISCSIOPTS_INITIAL_R2T_EN);
  2363. break;
  2364. case ISCSI_IFACE_PARAM_DATASEQ_INORDER_EN:
  2365. if (iface_param->iface_num & 0x1)
  2366. break;
  2367. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2368. init_fw_cb->iscsi_opts |=
  2369. cpu_to_le16(ISCSIOPTS_DATA_SEQ_INORDER_EN);
  2370. else
  2371. init_fw_cb->iscsi_opts &=
  2372. cpu_to_le16(~ISCSIOPTS_DATA_SEQ_INORDER_EN);
  2373. break;
  2374. case ISCSI_IFACE_PARAM_PDU_INORDER_EN:
  2375. if (iface_param->iface_num & 0x1)
  2376. break;
  2377. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2378. init_fw_cb->iscsi_opts |=
  2379. cpu_to_le16(ISCSIOPTS_DATA_PDU_INORDER_EN);
  2380. else
  2381. init_fw_cb->iscsi_opts &=
  2382. cpu_to_le16(~ISCSIOPTS_DATA_PDU_INORDER_EN);
  2383. break;
  2384. case ISCSI_IFACE_PARAM_ERL:
  2385. if (iface_param->iface_num & 0x1)
  2386. break;
  2387. init_fw_cb->iscsi_opts &= cpu_to_le16(~ISCSIOPTS_ERL);
  2388. init_fw_cb->iscsi_opts |= cpu_to_le16(iface_param->value[0] &
  2389. ISCSIOPTS_ERL);
  2390. break;
  2391. case ISCSI_IFACE_PARAM_MAX_RECV_DLENGTH:
  2392. if (iface_param->iface_num & 0x1)
  2393. break;
  2394. init_fw_cb->iscsi_max_pdu_size =
  2395. cpu_to_le32(*(uint32_t *)iface_param->value) /
  2396. BYTE_UNITS;
  2397. break;
  2398. case ISCSI_IFACE_PARAM_FIRST_BURST:
  2399. if (iface_param->iface_num & 0x1)
  2400. break;
  2401. init_fw_cb->iscsi_fburst_len =
  2402. cpu_to_le32(*(uint32_t *)iface_param->value) /
  2403. BYTE_UNITS;
  2404. break;
  2405. case ISCSI_IFACE_PARAM_MAX_R2T:
  2406. if (iface_param->iface_num & 0x1)
  2407. break;
  2408. init_fw_cb->iscsi_max_outstnd_r2t =
  2409. cpu_to_le16(*(uint16_t *)iface_param->value);
  2410. break;
  2411. case ISCSI_IFACE_PARAM_MAX_BURST:
  2412. if (iface_param->iface_num & 0x1)
  2413. break;
  2414. init_fw_cb->iscsi_max_burst_len =
  2415. cpu_to_le32(*(uint32_t *)iface_param->value) /
  2416. BYTE_UNITS;
  2417. break;
  2418. case ISCSI_IFACE_PARAM_CHAP_AUTH_EN:
  2419. if (iface_param->iface_num & 0x1)
  2420. break;
  2421. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2422. init_fw_cb->iscsi_opts |=
  2423. cpu_to_le16(ISCSIOPTS_CHAP_AUTH_EN);
  2424. else
  2425. init_fw_cb->iscsi_opts &=
  2426. cpu_to_le16(~ISCSIOPTS_CHAP_AUTH_EN);
  2427. break;
  2428. case ISCSI_IFACE_PARAM_BIDI_CHAP_EN:
  2429. if (iface_param->iface_num & 0x1)
  2430. break;
  2431. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2432. init_fw_cb->iscsi_opts |=
  2433. cpu_to_le16(ISCSIOPTS_BIDI_CHAP_EN);
  2434. else
  2435. init_fw_cb->iscsi_opts &=
  2436. cpu_to_le16(~ISCSIOPTS_BIDI_CHAP_EN);
  2437. break;
  2438. case ISCSI_IFACE_PARAM_DISCOVERY_AUTH_OPTIONAL:
  2439. if (iface_param->iface_num & 0x1)
  2440. break;
  2441. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2442. init_fw_cb->iscsi_opts |=
  2443. cpu_to_le16(ISCSIOPTS_DISCOVERY_AUTH_EN);
  2444. else
  2445. init_fw_cb->iscsi_opts &=
  2446. cpu_to_le16(~ISCSIOPTS_DISCOVERY_AUTH_EN);
  2447. break;
  2448. case ISCSI_IFACE_PARAM_DISCOVERY_LOGOUT_EN:
  2449. if (iface_param->iface_num & 0x1)
  2450. break;
  2451. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2452. init_fw_cb->iscsi_opts |=
  2453. cpu_to_le16(ISCSIOPTS_DISCOVERY_LOGOUT_EN);
  2454. else
  2455. init_fw_cb->iscsi_opts &=
  2456. cpu_to_le16(~ISCSIOPTS_DISCOVERY_LOGOUT_EN);
  2457. break;
  2458. case ISCSI_IFACE_PARAM_STRICT_LOGIN_COMP_EN:
  2459. if (iface_param->iface_num & 0x1)
  2460. break;
  2461. if (iface_param->value[0] == ISCSI_NET_PARAM_ENABLE)
  2462. init_fw_cb->iscsi_opts |=
  2463. cpu_to_le16(ISCSIOPTS_STRICT_LOGIN_COMP_EN);
  2464. else
  2465. init_fw_cb->iscsi_opts &=
  2466. cpu_to_le16(~ISCSIOPTS_STRICT_LOGIN_COMP_EN);
  2467. break;
  2468. default:
  2469. ql4_printk(KERN_ERR, ha, "Unknown iscsi param = %d\n",
  2470. iface_param->param);
  2471. break;
  2472. }
  2473. }
  2474. static void
  2475. qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
  2476. {
  2477. struct addr_ctrl_blk_def *acb;
  2478. acb = (struct addr_ctrl_blk_def *)init_fw_cb;
  2479. memset(acb->reserved1, 0, sizeof(acb->reserved1));
  2480. memset(acb->reserved2, 0, sizeof(acb->reserved2));
  2481. memset(acb->reserved3, 0, sizeof(acb->reserved3));
  2482. memset(acb->reserved4, 0, sizeof(acb->reserved4));
  2483. memset(acb->reserved5, 0, sizeof(acb->reserved5));
  2484. memset(acb->reserved6, 0, sizeof(acb->reserved6));
  2485. memset(acb->reserved7, 0, sizeof(acb->reserved7));
  2486. memset(acb->reserved8, 0, sizeof(acb->reserved8));
  2487. memset(acb->reserved9, 0, sizeof(acb->reserved9));
  2488. memset(acb->reserved10, 0, sizeof(acb->reserved10));
  2489. memset(acb->reserved11, 0, sizeof(acb->reserved11));
  2490. memset(acb->reserved12, 0, sizeof(acb->reserved12));
  2491. memset(acb->reserved13, 0, sizeof(acb->reserved13));
  2492. memset(acb->reserved14, 0, sizeof(acb->reserved14));
  2493. memset(acb->reserved15, 0, sizeof(acb->reserved15));
  2494. }
  2495. static int
  2496. qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
  2497. {
  2498. struct scsi_qla_host *ha = to_qla_host(shost);
  2499. int rval = 0;
  2500. struct iscsi_iface_param_info *iface_param = NULL;
  2501. struct addr_ctrl_blk *init_fw_cb = NULL;
  2502. dma_addr_t init_fw_cb_dma;
  2503. uint32_t mbox_cmd[MBOX_REG_COUNT];
  2504. uint32_t mbox_sts[MBOX_REG_COUNT];
  2505. uint32_t rem = len;
  2506. struct nlattr *attr;
  2507. init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
  2508. sizeof(struct addr_ctrl_blk),
  2509. &init_fw_cb_dma, GFP_KERNEL);
  2510. if (!init_fw_cb) {
  2511. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
  2512. __func__);
  2513. return -ENOMEM;
  2514. }
  2515. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  2516. memset(&mbox_cmd, 0, sizeof(mbox_cmd));
  2517. memset(&mbox_sts, 0, sizeof(mbox_sts));
  2518. if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
  2519. ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
  2520. rval = -EIO;
  2521. goto exit_init_fw_cb;
  2522. }
  2523. nla_for_each_attr(attr, data, len, rem) {
  2524. iface_param = nla_data(attr);
  2525. if (iface_param->param_type == ISCSI_NET_PARAM) {
  2526. switch (iface_param->iface_type) {
  2527. case ISCSI_IFACE_TYPE_IPV4:
  2528. switch (iface_param->iface_num) {
  2529. case 0:
  2530. qla4xxx_set_ipv4(ha, iface_param,
  2531. init_fw_cb);
  2532. break;
  2533. default:
  2534. /* Cannot have more than one IPv4 interface */
  2535. ql4_printk(KERN_ERR, ha,
  2536. "Invalid IPv4 iface number = %d\n",
  2537. iface_param->iface_num);
  2538. break;
  2539. }
  2540. break;
  2541. case ISCSI_IFACE_TYPE_IPV6:
  2542. switch (iface_param->iface_num) {
  2543. case 0:
  2544. case 1:
  2545. qla4xxx_set_ipv6(ha, iface_param,
  2546. init_fw_cb);
  2547. break;
  2548. default:
  2549. /* Cannot have more than two IPv6 interface */
  2550. ql4_printk(KERN_ERR, ha,
  2551. "Invalid IPv6 iface number = %d\n",
  2552. iface_param->iface_num);
  2553. break;
  2554. }
  2555. break;
  2556. default:
  2557. ql4_printk(KERN_ERR, ha,
  2558. "Invalid iface type\n");
  2559. break;
  2560. }
  2561. } else if (iface_param->param_type == ISCSI_IFACE_PARAM) {
  2562. qla4xxx_set_iscsi_param(ha, iface_param,
  2563. init_fw_cb);
  2564. } else {
  2565. continue;
  2566. }
  2567. }
  2568. init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
  2569. rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
  2570. sizeof(struct addr_ctrl_blk),
  2571. FLASH_OPT_RMW_COMMIT);
  2572. if (rval != QLA_SUCCESS) {
  2573. ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
  2574. __func__);
  2575. rval = -EIO;
  2576. goto exit_init_fw_cb;
  2577. }
  2578. rval = qla4xxx_disable_acb(ha);
  2579. if (rval != QLA_SUCCESS) {
  2580. ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
  2581. __func__);
  2582. rval = -EIO;
  2583. goto exit_init_fw_cb;
  2584. }
  2585. wait_for_completion_timeout(&ha->disable_acb_comp,
  2586. DISABLE_ACB_TOV * HZ);
  2587. qla4xxx_initcb_to_acb(init_fw_cb);
  2588. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
  2589. if (rval != QLA_SUCCESS) {
  2590. ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
  2591. __func__);
  2592. rval = -EIO;
  2593. goto exit_init_fw_cb;
  2594. }
  2595. memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
  2596. qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
  2597. init_fw_cb_dma);
  2598. exit_init_fw_cb:
  2599. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
  2600. init_fw_cb, init_fw_cb_dma);
  2601. return rval;
  2602. }
  2603. static int qla4xxx_session_get_param(struct iscsi_cls_session *cls_sess,
  2604. enum iscsi_param param, char *buf)
  2605. {
  2606. struct iscsi_session *sess = cls_sess->dd_data;
  2607. struct ddb_entry *ddb_entry = sess->dd_data;
  2608. struct scsi_qla_host *ha = ddb_entry->ha;
  2609. struct iscsi_cls_conn *cls_conn = ddb_entry->conn;
  2610. struct ql4_chap_table chap_tbl;
  2611. int rval, len;
  2612. uint16_t idx;
  2613. memset(&chap_tbl, 0, sizeof(chap_tbl));
  2614. switch (param) {
  2615. case ISCSI_PARAM_CHAP_IN_IDX:
  2616. rval = qla4xxx_get_chap_index(ha, sess->username_in,
  2617. sess->password_in, BIDI_CHAP,
  2618. &idx);
  2619. if (rval)
  2620. len = sprintf(buf, "\n");
  2621. else
  2622. len = sprintf(buf, "%hu\n", idx);
  2623. break;
  2624. case ISCSI_PARAM_CHAP_OUT_IDX:
  2625. if (ddb_entry->ddb_type == FLASH_DDB) {
  2626. if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
  2627. idx = ddb_entry->chap_tbl_idx;
  2628. rval = QLA_SUCCESS;
  2629. } else {
  2630. rval = QLA_ERROR;
  2631. }
  2632. } else {
  2633. rval = qla4xxx_get_chap_index(ha, sess->username,
  2634. sess->password,
  2635. LOCAL_CHAP, &idx);
  2636. }
  2637. if (rval)
  2638. len = sprintf(buf, "\n");
  2639. else
  2640. len = sprintf(buf, "%hu\n", idx);
  2641. break;
  2642. case ISCSI_PARAM_USERNAME:
  2643. case ISCSI_PARAM_PASSWORD:
  2644. /* First, populate session username and password for FLASH DDB,
  2645. * if not already done. This happens when session login fails
  2646. * for a FLASH DDB.
  2647. */
  2648. if (ddb_entry->ddb_type == FLASH_DDB &&
  2649. ddb_entry->chap_tbl_idx != INVALID_ENTRY &&
  2650. !sess->username && !sess->password) {
  2651. idx = ddb_entry->chap_tbl_idx;
  2652. rval = qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
  2653. chap_tbl.secret,
  2654. idx);
  2655. if (!rval) {
  2656. iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
  2657. (char *)chap_tbl.name,
  2658. strlen((char *)chap_tbl.name));
  2659. iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
  2660. (char *)chap_tbl.secret,
  2661. chap_tbl.secret_len);
  2662. }
  2663. }
  2664. /* allow fall-through */
  2665. default:
  2666. return iscsi_session_get_param(cls_sess, param, buf);
  2667. }
  2668. return len;
  2669. }
  2670. static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
  2671. enum iscsi_param param, char *buf)
  2672. {
  2673. struct iscsi_conn *conn;
  2674. struct qla_conn *qla_conn;
  2675. struct sockaddr *dst_addr;
  2676. conn = cls_conn->dd_data;
  2677. qla_conn = conn->dd_data;
  2678. dst_addr = (struct sockaddr *)&qla_conn->qla_ep->dst_addr;
  2679. switch (param) {
  2680. case ISCSI_PARAM_CONN_PORT:
  2681. case ISCSI_PARAM_CONN_ADDRESS:
  2682. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  2683. dst_addr, param, buf);
  2684. default:
  2685. return iscsi_conn_get_param(cls_conn, param, buf);
  2686. }
  2687. }
  2688. int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
  2689. {
  2690. uint32_t mbx_sts = 0;
  2691. uint16_t tmp_ddb_index;
  2692. int ret;
  2693. get_ddb_index:
  2694. tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
  2695. if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
  2696. DEBUG2(ql4_printk(KERN_INFO, ha,
  2697. "Free DDB index not available\n"));
  2698. ret = QLA_ERROR;
  2699. goto exit_get_ddb_index;
  2700. }
  2701. if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
  2702. goto get_ddb_index;
  2703. DEBUG2(ql4_printk(KERN_INFO, ha,
  2704. "Found a free DDB index at %d\n", tmp_ddb_index));
  2705. ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
  2706. if (ret == QLA_ERROR) {
  2707. if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
  2708. ql4_printk(KERN_INFO, ha,
  2709. "DDB index = %d not available trying next\n",
  2710. tmp_ddb_index);
  2711. goto get_ddb_index;
  2712. }
  2713. DEBUG2(ql4_printk(KERN_INFO, ha,
  2714. "Free FW DDB not available\n"));
  2715. }
  2716. *ddb_index = tmp_ddb_index;
  2717. exit_get_ddb_index:
  2718. return ret;
  2719. }
  2720. static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
  2721. struct ddb_entry *ddb_entry,
  2722. char *existing_ipaddr,
  2723. char *user_ipaddr)
  2724. {
  2725. uint8_t dst_ipaddr[IPv6_ADDR_LEN];
  2726. char formatted_ipaddr[DDB_IPADDR_LEN];
  2727. int status = QLA_SUCCESS, ret = 0;
  2728. if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
  2729. ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  2730. '\0', NULL);
  2731. if (ret == 0) {
  2732. status = QLA_ERROR;
  2733. goto out_match;
  2734. }
  2735. ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
  2736. } else {
  2737. ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
  2738. '\0', NULL);
  2739. if (ret == 0) {
  2740. status = QLA_ERROR;
  2741. goto out_match;
  2742. }
  2743. ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
  2744. }
  2745. if (strcmp(existing_ipaddr, formatted_ipaddr))
  2746. status = QLA_ERROR;
  2747. out_match:
  2748. return status;
  2749. }
  2750. static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
  2751. struct iscsi_cls_conn *cls_conn)
  2752. {
  2753. int idx = 0, max_ddbs, rval;
  2754. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  2755. struct iscsi_session *sess, *existing_sess;
  2756. struct iscsi_conn *conn, *existing_conn;
  2757. struct ddb_entry *ddb_entry;
  2758. sess = cls_sess->dd_data;
  2759. conn = cls_conn->dd_data;
  2760. if (sess->targetname == NULL ||
  2761. conn->persistent_address == NULL ||
  2762. conn->persistent_port == 0)
  2763. return QLA_ERROR;
  2764. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  2765. MAX_DEV_DB_ENTRIES;
  2766. for (idx = 0; idx < max_ddbs; idx++) {
  2767. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  2768. if (ddb_entry == NULL)
  2769. continue;
  2770. if (ddb_entry->ddb_type != FLASH_DDB)
  2771. continue;
  2772. existing_sess = ddb_entry->sess->dd_data;
  2773. existing_conn = ddb_entry->conn->dd_data;
  2774. if (existing_sess->targetname == NULL ||
  2775. existing_conn->persistent_address == NULL ||
  2776. existing_conn->persistent_port == 0)
  2777. continue;
  2778. DEBUG2(ql4_printk(KERN_INFO, ha,
  2779. "IQN = %s User IQN = %s\n",
  2780. existing_sess->targetname,
  2781. sess->targetname));
  2782. DEBUG2(ql4_printk(KERN_INFO, ha,
  2783. "IP = %s User IP = %s\n",
  2784. existing_conn->persistent_address,
  2785. conn->persistent_address));
  2786. DEBUG2(ql4_printk(KERN_INFO, ha,
  2787. "Port = %d User Port = %d\n",
  2788. existing_conn->persistent_port,
  2789. conn->persistent_port));
  2790. if (strcmp(existing_sess->targetname, sess->targetname))
  2791. continue;
  2792. rval = qla4xxx_match_ipaddress(ha, ddb_entry,
  2793. existing_conn->persistent_address,
  2794. conn->persistent_address);
  2795. if (rval == QLA_ERROR)
  2796. continue;
  2797. if (existing_conn->persistent_port != conn->persistent_port)
  2798. continue;
  2799. break;
  2800. }
  2801. if (idx == max_ddbs)
  2802. return QLA_ERROR;
  2803. DEBUG2(ql4_printk(KERN_INFO, ha,
  2804. "Match found in fwdb sessions\n"));
  2805. return QLA_SUCCESS;
  2806. }
  2807. static struct iscsi_cls_session *
  2808. qla4xxx_session_create(struct iscsi_endpoint *ep,
  2809. uint16_t cmds_max, uint16_t qdepth,
  2810. uint32_t initial_cmdsn)
  2811. {
  2812. struct iscsi_cls_session *cls_sess;
  2813. struct scsi_qla_host *ha;
  2814. struct qla_endpoint *qla_ep;
  2815. struct ddb_entry *ddb_entry;
  2816. uint16_t ddb_index;
  2817. struct iscsi_session *sess;
  2818. struct sockaddr *dst_addr;
  2819. int ret;
  2820. if (!ep) {
  2821. printk(KERN_ERR "qla4xxx: missing ep.\n");
  2822. return NULL;
  2823. }
  2824. qla_ep = ep->dd_data;
  2825. dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
  2826. ha = to_qla_host(qla_ep->host);
  2827. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  2828. ha->host_no));
  2829. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  2830. if (ret == QLA_ERROR)
  2831. return NULL;
  2832. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
  2833. cmds_max, sizeof(struct ddb_entry),
  2834. sizeof(struct ql4_task_data),
  2835. initial_cmdsn, ddb_index);
  2836. if (!cls_sess)
  2837. return NULL;
  2838. sess = cls_sess->dd_data;
  2839. ddb_entry = sess->dd_data;
  2840. ddb_entry->fw_ddb_index = ddb_index;
  2841. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  2842. ddb_entry->ha = ha;
  2843. ddb_entry->sess = cls_sess;
  2844. ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
  2845. ddb_entry->ddb_change = qla4xxx_ddb_change;
  2846. clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags);
  2847. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  2848. ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
  2849. ha->tot_ddbs++;
  2850. return cls_sess;
  2851. }
  2852. static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
  2853. {
  2854. struct iscsi_session *sess;
  2855. struct ddb_entry *ddb_entry;
  2856. struct scsi_qla_host *ha;
  2857. unsigned long flags, wtime;
  2858. struct dev_db_entry *fw_ddb_entry = NULL;
  2859. dma_addr_t fw_ddb_entry_dma;
  2860. uint32_t ddb_state;
  2861. int ret;
  2862. sess = cls_sess->dd_data;
  2863. ddb_entry = sess->dd_data;
  2864. ha = ddb_entry->ha;
  2865. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
  2866. ha->host_no));
  2867. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2868. &fw_ddb_entry_dma, GFP_KERNEL);
  2869. if (!fw_ddb_entry) {
  2870. ql4_printk(KERN_ERR, ha,
  2871. "%s: Unable to allocate dma buffer\n", __func__);
  2872. goto destroy_session;
  2873. }
  2874. wtime = jiffies + (HZ * LOGOUT_TOV);
  2875. do {
  2876. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  2877. fw_ddb_entry, fw_ddb_entry_dma,
  2878. NULL, NULL, &ddb_state, NULL,
  2879. NULL, NULL);
  2880. if (ret == QLA_ERROR)
  2881. goto destroy_session;
  2882. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  2883. (ddb_state == DDB_DS_SESSION_FAILED))
  2884. goto destroy_session;
  2885. schedule_timeout_uninterruptible(HZ);
  2886. } while ((time_after(wtime, jiffies)));
  2887. destroy_session:
  2888. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  2889. if (test_and_clear_bit(DDB_CONN_CLOSE_FAILURE, &ddb_entry->flags))
  2890. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  2891. spin_lock_irqsave(&ha->hardware_lock, flags);
  2892. qla4xxx_free_ddb(ha, ddb_entry);
  2893. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2894. iscsi_session_teardown(cls_sess);
  2895. if (fw_ddb_entry)
  2896. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2897. fw_ddb_entry, fw_ddb_entry_dma);
  2898. }
  2899. static struct iscsi_cls_conn *
  2900. qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
  2901. {
  2902. struct iscsi_cls_conn *cls_conn;
  2903. struct iscsi_session *sess;
  2904. struct ddb_entry *ddb_entry;
  2905. struct scsi_qla_host *ha;
  2906. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
  2907. conn_idx);
  2908. if (!cls_conn) {
  2909. pr_info("%s: Can not create connection for conn_idx = %u\n",
  2910. __func__, conn_idx);
  2911. return NULL;
  2912. }
  2913. sess = cls_sess->dd_data;
  2914. ddb_entry = sess->dd_data;
  2915. ddb_entry->conn = cls_conn;
  2916. ha = ddb_entry->ha;
  2917. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: conn_idx = %u\n", __func__,
  2918. conn_idx));
  2919. return cls_conn;
  2920. }
  2921. static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
  2922. struct iscsi_cls_conn *cls_conn,
  2923. uint64_t transport_fd, int is_leading)
  2924. {
  2925. struct iscsi_conn *conn;
  2926. struct qla_conn *qla_conn;
  2927. struct iscsi_endpoint *ep;
  2928. struct ddb_entry *ddb_entry;
  2929. struct scsi_qla_host *ha;
  2930. struct iscsi_session *sess;
  2931. sess = cls_session->dd_data;
  2932. ddb_entry = sess->dd_data;
  2933. ha = ddb_entry->ha;
  2934. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
  2935. cls_session->sid, cls_conn->cid));
  2936. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  2937. return -EINVAL;
  2938. ep = iscsi_lookup_endpoint(transport_fd);
  2939. conn = cls_conn->dd_data;
  2940. qla_conn = conn->dd_data;
  2941. qla_conn->qla_ep = ep->dd_data;
  2942. return 0;
  2943. }
  2944. static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
  2945. {
  2946. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  2947. struct iscsi_session *sess;
  2948. struct ddb_entry *ddb_entry;
  2949. struct scsi_qla_host *ha;
  2950. struct dev_db_entry *fw_ddb_entry = NULL;
  2951. dma_addr_t fw_ddb_entry_dma;
  2952. uint32_t mbx_sts = 0;
  2953. int ret = 0;
  2954. int status = QLA_SUCCESS;
  2955. sess = cls_sess->dd_data;
  2956. ddb_entry = sess->dd_data;
  2957. ha = ddb_entry->ha;
  2958. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: sid = %d, cid = %d\n", __func__,
  2959. cls_sess->sid, cls_conn->cid));
  2960. /* Check if we have matching FW DDB, if yes then do not
  2961. * login to this target. This could cause target to logout previous
  2962. * connection
  2963. */
  2964. ret = qla4xxx_match_fwdb_session(ha, cls_conn);
  2965. if (ret == QLA_SUCCESS) {
  2966. ql4_printk(KERN_INFO, ha,
  2967. "Session already exist in FW.\n");
  2968. ret = -EEXIST;
  2969. goto exit_conn_start;
  2970. }
  2971. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  2972. &fw_ddb_entry_dma, GFP_KERNEL);
  2973. if (!fw_ddb_entry) {
  2974. ql4_printk(KERN_ERR, ha,
  2975. "%s: Unable to allocate dma buffer\n", __func__);
  2976. ret = -ENOMEM;
  2977. goto exit_conn_start;
  2978. }
  2979. ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
  2980. if (ret) {
  2981. /* If iscsid is stopped and started then no need to do
  2982. * set param again since ddb state will be already
  2983. * active and FW does not allow set ddb to an
  2984. * active session.
  2985. */
  2986. if (mbx_sts)
  2987. if (ddb_entry->fw_ddb_device_state ==
  2988. DDB_DS_SESSION_ACTIVE) {
  2989. ddb_entry->unblock_sess(ddb_entry->sess);
  2990. goto exit_set_param;
  2991. }
  2992. ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
  2993. __func__, ddb_entry->fw_ddb_index);
  2994. goto exit_conn_start;
  2995. }
  2996. status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
  2997. if (status == QLA_ERROR) {
  2998. ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
  2999. sess->targetname);
  3000. ret = -EINVAL;
  3001. goto exit_conn_start;
  3002. }
  3003. if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
  3004. ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
  3005. DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
  3006. ddb_entry->fw_ddb_device_state));
  3007. exit_set_param:
  3008. ret = 0;
  3009. exit_conn_start:
  3010. if (fw_ddb_entry)
  3011. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3012. fw_ddb_entry, fw_ddb_entry_dma);
  3013. return ret;
  3014. }
  3015. static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
  3016. {
  3017. struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
  3018. struct iscsi_session *sess;
  3019. struct scsi_qla_host *ha;
  3020. struct ddb_entry *ddb_entry;
  3021. int options;
  3022. sess = cls_sess->dd_data;
  3023. ddb_entry = sess->dd_data;
  3024. ha = ddb_entry->ha;
  3025. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: cid = %d\n", __func__,
  3026. cls_conn->cid));
  3027. options = LOGOUT_OPTION_CLOSE_SESSION;
  3028. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
  3029. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  3030. }
  3031. static void qla4xxx_task_work(struct work_struct *wdata)
  3032. {
  3033. struct ql4_task_data *task_data;
  3034. struct scsi_qla_host *ha;
  3035. struct passthru_status *sts;
  3036. struct iscsi_task *task;
  3037. struct iscsi_hdr *hdr;
  3038. uint8_t *data;
  3039. uint32_t data_len;
  3040. struct iscsi_conn *conn;
  3041. int hdr_len;
  3042. itt_t itt;
  3043. task_data = container_of(wdata, struct ql4_task_data, task_work);
  3044. ha = task_data->ha;
  3045. task = task_data->task;
  3046. sts = &task_data->sts;
  3047. hdr_len = sizeof(struct iscsi_hdr);
  3048. DEBUG3(printk(KERN_INFO "Status returned\n"));
  3049. DEBUG3(qla4xxx_dump_buffer(sts, 64));
  3050. DEBUG3(printk(KERN_INFO "Response buffer"));
  3051. DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
  3052. conn = task->conn;
  3053. switch (sts->completionStatus) {
  3054. case PASSTHRU_STATUS_COMPLETE:
  3055. hdr = (struct iscsi_hdr *)task_data->resp_buffer;
  3056. /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
  3057. itt = sts->handle;
  3058. hdr->itt = itt;
  3059. data = task_data->resp_buffer + hdr_len;
  3060. data_len = task_data->resp_len - hdr_len;
  3061. iscsi_complete_pdu(conn, hdr, data, data_len);
  3062. break;
  3063. default:
  3064. ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
  3065. sts->completionStatus);
  3066. break;
  3067. }
  3068. return;
  3069. }
  3070. static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
  3071. {
  3072. struct ql4_task_data *task_data;
  3073. struct iscsi_session *sess;
  3074. struct ddb_entry *ddb_entry;
  3075. struct scsi_qla_host *ha;
  3076. int hdr_len;
  3077. sess = task->conn->session;
  3078. ddb_entry = sess->dd_data;
  3079. ha = ddb_entry->ha;
  3080. task_data = task->dd_data;
  3081. memset(task_data, 0, sizeof(struct ql4_task_data));
  3082. if (task->sc) {
  3083. ql4_printk(KERN_INFO, ha,
  3084. "%s: SCSI Commands not implemented\n", __func__);
  3085. return -EINVAL;
  3086. }
  3087. hdr_len = sizeof(struct iscsi_hdr);
  3088. task_data->ha = ha;
  3089. task_data->task = task;
  3090. if (task->data_count) {
  3091. task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
  3092. task->data_count,
  3093. PCI_DMA_TODEVICE);
  3094. }
  3095. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  3096. __func__, task->conn->max_recv_dlength, hdr_len));
  3097. task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
  3098. task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
  3099. task_data->resp_len,
  3100. &task_data->resp_dma,
  3101. GFP_ATOMIC);
  3102. if (!task_data->resp_buffer)
  3103. goto exit_alloc_pdu;
  3104. task_data->req_len = task->data_count + hdr_len;
  3105. task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
  3106. task_data->req_len,
  3107. &task_data->req_dma,
  3108. GFP_ATOMIC);
  3109. if (!task_data->req_buffer)
  3110. goto exit_alloc_pdu;
  3111. task->hdr = task_data->req_buffer;
  3112. INIT_WORK(&task_data->task_work, qla4xxx_task_work);
  3113. return 0;
  3114. exit_alloc_pdu:
  3115. if (task_data->resp_buffer)
  3116. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  3117. task_data->resp_buffer, task_data->resp_dma);
  3118. if (task_data->req_buffer)
  3119. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  3120. task_data->req_buffer, task_data->req_dma);
  3121. return -ENOMEM;
  3122. }
  3123. static void qla4xxx_task_cleanup(struct iscsi_task *task)
  3124. {
  3125. struct ql4_task_data *task_data;
  3126. struct iscsi_session *sess;
  3127. struct ddb_entry *ddb_entry;
  3128. struct scsi_qla_host *ha;
  3129. int hdr_len;
  3130. hdr_len = sizeof(struct iscsi_hdr);
  3131. sess = task->conn->session;
  3132. ddb_entry = sess->dd_data;
  3133. ha = ddb_entry->ha;
  3134. task_data = task->dd_data;
  3135. if (task->data_count) {
  3136. dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
  3137. task->data_count, PCI_DMA_TODEVICE);
  3138. }
  3139. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
  3140. __func__, task->conn->max_recv_dlength, hdr_len));
  3141. dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
  3142. task_data->resp_buffer, task_data->resp_dma);
  3143. dma_free_coherent(&ha->pdev->dev, task_data->req_len,
  3144. task_data->req_buffer, task_data->req_dma);
  3145. return;
  3146. }
  3147. static int qla4xxx_task_xmit(struct iscsi_task *task)
  3148. {
  3149. struct scsi_cmnd *sc = task->sc;
  3150. struct iscsi_session *sess = task->conn->session;
  3151. struct ddb_entry *ddb_entry = sess->dd_data;
  3152. struct scsi_qla_host *ha = ddb_entry->ha;
  3153. if (!sc)
  3154. return qla4xxx_send_passthru0(task);
  3155. ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
  3156. __func__);
  3157. return -ENOSYS;
  3158. }
  3159. static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,
  3160. struct iscsi_bus_flash_conn *conn,
  3161. struct dev_db_entry *fw_ddb_entry)
  3162. {
  3163. unsigned long options = 0;
  3164. int rc = 0;
  3165. options = le16_to_cpu(fw_ddb_entry->options);
  3166. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  3167. if (test_bit(OPT_IPV6_DEVICE, &options)) {
  3168. rc = iscsi_switch_str_param(&sess->portal_type,
  3169. PORTAL_TYPE_IPV6);
  3170. if (rc)
  3171. goto exit_copy;
  3172. } else {
  3173. rc = iscsi_switch_str_param(&sess->portal_type,
  3174. PORTAL_TYPE_IPV4);
  3175. if (rc)
  3176. goto exit_copy;
  3177. }
  3178. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  3179. &options);
  3180. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  3181. sess->entry_state = test_bit(OPT_ENTRY_STATE, &options);
  3182. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  3183. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  3184. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  3185. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  3186. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  3187. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  3188. &options);
  3189. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  3190. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  3191. conn->snack_req_en = test_bit(ISCSIOPT_SNACK_REQ_EN, &options);
  3192. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  3193. &options);
  3194. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  3195. sess->discovery_auth_optional =
  3196. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  3197. if (test_bit(ISCSIOPT_ERL1, &options))
  3198. sess->erl |= BIT_1;
  3199. if (test_bit(ISCSIOPT_ERL0, &options))
  3200. sess->erl |= BIT_0;
  3201. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  3202. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  3203. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  3204. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  3205. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  3206. conn->tcp_timer_scale |= BIT_3;
  3207. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  3208. conn->tcp_timer_scale |= BIT_2;
  3209. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  3210. conn->tcp_timer_scale |= BIT_1;
  3211. conn->tcp_timer_scale >>= 1;
  3212. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  3213. options = le16_to_cpu(fw_ddb_entry->ip_options);
  3214. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  3215. conn->max_recv_dlength = BYTE_UNITS *
  3216. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  3217. conn->max_xmit_dlength = BYTE_UNITS *
  3218. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  3219. sess->first_burst = BYTE_UNITS *
  3220. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  3221. sess->max_burst = BYTE_UNITS *
  3222. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  3223. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  3224. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  3225. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  3226. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  3227. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  3228. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  3229. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  3230. conn->ipv6_flow_label = le16_to_cpu(fw_ddb_entry->ipv6_flow_lbl);
  3231. conn->keepalive_timeout = le16_to_cpu(fw_ddb_entry->ka_timeout);
  3232. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  3233. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  3234. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  3235. sess->discovery_parent_idx = le16_to_cpu(fw_ddb_entry->ddb_link);
  3236. sess->discovery_parent_type = le16_to_cpu(fw_ddb_entry->ddb_link);
  3237. sess->chap_out_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3238. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  3239. sess->default_taskmgmt_timeout =
  3240. le16_to_cpu(fw_ddb_entry->def_timeout);
  3241. conn->port = le16_to_cpu(fw_ddb_entry->port);
  3242. options = le16_to_cpu(fw_ddb_entry->options);
  3243. conn->ipaddress = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  3244. if (!conn->ipaddress) {
  3245. rc = -ENOMEM;
  3246. goto exit_copy;
  3247. }
  3248. conn->redirect_ipaddr = kzalloc(IPv6_ADDR_LEN, GFP_KERNEL);
  3249. if (!conn->redirect_ipaddr) {
  3250. rc = -ENOMEM;
  3251. goto exit_copy;
  3252. }
  3253. memcpy(conn->ipaddress, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  3254. memcpy(conn->redirect_ipaddr, fw_ddb_entry->tgt_addr, IPv6_ADDR_LEN);
  3255. if (test_bit(OPT_IPV6_DEVICE, &options)) {
  3256. conn->ipv6_traffic_class = fw_ddb_entry->ipv4_tos;
  3257. conn->link_local_ipv6_addr = kmemdup(
  3258. fw_ddb_entry->link_local_ipv6_addr,
  3259. IPv6_ADDR_LEN, GFP_KERNEL);
  3260. if (!conn->link_local_ipv6_addr) {
  3261. rc = -ENOMEM;
  3262. goto exit_copy;
  3263. }
  3264. } else {
  3265. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  3266. }
  3267. if (fw_ddb_entry->iscsi_name[0]) {
  3268. rc = iscsi_switch_str_param(&sess->targetname,
  3269. (char *)fw_ddb_entry->iscsi_name);
  3270. if (rc)
  3271. goto exit_copy;
  3272. }
  3273. if (fw_ddb_entry->iscsi_alias[0]) {
  3274. rc = iscsi_switch_str_param(&sess->targetalias,
  3275. (char *)fw_ddb_entry->iscsi_alias);
  3276. if (rc)
  3277. goto exit_copy;
  3278. }
  3279. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  3280. exit_copy:
  3281. return rc;
  3282. }
  3283. static int qla4xxx_copy_to_fwddb_param(struct iscsi_bus_flash_session *sess,
  3284. struct iscsi_bus_flash_conn *conn,
  3285. struct dev_db_entry *fw_ddb_entry)
  3286. {
  3287. uint16_t options;
  3288. int rc = 0;
  3289. options = le16_to_cpu(fw_ddb_entry->options);
  3290. SET_BITVAL(conn->is_fw_assigned_ipv6, options, BIT_11);
  3291. if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
  3292. options |= BIT_8;
  3293. else
  3294. options &= ~BIT_8;
  3295. SET_BITVAL(sess->auto_snd_tgt_disable, options, BIT_6);
  3296. SET_BITVAL(sess->discovery_sess, options, BIT_4);
  3297. SET_BITVAL(sess->entry_state, options, BIT_3);
  3298. fw_ddb_entry->options = cpu_to_le16(options);
  3299. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  3300. SET_BITVAL(conn->hdrdgst_en, options, BIT_13);
  3301. SET_BITVAL(conn->datadgst_en, options, BIT_12);
  3302. SET_BITVAL(sess->imm_data_en, options, BIT_11);
  3303. SET_BITVAL(sess->initial_r2t_en, options, BIT_10);
  3304. SET_BITVAL(sess->dataseq_inorder_en, options, BIT_9);
  3305. SET_BITVAL(sess->pdu_inorder_en, options, BIT_8);
  3306. SET_BITVAL(sess->chap_auth_en, options, BIT_7);
  3307. SET_BITVAL(conn->snack_req_en, options, BIT_6);
  3308. SET_BITVAL(sess->discovery_logout_en, options, BIT_5);
  3309. SET_BITVAL(sess->bidi_chap_en, options, BIT_4);
  3310. SET_BITVAL(sess->discovery_auth_optional, options, BIT_3);
  3311. SET_BITVAL(sess->erl & BIT_1, options, BIT_1);
  3312. SET_BITVAL(sess->erl & BIT_0, options, BIT_0);
  3313. fw_ddb_entry->iscsi_options = cpu_to_le16(options);
  3314. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  3315. SET_BITVAL(conn->tcp_timestamp_stat, options, BIT_6);
  3316. SET_BITVAL(conn->tcp_nagle_disable, options, BIT_5);
  3317. SET_BITVAL(conn->tcp_wsf_disable, options, BIT_4);
  3318. SET_BITVAL(conn->tcp_timer_scale & BIT_2, options, BIT_3);
  3319. SET_BITVAL(conn->tcp_timer_scale & BIT_1, options, BIT_2);
  3320. SET_BITVAL(conn->tcp_timer_scale & BIT_0, options, BIT_1);
  3321. SET_BITVAL(conn->tcp_timestamp_en, options, BIT_0);
  3322. fw_ddb_entry->tcp_options = cpu_to_le16(options);
  3323. options = le16_to_cpu(fw_ddb_entry->ip_options);
  3324. SET_BITVAL(conn->fragment_disable, options, BIT_4);
  3325. fw_ddb_entry->ip_options = cpu_to_le16(options);
  3326. fw_ddb_entry->iscsi_max_outsnd_r2t = cpu_to_le16(sess->max_r2t);
  3327. fw_ddb_entry->iscsi_max_rcv_data_seg_len =
  3328. cpu_to_le16(conn->max_recv_dlength / BYTE_UNITS);
  3329. fw_ddb_entry->iscsi_max_snd_data_seg_len =
  3330. cpu_to_le16(conn->max_xmit_dlength / BYTE_UNITS);
  3331. fw_ddb_entry->iscsi_first_burst_len =
  3332. cpu_to_le16(sess->first_burst / BYTE_UNITS);
  3333. fw_ddb_entry->iscsi_max_burst_len = cpu_to_le16(sess->max_burst /
  3334. BYTE_UNITS);
  3335. fw_ddb_entry->iscsi_def_time2wait = cpu_to_le16(sess->time2wait);
  3336. fw_ddb_entry->iscsi_def_time2retain = cpu_to_le16(sess->time2retain);
  3337. fw_ddb_entry->tgt_portal_grp = cpu_to_le16(sess->tpgt);
  3338. fw_ddb_entry->mss = cpu_to_le16(conn->max_segment_size);
  3339. fw_ddb_entry->tcp_xmt_wsf = (uint8_t) cpu_to_le32(conn->tcp_xmit_wsf);
  3340. fw_ddb_entry->tcp_rcv_wsf = (uint8_t) cpu_to_le32(conn->tcp_recv_wsf);
  3341. fw_ddb_entry->ipv6_flow_lbl = cpu_to_le16(conn->ipv6_flow_label);
  3342. fw_ddb_entry->ka_timeout = cpu_to_le16(conn->keepalive_timeout);
  3343. fw_ddb_entry->lcl_port = cpu_to_le16(conn->local_port);
  3344. fw_ddb_entry->stat_sn = cpu_to_le32(conn->statsn);
  3345. fw_ddb_entry->exp_stat_sn = cpu_to_le32(conn->exp_statsn);
  3346. fw_ddb_entry->ddb_link = cpu_to_le16(sess->discovery_parent_idx);
  3347. fw_ddb_entry->chap_tbl_idx = cpu_to_le16(sess->chap_out_idx);
  3348. fw_ddb_entry->tsid = cpu_to_le16(sess->tsid);
  3349. fw_ddb_entry->port = cpu_to_le16(conn->port);
  3350. fw_ddb_entry->def_timeout =
  3351. cpu_to_le16(sess->default_taskmgmt_timeout);
  3352. if (!strncmp(sess->portal_type, PORTAL_TYPE_IPV6, 4))
  3353. fw_ddb_entry->ipv4_tos = conn->ipv6_traffic_class;
  3354. else
  3355. fw_ddb_entry->ipv4_tos = conn->ipv4_tos;
  3356. if (conn->ipaddress)
  3357. memcpy(fw_ddb_entry->ip_addr, conn->ipaddress,
  3358. sizeof(fw_ddb_entry->ip_addr));
  3359. if (conn->redirect_ipaddr)
  3360. memcpy(fw_ddb_entry->tgt_addr, conn->redirect_ipaddr,
  3361. sizeof(fw_ddb_entry->tgt_addr));
  3362. if (conn->link_local_ipv6_addr)
  3363. memcpy(fw_ddb_entry->link_local_ipv6_addr,
  3364. conn->link_local_ipv6_addr,
  3365. sizeof(fw_ddb_entry->link_local_ipv6_addr));
  3366. if (sess->targetname)
  3367. memcpy(fw_ddb_entry->iscsi_name, sess->targetname,
  3368. sizeof(fw_ddb_entry->iscsi_name));
  3369. if (sess->targetalias)
  3370. memcpy(fw_ddb_entry->iscsi_alias, sess->targetalias,
  3371. sizeof(fw_ddb_entry->iscsi_alias));
  3372. COPY_ISID(fw_ddb_entry->isid, sess->isid);
  3373. return rc;
  3374. }
  3375. static void qla4xxx_copy_to_sess_conn_params(struct iscsi_conn *conn,
  3376. struct iscsi_session *sess,
  3377. struct dev_db_entry *fw_ddb_entry)
  3378. {
  3379. unsigned long options = 0;
  3380. uint16_t ddb_link;
  3381. uint16_t disc_parent;
  3382. char ip_addr[DDB_IPADDR_LEN];
  3383. options = le16_to_cpu(fw_ddb_entry->options);
  3384. conn->is_fw_assigned_ipv6 = test_bit(OPT_IS_FW_ASSIGNED_IPV6, &options);
  3385. sess->auto_snd_tgt_disable = test_bit(OPT_AUTO_SENDTGTS_DISABLE,
  3386. &options);
  3387. sess->discovery_sess = test_bit(OPT_DISC_SESSION, &options);
  3388. options = le16_to_cpu(fw_ddb_entry->iscsi_options);
  3389. conn->hdrdgst_en = test_bit(ISCSIOPT_HEADER_DIGEST_EN, &options);
  3390. conn->datadgst_en = test_bit(ISCSIOPT_DATA_DIGEST_EN, &options);
  3391. sess->imm_data_en = test_bit(ISCSIOPT_IMMEDIATE_DATA_EN, &options);
  3392. sess->initial_r2t_en = test_bit(ISCSIOPT_INITIAL_R2T_EN, &options);
  3393. sess->dataseq_inorder_en = test_bit(ISCSIOPT_DATA_SEQ_IN_ORDER,
  3394. &options);
  3395. sess->pdu_inorder_en = test_bit(ISCSIOPT_DATA_PDU_IN_ORDER, &options);
  3396. sess->chap_auth_en = test_bit(ISCSIOPT_CHAP_AUTH_EN, &options);
  3397. sess->discovery_logout_en = test_bit(ISCSIOPT_DISCOVERY_LOGOUT_EN,
  3398. &options);
  3399. sess->bidi_chap_en = test_bit(ISCSIOPT_BIDI_CHAP_EN, &options);
  3400. sess->discovery_auth_optional =
  3401. test_bit(ISCSIOPT_DISCOVERY_AUTH_OPTIONAL, &options);
  3402. if (test_bit(ISCSIOPT_ERL1, &options))
  3403. sess->erl |= BIT_1;
  3404. if (test_bit(ISCSIOPT_ERL0, &options))
  3405. sess->erl |= BIT_0;
  3406. options = le16_to_cpu(fw_ddb_entry->tcp_options);
  3407. conn->tcp_timestamp_stat = test_bit(TCPOPT_TIMESTAMP_STAT, &options);
  3408. conn->tcp_nagle_disable = test_bit(TCPOPT_NAGLE_DISABLE, &options);
  3409. conn->tcp_wsf_disable = test_bit(TCPOPT_WSF_DISABLE, &options);
  3410. if (test_bit(TCPOPT_TIMER_SCALE3, &options))
  3411. conn->tcp_timer_scale |= BIT_3;
  3412. if (test_bit(TCPOPT_TIMER_SCALE2, &options))
  3413. conn->tcp_timer_scale |= BIT_2;
  3414. if (test_bit(TCPOPT_TIMER_SCALE1, &options))
  3415. conn->tcp_timer_scale |= BIT_1;
  3416. conn->tcp_timer_scale >>= 1;
  3417. conn->tcp_timestamp_en = test_bit(TCPOPT_TIMESTAMP_EN, &options);
  3418. options = le16_to_cpu(fw_ddb_entry->ip_options);
  3419. conn->fragment_disable = test_bit(IPOPT_FRAGMENT_DISABLE, &options);
  3420. conn->max_recv_dlength = BYTE_UNITS *
  3421. le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
  3422. conn->max_xmit_dlength = BYTE_UNITS *
  3423. le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
  3424. sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
  3425. sess->first_burst = BYTE_UNITS *
  3426. le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
  3427. sess->max_burst = BYTE_UNITS *
  3428. le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
  3429. sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  3430. sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
  3431. sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  3432. conn->max_segment_size = le16_to_cpu(fw_ddb_entry->mss);
  3433. conn->tcp_xmit_wsf = fw_ddb_entry->tcp_xmt_wsf;
  3434. conn->tcp_recv_wsf = fw_ddb_entry->tcp_rcv_wsf;
  3435. conn->ipv4_tos = fw_ddb_entry->ipv4_tos;
  3436. conn->keepalive_tmo = le16_to_cpu(fw_ddb_entry->ka_timeout);
  3437. conn->local_port = le16_to_cpu(fw_ddb_entry->lcl_port);
  3438. conn->statsn = le32_to_cpu(fw_ddb_entry->stat_sn);
  3439. conn->exp_statsn = le32_to_cpu(fw_ddb_entry->exp_stat_sn);
  3440. sess->tsid = le16_to_cpu(fw_ddb_entry->tsid);
  3441. COPY_ISID(sess->isid, fw_ddb_entry->isid);
  3442. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  3443. if (ddb_link == DDB_ISNS)
  3444. disc_parent = ISCSI_DISC_PARENT_ISNS;
  3445. else if (ddb_link == DDB_NO_LINK)
  3446. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  3447. else if (ddb_link < MAX_DDB_ENTRIES)
  3448. disc_parent = ISCSI_DISC_PARENT_SENDTGT;
  3449. else
  3450. disc_parent = ISCSI_DISC_PARENT_UNKNOWN;
  3451. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_DISCOVERY_PARENT_TYPE,
  3452. iscsi_get_discovery_parent_name(disc_parent), 0);
  3453. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_TARGET_ALIAS,
  3454. (char *)fw_ddb_entry->iscsi_alias, 0);
  3455. options = le16_to_cpu(fw_ddb_entry->options);
  3456. if (options & DDB_OPT_IPV6_DEVICE) {
  3457. memset(ip_addr, 0, sizeof(ip_addr));
  3458. sprintf(ip_addr, "%pI6", fw_ddb_entry->link_local_ipv6_addr);
  3459. iscsi_set_param(conn->cls_conn, ISCSI_PARAM_LOCAL_IPADDR,
  3460. (char *)ip_addr, 0);
  3461. }
  3462. }
  3463. static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
  3464. struct dev_db_entry *fw_ddb_entry,
  3465. struct iscsi_cls_session *cls_sess,
  3466. struct iscsi_cls_conn *cls_conn)
  3467. {
  3468. int buflen = 0;
  3469. struct iscsi_session *sess;
  3470. struct ddb_entry *ddb_entry;
  3471. struct ql4_chap_table chap_tbl;
  3472. struct iscsi_conn *conn;
  3473. char ip_addr[DDB_IPADDR_LEN];
  3474. uint16_t options = 0;
  3475. sess = cls_sess->dd_data;
  3476. ddb_entry = sess->dd_data;
  3477. conn = cls_conn->dd_data;
  3478. memset(&chap_tbl, 0, sizeof(chap_tbl));
  3479. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3480. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  3481. sess->def_taskmgmt_tmo = le16_to_cpu(fw_ddb_entry->def_timeout);
  3482. conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
  3483. memset(ip_addr, 0, sizeof(ip_addr));
  3484. options = le16_to_cpu(fw_ddb_entry->options);
  3485. if (options & DDB_OPT_IPV6_DEVICE) {
  3486. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv6", 4);
  3487. memset(ip_addr, 0, sizeof(ip_addr));
  3488. sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  3489. } else {
  3490. iscsi_set_param(cls_conn, ISCSI_PARAM_PORTAL_TYPE, "ipv4", 4);
  3491. sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  3492. }
  3493. iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
  3494. (char *)ip_addr, buflen);
  3495. iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
  3496. (char *)fw_ddb_entry->iscsi_name, buflen);
  3497. iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
  3498. (char *)ha->name_string, buflen);
  3499. if (ddb_entry->chap_tbl_idx != INVALID_ENTRY) {
  3500. if (!qla4xxx_get_uni_chap_at_index(ha, chap_tbl.name,
  3501. chap_tbl.secret,
  3502. ddb_entry->chap_tbl_idx)) {
  3503. iscsi_set_param(cls_conn, ISCSI_PARAM_USERNAME,
  3504. (char *)chap_tbl.name,
  3505. strlen((char *)chap_tbl.name));
  3506. iscsi_set_param(cls_conn, ISCSI_PARAM_PASSWORD,
  3507. (char *)chap_tbl.secret,
  3508. chap_tbl.secret_len);
  3509. }
  3510. }
  3511. }
  3512. void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
  3513. struct ddb_entry *ddb_entry)
  3514. {
  3515. struct iscsi_cls_session *cls_sess;
  3516. struct iscsi_cls_conn *cls_conn;
  3517. uint32_t ddb_state;
  3518. dma_addr_t fw_ddb_entry_dma;
  3519. struct dev_db_entry *fw_ddb_entry;
  3520. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3521. &fw_ddb_entry_dma, GFP_KERNEL);
  3522. if (!fw_ddb_entry) {
  3523. ql4_printk(KERN_ERR, ha,
  3524. "%s: Unable to allocate dma buffer\n", __func__);
  3525. goto exit_session_conn_fwddb_param;
  3526. }
  3527. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  3528. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  3529. NULL, NULL, NULL) == QLA_ERROR) {
  3530. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  3531. "get_ddb_entry for fw_ddb_index %d\n",
  3532. ha->host_no, __func__,
  3533. ddb_entry->fw_ddb_index));
  3534. goto exit_session_conn_fwddb_param;
  3535. }
  3536. cls_sess = ddb_entry->sess;
  3537. cls_conn = ddb_entry->conn;
  3538. /* Update params */
  3539. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  3540. exit_session_conn_fwddb_param:
  3541. if (fw_ddb_entry)
  3542. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3543. fw_ddb_entry, fw_ddb_entry_dma);
  3544. }
  3545. void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
  3546. struct ddb_entry *ddb_entry)
  3547. {
  3548. struct iscsi_cls_session *cls_sess;
  3549. struct iscsi_cls_conn *cls_conn;
  3550. struct iscsi_session *sess;
  3551. struct iscsi_conn *conn;
  3552. uint32_t ddb_state;
  3553. dma_addr_t fw_ddb_entry_dma;
  3554. struct dev_db_entry *fw_ddb_entry;
  3555. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3556. &fw_ddb_entry_dma, GFP_KERNEL);
  3557. if (!fw_ddb_entry) {
  3558. ql4_printk(KERN_ERR, ha,
  3559. "%s: Unable to allocate dma buffer\n", __func__);
  3560. goto exit_session_conn_param;
  3561. }
  3562. if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
  3563. fw_ddb_entry_dma, NULL, NULL, &ddb_state,
  3564. NULL, NULL, NULL) == QLA_ERROR) {
  3565. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
  3566. "get_ddb_entry for fw_ddb_index %d\n",
  3567. ha->host_no, __func__,
  3568. ddb_entry->fw_ddb_index));
  3569. goto exit_session_conn_param;
  3570. }
  3571. cls_sess = ddb_entry->sess;
  3572. sess = cls_sess->dd_data;
  3573. cls_conn = ddb_entry->conn;
  3574. conn = cls_conn->dd_data;
  3575. /* Update timers after login */
  3576. ddb_entry->default_relogin_timeout =
  3577. (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
  3578. (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
  3579. le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
  3580. ddb_entry->default_time2wait =
  3581. le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
  3582. /* Update params */
  3583. ddb_entry->chap_tbl_idx = le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  3584. qla4xxx_copy_to_sess_conn_params(conn, sess, fw_ddb_entry);
  3585. memcpy(sess->initiatorname, ha->name_string,
  3586. min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
  3587. exit_session_conn_param:
  3588. if (fw_ddb_entry)
  3589. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  3590. fw_ddb_entry, fw_ddb_entry_dma);
  3591. }
  3592. /*
  3593. * Timer routines
  3594. */
  3595. static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
  3596. unsigned long interval)
  3597. {
  3598. DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
  3599. __func__, ha->host->host_no));
  3600. init_timer(&ha->timer);
  3601. ha->timer.expires = jiffies + interval * HZ;
  3602. ha->timer.data = (unsigned long)ha;
  3603. ha->timer.function = (void (*)(unsigned long))func;
  3604. add_timer(&ha->timer);
  3605. ha->timer_active = 1;
  3606. }
  3607. static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
  3608. {
  3609. del_timer_sync(&ha->timer);
  3610. ha->timer_active = 0;
  3611. }
  3612. /***
  3613. * qla4xxx_mark_device_missing - blocks the session
  3614. * @cls_session: Pointer to the session to be blocked
  3615. * @ddb_entry: Pointer to device database entry
  3616. *
  3617. * This routine marks a device missing and close connection.
  3618. **/
  3619. void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
  3620. {
  3621. iscsi_block_session(cls_session);
  3622. }
  3623. /**
  3624. * qla4xxx_mark_all_devices_missing - mark all devices as missing.
  3625. * @ha: Pointer to host adapter structure.
  3626. *
  3627. * This routine marks a device missing and resets the relogin retry count.
  3628. **/
  3629. void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
  3630. {
  3631. iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
  3632. }
  3633. static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
  3634. struct ddb_entry *ddb_entry,
  3635. struct scsi_cmnd *cmd)
  3636. {
  3637. struct srb *srb;
  3638. srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  3639. if (!srb)
  3640. return srb;
  3641. kref_init(&srb->srb_ref);
  3642. srb->ha = ha;
  3643. srb->ddb = ddb_entry;
  3644. srb->cmd = cmd;
  3645. srb->flags = 0;
  3646. CMD_SP(cmd) = (void *)srb;
  3647. return srb;
  3648. }
  3649. static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
  3650. {
  3651. struct scsi_cmnd *cmd = srb->cmd;
  3652. if (srb->flags & SRB_DMA_VALID) {
  3653. scsi_dma_unmap(cmd);
  3654. srb->flags &= ~SRB_DMA_VALID;
  3655. }
  3656. CMD_SP(cmd) = NULL;
  3657. }
  3658. void qla4xxx_srb_compl(struct kref *ref)
  3659. {
  3660. struct srb *srb = container_of(ref, struct srb, srb_ref);
  3661. struct scsi_cmnd *cmd = srb->cmd;
  3662. struct scsi_qla_host *ha = srb->ha;
  3663. qla4xxx_srb_free_dma(ha, srb);
  3664. mempool_free(srb, ha->srb_mempool);
  3665. cmd->scsi_done(cmd);
  3666. }
  3667. /**
  3668. * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
  3669. * @host: scsi host
  3670. * @cmd: Pointer to Linux's SCSI command structure
  3671. *
  3672. * Remarks:
  3673. * This routine is invoked by Linux to send a SCSI command to the driver.
  3674. * The mid-level driver tries to ensure that queuecommand never gets
  3675. * invoked concurrently with itself or the interrupt handler (although
  3676. * the interrupt handler may call this routine as part of request-
  3677. * completion handling). Unfortunely, it sometimes calls the scheduler
  3678. * in interrupt context which is a big NO! NO!.
  3679. **/
  3680. static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  3681. {
  3682. struct scsi_qla_host *ha = to_qla_host(host);
  3683. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  3684. struct iscsi_cls_session *sess = ddb_entry->sess;
  3685. struct srb *srb;
  3686. int rval;
  3687. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  3688. if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
  3689. cmd->result = DID_NO_CONNECT << 16;
  3690. else
  3691. cmd->result = DID_REQUEUE << 16;
  3692. goto qc_fail_command;
  3693. }
  3694. if (!sess) {
  3695. cmd->result = DID_IMM_RETRY << 16;
  3696. goto qc_fail_command;
  3697. }
  3698. rval = iscsi_session_chkready(sess);
  3699. if (rval) {
  3700. cmd->result = rval;
  3701. goto qc_fail_command;
  3702. }
  3703. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  3704. test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  3705. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  3706. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  3707. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  3708. !test_bit(AF_ONLINE, &ha->flags) ||
  3709. !test_bit(AF_LINK_UP, &ha->flags) ||
  3710. test_bit(AF_LOOPBACK, &ha->flags) ||
  3711. test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags) ||
  3712. test_bit(DPC_RESTORE_ACB, &ha->dpc_flags) ||
  3713. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
  3714. goto qc_host_busy;
  3715. srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
  3716. if (!srb)
  3717. goto qc_host_busy;
  3718. rval = qla4xxx_send_command_to_isp(ha, srb);
  3719. if (rval != QLA_SUCCESS)
  3720. goto qc_host_busy_free_sp;
  3721. return 0;
  3722. qc_host_busy_free_sp:
  3723. qla4xxx_srb_free_dma(ha, srb);
  3724. mempool_free(srb, ha->srb_mempool);
  3725. qc_host_busy:
  3726. return SCSI_MLQUEUE_HOST_BUSY;
  3727. qc_fail_command:
  3728. cmd->scsi_done(cmd);
  3729. return 0;
  3730. }
  3731. /**
  3732. * qla4xxx_mem_free - frees memory allocated to adapter
  3733. * @ha: Pointer to host adapter structure.
  3734. *
  3735. * Frees memory previously allocated by qla4xxx_mem_alloc
  3736. **/
  3737. static void qla4xxx_mem_free(struct scsi_qla_host *ha)
  3738. {
  3739. if (ha->queues)
  3740. dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
  3741. ha->queues_dma);
  3742. if (ha->fw_dump)
  3743. vfree(ha->fw_dump);
  3744. ha->queues_len = 0;
  3745. ha->queues = NULL;
  3746. ha->queues_dma = 0;
  3747. ha->request_ring = NULL;
  3748. ha->request_dma = 0;
  3749. ha->response_ring = NULL;
  3750. ha->response_dma = 0;
  3751. ha->shadow_regs = NULL;
  3752. ha->shadow_regs_dma = 0;
  3753. ha->fw_dump = NULL;
  3754. ha->fw_dump_size = 0;
  3755. /* Free srb pool. */
  3756. if (ha->srb_mempool)
  3757. mempool_destroy(ha->srb_mempool);
  3758. ha->srb_mempool = NULL;
  3759. if (ha->chap_dma_pool)
  3760. dma_pool_destroy(ha->chap_dma_pool);
  3761. if (ha->chap_list)
  3762. vfree(ha->chap_list);
  3763. ha->chap_list = NULL;
  3764. if (ha->fw_ddb_dma_pool)
  3765. dma_pool_destroy(ha->fw_ddb_dma_pool);
  3766. /* release io space registers */
  3767. if (is_qla8022(ha)) {
  3768. if (ha->nx_pcibase)
  3769. iounmap(
  3770. (struct device_reg_82xx __iomem *)ha->nx_pcibase);
  3771. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3772. if (ha->nx_pcibase)
  3773. iounmap(
  3774. (struct device_reg_83xx __iomem *)ha->nx_pcibase);
  3775. } else if (ha->reg) {
  3776. iounmap(ha->reg);
  3777. }
  3778. if (ha->reset_tmplt.buff)
  3779. vfree(ha->reset_tmplt.buff);
  3780. pci_release_regions(ha->pdev);
  3781. }
  3782. /**
  3783. * qla4xxx_mem_alloc - allocates memory for use by adapter.
  3784. * @ha: Pointer to host adapter structure
  3785. *
  3786. * Allocates DMA memory for request and response queues. Also allocates memory
  3787. * for srbs.
  3788. **/
  3789. static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
  3790. {
  3791. unsigned long align;
  3792. /* Allocate contiguous block of DMA memory for queues. */
  3793. ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  3794. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
  3795. sizeof(struct shadow_regs) +
  3796. MEM_ALIGN_VALUE +
  3797. (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
  3798. ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
  3799. &ha->queues_dma, GFP_KERNEL);
  3800. if (ha->queues == NULL) {
  3801. ql4_printk(KERN_WARNING, ha,
  3802. "Memory Allocation failed - queues.\n");
  3803. goto mem_alloc_error_exit;
  3804. }
  3805. memset(ha->queues, 0, ha->queues_len);
  3806. /*
  3807. * As per RISC alignment requirements -- the bus-address must be a
  3808. * multiple of the request-ring size (in bytes).
  3809. */
  3810. align = 0;
  3811. if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
  3812. align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
  3813. (MEM_ALIGN_VALUE - 1));
  3814. /* Update request and response queue pointers. */
  3815. ha->request_dma = ha->queues_dma + align;
  3816. ha->request_ring = (struct queue_entry *) (ha->queues + align);
  3817. ha->response_dma = ha->queues_dma + align +
  3818. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
  3819. ha->response_ring = (struct queue_entry *) (ha->queues + align +
  3820. (REQUEST_QUEUE_DEPTH *
  3821. QUEUE_SIZE));
  3822. ha->shadow_regs_dma = ha->queues_dma + align +
  3823. (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
  3824. (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
  3825. ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
  3826. (REQUEST_QUEUE_DEPTH *
  3827. QUEUE_SIZE) +
  3828. (RESPONSE_QUEUE_DEPTH *
  3829. QUEUE_SIZE));
  3830. /* Allocate memory for srb pool. */
  3831. ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
  3832. mempool_free_slab, srb_cachep);
  3833. if (ha->srb_mempool == NULL) {
  3834. ql4_printk(KERN_WARNING, ha,
  3835. "Memory Allocation failed - SRB Pool.\n");
  3836. goto mem_alloc_error_exit;
  3837. }
  3838. ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
  3839. CHAP_DMA_BLOCK_SIZE, 8, 0);
  3840. if (ha->chap_dma_pool == NULL) {
  3841. ql4_printk(KERN_WARNING, ha,
  3842. "%s: chap_dma_pool allocation failed..\n", __func__);
  3843. goto mem_alloc_error_exit;
  3844. }
  3845. ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
  3846. DDB_DMA_BLOCK_SIZE, 8, 0);
  3847. if (ha->fw_ddb_dma_pool == NULL) {
  3848. ql4_printk(KERN_WARNING, ha,
  3849. "%s: fw_ddb_dma_pool allocation failed..\n",
  3850. __func__);
  3851. goto mem_alloc_error_exit;
  3852. }
  3853. return QLA_SUCCESS;
  3854. mem_alloc_error_exit:
  3855. qla4xxx_mem_free(ha);
  3856. return QLA_ERROR;
  3857. }
  3858. /**
  3859. * qla4_8xxx_check_temp - Check the ISP82XX temperature.
  3860. * @ha: adapter block pointer.
  3861. *
  3862. * Note: The caller should not hold the idc lock.
  3863. **/
  3864. static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
  3865. {
  3866. uint32_t temp, temp_state, temp_val;
  3867. int status = QLA_SUCCESS;
  3868. temp = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_TEMP_STATE);
  3869. temp_state = qla82xx_get_temp_state(temp);
  3870. temp_val = qla82xx_get_temp_val(temp);
  3871. if (temp_state == QLA82XX_TEMP_PANIC) {
  3872. ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
  3873. " exceeds maximum allowed. Hardware has been shut"
  3874. " down.\n", temp_val);
  3875. status = QLA_ERROR;
  3876. } else if (temp_state == QLA82XX_TEMP_WARN) {
  3877. if (ha->temperature == QLA82XX_TEMP_NORMAL)
  3878. ql4_printk(KERN_WARNING, ha, "Device temperature %d"
  3879. " degrees C exceeds operating range."
  3880. " Immediate action needed.\n", temp_val);
  3881. } else {
  3882. if (ha->temperature == QLA82XX_TEMP_WARN)
  3883. ql4_printk(KERN_INFO, ha, "Device temperature is"
  3884. " now %d degrees C in normal range.\n",
  3885. temp_val);
  3886. }
  3887. ha->temperature = temp_state;
  3888. return status;
  3889. }
  3890. /**
  3891. * qla4_8xxx_check_fw_alive - Check firmware health
  3892. * @ha: Pointer to host adapter structure.
  3893. *
  3894. * Context: Interrupt
  3895. **/
  3896. static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
  3897. {
  3898. uint32_t fw_heartbeat_counter;
  3899. int status = QLA_SUCCESS;
  3900. fw_heartbeat_counter = qla4_8xxx_rd_direct(ha,
  3901. QLA8XXX_PEG_ALIVE_COUNTER);
  3902. /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
  3903. if (fw_heartbeat_counter == 0xffffffff) {
  3904. DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
  3905. "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
  3906. ha->host_no, __func__));
  3907. return status;
  3908. }
  3909. if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
  3910. ha->seconds_since_last_heartbeat++;
  3911. /* FW not alive after 2 seconds */
  3912. if (ha->seconds_since_last_heartbeat == 2) {
  3913. ha->seconds_since_last_heartbeat = 0;
  3914. qla4_8xxx_dump_peg_reg(ha);
  3915. status = QLA_ERROR;
  3916. }
  3917. } else
  3918. ha->seconds_since_last_heartbeat = 0;
  3919. ha->fw_heartbeat_counter = fw_heartbeat_counter;
  3920. return status;
  3921. }
  3922. static void qla4_8xxx_process_fw_error(struct scsi_qla_host *ha)
  3923. {
  3924. uint32_t halt_status;
  3925. int halt_status_unrecoverable = 0;
  3926. halt_status = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
  3927. if (is_qla8022(ha)) {
  3928. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  3929. __func__);
  3930. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  3931. CRB_NIU_XG_PAUSE_CTL_P0 |
  3932. CRB_NIU_XG_PAUSE_CTL_P1);
  3933. if (QLA82XX_FWERROR_CODE(halt_status) == 0x67)
  3934. ql4_printk(KERN_ERR, ha, "%s: Firmware aborted with error code 0x00006700. Device is being reset\n",
  3935. __func__);
  3936. if (halt_status & HALT_STATUS_UNRECOVERABLE)
  3937. halt_status_unrecoverable = 1;
  3938. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  3939. if (halt_status & QLA83XX_HALT_STATUS_FW_RESET)
  3940. ql4_printk(KERN_ERR, ha, "%s: Firmware error detected device is being reset\n",
  3941. __func__);
  3942. else if (halt_status & QLA83XX_HALT_STATUS_UNRECOVERABLE)
  3943. halt_status_unrecoverable = 1;
  3944. }
  3945. /*
  3946. * Since we cannot change dev_state in interrupt context,
  3947. * set appropriate DPC flag then wakeup DPC
  3948. */
  3949. if (halt_status_unrecoverable) {
  3950. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  3951. } else {
  3952. ql4_printk(KERN_INFO, ha, "%s: detect abort needed!\n",
  3953. __func__);
  3954. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  3955. }
  3956. qla4xxx_mailbox_premature_completion(ha);
  3957. qla4xxx_wake_dpc(ha);
  3958. }
  3959. /**
  3960. * qla4_8xxx_watchdog - Poll dev state
  3961. * @ha: Pointer to host adapter structure.
  3962. *
  3963. * Context: Interrupt
  3964. **/
  3965. void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
  3966. {
  3967. uint32_t dev_state;
  3968. uint32_t idc_ctrl;
  3969. if (is_qla8032(ha) &&
  3970. (qla4_83xx_is_detached(ha) == QLA_SUCCESS))
  3971. WARN_ONCE(1, "%s: iSCSI function %d marked invisible\n",
  3972. __func__, ha->func_num);
  3973. /* don't poll if reset is going on */
  3974. if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
  3975. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  3976. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
  3977. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  3978. if (qla4_8xxx_check_temp(ha)) {
  3979. if (is_qla8022(ha)) {
  3980. ql4_printk(KERN_INFO, ha, "disabling pause transmit on port 0 & 1.\n");
  3981. qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
  3982. CRB_NIU_XG_PAUSE_CTL_P0 |
  3983. CRB_NIU_XG_PAUSE_CTL_P1);
  3984. }
  3985. set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
  3986. qla4xxx_wake_dpc(ha);
  3987. } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
  3988. !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  3989. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED RESET!\n",
  3990. __func__);
  3991. if (is_qla8032(ha) || is_qla8042(ha)) {
  3992. idc_ctrl = qla4_83xx_rd_reg(ha,
  3993. QLA83XX_IDC_DRV_CTRL);
  3994. if (!(idc_ctrl & GRACEFUL_RESET_BIT1)) {
  3995. ql4_printk(KERN_INFO, ha, "%s: Graceful reset bit is not set\n",
  3996. __func__);
  3997. qla4xxx_mailbox_premature_completion(
  3998. ha);
  3999. }
  4000. }
  4001. if ((is_qla8032(ha) || is_qla8042(ha)) ||
  4002. (is_qla8022(ha) && !ql4xdontresethba)) {
  4003. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  4004. qla4xxx_wake_dpc(ha);
  4005. }
  4006. } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
  4007. !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  4008. ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
  4009. __func__);
  4010. set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
  4011. qla4xxx_wake_dpc(ha);
  4012. } else {
  4013. /* Check firmware health */
  4014. if (qla4_8xxx_check_fw_alive(ha))
  4015. qla4_8xxx_process_fw_error(ha);
  4016. }
  4017. }
  4018. }
  4019. static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  4020. {
  4021. struct iscsi_session *sess;
  4022. struct ddb_entry *ddb_entry;
  4023. struct scsi_qla_host *ha;
  4024. sess = cls_sess->dd_data;
  4025. ddb_entry = sess->dd_data;
  4026. ha = ddb_entry->ha;
  4027. if (!(ddb_entry->ddb_type == FLASH_DDB))
  4028. return;
  4029. if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
  4030. !iscsi_is_session_online(cls_sess)) {
  4031. if (atomic_read(&ddb_entry->retry_relogin_timer) !=
  4032. INVALID_ENTRY) {
  4033. if (atomic_read(&ddb_entry->retry_relogin_timer) ==
  4034. 0) {
  4035. atomic_set(&ddb_entry->retry_relogin_timer,
  4036. INVALID_ENTRY);
  4037. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4038. set_bit(DF_RELOGIN, &ddb_entry->flags);
  4039. DEBUG2(ql4_printk(KERN_INFO, ha,
  4040. "%s: index [%d] login device\n",
  4041. __func__, ddb_entry->fw_ddb_index));
  4042. } else
  4043. atomic_dec(&ddb_entry->retry_relogin_timer);
  4044. }
  4045. }
  4046. /* Wait for relogin to timeout */
  4047. if (atomic_read(&ddb_entry->relogin_timer) &&
  4048. (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
  4049. /*
  4050. * If the relogin times out and the device is
  4051. * still NOT ONLINE then try and relogin again.
  4052. */
  4053. if (!iscsi_is_session_online(cls_sess)) {
  4054. /* Reset retry relogin timer */
  4055. atomic_inc(&ddb_entry->relogin_retry_count);
  4056. DEBUG2(ql4_printk(KERN_INFO, ha,
  4057. "%s: index[%d] relogin timed out-retrying"
  4058. " relogin (%d), retry (%d)\n", __func__,
  4059. ddb_entry->fw_ddb_index,
  4060. atomic_read(&ddb_entry->relogin_retry_count),
  4061. ddb_entry->default_time2wait + 4));
  4062. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  4063. atomic_set(&ddb_entry->retry_relogin_timer,
  4064. ddb_entry->default_time2wait + 4);
  4065. }
  4066. }
  4067. }
  4068. /**
  4069. * qla4xxx_timer - checks every second for work to do.
  4070. * @ha: Pointer to host adapter structure.
  4071. **/
  4072. static void qla4xxx_timer(struct scsi_qla_host *ha)
  4073. {
  4074. int start_dpc = 0;
  4075. uint16_t w;
  4076. iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
  4077. /* If we are in the middle of AER/EEH processing
  4078. * skip any processing and reschedule the timer
  4079. */
  4080. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  4081. mod_timer(&ha->timer, jiffies + HZ);
  4082. return;
  4083. }
  4084. /* Hardware read to trigger an EEH error during mailbox waits. */
  4085. if (!pci_channel_offline(ha->pdev))
  4086. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  4087. if (is_qla80XX(ha))
  4088. qla4_8xxx_watchdog(ha);
  4089. if (is_qla40XX(ha)) {
  4090. /* Check for heartbeat interval. */
  4091. if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
  4092. ha->heartbeat_interval != 0) {
  4093. ha->seconds_since_last_heartbeat++;
  4094. if (ha->seconds_since_last_heartbeat >
  4095. ha->heartbeat_interval + 2)
  4096. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  4097. }
  4098. }
  4099. /* Process any deferred work. */
  4100. if (!list_empty(&ha->work_list))
  4101. start_dpc++;
  4102. /* Wakeup the dpc routine for this adapter, if needed. */
  4103. if (start_dpc ||
  4104. test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  4105. test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
  4106. test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
  4107. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  4108. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  4109. test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
  4110. test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
  4111. test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
  4112. test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
  4113. test_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags) ||
  4114. test_bit(DPC_AEN, &ha->dpc_flags)) {
  4115. DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
  4116. " - dpc flags = 0x%lx\n",
  4117. ha->host_no, __func__, ha->dpc_flags));
  4118. qla4xxx_wake_dpc(ha);
  4119. }
  4120. /* Reschedule timer thread to call us back in one second */
  4121. mod_timer(&ha->timer, jiffies + HZ);
  4122. DEBUG2(ha->seconds_since_last_intr++);
  4123. }
  4124. /**
  4125. * qla4xxx_cmd_wait - waits for all outstanding commands to complete
  4126. * @ha: Pointer to host adapter structure.
  4127. *
  4128. * This routine stalls the driver until all outstanding commands are returned.
  4129. * Caller must release the Hardware Lock prior to calling this routine.
  4130. **/
  4131. static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
  4132. {
  4133. uint32_t index = 0;
  4134. unsigned long flags;
  4135. struct scsi_cmnd *cmd;
  4136. unsigned long wtime;
  4137. uint32_t wtmo;
  4138. if (is_qla40XX(ha))
  4139. wtmo = WAIT_CMD_TOV;
  4140. else
  4141. wtmo = ha->nx_reset_timeout / 2;
  4142. wtime = jiffies + (wtmo * HZ);
  4143. DEBUG2(ql4_printk(KERN_INFO, ha,
  4144. "Wait up to %u seconds for cmds to complete\n",
  4145. wtmo));
  4146. while (!time_after_eq(jiffies, wtime)) {
  4147. spin_lock_irqsave(&ha->hardware_lock, flags);
  4148. /* Find a command that hasn't completed. */
  4149. for (index = 0; index < ha->host->can_queue; index++) {
  4150. cmd = scsi_host_find_tag(ha->host, index);
  4151. /*
  4152. * We cannot just check if the index is valid,
  4153. * becase if we are run from the scsi eh, then
  4154. * the scsi/block layer is going to prevent
  4155. * the tag from being released.
  4156. */
  4157. if (cmd != NULL && CMD_SP(cmd))
  4158. break;
  4159. }
  4160. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4161. /* If No Commands are pending, wait is complete */
  4162. if (index == ha->host->can_queue)
  4163. return QLA_SUCCESS;
  4164. msleep(1000);
  4165. }
  4166. /* If we timed out on waiting for commands to come back
  4167. * return ERROR. */
  4168. return QLA_ERROR;
  4169. }
  4170. int qla4xxx_hw_reset(struct scsi_qla_host *ha)
  4171. {
  4172. uint32_t ctrl_status;
  4173. unsigned long flags = 0;
  4174. DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
  4175. if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
  4176. return QLA_ERROR;
  4177. spin_lock_irqsave(&ha->hardware_lock, flags);
  4178. /*
  4179. * If the SCSI Reset Interrupt bit is set, clear it.
  4180. * Otherwise, the Soft Reset won't work.
  4181. */
  4182. ctrl_status = readw(&ha->reg->ctrl_status);
  4183. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
  4184. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  4185. /* Issue Soft Reset */
  4186. writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
  4187. readl(&ha->reg->ctrl_status);
  4188. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4189. return QLA_SUCCESS;
  4190. }
  4191. /**
  4192. * qla4xxx_soft_reset - performs soft reset.
  4193. * @ha: Pointer to host adapter structure.
  4194. **/
  4195. int qla4xxx_soft_reset(struct scsi_qla_host *ha)
  4196. {
  4197. uint32_t max_wait_time;
  4198. unsigned long flags = 0;
  4199. int status;
  4200. uint32_t ctrl_status;
  4201. status = qla4xxx_hw_reset(ha);
  4202. if (status != QLA_SUCCESS)
  4203. return status;
  4204. status = QLA_ERROR;
  4205. /* Wait until the Network Reset Intr bit is cleared */
  4206. max_wait_time = RESET_INTR_TOV;
  4207. do {
  4208. spin_lock_irqsave(&ha->hardware_lock, flags);
  4209. ctrl_status = readw(&ha->reg->ctrl_status);
  4210. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4211. if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
  4212. break;
  4213. msleep(1000);
  4214. } while ((--max_wait_time));
  4215. if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
  4216. DEBUG2(printk(KERN_WARNING
  4217. "scsi%ld: Network Reset Intr not cleared by "
  4218. "Network function, clearing it now!\n",
  4219. ha->host_no));
  4220. spin_lock_irqsave(&ha->hardware_lock, flags);
  4221. writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
  4222. readl(&ha->reg->ctrl_status);
  4223. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4224. }
  4225. /* Wait until the firmware tells us the Soft Reset is done */
  4226. max_wait_time = SOFT_RESET_TOV;
  4227. do {
  4228. spin_lock_irqsave(&ha->hardware_lock, flags);
  4229. ctrl_status = readw(&ha->reg->ctrl_status);
  4230. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4231. if ((ctrl_status & CSR_SOFT_RESET) == 0) {
  4232. status = QLA_SUCCESS;
  4233. break;
  4234. }
  4235. msleep(1000);
  4236. } while ((--max_wait_time));
  4237. /*
  4238. * Also, make sure that the SCSI Reset Interrupt bit has been cleared
  4239. * after the soft reset has taken place.
  4240. */
  4241. spin_lock_irqsave(&ha->hardware_lock, flags);
  4242. ctrl_status = readw(&ha->reg->ctrl_status);
  4243. if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
  4244. writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
  4245. readl(&ha->reg->ctrl_status);
  4246. }
  4247. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4248. /* If soft reset fails then most probably the bios on other
  4249. * function is also enabled.
  4250. * Since the initialization is sequential the other fn
  4251. * wont be able to acknowledge the soft reset.
  4252. * Issue a force soft reset to workaround this scenario.
  4253. */
  4254. if (max_wait_time == 0) {
  4255. /* Issue Force Soft Reset */
  4256. spin_lock_irqsave(&ha->hardware_lock, flags);
  4257. writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
  4258. readl(&ha->reg->ctrl_status);
  4259. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4260. /* Wait until the firmware tells us the Soft Reset is done */
  4261. max_wait_time = SOFT_RESET_TOV;
  4262. do {
  4263. spin_lock_irqsave(&ha->hardware_lock, flags);
  4264. ctrl_status = readw(&ha->reg->ctrl_status);
  4265. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4266. if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
  4267. status = QLA_SUCCESS;
  4268. break;
  4269. }
  4270. msleep(1000);
  4271. } while ((--max_wait_time));
  4272. }
  4273. return status;
  4274. }
  4275. /**
  4276. * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
  4277. * @ha: Pointer to host adapter structure.
  4278. * @res: returned scsi status
  4279. *
  4280. * This routine is called just prior to a HARD RESET to return all
  4281. * outstanding commands back to the Operating System.
  4282. * Caller should make sure that the following locks are released
  4283. * before this calling routine: Hardware lock, and io_request_lock.
  4284. **/
  4285. static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
  4286. {
  4287. struct srb *srb;
  4288. int i;
  4289. unsigned long flags;
  4290. spin_lock_irqsave(&ha->hardware_lock, flags);
  4291. for (i = 0; i < ha->host->can_queue; i++) {
  4292. srb = qla4xxx_del_from_active_array(ha, i);
  4293. if (srb != NULL) {
  4294. srb->cmd->result = res;
  4295. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  4296. }
  4297. }
  4298. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4299. }
  4300. void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
  4301. {
  4302. clear_bit(AF_ONLINE, &ha->flags);
  4303. /* Disable the board */
  4304. ql4_printk(KERN_INFO, ha, "Disabling the board\n");
  4305. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  4306. qla4xxx_mark_all_devices_missing(ha);
  4307. clear_bit(AF_INIT_DONE, &ha->flags);
  4308. }
  4309. static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
  4310. {
  4311. struct iscsi_session *sess;
  4312. struct ddb_entry *ddb_entry;
  4313. sess = cls_session->dd_data;
  4314. ddb_entry = sess->dd_data;
  4315. ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
  4316. if (ddb_entry->ddb_type == FLASH_DDB)
  4317. iscsi_block_session(ddb_entry->sess);
  4318. else
  4319. iscsi_session_failure(cls_session->dd_data,
  4320. ISCSI_ERR_CONN_FAILED);
  4321. }
  4322. /**
  4323. * qla4xxx_recover_adapter - recovers adapter after a fatal error
  4324. * @ha: Pointer to host adapter structure.
  4325. **/
  4326. static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
  4327. {
  4328. int status = QLA_ERROR;
  4329. uint8_t reset_chip = 0;
  4330. uint32_t dev_state;
  4331. unsigned long wait;
  4332. /* Stall incoming I/O until we are done */
  4333. scsi_block_requests(ha->host);
  4334. clear_bit(AF_ONLINE, &ha->flags);
  4335. clear_bit(AF_LINK_UP, &ha->flags);
  4336. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
  4337. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  4338. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  4339. !test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  4340. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  4341. __func__);
  4342. /* disable pause frame for ISP83xx */
  4343. qla4_83xx_disable_pause(ha);
  4344. }
  4345. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  4346. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  4347. reset_chip = 1;
  4348. /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
  4349. * do not reset adapter, jump to initialize_adapter */
  4350. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  4351. status = QLA_SUCCESS;
  4352. goto recover_ha_init_adapter;
  4353. }
  4354. /* For the ISP-8xxx adapter, issue a stop_firmware if invoked
  4355. * from eh_host_reset or ioctl module */
  4356. if (is_qla80XX(ha) && !reset_chip &&
  4357. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
  4358. DEBUG2(ql4_printk(KERN_INFO, ha,
  4359. "scsi%ld: %s - Performing stop_firmware...\n",
  4360. ha->host_no, __func__));
  4361. status = ha->isp_ops->reset_firmware(ha);
  4362. if (status == QLA_SUCCESS) {
  4363. ha->isp_ops->disable_intrs(ha);
  4364. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  4365. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  4366. } else {
  4367. /* If the stop_firmware fails then
  4368. * reset the entire chip */
  4369. reset_chip = 1;
  4370. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  4371. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  4372. }
  4373. }
  4374. /* Issue full chip reset if recovering from a catastrophic error,
  4375. * or if stop_firmware fails for ISP-8xxx.
  4376. * This is the default case for ISP-4xxx */
  4377. if (is_qla40XX(ha) || reset_chip) {
  4378. if (is_qla40XX(ha))
  4379. goto chip_reset;
  4380. /* Check if 8XXX firmware is alive or not
  4381. * We may have arrived here from NEED_RESET
  4382. * detection only */
  4383. if (test_bit(AF_FW_RECOVERY, &ha->flags))
  4384. goto chip_reset;
  4385. wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
  4386. while (time_before(jiffies, wait)) {
  4387. if (qla4_8xxx_check_fw_alive(ha)) {
  4388. qla4xxx_mailbox_premature_completion(ha);
  4389. break;
  4390. }
  4391. set_current_state(TASK_UNINTERRUPTIBLE);
  4392. schedule_timeout(HZ);
  4393. }
  4394. chip_reset:
  4395. if (!test_bit(AF_FW_RECOVERY, &ha->flags))
  4396. qla4xxx_cmd_wait(ha);
  4397. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  4398. DEBUG2(ql4_printk(KERN_INFO, ha,
  4399. "scsi%ld: %s - Performing chip reset..\n",
  4400. ha->host_no, __func__));
  4401. status = ha->isp_ops->reset_chip(ha);
  4402. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  4403. }
  4404. /* Flush any pending ddb changed AENs */
  4405. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  4406. recover_ha_init_adapter:
  4407. /* Upon successful firmware/chip reset, re-initialize the adapter */
  4408. if (status == QLA_SUCCESS) {
  4409. /* For ISP-4xxx, force function 1 to always initialize
  4410. * before function 3 to prevent both funcions from
  4411. * stepping on top of the other */
  4412. if (is_qla40XX(ha) && (ha->mac_index == 3))
  4413. ssleep(6);
  4414. /* NOTE: AF_ONLINE flag set upon successful completion of
  4415. * qla4xxx_initialize_adapter */
  4416. status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  4417. if (is_qla80XX(ha) && (status == QLA_ERROR)) {
  4418. status = qla4_8xxx_check_init_adapter_retry(ha);
  4419. if (status == QLA_ERROR) {
  4420. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Don't retry recover adapter\n",
  4421. ha->host_no, __func__);
  4422. qla4xxx_dead_adapter_cleanup(ha);
  4423. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4424. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4425. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  4426. &ha->dpc_flags);
  4427. goto exit_recover;
  4428. }
  4429. }
  4430. }
  4431. /* Retry failed adapter initialization, if necessary
  4432. * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
  4433. * case to prevent ping-pong resets between functions */
  4434. if (!test_bit(AF_ONLINE, &ha->flags) &&
  4435. !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  4436. /* Adapter initialization failed, see if we can retry
  4437. * resetting the ha.
  4438. * Since we don't want to block the DPC for too long
  4439. * with multiple resets in the same thread,
  4440. * utilize DPC to retry */
  4441. if (is_qla80XX(ha)) {
  4442. ha->isp_ops->idc_lock(ha);
  4443. dev_state = qla4_8xxx_rd_direct(ha,
  4444. QLA8XXX_CRB_DEV_STATE);
  4445. ha->isp_ops->idc_unlock(ha);
  4446. if (dev_state == QLA8XXX_DEV_FAILED) {
  4447. ql4_printk(KERN_INFO, ha, "%s: don't retry "
  4448. "recover adapter. H/W is in Failed "
  4449. "state\n", __func__);
  4450. qla4xxx_dead_adapter_cleanup(ha);
  4451. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4452. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4453. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  4454. &ha->dpc_flags);
  4455. status = QLA_ERROR;
  4456. goto exit_recover;
  4457. }
  4458. }
  4459. if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
  4460. ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
  4461. DEBUG2(printk("scsi%ld: recover adapter - retrying "
  4462. "(%d) more times\n", ha->host_no,
  4463. ha->retry_reset_ha_cnt));
  4464. set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4465. status = QLA_ERROR;
  4466. } else {
  4467. if (ha->retry_reset_ha_cnt > 0) {
  4468. /* Schedule another Reset HA--DPC will retry */
  4469. ha->retry_reset_ha_cnt--;
  4470. DEBUG2(printk("scsi%ld: recover adapter - "
  4471. "retry remaining %d\n",
  4472. ha->host_no,
  4473. ha->retry_reset_ha_cnt));
  4474. status = QLA_ERROR;
  4475. }
  4476. if (ha->retry_reset_ha_cnt == 0) {
  4477. /* Recover adapter retries have been exhausted.
  4478. * Adapter DEAD */
  4479. DEBUG2(printk("scsi%ld: recover adapter "
  4480. "failed - board disabled\n",
  4481. ha->host_no));
  4482. qla4xxx_dead_adapter_cleanup(ha);
  4483. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4484. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4485. clear_bit(DPC_RESET_HA_FW_CONTEXT,
  4486. &ha->dpc_flags);
  4487. status = QLA_ERROR;
  4488. }
  4489. }
  4490. } else {
  4491. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4492. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  4493. clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
  4494. }
  4495. exit_recover:
  4496. ha->adapter_error_count++;
  4497. if (test_bit(AF_ONLINE, &ha->flags))
  4498. ha->isp_ops->enable_intrs(ha);
  4499. scsi_unblock_requests(ha->host);
  4500. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  4501. DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
  4502. status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
  4503. return status;
  4504. }
  4505. static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
  4506. {
  4507. struct iscsi_session *sess;
  4508. struct ddb_entry *ddb_entry;
  4509. struct scsi_qla_host *ha;
  4510. sess = cls_session->dd_data;
  4511. ddb_entry = sess->dd_data;
  4512. ha = ddb_entry->ha;
  4513. if (!iscsi_is_session_online(cls_session)) {
  4514. if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
  4515. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  4516. " unblock session\n", ha->host_no, __func__,
  4517. ddb_entry->fw_ddb_index);
  4518. iscsi_unblock_session(ddb_entry->sess);
  4519. } else {
  4520. /* Trigger relogin */
  4521. if (ddb_entry->ddb_type == FLASH_DDB) {
  4522. if (!(test_bit(DF_RELOGIN, &ddb_entry->flags) ||
  4523. test_bit(DF_DISABLE_RELOGIN,
  4524. &ddb_entry->flags)))
  4525. qla4xxx_arm_relogin_timer(ddb_entry);
  4526. } else
  4527. iscsi_session_failure(cls_session->dd_data,
  4528. ISCSI_ERR_CONN_FAILED);
  4529. }
  4530. }
  4531. }
  4532. int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
  4533. {
  4534. struct iscsi_session *sess;
  4535. struct ddb_entry *ddb_entry;
  4536. struct scsi_qla_host *ha;
  4537. sess = cls_session->dd_data;
  4538. ddb_entry = sess->dd_data;
  4539. ha = ddb_entry->ha;
  4540. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  4541. " unblock session\n", ha->host_no, __func__,
  4542. ddb_entry->fw_ddb_index);
  4543. iscsi_unblock_session(ddb_entry->sess);
  4544. /* Start scan target */
  4545. if (test_bit(AF_ONLINE, &ha->flags)) {
  4546. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  4547. " start scan\n", ha->host_no, __func__,
  4548. ddb_entry->fw_ddb_index);
  4549. scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
  4550. }
  4551. return QLA_SUCCESS;
  4552. }
  4553. int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
  4554. {
  4555. struct iscsi_session *sess;
  4556. struct ddb_entry *ddb_entry;
  4557. struct scsi_qla_host *ha;
  4558. int status = QLA_SUCCESS;
  4559. sess = cls_session->dd_data;
  4560. ddb_entry = sess->dd_data;
  4561. ha = ddb_entry->ha;
  4562. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
  4563. " unblock user space session\n", ha->host_no, __func__,
  4564. ddb_entry->fw_ddb_index);
  4565. if (!iscsi_is_session_online(cls_session)) {
  4566. iscsi_conn_start(ddb_entry->conn);
  4567. iscsi_conn_login_event(ddb_entry->conn,
  4568. ISCSI_CONN_STATE_LOGGED_IN);
  4569. } else {
  4570. ql4_printk(KERN_INFO, ha,
  4571. "scsi%ld: %s: ddb[%d] session [%d] already logged in\n",
  4572. ha->host_no, __func__, ddb_entry->fw_ddb_index,
  4573. cls_session->sid);
  4574. status = QLA_ERROR;
  4575. }
  4576. return status;
  4577. }
  4578. static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
  4579. {
  4580. iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
  4581. }
  4582. static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
  4583. {
  4584. uint16_t relogin_timer;
  4585. struct iscsi_session *sess;
  4586. struct ddb_entry *ddb_entry;
  4587. struct scsi_qla_host *ha;
  4588. sess = cls_sess->dd_data;
  4589. ddb_entry = sess->dd_data;
  4590. ha = ddb_entry->ha;
  4591. relogin_timer = max(ddb_entry->default_relogin_timeout,
  4592. (uint16_t)RELOGIN_TOV);
  4593. atomic_set(&ddb_entry->relogin_timer, relogin_timer);
  4594. DEBUG2(ql4_printk(KERN_INFO, ha,
  4595. "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
  4596. ddb_entry->fw_ddb_index, relogin_timer));
  4597. qla4xxx_login_flash_ddb(cls_sess);
  4598. }
  4599. static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
  4600. {
  4601. struct iscsi_session *sess;
  4602. struct ddb_entry *ddb_entry;
  4603. struct scsi_qla_host *ha;
  4604. sess = cls_sess->dd_data;
  4605. ddb_entry = sess->dd_data;
  4606. ha = ddb_entry->ha;
  4607. if (!(ddb_entry->ddb_type == FLASH_DDB))
  4608. return;
  4609. if (test_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  4610. return;
  4611. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
  4612. !iscsi_is_session_online(cls_sess)) {
  4613. DEBUG2(ql4_printk(KERN_INFO, ha,
  4614. "relogin issued\n"));
  4615. qla4xxx_relogin_flash_ddb(cls_sess);
  4616. }
  4617. }
  4618. void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
  4619. {
  4620. if (ha->dpc_thread)
  4621. queue_work(ha->dpc_thread, &ha->dpc_work);
  4622. }
  4623. static struct qla4_work_evt *
  4624. qla4xxx_alloc_work(struct scsi_qla_host *ha, uint32_t data_size,
  4625. enum qla4_work_type type)
  4626. {
  4627. struct qla4_work_evt *e;
  4628. uint32_t size = sizeof(struct qla4_work_evt) + data_size;
  4629. e = kzalloc(size, GFP_ATOMIC);
  4630. if (!e)
  4631. return NULL;
  4632. INIT_LIST_HEAD(&e->list);
  4633. e->type = type;
  4634. return e;
  4635. }
  4636. static void qla4xxx_post_work(struct scsi_qla_host *ha,
  4637. struct qla4_work_evt *e)
  4638. {
  4639. unsigned long flags;
  4640. spin_lock_irqsave(&ha->work_lock, flags);
  4641. list_add_tail(&e->list, &ha->work_list);
  4642. spin_unlock_irqrestore(&ha->work_lock, flags);
  4643. qla4xxx_wake_dpc(ha);
  4644. }
  4645. int qla4xxx_post_aen_work(struct scsi_qla_host *ha,
  4646. enum iscsi_host_event_code aen_code,
  4647. uint32_t data_size, uint8_t *data)
  4648. {
  4649. struct qla4_work_evt *e;
  4650. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_AEN);
  4651. if (!e)
  4652. return QLA_ERROR;
  4653. e->u.aen.code = aen_code;
  4654. e->u.aen.data_size = data_size;
  4655. memcpy(e->u.aen.data, data, data_size);
  4656. qla4xxx_post_work(ha, e);
  4657. return QLA_SUCCESS;
  4658. }
  4659. int qla4xxx_post_ping_evt_work(struct scsi_qla_host *ha,
  4660. uint32_t status, uint32_t pid,
  4661. uint32_t data_size, uint8_t *data)
  4662. {
  4663. struct qla4_work_evt *e;
  4664. e = qla4xxx_alloc_work(ha, data_size, QLA4_EVENT_PING_STATUS);
  4665. if (!e)
  4666. return QLA_ERROR;
  4667. e->u.ping.status = status;
  4668. e->u.ping.pid = pid;
  4669. e->u.ping.data_size = data_size;
  4670. memcpy(e->u.ping.data, data, data_size);
  4671. qla4xxx_post_work(ha, e);
  4672. return QLA_SUCCESS;
  4673. }
  4674. static void qla4xxx_do_work(struct scsi_qla_host *ha)
  4675. {
  4676. struct qla4_work_evt *e, *tmp;
  4677. unsigned long flags;
  4678. LIST_HEAD(work);
  4679. spin_lock_irqsave(&ha->work_lock, flags);
  4680. list_splice_init(&ha->work_list, &work);
  4681. spin_unlock_irqrestore(&ha->work_lock, flags);
  4682. list_for_each_entry_safe(e, tmp, &work, list) {
  4683. list_del_init(&e->list);
  4684. switch (e->type) {
  4685. case QLA4_EVENT_AEN:
  4686. iscsi_post_host_event(ha->host_no,
  4687. &qla4xxx_iscsi_transport,
  4688. e->u.aen.code,
  4689. e->u.aen.data_size,
  4690. e->u.aen.data);
  4691. break;
  4692. case QLA4_EVENT_PING_STATUS:
  4693. iscsi_ping_comp_event(ha->host_no,
  4694. &qla4xxx_iscsi_transport,
  4695. e->u.ping.status,
  4696. e->u.ping.pid,
  4697. e->u.ping.data_size,
  4698. e->u.ping.data);
  4699. break;
  4700. default:
  4701. ql4_printk(KERN_WARNING, ha, "event type: 0x%x not "
  4702. "supported", e->type);
  4703. }
  4704. kfree(e);
  4705. }
  4706. }
  4707. /**
  4708. * qla4xxx_do_dpc - dpc routine
  4709. * @data: in our case pointer to adapter structure
  4710. *
  4711. * This routine is a task that is schedule by the interrupt handler
  4712. * to perform the background processing for interrupts. We put it
  4713. * on a task queue that is consumed whenever the scheduler runs; that's
  4714. * so you can do anything (i.e. put the process to sleep etc). In fact,
  4715. * the mid-level tries to sleep when it reaches the driver threshold
  4716. * "host->can_queue". This can cause a panic if we were in our interrupt code.
  4717. **/
  4718. static void qla4xxx_do_dpc(struct work_struct *work)
  4719. {
  4720. struct scsi_qla_host *ha =
  4721. container_of(work, struct scsi_qla_host, dpc_work);
  4722. int status = QLA_ERROR;
  4723. DEBUG2(ql4_printk(KERN_INFO, ha,
  4724. "scsi%ld: %s: DPC handler waking up. flags = 0x%08lx, dpc_flags = 0x%08lx\n",
  4725. ha->host_no, __func__, ha->flags, ha->dpc_flags));
  4726. /* Initialization not yet finished. Don't do anything yet. */
  4727. if (!test_bit(AF_INIT_DONE, &ha->flags))
  4728. return;
  4729. if (test_bit(AF_EEH_BUSY, &ha->flags)) {
  4730. DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
  4731. ha->host_no, __func__, ha->flags));
  4732. return;
  4733. }
  4734. /* post events to application */
  4735. qla4xxx_do_work(ha);
  4736. if (is_qla80XX(ha)) {
  4737. if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
  4738. if (is_qla8032(ha) || is_qla8042(ha)) {
  4739. ql4_printk(KERN_INFO, ha, "%s: disabling pause transmit on port 0 & 1.\n",
  4740. __func__);
  4741. /* disable pause frame for ISP83xx */
  4742. qla4_83xx_disable_pause(ha);
  4743. }
  4744. ha->isp_ops->idc_lock(ha);
  4745. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  4746. QLA8XXX_DEV_FAILED);
  4747. ha->isp_ops->idc_unlock(ha);
  4748. ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
  4749. qla4_8xxx_device_state_handler(ha);
  4750. }
  4751. if (test_bit(DPC_POST_IDC_ACK, &ha->dpc_flags)) {
  4752. if (is_qla8042(ha)) {
  4753. if (ha->idc_info.info2 &
  4754. ENABLE_INTERNAL_LOOPBACK) {
  4755. ql4_printk(KERN_INFO, ha, "%s: Disabling ACB\n",
  4756. __func__);
  4757. status = qla4_84xx_config_acb(ha,
  4758. ACB_CONFIG_DISABLE);
  4759. if (status != QLA_SUCCESS) {
  4760. ql4_printk(KERN_INFO, ha, "%s: ACB config failed\n",
  4761. __func__);
  4762. }
  4763. }
  4764. }
  4765. qla4_83xx_post_idc_ack(ha);
  4766. clear_bit(DPC_POST_IDC_ACK, &ha->dpc_flags);
  4767. }
  4768. if (is_qla8042(ha) &&
  4769. test_bit(DPC_RESTORE_ACB, &ha->dpc_flags)) {
  4770. ql4_printk(KERN_INFO, ha, "%s: Restoring ACB\n",
  4771. __func__);
  4772. if (qla4_84xx_config_acb(ha, ACB_CONFIG_SET) !=
  4773. QLA_SUCCESS) {
  4774. ql4_printk(KERN_INFO, ha, "%s: ACB config failed ",
  4775. __func__);
  4776. }
  4777. clear_bit(DPC_RESTORE_ACB, &ha->dpc_flags);
  4778. }
  4779. if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
  4780. qla4_8xxx_need_qsnt_handler(ha);
  4781. }
  4782. }
  4783. if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
  4784. (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
  4785. test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
  4786. test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
  4787. if ((is_qla8022(ha) && ql4xdontresethba) ||
  4788. ((is_qla8032(ha) || is_qla8042(ha)) &&
  4789. qla4_83xx_idc_dontreset(ha))) {
  4790. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  4791. ha->host_no, __func__));
  4792. clear_bit(DPC_RESET_HA, &ha->dpc_flags);
  4793. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  4794. clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  4795. goto dpc_post_reset_ha;
  4796. }
  4797. if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
  4798. test_bit(DPC_RESET_HA, &ha->dpc_flags))
  4799. qla4xxx_recover_adapter(ha);
  4800. if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
  4801. uint8_t wait_time = RESET_INTR_TOV;
  4802. while ((readw(&ha->reg->ctrl_status) &
  4803. (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
  4804. if (--wait_time == 0)
  4805. break;
  4806. msleep(1000);
  4807. }
  4808. if (wait_time == 0)
  4809. DEBUG2(printk("scsi%ld: %s: SR|FSR "
  4810. "bit not cleared-- resetting\n",
  4811. ha->host_no, __func__));
  4812. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  4813. if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
  4814. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  4815. status = qla4xxx_recover_adapter(ha);
  4816. }
  4817. clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
  4818. if (status == QLA_SUCCESS)
  4819. ha->isp_ops->enable_intrs(ha);
  4820. }
  4821. }
  4822. dpc_post_reset_ha:
  4823. /* ---- process AEN? --- */
  4824. if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
  4825. qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
  4826. /* ---- Get DHCP IP Address? --- */
  4827. if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
  4828. qla4xxx_get_dhcp_ip_address(ha);
  4829. /* ---- relogin device? --- */
  4830. if (adapter_up(ha) &&
  4831. test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
  4832. iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
  4833. }
  4834. /* ---- link change? --- */
  4835. if (!test_bit(AF_LOOPBACK, &ha->flags) &&
  4836. test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
  4837. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  4838. /* ---- link down? --- */
  4839. qla4xxx_mark_all_devices_missing(ha);
  4840. } else {
  4841. /* ---- link up? --- *
  4842. * F/W will auto login to all devices ONLY ONCE after
  4843. * link up during driver initialization and runtime
  4844. * fatal error recovery. Therefore, the driver must
  4845. * manually relogin to devices when recovering from
  4846. * connection failures, logouts, expired KATO, etc. */
  4847. if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
  4848. qla4xxx_build_ddb_list(ha, ha->is_reset);
  4849. iscsi_host_for_each_session(ha->host,
  4850. qla4xxx_login_flash_ddb);
  4851. } else
  4852. qla4xxx_relogin_all_devices(ha);
  4853. }
  4854. }
  4855. if (test_and_clear_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags)) {
  4856. if (qla4xxx_sysfs_ddb_export(ha))
  4857. ql4_printk(KERN_ERR, ha, "%s: Error exporting ddb to sysfs\n",
  4858. __func__);
  4859. }
  4860. }
  4861. /**
  4862. * qla4xxx_free_adapter - release the adapter
  4863. * @ha: pointer to adapter structure
  4864. **/
  4865. static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
  4866. {
  4867. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  4868. /* Turn-off interrupts on the card. */
  4869. ha->isp_ops->disable_intrs(ha);
  4870. if (is_qla40XX(ha)) {
  4871. writel(set_rmask(CSR_SCSI_PROCESSOR_INTR),
  4872. &ha->reg->ctrl_status);
  4873. readl(&ha->reg->ctrl_status);
  4874. } else if (is_qla8022(ha)) {
  4875. writel(0, &ha->qla4_82xx_reg->host_int);
  4876. readl(&ha->qla4_82xx_reg->host_int);
  4877. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  4878. writel(0, &ha->qla4_83xx_reg->risc_intr);
  4879. readl(&ha->qla4_83xx_reg->risc_intr);
  4880. }
  4881. /* Remove timer thread, if present */
  4882. if (ha->timer_active)
  4883. qla4xxx_stop_timer(ha);
  4884. /* Kill the kernel thread for this host */
  4885. if (ha->dpc_thread)
  4886. destroy_workqueue(ha->dpc_thread);
  4887. /* Kill the kernel thread for this host */
  4888. if (ha->task_wq)
  4889. destroy_workqueue(ha->task_wq);
  4890. /* Put firmware in known state */
  4891. ha->isp_ops->reset_firmware(ha);
  4892. if (is_qla80XX(ha)) {
  4893. ha->isp_ops->idc_lock(ha);
  4894. qla4_8xxx_clear_drv_active(ha);
  4895. ha->isp_ops->idc_unlock(ha);
  4896. }
  4897. /* Detach interrupts */
  4898. qla4xxx_free_irqs(ha);
  4899. /* free extra memory */
  4900. qla4xxx_mem_free(ha);
  4901. }
  4902. int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
  4903. {
  4904. int status = 0;
  4905. unsigned long mem_base, mem_len, db_base, db_len;
  4906. struct pci_dev *pdev = ha->pdev;
  4907. status = pci_request_regions(pdev, DRIVER_NAME);
  4908. if (status) {
  4909. printk(KERN_WARNING
  4910. "scsi(%ld) Failed to reserve PIO regions (%s) "
  4911. "status=%d\n", ha->host_no, pci_name(pdev), status);
  4912. goto iospace_error_exit;
  4913. }
  4914. DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
  4915. __func__, pdev->revision));
  4916. ha->revision_id = pdev->revision;
  4917. /* remap phys address */
  4918. mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
  4919. mem_len = pci_resource_len(pdev, 0);
  4920. DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
  4921. __func__, mem_base, mem_len));
  4922. /* mapping of pcibase pointer */
  4923. ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
  4924. if (!ha->nx_pcibase) {
  4925. printk(KERN_ERR
  4926. "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
  4927. pci_release_regions(ha->pdev);
  4928. goto iospace_error_exit;
  4929. }
  4930. /* Mapping of IO base pointer, door bell read and write pointer */
  4931. /* mapping of IO base pointer */
  4932. if (is_qla8022(ha)) {
  4933. ha->qla4_82xx_reg = (struct device_reg_82xx __iomem *)
  4934. ((uint8_t *)ha->nx_pcibase + 0xbc000 +
  4935. (ha->pdev->devfn << 11));
  4936. ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
  4937. QLA82XX_CAM_RAM_DB2);
  4938. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  4939. ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
  4940. ((uint8_t *)ha->nx_pcibase);
  4941. }
  4942. db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
  4943. db_len = pci_resource_len(pdev, 4);
  4944. return 0;
  4945. iospace_error_exit:
  4946. return -ENOMEM;
  4947. }
  4948. /***
  4949. * qla4xxx_iospace_config - maps registers
  4950. * @ha: pointer to adapter structure
  4951. *
  4952. * This routines maps HBA's registers from the pci address space
  4953. * into the kernel virtual address space for memory mapped i/o.
  4954. **/
  4955. int qla4xxx_iospace_config(struct scsi_qla_host *ha)
  4956. {
  4957. unsigned long pio, pio_len, pio_flags;
  4958. unsigned long mmio, mmio_len, mmio_flags;
  4959. pio = pci_resource_start(ha->pdev, 0);
  4960. pio_len = pci_resource_len(ha->pdev, 0);
  4961. pio_flags = pci_resource_flags(ha->pdev, 0);
  4962. if (pio_flags & IORESOURCE_IO) {
  4963. if (pio_len < MIN_IOBASE_LEN) {
  4964. ql4_printk(KERN_WARNING, ha,
  4965. "Invalid PCI I/O region size\n");
  4966. pio = 0;
  4967. }
  4968. } else {
  4969. ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
  4970. pio = 0;
  4971. }
  4972. /* Use MMIO operations for all accesses. */
  4973. mmio = pci_resource_start(ha->pdev, 1);
  4974. mmio_len = pci_resource_len(ha->pdev, 1);
  4975. mmio_flags = pci_resource_flags(ha->pdev, 1);
  4976. if (!(mmio_flags & IORESOURCE_MEM)) {
  4977. ql4_printk(KERN_ERR, ha,
  4978. "region #0 not an MMIO resource, aborting\n");
  4979. goto iospace_error_exit;
  4980. }
  4981. if (mmio_len < MIN_IOBASE_LEN) {
  4982. ql4_printk(KERN_ERR, ha,
  4983. "Invalid PCI mem region size, aborting\n");
  4984. goto iospace_error_exit;
  4985. }
  4986. if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
  4987. ql4_printk(KERN_WARNING, ha,
  4988. "Failed to reserve PIO/MMIO regions\n");
  4989. goto iospace_error_exit;
  4990. }
  4991. ha->pio_address = pio;
  4992. ha->pio_length = pio_len;
  4993. ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
  4994. if (!ha->reg) {
  4995. ql4_printk(KERN_ERR, ha,
  4996. "cannot remap MMIO, aborting\n");
  4997. goto iospace_error_exit;
  4998. }
  4999. return 0;
  5000. iospace_error_exit:
  5001. return -ENOMEM;
  5002. }
  5003. static struct isp_operations qla4xxx_isp_ops = {
  5004. .iospace_config = qla4xxx_iospace_config,
  5005. .pci_config = qla4xxx_pci_config,
  5006. .disable_intrs = qla4xxx_disable_intrs,
  5007. .enable_intrs = qla4xxx_enable_intrs,
  5008. .start_firmware = qla4xxx_start_firmware,
  5009. .intr_handler = qla4xxx_intr_handler,
  5010. .interrupt_service_routine = qla4xxx_interrupt_service_routine,
  5011. .reset_chip = qla4xxx_soft_reset,
  5012. .reset_firmware = qla4xxx_hw_reset,
  5013. .queue_iocb = qla4xxx_queue_iocb,
  5014. .complete_iocb = qla4xxx_complete_iocb,
  5015. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  5016. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  5017. .get_sys_info = qla4xxx_get_sys_info,
  5018. .queue_mailbox_command = qla4xxx_queue_mbox_cmd,
  5019. .process_mailbox_interrupt = qla4xxx_process_mbox_intr,
  5020. };
  5021. static struct isp_operations qla4_82xx_isp_ops = {
  5022. .iospace_config = qla4_8xxx_iospace_config,
  5023. .pci_config = qla4_8xxx_pci_config,
  5024. .disable_intrs = qla4_82xx_disable_intrs,
  5025. .enable_intrs = qla4_82xx_enable_intrs,
  5026. .start_firmware = qla4_8xxx_load_risc,
  5027. .restart_firmware = qla4_82xx_try_start_fw,
  5028. .intr_handler = qla4_82xx_intr_handler,
  5029. .interrupt_service_routine = qla4_82xx_interrupt_service_routine,
  5030. .need_reset = qla4_8xxx_need_reset,
  5031. .reset_chip = qla4_82xx_isp_reset,
  5032. .reset_firmware = qla4_8xxx_stop_firmware,
  5033. .queue_iocb = qla4_82xx_queue_iocb,
  5034. .complete_iocb = qla4_82xx_complete_iocb,
  5035. .rd_shdw_req_q_out = qla4_82xx_rd_shdw_req_q_out,
  5036. .rd_shdw_rsp_q_in = qla4_82xx_rd_shdw_rsp_q_in,
  5037. .get_sys_info = qla4_8xxx_get_sys_info,
  5038. .rd_reg_direct = qla4_82xx_rd_32,
  5039. .wr_reg_direct = qla4_82xx_wr_32,
  5040. .rd_reg_indirect = qla4_82xx_md_rd_32,
  5041. .wr_reg_indirect = qla4_82xx_md_wr_32,
  5042. .idc_lock = qla4_82xx_idc_lock,
  5043. .idc_unlock = qla4_82xx_idc_unlock,
  5044. .rom_lock_recovery = qla4_82xx_rom_lock_recovery,
  5045. .queue_mailbox_command = qla4_82xx_queue_mbox_cmd,
  5046. .process_mailbox_interrupt = qla4_82xx_process_mbox_intr,
  5047. };
  5048. static struct isp_operations qla4_83xx_isp_ops = {
  5049. .iospace_config = qla4_8xxx_iospace_config,
  5050. .pci_config = qla4_8xxx_pci_config,
  5051. .disable_intrs = qla4_83xx_disable_intrs,
  5052. .enable_intrs = qla4_83xx_enable_intrs,
  5053. .start_firmware = qla4_8xxx_load_risc,
  5054. .restart_firmware = qla4_83xx_start_firmware,
  5055. .intr_handler = qla4_83xx_intr_handler,
  5056. .interrupt_service_routine = qla4_83xx_interrupt_service_routine,
  5057. .need_reset = qla4_8xxx_need_reset,
  5058. .reset_chip = qla4_83xx_isp_reset,
  5059. .reset_firmware = qla4_8xxx_stop_firmware,
  5060. .queue_iocb = qla4_83xx_queue_iocb,
  5061. .complete_iocb = qla4_83xx_complete_iocb,
  5062. .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
  5063. .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
  5064. .get_sys_info = qla4_8xxx_get_sys_info,
  5065. .rd_reg_direct = qla4_83xx_rd_reg,
  5066. .wr_reg_direct = qla4_83xx_wr_reg,
  5067. .rd_reg_indirect = qla4_83xx_rd_reg_indirect,
  5068. .wr_reg_indirect = qla4_83xx_wr_reg_indirect,
  5069. .idc_lock = qla4_83xx_drv_lock,
  5070. .idc_unlock = qla4_83xx_drv_unlock,
  5071. .rom_lock_recovery = qla4_83xx_rom_lock_recovery,
  5072. .queue_mailbox_command = qla4_83xx_queue_mbox_cmd,
  5073. .process_mailbox_interrupt = qla4_83xx_process_mbox_intr,
  5074. };
  5075. uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  5076. {
  5077. return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
  5078. }
  5079. uint16_t qla4_82xx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
  5080. {
  5081. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->req_q_out));
  5082. }
  5083. uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  5084. {
  5085. return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
  5086. }
  5087. uint16_t qla4_82xx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
  5088. {
  5089. return (uint16_t)le32_to_cpu(readl(&ha->qla4_82xx_reg->rsp_q_in));
  5090. }
  5091. static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
  5092. {
  5093. struct scsi_qla_host *ha = data;
  5094. char *str = buf;
  5095. int rc;
  5096. switch (type) {
  5097. case ISCSI_BOOT_ETH_FLAGS:
  5098. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  5099. break;
  5100. case ISCSI_BOOT_ETH_INDEX:
  5101. rc = sprintf(str, "0\n");
  5102. break;
  5103. case ISCSI_BOOT_ETH_MAC:
  5104. rc = sysfs_format_mac(str, ha->my_mac,
  5105. MAC_ADDR_LEN);
  5106. break;
  5107. default:
  5108. rc = -ENOSYS;
  5109. break;
  5110. }
  5111. return rc;
  5112. }
  5113. static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
  5114. {
  5115. int rc;
  5116. switch (type) {
  5117. case ISCSI_BOOT_ETH_FLAGS:
  5118. case ISCSI_BOOT_ETH_MAC:
  5119. case ISCSI_BOOT_ETH_INDEX:
  5120. rc = S_IRUGO;
  5121. break;
  5122. default:
  5123. rc = 0;
  5124. break;
  5125. }
  5126. return rc;
  5127. }
  5128. static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
  5129. {
  5130. struct scsi_qla_host *ha = data;
  5131. char *str = buf;
  5132. int rc;
  5133. switch (type) {
  5134. case ISCSI_BOOT_INI_INITIATOR_NAME:
  5135. rc = sprintf(str, "%s\n", ha->name_string);
  5136. break;
  5137. default:
  5138. rc = -ENOSYS;
  5139. break;
  5140. }
  5141. return rc;
  5142. }
  5143. static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
  5144. {
  5145. int rc;
  5146. switch (type) {
  5147. case ISCSI_BOOT_INI_INITIATOR_NAME:
  5148. rc = S_IRUGO;
  5149. break;
  5150. default:
  5151. rc = 0;
  5152. break;
  5153. }
  5154. return rc;
  5155. }
  5156. static ssize_t
  5157. qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
  5158. char *buf)
  5159. {
  5160. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  5161. char *str = buf;
  5162. int rc;
  5163. switch (type) {
  5164. case ISCSI_BOOT_TGT_NAME:
  5165. rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
  5166. break;
  5167. case ISCSI_BOOT_TGT_IP_ADDR:
  5168. if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
  5169. rc = sprintf(buf, "%pI4\n",
  5170. &boot_conn->dest_ipaddr.ip_address);
  5171. else
  5172. rc = sprintf(str, "%pI6\n",
  5173. &boot_conn->dest_ipaddr.ip_address);
  5174. break;
  5175. case ISCSI_BOOT_TGT_PORT:
  5176. rc = sprintf(str, "%d\n", boot_conn->dest_port);
  5177. break;
  5178. case ISCSI_BOOT_TGT_CHAP_NAME:
  5179. rc = sprintf(str, "%.*s\n",
  5180. boot_conn->chap.target_chap_name_length,
  5181. (char *)&boot_conn->chap.target_chap_name);
  5182. break;
  5183. case ISCSI_BOOT_TGT_CHAP_SECRET:
  5184. rc = sprintf(str, "%.*s\n",
  5185. boot_conn->chap.target_secret_length,
  5186. (char *)&boot_conn->chap.target_secret);
  5187. break;
  5188. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  5189. rc = sprintf(str, "%.*s\n",
  5190. boot_conn->chap.intr_chap_name_length,
  5191. (char *)&boot_conn->chap.intr_chap_name);
  5192. break;
  5193. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  5194. rc = sprintf(str, "%.*s\n",
  5195. boot_conn->chap.intr_secret_length,
  5196. (char *)&boot_conn->chap.intr_secret);
  5197. break;
  5198. case ISCSI_BOOT_TGT_FLAGS:
  5199. rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
  5200. break;
  5201. case ISCSI_BOOT_TGT_NIC_ASSOC:
  5202. rc = sprintf(str, "0\n");
  5203. break;
  5204. default:
  5205. rc = -ENOSYS;
  5206. break;
  5207. }
  5208. return rc;
  5209. }
  5210. static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
  5211. {
  5212. struct scsi_qla_host *ha = data;
  5213. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
  5214. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  5215. }
  5216. static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
  5217. {
  5218. struct scsi_qla_host *ha = data;
  5219. struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
  5220. return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
  5221. }
  5222. static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
  5223. {
  5224. int rc;
  5225. switch (type) {
  5226. case ISCSI_BOOT_TGT_NAME:
  5227. case ISCSI_BOOT_TGT_IP_ADDR:
  5228. case ISCSI_BOOT_TGT_PORT:
  5229. case ISCSI_BOOT_TGT_CHAP_NAME:
  5230. case ISCSI_BOOT_TGT_CHAP_SECRET:
  5231. case ISCSI_BOOT_TGT_REV_CHAP_NAME:
  5232. case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
  5233. case ISCSI_BOOT_TGT_NIC_ASSOC:
  5234. case ISCSI_BOOT_TGT_FLAGS:
  5235. rc = S_IRUGO;
  5236. break;
  5237. default:
  5238. rc = 0;
  5239. break;
  5240. }
  5241. return rc;
  5242. }
  5243. static void qla4xxx_boot_release(void *data)
  5244. {
  5245. struct scsi_qla_host *ha = data;
  5246. scsi_host_put(ha->host);
  5247. }
  5248. static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
  5249. {
  5250. dma_addr_t buf_dma;
  5251. uint32_t addr, pri_addr, sec_addr;
  5252. uint32_t offset;
  5253. uint16_t func_num;
  5254. uint8_t val;
  5255. uint8_t *buf = NULL;
  5256. size_t size = 13 * sizeof(uint8_t);
  5257. int ret = QLA_SUCCESS;
  5258. func_num = PCI_FUNC(ha->pdev->devfn);
  5259. ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
  5260. __func__, ha->pdev->device, func_num);
  5261. if (is_qla40XX(ha)) {
  5262. if (func_num == 1) {
  5263. addr = NVRAM_PORT0_BOOT_MODE;
  5264. pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
  5265. sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
  5266. } else if (func_num == 3) {
  5267. addr = NVRAM_PORT1_BOOT_MODE;
  5268. pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
  5269. sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
  5270. } else {
  5271. ret = QLA_ERROR;
  5272. goto exit_boot_info;
  5273. }
  5274. /* Check Boot Mode */
  5275. val = rd_nvram_byte(ha, addr);
  5276. if (!(val & 0x07)) {
  5277. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Adapter boot "
  5278. "options : 0x%x\n", __func__, val));
  5279. ret = QLA_ERROR;
  5280. goto exit_boot_info;
  5281. }
  5282. /* get primary valid target index */
  5283. val = rd_nvram_byte(ha, pri_addr);
  5284. if (val & BIT_7)
  5285. ddb_index[0] = (val & 0x7f);
  5286. /* get secondary valid target index */
  5287. val = rd_nvram_byte(ha, sec_addr);
  5288. if (val & BIT_7)
  5289. ddb_index[1] = (val & 0x7f);
  5290. } else if (is_qla80XX(ha)) {
  5291. buf = dma_alloc_coherent(&ha->pdev->dev, size,
  5292. &buf_dma, GFP_KERNEL);
  5293. if (!buf) {
  5294. DEBUG2(ql4_printk(KERN_ERR, ha,
  5295. "%s: Unable to allocate dma buffer\n",
  5296. __func__));
  5297. ret = QLA_ERROR;
  5298. goto exit_boot_info;
  5299. }
  5300. if (ha->port_num == 0)
  5301. offset = BOOT_PARAM_OFFSET_PORT0;
  5302. else if (ha->port_num == 1)
  5303. offset = BOOT_PARAM_OFFSET_PORT1;
  5304. else {
  5305. ret = QLA_ERROR;
  5306. goto exit_boot_info_free;
  5307. }
  5308. addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
  5309. offset;
  5310. if (qla4xxx_get_flash(ha, buf_dma, addr,
  5311. 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
  5312. DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
  5313. " failed\n", ha->host_no, __func__));
  5314. ret = QLA_ERROR;
  5315. goto exit_boot_info_free;
  5316. }
  5317. /* Check Boot Mode */
  5318. if (!(buf[1] & 0x07)) {
  5319. DEBUG2(ql4_printk(KERN_INFO, ha, "Firmware boot options"
  5320. " : 0x%x\n", buf[1]));
  5321. ret = QLA_ERROR;
  5322. goto exit_boot_info_free;
  5323. }
  5324. /* get primary valid target index */
  5325. if (buf[2] & BIT_7)
  5326. ddb_index[0] = buf[2] & 0x7f;
  5327. /* get secondary valid target index */
  5328. if (buf[11] & BIT_7)
  5329. ddb_index[1] = buf[11] & 0x7f;
  5330. } else {
  5331. ret = QLA_ERROR;
  5332. goto exit_boot_info;
  5333. }
  5334. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
  5335. " target ID %d\n", __func__, ddb_index[0],
  5336. ddb_index[1]));
  5337. exit_boot_info_free:
  5338. dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
  5339. exit_boot_info:
  5340. ha->pri_ddb_idx = ddb_index[0];
  5341. ha->sec_ddb_idx = ddb_index[1];
  5342. return ret;
  5343. }
  5344. /**
  5345. * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
  5346. * @ha: pointer to adapter structure
  5347. * @username: CHAP username to be returned
  5348. * @password: CHAP password to be returned
  5349. *
  5350. * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
  5351. * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
  5352. * So from the CHAP cache find the first BIDI CHAP entry and set it
  5353. * to the boot record in sysfs.
  5354. **/
  5355. static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
  5356. char *password)
  5357. {
  5358. int i, ret = -EINVAL;
  5359. int max_chap_entries = 0;
  5360. struct ql4_chap_table *chap_table;
  5361. if (is_qla80XX(ha))
  5362. max_chap_entries = (ha->hw.flt_chap_size / 2) /
  5363. sizeof(struct ql4_chap_table);
  5364. else
  5365. max_chap_entries = MAX_CHAP_ENTRIES_40XX;
  5366. if (!ha->chap_list) {
  5367. ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
  5368. return ret;
  5369. }
  5370. mutex_lock(&ha->chap_sem);
  5371. for (i = 0; i < max_chap_entries; i++) {
  5372. chap_table = (struct ql4_chap_table *)ha->chap_list + i;
  5373. if (chap_table->cookie !=
  5374. __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
  5375. continue;
  5376. }
  5377. if (chap_table->flags & BIT_7) /* local */
  5378. continue;
  5379. if (!(chap_table->flags & BIT_6)) /* Not BIDI */
  5380. continue;
  5381. strlcpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
  5382. strlcpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
  5383. ret = 0;
  5384. break;
  5385. }
  5386. mutex_unlock(&ha->chap_sem);
  5387. return ret;
  5388. }
  5389. static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
  5390. struct ql4_boot_session_info *boot_sess,
  5391. uint16_t ddb_index)
  5392. {
  5393. struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
  5394. struct dev_db_entry *fw_ddb_entry;
  5395. dma_addr_t fw_ddb_entry_dma;
  5396. uint16_t idx;
  5397. uint16_t options;
  5398. int ret = QLA_SUCCESS;
  5399. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5400. &fw_ddb_entry_dma, GFP_KERNEL);
  5401. if (!fw_ddb_entry) {
  5402. DEBUG2(ql4_printk(KERN_ERR, ha,
  5403. "%s: Unable to allocate dma buffer.\n",
  5404. __func__));
  5405. ret = QLA_ERROR;
  5406. return ret;
  5407. }
  5408. if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
  5409. fw_ddb_entry_dma, ddb_index)) {
  5410. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: No Flash DDB found at "
  5411. "index [%d]\n", __func__, ddb_index));
  5412. ret = QLA_ERROR;
  5413. goto exit_boot_target;
  5414. }
  5415. /* Update target name and IP from DDB */
  5416. memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
  5417. min(sizeof(boot_sess->target_name),
  5418. sizeof(fw_ddb_entry->iscsi_name)));
  5419. options = le16_to_cpu(fw_ddb_entry->options);
  5420. if (options & DDB_OPT_IPV6_DEVICE) {
  5421. memcpy(&boot_conn->dest_ipaddr.ip_address,
  5422. &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
  5423. } else {
  5424. boot_conn->dest_ipaddr.ip_type = 0x1;
  5425. memcpy(&boot_conn->dest_ipaddr.ip_address,
  5426. &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
  5427. }
  5428. boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
  5429. /* update chap information */
  5430. idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
  5431. if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  5432. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
  5433. ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
  5434. target_chap_name,
  5435. (char *)&boot_conn->chap.target_secret,
  5436. idx);
  5437. if (ret) {
  5438. ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
  5439. ret = QLA_ERROR;
  5440. goto exit_boot_target;
  5441. }
  5442. boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  5443. boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  5444. }
  5445. if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
  5446. DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
  5447. ret = qla4xxx_get_bidi_chap(ha,
  5448. (char *)&boot_conn->chap.intr_chap_name,
  5449. (char *)&boot_conn->chap.intr_secret);
  5450. if (ret) {
  5451. ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
  5452. ret = QLA_ERROR;
  5453. goto exit_boot_target;
  5454. }
  5455. boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
  5456. boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
  5457. }
  5458. exit_boot_target:
  5459. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  5460. fw_ddb_entry, fw_ddb_entry_dma);
  5461. return ret;
  5462. }
  5463. static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
  5464. {
  5465. uint16_t ddb_index[2];
  5466. int ret = QLA_ERROR;
  5467. int rval;
  5468. memset(ddb_index, 0, sizeof(ddb_index));
  5469. ddb_index[0] = 0xffff;
  5470. ddb_index[1] = 0xffff;
  5471. ret = get_fw_boot_info(ha, ddb_index);
  5472. if (ret != QLA_SUCCESS) {
  5473. DEBUG2(ql4_printk(KERN_INFO, ha,
  5474. "%s: No boot target configured.\n", __func__));
  5475. return ret;
  5476. }
  5477. if (ql4xdisablesysfsboot)
  5478. return QLA_SUCCESS;
  5479. if (ddb_index[0] == 0xffff)
  5480. goto sec_target;
  5481. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
  5482. ddb_index[0]);
  5483. if (rval != QLA_SUCCESS) {
  5484. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary boot target not "
  5485. "configured\n", __func__));
  5486. } else
  5487. ret = QLA_SUCCESS;
  5488. sec_target:
  5489. if (ddb_index[1] == 0xffff)
  5490. goto exit_get_boot_info;
  5491. rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
  5492. ddb_index[1]);
  5493. if (rval != QLA_SUCCESS) {
  5494. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Secondary boot target not"
  5495. " configured\n", __func__));
  5496. } else
  5497. ret = QLA_SUCCESS;
  5498. exit_get_boot_info:
  5499. return ret;
  5500. }
  5501. static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
  5502. {
  5503. struct iscsi_boot_kobj *boot_kobj;
  5504. if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
  5505. return QLA_ERROR;
  5506. if (ql4xdisablesysfsboot) {
  5507. ql4_printk(KERN_INFO, ha,
  5508. "%s: syfsboot disabled - driver will trigger login "
  5509. "and publish session for discovery .\n", __func__);
  5510. return QLA_SUCCESS;
  5511. }
  5512. ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
  5513. if (!ha->boot_kset)
  5514. goto kset_free;
  5515. if (!scsi_host_get(ha->host))
  5516. goto kset_free;
  5517. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
  5518. qla4xxx_show_boot_tgt_pri_info,
  5519. qla4xxx_tgt_get_attr_visibility,
  5520. qla4xxx_boot_release);
  5521. if (!boot_kobj)
  5522. goto put_host;
  5523. if (!scsi_host_get(ha->host))
  5524. goto kset_free;
  5525. boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
  5526. qla4xxx_show_boot_tgt_sec_info,
  5527. qla4xxx_tgt_get_attr_visibility,
  5528. qla4xxx_boot_release);
  5529. if (!boot_kobj)
  5530. goto put_host;
  5531. if (!scsi_host_get(ha->host))
  5532. goto kset_free;
  5533. boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
  5534. qla4xxx_show_boot_ini_info,
  5535. qla4xxx_ini_get_attr_visibility,
  5536. qla4xxx_boot_release);
  5537. if (!boot_kobj)
  5538. goto put_host;
  5539. if (!scsi_host_get(ha->host))
  5540. goto kset_free;
  5541. boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
  5542. qla4xxx_show_boot_eth_info,
  5543. qla4xxx_eth_get_attr_visibility,
  5544. qla4xxx_boot_release);
  5545. if (!boot_kobj)
  5546. goto put_host;
  5547. return QLA_SUCCESS;
  5548. put_host:
  5549. scsi_host_put(ha->host);
  5550. kset_free:
  5551. iscsi_boot_destroy_kset(ha->boot_kset);
  5552. return -ENOMEM;
  5553. }
  5554. static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
  5555. struct ql4_tuple_ddb *tddb)
  5556. {
  5557. struct scsi_qla_host *ha;
  5558. struct iscsi_cls_session *cls_sess;
  5559. struct iscsi_cls_conn *cls_conn;
  5560. struct iscsi_session *sess;
  5561. struct iscsi_conn *conn;
  5562. DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
  5563. ha = ddb_entry->ha;
  5564. cls_sess = ddb_entry->sess;
  5565. sess = cls_sess->dd_data;
  5566. cls_conn = ddb_entry->conn;
  5567. conn = cls_conn->dd_data;
  5568. tddb->tpgt = sess->tpgt;
  5569. tddb->port = conn->persistent_port;
  5570. strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
  5571. strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
  5572. }
  5573. static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
  5574. struct ql4_tuple_ddb *tddb,
  5575. uint8_t *flash_isid)
  5576. {
  5577. uint16_t options = 0;
  5578. tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
  5579. memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
  5580. min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
  5581. options = le16_to_cpu(fw_ddb_entry->options);
  5582. if (options & DDB_OPT_IPV6_DEVICE)
  5583. sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
  5584. else
  5585. sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
  5586. tddb->port = le16_to_cpu(fw_ddb_entry->port);
  5587. if (flash_isid == NULL)
  5588. memcpy(&tddb->isid[0], &fw_ddb_entry->isid[0],
  5589. sizeof(tddb->isid));
  5590. else
  5591. memcpy(&tddb->isid[0], &flash_isid[0], sizeof(tddb->isid));
  5592. }
  5593. static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
  5594. struct ql4_tuple_ddb *old_tddb,
  5595. struct ql4_tuple_ddb *new_tddb,
  5596. uint8_t is_isid_compare)
  5597. {
  5598. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  5599. return QLA_ERROR;
  5600. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
  5601. return QLA_ERROR;
  5602. if (old_tddb->port != new_tddb->port)
  5603. return QLA_ERROR;
  5604. /* For multi sessions, driver generates the ISID, so do not compare
  5605. * ISID in reset path since it would be a comparison between the
  5606. * driver generated ISID and firmware generated ISID. This could
  5607. * lead to adding duplicated DDBs in the list as driver generated
  5608. * ISID would not match firmware generated ISID.
  5609. */
  5610. if (is_isid_compare) {
  5611. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: old ISID [%02x%02x%02x"
  5612. "%02x%02x%02x] New ISID [%02x%02x%02x%02x%02x%02x]\n",
  5613. __func__, old_tddb->isid[5], old_tddb->isid[4],
  5614. old_tddb->isid[3], old_tddb->isid[2], old_tddb->isid[1],
  5615. old_tddb->isid[0], new_tddb->isid[5], new_tddb->isid[4],
  5616. new_tddb->isid[3], new_tddb->isid[2], new_tddb->isid[1],
  5617. new_tddb->isid[0]));
  5618. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  5619. sizeof(old_tddb->isid)))
  5620. return QLA_ERROR;
  5621. }
  5622. DEBUG2(ql4_printk(KERN_INFO, ha,
  5623. "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
  5624. old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
  5625. old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
  5626. new_tddb->ip_addr, new_tddb->iscsi_name));
  5627. return QLA_SUCCESS;
  5628. }
  5629. static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
  5630. struct dev_db_entry *fw_ddb_entry,
  5631. uint32_t *index)
  5632. {
  5633. struct ddb_entry *ddb_entry;
  5634. struct ql4_tuple_ddb *fw_tddb = NULL;
  5635. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5636. int idx;
  5637. int ret = QLA_ERROR;
  5638. fw_tddb = vzalloc(sizeof(*fw_tddb));
  5639. if (!fw_tddb) {
  5640. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5641. "Memory Allocation failed.\n"));
  5642. ret = QLA_SUCCESS;
  5643. goto exit_check;
  5644. }
  5645. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5646. if (!tmp_tddb) {
  5647. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5648. "Memory Allocation failed.\n"));
  5649. ret = QLA_SUCCESS;
  5650. goto exit_check;
  5651. }
  5652. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  5653. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  5654. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  5655. if (ddb_entry == NULL)
  5656. continue;
  5657. qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
  5658. if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, false)) {
  5659. ret = QLA_SUCCESS; /* found */
  5660. if (index != NULL)
  5661. *index = idx;
  5662. goto exit_check;
  5663. }
  5664. }
  5665. exit_check:
  5666. if (fw_tddb)
  5667. vfree(fw_tddb);
  5668. if (tmp_tddb)
  5669. vfree(tmp_tddb);
  5670. return ret;
  5671. }
  5672. /**
  5673. * qla4xxx_check_existing_isid - check if target with same isid exist
  5674. * in target list
  5675. * @list_nt: list of target
  5676. * @isid: isid to check
  5677. *
  5678. * This routine return QLA_SUCCESS if target with same isid exist
  5679. **/
  5680. static int qla4xxx_check_existing_isid(struct list_head *list_nt, uint8_t *isid)
  5681. {
  5682. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  5683. struct dev_db_entry *fw_ddb_entry;
  5684. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5685. fw_ddb_entry = &nt_ddb_idx->fw_ddb;
  5686. if (memcmp(&fw_ddb_entry->isid[0], &isid[0],
  5687. sizeof(nt_ddb_idx->fw_ddb.isid)) == 0) {
  5688. return QLA_SUCCESS;
  5689. }
  5690. }
  5691. return QLA_ERROR;
  5692. }
  5693. /**
  5694. * qla4xxx_update_isid - compare ddbs and updated isid
  5695. * @ha: Pointer to host adapter structure.
  5696. * @list_nt: list of nt target
  5697. * @fw_ddb_entry: firmware ddb entry
  5698. *
  5699. * This routine update isid if ddbs have same iqn, same isid and
  5700. * different IP addr.
  5701. * Return QLA_SUCCESS if isid is updated.
  5702. **/
  5703. static int qla4xxx_update_isid(struct scsi_qla_host *ha,
  5704. struct list_head *list_nt,
  5705. struct dev_db_entry *fw_ddb_entry)
  5706. {
  5707. uint8_t base_value, i;
  5708. base_value = fw_ddb_entry->isid[1] & 0x1f;
  5709. for (i = 0; i < 8; i++) {
  5710. fw_ddb_entry->isid[1] = (base_value | (i << 5));
  5711. if (qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  5712. break;
  5713. }
  5714. if (!qla4xxx_check_existing_isid(list_nt, fw_ddb_entry->isid))
  5715. return QLA_ERROR;
  5716. return QLA_SUCCESS;
  5717. }
  5718. /**
  5719. * qla4xxx_should_update_isid - check if isid need to update
  5720. * @ha: Pointer to host adapter structure.
  5721. * @old_tddb: ddb tuple
  5722. * @new_tddb: ddb tuple
  5723. *
  5724. * Return QLA_SUCCESS if different IP, different PORT, same iqn,
  5725. * same isid
  5726. **/
  5727. static int qla4xxx_should_update_isid(struct scsi_qla_host *ha,
  5728. struct ql4_tuple_ddb *old_tddb,
  5729. struct ql4_tuple_ddb *new_tddb)
  5730. {
  5731. if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr) == 0) {
  5732. /* Same ip */
  5733. if (old_tddb->port == new_tddb->port)
  5734. return QLA_ERROR;
  5735. }
  5736. if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
  5737. /* different iqn */
  5738. return QLA_ERROR;
  5739. if (memcmp(&old_tddb->isid[0], &new_tddb->isid[0],
  5740. sizeof(old_tddb->isid)))
  5741. /* different isid */
  5742. return QLA_ERROR;
  5743. return QLA_SUCCESS;
  5744. }
  5745. /**
  5746. * qla4xxx_is_flash_ddb_exists - check if fw_ddb_entry already exists in list_nt
  5747. * @ha: Pointer to host adapter structure.
  5748. * @list_nt: list of nt target.
  5749. * @fw_ddb_entry: firmware ddb entry.
  5750. *
  5751. * This routine check if fw_ddb_entry already exists in list_nt to avoid
  5752. * duplicate ddb in list_nt.
  5753. * Return QLA_SUCCESS if duplicate ddb exit in list_nl.
  5754. * Note: This function also update isid of DDB if required.
  5755. **/
  5756. static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
  5757. struct list_head *list_nt,
  5758. struct dev_db_entry *fw_ddb_entry)
  5759. {
  5760. struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
  5761. struct ql4_tuple_ddb *fw_tddb = NULL;
  5762. struct ql4_tuple_ddb *tmp_tddb = NULL;
  5763. int rval, ret = QLA_ERROR;
  5764. fw_tddb = vzalloc(sizeof(*fw_tddb));
  5765. if (!fw_tddb) {
  5766. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5767. "Memory Allocation failed.\n"));
  5768. ret = QLA_SUCCESS;
  5769. goto exit_check;
  5770. }
  5771. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  5772. if (!tmp_tddb) {
  5773. DEBUG2(ql4_printk(KERN_WARNING, ha,
  5774. "Memory Allocation failed.\n"));
  5775. ret = QLA_SUCCESS;
  5776. goto exit_check;
  5777. }
  5778. qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
  5779. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5780. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb,
  5781. nt_ddb_idx->flash_isid);
  5782. ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
  5783. /* found duplicate ddb */
  5784. if (ret == QLA_SUCCESS)
  5785. goto exit_check;
  5786. }
  5787. list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
  5788. qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb, NULL);
  5789. ret = qla4xxx_should_update_isid(ha, tmp_tddb, fw_tddb);
  5790. if (ret == QLA_SUCCESS) {
  5791. rval = qla4xxx_update_isid(ha, list_nt, fw_ddb_entry);
  5792. if (rval == QLA_SUCCESS)
  5793. ret = QLA_ERROR;
  5794. else
  5795. ret = QLA_SUCCESS;
  5796. goto exit_check;
  5797. }
  5798. }
  5799. exit_check:
  5800. if (fw_tddb)
  5801. vfree(fw_tddb);
  5802. if (tmp_tddb)
  5803. vfree(tmp_tddb);
  5804. return ret;
  5805. }
  5806. static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
  5807. {
  5808. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  5809. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  5810. list_del_init(&ddb_idx->list);
  5811. vfree(ddb_idx);
  5812. }
  5813. }
  5814. static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
  5815. struct dev_db_entry *fw_ddb_entry)
  5816. {
  5817. struct iscsi_endpoint *ep;
  5818. struct sockaddr_in *addr;
  5819. struct sockaddr_in6 *addr6;
  5820. struct sockaddr *t_addr;
  5821. struct sockaddr_storage *dst_addr;
  5822. char *ip;
  5823. /* TODO: need to destroy on unload iscsi_endpoint*/
  5824. dst_addr = vmalloc(sizeof(*dst_addr));
  5825. if (!dst_addr)
  5826. return NULL;
  5827. if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
  5828. t_addr = (struct sockaddr *)dst_addr;
  5829. t_addr->sa_family = AF_INET6;
  5830. addr6 = (struct sockaddr_in6 *)dst_addr;
  5831. ip = (char *)&addr6->sin6_addr;
  5832. memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
  5833. addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
  5834. } else {
  5835. t_addr = (struct sockaddr *)dst_addr;
  5836. t_addr->sa_family = AF_INET;
  5837. addr = (struct sockaddr_in *)dst_addr;
  5838. ip = (char *)&addr->sin_addr;
  5839. memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
  5840. addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
  5841. }
  5842. ep = qla4xxx_ep_connect(ha->host, (struct sockaddr *)dst_addr, 0);
  5843. vfree(dst_addr);
  5844. return ep;
  5845. }
  5846. static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
  5847. {
  5848. if (ql4xdisablesysfsboot)
  5849. return QLA_SUCCESS;
  5850. if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
  5851. return QLA_ERROR;
  5852. return QLA_SUCCESS;
  5853. }
  5854. static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
  5855. struct ddb_entry *ddb_entry,
  5856. uint16_t idx)
  5857. {
  5858. uint16_t def_timeout;
  5859. ddb_entry->ddb_type = FLASH_DDB;
  5860. ddb_entry->fw_ddb_index = INVALID_ENTRY;
  5861. ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
  5862. ddb_entry->ha = ha;
  5863. ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
  5864. ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
  5865. ddb_entry->chap_tbl_idx = INVALID_ENTRY;
  5866. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  5867. atomic_set(&ddb_entry->relogin_timer, 0);
  5868. atomic_set(&ddb_entry->relogin_retry_count, 0);
  5869. def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
  5870. ddb_entry->default_relogin_timeout =
  5871. (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
  5872. def_timeout : LOGIN_TOV;
  5873. ddb_entry->default_time2wait =
  5874. le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
  5875. if (ql4xdisablesysfsboot &&
  5876. (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx))
  5877. set_bit(DF_BOOT_TGT, &ddb_entry->flags);
  5878. }
  5879. static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
  5880. {
  5881. uint32_t idx = 0;
  5882. uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
  5883. uint32_t sts[MBOX_REG_COUNT];
  5884. uint32_t ip_state;
  5885. unsigned long wtime;
  5886. int ret;
  5887. wtime = jiffies + (HZ * IP_CONFIG_TOV);
  5888. do {
  5889. for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
  5890. if (ip_idx[idx] == -1)
  5891. continue;
  5892. ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
  5893. if (ret == QLA_ERROR) {
  5894. ip_idx[idx] = -1;
  5895. continue;
  5896. }
  5897. ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
  5898. DEBUG2(ql4_printk(KERN_INFO, ha,
  5899. "Waiting for IP state for idx = %d, state = 0x%x\n",
  5900. ip_idx[idx], ip_state));
  5901. if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
  5902. ip_state == IP_ADDRSTATE_INVALID ||
  5903. ip_state == IP_ADDRSTATE_PREFERRED ||
  5904. ip_state == IP_ADDRSTATE_DEPRICATED ||
  5905. ip_state == IP_ADDRSTATE_DISABLING)
  5906. ip_idx[idx] = -1;
  5907. }
  5908. /* Break if all IP states checked */
  5909. if ((ip_idx[0] == -1) &&
  5910. (ip_idx[1] == -1) &&
  5911. (ip_idx[2] == -1) &&
  5912. (ip_idx[3] == -1))
  5913. break;
  5914. schedule_timeout_uninterruptible(HZ);
  5915. } while (time_after(wtime, jiffies));
  5916. }
  5917. static int qla4xxx_cmp_fw_stentry(struct dev_db_entry *fw_ddb_entry,
  5918. struct dev_db_entry *flash_ddb_entry)
  5919. {
  5920. uint16_t options = 0;
  5921. size_t ip_len = IP_ADDR_LEN;
  5922. options = le16_to_cpu(fw_ddb_entry->options);
  5923. if (options & DDB_OPT_IPV6_DEVICE)
  5924. ip_len = IPv6_ADDR_LEN;
  5925. if (memcmp(fw_ddb_entry->ip_addr, flash_ddb_entry->ip_addr, ip_len))
  5926. return QLA_ERROR;
  5927. if (memcmp(&fw_ddb_entry->isid[0], &flash_ddb_entry->isid[0],
  5928. sizeof(fw_ddb_entry->isid)))
  5929. return QLA_ERROR;
  5930. if (memcmp(&fw_ddb_entry->port, &flash_ddb_entry->port,
  5931. sizeof(fw_ddb_entry->port)))
  5932. return QLA_ERROR;
  5933. return QLA_SUCCESS;
  5934. }
  5935. static int qla4xxx_find_flash_st_idx(struct scsi_qla_host *ha,
  5936. struct dev_db_entry *fw_ddb_entry,
  5937. uint32_t fw_idx, uint32_t *flash_index)
  5938. {
  5939. struct dev_db_entry *flash_ddb_entry;
  5940. dma_addr_t flash_ddb_entry_dma;
  5941. uint32_t idx = 0;
  5942. int max_ddbs;
  5943. int ret = QLA_ERROR, status;
  5944. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  5945. MAX_DEV_DB_ENTRIES;
  5946. flash_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5947. &flash_ddb_entry_dma);
  5948. if (flash_ddb_entry == NULL || fw_ddb_entry == NULL) {
  5949. ql4_printk(KERN_ERR, ha, "Out of memory\n");
  5950. goto exit_find_st_idx;
  5951. }
  5952. status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
  5953. flash_ddb_entry_dma, fw_idx);
  5954. if (status == QLA_SUCCESS) {
  5955. status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
  5956. if (status == QLA_SUCCESS) {
  5957. *flash_index = fw_idx;
  5958. ret = QLA_SUCCESS;
  5959. goto exit_find_st_idx;
  5960. }
  5961. }
  5962. for (idx = 0; idx < max_ddbs; idx++) {
  5963. status = qla4xxx_flashdb_by_index(ha, flash_ddb_entry,
  5964. flash_ddb_entry_dma, idx);
  5965. if (status == QLA_ERROR)
  5966. continue;
  5967. status = qla4xxx_cmp_fw_stentry(fw_ddb_entry, flash_ddb_entry);
  5968. if (status == QLA_SUCCESS) {
  5969. *flash_index = idx;
  5970. ret = QLA_SUCCESS;
  5971. goto exit_find_st_idx;
  5972. }
  5973. }
  5974. if (idx == max_ddbs)
  5975. ql4_printk(KERN_ERR, ha, "Failed to find ST [%d] in flash\n",
  5976. fw_idx);
  5977. exit_find_st_idx:
  5978. if (flash_ddb_entry)
  5979. dma_pool_free(ha->fw_ddb_dma_pool, flash_ddb_entry,
  5980. flash_ddb_entry_dma);
  5981. return ret;
  5982. }
  5983. static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
  5984. struct list_head *list_st)
  5985. {
  5986. struct qla_ddb_index *st_ddb_idx;
  5987. int max_ddbs;
  5988. int fw_idx_size;
  5989. struct dev_db_entry *fw_ddb_entry;
  5990. dma_addr_t fw_ddb_dma;
  5991. int ret;
  5992. uint32_t idx = 0, next_idx = 0;
  5993. uint32_t state = 0, conn_err = 0;
  5994. uint32_t flash_index = -1;
  5995. uint16_t conn_id = 0;
  5996. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  5997. &fw_ddb_dma);
  5998. if (fw_ddb_entry == NULL) {
  5999. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  6000. goto exit_st_list;
  6001. }
  6002. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6003. MAX_DEV_DB_ENTRIES;
  6004. fw_idx_size = sizeof(struct qla_ddb_index);
  6005. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  6006. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  6007. NULL, &next_idx, &state,
  6008. &conn_err, NULL, &conn_id);
  6009. if (ret == QLA_ERROR)
  6010. break;
  6011. /* Ignore DDB if invalid state (unassigned) */
  6012. if (state == DDB_DS_UNASSIGNED)
  6013. goto continue_next_st;
  6014. /* Check if ST, add to the list_st */
  6015. if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
  6016. goto continue_next_st;
  6017. st_ddb_idx = vzalloc(fw_idx_size);
  6018. if (!st_ddb_idx)
  6019. break;
  6020. ret = qla4xxx_find_flash_st_idx(ha, fw_ddb_entry, idx,
  6021. &flash_index);
  6022. if (ret == QLA_ERROR) {
  6023. ql4_printk(KERN_ERR, ha,
  6024. "No flash entry for ST at idx [%d]\n", idx);
  6025. st_ddb_idx->flash_ddb_idx = idx;
  6026. } else {
  6027. ql4_printk(KERN_INFO, ha,
  6028. "ST at idx [%d] is stored at flash [%d]\n",
  6029. idx, flash_index);
  6030. st_ddb_idx->flash_ddb_idx = flash_index;
  6031. }
  6032. st_ddb_idx->fw_ddb_idx = idx;
  6033. list_add_tail(&st_ddb_idx->list, list_st);
  6034. continue_next_st:
  6035. if (next_idx == 0)
  6036. break;
  6037. }
  6038. exit_st_list:
  6039. if (fw_ddb_entry)
  6040. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6041. }
  6042. /**
  6043. * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
  6044. * @ha: pointer to adapter structure
  6045. * @list_ddb: List from which failed ddb to be removed
  6046. *
  6047. * Iterate over the list of DDBs and find and remove DDBs that are either in
  6048. * no connection active state or failed state
  6049. **/
  6050. static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
  6051. struct list_head *list_ddb)
  6052. {
  6053. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6054. uint32_t next_idx = 0;
  6055. uint32_t state = 0, conn_err = 0;
  6056. int ret;
  6057. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  6058. ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
  6059. NULL, 0, NULL, &next_idx, &state,
  6060. &conn_err, NULL, NULL);
  6061. if (ret == QLA_ERROR)
  6062. continue;
  6063. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6064. state == DDB_DS_SESSION_FAILED) {
  6065. list_del_init(&ddb_idx->list);
  6066. vfree(ddb_idx);
  6067. }
  6068. }
  6069. }
  6070. static void qla4xxx_update_sess_disc_idx(struct scsi_qla_host *ha,
  6071. struct ddb_entry *ddb_entry,
  6072. struct dev_db_entry *fw_ddb_entry)
  6073. {
  6074. struct iscsi_cls_session *cls_sess;
  6075. struct iscsi_session *sess;
  6076. uint32_t max_ddbs = 0;
  6077. uint16_t ddb_link = -1;
  6078. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6079. MAX_DEV_DB_ENTRIES;
  6080. cls_sess = ddb_entry->sess;
  6081. sess = cls_sess->dd_data;
  6082. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6083. if (ddb_link < max_ddbs)
  6084. sess->discovery_parent_idx = ddb_link;
  6085. else
  6086. sess->discovery_parent_idx = DDB_NO_LINK;
  6087. }
  6088. static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
  6089. struct dev_db_entry *fw_ddb_entry,
  6090. int is_reset, uint16_t idx)
  6091. {
  6092. struct iscsi_cls_session *cls_sess;
  6093. struct iscsi_session *sess;
  6094. struct iscsi_cls_conn *cls_conn;
  6095. struct iscsi_endpoint *ep;
  6096. uint16_t cmds_max = 32;
  6097. uint16_t conn_id = 0;
  6098. uint32_t initial_cmdsn = 0;
  6099. int ret = QLA_SUCCESS;
  6100. struct ddb_entry *ddb_entry = NULL;
  6101. /* Create session object, with INVALID_ENTRY,
  6102. * the targer_id would get set when we issue the login
  6103. */
  6104. cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
  6105. cmds_max, sizeof(struct ddb_entry),
  6106. sizeof(struct ql4_task_data),
  6107. initial_cmdsn, INVALID_ENTRY);
  6108. if (!cls_sess) {
  6109. ret = QLA_ERROR;
  6110. goto exit_setup;
  6111. }
  6112. /*
  6113. * so calling module_put function to decrement the
  6114. * reference count.
  6115. **/
  6116. module_put(qla4xxx_iscsi_transport.owner);
  6117. sess = cls_sess->dd_data;
  6118. ddb_entry = sess->dd_data;
  6119. ddb_entry->sess = cls_sess;
  6120. cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
  6121. memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
  6122. sizeof(struct dev_db_entry));
  6123. qla4xxx_setup_flash_ddb_entry(ha, ddb_entry, idx);
  6124. cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
  6125. if (!cls_conn) {
  6126. ret = QLA_ERROR;
  6127. goto exit_setup;
  6128. }
  6129. ddb_entry->conn = cls_conn;
  6130. /* Setup ep, for displaying attributes in sysfs */
  6131. ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
  6132. if (ep) {
  6133. ep->conn = cls_conn;
  6134. cls_conn->ep = ep;
  6135. } else {
  6136. DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
  6137. ret = QLA_ERROR;
  6138. goto exit_setup;
  6139. }
  6140. /* Update sess/conn params */
  6141. qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
  6142. qla4xxx_update_sess_disc_idx(ha, ddb_entry, fw_ddb_entry);
  6143. if (is_reset == RESET_ADAPTER) {
  6144. iscsi_block_session(cls_sess);
  6145. /* Use the relogin path to discover new devices
  6146. * by short-circuting the logic of setting
  6147. * timer to relogin - instead set the flags
  6148. * to initiate login right away.
  6149. */
  6150. set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
  6151. set_bit(DF_RELOGIN, &ddb_entry->flags);
  6152. }
  6153. exit_setup:
  6154. return ret;
  6155. }
  6156. static void qla4xxx_update_fw_ddb_link(struct scsi_qla_host *ha,
  6157. struct list_head *list_ddb,
  6158. struct dev_db_entry *fw_ddb_entry)
  6159. {
  6160. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6161. uint16_t ddb_link;
  6162. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6163. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
  6164. if (ddb_idx->fw_ddb_idx == ddb_link) {
  6165. DEBUG2(ql4_printk(KERN_INFO, ha,
  6166. "Updating NT parent idx from [%d] to [%d]\n",
  6167. ddb_link, ddb_idx->flash_ddb_idx));
  6168. fw_ddb_entry->ddb_link =
  6169. cpu_to_le16(ddb_idx->flash_ddb_idx);
  6170. return;
  6171. }
  6172. }
  6173. }
  6174. static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
  6175. struct list_head *list_nt,
  6176. struct list_head *list_st,
  6177. int is_reset)
  6178. {
  6179. struct dev_db_entry *fw_ddb_entry;
  6180. struct ddb_entry *ddb_entry = NULL;
  6181. dma_addr_t fw_ddb_dma;
  6182. int max_ddbs;
  6183. int fw_idx_size;
  6184. int ret;
  6185. uint32_t idx = 0, next_idx = 0;
  6186. uint32_t state = 0, conn_err = 0;
  6187. uint32_t ddb_idx = -1;
  6188. uint16_t conn_id = 0;
  6189. uint16_t ddb_link = -1;
  6190. struct qla_ddb_index *nt_ddb_idx;
  6191. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6192. &fw_ddb_dma);
  6193. if (fw_ddb_entry == NULL) {
  6194. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  6195. goto exit_nt_list;
  6196. }
  6197. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6198. MAX_DEV_DB_ENTRIES;
  6199. fw_idx_size = sizeof(struct qla_ddb_index);
  6200. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  6201. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  6202. NULL, &next_idx, &state,
  6203. &conn_err, NULL, &conn_id);
  6204. if (ret == QLA_ERROR)
  6205. break;
  6206. if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
  6207. goto continue_next_nt;
  6208. /* Check if NT, then add to list it */
  6209. if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
  6210. goto continue_next_nt;
  6211. ddb_link = le16_to_cpu(fw_ddb_entry->ddb_link);
  6212. if (ddb_link < max_ddbs)
  6213. qla4xxx_update_fw_ddb_link(ha, list_st, fw_ddb_entry);
  6214. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6215. state == DDB_DS_SESSION_FAILED) &&
  6216. (is_reset == INIT_ADAPTER))
  6217. goto continue_next_nt;
  6218. DEBUG2(ql4_printk(KERN_INFO, ha,
  6219. "Adding DDB to session = 0x%x\n", idx));
  6220. if (is_reset == INIT_ADAPTER) {
  6221. nt_ddb_idx = vmalloc(fw_idx_size);
  6222. if (!nt_ddb_idx)
  6223. break;
  6224. nt_ddb_idx->fw_ddb_idx = idx;
  6225. /* Copy original isid as it may get updated in function
  6226. * qla4xxx_update_isid(). We need original isid in
  6227. * function qla4xxx_compare_tuple_ddb to find duplicate
  6228. * target */
  6229. memcpy(&nt_ddb_idx->flash_isid[0],
  6230. &fw_ddb_entry->isid[0],
  6231. sizeof(nt_ddb_idx->flash_isid));
  6232. ret = qla4xxx_is_flash_ddb_exists(ha, list_nt,
  6233. fw_ddb_entry);
  6234. if (ret == QLA_SUCCESS) {
  6235. /* free nt_ddb_idx and do not add to list_nt */
  6236. vfree(nt_ddb_idx);
  6237. goto continue_next_nt;
  6238. }
  6239. /* Copy updated isid */
  6240. memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
  6241. sizeof(struct dev_db_entry));
  6242. list_add_tail(&nt_ddb_idx->list, list_nt);
  6243. } else if (is_reset == RESET_ADAPTER) {
  6244. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry,
  6245. &ddb_idx);
  6246. if (ret == QLA_SUCCESS) {
  6247. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha,
  6248. ddb_idx);
  6249. if (ddb_entry != NULL)
  6250. qla4xxx_update_sess_disc_idx(ha,
  6251. ddb_entry,
  6252. fw_ddb_entry);
  6253. goto continue_next_nt;
  6254. }
  6255. }
  6256. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset, idx);
  6257. if (ret == QLA_ERROR)
  6258. goto exit_nt_list;
  6259. continue_next_nt:
  6260. if (next_idx == 0)
  6261. break;
  6262. }
  6263. exit_nt_list:
  6264. if (fw_ddb_entry)
  6265. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6266. }
  6267. static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
  6268. struct list_head *list_nt,
  6269. uint16_t target_id)
  6270. {
  6271. struct dev_db_entry *fw_ddb_entry;
  6272. dma_addr_t fw_ddb_dma;
  6273. int max_ddbs;
  6274. int fw_idx_size;
  6275. int ret;
  6276. uint32_t idx = 0, next_idx = 0;
  6277. uint32_t state = 0, conn_err = 0;
  6278. uint16_t conn_id = 0;
  6279. struct qla_ddb_index *nt_ddb_idx;
  6280. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6281. &fw_ddb_dma);
  6282. if (fw_ddb_entry == NULL) {
  6283. DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
  6284. goto exit_new_nt_list;
  6285. }
  6286. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  6287. MAX_DEV_DB_ENTRIES;
  6288. fw_idx_size = sizeof(struct qla_ddb_index);
  6289. for (idx = 0; idx < max_ddbs; idx = next_idx) {
  6290. ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
  6291. NULL, &next_idx, &state,
  6292. &conn_err, NULL, &conn_id);
  6293. if (ret == QLA_ERROR)
  6294. break;
  6295. /* Check if NT, then add it to list */
  6296. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  6297. goto continue_next_new_nt;
  6298. if (!(state == DDB_DS_NO_CONNECTION_ACTIVE))
  6299. goto continue_next_new_nt;
  6300. DEBUG2(ql4_printk(KERN_INFO, ha,
  6301. "Adding DDB to session = 0x%x\n", idx));
  6302. nt_ddb_idx = vmalloc(fw_idx_size);
  6303. if (!nt_ddb_idx)
  6304. break;
  6305. nt_ddb_idx->fw_ddb_idx = idx;
  6306. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
  6307. if (ret == QLA_SUCCESS) {
  6308. /* free nt_ddb_idx and do not add to list_nt */
  6309. vfree(nt_ddb_idx);
  6310. goto continue_next_new_nt;
  6311. }
  6312. if (target_id < max_ddbs)
  6313. fw_ddb_entry->ddb_link = cpu_to_le16(target_id);
  6314. list_add_tail(&nt_ddb_idx->list, list_nt);
  6315. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  6316. idx);
  6317. if (ret == QLA_ERROR)
  6318. goto exit_new_nt_list;
  6319. continue_next_new_nt:
  6320. if (next_idx == 0)
  6321. break;
  6322. }
  6323. exit_new_nt_list:
  6324. if (fw_ddb_entry)
  6325. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6326. }
  6327. /**
  6328. * qla4xxx_sysfs_ddb_is_non_persistent - check for non-persistence of ddb entry
  6329. * @dev: dev associated with the sysfs entry
  6330. * @data: pointer to flashnode session object
  6331. *
  6332. * Returns:
  6333. * 1: if flashnode entry is non-persistent
  6334. * 0: if flashnode entry is persistent
  6335. **/
  6336. static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
  6337. {
  6338. struct iscsi_bus_flash_session *fnode_sess;
  6339. if (!iscsi_flashnode_bus_match(dev, NULL))
  6340. return 0;
  6341. fnode_sess = iscsi_dev_to_flash_session(dev);
  6342. return (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT);
  6343. }
  6344. /**
  6345. * qla4xxx_sysfs_ddb_tgt_create - Create sysfs entry for target
  6346. * @ha: pointer to host
  6347. * @fw_ddb_entry: flash ddb data
  6348. * @idx: target index
  6349. * @user: if set then this call is made from userland else from kernel
  6350. *
  6351. * Returns:
  6352. * On sucess: QLA_SUCCESS
  6353. * On failure: QLA_ERROR
  6354. *
  6355. * This create separate sysfs entries for session and connection attributes of
  6356. * the given fw ddb entry.
  6357. * If this is invoked as a result of a userspace call then the entry is marked
  6358. * as nonpersistent using flash_state field.
  6359. **/
  6360. static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,
  6361. struct dev_db_entry *fw_ddb_entry,
  6362. uint16_t *idx, int user)
  6363. {
  6364. struct iscsi_bus_flash_session *fnode_sess = NULL;
  6365. struct iscsi_bus_flash_conn *fnode_conn = NULL;
  6366. int rc = QLA_ERROR;
  6367. fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
  6368. &qla4xxx_iscsi_transport, 0);
  6369. if (!fnode_sess) {
  6370. ql4_printk(KERN_ERR, ha,
  6371. "%s: Unable to create session sysfs entry for flashnode %d of host%lu\n",
  6372. __func__, *idx, ha->host_no);
  6373. goto exit_tgt_create;
  6374. }
  6375. fnode_conn = iscsi_create_flashnode_conn(ha->host, fnode_sess,
  6376. &qla4xxx_iscsi_transport, 0);
  6377. if (!fnode_conn) {
  6378. ql4_printk(KERN_ERR, ha,
  6379. "%s: Unable to create conn sysfs entry for flashnode %d of host%lu\n",
  6380. __func__, *idx, ha->host_no);
  6381. goto free_sess;
  6382. }
  6383. if (user) {
  6384. fnode_sess->flash_state = DEV_DB_NON_PERSISTENT;
  6385. } else {
  6386. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  6387. if (*idx == ha->pri_ddb_idx || *idx == ha->sec_ddb_idx)
  6388. fnode_sess->is_boot_target = 1;
  6389. else
  6390. fnode_sess->is_boot_target = 0;
  6391. }
  6392. rc = qla4xxx_copy_from_fwddb_param(fnode_sess, fnode_conn,
  6393. fw_ddb_entry);
  6394. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  6395. __func__, fnode_sess->dev.kobj.name);
  6396. ql4_printk(KERN_INFO, ha, "%s: sysfs entry %s created\n",
  6397. __func__, fnode_conn->dev.kobj.name);
  6398. return QLA_SUCCESS;
  6399. free_sess:
  6400. iscsi_destroy_flashnode_sess(fnode_sess);
  6401. exit_tgt_create:
  6402. return QLA_ERROR;
  6403. }
  6404. /**
  6405. * qla4xxx_sysfs_ddb_add - Add new ddb entry in flash
  6406. * @shost: pointer to host
  6407. * @buf: type of ddb entry (ipv4/ipv6)
  6408. * @len: length of buf
  6409. *
  6410. * This creates new ddb entry in the flash by finding first free index and
  6411. * storing default ddb there. And then create sysfs entry for the new ddb entry.
  6412. **/
  6413. static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
  6414. int len)
  6415. {
  6416. struct scsi_qla_host *ha = to_qla_host(shost);
  6417. struct dev_db_entry *fw_ddb_entry = NULL;
  6418. dma_addr_t fw_ddb_entry_dma;
  6419. struct device *dev;
  6420. uint16_t idx = 0;
  6421. uint16_t max_ddbs = 0;
  6422. uint32_t options = 0;
  6423. uint32_t rval = QLA_ERROR;
  6424. if (strncasecmp(PORTAL_TYPE_IPV4, buf, 4) &&
  6425. strncasecmp(PORTAL_TYPE_IPV6, buf, 4)) {
  6426. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Invalid portal type\n",
  6427. __func__));
  6428. goto exit_ddb_add;
  6429. }
  6430. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  6431. MAX_DEV_DB_ENTRIES;
  6432. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6433. &fw_ddb_entry_dma, GFP_KERNEL);
  6434. if (!fw_ddb_entry) {
  6435. DEBUG2(ql4_printk(KERN_ERR, ha,
  6436. "%s: Unable to allocate dma buffer\n",
  6437. __func__));
  6438. goto exit_ddb_add;
  6439. }
  6440. dev = iscsi_find_flashnode_sess(ha->host, NULL,
  6441. qla4xxx_sysfs_ddb_is_non_persistent);
  6442. if (dev) {
  6443. ql4_printk(KERN_ERR, ha,
  6444. "%s: A non-persistent entry %s found\n",
  6445. __func__, dev->kobj.name);
  6446. put_device(dev);
  6447. goto exit_ddb_add;
  6448. }
  6449. /* Index 0 and 1 are reserved for boot target entries */
  6450. for (idx = 2; idx < max_ddbs; idx++) {
  6451. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry,
  6452. fw_ddb_entry_dma, idx))
  6453. break;
  6454. }
  6455. if (idx == max_ddbs)
  6456. goto exit_ddb_add;
  6457. if (!strncasecmp("ipv6", buf, 4))
  6458. options |= IPV6_DEFAULT_DDB_ENTRY;
  6459. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6460. if (rval == QLA_ERROR)
  6461. goto exit_ddb_add;
  6462. rval = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 1);
  6463. exit_ddb_add:
  6464. if (fw_ddb_entry)
  6465. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6466. fw_ddb_entry, fw_ddb_entry_dma);
  6467. if (rval == QLA_SUCCESS)
  6468. return idx;
  6469. else
  6470. return -EIO;
  6471. }
  6472. /**
  6473. * qla4xxx_sysfs_ddb_apply - write the target ddb contents to Flash
  6474. * @fnode_sess: pointer to session attrs of flash ddb entry
  6475. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6476. *
  6477. * This writes the contents of target ddb buffer to Flash with a valid cookie
  6478. * value in order to make the ddb entry persistent.
  6479. **/
  6480. static int qla4xxx_sysfs_ddb_apply(struct iscsi_bus_flash_session *fnode_sess,
  6481. struct iscsi_bus_flash_conn *fnode_conn)
  6482. {
  6483. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6484. struct scsi_qla_host *ha = to_qla_host(shost);
  6485. uint32_t dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  6486. struct dev_db_entry *fw_ddb_entry = NULL;
  6487. dma_addr_t fw_ddb_entry_dma;
  6488. uint32_t options = 0;
  6489. int rval = 0;
  6490. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6491. &fw_ddb_entry_dma, GFP_KERNEL);
  6492. if (!fw_ddb_entry) {
  6493. DEBUG2(ql4_printk(KERN_ERR, ha,
  6494. "%s: Unable to allocate dma buffer\n",
  6495. __func__));
  6496. rval = -ENOMEM;
  6497. goto exit_ddb_apply;
  6498. }
  6499. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6500. options |= IPV6_DEFAULT_DDB_ENTRY;
  6501. rval = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6502. if (rval == QLA_ERROR)
  6503. goto exit_ddb_apply;
  6504. dev_db_start_offset += (fnode_sess->target_id *
  6505. sizeof(*fw_ddb_entry));
  6506. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  6507. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  6508. rval = qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  6509. sizeof(*fw_ddb_entry), FLASH_OPT_RMW_COMMIT);
  6510. if (rval == QLA_SUCCESS) {
  6511. fnode_sess->flash_state = DEV_DB_PERSISTENT;
  6512. ql4_printk(KERN_INFO, ha,
  6513. "%s: flash node %u of host %lu written to flash\n",
  6514. __func__, fnode_sess->target_id, ha->host_no);
  6515. } else {
  6516. rval = -EIO;
  6517. ql4_printk(KERN_ERR, ha,
  6518. "%s: Error while writing flash node %u of host %lu to flash\n",
  6519. __func__, fnode_sess->target_id, ha->host_no);
  6520. }
  6521. exit_ddb_apply:
  6522. if (fw_ddb_entry)
  6523. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6524. fw_ddb_entry, fw_ddb_entry_dma);
  6525. return rval;
  6526. }
  6527. static ssize_t qla4xxx_sysfs_ddb_conn_open(struct scsi_qla_host *ha,
  6528. struct dev_db_entry *fw_ddb_entry,
  6529. uint16_t idx)
  6530. {
  6531. struct dev_db_entry *ddb_entry = NULL;
  6532. dma_addr_t ddb_entry_dma;
  6533. unsigned long wtime;
  6534. uint32_t mbx_sts = 0;
  6535. uint32_t state = 0, conn_err = 0;
  6536. uint16_t tmo = 0;
  6537. int ret = 0;
  6538. ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  6539. &ddb_entry_dma, GFP_KERNEL);
  6540. if (!ddb_entry) {
  6541. DEBUG2(ql4_printk(KERN_ERR, ha,
  6542. "%s: Unable to allocate dma buffer\n",
  6543. __func__));
  6544. return QLA_ERROR;
  6545. }
  6546. memcpy(ddb_entry, fw_ddb_entry, sizeof(*ddb_entry));
  6547. ret = qla4xxx_set_ddb_entry(ha, idx, ddb_entry_dma, &mbx_sts);
  6548. if (ret != QLA_SUCCESS) {
  6549. DEBUG2(ql4_printk(KERN_ERR, ha,
  6550. "%s: Unable to set ddb entry for index %d\n",
  6551. __func__, idx));
  6552. goto exit_ddb_conn_open;
  6553. }
  6554. qla4xxx_conn_open(ha, idx);
  6555. /* To ensure that sendtargets is done, wait for at least 12 secs */
  6556. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  6557. (ha->def_timeout < LOGIN_TOV * 10) ?
  6558. ha->def_timeout : LOGIN_TOV);
  6559. DEBUG2(ql4_printk(KERN_INFO, ha,
  6560. "Default time to wait for login to ddb %d\n", tmo));
  6561. wtime = jiffies + (HZ * tmo);
  6562. do {
  6563. ret = qla4xxx_get_fwddb_entry(ha, idx, NULL, 0, NULL,
  6564. NULL, &state, &conn_err, NULL,
  6565. NULL);
  6566. if (ret == QLA_ERROR)
  6567. continue;
  6568. if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
  6569. state == DDB_DS_SESSION_FAILED)
  6570. break;
  6571. schedule_timeout_uninterruptible(HZ / 10);
  6572. } while (time_after(wtime, jiffies));
  6573. exit_ddb_conn_open:
  6574. if (ddb_entry)
  6575. dma_free_coherent(&ha->pdev->dev, sizeof(*ddb_entry),
  6576. ddb_entry, ddb_entry_dma);
  6577. return ret;
  6578. }
  6579. static int qla4xxx_ddb_login_st(struct scsi_qla_host *ha,
  6580. struct dev_db_entry *fw_ddb_entry,
  6581. uint16_t target_id)
  6582. {
  6583. struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
  6584. struct list_head list_nt;
  6585. uint16_t ddb_index;
  6586. int ret = 0;
  6587. if (test_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags)) {
  6588. ql4_printk(KERN_WARNING, ha,
  6589. "%s: A discovery already in progress!\n", __func__);
  6590. return QLA_ERROR;
  6591. }
  6592. INIT_LIST_HEAD(&list_nt);
  6593. set_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  6594. ret = qla4xxx_get_ddb_index(ha, &ddb_index);
  6595. if (ret == QLA_ERROR)
  6596. goto exit_login_st_clr_bit;
  6597. ret = qla4xxx_sysfs_ddb_conn_open(ha, fw_ddb_entry, ddb_index);
  6598. if (ret == QLA_ERROR)
  6599. goto exit_login_st;
  6600. qla4xxx_build_new_nt_list(ha, &list_nt, target_id);
  6601. list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, &list_nt, list) {
  6602. list_del_init(&ddb_idx->list);
  6603. qla4xxx_clear_ddb_entry(ha, ddb_idx->fw_ddb_idx);
  6604. vfree(ddb_idx);
  6605. }
  6606. exit_login_st:
  6607. if (qla4xxx_clear_ddb_entry(ha, ddb_index) == QLA_ERROR) {
  6608. ql4_printk(KERN_ERR, ha,
  6609. "Unable to clear DDB index = 0x%x\n", ddb_index);
  6610. }
  6611. clear_bit(ddb_index, ha->ddb_idx_map);
  6612. exit_login_st_clr_bit:
  6613. clear_bit(AF_ST_DISCOVERY_IN_PROGRESS, &ha->flags);
  6614. return ret;
  6615. }
  6616. static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,
  6617. struct dev_db_entry *fw_ddb_entry,
  6618. uint16_t idx)
  6619. {
  6620. int ret = QLA_ERROR;
  6621. ret = qla4xxx_is_session_exists(ha, fw_ddb_entry, NULL);
  6622. if (ret != QLA_SUCCESS)
  6623. ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, RESET_ADAPTER,
  6624. idx);
  6625. else
  6626. ret = -EPERM;
  6627. return ret;
  6628. }
  6629. /**
  6630. * qla4xxx_sysfs_ddb_login - Login to the specified target
  6631. * @fnode_sess: pointer to session attrs of flash ddb entry
  6632. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6633. *
  6634. * This logs in to the specified target
  6635. **/
  6636. static int qla4xxx_sysfs_ddb_login(struct iscsi_bus_flash_session *fnode_sess,
  6637. struct iscsi_bus_flash_conn *fnode_conn)
  6638. {
  6639. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6640. struct scsi_qla_host *ha = to_qla_host(shost);
  6641. struct dev_db_entry *fw_ddb_entry = NULL;
  6642. dma_addr_t fw_ddb_entry_dma;
  6643. uint32_t options = 0;
  6644. int ret = 0;
  6645. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT) {
  6646. ql4_printk(KERN_ERR, ha,
  6647. "%s: Target info is not persistent\n", __func__);
  6648. ret = -EIO;
  6649. goto exit_ddb_login;
  6650. }
  6651. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6652. &fw_ddb_entry_dma, GFP_KERNEL);
  6653. if (!fw_ddb_entry) {
  6654. DEBUG2(ql4_printk(KERN_ERR, ha,
  6655. "%s: Unable to allocate dma buffer\n",
  6656. __func__));
  6657. ret = -ENOMEM;
  6658. goto exit_ddb_login;
  6659. }
  6660. if (!strncasecmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6661. options |= IPV6_DEFAULT_DDB_ENTRY;
  6662. ret = qla4xxx_get_default_ddb(ha, options, fw_ddb_entry_dma);
  6663. if (ret == QLA_ERROR)
  6664. goto exit_ddb_login;
  6665. qla4xxx_copy_to_fwddb_param(fnode_sess, fnode_conn, fw_ddb_entry);
  6666. fw_ddb_entry->cookie = DDB_VALID_COOKIE;
  6667. if (strlen((char *)fw_ddb_entry->iscsi_name) == 0)
  6668. ret = qla4xxx_ddb_login_st(ha, fw_ddb_entry,
  6669. fnode_sess->target_id);
  6670. else
  6671. ret = qla4xxx_ddb_login_nt(ha, fw_ddb_entry,
  6672. fnode_sess->target_id);
  6673. if (ret > 0)
  6674. ret = -EIO;
  6675. exit_ddb_login:
  6676. if (fw_ddb_entry)
  6677. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6678. fw_ddb_entry, fw_ddb_entry_dma);
  6679. return ret;
  6680. }
  6681. /**
  6682. * qla4xxx_sysfs_ddb_logout_sid - Logout session for the specified target
  6683. * @cls_sess: pointer to session to be logged out
  6684. *
  6685. * This performs session log out from the specified target
  6686. **/
  6687. static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)
  6688. {
  6689. struct iscsi_session *sess;
  6690. struct ddb_entry *ddb_entry = NULL;
  6691. struct scsi_qla_host *ha;
  6692. struct dev_db_entry *fw_ddb_entry = NULL;
  6693. dma_addr_t fw_ddb_entry_dma;
  6694. unsigned long flags;
  6695. unsigned long wtime;
  6696. uint32_t ddb_state;
  6697. int options;
  6698. int ret = 0;
  6699. sess = cls_sess->dd_data;
  6700. ddb_entry = sess->dd_data;
  6701. ha = ddb_entry->ha;
  6702. if (ddb_entry->ddb_type != FLASH_DDB) {
  6703. ql4_printk(KERN_ERR, ha, "%s: Not a flash node session\n",
  6704. __func__);
  6705. ret = -ENXIO;
  6706. goto exit_ddb_logout;
  6707. }
  6708. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  6709. ql4_printk(KERN_ERR, ha,
  6710. "%s: Logout from boot target entry is not permitted.\n",
  6711. __func__);
  6712. ret = -EPERM;
  6713. goto exit_ddb_logout;
  6714. }
  6715. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6716. &fw_ddb_entry_dma, GFP_KERNEL);
  6717. if (!fw_ddb_entry) {
  6718. ql4_printk(KERN_ERR, ha,
  6719. "%s: Unable to allocate dma buffer\n", __func__);
  6720. ret = -ENOMEM;
  6721. goto exit_ddb_logout;
  6722. }
  6723. if (test_and_set_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags))
  6724. goto ddb_logout_init;
  6725. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  6726. fw_ddb_entry, fw_ddb_entry_dma,
  6727. NULL, NULL, &ddb_state, NULL,
  6728. NULL, NULL);
  6729. if (ret == QLA_ERROR)
  6730. goto ddb_logout_init;
  6731. if (ddb_state == DDB_DS_SESSION_ACTIVE)
  6732. goto ddb_logout_init;
  6733. /* wait until next relogin is triggered using DF_RELOGIN and
  6734. * clear DF_RELOGIN to avoid invocation of further relogin
  6735. */
  6736. wtime = jiffies + (HZ * RELOGIN_TOV);
  6737. do {
  6738. if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags))
  6739. goto ddb_logout_init;
  6740. schedule_timeout_uninterruptible(HZ);
  6741. } while ((time_after(wtime, jiffies)));
  6742. ddb_logout_init:
  6743. atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
  6744. atomic_set(&ddb_entry->relogin_timer, 0);
  6745. options = LOGOUT_OPTION_CLOSE_SESSION;
  6746. qla4xxx_session_logout_ddb(ha, ddb_entry, options);
  6747. memset(fw_ddb_entry, 0, sizeof(*fw_ddb_entry));
  6748. wtime = jiffies + (HZ * LOGOUT_TOV);
  6749. do {
  6750. ret = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  6751. fw_ddb_entry, fw_ddb_entry_dma,
  6752. NULL, NULL, &ddb_state, NULL,
  6753. NULL, NULL);
  6754. if (ret == QLA_ERROR)
  6755. goto ddb_logout_clr_sess;
  6756. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  6757. (ddb_state == DDB_DS_SESSION_FAILED))
  6758. goto ddb_logout_clr_sess;
  6759. schedule_timeout_uninterruptible(HZ);
  6760. } while ((time_after(wtime, jiffies)));
  6761. ddb_logout_clr_sess:
  6762. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  6763. /*
  6764. * we have decremented the reference count of the driver
  6765. * when we setup the session to have the driver unload
  6766. * to be seamless without actually destroying the
  6767. * session
  6768. **/
  6769. try_module_get(qla4xxx_iscsi_transport.owner);
  6770. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  6771. spin_lock_irqsave(&ha->hardware_lock, flags);
  6772. qla4xxx_free_ddb(ha, ddb_entry);
  6773. clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
  6774. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6775. iscsi_session_teardown(ddb_entry->sess);
  6776. clear_bit(DF_DISABLE_RELOGIN, &ddb_entry->flags);
  6777. ret = QLA_SUCCESS;
  6778. exit_ddb_logout:
  6779. if (fw_ddb_entry)
  6780. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  6781. fw_ddb_entry, fw_ddb_entry_dma);
  6782. return ret;
  6783. }
  6784. /**
  6785. * qla4xxx_sysfs_ddb_logout - Logout from the specified target
  6786. * @fnode_sess: pointer to session attrs of flash ddb entry
  6787. * @fnode_conn: pointer to connection attrs of flash ddb entry
  6788. *
  6789. * This performs log out from the specified target
  6790. **/
  6791. static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
  6792. struct iscsi_bus_flash_conn *fnode_conn)
  6793. {
  6794. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6795. struct scsi_qla_host *ha = to_qla_host(shost);
  6796. struct ql4_tuple_ddb *flash_tddb = NULL;
  6797. struct ql4_tuple_ddb *tmp_tddb = NULL;
  6798. struct dev_db_entry *fw_ddb_entry = NULL;
  6799. struct ddb_entry *ddb_entry = NULL;
  6800. dma_addr_t fw_ddb_dma;
  6801. uint32_t next_idx = 0;
  6802. uint32_t state = 0, conn_err = 0;
  6803. uint16_t conn_id = 0;
  6804. int idx, index;
  6805. int status, ret = 0;
  6806. fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
  6807. &fw_ddb_dma);
  6808. if (fw_ddb_entry == NULL) {
  6809. ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
  6810. ret = -ENOMEM;
  6811. goto exit_ddb_logout;
  6812. }
  6813. flash_tddb = vzalloc(sizeof(*flash_tddb));
  6814. if (!flash_tddb) {
  6815. ql4_printk(KERN_WARNING, ha,
  6816. "%s:Memory Allocation failed.\n", __func__);
  6817. ret = -ENOMEM;
  6818. goto exit_ddb_logout;
  6819. }
  6820. tmp_tddb = vzalloc(sizeof(*tmp_tddb));
  6821. if (!tmp_tddb) {
  6822. ql4_printk(KERN_WARNING, ha,
  6823. "%s:Memory Allocation failed.\n", __func__);
  6824. ret = -ENOMEM;
  6825. goto exit_ddb_logout;
  6826. }
  6827. if (!fnode_sess->targetname) {
  6828. ql4_printk(KERN_ERR, ha,
  6829. "%s:Cannot logout from SendTarget entry\n",
  6830. __func__);
  6831. ret = -EPERM;
  6832. goto exit_ddb_logout;
  6833. }
  6834. if (fnode_sess->is_boot_target) {
  6835. ql4_printk(KERN_ERR, ha,
  6836. "%s: Logout from boot target entry is not permitted.\n",
  6837. __func__);
  6838. ret = -EPERM;
  6839. goto exit_ddb_logout;
  6840. }
  6841. strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
  6842. ISCSI_NAME_SIZE);
  6843. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  6844. sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
  6845. else
  6846. sprintf(flash_tddb->ip_addr, "%pI4", fnode_conn->ipaddress);
  6847. flash_tddb->tpgt = fnode_sess->tpgt;
  6848. flash_tddb->port = fnode_conn->port;
  6849. COPY_ISID(flash_tddb->isid, fnode_sess->isid);
  6850. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  6851. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  6852. if (ddb_entry == NULL)
  6853. continue;
  6854. if (ddb_entry->ddb_type != FLASH_DDB)
  6855. continue;
  6856. index = ddb_entry->sess->target_id;
  6857. status = qla4xxx_get_fwddb_entry(ha, index, fw_ddb_entry,
  6858. fw_ddb_dma, NULL, &next_idx,
  6859. &state, &conn_err, NULL,
  6860. &conn_id);
  6861. if (status == QLA_ERROR) {
  6862. ret = -ENOMEM;
  6863. break;
  6864. }
  6865. qla4xxx_convert_param_ddb(fw_ddb_entry, tmp_tddb, NULL);
  6866. status = qla4xxx_compare_tuple_ddb(ha, flash_tddb, tmp_tddb,
  6867. true);
  6868. if (status == QLA_SUCCESS) {
  6869. ret = qla4xxx_sysfs_ddb_logout_sid(ddb_entry->sess);
  6870. break;
  6871. }
  6872. }
  6873. if (idx == MAX_DDB_ENTRIES)
  6874. ret = -ESRCH;
  6875. exit_ddb_logout:
  6876. if (flash_tddb)
  6877. vfree(flash_tddb);
  6878. if (tmp_tddb)
  6879. vfree(tmp_tddb);
  6880. if (fw_ddb_entry)
  6881. dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
  6882. return ret;
  6883. }
  6884. static int
  6885. qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
  6886. int param, char *buf)
  6887. {
  6888. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  6889. struct scsi_qla_host *ha = to_qla_host(shost);
  6890. struct iscsi_bus_flash_conn *fnode_conn;
  6891. struct ql4_chap_table chap_tbl;
  6892. struct device *dev;
  6893. int parent_type;
  6894. int rc = 0;
  6895. dev = iscsi_find_flashnode_conn(fnode_sess);
  6896. if (!dev)
  6897. return -EIO;
  6898. fnode_conn = iscsi_dev_to_flash_conn(dev);
  6899. switch (param) {
  6900. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  6901. rc = sprintf(buf, "%u\n", fnode_conn->is_fw_assigned_ipv6);
  6902. break;
  6903. case ISCSI_FLASHNODE_PORTAL_TYPE:
  6904. rc = sprintf(buf, "%s\n", fnode_sess->portal_type);
  6905. break;
  6906. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  6907. rc = sprintf(buf, "%u\n", fnode_sess->auto_snd_tgt_disable);
  6908. break;
  6909. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  6910. rc = sprintf(buf, "%u\n", fnode_sess->discovery_sess);
  6911. break;
  6912. case ISCSI_FLASHNODE_ENTRY_EN:
  6913. rc = sprintf(buf, "%u\n", fnode_sess->entry_state);
  6914. break;
  6915. case ISCSI_FLASHNODE_HDR_DGST_EN:
  6916. rc = sprintf(buf, "%u\n", fnode_conn->hdrdgst_en);
  6917. break;
  6918. case ISCSI_FLASHNODE_DATA_DGST_EN:
  6919. rc = sprintf(buf, "%u\n", fnode_conn->datadgst_en);
  6920. break;
  6921. case ISCSI_FLASHNODE_IMM_DATA_EN:
  6922. rc = sprintf(buf, "%u\n", fnode_sess->imm_data_en);
  6923. break;
  6924. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  6925. rc = sprintf(buf, "%u\n", fnode_sess->initial_r2t_en);
  6926. break;
  6927. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  6928. rc = sprintf(buf, "%u\n", fnode_sess->dataseq_inorder_en);
  6929. break;
  6930. case ISCSI_FLASHNODE_PDU_INORDER:
  6931. rc = sprintf(buf, "%u\n", fnode_sess->pdu_inorder_en);
  6932. break;
  6933. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  6934. rc = sprintf(buf, "%u\n", fnode_sess->chap_auth_en);
  6935. break;
  6936. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  6937. rc = sprintf(buf, "%u\n", fnode_conn->snack_req_en);
  6938. break;
  6939. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  6940. rc = sprintf(buf, "%u\n", fnode_sess->discovery_logout_en);
  6941. break;
  6942. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  6943. rc = sprintf(buf, "%u\n", fnode_sess->bidi_chap_en);
  6944. break;
  6945. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  6946. rc = sprintf(buf, "%u\n", fnode_sess->discovery_auth_optional);
  6947. break;
  6948. case ISCSI_FLASHNODE_ERL:
  6949. rc = sprintf(buf, "%u\n", fnode_sess->erl);
  6950. break;
  6951. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  6952. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_stat);
  6953. break;
  6954. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  6955. rc = sprintf(buf, "%u\n", fnode_conn->tcp_nagle_disable);
  6956. break;
  6957. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  6958. rc = sprintf(buf, "%u\n", fnode_conn->tcp_wsf_disable);
  6959. break;
  6960. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  6961. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timer_scale);
  6962. break;
  6963. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  6964. rc = sprintf(buf, "%u\n", fnode_conn->tcp_timestamp_en);
  6965. break;
  6966. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  6967. rc = sprintf(buf, "%u\n", fnode_conn->fragment_disable);
  6968. break;
  6969. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  6970. rc = sprintf(buf, "%u\n", fnode_conn->max_recv_dlength);
  6971. break;
  6972. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  6973. rc = sprintf(buf, "%u\n", fnode_conn->max_xmit_dlength);
  6974. break;
  6975. case ISCSI_FLASHNODE_FIRST_BURST:
  6976. rc = sprintf(buf, "%u\n", fnode_sess->first_burst);
  6977. break;
  6978. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  6979. rc = sprintf(buf, "%u\n", fnode_sess->time2wait);
  6980. break;
  6981. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  6982. rc = sprintf(buf, "%u\n", fnode_sess->time2retain);
  6983. break;
  6984. case ISCSI_FLASHNODE_MAX_R2T:
  6985. rc = sprintf(buf, "%u\n", fnode_sess->max_r2t);
  6986. break;
  6987. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  6988. rc = sprintf(buf, "%u\n", fnode_conn->keepalive_timeout);
  6989. break;
  6990. case ISCSI_FLASHNODE_ISID:
  6991. rc = sprintf(buf, "%02x%02x%02x%02x%02x%02x\n",
  6992. fnode_sess->isid[0], fnode_sess->isid[1],
  6993. fnode_sess->isid[2], fnode_sess->isid[3],
  6994. fnode_sess->isid[4], fnode_sess->isid[5]);
  6995. break;
  6996. case ISCSI_FLASHNODE_TSID:
  6997. rc = sprintf(buf, "%u\n", fnode_sess->tsid);
  6998. break;
  6999. case ISCSI_FLASHNODE_PORT:
  7000. rc = sprintf(buf, "%d\n", fnode_conn->port);
  7001. break;
  7002. case ISCSI_FLASHNODE_MAX_BURST:
  7003. rc = sprintf(buf, "%u\n", fnode_sess->max_burst);
  7004. break;
  7005. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  7006. rc = sprintf(buf, "%u\n",
  7007. fnode_sess->default_taskmgmt_timeout);
  7008. break;
  7009. case ISCSI_FLASHNODE_IPADDR:
  7010. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7011. rc = sprintf(buf, "%pI6\n", fnode_conn->ipaddress);
  7012. else
  7013. rc = sprintf(buf, "%pI4\n", fnode_conn->ipaddress);
  7014. break;
  7015. case ISCSI_FLASHNODE_ALIAS:
  7016. if (fnode_sess->targetalias)
  7017. rc = sprintf(buf, "%s\n", fnode_sess->targetalias);
  7018. else
  7019. rc = sprintf(buf, "\n");
  7020. break;
  7021. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  7022. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7023. rc = sprintf(buf, "%pI6\n",
  7024. fnode_conn->redirect_ipaddr);
  7025. else
  7026. rc = sprintf(buf, "%pI4\n",
  7027. fnode_conn->redirect_ipaddr);
  7028. break;
  7029. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  7030. rc = sprintf(buf, "%u\n", fnode_conn->max_segment_size);
  7031. break;
  7032. case ISCSI_FLASHNODE_LOCAL_PORT:
  7033. rc = sprintf(buf, "%u\n", fnode_conn->local_port);
  7034. break;
  7035. case ISCSI_FLASHNODE_IPV4_TOS:
  7036. rc = sprintf(buf, "%u\n", fnode_conn->ipv4_tos);
  7037. break;
  7038. case ISCSI_FLASHNODE_IPV6_TC:
  7039. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7040. rc = sprintf(buf, "%u\n",
  7041. fnode_conn->ipv6_traffic_class);
  7042. else
  7043. rc = sprintf(buf, "\n");
  7044. break;
  7045. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  7046. rc = sprintf(buf, "%u\n", fnode_conn->ipv6_flow_label);
  7047. break;
  7048. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  7049. if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
  7050. rc = sprintf(buf, "%pI6\n",
  7051. fnode_conn->link_local_ipv6_addr);
  7052. else
  7053. rc = sprintf(buf, "\n");
  7054. break;
  7055. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  7056. rc = sprintf(buf, "%u\n", fnode_sess->discovery_parent_idx);
  7057. break;
  7058. case ISCSI_FLASHNODE_DISCOVERY_PARENT_TYPE:
  7059. if (fnode_sess->discovery_parent_type == DDB_ISNS)
  7060. parent_type = ISCSI_DISC_PARENT_ISNS;
  7061. else if (fnode_sess->discovery_parent_type == DDB_NO_LINK)
  7062. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  7063. else if (fnode_sess->discovery_parent_type < MAX_DDB_ENTRIES)
  7064. parent_type = ISCSI_DISC_PARENT_SENDTGT;
  7065. else
  7066. parent_type = ISCSI_DISC_PARENT_UNKNOWN;
  7067. rc = sprintf(buf, "%s\n",
  7068. iscsi_get_discovery_parent_name(parent_type));
  7069. break;
  7070. case ISCSI_FLASHNODE_NAME:
  7071. if (fnode_sess->targetname)
  7072. rc = sprintf(buf, "%s\n", fnode_sess->targetname);
  7073. else
  7074. rc = sprintf(buf, "\n");
  7075. break;
  7076. case ISCSI_FLASHNODE_TPGT:
  7077. rc = sprintf(buf, "%u\n", fnode_sess->tpgt);
  7078. break;
  7079. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  7080. rc = sprintf(buf, "%u\n", fnode_conn->tcp_xmit_wsf);
  7081. break;
  7082. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  7083. rc = sprintf(buf, "%u\n", fnode_conn->tcp_recv_wsf);
  7084. break;
  7085. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  7086. rc = sprintf(buf, "%u\n", fnode_sess->chap_out_idx);
  7087. break;
  7088. case ISCSI_FLASHNODE_USERNAME:
  7089. if (fnode_sess->chap_auth_en) {
  7090. qla4xxx_get_uni_chap_at_index(ha,
  7091. chap_tbl.name,
  7092. chap_tbl.secret,
  7093. fnode_sess->chap_out_idx);
  7094. rc = sprintf(buf, "%s\n", chap_tbl.name);
  7095. } else {
  7096. rc = sprintf(buf, "\n");
  7097. }
  7098. break;
  7099. case ISCSI_FLASHNODE_PASSWORD:
  7100. if (fnode_sess->chap_auth_en) {
  7101. qla4xxx_get_uni_chap_at_index(ha,
  7102. chap_tbl.name,
  7103. chap_tbl.secret,
  7104. fnode_sess->chap_out_idx);
  7105. rc = sprintf(buf, "%s\n", chap_tbl.secret);
  7106. } else {
  7107. rc = sprintf(buf, "\n");
  7108. }
  7109. break;
  7110. case ISCSI_FLASHNODE_STATSN:
  7111. rc = sprintf(buf, "%u\n", fnode_conn->statsn);
  7112. break;
  7113. case ISCSI_FLASHNODE_EXP_STATSN:
  7114. rc = sprintf(buf, "%u\n", fnode_conn->exp_statsn);
  7115. break;
  7116. case ISCSI_FLASHNODE_IS_BOOT_TGT:
  7117. rc = sprintf(buf, "%u\n", fnode_sess->is_boot_target);
  7118. break;
  7119. default:
  7120. rc = -ENOSYS;
  7121. break;
  7122. }
  7123. put_device(dev);
  7124. return rc;
  7125. }
  7126. /**
  7127. * qla4xxx_sysfs_ddb_set_param - Set parameter for firmware DDB entry
  7128. * @fnode_sess: pointer to session attrs of flash ddb entry
  7129. * @fnode_conn: pointer to connection attrs of flash ddb entry
  7130. * @data: Parameters and their values to update
  7131. * @len: len of data
  7132. *
  7133. * This sets the parameter of flash ddb entry and writes them to flash
  7134. **/
  7135. static int
  7136. qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,
  7137. struct iscsi_bus_flash_conn *fnode_conn,
  7138. void *data, int len)
  7139. {
  7140. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  7141. struct scsi_qla_host *ha = to_qla_host(shost);
  7142. struct iscsi_flashnode_param_info *fnode_param;
  7143. struct ql4_chap_table chap_tbl;
  7144. struct nlattr *attr;
  7145. uint16_t chap_out_idx = INVALID_ENTRY;
  7146. int rc = QLA_ERROR;
  7147. uint32_t rem = len;
  7148. memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
  7149. nla_for_each_attr(attr, data, len, rem) {
  7150. fnode_param = nla_data(attr);
  7151. switch (fnode_param->param) {
  7152. case ISCSI_FLASHNODE_IS_FW_ASSIGNED_IPV6:
  7153. fnode_conn->is_fw_assigned_ipv6 = fnode_param->value[0];
  7154. break;
  7155. case ISCSI_FLASHNODE_PORTAL_TYPE:
  7156. memcpy(fnode_sess->portal_type, fnode_param->value,
  7157. strlen(fnode_sess->portal_type));
  7158. break;
  7159. case ISCSI_FLASHNODE_AUTO_SND_TGT_DISABLE:
  7160. fnode_sess->auto_snd_tgt_disable =
  7161. fnode_param->value[0];
  7162. break;
  7163. case ISCSI_FLASHNODE_DISCOVERY_SESS:
  7164. fnode_sess->discovery_sess = fnode_param->value[0];
  7165. break;
  7166. case ISCSI_FLASHNODE_ENTRY_EN:
  7167. fnode_sess->entry_state = fnode_param->value[0];
  7168. break;
  7169. case ISCSI_FLASHNODE_HDR_DGST_EN:
  7170. fnode_conn->hdrdgst_en = fnode_param->value[0];
  7171. break;
  7172. case ISCSI_FLASHNODE_DATA_DGST_EN:
  7173. fnode_conn->datadgst_en = fnode_param->value[0];
  7174. break;
  7175. case ISCSI_FLASHNODE_IMM_DATA_EN:
  7176. fnode_sess->imm_data_en = fnode_param->value[0];
  7177. break;
  7178. case ISCSI_FLASHNODE_INITIAL_R2T_EN:
  7179. fnode_sess->initial_r2t_en = fnode_param->value[0];
  7180. break;
  7181. case ISCSI_FLASHNODE_DATASEQ_INORDER:
  7182. fnode_sess->dataseq_inorder_en = fnode_param->value[0];
  7183. break;
  7184. case ISCSI_FLASHNODE_PDU_INORDER:
  7185. fnode_sess->pdu_inorder_en = fnode_param->value[0];
  7186. break;
  7187. case ISCSI_FLASHNODE_CHAP_AUTH_EN:
  7188. fnode_sess->chap_auth_en = fnode_param->value[0];
  7189. /* Invalidate chap index if chap auth is disabled */
  7190. if (!fnode_sess->chap_auth_en)
  7191. fnode_sess->chap_out_idx = INVALID_ENTRY;
  7192. break;
  7193. case ISCSI_FLASHNODE_SNACK_REQ_EN:
  7194. fnode_conn->snack_req_en = fnode_param->value[0];
  7195. break;
  7196. case ISCSI_FLASHNODE_DISCOVERY_LOGOUT_EN:
  7197. fnode_sess->discovery_logout_en = fnode_param->value[0];
  7198. break;
  7199. case ISCSI_FLASHNODE_BIDI_CHAP_EN:
  7200. fnode_sess->bidi_chap_en = fnode_param->value[0];
  7201. break;
  7202. case ISCSI_FLASHNODE_DISCOVERY_AUTH_OPTIONAL:
  7203. fnode_sess->discovery_auth_optional =
  7204. fnode_param->value[0];
  7205. break;
  7206. case ISCSI_FLASHNODE_ERL:
  7207. fnode_sess->erl = fnode_param->value[0];
  7208. break;
  7209. case ISCSI_FLASHNODE_TCP_TIMESTAMP_STAT:
  7210. fnode_conn->tcp_timestamp_stat = fnode_param->value[0];
  7211. break;
  7212. case ISCSI_FLASHNODE_TCP_NAGLE_DISABLE:
  7213. fnode_conn->tcp_nagle_disable = fnode_param->value[0];
  7214. break;
  7215. case ISCSI_FLASHNODE_TCP_WSF_DISABLE:
  7216. fnode_conn->tcp_wsf_disable = fnode_param->value[0];
  7217. break;
  7218. case ISCSI_FLASHNODE_TCP_TIMER_SCALE:
  7219. fnode_conn->tcp_timer_scale = fnode_param->value[0];
  7220. break;
  7221. case ISCSI_FLASHNODE_TCP_TIMESTAMP_EN:
  7222. fnode_conn->tcp_timestamp_en = fnode_param->value[0];
  7223. break;
  7224. case ISCSI_FLASHNODE_IP_FRAG_DISABLE:
  7225. fnode_conn->fragment_disable = fnode_param->value[0];
  7226. break;
  7227. case ISCSI_FLASHNODE_MAX_RECV_DLENGTH:
  7228. fnode_conn->max_recv_dlength =
  7229. *(unsigned *)fnode_param->value;
  7230. break;
  7231. case ISCSI_FLASHNODE_MAX_XMIT_DLENGTH:
  7232. fnode_conn->max_xmit_dlength =
  7233. *(unsigned *)fnode_param->value;
  7234. break;
  7235. case ISCSI_FLASHNODE_FIRST_BURST:
  7236. fnode_sess->first_burst =
  7237. *(unsigned *)fnode_param->value;
  7238. break;
  7239. case ISCSI_FLASHNODE_DEF_TIME2WAIT:
  7240. fnode_sess->time2wait = *(uint16_t *)fnode_param->value;
  7241. break;
  7242. case ISCSI_FLASHNODE_DEF_TIME2RETAIN:
  7243. fnode_sess->time2retain =
  7244. *(uint16_t *)fnode_param->value;
  7245. break;
  7246. case ISCSI_FLASHNODE_MAX_R2T:
  7247. fnode_sess->max_r2t =
  7248. *(uint16_t *)fnode_param->value;
  7249. break;
  7250. case ISCSI_FLASHNODE_KEEPALIVE_TMO:
  7251. fnode_conn->keepalive_timeout =
  7252. *(uint16_t *)fnode_param->value;
  7253. break;
  7254. case ISCSI_FLASHNODE_ISID:
  7255. memcpy(fnode_sess->isid, fnode_param->value,
  7256. sizeof(fnode_sess->isid));
  7257. break;
  7258. case ISCSI_FLASHNODE_TSID:
  7259. fnode_sess->tsid = *(uint16_t *)fnode_param->value;
  7260. break;
  7261. case ISCSI_FLASHNODE_PORT:
  7262. fnode_conn->port = *(uint16_t *)fnode_param->value;
  7263. break;
  7264. case ISCSI_FLASHNODE_MAX_BURST:
  7265. fnode_sess->max_burst = *(unsigned *)fnode_param->value;
  7266. break;
  7267. case ISCSI_FLASHNODE_DEF_TASKMGMT_TMO:
  7268. fnode_sess->default_taskmgmt_timeout =
  7269. *(uint16_t *)fnode_param->value;
  7270. break;
  7271. case ISCSI_FLASHNODE_IPADDR:
  7272. memcpy(fnode_conn->ipaddress, fnode_param->value,
  7273. IPv6_ADDR_LEN);
  7274. break;
  7275. case ISCSI_FLASHNODE_ALIAS:
  7276. rc = iscsi_switch_str_param(&fnode_sess->targetalias,
  7277. (char *)fnode_param->value);
  7278. break;
  7279. case ISCSI_FLASHNODE_REDIRECT_IPADDR:
  7280. memcpy(fnode_conn->redirect_ipaddr, fnode_param->value,
  7281. IPv6_ADDR_LEN);
  7282. break;
  7283. case ISCSI_FLASHNODE_MAX_SEGMENT_SIZE:
  7284. fnode_conn->max_segment_size =
  7285. *(unsigned *)fnode_param->value;
  7286. break;
  7287. case ISCSI_FLASHNODE_LOCAL_PORT:
  7288. fnode_conn->local_port =
  7289. *(uint16_t *)fnode_param->value;
  7290. break;
  7291. case ISCSI_FLASHNODE_IPV4_TOS:
  7292. fnode_conn->ipv4_tos = fnode_param->value[0];
  7293. break;
  7294. case ISCSI_FLASHNODE_IPV6_TC:
  7295. fnode_conn->ipv6_traffic_class = fnode_param->value[0];
  7296. break;
  7297. case ISCSI_FLASHNODE_IPV6_FLOW_LABEL:
  7298. fnode_conn->ipv6_flow_label = fnode_param->value[0];
  7299. break;
  7300. case ISCSI_FLASHNODE_NAME:
  7301. rc = iscsi_switch_str_param(&fnode_sess->targetname,
  7302. (char *)fnode_param->value);
  7303. break;
  7304. case ISCSI_FLASHNODE_TPGT:
  7305. fnode_sess->tpgt = *(uint16_t *)fnode_param->value;
  7306. break;
  7307. case ISCSI_FLASHNODE_LINK_LOCAL_IPV6:
  7308. memcpy(fnode_conn->link_local_ipv6_addr,
  7309. fnode_param->value, IPv6_ADDR_LEN);
  7310. break;
  7311. case ISCSI_FLASHNODE_DISCOVERY_PARENT_IDX:
  7312. fnode_sess->discovery_parent_idx =
  7313. *(uint16_t *)fnode_param->value;
  7314. break;
  7315. case ISCSI_FLASHNODE_TCP_XMIT_WSF:
  7316. fnode_conn->tcp_xmit_wsf =
  7317. *(uint8_t *)fnode_param->value;
  7318. break;
  7319. case ISCSI_FLASHNODE_TCP_RECV_WSF:
  7320. fnode_conn->tcp_recv_wsf =
  7321. *(uint8_t *)fnode_param->value;
  7322. break;
  7323. case ISCSI_FLASHNODE_STATSN:
  7324. fnode_conn->statsn = *(uint32_t *)fnode_param->value;
  7325. break;
  7326. case ISCSI_FLASHNODE_EXP_STATSN:
  7327. fnode_conn->exp_statsn =
  7328. *(uint32_t *)fnode_param->value;
  7329. break;
  7330. case ISCSI_FLASHNODE_CHAP_OUT_IDX:
  7331. chap_out_idx = *(uint16_t *)fnode_param->value;
  7332. if (!qla4xxx_get_uni_chap_at_index(ha,
  7333. chap_tbl.name,
  7334. chap_tbl.secret,
  7335. chap_out_idx)) {
  7336. fnode_sess->chap_out_idx = chap_out_idx;
  7337. /* Enable chap auth if chap index is valid */
  7338. fnode_sess->chap_auth_en = QL4_PARAM_ENABLE;
  7339. }
  7340. break;
  7341. default:
  7342. ql4_printk(KERN_ERR, ha,
  7343. "%s: No such sysfs attribute\n", __func__);
  7344. rc = -ENOSYS;
  7345. goto exit_set_param;
  7346. }
  7347. }
  7348. rc = qla4xxx_sysfs_ddb_apply(fnode_sess, fnode_conn);
  7349. exit_set_param:
  7350. return rc;
  7351. }
  7352. /**
  7353. * qla4xxx_sysfs_ddb_delete - Delete firmware DDB entry
  7354. * @fnode_sess: pointer to session attrs of flash ddb entry
  7355. *
  7356. * This invalidates the flash ddb entry at the given index
  7357. **/
  7358. static int qla4xxx_sysfs_ddb_delete(struct iscsi_bus_flash_session *fnode_sess)
  7359. {
  7360. struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
  7361. struct scsi_qla_host *ha = to_qla_host(shost);
  7362. uint32_t dev_db_start_offset;
  7363. uint32_t dev_db_end_offset;
  7364. struct dev_db_entry *fw_ddb_entry = NULL;
  7365. dma_addr_t fw_ddb_entry_dma;
  7366. uint16_t *ddb_cookie = NULL;
  7367. size_t ddb_size = 0;
  7368. void *pddb = NULL;
  7369. int target_id;
  7370. int rc = 0;
  7371. if (fnode_sess->is_boot_target) {
  7372. rc = -EPERM;
  7373. DEBUG2(ql4_printk(KERN_ERR, ha,
  7374. "%s: Deletion of boot target entry is not permitted.\n",
  7375. __func__));
  7376. goto exit_ddb_del;
  7377. }
  7378. if (fnode_sess->flash_state == DEV_DB_NON_PERSISTENT)
  7379. goto sysfs_ddb_del;
  7380. if (is_qla40XX(ha)) {
  7381. dev_db_start_offset = FLASH_OFFSET_DB_INFO;
  7382. dev_db_end_offset = FLASH_OFFSET_DB_END;
  7383. dev_db_start_offset += (fnode_sess->target_id *
  7384. sizeof(*fw_ddb_entry));
  7385. ddb_size = sizeof(*fw_ddb_entry);
  7386. } else {
  7387. dev_db_start_offset = FLASH_RAW_ACCESS_ADDR +
  7388. (ha->hw.flt_region_ddb << 2);
  7389. /* flt_ddb_size is DDB table size for both ports
  7390. * so divide it by 2 to calculate the offset for second port
  7391. */
  7392. if (ha->port_num == 1)
  7393. dev_db_start_offset += (ha->hw.flt_ddb_size / 2);
  7394. dev_db_end_offset = dev_db_start_offset +
  7395. (ha->hw.flt_ddb_size / 2);
  7396. dev_db_start_offset += (fnode_sess->target_id *
  7397. sizeof(*fw_ddb_entry));
  7398. dev_db_start_offset += offsetof(struct dev_db_entry, cookie);
  7399. ddb_size = sizeof(*ddb_cookie);
  7400. }
  7401. DEBUG2(ql4_printk(KERN_ERR, ha, "%s: start offset=%u, end offset=%u\n",
  7402. __func__, dev_db_start_offset, dev_db_end_offset));
  7403. if (dev_db_start_offset > dev_db_end_offset) {
  7404. rc = -EIO;
  7405. DEBUG2(ql4_printk(KERN_ERR, ha, "%s:Invalid DDB index %u\n",
  7406. __func__, fnode_sess->target_id));
  7407. goto exit_ddb_del;
  7408. }
  7409. pddb = dma_alloc_coherent(&ha->pdev->dev, ddb_size,
  7410. &fw_ddb_entry_dma, GFP_KERNEL);
  7411. if (!pddb) {
  7412. rc = -ENOMEM;
  7413. DEBUG2(ql4_printk(KERN_ERR, ha,
  7414. "%s: Unable to allocate dma buffer\n",
  7415. __func__));
  7416. goto exit_ddb_del;
  7417. }
  7418. if (is_qla40XX(ha)) {
  7419. fw_ddb_entry = pddb;
  7420. memset(fw_ddb_entry, 0, ddb_size);
  7421. ddb_cookie = &fw_ddb_entry->cookie;
  7422. } else {
  7423. ddb_cookie = pddb;
  7424. }
  7425. /* invalidate the cookie */
  7426. *ddb_cookie = 0xFFEE;
  7427. qla4xxx_set_flash(ha, fw_ddb_entry_dma, dev_db_start_offset,
  7428. ddb_size, FLASH_OPT_RMW_COMMIT);
  7429. sysfs_ddb_del:
  7430. target_id = fnode_sess->target_id;
  7431. iscsi_destroy_flashnode_sess(fnode_sess);
  7432. ql4_printk(KERN_INFO, ha,
  7433. "%s: session and conn entries for flashnode %u of host %lu deleted\n",
  7434. __func__, target_id, ha->host_no);
  7435. exit_ddb_del:
  7436. if (pddb)
  7437. dma_free_coherent(&ha->pdev->dev, ddb_size, pddb,
  7438. fw_ddb_entry_dma);
  7439. return rc;
  7440. }
  7441. /**
  7442. * qla4xxx_sysfs_ddb_export - Create sysfs entries for firmware DDBs
  7443. * @ha: pointer to adapter structure
  7444. *
  7445. * Export the firmware DDB for all send targets and normal targets to sysfs.
  7446. **/
  7447. int qla4xxx_sysfs_ddb_export(struct scsi_qla_host *ha)
  7448. {
  7449. struct dev_db_entry *fw_ddb_entry = NULL;
  7450. dma_addr_t fw_ddb_entry_dma;
  7451. uint16_t max_ddbs;
  7452. uint16_t idx = 0;
  7453. int ret = QLA_SUCCESS;
  7454. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev,
  7455. sizeof(*fw_ddb_entry),
  7456. &fw_ddb_entry_dma, GFP_KERNEL);
  7457. if (!fw_ddb_entry) {
  7458. DEBUG2(ql4_printk(KERN_ERR, ha,
  7459. "%s: Unable to allocate dma buffer\n",
  7460. __func__));
  7461. return -ENOMEM;
  7462. }
  7463. max_ddbs = is_qla40XX(ha) ? MAX_PRST_DEV_DB_ENTRIES :
  7464. MAX_DEV_DB_ENTRIES;
  7465. for (idx = 0; idx < max_ddbs; idx++) {
  7466. if (qla4xxx_flashdb_by_index(ha, fw_ddb_entry, fw_ddb_entry_dma,
  7467. idx))
  7468. continue;
  7469. ret = qla4xxx_sysfs_ddb_tgt_create(ha, fw_ddb_entry, &idx, 0);
  7470. if (ret) {
  7471. ret = -EIO;
  7472. break;
  7473. }
  7474. }
  7475. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry), fw_ddb_entry,
  7476. fw_ddb_entry_dma);
  7477. return ret;
  7478. }
  7479. static void qla4xxx_sysfs_ddb_remove(struct scsi_qla_host *ha)
  7480. {
  7481. iscsi_destroy_all_flashnode(ha->host);
  7482. }
  7483. /**
  7484. * qla4xxx_build_ddb_list - Build ddb list and setup sessions
  7485. * @ha: pointer to adapter structure
  7486. * @is_reset: Is this init path or reset path
  7487. *
  7488. * Create a list of sendtargets (st) from firmware DDBs, issue send targets
  7489. * using connection open, then create the list of normal targets (nt)
  7490. * from firmware DDBs. Based on the list of nt setup session and connection
  7491. * objects.
  7492. **/
  7493. void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
  7494. {
  7495. uint16_t tmo = 0;
  7496. struct list_head list_st, list_nt;
  7497. struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
  7498. unsigned long wtime;
  7499. if (!test_bit(AF_LINK_UP, &ha->flags)) {
  7500. set_bit(AF_BUILD_DDB_LIST, &ha->flags);
  7501. ha->is_reset = is_reset;
  7502. return;
  7503. }
  7504. INIT_LIST_HEAD(&list_st);
  7505. INIT_LIST_HEAD(&list_nt);
  7506. qla4xxx_build_st_list(ha, &list_st);
  7507. /* Before issuing conn open mbox, ensure all IPs states are configured
  7508. * Note, conn open fails if IPs are not configured
  7509. */
  7510. qla4xxx_wait_for_ip_configuration(ha);
  7511. /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
  7512. list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
  7513. qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
  7514. }
  7515. /* Wait to ensure all sendtargets are done for min 12 sec wait */
  7516. tmo = ((ha->def_timeout > LOGIN_TOV) &&
  7517. (ha->def_timeout < LOGIN_TOV * 10) ?
  7518. ha->def_timeout : LOGIN_TOV);
  7519. DEBUG2(ql4_printk(KERN_INFO, ha,
  7520. "Default time to wait for build ddb %d\n", tmo));
  7521. wtime = jiffies + (HZ * tmo);
  7522. do {
  7523. if (list_empty(&list_st))
  7524. break;
  7525. qla4xxx_remove_failed_ddb(ha, &list_st);
  7526. schedule_timeout_uninterruptible(HZ / 10);
  7527. } while (time_after(wtime, jiffies));
  7528. qla4xxx_build_nt_list(ha, &list_nt, &list_st, is_reset);
  7529. qla4xxx_free_ddb_list(&list_st);
  7530. qla4xxx_free_ddb_list(&list_nt);
  7531. qla4xxx_free_ddb_index(ha);
  7532. }
  7533. /**
  7534. * qla4xxx_wait_login_resp_boot_tgt - Wait for iSCSI boot target login
  7535. * response.
  7536. * @ha: pointer to adapter structure
  7537. *
  7538. * When the boot entry is normal iSCSI target then DF_BOOT_TGT flag will be
  7539. * set in DDB and we will wait for login response of boot targets during
  7540. * probe.
  7541. **/
  7542. static void qla4xxx_wait_login_resp_boot_tgt(struct scsi_qla_host *ha)
  7543. {
  7544. struct ddb_entry *ddb_entry;
  7545. struct dev_db_entry *fw_ddb_entry = NULL;
  7546. dma_addr_t fw_ddb_entry_dma;
  7547. unsigned long wtime;
  7548. uint32_t ddb_state;
  7549. int max_ddbs, idx, ret;
  7550. max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
  7551. MAX_DEV_DB_ENTRIES;
  7552. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7553. &fw_ddb_entry_dma, GFP_KERNEL);
  7554. if (!fw_ddb_entry) {
  7555. ql4_printk(KERN_ERR, ha,
  7556. "%s: Unable to allocate dma buffer\n", __func__);
  7557. goto exit_login_resp;
  7558. }
  7559. wtime = jiffies + (HZ * BOOT_LOGIN_RESP_TOV);
  7560. for (idx = 0; idx < max_ddbs; idx++) {
  7561. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  7562. if (ddb_entry == NULL)
  7563. continue;
  7564. if (test_bit(DF_BOOT_TGT, &ddb_entry->flags)) {
  7565. DEBUG2(ql4_printk(KERN_INFO, ha,
  7566. "%s: DDB index [%d]\n", __func__,
  7567. ddb_entry->fw_ddb_index));
  7568. do {
  7569. ret = qla4xxx_get_fwddb_entry(ha,
  7570. ddb_entry->fw_ddb_index,
  7571. fw_ddb_entry, fw_ddb_entry_dma,
  7572. NULL, NULL, &ddb_state, NULL,
  7573. NULL, NULL);
  7574. if (ret == QLA_ERROR)
  7575. goto exit_login_resp;
  7576. if ((ddb_state == DDB_DS_SESSION_ACTIVE) ||
  7577. (ddb_state == DDB_DS_SESSION_FAILED))
  7578. break;
  7579. schedule_timeout_uninterruptible(HZ);
  7580. } while ((time_after(wtime, jiffies)));
  7581. if (!time_after(wtime, jiffies)) {
  7582. DEBUG2(ql4_printk(KERN_INFO, ha,
  7583. "%s: Login response wait timer expired\n",
  7584. __func__));
  7585. goto exit_login_resp;
  7586. }
  7587. }
  7588. }
  7589. exit_login_resp:
  7590. if (fw_ddb_entry)
  7591. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7592. fw_ddb_entry, fw_ddb_entry_dma);
  7593. }
  7594. /**
  7595. * qla4xxx_probe_adapter - callback function to probe HBA
  7596. * @pdev: pointer to pci_dev structure
  7597. * @pci_device_id: pointer to pci_device entry
  7598. *
  7599. * This routine will probe for Qlogic 4xxx iSCSI host adapters.
  7600. * It returns zero if successful. It also initializes all data necessary for
  7601. * the driver.
  7602. **/
  7603. static int qla4xxx_probe_adapter(struct pci_dev *pdev,
  7604. const struct pci_device_id *ent)
  7605. {
  7606. int ret = -ENODEV, status;
  7607. struct Scsi_Host *host;
  7608. struct scsi_qla_host *ha;
  7609. uint8_t init_retry_count = 0;
  7610. char buf[34];
  7611. struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
  7612. uint32_t dev_state;
  7613. if (pci_enable_device(pdev))
  7614. return -1;
  7615. host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
  7616. if (host == NULL) {
  7617. printk(KERN_WARNING
  7618. "qla4xxx: Couldn't allocate host from scsi layer!\n");
  7619. goto probe_disable_device;
  7620. }
  7621. /* Clear our data area */
  7622. ha = to_qla_host(host);
  7623. memset(ha, 0, sizeof(*ha));
  7624. /* Save the information from PCI BIOS. */
  7625. ha->pdev = pdev;
  7626. ha->host = host;
  7627. ha->host_no = host->host_no;
  7628. ha->func_num = PCI_FUNC(ha->pdev->devfn);
  7629. pci_enable_pcie_error_reporting(pdev);
  7630. /* Setup Runtime configurable options */
  7631. if (is_qla8022(ha)) {
  7632. ha->isp_ops = &qla4_82xx_isp_ops;
  7633. ha->reg_tbl = (uint32_t *) qla4_82xx_reg_tbl;
  7634. ha->qdr_sn_window = -1;
  7635. ha->ddr_mn_window = -1;
  7636. ha->curr_window = 255;
  7637. nx_legacy_intr = &legacy_intr[ha->func_num];
  7638. ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
  7639. ha->nx_legacy_intr.tgt_status_reg =
  7640. nx_legacy_intr->tgt_status_reg;
  7641. ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
  7642. ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
  7643. } else if (is_qla8032(ha) || is_qla8042(ha)) {
  7644. ha->isp_ops = &qla4_83xx_isp_ops;
  7645. ha->reg_tbl = (uint32_t *)qla4_83xx_reg_tbl;
  7646. } else {
  7647. ha->isp_ops = &qla4xxx_isp_ops;
  7648. }
  7649. if (is_qla80XX(ha)) {
  7650. rwlock_init(&ha->hw_lock);
  7651. ha->pf_bit = ha->func_num << 16;
  7652. /* Set EEH reset type to fundamental if required by hba */
  7653. pdev->needs_freset = 1;
  7654. }
  7655. /* Configure PCI I/O space. */
  7656. ret = ha->isp_ops->iospace_config(ha);
  7657. if (ret)
  7658. goto probe_failed_ioconfig;
  7659. ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
  7660. pdev->device, pdev->irq, ha->reg);
  7661. qla4xxx_config_dma_addressing(ha);
  7662. /* Initialize lists and spinlocks. */
  7663. INIT_LIST_HEAD(&ha->free_srb_q);
  7664. mutex_init(&ha->mbox_sem);
  7665. mutex_init(&ha->chap_sem);
  7666. init_completion(&ha->mbx_intr_comp);
  7667. init_completion(&ha->disable_acb_comp);
  7668. init_completion(&ha->idc_comp);
  7669. init_completion(&ha->link_up_comp);
  7670. init_completion(&ha->disable_acb_comp);
  7671. spin_lock_init(&ha->hardware_lock);
  7672. spin_lock_init(&ha->work_lock);
  7673. /* Initialize work list */
  7674. INIT_LIST_HEAD(&ha->work_list);
  7675. /* Allocate dma buffers */
  7676. if (qla4xxx_mem_alloc(ha)) {
  7677. ql4_printk(KERN_WARNING, ha,
  7678. "[ERROR] Failed to allocate memory for adapter\n");
  7679. ret = -ENOMEM;
  7680. goto probe_failed;
  7681. }
  7682. host->cmd_per_lun = 3;
  7683. host->max_channel = 0;
  7684. host->max_lun = MAX_LUNS - 1;
  7685. host->max_id = MAX_TARGETS;
  7686. host->max_cmd_len = IOCB_MAX_CDB_LEN;
  7687. host->can_queue = MAX_SRBS ;
  7688. host->transportt = qla4xxx_scsi_transport;
  7689. pci_set_drvdata(pdev, ha);
  7690. ret = scsi_add_host(host, &pdev->dev);
  7691. if (ret)
  7692. goto probe_failed;
  7693. if (is_qla80XX(ha))
  7694. qla4_8xxx_get_flash_info(ha);
  7695. if (is_qla8032(ha) || is_qla8042(ha)) {
  7696. qla4_83xx_read_reset_template(ha);
  7697. /*
  7698. * NOTE: If ql4dontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  7699. * If DONRESET_BIT0 is set, drivers should not set dev_state
  7700. * to NEED_RESET. But if NEED_RESET is set, drivers should
  7701. * should honor the reset.
  7702. */
  7703. if (ql4xdontresethba == 1)
  7704. qla4_83xx_set_idc_dontreset(ha);
  7705. }
  7706. /*
  7707. * Initialize the Host adapter request/response queues and
  7708. * firmware
  7709. * NOTE: interrupts enabled upon successful completion
  7710. */
  7711. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  7712. /* Dont retry adapter initialization if IRQ allocation failed */
  7713. if (is_qla80XX(ha) && (status == QLA_ERROR))
  7714. goto skip_retry_init;
  7715. while ((!test_bit(AF_ONLINE, &ha->flags)) &&
  7716. init_retry_count++ < MAX_INIT_RETRIES) {
  7717. if (is_qla80XX(ha)) {
  7718. ha->isp_ops->idc_lock(ha);
  7719. dev_state = qla4_8xxx_rd_direct(ha,
  7720. QLA8XXX_CRB_DEV_STATE);
  7721. ha->isp_ops->idc_unlock(ha);
  7722. if (dev_state == QLA8XXX_DEV_FAILED) {
  7723. ql4_printk(KERN_WARNING, ha, "%s: don't retry "
  7724. "initialize adapter. H/W is in failed state\n",
  7725. __func__);
  7726. break;
  7727. }
  7728. }
  7729. DEBUG2(printk("scsi: %s: retrying adapter initialization "
  7730. "(%d)\n", __func__, init_retry_count));
  7731. if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
  7732. continue;
  7733. status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
  7734. if (is_qla80XX(ha) && (status == QLA_ERROR)) {
  7735. if (qla4_8xxx_check_init_adapter_retry(ha) == QLA_ERROR)
  7736. goto skip_retry_init;
  7737. }
  7738. }
  7739. skip_retry_init:
  7740. if (!test_bit(AF_ONLINE, &ha->flags)) {
  7741. ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
  7742. if ((is_qla8022(ha) && ql4xdontresethba) ||
  7743. ((is_qla8032(ha) || is_qla8042(ha)) &&
  7744. qla4_83xx_idc_dontreset(ha))) {
  7745. /* Put the device in failed state. */
  7746. DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
  7747. ha->isp_ops->idc_lock(ha);
  7748. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  7749. QLA8XXX_DEV_FAILED);
  7750. ha->isp_ops->idc_unlock(ha);
  7751. }
  7752. ret = -ENODEV;
  7753. goto remove_host;
  7754. }
  7755. /* Startup the kernel thread for this host adapter. */
  7756. DEBUG2(printk("scsi: %s: Starting kernel thread for "
  7757. "qla4xxx_dpc\n", __func__));
  7758. sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
  7759. ha->dpc_thread = create_singlethread_workqueue(buf);
  7760. if (!ha->dpc_thread) {
  7761. ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
  7762. ret = -ENODEV;
  7763. goto remove_host;
  7764. }
  7765. INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
  7766. ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
  7767. ha->host_no);
  7768. if (!ha->task_wq) {
  7769. ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
  7770. ret = -ENODEV;
  7771. goto remove_host;
  7772. }
  7773. /*
  7774. * For ISP-8XXX, request_irqs is called in qla4_8xxx_load_risc
  7775. * (which is called indirectly by qla4xxx_initialize_adapter),
  7776. * so that irqs will be registered after crbinit but before
  7777. * mbx_intr_enable.
  7778. */
  7779. if (is_qla40XX(ha)) {
  7780. ret = qla4xxx_request_irqs(ha);
  7781. if (ret) {
  7782. ql4_printk(KERN_WARNING, ha, "Failed to reserve "
  7783. "interrupt %d already in use.\n", pdev->irq);
  7784. goto remove_host;
  7785. }
  7786. }
  7787. pci_save_state(ha->pdev);
  7788. ha->isp_ops->enable_intrs(ha);
  7789. /* Start timer thread. */
  7790. qla4xxx_start_timer(ha, qla4xxx_timer, 1);
  7791. set_bit(AF_INIT_DONE, &ha->flags);
  7792. qla4_8xxx_alloc_sysfs_attr(ha);
  7793. printk(KERN_INFO
  7794. " QLogic iSCSI HBA Driver version: %s\n"
  7795. " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
  7796. qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
  7797. ha->host_no, ha->fw_info.fw_major, ha->fw_info.fw_minor,
  7798. ha->fw_info.fw_patch, ha->fw_info.fw_build);
  7799. /* Set the driver version */
  7800. if (is_qla80XX(ha))
  7801. qla4_8xxx_set_param(ha, SET_DRVR_VERSION);
  7802. if (qla4xxx_setup_boot_info(ha))
  7803. ql4_printk(KERN_ERR, ha,
  7804. "%s: No iSCSI boot target configured\n", __func__);
  7805. set_bit(DPC_SYSFS_DDB_EXPORT, &ha->dpc_flags);
  7806. /* Perform the build ddb list and login to each */
  7807. qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
  7808. iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
  7809. qla4xxx_wait_login_resp_boot_tgt(ha);
  7810. qla4xxx_create_chap_list(ha);
  7811. qla4xxx_create_ifaces(ha);
  7812. return 0;
  7813. remove_host:
  7814. scsi_remove_host(ha->host);
  7815. probe_failed:
  7816. qla4xxx_free_adapter(ha);
  7817. probe_failed_ioconfig:
  7818. pci_disable_pcie_error_reporting(pdev);
  7819. scsi_host_put(ha->host);
  7820. probe_disable_device:
  7821. pci_disable_device(pdev);
  7822. return ret;
  7823. }
  7824. /**
  7825. * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
  7826. * @ha: pointer to adapter structure
  7827. *
  7828. * Mark the other ISP-4xxx port to indicate that the driver is being removed,
  7829. * so that the other port will not re-initialize while in the process of
  7830. * removing the ha due to driver unload or hba hotplug.
  7831. **/
  7832. static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
  7833. {
  7834. struct scsi_qla_host *other_ha = NULL;
  7835. struct pci_dev *other_pdev = NULL;
  7836. int fn = ISP4XXX_PCI_FN_2;
  7837. /*iscsi function numbers for ISP4xxx is 1 and 3*/
  7838. if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
  7839. fn = ISP4XXX_PCI_FN_1;
  7840. other_pdev =
  7841. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  7842. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  7843. fn));
  7844. /* Get other_ha if other_pdev is valid and state is enable*/
  7845. if (other_pdev) {
  7846. if (atomic_read(&other_pdev->enable_cnt)) {
  7847. other_ha = pci_get_drvdata(other_pdev);
  7848. if (other_ha) {
  7849. set_bit(AF_HA_REMOVAL, &other_ha->flags);
  7850. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
  7851. "Prevent %s reinit\n", __func__,
  7852. dev_name(&other_ha->pdev->dev)));
  7853. }
  7854. }
  7855. pci_dev_put(other_pdev);
  7856. }
  7857. }
  7858. static void qla4xxx_destroy_ddb(struct scsi_qla_host *ha,
  7859. struct ddb_entry *ddb_entry)
  7860. {
  7861. struct dev_db_entry *fw_ddb_entry = NULL;
  7862. dma_addr_t fw_ddb_entry_dma;
  7863. unsigned long wtime;
  7864. uint32_t ddb_state;
  7865. int options;
  7866. int status;
  7867. options = LOGOUT_OPTION_CLOSE_SESSION;
  7868. if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR) {
  7869. ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
  7870. goto clear_ddb;
  7871. }
  7872. fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7873. &fw_ddb_entry_dma, GFP_KERNEL);
  7874. if (!fw_ddb_entry) {
  7875. ql4_printk(KERN_ERR, ha,
  7876. "%s: Unable to allocate dma buffer\n", __func__);
  7877. goto clear_ddb;
  7878. }
  7879. wtime = jiffies + (HZ * LOGOUT_TOV);
  7880. do {
  7881. status = qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index,
  7882. fw_ddb_entry, fw_ddb_entry_dma,
  7883. NULL, NULL, &ddb_state, NULL,
  7884. NULL, NULL);
  7885. if (status == QLA_ERROR)
  7886. goto free_ddb;
  7887. if ((ddb_state == DDB_DS_NO_CONNECTION_ACTIVE) ||
  7888. (ddb_state == DDB_DS_SESSION_FAILED))
  7889. goto free_ddb;
  7890. schedule_timeout_uninterruptible(HZ);
  7891. } while ((time_after(wtime, jiffies)));
  7892. free_ddb:
  7893. dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
  7894. fw_ddb_entry, fw_ddb_entry_dma);
  7895. clear_ddb:
  7896. qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
  7897. }
  7898. static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
  7899. {
  7900. struct ddb_entry *ddb_entry;
  7901. int idx;
  7902. for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
  7903. ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
  7904. if ((ddb_entry != NULL) &&
  7905. (ddb_entry->ddb_type == FLASH_DDB)) {
  7906. qla4xxx_destroy_ddb(ha, ddb_entry);
  7907. /*
  7908. * we have decremented the reference count of the driver
  7909. * when we setup the session to have the driver unload
  7910. * to be seamless without actually destroying the
  7911. * session
  7912. **/
  7913. try_module_get(qla4xxx_iscsi_transport.owner);
  7914. iscsi_destroy_endpoint(ddb_entry->conn->ep);
  7915. qla4xxx_free_ddb(ha, ddb_entry);
  7916. iscsi_session_teardown(ddb_entry->sess);
  7917. }
  7918. }
  7919. }
  7920. /**
  7921. * qla4xxx_remove_adapter - callback function to remove adapter.
  7922. * @pci_dev: PCI device pointer
  7923. **/
  7924. static void qla4xxx_remove_adapter(struct pci_dev *pdev)
  7925. {
  7926. struct scsi_qla_host *ha;
  7927. /*
  7928. * If the PCI device is disabled then it means probe_adapter had
  7929. * failed and resources already cleaned up on probe_adapter exit.
  7930. */
  7931. if (!pci_is_enabled(pdev))
  7932. return;
  7933. ha = pci_get_drvdata(pdev);
  7934. if (is_qla40XX(ha))
  7935. qla4xxx_prevent_other_port_reinit(ha);
  7936. /* destroy iface from sysfs */
  7937. qla4xxx_destroy_ifaces(ha);
  7938. if ((!ql4xdisablesysfsboot) && ha->boot_kset)
  7939. iscsi_boot_destroy_kset(ha->boot_kset);
  7940. qla4xxx_destroy_fw_ddb_session(ha);
  7941. qla4_8xxx_free_sysfs_attr(ha);
  7942. qla4xxx_sysfs_ddb_remove(ha);
  7943. scsi_remove_host(ha->host);
  7944. qla4xxx_free_adapter(ha);
  7945. scsi_host_put(ha->host);
  7946. pci_disable_pcie_error_reporting(pdev);
  7947. pci_disable_device(pdev);
  7948. }
  7949. /**
  7950. * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
  7951. * @ha: HA context
  7952. *
  7953. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  7954. * supported addressing method.
  7955. */
  7956. static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
  7957. {
  7958. int retval;
  7959. /* Update our PCI device dma_mask for full 64 bit mask */
  7960. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
  7961. if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  7962. dev_dbg(&ha->pdev->dev,
  7963. "Failed to set 64 bit PCI consistent mask; "
  7964. "using 32 bit.\n");
  7965. retval = pci_set_consistent_dma_mask(ha->pdev,
  7966. DMA_BIT_MASK(32));
  7967. }
  7968. } else
  7969. retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  7970. }
  7971. static int qla4xxx_slave_alloc(struct scsi_device *sdev)
  7972. {
  7973. struct iscsi_cls_session *cls_sess;
  7974. struct iscsi_session *sess;
  7975. struct ddb_entry *ddb;
  7976. int queue_depth = QL4_DEF_QDEPTH;
  7977. cls_sess = starget_to_session(sdev->sdev_target);
  7978. sess = cls_sess->dd_data;
  7979. ddb = sess->dd_data;
  7980. sdev->hostdata = ddb;
  7981. if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
  7982. queue_depth = ql4xmaxqdepth;
  7983. scsi_change_queue_depth(sdev, queue_depth);
  7984. return 0;
  7985. }
  7986. /**
  7987. * qla4xxx_del_from_active_array - returns an active srb
  7988. * @ha: Pointer to host adapter structure.
  7989. * @index: index into the active_array
  7990. *
  7991. * This routine removes and returns the srb at the specified index
  7992. **/
  7993. struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
  7994. uint32_t index)
  7995. {
  7996. struct srb *srb = NULL;
  7997. struct scsi_cmnd *cmd = NULL;
  7998. cmd = scsi_host_find_tag(ha->host, index);
  7999. if (!cmd)
  8000. return srb;
  8001. srb = (struct srb *)CMD_SP(cmd);
  8002. if (!srb)
  8003. return srb;
  8004. /* update counters */
  8005. if (srb->flags & SRB_DMA_VALID) {
  8006. ha->iocb_cnt -= srb->iocb_cnt;
  8007. if (srb->cmd)
  8008. srb->cmd->host_scribble =
  8009. (unsigned char *)(unsigned long) MAX_SRBS;
  8010. }
  8011. return srb;
  8012. }
  8013. /**
  8014. * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
  8015. * @ha: Pointer to host adapter structure.
  8016. * @cmd: Scsi Command to wait on.
  8017. *
  8018. * This routine waits for the command to be returned by the Firmware
  8019. * for some max time.
  8020. **/
  8021. static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
  8022. struct scsi_cmnd *cmd)
  8023. {
  8024. int done = 0;
  8025. struct srb *rp;
  8026. uint32_t max_wait_time = EH_WAIT_CMD_TOV;
  8027. int ret = SUCCESS;
  8028. /* Dont wait on command if PCI error is being handled
  8029. * by PCI AER driver
  8030. */
  8031. if (unlikely(pci_channel_offline(ha->pdev)) ||
  8032. (test_bit(AF_EEH_BUSY, &ha->flags))) {
  8033. ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
  8034. ha->host_no, __func__);
  8035. return ret;
  8036. }
  8037. do {
  8038. /* Checking to see if its returned to OS */
  8039. rp = (struct srb *) CMD_SP(cmd);
  8040. if (rp == NULL) {
  8041. done++;
  8042. break;
  8043. }
  8044. msleep(2000);
  8045. } while (max_wait_time--);
  8046. return done;
  8047. }
  8048. /**
  8049. * qla4xxx_wait_for_hba_online - waits for HBA to come online
  8050. * @ha: Pointer to host adapter structure
  8051. **/
  8052. static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
  8053. {
  8054. unsigned long wait_online;
  8055. wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
  8056. while (time_before(jiffies, wait_online)) {
  8057. if (adapter_up(ha))
  8058. return QLA_SUCCESS;
  8059. msleep(2000);
  8060. }
  8061. return QLA_ERROR;
  8062. }
  8063. /**
  8064. * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
  8065. * @ha: pointer to HBA
  8066. * @t: target id
  8067. * @l: lun id
  8068. *
  8069. * This function waits for all outstanding commands to a lun to complete. It
  8070. * returns 0 if all pending commands are returned and 1 otherwise.
  8071. **/
  8072. static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
  8073. struct scsi_target *stgt,
  8074. struct scsi_device *sdev)
  8075. {
  8076. int cnt;
  8077. int status = 0;
  8078. struct scsi_cmnd *cmd;
  8079. /*
  8080. * Waiting for all commands for the designated target or dev
  8081. * in the active array
  8082. */
  8083. for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
  8084. cmd = scsi_host_find_tag(ha->host, cnt);
  8085. if (cmd && stgt == scsi_target(cmd->device) &&
  8086. (!sdev || sdev == cmd->device)) {
  8087. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  8088. status++;
  8089. break;
  8090. }
  8091. }
  8092. }
  8093. return status;
  8094. }
  8095. /**
  8096. * qla4xxx_eh_abort - callback for abort task.
  8097. * @cmd: Pointer to Linux's SCSI command structure
  8098. *
  8099. * This routine is called by the Linux OS to abort the specified
  8100. * command.
  8101. **/
  8102. static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
  8103. {
  8104. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8105. unsigned int id = cmd->device->id;
  8106. uint64_t lun = cmd->device->lun;
  8107. unsigned long flags;
  8108. struct srb *srb = NULL;
  8109. int ret = SUCCESS;
  8110. int wait = 0;
  8111. int rval;
  8112. ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Abort command issued cmd=%p, cdb=0x%x\n",
  8113. ha->host_no, id, lun, cmd, cmd->cmnd[0]);
  8114. rval = qla4xxx_isp_check_reg(ha);
  8115. if (rval != QLA_SUCCESS) {
  8116. ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
  8117. return FAILED;
  8118. }
  8119. spin_lock_irqsave(&ha->hardware_lock, flags);
  8120. srb = (struct srb *) CMD_SP(cmd);
  8121. if (!srb) {
  8122. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  8123. ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
  8124. ha->host_no, id, lun);
  8125. return SUCCESS;
  8126. }
  8127. kref_get(&srb->srb_ref);
  8128. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  8129. if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
  8130. DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx failed.\n",
  8131. ha->host_no, id, lun));
  8132. ret = FAILED;
  8133. } else {
  8134. DEBUG3(printk("scsi%ld:%d:%llu: Abort_task mbx success.\n",
  8135. ha->host_no, id, lun));
  8136. wait = 1;
  8137. }
  8138. kref_put(&srb->srb_ref, qla4xxx_srb_compl);
  8139. /* Wait for command to complete */
  8140. if (wait) {
  8141. if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
  8142. DEBUG2(printk("scsi%ld:%d:%llu: Abort handler timed out\n",
  8143. ha->host_no, id, lun));
  8144. ret = FAILED;
  8145. }
  8146. }
  8147. ql4_printk(KERN_INFO, ha,
  8148. "scsi%ld:%d:%llu: Abort command - %s\n",
  8149. ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
  8150. return ret;
  8151. }
  8152. /**
  8153. * qla4xxx_eh_device_reset - callback for target reset.
  8154. * @cmd: Pointer to Linux's SCSI command structure
  8155. *
  8156. * This routine is called by the Linux OS to reset all luns on the
  8157. * specified target.
  8158. **/
  8159. static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
  8160. {
  8161. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8162. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  8163. int ret = FAILED, stat;
  8164. int rval;
  8165. if (!ddb_entry)
  8166. return ret;
  8167. ret = iscsi_block_scsi_eh(cmd);
  8168. if (ret)
  8169. return ret;
  8170. ret = FAILED;
  8171. ql4_printk(KERN_INFO, ha,
  8172. "scsi%ld:%d:%d:%llu: DEVICE RESET ISSUED.\n", ha->host_no,
  8173. cmd->device->channel, cmd->device->id, cmd->device->lun);
  8174. DEBUG2(printk(KERN_INFO
  8175. "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
  8176. "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
  8177. cmd, jiffies, cmd->request->timeout / HZ,
  8178. ha->dpc_flags, cmd->result, cmd->allowed));
  8179. rval = qla4xxx_isp_check_reg(ha);
  8180. if (rval != QLA_SUCCESS) {
  8181. ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
  8182. return FAILED;
  8183. }
  8184. /* FIXME: wait for hba to go online */
  8185. stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
  8186. if (stat != QLA_SUCCESS) {
  8187. ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
  8188. goto eh_dev_reset_done;
  8189. }
  8190. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  8191. cmd->device)) {
  8192. ql4_printk(KERN_INFO, ha,
  8193. "DEVICE RESET FAILED - waiting for "
  8194. "commands.\n");
  8195. goto eh_dev_reset_done;
  8196. }
  8197. /* Send marker. */
  8198. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  8199. MM_LUN_RESET) != QLA_SUCCESS)
  8200. goto eh_dev_reset_done;
  8201. ql4_printk(KERN_INFO, ha,
  8202. "scsi(%ld:%d:%d:%llu): DEVICE RESET SUCCEEDED.\n",
  8203. ha->host_no, cmd->device->channel, cmd->device->id,
  8204. cmd->device->lun);
  8205. ret = SUCCESS;
  8206. eh_dev_reset_done:
  8207. return ret;
  8208. }
  8209. /**
  8210. * qla4xxx_eh_target_reset - callback for target reset.
  8211. * @cmd: Pointer to Linux's SCSI command structure
  8212. *
  8213. * This routine is called by the Linux OS to reset the target.
  8214. **/
  8215. static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
  8216. {
  8217. struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
  8218. struct ddb_entry *ddb_entry = cmd->device->hostdata;
  8219. int stat, ret;
  8220. int rval;
  8221. if (!ddb_entry)
  8222. return FAILED;
  8223. ret = iscsi_block_scsi_eh(cmd);
  8224. if (ret)
  8225. return ret;
  8226. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8227. "WARM TARGET RESET ISSUED.\n");
  8228. DEBUG2(printk(KERN_INFO
  8229. "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
  8230. "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
  8231. ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
  8232. ha->dpc_flags, cmd->result, cmd->allowed));
  8233. rval = qla4xxx_isp_check_reg(ha);
  8234. if (rval != QLA_SUCCESS) {
  8235. ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
  8236. return FAILED;
  8237. }
  8238. stat = qla4xxx_reset_target(ha, ddb_entry);
  8239. if (stat != QLA_SUCCESS) {
  8240. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8241. "WARM TARGET RESET FAILED.\n");
  8242. return FAILED;
  8243. }
  8244. if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
  8245. NULL)) {
  8246. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8247. "WARM TARGET DEVICE RESET FAILED - "
  8248. "waiting for commands.\n");
  8249. return FAILED;
  8250. }
  8251. /* Send marker. */
  8252. if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
  8253. MM_TGT_WARM_RESET) != QLA_SUCCESS) {
  8254. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8255. "WARM TARGET DEVICE RESET FAILED - "
  8256. "marker iocb failed.\n");
  8257. return FAILED;
  8258. }
  8259. starget_printk(KERN_INFO, scsi_target(cmd->device),
  8260. "WARM TARGET RESET SUCCEEDED.\n");
  8261. return SUCCESS;
  8262. }
  8263. /**
  8264. * qla4xxx_is_eh_active - check if error handler is running
  8265. * @shost: Pointer to SCSI Host struct
  8266. *
  8267. * This routine finds that if reset host is called in EH
  8268. * scenario or from some application like sg_reset
  8269. **/
  8270. static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
  8271. {
  8272. if (shost->shost_state == SHOST_RECOVERY)
  8273. return 1;
  8274. return 0;
  8275. }
  8276. /**
  8277. * qla4xxx_eh_host_reset - kernel callback
  8278. * @cmd: Pointer to Linux's SCSI command structure
  8279. *
  8280. * This routine is invoked by the Linux kernel to perform fatal error
  8281. * recovery on the specified adapter.
  8282. **/
  8283. static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
  8284. {
  8285. int return_status = FAILED;
  8286. struct scsi_qla_host *ha;
  8287. int rval;
  8288. ha = to_qla_host(cmd->device->host);
  8289. rval = qla4xxx_isp_check_reg(ha);
  8290. if (rval != QLA_SUCCESS) {
  8291. ql4_printk(KERN_INFO, ha, "PCI/Register disconnect, exiting.\n");
  8292. return FAILED;
  8293. }
  8294. if ((is_qla8032(ha) || is_qla8042(ha)) && ql4xdontresethba)
  8295. qla4_83xx_set_idc_dontreset(ha);
  8296. /*
  8297. * For ISP8324 and ISP8042, if IDC_CTRL DONTRESET_BIT0 is set by other
  8298. * protocol drivers, we should not set device_state to NEED_RESET
  8299. */
  8300. if (ql4xdontresethba ||
  8301. ((is_qla8032(ha) || is_qla8042(ha)) &&
  8302. qla4_83xx_idc_dontreset(ha))) {
  8303. DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
  8304. ha->host_no, __func__));
  8305. /* Clear outstanding srb in queues */
  8306. if (qla4xxx_is_eh_active(cmd->device->host))
  8307. qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
  8308. return FAILED;
  8309. }
  8310. ql4_printk(KERN_INFO, ha,
  8311. "scsi(%ld:%d:%d:%llu): HOST RESET ISSUED.\n", ha->host_no,
  8312. cmd->device->channel, cmd->device->id, cmd->device->lun);
  8313. if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
  8314. DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
  8315. "DEAD.\n", ha->host_no, cmd->device->channel,
  8316. __func__));
  8317. return FAILED;
  8318. }
  8319. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8320. if (is_qla80XX(ha))
  8321. set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
  8322. else
  8323. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  8324. }
  8325. if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
  8326. return_status = SUCCESS;
  8327. ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
  8328. return_status == FAILED ? "FAILED" : "SUCCEEDED");
  8329. return return_status;
  8330. }
  8331. static int qla4xxx_context_reset(struct scsi_qla_host *ha)
  8332. {
  8333. uint32_t mbox_cmd[MBOX_REG_COUNT];
  8334. uint32_t mbox_sts[MBOX_REG_COUNT];
  8335. struct addr_ctrl_blk_def *acb = NULL;
  8336. uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
  8337. int rval = QLA_SUCCESS;
  8338. dma_addr_t acb_dma;
  8339. acb = dma_alloc_coherent(&ha->pdev->dev,
  8340. sizeof(struct addr_ctrl_blk_def),
  8341. &acb_dma, GFP_KERNEL);
  8342. if (!acb) {
  8343. ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
  8344. __func__);
  8345. rval = -ENOMEM;
  8346. goto exit_port_reset;
  8347. }
  8348. memset(acb, 0, acb_len);
  8349. rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
  8350. if (rval != QLA_SUCCESS) {
  8351. rval = -EIO;
  8352. goto exit_free_acb;
  8353. }
  8354. rval = qla4xxx_disable_acb(ha);
  8355. if (rval != QLA_SUCCESS) {
  8356. rval = -EIO;
  8357. goto exit_free_acb;
  8358. }
  8359. wait_for_completion_timeout(&ha->disable_acb_comp,
  8360. DISABLE_ACB_TOV * HZ);
  8361. rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
  8362. if (rval != QLA_SUCCESS) {
  8363. rval = -EIO;
  8364. goto exit_free_acb;
  8365. }
  8366. exit_free_acb:
  8367. dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
  8368. acb, acb_dma);
  8369. exit_port_reset:
  8370. DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
  8371. rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
  8372. return rval;
  8373. }
  8374. static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
  8375. {
  8376. struct scsi_qla_host *ha = to_qla_host(shost);
  8377. int rval = QLA_SUCCESS;
  8378. uint32_t idc_ctrl;
  8379. if (ql4xdontresethba) {
  8380. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
  8381. __func__));
  8382. rval = -EPERM;
  8383. goto exit_host_reset;
  8384. }
  8385. if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
  8386. goto recover_adapter;
  8387. switch (reset_type) {
  8388. case SCSI_ADAPTER_RESET:
  8389. set_bit(DPC_RESET_HA, &ha->dpc_flags);
  8390. break;
  8391. case SCSI_FIRMWARE_RESET:
  8392. if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8393. if (is_qla80XX(ha))
  8394. /* set firmware context reset */
  8395. set_bit(DPC_RESET_HA_FW_CONTEXT,
  8396. &ha->dpc_flags);
  8397. else {
  8398. rval = qla4xxx_context_reset(ha);
  8399. goto exit_host_reset;
  8400. }
  8401. }
  8402. break;
  8403. }
  8404. recover_adapter:
  8405. /* For ISP8324 and ISP8042 set graceful reset bit in IDC_DRV_CTRL if
  8406. * reset is issued by application */
  8407. if ((is_qla8032(ha) || is_qla8042(ha)) &&
  8408. test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
  8409. idc_ctrl = qla4_83xx_rd_reg(ha, QLA83XX_IDC_DRV_CTRL);
  8410. qla4_83xx_wr_reg(ha, QLA83XX_IDC_DRV_CTRL,
  8411. (idc_ctrl | GRACEFUL_RESET_BIT1));
  8412. }
  8413. rval = qla4xxx_recover_adapter(ha);
  8414. if (rval != QLA_SUCCESS) {
  8415. DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
  8416. __func__));
  8417. rval = -EIO;
  8418. }
  8419. exit_host_reset:
  8420. return rval;
  8421. }
  8422. /* PCI AER driver recovers from all correctable errors w/o
  8423. * driver intervention. For uncorrectable errors PCI AER
  8424. * driver calls the following device driver's callbacks
  8425. *
  8426. * - Fatal Errors - link_reset
  8427. * - Non-Fatal Errors - driver's pci_error_detected() which
  8428. * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
  8429. *
  8430. * PCI AER driver calls
  8431. * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
  8432. * returns RECOVERED or NEED_RESET if fw_hung
  8433. * NEED_RESET - driver's slot_reset()
  8434. * DISCONNECT - device is dead & cannot recover
  8435. * RECOVERED - driver's pci_resume()
  8436. */
  8437. static pci_ers_result_t
  8438. qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  8439. {
  8440. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8441. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
  8442. ha->host_no, __func__, state);
  8443. if (!is_aer_supported(ha))
  8444. return PCI_ERS_RESULT_NONE;
  8445. switch (state) {
  8446. case pci_channel_io_normal:
  8447. clear_bit(AF_EEH_BUSY, &ha->flags);
  8448. return PCI_ERS_RESULT_CAN_RECOVER;
  8449. case pci_channel_io_frozen:
  8450. set_bit(AF_EEH_BUSY, &ha->flags);
  8451. qla4xxx_mailbox_premature_completion(ha);
  8452. qla4xxx_free_irqs(ha);
  8453. pci_disable_device(pdev);
  8454. /* Return back all IOs */
  8455. qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
  8456. return PCI_ERS_RESULT_NEED_RESET;
  8457. case pci_channel_io_perm_failure:
  8458. set_bit(AF_EEH_BUSY, &ha->flags);
  8459. set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
  8460. qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
  8461. return PCI_ERS_RESULT_DISCONNECT;
  8462. }
  8463. return PCI_ERS_RESULT_NEED_RESET;
  8464. }
  8465. /**
  8466. * qla4xxx_pci_mmio_enabled() gets called if
  8467. * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
  8468. * and read/write to the device still works.
  8469. **/
  8470. static pci_ers_result_t
  8471. qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
  8472. {
  8473. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8474. if (!is_aer_supported(ha))
  8475. return PCI_ERS_RESULT_NONE;
  8476. return PCI_ERS_RESULT_RECOVERED;
  8477. }
  8478. static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
  8479. {
  8480. uint32_t rval = QLA_ERROR;
  8481. int fn;
  8482. struct pci_dev *other_pdev = NULL;
  8483. ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
  8484. set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  8485. if (test_bit(AF_ONLINE, &ha->flags)) {
  8486. clear_bit(AF_ONLINE, &ha->flags);
  8487. clear_bit(AF_LINK_UP, &ha->flags);
  8488. iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
  8489. qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
  8490. }
  8491. fn = PCI_FUNC(ha->pdev->devfn);
  8492. if (is_qla8022(ha)) {
  8493. while (fn > 0) {
  8494. fn--;
  8495. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at func %x\n",
  8496. ha->host_no, __func__, fn);
  8497. /* Get the pci device given the domain, bus,
  8498. * slot/function number */
  8499. other_pdev = pci_get_domain_bus_and_slot(
  8500. pci_domain_nr(ha->pdev->bus),
  8501. ha->pdev->bus->number,
  8502. PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  8503. fn));
  8504. if (!other_pdev)
  8505. continue;
  8506. if (atomic_read(&other_pdev->enable_cnt)) {
  8507. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI func in enabled state%x\n",
  8508. ha->host_no, __func__, fn);
  8509. pci_dev_put(other_pdev);
  8510. break;
  8511. }
  8512. pci_dev_put(other_pdev);
  8513. }
  8514. } else {
  8515. /* this case is meant for ISP83xx/ISP84xx only */
  8516. if (qla4_83xx_can_perform_reset(ha)) {
  8517. /* reset fn as iSCSI is going to perform the reset */
  8518. fn = 0;
  8519. }
  8520. }
  8521. /* The first function on the card, the reset owner will
  8522. * start & initialize the firmware. The other functions
  8523. * on the card will reset the firmware context
  8524. */
  8525. if (!fn) {
  8526. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
  8527. "0x%x is the owner\n", ha->host_no, __func__,
  8528. ha->pdev->devfn);
  8529. ha->isp_ops->idc_lock(ha);
  8530. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8531. QLA8XXX_DEV_COLD);
  8532. ha->isp_ops->idc_unlock(ha);
  8533. rval = qla4_8xxx_update_idc_reg(ha);
  8534. if (rval == QLA_ERROR) {
  8535. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: FAILED\n",
  8536. ha->host_no, __func__);
  8537. ha->isp_ops->idc_lock(ha);
  8538. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8539. QLA8XXX_DEV_FAILED);
  8540. ha->isp_ops->idc_unlock(ha);
  8541. goto exit_error_recovery;
  8542. }
  8543. clear_bit(AF_FW_RECOVERY, &ha->flags);
  8544. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  8545. if (rval != QLA_SUCCESS) {
  8546. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  8547. "FAILED\n", ha->host_no, __func__);
  8548. qla4xxx_free_irqs(ha);
  8549. ha->isp_ops->idc_lock(ha);
  8550. qla4_8xxx_clear_drv_active(ha);
  8551. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8552. QLA8XXX_DEV_FAILED);
  8553. ha->isp_ops->idc_unlock(ha);
  8554. } else {
  8555. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
  8556. "READY\n", ha->host_no, __func__);
  8557. ha->isp_ops->idc_lock(ha);
  8558. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  8559. QLA8XXX_DEV_READY);
  8560. /* Clear driver state register */
  8561. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, 0);
  8562. qla4_8xxx_set_drv_active(ha);
  8563. ha->isp_ops->idc_unlock(ha);
  8564. ha->isp_ops->enable_intrs(ha);
  8565. }
  8566. } else {
  8567. ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
  8568. "the reset owner\n", ha->host_no, __func__,
  8569. ha->pdev->devfn);
  8570. if ((qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE) ==
  8571. QLA8XXX_DEV_READY)) {
  8572. clear_bit(AF_FW_RECOVERY, &ha->flags);
  8573. rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
  8574. if (rval == QLA_SUCCESS)
  8575. ha->isp_ops->enable_intrs(ha);
  8576. else
  8577. qla4xxx_free_irqs(ha);
  8578. ha->isp_ops->idc_lock(ha);
  8579. qla4_8xxx_set_drv_active(ha);
  8580. ha->isp_ops->idc_unlock(ha);
  8581. }
  8582. }
  8583. exit_error_recovery:
  8584. clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
  8585. return rval;
  8586. }
  8587. static pci_ers_result_t
  8588. qla4xxx_pci_slot_reset(struct pci_dev *pdev)
  8589. {
  8590. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  8591. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8592. int rc;
  8593. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
  8594. ha->host_no, __func__);
  8595. if (!is_aer_supported(ha))
  8596. return PCI_ERS_RESULT_NONE;
  8597. /* Restore the saved state of PCIe device -
  8598. * BAR registers, PCI Config space, PCIX, MSI,
  8599. * IOV states
  8600. */
  8601. pci_restore_state(pdev);
  8602. /* pci_restore_state() clears the saved_state flag of the device
  8603. * save restored state which resets saved_state flag
  8604. */
  8605. pci_save_state(pdev);
  8606. /* Initialize device or resume if in suspended state */
  8607. rc = pci_enable_device(pdev);
  8608. if (rc) {
  8609. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
  8610. "device after reset\n", ha->host_no, __func__);
  8611. goto exit_slot_reset;
  8612. }
  8613. ha->isp_ops->disable_intrs(ha);
  8614. if (is_qla80XX(ha)) {
  8615. if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
  8616. ret = PCI_ERS_RESULT_RECOVERED;
  8617. goto exit_slot_reset;
  8618. } else
  8619. goto exit_slot_reset;
  8620. }
  8621. exit_slot_reset:
  8622. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
  8623. "device after reset\n", ha->host_no, __func__, ret);
  8624. return ret;
  8625. }
  8626. static void
  8627. qla4xxx_pci_resume(struct pci_dev *pdev)
  8628. {
  8629. struct scsi_qla_host *ha = pci_get_drvdata(pdev);
  8630. int ret;
  8631. ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
  8632. ha->host_no, __func__);
  8633. ret = qla4xxx_wait_for_hba_online(ha);
  8634. if (ret != QLA_SUCCESS) {
  8635. ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
  8636. "resume I/O from slot/link_reset\n", ha->host_no,
  8637. __func__);
  8638. }
  8639. pci_cleanup_aer_uncorrect_error_status(pdev);
  8640. clear_bit(AF_EEH_BUSY, &ha->flags);
  8641. }
  8642. static const struct pci_error_handlers qla4xxx_err_handler = {
  8643. .error_detected = qla4xxx_pci_error_detected,
  8644. .mmio_enabled = qla4xxx_pci_mmio_enabled,
  8645. .slot_reset = qla4xxx_pci_slot_reset,
  8646. .resume = qla4xxx_pci_resume,
  8647. };
  8648. static struct pci_device_id qla4xxx_pci_tbl[] = {
  8649. {
  8650. .vendor = PCI_VENDOR_ID_QLOGIC,
  8651. .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
  8652. .subvendor = PCI_ANY_ID,
  8653. .subdevice = PCI_ANY_ID,
  8654. },
  8655. {
  8656. .vendor = PCI_VENDOR_ID_QLOGIC,
  8657. .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
  8658. .subvendor = PCI_ANY_ID,
  8659. .subdevice = PCI_ANY_ID,
  8660. },
  8661. {
  8662. .vendor = PCI_VENDOR_ID_QLOGIC,
  8663. .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
  8664. .subvendor = PCI_ANY_ID,
  8665. .subdevice = PCI_ANY_ID,
  8666. },
  8667. {
  8668. .vendor = PCI_VENDOR_ID_QLOGIC,
  8669. .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
  8670. .subvendor = PCI_ANY_ID,
  8671. .subdevice = PCI_ANY_ID,
  8672. },
  8673. {
  8674. .vendor = PCI_VENDOR_ID_QLOGIC,
  8675. .device = PCI_DEVICE_ID_QLOGIC_ISP8324,
  8676. .subvendor = PCI_ANY_ID,
  8677. .subdevice = PCI_ANY_ID,
  8678. },
  8679. {
  8680. .vendor = PCI_VENDOR_ID_QLOGIC,
  8681. .device = PCI_DEVICE_ID_QLOGIC_ISP8042,
  8682. .subvendor = PCI_ANY_ID,
  8683. .subdevice = PCI_ANY_ID,
  8684. },
  8685. {0, 0},
  8686. };
  8687. MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
  8688. static struct pci_driver qla4xxx_pci_driver = {
  8689. .name = DRIVER_NAME,
  8690. .id_table = qla4xxx_pci_tbl,
  8691. .probe = qla4xxx_probe_adapter,
  8692. .remove = qla4xxx_remove_adapter,
  8693. .err_handler = &qla4xxx_err_handler,
  8694. };
  8695. static int __init qla4xxx_module_init(void)
  8696. {
  8697. int ret;
  8698. if (ql4xqfulltracking)
  8699. qla4xxx_driver_template.track_queue_depth = 1;
  8700. /* Allocate cache for SRBs. */
  8701. srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
  8702. SLAB_HWCACHE_ALIGN, NULL);
  8703. if (srb_cachep == NULL) {
  8704. printk(KERN_ERR
  8705. "%s: Unable to allocate SRB cache..."
  8706. "Failing load!\n", DRIVER_NAME);
  8707. ret = -ENOMEM;
  8708. goto no_srp_cache;
  8709. }
  8710. /* Derive version string. */
  8711. strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
  8712. if (ql4xextended_error_logging)
  8713. strcat(qla4xxx_version_str, "-debug");
  8714. qla4xxx_scsi_transport =
  8715. iscsi_register_transport(&qla4xxx_iscsi_transport);
  8716. if (!qla4xxx_scsi_transport){
  8717. ret = -ENODEV;
  8718. goto release_srb_cache;
  8719. }
  8720. ret = pci_register_driver(&qla4xxx_pci_driver);
  8721. if (ret)
  8722. goto unregister_transport;
  8723. printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
  8724. return 0;
  8725. unregister_transport:
  8726. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  8727. release_srb_cache:
  8728. kmem_cache_destroy(srb_cachep);
  8729. no_srp_cache:
  8730. return ret;
  8731. }
  8732. static void __exit qla4xxx_module_exit(void)
  8733. {
  8734. pci_unregister_driver(&qla4xxx_pci_driver);
  8735. iscsi_unregister_transport(&qla4xxx_iscsi_transport);
  8736. kmem_cache_destroy(srb_cachep);
  8737. }
  8738. module_init(qla4xxx_module_init);
  8739. module_exit(qla4xxx_module_exit);
  8740. MODULE_AUTHOR("QLogic Corporation");
  8741. MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
  8742. MODULE_LICENSE("GPL");
  8743. MODULE_VERSION(QLA4XXX_DRIVER_VERSION);