pm8001_hwi.c 144 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504
  1. /*
  2. * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
  3. *
  4. * Copyright (c) 2008-2009 USI Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions, and the following disclaimer,
  12. * without modification.
  13. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  14. * substantially similar to the "NO WARRANTY" disclaimer below
  15. * ("Disclaimer") and any redistribution must be conditioned upon
  16. * including a substantially similar Disclaimer requirement for further
  17. * binary redistribution.
  18. * 3. Neither the names of the above-listed copyright holders nor the names
  19. * of any contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * Alternatively, this software may be distributed under the terms of the
  23. * GNU General Public License ("GPL") version 2 as published by the Free
  24. * Software Foundation.
  25. *
  26. * NO WARRANTY
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  36. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGES.
  38. *
  39. */
  40. #include <linux/slab.h>
  41. #include "pm8001_sas.h"
  42. #include "pm8001_hwi.h"
  43. #include "pm8001_chips.h"
  44. #include "pm8001_ctl.h"
  45. /**
  46. * read_main_config_table - read the configure table and save it.
  47. * @pm8001_ha: our hba card information
  48. */
  49. static void __devinit read_main_config_table(struct pm8001_hba_info *pm8001_ha)
  50. {
  51. void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
  52. pm8001_ha->main_cfg_tbl.signature = pm8001_mr32(address, 0x00);
  53. pm8001_ha->main_cfg_tbl.interface_rev = pm8001_mr32(address, 0x04);
  54. pm8001_ha->main_cfg_tbl.firmware_rev = pm8001_mr32(address, 0x08);
  55. pm8001_ha->main_cfg_tbl.max_out_io = pm8001_mr32(address, 0x0C);
  56. pm8001_ha->main_cfg_tbl.max_sgl = pm8001_mr32(address, 0x10);
  57. pm8001_ha->main_cfg_tbl.ctrl_cap_flag = pm8001_mr32(address, 0x14);
  58. pm8001_ha->main_cfg_tbl.gst_offset = pm8001_mr32(address, 0x18);
  59. pm8001_ha->main_cfg_tbl.inbound_queue_offset =
  60. pm8001_mr32(address, MAIN_IBQ_OFFSET);
  61. pm8001_ha->main_cfg_tbl.outbound_queue_offset =
  62. pm8001_mr32(address, MAIN_OBQ_OFFSET);
  63. pm8001_ha->main_cfg_tbl.hda_mode_flag =
  64. pm8001_mr32(address, MAIN_HDA_FLAGS_OFFSET);
  65. /* read analog Setting offset from the configuration table */
  66. pm8001_ha->main_cfg_tbl.anolog_setup_table_offset =
  67. pm8001_mr32(address, MAIN_ANALOG_SETUP_OFFSET);
  68. /* read Error Dump Offset and Length */
  69. pm8001_ha->main_cfg_tbl.fatal_err_dump_offset0 =
  70. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_OFFSET);
  71. pm8001_ha->main_cfg_tbl.fatal_err_dump_length0 =
  72. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP0_LENGTH);
  73. pm8001_ha->main_cfg_tbl.fatal_err_dump_offset1 =
  74. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_OFFSET);
  75. pm8001_ha->main_cfg_tbl.fatal_err_dump_length1 =
  76. pm8001_mr32(address, MAIN_FATAL_ERROR_RDUMP1_LENGTH);
  77. }
  78. /**
  79. * read_general_status_table - read the general status table and save it.
  80. * @pm8001_ha: our hba card information
  81. */
  82. static void __devinit
  83. read_general_status_table(struct pm8001_hba_info *pm8001_ha)
  84. {
  85. void __iomem *address = pm8001_ha->general_stat_tbl_addr;
  86. pm8001_ha->gs_tbl.gst_len_mpistate = pm8001_mr32(address, 0x00);
  87. pm8001_ha->gs_tbl.iq_freeze_state0 = pm8001_mr32(address, 0x04);
  88. pm8001_ha->gs_tbl.iq_freeze_state1 = pm8001_mr32(address, 0x08);
  89. pm8001_ha->gs_tbl.msgu_tcnt = pm8001_mr32(address, 0x0C);
  90. pm8001_ha->gs_tbl.iop_tcnt = pm8001_mr32(address, 0x10);
  91. pm8001_ha->gs_tbl.reserved = pm8001_mr32(address, 0x14);
  92. pm8001_ha->gs_tbl.phy_state[0] = pm8001_mr32(address, 0x18);
  93. pm8001_ha->gs_tbl.phy_state[1] = pm8001_mr32(address, 0x1C);
  94. pm8001_ha->gs_tbl.phy_state[2] = pm8001_mr32(address, 0x20);
  95. pm8001_ha->gs_tbl.phy_state[3] = pm8001_mr32(address, 0x24);
  96. pm8001_ha->gs_tbl.phy_state[4] = pm8001_mr32(address, 0x28);
  97. pm8001_ha->gs_tbl.phy_state[5] = pm8001_mr32(address, 0x2C);
  98. pm8001_ha->gs_tbl.phy_state[6] = pm8001_mr32(address, 0x30);
  99. pm8001_ha->gs_tbl.phy_state[7] = pm8001_mr32(address, 0x34);
  100. pm8001_ha->gs_tbl.reserved1 = pm8001_mr32(address, 0x38);
  101. pm8001_ha->gs_tbl.reserved2 = pm8001_mr32(address, 0x3C);
  102. pm8001_ha->gs_tbl.reserved3 = pm8001_mr32(address, 0x40);
  103. pm8001_ha->gs_tbl.recover_err_info[0] = pm8001_mr32(address, 0x44);
  104. pm8001_ha->gs_tbl.recover_err_info[1] = pm8001_mr32(address, 0x48);
  105. pm8001_ha->gs_tbl.recover_err_info[2] = pm8001_mr32(address, 0x4C);
  106. pm8001_ha->gs_tbl.recover_err_info[3] = pm8001_mr32(address, 0x50);
  107. pm8001_ha->gs_tbl.recover_err_info[4] = pm8001_mr32(address, 0x54);
  108. pm8001_ha->gs_tbl.recover_err_info[5] = pm8001_mr32(address, 0x58);
  109. pm8001_ha->gs_tbl.recover_err_info[6] = pm8001_mr32(address, 0x5C);
  110. pm8001_ha->gs_tbl.recover_err_info[7] = pm8001_mr32(address, 0x60);
  111. }
  112. /**
  113. * read_inbnd_queue_table - read the inbound queue table and save it.
  114. * @pm8001_ha: our hba card information
  115. */
  116. static void __devinit
  117. read_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
  118. {
  119. int inbQ_num = 1;
  120. int i;
  121. void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
  122. for (i = 0; i < inbQ_num; i++) {
  123. u32 offset = i * 0x20;
  124. pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
  125. get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
  126. pm8001_ha->inbnd_q_tbl[i].pi_offset =
  127. pm8001_mr32(address, (offset + 0x18));
  128. }
  129. }
  130. /**
  131. * read_outbnd_queue_table - read the outbound queue table and save it.
  132. * @pm8001_ha: our hba card information
  133. */
  134. static void __devinit
  135. read_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha)
  136. {
  137. int outbQ_num = 1;
  138. int i;
  139. void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
  140. for (i = 0; i < outbQ_num; i++) {
  141. u32 offset = i * 0x24;
  142. pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
  143. get_pci_bar_index(pm8001_mr32(address, (offset + 0x14)));
  144. pm8001_ha->outbnd_q_tbl[i].ci_offset =
  145. pm8001_mr32(address, (offset + 0x18));
  146. }
  147. }
  148. /**
  149. * init_default_table_values - init the default table.
  150. * @pm8001_ha: our hba card information
  151. */
  152. static void __devinit
  153. init_default_table_values(struct pm8001_hba_info *pm8001_ha)
  154. {
  155. int qn = 1;
  156. int i;
  157. u32 offsetib, offsetob;
  158. void __iomem *addressib = pm8001_ha->inbnd_q_tbl_addr;
  159. void __iomem *addressob = pm8001_ha->outbnd_q_tbl_addr;
  160. pm8001_ha->main_cfg_tbl.inbound_q_nppd_hppd = 0;
  161. pm8001_ha->main_cfg_tbl.outbound_hw_event_pid0_3 = 0;
  162. pm8001_ha->main_cfg_tbl.outbound_hw_event_pid4_7 = 0;
  163. pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid0_3 = 0;
  164. pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid4_7 = 0;
  165. pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid0_3 = 0;
  166. pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid4_7 = 0;
  167. pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid0_3 = 0;
  168. pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid4_7 = 0;
  169. pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid0_3 = 0;
  170. pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid4_7 = 0;
  171. pm8001_ha->main_cfg_tbl.upper_event_log_addr =
  172. pm8001_ha->memoryMap.region[AAP1].phys_addr_hi;
  173. pm8001_ha->main_cfg_tbl.lower_event_log_addr =
  174. pm8001_ha->memoryMap.region[AAP1].phys_addr_lo;
  175. pm8001_ha->main_cfg_tbl.event_log_size = PM8001_EVENT_LOG_SIZE;
  176. pm8001_ha->main_cfg_tbl.event_log_option = 0x01;
  177. pm8001_ha->main_cfg_tbl.upper_iop_event_log_addr =
  178. pm8001_ha->memoryMap.region[IOP].phys_addr_hi;
  179. pm8001_ha->main_cfg_tbl.lower_iop_event_log_addr =
  180. pm8001_ha->memoryMap.region[IOP].phys_addr_lo;
  181. pm8001_ha->main_cfg_tbl.iop_event_log_size = PM8001_EVENT_LOG_SIZE;
  182. pm8001_ha->main_cfg_tbl.iop_event_log_option = 0x01;
  183. pm8001_ha->main_cfg_tbl.fatal_err_interrupt = 0x01;
  184. for (i = 0; i < qn; i++) {
  185. pm8001_ha->inbnd_q_tbl[i].element_pri_size_cnt =
  186. 0x00000100 | (0x00000040 << 16) | (0x00<<30);
  187. pm8001_ha->inbnd_q_tbl[i].upper_base_addr =
  188. pm8001_ha->memoryMap.region[IB].phys_addr_hi;
  189. pm8001_ha->inbnd_q_tbl[i].lower_base_addr =
  190. pm8001_ha->memoryMap.region[IB].phys_addr_lo;
  191. pm8001_ha->inbnd_q_tbl[i].base_virt =
  192. (u8 *)pm8001_ha->memoryMap.region[IB].virt_ptr;
  193. pm8001_ha->inbnd_q_tbl[i].total_length =
  194. pm8001_ha->memoryMap.region[IB].total_len;
  195. pm8001_ha->inbnd_q_tbl[i].ci_upper_base_addr =
  196. pm8001_ha->memoryMap.region[CI].phys_addr_hi;
  197. pm8001_ha->inbnd_q_tbl[i].ci_lower_base_addr =
  198. pm8001_ha->memoryMap.region[CI].phys_addr_lo;
  199. pm8001_ha->inbnd_q_tbl[i].ci_virt =
  200. pm8001_ha->memoryMap.region[CI].virt_ptr;
  201. offsetib = i * 0x20;
  202. pm8001_ha->inbnd_q_tbl[i].pi_pci_bar =
  203. get_pci_bar_index(pm8001_mr32(addressib,
  204. (offsetib + 0x14)));
  205. pm8001_ha->inbnd_q_tbl[i].pi_offset =
  206. pm8001_mr32(addressib, (offsetib + 0x18));
  207. pm8001_ha->inbnd_q_tbl[i].producer_idx = 0;
  208. pm8001_ha->inbnd_q_tbl[i].consumer_index = 0;
  209. }
  210. for (i = 0; i < qn; i++) {
  211. pm8001_ha->outbnd_q_tbl[i].element_size_cnt =
  212. 256 | (64 << 16) | (1<<30);
  213. pm8001_ha->outbnd_q_tbl[i].upper_base_addr =
  214. pm8001_ha->memoryMap.region[OB].phys_addr_hi;
  215. pm8001_ha->outbnd_q_tbl[i].lower_base_addr =
  216. pm8001_ha->memoryMap.region[OB].phys_addr_lo;
  217. pm8001_ha->outbnd_q_tbl[i].base_virt =
  218. (u8 *)pm8001_ha->memoryMap.region[OB].virt_ptr;
  219. pm8001_ha->outbnd_q_tbl[i].total_length =
  220. pm8001_ha->memoryMap.region[OB].total_len;
  221. pm8001_ha->outbnd_q_tbl[i].pi_upper_base_addr =
  222. pm8001_ha->memoryMap.region[PI].phys_addr_hi;
  223. pm8001_ha->outbnd_q_tbl[i].pi_lower_base_addr =
  224. pm8001_ha->memoryMap.region[PI].phys_addr_lo;
  225. pm8001_ha->outbnd_q_tbl[i].interrup_vec_cnt_delay =
  226. 0 | (10 << 16) | (0 << 24);
  227. pm8001_ha->outbnd_q_tbl[i].pi_virt =
  228. pm8001_ha->memoryMap.region[PI].virt_ptr;
  229. offsetob = i * 0x24;
  230. pm8001_ha->outbnd_q_tbl[i].ci_pci_bar =
  231. get_pci_bar_index(pm8001_mr32(addressob,
  232. offsetob + 0x14));
  233. pm8001_ha->outbnd_q_tbl[i].ci_offset =
  234. pm8001_mr32(addressob, (offsetob + 0x18));
  235. pm8001_ha->outbnd_q_tbl[i].consumer_idx = 0;
  236. pm8001_ha->outbnd_q_tbl[i].producer_index = 0;
  237. }
  238. }
  239. /**
  240. * update_main_config_table - update the main default table to the HBA.
  241. * @pm8001_ha: our hba card information
  242. */
  243. static void __devinit
  244. update_main_config_table(struct pm8001_hba_info *pm8001_ha)
  245. {
  246. void __iomem *address = pm8001_ha->main_cfg_tbl_addr;
  247. pm8001_mw32(address, 0x24,
  248. pm8001_ha->main_cfg_tbl.inbound_q_nppd_hppd);
  249. pm8001_mw32(address, 0x28,
  250. pm8001_ha->main_cfg_tbl.outbound_hw_event_pid0_3);
  251. pm8001_mw32(address, 0x2C,
  252. pm8001_ha->main_cfg_tbl.outbound_hw_event_pid4_7);
  253. pm8001_mw32(address, 0x30,
  254. pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid0_3);
  255. pm8001_mw32(address, 0x34,
  256. pm8001_ha->main_cfg_tbl.outbound_ncq_event_pid4_7);
  257. pm8001_mw32(address, 0x38,
  258. pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid0_3);
  259. pm8001_mw32(address, 0x3C,
  260. pm8001_ha->main_cfg_tbl.outbound_tgt_ITNexus_event_pid4_7);
  261. pm8001_mw32(address, 0x40,
  262. pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid0_3);
  263. pm8001_mw32(address, 0x44,
  264. pm8001_ha->main_cfg_tbl.outbound_tgt_ssp_event_pid4_7);
  265. pm8001_mw32(address, 0x48,
  266. pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid0_3);
  267. pm8001_mw32(address, 0x4C,
  268. pm8001_ha->main_cfg_tbl.outbound_tgt_smp_event_pid4_7);
  269. pm8001_mw32(address, 0x50,
  270. pm8001_ha->main_cfg_tbl.upper_event_log_addr);
  271. pm8001_mw32(address, 0x54,
  272. pm8001_ha->main_cfg_tbl.lower_event_log_addr);
  273. pm8001_mw32(address, 0x58, pm8001_ha->main_cfg_tbl.event_log_size);
  274. pm8001_mw32(address, 0x5C, pm8001_ha->main_cfg_tbl.event_log_option);
  275. pm8001_mw32(address, 0x60,
  276. pm8001_ha->main_cfg_tbl.upper_iop_event_log_addr);
  277. pm8001_mw32(address, 0x64,
  278. pm8001_ha->main_cfg_tbl.lower_iop_event_log_addr);
  279. pm8001_mw32(address, 0x68, pm8001_ha->main_cfg_tbl.iop_event_log_size);
  280. pm8001_mw32(address, 0x6C,
  281. pm8001_ha->main_cfg_tbl.iop_event_log_option);
  282. pm8001_mw32(address, 0x70,
  283. pm8001_ha->main_cfg_tbl.fatal_err_interrupt);
  284. }
  285. /**
  286. * update_inbnd_queue_table - update the inbound queue table to the HBA.
  287. * @pm8001_ha: our hba card information
  288. */
  289. static void __devinit
  290. update_inbnd_queue_table(struct pm8001_hba_info *pm8001_ha, int number)
  291. {
  292. void __iomem *address = pm8001_ha->inbnd_q_tbl_addr;
  293. u16 offset = number * 0x20;
  294. pm8001_mw32(address, offset + 0x00,
  295. pm8001_ha->inbnd_q_tbl[number].element_pri_size_cnt);
  296. pm8001_mw32(address, offset + 0x04,
  297. pm8001_ha->inbnd_q_tbl[number].upper_base_addr);
  298. pm8001_mw32(address, offset + 0x08,
  299. pm8001_ha->inbnd_q_tbl[number].lower_base_addr);
  300. pm8001_mw32(address, offset + 0x0C,
  301. pm8001_ha->inbnd_q_tbl[number].ci_upper_base_addr);
  302. pm8001_mw32(address, offset + 0x10,
  303. pm8001_ha->inbnd_q_tbl[number].ci_lower_base_addr);
  304. }
  305. /**
  306. * update_outbnd_queue_table - update the outbound queue table to the HBA.
  307. * @pm8001_ha: our hba card information
  308. */
  309. static void __devinit
  310. update_outbnd_queue_table(struct pm8001_hba_info *pm8001_ha, int number)
  311. {
  312. void __iomem *address = pm8001_ha->outbnd_q_tbl_addr;
  313. u16 offset = number * 0x24;
  314. pm8001_mw32(address, offset + 0x00,
  315. pm8001_ha->outbnd_q_tbl[number].element_size_cnt);
  316. pm8001_mw32(address, offset + 0x04,
  317. pm8001_ha->outbnd_q_tbl[number].upper_base_addr);
  318. pm8001_mw32(address, offset + 0x08,
  319. pm8001_ha->outbnd_q_tbl[number].lower_base_addr);
  320. pm8001_mw32(address, offset + 0x0C,
  321. pm8001_ha->outbnd_q_tbl[number].pi_upper_base_addr);
  322. pm8001_mw32(address, offset + 0x10,
  323. pm8001_ha->outbnd_q_tbl[number].pi_lower_base_addr);
  324. pm8001_mw32(address, offset + 0x1C,
  325. pm8001_ha->outbnd_q_tbl[number].interrup_vec_cnt_delay);
  326. }
  327. /**
  328. * bar4_shift - function is called to shift BAR base address
  329. * @pm8001_ha : our hba card information
  330. * @shiftValue : shifting value in memory bar.
  331. */
  332. static int bar4_shift(struct pm8001_hba_info *pm8001_ha, u32 shiftValue)
  333. {
  334. u32 regVal;
  335. u32 max_wait_count;
  336. /* program the inbound AXI translation Lower Address */
  337. pm8001_cw32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW, shiftValue);
  338. /* confirm the setting is written */
  339. max_wait_count = 1 * 1000 * 1000; /* 1 sec */
  340. do {
  341. udelay(1);
  342. regVal = pm8001_cr32(pm8001_ha, 1, SPC_IBW_AXI_TRANSLATION_LOW);
  343. } while ((regVal != shiftValue) && (--max_wait_count));
  344. if (!max_wait_count) {
  345. PM8001_INIT_DBG(pm8001_ha,
  346. pm8001_printk("TIMEOUT:SPC_IBW_AXI_TRANSLATION_LOW"
  347. " = 0x%x\n", regVal));
  348. return -1;
  349. }
  350. return 0;
  351. }
  352. /**
  353. * mpi_set_phys_g3_with_ssc
  354. * @pm8001_ha: our hba card information
  355. * @SSCbit: set SSCbit to 0 to disable all phys ssc; 1 to enable all phys ssc.
  356. */
  357. static void __devinit
  358. mpi_set_phys_g3_with_ssc(struct pm8001_hba_info *pm8001_ha, u32 SSCbit)
  359. {
  360. u32 value, offset, i;
  361. #define SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR 0x00030000
  362. #define SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR 0x00040000
  363. #define SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET 0x1074
  364. #define SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET 0x1074
  365. #define PHY_G3_WITHOUT_SSC_BIT_SHIFT 12
  366. #define PHY_G3_WITH_SSC_BIT_SHIFT 13
  367. #define SNW3_PHY_CAPABILITIES_PARITY 31
  368. /*
  369. * Using shifted destination address 0x3_0000:0x1074 + 0x4000*N (N=0:3)
  370. * Using shifted destination address 0x4_0000:0x1074 + 0x4000*(N-4) (N=4:7)
  371. */
  372. if (-1 == bar4_shift(pm8001_ha, SAS2_SETTINGS_LOCAL_PHY_0_3_SHIFT_ADDR))
  373. return;
  374. for (i = 0; i < 4; i++) {
  375. offset = SAS2_SETTINGS_LOCAL_PHY_0_3_OFFSET + 0x4000 * i;
  376. pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
  377. }
  378. /* shift membase 3 for SAS2_SETTINGS_LOCAL_PHY 4 - 7 */
  379. if (-1 == bar4_shift(pm8001_ha, SAS2_SETTINGS_LOCAL_PHY_4_7_SHIFT_ADDR))
  380. return;
  381. for (i = 4; i < 8; i++) {
  382. offset = SAS2_SETTINGS_LOCAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
  383. pm8001_cw32(pm8001_ha, 2, offset, 0x80001501);
  384. }
  385. /*************************************************************
  386. Change the SSC upspreading value to 0x0 so that upspreading is disabled.
  387. Device MABC SMOD0 Controls
  388. Address: (via MEMBASE-III):
  389. Using shifted destination address 0x0_0000: with Offset 0xD8
  390. 31:28 R/W Reserved Do not change
  391. 27:24 R/W SAS_SMOD_SPRDUP 0000
  392. 23:20 R/W SAS_SMOD_SPRDDN 0000
  393. 19:0 R/W Reserved Do not change
  394. Upon power-up this register will read as 0x8990c016,
  395. and I would like you to change the SAS_SMOD_SPRDUP bits to 0b0000
  396. so that the written value will be 0x8090c016.
  397. This will ensure only down-spreading SSC is enabled on the SPC.
  398. *************************************************************/
  399. value = pm8001_cr32(pm8001_ha, 2, 0xd8);
  400. pm8001_cw32(pm8001_ha, 2, 0xd8, 0x8000C016);
  401. /*set the shifted destination address to 0x0 to avoid error operation */
  402. bar4_shift(pm8001_ha, 0x0);
  403. return;
  404. }
  405. /**
  406. * mpi_set_open_retry_interval_reg
  407. * @pm8001_ha: our hba card information
  408. * @interval - interval time for each OPEN_REJECT (RETRY). The units are in 1us.
  409. */
  410. static void __devinit
  411. mpi_set_open_retry_interval_reg(struct pm8001_hba_info *pm8001_ha,
  412. u32 interval)
  413. {
  414. u32 offset;
  415. u32 value;
  416. u32 i;
  417. #define OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR 0x00030000
  418. #define OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR 0x00040000
  419. #define OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET 0x30B4
  420. #define OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET 0x30B4
  421. #define OPEN_RETRY_INTERVAL_REG_MASK 0x0000FFFF
  422. value = interval & OPEN_RETRY_INTERVAL_REG_MASK;
  423. /* shift bar and set the OPEN_REJECT(RETRY) interval time of PHY 0 -3.*/
  424. if (-1 == bar4_shift(pm8001_ha,
  425. OPEN_RETRY_INTERVAL_PHY_0_3_SHIFT_ADDR))
  426. return;
  427. for (i = 0; i < 4; i++) {
  428. offset = OPEN_RETRY_INTERVAL_PHY_0_3_OFFSET + 0x4000 * i;
  429. pm8001_cw32(pm8001_ha, 2, offset, value);
  430. }
  431. if (-1 == bar4_shift(pm8001_ha,
  432. OPEN_RETRY_INTERVAL_PHY_4_7_SHIFT_ADDR))
  433. return;
  434. for (i = 4; i < 8; i++) {
  435. offset = OPEN_RETRY_INTERVAL_PHY_4_7_OFFSET + 0x4000 * (i-4);
  436. pm8001_cw32(pm8001_ha, 2, offset, value);
  437. }
  438. /*set the shifted destination address to 0x0 to avoid error operation */
  439. bar4_shift(pm8001_ha, 0x0);
  440. return;
  441. }
  442. /**
  443. * mpi_init_check - check firmware initialization status.
  444. * @pm8001_ha: our hba card information
  445. */
  446. static int mpi_init_check(struct pm8001_hba_info *pm8001_ha)
  447. {
  448. u32 max_wait_count;
  449. u32 value;
  450. u32 gst_len_mpistate;
  451. /* Write bit0=1 to Inbound DoorBell Register to tell the SPC FW the
  452. table is updated */
  453. pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_UPDATE);
  454. /* wait until Inbound DoorBell Clear Register toggled */
  455. max_wait_count = 1 * 1000 * 1000;/* 1 sec */
  456. do {
  457. udelay(1);
  458. value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
  459. value &= SPC_MSGU_CFG_TABLE_UPDATE;
  460. } while ((value != 0) && (--max_wait_count));
  461. if (!max_wait_count)
  462. return -1;
  463. /* check the MPI-State for initialization */
  464. gst_len_mpistate =
  465. pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
  466. GST_GSTLEN_MPIS_OFFSET);
  467. if (GST_MPI_STATE_INIT != (gst_len_mpistate & GST_MPI_STATE_MASK))
  468. return -1;
  469. /* check MPI Initialization error */
  470. gst_len_mpistate = gst_len_mpistate >> 16;
  471. if (0x0000 != gst_len_mpistate)
  472. return -1;
  473. return 0;
  474. }
  475. /**
  476. * check_fw_ready - The LLDD check if the FW is ready, if not, return error.
  477. * @pm8001_ha: our hba card information
  478. */
  479. static int check_fw_ready(struct pm8001_hba_info *pm8001_ha)
  480. {
  481. u32 value, value1;
  482. u32 max_wait_count;
  483. /* check error state */
  484. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  485. value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
  486. /* check AAP error */
  487. if (SCRATCH_PAD1_ERR == (value & SCRATCH_PAD_STATE_MASK)) {
  488. /* error state */
  489. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
  490. return -1;
  491. }
  492. /* check IOP error */
  493. if (SCRATCH_PAD2_ERR == (value1 & SCRATCH_PAD_STATE_MASK)) {
  494. /* error state */
  495. value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3);
  496. return -1;
  497. }
  498. /* bit 4-31 of scratch pad1 should be zeros if it is not
  499. in error state*/
  500. if (value & SCRATCH_PAD1_STATE_MASK) {
  501. /* error case */
  502. pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0);
  503. return -1;
  504. }
  505. /* bit 2, 4-31 of scratch pad2 should be zeros if it is not
  506. in error state */
  507. if (value1 & SCRATCH_PAD2_STATE_MASK) {
  508. /* error case */
  509. return -1;
  510. }
  511. max_wait_count = 1 * 1000 * 1000;/* 1 sec timeout */
  512. /* wait until scratch pad 1 and 2 registers in ready state */
  513. do {
  514. udelay(1);
  515. value = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
  516. & SCRATCH_PAD1_RDY;
  517. value1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
  518. & SCRATCH_PAD2_RDY;
  519. if ((--max_wait_count) == 0)
  520. return -1;
  521. } while ((value != SCRATCH_PAD1_RDY) || (value1 != SCRATCH_PAD2_RDY));
  522. return 0;
  523. }
  524. static void init_pci_device_addresses(struct pm8001_hba_info *pm8001_ha)
  525. {
  526. void __iomem *base_addr;
  527. u32 value;
  528. u32 offset;
  529. u32 pcibar;
  530. u32 pcilogic;
  531. value = pm8001_cr32(pm8001_ha, 0, 0x44);
  532. offset = value & 0x03FFFFFF;
  533. PM8001_INIT_DBG(pm8001_ha,
  534. pm8001_printk("Scratchpad 0 Offset: %x \n", offset));
  535. pcilogic = (value & 0xFC000000) >> 26;
  536. pcibar = get_pci_bar_index(pcilogic);
  537. PM8001_INIT_DBG(pm8001_ha,
  538. pm8001_printk("Scratchpad 0 PCI BAR: %d \n", pcibar));
  539. pm8001_ha->main_cfg_tbl_addr = base_addr =
  540. pm8001_ha->io_mem[pcibar].memvirtaddr + offset;
  541. pm8001_ha->general_stat_tbl_addr =
  542. base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x18);
  543. pm8001_ha->inbnd_q_tbl_addr =
  544. base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x1C);
  545. pm8001_ha->outbnd_q_tbl_addr =
  546. base_addr + pm8001_cr32(pm8001_ha, pcibar, offset + 0x20);
  547. }
  548. /**
  549. * pm8001_chip_init - the main init function that initialize whole PM8001 chip.
  550. * @pm8001_ha: our hba card information
  551. */
  552. static int __devinit pm8001_chip_init(struct pm8001_hba_info *pm8001_ha)
  553. {
  554. /* check the firmware status */
  555. if (-1 == check_fw_ready(pm8001_ha)) {
  556. PM8001_FAIL_DBG(pm8001_ha,
  557. pm8001_printk("Firmware is not ready!\n"));
  558. return -EBUSY;
  559. }
  560. /* Initialize pci space address eg: mpi offset */
  561. init_pci_device_addresses(pm8001_ha);
  562. init_default_table_values(pm8001_ha);
  563. read_main_config_table(pm8001_ha);
  564. read_general_status_table(pm8001_ha);
  565. read_inbnd_queue_table(pm8001_ha);
  566. read_outbnd_queue_table(pm8001_ha);
  567. /* update main config table ,inbound table and outbound table */
  568. update_main_config_table(pm8001_ha);
  569. update_inbnd_queue_table(pm8001_ha, 0);
  570. update_outbnd_queue_table(pm8001_ha, 0);
  571. mpi_set_phys_g3_with_ssc(pm8001_ha, 0);
  572. mpi_set_open_retry_interval_reg(pm8001_ha, 7);
  573. /* notify firmware update finished and check initialization status */
  574. if (0 == mpi_init_check(pm8001_ha)) {
  575. PM8001_INIT_DBG(pm8001_ha,
  576. pm8001_printk("MPI initialize successful!\n"));
  577. } else
  578. return -EBUSY;
  579. /*This register is a 16-bit timer with a resolution of 1us. This is the
  580. timer used for interrupt delay/coalescing in the PCIe Application Layer.
  581. Zero is not a valid value. A value of 1 in the register will cause the
  582. interrupts to be normal. A value greater than 1 will cause coalescing
  583. delays.*/
  584. pm8001_cw32(pm8001_ha, 1, 0x0033c0, 0x1);
  585. pm8001_cw32(pm8001_ha, 1, 0x0033c4, 0x0);
  586. return 0;
  587. }
  588. static int mpi_uninit_check(struct pm8001_hba_info *pm8001_ha)
  589. {
  590. u32 max_wait_count;
  591. u32 value;
  592. u32 gst_len_mpistate;
  593. init_pci_device_addresses(pm8001_ha);
  594. /* Write bit1=1 to Inbound DoorBell Register to tell the SPC FW the
  595. table is stop */
  596. pm8001_cw32(pm8001_ha, 0, MSGU_IBDB_SET, SPC_MSGU_CFG_TABLE_RESET);
  597. /* wait until Inbound DoorBell Clear Register toggled */
  598. max_wait_count = 1 * 1000 * 1000;/* 1 sec */
  599. do {
  600. udelay(1);
  601. value = pm8001_cr32(pm8001_ha, 0, MSGU_IBDB_SET);
  602. value &= SPC_MSGU_CFG_TABLE_RESET;
  603. } while ((value != 0) && (--max_wait_count));
  604. if (!max_wait_count) {
  605. PM8001_FAIL_DBG(pm8001_ha,
  606. pm8001_printk("TIMEOUT:IBDB value/=0x%x\n", value));
  607. return -1;
  608. }
  609. /* check the MPI-State for termination in progress */
  610. /* wait until Inbound DoorBell Clear Register toggled */
  611. max_wait_count = 1 * 1000 * 1000; /* 1 sec */
  612. do {
  613. udelay(1);
  614. gst_len_mpistate =
  615. pm8001_mr32(pm8001_ha->general_stat_tbl_addr,
  616. GST_GSTLEN_MPIS_OFFSET);
  617. if (GST_MPI_STATE_UNINIT ==
  618. (gst_len_mpistate & GST_MPI_STATE_MASK))
  619. break;
  620. } while (--max_wait_count);
  621. if (!max_wait_count) {
  622. PM8001_FAIL_DBG(pm8001_ha,
  623. pm8001_printk(" TIME OUT MPI State = 0x%x\n",
  624. gst_len_mpistate & GST_MPI_STATE_MASK));
  625. return -1;
  626. }
  627. return 0;
  628. }
  629. /**
  630. * soft_reset_ready_check - Function to check FW is ready for soft reset.
  631. * @pm8001_ha: our hba card information
  632. */
  633. static u32 soft_reset_ready_check(struct pm8001_hba_info *pm8001_ha)
  634. {
  635. u32 regVal, regVal1, regVal2;
  636. if (mpi_uninit_check(pm8001_ha) != 0) {
  637. PM8001_FAIL_DBG(pm8001_ha,
  638. pm8001_printk("MPI state is not ready\n"));
  639. return -1;
  640. }
  641. /* read the scratch pad 2 register bit 2 */
  642. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2)
  643. & SCRATCH_PAD2_FWRDY_RST;
  644. if (regVal == SCRATCH_PAD2_FWRDY_RST) {
  645. PM8001_INIT_DBG(pm8001_ha,
  646. pm8001_printk("Firmware is ready for reset .\n"));
  647. } else {
  648. /* Trigger NMI twice via RB6 */
  649. if (-1 == bar4_shift(pm8001_ha, RB6_ACCESS_REG)) {
  650. PM8001_FAIL_DBG(pm8001_ha,
  651. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  652. RB6_ACCESS_REG));
  653. return -1;
  654. }
  655. pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET,
  656. RB6_MAGIC_NUMBER_RST);
  657. pm8001_cw32(pm8001_ha, 2, SPC_RB6_OFFSET, RB6_MAGIC_NUMBER_RST);
  658. /* wait for 100 ms */
  659. mdelay(100);
  660. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2) &
  661. SCRATCH_PAD2_FWRDY_RST;
  662. if (regVal != SCRATCH_PAD2_FWRDY_RST) {
  663. regVal1 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  664. regVal2 = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
  665. PM8001_FAIL_DBG(pm8001_ha,
  666. pm8001_printk("TIMEOUT:MSGU_SCRATCH_PAD1"
  667. "=0x%x, MSGU_SCRATCH_PAD2=0x%x\n",
  668. regVal1, regVal2));
  669. PM8001_FAIL_DBG(pm8001_ha,
  670. pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
  671. pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_0)));
  672. PM8001_FAIL_DBG(pm8001_ha,
  673. pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
  674. pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_3)));
  675. return -1;
  676. }
  677. }
  678. return 0;
  679. }
  680. /**
  681. * pm8001_chip_soft_rst - soft reset the PM8001 chip, so that the clear all
  682. * the FW register status to the originated status.
  683. * @pm8001_ha: our hba card information
  684. * @signature: signature in host scratch pad0 register.
  685. */
  686. static int
  687. pm8001_chip_soft_rst(struct pm8001_hba_info *pm8001_ha, u32 signature)
  688. {
  689. u32 regVal, toggleVal;
  690. u32 max_wait_count;
  691. u32 regVal1, regVal2, regVal3;
  692. /* step1: Check FW is ready for soft reset */
  693. if (soft_reset_ready_check(pm8001_ha) != 0) {
  694. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("FW is not ready\n"));
  695. return -1;
  696. }
  697. /* step 2: clear NMI status register on AAP1 and IOP, write the same
  698. value to clear */
  699. /* map 0x60000 to BAR4(0x20), BAR2(win) */
  700. if (-1 == bar4_shift(pm8001_ha, MBIC_AAP1_ADDR_BASE)) {
  701. PM8001_FAIL_DBG(pm8001_ha,
  702. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  703. MBIC_AAP1_ADDR_BASE));
  704. return -1;
  705. }
  706. regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP);
  707. PM8001_INIT_DBG(pm8001_ha,
  708. pm8001_printk("MBIC - NMI Enable VPE0 (IOP)= 0x%x\n", regVal));
  709. pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_IOP, 0x0);
  710. /* map 0x70000 to BAR4(0x20), BAR2(win) */
  711. if (-1 == bar4_shift(pm8001_ha, MBIC_IOP_ADDR_BASE)) {
  712. PM8001_FAIL_DBG(pm8001_ha,
  713. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  714. MBIC_IOP_ADDR_BASE));
  715. return -1;
  716. }
  717. regVal = pm8001_cr32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1);
  718. PM8001_INIT_DBG(pm8001_ha,
  719. pm8001_printk("MBIC - NMI Enable VPE0 (AAP1)= 0x%x\n", regVal));
  720. pm8001_cw32(pm8001_ha, 2, MBIC_NMI_ENABLE_VPE0_AAP1, 0x0);
  721. regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE);
  722. PM8001_INIT_DBG(pm8001_ha,
  723. pm8001_printk("PCIE -Event Interrupt Enable = 0x%x\n", regVal));
  724. pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT_ENABLE, 0x0);
  725. regVal = pm8001_cr32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT);
  726. PM8001_INIT_DBG(pm8001_ha,
  727. pm8001_printk("PCIE - Event Interrupt = 0x%x\n", regVal));
  728. pm8001_cw32(pm8001_ha, 1, PCIE_EVENT_INTERRUPT, regVal);
  729. regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE);
  730. PM8001_INIT_DBG(pm8001_ha,
  731. pm8001_printk("PCIE -Error Interrupt Enable = 0x%x\n", regVal));
  732. pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT_ENABLE, 0x0);
  733. regVal = pm8001_cr32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT);
  734. PM8001_INIT_DBG(pm8001_ha,
  735. pm8001_printk("PCIE - Error Interrupt = 0x%x\n", regVal));
  736. pm8001_cw32(pm8001_ha, 1, PCIE_ERROR_INTERRUPT, regVal);
  737. /* read the scratch pad 1 register bit 2 */
  738. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1)
  739. & SCRATCH_PAD1_RST;
  740. toggleVal = regVal ^ SCRATCH_PAD1_RST;
  741. /* set signature in host scratch pad0 register to tell SPC that the
  742. host performs the soft reset */
  743. pm8001_cw32(pm8001_ha, 0, MSGU_HOST_SCRATCH_PAD_0, signature);
  744. /* read required registers for confirmming */
  745. /* map 0x0700000 to BAR4(0x20), BAR2(win) */
  746. if (-1 == bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
  747. PM8001_FAIL_DBG(pm8001_ha,
  748. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  749. GSM_ADDR_BASE));
  750. return -1;
  751. }
  752. PM8001_INIT_DBG(pm8001_ha,
  753. pm8001_printk("GSM 0x0(0x00007b88)-GSM Configuration and"
  754. " Reset = 0x%x\n",
  755. pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
  756. /* step 3: host read GSM Configuration and Reset register */
  757. regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
  758. /* Put those bits to low */
  759. /* GSM XCBI offset = 0x70 0000
  760. 0x00 Bit 13 COM_SLV_SW_RSTB 1
  761. 0x00 Bit 12 QSSP_SW_RSTB 1
  762. 0x00 Bit 11 RAAE_SW_RSTB 1
  763. 0x00 Bit 9 RB_1_SW_RSTB 1
  764. 0x00 Bit 8 SM_SW_RSTB 1
  765. */
  766. regVal &= ~(0x00003b00);
  767. /* host write GSM Configuration and Reset register */
  768. pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
  769. PM8001_INIT_DBG(pm8001_ha,
  770. pm8001_printk("GSM 0x0 (0x00007b88 ==> 0x00004088) - GSM "
  771. "Configuration and Reset is set to = 0x%x\n",
  772. pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
  773. /* step 4: */
  774. /* disable GSM - Read Address Parity Check */
  775. regVal1 = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
  776. PM8001_INIT_DBG(pm8001_ha,
  777. pm8001_printk("GSM 0x700038 - Read Address Parity Check "
  778. "Enable = 0x%x\n", regVal1));
  779. pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, 0x0);
  780. PM8001_INIT_DBG(pm8001_ha,
  781. pm8001_printk("GSM 0x700038 - Read Address Parity Check Enable"
  782. "is set to = 0x%x\n",
  783. pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK)));
  784. /* disable GSM - Write Address Parity Check */
  785. regVal2 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
  786. PM8001_INIT_DBG(pm8001_ha,
  787. pm8001_printk("GSM 0x700040 - Write Address Parity Check"
  788. " Enable = 0x%x\n", regVal2));
  789. pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, 0x0);
  790. PM8001_INIT_DBG(pm8001_ha,
  791. pm8001_printk("GSM 0x700040 - Write Address Parity Check "
  792. "Enable is set to = 0x%x\n",
  793. pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK)));
  794. /* disable GSM - Write Data Parity Check */
  795. regVal3 = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
  796. PM8001_INIT_DBG(pm8001_ha,
  797. pm8001_printk("GSM 0x300048 - Write Data Parity Check"
  798. " Enable = 0x%x\n", regVal3));
  799. pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, 0x0);
  800. PM8001_INIT_DBG(pm8001_ha,
  801. pm8001_printk("GSM 0x300048 - Write Data Parity Check Enable"
  802. "is set to = 0x%x\n",
  803. pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK)));
  804. /* step 5: delay 10 usec */
  805. udelay(10);
  806. /* step 5-b: set GPIO-0 output control to tristate anyway */
  807. if (-1 == bar4_shift(pm8001_ha, GPIO_ADDR_BASE)) {
  808. PM8001_INIT_DBG(pm8001_ha,
  809. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  810. GPIO_ADDR_BASE));
  811. return -1;
  812. }
  813. regVal = pm8001_cr32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET);
  814. PM8001_INIT_DBG(pm8001_ha,
  815. pm8001_printk("GPIO Output Control Register:"
  816. " = 0x%x\n", regVal));
  817. /* set GPIO-0 output control to tri-state */
  818. regVal &= 0xFFFFFFFC;
  819. pm8001_cw32(pm8001_ha, 2, GPIO_GPIO_0_0UTPUT_CTL_OFFSET, regVal);
  820. /* Step 6: Reset the IOP and AAP1 */
  821. /* map 0x00000 to BAR4(0x20), BAR2(win) */
  822. if (-1 == bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
  823. PM8001_FAIL_DBG(pm8001_ha,
  824. pm8001_printk("SPC Shift Bar4 to 0x%x failed\n",
  825. SPC_TOP_LEVEL_ADDR_BASE));
  826. return -1;
  827. }
  828. regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
  829. PM8001_INIT_DBG(pm8001_ha,
  830. pm8001_printk("Top Register before resetting IOP/AAP1"
  831. ":= 0x%x\n", regVal));
  832. regVal &= ~(SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
  833. pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
  834. /* step 7: Reset the BDMA/OSSP */
  835. regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
  836. PM8001_INIT_DBG(pm8001_ha,
  837. pm8001_printk("Top Register before resetting BDMA/OSSP"
  838. ": = 0x%x\n", regVal));
  839. regVal &= ~(SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
  840. pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
  841. /* step 8: delay 10 usec */
  842. udelay(10);
  843. /* step 9: bring the BDMA and OSSP out of reset */
  844. regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
  845. PM8001_INIT_DBG(pm8001_ha,
  846. pm8001_printk("Top Register before bringing up BDMA/OSSP"
  847. ":= 0x%x\n", regVal));
  848. regVal |= (SPC_REG_RESET_BDMA_CORE | SPC_REG_RESET_OSSP);
  849. pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
  850. /* step 10: delay 10 usec */
  851. udelay(10);
  852. /* step 11: reads and sets the GSM Configuration and Reset Register */
  853. /* map 0x0700000 to BAR4(0x20), BAR2(win) */
  854. if (-1 == bar4_shift(pm8001_ha, GSM_ADDR_BASE)) {
  855. PM8001_FAIL_DBG(pm8001_ha,
  856. pm8001_printk("SPC Shift Bar4 to 0x%x failed\n",
  857. GSM_ADDR_BASE));
  858. return -1;
  859. }
  860. PM8001_INIT_DBG(pm8001_ha,
  861. pm8001_printk("GSM 0x0 (0x00007b88)-GSM Configuration and "
  862. "Reset = 0x%x\n", pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
  863. regVal = pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET);
  864. /* Put those bits to high */
  865. /* GSM XCBI offset = 0x70 0000
  866. 0x00 Bit 13 COM_SLV_SW_RSTB 1
  867. 0x00 Bit 12 QSSP_SW_RSTB 1
  868. 0x00 Bit 11 RAAE_SW_RSTB 1
  869. 0x00 Bit 9 RB_1_SW_RSTB 1
  870. 0x00 Bit 8 SM_SW_RSTB 1
  871. */
  872. regVal |= (GSM_CONFIG_RESET_VALUE);
  873. pm8001_cw32(pm8001_ha, 2, GSM_CONFIG_RESET, regVal);
  874. PM8001_INIT_DBG(pm8001_ha,
  875. pm8001_printk("GSM (0x00004088 ==> 0x00007b88) - GSM"
  876. " Configuration and Reset is set to = 0x%x\n",
  877. pm8001_cr32(pm8001_ha, 2, GSM_CONFIG_RESET)));
  878. /* step 12: Restore GSM - Read Address Parity Check */
  879. regVal = pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK);
  880. /* just for debugging */
  881. PM8001_INIT_DBG(pm8001_ha,
  882. pm8001_printk("GSM 0x700038 - Read Address Parity Check Enable"
  883. " = 0x%x\n", regVal));
  884. pm8001_cw32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK, regVal1);
  885. PM8001_INIT_DBG(pm8001_ha,
  886. pm8001_printk("GSM 0x700038 - Read Address Parity"
  887. " Check Enable is set to = 0x%x\n",
  888. pm8001_cr32(pm8001_ha, 2, GSM_READ_ADDR_PARITY_CHECK)));
  889. /* Restore GSM - Write Address Parity Check */
  890. regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK);
  891. pm8001_cw32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK, regVal2);
  892. PM8001_INIT_DBG(pm8001_ha,
  893. pm8001_printk("GSM 0x700040 - Write Address Parity Check"
  894. " Enable is set to = 0x%x\n",
  895. pm8001_cr32(pm8001_ha, 2, GSM_WRITE_ADDR_PARITY_CHECK)));
  896. /* Restore GSM - Write Data Parity Check */
  897. regVal = pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK);
  898. pm8001_cw32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK, regVal3);
  899. PM8001_INIT_DBG(pm8001_ha,
  900. pm8001_printk("GSM 0x700048 - Write Data Parity Check Enable"
  901. "is set to = 0x%x\n",
  902. pm8001_cr32(pm8001_ha, 2, GSM_WRITE_DATA_PARITY_CHECK)));
  903. /* step 13: bring the IOP and AAP1 out of reset */
  904. /* map 0x00000 to BAR4(0x20), BAR2(win) */
  905. if (-1 == bar4_shift(pm8001_ha, SPC_TOP_LEVEL_ADDR_BASE)) {
  906. PM8001_FAIL_DBG(pm8001_ha,
  907. pm8001_printk("Shift Bar4 to 0x%x failed\n",
  908. SPC_TOP_LEVEL_ADDR_BASE));
  909. return -1;
  910. }
  911. regVal = pm8001_cr32(pm8001_ha, 2, SPC_REG_RESET);
  912. regVal |= (SPC_REG_RESET_PCS_IOP_SS | SPC_REG_RESET_PCS_AAP1_SS);
  913. pm8001_cw32(pm8001_ha, 2, SPC_REG_RESET, regVal);
  914. /* step 14: delay 10 usec - Normal Mode */
  915. udelay(10);
  916. /* check Soft Reset Normal mode or Soft Reset HDA mode */
  917. if (signature == SPC_SOFT_RESET_SIGNATURE) {
  918. /* step 15 (Normal Mode): wait until scratch pad1 register
  919. bit 2 toggled */
  920. max_wait_count = 2 * 1000 * 1000;/* 2 sec */
  921. do {
  922. udelay(1);
  923. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1) &
  924. SCRATCH_PAD1_RST;
  925. } while ((regVal != toggleVal) && (--max_wait_count));
  926. if (!max_wait_count) {
  927. regVal = pm8001_cr32(pm8001_ha, 0,
  928. MSGU_SCRATCH_PAD_1);
  929. PM8001_FAIL_DBG(pm8001_ha,
  930. pm8001_printk("TIMEOUT : ToggleVal 0x%x,"
  931. "MSGU_SCRATCH_PAD1 = 0x%x\n",
  932. toggleVal, regVal));
  933. PM8001_FAIL_DBG(pm8001_ha,
  934. pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
  935. pm8001_cr32(pm8001_ha, 0,
  936. MSGU_SCRATCH_PAD_0)));
  937. PM8001_FAIL_DBG(pm8001_ha,
  938. pm8001_printk("SCRATCH_PAD2 value = 0x%x\n",
  939. pm8001_cr32(pm8001_ha, 0,
  940. MSGU_SCRATCH_PAD_2)));
  941. PM8001_FAIL_DBG(pm8001_ha,
  942. pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
  943. pm8001_cr32(pm8001_ha, 0,
  944. MSGU_SCRATCH_PAD_3)));
  945. return -1;
  946. }
  947. /* step 16 (Normal) - Clear ODMR and ODCR */
  948. pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
  949. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
  950. /* step 17 (Normal Mode): wait for the FW and IOP to get
  951. ready - 1 sec timeout */
  952. /* Wait for the SPC Configuration Table to be ready */
  953. if (check_fw_ready(pm8001_ha) == -1) {
  954. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_1);
  955. /* return error if MPI Configuration Table not ready */
  956. PM8001_INIT_DBG(pm8001_ha,
  957. pm8001_printk("FW not ready SCRATCH_PAD1"
  958. " = 0x%x\n", regVal));
  959. regVal = pm8001_cr32(pm8001_ha, 0, MSGU_SCRATCH_PAD_2);
  960. /* return error if MPI Configuration Table not ready */
  961. PM8001_INIT_DBG(pm8001_ha,
  962. pm8001_printk("FW not ready SCRATCH_PAD2"
  963. " = 0x%x\n", regVal));
  964. PM8001_INIT_DBG(pm8001_ha,
  965. pm8001_printk("SCRATCH_PAD0 value = 0x%x\n",
  966. pm8001_cr32(pm8001_ha, 0,
  967. MSGU_SCRATCH_PAD_0)));
  968. PM8001_INIT_DBG(pm8001_ha,
  969. pm8001_printk("SCRATCH_PAD3 value = 0x%x\n",
  970. pm8001_cr32(pm8001_ha, 0,
  971. MSGU_SCRATCH_PAD_3)));
  972. return -1;
  973. }
  974. }
  975. PM8001_INIT_DBG(pm8001_ha,
  976. pm8001_printk("SPC soft reset Complete\n"));
  977. return 0;
  978. }
  979. static void pm8001_hw_chip_rst(struct pm8001_hba_info *pm8001_ha)
  980. {
  981. u32 i;
  982. u32 regVal;
  983. PM8001_INIT_DBG(pm8001_ha,
  984. pm8001_printk("chip reset start\n"));
  985. /* do SPC chip reset. */
  986. regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
  987. regVal &= ~(SPC_REG_RESET_DEVICE);
  988. pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
  989. /* delay 10 usec */
  990. udelay(10);
  991. /* bring chip reset out of reset */
  992. regVal = pm8001_cr32(pm8001_ha, 1, SPC_REG_RESET);
  993. regVal |= SPC_REG_RESET_DEVICE;
  994. pm8001_cw32(pm8001_ha, 1, SPC_REG_RESET, regVal);
  995. /* delay 10 usec */
  996. udelay(10);
  997. /* wait for 20 msec until the firmware gets reloaded */
  998. i = 20;
  999. do {
  1000. mdelay(1);
  1001. } while ((--i) != 0);
  1002. PM8001_INIT_DBG(pm8001_ha,
  1003. pm8001_printk("chip reset finished\n"));
  1004. }
  1005. /**
  1006. * pm8001_chip_iounmap - which maped when initialized.
  1007. * @pm8001_ha: our hba card information
  1008. */
  1009. static void pm8001_chip_iounmap(struct pm8001_hba_info *pm8001_ha)
  1010. {
  1011. s8 bar, logical = 0;
  1012. for (bar = 0; bar < 6; bar++) {
  1013. /*
  1014. ** logical BARs for SPC:
  1015. ** bar 0 and 1 - logical BAR0
  1016. ** bar 2 and 3 - logical BAR1
  1017. ** bar4 - logical BAR2
  1018. ** bar5 - logical BAR3
  1019. ** Skip the appropriate assignments:
  1020. */
  1021. if ((bar == 1) || (bar == 3))
  1022. continue;
  1023. if (pm8001_ha->io_mem[logical].memvirtaddr) {
  1024. iounmap(pm8001_ha->io_mem[logical].memvirtaddr);
  1025. logical++;
  1026. }
  1027. }
  1028. }
  1029. /**
  1030. * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
  1031. * @pm8001_ha: our hba card information
  1032. */
  1033. static void
  1034. pm8001_chip_intx_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
  1035. {
  1036. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_CLEAR_ALL);
  1037. pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, ODCR_CLEAR_ALL);
  1038. }
  1039. /**
  1040. * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
  1041. * @pm8001_ha: our hba card information
  1042. */
  1043. static void
  1044. pm8001_chip_intx_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
  1045. {
  1046. pm8001_cw32(pm8001_ha, 0, MSGU_ODMR, ODMR_MASK_ALL);
  1047. }
  1048. /**
  1049. * pm8001_chip_msix_interrupt_enable - enable PM8001 chip interrupt
  1050. * @pm8001_ha: our hba card information
  1051. */
  1052. static void
  1053. pm8001_chip_msix_interrupt_enable(struct pm8001_hba_info *pm8001_ha,
  1054. u32 int_vec_idx)
  1055. {
  1056. u32 msi_index;
  1057. u32 value;
  1058. msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
  1059. msi_index += MSIX_TABLE_BASE;
  1060. pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_ENABLE);
  1061. value = (1 << int_vec_idx);
  1062. pm8001_cw32(pm8001_ha, 0, MSGU_ODCR, value);
  1063. }
  1064. /**
  1065. * pm8001_chip_msix_interrupt_disable - disable PM8001 chip interrupt
  1066. * @pm8001_ha: our hba card information
  1067. */
  1068. static void
  1069. pm8001_chip_msix_interrupt_disable(struct pm8001_hba_info *pm8001_ha,
  1070. u32 int_vec_idx)
  1071. {
  1072. u32 msi_index;
  1073. msi_index = int_vec_idx * MSIX_TABLE_ELEMENT_SIZE;
  1074. msi_index += MSIX_TABLE_BASE;
  1075. pm8001_cw32(pm8001_ha, 0, msi_index, MSIX_INTERRUPT_DISABLE);
  1076. }
  1077. /**
  1078. * pm8001_chip_interrupt_enable - enable PM8001 chip interrupt
  1079. * @pm8001_ha: our hba card information
  1080. */
  1081. static void
  1082. pm8001_chip_interrupt_enable(struct pm8001_hba_info *pm8001_ha)
  1083. {
  1084. #ifdef PM8001_USE_MSIX
  1085. pm8001_chip_msix_interrupt_enable(pm8001_ha, 0);
  1086. return;
  1087. #endif
  1088. pm8001_chip_intx_interrupt_enable(pm8001_ha);
  1089. }
  1090. /**
  1091. * pm8001_chip_intx_interrupt_disable- disable PM8001 chip interrupt
  1092. * @pm8001_ha: our hba card information
  1093. */
  1094. static void
  1095. pm8001_chip_interrupt_disable(struct pm8001_hba_info *pm8001_ha)
  1096. {
  1097. #ifdef PM8001_USE_MSIX
  1098. pm8001_chip_msix_interrupt_disable(pm8001_ha, 0);
  1099. return;
  1100. #endif
  1101. pm8001_chip_intx_interrupt_disable(pm8001_ha);
  1102. }
  1103. /**
  1104. * mpi_msg_free_get- get the free message buffer for transfer inbound queue.
  1105. * @circularQ: the inbound queue we want to transfer to HBA.
  1106. * @messageSize: the message size of this transfer, normally it is 64 bytes
  1107. * @messagePtr: the pointer to message.
  1108. */
  1109. static int mpi_msg_free_get(struct inbound_queue_table *circularQ,
  1110. u16 messageSize, void **messagePtr)
  1111. {
  1112. u32 offset, consumer_index;
  1113. struct mpi_msg_hdr *msgHeader;
  1114. u8 bcCount = 1; /* only support single buffer */
  1115. /* Checks is the requested message size can be allocated in this queue*/
  1116. if (messageSize > 64) {
  1117. *messagePtr = NULL;
  1118. return -1;
  1119. }
  1120. /* Stores the new consumer index */
  1121. consumer_index = pm8001_read_32(circularQ->ci_virt);
  1122. circularQ->consumer_index = cpu_to_le32(consumer_index);
  1123. if (((circularQ->producer_idx + bcCount) % 256) ==
  1124. circularQ->consumer_index) {
  1125. *messagePtr = NULL;
  1126. return -1;
  1127. }
  1128. /* get memory IOMB buffer address */
  1129. offset = circularQ->producer_idx * 64;
  1130. /* increment to next bcCount element */
  1131. circularQ->producer_idx = (circularQ->producer_idx + bcCount) % 256;
  1132. /* Adds that distance to the base of the region virtual address plus
  1133. the message header size*/
  1134. msgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt + offset);
  1135. *messagePtr = ((void *)msgHeader) + sizeof(struct mpi_msg_hdr);
  1136. return 0;
  1137. }
  1138. /**
  1139. * mpi_build_cmd- build the message queue for transfer, update the PI to FW
  1140. * to tell the fw to get this message from IOMB.
  1141. * @pm8001_ha: our hba card information
  1142. * @circularQ: the inbound queue we want to transfer to HBA.
  1143. * @opCode: the operation code represents commands which LLDD and fw recognized.
  1144. * @payload: the command payload of each operation command.
  1145. */
  1146. static int mpi_build_cmd(struct pm8001_hba_info *pm8001_ha,
  1147. struct inbound_queue_table *circularQ,
  1148. u32 opCode, void *payload)
  1149. {
  1150. u32 Header = 0, hpriority = 0, bc = 1, category = 0x02;
  1151. u32 responseQueue = 0;
  1152. void *pMessage;
  1153. if (mpi_msg_free_get(circularQ, 64, &pMessage) < 0) {
  1154. PM8001_IO_DBG(pm8001_ha,
  1155. pm8001_printk("No free mpi buffer \n"));
  1156. return -1;
  1157. }
  1158. BUG_ON(!payload);
  1159. /*Copy to the payload*/
  1160. memcpy(pMessage, payload, (64 - sizeof(struct mpi_msg_hdr)));
  1161. /*Build the header*/
  1162. Header = ((1 << 31) | (hpriority << 30) | ((bc & 0x1f) << 24)
  1163. | ((responseQueue & 0x3F) << 16)
  1164. | ((category & 0xF) << 12) | (opCode & 0xFFF));
  1165. pm8001_write_32((pMessage - 4), 0, cpu_to_le32(Header));
  1166. /*Update the PI to the firmware*/
  1167. pm8001_cw32(pm8001_ha, circularQ->pi_pci_bar,
  1168. circularQ->pi_offset, circularQ->producer_idx);
  1169. PM8001_IO_DBG(pm8001_ha,
  1170. pm8001_printk("after PI= %d CI= %d \n", circularQ->producer_idx,
  1171. circularQ->consumer_index));
  1172. return 0;
  1173. }
  1174. static u32 mpi_msg_free_set(struct pm8001_hba_info *pm8001_ha, void *pMsg,
  1175. struct outbound_queue_table *circularQ, u8 bc)
  1176. {
  1177. u32 producer_index;
  1178. struct mpi_msg_hdr *msgHeader;
  1179. struct mpi_msg_hdr *pOutBoundMsgHeader;
  1180. msgHeader = (struct mpi_msg_hdr *)(pMsg - sizeof(struct mpi_msg_hdr));
  1181. pOutBoundMsgHeader = (struct mpi_msg_hdr *)(circularQ->base_virt +
  1182. circularQ->consumer_idx * 64);
  1183. if (pOutBoundMsgHeader != msgHeader) {
  1184. PM8001_FAIL_DBG(pm8001_ha,
  1185. pm8001_printk("consumer_idx = %d msgHeader = %p\n",
  1186. circularQ->consumer_idx, msgHeader));
  1187. /* Update the producer index from SPC */
  1188. producer_index = pm8001_read_32(circularQ->pi_virt);
  1189. circularQ->producer_index = cpu_to_le32(producer_index);
  1190. PM8001_FAIL_DBG(pm8001_ha,
  1191. pm8001_printk("consumer_idx = %d producer_index = %d"
  1192. "msgHeader = %p\n", circularQ->consumer_idx,
  1193. circularQ->producer_index, msgHeader));
  1194. return 0;
  1195. }
  1196. /* free the circular queue buffer elements associated with the message*/
  1197. circularQ->consumer_idx = (circularQ->consumer_idx + bc) % 256;
  1198. /* update the CI of outbound queue */
  1199. pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar, circularQ->ci_offset,
  1200. circularQ->consumer_idx);
  1201. /* Update the producer index from SPC*/
  1202. producer_index = pm8001_read_32(circularQ->pi_virt);
  1203. circularQ->producer_index = cpu_to_le32(producer_index);
  1204. PM8001_IO_DBG(pm8001_ha,
  1205. pm8001_printk(" CI=%d PI=%d\n", circularQ->consumer_idx,
  1206. circularQ->producer_index));
  1207. return 0;
  1208. }
  1209. /**
  1210. * mpi_msg_consume- get the MPI message from outbound queue message table.
  1211. * @pm8001_ha: our hba card information
  1212. * @circularQ: the outbound queue table.
  1213. * @messagePtr1: the message contents of this outbound message.
  1214. * @pBC: the message size.
  1215. */
  1216. static u32 mpi_msg_consume(struct pm8001_hba_info *pm8001_ha,
  1217. struct outbound_queue_table *circularQ,
  1218. void **messagePtr1, u8 *pBC)
  1219. {
  1220. struct mpi_msg_hdr *msgHeader;
  1221. __le32 msgHeader_tmp;
  1222. u32 header_tmp;
  1223. do {
  1224. /* If there are not-yet-delivered messages ... */
  1225. if (circularQ->producer_index != circularQ->consumer_idx) {
  1226. /*Get the pointer to the circular queue buffer element*/
  1227. msgHeader = (struct mpi_msg_hdr *)
  1228. (circularQ->base_virt +
  1229. circularQ->consumer_idx * 64);
  1230. /* read header */
  1231. header_tmp = pm8001_read_32(msgHeader);
  1232. msgHeader_tmp = cpu_to_le32(header_tmp);
  1233. if (0 != (msgHeader_tmp & 0x80000000)) {
  1234. if (OPC_OUB_SKIP_ENTRY !=
  1235. (msgHeader_tmp & 0xfff)) {
  1236. *messagePtr1 =
  1237. ((u8 *)msgHeader) +
  1238. sizeof(struct mpi_msg_hdr);
  1239. *pBC = (u8)((msgHeader_tmp >> 24) &
  1240. 0x1f);
  1241. PM8001_IO_DBG(pm8001_ha,
  1242. pm8001_printk(": CI=%d PI=%d "
  1243. "msgHeader=%x\n",
  1244. circularQ->consumer_idx,
  1245. circularQ->producer_index,
  1246. msgHeader_tmp));
  1247. return MPI_IO_STATUS_SUCCESS;
  1248. } else {
  1249. circularQ->consumer_idx =
  1250. (circularQ->consumer_idx +
  1251. ((msgHeader_tmp >> 24) & 0x1f))
  1252. % 256;
  1253. msgHeader_tmp = 0;
  1254. pm8001_write_32(msgHeader, 0, 0);
  1255. /* update the CI of outbound queue */
  1256. pm8001_cw32(pm8001_ha,
  1257. circularQ->ci_pci_bar,
  1258. circularQ->ci_offset,
  1259. circularQ->consumer_idx);
  1260. }
  1261. } else {
  1262. circularQ->consumer_idx =
  1263. (circularQ->consumer_idx +
  1264. ((msgHeader_tmp >> 24) & 0x1f)) % 256;
  1265. msgHeader_tmp = 0;
  1266. pm8001_write_32(msgHeader, 0, 0);
  1267. /* update the CI of outbound queue */
  1268. pm8001_cw32(pm8001_ha, circularQ->ci_pci_bar,
  1269. circularQ->ci_offset,
  1270. circularQ->consumer_idx);
  1271. return MPI_IO_STATUS_FAIL;
  1272. }
  1273. } else {
  1274. u32 producer_index;
  1275. void *pi_virt = circularQ->pi_virt;
  1276. /* Update the producer index from SPC */
  1277. producer_index = pm8001_read_32(pi_virt);
  1278. circularQ->producer_index = cpu_to_le32(producer_index);
  1279. }
  1280. } while (circularQ->producer_index != circularQ->consumer_idx);
  1281. /* while we don't have any more not-yet-delivered message */
  1282. /* report empty */
  1283. return MPI_IO_STATUS_BUSY;
  1284. }
  1285. static void pm8001_work_fn(struct work_struct *work)
  1286. {
  1287. struct pm8001_work *pw = container_of(work, struct pm8001_work, work);
  1288. struct pm8001_device *pm8001_dev;
  1289. struct domain_device *dev;
  1290. switch (pw->handler) {
  1291. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1292. pm8001_dev = pw->data;
  1293. dev = pm8001_dev->sas_device;
  1294. pm8001_I_T_nexus_reset(dev);
  1295. break;
  1296. case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
  1297. pm8001_dev = pw->data;
  1298. dev = pm8001_dev->sas_device;
  1299. pm8001_I_T_nexus_reset(dev);
  1300. break;
  1301. case IO_DS_IN_ERROR:
  1302. pm8001_dev = pw->data;
  1303. dev = pm8001_dev->sas_device;
  1304. pm8001_I_T_nexus_reset(dev);
  1305. break;
  1306. case IO_DS_NON_OPERATIONAL:
  1307. pm8001_dev = pw->data;
  1308. dev = pm8001_dev->sas_device;
  1309. pm8001_I_T_nexus_reset(dev);
  1310. break;
  1311. }
  1312. kfree(pw);
  1313. }
  1314. static int pm8001_handle_event(struct pm8001_hba_info *pm8001_ha, void *data,
  1315. int handler)
  1316. {
  1317. struct pm8001_work *pw;
  1318. int ret = 0;
  1319. pw = kmalloc(sizeof(struct pm8001_work), GFP_ATOMIC);
  1320. if (pw) {
  1321. pw->pm8001_ha = pm8001_ha;
  1322. pw->data = data;
  1323. pw->handler = handler;
  1324. INIT_WORK(&pw->work, pm8001_work_fn);
  1325. queue_work(pm8001_wq, &pw->work);
  1326. } else
  1327. ret = -ENOMEM;
  1328. return ret;
  1329. }
  1330. /**
  1331. * mpi_ssp_completion- process the event that FW response to the SSP request.
  1332. * @pm8001_ha: our hba card information
  1333. * @piomb: the message contents of this outbound message.
  1334. *
  1335. * When FW has completed a ssp request for example a IO request, after it has
  1336. * filled the SG data with the data, it will trigger this event represent
  1337. * that he has finished the job,please check the coresponding buffer.
  1338. * So we will tell the caller who maybe waiting the result to tell upper layer
  1339. * that the task has been finished.
  1340. */
  1341. static void
  1342. mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
  1343. {
  1344. struct sas_task *t;
  1345. struct pm8001_ccb_info *ccb;
  1346. unsigned long flags;
  1347. u32 status;
  1348. u32 param;
  1349. u32 tag;
  1350. struct ssp_completion_resp *psspPayload;
  1351. struct task_status_struct *ts;
  1352. struct ssp_response_iu *iu;
  1353. struct pm8001_device *pm8001_dev;
  1354. psspPayload = (struct ssp_completion_resp *)(piomb + 4);
  1355. status = le32_to_cpu(psspPayload->status);
  1356. tag = le32_to_cpu(psspPayload->tag);
  1357. ccb = &pm8001_ha->ccb_info[tag];
  1358. pm8001_dev = ccb->device;
  1359. param = le32_to_cpu(psspPayload->param);
  1360. t = ccb->task;
  1361. if (status && status != IO_UNDERFLOW)
  1362. PM8001_FAIL_DBG(pm8001_ha,
  1363. pm8001_printk("sas IO status 0x%x\n", status));
  1364. if (unlikely(!t || !t->lldd_task || !t->dev))
  1365. return;
  1366. ts = &t->task_status;
  1367. switch (status) {
  1368. case IO_SUCCESS:
  1369. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS"
  1370. ",param = %d \n", param));
  1371. if (param == 0) {
  1372. ts->resp = SAS_TASK_COMPLETE;
  1373. ts->stat = SAM_STAT_GOOD;
  1374. } else {
  1375. ts->resp = SAS_TASK_COMPLETE;
  1376. ts->stat = SAS_PROTO_RESPONSE;
  1377. ts->residual = param;
  1378. iu = &psspPayload->ssp_resp_iu;
  1379. sas_ssp_task_response(pm8001_ha->dev, t, iu);
  1380. }
  1381. if (pm8001_dev)
  1382. pm8001_dev->running_req--;
  1383. break;
  1384. case IO_ABORTED:
  1385. PM8001_IO_DBG(pm8001_ha,
  1386. pm8001_printk("IO_ABORTED IOMB Tag \n"));
  1387. ts->resp = SAS_TASK_COMPLETE;
  1388. ts->stat = SAS_ABORTED_TASK;
  1389. break;
  1390. case IO_UNDERFLOW:
  1391. /* SSP Completion with error */
  1392. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW"
  1393. ",param = %d \n", param));
  1394. ts->resp = SAS_TASK_COMPLETE;
  1395. ts->stat = SAS_DATA_UNDERRUN;
  1396. ts->residual = param;
  1397. if (pm8001_dev)
  1398. pm8001_dev->running_req--;
  1399. break;
  1400. case IO_NO_DEVICE:
  1401. PM8001_IO_DBG(pm8001_ha,
  1402. pm8001_printk("IO_NO_DEVICE\n"));
  1403. ts->resp = SAS_TASK_UNDELIVERED;
  1404. ts->stat = SAS_PHY_DOWN;
  1405. break;
  1406. case IO_XFER_ERROR_BREAK:
  1407. PM8001_IO_DBG(pm8001_ha,
  1408. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  1409. ts->resp = SAS_TASK_COMPLETE;
  1410. ts->stat = SAS_OPEN_REJECT;
  1411. break;
  1412. case IO_XFER_ERROR_PHY_NOT_READY:
  1413. PM8001_IO_DBG(pm8001_ha,
  1414. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  1415. ts->resp = SAS_TASK_COMPLETE;
  1416. ts->stat = SAS_OPEN_REJECT;
  1417. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1418. break;
  1419. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  1420. PM8001_IO_DBG(pm8001_ha,
  1421. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  1422. ts->resp = SAS_TASK_COMPLETE;
  1423. ts->stat = SAS_OPEN_REJECT;
  1424. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1425. break;
  1426. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  1427. PM8001_IO_DBG(pm8001_ha,
  1428. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  1429. ts->resp = SAS_TASK_COMPLETE;
  1430. ts->stat = SAS_OPEN_REJECT;
  1431. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1432. break;
  1433. case IO_OPEN_CNX_ERROR_BREAK:
  1434. PM8001_IO_DBG(pm8001_ha,
  1435. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  1436. ts->resp = SAS_TASK_COMPLETE;
  1437. ts->stat = SAS_OPEN_REJECT;
  1438. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1439. break;
  1440. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1441. PM8001_IO_DBG(pm8001_ha,
  1442. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  1443. ts->resp = SAS_TASK_COMPLETE;
  1444. ts->stat = SAS_OPEN_REJECT;
  1445. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1446. if (!t->uldd_task)
  1447. pm8001_handle_event(pm8001_ha,
  1448. pm8001_dev,
  1449. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  1450. break;
  1451. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  1452. PM8001_IO_DBG(pm8001_ha,
  1453. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  1454. ts->resp = SAS_TASK_COMPLETE;
  1455. ts->stat = SAS_OPEN_REJECT;
  1456. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1457. break;
  1458. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  1459. PM8001_IO_DBG(pm8001_ha,
  1460. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  1461. "NOT_SUPPORTED\n"));
  1462. ts->resp = SAS_TASK_COMPLETE;
  1463. ts->stat = SAS_OPEN_REJECT;
  1464. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1465. break;
  1466. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  1467. PM8001_IO_DBG(pm8001_ha,
  1468. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  1469. ts->resp = SAS_TASK_UNDELIVERED;
  1470. ts->stat = SAS_OPEN_REJECT;
  1471. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1472. break;
  1473. case IO_XFER_ERROR_NAK_RECEIVED:
  1474. PM8001_IO_DBG(pm8001_ha,
  1475. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  1476. ts->resp = SAS_TASK_COMPLETE;
  1477. ts->stat = SAS_OPEN_REJECT;
  1478. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1479. break;
  1480. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  1481. PM8001_IO_DBG(pm8001_ha,
  1482. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  1483. ts->resp = SAS_TASK_COMPLETE;
  1484. ts->stat = SAS_NAK_R_ERR;
  1485. break;
  1486. case IO_XFER_ERROR_DMA:
  1487. PM8001_IO_DBG(pm8001_ha,
  1488. pm8001_printk("IO_XFER_ERROR_DMA\n"));
  1489. ts->resp = SAS_TASK_COMPLETE;
  1490. ts->stat = SAS_OPEN_REJECT;
  1491. break;
  1492. case IO_XFER_OPEN_RETRY_TIMEOUT:
  1493. PM8001_IO_DBG(pm8001_ha,
  1494. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  1495. ts->resp = SAS_TASK_COMPLETE;
  1496. ts->stat = SAS_OPEN_REJECT;
  1497. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1498. break;
  1499. case IO_XFER_ERROR_OFFSET_MISMATCH:
  1500. PM8001_IO_DBG(pm8001_ha,
  1501. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  1502. ts->resp = SAS_TASK_COMPLETE;
  1503. ts->stat = SAS_OPEN_REJECT;
  1504. break;
  1505. case IO_PORT_IN_RESET:
  1506. PM8001_IO_DBG(pm8001_ha,
  1507. pm8001_printk("IO_PORT_IN_RESET\n"));
  1508. ts->resp = SAS_TASK_COMPLETE;
  1509. ts->stat = SAS_OPEN_REJECT;
  1510. break;
  1511. case IO_DS_NON_OPERATIONAL:
  1512. PM8001_IO_DBG(pm8001_ha,
  1513. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  1514. ts->resp = SAS_TASK_COMPLETE;
  1515. ts->stat = SAS_OPEN_REJECT;
  1516. if (!t->uldd_task)
  1517. pm8001_handle_event(pm8001_ha,
  1518. pm8001_dev,
  1519. IO_DS_NON_OPERATIONAL);
  1520. break;
  1521. case IO_DS_IN_RECOVERY:
  1522. PM8001_IO_DBG(pm8001_ha,
  1523. pm8001_printk("IO_DS_IN_RECOVERY\n"));
  1524. ts->resp = SAS_TASK_COMPLETE;
  1525. ts->stat = SAS_OPEN_REJECT;
  1526. break;
  1527. case IO_TM_TAG_NOT_FOUND:
  1528. PM8001_IO_DBG(pm8001_ha,
  1529. pm8001_printk("IO_TM_TAG_NOT_FOUND\n"));
  1530. ts->resp = SAS_TASK_COMPLETE;
  1531. ts->stat = SAS_OPEN_REJECT;
  1532. break;
  1533. case IO_SSP_EXT_IU_ZERO_LEN_ERROR:
  1534. PM8001_IO_DBG(pm8001_ha,
  1535. pm8001_printk("IO_SSP_EXT_IU_ZERO_LEN_ERROR\n"));
  1536. ts->resp = SAS_TASK_COMPLETE;
  1537. ts->stat = SAS_OPEN_REJECT;
  1538. break;
  1539. case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  1540. PM8001_IO_DBG(pm8001_ha,
  1541. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  1542. ts->resp = SAS_TASK_COMPLETE;
  1543. ts->stat = SAS_OPEN_REJECT;
  1544. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1545. default:
  1546. PM8001_IO_DBG(pm8001_ha,
  1547. pm8001_printk("Unknown status 0x%x\n", status));
  1548. /* not allowed case. Therefore, return failed status */
  1549. ts->resp = SAS_TASK_COMPLETE;
  1550. ts->stat = SAS_OPEN_REJECT;
  1551. break;
  1552. }
  1553. PM8001_IO_DBG(pm8001_ha,
  1554. pm8001_printk("scsi_status = %x \n ",
  1555. psspPayload->ssp_resp_iu.status));
  1556. spin_lock_irqsave(&t->task_state_lock, flags);
  1557. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  1558. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  1559. t->task_state_flags |= SAS_TASK_STATE_DONE;
  1560. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  1561. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1562. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
  1563. " io_status 0x%x resp 0x%x "
  1564. "stat 0x%x but aborted by upper layer!\n",
  1565. t, status, ts->resp, ts->stat));
  1566. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1567. } else {
  1568. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1569. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1570. mb();/* in order to force CPU ordering */
  1571. t->task_done(t);
  1572. }
  1573. }
  1574. /*See the comments for mpi_ssp_completion */
  1575. static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
  1576. {
  1577. struct sas_task *t;
  1578. unsigned long flags;
  1579. struct task_status_struct *ts;
  1580. struct pm8001_ccb_info *ccb;
  1581. struct pm8001_device *pm8001_dev;
  1582. struct ssp_event_resp *psspPayload =
  1583. (struct ssp_event_resp *)(piomb + 4);
  1584. u32 event = le32_to_cpu(psspPayload->event);
  1585. u32 tag = le32_to_cpu(psspPayload->tag);
  1586. u32 port_id = le32_to_cpu(psspPayload->port_id);
  1587. u32 dev_id = le32_to_cpu(psspPayload->device_id);
  1588. ccb = &pm8001_ha->ccb_info[tag];
  1589. t = ccb->task;
  1590. pm8001_dev = ccb->device;
  1591. if (event)
  1592. PM8001_FAIL_DBG(pm8001_ha,
  1593. pm8001_printk("sas IO status 0x%x\n", event));
  1594. if (unlikely(!t || !t->lldd_task || !t->dev))
  1595. return;
  1596. ts = &t->task_status;
  1597. PM8001_IO_DBG(pm8001_ha,
  1598. pm8001_printk("port_id = %x,device_id = %x\n",
  1599. port_id, dev_id));
  1600. switch (event) {
  1601. case IO_OVERFLOW:
  1602. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n");)
  1603. ts->resp = SAS_TASK_COMPLETE;
  1604. ts->stat = SAS_DATA_OVERRUN;
  1605. ts->residual = 0;
  1606. if (pm8001_dev)
  1607. pm8001_dev->running_req--;
  1608. break;
  1609. case IO_XFER_ERROR_BREAK:
  1610. PM8001_IO_DBG(pm8001_ha,
  1611. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  1612. ts->resp = SAS_TASK_COMPLETE;
  1613. ts->stat = SAS_INTERRUPTED;
  1614. break;
  1615. case IO_XFER_ERROR_PHY_NOT_READY:
  1616. PM8001_IO_DBG(pm8001_ha,
  1617. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  1618. ts->resp = SAS_TASK_COMPLETE;
  1619. ts->stat = SAS_OPEN_REJECT;
  1620. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1621. break;
  1622. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  1623. PM8001_IO_DBG(pm8001_ha,
  1624. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
  1625. "_SUPPORTED\n"));
  1626. ts->resp = SAS_TASK_COMPLETE;
  1627. ts->stat = SAS_OPEN_REJECT;
  1628. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1629. break;
  1630. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  1631. PM8001_IO_DBG(pm8001_ha,
  1632. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  1633. ts->resp = SAS_TASK_COMPLETE;
  1634. ts->stat = SAS_OPEN_REJECT;
  1635. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1636. break;
  1637. case IO_OPEN_CNX_ERROR_BREAK:
  1638. PM8001_IO_DBG(pm8001_ha,
  1639. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  1640. ts->resp = SAS_TASK_COMPLETE;
  1641. ts->stat = SAS_OPEN_REJECT;
  1642. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1643. break;
  1644. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1645. PM8001_IO_DBG(pm8001_ha,
  1646. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  1647. ts->resp = SAS_TASK_COMPLETE;
  1648. ts->stat = SAS_OPEN_REJECT;
  1649. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1650. if (!t->uldd_task)
  1651. pm8001_handle_event(pm8001_ha,
  1652. pm8001_dev,
  1653. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  1654. break;
  1655. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  1656. PM8001_IO_DBG(pm8001_ha,
  1657. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  1658. ts->resp = SAS_TASK_COMPLETE;
  1659. ts->stat = SAS_OPEN_REJECT;
  1660. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1661. break;
  1662. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  1663. PM8001_IO_DBG(pm8001_ha,
  1664. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  1665. "NOT_SUPPORTED\n"));
  1666. ts->resp = SAS_TASK_COMPLETE;
  1667. ts->stat = SAS_OPEN_REJECT;
  1668. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1669. break;
  1670. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  1671. PM8001_IO_DBG(pm8001_ha,
  1672. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  1673. ts->resp = SAS_TASK_COMPLETE;
  1674. ts->stat = SAS_OPEN_REJECT;
  1675. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1676. break;
  1677. case IO_XFER_ERROR_NAK_RECEIVED:
  1678. PM8001_IO_DBG(pm8001_ha,
  1679. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  1680. ts->resp = SAS_TASK_COMPLETE;
  1681. ts->stat = SAS_OPEN_REJECT;
  1682. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1683. break;
  1684. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  1685. PM8001_IO_DBG(pm8001_ha,
  1686. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  1687. ts->resp = SAS_TASK_COMPLETE;
  1688. ts->stat = SAS_NAK_R_ERR;
  1689. break;
  1690. case IO_XFER_OPEN_RETRY_TIMEOUT:
  1691. PM8001_IO_DBG(pm8001_ha,
  1692. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  1693. ts->resp = SAS_TASK_COMPLETE;
  1694. ts->stat = SAS_OPEN_REJECT;
  1695. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1696. break;
  1697. case IO_XFER_ERROR_UNEXPECTED_PHASE:
  1698. PM8001_IO_DBG(pm8001_ha,
  1699. pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
  1700. ts->resp = SAS_TASK_COMPLETE;
  1701. ts->stat = SAS_DATA_OVERRUN;
  1702. break;
  1703. case IO_XFER_ERROR_XFER_RDY_OVERRUN:
  1704. PM8001_IO_DBG(pm8001_ha,
  1705. pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
  1706. ts->resp = SAS_TASK_COMPLETE;
  1707. ts->stat = SAS_DATA_OVERRUN;
  1708. break;
  1709. case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
  1710. PM8001_IO_DBG(pm8001_ha,
  1711. pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
  1712. ts->resp = SAS_TASK_COMPLETE;
  1713. ts->stat = SAS_DATA_OVERRUN;
  1714. break;
  1715. case IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
  1716. PM8001_IO_DBG(pm8001_ha,
  1717. pm8001_printk("IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT\n"));
  1718. ts->resp = SAS_TASK_COMPLETE;
  1719. ts->stat = SAS_DATA_OVERRUN;
  1720. break;
  1721. case IO_XFER_ERROR_OFFSET_MISMATCH:
  1722. PM8001_IO_DBG(pm8001_ha,
  1723. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  1724. ts->resp = SAS_TASK_COMPLETE;
  1725. ts->stat = SAS_DATA_OVERRUN;
  1726. break;
  1727. case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
  1728. PM8001_IO_DBG(pm8001_ha,
  1729. pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
  1730. ts->resp = SAS_TASK_COMPLETE;
  1731. ts->stat = SAS_DATA_OVERRUN;
  1732. break;
  1733. case IO_XFER_CMD_FRAME_ISSUED:
  1734. PM8001_IO_DBG(pm8001_ha,
  1735. pm8001_printk(" IO_XFER_CMD_FRAME_ISSUED\n"));
  1736. return;
  1737. default:
  1738. PM8001_IO_DBG(pm8001_ha,
  1739. pm8001_printk("Unknown status 0x%x\n", event));
  1740. /* not allowed case. Therefore, return failed status */
  1741. ts->resp = SAS_TASK_COMPLETE;
  1742. ts->stat = SAS_DATA_OVERRUN;
  1743. break;
  1744. }
  1745. spin_lock_irqsave(&t->task_state_lock, flags);
  1746. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  1747. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  1748. t->task_state_flags |= SAS_TASK_STATE_DONE;
  1749. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  1750. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1751. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
  1752. " event 0x%x resp 0x%x "
  1753. "stat 0x%x but aborted by upper layer!\n",
  1754. t, event, ts->resp, ts->stat));
  1755. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1756. } else {
  1757. spin_unlock_irqrestore(&t->task_state_lock, flags);
  1758. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1759. mb();/* in order to force CPU ordering */
  1760. t->task_done(t);
  1761. }
  1762. }
  1763. /*See the comments for mpi_ssp_completion */
  1764. static void
  1765. mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
  1766. {
  1767. struct sas_task *t;
  1768. struct pm8001_ccb_info *ccb;
  1769. unsigned long flags = 0;
  1770. u32 param;
  1771. u32 status;
  1772. u32 tag;
  1773. struct sata_completion_resp *psataPayload;
  1774. struct task_status_struct *ts;
  1775. struct ata_task_resp *resp ;
  1776. u32 *sata_resp;
  1777. struct pm8001_device *pm8001_dev;
  1778. psataPayload = (struct sata_completion_resp *)(piomb + 4);
  1779. status = le32_to_cpu(psataPayload->status);
  1780. tag = le32_to_cpu(psataPayload->tag);
  1781. ccb = &pm8001_ha->ccb_info[tag];
  1782. param = le32_to_cpu(psataPayload->param);
  1783. t = ccb->task;
  1784. ts = &t->task_status;
  1785. pm8001_dev = ccb->device;
  1786. if (status)
  1787. PM8001_FAIL_DBG(pm8001_ha,
  1788. pm8001_printk("sata IO status 0x%x\n", status));
  1789. if (unlikely(!t || !t->lldd_task || !t->dev))
  1790. return;
  1791. switch (status) {
  1792. case IO_SUCCESS:
  1793. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
  1794. if (param == 0) {
  1795. ts->resp = SAS_TASK_COMPLETE;
  1796. ts->stat = SAM_STAT_GOOD;
  1797. } else {
  1798. u8 len;
  1799. ts->resp = SAS_TASK_COMPLETE;
  1800. ts->stat = SAS_PROTO_RESPONSE;
  1801. ts->residual = param;
  1802. PM8001_IO_DBG(pm8001_ha,
  1803. pm8001_printk("SAS_PROTO_RESPONSE len = %d\n",
  1804. param));
  1805. sata_resp = &psataPayload->sata_resp[0];
  1806. resp = (struct ata_task_resp *)ts->buf;
  1807. if (t->ata_task.dma_xfer == 0 &&
  1808. t->data_dir == PCI_DMA_FROMDEVICE) {
  1809. len = sizeof(struct pio_setup_fis);
  1810. PM8001_IO_DBG(pm8001_ha,
  1811. pm8001_printk("PIO read len = %d\n", len));
  1812. } else if (t->ata_task.use_ncq) {
  1813. len = sizeof(struct set_dev_bits_fis);
  1814. PM8001_IO_DBG(pm8001_ha,
  1815. pm8001_printk("FPDMA len = %d\n", len));
  1816. } else {
  1817. len = sizeof(struct dev_to_host_fis);
  1818. PM8001_IO_DBG(pm8001_ha,
  1819. pm8001_printk("other len = %d\n", len));
  1820. }
  1821. if (SAS_STATUS_BUF_SIZE >= sizeof(*resp)) {
  1822. resp->frame_len = len;
  1823. memcpy(&resp->ending_fis[0], sata_resp, len);
  1824. ts->buf_valid_size = sizeof(*resp);
  1825. } else
  1826. PM8001_IO_DBG(pm8001_ha,
  1827. pm8001_printk("response to large \n"));
  1828. }
  1829. if (pm8001_dev)
  1830. pm8001_dev->running_req--;
  1831. break;
  1832. case IO_ABORTED:
  1833. PM8001_IO_DBG(pm8001_ha,
  1834. pm8001_printk("IO_ABORTED IOMB Tag \n"));
  1835. ts->resp = SAS_TASK_COMPLETE;
  1836. ts->stat = SAS_ABORTED_TASK;
  1837. if (pm8001_dev)
  1838. pm8001_dev->running_req--;
  1839. break;
  1840. /* following cases are to do cases */
  1841. case IO_UNDERFLOW:
  1842. /* SATA Completion with error */
  1843. PM8001_IO_DBG(pm8001_ha,
  1844. pm8001_printk("IO_UNDERFLOW param = %d\n", param));
  1845. ts->resp = SAS_TASK_COMPLETE;
  1846. ts->stat = SAS_DATA_UNDERRUN;
  1847. ts->residual = param;
  1848. if (pm8001_dev)
  1849. pm8001_dev->running_req--;
  1850. break;
  1851. case IO_NO_DEVICE:
  1852. PM8001_IO_DBG(pm8001_ha,
  1853. pm8001_printk("IO_NO_DEVICE\n"));
  1854. ts->resp = SAS_TASK_UNDELIVERED;
  1855. ts->stat = SAS_PHY_DOWN;
  1856. break;
  1857. case IO_XFER_ERROR_BREAK:
  1858. PM8001_IO_DBG(pm8001_ha,
  1859. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  1860. ts->resp = SAS_TASK_COMPLETE;
  1861. ts->stat = SAS_INTERRUPTED;
  1862. break;
  1863. case IO_XFER_ERROR_PHY_NOT_READY:
  1864. PM8001_IO_DBG(pm8001_ha,
  1865. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  1866. ts->resp = SAS_TASK_COMPLETE;
  1867. ts->stat = SAS_OPEN_REJECT;
  1868. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  1869. break;
  1870. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  1871. PM8001_IO_DBG(pm8001_ha,
  1872. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
  1873. "_SUPPORTED\n"));
  1874. ts->resp = SAS_TASK_COMPLETE;
  1875. ts->stat = SAS_OPEN_REJECT;
  1876. ts->open_rej_reason = SAS_OREJ_EPROTO;
  1877. break;
  1878. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  1879. PM8001_IO_DBG(pm8001_ha,
  1880. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  1881. ts->resp = SAS_TASK_COMPLETE;
  1882. ts->stat = SAS_OPEN_REJECT;
  1883. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  1884. break;
  1885. case IO_OPEN_CNX_ERROR_BREAK:
  1886. PM8001_IO_DBG(pm8001_ha,
  1887. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  1888. ts->resp = SAS_TASK_COMPLETE;
  1889. ts->stat = SAS_OPEN_REJECT;
  1890. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  1891. break;
  1892. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  1893. PM8001_IO_DBG(pm8001_ha,
  1894. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  1895. ts->resp = SAS_TASK_COMPLETE;
  1896. ts->stat = SAS_DEV_NO_RESPONSE;
  1897. if (!t->uldd_task) {
  1898. pm8001_handle_event(pm8001_ha,
  1899. pm8001_dev,
  1900. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  1901. ts->resp = SAS_TASK_UNDELIVERED;
  1902. ts->stat = SAS_QUEUE_FULL;
  1903. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1904. mb();/*in order to force CPU ordering*/
  1905. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1906. t->task_done(t);
  1907. spin_lock_irqsave(&pm8001_ha->lock, flags);
  1908. return;
  1909. }
  1910. break;
  1911. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  1912. PM8001_IO_DBG(pm8001_ha,
  1913. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  1914. ts->resp = SAS_TASK_UNDELIVERED;
  1915. ts->stat = SAS_OPEN_REJECT;
  1916. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  1917. if (!t->uldd_task) {
  1918. pm8001_handle_event(pm8001_ha,
  1919. pm8001_dev,
  1920. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  1921. ts->resp = SAS_TASK_UNDELIVERED;
  1922. ts->stat = SAS_QUEUE_FULL;
  1923. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1924. mb();/*ditto*/
  1925. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1926. t->task_done(t);
  1927. spin_lock_irqsave(&pm8001_ha->lock, flags);
  1928. return;
  1929. }
  1930. break;
  1931. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  1932. PM8001_IO_DBG(pm8001_ha,
  1933. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  1934. "NOT_SUPPORTED\n"));
  1935. ts->resp = SAS_TASK_COMPLETE;
  1936. ts->stat = SAS_OPEN_REJECT;
  1937. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  1938. break;
  1939. case IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
  1940. PM8001_IO_DBG(pm8001_ha,
  1941. pm8001_printk("IO_OPEN_CNX_ERROR_STP_RESOURCES"
  1942. "_BUSY\n"));
  1943. ts->resp = SAS_TASK_COMPLETE;
  1944. ts->stat = SAS_DEV_NO_RESPONSE;
  1945. if (!t->uldd_task) {
  1946. pm8001_handle_event(pm8001_ha,
  1947. pm8001_dev,
  1948. IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY);
  1949. ts->resp = SAS_TASK_UNDELIVERED;
  1950. ts->stat = SAS_QUEUE_FULL;
  1951. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  1952. mb();/* ditto*/
  1953. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  1954. t->task_done(t);
  1955. spin_lock_irqsave(&pm8001_ha->lock, flags);
  1956. return;
  1957. }
  1958. break;
  1959. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  1960. PM8001_IO_DBG(pm8001_ha,
  1961. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  1962. ts->resp = SAS_TASK_COMPLETE;
  1963. ts->stat = SAS_OPEN_REJECT;
  1964. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  1965. break;
  1966. case IO_XFER_ERROR_NAK_RECEIVED:
  1967. PM8001_IO_DBG(pm8001_ha,
  1968. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  1969. ts->resp = SAS_TASK_COMPLETE;
  1970. ts->stat = SAS_NAK_R_ERR;
  1971. break;
  1972. case IO_XFER_ERROR_ACK_NAK_TIMEOUT:
  1973. PM8001_IO_DBG(pm8001_ha,
  1974. pm8001_printk("IO_XFER_ERROR_ACK_NAK_TIMEOUT\n"));
  1975. ts->resp = SAS_TASK_COMPLETE;
  1976. ts->stat = SAS_NAK_R_ERR;
  1977. break;
  1978. case IO_XFER_ERROR_DMA:
  1979. PM8001_IO_DBG(pm8001_ha,
  1980. pm8001_printk("IO_XFER_ERROR_DMA\n"));
  1981. ts->resp = SAS_TASK_COMPLETE;
  1982. ts->stat = SAS_ABORTED_TASK;
  1983. break;
  1984. case IO_XFER_ERROR_SATA_LINK_TIMEOUT:
  1985. PM8001_IO_DBG(pm8001_ha,
  1986. pm8001_printk("IO_XFER_ERROR_SATA_LINK_TIMEOUT\n"));
  1987. ts->resp = SAS_TASK_UNDELIVERED;
  1988. ts->stat = SAS_DEV_NO_RESPONSE;
  1989. break;
  1990. case IO_XFER_ERROR_REJECTED_NCQ_MODE:
  1991. PM8001_IO_DBG(pm8001_ha,
  1992. pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
  1993. ts->resp = SAS_TASK_COMPLETE;
  1994. ts->stat = SAS_DATA_UNDERRUN;
  1995. break;
  1996. case IO_XFER_OPEN_RETRY_TIMEOUT:
  1997. PM8001_IO_DBG(pm8001_ha,
  1998. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  1999. ts->resp = SAS_TASK_COMPLETE;
  2000. ts->stat = SAS_OPEN_TO;
  2001. break;
  2002. case IO_PORT_IN_RESET:
  2003. PM8001_IO_DBG(pm8001_ha,
  2004. pm8001_printk("IO_PORT_IN_RESET\n"));
  2005. ts->resp = SAS_TASK_COMPLETE;
  2006. ts->stat = SAS_DEV_NO_RESPONSE;
  2007. break;
  2008. case IO_DS_NON_OPERATIONAL:
  2009. PM8001_IO_DBG(pm8001_ha,
  2010. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  2011. ts->resp = SAS_TASK_COMPLETE;
  2012. ts->stat = SAS_DEV_NO_RESPONSE;
  2013. if (!t->uldd_task) {
  2014. pm8001_handle_event(pm8001_ha, pm8001_dev,
  2015. IO_DS_NON_OPERATIONAL);
  2016. ts->resp = SAS_TASK_UNDELIVERED;
  2017. ts->stat = SAS_QUEUE_FULL;
  2018. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2019. mb();/*ditto*/
  2020. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  2021. t->task_done(t);
  2022. spin_lock_irqsave(&pm8001_ha->lock, flags);
  2023. return;
  2024. }
  2025. break;
  2026. case IO_DS_IN_RECOVERY:
  2027. PM8001_IO_DBG(pm8001_ha,
  2028. pm8001_printk(" IO_DS_IN_RECOVERY\n"));
  2029. ts->resp = SAS_TASK_COMPLETE;
  2030. ts->stat = SAS_DEV_NO_RESPONSE;
  2031. break;
  2032. case IO_DS_IN_ERROR:
  2033. PM8001_IO_DBG(pm8001_ha,
  2034. pm8001_printk("IO_DS_IN_ERROR\n"));
  2035. ts->resp = SAS_TASK_COMPLETE;
  2036. ts->stat = SAS_DEV_NO_RESPONSE;
  2037. if (!t->uldd_task) {
  2038. pm8001_handle_event(pm8001_ha, pm8001_dev,
  2039. IO_DS_IN_ERROR);
  2040. ts->resp = SAS_TASK_UNDELIVERED;
  2041. ts->stat = SAS_QUEUE_FULL;
  2042. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2043. mb();/*ditto*/
  2044. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  2045. t->task_done(t);
  2046. spin_lock_irqsave(&pm8001_ha->lock, flags);
  2047. return;
  2048. }
  2049. break;
  2050. case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  2051. PM8001_IO_DBG(pm8001_ha,
  2052. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  2053. ts->resp = SAS_TASK_COMPLETE;
  2054. ts->stat = SAS_OPEN_REJECT;
  2055. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2056. default:
  2057. PM8001_IO_DBG(pm8001_ha,
  2058. pm8001_printk("Unknown status 0x%x\n", status));
  2059. /* not allowed case. Therefore, return failed status */
  2060. ts->resp = SAS_TASK_COMPLETE;
  2061. ts->stat = SAS_DEV_NO_RESPONSE;
  2062. break;
  2063. }
  2064. spin_lock_irqsave(&t->task_state_lock, flags);
  2065. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2066. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2067. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2068. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2069. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2070. PM8001_FAIL_DBG(pm8001_ha,
  2071. pm8001_printk("task 0x%p done with io_status 0x%x"
  2072. " resp 0x%x stat 0x%x but aborted by upper layer!\n",
  2073. t, status, ts->resp, ts->stat));
  2074. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2075. } else if (t->uldd_task) {
  2076. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2077. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2078. mb();/* ditto */
  2079. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  2080. t->task_done(t);
  2081. spin_lock_irqsave(&pm8001_ha->lock, flags);
  2082. } else if (!t->uldd_task) {
  2083. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2084. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2085. mb();/*ditto*/
  2086. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  2087. t->task_done(t);
  2088. spin_lock_irqsave(&pm8001_ha->lock, flags);
  2089. }
  2090. }
  2091. /*See the comments for mpi_ssp_completion */
  2092. static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
  2093. {
  2094. struct sas_task *t;
  2095. unsigned long flags = 0;
  2096. struct task_status_struct *ts;
  2097. struct pm8001_ccb_info *ccb;
  2098. struct pm8001_device *pm8001_dev;
  2099. struct sata_event_resp *psataPayload =
  2100. (struct sata_event_resp *)(piomb + 4);
  2101. u32 event = le32_to_cpu(psataPayload->event);
  2102. u32 tag = le32_to_cpu(psataPayload->tag);
  2103. u32 port_id = le32_to_cpu(psataPayload->port_id);
  2104. u32 dev_id = le32_to_cpu(psataPayload->device_id);
  2105. ccb = &pm8001_ha->ccb_info[tag];
  2106. t = ccb->task;
  2107. pm8001_dev = ccb->device;
  2108. if (event)
  2109. PM8001_FAIL_DBG(pm8001_ha,
  2110. pm8001_printk("sata IO status 0x%x\n", event));
  2111. if (unlikely(!t || !t->lldd_task || !t->dev))
  2112. return;
  2113. ts = &t->task_status;
  2114. PM8001_IO_DBG(pm8001_ha,
  2115. pm8001_printk("port_id = %x,device_id = %x\n",
  2116. port_id, dev_id));
  2117. switch (event) {
  2118. case IO_OVERFLOW:
  2119. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
  2120. ts->resp = SAS_TASK_COMPLETE;
  2121. ts->stat = SAS_DATA_OVERRUN;
  2122. ts->residual = 0;
  2123. if (pm8001_dev)
  2124. pm8001_dev->running_req--;
  2125. break;
  2126. case IO_XFER_ERROR_BREAK:
  2127. PM8001_IO_DBG(pm8001_ha,
  2128. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  2129. ts->resp = SAS_TASK_COMPLETE;
  2130. ts->stat = SAS_INTERRUPTED;
  2131. break;
  2132. case IO_XFER_ERROR_PHY_NOT_READY:
  2133. PM8001_IO_DBG(pm8001_ha,
  2134. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  2135. ts->resp = SAS_TASK_COMPLETE;
  2136. ts->stat = SAS_OPEN_REJECT;
  2137. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2138. break;
  2139. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  2140. PM8001_IO_DBG(pm8001_ha,
  2141. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT"
  2142. "_SUPPORTED\n"));
  2143. ts->resp = SAS_TASK_COMPLETE;
  2144. ts->stat = SAS_OPEN_REJECT;
  2145. ts->open_rej_reason = SAS_OREJ_EPROTO;
  2146. break;
  2147. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  2148. PM8001_IO_DBG(pm8001_ha,
  2149. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  2150. ts->resp = SAS_TASK_COMPLETE;
  2151. ts->stat = SAS_OPEN_REJECT;
  2152. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2153. break;
  2154. case IO_OPEN_CNX_ERROR_BREAK:
  2155. PM8001_IO_DBG(pm8001_ha,
  2156. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  2157. ts->resp = SAS_TASK_COMPLETE;
  2158. ts->stat = SAS_OPEN_REJECT;
  2159. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  2160. break;
  2161. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  2162. PM8001_IO_DBG(pm8001_ha,
  2163. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  2164. ts->resp = SAS_TASK_UNDELIVERED;
  2165. ts->stat = SAS_DEV_NO_RESPONSE;
  2166. if (!t->uldd_task) {
  2167. pm8001_handle_event(pm8001_ha,
  2168. pm8001_dev,
  2169. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2170. ts->resp = SAS_TASK_COMPLETE;
  2171. ts->stat = SAS_QUEUE_FULL;
  2172. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2173. mb();/*ditto*/
  2174. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  2175. t->task_done(t);
  2176. spin_lock_irqsave(&pm8001_ha->lock, flags);
  2177. return;
  2178. }
  2179. break;
  2180. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  2181. PM8001_IO_DBG(pm8001_ha,
  2182. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  2183. ts->resp = SAS_TASK_UNDELIVERED;
  2184. ts->stat = SAS_OPEN_REJECT;
  2185. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  2186. break;
  2187. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  2188. PM8001_IO_DBG(pm8001_ha,
  2189. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  2190. "NOT_SUPPORTED\n"));
  2191. ts->resp = SAS_TASK_COMPLETE;
  2192. ts->stat = SAS_OPEN_REJECT;
  2193. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  2194. break;
  2195. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  2196. PM8001_IO_DBG(pm8001_ha,
  2197. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  2198. ts->resp = SAS_TASK_COMPLETE;
  2199. ts->stat = SAS_OPEN_REJECT;
  2200. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2201. break;
  2202. case IO_XFER_ERROR_NAK_RECEIVED:
  2203. PM8001_IO_DBG(pm8001_ha,
  2204. pm8001_printk("IO_XFER_ERROR_NAK_RECEIVED\n"));
  2205. ts->resp = SAS_TASK_COMPLETE;
  2206. ts->stat = SAS_NAK_R_ERR;
  2207. break;
  2208. case IO_XFER_ERROR_PEER_ABORTED:
  2209. PM8001_IO_DBG(pm8001_ha,
  2210. pm8001_printk("IO_XFER_ERROR_PEER_ABORTED\n"));
  2211. ts->resp = SAS_TASK_COMPLETE;
  2212. ts->stat = SAS_NAK_R_ERR;
  2213. break;
  2214. case IO_XFER_ERROR_REJECTED_NCQ_MODE:
  2215. PM8001_IO_DBG(pm8001_ha,
  2216. pm8001_printk("IO_XFER_ERROR_REJECTED_NCQ_MODE\n"));
  2217. ts->resp = SAS_TASK_COMPLETE;
  2218. ts->stat = SAS_DATA_UNDERRUN;
  2219. break;
  2220. case IO_XFER_OPEN_RETRY_TIMEOUT:
  2221. PM8001_IO_DBG(pm8001_ha,
  2222. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  2223. ts->resp = SAS_TASK_COMPLETE;
  2224. ts->stat = SAS_OPEN_TO;
  2225. break;
  2226. case IO_XFER_ERROR_UNEXPECTED_PHASE:
  2227. PM8001_IO_DBG(pm8001_ha,
  2228. pm8001_printk("IO_XFER_ERROR_UNEXPECTED_PHASE\n"));
  2229. ts->resp = SAS_TASK_COMPLETE;
  2230. ts->stat = SAS_OPEN_TO;
  2231. break;
  2232. case IO_XFER_ERROR_XFER_RDY_OVERRUN:
  2233. PM8001_IO_DBG(pm8001_ha,
  2234. pm8001_printk("IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
  2235. ts->resp = SAS_TASK_COMPLETE;
  2236. ts->stat = SAS_OPEN_TO;
  2237. break;
  2238. case IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
  2239. PM8001_IO_DBG(pm8001_ha,
  2240. pm8001_printk("IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED\n"));
  2241. ts->resp = SAS_TASK_COMPLETE;
  2242. ts->stat = SAS_OPEN_TO;
  2243. break;
  2244. case IO_XFER_ERROR_OFFSET_MISMATCH:
  2245. PM8001_IO_DBG(pm8001_ha,
  2246. pm8001_printk("IO_XFER_ERROR_OFFSET_MISMATCH\n"));
  2247. ts->resp = SAS_TASK_COMPLETE;
  2248. ts->stat = SAS_OPEN_TO;
  2249. break;
  2250. case IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
  2251. PM8001_IO_DBG(pm8001_ha,
  2252. pm8001_printk("IO_XFER_ERROR_XFER_ZERO_DATA_LEN\n"));
  2253. ts->resp = SAS_TASK_COMPLETE;
  2254. ts->stat = SAS_OPEN_TO;
  2255. break;
  2256. case IO_XFER_CMD_FRAME_ISSUED:
  2257. PM8001_IO_DBG(pm8001_ha,
  2258. pm8001_printk("IO_XFER_CMD_FRAME_ISSUED\n"));
  2259. break;
  2260. case IO_XFER_PIO_SETUP_ERROR:
  2261. PM8001_IO_DBG(pm8001_ha,
  2262. pm8001_printk("IO_XFER_PIO_SETUP_ERROR\n"));
  2263. ts->resp = SAS_TASK_COMPLETE;
  2264. ts->stat = SAS_OPEN_TO;
  2265. break;
  2266. default:
  2267. PM8001_IO_DBG(pm8001_ha,
  2268. pm8001_printk("Unknown status 0x%x\n", event));
  2269. /* not allowed case. Therefore, return failed status */
  2270. ts->resp = SAS_TASK_COMPLETE;
  2271. ts->stat = SAS_OPEN_TO;
  2272. break;
  2273. }
  2274. spin_lock_irqsave(&t->task_state_lock, flags);
  2275. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2276. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2277. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2278. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2279. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2280. PM8001_FAIL_DBG(pm8001_ha,
  2281. pm8001_printk("task 0x%p done with io_status 0x%x"
  2282. " resp 0x%x stat 0x%x but aborted by upper layer!\n",
  2283. t, event, ts->resp, ts->stat));
  2284. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2285. } else if (t->uldd_task) {
  2286. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2287. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2288. mb();/* ditto */
  2289. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  2290. t->task_done(t);
  2291. spin_lock_irqsave(&pm8001_ha->lock, flags);
  2292. } else if (!t->uldd_task) {
  2293. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2294. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2295. mb();/*ditto*/
  2296. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  2297. t->task_done(t);
  2298. spin_lock_irqsave(&pm8001_ha->lock, flags);
  2299. }
  2300. }
  2301. /*See the comments for mpi_ssp_completion */
  2302. static void
  2303. mpi_smp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2304. {
  2305. u32 param;
  2306. struct sas_task *t;
  2307. struct pm8001_ccb_info *ccb;
  2308. unsigned long flags;
  2309. u32 status;
  2310. u32 tag;
  2311. struct smp_completion_resp *psmpPayload;
  2312. struct task_status_struct *ts;
  2313. struct pm8001_device *pm8001_dev;
  2314. psmpPayload = (struct smp_completion_resp *)(piomb + 4);
  2315. status = le32_to_cpu(psmpPayload->status);
  2316. tag = le32_to_cpu(psmpPayload->tag);
  2317. ccb = &pm8001_ha->ccb_info[tag];
  2318. param = le32_to_cpu(psmpPayload->param);
  2319. t = ccb->task;
  2320. ts = &t->task_status;
  2321. pm8001_dev = ccb->device;
  2322. if (status)
  2323. PM8001_FAIL_DBG(pm8001_ha,
  2324. pm8001_printk("smp IO status 0x%x\n", status));
  2325. if (unlikely(!t || !t->lldd_task || !t->dev))
  2326. return;
  2327. switch (status) {
  2328. case IO_SUCCESS:
  2329. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
  2330. ts->resp = SAS_TASK_COMPLETE;
  2331. ts->stat = SAM_STAT_GOOD;
  2332. if (pm8001_dev)
  2333. pm8001_dev->running_req--;
  2334. break;
  2335. case IO_ABORTED:
  2336. PM8001_IO_DBG(pm8001_ha,
  2337. pm8001_printk("IO_ABORTED IOMB\n"));
  2338. ts->resp = SAS_TASK_COMPLETE;
  2339. ts->stat = SAS_ABORTED_TASK;
  2340. if (pm8001_dev)
  2341. pm8001_dev->running_req--;
  2342. break;
  2343. case IO_OVERFLOW:
  2344. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_UNDERFLOW\n"));
  2345. ts->resp = SAS_TASK_COMPLETE;
  2346. ts->stat = SAS_DATA_OVERRUN;
  2347. ts->residual = 0;
  2348. if (pm8001_dev)
  2349. pm8001_dev->running_req--;
  2350. break;
  2351. case IO_NO_DEVICE:
  2352. PM8001_IO_DBG(pm8001_ha, pm8001_printk("IO_NO_DEVICE\n"));
  2353. ts->resp = SAS_TASK_COMPLETE;
  2354. ts->stat = SAS_PHY_DOWN;
  2355. break;
  2356. case IO_ERROR_HW_TIMEOUT:
  2357. PM8001_IO_DBG(pm8001_ha,
  2358. pm8001_printk("IO_ERROR_HW_TIMEOUT\n"));
  2359. ts->resp = SAS_TASK_COMPLETE;
  2360. ts->stat = SAM_STAT_BUSY;
  2361. break;
  2362. case IO_XFER_ERROR_BREAK:
  2363. PM8001_IO_DBG(pm8001_ha,
  2364. pm8001_printk("IO_XFER_ERROR_BREAK\n"));
  2365. ts->resp = SAS_TASK_COMPLETE;
  2366. ts->stat = SAM_STAT_BUSY;
  2367. break;
  2368. case IO_XFER_ERROR_PHY_NOT_READY:
  2369. PM8001_IO_DBG(pm8001_ha,
  2370. pm8001_printk("IO_XFER_ERROR_PHY_NOT_READY\n"));
  2371. ts->resp = SAS_TASK_COMPLETE;
  2372. ts->stat = SAM_STAT_BUSY;
  2373. break;
  2374. case IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
  2375. PM8001_IO_DBG(pm8001_ha,
  2376. pm8001_printk("IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED\n"));
  2377. ts->resp = SAS_TASK_COMPLETE;
  2378. ts->stat = SAS_OPEN_REJECT;
  2379. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2380. break;
  2381. case IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
  2382. PM8001_IO_DBG(pm8001_ha,
  2383. pm8001_printk("IO_OPEN_CNX_ERROR_ZONE_VIOLATION\n"));
  2384. ts->resp = SAS_TASK_COMPLETE;
  2385. ts->stat = SAS_OPEN_REJECT;
  2386. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2387. break;
  2388. case IO_OPEN_CNX_ERROR_BREAK:
  2389. PM8001_IO_DBG(pm8001_ha,
  2390. pm8001_printk("IO_OPEN_CNX_ERROR_BREAK\n"));
  2391. ts->resp = SAS_TASK_COMPLETE;
  2392. ts->stat = SAS_OPEN_REJECT;
  2393. ts->open_rej_reason = SAS_OREJ_RSVD_CONT0;
  2394. break;
  2395. case IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
  2396. PM8001_IO_DBG(pm8001_ha,
  2397. pm8001_printk("IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS\n"));
  2398. ts->resp = SAS_TASK_COMPLETE;
  2399. ts->stat = SAS_OPEN_REJECT;
  2400. ts->open_rej_reason = SAS_OREJ_UNKNOWN;
  2401. pm8001_handle_event(pm8001_ha,
  2402. pm8001_dev,
  2403. IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS);
  2404. break;
  2405. case IO_OPEN_CNX_ERROR_BAD_DESTINATION:
  2406. PM8001_IO_DBG(pm8001_ha,
  2407. pm8001_printk("IO_OPEN_CNX_ERROR_BAD_DESTINATION\n"));
  2408. ts->resp = SAS_TASK_COMPLETE;
  2409. ts->stat = SAS_OPEN_REJECT;
  2410. ts->open_rej_reason = SAS_OREJ_BAD_DEST;
  2411. break;
  2412. case IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
  2413. PM8001_IO_DBG(pm8001_ha,
  2414. pm8001_printk("IO_OPEN_CNX_ERROR_CONNECTION_RATE_"
  2415. "NOT_SUPPORTED\n"));
  2416. ts->resp = SAS_TASK_COMPLETE;
  2417. ts->stat = SAS_OPEN_REJECT;
  2418. ts->open_rej_reason = SAS_OREJ_CONN_RATE;
  2419. break;
  2420. case IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
  2421. PM8001_IO_DBG(pm8001_ha,
  2422. pm8001_printk("IO_OPEN_CNX_ERROR_WRONG_DESTINATION\n"));
  2423. ts->resp = SAS_TASK_COMPLETE;
  2424. ts->stat = SAS_OPEN_REJECT;
  2425. ts->open_rej_reason = SAS_OREJ_WRONG_DEST;
  2426. break;
  2427. case IO_XFER_ERROR_RX_FRAME:
  2428. PM8001_IO_DBG(pm8001_ha,
  2429. pm8001_printk("IO_XFER_ERROR_RX_FRAME\n"));
  2430. ts->resp = SAS_TASK_COMPLETE;
  2431. ts->stat = SAS_DEV_NO_RESPONSE;
  2432. break;
  2433. case IO_XFER_OPEN_RETRY_TIMEOUT:
  2434. PM8001_IO_DBG(pm8001_ha,
  2435. pm8001_printk("IO_XFER_OPEN_RETRY_TIMEOUT\n"));
  2436. ts->resp = SAS_TASK_COMPLETE;
  2437. ts->stat = SAS_OPEN_REJECT;
  2438. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2439. break;
  2440. case IO_ERROR_INTERNAL_SMP_RESOURCE:
  2441. PM8001_IO_DBG(pm8001_ha,
  2442. pm8001_printk("IO_ERROR_INTERNAL_SMP_RESOURCE\n"));
  2443. ts->resp = SAS_TASK_COMPLETE;
  2444. ts->stat = SAS_QUEUE_FULL;
  2445. break;
  2446. case IO_PORT_IN_RESET:
  2447. PM8001_IO_DBG(pm8001_ha,
  2448. pm8001_printk("IO_PORT_IN_RESET\n"));
  2449. ts->resp = SAS_TASK_COMPLETE;
  2450. ts->stat = SAS_OPEN_REJECT;
  2451. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2452. break;
  2453. case IO_DS_NON_OPERATIONAL:
  2454. PM8001_IO_DBG(pm8001_ha,
  2455. pm8001_printk("IO_DS_NON_OPERATIONAL\n"));
  2456. ts->resp = SAS_TASK_COMPLETE;
  2457. ts->stat = SAS_DEV_NO_RESPONSE;
  2458. break;
  2459. case IO_DS_IN_RECOVERY:
  2460. PM8001_IO_DBG(pm8001_ha,
  2461. pm8001_printk("IO_DS_IN_RECOVERY\n"));
  2462. ts->resp = SAS_TASK_COMPLETE;
  2463. ts->stat = SAS_OPEN_REJECT;
  2464. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2465. break;
  2466. case IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
  2467. PM8001_IO_DBG(pm8001_ha,
  2468. pm8001_printk("IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY\n"));
  2469. ts->resp = SAS_TASK_COMPLETE;
  2470. ts->stat = SAS_OPEN_REJECT;
  2471. ts->open_rej_reason = SAS_OREJ_RSVD_RETRY;
  2472. break;
  2473. default:
  2474. PM8001_IO_DBG(pm8001_ha,
  2475. pm8001_printk("Unknown status 0x%x\n", status));
  2476. ts->resp = SAS_TASK_COMPLETE;
  2477. ts->stat = SAS_DEV_NO_RESPONSE;
  2478. /* not allowed case. Therefore, return failed status */
  2479. break;
  2480. }
  2481. spin_lock_irqsave(&t->task_state_lock, flags);
  2482. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  2483. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  2484. t->task_state_flags |= SAS_TASK_STATE_DONE;
  2485. if (unlikely((t->task_state_flags & SAS_TASK_STATE_ABORTED))) {
  2486. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2487. PM8001_FAIL_DBG(pm8001_ha, pm8001_printk("task 0x%p done with"
  2488. " io_status 0x%x resp 0x%x "
  2489. "stat 0x%x but aborted by upper layer!\n",
  2490. t, status, ts->resp, ts->stat));
  2491. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2492. } else {
  2493. spin_unlock_irqrestore(&t->task_state_lock, flags);
  2494. pm8001_ccb_task_free(pm8001_ha, t, ccb, tag);
  2495. mb();/* in order to force CPU ordering */
  2496. t->task_done(t);
  2497. }
  2498. }
  2499. static void
  2500. mpi_set_dev_state_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2501. {
  2502. struct set_dev_state_resp *pPayload =
  2503. (struct set_dev_state_resp *)(piomb + 4);
  2504. u32 tag = le32_to_cpu(pPayload->tag);
  2505. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
  2506. struct pm8001_device *pm8001_dev = ccb->device;
  2507. u32 status = le32_to_cpu(pPayload->status);
  2508. u32 device_id = le32_to_cpu(pPayload->device_id);
  2509. u8 pds = le32_to_cpu(pPayload->pds_nds) | PDS_BITS;
  2510. u8 nds = le32_to_cpu(pPayload->pds_nds) | NDS_BITS;
  2511. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set device id = 0x%x state "
  2512. "from 0x%x to 0x%x status = 0x%x!\n",
  2513. device_id, pds, nds, status));
  2514. complete(pm8001_dev->setds_completion);
  2515. ccb->task = NULL;
  2516. ccb->ccb_tag = 0xFFFFFFFF;
  2517. pm8001_ccb_free(pm8001_ha, tag);
  2518. }
  2519. static void
  2520. mpi_set_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2521. {
  2522. struct get_nvm_data_resp *pPayload =
  2523. (struct get_nvm_data_resp *)(piomb + 4);
  2524. u32 tag = le32_to_cpu(pPayload->tag);
  2525. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
  2526. u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
  2527. complete(pm8001_ha->nvmd_completion);
  2528. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Set nvm data complete!\n"));
  2529. if ((dlen_status & NVMD_STAT) != 0) {
  2530. PM8001_FAIL_DBG(pm8001_ha,
  2531. pm8001_printk("Set nvm data error!\n"));
  2532. return;
  2533. }
  2534. ccb->task = NULL;
  2535. ccb->ccb_tag = 0xFFFFFFFF;
  2536. pm8001_ccb_free(pm8001_ha, tag);
  2537. }
  2538. static void
  2539. mpi_get_nvmd_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2540. {
  2541. struct fw_control_ex *fw_control_context;
  2542. struct get_nvm_data_resp *pPayload =
  2543. (struct get_nvm_data_resp *)(piomb + 4);
  2544. u32 tag = le32_to_cpu(pPayload->tag);
  2545. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
  2546. u32 dlen_status = le32_to_cpu(pPayload->dlen_status);
  2547. u32 ir_tds_bn_dps_das_nvm =
  2548. le32_to_cpu(pPayload->ir_tda_bn_dps_das_nvm);
  2549. void *virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr;
  2550. fw_control_context = ccb->fw_control_context;
  2551. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("Get nvm data complete!\n"));
  2552. if ((dlen_status & NVMD_STAT) != 0) {
  2553. PM8001_FAIL_DBG(pm8001_ha,
  2554. pm8001_printk("Get nvm data error!\n"));
  2555. complete(pm8001_ha->nvmd_completion);
  2556. return;
  2557. }
  2558. if (ir_tds_bn_dps_das_nvm & IPMode) {
  2559. /* indirect mode - IR bit set */
  2560. PM8001_MSG_DBG(pm8001_ha,
  2561. pm8001_printk("Get NVMD success, IR=1\n"));
  2562. if ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == TWI_DEVICE) {
  2563. if (ir_tds_bn_dps_das_nvm == 0x80a80200) {
  2564. memcpy(pm8001_ha->sas_addr,
  2565. ((u8 *)virt_addr + 4),
  2566. SAS_ADDR_SIZE);
  2567. PM8001_MSG_DBG(pm8001_ha,
  2568. pm8001_printk("Get SAS address"
  2569. " from VPD successfully!\n"));
  2570. }
  2571. } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == C_SEEPROM)
  2572. || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == VPD_FLASH) ||
  2573. ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == EXPAN_ROM)) {
  2574. ;
  2575. } else if (((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == AAP1_RDUMP)
  2576. || ((ir_tds_bn_dps_das_nvm & NVMD_TYPE) == IOP_RDUMP)) {
  2577. ;
  2578. } else {
  2579. /* Should not be happened*/
  2580. PM8001_MSG_DBG(pm8001_ha,
  2581. pm8001_printk("(IR=1)Wrong Device type 0x%x\n",
  2582. ir_tds_bn_dps_das_nvm));
  2583. }
  2584. } else /* direct mode */{
  2585. PM8001_MSG_DBG(pm8001_ha,
  2586. pm8001_printk("Get NVMD success, IR=0, dataLen=%d\n",
  2587. (dlen_status & NVMD_LEN) >> 24));
  2588. }
  2589. memcpy(fw_control_context->usrAddr,
  2590. pm8001_ha->memoryMap.region[NVMD].virt_ptr,
  2591. fw_control_context->len);
  2592. complete(pm8001_ha->nvmd_completion);
  2593. ccb->task = NULL;
  2594. ccb->ccb_tag = 0xFFFFFFFF;
  2595. pm8001_ccb_free(pm8001_ha, tag);
  2596. }
  2597. static int mpi_local_phy_ctl(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2598. {
  2599. struct local_phy_ctl_resp *pPayload =
  2600. (struct local_phy_ctl_resp *)(piomb + 4);
  2601. u32 status = le32_to_cpu(pPayload->status);
  2602. u32 phy_id = le32_to_cpu(pPayload->phyop_phyid) & ID_BITS;
  2603. u32 phy_op = le32_to_cpu(pPayload->phyop_phyid) & OP_BITS;
  2604. if (status != 0) {
  2605. PM8001_MSG_DBG(pm8001_ha,
  2606. pm8001_printk("%x phy execute %x phy op failed! \n",
  2607. phy_id, phy_op));
  2608. } else
  2609. PM8001_MSG_DBG(pm8001_ha,
  2610. pm8001_printk("%x phy execute %x phy op success! \n",
  2611. phy_id, phy_op));
  2612. return 0;
  2613. }
  2614. /**
  2615. * pm8001_bytes_dmaed - one of the interface function communication with libsas
  2616. * @pm8001_ha: our hba card information
  2617. * @i: which phy that received the event.
  2618. *
  2619. * when HBA driver received the identify done event or initiate FIS received
  2620. * event(for SATA), it will invoke this function to notify the sas layer that
  2621. * the sas toplogy has formed, please discover the the whole sas domain,
  2622. * while receive a broadcast(change) primitive just tell the sas
  2623. * layer to discover the changed domain rather than the whole domain.
  2624. */
  2625. static void pm8001_bytes_dmaed(struct pm8001_hba_info *pm8001_ha, int i)
  2626. {
  2627. struct pm8001_phy *phy = &pm8001_ha->phy[i];
  2628. struct asd_sas_phy *sas_phy = &phy->sas_phy;
  2629. struct sas_ha_struct *sas_ha;
  2630. if (!phy->phy_attached)
  2631. return;
  2632. sas_ha = pm8001_ha->sas;
  2633. if (sas_phy->phy) {
  2634. struct sas_phy *sphy = sas_phy->phy;
  2635. sphy->negotiated_linkrate = sas_phy->linkrate;
  2636. sphy->minimum_linkrate = phy->minimum_linkrate;
  2637. sphy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
  2638. sphy->maximum_linkrate = phy->maximum_linkrate;
  2639. sphy->maximum_linkrate_hw = phy->maximum_linkrate;
  2640. }
  2641. if (phy->phy_type & PORT_TYPE_SAS) {
  2642. struct sas_identify_frame *id;
  2643. id = (struct sas_identify_frame *)phy->frame_rcvd;
  2644. id->dev_type = phy->identify.device_type;
  2645. id->initiator_bits = SAS_PROTOCOL_ALL;
  2646. id->target_bits = phy->identify.target_port_protocols;
  2647. } else if (phy->phy_type & PORT_TYPE_SATA) {
  2648. /*Nothing*/
  2649. }
  2650. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("phy %d byte dmaded.\n", i));
  2651. sas_phy->frame_rcvd_size = phy->frame_rcvd_size;
  2652. pm8001_ha->sas->notify_port_event(sas_phy, PORTE_BYTES_DMAED);
  2653. }
  2654. /* Get the link rate speed */
  2655. static void get_lrate_mode(struct pm8001_phy *phy, u8 link_rate)
  2656. {
  2657. struct sas_phy *sas_phy = phy->sas_phy.phy;
  2658. switch (link_rate) {
  2659. case PHY_SPEED_60:
  2660. phy->sas_phy.linkrate = SAS_LINK_RATE_6_0_GBPS;
  2661. phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
  2662. break;
  2663. case PHY_SPEED_30:
  2664. phy->sas_phy.linkrate = SAS_LINK_RATE_3_0_GBPS;
  2665. phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
  2666. break;
  2667. case PHY_SPEED_15:
  2668. phy->sas_phy.linkrate = SAS_LINK_RATE_1_5_GBPS;
  2669. phy->sas_phy.phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
  2670. break;
  2671. }
  2672. sas_phy->negotiated_linkrate = phy->sas_phy.linkrate;
  2673. sas_phy->maximum_linkrate_hw = SAS_LINK_RATE_6_0_GBPS;
  2674. sas_phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
  2675. sas_phy->maximum_linkrate = SAS_LINK_RATE_6_0_GBPS;
  2676. sas_phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  2677. }
  2678. /**
  2679. * asd_get_attached_sas_addr -- extract/generate attached SAS address
  2680. * @phy: pointer to asd_phy
  2681. * @sas_addr: pointer to buffer where the SAS address is to be written
  2682. *
  2683. * This function extracts the SAS address from an IDENTIFY frame
  2684. * received. If OOB is SATA, then a SAS address is generated from the
  2685. * HA tables.
  2686. *
  2687. * LOCKING: the frame_rcvd_lock needs to be held since this parses the frame
  2688. * buffer.
  2689. */
  2690. static void pm8001_get_attached_sas_addr(struct pm8001_phy *phy,
  2691. u8 *sas_addr)
  2692. {
  2693. if (phy->sas_phy.frame_rcvd[0] == 0x34
  2694. && phy->sas_phy.oob_mode == SATA_OOB_MODE) {
  2695. struct pm8001_hba_info *pm8001_ha = phy->sas_phy.ha->lldd_ha;
  2696. /* FIS device-to-host */
  2697. u64 addr = be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr);
  2698. addr += phy->sas_phy.id;
  2699. *(__be64 *)sas_addr = cpu_to_be64(addr);
  2700. } else {
  2701. struct sas_identify_frame *idframe =
  2702. (void *) phy->sas_phy.frame_rcvd;
  2703. memcpy(sas_addr, idframe->sas_addr, SAS_ADDR_SIZE);
  2704. }
  2705. }
  2706. /**
  2707. * pm8001_hw_event_ack_req- For PM8001,some events need to acknowage to FW.
  2708. * @pm8001_ha: our hba card information
  2709. * @Qnum: the outbound queue message number.
  2710. * @SEA: source of event to ack
  2711. * @port_id: port id.
  2712. * @phyId: phy id.
  2713. * @param0: parameter 0.
  2714. * @param1: parameter 1.
  2715. */
  2716. static void pm8001_hw_event_ack_req(struct pm8001_hba_info *pm8001_ha,
  2717. u32 Qnum, u32 SEA, u32 port_id, u32 phyId, u32 param0, u32 param1)
  2718. {
  2719. struct hw_event_ack_req payload;
  2720. u32 opc = OPC_INB_SAS_HW_EVENT_ACK;
  2721. struct inbound_queue_table *circularQ;
  2722. memset((u8 *)&payload, 0, sizeof(payload));
  2723. circularQ = &pm8001_ha->inbnd_q_tbl[Qnum];
  2724. payload.tag = 1;
  2725. payload.sea_phyid_portid = cpu_to_le32(((SEA & 0xFFFF) << 8) |
  2726. ((phyId & 0x0F) << 4) | (port_id & 0x0F));
  2727. payload.param0 = cpu_to_le32(param0);
  2728. payload.param1 = cpu_to_le32(param1);
  2729. mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  2730. }
  2731. static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
  2732. u32 phyId, u32 phy_op);
  2733. /**
  2734. * hw_event_sas_phy_up -FW tells me a SAS phy up event.
  2735. * @pm8001_ha: our hba card information
  2736. * @piomb: IO message buffer
  2737. */
  2738. static void
  2739. hw_event_sas_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2740. {
  2741. struct hw_event_resp *pPayload =
  2742. (struct hw_event_resp *)(piomb + 4);
  2743. u32 lr_evt_status_phyid_portid =
  2744. le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
  2745. u8 link_rate =
  2746. (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
  2747. u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
  2748. u8 phy_id =
  2749. (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
  2750. u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
  2751. u8 portstate = (u8)(npip_portstate & 0x0000000F);
  2752. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2753. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  2754. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2755. unsigned long flags;
  2756. u8 deviceType = pPayload->sas_identify.dev_type;
  2757. port->port_state = portstate;
  2758. PM8001_MSG_DBG(pm8001_ha,
  2759. pm8001_printk("HW_EVENT_SAS_PHY_UP port id = %d, phy id = %d\n",
  2760. port_id, phy_id));
  2761. switch (deviceType) {
  2762. case SAS_PHY_UNUSED:
  2763. PM8001_MSG_DBG(pm8001_ha,
  2764. pm8001_printk("device type no device.\n"));
  2765. break;
  2766. case SAS_END_DEVICE:
  2767. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("end device.\n"));
  2768. pm8001_chip_phy_ctl_req(pm8001_ha, phy_id,
  2769. PHY_NOTIFY_ENABLE_SPINUP);
  2770. port->port_attached = 1;
  2771. get_lrate_mode(phy, link_rate);
  2772. break;
  2773. case SAS_EDGE_EXPANDER_DEVICE:
  2774. PM8001_MSG_DBG(pm8001_ha,
  2775. pm8001_printk("expander device.\n"));
  2776. port->port_attached = 1;
  2777. get_lrate_mode(phy, link_rate);
  2778. break;
  2779. case SAS_FANOUT_EXPANDER_DEVICE:
  2780. PM8001_MSG_DBG(pm8001_ha,
  2781. pm8001_printk("fanout expander device.\n"));
  2782. port->port_attached = 1;
  2783. get_lrate_mode(phy, link_rate);
  2784. break;
  2785. default:
  2786. PM8001_MSG_DBG(pm8001_ha,
  2787. pm8001_printk("unknown device type(%x)\n", deviceType));
  2788. break;
  2789. }
  2790. phy->phy_type |= PORT_TYPE_SAS;
  2791. phy->identify.device_type = deviceType;
  2792. phy->phy_attached = 1;
  2793. if (phy->identify.device_type == SAS_END_DEV)
  2794. phy->identify.target_port_protocols = SAS_PROTOCOL_SSP;
  2795. else if (phy->identify.device_type != NO_DEVICE)
  2796. phy->identify.target_port_protocols = SAS_PROTOCOL_SMP;
  2797. phy->sas_phy.oob_mode = SAS_OOB_MODE;
  2798. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
  2799. spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
  2800. memcpy(phy->frame_rcvd, &pPayload->sas_identify,
  2801. sizeof(struct sas_identify_frame)-4);
  2802. phy->frame_rcvd_size = sizeof(struct sas_identify_frame) - 4;
  2803. pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
  2804. spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
  2805. if (pm8001_ha->flags == PM8001F_RUN_TIME)
  2806. mdelay(200);/*delay a moment to wait disk to spinup*/
  2807. pm8001_bytes_dmaed(pm8001_ha, phy_id);
  2808. }
  2809. /**
  2810. * hw_event_sata_phy_up -FW tells me a SATA phy up event.
  2811. * @pm8001_ha: our hba card information
  2812. * @piomb: IO message buffer
  2813. */
  2814. static void
  2815. hw_event_sata_phy_up(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2816. {
  2817. struct hw_event_resp *pPayload =
  2818. (struct hw_event_resp *)(piomb + 4);
  2819. u32 lr_evt_status_phyid_portid =
  2820. le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
  2821. u8 link_rate =
  2822. (u8)((lr_evt_status_phyid_portid & 0xF0000000) >> 28);
  2823. u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
  2824. u8 phy_id =
  2825. (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
  2826. u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
  2827. u8 portstate = (u8)(npip_portstate & 0x0000000F);
  2828. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2829. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  2830. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2831. unsigned long flags;
  2832. PM8001_MSG_DBG(pm8001_ha,
  2833. pm8001_printk("HW_EVENT_SATA_PHY_UP port id = %d,"
  2834. " phy id = %d\n", port_id, phy_id));
  2835. port->port_state = portstate;
  2836. port->port_attached = 1;
  2837. get_lrate_mode(phy, link_rate);
  2838. phy->phy_type |= PORT_TYPE_SATA;
  2839. phy->phy_attached = 1;
  2840. phy->sas_phy.oob_mode = SATA_OOB_MODE;
  2841. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_DONE);
  2842. spin_lock_irqsave(&phy->sas_phy.frame_rcvd_lock, flags);
  2843. memcpy(phy->frame_rcvd, ((u8 *)&pPayload->sata_fis - 4),
  2844. sizeof(struct dev_to_host_fis));
  2845. phy->frame_rcvd_size = sizeof(struct dev_to_host_fis);
  2846. phy->identify.target_port_protocols = SAS_PROTOCOL_SATA;
  2847. phy->identify.device_type = SATA_DEV;
  2848. pm8001_get_attached_sas_addr(phy, phy->sas_phy.attached_sas_addr);
  2849. spin_unlock_irqrestore(&phy->sas_phy.frame_rcvd_lock, flags);
  2850. pm8001_bytes_dmaed(pm8001_ha, phy_id);
  2851. }
  2852. /**
  2853. * hw_event_phy_down -we should notify the libsas the phy is down.
  2854. * @pm8001_ha: our hba card information
  2855. * @piomb: IO message buffer
  2856. */
  2857. static void
  2858. hw_event_phy_down(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2859. {
  2860. struct hw_event_resp *pPayload =
  2861. (struct hw_event_resp *)(piomb + 4);
  2862. u32 lr_evt_status_phyid_portid =
  2863. le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
  2864. u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
  2865. u8 phy_id =
  2866. (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
  2867. u32 npip_portstate = le32_to_cpu(pPayload->npip_portstate);
  2868. u8 portstate = (u8)(npip_portstate & 0x0000000F);
  2869. struct pm8001_port *port = &pm8001_ha->port[port_id];
  2870. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  2871. port->port_state = portstate;
  2872. phy->phy_type = 0;
  2873. phy->identify.device_type = 0;
  2874. phy->phy_attached = 0;
  2875. memset(&phy->dev_sas_addr, 0, SAS_ADDR_SIZE);
  2876. switch (portstate) {
  2877. case PORT_VALID:
  2878. break;
  2879. case PORT_INVALID:
  2880. PM8001_MSG_DBG(pm8001_ha,
  2881. pm8001_printk(" PortInvalid portID %d \n", port_id));
  2882. PM8001_MSG_DBG(pm8001_ha,
  2883. pm8001_printk(" Last phy Down and port invalid\n"));
  2884. port->port_attached = 0;
  2885. pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
  2886. port_id, phy_id, 0, 0);
  2887. break;
  2888. case PORT_IN_RESET:
  2889. PM8001_MSG_DBG(pm8001_ha,
  2890. pm8001_printk(" Port In Reset portID %d \n", port_id));
  2891. break;
  2892. case PORT_NOT_ESTABLISHED:
  2893. PM8001_MSG_DBG(pm8001_ha,
  2894. pm8001_printk(" phy Down and PORT_NOT_ESTABLISHED\n"));
  2895. port->port_attached = 0;
  2896. break;
  2897. case PORT_LOSTCOMM:
  2898. PM8001_MSG_DBG(pm8001_ha,
  2899. pm8001_printk(" phy Down and PORT_LOSTCOMM\n"));
  2900. PM8001_MSG_DBG(pm8001_ha,
  2901. pm8001_printk(" Last phy Down and port invalid\n"));
  2902. port->port_attached = 0;
  2903. pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_PHY_DOWN,
  2904. port_id, phy_id, 0, 0);
  2905. break;
  2906. default:
  2907. port->port_attached = 0;
  2908. PM8001_MSG_DBG(pm8001_ha,
  2909. pm8001_printk(" phy Down and(default) = %x\n",
  2910. portstate));
  2911. break;
  2912. }
  2913. }
  2914. /**
  2915. * mpi_reg_resp -process register device ID response.
  2916. * @pm8001_ha: our hba card information
  2917. * @piomb: IO message buffer
  2918. *
  2919. * when sas layer find a device it will notify LLDD, then the driver register
  2920. * the domain device to FW, this event is the return device ID which the FW
  2921. * has assigned, from now,inter-communication with FW is no longer using the
  2922. * SAS address, use device ID which FW assigned.
  2923. */
  2924. static int mpi_reg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2925. {
  2926. u32 status;
  2927. u32 device_id;
  2928. u32 htag;
  2929. struct pm8001_ccb_info *ccb;
  2930. struct pm8001_device *pm8001_dev;
  2931. struct dev_reg_resp *registerRespPayload =
  2932. (struct dev_reg_resp *)(piomb + 4);
  2933. htag = le32_to_cpu(registerRespPayload->tag);
  2934. ccb = &pm8001_ha->ccb_info[registerRespPayload->tag];
  2935. pm8001_dev = ccb->device;
  2936. status = le32_to_cpu(registerRespPayload->status);
  2937. device_id = le32_to_cpu(registerRespPayload->device_id);
  2938. PM8001_MSG_DBG(pm8001_ha,
  2939. pm8001_printk(" register device is status = %d\n", status));
  2940. switch (status) {
  2941. case DEVREG_SUCCESS:
  2942. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("DEVREG_SUCCESS\n"));
  2943. pm8001_dev->device_id = device_id;
  2944. break;
  2945. case DEVREG_FAILURE_OUT_OF_RESOURCE:
  2946. PM8001_MSG_DBG(pm8001_ha,
  2947. pm8001_printk("DEVREG_FAILURE_OUT_OF_RESOURCE\n"));
  2948. break;
  2949. case DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED:
  2950. PM8001_MSG_DBG(pm8001_ha,
  2951. pm8001_printk("DEVREG_FAILURE_DEVICE_ALREADY_REGISTERED\n"));
  2952. break;
  2953. case DEVREG_FAILURE_INVALID_PHY_ID:
  2954. PM8001_MSG_DBG(pm8001_ha,
  2955. pm8001_printk("DEVREG_FAILURE_INVALID_PHY_ID\n"));
  2956. break;
  2957. case DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED:
  2958. PM8001_MSG_DBG(pm8001_ha,
  2959. pm8001_printk("DEVREG_FAILURE_PHY_ID_ALREADY_REGISTERED\n"));
  2960. break;
  2961. case DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE:
  2962. PM8001_MSG_DBG(pm8001_ha,
  2963. pm8001_printk("DEVREG_FAILURE_PORT_ID_OUT_OF_RANGE\n"));
  2964. break;
  2965. case DEVREG_FAILURE_PORT_NOT_VALID_STATE:
  2966. PM8001_MSG_DBG(pm8001_ha,
  2967. pm8001_printk("DEVREG_FAILURE_PORT_NOT_VALID_STATE\n"));
  2968. break;
  2969. case DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID:
  2970. PM8001_MSG_DBG(pm8001_ha,
  2971. pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_VALID\n"));
  2972. break;
  2973. default:
  2974. PM8001_MSG_DBG(pm8001_ha,
  2975. pm8001_printk("DEVREG_FAILURE_DEVICE_TYPE_NOT_UNSORPORTED\n"));
  2976. break;
  2977. }
  2978. complete(pm8001_dev->dcompletion);
  2979. ccb->task = NULL;
  2980. ccb->ccb_tag = 0xFFFFFFFF;
  2981. pm8001_ccb_free(pm8001_ha, htag);
  2982. return 0;
  2983. }
  2984. static int mpi_dereg_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  2985. {
  2986. u32 status;
  2987. u32 device_id;
  2988. struct dev_reg_resp *registerRespPayload =
  2989. (struct dev_reg_resp *)(piomb + 4);
  2990. status = le32_to_cpu(registerRespPayload->status);
  2991. device_id = le32_to_cpu(registerRespPayload->device_id);
  2992. if (status != 0)
  2993. PM8001_MSG_DBG(pm8001_ha,
  2994. pm8001_printk(" deregister device failed ,status = %x"
  2995. ", device_id = %x\n", status, device_id));
  2996. return 0;
  2997. }
  2998. static int
  2999. mpi_fw_flash_update_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3000. {
  3001. u32 status;
  3002. struct fw_control_ex fw_control_context;
  3003. struct fw_flash_Update_resp *ppayload =
  3004. (struct fw_flash_Update_resp *)(piomb + 4);
  3005. u32 tag = le32_to_cpu(ppayload->tag);
  3006. struct pm8001_ccb_info *ccb = &pm8001_ha->ccb_info[tag];
  3007. status = le32_to_cpu(ppayload->status);
  3008. memcpy(&fw_control_context,
  3009. ccb->fw_control_context,
  3010. sizeof(fw_control_context));
  3011. switch (status) {
  3012. case FLASH_UPDATE_COMPLETE_PENDING_REBOOT:
  3013. PM8001_MSG_DBG(pm8001_ha,
  3014. pm8001_printk(": FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n"));
  3015. break;
  3016. case FLASH_UPDATE_IN_PROGRESS:
  3017. PM8001_MSG_DBG(pm8001_ha,
  3018. pm8001_printk(": FLASH_UPDATE_IN_PROGRESS\n"));
  3019. break;
  3020. case FLASH_UPDATE_HDR_ERR:
  3021. PM8001_MSG_DBG(pm8001_ha,
  3022. pm8001_printk(": FLASH_UPDATE_HDR_ERR\n"));
  3023. break;
  3024. case FLASH_UPDATE_OFFSET_ERR:
  3025. PM8001_MSG_DBG(pm8001_ha,
  3026. pm8001_printk(": FLASH_UPDATE_OFFSET_ERR\n"));
  3027. break;
  3028. case FLASH_UPDATE_CRC_ERR:
  3029. PM8001_MSG_DBG(pm8001_ha,
  3030. pm8001_printk(": FLASH_UPDATE_CRC_ERR\n"));
  3031. break;
  3032. case FLASH_UPDATE_LENGTH_ERR:
  3033. PM8001_MSG_DBG(pm8001_ha,
  3034. pm8001_printk(": FLASH_UPDATE_LENGTH_ERR\n"));
  3035. break;
  3036. case FLASH_UPDATE_HW_ERR:
  3037. PM8001_MSG_DBG(pm8001_ha,
  3038. pm8001_printk(": FLASH_UPDATE_HW_ERR\n"));
  3039. break;
  3040. case FLASH_UPDATE_DNLD_NOT_SUPPORTED:
  3041. PM8001_MSG_DBG(pm8001_ha,
  3042. pm8001_printk(": FLASH_UPDATE_DNLD_NOT_SUPPORTED\n"));
  3043. break;
  3044. case FLASH_UPDATE_DISABLED:
  3045. PM8001_MSG_DBG(pm8001_ha,
  3046. pm8001_printk(": FLASH_UPDATE_DISABLED\n"));
  3047. break;
  3048. default:
  3049. PM8001_MSG_DBG(pm8001_ha,
  3050. pm8001_printk("No matched status = %d\n", status));
  3051. break;
  3052. }
  3053. ccb->fw_control_context->fw_control->retcode = status;
  3054. pci_free_consistent(pm8001_ha->pdev,
  3055. fw_control_context.len,
  3056. fw_control_context.virtAddr,
  3057. fw_control_context.phys_addr);
  3058. complete(pm8001_ha->nvmd_completion);
  3059. ccb->task = NULL;
  3060. ccb->ccb_tag = 0xFFFFFFFF;
  3061. pm8001_ccb_free(pm8001_ha, tag);
  3062. return 0;
  3063. }
  3064. static int
  3065. mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
  3066. {
  3067. u32 status;
  3068. int i;
  3069. struct general_event_resp *pPayload =
  3070. (struct general_event_resp *)(piomb + 4);
  3071. status = le32_to_cpu(pPayload->status);
  3072. PM8001_MSG_DBG(pm8001_ha,
  3073. pm8001_printk(" status = 0x%x\n", status));
  3074. for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++)
  3075. PM8001_MSG_DBG(pm8001_ha,
  3076. pm8001_printk("inb_IOMB_payload[0x%x] 0x%x, \n", i,
  3077. pPayload->inb_IOMB_payload[i]));
  3078. return 0;
  3079. }
  3080. static int
  3081. mpi_task_abort_resp(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3082. {
  3083. struct sas_task *t;
  3084. struct pm8001_ccb_info *ccb;
  3085. unsigned long flags;
  3086. u32 status ;
  3087. u32 tag, scp;
  3088. struct task_status_struct *ts;
  3089. struct task_abort_resp *pPayload =
  3090. (struct task_abort_resp *)(piomb + 4);
  3091. ccb = &pm8001_ha->ccb_info[pPayload->tag];
  3092. t = ccb->task;
  3093. status = le32_to_cpu(pPayload->status);
  3094. tag = le32_to_cpu(pPayload->tag);
  3095. scp = le32_to_cpu(pPayload->scp);
  3096. PM8001_IO_DBG(pm8001_ha,
  3097. pm8001_printk(" status = 0x%x\n", status));
  3098. if (t == NULL)
  3099. return -1;
  3100. ts = &t->task_status;
  3101. if (status != 0)
  3102. PM8001_FAIL_DBG(pm8001_ha,
  3103. pm8001_printk("task abort failed status 0x%x ,"
  3104. "tag = 0x%x, scp= 0x%x\n", status, tag, scp));
  3105. switch (status) {
  3106. case IO_SUCCESS:
  3107. PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_SUCCESS\n"));
  3108. ts->resp = SAS_TASK_COMPLETE;
  3109. ts->stat = SAM_STAT_GOOD;
  3110. break;
  3111. case IO_NOT_VALID:
  3112. PM8001_EH_DBG(pm8001_ha, pm8001_printk("IO_NOT_VALID\n"));
  3113. ts->resp = TMF_RESP_FUNC_FAILED;
  3114. break;
  3115. }
  3116. spin_lock_irqsave(&t->task_state_lock, flags);
  3117. t->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  3118. t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  3119. t->task_state_flags |= SAS_TASK_STATE_DONE;
  3120. spin_unlock_irqrestore(&t->task_state_lock, flags);
  3121. pm8001_ccb_task_free(pm8001_ha, t, ccb, pPayload->tag);
  3122. mb();
  3123. t->task_done(t);
  3124. return 0;
  3125. }
  3126. /**
  3127. * mpi_hw_event -The hw event has come.
  3128. * @pm8001_ha: our hba card information
  3129. * @piomb: IO message buffer
  3130. */
  3131. static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
  3132. {
  3133. unsigned long flags;
  3134. struct hw_event_resp *pPayload =
  3135. (struct hw_event_resp *)(piomb + 4);
  3136. u32 lr_evt_status_phyid_portid =
  3137. le32_to_cpu(pPayload->lr_evt_status_phyid_portid);
  3138. u8 port_id = (u8)(lr_evt_status_phyid_portid & 0x0000000F);
  3139. u8 phy_id =
  3140. (u8)((lr_evt_status_phyid_portid & 0x000000F0) >> 4);
  3141. u16 eventType =
  3142. (u16)((lr_evt_status_phyid_portid & 0x00FFFF00) >> 8);
  3143. u8 status =
  3144. (u8)((lr_evt_status_phyid_portid & 0x0F000000) >> 24);
  3145. struct sas_ha_struct *sas_ha = pm8001_ha->sas;
  3146. struct pm8001_phy *phy = &pm8001_ha->phy[phy_id];
  3147. struct asd_sas_phy *sas_phy = sas_ha->sas_phy[phy_id];
  3148. PM8001_MSG_DBG(pm8001_ha,
  3149. pm8001_printk("outbound queue HW event & event type : "));
  3150. switch (eventType) {
  3151. case HW_EVENT_PHY_START_STATUS:
  3152. PM8001_MSG_DBG(pm8001_ha,
  3153. pm8001_printk("HW_EVENT_PHY_START_STATUS"
  3154. " status = %x\n", status));
  3155. if (status == 0) {
  3156. phy->phy_state = 1;
  3157. if (pm8001_ha->flags == PM8001F_RUN_TIME)
  3158. complete(phy->enable_completion);
  3159. }
  3160. break;
  3161. case HW_EVENT_SAS_PHY_UP:
  3162. PM8001_MSG_DBG(pm8001_ha,
  3163. pm8001_printk("HW_EVENT_PHY_START_STATUS \n"));
  3164. hw_event_sas_phy_up(pm8001_ha, piomb);
  3165. break;
  3166. case HW_EVENT_SATA_PHY_UP:
  3167. PM8001_MSG_DBG(pm8001_ha,
  3168. pm8001_printk("HW_EVENT_SATA_PHY_UP \n"));
  3169. hw_event_sata_phy_up(pm8001_ha, piomb);
  3170. break;
  3171. case HW_EVENT_PHY_STOP_STATUS:
  3172. PM8001_MSG_DBG(pm8001_ha,
  3173. pm8001_printk("HW_EVENT_PHY_STOP_STATUS "
  3174. "status = %x\n", status));
  3175. if (status == 0)
  3176. phy->phy_state = 0;
  3177. break;
  3178. case HW_EVENT_SATA_SPINUP_HOLD:
  3179. PM8001_MSG_DBG(pm8001_ha,
  3180. pm8001_printk("HW_EVENT_SATA_SPINUP_HOLD \n"));
  3181. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_SPINUP_HOLD);
  3182. break;
  3183. case HW_EVENT_PHY_DOWN:
  3184. PM8001_MSG_DBG(pm8001_ha,
  3185. pm8001_printk("HW_EVENT_PHY_DOWN \n"));
  3186. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_LOSS_OF_SIGNAL);
  3187. phy->phy_attached = 0;
  3188. phy->phy_state = 0;
  3189. hw_event_phy_down(pm8001_ha, piomb);
  3190. break;
  3191. case HW_EVENT_PORT_INVALID:
  3192. PM8001_MSG_DBG(pm8001_ha,
  3193. pm8001_printk("HW_EVENT_PORT_INVALID\n"));
  3194. sas_phy_disconnected(sas_phy);
  3195. phy->phy_attached = 0;
  3196. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3197. break;
  3198. /* the broadcast change primitive received, tell the LIBSAS this event
  3199. to revalidate the sas domain*/
  3200. case HW_EVENT_BROADCAST_CHANGE:
  3201. PM8001_MSG_DBG(pm8001_ha,
  3202. pm8001_printk("HW_EVENT_BROADCAST_CHANGE\n"));
  3203. pm8001_hw_event_ack_req(pm8001_ha, 0, HW_EVENT_BROADCAST_CHANGE,
  3204. port_id, phy_id, 1, 0);
  3205. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3206. sas_phy->sas_prim = HW_EVENT_BROADCAST_CHANGE;
  3207. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3208. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3209. break;
  3210. case HW_EVENT_PHY_ERROR:
  3211. PM8001_MSG_DBG(pm8001_ha,
  3212. pm8001_printk("HW_EVENT_PHY_ERROR\n"));
  3213. sas_phy_disconnected(&phy->sas_phy);
  3214. phy->phy_attached = 0;
  3215. sas_ha->notify_phy_event(&phy->sas_phy, PHYE_OOB_ERROR);
  3216. break;
  3217. case HW_EVENT_BROADCAST_EXP:
  3218. PM8001_MSG_DBG(pm8001_ha,
  3219. pm8001_printk("HW_EVENT_BROADCAST_EXP\n"));
  3220. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3221. sas_phy->sas_prim = HW_EVENT_BROADCAST_EXP;
  3222. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3223. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3224. break;
  3225. case HW_EVENT_LINK_ERR_INVALID_DWORD:
  3226. PM8001_MSG_DBG(pm8001_ha,
  3227. pm8001_printk("HW_EVENT_LINK_ERR_INVALID_DWORD\n"));
  3228. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3229. HW_EVENT_LINK_ERR_INVALID_DWORD, port_id, phy_id, 0, 0);
  3230. sas_phy_disconnected(sas_phy);
  3231. phy->phy_attached = 0;
  3232. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3233. break;
  3234. case HW_EVENT_LINK_ERR_DISPARITY_ERROR:
  3235. PM8001_MSG_DBG(pm8001_ha,
  3236. pm8001_printk("HW_EVENT_LINK_ERR_DISPARITY_ERROR\n"));
  3237. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3238. HW_EVENT_LINK_ERR_DISPARITY_ERROR,
  3239. port_id, phy_id, 0, 0);
  3240. sas_phy_disconnected(sas_phy);
  3241. phy->phy_attached = 0;
  3242. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3243. break;
  3244. case HW_EVENT_LINK_ERR_CODE_VIOLATION:
  3245. PM8001_MSG_DBG(pm8001_ha,
  3246. pm8001_printk("HW_EVENT_LINK_ERR_CODE_VIOLATION\n"));
  3247. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3248. HW_EVENT_LINK_ERR_CODE_VIOLATION,
  3249. port_id, phy_id, 0, 0);
  3250. sas_phy_disconnected(sas_phy);
  3251. phy->phy_attached = 0;
  3252. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3253. break;
  3254. case HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH:
  3255. PM8001_MSG_DBG(pm8001_ha,
  3256. pm8001_printk("HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH\n"));
  3257. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3258. HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH,
  3259. port_id, phy_id, 0, 0);
  3260. sas_phy_disconnected(sas_phy);
  3261. phy->phy_attached = 0;
  3262. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3263. break;
  3264. case HW_EVENT_MALFUNCTION:
  3265. PM8001_MSG_DBG(pm8001_ha,
  3266. pm8001_printk("HW_EVENT_MALFUNCTION\n"));
  3267. break;
  3268. case HW_EVENT_BROADCAST_SES:
  3269. PM8001_MSG_DBG(pm8001_ha,
  3270. pm8001_printk("HW_EVENT_BROADCAST_SES\n"));
  3271. spin_lock_irqsave(&sas_phy->sas_prim_lock, flags);
  3272. sas_phy->sas_prim = HW_EVENT_BROADCAST_SES;
  3273. spin_unlock_irqrestore(&sas_phy->sas_prim_lock, flags);
  3274. sas_ha->notify_port_event(sas_phy, PORTE_BROADCAST_RCVD);
  3275. break;
  3276. case HW_EVENT_INBOUND_CRC_ERROR:
  3277. PM8001_MSG_DBG(pm8001_ha,
  3278. pm8001_printk("HW_EVENT_INBOUND_CRC_ERROR\n"));
  3279. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3280. HW_EVENT_INBOUND_CRC_ERROR,
  3281. port_id, phy_id, 0, 0);
  3282. break;
  3283. case HW_EVENT_HARD_RESET_RECEIVED:
  3284. PM8001_MSG_DBG(pm8001_ha,
  3285. pm8001_printk("HW_EVENT_HARD_RESET_RECEIVED\n"));
  3286. sas_ha->notify_port_event(sas_phy, PORTE_HARD_RESET);
  3287. break;
  3288. case HW_EVENT_ID_FRAME_TIMEOUT:
  3289. PM8001_MSG_DBG(pm8001_ha,
  3290. pm8001_printk("HW_EVENT_ID_FRAME_TIMEOUT\n"));
  3291. sas_phy_disconnected(sas_phy);
  3292. phy->phy_attached = 0;
  3293. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3294. break;
  3295. case HW_EVENT_LINK_ERR_PHY_RESET_FAILED:
  3296. PM8001_MSG_DBG(pm8001_ha,
  3297. pm8001_printk("HW_EVENT_LINK_ERR_PHY_RESET_FAILED \n"));
  3298. pm8001_hw_event_ack_req(pm8001_ha, 0,
  3299. HW_EVENT_LINK_ERR_PHY_RESET_FAILED,
  3300. port_id, phy_id, 0, 0);
  3301. sas_phy_disconnected(sas_phy);
  3302. phy->phy_attached = 0;
  3303. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3304. break;
  3305. case HW_EVENT_PORT_RESET_TIMER_TMO:
  3306. PM8001_MSG_DBG(pm8001_ha,
  3307. pm8001_printk("HW_EVENT_PORT_RESET_TIMER_TMO \n"));
  3308. sas_phy_disconnected(sas_phy);
  3309. phy->phy_attached = 0;
  3310. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3311. break;
  3312. case HW_EVENT_PORT_RECOVERY_TIMER_TMO:
  3313. PM8001_MSG_DBG(pm8001_ha,
  3314. pm8001_printk("HW_EVENT_PORT_RECOVERY_TIMER_TMO \n"));
  3315. sas_phy_disconnected(sas_phy);
  3316. phy->phy_attached = 0;
  3317. sas_ha->notify_port_event(sas_phy, PORTE_LINK_RESET_ERR);
  3318. break;
  3319. case HW_EVENT_PORT_RECOVER:
  3320. PM8001_MSG_DBG(pm8001_ha,
  3321. pm8001_printk("HW_EVENT_PORT_RECOVER \n"));
  3322. break;
  3323. case HW_EVENT_PORT_RESET_COMPLETE:
  3324. PM8001_MSG_DBG(pm8001_ha,
  3325. pm8001_printk("HW_EVENT_PORT_RESET_COMPLETE \n"));
  3326. break;
  3327. case EVENT_BROADCAST_ASYNCH_EVENT:
  3328. PM8001_MSG_DBG(pm8001_ha,
  3329. pm8001_printk("EVENT_BROADCAST_ASYNCH_EVENT\n"));
  3330. break;
  3331. default:
  3332. PM8001_MSG_DBG(pm8001_ha,
  3333. pm8001_printk("Unknown event type = %x\n", eventType));
  3334. break;
  3335. }
  3336. return 0;
  3337. }
  3338. /**
  3339. * process_one_iomb - process one outbound Queue memory block
  3340. * @pm8001_ha: our hba card information
  3341. * @piomb: IO message buffer
  3342. */
  3343. static void process_one_iomb(struct pm8001_hba_info *pm8001_ha, void *piomb)
  3344. {
  3345. u32 pHeader = (u32)*(u32 *)piomb;
  3346. u8 opc = (u8)((le32_to_cpu(pHeader)) & 0xFFF);
  3347. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("process_one_iomb:"));
  3348. switch (opc) {
  3349. case OPC_OUB_ECHO:
  3350. PM8001_MSG_DBG(pm8001_ha, pm8001_printk("OPC_OUB_ECHO \n"));
  3351. break;
  3352. case OPC_OUB_HW_EVENT:
  3353. PM8001_MSG_DBG(pm8001_ha,
  3354. pm8001_printk("OPC_OUB_HW_EVENT \n"));
  3355. mpi_hw_event(pm8001_ha, piomb);
  3356. break;
  3357. case OPC_OUB_SSP_COMP:
  3358. PM8001_MSG_DBG(pm8001_ha,
  3359. pm8001_printk("OPC_OUB_SSP_COMP \n"));
  3360. mpi_ssp_completion(pm8001_ha, piomb);
  3361. break;
  3362. case OPC_OUB_SMP_COMP:
  3363. PM8001_MSG_DBG(pm8001_ha,
  3364. pm8001_printk("OPC_OUB_SMP_COMP \n"));
  3365. mpi_smp_completion(pm8001_ha, piomb);
  3366. break;
  3367. case OPC_OUB_LOCAL_PHY_CNTRL:
  3368. PM8001_MSG_DBG(pm8001_ha,
  3369. pm8001_printk("OPC_OUB_LOCAL_PHY_CNTRL\n"));
  3370. mpi_local_phy_ctl(pm8001_ha, piomb);
  3371. break;
  3372. case OPC_OUB_DEV_REGIST:
  3373. PM8001_MSG_DBG(pm8001_ha,
  3374. pm8001_printk("OPC_OUB_DEV_REGIST \n"));
  3375. mpi_reg_resp(pm8001_ha, piomb);
  3376. break;
  3377. case OPC_OUB_DEREG_DEV:
  3378. PM8001_MSG_DBG(pm8001_ha,
  3379. pm8001_printk("unresgister the deviece \n"));
  3380. mpi_dereg_resp(pm8001_ha, piomb);
  3381. break;
  3382. case OPC_OUB_GET_DEV_HANDLE:
  3383. PM8001_MSG_DBG(pm8001_ha,
  3384. pm8001_printk("OPC_OUB_GET_DEV_HANDLE \n"));
  3385. break;
  3386. case OPC_OUB_SATA_COMP:
  3387. PM8001_MSG_DBG(pm8001_ha,
  3388. pm8001_printk("OPC_OUB_SATA_COMP \n"));
  3389. mpi_sata_completion(pm8001_ha, piomb);
  3390. break;
  3391. case OPC_OUB_SATA_EVENT:
  3392. PM8001_MSG_DBG(pm8001_ha,
  3393. pm8001_printk("OPC_OUB_SATA_EVENT \n"));
  3394. mpi_sata_event(pm8001_ha, piomb);
  3395. break;
  3396. case OPC_OUB_SSP_EVENT:
  3397. PM8001_MSG_DBG(pm8001_ha,
  3398. pm8001_printk("OPC_OUB_SSP_EVENT\n"));
  3399. mpi_ssp_event(pm8001_ha, piomb);
  3400. break;
  3401. case OPC_OUB_DEV_HANDLE_ARRIV:
  3402. PM8001_MSG_DBG(pm8001_ha,
  3403. pm8001_printk("OPC_OUB_DEV_HANDLE_ARRIV\n"));
  3404. /*This is for target*/
  3405. break;
  3406. case OPC_OUB_SSP_RECV_EVENT:
  3407. PM8001_MSG_DBG(pm8001_ha,
  3408. pm8001_printk("OPC_OUB_SSP_RECV_EVENT\n"));
  3409. /*This is for target*/
  3410. break;
  3411. case OPC_OUB_DEV_INFO:
  3412. PM8001_MSG_DBG(pm8001_ha,
  3413. pm8001_printk("OPC_OUB_DEV_INFO\n"));
  3414. break;
  3415. case OPC_OUB_FW_FLASH_UPDATE:
  3416. PM8001_MSG_DBG(pm8001_ha,
  3417. pm8001_printk("OPC_OUB_FW_FLASH_UPDATE\n"));
  3418. mpi_fw_flash_update_resp(pm8001_ha, piomb);
  3419. break;
  3420. case OPC_OUB_GPIO_RESPONSE:
  3421. PM8001_MSG_DBG(pm8001_ha,
  3422. pm8001_printk("OPC_OUB_GPIO_RESPONSE\n"));
  3423. break;
  3424. case OPC_OUB_GPIO_EVENT:
  3425. PM8001_MSG_DBG(pm8001_ha,
  3426. pm8001_printk("OPC_OUB_GPIO_EVENT\n"));
  3427. break;
  3428. case OPC_OUB_GENERAL_EVENT:
  3429. PM8001_MSG_DBG(pm8001_ha,
  3430. pm8001_printk("OPC_OUB_GENERAL_EVENT\n"));
  3431. mpi_general_event(pm8001_ha, piomb);
  3432. break;
  3433. case OPC_OUB_SSP_ABORT_RSP:
  3434. PM8001_MSG_DBG(pm8001_ha,
  3435. pm8001_printk("OPC_OUB_SSP_ABORT_RSP\n"));
  3436. mpi_task_abort_resp(pm8001_ha, piomb);
  3437. break;
  3438. case OPC_OUB_SATA_ABORT_RSP:
  3439. PM8001_MSG_DBG(pm8001_ha,
  3440. pm8001_printk("OPC_OUB_SATA_ABORT_RSP\n"));
  3441. mpi_task_abort_resp(pm8001_ha, piomb);
  3442. break;
  3443. case OPC_OUB_SAS_DIAG_MODE_START_END:
  3444. PM8001_MSG_DBG(pm8001_ha,
  3445. pm8001_printk("OPC_OUB_SAS_DIAG_MODE_START_END\n"));
  3446. break;
  3447. case OPC_OUB_SAS_DIAG_EXECUTE:
  3448. PM8001_MSG_DBG(pm8001_ha,
  3449. pm8001_printk("OPC_OUB_SAS_DIAG_EXECUTE\n"));
  3450. break;
  3451. case OPC_OUB_GET_TIME_STAMP:
  3452. PM8001_MSG_DBG(pm8001_ha,
  3453. pm8001_printk("OPC_OUB_GET_TIME_STAMP\n"));
  3454. break;
  3455. case OPC_OUB_SAS_HW_EVENT_ACK:
  3456. PM8001_MSG_DBG(pm8001_ha,
  3457. pm8001_printk("OPC_OUB_SAS_HW_EVENT_ACK\n"));
  3458. break;
  3459. case OPC_OUB_PORT_CONTROL:
  3460. PM8001_MSG_DBG(pm8001_ha,
  3461. pm8001_printk("OPC_OUB_PORT_CONTROL\n"));
  3462. break;
  3463. case OPC_OUB_SMP_ABORT_RSP:
  3464. PM8001_MSG_DBG(pm8001_ha,
  3465. pm8001_printk("OPC_OUB_SMP_ABORT_RSP\n"));
  3466. mpi_task_abort_resp(pm8001_ha, piomb);
  3467. break;
  3468. case OPC_OUB_GET_NVMD_DATA:
  3469. PM8001_MSG_DBG(pm8001_ha,
  3470. pm8001_printk("OPC_OUB_GET_NVMD_DATA\n"));
  3471. mpi_get_nvmd_resp(pm8001_ha, piomb);
  3472. break;
  3473. case OPC_OUB_SET_NVMD_DATA:
  3474. PM8001_MSG_DBG(pm8001_ha,
  3475. pm8001_printk("OPC_OUB_SET_NVMD_DATA\n"));
  3476. mpi_set_nvmd_resp(pm8001_ha, piomb);
  3477. break;
  3478. case OPC_OUB_DEVICE_HANDLE_REMOVAL:
  3479. PM8001_MSG_DBG(pm8001_ha,
  3480. pm8001_printk("OPC_OUB_DEVICE_HANDLE_REMOVAL\n"));
  3481. break;
  3482. case OPC_OUB_SET_DEVICE_STATE:
  3483. PM8001_MSG_DBG(pm8001_ha,
  3484. pm8001_printk("OPC_OUB_SET_DEVICE_STATE\n"));
  3485. mpi_set_dev_state_resp(pm8001_ha, piomb);
  3486. break;
  3487. case OPC_OUB_GET_DEVICE_STATE:
  3488. PM8001_MSG_DBG(pm8001_ha,
  3489. pm8001_printk("OPC_OUB_GET_DEVICE_STATE\n"));
  3490. break;
  3491. case OPC_OUB_SET_DEV_INFO:
  3492. PM8001_MSG_DBG(pm8001_ha,
  3493. pm8001_printk("OPC_OUB_SET_DEV_INFO\n"));
  3494. break;
  3495. case OPC_OUB_SAS_RE_INITIALIZE:
  3496. PM8001_MSG_DBG(pm8001_ha,
  3497. pm8001_printk("OPC_OUB_SAS_RE_INITIALIZE\n"));
  3498. break;
  3499. default:
  3500. PM8001_MSG_DBG(pm8001_ha,
  3501. pm8001_printk("Unknown outbound Queue IOMB OPC = %x\n",
  3502. opc));
  3503. break;
  3504. }
  3505. }
  3506. static int process_oq(struct pm8001_hba_info *pm8001_ha)
  3507. {
  3508. struct outbound_queue_table *circularQ;
  3509. void *pMsg1 = NULL;
  3510. u8 bc = 0;
  3511. u32 ret = MPI_IO_STATUS_FAIL;
  3512. circularQ = &pm8001_ha->outbnd_q_tbl[0];
  3513. do {
  3514. ret = mpi_msg_consume(pm8001_ha, circularQ, &pMsg1, &bc);
  3515. if (MPI_IO_STATUS_SUCCESS == ret) {
  3516. /* process the outbound message */
  3517. process_one_iomb(pm8001_ha, (void *)(pMsg1 - 4));
  3518. /* free the message from the outbound circular buffer */
  3519. mpi_msg_free_set(pm8001_ha, pMsg1, circularQ, bc);
  3520. }
  3521. if (MPI_IO_STATUS_BUSY == ret) {
  3522. u32 producer_idx;
  3523. /* Update the producer index from SPC */
  3524. producer_idx = pm8001_read_32(circularQ->pi_virt);
  3525. circularQ->producer_index = cpu_to_le32(producer_idx);
  3526. if (circularQ->producer_index ==
  3527. circularQ->consumer_idx)
  3528. /* OQ is empty */
  3529. break;
  3530. }
  3531. } while (1);
  3532. return ret;
  3533. }
  3534. /* PCI_DMA_... to our direction translation. */
  3535. static const u8 data_dir_flags[] = {
  3536. [PCI_DMA_BIDIRECTIONAL] = DATA_DIR_BYRECIPIENT,/* UNSPECIFIED */
  3537. [PCI_DMA_TODEVICE] = DATA_DIR_OUT,/* OUTBOUND */
  3538. [PCI_DMA_FROMDEVICE] = DATA_DIR_IN,/* INBOUND */
  3539. [PCI_DMA_NONE] = DATA_DIR_NONE,/* NO TRANSFER */
  3540. };
  3541. static void
  3542. pm8001_chip_make_sg(struct scatterlist *scatter, int nr, void *prd)
  3543. {
  3544. int i;
  3545. struct scatterlist *sg;
  3546. struct pm8001_prd *buf_prd = prd;
  3547. for_each_sg(scatter, sg, nr, i) {
  3548. buf_prd->addr = cpu_to_le64(sg_dma_address(sg));
  3549. buf_prd->im_len.len = cpu_to_le32(sg_dma_len(sg));
  3550. buf_prd->im_len.e = 0;
  3551. buf_prd++;
  3552. }
  3553. }
  3554. static void build_smp_cmd(u32 deviceID, u32 hTag, struct smp_req *psmp_cmd)
  3555. {
  3556. psmp_cmd->tag = cpu_to_le32(hTag);
  3557. psmp_cmd->device_id = cpu_to_le32(deviceID);
  3558. psmp_cmd->len_ip_ir = cpu_to_le32(1|(1 << 1));
  3559. }
  3560. /**
  3561. * pm8001_chip_smp_req - send a SMP task to FW
  3562. * @pm8001_ha: our hba card information.
  3563. * @ccb: the ccb information this request used.
  3564. */
  3565. static int pm8001_chip_smp_req(struct pm8001_hba_info *pm8001_ha,
  3566. struct pm8001_ccb_info *ccb)
  3567. {
  3568. int elem, rc;
  3569. struct sas_task *task = ccb->task;
  3570. struct domain_device *dev = task->dev;
  3571. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  3572. struct scatterlist *sg_req, *sg_resp;
  3573. u32 req_len, resp_len;
  3574. struct smp_req smp_cmd;
  3575. u32 opc;
  3576. struct inbound_queue_table *circularQ;
  3577. memset(&smp_cmd, 0, sizeof(smp_cmd));
  3578. /*
  3579. * DMA-map SMP request, response buffers
  3580. */
  3581. sg_req = &task->smp_task.smp_req;
  3582. elem = dma_map_sg(pm8001_ha->dev, sg_req, 1, PCI_DMA_TODEVICE);
  3583. if (!elem)
  3584. return -ENOMEM;
  3585. req_len = sg_dma_len(sg_req);
  3586. sg_resp = &task->smp_task.smp_resp;
  3587. elem = dma_map_sg(pm8001_ha->dev, sg_resp, 1, PCI_DMA_FROMDEVICE);
  3588. if (!elem) {
  3589. rc = -ENOMEM;
  3590. goto err_out;
  3591. }
  3592. resp_len = sg_dma_len(sg_resp);
  3593. /* must be in dwords */
  3594. if ((req_len & 0x3) || (resp_len & 0x3)) {
  3595. rc = -EINVAL;
  3596. goto err_out_2;
  3597. }
  3598. opc = OPC_INB_SMP_REQUEST;
  3599. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3600. smp_cmd.tag = cpu_to_le32(ccb->ccb_tag);
  3601. smp_cmd.long_smp_req.long_req_addr =
  3602. cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_req));
  3603. smp_cmd.long_smp_req.long_req_size =
  3604. cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_req)-4);
  3605. smp_cmd.long_smp_req.long_resp_addr =
  3606. cpu_to_le64((u64)sg_dma_address(&task->smp_task.smp_resp));
  3607. smp_cmd.long_smp_req.long_resp_size =
  3608. cpu_to_le32((u32)sg_dma_len(&task->smp_task.smp_resp)-4);
  3609. build_smp_cmd(pm8001_dev->device_id, smp_cmd.tag, &smp_cmd);
  3610. mpi_build_cmd(pm8001_ha, circularQ, opc, (u32 *)&smp_cmd);
  3611. return 0;
  3612. err_out_2:
  3613. dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_resp, 1,
  3614. PCI_DMA_FROMDEVICE);
  3615. err_out:
  3616. dma_unmap_sg(pm8001_ha->dev, &ccb->task->smp_task.smp_req, 1,
  3617. PCI_DMA_TODEVICE);
  3618. return rc;
  3619. }
  3620. /**
  3621. * pm8001_chip_ssp_io_req - send a SSP task to FW
  3622. * @pm8001_ha: our hba card information.
  3623. * @ccb: the ccb information this request used.
  3624. */
  3625. static int pm8001_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
  3626. struct pm8001_ccb_info *ccb)
  3627. {
  3628. struct sas_task *task = ccb->task;
  3629. struct domain_device *dev = task->dev;
  3630. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  3631. struct ssp_ini_io_start_req ssp_cmd;
  3632. u32 tag = ccb->ccb_tag;
  3633. int ret;
  3634. __le64 phys_addr;
  3635. struct inbound_queue_table *circularQ;
  3636. u32 opc = OPC_INB_SSPINIIOSTART;
  3637. memset(&ssp_cmd, 0, sizeof(ssp_cmd));
  3638. memcpy(ssp_cmd.ssp_iu.lun, task->ssp_task.LUN, 8);
  3639. ssp_cmd.dir_m_tlr =
  3640. cpu_to_le32(data_dir_flags[task->data_dir] << 8 | 0x0);/*0 for
  3641. SAS 1.1 compatible TLR*/
  3642. ssp_cmd.data_len = cpu_to_le32(task->total_xfer_len);
  3643. ssp_cmd.device_id = cpu_to_le32(pm8001_dev->device_id);
  3644. ssp_cmd.tag = cpu_to_le32(tag);
  3645. if (task->ssp_task.enable_first_burst)
  3646. ssp_cmd.ssp_iu.efb_prio_attr |= 0x80;
  3647. ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_prio << 3);
  3648. ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
  3649. memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cdb, 16);
  3650. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3651. /* fill in PRD (scatter/gather) table, if any */
  3652. if (task->num_scatter > 1) {
  3653. pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
  3654. phys_addr = cpu_to_le64(ccb->ccb_dma_handle +
  3655. offsetof(struct pm8001_ccb_info, buf_prd[0]));
  3656. ssp_cmd.addr_low = lower_32_bits(phys_addr);
  3657. ssp_cmd.addr_high = upper_32_bits(phys_addr);
  3658. ssp_cmd.esgl = cpu_to_le32(1<<31);
  3659. } else if (task->num_scatter == 1) {
  3660. __le64 dma_addr = cpu_to_le64(sg_dma_address(task->scatter));
  3661. ssp_cmd.addr_low = lower_32_bits(dma_addr);
  3662. ssp_cmd.addr_high = upper_32_bits(dma_addr);
  3663. ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
  3664. ssp_cmd.esgl = 0;
  3665. } else if (task->num_scatter == 0) {
  3666. ssp_cmd.addr_low = 0;
  3667. ssp_cmd.addr_high = 0;
  3668. ssp_cmd.len = cpu_to_le32(task->total_xfer_len);
  3669. ssp_cmd.esgl = 0;
  3670. }
  3671. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &ssp_cmd);
  3672. return ret;
  3673. }
  3674. static int pm8001_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
  3675. struct pm8001_ccb_info *ccb)
  3676. {
  3677. struct sas_task *task = ccb->task;
  3678. struct domain_device *dev = task->dev;
  3679. struct pm8001_device *pm8001_ha_dev = dev->lldd_dev;
  3680. u32 tag = ccb->ccb_tag;
  3681. int ret;
  3682. struct sata_start_req sata_cmd;
  3683. u32 hdr_tag, ncg_tag = 0;
  3684. __le64 phys_addr;
  3685. u32 ATAP = 0x0;
  3686. u32 dir;
  3687. struct inbound_queue_table *circularQ;
  3688. u32 opc = OPC_INB_SATA_HOST_OPSTART;
  3689. memset(&sata_cmd, 0, sizeof(sata_cmd));
  3690. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3691. if (task->data_dir == PCI_DMA_NONE) {
  3692. ATAP = 0x04; /* no data*/
  3693. PM8001_IO_DBG(pm8001_ha, pm8001_printk("no data \n"));
  3694. } else if (likely(!task->ata_task.device_control_reg_update)) {
  3695. if (task->ata_task.dma_xfer) {
  3696. ATAP = 0x06; /* DMA */
  3697. PM8001_IO_DBG(pm8001_ha, pm8001_printk("DMA \n"));
  3698. } else {
  3699. ATAP = 0x05; /* PIO*/
  3700. PM8001_IO_DBG(pm8001_ha, pm8001_printk("PIO \n"));
  3701. }
  3702. if (task->ata_task.use_ncq &&
  3703. dev->sata_dev.command_set != ATAPI_COMMAND_SET) {
  3704. ATAP = 0x07; /* FPDMA */
  3705. PM8001_IO_DBG(pm8001_ha, pm8001_printk("FPDMA \n"));
  3706. }
  3707. }
  3708. if (task->ata_task.use_ncq && pm8001_get_ncq_tag(task, &hdr_tag))
  3709. ncg_tag = hdr_tag;
  3710. dir = data_dir_flags[task->data_dir] << 8;
  3711. sata_cmd.tag = cpu_to_le32(tag);
  3712. sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev->device_id);
  3713. sata_cmd.data_len = cpu_to_le32(task->total_xfer_len);
  3714. sata_cmd.ncqtag_atap_dir_m =
  3715. cpu_to_le32(((ncg_tag & 0xff)<<16)|((ATAP & 0x3f) << 10) | dir);
  3716. sata_cmd.sata_fis = task->ata_task.fis;
  3717. if (likely(!task->ata_task.device_control_reg_update))
  3718. sata_cmd.sata_fis.flags |= 0x80;/* C=1: update ATA cmd reg */
  3719. sata_cmd.sata_fis.flags &= 0xF0;/* PM_PORT field shall be 0 */
  3720. /* fill in PRD (scatter/gather) table, if any */
  3721. if (task->num_scatter > 1) {
  3722. pm8001_chip_make_sg(task->scatter, ccb->n_elem, ccb->buf_prd);
  3723. phys_addr = cpu_to_le64(ccb->ccb_dma_handle +
  3724. offsetof(struct pm8001_ccb_info, buf_prd[0]));
  3725. sata_cmd.addr_low = lower_32_bits(phys_addr);
  3726. sata_cmd.addr_high = upper_32_bits(phys_addr);
  3727. sata_cmd.esgl = cpu_to_le32(1 << 31);
  3728. } else if (task->num_scatter == 1) {
  3729. __le64 dma_addr = cpu_to_le64(sg_dma_address(task->scatter));
  3730. sata_cmd.addr_low = lower_32_bits(dma_addr);
  3731. sata_cmd.addr_high = upper_32_bits(dma_addr);
  3732. sata_cmd.len = cpu_to_le32(task->total_xfer_len);
  3733. sata_cmd.esgl = 0;
  3734. } else if (task->num_scatter == 0) {
  3735. sata_cmd.addr_low = 0;
  3736. sata_cmd.addr_high = 0;
  3737. sata_cmd.len = cpu_to_le32(task->total_xfer_len);
  3738. sata_cmd.esgl = 0;
  3739. }
  3740. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &sata_cmd);
  3741. return ret;
  3742. }
  3743. /**
  3744. * pm8001_chip_phy_start_req - start phy via PHY_START COMMAND
  3745. * @pm8001_ha: our hba card information.
  3746. * @num: the inbound queue number
  3747. * @phy_id: the phy id which we wanted to start up.
  3748. */
  3749. static int
  3750. pm8001_chip_phy_start_req(struct pm8001_hba_info *pm8001_ha, u8 phy_id)
  3751. {
  3752. struct phy_start_req payload;
  3753. struct inbound_queue_table *circularQ;
  3754. int ret;
  3755. u32 tag = 0x01;
  3756. u32 opcode = OPC_INB_PHYSTART;
  3757. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3758. memset(&payload, 0, sizeof(payload));
  3759. payload.tag = cpu_to_le32(tag);
  3760. /*
  3761. ** [0:7] PHY Identifier
  3762. ** [8:11] link rate 1.5G, 3G, 6G
  3763. ** [12:13] link mode 01b SAS mode; 10b SATA mode; 11b both
  3764. ** [14] 0b disable spin up hold; 1b enable spin up hold
  3765. */
  3766. payload.ase_sh_lm_slr_phyid = cpu_to_le32(SPINHOLD_DISABLE |
  3767. LINKMODE_AUTO | LINKRATE_15 |
  3768. LINKRATE_30 | LINKRATE_60 | phy_id);
  3769. payload.sas_identify.dev_type = SAS_END_DEV;
  3770. payload.sas_identify.initiator_bits = SAS_PROTOCOL_ALL;
  3771. memcpy(payload.sas_identify.sas_addr,
  3772. pm8001_ha->sas_addr, SAS_ADDR_SIZE);
  3773. payload.sas_identify.phy_id = phy_id;
  3774. ret = mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload);
  3775. return ret;
  3776. }
  3777. /**
  3778. * pm8001_chip_phy_stop_req - start phy via PHY_STOP COMMAND
  3779. * @pm8001_ha: our hba card information.
  3780. * @num: the inbound queue number
  3781. * @phy_id: the phy id which we wanted to start up.
  3782. */
  3783. static int pm8001_chip_phy_stop_req(struct pm8001_hba_info *pm8001_ha,
  3784. u8 phy_id)
  3785. {
  3786. struct phy_stop_req payload;
  3787. struct inbound_queue_table *circularQ;
  3788. int ret;
  3789. u32 tag = 0x01;
  3790. u32 opcode = OPC_INB_PHYSTOP;
  3791. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3792. memset(&payload, 0, sizeof(payload));
  3793. payload.tag = cpu_to_le32(tag);
  3794. payload.phy_id = cpu_to_le32(phy_id);
  3795. ret = mpi_build_cmd(pm8001_ha, circularQ, opcode, &payload);
  3796. return ret;
  3797. }
  3798. /**
  3799. * see comments on mpi_reg_resp.
  3800. */
  3801. static int pm8001_chip_reg_dev_req(struct pm8001_hba_info *pm8001_ha,
  3802. struct pm8001_device *pm8001_dev, u32 flag)
  3803. {
  3804. struct reg_dev_req payload;
  3805. u32 opc;
  3806. u32 stp_sspsmp_sata = 0x4;
  3807. struct inbound_queue_table *circularQ;
  3808. u32 linkrate, phy_id;
  3809. int rc, tag = 0xdeadbeef;
  3810. struct pm8001_ccb_info *ccb;
  3811. u8 retryFlag = 0x1;
  3812. u16 firstBurstSize = 0;
  3813. u16 ITNT = 2000;
  3814. struct domain_device *dev = pm8001_dev->sas_device;
  3815. struct domain_device *parent_dev = dev->parent;
  3816. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3817. memset(&payload, 0, sizeof(payload));
  3818. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  3819. if (rc)
  3820. return rc;
  3821. ccb = &pm8001_ha->ccb_info[tag];
  3822. ccb->device = pm8001_dev;
  3823. ccb->ccb_tag = tag;
  3824. payload.tag = cpu_to_le32(tag);
  3825. if (flag == 1)
  3826. stp_sspsmp_sata = 0x02; /*direct attached sata */
  3827. else {
  3828. if (pm8001_dev->dev_type == SATA_DEV)
  3829. stp_sspsmp_sata = 0x00; /* stp*/
  3830. else if (pm8001_dev->dev_type == SAS_END_DEV ||
  3831. pm8001_dev->dev_type == EDGE_DEV ||
  3832. pm8001_dev->dev_type == FANOUT_DEV)
  3833. stp_sspsmp_sata = 0x01; /*ssp or smp*/
  3834. }
  3835. if (parent_dev && DEV_IS_EXPANDER(parent_dev->dev_type))
  3836. phy_id = parent_dev->ex_dev.ex_phy->phy_id;
  3837. else
  3838. phy_id = pm8001_dev->attached_phy;
  3839. opc = OPC_INB_REG_DEV;
  3840. linkrate = (pm8001_dev->sas_device->linkrate < dev->port->linkrate) ?
  3841. pm8001_dev->sas_device->linkrate : dev->port->linkrate;
  3842. payload.phyid_portid =
  3843. cpu_to_le32(((pm8001_dev->sas_device->port->id) & 0x0F) |
  3844. ((phy_id & 0x0F) << 4));
  3845. payload.dtype_dlr_retry = cpu_to_le32((retryFlag & 0x01) |
  3846. ((linkrate & 0x0F) * 0x1000000) |
  3847. ((stp_sspsmp_sata & 0x03) * 0x10000000));
  3848. payload.firstburstsize_ITNexustimeout =
  3849. cpu_to_le32(ITNT | (firstBurstSize * 0x10000));
  3850. memcpy(payload.sas_addr, pm8001_dev->sas_device->sas_addr,
  3851. SAS_ADDR_SIZE);
  3852. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  3853. return rc;
  3854. }
  3855. /**
  3856. * see comments on mpi_reg_resp.
  3857. */
  3858. static int pm8001_chip_dereg_dev_req(struct pm8001_hba_info *pm8001_ha,
  3859. u32 device_id)
  3860. {
  3861. struct dereg_dev_req payload;
  3862. u32 opc = OPC_INB_DEREG_DEV_HANDLE;
  3863. int ret;
  3864. struct inbound_queue_table *circularQ;
  3865. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3866. memset(&payload, 0, sizeof(payload));
  3867. payload.tag = 1;
  3868. payload.device_id = cpu_to_le32(device_id);
  3869. PM8001_MSG_DBG(pm8001_ha,
  3870. pm8001_printk("unregister device device_id = %d\n", device_id));
  3871. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  3872. return ret;
  3873. }
  3874. /**
  3875. * pm8001_chip_phy_ctl_req - support the local phy operation
  3876. * @pm8001_ha: our hba card information.
  3877. * @num: the inbound queue number
  3878. * @phy_id: the phy id which we wanted to operate
  3879. * @phy_op:
  3880. */
  3881. static int pm8001_chip_phy_ctl_req(struct pm8001_hba_info *pm8001_ha,
  3882. u32 phyId, u32 phy_op)
  3883. {
  3884. struct local_phy_ctl_req payload;
  3885. struct inbound_queue_table *circularQ;
  3886. int ret;
  3887. u32 opc = OPC_INB_LOCAL_PHY_CONTROL;
  3888. memset(&payload, 0, sizeof(payload));
  3889. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3890. payload.tag = 1;
  3891. payload.phyop_phyid =
  3892. cpu_to_le32(((phy_op & 0xff) << 8) | (phyId & 0x0F));
  3893. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  3894. return ret;
  3895. }
  3896. static u32 pm8001_chip_is_our_interupt(struct pm8001_hba_info *pm8001_ha)
  3897. {
  3898. u32 value;
  3899. #ifdef PM8001_USE_MSIX
  3900. return 1;
  3901. #endif
  3902. value = pm8001_cr32(pm8001_ha, 0, MSGU_ODR);
  3903. if (value)
  3904. return 1;
  3905. return 0;
  3906. }
  3907. /**
  3908. * pm8001_chip_isr - PM8001 isr handler.
  3909. * @pm8001_ha: our hba card information.
  3910. * @irq: irq number.
  3911. * @stat: stat.
  3912. */
  3913. static irqreturn_t
  3914. pm8001_chip_isr(struct pm8001_hba_info *pm8001_ha)
  3915. {
  3916. unsigned long flags;
  3917. spin_lock_irqsave(&pm8001_ha->lock, flags);
  3918. pm8001_chip_interrupt_disable(pm8001_ha);
  3919. process_oq(pm8001_ha);
  3920. pm8001_chip_interrupt_enable(pm8001_ha);
  3921. spin_unlock_irqrestore(&pm8001_ha->lock, flags);
  3922. return IRQ_HANDLED;
  3923. }
  3924. static int send_task_abort(struct pm8001_hba_info *pm8001_ha, u32 opc,
  3925. u32 dev_id, u8 flag, u32 task_tag, u32 cmd_tag)
  3926. {
  3927. struct task_abort_req task_abort;
  3928. struct inbound_queue_table *circularQ;
  3929. int ret;
  3930. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3931. memset(&task_abort, 0, sizeof(task_abort));
  3932. if (ABORT_SINGLE == (flag & ABORT_MASK)) {
  3933. task_abort.abort_all = 0;
  3934. task_abort.device_id = cpu_to_le32(dev_id);
  3935. task_abort.tag_to_abort = cpu_to_le32(task_tag);
  3936. task_abort.tag = cpu_to_le32(cmd_tag);
  3937. } else if (ABORT_ALL == (flag & ABORT_MASK)) {
  3938. task_abort.abort_all = cpu_to_le32(1);
  3939. task_abort.device_id = cpu_to_le32(dev_id);
  3940. task_abort.tag = cpu_to_le32(cmd_tag);
  3941. }
  3942. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &task_abort);
  3943. return ret;
  3944. }
  3945. /**
  3946. * pm8001_chip_abort_task - SAS abort task when error or exception happened.
  3947. * @task: the task we wanted to aborted.
  3948. * @flag: the abort flag.
  3949. */
  3950. static int pm8001_chip_abort_task(struct pm8001_hba_info *pm8001_ha,
  3951. struct pm8001_device *pm8001_dev, u8 flag, u32 task_tag, u32 cmd_tag)
  3952. {
  3953. u32 opc, device_id;
  3954. int rc = TMF_RESP_FUNC_FAILED;
  3955. PM8001_EH_DBG(pm8001_ha, pm8001_printk("cmd_tag = %x, abort task tag"
  3956. " = %x", cmd_tag, task_tag));
  3957. if (pm8001_dev->dev_type == SAS_END_DEV)
  3958. opc = OPC_INB_SSP_ABORT;
  3959. else if (pm8001_dev->dev_type == SATA_DEV)
  3960. opc = OPC_INB_SATA_ABORT;
  3961. else
  3962. opc = OPC_INB_SMP_ABORT;/* SMP */
  3963. device_id = pm8001_dev->device_id;
  3964. rc = send_task_abort(pm8001_ha, opc, device_id, flag,
  3965. task_tag, cmd_tag);
  3966. if (rc != TMF_RESP_FUNC_COMPLETE)
  3967. PM8001_EH_DBG(pm8001_ha, pm8001_printk("rc= %d\n", rc));
  3968. return rc;
  3969. }
  3970. /**
  3971. * pm8001_chip_ssp_tm_req - built the task management command.
  3972. * @pm8001_ha: our hba card information.
  3973. * @ccb: the ccb information.
  3974. * @tmf: task management function.
  3975. */
  3976. static int pm8001_chip_ssp_tm_req(struct pm8001_hba_info *pm8001_ha,
  3977. struct pm8001_ccb_info *ccb, struct pm8001_tmf_task *tmf)
  3978. {
  3979. struct sas_task *task = ccb->task;
  3980. struct domain_device *dev = task->dev;
  3981. struct pm8001_device *pm8001_dev = dev->lldd_dev;
  3982. u32 opc = OPC_INB_SSPINITMSTART;
  3983. struct inbound_queue_table *circularQ;
  3984. struct ssp_ini_tm_start_req sspTMCmd;
  3985. int ret;
  3986. memset(&sspTMCmd, 0, sizeof(sspTMCmd));
  3987. sspTMCmd.device_id = cpu_to_le32(pm8001_dev->device_id);
  3988. sspTMCmd.relate_tag = cpu_to_le32(tmf->tag_of_task_to_be_managed);
  3989. sspTMCmd.tmf = cpu_to_le32(tmf->tmf);
  3990. memcpy(sspTMCmd.lun, task->ssp_task.LUN, 8);
  3991. sspTMCmd.tag = cpu_to_le32(ccb->ccb_tag);
  3992. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  3993. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &sspTMCmd);
  3994. return ret;
  3995. }
  3996. static int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha,
  3997. void *payload)
  3998. {
  3999. u32 opc = OPC_INB_GET_NVMD_DATA;
  4000. u32 nvmd_type;
  4001. int rc;
  4002. u32 tag;
  4003. struct pm8001_ccb_info *ccb;
  4004. struct inbound_queue_table *circularQ;
  4005. struct get_nvm_data_req nvmd_req;
  4006. struct fw_control_ex *fw_control_context;
  4007. struct pm8001_ioctl_payload *ioctl_payload = payload;
  4008. nvmd_type = ioctl_payload->minor_function;
  4009. fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
  4010. if (!fw_control_context)
  4011. return -ENOMEM;
  4012. fw_control_context->usrAddr = (u8 *)&ioctl_payload->func_specific[0];
  4013. fw_control_context->len = ioctl_payload->length;
  4014. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4015. memset(&nvmd_req, 0, sizeof(nvmd_req));
  4016. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4017. if (rc) {
  4018. kfree(fw_control_context);
  4019. return rc;
  4020. }
  4021. ccb = &pm8001_ha->ccb_info[tag];
  4022. ccb->ccb_tag = tag;
  4023. ccb->fw_control_context = fw_control_context;
  4024. nvmd_req.tag = cpu_to_le32(tag);
  4025. switch (nvmd_type) {
  4026. case TWI_DEVICE: {
  4027. u32 twi_addr, twi_page_size;
  4028. twi_addr = 0xa8;
  4029. twi_page_size = 2;
  4030. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
  4031. twi_page_size << 8 | TWI_DEVICE);
  4032. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4033. nvmd_req.resp_addr_hi =
  4034. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4035. nvmd_req.resp_addr_lo =
  4036. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4037. break;
  4038. }
  4039. case C_SEEPROM: {
  4040. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
  4041. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4042. nvmd_req.resp_addr_hi =
  4043. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4044. nvmd_req.resp_addr_lo =
  4045. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4046. break;
  4047. }
  4048. case VPD_FLASH: {
  4049. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
  4050. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4051. nvmd_req.resp_addr_hi =
  4052. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4053. nvmd_req.resp_addr_lo =
  4054. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4055. break;
  4056. }
  4057. case EXPAN_ROM: {
  4058. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
  4059. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4060. nvmd_req.resp_addr_hi =
  4061. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4062. nvmd_req.resp_addr_lo =
  4063. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4064. break;
  4065. }
  4066. default:
  4067. break;
  4068. }
  4069. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req);
  4070. return rc;
  4071. }
  4072. static int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha,
  4073. void *payload)
  4074. {
  4075. u32 opc = OPC_INB_SET_NVMD_DATA;
  4076. u32 nvmd_type;
  4077. int rc;
  4078. u32 tag;
  4079. struct pm8001_ccb_info *ccb;
  4080. struct inbound_queue_table *circularQ;
  4081. struct set_nvm_data_req nvmd_req;
  4082. struct fw_control_ex *fw_control_context;
  4083. struct pm8001_ioctl_payload *ioctl_payload = payload;
  4084. nvmd_type = ioctl_payload->minor_function;
  4085. fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
  4086. if (!fw_control_context)
  4087. return -ENOMEM;
  4088. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4089. memcpy(pm8001_ha->memoryMap.region[NVMD].virt_ptr,
  4090. ioctl_payload->func_specific,
  4091. ioctl_payload->length);
  4092. memset(&nvmd_req, 0, sizeof(nvmd_req));
  4093. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4094. if (rc) {
  4095. kfree(fw_control_context);
  4096. return rc;
  4097. }
  4098. ccb = &pm8001_ha->ccb_info[tag];
  4099. ccb->fw_control_context = fw_control_context;
  4100. ccb->ccb_tag = tag;
  4101. nvmd_req.tag = cpu_to_le32(tag);
  4102. switch (nvmd_type) {
  4103. case TWI_DEVICE: {
  4104. u32 twi_addr, twi_page_size;
  4105. twi_addr = 0xa8;
  4106. twi_page_size = 2;
  4107. nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
  4108. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | twi_addr << 16 |
  4109. twi_page_size << 8 | TWI_DEVICE);
  4110. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4111. nvmd_req.resp_addr_hi =
  4112. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4113. nvmd_req.resp_addr_lo =
  4114. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4115. break;
  4116. }
  4117. case C_SEEPROM:
  4118. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | C_SEEPROM);
  4119. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4120. nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
  4121. nvmd_req.resp_addr_hi =
  4122. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4123. nvmd_req.resp_addr_lo =
  4124. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4125. break;
  4126. case VPD_FLASH:
  4127. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | VPD_FLASH);
  4128. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4129. nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
  4130. nvmd_req.resp_addr_hi =
  4131. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4132. nvmd_req.resp_addr_lo =
  4133. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4134. break;
  4135. case EXPAN_ROM:
  4136. nvmd_req.len_ir_vpdd = cpu_to_le32(IPMode | EXPAN_ROM);
  4137. nvmd_req.resp_len = cpu_to_le32(ioctl_payload->length);
  4138. nvmd_req.reserved[0] = cpu_to_le32(0xFEDCBA98);
  4139. nvmd_req.resp_addr_hi =
  4140. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_hi);
  4141. nvmd_req.resp_addr_lo =
  4142. cpu_to_le32(pm8001_ha->memoryMap.region[NVMD].phys_addr_lo);
  4143. break;
  4144. default:
  4145. break;
  4146. }
  4147. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &nvmd_req);
  4148. return rc;
  4149. }
  4150. /**
  4151. * pm8001_chip_fw_flash_update_build - support the firmware update operation
  4152. * @pm8001_ha: our hba card information.
  4153. * @fw_flash_updata_info: firmware flash update param
  4154. */
  4155. static int
  4156. pm8001_chip_fw_flash_update_build(struct pm8001_hba_info *pm8001_ha,
  4157. void *fw_flash_updata_info, u32 tag)
  4158. {
  4159. struct fw_flash_Update_req payload;
  4160. struct fw_flash_updata_info *info;
  4161. struct inbound_queue_table *circularQ;
  4162. int ret;
  4163. u32 opc = OPC_INB_FW_FLASH_UPDATE;
  4164. memset(&payload, 0, sizeof(struct fw_flash_Update_req));
  4165. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4166. info = fw_flash_updata_info;
  4167. payload.tag = cpu_to_le32(tag);
  4168. payload.cur_image_len = cpu_to_le32(info->cur_image_len);
  4169. payload.cur_image_offset = cpu_to_le32(info->cur_image_offset);
  4170. payload.total_image_len = cpu_to_le32(info->total_image_len);
  4171. payload.len = info->sgl.im_len.len ;
  4172. payload.sgl_addr_lo = lower_32_bits(info->sgl.addr);
  4173. payload.sgl_addr_hi = upper_32_bits(info->sgl.addr);
  4174. ret = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4175. return ret;
  4176. }
  4177. static int
  4178. pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
  4179. void *payload)
  4180. {
  4181. struct fw_flash_updata_info flash_update_info;
  4182. struct fw_control_info *fw_control;
  4183. struct fw_control_ex *fw_control_context;
  4184. int rc;
  4185. u32 tag;
  4186. struct pm8001_ccb_info *ccb;
  4187. void *buffer = NULL;
  4188. dma_addr_t phys_addr;
  4189. u32 phys_addr_hi;
  4190. u32 phys_addr_lo;
  4191. struct pm8001_ioctl_payload *ioctl_payload = payload;
  4192. fw_control_context = kzalloc(sizeof(struct fw_control_ex), GFP_KERNEL);
  4193. if (!fw_control_context)
  4194. return -ENOMEM;
  4195. fw_control = (struct fw_control_info *)&ioctl_payload->func_specific[0];
  4196. if (fw_control->len != 0) {
  4197. if (pm8001_mem_alloc(pm8001_ha->pdev,
  4198. (void **)&buffer,
  4199. &phys_addr,
  4200. &phys_addr_hi,
  4201. &phys_addr_lo,
  4202. fw_control->len, 0) != 0) {
  4203. PM8001_FAIL_DBG(pm8001_ha,
  4204. pm8001_printk("Mem alloc failure\n"));
  4205. kfree(fw_control_context);
  4206. return -ENOMEM;
  4207. }
  4208. }
  4209. memcpy(buffer, fw_control->buffer, fw_control->len);
  4210. flash_update_info.sgl.addr = cpu_to_le64(phys_addr);
  4211. flash_update_info.sgl.im_len.len = cpu_to_le32(fw_control->len);
  4212. flash_update_info.sgl.im_len.e = 0;
  4213. flash_update_info.cur_image_offset = fw_control->offset;
  4214. flash_update_info.cur_image_len = fw_control->len;
  4215. flash_update_info.total_image_len = fw_control->size;
  4216. fw_control_context->fw_control = fw_control;
  4217. fw_control_context->virtAddr = buffer;
  4218. fw_control_context->len = fw_control->len;
  4219. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4220. if (rc) {
  4221. kfree(fw_control_context);
  4222. return rc;
  4223. }
  4224. ccb = &pm8001_ha->ccb_info[tag];
  4225. ccb->fw_control_context = fw_control_context;
  4226. ccb->ccb_tag = tag;
  4227. rc = pm8001_chip_fw_flash_update_build(pm8001_ha, &flash_update_info,
  4228. tag);
  4229. return rc;
  4230. }
  4231. static int
  4232. pm8001_chip_set_dev_state_req(struct pm8001_hba_info *pm8001_ha,
  4233. struct pm8001_device *pm8001_dev, u32 state)
  4234. {
  4235. struct set_dev_state_req payload;
  4236. struct inbound_queue_table *circularQ;
  4237. struct pm8001_ccb_info *ccb;
  4238. int rc;
  4239. u32 tag;
  4240. u32 opc = OPC_INB_SET_DEVICE_STATE;
  4241. memset(&payload, 0, sizeof(payload));
  4242. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4243. if (rc)
  4244. return -1;
  4245. ccb = &pm8001_ha->ccb_info[tag];
  4246. ccb->ccb_tag = tag;
  4247. ccb->device = pm8001_dev;
  4248. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4249. payload.tag = cpu_to_le32(tag);
  4250. payload.device_id = cpu_to_le32(pm8001_dev->device_id);
  4251. payload.nds = cpu_to_le32(state);
  4252. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4253. return rc;
  4254. }
  4255. static int
  4256. pm8001_chip_sas_re_initialization(struct pm8001_hba_info *pm8001_ha)
  4257. {
  4258. struct sas_re_initialization_req payload;
  4259. struct inbound_queue_table *circularQ;
  4260. struct pm8001_ccb_info *ccb;
  4261. int rc;
  4262. u32 tag;
  4263. u32 opc = OPC_INB_SAS_RE_INITIALIZE;
  4264. memset(&payload, 0, sizeof(payload));
  4265. rc = pm8001_tag_alloc(pm8001_ha, &tag);
  4266. if (rc)
  4267. return -1;
  4268. ccb = &pm8001_ha->ccb_info[tag];
  4269. ccb->ccb_tag = tag;
  4270. circularQ = &pm8001_ha->inbnd_q_tbl[0];
  4271. payload.tag = cpu_to_le32(tag);
  4272. payload.SSAHOLT = cpu_to_le32(0xd << 25);
  4273. payload.sata_hol_tmo = cpu_to_le32(80);
  4274. payload.open_reject_cmdretries_data_retries = cpu_to_le32(0xff00ff);
  4275. rc = mpi_build_cmd(pm8001_ha, circularQ, opc, &payload);
  4276. return rc;
  4277. }
  4278. const struct pm8001_dispatch pm8001_8001_dispatch = {
  4279. .name = "pmc8001",
  4280. .chip_init = pm8001_chip_init,
  4281. .chip_soft_rst = pm8001_chip_soft_rst,
  4282. .chip_rst = pm8001_hw_chip_rst,
  4283. .chip_iounmap = pm8001_chip_iounmap,
  4284. .isr = pm8001_chip_isr,
  4285. .is_our_interupt = pm8001_chip_is_our_interupt,
  4286. .isr_process_oq = process_oq,
  4287. .interrupt_enable = pm8001_chip_interrupt_enable,
  4288. .interrupt_disable = pm8001_chip_interrupt_disable,
  4289. .make_prd = pm8001_chip_make_sg,
  4290. .smp_req = pm8001_chip_smp_req,
  4291. .ssp_io_req = pm8001_chip_ssp_io_req,
  4292. .sata_req = pm8001_chip_sata_req,
  4293. .phy_start_req = pm8001_chip_phy_start_req,
  4294. .phy_stop_req = pm8001_chip_phy_stop_req,
  4295. .reg_dev_req = pm8001_chip_reg_dev_req,
  4296. .dereg_dev_req = pm8001_chip_dereg_dev_req,
  4297. .phy_ctl_req = pm8001_chip_phy_ctl_req,
  4298. .task_abort = pm8001_chip_abort_task,
  4299. .ssp_tm_req = pm8001_chip_ssp_tm_req,
  4300. .get_nvmd_req = pm8001_chip_get_nvmd_req,
  4301. .set_nvmd_req = pm8001_chip_set_nvmd_req,
  4302. .fw_flash_update_req = pm8001_chip_fw_flash_update_req,
  4303. .set_dev_state_req = pm8001_chip_set_dev_state_req,
  4304. .sas_re_init_req = pm8001_chip_sas_re_initialization,
  4305. };