qla_os.c 157 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/kobject.h>
  14. #include <linux/slab.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/scsicam.h>
  17. #include <scsi/scsi_transport.h>
  18. #include <scsi/scsi_transport_fc.h>
  19. #include "qla_target.h"
  20. /*
  21. * Driver version
  22. */
  23. char qla2x00_version_str[40];
  24. static int apidev_major;
  25. /*
  26. * SRB allocation cache
  27. */
  28. static struct kmem_cache *srb_cachep;
  29. /*
  30. * CT6 CTX allocation cache
  31. */
  32. static struct kmem_cache *ctx_cachep;
  33. /*
  34. * error level for logging
  35. */
  36. int ql_errlev = ql_log_all;
  37. static int ql2xenableclass2;
  38. module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
  39. MODULE_PARM_DESC(ql2xenableclass2,
  40. "Specify if Class 2 operations are supported from the very "
  41. "beginning. Default is 0 - class 2 not supported.");
  42. int ql2xlogintimeout = 20;
  43. module_param(ql2xlogintimeout, int, S_IRUGO);
  44. MODULE_PARM_DESC(ql2xlogintimeout,
  45. "Login timeout value in seconds.");
  46. int qlport_down_retry;
  47. module_param(qlport_down_retry, int, S_IRUGO);
  48. MODULE_PARM_DESC(qlport_down_retry,
  49. "Maximum number of command retries to a port that returns "
  50. "a PORT-DOWN status.");
  51. int ql2xplogiabsentdevice;
  52. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  53. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  54. "Option to enable PLOGI to devices that are not present after "
  55. "a Fabric scan. This is needed for several broken switches. "
  56. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  57. int ql2xloginretrycount = 0;
  58. module_param(ql2xloginretrycount, int, S_IRUGO);
  59. MODULE_PARM_DESC(ql2xloginretrycount,
  60. "Specify an alternate value for the NVRAM login retry count.");
  61. int ql2xallocfwdump = 1;
  62. module_param(ql2xallocfwdump, int, S_IRUGO);
  63. MODULE_PARM_DESC(ql2xallocfwdump,
  64. "Option to enable allocation of memory for a firmware dump "
  65. "during HBA initialization. Memory allocation requirements "
  66. "vary by ISP type. Default is 1 - allocate memory.");
  67. int ql2xextended_error_logging;
  68. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  69. MODULE_PARM_DESC(ql2xextended_error_logging,
  70. "Option to enable extended error logging,\n"
  71. "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
  72. "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
  73. "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
  74. "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
  75. "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
  76. "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
  77. "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
  78. "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
  79. "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
  80. "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
  81. "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
  82. "\t\t0x1e400000 - Preferred value for capturing essential "
  83. "debug information (equivalent to old "
  84. "ql2xextended_error_logging=1).\n"
  85. "\t\tDo LOGICAL OR of the value to enable more than one level");
  86. int ql2xshiftctondsd = 6;
  87. module_param(ql2xshiftctondsd, int, S_IRUGO);
  88. MODULE_PARM_DESC(ql2xshiftctondsd,
  89. "Set to control shifting of command type processing "
  90. "based on total number of SG elements.");
  91. int ql2xfdmienable=1;
  92. module_param(ql2xfdmienable, int, S_IRUGO);
  93. MODULE_PARM_DESC(ql2xfdmienable,
  94. "Enables FDMI registrations. "
  95. "0 - no FDMI. Default is 1 - perform FDMI.");
  96. int ql2xmaxqdepth = MAX_Q_DEPTH;
  97. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  98. MODULE_PARM_DESC(ql2xmaxqdepth,
  99. "Maximum queue depth to set for each LUN. "
  100. "Default is 32.");
  101. int ql2xenabledif = 2;
  102. module_param(ql2xenabledif, int, S_IRUGO);
  103. MODULE_PARM_DESC(ql2xenabledif,
  104. " Enable T10-CRC-DIF "
  105. " Default is 0 - No DIF Support. 1 - Enable it"
  106. ", 2 - Enable DIF for all types, except Type 0.");
  107. int ql2xenablehba_err_chk = 2;
  108. module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
  109. MODULE_PARM_DESC(ql2xenablehba_err_chk,
  110. " Enable T10-CRC-DIF Error isolation by HBA:\n"
  111. " Default is 1.\n"
  112. " 0 -- Error isolation disabled\n"
  113. " 1 -- Error isolation enabled only for DIX Type 0\n"
  114. " 2 -- Error isolation enabled for all Types\n");
  115. int ql2xiidmaenable=1;
  116. module_param(ql2xiidmaenable, int, S_IRUGO);
  117. MODULE_PARM_DESC(ql2xiidmaenable,
  118. "Enables iIDMA settings "
  119. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  120. int ql2xmaxqueues = 1;
  121. module_param(ql2xmaxqueues, int, S_IRUGO);
  122. MODULE_PARM_DESC(ql2xmaxqueues,
  123. "Enables MQ settings "
  124. "Default is 1 for single queue. Set it to number "
  125. "of queues in MQ mode.");
  126. int ql2xmultique_tag;
  127. module_param(ql2xmultique_tag, int, S_IRUGO);
  128. MODULE_PARM_DESC(ql2xmultique_tag,
  129. "Enables CPU affinity settings for the driver "
  130. "Default is 0 for no affinity of request and response IO. "
  131. "Set it to 1 to turn on the cpu affinity.");
  132. int ql2xfwloadbin;
  133. module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
  134. MODULE_PARM_DESC(ql2xfwloadbin,
  135. "Option to specify location from which to load ISP firmware:.\n"
  136. " 2 -- load firmware via the request_firmware() (hotplug).\n"
  137. " interface.\n"
  138. " 1 -- load firmware from flash.\n"
  139. " 0 -- use default semantics.\n");
  140. int ql2xetsenable;
  141. module_param(ql2xetsenable, int, S_IRUGO);
  142. MODULE_PARM_DESC(ql2xetsenable,
  143. "Enables firmware ETS burst."
  144. "Default is 0 - skip ETS enablement.");
  145. int ql2xdbwr = 1;
  146. module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
  147. MODULE_PARM_DESC(ql2xdbwr,
  148. "Option to specify scheme for request queue posting.\n"
  149. " 0 -- Regular doorbell.\n"
  150. " 1 -- CAMRAM doorbell (faster).\n");
  151. int ql2xtargetreset = 1;
  152. module_param(ql2xtargetreset, int, S_IRUGO);
  153. MODULE_PARM_DESC(ql2xtargetreset,
  154. "Enable target reset."
  155. "Default is 1 - use hw defaults.");
  156. int ql2xgffidenable;
  157. module_param(ql2xgffidenable, int, S_IRUGO);
  158. MODULE_PARM_DESC(ql2xgffidenable,
  159. "Enables GFF_ID checks of port type. "
  160. "Default is 0 - Do not use GFF_ID information.");
  161. int ql2xasynctmfenable;
  162. module_param(ql2xasynctmfenable, int, S_IRUGO);
  163. MODULE_PARM_DESC(ql2xasynctmfenable,
  164. "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
  165. "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
  166. int ql2xdontresethba;
  167. module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
  168. MODULE_PARM_DESC(ql2xdontresethba,
  169. "Option to specify reset behaviour.\n"
  170. " 0 (Default) -- Reset on failure.\n"
  171. " 1 -- Do not reset on failure.\n");
  172. uint ql2xmaxlun = MAX_LUNS;
  173. module_param(ql2xmaxlun, uint, S_IRUGO);
  174. MODULE_PARM_DESC(ql2xmaxlun,
  175. "Defines the maximum LU number to register with the SCSI "
  176. "midlayer. Default is 65535.");
  177. int ql2xmdcapmask = 0x1F;
  178. module_param(ql2xmdcapmask, int, S_IRUGO);
  179. MODULE_PARM_DESC(ql2xmdcapmask,
  180. "Set the Minidump driver capture mask level. "
  181. "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
  182. int ql2xmdenable = 1;
  183. module_param(ql2xmdenable, int, S_IRUGO);
  184. MODULE_PARM_DESC(ql2xmdenable,
  185. "Enable/disable MiniDump. "
  186. "0 - MiniDump disabled. "
  187. "1 (Default) - MiniDump enabled.");
  188. /*
  189. * SCSI host template entry points
  190. */
  191. static int qla2xxx_slave_configure(struct scsi_device * device);
  192. static int qla2xxx_slave_alloc(struct scsi_device *);
  193. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  194. static void qla2xxx_scan_start(struct Scsi_Host *);
  195. static void qla2xxx_slave_destroy(struct scsi_device *);
  196. static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  197. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  198. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  199. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  200. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  201. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  202. static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
  203. static int qla2x00_change_queue_type(struct scsi_device *, int);
  204. static void qla2x00_free_device(scsi_qla_host_t *);
  205. struct scsi_host_template qla2xxx_driver_template = {
  206. .module = THIS_MODULE,
  207. .name = QLA2XXX_DRIVER_NAME,
  208. .queuecommand = qla2xxx_queuecommand,
  209. .eh_abort_handler = qla2xxx_eh_abort,
  210. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  211. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  212. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  213. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  214. .slave_configure = qla2xxx_slave_configure,
  215. .slave_alloc = qla2xxx_slave_alloc,
  216. .slave_destroy = qla2xxx_slave_destroy,
  217. .scan_finished = qla2xxx_scan_finished,
  218. .scan_start = qla2xxx_scan_start,
  219. .change_queue_depth = qla2x00_change_queue_depth,
  220. .change_queue_type = qla2x00_change_queue_type,
  221. .this_id = -1,
  222. .cmd_per_lun = 3,
  223. .use_clustering = ENABLE_CLUSTERING,
  224. .sg_tablesize = SG_ALL,
  225. .max_sectors = 0xFFFF,
  226. .shost_attrs = qla2x00_host_attrs,
  227. .supported_mode = MODE_INITIATOR,
  228. };
  229. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  230. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  231. /* TODO Convert to inlines
  232. *
  233. * Timer routines
  234. */
  235. __inline__ void
  236. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  237. {
  238. init_timer(&vha->timer);
  239. vha->timer.expires = jiffies + interval * HZ;
  240. vha->timer.data = (unsigned long)vha;
  241. vha->timer.function = (void (*)(unsigned long))func;
  242. add_timer(&vha->timer);
  243. vha->timer_active = 1;
  244. }
  245. static inline void
  246. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  247. {
  248. /* Currently used for 82XX only. */
  249. if (vha->device_flags & DFLG_DEV_FAILED) {
  250. ql_dbg(ql_dbg_timer, vha, 0x600d,
  251. "Device in a failed state, returning.\n");
  252. return;
  253. }
  254. mod_timer(&vha->timer, jiffies + interval * HZ);
  255. }
  256. static __inline__ void
  257. qla2x00_stop_timer(scsi_qla_host_t *vha)
  258. {
  259. del_timer_sync(&vha->timer);
  260. vha->timer_active = 0;
  261. }
  262. static int qla2x00_do_dpc(void *data);
  263. static void qla2x00_rst_aen(scsi_qla_host_t *);
  264. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  265. struct req_que **, struct rsp_que **);
  266. static void qla2x00_free_fw_dump(struct qla_hw_data *);
  267. static void qla2x00_mem_free(struct qla_hw_data *);
  268. /* -------------------------------------------------------------------------- */
  269. static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
  270. struct rsp_que *rsp)
  271. {
  272. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  273. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  274. GFP_KERNEL);
  275. if (!ha->req_q_map) {
  276. ql_log(ql_log_fatal, vha, 0x003b,
  277. "Unable to allocate memory for request queue ptrs.\n");
  278. goto fail_req_map;
  279. }
  280. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  281. GFP_KERNEL);
  282. if (!ha->rsp_q_map) {
  283. ql_log(ql_log_fatal, vha, 0x003c,
  284. "Unable to allocate memory for response queue ptrs.\n");
  285. goto fail_rsp_map;
  286. }
  287. /*
  288. * Make sure we record at least the request and response queue zero in
  289. * case we need to free them if part of the probe fails.
  290. */
  291. ha->rsp_q_map[0] = rsp;
  292. ha->req_q_map[0] = req;
  293. set_bit(0, ha->rsp_qid_map);
  294. set_bit(0, ha->req_qid_map);
  295. return 1;
  296. fail_rsp_map:
  297. kfree(ha->req_q_map);
  298. ha->req_q_map = NULL;
  299. fail_req_map:
  300. return -ENOMEM;
  301. }
  302. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  303. {
  304. if (IS_QLAFX00(ha)) {
  305. if (req && req->ring_fx00)
  306. dma_free_coherent(&ha->pdev->dev,
  307. (req->length_fx00 + 1) * sizeof(request_t),
  308. req->ring_fx00, req->dma_fx00);
  309. } else if (req && req->ring)
  310. dma_free_coherent(&ha->pdev->dev,
  311. (req->length + 1) * sizeof(request_t),
  312. req->ring, req->dma);
  313. if (req)
  314. kfree(req->outstanding_cmds);
  315. kfree(req);
  316. req = NULL;
  317. }
  318. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  319. {
  320. if (IS_QLAFX00(ha)) {
  321. if (rsp && rsp->ring)
  322. dma_free_coherent(&ha->pdev->dev,
  323. (rsp->length_fx00 + 1) * sizeof(request_t),
  324. rsp->ring_fx00, rsp->dma_fx00);
  325. } else if (rsp && rsp->ring) {
  326. dma_free_coherent(&ha->pdev->dev,
  327. (rsp->length + 1) * sizeof(response_t),
  328. rsp->ring, rsp->dma);
  329. }
  330. kfree(rsp);
  331. rsp = NULL;
  332. }
  333. static void qla2x00_free_queues(struct qla_hw_data *ha)
  334. {
  335. struct req_que *req;
  336. struct rsp_que *rsp;
  337. int cnt;
  338. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  339. req = ha->req_q_map[cnt];
  340. qla2x00_free_req_que(ha, req);
  341. }
  342. kfree(ha->req_q_map);
  343. ha->req_q_map = NULL;
  344. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  345. rsp = ha->rsp_q_map[cnt];
  346. qla2x00_free_rsp_que(ha, rsp);
  347. }
  348. kfree(ha->rsp_q_map);
  349. ha->rsp_q_map = NULL;
  350. }
  351. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  352. {
  353. uint16_t options = 0;
  354. int ques, req, ret;
  355. struct qla_hw_data *ha = vha->hw;
  356. if (!(ha->fw_attributes & BIT_6)) {
  357. ql_log(ql_log_warn, vha, 0x00d8,
  358. "Firmware is not multi-queue capable.\n");
  359. goto fail;
  360. }
  361. if (ql2xmultique_tag) {
  362. /* create a request queue for IO */
  363. options |= BIT_7;
  364. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  365. QLA_DEFAULT_QUE_QOS);
  366. if (!req) {
  367. ql_log(ql_log_warn, vha, 0x00e0,
  368. "Failed to create request queue.\n");
  369. goto fail;
  370. }
  371. ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
  372. vha->req = ha->req_q_map[req];
  373. options |= BIT_1;
  374. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  375. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  376. if (!ret) {
  377. ql_log(ql_log_warn, vha, 0x00e8,
  378. "Failed to create response queue.\n");
  379. goto fail2;
  380. }
  381. }
  382. ha->flags.cpu_affinity_enabled = 1;
  383. ql_dbg(ql_dbg_multiq, vha, 0xc007,
  384. "CPU affinity mode enalbed, "
  385. "no. of response queues:%d no. of request queues:%d.\n",
  386. ha->max_rsp_queues, ha->max_req_queues);
  387. ql_dbg(ql_dbg_init, vha, 0x00e9,
  388. "CPU affinity mode enalbed, "
  389. "no. of response queues:%d no. of request queues:%d.\n",
  390. ha->max_rsp_queues, ha->max_req_queues);
  391. }
  392. return 0;
  393. fail2:
  394. qla25xx_delete_queues(vha);
  395. destroy_workqueue(ha->wq);
  396. ha->wq = NULL;
  397. vha->req = ha->req_q_map[0];
  398. fail:
  399. ha->mqenable = 0;
  400. kfree(ha->req_q_map);
  401. kfree(ha->rsp_q_map);
  402. ha->max_req_queues = ha->max_rsp_queues = 1;
  403. return 1;
  404. }
  405. static char *
  406. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  407. {
  408. struct qla_hw_data *ha = vha->hw;
  409. static char *pci_bus_modes[] = {
  410. "33", "66", "100", "133",
  411. };
  412. uint16_t pci_bus;
  413. strcpy(str, "PCI");
  414. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  415. if (pci_bus) {
  416. strcat(str, "-X (");
  417. strcat(str, pci_bus_modes[pci_bus]);
  418. } else {
  419. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  420. strcat(str, " (");
  421. strcat(str, pci_bus_modes[pci_bus]);
  422. }
  423. strcat(str, " MHz)");
  424. return (str);
  425. }
  426. static char *
  427. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  428. {
  429. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  430. struct qla_hw_data *ha = vha->hw;
  431. uint32_t pci_bus;
  432. if (pci_is_pcie(ha->pdev)) {
  433. char lwstr[6];
  434. uint32_t lstat, lspeed, lwidth;
  435. pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
  436. lspeed = lstat & PCI_EXP_LNKCAP_SLS;
  437. lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
  438. strcpy(str, "PCIe (");
  439. switch (lspeed) {
  440. case 1:
  441. strcat(str, "2.5GT/s ");
  442. break;
  443. case 2:
  444. strcat(str, "5.0GT/s ");
  445. break;
  446. case 3:
  447. strcat(str, "8.0GT/s ");
  448. break;
  449. default:
  450. strcat(str, "<unknown> ");
  451. break;
  452. }
  453. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  454. strcat(str, lwstr);
  455. return str;
  456. }
  457. strcpy(str, "PCI");
  458. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  459. if (pci_bus == 0 || pci_bus == 8) {
  460. strcat(str, " (");
  461. strcat(str, pci_bus_modes[pci_bus >> 3]);
  462. } else {
  463. strcat(str, "-X ");
  464. if (pci_bus & BIT_2)
  465. strcat(str, "Mode 2");
  466. else
  467. strcat(str, "Mode 1");
  468. strcat(str, " (");
  469. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  470. }
  471. strcat(str, " MHz)");
  472. return str;
  473. }
  474. static char *
  475. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  476. {
  477. char un_str[10];
  478. struct qla_hw_data *ha = vha->hw;
  479. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  480. ha->fw_minor_version,
  481. ha->fw_subminor_version);
  482. if (ha->fw_attributes & BIT_9) {
  483. strcat(str, "FLX");
  484. return (str);
  485. }
  486. switch (ha->fw_attributes & 0xFF) {
  487. case 0x7:
  488. strcat(str, "EF");
  489. break;
  490. case 0x17:
  491. strcat(str, "TP");
  492. break;
  493. case 0x37:
  494. strcat(str, "IP");
  495. break;
  496. case 0x77:
  497. strcat(str, "VI");
  498. break;
  499. default:
  500. sprintf(un_str, "(%x)", ha->fw_attributes);
  501. strcat(str, un_str);
  502. break;
  503. }
  504. if (ha->fw_attributes & 0x100)
  505. strcat(str, "X");
  506. return (str);
  507. }
  508. static char *
  509. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  510. {
  511. struct qla_hw_data *ha = vha->hw;
  512. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  513. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  514. return str;
  515. }
  516. void
  517. qla2x00_sp_free_dma(void *vha, void *ptr)
  518. {
  519. srb_t *sp = (srb_t *)ptr;
  520. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  521. struct qla_hw_data *ha = sp->fcport->vha->hw;
  522. void *ctx = GET_CMD_CTX_SP(sp);
  523. if (sp->flags & SRB_DMA_VALID) {
  524. scsi_dma_unmap(cmd);
  525. sp->flags &= ~SRB_DMA_VALID;
  526. }
  527. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  528. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  529. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  530. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  531. }
  532. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  533. /* List assured to be having elements */
  534. qla2x00_clean_dsd_pool(ha, sp);
  535. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  536. }
  537. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  538. dma_pool_free(ha->dl_dma_pool, ctx,
  539. ((struct crc_context *)ctx)->crc_ctx_dma);
  540. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  541. }
  542. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  543. struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
  544. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
  545. ctx1->fcp_cmnd_dma);
  546. list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
  547. ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
  548. ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
  549. mempool_free(ctx1, ha->ctx_mempool);
  550. ctx1 = NULL;
  551. }
  552. CMD_SP(cmd) = NULL;
  553. qla2x00_rel_sp(sp->fcport->vha, sp);
  554. }
  555. static void
  556. qla2x00_sp_compl(void *data, void *ptr, int res)
  557. {
  558. struct qla_hw_data *ha = (struct qla_hw_data *)data;
  559. srb_t *sp = (srb_t *)ptr;
  560. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  561. cmd->result = res;
  562. if (atomic_read(&sp->ref_count) == 0) {
  563. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
  564. "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
  565. sp, GET_CMD_SP(sp));
  566. if (ql2xextended_error_logging & ql_dbg_io)
  567. BUG();
  568. return;
  569. }
  570. if (!atomic_dec_and_test(&sp->ref_count))
  571. return;
  572. qla2x00_sp_free_dma(ha, sp);
  573. cmd->scsi_done(cmd);
  574. }
  575. /* If we are SP1 here, we need to still take and release the host_lock as SP1
  576. * does not have the changes necessary to avoid taking host->host_lock.
  577. */
  578. static int
  579. qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  580. {
  581. scsi_qla_host_t *vha = shost_priv(host);
  582. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  583. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  584. struct qla_hw_data *ha = vha->hw;
  585. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  586. srb_t *sp;
  587. int rval;
  588. if (ha->flags.eeh_busy) {
  589. if (ha->flags.pci_channel_io_perm_failure) {
  590. ql_dbg(ql_dbg_aer, vha, 0x9010,
  591. "PCI Channel IO permanent failure, exiting "
  592. "cmd=%p.\n", cmd);
  593. cmd->result = DID_NO_CONNECT << 16;
  594. } else {
  595. ql_dbg(ql_dbg_aer, vha, 0x9011,
  596. "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
  597. cmd->result = DID_REQUEUE << 16;
  598. }
  599. goto qc24_fail_command;
  600. }
  601. rval = fc_remote_port_chkready(rport);
  602. if (rval) {
  603. cmd->result = rval;
  604. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
  605. "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
  606. cmd, rval);
  607. goto qc24_fail_command;
  608. }
  609. if (!vha->flags.difdix_supported &&
  610. scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  611. ql_dbg(ql_dbg_io, vha, 0x3004,
  612. "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
  613. cmd);
  614. cmd->result = DID_NO_CONNECT << 16;
  615. goto qc24_fail_command;
  616. }
  617. if (!fcport) {
  618. cmd->result = DID_NO_CONNECT << 16;
  619. goto qc24_fail_command;
  620. }
  621. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  622. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  623. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  624. ql_dbg(ql_dbg_io, vha, 0x3005,
  625. "Returning DNC, fcport_state=%d loop_state=%d.\n",
  626. atomic_read(&fcport->state),
  627. atomic_read(&base_vha->loop_state));
  628. cmd->result = DID_NO_CONNECT << 16;
  629. goto qc24_fail_command;
  630. }
  631. goto qc24_target_busy;
  632. }
  633. sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
  634. if (!sp) {
  635. set_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags);
  636. goto qc24_host_busy;
  637. }
  638. sp->u.scmd.cmd = cmd;
  639. sp->type = SRB_SCSI_CMD;
  640. atomic_set(&sp->ref_count, 1);
  641. CMD_SP(cmd) = (void *)sp;
  642. sp->free = qla2x00_sp_free_dma;
  643. sp->done = qla2x00_sp_compl;
  644. rval = ha->isp_ops->start_scsi(sp);
  645. if (rval != QLA_SUCCESS) {
  646. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
  647. "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
  648. set_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags);
  649. goto qc24_host_busy_free_sp;
  650. }
  651. return 0;
  652. qc24_host_busy_free_sp:
  653. qla2x00_sp_free_dma(ha, sp);
  654. qc24_host_busy:
  655. return SCSI_MLQUEUE_HOST_BUSY;
  656. qc24_target_busy:
  657. return SCSI_MLQUEUE_TARGET_BUSY;
  658. qc24_fail_command:
  659. cmd->scsi_done(cmd);
  660. return 0;
  661. }
  662. /*
  663. * qla2x00_eh_wait_on_command
  664. * Waits for the command to be returned by the Firmware for some
  665. * max time.
  666. *
  667. * Input:
  668. * cmd = Scsi Command to wait on.
  669. *
  670. * Return:
  671. * Not Found : 0
  672. * Found : 1
  673. */
  674. static int
  675. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  676. {
  677. #define ABORT_POLLING_PERIOD 1000
  678. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  679. unsigned long wait_iter = ABORT_WAIT_ITER;
  680. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  681. struct qla_hw_data *ha = vha->hw;
  682. int ret = QLA_SUCCESS;
  683. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  684. ql_dbg(ql_dbg_taskm, vha, 0x8005,
  685. "Return:eh_wait.\n");
  686. return ret;
  687. }
  688. while (CMD_SP(cmd) && wait_iter--) {
  689. msleep(ABORT_POLLING_PERIOD);
  690. }
  691. if (CMD_SP(cmd))
  692. ret = QLA_FUNCTION_FAILED;
  693. return ret;
  694. }
  695. /*
  696. * qla2x00_wait_for_hba_online
  697. * Wait till the HBA is online after going through
  698. * <= MAX_RETRIES_OF_ISP_ABORT or
  699. * finally HBA is disabled ie marked offline
  700. *
  701. * Input:
  702. * ha - pointer to host adapter structure
  703. *
  704. * Note:
  705. * Does context switching-Release SPIN_LOCK
  706. * (if any) before calling this routine.
  707. *
  708. * Return:
  709. * Success (Adapter is online) : 0
  710. * Failed (Adapter is offline/disabled) : 1
  711. */
  712. int
  713. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  714. {
  715. int return_status;
  716. unsigned long wait_online;
  717. struct qla_hw_data *ha = vha->hw;
  718. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  719. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  720. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  721. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  722. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  723. ha->dpc_active) && time_before(jiffies, wait_online)) {
  724. msleep(1000);
  725. }
  726. if (base_vha->flags.online)
  727. return_status = QLA_SUCCESS;
  728. else
  729. return_status = QLA_FUNCTION_FAILED;
  730. return (return_status);
  731. }
  732. /*
  733. * qla2x00_wait_for_reset_ready
  734. * Wait till the HBA is online after going through
  735. * <= MAX_RETRIES_OF_ISP_ABORT or
  736. * finally HBA is disabled ie marked offline or flash
  737. * operations are in progress.
  738. *
  739. * Input:
  740. * ha - pointer to host adapter structure
  741. *
  742. * Note:
  743. * Does context switching-Release SPIN_LOCK
  744. * (if any) before calling this routine.
  745. *
  746. * Return:
  747. * Success (Adapter is online/no flash ops) : 0
  748. * Failed (Adapter is offline/disabled/flash ops in progress) : 1
  749. */
  750. static int
  751. qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
  752. {
  753. int return_status;
  754. unsigned long wait_online;
  755. struct qla_hw_data *ha = vha->hw;
  756. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  757. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  758. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  759. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  760. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  761. ha->optrom_state != QLA_SWAITING ||
  762. ha->dpc_active) && time_before(jiffies, wait_online))
  763. msleep(1000);
  764. if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
  765. return_status = QLA_SUCCESS;
  766. else
  767. return_status = QLA_FUNCTION_FAILED;
  768. ql_dbg(ql_dbg_taskm, vha, 0x8019,
  769. "%s return status=%d.\n", __func__, return_status);
  770. return return_status;
  771. }
  772. int
  773. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  774. {
  775. int return_status;
  776. unsigned long wait_reset;
  777. struct qla_hw_data *ha = vha->hw;
  778. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  779. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  780. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  781. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  782. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  783. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  784. msleep(1000);
  785. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  786. ha->flags.chip_reset_done)
  787. break;
  788. }
  789. if (ha->flags.chip_reset_done)
  790. return_status = QLA_SUCCESS;
  791. else
  792. return_status = QLA_FUNCTION_FAILED;
  793. return return_status;
  794. }
  795. static void
  796. sp_get(struct srb *sp)
  797. {
  798. atomic_inc(&sp->ref_count);
  799. }
  800. /**************************************************************************
  801. * qla2xxx_eh_abort
  802. *
  803. * Description:
  804. * The abort function will abort the specified command.
  805. *
  806. * Input:
  807. * cmd = Linux SCSI command packet to be aborted.
  808. *
  809. * Returns:
  810. * Either SUCCESS or FAILED.
  811. *
  812. * Note:
  813. * Only return FAILED if command not returned by firmware.
  814. **************************************************************************/
  815. static int
  816. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  817. {
  818. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  819. srb_t *sp;
  820. int ret;
  821. unsigned int id, lun;
  822. unsigned long flags;
  823. int wait = 0;
  824. struct qla_hw_data *ha = vha->hw;
  825. if (!CMD_SP(cmd))
  826. return SUCCESS;
  827. ret = fc_block_scsi_eh(cmd);
  828. if (ret != 0)
  829. return ret;
  830. ret = SUCCESS;
  831. id = cmd->device->id;
  832. lun = cmd->device->lun;
  833. spin_lock_irqsave(&ha->hardware_lock, flags);
  834. sp = (srb_t *) CMD_SP(cmd);
  835. if (!sp) {
  836. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  837. return SUCCESS;
  838. }
  839. ql_dbg(ql_dbg_taskm, vha, 0x8002,
  840. "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
  841. vha->host_no, id, lun, sp, cmd);
  842. /* Get a reference to the sp and drop the lock.*/
  843. sp_get(sp);
  844. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  845. if (ha->isp_ops->abort_command(sp)) {
  846. ret = FAILED;
  847. ql_dbg(ql_dbg_taskm, vha, 0x8003,
  848. "Abort command mbx failed cmd=%p.\n", cmd);
  849. } else {
  850. ql_dbg(ql_dbg_taskm, vha, 0x8004,
  851. "Abort command mbx success cmd=%p.\n", cmd);
  852. wait = 1;
  853. }
  854. spin_lock_irqsave(&ha->hardware_lock, flags);
  855. sp->done(ha, sp, 0);
  856. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  857. /* Did the command return during mailbox execution? */
  858. if (ret == FAILED && !CMD_SP(cmd))
  859. ret = SUCCESS;
  860. /* Wait for the command to be returned. */
  861. if (wait) {
  862. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  863. ql_log(ql_log_warn, vha, 0x8006,
  864. "Abort handler timed out cmd=%p.\n", cmd);
  865. ret = FAILED;
  866. }
  867. }
  868. ql_log(ql_log_info, vha, 0x801c,
  869. "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
  870. vha->host_no, id, lun, wait, ret);
  871. return ret;
  872. }
  873. int
  874. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  875. unsigned int l, enum nexus_wait_type type)
  876. {
  877. int cnt, match, status;
  878. unsigned long flags;
  879. struct qla_hw_data *ha = vha->hw;
  880. struct req_que *req;
  881. srb_t *sp;
  882. struct scsi_cmnd *cmd;
  883. status = QLA_SUCCESS;
  884. spin_lock_irqsave(&ha->hardware_lock, flags);
  885. req = vha->req;
  886. for (cnt = 1; status == QLA_SUCCESS &&
  887. cnt < req->num_outstanding_cmds; cnt++) {
  888. sp = req->outstanding_cmds[cnt];
  889. if (!sp)
  890. continue;
  891. if (sp->type != SRB_SCSI_CMD)
  892. continue;
  893. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  894. continue;
  895. match = 0;
  896. cmd = GET_CMD_SP(sp);
  897. switch (type) {
  898. case WAIT_HOST:
  899. match = 1;
  900. break;
  901. case WAIT_TARGET:
  902. match = cmd->device->id == t;
  903. break;
  904. case WAIT_LUN:
  905. match = (cmd->device->id == t &&
  906. cmd->device->lun == l);
  907. break;
  908. }
  909. if (!match)
  910. continue;
  911. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  912. status = qla2x00_eh_wait_on_command(cmd);
  913. spin_lock_irqsave(&ha->hardware_lock, flags);
  914. }
  915. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  916. return status;
  917. }
  918. static char *reset_errors[] = {
  919. "HBA not online",
  920. "HBA not ready",
  921. "Task management failed",
  922. "Waiting for command completions",
  923. };
  924. static int
  925. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  926. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
  927. {
  928. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  929. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  930. int err;
  931. if (!fcport) {
  932. return FAILED;
  933. }
  934. err = fc_block_scsi_eh(cmd);
  935. if (err != 0)
  936. return err;
  937. ql_log(ql_log_info, vha, 0x8009,
  938. "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
  939. cmd->device->id, cmd->device->lun, cmd);
  940. err = 0;
  941. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  942. ql_log(ql_log_warn, vha, 0x800a,
  943. "Wait for hba online failed for cmd=%p.\n", cmd);
  944. goto eh_reset_failed;
  945. }
  946. err = 2;
  947. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  948. != QLA_SUCCESS) {
  949. ql_log(ql_log_warn, vha, 0x800c,
  950. "do_reset failed for cmd=%p.\n", cmd);
  951. goto eh_reset_failed;
  952. }
  953. err = 3;
  954. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  955. cmd->device->lun, type) != QLA_SUCCESS) {
  956. ql_log(ql_log_warn, vha, 0x800d,
  957. "wait for pending cmds failed for cmd=%p.\n", cmd);
  958. goto eh_reset_failed;
  959. }
  960. ql_log(ql_log_info, vha, 0x800e,
  961. "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
  962. vha->host_no, cmd->device->id, cmd->device->lun, cmd);
  963. return SUCCESS;
  964. eh_reset_failed:
  965. ql_log(ql_log_info, vha, 0x800f,
  966. "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
  967. reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
  968. cmd);
  969. return FAILED;
  970. }
  971. static int
  972. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  973. {
  974. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  975. struct qla_hw_data *ha = vha->hw;
  976. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  977. ha->isp_ops->lun_reset);
  978. }
  979. static int
  980. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  981. {
  982. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  983. struct qla_hw_data *ha = vha->hw;
  984. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  985. ha->isp_ops->target_reset);
  986. }
  987. /**************************************************************************
  988. * qla2xxx_eh_bus_reset
  989. *
  990. * Description:
  991. * The bus reset function will reset the bus and abort any executing
  992. * commands.
  993. *
  994. * Input:
  995. * cmd = Linux SCSI command packet of the command that cause the
  996. * bus reset.
  997. *
  998. * Returns:
  999. * SUCCESS/FAILURE (defined as macro in scsi.h).
  1000. *
  1001. **************************************************************************/
  1002. static int
  1003. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  1004. {
  1005. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1006. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  1007. int ret = FAILED;
  1008. unsigned int id, lun;
  1009. id = cmd->device->id;
  1010. lun = cmd->device->lun;
  1011. if (!fcport) {
  1012. return ret;
  1013. }
  1014. ret = fc_block_scsi_eh(cmd);
  1015. if (ret != 0)
  1016. return ret;
  1017. ret = FAILED;
  1018. ql_log(ql_log_info, vha, 0x8012,
  1019. "BUS RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
  1020. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1021. ql_log(ql_log_fatal, vha, 0x8013,
  1022. "Wait for hba online failed board disabled.\n");
  1023. goto eh_bus_reset_done;
  1024. }
  1025. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  1026. ret = SUCCESS;
  1027. if (ret == FAILED)
  1028. goto eh_bus_reset_done;
  1029. /* Flush outstanding commands. */
  1030. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
  1031. QLA_SUCCESS) {
  1032. ql_log(ql_log_warn, vha, 0x8014,
  1033. "Wait for pending commands failed.\n");
  1034. ret = FAILED;
  1035. }
  1036. eh_bus_reset_done:
  1037. ql_log(ql_log_warn, vha, 0x802b,
  1038. "BUS RESET %s nexus=%ld:%d:%d.\n",
  1039. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1040. return ret;
  1041. }
  1042. /**************************************************************************
  1043. * qla2xxx_eh_host_reset
  1044. *
  1045. * Description:
  1046. * The reset function will reset the Adapter.
  1047. *
  1048. * Input:
  1049. * cmd = Linux SCSI command packet of the command that cause the
  1050. * adapter reset.
  1051. *
  1052. * Returns:
  1053. * Either SUCCESS or FAILED.
  1054. *
  1055. * Note:
  1056. **************************************************************************/
  1057. static int
  1058. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1059. {
  1060. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1061. struct qla_hw_data *ha = vha->hw;
  1062. int ret = FAILED;
  1063. unsigned int id, lun;
  1064. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1065. id = cmd->device->id;
  1066. lun = cmd->device->lun;
  1067. ql_log(ql_log_info, vha, 0x8018,
  1068. "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
  1069. if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
  1070. goto eh_host_reset_lock;
  1071. if (vha != base_vha) {
  1072. if (qla2x00_vp_abort_isp(vha))
  1073. goto eh_host_reset_lock;
  1074. } else {
  1075. if (IS_P3P_TYPE(vha->hw)) {
  1076. if (!qla82xx_fcoe_ctx_reset(vha)) {
  1077. /* Ctx reset success */
  1078. ret = SUCCESS;
  1079. goto eh_host_reset_lock;
  1080. }
  1081. /* fall thru if ctx reset failed */
  1082. }
  1083. if (ha->wq)
  1084. flush_workqueue(ha->wq);
  1085. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1086. if (ha->isp_ops->abort_isp(base_vha)) {
  1087. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1088. /* failed. schedule dpc to try */
  1089. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  1090. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1091. ql_log(ql_log_warn, vha, 0x802a,
  1092. "wait for hba online failed.\n");
  1093. goto eh_host_reset_lock;
  1094. }
  1095. }
  1096. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1097. }
  1098. /* Waiting for command to be returned to OS.*/
  1099. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
  1100. QLA_SUCCESS)
  1101. ret = SUCCESS;
  1102. eh_host_reset_lock:
  1103. ql_log(ql_log_info, vha, 0x8017,
  1104. "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
  1105. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1106. return ret;
  1107. }
  1108. /*
  1109. * qla2x00_loop_reset
  1110. * Issue loop reset.
  1111. *
  1112. * Input:
  1113. * ha = adapter block pointer.
  1114. *
  1115. * Returns:
  1116. * 0 = success
  1117. */
  1118. int
  1119. qla2x00_loop_reset(scsi_qla_host_t *vha)
  1120. {
  1121. int ret;
  1122. struct fc_port *fcport;
  1123. struct qla_hw_data *ha = vha->hw;
  1124. if (IS_QLAFX00(ha)) {
  1125. return qlafx00_loop_reset(vha);
  1126. }
  1127. if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
  1128. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1129. if (fcport->port_type != FCT_TARGET)
  1130. continue;
  1131. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  1132. if (ret != QLA_SUCCESS) {
  1133. ql_dbg(ql_dbg_taskm, vha, 0x802c,
  1134. "Bus Reset failed: Reset=%d "
  1135. "d_id=%x.\n", ret, fcport->d_id.b24);
  1136. }
  1137. }
  1138. }
  1139. if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
  1140. atomic_set(&vha->loop_state, LOOP_DOWN);
  1141. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  1142. qla2x00_mark_all_devices_lost(vha, 0);
  1143. ret = qla2x00_full_login_lip(vha);
  1144. if (ret != QLA_SUCCESS) {
  1145. ql_dbg(ql_dbg_taskm, vha, 0x802d,
  1146. "full_login_lip=%d.\n", ret);
  1147. }
  1148. }
  1149. if (ha->flags.enable_lip_reset) {
  1150. ret = qla2x00_lip_reset(vha);
  1151. if (ret != QLA_SUCCESS)
  1152. ql_dbg(ql_dbg_taskm, vha, 0x802e,
  1153. "lip_reset failed (%d).\n", ret);
  1154. }
  1155. /* Issue marker command only when we are going to start the I/O */
  1156. vha->marker_needed = 1;
  1157. return QLA_SUCCESS;
  1158. }
  1159. void
  1160. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  1161. {
  1162. int que, cnt;
  1163. unsigned long flags;
  1164. srb_t *sp;
  1165. struct qla_hw_data *ha = vha->hw;
  1166. struct req_que *req;
  1167. spin_lock_irqsave(&ha->hardware_lock, flags);
  1168. for (que = 0; que < ha->max_req_queues; que++) {
  1169. req = ha->req_q_map[que];
  1170. if (!req)
  1171. continue;
  1172. if (!req->outstanding_cmds)
  1173. continue;
  1174. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
  1175. sp = req->outstanding_cmds[cnt];
  1176. if (sp) {
  1177. req->outstanding_cmds[cnt] = NULL;
  1178. sp->done(vha, sp, res);
  1179. }
  1180. }
  1181. }
  1182. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1183. }
  1184. static int
  1185. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1186. {
  1187. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1188. if (!rport || fc_remote_port_chkready(rport))
  1189. return -ENXIO;
  1190. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1191. return 0;
  1192. }
  1193. static int
  1194. qla2xxx_slave_configure(struct scsi_device *sdev)
  1195. {
  1196. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1197. struct req_que *req = vha->req;
  1198. if (IS_T10_PI_CAPABLE(vha->hw))
  1199. blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
  1200. if (sdev->tagged_supported)
  1201. scsi_activate_tcq(sdev, req->max_q_depth);
  1202. else
  1203. scsi_deactivate_tcq(sdev, req->max_q_depth);
  1204. return 0;
  1205. }
  1206. static void
  1207. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1208. {
  1209. sdev->hostdata = NULL;
  1210. }
  1211. static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
  1212. {
  1213. fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
  1214. if (!scsi_track_queue_full(sdev, qdepth))
  1215. return;
  1216. ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
  1217. "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
  1218. sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
  1219. }
  1220. static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
  1221. {
  1222. fc_port_t *fcport = sdev->hostdata;
  1223. struct scsi_qla_host *vha = fcport->vha;
  1224. struct req_que *req = NULL;
  1225. req = vha->req;
  1226. if (!req)
  1227. return;
  1228. if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
  1229. return;
  1230. if (sdev->ordered_tags)
  1231. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
  1232. else
  1233. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
  1234. ql_dbg(ql_dbg_io, vha, 0x302a,
  1235. "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
  1236. sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
  1237. }
  1238. static int
  1239. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1240. {
  1241. switch (reason) {
  1242. case SCSI_QDEPTH_DEFAULT:
  1243. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1244. break;
  1245. case SCSI_QDEPTH_QFULL:
  1246. qla2x00_handle_queue_full(sdev, qdepth);
  1247. break;
  1248. case SCSI_QDEPTH_RAMP_UP:
  1249. qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
  1250. break;
  1251. default:
  1252. return -EOPNOTSUPP;
  1253. }
  1254. return sdev->queue_depth;
  1255. }
  1256. static int
  1257. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  1258. {
  1259. if (sdev->tagged_supported) {
  1260. scsi_set_tag_type(sdev, tag_type);
  1261. if (tag_type)
  1262. scsi_activate_tcq(sdev, sdev->queue_depth);
  1263. else
  1264. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1265. } else
  1266. tag_type = 0;
  1267. return tag_type;
  1268. }
  1269. static void
  1270. qla2x00_host_ramp_down_queuedepth(scsi_qla_host_t *vha)
  1271. {
  1272. scsi_qla_host_t *vp;
  1273. struct Scsi_Host *shost;
  1274. struct scsi_device *sdev;
  1275. struct qla_hw_data *ha = vha->hw;
  1276. unsigned long flags;
  1277. ha->host_last_rampdown_time = jiffies;
  1278. if (ha->cfg_lun_q_depth <= vha->host->cmd_per_lun)
  1279. return;
  1280. if ((ha->cfg_lun_q_depth / 2) < vha->host->cmd_per_lun)
  1281. ha->cfg_lun_q_depth = vha->host->cmd_per_lun;
  1282. else
  1283. ha->cfg_lun_q_depth = ha->cfg_lun_q_depth / 2;
  1284. /*
  1285. * Geometrically ramp down the queue depth for all devices on this
  1286. * adapter
  1287. */
  1288. spin_lock_irqsave(&ha->vport_slock, flags);
  1289. list_for_each_entry(vp, &ha->vp_list, list) {
  1290. shost = vp->host;
  1291. shost_for_each_device(sdev, shost) {
  1292. if (sdev->queue_depth > shost->cmd_per_lun) {
  1293. if (sdev->queue_depth < ha->cfg_lun_q_depth)
  1294. continue;
  1295. ql_dbg(ql_dbg_io, vp, 0x3031,
  1296. "%ld:%d:%d: Ramping down queue depth to %d",
  1297. vp->host_no, sdev->id, sdev->lun,
  1298. ha->cfg_lun_q_depth);
  1299. qla2x00_change_queue_depth(sdev,
  1300. ha->cfg_lun_q_depth, SCSI_QDEPTH_DEFAULT);
  1301. }
  1302. }
  1303. }
  1304. spin_unlock_irqrestore(&ha->vport_slock, flags);
  1305. return;
  1306. }
  1307. static void
  1308. qla2x00_host_ramp_up_queuedepth(scsi_qla_host_t *vha)
  1309. {
  1310. scsi_qla_host_t *vp;
  1311. struct Scsi_Host *shost;
  1312. struct scsi_device *sdev;
  1313. struct qla_hw_data *ha = vha->hw;
  1314. unsigned long flags;
  1315. ha->host_last_rampup_time = jiffies;
  1316. ha->cfg_lun_q_depth++;
  1317. /*
  1318. * Linearly ramp up the queue depth for all devices on this
  1319. * adapter
  1320. */
  1321. spin_lock_irqsave(&ha->vport_slock, flags);
  1322. list_for_each_entry(vp, &ha->vp_list, list) {
  1323. shost = vp->host;
  1324. shost_for_each_device(sdev, shost) {
  1325. if (sdev->queue_depth > ha->cfg_lun_q_depth)
  1326. continue;
  1327. qla2x00_change_queue_depth(sdev, ha->cfg_lun_q_depth,
  1328. SCSI_QDEPTH_RAMP_UP);
  1329. }
  1330. }
  1331. spin_unlock_irqrestore(&ha->vport_slock, flags);
  1332. return;
  1333. }
  1334. /**
  1335. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1336. * @ha: HA context
  1337. *
  1338. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1339. * supported addressing method.
  1340. */
  1341. static void
  1342. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1343. {
  1344. /* Assume a 32bit DMA mask. */
  1345. ha->flags.enable_64bit_addressing = 0;
  1346. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1347. /* Any upper-dword bits set? */
  1348. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1349. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1350. /* Ok, a 64bit DMA mask is applicable. */
  1351. ha->flags.enable_64bit_addressing = 1;
  1352. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1353. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1354. return;
  1355. }
  1356. }
  1357. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1358. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1359. }
  1360. static void
  1361. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1362. {
  1363. unsigned long flags = 0;
  1364. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1365. spin_lock_irqsave(&ha->hardware_lock, flags);
  1366. ha->interrupts_on = 1;
  1367. /* enable risc and host interrupts */
  1368. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1369. RD_REG_WORD(&reg->ictrl);
  1370. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1371. }
  1372. static void
  1373. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1374. {
  1375. unsigned long flags = 0;
  1376. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1377. spin_lock_irqsave(&ha->hardware_lock, flags);
  1378. ha->interrupts_on = 0;
  1379. /* disable risc and host interrupts */
  1380. WRT_REG_WORD(&reg->ictrl, 0);
  1381. RD_REG_WORD(&reg->ictrl);
  1382. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1383. }
  1384. static void
  1385. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1386. {
  1387. unsigned long flags = 0;
  1388. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1389. spin_lock_irqsave(&ha->hardware_lock, flags);
  1390. ha->interrupts_on = 1;
  1391. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1392. RD_REG_DWORD(&reg->ictrl);
  1393. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1394. }
  1395. static void
  1396. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1397. {
  1398. unsigned long flags = 0;
  1399. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1400. if (IS_NOPOLLING_TYPE(ha))
  1401. return;
  1402. spin_lock_irqsave(&ha->hardware_lock, flags);
  1403. ha->interrupts_on = 0;
  1404. WRT_REG_DWORD(&reg->ictrl, 0);
  1405. RD_REG_DWORD(&reg->ictrl);
  1406. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1407. }
  1408. static int
  1409. qla2x00_iospace_config(struct qla_hw_data *ha)
  1410. {
  1411. resource_size_t pio;
  1412. uint16_t msix;
  1413. int cpus;
  1414. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1415. QLA2XXX_DRIVER_NAME)) {
  1416. ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
  1417. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1418. pci_name(ha->pdev));
  1419. goto iospace_error_exit;
  1420. }
  1421. if (!(ha->bars & 1))
  1422. goto skip_pio;
  1423. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1424. pio = pci_resource_start(ha->pdev, 0);
  1425. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1426. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1427. ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
  1428. "Invalid pci I/O region size (%s).\n",
  1429. pci_name(ha->pdev));
  1430. pio = 0;
  1431. }
  1432. } else {
  1433. ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
  1434. "Region #0 no a PIO resource (%s).\n",
  1435. pci_name(ha->pdev));
  1436. pio = 0;
  1437. }
  1438. ha->pio_address = pio;
  1439. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
  1440. "PIO address=%llu.\n",
  1441. (unsigned long long)ha->pio_address);
  1442. skip_pio:
  1443. /* Use MMIO operations for all accesses. */
  1444. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1445. ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
  1446. "Region #1 not an MMIO resource (%s), aborting.\n",
  1447. pci_name(ha->pdev));
  1448. goto iospace_error_exit;
  1449. }
  1450. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1451. ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
  1452. "Invalid PCI mem region size (%s), aborting.\n",
  1453. pci_name(ha->pdev));
  1454. goto iospace_error_exit;
  1455. }
  1456. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1457. if (!ha->iobase) {
  1458. ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
  1459. "Cannot remap MMIO (%s), aborting.\n",
  1460. pci_name(ha->pdev));
  1461. goto iospace_error_exit;
  1462. }
  1463. /* Determine queue resources */
  1464. ha->max_req_queues = ha->max_rsp_queues = 1;
  1465. if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
  1466. (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
  1467. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1468. goto mqiobase_exit;
  1469. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1470. pci_resource_len(ha->pdev, 3));
  1471. if (ha->mqiobase) {
  1472. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
  1473. "MQIO Base=%p.\n", ha->mqiobase);
  1474. /* Read MSIX vector size of the board */
  1475. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1476. ha->msix_count = msix;
  1477. /* Max queues are bounded by available msix vectors */
  1478. /* queue 0 uses two msix vectors */
  1479. if (ql2xmultique_tag) {
  1480. cpus = num_online_cpus();
  1481. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1482. (cpus + 1) : (ha->msix_count - 1);
  1483. ha->max_req_queues = 2;
  1484. } else if (ql2xmaxqueues > 1) {
  1485. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1486. QLA_MQ_SIZE : ql2xmaxqueues;
  1487. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
  1488. "QoS mode set, max no of request queues:%d.\n",
  1489. ha->max_req_queues);
  1490. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
  1491. "QoS mode set, max no of request queues:%d.\n",
  1492. ha->max_req_queues);
  1493. }
  1494. ql_log_pci(ql_log_info, ha->pdev, 0x001a,
  1495. "MSI-X vector count: %d.\n", msix);
  1496. } else
  1497. ql_log_pci(ql_log_info, ha->pdev, 0x001b,
  1498. "BAR 3 not enabled.\n");
  1499. mqiobase_exit:
  1500. ha->msix_count = ha->max_rsp_queues + 1;
  1501. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
  1502. "MSIX Count:%d.\n", ha->msix_count);
  1503. return (0);
  1504. iospace_error_exit:
  1505. return (-ENOMEM);
  1506. }
  1507. static int
  1508. qla83xx_iospace_config(struct qla_hw_data *ha)
  1509. {
  1510. uint16_t msix;
  1511. int cpus;
  1512. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1513. QLA2XXX_DRIVER_NAME)) {
  1514. ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
  1515. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1516. pci_name(ha->pdev));
  1517. goto iospace_error_exit;
  1518. }
  1519. /* Use MMIO operations for all accesses. */
  1520. if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
  1521. ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
  1522. "Invalid pci I/O region size (%s).\n",
  1523. pci_name(ha->pdev));
  1524. goto iospace_error_exit;
  1525. }
  1526. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1527. ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
  1528. "Invalid PCI mem region size (%s), aborting\n",
  1529. pci_name(ha->pdev));
  1530. goto iospace_error_exit;
  1531. }
  1532. ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
  1533. if (!ha->iobase) {
  1534. ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
  1535. "Cannot remap MMIO (%s), aborting.\n",
  1536. pci_name(ha->pdev));
  1537. goto iospace_error_exit;
  1538. }
  1539. /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
  1540. /* 83XX 26XX always use MQ type access for queues
  1541. * - mbar 2, a.k.a region 4 */
  1542. ha->max_req_queues = ha->max_rsp_queues = 1;
  1543. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
  1544. pci_resource_len(ha->pdev, 4));
  1545. if (!ha->mqiobase) {
  1546. ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
  1547. "BAR2/region4 not enabled\n");
  1548. goto mqiobase_exit;
  1549. }
  1550. ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
  1551. pci_resource_len(ha->pdev, 2));
  1552. if (ha->msixbase) {
  1553. /* Read MSIX vector size of the board */
  1554. pci_read_config_word(ha->pdev,
  1555. QLA_83XX_PCI_MSIX_CONTROL, &msix);
  1556. ha->msix_count = msix;
  1557. /* Max queues are bounded by available msix vectors */
  1558. /* queue 0 uses two msix vectors */
  1559. if (ql2xmultique_tag) {
  1560. cpus = num_online_cpus();
  1561. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1562. (cpus + 1) : (ha->msix_count - 1);
  1563. ha->max_req_queues = 2;
  1564. } else if (ql2xmaxqueues > 1) {
  1565. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1566. QLA_MQ_SIZE : ql2xmaxqueues;
  1567. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
  1568. "QoS mode set, max no of request queues:%d.\n",
  1569. ha->max_req_queues);
  1570. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
  1571. "QoS mode set, max no of request queues:%d.\n",
  1572. ha->max_req_queues);
  1573. }
  1574. ql_log_pci(ql_log_info, ha->pdev, 0x011c,
  1575. "MSI-X vector count: %d.\n", msix);
  1576. } else
  1577. ql_log_pci(ql_log_info, ha->pdev, 0x011e,
  1578. "BAR 1 not enabled.\n");
  1579. mqiobase_exit:
  1580. ha->msix_count = ha->max_rsp_queues + 1;
  1581. qlt_83xx_iospace_config(ha);
  1582. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
  1583. "MSIX Count:%d.\n", ha->msix_count);
  1584. return 0;
  1585. iospace_error_exit:
  1586. return -ENOMEM;
  1587. }
  1588. static struct isp_operations qla2100_isp_ops = {
  1589. .pci_config = qla2100_pci_config,
  1590. .reset_chip = qla2x00_reset_chip,
  1591. .chip_diag = qla2x00_chip_diag,
  1592. .config_rings = qla2x00_config_rings,
  1593. .reset_adapter = qla2x00_reset_adapter,
  1594. .nvram_config = qla2x00_nvram_config,
  1595. .update_fw_options = qla2x00_update_fw_options,
  1596. .load_risc = qla2x00_load_risc,
  1597. .pci_info_str = qla2x00_pci_info_str,
  1598. .fw_version_str = qla2x00_fw_version_str,
  1599. .intr_handler = qla2100_intr_handler,
  1600. .enable_intrs = qla2x00_enable_intrs,
  1601. .disable_intrs = qla2x00_disable_intrs,
  1602. .abort_command = qla2x00_abort_command,
  1603. .target_reset = qla2x00_abort_target,
  1604. .lun_reset = qla2x00_lun_reset,
  1605. .fabric_login = qla2x00_login_fabric,
  1606. .fabric_logout = qla2x00_fabric_logout,
  1607. .calc_req_entries = qla2x00_calc_iocbs_32,
  1608. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1609. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1610. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1611. .read_nvram = qla2x00_read_nvram_data,
  1612. .write_nvram = qla2x00_write_nvram_data,
  1613. .fw_dump = qla2100_fw_dump,
  1614. .beacon_on = NULL,
  1615. .beacon_off = NULL,
  1616. .beacon_blink = NULL,
  1617. .read_optrom = qla2x00_read_optrom_data,
  1618. .write_optrom = qla2x00_write_optrom_data,
  1619. .get_flash_version = qla2x00_get_flash_version,
  1620. .start_scsi = qla2x00_start_scsi,
  1621. .abort_isp = qla2x00_abort_isp,
  1622. .iospace_config = qla2x00_iospace_config,
  1623. .initialize_adapter = qla2x00_initialize_adapter,
  1624. };
  1625. static struct isp_operations qla2300_isp_ops = {
  1626. .pci_config = qla2300_pci_config,
  1627. .reset_chip = qla2x00_reset_chip,
  1628. .chip_diag = qla2x00_chip_diag,
  1629. .config_rings = qla2x00_config_rings,
  1630. .reset_adapter = qla2x00_reset_adapter,
  1631. .nvram_config = qla2x00_nvram_config,
  1632. .update_fw_options = qla2x00_update_fw_options,
  1633. .load_risc = qla2x00_load_risc,
  1634. .pci_info_str = qla2x00_pci_info_str,
  1635. .fw_version_str = qla2x00_fw_version_str,
  1636. .intr_handler = qla2300_intr_handler,
  1637. .enable_intrs = qla2x00_enable_intrs,
  1638. .disable_intrs = qla2x00_disable_intrs,
  1639. .abort_command = qla2x00_abort_command,
  1640. .target_reset = qla2x00_abort_target,
  1641. .lun_reset = qla2x00_lun_reset,
  1642. .fabric_login = qla2x00_login_fabric,
  1643. .fabric_logout = qla2x00_fabric_logout,
  1644. .calc_req_entries = qla2x00_calc_iocbs_32,
  1645. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1646. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1647. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1648. .read_nvram = qla2x00_read_nvram_data,
  1649. .write_nvram = qla2x00_write_nvram_data,
  1650. .fw_dump = qla2300_fw_dump,
  1651. .beacon_on = qla2x00_beacon_on,
  1652. .beacon_off = qla2x00_beacon_off,
  1653. .beacon_blink = qla2x00_beacon_blink,
  1654. .read_optrom = qla2x00_read_optrom_data,
  1655. .write_optrom = qla2x00_write_optrom_data,
  1656. .get_flash_version = qla2x00_get_flash_version,
  1657. .start_scsi = qla2x00_start_scsi,
  1658. .abort_isp = qla2x00_abort_isp,
  1659. .iospace_config = qla2x00_iospace_config,
  1660. .initialize_adapter = qla2x00_initialize_adapter,
  1661. };
  1662. static struct isp_operations qla24xx_isp_ops = {
  1663. .pci_config = qla24xx_pci_config,
  1664. .reset_chip = qla24xx_reset_chip,
  1665. .chip_diag = qla24xx_chip_diag,
  1666. .config_rings = qla24xx_config_rings,
  1667. .reset_adapter = qla24xx_reset_adapter,
  1668. .nvram_config = qla24xx_nvram_config,
  1669. .update_fw_options = qla24xx_update_fw_options,
  1670. .load_risc = qla24xx_load_risc,
  1671. .pci_info_str = qla24xx_pci_info_str,
  1672. .fw_version_str = qla24xx_fw_version_str,
  1673. .intr_handler = qla24xx_intr_handler,
  1674. .enable_intrs = qla24xx_enable_intrs,
  1675. .disable_intrs = qla24xx_disable_intrs,
  1676. .abort_command = qla24xx_abort_command,
  1677. .target_reset = qla24xx_abort_target,
  1678. .lun_reset = qla24xx_lun_reset,
  1679. .fabric_login = qla24xx_login_fabric,
  1680. .fabric_logout = qla24xx_fabric_logout,
  1681. .calc_req_entries = NULL,
  1682. .build_iocbs = NULL,
  1683. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1684. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1685. .read_nvram = qla24xx_read_nvram_data,
  1686. .write_nvram = qla24xx_write_nvram_data,
  1687. .fw_dump = qla24xx_fw_dump,
  1688. .beacon_on = qla24xx_beacon_on,
  1689. .beacon_off = qla24xx_beacon_off,
  1690. .beacon_blink = qla24xx_beacon_blink,
  1691. .read_optrom = qla24xx_read_optrom_data,
  1692. .write_optrom = qla24xx_write_optrom_data,
  1693. .get_flash_version = qla24xx_get_flash_version,
  1694. .start_scsi = qla24xx_start_scsi,
  1695. .abort_isp = qla2x00_abort_isp,
  1696. .iospace_config = qla2x00_iospace_config,
  1697. .initialize_adapter = qla2x00_initialize_adapter,
  1698. };
  1699. static struct isp_operations qla25xx_isp_ops = {
  1700. .pci_config = qla25xx_pci_config,
  1701. .reset_chip = qla24xx_reset_chip,
  1702. .chip_diag = qla24xx_chip_diag,
  1703. .config_rings = qla24xx_config_rings,
  1704. .reset_adapter = qla24xx_reset_adapter,
  1705. .nvram_config = qla24xx_nvram_config,
  1706. .update_fw_options = qla24xx_update_fw_options,
  1707. .load_risc = qla24xx_load_risc,
  1708. .pci_info_str = qla24xx_pci_info_str,
  1709. .fw_version_str = qla24xx_fw_version_str,
  1710. .intr_handler = qla24xx_intr_handler,
  1711. .enable_intrs = qla24xx_enable_intrs,
  1712. .disable_intrs = qla24xx_disable_intrs,
  1713. .abort_command = qla24xx_abort_command,
  1714. .target_reset = qla24xx_abort_target,
  1715. .lun_reset = qla24xx_lun_reset,
  1716. .fabric_login = qla24xx_login_fabric,
  1717. .fabric_logout = qla24xx_fabric_logout,
  1718. .calc_req_entries = NULL,
  1719. .build_iocbs = NULL,
  1720. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1721. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1722. .read_nvram = qla25xx_read_nvram_data,
  1723. .write_nvram = qla25xx_write_nvram_data,
  1724. .fw_dump = qla25xx_fw_dump,
  1725. .beacon_on = qla24xx_beacon_on,
  1726. .beacon_off = qla24xx_beacon_off,
  1727. .beacon_blink = qla24xx_beacon_blink,
  1728. .read_optrom = qla25xx_read_optrom_data,
  1729. .write_optrom = qla24xx_write_optrom_data,
  1730. .get_flash_version = qla24xx_get_flash_version,
  1731. .start_scsi = qla24xx_dif_start_scsi,
  1732. .abort_isp = qla2x00_abort_isp,
  1733. .iospace_config = qla2x00_iospace_config,
  1734. .initialize_adapter = qla2x00_initialize_adapter,
  1735. };
  1736. static struct isp_operations qla81xx_isp_ops = {
  1737. .pci_config = qla25xx_pci_config,
  1738. .reset_chip = qla24xx_reset_chip,
  1739. .chip_diag = qla24xx_chip_diag,
  1740. .config_rings = qla24xx_config_rings,
  1741. .reset_adapter = qla24xx_reset_adapter,
  1742. .nvram_config = qla81xx_nvram_config,
  1743. .update_fw_options = qla81xx_update_fw_options,
  1744. .load_risc = qla81xx_load_risc,
  1745. .pci_info_str = qla24xx_pci_info_str,
  1746. .fw_version_str = qla24xx_fw_version_str,
  1747. .intr_handler = qla24xx_intr_handler,
  1748. .enable_intrs = qla24xx_enable_intrs,
  1749. .disable_intrs = qla24xx_disable_intrs,
  1750. .abort_command = qla24xx_abort_command,
  1751. .target_reset = qla24xx_abort_target,
  1752. .lun_reset = qla24xx_lun_reset,
  1753. .fabric_login = qla24xx_login_fabric,
  1754. .fabric_logout = qla24xx_fabric_logout,
  1755. .calc_req_entries = NULL,
  1756. .build_iocbs = NULL,
  1757. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1758. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1759. .read_nvram = NULL,
  1760. .write_nvram = NULL,
  1761. .fw_dump = qla81xx_fw_dump,
  1762. .beacon_on = qla24xx_beacon_on,
  1763. .beacon_off = qla24xx_beacon_off,
  1764. .beacon_blink = qla83xx_beacon_blink,
  1765. .read_optrom = qla25xx_read_optrom_data,
  1766. .write_optrom = qla24xx_write_optrom_data,
  1767. .get_flash_version = qla24xx_get_flash_version,
  1768. .start_scsi = qla24xx_dif_start_scsi,
  1769. .abort_isp = qla2x00_abort_isp,
  1770. .iospace_config = qla2x00_iospace_config,
  1771. .initialize_adapter = qla2x00_initialize_adapter,
  1772. };
  1773. static struct isp_operations qla82xx_isp_ops = {
  1774. .pci_config = qla82xx_pci_config,
  1775. .reset_chip = qla82xx_reset_chip,
  1776. .chip_diag = qla24xx_chip_diag,
  1777. .config_rings = qla82xx_config_rings,
  1778. .reset_adapter = qla24xx_reset_adapter,
  1779. .nvram_config = qla81xx_nvram_config,
  1780. .update_fw_options = qla24xx_update_fw_options,
  1781. .load_risc = qla82xx_load_risc,
  1782. .pci_info_str = qla24xx_pci_info_str,
  1783. .fw_version_str = qla24xx_fw_version_str,
  1784. .intr_handler = qla82xx_intr_handler,
  1785. .enable_intrs = qla82xx_enable_intrs,
  1786. .disable_intrs = qla82xx_disable_intrs,
  1787. .abort_command = qla24xx_abort_command,
  1788. .target_reset = qla24xx_abort_target,
  1789. .lun_reset = qla24xx_lun_reset,
  1790. .fabric_login = qla24xx_login_fabric,
  1791. .fabric_logout = qla24xx_fabric_logout,
  1792. .calc_req_entries = NULL,
  1793. .build_iocbs = NULL,
  1794. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1795. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1796. .read_nvram = qla24xx_read_nvram_data,
  1797. .write_nvram = qla24xx_write_nvram_data,
  1798. .fw_dump = qla24xx_fw_dump,
  1799. .beacon_on = qla82xx_beacon_on,
  1800. .beacon_off = qla82xx_beacon_off,
  1801. .beacon_blink = NULL,
  1802. .read_optrom = qla82xx_read_optrom_data,
  1803. .write_optrom = qla82xx_write_optrom_data,
  1804. .get_flash_version = qla82xx_get_flash_version,
  1805. .start_scsi = qla82xx_start_scsi,
  1806. .abort_isp = qla82xx_abort_isp,
  1807. .iospace_config = qla82xx_iospace_config,
  1808. .initialize_adapter = qla2x00_initialize_adapter,
  1809. };
  1810. static struct isp_operations qla8044_isp_ops = {
  1811. .pci_config = qla82xx_pci_config,
  1812. .reset_chip = qla82xx_reset_chip,
  1813. .chip_diag = qla24xx_chip_diag,
  1814. .config_rings = qla82xx_config_rings,
  1815. .reset_adapter = qla24xx_reset_adapter,
  1816. .nvram_config = qla81xx_nvram_config,
  1817. .update_fw_options = qla24xx_update_fw_options,
  1818. .load_risc = qla82xx_load_risc,
  1819. .pci_info_str = qla24xx_pci_info_str,
  1820. .fw_version_str = qla24xx_fw_version_str,
  1821. .intr_handler = qla8044_intr_handler,
  1822. .enable_intrs = qla82xx_enable_intrs,
  1823. .disable_intrs = qla82xx_disable_intrs,
  1824. .abort_command = qla24xx_abort_command,
  1825. .target_reset = qla24xx_abort_target,
  1826. .lun_reset = qla24xx_lun_reset,
  1827. .fabric_login = qla24xx_login_fabric,
  1828. .fabric_logout = qla24xx_fabric_logout,
  1829. .calc_req_entries = NULL,
  1830. .build_iocbs = NULL,
  1831. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1832. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1833. .read_nvram = NULL,
  1834. .write_nvram = NULL,
  1835. .fw_dump = qla24xx_fw_dump,
  1836. .beacon_on = qla82xx_beacon_on,
  1837. .beacon_off = qla82xx_beacon_off,
  1838. .beacon_blink = NULL,
  1839. .read_optrom = qla82xx_read_optrom_data,
  1840. .write_optrom = qla8044_write_optrom_data,
  1841. .get_flash_version = qla82xx_get_flash_version,
  1842. .start_scsi = qla82xx_start_scsi,
  1843. .abort_isp = qla8044_abort_isp,
  1844. .iospace_config = qla82xx_iospace_config,
  1845. .initialize_adapter = qla2x00_initialize_adapter,
  1846. };
  1847. static struct isp_operations qla83xx_isp_ops = {
  1848. .pci_config = qla25xx_pci_config,
  1849. .reset_chip = qla24xx_reset_chip,
  1850. .chip_diag = qla24xx_chip_diag,
  1851. .config_rings = qla24xx_config_rings,
  1852. .reset_adapter = qla24xx_reset_adapter,
  1853. .nvram_config = qla81xx_nvram_config,
  1854. .update_fw_options = qla81xx_update_fw_options,
  1855. .load_risc = qla81xx_load_risc,
  1856. .pci_info_str = qla24xx_pci_info_str,
  1857. .fw_version_str = qla24xx_fw_version_str,
  1858. .intr_handler = qla24xx_intr_handler,
  1859. .enable_intrs = qla24xx_enable_intrs,
  1860. .disable_intrs = qla24xx_disable_intrs,
  1861. .abort_command = qla24xx_abort_command,
  1862. .target_reset = qla24xx_abort_target,
  1863. .lun_reset = qla24xx_lun_reset,
  1864. .fabric_login = qla24xx_login_fabric,
  1865. .fabric_logout = qla24xx_fabric_logout,
  1866. .calc_req_entries = NULL,
  1867. .build_iocbs = NULL,
  1868. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1869. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1870. .read_nvram = NULL,
  1871. .write_nvram = NULL,
  1872. .fw_dump = qla83xx_fw_dump,
  1873. .beacon_on = qla24xx_beacon_on,
  1874. .beacon_off = qla24xx_beacon_off,
  1875. .beacon_blink = qla83xx_beacon_blink,
  1876. .read_optrom = qla25xx_read_optrom_data,
  1877. .write_optrom = qla24xx_write_optrom_data,
  1878. .get_flash_version = qla24xx_get_flash_version,
  1879. .start_scsi = qla24xx_dif_start_scsi,
  1880. .abort_isp = qla2x00_abort_isp,
  1881. .iospace_config = qla83xx_iospace_config,
  1882. .initialize_adapter = qla2x00_initialize_adapter,
  1883. };
  1884. static struct isp_operations qlafx00_isp_ops = {
  1885. .pci_config = qlafx00_pci_config,
  1886. .reset_chip = qlafx00_soft_reset,
  1887. .chip_diag = qlafx00_chip_diag,
  1888. .config_rings = qlafx00_config_rings,
  1889. .reset_adapter = qlafx00_soft_reset,
  1890. .nvram_config = NULL,
  1891. .update_fw_options = NULL,
  1892. .load_risc = NULL,
  1893. .pci_info_str = qlafx00_pci_info_str,
  1894. .fw_version_str = qlafx00_fw_version_str,
  1895. .intr_handler = qlafx00_intr_handler,
  1896. .enable_intrs = qlafx00_enable_intrs,
  1897. .disable_intrs = qlafx00_disable_intrs,
  1898. .abort_command = qlafx00_abort_command,
  1899. .target_reset = qlafx00_abort_target,
  1900. .lun_reset = qlafx00_lun_reset,
  1901. .fabric_login = NULL,
  1902. .fabric_logout = NULL,
  1903. .calc_req_entries = NULL,
  1904. .build_iocbs = NULL,
  1905. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1906. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1907. .read_nvram = qla24xx_read_nvram_data,
  1908. .write_nvram = qla24xx_write_nvram_data,
  1909. .fw_dump = NULL,
  1910. .beacon_on = qla24xx_beacon_on,
  1911. .beacon_off = qla24xx_beacon_off,
  1912. .beacon_blink = NULL,
  1913. .read_optrom = qla24xx_read_optrom_data,
  1914. .write_optrom = qla24xx_write_optrom_data,
  1915. .get_flash_version = qla24xx_get_flash_version,
  1916. .start_scsi = qlafx00_start_scsi,
  1917. .abort_isp = qlafx00_abort_isp,
  1918. .iospace_config = qlafx00_iospace_config,
  1919. .initialize_adapter = qlafx00_initialize_adapter,
  1920. };
  1921. static inline void
  1922. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1923. {
  1924. ha->device_type = DT_EXTENDED_IDS;
  1925. switch (ha->pdev->device) {
  1926. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1927. ha->device_type |= DT_ISP2100;
  1928. ha->device_type &= ~DT_EXTENDED_IDS;
  1929. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1930. break;
  1931. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1932. ha->device_type |= DT_ISP2200;
  1933. ha->device_type &= ~DT_EXTENDED_IDS;
  1934. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1935. break;
  1936. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1937. ha->device_type |= DT_ISP2300;
  1938. ha->device_type |= DT_ZIO_SUPPORTED;
  1939. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1940. break;
  1941. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1942. ha->device_type |= DT_ISP2312;
  1943. ha->device_type |= DT_ZIO_SUPPORTED;
  1944. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1945. break;
  1946. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1947. ha->device_type |= DT_ISP2322;
  1948. ha->device_type |= DT_ZIO_SUPPORTED;
  1949. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1950. ha->pdev->subsystem_device == 0x0170)
  1951. ha->device_type |= DT_OEM_001;
  1952. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1953. break;
  1954. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1955. ha->device_type |= DT_ISP6312;
  1956. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1957. break;
  1958. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1959. ha->device_type |= DT_ISP6322;
  1960. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1961. break;
  1962. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1963. ha->device_type |= DT_ISP2422;
  1964. ha->device_type |= DT_ZIO_SUPPORTED;
  1965. ha->device_type |= DT_FWI2;
  1966. ha->device_type |= DT_IIDMA;
  1967. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1968. break;
  1969. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1970. ha->device_type |= DT_ISP2432;
  1971. ha->device_type |= DT_ZIO_SUPPORTED;
  1972. ha->device_type |= DT_FWI2;
  1973. ha->device_type |= DT_IIDMA;
  1974. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1975. break;
  1976. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1977. ha->device_type |= DT_ISP8432;
  1978. ha->device_type |= DT_ZIO_SUPPORTED;
  1979. ha->device_type |= DT_FWI2;
  1980. ha->device_type |= DT_IIDMA;
  1981. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1982. break;
  1983. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1984. ha->device_type |= DT_ISP5422;
  1985. ha->device_type |= DT_FWI2;
  1986. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1987. break;
  1988. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1989. ha->device_type |= DT_ISP5432;
  1990. ha->device_type |= DT_FWI2;
  1991. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1992. break;
  1993. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1994. ha->device_type |= DT_ISP2532;
  1995. ha->device_type |= DT_ZIO_SUPPORTED;
  1996. ha->device_type |= DT_FWI2;
  1997. ha->device_type |= DT_IIDMA;
  1998. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1999. break;
  2000. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  2001. ha->device_type |= DT_ISP8001;
  2002. ha->device_type |= DT_ZIO_SUPPORTED;
  2003. ha->device_type |= DT_FWI2;
  2004. ha->device_type |= DT_IIDMA;
  2005. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2006. break;
  2007. case PCI_DEVICE_ID_QLOGIC_ISP8021:
  2008. ha->device_type |= DT_ISP8021;
  2009. ha->device_type |= DT_ZIO_SUPPORTED;
  2010. ha->device_type |= DT_FWI2;
  2011. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2012. /* Initialize 82XX ISP flags */
  2013. qla82xx_init_flags(ha);
  2014. break;
  2015. case PCI_DEVICE_ID_QLOGIC_ISP8044:
  2016. ha->device_type |= DT_ISP8044;
  2017. ha->device_type |= DT_ZIO_SUPPORTED;
  2018. ha->device_type |= DT_FWI2;
  2019. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2020. /* Initialize 82XX ISP flags */
  2021. qla82xx_init_flags(ha);
  2022. break;
  2023. case PCI_DEVICE_ID_QLOGIC_ISP2031:
  2024. ha->device_type |= DT_ISP2031;
  2025. ha->device_type |= DT_ZIO_SUPPORTED;
  2026. ha->device_type |= DT_FWI2;
  2027. ha->device_type |= DT_IIDMA;
  2028. ha->device_type |= DT_T10_PI;
  2029. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2030. break;
  2031. case PCI_DEVICE_ID_QLOGIC_ISP8031:
  2032. ha->device_type |= DT_ISP8031;
  2033. ha->device_type |= DT_ZIO_SUPPORTED;
  2034. ha->device_type |= DT_FWI2;
  2035. ha->device_type |= DT_IIDMA;
  2036. ha->device_type |= DT_T10_PI;
  2037. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2038. break;
  2039. case PCI_DEVICE_ID_QLOGIC_ISPF001:
  2040. ha->device_type |= DT_ISPFX00;
  2041. break;
  2042. }
  2043. if (IS_QLA82XX(ha))
  2044. ha->port_no = !(ha->portnum & 1);
  2045. else
  2046. /* Get adapter physical port no from interrupt pin register. */
  2047. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  2048. if (ha->port_no & 1)
  2049. ha->flags.port0 = 1;
  2050. else
  2051. ha->flags.port0 = 0;
  2052. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
  2053. "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
  2054. ha->device_type, ha->flags.port0, ha->fw_srisc_address);
  2055. }
  2056. static void
  2057. qla2xxx_scan_start(struct Scsi_Host *shost)
  2058. {
  2059. scsi_qla_host_t *vha = shost_priv(shost);
  2060. if (vha->hw->flags.running_gold_fw)
  2061. return;
  2062. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2063. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2064. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2065. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  2066. }
  2067. static int
  2068. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2069. {
  2070. scsi_qla_host_t *vha = shost_priv(shost);
  2071. if (!vha->host)
  2072. return 1;
  2073. if (time > vha->hw->loop_reset_delay * HZ)
  2074. return 1;
  2075. return atomic_read(&vha->loop_state) == LOOP_READY;
  2076. }
  2077. /*
  2078. * PCI driver interface
  2079. */
  2080. static int
  2081. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2082. {
  2083. int ret = -ENODEV;
  2084. struct Scsi_Host *host;
  2085. scsi_qla_host_t *base_vha = NULL;
  2086. struct qla_hw_data *ha;
  2087. char pci_info[30];
  2088. char fw_str[30], wq_name[30];
  2089. struct scsi_host_template *sht;
  2090. int bars, mem_only = 0;
  2091. uint16_t req_length = 0, rsp_length = 0;
  2092. struct req_que *req = NULL;
  2093. struct rsp_que *rsp = NULL;
  2094. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  2095. sht = &qla2xxx_driver_template;
  2096. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  2097. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  2098. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  2099. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  2100. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  2101. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  2102. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
  2103. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
  2104. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
  2105. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
  2106. pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
  2107. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044) {
  2108. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2109. mem_only = 1;
  2110. ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
  2111. "Mem only adapter.\n");
  2112. }
  2113. ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
  2114. "Bars=%d.\n", bars);
  2115. if (mem_only) {
  2116. if (pci_enable_device_mem(pdev))
  2117. goto probe_out;
  2118. } else {
  2119. if (pci_enable_device(pdev))
  2120. goto probe_out;
  2121. }
  2122. /* This may fail but that's ok */
  2123. pci_enable_pcie_error_reporting(pdev);
  2124. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  2125. if (!ha) {
  2126. ql_log_pci(ql_log_fatal, pdev, 0x0009,
  2127. "Unable to allocate memory for ha.\n");
  2128. goto probe_out;
  2129. }
  2130. ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
  2131. "Memory allocated for ha=%p.\n", ha);
  2132. ha->pdev = pdev;
  2133. ha->tgt.enable_class_2 = ql2xenableclass2;
  2134. /* Clear our data area */
  2135. ha->bars = bars;
  2136. ha->mem_only = mem_only;
  2137. spin_lock_init(&ha->hardware_lock);
  2138. spin_lock_init(&ha->vport_slock);
  2139. mutex_init(&ha->selflogin_lock);
  2140. /* Set ISP-type information. */
  2141. qla2x00_set_isp_flags(ha);
  2142. /* Set EEH reset type to fundamental if required by hba */
  2143. if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
  2144. IS_QLA83XX(ha))
  2145. pdev->needs_freset = 1;
  2146. ha->prev_topology = 0;
  2147. ha->init_cb_size = sizeof(init_cb_t);
  2148. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  2149. ha->optrom_size = OPTROM_SIZE_2300;
  2150. ha->cfg_lun_q_depth = ql2xmaxqdepth;
  2151. /* Assign ISP specific operations. */
  2152. if (IS_QLA2100(ha)) {
  2153. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2154. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  2155. req_length = REQUEST_ENTRY_CNT_2100;
  2156. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2157. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2158. ha->gid_list_info_size = 4;
  2159. ha->flash_conf_off = ~0;
  2160. ha->flash_data_off = ~0;
  2161. ha->nvram_conf_off = ~0;
  2162. ha->nvram_data_off = ~0;
  2163. ha->isp_ops = &qla2100_isp_ops;
  2164. } else if (IS_QLA2200(ha)) {
  2165. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2166. ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
  2167. req_length = REQUEST_ENTRY_CNT_2200;
  2168. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2169. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2170. ha->gid_list_info_size = 4;
  2171. ha->flash_conf_off = ~0;
  2172. ha->flash_data_off = ~0;
  2173. ha->nvram_conf_off = ~0;
  2174. ha->nvram_data_off = ~0;
  2175. ha->isp_ops = &qla2100_isp_ops;
  2176. } else if (IS_QLA23XX(ha)) {
  2177. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2178. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2179. req_length = REQUEST_ENTRY_CNT_2200;
  2180. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2181. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2182. ha->gid_list_info_size = 6;
  2183. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  2184. ha->optrom_size = OPTROM_SIZE_2322;
  2185. ha->flash_conf_off = ~0;
  2186. ha->flash_data_off = ~0;
  2187. ha->nvram_conf_off = ~0;
  2188. ha->nvram_data_off = ~0;
  2189. ha->isp_ops = &qla2300_isp_ops;
  2190. } else if (IS_QLA24XX_TYPE(ha)) {
  2191. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2192. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2193. req_length = REQUEST_ENTRY_CNT_24XX;
  2194. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2195. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2196. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2197. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2198. ha->gid_list_info_size = 8;
  2199. ha->optrom_size = OPTROM_SIZE_24XX;
  2200. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  2201. ha->isp_ops = &qla24xx_isp_ops;
  2202. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2203. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2204. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2205. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2206. } else if (IS_QLA25XX(ha)) {
  2207. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2208. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2209. req_length = REQUEST_ENTRY_CNT_24XX;
  2210. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2211. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2212. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2213. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2214. ha->gid_list_info_size = 8;
  2215. ha->optrom_size = OPTROM_SIZE_25XX;
  2216. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2217. ha->isp_ops = &qla25xx_isp_ops;
  2218. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2219. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2220. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2221. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2222. } else if (IS_QLA81XX(ha)) {
  2223. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2224. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2225. req_length = REQUEST_ENTRY_CNT_24XX;
  2226. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2227. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2228. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2229. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2230. ha->gid_list_info_size = 8;
  2231. ha->optrom_size = OPTROM_SIZE_81XX;
  2232. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2233. ha->isp_ops = &qla81xx_isp_ops;
  2234. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2235. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2236. ha->nvram_conf_off = ~0;
  2237. ha->nvram_data_off = ~0;
  2238. } else if (IS_QLA82XX(ha)) {
  2239. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2240. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2241. req_length = REQUEST_ENTRY_CNT_82XX;
  2242. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2243. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2244. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2245. ha->gid_list_info_size = 8;
  2246. ha->optrom_size = OPTROM_SIZE_82XX;
  2247. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2248. ha->isp_ops = &qla82xx_isp_ops;
  2249. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2250. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2251. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2252. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2253. } else if (IS_QLA8044(ha)) {
  2254. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2255. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2256. req_length = REQUEST_ENTRY_CNT_82XX;
  2257. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2258. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2259. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2260. ha->gid_list_info_size = 8;
  2261. ha->optrom_size = OPTROM_SIZE_83XX;
  2262. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2263. ha->isp_ops = &qla8044_isp_ops;
  2264. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2265. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2266. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2267. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2268. } else if (IS_QLA83XX(ha)) {
  2269. ha->portnum = PCI_FUNC(ha->pdev->devfn);
  2270. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2271. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2272. req_length = REQUEST_ENTRY_CNT_24XX;
  2273. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2274. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2275. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2276. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2277. ha->gid_list_info_size = 8;
  2278. ha->optrom_size = OPTROM_SIZE_83XX;
  2279. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2280. ha->isp_ops = &qla83xx_isp_ops;
  2281. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2282. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2283. ha->nvram_conf_off = ~0;
  2284. ha->nvram_data_off = ~0;
  2285. } else if (IS_QLAFX00(ha)) {
  2286. ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
  2287. ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
  2288. ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
  2289. req_length = REQUEST_ENTRY_CNT_FX00;
  2290. rsp_length = RESPONSE_ENTRY_CNT_FX00;
  2291. ha->init_cb_size = sizeof(struct init_cb_fx);
  2292. ha->isp_ops = &qlafx00_isp_ops;
  2293. ha->port_down_retry_count = 30; /* default value */
  2294. ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
  2295. ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
  2296. ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
  2297. ha->mr.fw_hbt_en = 1;
  2298. }
  2299. ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
  2300. "mbx_count=%d, req_length=%d, "
  2301. "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
  2302. "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
  2303. "max_fibre_devices=%d.\n",
  2304. ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
  2305. ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
  2306. ha->nvram_npiv_size, ha->max_fibre_devices);
  2307. ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
  2308. "isp_ops=%p, flash_conf_off=%d, "
  2309. "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
  2310. ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
  2311. ha->nvram_conf_off, ha->nvram_data_off);
  2312. /* Configure PCI I/O space */
  2313. ret = ha->isp_ops->iospace_config(ha);
  2314. if (ret)
  2315. goto iospace_config_failed;
  2316. ql_log_pci(ql_log_info, pdev, 0x001d,
  2317. "Found an ISP%04X irq %d iobase 0x%p.\n",
  2318. pdev->device, pdev->irq, ha->iobase);
  2319. mutex_init(&ha->vport_lock);
  2320. init_completion(&ha->mbx_cmd_comp);
  2321. complete(&ha->mbx_cmd_comp);
  2322. init_completion(&ha->mbx_intr_comp);
  2323. init_completion(&ha->dcbx_comp);
  2324. init_completion(&ha->lb_portup_comp);
  2325. set_bit(0, (unsigned long *) ha->vp_idx_map);
  2326. qla2x00_config_dma_addressing(ha);
  2327. ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
  2328. "64 Bit addressing is %s.\n",
  2329. ha->flags.enable_64bit_addressing ? "enable" :
  2330. "disable");
  2331. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  2332. if (!ret) {
  2333. ql_log_pci(ql_log_fatal, pdev, 0x0031,
  2334. "Failed to allocate memory for adapter, aborting.\n");
  2335. goto probe_hw_failed;
  2336. }
  2337. req->max_q_depth = MAX_Q_DEPTH;
  2338. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  2339. req->max_q_depth = ql2xmaxqdepth;
  2340. base_vha = qla2x00_create_host(sht, ha);
  2341. if (!base_vha) {
  2342. ret = -ENOMEM;
  2343. qla2x00_mem_free(ha);
  2344. qla2x00_free_req_que(ha, req);
  2345. qla2x00_free_rsp_que(ha, rsp);
  2346. goto probe_hw_failed;
  2347. }
  2348. pci_set_drvdata(pdev, base_vha);
  2349. host = base_vha->host;
  2350. base_vha->req = req;
  2351. if (IS_QLAFX00(ha))
  2352. host->can_queue = 1024;
  2353. else
  2354. host->can_queue = req->length + 128;
  2355. if (IS_QLA2XXX_MIDTYPE(ha))
  2356. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  2357. else
  2358. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  2359. base_vha->vp_idx;
  2360. /* Setup fcport template structure. */
  2361. ha->mr.fcport.vha = base_vha;
  2362. ha->mr.fcport.port_type = FCT_UNKNOWN;
  2363. ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
  2364. qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
  2365. ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
  2366. ha->mr.fcport.scan_state = 1;
  2367. /* Set the SG table size based on ISP type */
  2368. if (!IS_FWI2_CAPABLE(ha)) {
  2369. if (IS_QLA2100(ha))
  2370. host->sg_tablesize = 32;
  2371. } else {
  2372. if (!IS_QLA82XX(ha))
  2373. host->sg_tablesize = QLA_SG_ALL;
  2374. }
  2375. ql_dbg(ql_dbg_init, base_vha, 0x0032,
  2376. "can_queue=%d, req=%p, "
  2377. "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
  2378. host->can_queue, base_vha->req,
  2379. base_vha->mgmt_svr_loop_id, host->sg_tablesize);
  2380. host->max_id = ha->max_fibre_devices;
  2381. host->cmd_per_lun = 3;
  2382. host->unique_id = host->host_no;
  2383. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
  2384. host->max_cmd_len = 32;
  2385. else
  2386. host->max_cmd_len = MAX_CMDSZ;
  2387. host->max_channel = MAX_BUSES - 1;
  2388. host->max_lun = ql2xmaxlun;
  2389. host->transportt = qla2xxx_transport_template;
  2390. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  2391. ql_dbg(ql_dbg_init, base_vha, 0x0033,
  2392. "max_id=%d this_id=%d "
  2393. "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
  2394. "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
  2395. host->this_id, host->cmd_per_lun, host->unique_id,
  2396. host->max_cmd_len, host->max_channel, host->max_lun,
  2397. host->transportt, sht->vendor_id);
  2398. que_init:
  2399. /* Alloc arrays of request and response ring ptrs */
  2400. if (!qla2x00_alloc_queues(ha, req, rsp)) {
  2401. ql_log(ql_log_fatal, base_vha, 0x003d,
  2402. "Failed to allocate memory for queue pointers..."
  2403. "aborting.\n");
  2404. goto probe_init_failed;
  2405. }
  2406. qlt_probe_one_stage1(base_vha, ha);
  2407. /* Set up the irqs */
  2408. ret = qla2x00_request_irqs(ha, rsp);
  2409. if (ret)
  2410. goto probe_init_failed;
  2411. pci_save_state(pdev);
  2412. /* Assign back pointers */
  2413. rsp->req = req;
  2414. req->rsp = rsp;
  2415. if (IS_QLAFX00(ha)) {
  2416. ha->rsp_q_map[0] = rsp;
  2417. ha->req_q_map[0] = req;
  2418. set_bit(0, ha->req_qid_map);
  2419. set_bit(0, ha->rsp_qid_map);
  2420. }
  2421. /* FWI2-capable only. */
  2422. req->req_q_in = &ha->iobase->isp24.req_q_in;
  2423. req->req_q_out = &ha->iobase->isp24.req_q_out;
  2424. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  2425. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  2426. if (ha->mqenable || IS_QLA83XX(ha)) {
  2427. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  2428. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  2429. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  2430. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  2431. }
  2432. if (IS_QLAFX00(ha)) {
  2433. req->req_q_in = &ha->iobase->ispfx00.req_q_in;
  2434. req->req_q_out = &ha->iobase->ispfx00.req_q_out;
  2435. rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
  2436. rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
  2437. }
  2438. if (IS_P3P_TYPE(ha)) {
  2439. req->req_q_out = &ha->iobase->isp82.req_q_out[0];
  2440. rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
  2441. rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
  2442. }
  2443. ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
  2444. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2445. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2446. ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
  2447. "req->req_q_in=%p req->req_q_out=%p "
  2448. "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2449. req->req_q_in, req->req_q_out,
  2450. rsp->rsp_q_in, rsp->rsp_q_out);
  2451. ql_dbg(ql_dbg_init, base_vha, 0x003e,
  2452. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2453. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2454. ql_dbg(ql_dbg_init, base_vha, 0x003f,
  2455. "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2456. req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
  2457. if (ha->isp_ops->initialize_adapter(base_vha)) {
  2458. ql_log(ql_log_fatal, base_vha, 0x00d6,
  2459. "Failed to initialize adapter - Adapter flags %x.\n",
  2460. base_vha->device_flags);
  2461. if (IS_QLA82XX(ha)) {
  2462. qla82xx_idc_lock(ha);
  2463. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2464. QLA8XXX_DEV_FAILED);
  2465. qla82xx_idc_unlock(ha);
  2466. ql_log(ql_log_fatal, base_vha, 0x00d7,
  2467. "HW State: FAILED.\n");
  2468. } else if (IS_QLA8044(ha)) {
  2469. qla8044_idc_lock(ha);
  2470. qla8044_wr_direct(base_vha,
  2471. QLA8044_CRB_DEV_STATE_INDEX,
  2472. QLA8XXX_DEV_FAILED);
  2473. qla8044_idc_unlock(ha);
  2474. ql_log(ql_log_fatal, base_vha, 0x0150,
  2475. "HW State: FAILED.\n");
  2476. }
  2477. ret = -ENODEV;
  2478. goto probe_failed;
  2479. }
  2480. if (ha->mqenable) {
  2481. if (qla25xx_setup_mode(base_vha)) {
  2482. ql_log(ql_log_warn, base_vha, 0x00ec,
  2483. "Failed to create queues, falling back to single queue mode.\n");
  2484. goto que_init;
  2485. }
  2486. }
  2487. if (ha->flags.running_gold_fw)
  2488. goto skip_dpc;
  2489. /*
  2490. * Startup the kernel thread for this host adapter
  2491. */
  2492. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  2493. "%s_dpc", base_vha->host_str);
  2494. if (IS_ERR(ha->dpc_thread)) {
  2495. ql_log(ql_log_fatal, base_vha, 0x00ed,
  2496. "Failed to start DPC thread.\n");
  2497. ret = PTR_ERR(ha->dpc_thread);
  2498. goto probe_failed;
  2499. }
  2500. ql_dbg(ql_dbg_init, base_vha, 0x00ee,
  2501. "DPC thread started successfully.\n");
  2502. /*
  2503. * If we're not coming up in initiator mode, we might sit for
  2504. * a while without waking up the dpc thread, which leads to a
  2505. * stuck process warning. So just kick the dpc once here and
  2506. * let the kthread start (and go back to sleep in qla2x00_do_dpc).
  2507. */
  2508. qla2xxx_wake_dpc(base_vha);
  2509. if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
  2510. sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
  2511. ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
  2512. INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
  2513. sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
  2514. ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
  2515. INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
  2516. INIT_WORK(&ha->idc_state_handler,
  2517. qla83xx_idc_state_handler_work);
  2518. INIT_WORK(&ha->nic_core_unrecoverable,
  2519. qla83xx_nic_core_unrecoverable_work);
  2520. }
  2521. skip_dpc:
  2522. list_add_tail(&base_vha->list, &ha->vp_list);
  2523. base_vha->host->irq = ha->pdev->irq;
  2524. /* Initialized the timer */
  2525. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  2526. ql_dbg(ql_dbg_init, base_vha, 0x00ef,
  2527. "Started qla2x00_timer with "
  2528. "interval=%d.\n", WATCH_INTERVAL);
  2529. ql_dbg(ql_dbg_init, base_vha, 0x00f0,
  2530. "Detected hba at address=%p.\n",
  2531. ha);
  2532. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  2533. if (ha->fw_attributes & BIT_4) {
  2534. int prot = 0, guard;
  2535. base_vha->flags.difdix_supported = 1;
  2536. ql_dbg(ql_dbg_init, base_vha, 0x00f1,
  2537. "Registering for DIF/DIX type 1 and 3 protection.\n");
  2538. if (ql2xenabledif == 1)
  2539. prot = SHOST_DIX_TYPE0_PROTECTION;
  2540. scsi_host_set_prot(host,
  2541. prot | SHOST_DIF_TYPE1_PROTECTION
  2542. | SHOST_DIF_TYPE2_PROTECTION
  2543. | SHOST_DIF_TYPE3_PROTECTION
  2544. | SHOST_DIX_TYPE1_PROTECTION
  2545. | SHOST_DIX_TYPE2_PROTECTION
  2546. | SHOST_DIX_TYPE3_PROTECTION);
  2547. guard = SHOST_DIX_GUARD_CRC;
  2548. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  2549. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  2550. guard |= SHOST_DIX_GUARD_IP;
  2551. scsi_host_set_guard(host, guard);
  2552. } else
  2553. base_vha->flags.difdix_supported = 0;
  2554. }
  2555. ha->isp_ops->enable_intrs(ha);
  2556. if (IS_QLAFX00(ha)) {
  2557. ret = qlafx00_fx_disc(base_vha,
  2558. &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
  2559. host->sg_tablesize = (ha->mr.extended_io_enabled) ?
  2560. QLA_SG_ALL : 128;
  2561. }
  2562. ret = scsi_add_host(host, &pdev->dev);
  2563. if (ret)
  2564. goto probe_failed;
  2565. base_vha->flags.init_done = 1;
  2566. base_vha->flags.online = 1;
  2567. ql_dbg(ql_dbg_init, base_vha, 0x00f2,
  2568. "Init done and hba is online.\n");
  2569. if (qla_ini_mode_enabled(base_vha))
  2570. scsi_scan_host(host);
  2571. else
  2572. ql_dbg(ql_dbg_init, base_vha, 0x0122,
  2573. "skipping scsi_scan_host() for non-initiator port\n");
  2574. qla2x00_alloc_sysfs_attr(base_vha);
  2575. if (IS_QLAFX00(ha)) {
  2576. ret = qlafx00_fx_disc(base_vha,
  2577. &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
  2578. /* Register system information */
  2579. ret = qlafx00_fx_disc(base_vha,
  2580. &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
  2581. }
  2582. qla2x00_init_host_attr(base_vha);
  2583. qla2x00_dfs_setup(base_vha);
  2584. ql_log(ql_log_info, base_vha, 0x00fb,
  2585. "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
  2586. ql_log(ql_log_info, base_vha, 0x00fc,
  2587. "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
  2588. pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
  2589. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
  2590. base_vha->host_no,
  2591. ha->isp_ops->fw_version_str(base_vha, fw_str));
  2592. qlt_add_target(ha, base_vha);
  2593. return 0;
  2594. probe_init_failed:
  2595. qla2x00_free_req_que(ha, req);
  2596. ha->req_q_map[0] = NULL;
  2597. clear_bit(0, ha->req_qid_map);
  2598. qla2x00_free_rsp_que(ha, rsp);
  2599. ha->rsp_q_map[0] = NULL;
  2600. clear_bit(0, ha->rsp_qid_map);
  2601. ha->max_req_queues = ha->max_rsp_queues = 0;
  2602. probe_failed:
  2603. if (base_vha->timer_active)
  2604. qla2x00_stop_timer(base_vha);
  2605. base_vha->flags.online = 0;
  2606. if (ha->dpc_thread) {
  2607. struct task_struct *t = ha->dpc_thread;
  2608. ha->dpc_thread = NULL;
  2609. kthread_stop(t);
  2610. }
  2611. qla2x00_free_device(base_vha);
  2612. scsi_host_put(base_vha->host);
  2613. probe_hw_failed:
  2614. if (IS_QLA82XX(ha)) {
  2615. qla82xx_idc_lock(ha);
  2616. qla82xx_clear_drv_active(ha);
  2617. qla82xx_idc_unlock(ha);
  2618. }
  2619. if (IS_QLA8044(ha)) {
  2620. qla8044_idc_lock(ha);
  2621. qla8044_clear_drv_active(base_vha);
  2622. qla8044_idc_unlock(ha);
  2623. }
  2624. iospace_config_failed:
  2625. if (IS_P3P_TYPE(ha)) {
  2626. if (!ha->nx_pcibase)
  2627. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2628. if (!ql2xdbwr)
  2629. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2630. } else {
  2631. if (ha->iobase)
  2632. iounmap(ha->iobase);
  2633. if (ha->cregbase)
  2634. iounmap(ha->cregbase);
  2635. }
  2636. pci_release_selected_regions(ha->pdev, ha->bars);
  2637. kfree(ha);
  2638. ha = NULL;
  2639. probe_out:
  2640. pci_disable_device(pdev);
  2641. return ret;
  2642. }
  2643. static void
  2644. qla2x00_stop_dpc_thread(scsi_qla_host_t *vha)
  2645. {
  2646. struct qla_hw_data *ha = vha->hw;
  2647. struct task_struct *t = ha->dpc_thread;
  2648. if (ha->dpc_thread == NULL)
  2649. return;
  2650. /*
  2651. * qla2xxx_wake_dpc checks for ->dpc_thread
  2652. * so we need to zero it out.
  2653. */
  2654. ha->dpc_thread = NULL;
  2655. kthread_stop(t);
  2656. }
  2657. static void
  2658. qla2x00_shutdown(struct pci_dev *pdev)
  2659. {
  2660. scsi_qla_host_t *vha;
  2661. struct qla_hw_data *ha;
  2662. if (!atomic_read(&pdev->enable_cnt))
  2663. return;
  2664. vha = pci_get_drvdata(pdev);
  2665. ha = vha->hw;
  2666. /* Notify ISPFX00 firmware */
  2667. if (IS_QLAFX00(ha))
  2668. qlafx00_driver_shutdown(vha, 20);
  2669. /* Turn-off FCE trace */
  2670. if (ha->flags.fce_enabled) {
  2671. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2672. ha->flags.fce_enabled = 0;
  2673. }
  2674. /* Turn-off EFT trace */
  2675. if (ha->eft)
  2676. qla2x00_disable_eft_trace(vha);
  2677. /* Stop currently executing firmware. */
  2678. qla2x00_try_to_stop_firmware(vha);
  2679. /* Turn adapter off line */
  2680. vha->flags.online = 0;
  2681. /* turn-off interrupts on the card */
  2682. if (ha->interrupts_on) {
  2683. vha->flags.init_done = 0;
  2684. ha->isp_ops->disable_intrs(ha);
  2685. }
  2686. qla2x00_free_irqs(vha);
  2687. qla2x00_free_fw_dump(ha);
  2688. }
  2689. static void
  2690. qla2x00_remove_one(struct pci_dev *pdev)
  2691. {
  2692. scsi_qla_host_t *base_vha, *vha;
  2693. struct qla_hw_data *ha;
  2694. unsigned long flags;
  2695. /*
  2696. * If the PCI device is disabled that means that probe failed and any
  2697. * resources should be have cleaned up on probe exit.
  2698. */
  2699. if (!atomic_read(&pdev->enable_cnt))
  2700. return;
  2701. base_vha = pci_get_drvdata(pdev);
  2702. ha = base_vha->hw;
  2703. ha->flags.host_shutting_down = 1;
  2704. set_bit(UNLOADING, &base_vha->dpc_flags);
  2705. if (IS_QLAFX00(ha))
  2706. qlafx00_driver_shutdown(base_vha, 20);
  2707. mutex_lock(&ha->vport_lock);
  2708. while (ha->cur_vport_count) {
  2709. spin_lock_irqsave(&ha->vport_slock, flags);
  2710. BUG_ON(base_vha->list.next == &ha->vp_list);
  2711. /* This assumes first entry in ha->vp_list is always base vha */
  2712. vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
  2713. scsi_host_get(vha->host);
  2714. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2715. mutex_unlock(&ha->vport_lock);
  2716. fc_vport_terminate(vha->fc_vport);
  2717. scsi_host_put(vha->host);
  2718. mutex_lock(&ha->vport_lock);
  2719. }
  2720. mutex_unlock(&ha->vport_lock);
  2721. if (IS_QLA8031(ha)) {
  2722. ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
  2723. "Clearing fcoe driver presence.\n");
  2724. if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
  2725. ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
  2726. "Error while clearing DRV-Presence.\n");
  2727. }
  2728. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2729. qla2x00_dfs_remove(base_vha);
  2730. qla84xx_put_chip(base_vha);
  2731. /* Disable timer */
  2732. if (base_vha->timer_active)
  2733. qla2x00_stop_timer(base_vha);
  2734. base_vha->flags.online = 0;
  2735. /* Flush the work queue and remove it */
  2736. if (ha->wq) {
  2737. flush_workqueue(ha->wq);
  2738. destroy_workqueue(ha->wq);
  2739. ha->wq = NULL;
  2740. }
  2741. /* Cancel all work and destroy DPC workqueues */
  2742. if (ha->dpc_lp_wq) {
  2743. cancel_work_sync(&ha->idc_aen);
  2744. destroy_workqueue(ha->dpc_lp_wq);
  2745. ha->dpc_lp_wq = NULL;
  2746. }
  2747. if (ha->dpc_hp_wq) {
  2748. cancel_work_sync(&ha->nic_core_reset);
  2749. cancel_work_sync(&ha->idc_state_handler);
  2750. cancel_work_sync(&ha->nic_core_unrecoverable);
  2751. destroy_workqueue(ha->dpc_hp_wq);
  2752. ha->dpc_hp_wq = NULL;
  2753. }
  2754. /* Kill the kernel thread for this host */
  2755. if (ha->dpc_thread) {
  2756. struct task_struct *t = ha->dpc_thread;
  2757. /*
  2758. * qla2xxx_wake_dpc checks for ->dpc_thread
  2759. * so we need to zero it out.
  2760. */
  2761. ha->dpc_thread = NULL;
  2762. kthread_stop(t);
  2763. }
  2764. qlt_remove_target(ha, base_vha);
  2765. qla2x00_free_sysfs_attr(base_vha);
  2766. fc_remove_host(base_vha->host);
  2767. scsi_remove_host(base_vha->host);
  2768. qla2x00_free_device(base_vha);
  2769. scsi_host_put(base_vha->host);
  2770. if (IS_QLA8044(ha)) {
  2771. qla8044_idc_lock(ha);
  2772. qla8044_clear_drv_active(base_vha);
  2773. qla8044_idc_unlock(ha);
  2774. }
  2775. if (IS_QLA82XX(ha)) {
  2776. qla82xx_idc_lock(ha);
  2777. qla82xx_clear_drv_active(ha);
  2778. qla82xx_idc_unlock(ha);
  2779. iounmap((device_reg_t __iomem *)ha->nx_pcibase);
  2780. if (!ql2xdbwr)
  2781. iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
  2782. } else {
  2783. if (ha->iobase)
  2784. iounmap(ha->iobase);
  2785. if (ha->cregbase)
  2786. iounmap(ha->cregbase);
  2787. if (ha->mqiobase)
  2788. iounmap(ha->mqiobase);
  2789. if (IS_QLA83XX(ha) && ha->msixbase)
  2790. iounmap(ha->msixbase);
  2791. }
  2792. pci_release_selected_regions(ha->pdev, ha->bars);
  2793. kfree(ha);
  2794. ha = NULL;
  2795. pci_disable_pcie_error_reporting(pdev);
  2796. pci_disable_device(pdev);
  2797. pci_set_drvdata(pdev, NULL);
  2798. }
  2799. static void
  2800. qla2x00_free_device(scsi_qla_host_t *vha)
  2801. {
  2802. struct qla_hw_data *ha = vha->hw;
  2803. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2804. /* Disable timer */
  2805. if (vha->timer_active)
  2806. qla2x00_stop_timer(vha);
  2807. qla2x00_stop_dpc_thread(vha);
  2808. qla25xx_delete_queues(vha);
  2809. if (ha->flags.fce_enabled)
  2810. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2811. if (ha->eft)
  2812. qla2x00_disable_eft_trace(vha);
  2813. /* Stop currently executing firmware. */
  2814. qla2x00_try_to_stop_firmware(vha);
  2815. vha->flags.online = 0;
  2816. /* turn-off interrupts on the card */
  2817. if (ha->interrupts_on) {
  2818. vha->flags.init_done = 0;
  2819. ha->isp_ops->disable_intrs(ha);
  2820. }
  2821. qla2x00_free_irqs(vha);
  2822. qla2x00_free_fcports(vha);
  2823. qla2x00_mem_free(ha);
  2824. qla82xx_md_free(vha);
  2825. qla2x00_free_queues(ha);
  2826. }
  2827. void qla2x00_free_fcports(struct scsi_qla_host *vha)
  2828. {
  2829. fc_port_t *fcport, *tfcport;
  2830. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  2831. list_del(&fcport->list);
  2832. qla2x00_clear_loop_id(fcport);
  2833. kfree(fcport);
  2834. fcport = NULL;
  2835. }
  2836. }
  2837. static inline void
  2838. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  2839. int defer)
  2840. {
  2841. struct fc_rport *rport;
  2842. scsi_qla_host_t *base_vha;
  2843. unsigned long flags;
  2844. if (!fcport->rport)
  2845. return;
  2846. rport = fcport->rport;
  2847. if (defer) {
  2848. base_vha = pci_get_drvdata(vha->hw->pdev);
  2849. spin_lock_irqsave(vha->host->host_lock, flags);
  2850. fcport->drport = rport;
  2851. spin_unlock_irqrestore(vha->host->host_lock, flags);
  2852. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2853. qla2xxx_wake_dpc(base_vha);
  2854. } else {
  2855. fc_remote_port_delete(rport);
  2856. qlt_fc_port_deleted(vha, fcport);
  2857. }
  2858. }
  2859. /*
  2860. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  2861. *
  2862. * Input: ha = adapter block pointer. fcport = port structure pointer.
  2863. *
  2864. * Return: None.
  2865. *
  2866. * Context:
  2867. */
  2868. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  2869. int do_login, int defer)
  2870. {
  2871. if (IS_QLAFX00(vha->hw)) {
  2872. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2873. qla2x00_schedule_rport_del(vha, fcport, defer);
  2874. return;
  2875. }
  2876. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2877. vha->vp_idx == fcport->vha->vp_idx) {
  2878. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2879. qla2x00_schedule_rport_del(vha, fcport, defer);
  2880. }
  2881. /*
  2882. * We may need to retry the login, so don't change the state of the
  2883. * port but do the retries.
  2884. */
  2885. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  2886. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2887. if (!do_login)
  2888. return;
  2889. if (fcport->login_retry == 0) {
  2890. fcport->login_retry = vha->hw->login_retry_count;
  2891. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2892. ql_dbg(ql_dbg_disc, vha, 0x2067,
  2893. "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
  2894. fcport->port_name, fcport->loop_id, fcport->login_retry);
  2895. }
  2896. }
  2897. /*
  2898. * qla2x00_mark_all_devices_lost
  2899. * Updates fcport state when device goes offline.
  2900. *
  2901. * Input:
  2902. * ha = adapter block pointer.
  2903. * fcport = port structure pointer.
  2904. *
  2905. * Return:
  2906. * None.
  2907. *
  2908. * Context:
  2909. */
  2910. void
  2911. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  2912. {
  2913. fc_port_t *fcport;
  2914. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2915. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
  2916. continue;
  2917. /*
  2918. * No point in marking the device as lost, if the device is
  2919. * already DEAD.
  2920. */
  2921. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  2922. continue;
  2923. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  2924. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2925. if (defer)
  2926. qla2x00_schedule_rport_del(vha, fcport, defer);
  2927. else if (vha->vp_idx == fcport->vha->vp_idx)
  2928. qla2x00_schedule_rport_del(vha, fcport, defer);
  2929. }
  2930. }
  2931. }
  2932. /*
  2933. * qla2x00_mem_alloc
  2934. * Allocates adapter memory.
  2935. *
  2936. * Returns:
  2937. * 0 = success.
  2938. * !0 = failure.
  2939. */
  2940. static int
  2941. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  2942. struct req_que **req, struct rsp_que **rsp)
  2943. {
  2944. char name[16];
  2945. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  2946. &ha->init_cb_dma, GFP_KERNEL);
  2947. if (!ha->init_cb)
  2948. goto fail;
  2949. if (qlt_mem_alloc(ha) < 0)
  2950. goto fail_free_init_cb;
  2951. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
  2952. qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
  2953. if (!ha->gid_list)
  2954. goto fail_free_tgt_mem;
  2955. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  2956. if (!ha->srb_mempool)
  2957. goto fail_free_gid_list;
  2958. if (IS_P3P_TYPE(ha)) {
  2959. /* Allocate cache for CT6 Ctx. */
  2960. if (!ctx_cachep) {
  2961. ctx_cachep = kmem_cache_create("qla2xxx_ctx",
  2962. sizeof(struct ct6_dsd), 0,
  2963. SLAB_HWCACHE_ALIGN, NULL);
  2964. if (!ctx_cachep)
  2965. goto fail_free_gid_list;
  2966. }
  2967. ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
  2968. ctx_cachep);
  2969. if (!ha->ctx_mempool)
  2970. goto fail_free_srb_mempool;
  2971. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
  2972. "ctx_cachep=%p ctx_mempool=%p.\n",
  2973. ctx_cachep, ha->ctx_mempool);
  2974. }
  2975. /* Get memory for cached NVRAM */
  2976. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  2977. if (!ha->nvram)
  2978. goto fail_free_ctx_mempool;
  2979. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  2980. ha->pdev->device);
  2981. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2982. DMA_POOL_SIZE, 8, 0);
  2983. if (!ha->s_dma_pool)
  2984. goto fail_free_nvram;
  2985. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
  2986. "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
  2987. ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
  2988. if (IS_P3P_TYPE(ha) || ql2xenabledif) {
  2989. ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2990. DSD_LIST_DMA_POOL_SIZE, 8, 0);
  2991. if (!ha->dl_dma_pool) {
  2992. ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
  2993. "Failed to allocate memory for dl_dma_pool.\n");
  2994. goto fail_s_dma_pool;
  2995. }
  2996. ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  2997. FCP_CMND_DMA_POOL_SIZE, 8, 0);
  2998. if (!ha->fcp_cmnd_dma_pool) {
  2999. ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
  3000. "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
  3001. goto fail_dl_dma_pool;
  3002. }
  3003. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
  3004. "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
  3005. ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
  3006. }
  3007. /* Allocate memory for SNS commands */
  3008. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  3009. /* Get consistent memory allocated for SNS commands */
  3010. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  3011. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  3012. if (!ha->sns_cmd)
  3013. goto fail_dma_pool;
  3014. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
  3015. "sns_cmd: %p.\n", ha->sns_cmd);
  3016. } else {
  3017. /* Get consistent memory allocated for MS IOCB */
  3018. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3019. &ha->ms_iocb_dma);
  3020. if (!ha->ms_iocb)
  3021. goto fail_dma_pool;
  3022. /* Get consistent memory allocated for CT SNS commands */
  3023. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  3024. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  3025. if (!ha->ct_sns)
  3026. goto fail_free_ms_iocb;
  3027. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
  3028. "ms_iocb=%p ct_sns=%p.\n",
  3029. ha->ms_iocb, ha->ct_sns);
  3030. }
  3031. /* Allocate memory for request ring */
  3032. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  3033. if (!*req) {
  3034. ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
  3035. "Failed to allocate memory for req.\n");
  3036. goto fail_req;
  3037. }
  3038. (*req)->length = req_len;
  3039. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3040. ((*req)->length + 1) * sizeof(request_t),
  3041. &(*req)->dma, GFP_KERNEL);
  3042. if (!(*req)->ring) {
  3043. ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
  3044. "Failed to allocate memory for req_ring.\n");
  3045. goto fail_req_ring;
  3046. }
  3047. /* Allocate memory for response ring */
  3048. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  3049. if (!*rsp) {
  3050. ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
  3051. "Failed to allocate memory for rsp.\n");
  3052. goto fail_rsp;
  3053. }
  3054. (*rsp)->hw = ha;
  3055. (*rsp)->length = rsp_len;
  3056. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3057. ((*rsp)->length + 1) * sizeof(response_t),
  3058. &(*rsp)->dma, GFP_KERNEL);
  3059. if (!(*rsp)->ring) {
  3060. ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
  3061. "Failed to allocate memory for rsp_ring.\n");
  3062. goto fail_rsp_ring;
  3063. }
  3064. (*req)->rsp = *rsp;
  3065. (*rsp)->req = *req;
  3066. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
  3067. "req=%p req->length=%d req->ring=%p rsp=%p "
  3068. "rsp->length=%d rsp->ring=%p.\n",
  3069. *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
  3070. (*rsp)->ring);
  3071. /* Allocate memory for NVRAM data for vports */
  3072. if (ha->nvram_npiv_size) {
  3073. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  3074. ha->nvram_npiv_size, GFP_KERNEL);
  3075. if (!ha->npiv_info) {
  3076. ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
  3077. "Failed to allocate memory for npiv_info.\n");
  3078. goto fail_npiv_info;
  3079. }
  3080. } else
  3081. ha->npiv_info = NULL;
  3082. /* Get consistent memory allocated for EX-INIT-CB. */
  3083. if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) {
  3084. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3085. &ha->ex_init_cb_dma);
  3086. if (!ha->ex_init_cb)
  3087. goto fail_ex_init_cb;
  3088. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
  3089. "ex_init_cb=%p.\n", ha->ex_init_cb);
  3090. }
  3091. INIT_LIST_HEAD(&ha->gbl_dsd_list);
  3092. /* Get consistent memory allocated for Async Port-Database. */
  3093. if (!IS_FWI2_CAPABLE(ha)) {
  3094. ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3095. &ha->async_pd_dma);
  3096. if (!ha->async_pd)
  3097. goto fail_async_pd;
  3098. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
  3099. "async_pd=%p.\n", ha->async_pd);
  3100. }
  3101. INIT_LIST_HEAD(&ha->vp_list);
  3102. /* Allocate memory for our loop_id bitmap */
  3103. ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
  3104. GFP_KERNEL);
  3105. if (!ha->loop_id_map)
  3106. goto fail_async_pd;
  3107. else {
  3108. qla2x00_set_reserved_loop_ids(ha);
  3109. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
  3110. "loop_id_map=%p. \n", ha->loop_id_map);
  3111. }
  3112. return 1;
  3113. fail_async_pd:
  3114. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  3115. fail_ex_init_cb:
  3116. kfree(ha->npiv_info);
  3117. fail_npiv_info:
  3118. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  3119. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  3120. (*rsp)->ring = NULL;
  3121. (*rsp)->dma = 0;
  3122. fail_rsp_ring:
  3123. kfree(*rsp);
  3124. fail_rsp:
  3125. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  3126. sizeof(request_t), (*req)->ring, (*req)->dma);
  3127. (*req)->ring = NULL;
  3128. (*req)->dma = 0;
  3129. fail_req_ring:
  3130. kfree(*req);
  3131. fail_req:
  3132. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3133. ha->ct_sns, ha->ct_sns_dma);
  3134. ha->ct_sns = NULL;
  3135. ha->ct_sns_dma = 0;
  3136. fail_free_ms_iocb:
  3137. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3138. ha->ms_iocb = NULL;
  3139. ha->ms_iocb_dma = 0;
  3140. fail_dma_pool:
  3141. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3142. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3143. ha->fcp_cmnd_dma_pool = NULL;
  3144. }
  3145. fail_dl_dma_pool:
  3146. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3147. dma_pool_destroy(ha->dl_dma_pool);
  3148. ha->dl_dma_pool = NULL;
  3149. }
  3150. fail_s_dma_pool:
  3151. dma_pool_destroy(ha->s_dma_pool);
  3152. ha->s_dma_pool = NULL;
  3153. fail_free_nvram:
  3154. kfree(ha->nvram);
  3155. ha->nvram = NULL;
  3156. fail_free_ctx_mempool:
  3157. mempool_destroy(ha->ctx_mempool);
  3158. ha->ctx_mempool = NULL;
  3159. fail_free_srb_mempool:
  3160. mempool_destroy(ha->srb_mempool);
  3161. ha->srb_mempool = NULL;
  3162. fail_free_gid_list:
  3163. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3164. ha->gid_list,
  3165. ha->gid_list_dma);
  3166. ha->gid_list = NULL;
  3167. ha->gid_list_dma = 0;
  3168. fail_free_tgt_mem:
  3169. qlt_mem_free(ha);
  3170. fail_free_init_cb:
  3171. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  3172. ha->init_cb_dma);
  3173. ha->init_cb = NULL;
  3174. ha->init_cb_dma = 0;
  3175. fail:
  3176. ql_log(ql_log_fatal, NULL, 0x0030,
  3177. "Memory allocation failure.\n");
  3178. return -ENOMEM;
  3179. }
  3180. /*
  3181. * qla2x00_free_fw_dump
  3182. * Frees fw dump stuff.
  3183. *
  3184. * Input:
  3185. * ha = adapter block pointer
  3186. */
  3187. static void
  3188. qla2x00_free_fw_dump(struct qla_hw_data *ha)
  3189. {
  3190. if (ha->fce)
  3191. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  3192. ha->fce_dma);
  3193. if (ha->fw_dump) {
  3194. if (ha->eft)
  3195. dma_free_coherent(&ha->pdev->dev,
  3196. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  3197. vfree(ha->fw_dump);
  3198. }
  3199. ha->fce = NULL;
  3200. ha->fce_dma = 0;
  3201. ha->eft = NULL;
  3202. ha->eft_dma = 0;
  3203. ha->fw_dump = NULL;
  3204. ha->fw_dumped = 0;
  3205. ha->fw_dump_reading = 0;
  3206. }
  3207. /*
  3208. * qla2x00_mem_free
  3209. * Frees all adapter allocated memory.
  3210. *
  3211. * Input:
  3212. * ha = adapter block pointer.
  3213. */
  3214. static void
  3215. qla2x00_mem_free(struct qla_hw_data *ha)
  3216. {
  3217. qla2x00_free_fw_dump(ha);
  3218. if (ha->mctp_dump)
  3219. dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
  3220. ha->mctp_dump_dma);
  3221. if (ha->srb_mempool)
  3222. mempool_destroy(ha->srb_mempool);
  3223. if (ha->dcbx_tlv)
  3224. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  3225. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  3226. if (ha->xgmac_data)
  3227. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  3228. ha->xgmac_data, ha->xgmac_data_dma);
  3229. if (ha->sns_cmd)
  3230. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  3231. ha->sns_cmd, ha->sns_cmd_dma);
  3232. if (ha->ct_sns)
  3233. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3234. ha->ct_sns, ha->ct_sns_dma);
  3235. if (ha->sfp_data)
  3236. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  3237. if (ha->ms_iocb)
  3238. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3239. if (ha->ex_init_cb)
  3240. dma_pool_free(ha->s_dma_pool,
  3241. ha->ex_init_cb, ha->ex_init_cb_dma);
  3242. if (ha->async_pd)
  3243. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  3244. if (ha->s_dma_pool)
  3245. dma_pool_destroy(ha->s_dma_pool);
  3246. if (ha->gid_list)
  3247. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3248. ha->gid_list, ha->gid_list_dma);
  3249. if (IS_QLA82XX(ha)) {
  3250. if (!list_empty(&ha->gbl_dsd_list)) {
  3251. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  3252. /* clean up allocated prev pool */
  3253. list_for_each_entry_safe(dsd_ptr,
  3254. tdsd_ptr, &ha->gbl_dsd_list, list) {
  3255. dma_pool_free(ha->dl_dma_pool,
  3256. dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
  3257. list_del(&dsd_ptr->list);
  3258. kfree(dsd_ptr);
  3259. }
  3260. }
  3261. }
  3262. if (ha->dl_dma_pool)
  3263. dma_pool_destroy(ha->dl_dma_pool);
  3264. if (ha->fcp_cmnd_dma_pool)
  3265. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3266. if (ha->ctx_mempool)
  3267. mempool_destroy(ha->ctx_mempool);
  3268. qlt_mem_free(ha);
  3269. if (ha->init_cb)
  3270. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  3271. ha->init_cb, ha->init_cb_dma);
  3272. vfree(ha->optrom_buffer);
  3273. kfree(ha->nvram);
  3274. kfree(ha->npiv_info);
  3275. kfree(ha->swl);
  3276. kfree(ha->loop_id_map);
  3277. ha->srb_mempool = NULL;
  3278. ha->ctx_mempool = NULL;
  3279. ha->sns_cmd = NULL;
  3280. ha->sns_cmd_dma = 0;
  3281. ha->ct_sns = NULL;
  3282. ha->ct_sns_dma = 0;
  3283. ha->ms_iocb = NULL;
  3284. ha->ms_iocb_dma = 0;
  3285. ha->init_cb = NULL;
  3286. ha->init_cb_dma = 0;
  3287. ha->ex_init_cb = NULL;
  3288. ha->ex_init_cb_dma = 0;
  3289. ha->async_pd = NULL;
  3290. ha->async_pd_dma = 0;
  3291. ha->s_dma_pool = NULL;
  3292. ha->dl_dma_pool = NULL;
  3293. ha->fcp_cmnd_dma_pool = NULL;
  3294. ha->gid_list = NULL;
  3295. ha->gid_list_dma = 0;
  3296. ha->tgt.atio_ring = NULL;
  3297. ha->tgt.atio_dma = 0;
  3298. ha->tgt.tgt_vp_map = NULL;
  3299. }
  3300. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  3301. struct qla_hw_data *ha)
  3302. {
  3303. struct Scsi_Host *host;
  3304. struct scsi_qla_host *vha = NULL;
  3305. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  3306. if (host == NULL) {
  3307. ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
  3308. "Failed to allocate host from the scsi layer, aborting.\n");
  3309. goto fail;
  3310. }
  3311. /* Clear our data area */
  3312. vha = shost_priv(host);
  3313. memset(vha, 0, sizeof(scsi_qla_host_t));
  3314. vha->host = host;
  3315. vha->host_no = host->host_no;
  3316. vha->hw = ha;
  3317. INIT_LIST_HEAD(&vha->vp_fcports);
  3318. INIT_LIST_HEAD(&vha->work_list);
  3319. INIT_LIST_HEAD(&vha->list);
  3320. spin_lock_init(&vha->work_lock);
  3321. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  3322. ql_dbg(ql_dbg_init, vha, 0x0041,
  3323. "Allocated the host=%p hw=%p vha=%p dev_name=%s",
  3324. vha->host, vha->hw, vha,
  3325. dev_name(&(ha->pdev->dev)));
  3326. return vha;
  3327. fail:
  3328. return vha;
  3329. }
  3330. static struct qla_work_evt *
  3331. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  3332. {
  3333. struct qla_work_evt *e;
  3334. uint8_t bail;
  3335. QLA_VHA_MARK_BUSY(vha, bail);
  3336. if (bail)
  3337. return NULL;
  3338. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  3339. if (!e) {
  3340. QLA_VHA_MARK_NOT_BUSY(vha);
  3341. return NULL;
  3342. }
  3343. INIT_LIST_HEAD(&e->list);
  3344. e->type = type;
  3345. e->flags = QLA_EVT_FLAG_FREE;
  3346. return e;
  3347. }
  3348. static int
  3349. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  3350. {
  3351. unsigned long flags;
  3352. spin_lock_irqsave(&vha->work_lock, flags);
  3353. list_add_tail(&e->list, &vha->work_list);
  3354. spin_unlock_irqrestore(&vha->work_lock, flags);
  3355. qla2xxx_wake_dpc(vha);
  3356. return QLA_SUCCESS;
  3357. }
  3358. int
  3359. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  3360. u32 data)
  3361. {
  3362. struct qla_work_evt *e;
  3363. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  3364. if (!e)
  3365. return QLA_FUNCTION_FAILED;
  3366. e->u.aen.code = code;
  3367. e->u.aen.data = data;
  3368. return qla2x00_post_work(vha, e);
  3369. }
  3370. int
  3371. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  3372. {
  3373. struct qla_work_evt *e;
  3374. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  3375. if (!e)
  3376. return QLA_FUNCTION_FAILED;
  3377. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  3378. return qla2x00_post_work(vha, e);
  3379. }
  3380. #define qla2x00_post_async_work(name, type) \
  3381. int qla2x00_post_async_##name##_work( \
  3382. struct scsi_qla_host *vha, \
  3383. fc_port_t *fcport, uint16_t *data) \
  3384. { \
  3385. struct qla_work_evt *e; \
  3386. \
  3387. e = qla2x00_alloc_work(vha, type); \
  3388. if (!e) \
  3389. return QLA_FUNCTION_FAILED; \
  3390. \
  3391. e->u.logio.fcport = fcport; \
  3392. if (data) { \
  3393. e->u.logio.data[0] = data[0]; \
  3394. e->u.logio.data[1] = data[1]; \
  3395. } \
  3396. return qla2x00_post_work(vha, e); \
  3397. }
  3398. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  3399. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  3400. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  3401. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  3402. qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
  3403. qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
  3404. int
  3405. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  3406. {
  3407. struct qla_work_evt *e;
  3408. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  3409. if (!e)
  3410. return QLA_FUNCTION_FAILED;
  3411. e->u.uevent.code = code;
  3412. return qla2x00_post_work(vha, e);
  3413. }
  3414. static void
  3415. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  3416. {
  3417. char event_string[40];
  3418. char *envp[] = { event_string, NULL };
  3419. switch (code) {
  3420. case QLA_UEVENT_CODE_FW_DUMP:
  3421. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  3422. vha->host_no);
  3423. break;
  3424. default:
  3425. /* do nothing */
  3426. break;
  3427. }
  3428. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  3429. }
  3430. int
  3431. qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
  3432. uint32_t *data, int cnt)
  3433. {
  3434. struct qla_work_evt *e;
  3435. e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
  3436. if (!e)
  3437. return QLA_FUNCTION_FAILED;
  3438. e->u.aenfx.evtcode = evtcode;
  3439. e->u.aenfx.count = cnt;
  3440. memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
  3441. return qla2x00_post_work(vha, e);
  3442. }
  3443. void
  3444. qla2x00_do_work(struct scsi_qla_host *vha)
  3445. {
  3446. struct qla_work_evt *e, *tmp;
  3447. unsigned long flags;
  3448. LIST_HEAD(work);
  3449. spin_lock_irqsave(&vha->work_lock, flags);
  3450. list_splice_init(&vha->work_list, &work);
  3451. spin_unlock_irqrestore(&vha->work_lock, flags);
  3452. list_for_each_entry_safe(e, tmp, &work, list) {
  3453. list_del_init(&e->list);
  3454. switch (e->type) {
  3455. case QLA_EVT_AEN:
  3456. fc_host_post_event(vha->host, fc_get_event_number(),
  3457. e->u.aen.code, e->u.aen.data);
  3458. break;
  3459. case QLA_EVT_IDC_ACK:
  3460. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  3461. break;
  3462. case QLA_EVT_ASYNC_LOGIN:
  3463. qla2x00_async_login(vha, e->u.logio.fcport,
  3464. e->u.logio.data);
  3465. break;
  3466. case QLA_EVT_ASYNC_LOGIN_DONE:
  3467. qla2x00_async_login_done(vha, e->u.logio.fcport,
  3468. e->u.logio.data);
  3469. break;
  3470. case QLA_EVT_ASYNC_LOGOUT:
  3471. qla2x00_async_logout(vha, e->u.logio.fcport);
  3472. break;
  3473. case QLA_EVT_ASYNC_LOGOUT_DONE:
  3474. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  3475. e->u.logio.data);
  3476. break;
  3477. case QLA_EVT_ASYNC_ADISC:
  3478. qla2x00_async_adisc(vha, e->u.logio.fcport,
  3479. e->u.logio.data);
  3480. break;
  3481. case QLA_EVT_ASYNC_ADISC_DONE:
  3482. qla2x00_async_adisc_done(vha, e->u.logio.fcport,
  3483. e->u.logio.data);
  3484. break;
  3485. case QLA_EVT_UEVENT:
  3486. qla2x00_uevent_emit(vha, e->u.uevent.code);
  3487. break;
  3488. case QLA_EVT_AENFX:
  3489. qlafx00_process_aen(vha, e);
  3490. break;
  3491. }
  3492. if (e->flags & QLA_EVT_FLAG_FREE)
  3493. kfree(e);
  3494. /* For each work completed decrement vha ref count */
  3495. QLA_VHA_MARK_NOT_BUSY(vha);
  3496. }
  3497. }
  3498. /* Relogins all the fcports of a vport
  3499. * Context: dpc thread
  3500. */
  3501. void qla2x00_relogin(struct scsi_qla_host *vha)
  3502. {
  3503. fc_port_t *fcport;
  3504. int status;
  3505. uint16_t next_loopid = 0;
  3506. struct qla_hw_data *ha = vha->hw;
  3507. uint16_t data[2];
  3508. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3509. /*
  3510. * If the port is not ONLINE then try to login
  3511. * to it if we haven't run out of retries.
  3512. */
  3513. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  3514. fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
  3515. fcport->login_retry--;
  3516. if (fcport->flags & FCF_FABRIC_DEVICE) {
  3517. if (fcport->flags & FCF_FCP2_DEVICE)
  3518. ha->isp_ops->fabric_logout(vha,
  3519. fcport->loop_id,
  3520. fcport->d_id.b.domain,
  3521. fcport->d_id.b.area,
  3522. fcport->d_id.b.al_pa);
  3523. if (fcport->loop_id == FC_NO_LOOP_ID) {
  3524. fcport->loop_id = next_loopid =
  3525. ha->min_external_loopid;
  3526. status = qla2x00_find_new_loop_id(
  3527. vha, fcport);
  3528. if (status != QLA_SUCCESS) {
  3529. /* Ran out of IDs to use */
  3530. break;
  3531. }
  3532. }
  3533. if (IS_ALOGIO_CAPABLE(ha)) {
  3534. fcport->flags |= FCF_ASYNC_SENT;
  3535. data[0] = 0;
  3536. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  3537. status = qla2x00_post_async_login_work(
  3538. vha, fcport, data);
  3539. if (status == QLA_SUCCESS)
  3540. continue;
  3541. /* Attempt a retry. */
  3542. status = 1;
  3543. } else {
  3544. status = qla2x00_fabric_login(vha,
  3545. fcport, &next_loopid);
  3546. if (status == QLA_SUCCESS) {
  3547. int status2;
  3548. uint8_t opts;
  3549. opts = 0;
  3550. if (fcport->flags &
  3551. FCF_FCP2_DEVICE)
  3552. opts |= BIT_1;
  3553. status2 =
  3554. qla2x00_get_port_database(
  3555. vha, fcport, opts);
  3556. if (status2 != QLA_SUCCESS)
  3557. status = 1;
  3558. }
  3559. }
  3560. } else
  3561. status = qla2x00_local_device_login(vha,
  3562. fcport);
  3563. if (status == QLA_SUCCESS) {
  3564. fcport->old_loop_id = fcport->loop_id;
  3565. ql_dbg(ql_dbg_disc, vha, 0x2003,
  3566. "Port login OK: logged in ID 0x%x.\n",
  3567. fcport->loop_id);
  3568. qla2x00_update_fcport(vha, fcport);
  3569. } else if (status == 1) {
  3570. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  3571. /* retry the login again */
  3572. ql_dbg(ql_dbg_disc, vha, 0x2007,
  3573. "Retrying %d login again loop_id 0x%x.\n",
  3574. fcport->login_retry, fcport->loop_id);
  3575. } else {
  3576. fcport->login_retry = 0;
  3577. }
  3578. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  3579. qla2x00_clear_loop_id(fcport);
  3580. }
  3581. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3582. break;
  3583. }
  3584. }
  3585. /* Schedule work on any of the dpc-workqueues */
  3586. void
  3587. qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
  3588. {
  3589. struct qla_hw_data *ha = base_vha->hw;
  3590. switch (work_code) {
  3591. case MBA_IDC_AEN: /* 0x8200 */
  3592. if (ha->dpc_lp_wq)
  3593. queue_work(ha->dpc_lp_wq, &ha->idc_aen);
  3594. break;
  3595. case QLA83XX_NIC_CORE_RESET: /* 0x1 */
  3596. if (!ha->flags.nic_core_reset_hdlr_active) {
  3597. if (ha->dpc_hp_wq)
  3598. queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
  3599. } else
  3600. ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
  3601. "NIC Core reset is already active. Skip "
  3602. "scheduling it again.\n");
  3603. break;
  3604. case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
  3605. if (ha->dpc_hp_wq)
  3606. queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
  3607. break;
  3608. case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
  3609. if (ha->dpc_hp_wq)
  3610. queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
  3611. break;
  3612. default:
  3613. ql_log(ql_log_warn, base_vha, 0xb05f,
  3614. "Unknow work-code=0x%x.\n", work_code);
  3615. }
  3616. return;
  3617. }
  3618. /* Work: Perform NIC Core Unrecoverable state handling */
  3619. void
  3620. qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
  3621. {
  3622. struct qla_hw_data *ha =
  3623. container_of(work, struct qla_hw_data, nic_core_unrecoverable);
  3624. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3625. uint32_t dev_state = 0;
  3626. qla83xx_idc_lock(base_vha, 0);
  3627. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3628. qla83xx_reset_ownership(base_vha);
  3629. if (ha->flags.nic_core_reset_owner) {
  3630. ha->flags.nic_core_reset_owner = 0;
  3631. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3632. QLA8XXX_DEV_FAILED);
  3633. ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
  3634. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3635. }
  3636. qla83xx_idc_unlock(base_vha, 0);
  3637. }
  3638. /* Work: Execute IDC state handler */
  3639. void
  3640. qla83xx_idc_state_handler_work(struct work_struct *work)
  3641. {
  3642. struct qla_hw_data *ha =
  3643. container_of(work, struct qla_hw_data, idc_state_handler);
  3644. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3645. uint32_t dev_state = 0;
  3646. qla83xx_idc_lock(base_vha, 0);
  3647. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3648. if (dev_state == QLA8XXX_DEV_FAILED ||
  3649. dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
  3650. qla83xx_idc_state_handler(base_vha);
  3651. qla83xx_idc_unlock(base_vha, 0);
  3652. }
  3653. static int
  3654. qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
  3655. {
  3656. int rval = QLA_SUCCESS;
  3657. unsigned long heart_beat_wait = jiffies + (1 * HZ);
  3658. uint32_t heart_beat_counter1, heart_beat_counter2;
  3659. do {
  3660. if (time_after(jiffies, heart_beat_wait)) {
  3661. ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
  3662. "Nic Core f/w is not alive.\n");
  3663. rval = QLA_FUNCTION_FAILED;
  3664. break;
  3665. }
  3666. qla83xx_idc_lock(base_vha, 0);
  3667. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  3668. &heart_beat_counter1);
  3669. qla83xx_idc_unlock(base_vha, 0);
  3670. msleep(100);
  3671. qla83xx_idc_lock(base_vha, 0);
  3672. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  3673. &heart_beat_counter2);
  3674. qla83xx_idc_unlock(base_vha, 0);
  3675. } while (heart_beat_counter1 == heart_beat_counter2);
  3676. return rval;
  3677. }
  3678. /* Work: Perform NIC Core Reset handling */
  3679. void
  3680. qla83xx_nic_core_reset_work(struct work_struct *work)
  3681. {
  3682. struct qla_hw_data *ha =
  3683. container_of(work, struct qla_hw_data, nic_core_reset);
  3684. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3685. uint32_t dev_state = 0;
  3686. if (IS_QLA2031(ha)) {
  3687. if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
  3688. ql_log(ql_log_warn, base_vha, 0xb081,
  3689. "Failed to dump mctp\n");
  3690. return;
  3691. }
  3692. if (!ha->flags.nic_core_reset_hdlr_active) {
  3693. if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
  3694. qla83xx_idc_lock(base_vha, 0);
  3695. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3696. &dev_state);
  3697. qla83xx_idc_unlock(base_vha, 0);
  3698. if (dev_state != QLA8XXX_DEV_NEED_RESET) {
  3699. ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
  3700. "Nic Core f/w is alive.\n");
  3701. return;
  3702. }
  3703. }
  3704. ha->flags.nic_core_reset_hdlr_active = 1;
  3705. if (qla83xx_nic_core_reset(base_vha)) {
  3706. /* NIC Core reset failed. */
  3707. ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
  3708. "NIC Core reset failed.\n");
  3709. }
  3710. ha->flags.nic_core_reset_hdlr_active = 0;
  3711. }
  3712. }
  3713. /* Work: Handle 8200 IDC aens */
  3714. void
  3715. qla83xx_service_idc_aen(struct work_struct *work)
  3716. {
  3717. struct qla_hw_data *ha =
  3718. container_of(work, struct qla_hw_data, idc_aen);
  3719. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3720. uint32_t dev_state, idc_control;
  3721. qla83xx_idc_lock(base_vha, 0);
  3722. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3723. qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
  3724. qla83xx_idc_unlock(base_vha, 0);
  3725. if (dev_state == QLA8XXX_DEV_NEED_RESET) {
  3726. if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
  3727. ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
  3728. "Application requested NIC Core Reset.\n");
  3729. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  3730. } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
  3731. QLA_SUCCESS) {
  3732. ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
  3733. "Other protocol driver requested NIC Core Reset.\n");
  3734. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  3735. }
  3736. } else if (dev_state == QLA8XXX_DEV_FAILED ||
  3737. dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
  3738. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3739. }
  3740. }
  3741. static void
  3742. qla83xx_wait_logic(void)
  3743. {
  3744. int i;
  3745. /* Yield CPU */
  3746. if (!in_interrupt()) {
  3747. /*
  3748. * Wait about 200ms before retrying again.
  3749. * This controls the number of retries for single
  3750. * lock operation.
  3751. */
  3752. msleep(100);
  3753. schedule();
  3754. } else {
  3755. for (i = 0; i < 20; i++)
  3756. cpu_relax(); /* This a nop instr on i386 */
  3757. }
  3758. }
  3759. static int
  3760. qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
  3761. {
  3762. int rval;
  3763. uint32_t data;
  3764. uint32_t idc_lck_rcvry_stage_mask = 0x3;
  3765. uint32_t idc_lck_rcvry_owner_mask = 0x3c;
  3766. struct qla_hw_data *ha = base_vha->hw;
  3767. ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
  3768. "Trying force recovery of the IDC lock.\n");
  3769. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
  3770. if (rval)
  3771. return rval;
  3772. if ((data & idc_lck_rcvry_stage_mask) > 0) {
  3773. return QLA_SUCCESS;
  3774. } else {
  3775. data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
  3776. rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  3777. data);
  3778. if (rval)
  3779. return rval;
  3780. msleep(200);
  3781. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  3782. &data);
  3783. if (rval)
  3784. return rval;
  3785. if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
  3786. data &= (IDC_LOCK_RECOVERY_STAGE2 |
  3787. ~(idc_lck_rcvry_stage_mask));
  3788. rval = qla83xx_wr_reg(base_vha,
  3789. QLA83XX_IDC_LOCK_RECOVERY, data);
  3790. if (rval)
  3791. return rval;
  3792. /* Forcefully perform IDC UnLock */
  3793. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
  3794. &data);
  3795. if (rval)
  3796. return rval;
  3797. /* Clear lock-id by setting 0xff */
  3798. rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3799. 0xff);
  3800. if (rval)
  3801. return rval;
  3802. /* Clear lock-recovery by setting 0x0 */
  3803. rval = qla83xx_wr_reg(base_vha,
  3804. QLA83XX_IDC_LOCK_RECOVERY, 0x0);
  3805. if (rval)
  3806. return rval;
  3807. } else
  3808. return QLA_SUCCESS;
  3809. }
  3810. return rval;
  3811. }
  3812. static int
  3813. qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
  3814. {
  3815. int rval = QLA_SUCCESS;
  3816. uint32_t o_drv_lockid, n_drv_lockid;
  3817. unsigned long lock_recovery_timeout;
  3818. lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
  3819. retry_lockid:
  3820. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
  3821. if (rval)
  3822. goto exit;
  3823. /* MAX wait time before forcing IDC Lock recovery = 2 secs */
  3824. if (time_after_eq(jiffies, lock_recovery_timeout)) {
  3825. if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
  3826. return QLA_SUCCESS;
  3827. else
  3828. return QLA_FUNCTION_FAILED;
  3829. }
  3830. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
  3831. if (rval)
  3832. goto exit;
  3833. if (o_drv_lockid == n_drv_lockid) {
  3834. qla83xx_wait_logic();
  3835. goto retry_lockid;
  3836. } else
  3837. return QLA_SUCCESS;
  3838. exit:
  3839. return rval;
  3840. }
  3841. void
  3842. qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  3843. {
  3844. uint16_t options = (requester_id << 15) | BIT_6;
  3845. uint32_t data;
  3846. uint32_t lock_owner;
  3847. struct qla_hw_data *ha = base_vha->hw;
  3848. /* IDC-lock implementation using driver-lock/lock-id remote registers */
  3849. retry_lock:
  3850. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
  3851. == QLA_SUCCESS) {
  3852. if (data) {
  3853. /* Setting lock-id to our function-number */
  3854. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3855. ha->portnum);
  3856. } else {
  3857. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  3858. &lock_owner);
  3859. ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
  3860. "Failed to acquire IDC lock, acquired by %d, "
  3861. "retrying...\n", lock_owner);
  3862. /* Retry/Perform IDC-Lock recovery */
  3863. if (qla83xx_idc_lock_recovery(base_vha)
  3864. == QLA_SUCCESS) {
  3865. qla83xx_wait_logic();
  3866. goto retry_lock;
  3867. } else
  3868. ql_log(ql_log_warn, base_vha, 0xb075,
  3869. "IDC Lock recovery FAILED.\n");
  3870. }
  3871. }
  3872. return;
  3873. /* XXX: IDC-lock implementation using access-control mbx */
  3874. retry_lock2:
  3875. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  3876. ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
  3877. "Failed to acquire IDC lock. retrying...\n");
  3878. /* Retry/Perform IDC-Lock recovery */
  3879. if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
  3880. qla83xx_wait_logic();
  3881. goto retry_lock2;
  3882. } else
  3883. ql_log(ql_log_warn, base_vha, 0xb076,
  3884. "IDC Lock recovery FAILED.\n");
  3885. }
  3886. return;
  3887. }
  3888. void
  3889. qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  3890. {
  3891. uint16_t options = (requester_id << 15) | BIT_7, retry;
  3892. uint32_t data;
  3893. struct qla_hw_data *ha = base_vha->hw;
  3894. /* IDC-unlock implementation using driver-unlock/lock-id
  3895. * remote registers
  3896. */
  3897. retry = 0;
  3898. retry_unlock:
  3899. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
  3900. == QLA_SUCCESS) {
  3901. if (data == ha->portnum) {
  3902. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
  3903. /* Clearing lock-id by setting 0xff */
  3904. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
  3905. } else if (retry < 10) {
  3906. /* SV: XXX: IDC unlock retrying needed here? */
  3907. /* Retry for IDC-unlock */
  3908. qla83xx_wait_logic();
  3909. retry++;
  3910. ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
  3911. "Failed to release IDC lock, retyring=%d\n", retry);
  3912. goto retry_unlock;
  3913. }
  3914. } else if (retry < 10) {
  3915. /* Retry for IDC-unlock */
  3916. qla83xx_wait_logic();
  3917. retry++;
  3918. ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
  3919. "Failed to read drv-lockid, retyring=%d\n", retry);
  3920. goto retry_unlock;
  3921. }
  3922. return;
  3923. /* XXX: IDC-unlock implementation using access-control mbx */
  3924. retry = 0;
  3925. retry_unlock2:
  3926. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  3927. if (retry < 10) {
  3928. /* Retry for IDC-unlock */
  3929. qla83xx_wait_logic();
  3930. retry++;
  3931. ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
  3932. "Failed to release IDC lock, retyring=%d\n", retry);
  3933. goto retry_unlock2;
  3934. }
  3935. }
  3936. return;
  3937. }
  3938. int
  3939. __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  3940. {
  3941. int rval = QLA_SUCCESS;
  3942. struct qla_hw_data *ha = vha->hw;
  3943. uint32_t drv_presence;
  3944. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3945. if (rval == QLA_SUCCESS) {
  3946. drv_presence |= (1 << ha->portnum);
  3947. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  3948. drv_presence);
  3949. }
  3950. return rval;
  3951. }
  3952. int
  3953. qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  3954. {
  3955. int rval = QLA_SUCCESS;
  3956. qla83xx_idc_lock(vha, 0);
  3957. rval = __qla83xx_set_drv_presence(vha);
  3958. qla83xx_idc_unlock(vha, 0);
  3959. return rval;
  3960. }
  3961. int
  3962. __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  3963. {
  3964. int rval = QLA_SUCCESS;
  3965. struct qla_hw_data *ha = vha->hw;
  3966. uint32_t drv_presence;
  3967. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3968. if (rval == QLA_SUCCESS) {
  3969. drv_presence &= ~(1 << ha->portnum);
  3970. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  3971. drv_presence);
  3972. }
  3973. return rval;
  3974. }
  3975. int
  3976. qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  3977. {
  3978. int rval = QLA_SUCCESS;
  3979. qla83xx_idc_lock(vha, 0);
  3980. rval = __qla83xx_clear_drv_presence(vha);
  3981. qla83xx_idc_unlock(vha, 0);
  3982. return rval;
  3983. }
  3984. static void
  3985. qla83xx_need_reset_handler(scsi_qla_host_t *vha)
  3986. {
  3987. struct qla_hw_data *ha = vha->hw;
  3988. uint32_t drv_ack, drv_presence;
  3989. unsigned long ack_timeout;
  3990. /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
  3991. ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
  3992. while (1) {
  3993. qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3994. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3995. if ((drv_ack & drv_presence) == drv_presence)
  3996. break;
  3997. if (time_after_eq(jiffies, ack_timeout)) {
  3998. ql_log(ql_log_warn, vha, 0xb067,
  3999. "RESET ACK TIMEOUT! drv_presence=0x%x "
  4000. "drv_ack=0x%x\n", drv_presence, drv_ack);
  4001. /*
  4002. * The function(s) which did not ack in time are forced
  4003. * to withdraw any further participation in the IDC
  4004. * reset.
  4005. */
  4006. if (drv_ack != drv_presence)
  4007. qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4008. drv_ack);
  4009. break;
  4010. }
  4011. qla83xx_idc_unlock(vha, 0);
  4012. msleep(1000);
  4013. qla83xx_idc_lock(vha, 0);
  4014. }
  4015. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
  4016. ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
  4017. }
  4018. static int
  4019. qla83xx_device_bootstrap(scsi_qla_host_t *vha)
  4020. {
  4021. int rval = QLA_SUCCESS;
  4022. uint32_t idc_control;
  4023. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
  4024. ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
  4025. /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
  4026. __qla83xx_get_idc_control(vha, &idc_control);
  4027. idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
  4028. __qla83xx_set_idc_control(vha, 0);
  4029. qla83xx_idc_unlock(vha, 0);
  4030. rval = qla83xx_restart_nic_firmware(vha);
  4031. qla83xx_idc_lock(vha, 0);
  4032. if (rval != QLA_SUCCESS) {
  4033. ql_log(ql_log_fatal, vha, 0xb06a,
  4034. "Failed to restart NIC f/w.\n");
  4035. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
  4036. ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
  4037. } else {
  4038. ql_dbg(ql_dbg_p3p, vha, 0xb06c,
  4039. "Success in restarting nic f/w.\n");
  4040. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
  4041. ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
  4042. }
  4043. return rval;
  4044. }
  4045. /* Assumes idc_lock always held on entry */
  4046. int
  4047. qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
  4048. {
  4049. struct qla_hw_data *ha = base_vha->hw;
  4050. int rval = QLA_SUCCESS;
  4051. unsigned long dev_init_timeout;
  4052. uint32_t dev_state;
  4053. /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
  4054. dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
  4055. while (1) {
  4056. if (time_after_eq(jiffies, dev_init_timeout)) {
  4057. ql_log(ql_log_warn, base_vha, 0xb06e,
  4058. "Initialization TIMEOUT!\n");
  4059. /* Init timeout. Disable further NIC Core
  4060. * communication.
  4061. */
  4062. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  4063. QLA8XXX_DEV_FAILED);
  4064. ql_log(ql_log_info, base_vha, 0xb06f,
  4065. "HW State: FAILED.\n");
  4066. }
  4067. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  4068. switch (dev_state) {
  4069. case QLA8XXX_DEV_READY:
  4070. if (ha->flags.nic_core_reset_owner)
  4071. qla83xx_idc_audit(base_vha,
  4072. IDC_AUDIT_COMPLETION);
  4073. ha->flags.nic_core_reset_owner = 0;
  4074. ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
  4075. "Reset_owner reset by 0x%x.\n",
  4076. ha->portnum);
  4077. goto exit;
  4078. case QLA8XXX_DEV_COLD:
  4079. if (ha->flags.nic_core_reset_owner)
  4080. rval = qla83xx_device_bootstrap(base_vha);
  4081. else {
  4082. /* Wait for AEN to change device-state */
  4083. qla83xx_idc_unlock(base_vha, 0);
  4084. msleep(1000);
  4085. qla83xx_idc_lock(base_vha, 0);
  4086. }
  4087. break;
  4088. case QLA8XXX_DEV_INITIALIZING:
  4089. /* Wait for AEN to change device-state */
  4090. qla83xx_idc_unlock(base_vha, 0);
  4091. msleep(1000);
  4092. qla83xx_idc_lock(base_vha, 0);
  4093. break;
  4094. case QLA8XXX_DEV_NEED_RESET:
  4095. if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
  4096. qla83xx_need_reset_handler(base_vha);
  4097. else {
  4098. /* Wait for AEN to change device-state */
  4099. qla83xx_idc_unlock(base_vha, 0);
  4100. msleep(1000);
  4101. qla83xx_idc_lock(base_vha, 0);
  4102. }
  4103. /* reset timeout value after need reset handler */
  4104. dev_init_timeout = jiffies +
  4105. (ha->fcoe_dev_init_timeout * HZ);
  4106. break;
  4107. case QLA8XXX_DEV_NEED_QUIESCENT:
  4108. /* XXX: DEBUG for now */
  4109. qla83xx_idc_unlock(base_vha, 0);
  4110. msleep(1000);
  4111. qla83xx_idc_lock(base_vha, 0);
  4112. break;
  4113. case QLA8XXX_DEV_QUIESCENT:
  4114. /* XXX: DEBUG for now */
  4115. if (ha->flags.quiesce_owner)
  4116. goto exit;
  4117. qla83xx_idc_unlock(base_vha, 0);
  4118. msleep(1000);
  4119. qla83xx_idc_lock(base_vha, 0);
  4120. dev_init_timeout = jiffies +
  4121. (ha->fcoe_dev_init_timeout * HZ);
  4122. break;
  4123. case QLA8XXX_DEV_FAILED:
  4124. if (ha->flags.nic_core_reset_owner)
  4125. qla83xx_idc_audit(base_vha,
  4126. IDC_AUDIT_COMPLETION);
  4127. ha->flags.nic_core_reset_owner = 0;
  4128. __qla83xx_clear_drv_presence(base_vha);
  4129. qla83xx_idc_unlock(base_vha, 0);
  4130. qla8xxx_dev_failed_handler(base_vha);
  4131. rval = QLA_FUNCTION_FAILED;
  4132. qla83xx_idc_lock(base_vha, 0);
  4133. goto exit;
  4134. case QLA8XXX_BAD_VALUE:
  4135. qla83xx_idc_unlock(base_vha, 0);
  4136. msleep(1000);
  4137. qla83xx_idc_lock(base_vha, 0);
  4138. break;
  4139. default:
  4140. ql_log(ql_log_warn, base_vha, 0xb071,
  4141. "Unknow Device State: %x.\n", dev_state);
  4142. qla83xx_idc_unlock(base_vha, 0);
  4143. qla8xxx_dev_failed_handler(base_vha);
  4144. rval = QLA_FUNCTION_FAILED;
  4145. qla83xx_idc_lock(base_vha, 0);
  4146. goto exit;
  4147. }
  4148. }
  4149. exit:
  4150. return rval;
  4151. }
  4152. /**************************************************************************
  4153. * qla2x00_do_dpc
  4154. * This kernel thread is a task that is schedule by the interrupt handler
  4155. * to perform the background processing for interrupts.
  4156. *
  4157. * Notes:
  4158. * This task always run in the context of a kernel thread. It
  4159. * is kick-off by the driver's detect code and starts up
  4160. * up one per adapter. It immediately goes to sleep and waits for
  4161. * some fibre event. When either the interrupt handler or
  4162. * the timer routine detects a event it will one of the task
  4163. * bits then wake us up.
  4164. **************************************************************************/
  4165. static int
  4166. qla2x00_do_dpc(void *data)
  4167. {
  4168. int rval;
  4169. scsi_qla_host_t *base_vha;
  4170. struct qla_hw_data *ha;
  4171. ha = (struct qla_hw_data *)data;
  4172. base_vha = pci_get_drvdata(ha->pdev);
  4173. set_user_nice(current, -20);
  4174. set_current_state(TASK_INTERRUPTIBLE);
  4175. while (!kthread_should_stop()) {
  4176. ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
  4177. "DPC handler sleeping.\n");
  4178. schedule();
  4179. __set_current_state(TASK_RUNNING);
  4180. if (!base_vha->flags.init_done || ha->flags.mbox_busy)
  4181. goto end_loop;
  4182. if (ha->flags.eeh_busy) {
  4183. ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
  4184. "eeh_busy=%d.\n", ha->flags.eeh_busy);
  4185. goto end_loop;
  4186. }
  4187. ha->dpc_active = 1;
  4188. ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
  4189. "DPC handler waking up, dpc_flags=0x%lx.\n",
  4190. base_vha->dpc_flags);
  4191. qla2x00_do_work(base_vha);
  4192. if (IS_P3P_TYPE(ha)) {
  4193. if (IS_QLA8044(ha)) {
  4194. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4195. &base_vha->dpc_flags)) {
  4196. qla8044_idc_lock(ha);
  4197. qla8044_wr_direct(base_vha,
  4198. QLA8044_CRB_DEV_STATE_INDEX,
  4199. QLA8XXX_DEV_FAILED);
  4200. qla8044_idc_unlock(ha);
  4201. ql_log(ql_log_info, base_vha, 0x4004,
  4202. "HW State: FAILED.\n");
  4203. qla8044_device_state_handler(base_vha);
  4204. continue;
  4205. }
  4206. } else {
  4207. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4208. &base_vha->dpc_flags)) {
  4209. qla82xx_idc_lock(ha);
  4210. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4211. QLA8XXX_DEV_FAILED);
  4212. qla82xx_idc_unlock(ha);
  4213. ql_log(ql_log_info, base_vha, 0x0151,
  4214. "HW State: FAILED.\n");
  4215. qla82xx_device_state_handler(base_vha);
  4216. continue;
  4217. }
  4218. }
  4219. if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
  4220. &base_vha->dpc_flags)) {
  4221. ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
  4222. "FCoE context reset scheduled.\n");
  4223. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4224. &base_vha->dpc_flags))) {
  4225. if (qla82xx_fcoe_ctx_reset(base_vha)) {
  4226. /* FCoE-ctx reset failed.
  4227. * Escalate to chip-reset
  4228. */
  4229. set_bit(ISP_ABORT_NEEDED,
  4230. &base_vha->dpc_flags);
  4231. }
  4232. clear_bit(ABORT_ISP_ACTIVE,
  4233. &base_vha->dpc_flags);
  4234. }
  4235. ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
  4236. "FCoE context reset end.\n");
  4237. }
  4238. } else if (IS_QLAFX00(ha)) {
  4239. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4240. &base_vha->dpc_flags)) {
  4241. ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
  4242. "Firmware Reset Recovery\n");
  4243. if (qlafx00_reset_initialize(base_vha)) {
  4244. /* Failed. Abort isp later. */
  4245. if (!test_bit(UNLOADING,
  4246. &base_vha->dpc_flags))
  4247. set_bit(ISP_UNRECOVERABLE,
  4248. &base_vha->dpc_flags);
  4249. ql_dbg(ql_dbg_dpc, base_vha,
  4250. 0x4021,
  4251. "Reset Recovery Failed\n");
  4252. }
  4253. }
  4254. if (test_and_clear_bit(FX00_TARGET_SCAN,
  4255. &base_vha->dpc_flags)) {
  4256. ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
  4257. "ISPFx00 Target Scan scheduled\n");
  4258. if (qlafx00_rescan_isp(base_vha)) {
  4259. if (!test_bit(UNLOADING,
  4260. &base_vha->dpc_flags))
  4261. set_bit(ISP_UNRECOVERABLE,
  4262. &base_vha->dpc_flags);
  4263. ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
  4264. "ISPFx00 Target Scan Failed\n");
  4265. }
  4266. ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
  4267. "ISPFx00 Target Scan End\n");
  4268. }
  4269. }
  4270. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  4271. &base_vha->dpc_flags)) {
  4272. ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
  4273. "ISP abort scheduled.\n");
  4274. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4275. &base_vha->dpc_flags))) {
  4276. if (ha->isp_ops->abort_isp(base_vha)) {
  4277. /* failed. retry later */
  4278. set_bit(ISP_ABORT_NEEDED,
  4279. &base_vha->dpc_flags);
  4280. }
  4281. clear_bit(ABORT_ISP_ACTIVE,
  4282. &base_vha->dpc_flags);
  4283. }
  4284. ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
  4285. "ISP abort end.\n");
  4286. }
  4287. if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
  4288. &base_vha->dpc_flags)) {
  4289. qla2x00_update_fcports(base_vha);
  4290. }
  4291. if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
  4292. int ret;
  4293. ret = qla2x00_send_change_request(base_vha, 0x3, 0);
  4294. if (ret != QLA_SUCCESS)
  4295. ql_log(ql_log_warn, base_vha, 0x121,
  4296. "Failed to enable receiving of RSCN "
  4297. "requests: 0x%x.\n", ret);
  4298. clear_bit(SCR_PENDING, &base_vha->dpc_flags);
  4299. }
  4300. if (IS_QLAFX00(ha))
  4301. goto loop_resync_check;
  4302. if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
  4303. ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
  4304. "Quiescence mode scheduled.\n");
  4305. if (IS_P3P_TYPE(ha)) {
  4306. if (IS_QLA82XX(ha))
  4307. qla82xx_device_state_handler(base_vha);
  4308. if (IS_QLA8044(ha))
  4309. qla8044_device_state_handler(base_vha);
  4310. clear_bit(ISP_QUIESCE_NEEDED,
  4311. &base_vha->dpc_flags);
  4312. if (!ha->flags.quiesce_owner) {
  4313. qla2x00_perform_loop_resync(base_vha);
  4314. if (IS_QLA82XX(ha)) {
  4315. qla82xx_idc_lock(ha);
  4316. qla82xx_clear_qsnt_ready(
  4317. base_vha);
  4318. qla82xx_idc_unlock(ha);
  4319. } else if (IS_QLA8044(ha)) {
  4320. qla8044_idc_lock(ha);
  4321. qla8044_clear_qsnt_ready(
  4322. base_vha);
  4323. qla8044_idc_unlock(ha);
  4324. }
  4325. }
  4326. } else {
  4327. clear_bit(ISP_QUIESCE_NEEDED,
  4328. &base_vha->dpc_flags);
  4329. qla2x00_quiesce_io(base_vha);
  4330. }
  4331. ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
  4332. "Quiescence mode end.\n");
  4333. }
  4334. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  4335. &base_vha->dpc_flags) &&
  4336. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  4337. ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
  4338. "Reset marker scheduled.\n");
  4339. qla2x00_rst_aen(base_vha);
  4340. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  4341. ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
  4342. "Reset marker end.\n");
  4343. }
  4344. /* Retry each device up to login retry count */
  4345. if ((test_and_clear_bit(RELOGIN_NEEDED,
  4346. &base_vha->dpc_flags)) &&
  4347. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  4348. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  4349. ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
  4350. "Relogin scheduled.\n");
  4351. qla2x00_relogin(base_vha);
  4352. ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
  4353. "Relogin end.\n");
  4354. }
  4355. loop_resync_check:
  4356. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  4357. &base_vha->dpc_flags)) {
  4358. ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
  4359. "Loop resync scheduled.\n");
  4360. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  4361. &base_vha->dpc_flags))) {
  4362. rval = qla2x00_loop_resync(base_vha);
  4363. clear_bit(LOOP_RESYNC_ACTIVE,
  4364. &base_vha->dpc_flags);
  4365. }
  4366. ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
  4367. "Loop resync end.\n");
  4368. }
  4369. if (IS_QLAFX00(ha))
  4370. goto intr_on_check;
  4371. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  4372. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  4373. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  4374. qla2xxx_flash_npiv_conf(base_vha);
  4375. }
  4376. if (test_and_clear_bit(HOST_RAMP_DOWN_QUEUE_DEPTH,
  4377. &base_vha->dpc_flags)) {
  4378. /* Prevents simultaneous ramp up and down */
  4379. clear_bit(HOST_RAMP_UP_QUEUE_DEPTH,
  4380. &base_vha->dpc_flags);
  4381. qla2x00_host_ramp_down_queuedepth(base_vha);
  4382. }
  4383. if (test_and_clear_bit(HOST_RAMP_UP_QUEUE_DEPTH,
  4384. &base_vha->dpc_flags))
  4385. qla2x00_host_ramp_up_queuedepth(base_vha);
  4386. intr_on_check:
  4387. if (!ha->interrupts_on)
  4388. ha->isp_ops->enable_intrs(ha);
  4389. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  4390. &base_vha->dpc_flags))
  4391. ha->isp_ops->beacon_blink(base_vha);
  4392. if (!IS_QLAFX00(ha))
  4393. qla2x00_do_dpc_all_vps(base_vha);
  4394. ha->dpc_active = 0;
  4395. end_loop:
  4396. set_current_state(TASK_INTERRUPTIBLE);
  4397. } /* End of while(1) */
  4398. __set_current_state(TASK_RUNNING);
  4399. ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
  4400. "DPC handler exiting.\n");
  4401. /*
  4402. * Make sure that nobody tries to wake us up again.
  4403. */
  4404. ha->dpc_active = 0;
  4405. /* Cleanup any residual CTX SRBs. */
  4406. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  4407. return 0;
  4408. }
  4409. void
  4410. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  4411. {
  4412. struct qla_hw_data *ha = vha->hw;
  4413. struct task_struct *t = ha->dpc_thread;
  4414. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  4415. wake_up_process(t);
  4416. }
  4417. /*
  4418. * qla2x00_rst_aen
  4419. * Processes asynchronous reset.
  4420. *
  4421. * Input:
  4422. * ha = adapter block pointer.
  4423. */
  4424. static void
  4425. qla2x00_rst_aen(scsi_qla_host_t *vha)
  4426. {
  4427. if (vha->flags.online && !vha->flags.reset_active &&
  4428. !atomic_read(&vha->loop_down_timer) &&
  4429. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  4430. do {
  4431. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4432. /*
  4433. * Issue marker command only when we are going to start
  4434. * the I/O.
  4435. */
  4436. vha->marker_needed = 1;
  4437. } while (!atomic_read(&vha->loop_down_timer) &&
  4438. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  4439. }
  4440. }
  4441. /**************************************************************************
  4442. * qla2x00_timer
  4443. *
  4444. * Description:
  4445. * One second timer
  4446. *
  4447. * Context: Interrupt
  4448. ***************************************************************************/
  4449. void
  4450. qla2x00_timer(scsi_qla_host_t *vha)
  4451. {
  4452. unsigned long cpu_flags = 0;
  4453. int start_dpc = 0;
  4454. int index;
  4455. srb_t *sp;
  4456. uint16_t w;
  4457. struct qla_hw_data *ha = vha->hw;
  4458. struct req_que *req;
  4459. if (ha->flags.eeh_busy) {
  4460. ql_dbg(ql_dbg_timer, vha, 0x6000,
  4461. "EEH = %d, restarting timer.\n",
  4462. ha->flags.eeh_busy);
  4463. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4464. return;
  4465. }
  4466. /* Hardware read to raise pending EEH errors during mailbox waits. */
  4467. if (!pci_channel_offline(ha->pdev))
  4468. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  4469. /* Make sure qla82xx_watchdog is run only for physical port */
  4470. if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
  4471. if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
  4472. start_dpc++;
  4473. if (IS_QLA82XX(ha))
  4474. qla82xx_watchdog(vha);
  4475. else if (IS_QLA8044(ha))
  4476. qla8044_watchdog(vha);
  4477. }
  4478. if (!vha->vp_idx && IS_QLAFX00(ha))
  4479. qlafx00_timer_routine(vha);
  4480. /* Loop down handler. */
  4481. if (atomic_read(&vha->loop_down_timer) > 0 &&
  4482. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
  4483. !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
  4484. && vha->flags.online) {
  4485. if (atomic_read(&vha->loop_down_timer) ==
  4486. vha->loop_down_abort_time) {
  4487. ql_log(ql_log_info, vha, 0x6008,
  4488. "Loop down - aborting the queues before time expires.\n");
  4489. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  4490. atomic_set(&vha->loop_state, LOOP_DEAD);
  4491. /*
  4492. * Schedule an ISP abort to return any FCP2-device
  4493. * commands.
  4494. */
  4495. /* NPIV - scan physical port only */
  4496. if (!vha->vp_idx) {
  4497. spin_lock_irqsave(&ha->hardware_lock,
  4498. cpu_flags);
  4499. req = ha->req_q_map[0];
  4500. for (index = 1;
  4501. index < req->num_outstanding_cmds;
  4502. index++) {
  4503. fc_port_t *sfcp;
  4504. sp = req->outstanding_cmds[index];
  4505. if (!sp)
  4506. continue;
  4507. if (sp->type != SRB_SCSI_CMD)
  4508. continue;
  4509. sfcp = sp->fcport;
  4510. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  4511. continue;
  4512. if (IS_QLA82XX(ha))
  4513. set_bit(FCOE_CTX_RESET_NEEDED,
  4514. &vha->dpc_flags);
  4515. else
  4516. set_bit(ISP_ABORT_NEEDED,
  4517. &vha->dpc_flags);
  4518. break;
  4519. }
  4520. spin_unlock_irqrestore(&ha->hardware_lock,
  4521. cpu_flags);
  4522. }
  4523. start_dpc++;
  4524. }
  4525. /* if the loop has been down for 4 minutes, reinit adapter */
  4526. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  4527. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  4528. ql_log(ql_log_warn, vha, 0x6009,
  4529. "Loop down - aborting ISP.\n");
  4530. if (IS_QLA82XX(ha))
  4531. set_bit(FCOE_CTX_RESET_NEEDED,
  4532. &vha->dpc_flags);
  4533. else
  4534. set_bit(ISP_ABORT_NEEDED,
  4535. &vha->dpc_flags);
  4536. }
  4537. }
  4538. ql_dbg(ql_dbg_timer, vha, 0x600a,
  4539. "Loop down - seconds remaining %d.\n",
  4540. atomic_read(&vha->loop_down_timer));
  4541. }
  4542. /* Check if beacon LED needs to be blinked for physical host only */
  4543. if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
  4544. /* There is no beacon_blink function for ISP82xx */
  4545. if (!IS_P3P_TYPE(ha)) {
  4546. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  4547. start_dpc++;
  4548. }
  4549. }
  4550. /* Process any deferred work. */
  4551. if (!list_empty(&vha->work_list))
  4552. start_dpc++;
  4553. /* Schedule the DPC routine if needed */
  4554. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  4555. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  4556. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  4557. start_dpc ||
  4558. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  4559. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  4560. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
  4561. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
  4562. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  4563. test_bit(RELOGIN_NEEDED, &vha->dpc_flags) ||
  4564. test_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags) ||
  4565. test_bit(HOST_RAMP_UP_QUEUE_DEPTH, &vha->dpc_flags))) {
  4566. ql_dbg(ql_dbg_timer, vha, 0x600b,
  4567. "isp_abort_needed=%d loop_resync_needed=%d "
  4568. "fcport_update_needed=%d start_dpc=%d "
  4569. "reset_marker_needed=%d",
  4570. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
  4571. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
  4572. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
  4573. start_dpc,
  4574. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
  4575. ql_dbg(ql_dbg_timer, vha, 0x600c,
  4576. "beacon_blink_needed=%d isp_unrecoverable=%d "
  4577. "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
  4578. "relogin_needed=%d, host_ramp_down_needed=%d "
  4579. "host_ramp_up_needed=%d.\n",
  4580. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
  4581. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
  4582. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
  4583. test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
  4584. test_bit(RELOGIN_NEEDED, &vha->dpc_flags),
  4585. test_bit(HOST_RAMP_UP_QUEUE_DEPTH, &vha->dpc_flags),
  4586. test_bit(HOST_RAMP_DOWN_QUEUE_DEPTH, &vha->dpc_flags));
  4587. qla2xxx_wake_dpc(vha);
  4588. }
  4589. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4590. }
  4591. /* Firmware interface routines. */
  4592. #define FW_BLOBS 10
  4593. #define FW_ISP21XX 0
  4594. #define FW_ISP22XX 1
  4595. #define FW_ISP2300 2
  4596. #define FW_ISP2322 3
  4597. #define FW_ISP24XX 4
  4598. #define FW_ISP25XX 5
  4599. #define FW_ISP81XX 6
  4600. #define FW_ISP82XX 7
  4601. #define FW_ISP2031 8
  4602. #define FW_ISP8031 9
  4603. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  4604. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  4605. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  4606. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  4607. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  4608. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  4609. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  4610. #define FW_FILE_ISP82XX "ql8200_fw.bin"
  4611. #define FW_FILE_ISP2031 "ql2600_fw.bin"
  4612. #define FW_FILE_ISP8031 "ql8300_fw.bin"
  4613. static DEFINE_MUTEX(qla_fw_lock);
  4614. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  4615. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  4616. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  4617. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  4618. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  4619. { .name = FW_FILE_ISP24XX, },
  4620. { .name = FW_FILE_ISP25XX, },
  4621. { .name = FW_FILE_ISP81XX, },
  4622. { .name = FW_FILE_ISP82XX, },
  4623. { .name = FW_FILE_ISP2031, },
  4624. { .name = FW_FILE_ISP8031, },
  4625. };
  4626. struct fw_blob *
  4627. qla2x00_request_firmware(scsi_qla_host_t *vha)
  4628. {
  4629. struct qla_hw_data *ha = vha->hw;
  4630. struct fw_blob *blob;
  4631. if (IS_QLA2100(ha)) {
  4632. blob = &qla_fw_blobs[FW_ISP21XX];
  4633. } else if (IS_QLA2200(ha)) {
  4634. blob = &qla_fw_blobs[FW_ISP22XX];
  4635. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  4636. blob = &qla_fw_blobs[FW_ISP2300];
  4637. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  4638. blob = &qla_fw_blobs[FW_ISP2322];
  4639. } else if (IS_QLA24XX_TYPE(ha)) {
  4640. blob = &qla_fw_blobs[FW_ISP24XX];
  4641. } else if (IS_QLA25XX(ha)) {
  4642. blob = &qla_fw_blobs[FW_ISP25XX];
  4643. } else if (IS_QLA81XX(ha)) {
  4644. blob = &qla_fw_blobs[FW_ISP81XX];
  4645. } else if (IS_QLA82XX(ha)) {
  4646. blob = &qla_fw_blobs[FW_ISP82XX];
  4647. } else if (IS_QLA2031(ha)) {
  4648. blob = &qla_fw_blobs[FW_ISP2031];
  4649. } else if (IS_QLA8031(ha)) {
  4650. blob = &qla_fw_blobs[FW_ISP8031];
  4651. } else {
  4652. return NULL;
  4653. }
  4654. mutex_lock(&qla_fw_lock);
  4655. if (blob->fw)
  4656. goto out;
  4657. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  4658. ql_log(ql_log_warn, vha, 0x0063,
  4659. "Failed to load firmware image (%s).\n", blob->name);
  4660. blob->fw = NULL;
  4661. blob = NULL;
  4662. goto out;
  4663. }
  4664. out:
  4665. mutex_unlock(&qla_fw_lock);
  4666. return blob;
  4667. }
  4668. static void
  4669. qla2x00_release_firmware(void)
  4670. {
  4671. int idx;
  4672. mutex_lock(&qla_fw_lock);
  4673. for (idx = 0; idx < FW_BLOBS; idx++)
  4674. release_firmware(qla_fw_blobs[idx].fw);
  4675. mutex_unlock(&qla_fw_lock);
  4676. }
  4677. static pci_ers_result_t
  4678. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  4679. {
  4680. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  4681. struct qla_hw_data *ha = vha->hw;
  4682. ql_dbg(ql_dbg_aer, vha, 0x9000,
  4683. "PCI error detected, state %x.\n", state);
  4684. switch (state) {
  4685. case pci_channel_io_normal:
  4686. ha->flags.eeh_busy = 0;
  4687. return PCI_ERS_RESULT_CAN_RECOVER;
  4688. case pci_channel_io_frozen:
  4689. ha->flags.eeh_busy = 1;
  4690. /* For ISP82XX complete any pending mailbox cmd */
  4691. if (IS_QLA82XX(ha)) {
  4692. ha->flags.isp82xx_fw_hung = 1;
  4693. ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
  4694. qla82xx_clear_pending_mbx(vha);
  4695. }
  4696. qla2x00_free_irqs(vha);
  4697. pci_disable_device(pdev);
  4698. /* Return back all IOs */
  4699. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  4700. return PCI_ERS_RESULT_NEED_RESET;
  4701. case pci_channel_io_perm_failure:
  4702. ha->flags.pci_channel_io_perm_failure = 1;
  4703. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  4704. return PCI_ERS_RESULT_DISCONNECT;
  4705. }
  4706. return PCI_ERS_RESULT_NEED_RESET;
  4707. }
  4708. static pci_ers_result_t
  4709. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  4710. {
  4711. int risc_paused = 0;
  4712. uint32_t stat;
  4713. unsigned long flags;
  4714. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4715. struct qla_hw_data *ha = base_vha->hw;
  4716. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4717. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  4718. if (IS_QLA82XX(ha))
  4719. return PCI_ERS_RESULT_RECOVERED;
  4720. spin_lock_irqsave(&ha->hardware_lock, flags);
  4721. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  4722. stat = RD_REG_DWORD(&reg->hccr);
  4723. if (stat & HCCR_RISC_PAUSE)
  4724. risc_paused = 1;
  4725. } else if (IS_QLA23XX(ha)) {
  4726. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  4727. if (stat & HSR_RISC_PAUSED)
  4728. risc_paused = 1;
  4729. } else if (IS_FWI2_CAPABLE(ha)) {
  4730. stat = RD_REG_DWORD(&reg24->host_status);
  4731. if (stat & HSRX_RISC_PAUSED)
  4732. risc_paused = 1;
  4733. }
  4734. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4735. if (risc_paused) {
  4736. ql_log(ql_log_info, base_vha, 0x9003,
  4737. "RISC paused -- mmio_enabled, Dumping firmware.\n");
  4738. ha->isp_ops->fw_dump(base_vha, 0);
  4739. return PCI_ERS_RESULT_NEED_RESET;
  4740. } else
  4741. return PCI_ERS_RESULT_RECOVERED;
  4742. }
  4743. static uint32_t
  4744. qla82xx_error_recovery(scsi_qla_host_t *base_vha)
  4745. {
  4746. uint32_t rval = QLA_FUNCTION_FAILED;
  4747. uint32_t drv_active = 0;
  4748. struct qla_hw_data *ha = base_vha->hw;
  4749. int fn;
  4750. struct pci_dev *other_pdev = NULL;
  4751. ql_dbg(ql_dbg_aer, base_vha, 0x9006,
  4752. "Entered %s.\n", __func__);
  4753. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4754. if (base_vha->flags.online) {
  4755. /* Abort all outstanding commands,
  4756. * so as to be requeued later */
  4757. qla2x00_abort_isp_cleanup(base_vha);
  4758. }
  4759. fn = PCI_FUNC(ha->pdev->devfn);
  4760. while (fn > 0) {
  4761. fn--;
  4762. ql_dbg(ql_dbg_aer, base_vha, 0x9007,
  4763. "Finding pci device at function = 0x%x.\n", fn);
  4764. other_pdev =
  4765. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  4766. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  4767. fn));
  4768. if (!other_pdev)
  4769. continue;
  4770. if (atomic_read(&other_pdev->enable_cnt)) {
  4771. ql_dbg(ql_dbg_aer, base_vha, 0x9008,
  4772. "Found PCI func available and enable at 0x%x.\n",
  4773. fn);
  4774. pci_dev_put(other_pdev);
  4775. break;
  4776. }
  4777. pci_dev_put(other_pdev);
  4778. }
  4779. if (!fn) {
  4780. /* Reset owner */
  4781. ql_dbg(ql_dbg_aer, base_vha, 0x9009,
  4782. "This devfn is reset owner = 0x%x.\n",
  4783. ha->pdev->devfn);
  4784. qla82xx_idc_lock(ha);
  4785. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4786. QLA8XXX_DEV_INITIALIZING);
  4787. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  4788. QLA82XX_IDC_VERSION);
  4789. drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  4790. ql_dbg(ql_dbg_aer, base_vha, 0x900a,
  4791. "drv_active = 0x%x.\n", drv_active);
  4792. qla82xx_idc_unlock(ha);
  4793. /* Reset if device is not already reset
  4794. * drv_active would be 0 if a reset has already been done
  4795. */
  4796. if (drv_active)
  4797. rval = qla82xx_start_firmware(base_vha);
  4798. else
  4799. rval = QLA_SUCCESS;
  4800. qla82xx_idc_lock(ha);
  4801. if (rval != QLA_SUCCESS) {
  4802. ql_log(ql_log_info, base_vha, 0x900b,
  4803. "HW State: FAILED.\n");
  4804. qla82xx_clear_drv_active(ha);
  4805. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4806. QLA8XXX_DEV_FAILED);
  4807. } else {
  4808. ql_log(ql_log_info, base_vha, 0x900c,
  4809. "HW State: READY.\n");
  4810. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4811. QLA8XXX_DEV_READY);
  4812. qla82xx_idc_unlock(ha);
  4813. ha->flags.isp82xx_fw_hung = 0;
  4814. rval = qla82xx_restart_isp(base_vha);
  4815. qla82xx_idc_lock(ha);
  4816. /* Clear driver state register */
  4817. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  4818. qla82xx_set_drv_active(base_vha);
  4819. }
  4820. qla82xx_idc_unlock(ha);
  4821. } else {
  4822. ql_dbg(ql_dbg_aer, base_vha, 0x900d,
  4823. "This devfn is not reset owner = 0x%x.\n",
  4824. ha->pdev->devfn);
  4825. if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  4826. QLA8XXX_DEV_READY)) {
  4827. ha->flags.isp82xx_fw_hung = 0;
  4828. rval = qla82xx_restart_isp(base_vha);
  4829. qla82xx_idc_lock(ha);
  4830. qla82xx_set_drv_active(base_vha);
  4831. qla82xx_idc_unlock(ha);
  4832. }
  4833. }
  4834. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4835. return rval;
  4836. }
  4837. static pci_ers_result_t
  4838. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  4839. {
  4840. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  4841. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4842. struct qla_hw_data *ha = base_vha->hw;
  4843. struct rsp_que *rsp;
  4844. int rc, retries = 10;
  4845. ql_dbg(ql_dbg_aer, base_vha, 0x9004,
  4846. "Slot Reset.\n");
  4847. /* Workaround: qla2xxx driver which access hardware earlier
  4848. * needs error state to be pci_channel_io_online.
  4849. * Otherwise mailbox command timesout.
  4850. */
  4851. pdev->error_state = pci_channel_io_normal;
  4852. pci_restore_state(pdev);
  4853. /* pci_restore_state() clears the saved_state flag of the device
  4854. * save restored state which resets saved_state flag
  4855. */
  4856. pci_save_state(pdev);
  4857. if (ha->mem_only)
  4858. rc = pci_enable_device_mem(pdev);
  4859. else
  4860. rc = pci_enable_device(pdev);
  4861. if (rc) {
  4862. ql_log(ql_log_warn, base_vha, 0x9005,
  4863. "Can't re-enable PCI device after reset.\n");
  4864. goto exit_slot_reset;
  4865. }
  4866. rsp = ha->rsp_q_map[0];
  4867. if (qla2x00_request_irqs(ha, rsp))
  4868. goto exit_slot_reset;
  4869. if (ha->isp_ops->pci_config(base_vha))
  4870. goto exit_slot_reset;
  4871. if (IS_QLA82XX(ha)) {
  4872. if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
  4873. ret = PCI_ERS_RESULT_RECOVERED;
  4874. goto exit_slot_reset;
  4875. } else
  4876. goto exit_slot_reset;
  4877. }
  4878. while (ha->flags.mbox_busy && retries--)
  4879. msleep(1000);
  4880. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4881. if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
  4882. ret = PCI_ERS_RESULT_RECOVERED;
  4883. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  4884. exit_slot_reset:
  4885. ql_dbg(ql_dbg_aer, base_vha, 0x900e,
  4886. "slot_reset return %x.\n", ret);
  4887. return ret;
  4888. }
  4889. static void
  4890. qla2xxx_pci_resume(struct pci_dev *pdev)
  4891. {
  4892. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  4893. struct qla_hw_data *ha = base_vha->hw;
  4894. int ret;
  4895. ql_dbg(ql_dbg_aer, base_vha, 0x900f,
  4896. "pci_resume.\n");
  4897. ret = qla2x00_wait_for_hba_online(base_vha);
  4898. if (ret != QLA_SUCCESS) {
  4899. ql_log(ql_log_fatal, base_vha, 0x9002,
  4900. "The device failed to resume I/O from slot/link_reset.\n");
  4901. }
  4902. pci_cleanup_aer_uncorrect_error_status(pdev);
  4903. ha->flags.eeh_busy = 0;
  4904. }
  4905. static const struct pci_error_handlers qla2xxx_err_handler = {
  4906. .error_detected = qla2xxx_pci_error_detected,
  4907. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  4908. .slot_reset = qla2xxx_pci_slot_reset,
  4909. .resume = qla2xxx_pci_resume,
  4910. };
  4911. static struct pci_device_id qla2xxx_pci_tbl[] = {
  4912. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  4913. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  4914. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  4915. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  4916. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  4917. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  4918. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  4919. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  4920. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  4921. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  4922. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  4923. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  4924. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  4925. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
  4926. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  4927. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
  4928. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
  4929. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
  4930. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
  4931. { 0 },
  4932. };
  4933. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  4934. static struct pci_driver qla2xxx_pci_driver = {
  4935. .name = QLA2XXX_DRIVER_NAME,
  4936. .driver = {
  4937. .owner = THIS_MODULE,
  4938. },
  4939. .id_table = qla2xxx_pci_tbl,
  4940. .probe = qla2x00_probe_one,
  4941. .remove = qla2x00_remove_one,
  4942. .shutdown = qla2x00_shutdown,
  4943. .err_handler = &qla2xxx_err_handler,
  4944. };
  4945. static const struct file_operations apidev_fops = {
  4946. .owner = THIS_MODULE,
  4947. .llseek = noop_llseek,
  4948. };
  4949. /**
  4950. * qla2x00_module_init - Module initialization.
  4951. **/
  4952. static int __init
  4953. qla2x00_module_init(void)
  4954. {
  4955. int ret = 0;
  4956. /* Allocate cache for SRBs. */
  4957. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  4958. SLAB_HWCACHE_ALIGN, NULL);
  4959. if (srb_cachep == NULL) {
  4960. ql_log(ql_log_fatal, NULL, 0x0001,
  4961. "Unable to allocate SRB cache...Failing load!.\n");
  4962. return -ENOMEM;
  4963. }
  4964. /* Initialize target kmem_cache and mem_pools */
  4965. ret = qlt_init();
  4966. if (ret < 0) {
  4967. kmem_cache_destroy(srb_cachep);
  4968. return ret;
  4969. } else if (ret > 0) {
  4970. /*
  4971. * If initiator mode is explictly disabled by qlt_init(),
  4972. * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
  4973. * performing scsi_scan_target() during LOOP UP event.
  4974. */
  4975. qla2xxx_transport_functions.disable_target_scan = 1;
  4976. qla2xxx_transport_vport_functions.disable_target_scan = 1;
  4977. }
  4978. /* Derive version string. */
  4979. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  4980. if (ql2xextended_error_logging)
  4981. strcat(qla2x00_version_str, "-debug");
  4982. qla2xxx_transport_template =
  4983. fc_attach_transport(&qla2xxx_transport_functions);
  4984. if (!qla2xxx_transport_template) {
  4985. kmem_cache_destroy(srb_cachep);
  4986. ql_log(ql_log_fatal, NULL, 0x0002,
  4987. "fc_attach_transport failed...Failing load!.\n");
  4988. qlt_exit();
  4989. return -ENODEV;
  4990. }
  4991. apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
  4992. if (apidev_major < 0) {
  4993. ql_log(ql_log_fatal, NULL, 0x0003,
  4994. "Unable to register char device %s.\n", QLA2XXX_APIDEV);
  4995. }
  4996. qla2xxx_transport_vport_template =
  4997. fc_attach_transport(&qla2xxx_transport_vport_functions);
  4998. if (!qla2xxx_transport_vport_template) {
  4999. kmem_cache_destroy(srb_cachep);
  5000. qlt_exit();
  5001. fc_release_transport(qla2xxx_transport_template);
  5002. ql_log(ql_log_fatal, NULL, 0x0004,
  5003. "fc_attach_transport vport failed...Failing load!.\n");
  5004. return -ENODEV;
  5005. }
  5006. ql_log(ql_log_info, NULL, 0x0005,
  5007. "QLogic Fibre Channel HBA Driver: %s.\n",
  5008. qla2x00_version_str);
  5009. ret = pci_register_driver(&qla2xxx_pci_driver);
  5010. if (ret) {
  5011. kmem_cache_destroy(srb_cachep);
  5012. qlt_exit();
  5013. fc_release_transport(qla2xxx_transport_template);
  5014. fc_release_transport(qla2xxx_transport_vport_template);
  5015. ql_log(ql_log_fatal, NULL, 0x0006,
  5016. "pci_register_driver failed...ret=%d Failing load!.\n",
  5017. ret);
  5018. }
  5019. return ret;
  5020. }
  5021. /**
  5022. * qla2x00_module_exit - Module cleanup.
  5023. **/
  5024. static void __exit
  5025. qla2x00_module_exit(void)
  5026. {
  5027. unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
  5028. pci_unregister_driver(&qla2xxx_pci_driver);
  5029. qla2x00_release_firmware();
  5030. kmem_cache_destroy(srb_cachep);
  5031. qlt_exit();
  5032. if (ctx_cachep)
  5033. kmem_cache_destroy(ctx_cachep);
  5034. fc_release_transport(qla2xxx_transport_template);
  5035. fc_release_transport(qla2xxx_transport_vport_template);
  5036. }
  5037. module_init(qla2x00_module_init);
  5038. module_exit(qla2x00_module_exit);
  5039. MODULE_AUTHOR("QLogic Corporation");
  5040. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  5041. MODULE_LICENSE("GPL");
  5042. MODULE_VERSION(QLA2XXX_VERSION);
  5043. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  5044. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  5045. MODULE_FIRMWARE(FW_FILE_ISP2300);
  5046. MODULE_FIRMWARE(FW_FILE_ISP2322);
  5047. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  5048. MODULE_FIRMWARE(FW_FILE_ISP25XX);