pm8001_hwi.c 163 KB

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