qla_os.c 144 KB

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