mptsas.c 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408
  1. /*
  2. * linux/drivers/message/fusion/mptsas.c
  3. * For use with LSI PCI chip/adapter(s)
  4. * running LSI Fusion MPT (Message Passing Technology) firmware.
  5. *
  6. * Copyright (c) 1999-2008 LSI Corporation
  7. * (mailto:DL-MPTFusionLinux@lsi.com)
  8. */
  9. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  10. /*
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; version 2 of the License.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. NO WARRANTY
  19. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  20. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  21. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  22. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  23. solely responsible for determining the appropriateness of using and
  24. distributing the Program and assumes all risks associated with its
  25. exercise of rights under this Agreement, including but not limited to
  26. the risks and costs of program errors, damage to or loss of data,
  27. programs or equipment, and unavailability or interruption of operations.
  28. DISCLAIMER OF LIABILITY
  29. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  30. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  32. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  33. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  34. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  35. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  36. You should have received a copy of the GNU General Public License
  37. along with this program; if not, write to the Free Software
  38. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  39. */
  40. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/init.h>
  44. #include <linux/errno.h>
  45. #include <linux/jiffies.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/delay.h> /* for mdelay */
  48. #include <scsi/scsi.h>
  49. #include <scsi/scsi_cmnd.h>
  50. #include <scsi/scsi_device.h>
  51. #include <scsi/scsi_host.h>
  52. #include <scsi/scsi_transport_sas.h>
  53. #include <scsi/scsi_dbg.h>
  54. #include "mptbase.h"
  55. #include "mptscsih.h"
  56. #include "mptsas.h"
  57. #define my_NAME "Fusion MPT SAS Host driver"
  58. #define my_VERSION MPT_LINUX_VERSION_COMMON
  59. #define MYNAM "mptsas"
  60. /*
  61. * Reserved channel for integrated raid
  62. */
  63. #define MPTSAS_RAID_CHANNEL 1
  64. MODULE_AUTHOR(MODULEAUTHOR);
  65. MODULE_DESCRIPTION(my_NAME);
  66. MODULE_LICENSE("GPL");
  67. MODULE_VERSION(my_VERSION);
  68. static int mpt_pt_clear;
  69. module_param(mpt_pt_clear, int, 0);
  70. MODULE_PARM_DESC(mpt_pt_clear,
  71. " Clear persistency table: enable=1 "
  72. "(default=MPTSCSIH_PT_CLEAR=0)");
  73. /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
  74. #define MPTSAS_MAX_LUN (16895)
  75. static int max_lun = MPTSAS_MAX_LUN;
  76. module_param(max_lun, int, 0);
  77. MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
  78. static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
  79. static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
  80. static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
  81. static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
  82. static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
  83. static void mptsas_firmware_event_work(struct work_struct *work);
  84. static void mptsas_send_sas_event(struct fw_event_work *fw_event);
  85. static void mptsas_send_raid_event(struct fw_event_work *fw_event);
  86. static void mptsas_send_ir2_event(struct fw_event_work *fw_event);
  87. static void mptsas_parse_device_info(struct sas_identify *identify,
  88. struct mptsas_devinfo *device_info);
  89. static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
  90. struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
  91. static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address
  92. (MPT_ADAPTER *ioc, u64 sas_address);
  93. static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
  94. struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
  95. static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
  96. struct mptsas_enclosure *enclosure, u32 form, u32 form_specific);
  97. static int mptsas_add_end_device(MPT_ADAPTER *ioc,
  98. struct mptsas_phyinfo *phy_info);
  99. static void mptsas_del_end_device(MPT_ADAPTER *ioc,
  100. struct mptsas_phyinfo *phy_info);
  101. static void mptsas_send_link_status_event(struct fw_event_work *fw_event);
  102. static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address
  103. (MPT_ADAPTER *ioc, u64 sas_address);
  104. static void mptsas_expander_delete(MPT_ADAPTER *ioc,
  105. struct mptsas_portinfo *port_info, u8 force);
  106. static void mptsas_send_expander_event(struct fw_event_work *fw_event);
  107. static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
  108. static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
  109. static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
  110. MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
  111. {
  112. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  113. "---- IO UNIT PAGE 0 ------------\n", ioc->name));
  114. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
  115. ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
  116. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
  117. ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
  118. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
  119. ioc->name, phy_data->Port));
  120. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
  121. ioc->name, phy_data->PortFlags));
  122. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
  123. ioc->name, phy_data->PhyFlags));
  124. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
  125. ioc->name, phy_data->NegotiatedLinkRate));
  126. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  127. "Controller PHY Device Info=0x%X\n", ioc->name,
  128. le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
  129. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
  130. ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
  131. }
  132. static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
  133. {
  134. __le64 sas_address;
  135. memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
  136. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  137. "---- SAS PHY PAGE 0 ------------\n", ioc->name));
  138. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  139. "Attached Device Handle=0x%X\n", ioc->name,
  140. le16_to_cpu(pg0->AttachedDevHandle)));
  141. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
  142. ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
  143. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  144. "Attached PHY Identifier=0x%X\n", ioc->name,
  145. pg0->AttachedPhyIdentifier));
  146. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
  147. ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
  148. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
  149. ioc->name, pg0->ProgrammedLinkRate));
  150. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
  151. ioc->name, pg0->ChangeCount));
  152. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
  153. ioc->name, le32_to_cpu(pg0->PhyInfo)));
  154. }
  155. static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
  156. {
  157. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  158. "---- SAS PHY PAGE 1 ------------\n", ioc->name));
  159. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
  160. ioc->name, pg1->InvalidDwordCount));
  161. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  162. "Running Disparity Error Count=0x%x\n", ioc->name,
  163. pg1->RunningDisparityErrorCount));
  164. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  165. "Loss Dword Synch Count=0x%x\n", ioc->name,
  166. pg1->LossDwordSynchCount));
  167. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  168. "PHY Reset Problem Count=0x%x\n\n", ioc->name,
  169. pg1->PhyResetProblemCount));
  170. }
  171. static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
  172. {
  173. __le64 sas_address;
  174. memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
  175. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  176. "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
  177. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
  178. ioc->name, le16_to_cpu(pg0->DevHandle)));
  179. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
  180. ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
  181. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
  182. ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
  183. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
  184. ioc->name, le16_to_cpu(pg0->Slot)));
  185. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
  186. ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
  187. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
  188. ioc->name, pg0->TargetID));
  189. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
  190. ioc->name, pg0->Bus));
  191. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
  192. ioc->name, pg0->PhyNum));
  193. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
  194. ioc->name, le16_to_cpu(pg0->AccessStatus)));
  195. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
  196. ioc->name, le32_to_cpu(pg0->DeviceInfo)));
  197. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
  198. ioc->name, le16_to_cpu(pg0->Flags)));
  199. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
  200. ioc->name, pg0->PhysicalPort));
  201. }
  202. static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
  203. {
  204. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  205. "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
  206. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
  207. ioc->name, pg1->PhysicalPort));
  208. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
  209. ioc->name, pg1->PhyIdentifier));
  210. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
  211. ioc->name, pg1->NegotiatedLinkRate));
  212. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
  213. ioc->name, pg1->ProgrammedLinkRate));
  214. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
  215. ioc->name, pg1->HwLinkRate));
  216. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
  217. ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
  218. dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  219. "Attached Device Handle=0x%X\n\n", ioc->name,
  220. le16_to_cpu(pg1->AttachedDevHandle)));
  221. }
  222. /* inhibit sas firmware event handling */
  223. static void
  224. mptsas_fw_event_off(MPT_ADAPTER *ioc)
  225. {
  226. unsigned long flags;
  227. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  228. ioc->fw_events_off = 1;
  229. ioc->sas_discovery_quiesce_io = 0;
  230. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  231. }
  232. /* enable sas firmware event handling */
  233. static void
  234. mptsas_fw_event_on(MPT_ADAPTER *ioc)
  235. {
  236. unsigned long flags;
  237. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  238. ioc->fw_events_off = 0;
  239. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  240. }
  241. /* queue a sas firmware event */
  242. static void
  243. mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
  244. unsigned long delay)
  245. {
  246. unsigned long flags;
  247. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  248. list_add_tail(&fw_event->list, &ioc->fw_event_list);
  249. INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
  250. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)\n",
  251. ioc->name, __func__, fw_event));
  252. queue_delayed_work(ioc->fw_event_q, &fw_event->work,
  253. delay);
  254. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  255. }
  256. /* free memory assoicated to a sas firmware event */
  257. static void
  258. mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
  259. {
  260. unsigned long flags;
  261. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  262. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n",
  263. ioc->name, __func__, fw_event));
  264. list_del(&fw_event->list);
  265. kfree(fw_event);
  266. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  267. }
  268. /* walk the firmware event queue, and either stop or wait for
  269. * outstanding events to complete */
  270. static void
  271. mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
  272. {
  273. struct fw_event_work *fw_event, *next;
  274. struct mptsas_target_reset_event *target_reset_list, *n;
  275. u8 flush_q;
  276. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  277. /* flush the target_reset_list */
  278. if (!list_empty(&hd->target_reset_list)) {
  279. list_for_each_entry_safe(target_reset_list, n,
  280. &hd->target_reset_list, list) {
  281. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  282. "%s: removing target reset for id=%d\n",
  283. ioc->name, __func__,
  284. target_reset_list->sas_event_data.TargetID));
  285. list_del(&target_reset_list->list);
  286. kfree(target_reset_list);
  287. }
  288. }
  289. if (list_empty(&ioc->fw_event_list) ||
  290. !ioc->fw_event_q || in_interrupt())
  291. return;
  292. flush_q = 0;
  293. list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
  294. if (cancel_delayed_work(&fw_event->work))
  295. mptsas_free_fw_event(ioc, fw_event);
  296. else
  297. flush_q = 1;
  298. }
  299. if (flush_q)
  300. flush_workqueue(ioc->fw_event_q);
  301. }
  302. static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
  303. {
  304. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  305. return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
  306. }
  307. static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
  308. {
  309. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  310. return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
  311. }
  312. /*
  313. * mptsas_find_portinfo_by_handle
  314. *
  315. * This function should be called with the sas_topology_mutex already held
  316. */
  317. static struct mptsas_portinfo *
  318. mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
  319. {
  320. struct mptsas_portinfo *port_info, *rc=NULL;
  321. int i;
  322. list_for_each_entry(port_info, &ioc->sas_topology, list)
  323. for (i = 0; i < port_info->num_phys; i++)
  324. if (port_info->phy_info[i].identify.handle == handle) {
  325. rc = port_info;
  326. goto out;
  327. }
  328. out:
  329. return rc;
  330. }
  331. /**
  332. * mptsas_find_portinfo_by_sas_address -
  333. * @ioc: Pointer to MPT_ADAPTER structure
  334. * @handle:
  335. *
  336. * This function should be called with the sas_topology_mutex already held
  337. *
  338. **/
  339. static struct mptsas_portinfo *
  340. mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
  341. {
  342. struct mptsas_portinfo *port_info, *rc = NULL;
  343. int i;
  344. if (sas_address >= ioc->hba_port_sas_addr &&
  345. sas_address < (ioc->hba_port_sas_addr +
  346. ioc->hba_port_num_phy))
  347. return ioc->hba_port_info;
  348. mutex_lock(&ioc->sas_topology_mutex);
  349. list_for_each_entry(port_info, &ioc->sas_topology, list)
  350. for (i = 0; i < port_info->num_phys; i++)
  351. if (port_info->phy_info[i].identify.sas_address ==
  352. sas_address) {
  353. rc = port_info;
  354. goto out;
  355. }
  356. out:
  357. mutex_unlock(&ioc->sas_topology_mutex);
  358. return rc;
  359. }
  360. /*
  361. * Returns true if there is a scsi end device
  362. */
  363. static inline int
  364. mptsas_is_end_device(struct mptsas_devinfo * attached)
  365. {
  366. if ((attached->sas_address) &&
  367. (attached->device_info &
  368. MPI_SAS_DEVICE_INFO_END_DEVICE) &&
  369. ((attached->device_info &
  370. MPI_SAS_DEVICE_INFO_SSP_TARGET) |
  371. (attached->device_info &
  372. MPI_SAS_DEVICE_INFO_STP_TARGET) |
  373. (attached->device_info &
  374. MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
  375. return 1;
  376. else
  377. return 0;
  378. }
  379. /* no mutex */
  380. static void
  381. mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
  382. {
  383. struct mptsas_portinfo *port_info;
  384. struct mptsas_phyinfo *phy_info;
  385. u8 i;
  386. if (!port_details)
  387. return;
  388. port_info = port_details->port_info;
  389. phy_info = port_info->phy_info;
  390. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
  391. "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
  392. port_details->num_phys, (unsigned long long)
  393. port_details->phy_bitmask));
  394. for (i = 0; i < port_info->num_phys; i++, phy_info++) {
  395. if(phy_info->port_details != port_details)
  396. continue;
  397. memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
  398. mptsas_set_rphy(ioc, phy_info, NULL);
  399. phy_info->port_details = NULL;
  400. }
  401. kfree(port_details);
  402. }
  403. static inline struct sas_rphy *
  404. mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
  405. {
  406. if (phy_info->port_details)
  407. return phy_info->port_details->rphy;
  408. else
  409. return NULL;
  410. }
  411. static inline void
  412. mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
  413. {
  414. if (phy_info->port_details) {
  415. phy_info->port_details->rphy = rphy;
  416. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
  417. ioc->name, rphy));
  418. }
  419. if (rphy) {
  420. dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
  421. &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
  422. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
  423. ioc->name, rphy, rphy->dev.release));
  424. }
  425. }
  426. static inline struct sas_port *
  427. mptsas_get_port(struct mptsas_phyinfo *phy_info)
  428. {
  429. if (phy_info->port_details)
  430. return phy_info->port_details->port;
  431. else
  432. return NULL;
  433. }
  434. static inline void
  435. mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
  436. {
  437. if (phy_info->port_details)
  438. phy_info->port_details->port = port;
  439. if (port) {
  440. dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
  441. &port->dev, MYIOC_s_FMT "add:", ioc->name));
  442. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
  443. ioc->name, port, port->dev.release));
  444. }
  445. }
  446. static inline struct scsi_target *
  447. mptsas_get_starget(struct mptsas_phyinfo *phy_info)
  448. {
  449. if (phy_info->port_details)
  450. return phy_info->port_details->starget;
  451. else
  452. return NULL;
  453. }
  454. static inline void
  455. mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
  456. starget)
  457. {
  458. if (phy_info->port_details)
  459. phy_info->port_details->starget = starget;
  460. }
  461. /**
  462. * mptsas_add_device_component -
  463. * @ioc: Pointer to MPT_ADAPTER structure
  464. * @channel: fw mapped id's
  465. * @id:
  466. * @sas_address:
  467. * @device_info:
  468. *
  469. **/
  470. static void
  471. mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
  472. u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
  473. {
  474. struct mptsas_device_info *sas_info, *next;
  475. struct scsi_device *sdev;
  476. struct scsi_target *starget;
  477. struct sas_rphy *rphy;
  478. /*
  479. * Delete all matching devices out of the list
  480. */
  481. mutex_lock(&ioc->sas_device_info_mutex);
  482. list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
  483. list) {
  484. if ((sas_info->sas_address == sas_address ||
  485. (sas_info->fw.channel == channel &&
  486. sas_info->fw.id == id))) {
  487. list_del(&sas_info->list);
  488. kfree(sas_info);
  489. }
  490. }
  491. sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
  492. if (!sas_info)
  493. goto out;
  494. /*
  495. * Set Firmware mapping
  496. */
  497. sas_info->fw.id = id;
  498. sas_info->fw.channel = channel;
  499. sas_info->sas_address = sas_address;
  500. sas_info->device_info = device_info;
  501. sas_info->slot = slot;
  502. sas_info->enclosure_logical_id = enclosure_logical_id;
  503. INIT_LIST_HEAD(&sas_info->list);
  504. list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
  505. /*
  506. * Set OS mapping
  507. */
  508. shost_for_each_device(sdev, ioc->sh) {
  509. starget = scsi_target(sdev);
  510. rphy = dev_to_rphy(starget->dev.parent);
  511. if (rphy->identify.sas_address == sas_address) {
  512. sas_info->os.id = starget->id;
  513. sas_info->os.channel = starget->channel;
  514. }
  515. }
  516. out:
  517. mutex_unlock(&ioc->sas_device_info_mutex);
  518. return;
  519. }
  520. /**
  521. * mptsas_add_device_component_by_fw -
  522. * @ioc: Pointer to MPT_ADAPTER structure
  523. * @channel: fw mapped id's
  524. * @id:
  525. *
  526. **/
  527. static void
  528. mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
  529. {
  530. struct mptsas_devinfo sas_device;
  531. struct mptsas_enclosure enclosure_info;
  532. int rc;
  533. rc = mptsas_sas_device_pg0(ioc, &sas_device,
  534. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
  535. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  536. (channel << 8) + id);
  537. if (rc)
  538. return;
  539. memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
  540. mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
  541. (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
  542. MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
  543. sas_device.handle_enclosure);
  544. mptsas_add_device_component(ioc, sas_device.channel,
  545. sas_device.id, sas_device.sas_address, sas_device.device_info,
  546. sas_device.slot, enclosure_info.enclosure_logical_id);
  547. }
  548. /**
  549. * mptsas_add_device_component_starget -
  550. * @ioc: Pointer to MPT_ADAPTER structure
  551. * @starget:
  552. *
  553. **/
  554. static void
  555. mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
  556. struct scsi_target *starget)
  557. {
  558. VirtTarget *vtarget;
  559. struct sas_rphy *rphy;
  560. struct mptsas_phyinfo *phy_info = NULL;
  561. struct mptsas_enclosure enclosure_info;
  562. rphy = dev_to_rphy(starget->dev.parent);
  563. vtarget = starget->hostdata;
  564. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  565. rphy->identify.sas_address);
  566. if (!phy_info)
  567. return;
  568. memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
  569. mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
  570. (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
  571. MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
  572. phy_info->attached.handle_enclosure);
  573. mptsas_add_device_component(ioc, phy_info->attached.channel,
  574. phy_info->attached.id, phy_info->attached.sas_address,
  575. phy_info->attached.device_info,
  576. phy_info->attached.slot, enclosure_info.enclosure_logical_id);
  577. }
  578. /**
  579. * mptsas_del_device_components - Cleaning the list
  580. * @ioc: Pointer to MPT_ADAPTER structure
  581. *
  582. **/
  583. static void
  584. mptsas_del_device_components(MPT_ADAPTER *ioc)
  585. {
  586. struct mptsas_device_info *sas_info, *next;
  587. mutex_lock(&ioc->sas_device_info_mutex);
  588. list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
  589. list) {
  590. list_del(&sas_info->list);
  591. kfree(sas_info);
  592. }
  593. mutex_unlock(&ioc->sas_device_info_mutex);
  594. }
  595. /*
  596. * mptsas_setup_wide_ports
  597. *
  598. * Updates for new and existing narrow/wide port configuration
  599. * in the sas_topology
  600. */
  601. static void
  602. mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
  603. {
  604. struct mptsas_portinfo_details * port_details;
  605. struct mptsas_phyinfo *phy_info, *phy_info_cmp;
  606. u64 sas_address;
  607. int i, j;
  608. mutex_lock(&ioc->sas_topology_mutex);
  609. phy_info = port_info->phy_info;
  610. for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
  611. if (phy_info->attached.handle)
  612. continue;
  613. port_details = phy_info->port_details;
  614. if (!port_details)
  615. continue;
  616. if (port_details->num_phys < 2)
  617. continue;
  618. /*
  619. * Removing a phy from a port, letting the last
  620. * phy be removed by firmware events.
  621. */
  622. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  623. "%s: [%p]: deleting phy = %d\n",
  624. ioc->name, __func__, port_details, i));
  625. port_details->num_phys--;
  626. port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
  627. memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
  628. sas_port_delete_phy(port_details->port, phy_info->phy);
  629. phy_info->port_details = NULL;
  630. }
  631. /*
  632. * Populate and refresh the tree
  633. */
  634. phy_info = port_info->phy_info;
  635. for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
  636. sas_address = phy_info->attached.sas_address;
  637. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
  638. ioc->name, i, (unsigned long long)sas_address));
  639. if (!sas_address)
  640. continue;
  641. port_details = phy_info->port_details;
  642. /*
  643. * Forming a port
  644. */
  645. if (!port_details) {
  646. port_details = kzalloc(sizeof(*port_details),
  647. GFP_KERNEL);
  648. if (!port_details)
  649. goto out;
  650. port_details->num_phys = 1;
  651. port_details->port_info = port_info;
  652. if (phy_info->phy_id < 64 )
  653. port_details->phy_bitmask |=
  654. (1 << phy_info->phy_id);
  655. phy_info->sas_port_add_phy=1;
  656. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
  657. "phy_id=%d sas_address=0x%018llX\n",
  658. ioc->name, i, (unsigned long long)sas_address));
  659. phy_info->port_details = port_details;
  660. }
  661. if (i == port_info->num_phys - 1)
  662. continue;
  663. phy_info_cmp = &port_info->phy_info[i + 1];
  664. for (j = i + 1 ; j < port_info->num_phys ; j++,
  665. phy_info_cmp++) {
  666. if (!phy_info_cmp->attached.sas_address)
  667. continue;
  668. if (sas_address != phy_info_cmp->attached.sas_address)
  669. continue;
  670. if (phy_info_cmp->port_details == port_details )
  671. continue;
  672. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  673. "\t\tphy_id=%d sas_address=0x%018llX\n",
  674. ioc->name, j, (unsigned long long)
  675. phy_info_cmp->attached.sas_address));
  676. if (phy_info_cmp->port_details) {
  677. port_details->rphy =
  678. mptsas_get_rphy(phy_info_cmp);
  679. port_details->port =
  680. mptsas_get_port(phy_info_cmp);
  681. port_details->starget =
  682. mptsas_get_starget(phy_info_cmp);
  683. port_details->num_phys =
  684. phy_info_cmp->port_details->num_phys;
  685. if (!phy_info_cmp->port_details->num_phys)
  686. kfree(phy_info_cmp->port_details);
  687. } else
  688. phy_info_cmp->sas_port_add_phy=1;
  689. /*
  690. * Adding a phy to a port
  691. */
  692. phy_info_cmp->port_details = port_details;
  693. if (phy_info_cmp->phy_id < 64 )
  694. port_details->phy_bitmask |=
  695. (1 << phy_info_cmp->phy_id);
  696. port_details->num_phys++;
  697. }
  698. }
  699. out:
  700. for (i = 0; i < port_info->num_phys; i++) {
  701. port_details = port_info->phy_info[i].port_details;
  702. if (!port_details)
  703. continue;
  704. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  705. "%s: [%p]: phy_id=%02d num_phys=%02d "
  706. "bitmask=0x%016llX\n", ioc->name, __func__,
  707. port_details, i, port_details->num_phys,
  708. (unsigned long long)port_details->phy_bitmask));
  709. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
  710. ioc->name, port_details->port, port_details->rphy));
  711. }
  712. dsaswideprintk(ioc, printk("\n"));
  713. mutex_unlock(&ioc->sas_topology_mutex);
  714. }
  715. /**
  716. * csmisas_find_vtarget
  717. *
  718. * @ioc
  719. * @volume_id
  720. * @volume_bus
  721. *
  722. **/
  723. static VirtTarget *
  724. mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
  725. {
  726. struct scsi_device *sdev;
  727. VirtDevice *vdevice;
  728. VirtTarget *vtarget = NULL;
  729. shost_for_each_device(sdev, ioc->sh) {
  730. vdevice = sdev->hostdata;
  731. if ((vdevice == NULL) ||
  732. (vdevice->vtarget == NULL))
  733. continue;
  734. if (vdevice->vtarget->id == id &&
  735. vdevice->vtarget->channel == channel)
  736. vtarget = vdevice->vtarget;
  737. }
  738. return vtarget;
  739. }
  740. static void
  741. mptsas_queue_device_delete(MPT_ADAPTER *ioc,
  742. MpiEventDataSasDeviceStatusChange_t *sas_event_data)
  743. {
  744. struct fw_event_work *fw_event;
  745. int sz;
  746. sz = offsetof(struct fw_event_work, event_data) +
  747. sizeof(MpiEventDataSasDeviceStatusChange_t);
  748. fw_event = kzalloc(sz, GFP_ATOMIC);
  749. if (!fw_event) {
  750. printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
  751. ioc->name, __func__, __LINE__);
  752. return;
  753. }
  754. memcpy(fw_event->event_data, sas_event_data,
  755. sizeof(MpiEventDataSasDeviceStatusChange_t));
  756. fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
  757. fw_event->ioc = ioc;
  758. mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
  759. }
  760. static void
  761. mptsas_queue_rescan(MPT_ADAPTER *ioc)
  762. {
  763. struct fw_event_work *fw_event;
  764. int sz;
  765. sz = offsetof(struct fw_event_work, event_data);
  766. fw_event = kzalloc(sz, GFP_ATOMIC);
  767. if (!fw_event) {
  768. printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
  769. ioc->name, __func__, __LINE__);
  770. return;
  771. }
  772. fw_event->event = -1;
  773. fw_event->ioc = ioc;
  774. mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
  775. }
  776. /**
  777. * mptsas_target_reset
  778. *
  779. * Issues TARGET_RESET to end device using handshaking method
  780. *
  781. * @ioc
  782. * @channel
  783. * @id
  784. *
  785. * Returns (1) success
  786. * (0) failure
  787. *
  788. **/
  789. static int
  790. mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
  791. {
  792. MPT_FRAME_HDR *mf;
  793. SCSITaskMgmt_t *pScsiTm;
  794. if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
  795. return 0;
  796. mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
  797. if (mf == NULL) {
  798. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
  799. "%s, no msg frames @%d!!\n", ioc->name,
  800. __func__, __LINE__));
  801. goto out_fail;
  802. }
  803. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
  804. ioc->name, mf));
  805. /* Format the Request
  806. */
  807. pScsiTm = (SCSITaskMgmt_t *) mf;
  808. memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
  809. pScsiTm->TargetID = id;
  810. pScsiTm->Bus = channel;
  811. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  812. pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  813. pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
  814. DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
  815. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  816. "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
  817. ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
  818. mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
  819. return 1;
  820. out_fail:
  821. mpt_clear_taskmgmt_in_progress_flag(ioc);
  822. return 0;
  823. }
  824. /**
  825. * mptsas_target_reset_queue
  826. *
  827. * Receive request for TARGET_RESET after recieving an firmware
  828. * event NOT_RESPONDING_EVENT, then put command in link list
  829. * and queue if task_queue already in use.
  830. *
  831. * @ioc
  832. * @sas_event_data
  833. *
  834. **/
  835. static void
  836. mptsas_target_reset_queue(MPT_ADAPTER *ioc,
  837. EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
  838. {
  839. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  840. VirtTarget *vtarget = NULL;
  841. struct mptsas_target_reset_event *target_reset_list;
  842. u8 id, channel;
  843. id = sas_event_data->TargetID;
  844. channel = sas_event_data->Bus;
  845. if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
  846. return;
  847. vtarget->deleted = 1; /* block IO */
  848. target_reset_list = kzalloc(sizeof(*target_reset_list),
  849. GFP_ATOMIC);
  850. if (!target_reset_list) {
  851. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
  852. "%s, failed to allocate mem @%d..!!\n",
  853. ioc->name, __func__, __LINE__));
  854. return;
  855. }
  856. memcpy(&target_reset_list->sas_event_data, sas_event_data,
  857. sizeof(*sas_event_data));
  858. list_add_tail(&target_reset_list->list, &hd->target_reset_list);
  859. target_reset_list->time_count = jiffies;
  860. if (mptsas_target_reset(ioc, channel, id)) {
  861. target_reset_list->target_reset_issued = 1;
  862. }
  863. }
  864. /**
  865. * mptsas_taskmgmt_complete - Completion for TARGET_RESET after
  866. * NOT_RESPONDING_EVENT, enable work queue to finish off removing device
  867. * from upper layers. then send next TARGET_RESET in the queue.
  868. * @ioc: Pointer to MPT_ADAPTER structure
  869. *
  870. **/
  871. static int
  872. mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  873. {
  874. MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
  875. struct list_head *head = &hd->target_reset_list;
  876. u8 id, channel;
  877. struct mptsas_target_reset_event *target_reset_list;
  878. SCSITaskMgmtReply_t *pScsiTmReply;
  879. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
  880. "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
  881. pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
  882. if (pScsiTmReply) {
  883. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  884. "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
  885. "\ttask_type = 0x%02X, iocstatus = 0x%04X "
  886. "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
  887. "term_cmnds = %d\n", ioc->name,
  888. pScsiTmReply->Bus, pScsiTmReply->TargetID,
  889. pScsiTmReply->TaskType,
  890. le16_to_cpu(pScsiTmReply->IOCStatus),
  891. le32_to_cpu(pScsiTmReply->IOCLogInfo),
  892. pScsiTmReply->ResponseCode,
  893. le32_to_cpu(pScsiTmReply->TerminationCount)));
  894. if (pScsiTmReply->ResponseCode)
  895. mptscsih_taskmgmt_response_code(ioc,
  896. pScsiTmReply->ResponseCode);
  897. }
  898. if (pScsiTmReply && (pScsiTmReply->TaskType ==
  899. MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
  900. MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
  901. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  902. ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  903. memcpy(ioc->taskmgmt_cmds.reply, mr,
  904. min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
  905. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
  906. ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  907. complete(&ioc->taskmgmt_cmds.done);
  908. return 1;
  909. }
  910. return 0;
  911. }
  912. mpt_clear_taskmgmt_in_progress_flag(ioc);
  913. if (list_empty(head))
  914. return 1;
  915. target_reset_list = list_entry(head->next,
  916. struct mptsas_target_reset_event, list);
  917. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  918. "TaskMgmt: completed (%d seconds)\n",
  919. ioc->name, jiffies_to_msecs(jiffies -
  920. target_reset_list->time_count)/1000));
  921. id = pScsiTmReply->TargetID;
  922. channel = pScsiTmReply->Bus;
  923. target_reset_list->time_count = jiffies;
  924. /*
  925. * retry target reset
  926. */
  927. if (!target_reset_list->target_reset_issued) {
  928. if (mptsas_target_reset(ioc, channel, id))
  929. target_reset_list->target_reset_issued = 1;
  930. return 1;
  931. }
  932. /*
  933. * enable work queue to remove device from upper layers
  934. */
  935. list_del(&target_reset_list->list);
  936. if ((mptsas_find_vtarget(ioc, channel, id)) && !ioc->fw_events_off)
  937. mptsas_queue_device_delete(ioc,
  938. &target_reset_list->sas_event_data);
  939. /*
  940. * issue target reset to next device in the queue
  941. */
  942. head = &hd->target_reset_list;
  943. if (list_empty(head))
  944. return 1;
  945. target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
  946. list);
  947. id = target_reset_list->sas_event_data.TargetID;
  948. channel = target_reset_list->sas_event_data.Bus;
  949. target_reset_list->time_count = jiffies;
  950. if (mptsas_target_reset(ioc, channel, id))
  951. target_reset_list->target_reset_issued = 1;
  952. return 1;
  953. }
  954. /**
  955. * mptscsih_ioc_reset
  956. *
  957. * @ioc
  958. * @reset_phase
  959. *
  960. **/
  961. static int
  962. mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  963. {
  964. MPT_SCSI_HOST *hd;
  965. int rc;
  966. rc = mptscsih_ioc_reset(ioc, reset_phase);
  967. if ((ioc->bus_type != SAS) || (!rc))
  968. return rc;
  969. hd = shost_priv(ioc->sh);
  970. if (!hd->ioc)
  971. goto out;
  972. switch (reset_phase) {
  973. case MPT_IOC_SETUP_RESET:
  974. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  975. "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
  976. mptsas_fw_event_off(ioc);
  977. break;
  978. case MPT_IOC_PRE_RESET:
  979. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  980. "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
  981. break;
  982. case MPT_IOC_POST_RESET:
  983. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  984. "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
  985. if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
  986. ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
  987. complete(&ioc->sas_mgmt.done);
  988. }
  989. mptsas_cleanup_fw_event_q(ioc);
  990. mptsas_queue_rescan(ioc);
  991. mptsas_fw_event_on(ioc);
  992. break;
  993. default:
  994. break;
  995. }
  996. out:
  997. return rc;
  998. }
  999. /**
  1000. * enum device_state -
  1001. * @DEVICE_RETRY: need to retry the TUR
  1002. * @DEVICE_ERROR: TUR return error, don't add device
  1003. * @DEVICE_READY: device can be added
  1004. *
  1005. */
  1006. enum device_state{
  1007. DEVICE_RETRY,
  1008. DEVICE_ERROR,
  1009. DEVICE_READY,
  1010. };
  1011. static int
  1012. mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
  1013. u32 form, u32 form_specific)
  1014. {
  1015. ConfigExtendedPageHeader_t hdr;
  1016. CONFIGPARMS cfg;
  1017. SasEnclosurePage0_t *buffer;
  1018. dma_addr_t dma_handle;
  1019. int error;
  1020. __le64 le_identifier;
  1021. memset(&hdr, 0, sizeof(hdr));
  1022. hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
  1023. hdr.PageNumber = 0;
  1024. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1025. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
  1026. cfg.cfghdr.ehdr = &hdr;
  1027. cfg.physAddr = -1;
  1028. cfg.pageAddr = form + form_specific;
  1029. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1030. cfg.dir = 0; /* read */
  1031. cfg.timeout = 10;
  1032. error = mpt_config(ioc, &cfg);
  1033. if (error)
  1034. goto out;
  1035. if (!hdr.ExtPageLength) {
  1036. error = -ENXIO;
  1037. goto out;
  1038. }
  1039. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1040. &dma_handle);
  1041. if (!buffer) {
  1042. error = -ENOMEM;
  1043. goto out;
  1044. }
  1045. cfg.physAddr = dma_handle;
  1046. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1047. error = mpt_config(ioc, &cfg);
  1048. if (error)
  1049. goto out_free_consistent;
  1050. /* save config data */
  1051. memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
  1052. enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
  1053. enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
  1054. enclosure->flags = le16_to_cpu(buffer->Flags);
  1055. enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
  1056. enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
  1057. enclosure->start_id = buffer->StartTargetID;
  1058. enclosure->start_channel = buffer->StartBus;
  1059. enclosure->sep_id = buffer->SEPTargetID;
  1060. enclosure->sep_channel = buffer->SEPBus;
  1061. out_free_consistent:
  1062. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1063. buffer, dma_handle);
  1064. out:
  1065. return error;
  1066. }
  1067. /**
  1068. * mptsas_add_end_device - report a new end device to sas transport layer
  1069. * @ioc: Pointer to MPT_ADAPTER structure
  1070. * @phy_info: decribes attached device
  1071. *
  1072. * return (0) success (1) failure
  1073. *
  1074. **/
  1075. static int
  1076. mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
  1077. {
  1078. struct sas_rphy *rphy;
  1079. struct sas_port *port;
  1080. struct sas_identify identify;
  1081. char *ds = NULL;
  1082. u8 fw_id;
  1083. if (!phy_info) {
  1084. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1085. "%s: exit at line=%d\n", ioc->name,
  1086. __func__, __LINE__));
  1087. return 1;
  1088. }
  1089. fw_id = phy_info->attached.id;
  1090. if (mptsas_get_rphy(phy_info)) {
  1091. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1092. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1093. __func__, fw_id, __LINE__));
  1094. return 2;
  1095. }
  1096. port = mptsas_get_port(phy_info);
  1097. if (!port) {
  1098. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1099. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1100. __func__, fw_id, __LINE__));
  1101. return 3;
  1102. }
  1103. if (phy_info->attached.device_info &
  1104. MPI_SAS_DEVICE_INFO_SSP_TARGET)
  1105. ds = "ssp";
  1106. if (phy_info->attached.device_info &
  1107. MPI_SAS_DEVICE_INFO_STP_TARGET)
  1108. ds = "stp";
  1109. if (phy_info->attached.device_info &
  1110. MPI_SAS_DEVICE_INFO_SATA_DEVICE)
  1111. ds = "sata";
  1112. printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
  1113. " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
  1114. phy_info->attached.channel, phy_info->attached.id,
  1115. phy_info->attached.phy_id, (unsigned long long)
  1116. phy_info->attached.sas_address);
  1117. mptsas_parse_device_info(&identify, &phy_info->attached);
  1118. rphy = sas_end_device_alloc(port);
  1119. if (!rphy) {
  1120. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1121. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1122. __func__, fw_id, __LINE__));
  1123. return 5; /* non-fatal: an rphy can be added later */
  1124. }
  1125. rphy->identify = identify;
  1126. if (sas_rphy_add(rphy)) {
  1127. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1128. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1129. __func__, fw_id, __LINE__));
  1130. sas_rphy_free(rphy);
  1131. return 6;
  1132. }
  1133. mptsas_set_rphy(ioc, phy_info, rphy);
  1134. return 0;
  1135. }
  1136. /**
  1137. * mptsas_del_end_device - report a deleted end device to sas transport
  1138. * layer
  1139. * @ioc: Pointer to MPT_ADAPTER structure
  1140. * @phy_info: decribes attached device
  1141. *
  1142. **/
  1143. static void
  1144. mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
  1145. {
  1146. struct sas_rphy *rphy;
  1147. struct sas_port *port;
  1148. struct mptsas_portinfo *port_info;
  1149. struct mptsas_phyinfo *phy_info_parent;
  1150. int i;
  1151. char *ds = NULL;
  1152. u8 fw_id;
  1153. u64 sas_address;
  1154. if (!phy_info)
  1155. return;
  1156. fw_id = phy_info->attached.id;
  1157. sas_address = phy_info->attached.sas_address;
  1158. if (!phy_info->port_details) {
  1159. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1160. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1161. __func__, fw_id, __LINE__));
  1162. return;
  1163. }
  1164. rphy = mptsas_get_rphy(phy_info);
  1165. if (!rphy) {
  1166. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1167. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1168. __func__, fw_id, __LINE__));
  1169. return;
  1170. }
  1171. if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR
  1172. || phy_info->attached.device_info
  1173. & MPI_SAS_DEVICE_INFO_SMP_INITIATOR
  1174. || phy_info->attached.device_info
  1175. & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
  1176. ds = "initiator";
  1177. if (phy_info->attached.device_info &
  1178. MPI_SAS_DEVICE_INFO_SSP_TARGET)
  1179. ds = "ssp";
  1180. if (phy_info->attached.device_info &
  1181. MPI_SAS_DEVICE_INFO_STP_TARGET)
  1182. ds = "stp";
  1183. if (phy_info->attached.device_info &
  1184. MPI_SAS_DEVICE_INFO_SATA_DEVICE)
  1185. ds = "sata";
  1186. dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT
  1187. "removing %s device: fw_channel %d, fw_id %d, phy %d,"
  1188. "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel,
  1189. phy_info->attached.id, phy_info->attached.phy_id,
  1190. (unsigned long long) sas_address);
  1191. port = mptsas_get_port(phy_info);
  1192. if (!port) {
  1193. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1194. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  1195. __func__, fw_id, __LINE__));
  1196. return;
  1197. }
  1198. port_info = phy_info->portinfo;
  1199. phy_info_parent = port_info->phy_info;
  1200. for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
  1201. if (!phy_info_parent->phy)
  1202. continue;
  1203. if (phy_info_parent->attached.sas_address !=
  1204. sas_address)
  1205. continue;
  1206. dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
  1207. MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
  1208. ioc->name, phy_info_parent->phy_id,
  1209. phy_info_parent->phy);
  1210. sas_port_delete_phy(port, phy_info_parent->phy);
  1211. }
  1212. dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
  1213. "delete port %d, sas_addr (0x%llx)\n", ioc->name,
  1214. port->port_identifier, (unsigned long long)sas_address);
  1215. sas_port_delete(port);
  1216. mptsas_set_port(ioc, phy_info, NULL);
  1217. mptsas_port_delete(ioc, phy_info->port_details);
  1218. }
  1219. struct mptsas_phyinfo *
  1220. mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
  1221. struct mptsas_devinfo *sas_device)
  1222. {
  1223. struct mptsas_phyinfo *phy_info;
  1224. struct mptsas_portinfo *port_info;
  1225. int i;
  1226. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  1227. sas_device->sas_address);
  1228. if (!phy_info)
  1229. goto out;
  1230. port_info = phy_info->portinfo;
  1231. if (!port_info)
  1232. goto out;
  1233. mutex_lock(&ioc->sas_topology_mutex);
  1234. for (i = 0; i < port_info->num_phys; i++) {
  1235. if (port_info->phy_info[i].attached.sas_address !=
  1236. sas_device->sas_address)
  1237. continue;
  1238. port_info->phy_info[i].attached.channel = sas_device->channel;
  1239. port_info->phy_info[i].attached.id = sas_device->id;
  1240. port_info->phy_info[i].attached.sas_address =
  1241. sas_device->sas_address;
  1242. port_info->phy_info[i].attached.handle = sas_device->handle;
  1243. port_info->phy_info[i].attached.handle_parent =
  1244. sas_device->handle_parent;
  1245. port_info->phy_info[i].attached.handle_enclosure =
  1246. sas_device->handle_enclosure;
  1247. }
  1248. mutex_unlock(&ioc->sas_topology_mutex);
  1249. out:
  1250. return phy_info;
  1251. }
  1252. /**
  1253. * mptsas_firmware_event_work - work thread for processing fw events
  1254. * @work: work queue payload containing info describing the event
  1255. * Context: user
  1256. *
  1257. */
  1258. static void
  1259. mptsas_firmware_event_work(struct work_struct *work)
  1260. {
  1261. struct fw_event_work *fw_event =
  1262. container_of(work, struct fw_event_work, work.work);
  1263. MPT_ADAPTER *ioc = fw_event->ioc;
  1264. /* special rescan topology handling */
  1265. if (fw_event->event == -1) {
  1266. if (ioc->in_rescan) {
  1267. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1268. "%s: rescan ignored as it is in progress\n",
  1269. ioc->name, __func__));
  1270. return;
  1271. }
  1272. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after "
  1273. "reset\n", ioc->name, __func__));
  1274. ioc->in_rescan = 1;
  1275. mptsas_not_responding_devices(ioc);
  1276. mptsas_scan_sas_topology(ioc);
  1277. ioc->in_rescan = 0;
  1278. mptsas_free_fw_event(ioc, fw_event);
  1279. return;
  1280. }
  1281. /* events handling turned off during host reset */
  1282. if (ioc->fw_events_off) {
  1283. mptsas_free_fw_event(ioc, fw_event);
  1284. return;
  1285. }
  1286. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), "
  1287. "event = (0x%02x)\n", ioc->name, __func__, fw_event,
  1288. (fw_event->event & 0xFF)));
  1289. switch (fw_event->event) {
  1290. case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
  1291. mptsas_send_sas_event(fw_event);
  1292. break;
  1293. case MPI_EVENT_INTEGRATED_RAID:
  1294. mptsas_send_raid_event(fw_event);
  1295. break;
  1296. case MPI_EVENT_IR2:
  1297. mptsas_send_ir2_event(fw_event);
  1298. break;
  1299. case MPI_EVENT_PERSISTENT_TABLE_FULL:
  1300. mptbase_sas_persist_operation(ioc,
  1301. MPI_SAS_OP_CLEAR_NOT_PRESENT);
  1302. mptsas_free_fw_event(ioc, fw_event);
  1303. break;
  1304. case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
  1305. mptsas_send_expander_event(fw_event);
  1306. break;
  1307. case MPI_EVENT_SAS_PHY_LINK_STATUS:
  1308. mptsas_send_link_status_event(fw_event);
  1309. break;
  1310. }
  1311. }
  1312. static int
  1313. mptsas_slave_configure(struct scsi_device *sdev)
  1314. {
  1315. struct Scsi_Host *host = sdev->host;
  1316. MPT_SCSI_HOST *hd = shost_priv(host);
  1317. MPT_ADAPTER *ioc = hd->ioc;
  1318. if (sdev->channel == MPTSAS_RAID_CHANNEL)
  1319. goto out;
  1320. sas_read_port_mode_page(sdev);
  1321. mptsas_add_device_component_starget(ioc, scsi_target(sdev));
  1322. out:
  1323. return mptscsih_slave_configure(sdev);
  1324. }
  1325. static int
  1326. mptsas_target_alloc(struct scsi_target *starget)
  1327. {
  1328. struct Scsi_Host *host = dev_to_shost(&starget->dev);
  1329. MPT_SCSI_HOST *hd = shost_priv(host);
  1330. VirtTarget *vtarget;
  1331. u8 id, channel;
  1332. struct sas_rphy *rphy;
  1333. struct mptsas_portinfo *p;
  1334. int i;
  1335. MPT_ADAPTER *ioc = hd->ioc;
  1336. vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
  1337. if (!vtarget)
  1338. return -ENOMEM;
  1339. vtarget->starget = starget;
  1340. vtarget->ioc_id = ioc->id;
  1341. vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
  1342. id = starget->id;
  1343. channel = 0;
  1344. /*
  1345. * RAID volumes placed beyond the last expected port.
  1346. */
  1347. if (starget->channel == MPTSAS_RAID_CHANNEL) {
  1348. for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
  1349. if (id == ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
  1350. channel = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
  1351. goto out;
  1352. }
  1353. rphy = dev_to_rphy(starget->dev.parent);
  1354. mutex_lock(&ioc->sas_topology_mutex);
  1355. list_for_each_entry(p, &ioc->sas_topology, list) {
  1356. for (i = 0; i < p->num_phys; i++) {
  1357. if (p->phy_info[i].attached.sas_address !=
  1358. rphy->identify.sas_address)
  1359. continue;
  1360. id = p->phy_info[i].attached.id;
  1361. channel = p->phy_info[i].attached.channel;
  1362. mptsas_set_starget(&p->phy_info[i], starget);
  1363. /*
  1364. * Exposing hidden raid components
  1365. */
  1366. if (mptscsih_is_phys_disk(ioc, channel, id)) {
  1367. id = mptscsih_raid_id_to_num(ioc,
  1368. channel, id);
  1369. vtarget->tflags |=
  1370. MPT_TARGET_FLAGS_RAID_COMPONENT;
  1371. p->phy_info[i].attached.phys_disk_num = id;
  1372. }
  1373. mutex_unlock(&ioc->sas_topology_mutex);
  1374. goto out;
  1375. }
  1376. }
  1377. mutex_unlock(&ioc->sas_topology_mutex);
  1378. kfree(vtarget);
  1379. return -ENXIO;
  1380. out:
  1381. vtarget->id = id;
  1382. vtarget->channel = channel;
  1383. starget->hostdata = vtarget;
  1384. return 0;
  1385. }
  1386. static void
  1387. mptsas_target_destroy(struct scsi_target *starget)
  1388. {
  1389. struct Scsi_Host *host = dev_to_shost(&starget->dev);
  1390. MPT_SCSI_HOST *hd = shost_priv(host);
  1391. struct sas_rphy *rphy;
  1392. struct mptsas_portinfo *p;
  1393. int i;
  1394. MPT_ADAPTER *ioc = hd->ioc;
  1395. VirtTarget *vtarget;
  1396. if (!starget->hostdata)
  1397. return;
  1398. vtarget = starget->hostdata;
  1399. if (starget->channel == MPTSAS_RAID_CHANNEL)
  1400. goto out;
  1401. rphy = dev_to_rphy(starget->dev.parent);
  1402. list_for_each_entry(p, &ioc->sas_topology, list) {
  1403. for (i = 0; i < p->num_phys; i++) {
  1404. if (p->phy_info[i].attached.sas_address !=
  1405. rphy->identify.sas_address)
  1406. continue;
  1407. starget_printk(KERN_INFO, starget, MYIOC_s_FMT
  1408. "delete device: fw_channel %d, fw_id %d, phy %d, "
  1409. "sas_addr 0x%llx\n", ioc->name,
  1410. p->phy_info[i].attached.channel,
  1411. p->phy_info[i].attached.id,
  1412. p->phy_info[i].attached.phy_id, (unsigned long long)
  1413. p->phy_info[i].attached.sas_address);
  1414. mptsas_set_starget(&p->phy_info[i], NULL);
  1415. }
  1416. }
  1417. out:
  1418. vtarget->starget = NULL;
  1419. kfree(starget->hostdata);
  1420. starget->hostdata = NULL;
  1421. }
  1422. static int
  1423. mptsas_slave_alloc(struct scsi_device *sdev)
  1424. {
  1425. struct Scsi_Host *host = sdev->host;
  1426. MPT_SCSI_HOST *hd = shost_priv(host);
  1427. struct sas_rphy *rphy;
  1428. struct mptsas_portinfo *p;
  1429. VirtDevice *vdevice;
  1430. struct scsi_target *starget;
  1431. int i;
  1432. MPT_ADAPTER *ioc = hd->ioc;
  1433. vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
  1434. if (!vdevice) {
  1435. printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
  1436. ioc->name, sizeof(VirtDevice));
  1437. return -ENOMEM;
  1438. }
  1439. starget = scsi_target(sdev);
  1440. vdevice->vtarget = starget->hostdata;
  1441. if (sdev->channel == MPTSAS_RAID_CHANNEL)
  1442. goto out;
  1443. rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
  1444. mutex_lock(&ioc->sas_topology_mutex);
  1445. list_for_each_entry(p, &ioc->sas_topology, list) {
  1446. for (i = 0; i < p->num_phys; i++) {
  1447. if (p->phy_info[i].attached.sas_address !=
  1448. rphy->identify.sas_address)
  1449. continue;
  1450. vdevice->lun = sdev->lun;
  1451. /*
  1452. * Exposing hidden raid components
  1453. */
  1454. if (mptscsih_is_phys_disk(ioc,
  1455. p->phy_info[i].attached.channel,
  1456. p->phy_info[i].attached.id))
  1457. sdev->no_uld_attach = 1;
  1458. mutex_unlock(&ioc->sas_topology_mutex);
  1459. goto out;
  1460. }
  1461. }
  1462. mutex_unlock(&ioc->sas_topology_mutex);
  1463. kfree(vdevice);
  1464. return -ENXIO;
  1465. out:
  1466. vdevice->vtarget->num_luns++;
  1467. sdev->hostdata = vdevice;
  1468. return 0;
  1469. }
  1470. static int
  1471. mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
  1472. {
  1473. MPT_SCSI_HOST *hd;
  1474. MPT_ADAPTER *ioc;
  1475. VirtDevice *vdevice = SCpnt->device->hostdata;
  1476. if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
  1477. SCpnt->result = DID_NO_CONNECT << 16;
  1478. done(SCpnt);
  1479. return 0;
  1480. }
  1481. hd = shost_priv(SCpnt->device->host);
  1482. ioc = hd->ioc;
  1483. if (ioc->sas_discovery_quiesce_io)
  1484. return SCSI_MLQUEUE_HOST_BUSY;
  1485. // scsi_print_command(SCpnt);
  1486. return mptscsih_qcmd(SCpnt,done);
  1487. }
  1488. static struct scsi_host_template mptsas_driver_template = {
  1489. .module = THIS_MODULE,
  1490. .proc_name = "mptsas",
  1491. .proc_info = mptscsih_proc_info,
  1492. .name = "MPT SPI Host",
  1493. .info = mptscsih_info,
  1494. .queuecommand = mptsas_qcmd,
  1495. .target_alloc = mptsas_target_alloc,
  1496. .slave_alloc = mptsas_slave_alloc,
  1497. .slave_configure = mptsas_slave_configure,
  1498. .target_destroy = mptsas_target_destroy,
  1499. .slave_destroy = mptscsih_slave_destroy,
  1500. .change_queue_depth = mptscsih_change_queue_depth,
  1501. .eh_abort_handler = mptscsih_abort,
  1502. .eh_device_reset_handler = mptscsih_dev_reset,
  1503. .eh_bus_reset_handler = mptscsih_bus_reset,
  1504. .eh_host_reset_handler = mptscsih_host_reset,
  1505. .bios_param = mptscsih_bios_param,
  1506. .can_queue = MPT_FC_CAN_QUEUE,
  1507. .this_id = -1,
  1508. .sg_tablesize = MPT_SCSI_SG_DEPTH,
  1509. .max_sectors = 8192,
  1510. .cmd_per_lun = 7,
  1511. .use_clustering = ENABLE_CLUSTERING,
  1512. .shost_attrs = mptscsih_host_attrs,
  1513. };
  1514. static int mptsas_get_linkerrors(struct sas_phy *phy)
  1515. {
  1516. MPT_ADAPTER *ioc = phy_to_ioc(phy);
  1517. ConfigExtendedPageHeader_t hdr;
  1518. CONFIGPARMS cfg;
  1519. SasPhyPage1_t *buffer;
  1520. dma_addr_t dma_handle;
  1521. int error;
  1522. /* FIXME: only have link errors on local phys */
  1523. if (!scsi_is_sas_phy_local(phy))
  1524. return -EINVAL;
  1525. hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
  1526. hdr.ExtPageLength = 0;
  1527. hdr.PageNumber = 1 /* page number 1*/;
  1528. hdr.Reserved1 = 0;
  1529. hdr.Reserved2 = 0;
  1530. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1531. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
  1532. cfg.cfghdr.ehdr = &hdr;
  1533. cfg.physAddr = -1;
  1534. cfg.pageAddr = phy->identify.phy_identifier;
  1535. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1536. cfg.dir = 0; /* read */
  1537. cfg.timeout = 10;
  1538. error = mpt_config(ioc, &cfg);
  1539. if (error)
  1540. return error;
  1541. if (!hdr.ExtPageLength)
  1542. return -ENXIO;
  1543. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1544. &dma_handle);
  1545. if (!buffer)
  1546. return -ENOMEM;
  1547. cfg.physAddr = dma_handle;
  1548. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1549. error = mpt_config(ioc, &cfg);
  1550. if (error)
  1551. goto out_free_consistent;
  1552. mptsas_print_phy_pg1(ioc, buffer);
  1553. phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
  1554. phy->running_disparity_error_count =
  1555. le32_to_cpu(buffer->RunningDisparityErrorCount);
  1556. phy->loss_of_dword_sync_count =
  1557. le32_to_cpu(buffer->LossDwordSynchCount);
  1558. phy->phy_reset_problem_count =
  1559. le32_to_cpu(buffer->PhyResetProblemCount);
  1560. out_free_consistent:
  1561. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1562. buffer, dma_handle);
  1563. return error;
  1564. }
  1565. static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
  1566. MPT_FRAME_HDR *reply)
  1567. {
  1568. ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  1569. if (reply != NULL) {
  1570. ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
  1571. memcpy(ioc->sas_mgmt.reply, reply,
  1572. min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
  1573. }
  1574. complete(&ioc->sas_mgmt.done);
  1575. return 1;
  1576. }
  1577. static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
  1578. {
  1579. MPT_ADAPTER *ioc = phy_to_ioc(phy);
  1580. SasIoUnitControlRequest_t *req;
  1581. SasIoUnitControlReply_t *reply;
  1582. MPT_FRAME_HDR *mf;
  1583. MPIHeader_t *hdr;
  1584. unsigned long timeleft;
  1585. int error = -ERESTARTSYS;
  1586. /* FIXME: fusion doesn't allow non-local phy reset */
  1587. if (!scsi_is_sas_phy_local(phy))
  1588. return -EINVAL;
  1589. /* not implemented for expanders */
  1590. if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
  1591. return -ENXIO;
  1592. if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
  1593. goto out;
  1594. mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
  1595. if (!mf) {
  1596. error = -ENOMEM;
  1597. goto out_unlock;
  1598. }
  1599. hdr = (MPIHeader_t *) mf;
  1600. req = (SasIoUnitControlRequest_t *)mf;
  1601. memset(req, 0, sizeof(SasIoUnitControlRequest_t));
  1602. req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
  1603. req->MsgContext = hdr->MsgContext;
  1604. req->Operation = hard_reset ?
  1605. MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
  1606. req->PhyNum = phy->identify.phy_identifier;
  1607. mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
  1608. timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
  1609. 10 * HZ);
  1610. if (!timeleft) {
  1611. /* On timeout reset the board */
  1612. mpt_free_msg_frame(ioc, mf);
  1613. mpt_HardResetHandler(ioc, CAN_SLEEP);
  1614. error = -ETIMEDOUT;
  1615. goto out_unlock;
  1616. }
  1617. /* a reply frame is expected */
  1618. if ((ioc->sas_mgmt.status &
  1619. MPT_MGMT_STATUS_RF_VALID) == 0) {
  1620. error = -ENXIO;
  1621. goto out_unlock;
  1622. }
  1623. /* process the completed Reply Message Frame */
  1624. reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
  1625. if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
  1626. printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
  1627. ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
  1628. error = -ENXIO;
  1629. goto out_unlock;
  1630. }
  1631. error = 0;
  1632. out_unlock:
  1633. mutex_unlock(&ioc->sas_mgmt.mutex);
  1634. out:
  1635. return error;
  1636. }
  1637. static int
  1638. mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
  1639. {
  1640. MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
  1641. int i, error;
  1642. struct mptsas_portinfo *p;
  1643. struct mptsas_enclosure enclosure_info;
  1644. u64 enclosure_handle;
  1645. mutex_lock(&ioc->sas_topology_mutex);
  1646. list_for_each_entry(p, &ioc->sas_topology, list) {
  1647. for (i = 0; i < p->num_phys; i++) {
  1648. if (p->phy_info[i].attached.sas_address ==
  1649. rphy->identify.sas_address) {
  1650. enclosure_handle = p->phy_info[i].
  1651. attached.handle_enclosure;
  1652. goto found_info;
  1653. }
  1654. }
  1655. }
  1656. mutex_unlock(&ioc->sas_topology_mutex);
  1657. return -ENXIO;
  1658. found_info:
  1659. mutex_unlock(&ioc->sas_topology_mutex);
  1660. memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
  1661. error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
  1662. (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
  1663. MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
  1664. if (!error)
  1665. *identifier = enclosure_info.enclosure_logical_id;
  1666. return error;
  1667. }
  1668. static int
  1669. mptsas_get_bay_identifier(struct sas_rphy *rphy)
  1670. {
  1671. MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
  1672. struct mptsas_portinfo *p;
  1673. int i, rc;
  1674. mutex_lock(&ioc->sas_topology_mutex);
  1675. list_for_each_entry(p, &ioc->sas_topology, list) {
  1676. for (i = 0; i < p->num_phys; i++) {
  1677. if (p->phy_info[i].attached.sas_address ==
  1678. rphy->identify.sas_address) {
  1679. rc = p->phy_info[i].attached.slot;
  1680. goto out;
  1681. }
  1682. }
  1683. }
  1684. rc = -ENXIO;
  1685. out:
  1686. mutex_unlock(&ioc->sas_topology_mutex);
  1687. return rc;
  1688. }
  1689. static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
  1690. struct request *req)
  1691. {
  1692. MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
  1693. MPT_FRAME_HDR *mf;
  1694. SmpPassthroughRequest_t *smpreq;
  1695. struct request *rsp = req->next_rq;
  1696. int ret;
  1697. int flagsLength;
  1698. unsigned long timeleft;
  1699. char *psge;
  1700. dma_addr_t dma_addr_in = 0;
  1701. dma_addr_t dma_addr_out = 0;
  1702. u64 sas_address = 0;
  1703. if (!rsp) {
  1704. printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n",
  1705. ioc->name, __func__);
  1706. return -EINVAL;
  1707. }
  1708. /* do we need to support multiple segments? */
  1709. if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
  1710. printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
  1711. ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
  1712. rsp->bio->bi_vcnt, rsp->data_len);
  1713. return -EINVAL;
  1714. }
  1715. ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
  1716. if (ret)
  1717. goto out;
  1718. mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
  1719. if (!mf) {
  1720. ret = -ENOMEM;
  1721. goto out_unlock;
  1722. }
  1723. smpreq = (SmpPassthroughRequest_t *)mf;
  1724. memset(smpreq, 0, sizeof(*smpreq));
  1725. smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
  1726. smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
  1727. if (rphy)
  1728. sas_address = rphy->identify.sas_address;
  1729. else {
  1730. struct mptsas_portinfo *port_info;
  1731. mutex_lock(&ioc->sas_topology_mutex);
  1732. port_info = ioc->hba_port_info;
  1733. if (port_info && port_info->phy_info)
  1734. sas_address =
  1735. port_info->phy_info[0].phy->identify.sas_address;
  1736. mutex_unlock(&ioc->sas_topology_mutex);
  1737. }
  1738. *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
  1739. psge = (char *)
  1740. (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
  1741. /* request */
  1742. flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
  1743. MPI_SGE_FLAGS_END_OF_BUFFER |
  1744. MPI_SGE_FLAGS_DIRECTION)
  1745. << MPI_SGE_FLAGS_SHIFT;
  1746. flagsLength |= (req->data_len - 4);
  1747. dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
  1748. req->data_len, PCI_DMA_BIDIRECTIONAL);
  1749. if (!dma_addr_out)
  1750. goto put_mf;
  1751. ioc->add_sge(psge, flagsLength, dma_addr_out);
  1752. psge += (sizeof(u32) + sizeof(dma_addr_t));
  1753. /* response */
  1754. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  1755. flagsLength |= rsp->data_len + 4;
  1756. dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
  1757. rsp->data_len, PCI_DMA_BIDIRECTIONAL);
  1758. if (!dma_addr_in)
  1759. goto unmap;
  1760. ioc->add_sge(psge, flagsLength, dma_addr_in);
  1761. mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
  1762. timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
  1763. if (!timeleft) {
  1764. printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__);
  1765. /* On timeout reset the board */
  1766. mpt_HardResetHandler(ioc, CAN_SLEEP);
  1767. ret = -ETIMEDOUT;
  1768. goto unmap;
  1769. }
  1770. mf = NULL;
  1771. if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
  1772. SmpPassthroughReply_t *smprep;
  1773. smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
  1774. memcpy(req->sense, smprep, sizeof(*smprep));
  1775. req->sense_len = sizeof(*smprep);
  1776. req->data_len = 0;
  1777. rsp->data_len -= smprep->ResponseDataLength;
  1778. } else {
  1779. printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
  1780. ioc->name, __func__);
  1781. ret = -ENXIO;
  1782. }
  1783. unmap:
  1784. if (dma_addr_out)
  1785. pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
  1786. PCI_DMA_BIDIRECTIONAL);
  1787. if (dma_addr_in)
  1788. pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
  1789. PCI_DMA_BIDIRECTIONAL);
  1790. put_mf:
  1791. if (mf)
  1792. mpt_free_msg_frame(ioc, mf);
  1793. out_unlock:
  1794. mutex_unlock(&ioc->sas_mgmt.mutex);
  1795. out:
  1796. return ret;
  1797. }
  1798. static struct sas_function_template mptsas_transport_functions = {
  1799. .get_linkerrors = mptsas_get_linkerrors,
  1800. .get_enclosure_identifier = mptsas_get_enclosure_identifier,
  1801. .get_bay_identifier = mptsas_get_bay_identifier,
  1802. .phy_reset = mptsas_phy_reset,
  1803. .smp_handler = mptsas_smp_handler,
  1804. };
  1805. static struct scsi_transport_template *mptsas_transport_template;
  1806. static int
  1807. mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
  1808. {
  1809. ConfigExtendedPageHeader_t hdr;
  1810. CONFIGPARMS cfg;
  1811. SasIOUnitPage0_t *buffer;
  1812. dma_addr_t dma_handle;
  1813. int error, i;
  1814. hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
  1815. hdr.ExtPageLength = 0;
  1816. hdr.PageNumber = 0;
  1817. hdr.Reserved1 = 0;
  1818. hdr.Reserved2 = 0;
  1819. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1820. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  1821. cfg.cfghdr.ehdr = &hdr;
  1822. cfg.physAddr = -1;
  1823. cfg.pageAddr = 0;
  1824. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1825. cfg.dir = 0; /* read */
  1826. cfg.timeout = 10;
  1827. error = mpt_config(ioc, &cfg);
  1828. if (error)
  1829. goto out;
  1830. if (!hdr.ExtPageLength) {
  1831. error = -ENXIO;
  1832. goto out;
  1833. }
  1834. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1835. &dma_handle);
  1836. if (!buffer) {
  1837. error = -ENOMEM;
  1838. goto out;
  1839. }
  1840. cfg.physAddr = dma_handle;
  1841. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1842. error = mpt_config(ioc, &cfg);
  1843. if (error)
  1844. goto out_free_consistent;
  1845. port_info->num_phys = buffer->NumPhys;
  1846. port_info->phy_info = kcalloc(port_info->num_phys,
  1847. sizeof(*port_info->phy_info),GFP_KERNEL);
  1848. if (!port_info->phy_info) {
  1849. error = -ENOMEM;
  1850. goto out_free_consistent;
  1851. }
  1852. ioc->nvdata_version_persistent =
  1853. le16_to_cpu(buffer->NvdataVersionPersistent);
  1854. ioc->nvdata_version_default =
  1855. le16_to_cpu(buffer->NvdataVersionDefault);
  1856. for (i = 0; i < port_info->num_phys; i++) {
  1857. mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
  1858. port_info->phy_info[i].phy_id = i;
  1859. port_info->phy_info[i].port_id =
  1860. buffer->PhyData[i].Port;
  1861. port_info->phy_info[i].negotiated_link_rate =
  1862. buffer->PhyData[i].NegotiatedLinkRate;
  1863. port_info->phy_info[i].portinfo = port_info;
  1864. port_info->phy_info[i].handle =
  1865. le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
  1866. }
  1867. out_free_consistent:
  1868. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1869. buffer, dma_handle);
  1870. out:
  1871. return error;
  1872. }
  1873. static int
  1874. mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
  1875. {
  1876. ConfigExtendedPageHeader_t hdr;
  1877. CONFIGPARMS cfg;
  1878. SasIOUnitPage1_t *buffer;
  1879. dma_addr_t dma_handle;
  1880. int error;
  1881. u16 device_missing_delay;
  1882. memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
  1883. memset(&cfg, 0, sizeof(CONFIGPARMS));
  1884. cfg.cfghdr.ehdr = &hdr;
  1885. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1886. cfg.timeout = 10;
  1887. cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1888. cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  1889. cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
  1890. cfg.cfghdr.ehdr->PageNumber = 1;
  1891. error = mpt_config(ioc, &cfg);
  1892. if (error)
  1893. goto out;
  1894. if (!hdr.ExtPageLength) {
  1895. error = -ENXIO;
  1896. goto out;
  1897. }
  1898. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1899. &dma_handle);
  1900. if (!buffer) {
  1901. error = -ENOMEM;
  1902. goto out;
  1903. }
  1904. cfg.physAddr = dma_handle;
  1905. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1906. error = mpt_config(ioc, &cfg);
  1907. if (error)
  1908. goto out_free_consistent;
  1909. ioc->io_missing_delay =
  1910. le16_to_cpu(buffer->IODeviceMissingDelay);
  1911. device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay);
  1912. ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
  1913. (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
  1914. device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  1915. out_free_consistent:
  1916. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1917. buffer, dma_handle);
  1918. out:
  1919. return error;
  1920. }
  1921. static int
  1922. mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
  1923. u32 form, u32 form_specific)
  1924. {
  1925. ConfigExtendedPageHeader_t hdr;
  1926. CONFIGPARMS cfg;
  1927. SasPhyPage0_t *buffer;
  1928. dma_addr_t dma_handle;
  1929. int error;
  1930. hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
  1931. hdr.ExtPageLength = 0;
  1932. hdr.PageNumber = 0;
  1933. hdr.Reserved1 = 0;
  1934. hdr.Reserved2 = 0;
  1935. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1936. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
  1937. cfg.cfghdr.ehdr = &hdr;
  1938. cfg.dir = 0; /* read */
  1939. cfg.timeout = 10;
  1940. /* Get Phy Pg 0 for each Phy. */
  1941. cfg.physAddr = -1;
  1942. cfg.pageAddr = form + form_specific;
  1943. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1944. error = mpt_config(ioc, &cfg);
  1945. if (error)
  1946. goto out;
  1947. if (!hdr.ExtPageLength) {
  1948. error = -ENXIO;
  1949. goto out;
  1950. }
  1951. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1952. &dma_handle);
  1953. if (!buffer) {
  1954. error = -ENOMEM;
  1955. goto out;
  1956. }
  1957. cfg.physAddr = dma_handle;
  1958. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1959. error = mpt_config(ioc, &cfg);
  1960. if (error)
  1961. goto out_free_consistent;
  1962. mptsas_print_phy_pg0(ioc, buffer);
  1963. phy_info->hw_link_rate = buffer->HwLinkRate;
  1964. phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
  1965. phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
  1966. phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
  1967. out_free_consistent:
  1968. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1969. buffer, dma_handle);
  1970. out:
  1971. return error;
  1972. }
  1973. static int
  1974. mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
  1975. u32 form, u32 form_specific)
  1976. {
  1977. ConfigExtendedPageHeader_t hdr;
  1978. CONFIGPARMS cfg;
  1979. SasDevicePage0_t *buffer;
  1980. dma_addr_t dma_handle;
  1981. __le64 sas_address;
  1982. int error=0;
  1983. if (ioc->sas_discovery_runtime &&
  1984. mptsas_is_end_device(device_info))
  1985. goto out;
  1986. hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
  1987. hdr.ExtPageLength = 0;
  1988. hdr.PageNumber = 0;
  1989. hdr.Reserved1 = 0;
  1990. hdr.Reserved2 = 0;
  1991. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1992. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
  1993. cfg.cfghdr.ehdr = &hdr;
  1994. cfg.pageAddr = form + form_specific;
  1995. cfg.physAddr = -1;
  1996. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1997. cfg.dir = 0; /* read */
  1998. cfg.timeout = 10;
  1999. memset(device_info, 0, sizeof(struct mptsas_devinfo));
  2000. error = mpt_config(ioc, &cfg);
  2001. if (error)
  2002. goto out;
  2003. if (!hdr.ExtPageLength) {
  2004. error = -ENXIO;
  2005. goto out;
  2006. }
  2007. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  2008. &dma_handle);
  2009. if (!buffer) {
  2010. error = -ENOMEM;
  2011. goto out;
  2012. }
  2013. cfg.physAddr = dma_handle;
  2014. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2015. error = mpt_config(ioc, &cfg);
  2016. if (error)
  2017. goto out_free_consistent;
  2018. mptsas_print_device_pg0(ioc, buffer);
  2019. device_info->handle = le16_to_cpu(buffer->DevHandle);
  2020. device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
  2021. device_info->handle_enclosure =
  2022. le16_to_cpu(buffer->EnclosureHandle);
  2023. device_info->slot = le16_to_cpu(buffer->Slot);
  2024. device_info->phy_id = buffer->PhyNum;
  2025. device_info->port_id = buffer->PhysicalPort;
  2026. device_info->id = buffer->TargetID;
  2027. device_info->phys_disk_num = ~0;
  2028. device_info->channel = buffer->Bus;
  2029. memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
  2030. device_info->sas_address = le64_to_cpu(sas_address);
  2031. device_info->device_info =
  2032. le32_to_cpu(buffer->DeviceInfo);
  2033. out_free_consistent:
  2034. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  2035. buffer, dma_handle);
  2036. out:
  2037. return error;
  2038. }
  2039. static int
  2040. mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
  2041. u32 form, u32 form_specific)
  2042. {
  2043. ConfigExtendedPageHeader_t hdr;
  2044. CONFIGPARMS cfg;
  2045. SasExpanderPage0_t *buffer;
  2046. dma_addr_t dma_handle;
  2047. int i, error;
  2048. hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
  2049. hdr.ExtPageLength = 0;
  2050. hdr.PageNumber = 0;
  2051. hdr.Reserved1 = 0;
  2052. hdr.Reserved2 = 0;
  2053. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  2054. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
  2055. cfg.cfghdr.ehdr = &hdr;
  2056. cfg.physAddr = -1;
  2057. cfg.pageAddr = form + form_specific;
  2058. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  2059. cfg.dir = 0; /* read */
  2060. cfg.timeout = 10;
  2061. memset(port_info, 0, sizeof(struct mptsas_portinfo));
  2062. error = mpt_config(ioc, &cfg);
  2063. if (error)
  2064. goto out;
  2065. if (!hdr.ExtPageLength) {
  2066. error = -ENXIO;
  2067. goto out;
  2068. }
  2069. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  2070. &dma_handle);
  2071. if (!buffer) {
  2072. error = -ENOMEM;
  2073. goto out;
  2074. }
  2075. cfg.physAddr = dma_handle;
  2076. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2077. error = mpt_config(ioc, &cfg);
  2078. if (error)
  2079. goto out_free_consistent;
  2080. if (!buffer->NumPhys) {
  2081. error = -ENODEV;
  2082. goto out_free_consistent;
  2083. }
  2084. /* save config data */
  2085. port_info->num_phys = buffer->NumPhys;
  2086. port_info->phy_info = kcalloc(port_info->num_phys,
  2087. sizeof(*port_info->phy_info),GFP_KERNEL);
  2088. if (!port_info->phy_info) {
  2089. error = -ENOMEM;
  2090. goto out_free_consistent;
  2091. }
  2092. for (i = 0; i < port_info->num_phys; i++) {
  2093. port_info->phy_info[i].portinfo = port_info;
  2094. port_info->phy_info[i].handle =
  2095. le16_to_cpu(buffer->DevHandle);
  2096. }
  2097. out_free_consistent:
  2098. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  2099. buffer, dma_handle);
  2100. out:
  2101. return error;
  2102. }
  2103. static int
  2104. mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
  2105. u32 form, u32 form_specific)
  2106. {
  2107. ConfigExtendedPageHeader_t hdr;
  2108. CONFIGPARMS cfg;
  2109. SasExpanderPage1_t *buffer;
  2110. dma_addr_t dma_handle;
  2111. int error=0;
  2112. if (ioc->sas_discovery_runtime &&
  2113. mptsas_is_end_device(&phy_info->attached))
  2114. goto out;
  2115. hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
  2116. hdr.ExtPageLength = 0;
  2117. hdr.PageNumber = 1;
  2118. hdr.Reserved1 = 0;
  2119. hdr.Reserved2 = 0;
  2120. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  2121. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
  2122. cfg.cfghdr.ehdr = &hdr;
  2123. cfg.physAddr = -1;
  2124. cfg.pageAddr = form + form_specific;
  2125. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  2126. cfg.dir = 0; /* read */
  2127. cfg.timeout = 10;
  2128. error = mpt_config(ioc, &cfg);
  2129. if (error)
  2130. goto out;
  2131. if (!hdr.ExtPageLength) {
  2132. error = -ENXIO;
  2133. goto out;
  2134. }
  2135. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  2136. &dma_handle);
  2137. if (!buffer) {
  2138. error = -ENOMEM;
  2139. goto out;
  2140. }
  2141. cfg.physAddr = dma_handle;
  2142. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2143. error = mpt_config(ioc, &cfg);
  2144. if (error)
  2145. goto out_free_consistent;
  2146. mptsas_print_expander_pg1(ioc, buffer);
  2147. /* save config data */
  2148. phy_info->phy_id = buffer->PhyIdentifier;
  2149. phy_info->port_id = buffer->PhysicalPort;
  2150. phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
  2151. phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
  2152. phy_info->hw_link_rate = buffer->HwLinkRate;
  2153. phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
  2154. phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
  2155. out_free_consistent:
  2156. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  2157. buffer, dma_handle);
  2158. out:
  2159. return error;
  2160. }
  2161. static void
  2162. mptsas_parse_device_info(struct sas_identify *identify,
  2163. struct mptsas_devinfo *device_info)
  2164. {
  2165. u16 protocols;
  2166. identify->sas_address = device_info->sas_address;
  2167. identify->phy_identifier = device_info->phy_id;
  2168. /*
  2169. * Fill in Phy Initiator Port Protocol.
  2170. * Bits 6:3, more than one bit can be set, fall through cases.
  2171. */
  2172. protocols = device_info->device_info & 0x78;
  2173. identify->initiator_port_protocols = 0;
  2174. if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
  2175. identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
  2176. if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
  2177. identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
  2178. if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
  2179. identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
  2180. if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
  2181. identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
  2182. /*
  2183. * Fill in Phy Target Port Protocol.
  2184. * Bits 10:7, more than one bit can be set, fall through cases.
  2185. */
  2186. protocols = device_info->device_info & 0x780;
  2187. identify->target_port_protocols = 0;
  2188. if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
  2189. identify->target_port_protocols |= SAS_PROTOCOL_SSP;
  2190. if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
  2191. identify->target_port_protocols |= SAS_PROTOCOL_STP;
  2192. if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
  2193. identify->target_port_protocols |= SAS_PROTOCOL_SMP;
  2194. if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
  2195. identify->target_port_protocols |= SAS_PROTOCOL_SATA;
  2196. /*
  2197. * Fill in Attached device type.
  2198. */
  2199. switch (device_info->device_info &
  2200. MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
  2201. case MPI_SAS_DEVICE_INFO_NO_DEVICE:
  2202. identify->device_type = SAS_PHY_UNUSED;
  2203. break;
  2204. case MPI_SAS_DEVICE_INFO_END_DEVICE:
  2205. identify->device_type = SAS_END_DEVICE;
  2206. break;
  2207. case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
  2208. identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
  2209. break;
  2210. case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
  2211. identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
  2212. break;
  2213. }
  2214. }
  2215. static int mptsas_probe_one_phy(struct device *dev,
  2216. struct mptsas_phyinfo *phy_info, int index, int local)
  2217. {
  2218. MPT_ADAPTER *ioc;
  2219. struct sas_phy *phy;
  2220. struct sas_port *port;
  2221. int error = 0;
  2222. if (!dev) {
  2223. error = -ENODEV;
  2224. goto out;
  2225. }
  2226. if (!phy_info->phy) {
  2227. phy = sas_phy_alloc(dev, index);
  2228. if (!phy) {
  2229. error = -ENOMEM;
  2230. goto out;
  2231. }
  2232. } else
  2233. phy = phy_info->phy;
  2234. mptsas_parse_device_info(&phy->identify, &phy_info->identify);
  2235. /*
  2236. * Set Negotiated link rate.
  2237. */
  2238. switch (phy_info->negotiated_link_rate) {
  2239. case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
  2240. phy->negotiated_linkrate = SAS_PHY_DISABLED;
  2241. break;
  2242. case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
  2243. phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
  2244. break;
  2245. case MPI_SAS_IOUNIT0_RATE_1_5:
  2246. phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
  2247. break;
  2248. case MPI_SAS_IOUNIT0_RATE_3_0:
  2249. phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
  2250. break;
  2251. case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
  2252. case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
  2253. default:
  2254. phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
  2255. break;
  2256. }
  2257. /*
  2258. * Set Max hardware link rate.
  2259. */
  2260. switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
  2261. case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
  2262. phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
  2263. break;
  2264. case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
  2265. phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
  2266. break;
  2267. default:
  2268. break;
  2269. }
  2270. /*
  2271. * Set Max programmed link rate.
  2272. */
  2273. switch (phy_info->programmed_link_rate &
  2274. MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
  2275. case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
  2276. phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  2277. break;
  2278. case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
  2279. phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
  2280. break;
  2281. default:
  2282. break;
  2283. }
  2284. /*
  2285. * Set Min hardware link rate.
  2286. */
  2287. switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
  2288. case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
  2289. phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
  2290. break;
  2291. case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
  2292. phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
  2293. break;
  2294. default:
  2295. break;
  2296. }
  2297. /*
  2298. * Set Min programmed link rate.
  2299. */
  2300. switch (phy_info->programmed_link_rate &
  2301. MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
  2302. case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
  2303. phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  2304. break;
  2305. case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
  2306. phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
  2307. break;
  2308. default:
  2309. break;
  2310. }
  2311. if (!phy_info->phy) {
  2312. error = sas_phy_add(phy);
  2313. if (error) {
  2314. sas_phy_free(phy);
  2315. goto out;
  2316. }
  2317. phy_info->phy = phy;
  2318. }
  2319. if (!phy_info->attached.handle ||
  2320. !phy_info->port_details)
  2321. goto out;
  2322. port = mptsas_get_port(phy_info);
  2323. ioc = phy_to_ioc(phy_info->phy);
  2324. if (phy_info->sas_port_add_phy) {
  2325. if (!port) {
  2326. port = sas_port_alloc_num(dev);
  2327. if (!port) {
  2328. error = -ENOMEM;
  2329. goto out;
  2330. }
  2331. error = sas_port_add(port);
  2332. if (error) {
  2333. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2334. "%s: exit at line=%d\n", ioc->name,
  2335. __func__, __LINE__));
  2336. goto out;
  2337. }
  2338. mptsas_set_port(ioc, phy_info, port);
  2339. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2340. "sas_port_alloc: port=%p dev=%p port_id=%d\n",
  2341. ioc->name, port, dev, port->port_identifier));
  2342. }
  2343. dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_port_add_phy: phy_id=%d\n",
  2344. ioc->name, phy_info->phy_id));
  2345. sas_port_add_phy(port, phy_info->phy);
  2346. phy_info->sas_port_add_phy = 0;
  2347. }
  2348. if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
  2349. struct sas_rphy *rphy;
  2350. struct device *parent;
  2351. struct sas_identify identify;
  2352. parent = dev->parent->parent;
  2353. /*
  2354. * Let the hotplug_work thread handle processing
  2355. * the adding/removing of devices that occur
  2356. * after start of day.
  2357. */
  2358. if (ioc->sas_discovery_runtime &&
  2359. mptsas_is_end_device(&phy_info->attached))
  2360. goto out;
  2361. mptsas_parse_device_info(&identify, &phy_info->attached);
  2362. if (scsi_is_host_device(parent)) {
  2363. struct mptsas_portinfo *port_info;
  2364. int i;
  2365. port_info = ioc->hba_port_info;
  2366. for (i = 0; i < port_info->num_phys; i++)
  2367. if (port_info->phy_info[i].identify.sas_address ==
  2368. identify.sas_address) {
  2369. sas_port_mark_backlink(port);
  2370. goto out;
  2371. }
  2372. } else if (scsi_is_sas_rphy(parent)) {
  2373. struct sas_rphy *parent_rphy = dev_to_rphy(parent);
  2374. if (identify.sas_address ==
  2375. parent_rphy->identify.sas_address) {
  2376. sas_port_mark_backlink(port);
  2377. goto out;
  2378. }
  2379. }
  2380. switch (identify.device_type) {
  2381. case SAS_END_DEVICE:
  2382. rphy = sas_end_device_alloc(port);
  2383. break;
  2384. case SAS_EDGE_EXPANDER_DEVICE:
  2385. case SAS_FANOUT_EXPANDER_DEVICE:
  2386. rphy = sas_expander_alloc(port, identify.device_type);
  2387. break;
  2388. default:
  2389. rphy = NULL;
  2390. break;
  2391. }
  2392. if (!rphy) {
  2393. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2394. "%s: exit at line=%d\n", ioc->name,
  2395. __func__, __LINE__));
  2396. goto out;
  2397. }
  2398. rphy->identify = identify;
  2399. error = sas_rphy_add(rphy);
  2400. if (error) {
  2401. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2402. "%s: exit at line=%d\n", ioc->name,
  2403. __func__, __LINE__));
  2404. sas_rphy_free(rphy);
  2405. goto out;
  2406. }
  2407. mptsas_set_rphy(ioc, phy_info, rphy);
  2408. }
  2409. out:
  2410. return error;
  2411. }
  2412. static int
  2413. mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
  2414. {
  2415. struct mptsas_portinfo *port_info, *hba;
  2416. int error = -ENOMEM, i;
  2417. hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
  2418. if (! hba)
  2419. goto out;
  2420. error = mptsas_sas_io_unit_pg0(ioc, hba);
  2421. if (error)
  2422. goto out_free_port_info;
  2423. mptsas_sas_io_unit_pg1(ioc);
  2424. mutex_lock(&ioc->sas_topology_mutex);
  2425. port_info = ioc->hba_port_info;
  2426. if (!port_info) {
  2427. ioc->hba_port_info = port_info = hba;
  2428. ioc->hba_port_num_phy = port_info->num_phys;
  2429. list_add_tail(&port_info->list, &ioc->sas_topology);
  2430. } else {
  2431. for (i = 0; i < hba->num_phys; i++) {
  2432. port_info->phy_info[i].negotiated_link_rate =
  2433. hba->phy_info[i].negotiated_link_rate;
  2434. port_info->phy_info[i].handle =
  2435. hba->phy_info[i].handle;
  2436. port_info->phy_info[i].port_id =
  2437. hba->phy_info[i].port_id;
  2438. }
  2439. kfree(hba->phy_info);
  2440. kfree(hba);
  2441. hba = NULL;
  2442. }
  2443. mutex_unlock(&ioc->sas_topology_mutex);
  2444. #if defined(CPQ_CIM)
  2445. ioc->num_ports = port_info->num_phys;
  2446. #endif
  2447. for (i = 0; i < port_info->num_phys; i++) {
  2448. mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
  2449. (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
  2450. MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
  2451. port_info->phy_info[i].identify.handle =
  2452. port_info->phy_info[i].handle;
  2453. mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
  2454. (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
  2455. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  2456. port_info->phy_info[i].identify.handle);
  2457. if (!ioc->hba_port_sas_addr)
  2458. ioc->hba_port_sas_addr =
  2459. port_info->phy_info[i].identify.sas_address;
  2460. port_info->phy_info[i].identify.phy_id =
  2461. port_info->phy_info[i].phy_id = i;
  2462. if (port_info->phy_info[i].attached.handle)
  2463. mptsas_sas_device_pg0(ioc,
  2464. &port_info->phy_info[i].attached,
  2465. (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
  2466. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  2467. port_info->phy_info[i].attached.handle);
  2468. }
  2469. mptsas_setup_wide_ports(ioc, port_info);
  2470. for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
  2471. mptsas_probe_one_phy(&ioc->sh->shost_gendev,
  2472. &port_info->phy_info[i], ioc->sas_index, 1);
  2473. return 0;
  2474. out_free_port_info:
  2475. kfree(hba);
  2476. out:
  2477. return error;
  2478. }
  2479. static void
  2480. mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
  2481. {
  2482. struct mptsas_portinfo *parent;
  2483. struct device *parent_dev;
  2484. struct sas_rphy *rphy;
  2485. int i;
  2486. u64 sas_address; /* expander sas address */
  2487. u32 handle;
  2488. handle = port_info->phy_info[0].handle;
  2489. sas_address = port_info->phy_info[0].identify.sas_address;
  2490. for (i = 0; i < port_info->num_phys; i++) {
  2491. mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
  2492. (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
  2493. MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle);
  2494. mptsas_sas_device_pg0(ioc,
  2495. &port_info->phy_info[i].identify,
  2496. (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
  2497. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  2498. port_info->phy_info[i].identify.handle);
  2499. port_info->phy_info[i].identify.phy_id =
  2500. port_info->phy_info[i].phy_id;
  2501. if (port_info->phy_info[i].attached.handle) {
  2502. mptsas_sas_device_pg0(ioc,
  2503. &port_info->phy_info[i].attached,
  2504. (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
  2505. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  2506. port_info->phy_info[i].attached.handle);
  2507. port_info->phy_info[i].attached.phy_id =
  2508. port_info->phy_info[i].phy_id;
  2509. }
  2510. }
  2511. mutex_lock(&ioc->sas_topology_mutex);
  2512. parent = mptsas_find_portinfo_by_handle(ioc,
  2513. port_info->phy_info[0].identify.handle_parent);
  2514. if (!parent) {
  2515. mutex_unlock(&ioc->sas_topology_mutex);
  2516. return;
  2517. }
  2518. for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev;
  2519. i++) {
  2520. if (parent->phy_info[i].attached.sas_address == sas_address) {
  2521. rphy = mptsas_get_rphy(&parent->phy_info[i]);
  2522. parent_dev = &rphy->dev;
  2523. }
  2524. }
  2525. mutex_unlock(&ioc->sas_topology_mutex);
  2526. mptsas_setup_wide_ports(ioc, port_info);
  2527. for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
  2528. mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i],
  2529. ioc->sas_index, 0);
  2530. }
  2531. static void
  2532. mptsas_expander_event_add(MPT_ADAPTER *ioc,
  2533. MpiEventDataSasExpanderStatusChange_t *expander_data)
  2534. {
  2535. struct mptsas_portinfo *port_info;
  2536. int i;
  2537. __le64 sas_address;
  2538. port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
  2539. if (!port_info)
  2540. BUG();
  2541. port_info->num_phys = (expander_data->NumPhys) ?
  2542. expander_data->NumPhys : 1;
  2543. port_info->phy_info = kcalloc(port_info->num_phys,
  2544. sizeof(struct mptsas_phyinfo), GFP_KERNEL);
  2545. if (!port_info->phy_info)
  2546. BUG();
  2547. memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
  2548. for (i = 0; i < port_info->num_phys; i++) {
  2549. port_info->phy_info[i].portinfo = port_info;
  2550. port_info->phy_info[i].handle =
  2551. le16_to_cpu(expander_data->DevHandle);
  2552. port_info->phy_info[i].identify.sas_address =
  2553. le64_to_cpu(sas_address);
  2554. port_info->phy_info[i].identify.handle_parent =
  2555. le16_to_cpu(expander_data->ParentDevHandle);
  2556. }
  2557. mutex_lock(&ioc->sas_topology_mutex);
  2558. list_add_tail(&port_info->list, &ioc->sas_topology);
  2559. mutex_unlock(&ioc->sas_topology_mutex);
  2560. printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
  2561. "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
  2562. (unsigned long long)sas_address);
  2563. mptsas_expander_refresh(ioc, port_info);
  2564. }
  2565. /**
  2566. * mptsas_delete_expander_siblings - remove siblings attached to expander
  2567. * @ioc: Pointer to MPT_ADAPTER structure
  2568. * @parent: the parent port_info object
  2569. * @expander: the expander port_info object
  2570. **/
  2571. static void
  2572. mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo
  2573. *parent, struct mptsas_portinfo *expander)
  2574. {
  2575. struct mptsas_phyinfo *phy_info;
  2576. struct mptsas_portinfo *port_info;
  2577. struct sas_rphy *rphy;
  2578. int i;
  2579. phy_info = expander->phy_info;
  2580. for (i = 0; i < expander->num_phys; i++, phy_info++) {
  2581. rphy = mptsas_get_rphy(phy_info);
  2582. if (!rphy)
  2583. continue;
  2584. if (rphy->identify.device_type == SAS_END_DEVICE)
  2585. mptsas_del_end_device(ioc, phy_info);
  2586. }
  2587. phy_info = expander->phy_info;
  2588. for (i = 0; i < expander->num_phys; i++, phy_info++) {
  2589. rphy = mptsas_get_rphy(phy_info);
  2590. if (!rphy)
  2591. continue;
  2592. if (rphy->identify.device_type ==
  2593. MPI_SAS_DEVICE_INFO_EDGE_EXPANDER ||
  2594. rphy->identify.device_type ==
  2595. MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
  2596. port_info = mptsas_find_portinfo_by_sas_address(ioc,
  2597. rphy->identify.sas_address);
  2598. if (!port_info)
  2599. continue;
  2600. if (port_info == parent) /* backlink rphy */
  2601. continue;
  2602. /*
  2603. Delete this expander even if the expdevpage is exists
  2604. because the parent expander is already deleted
  2605. */
  2606. mptsas_expander_delete(ioc, port_info, 1);
  2607. }
  2608. }
  2609. }
  2610. /**
  2611. * mptsas_expander_delete - remove this expander
  2612. * @ioc: Pointer to MPT_ADAPTER structure
  2613. * @port_info: expander port_info struct
  2614. * @force: Flag to forcefully delete the expander
  2615. *
  2616. **/
  2617. static void mptsas_expander_delete(MPT_ADAPTER *ioc,
  2618. struct mptsas_portinfo *port_info, u8 force)
  2619. {
  2620. struct mptsas_portinfo *parent;
  2621. int i;
  2622. u64 expander_sas_address;
  2623. struct mptsas_phyinfo *phy_info;
  2624. struct mptsas_portinfo buffer;
  2625. struct mptsas_portinfo_details *port_details;
  2626. struct sas_port *port;
  2627. if (!port_info)
  2628. return;
  2629. /* see if expander is still there before deleting */
  2630. mptsas_sas_expander_pg0(ioc, &buffer,
  2631. (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
  2632. MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
  2633. port_info->phy_info[0].identify.handle);
  2634. if (buffer.num_phys) {
  2635. kfree(buffer.phy_info);
  2636. if (!force)
  2637. return;
  2638. }
  2639. /*
  2640. * Obtain the port_info instance to the parent port
  2641. */
  2642. port_details = NULL;
  2643. expander_sas_address =
  2644. port_info->phy_info[0].identify.sas_address;
  2645. parent = mptsas_find_portinfo_by_handle(ioc,
  2646. port_info->phy_info[0].identify.handle_parent);
  2647. mptsas_delete_expander_siblings(ioc, parent, port_info);
  2648. if (!parent)
  2649. goto out;
  2650. /*
  2651. * Delete rphys in the parent that point
  2652. * to this expander.
  2653. */
  2654. phy_info = parent->phy_info;
  2655. port = NULL;
  2656. for (i = 0; i < parent->num_phys; i++, phy_info++) {
  2657. if (!phy_info->phy)
  2658. continue;
  2659. if (phy_info->attached.sas_address !=
  2660. expander_sas_address)
  2661. continue;
  2662. if (!port) {
  2663. port = mptsas_get_port(phy_info);
  2664. port_details = phy_info->port_details;
  2665. }
  2666. dev_printk(KERN_DEBUG, &phy_info->phy->dev,
  2667. MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
  2668. phy_info->phy_id, phy_info->phy);
  2669. sas_port_delete_phy(port, phy_info->phy);
  2670. }
  2671. if (port) {
  2672. dev_printk(KERN_DEBUG, &port->dev,
  2673. MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n",
  2674. ioc->name, port->port_identifier,
  2675. (unsigned long long)expander_sas_address);
  2676. sas_port_delete(port);
  2677. mptsas_port_delete(ioc, port_details);
  2678. }
  2679. out:
  2680. printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, "
  2681. "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
  2682. (unsigned long long)expander_sas_address);
  2683. /*
  2684. * free link
  2685. */
  2686. list_del(&port_info->list);
  2687. kfree(port_info->phy_info);
  2688. kfree(port_info);
  2689. }
  2690. /**
  2691. * mptsas_send_expander_event - expanders events
  2692. * @ioc: Pointer to MPT_ADAPTER structure
  2693. * @expander_data: event data
  2694. *
  2695. *
  2696. * This function handles adding, removing, and refreshing
  2697. * device handles within the expander objects.
  2698. */
  2699. static void
  2700. mptsas_send_expander_event(struct fw_event_work *fw_event)
  2701. {
  2702. MPT_ADAPTER *ioc;
  2703. MpiEventDataSasExpanderStatusChange_t *expander_data;
  2704. struct mptsas_portinfo *port_info;
  2705. __le64 sas_address;
  2706. int i;
  2707. ioc = fw_event->ioc;
  2708. expander_data = (MpiEventDataSasExpanderStatusChange_t *)
  2709. fw_event->event_data;
  2710. memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
  2711. port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
  2712. if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) {
  2713. if (port_info) {
  2714. for (i = 0; i < port_info->num_phys; i++) {
  2715. port_info->phy_info[i].portinfo = port_info;
  2716. port_info->phy_info[i].handle =
  2717. le16_to_cpu(expander_data->DevHandle);
  2718. port_info->phy_info[i].identify.sas_address =
  2719. le64_to_cpu(sas_address);
  2720. port_info->phy_info[i].identify.handle_parent =
  2721. le16_to_cpu(expander_data->ParentDevHandle);
  2722. }
  2723. mptsas_expander_refresh(ioc, port_info);
  2724. } else if (!port_info && expander_data->NumPhys)
  2725. mptsas_expander_event_add(ioc, expander_data);
  2726. } else if (expander_data->ReasonCode ==
  2727. MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING)
  2728. mptsas_expander_delete(ioc, port_info, 0);
  2729. mptsas_free_fw_event(ioc, fw_event);
  2730. }
  2731. /**
  2732. * mptsas_expander_add -
  2733. * @ioc: Pointer to MPT_ADAPTER structure
  2734. * @handle:
  2735. *
  2736. */
  2737. struct mptsas_portinfo *
  2738. mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle)
  2739. {
  2740. struct mptsas_portinfo buffer, *port_info;
  2741. int i;
  2742. if ((mptsas_sas_expander_pg0(ioc, &buffer,
  2743. (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
  2744. MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)))
  2745. return NULL;
  2746. port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC);
  2747. if (!port_info) {
  2748. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2749. "%s: exit at line=%d\n", ioc->name,
  2750. __func__, __LINE__));
  2751. return NULL;
  2752. }
  2753. port_info->num_phys = buffer.num_phys;
  2754. port_info->phy_info = buffer.phy_info;
  2755. for (i = 0; i < port_info->num_phys; i++)
  2756. port_info->phy_info[i].portinfo = port_info;
  2757. mutex_lock(&ioc->sas_topology_mutex);
  2758. list_add_tail(&port_info->list, &ioc->sas_topology);
  2759. mutex_unlock(&ioc->sas_topology_mutex);
  2760. printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
  2761. "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
  2762. (unsigned long long)buffer.phy_info[0].identify.sas_address);
  2763. mptsas_expander_refresh(ioc, port_info);
  2764. return port_info;
  2765. }
  2766. static void
  2767. mptsas_send_link_status_event(struct fw_event_work *fw_event)
  2768. {
  2769. MPT_ADAPTER *ioc;
  2770. MpiEventDataSasPhyLinkStatus_t *link_data;
  2771. struct mptsas_portinfo *port_info;
  2772. struct mptsas_phyinfo *phy_info = NULL;
  2773. __le64 sas_address;
  2774. u8 phy_num;
  2775. u8 link_rate;
  2776. ioc = fw_event->ioc;
  2777. link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data;
  2778. memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64));
  2779. sas_address = le64_to_cpu(sas_address);
  2780. link_rate = link_data->LinkRates >> 4;
  2781. phy_num = link_data->PhyNum;
  2782. port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
  2783. if (port_info) {
  2784. phy_info = &port_info->phy_info[phy_num];
  2785. if (phy_info)
  2786. phy_info->negotiated_link_rate = link_rate;
  2787. }
  2788. if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 ||
  2789. link_rate == MPI_SAS_IOUNIT0_RATE_3_0) {
  2790. if (!port_info) {
  2791. if (ioc->old_sas_discovery_protocal) {
  2792. port_info = mptsas_expander_add(ioc,
  2793. le16_to_cpu(link_data->DevHandle));
  2794. if (port_info)
  2795. goto out;
  2796. }
  2797. goto out;
  2798. }
  2799. if (port_info == ioc->hba_port_info)
  2800. mptsas_probe_hba_phys(ioc);
  2801. else
  2802. mptsas_expander_refresh(ioc, port_info);
  2803. } else if (phy_info && phy_info->phy) {
  2804. if (link_rate == MPI_SAS_IOUNIT0_RATE_PHY_DISABLED)
  2805. phy_info->phy->negotiated_linkrate =
  2806. SAS_PHY_DISABLED;
  2807. else if (link_rate ==
  2808. MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION)
  2809. phy_info->phy->negotiated_linkrate =
  2810. SAS_LINK_RATE_FAILED;
  2811. else
  2812. phy_info->phy->negotiated_linkrate =
  2813. SAS_LINK_RATE_UNKNOWN;
  2814. }
  2815. out:
  2816. mptsas_free_fw_event(ioc, fw_event);
  2817. }
  2818. static void
  2819. mptsas_not_responding_devices(MPT_ADAPTER *ioc)
  2820. {
  2821. struct mptsas_portinfo buffer, *port_info;
  2822. struct mptsas_device_info *sas_info;
  2823. struct mptsas_devinfo sas_device;
  2824. u32 handle;
  2825. VirtTarget *vtarget = NULL;
  2826. struct mptsas_phyinfo *phy_info;
  2827. u8 found_expander;
  2828. int retval, retry_count;
  2829. unsigned long flags;
  2830. mpt_findImVolumes(ioc);
  2831. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  2832. if (ioc->ioc_reset_in_progress) {
  2833. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2834. "%s: exiting due to a parallel reset \n", ioc->name,
  2835. __func__));
  2836. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  2837. return;
  2838. }
  2839. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  2840. /* devices, logical volumes */
  2841. mutex_lock(&ioc->sas_device_info_mutex);
  2842. redo_device_scan:
  2843. list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) {
  2844. sas_device.handle = 0;
  2845. retry_count = 0;
  2846. retry_page:
  2847. retval = mptsas_sas_device_pg0(ioc, &sas_device,
  2848. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID
  2849. << MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  2850. (sas_info->fw.channel << 8) +
  2851. sas_info->fw.id);
  2852. if (sas_device.handle)
  2853. continue;
  2854. if (retval == -EBUSY) {
  2855. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  2856. if (ioc->ioc_reset_in_progress) {
  2857. dfailprintk(ioc,
  2858. printk(MYIOC_s_DEBUG_FMT
  2859. "%s: exiting due to reset\n",
  2860. ioc->name, __func__));
  2861. spin_unlock_irqrestore
  2862. (&ioc->taskmgmt_lock, flags);
  2863. mutex_unlock(&ioc->sas_device_info_mutex);
  2864. return;
  2865. }
  2866. spin_unlock_irqrestore(&ioc->taskmgmt_lock,
  2867. flags);
  2868. }
  2869. if (retval && (retval != -ENODEV)) {
  2870. if (retry_count < 10) {
  2871. retry_count++;
  2872. goto retry_page;
  2873. } else {
  2874. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2875. "%s: Config page retry exceeded retry "
  2876. "count deleting device 0x%llx\n",
  2877. ioc->name, __func__,
  2878. sas_info->sas_address));
  2879. }
  2880. }
  2881. /* delete device */
  2882. vtarget = mptsas_find_vtarget(ioc,
  2883. sas_info->fw.channel, sas_info->fw.id);
  2884. if (vtarget)
  2885. vtarget->deleted = 1;
  2886. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  2887. sas_info->sas_address);
  2888. if (phy_info) {
  2889. mptsas_del_end_device(ioc, phy_info);
  2890. goto redo_device_scan;
  2891. }
  2892. }
  2893. mutex_unlock(&ioc->sas_device_info_mutex);
  2894. /* expanders */
  2895. mutex_lock(&ioc->sas_topology_mutex);
  2896. redo_expander_scan:
  2897. list_for_each_entry(port_info, &ioc->sas_topology, list) {
  2898. if (port_info->phy_info &&
  2899. (!(port_info->phy_info[0].identify.device_info &
  2900. MPI_SAS_DEVICE_INFO_SMP_TARGET)))
  2901. continue;
  2902. found_expander = 0;
  2903. handle = 0xFFFF;
  2904. while (!mptsas_sas_expander_pg0(ioc, &buffer,
  2905. (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
  2906. MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) &&
  2907. !found_expander) {
  2908. handle = buffer.phy_info[0].handle;
  2909. if (buffer.phy_info[0].identify.sas_address ==
  2910. port_info->phy_info[0].identify.sas_address) {
  2911. found_expander = 1;
  2912. }
  2913. kfree(buffer.phy_info);
  2914. }
  2915. if (!found_expander) {
  2916. mptsas_expander_delete(ioc, port_info, 0);
  2917. goto redo_expander_scan;
  2918. }
  2919. }
  2920. mutex_lock(&ioc->sas_topology_mutex);
  2921. }
  2922. /**
  2923. * mptsas_probe_expanders - adding expanders
  2924. * @ioc: Pointer to MPT_ADAPTER structure
  2925. *
  2926. **/
  2927. static void
  2928. mptsas_probe_expanders(MPT_ADAPTER *ioc)
  2929. {
  2930. struct mptsas_portinfo buffer, *port_info;
  2931. u32 handle;
  2932. int i;
  2933. handle = 0xFFFF;
  2934. while (!mptsas_sas_expander_pg0(ioc, &buffer,
  2935. (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
  2936. MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) {
  2937. handle = buffer.phy_info[0].handle;
  2938. port_info = mptsas_find_portinfo_by_sas_address(ioc,
  2939. buffer.phy_info[0].identify.sas_address);
  2940. if (port_info) {
  2941. /* refreshing handles */
  2942. for (i = 0; i < buffer.num_phys; i++) {
  2943. port_info->phy_info[i].handle = handle;
  2944. port_info->phy_info[i].identify.handle_parent =
  2945. buffer.phy_info[0].identify.handle_parent;
  2946. }
  2947. mptsas_expander_refresh(ioc, port_info);
  2948. kfree(buffer.phy_info);
  2949. continue;
  2950. }
  2951. port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
  2952. if (!port_info) {
  2953. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2954. "%s: exit at line=%d\n", ioc->name,
  2955. __func__, __LINE__));
  2956. return;
  2957. }
  2958. port_info->num_phys = buffer.num_phys;
  2959. port_info->phy_info = buffer.phy_info;
  2960. for (i = 0; i < port_info->num_phys; i++)
  2961. port_info->phy_info[i].portinfo = port_info;
  2962. mutex_lock(&ioc->sas_topology_mutex);
  2963. list_add_tail(&port_info->list, &ioc->sas_topology);
  2964. mutex_unlock(&ioc->sas_topology_mutex);
  2965. printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
  2966. "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
  2967. (unsigned long long)buffer.phy_info[0].identify.sas_address);
  2968. mptsas_expander_refresh(ioc, port_info);
  2969. }
  2970. }
  2971. static void
  2972. mptsas_probe_devices(MPT_ADAPTER *ioc)
  2973. {
  2974. u16 handle;
  2975. struct mptsas_devinfo sas_device;
  2976. struct mptsas_phyinfo *phy_info;
  2977. handle = 0xFFFF;
  2978. while (!(mptsas_sas_device_pg0(ioc, &sas_device,
  2979. MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  2980. handle = sas_device.handle;
  2981. if ((sas_device.device_info &
  2982. (MPI_SAS_DEVICE_INFO_SSP_TARGET |
  2983. MPI_SAS_DEVICE_INFO_STP_TARGET |
  2984. MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0)
  2985. continue;
  2986. phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
  2987. if (!phy_info)
  2988. continue;
  2989. if (mptsas_get_rphy(phy_info))
  2990. continue;
  2991. mptsas_add_end_device(ioc, phy_info);
  2992. }
  2993. }
  2994. /*
  2995. * Start of day discovery
  2996. */
  2997. static void
  2998. mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
  2999. {
  3000. struct scsi_device *sdev;
  3001. int i;
  3002. mptsas_probe_hba_phys(ioc);
  3003. mptsas_probe_expanders(ioc);
  3004. mptsas_probe_devices(ioc);
  3005. /*
  3006. Reporting RAID volumes.
  3007. */
  3008. if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
  3009. !ioc->raid_data.pIocPg2->NumActiveVolumes)
  3010. return;
  3011. for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
  3012. sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
  3013. ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
  3014. if (sdev) {
  3015. scsi_device_put(sdev);
  3016. continue;
  3017. }
  3018. printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
  3019. "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
  3020. ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID);
  3021. scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
  3022. ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
  3023. }
  3024. }
  3025. static struct mptsas_phyinfo *
  3026. mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
  3027. {
  3028. struct mptsas_portinfo *port_info;
  3029. struct mptsas_phyinfo *phy_info = NULL;
  3030. int i;
  3031. mutex_lock(&ioc->sas_topology_mutex);
  3032. list_for_each_entry(port_info, &ioc->sas_topology, list) {
  3033. for (i = 0; i < port_info->num_phys; i++) {
  3034. if (!mptsas_is_end_device(
  3035. &port_info->phy_info[i].attached))
  3036. continue;
  3037. if (port_info->phy_info[i].attached.sas_address
  3038. != sas_address)
  3039. continue;
  3040. phy_info = &port_info->phy_info[i];
  3041. break;
  3042. }
  3043. }
  3044. mutex_unlock(&ioc->sas_topology_mutex);
  3045. return phy_info;
  3046. }
  3047. static struct mptsas_phyinfo *
  3048. mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
  3049. {
  3050. struct mptsas_portinfo *port_info;
  3051. struct mptsas_phyinfo *phy_info = NULL;
  3052. int i;
  3053. mutex_lock(&ioc->sas_topology_mutex);
  3054. list_for_each_entry(port_info, &ioc->sas_topology, list) {
  3055. for (i = 0; i < port_info->num_phys; i++) {
  3056. if (!mptsas_is_end_device(
  3057. &port_info->phy_info[i].attached))
  3058. continue;
  3059. if (port_info->phy_info[i].attached.phys_disk_num == ~0)
  3060. continue;
  3061. if (port_info->phy_info[i].attached.phys_disk_num != id)
  3062. continue;
  3063. if (port_info->phy_info[i].attached.channel != channel)
  3064. continue;
  3065. phy_info = &port_info->phy_info[i];
  3066. break;
  3067. }
  3068. }
  3069. mutex_unlock(&ioc->sas_topology_mutex);
  3070. return phy_info;
  3071. }
  3072. static void
  3073. mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
  3074. {
  3075. int rc;
  3076. sdev->no_uld_attach = data ? 1 : 0;
  3077. rc = scsi_device_reprobe(sdev);
  3078. }
  3079. static void
  3080. mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
  3081. {
  3082. starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
  3083. mptsas_reprobe_lun);
  3084. }
  3085. static void
  3086. mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
  3087. {
  3088. CONFIGPARMS cfg;
  3089. ConfigPageHeader_t hdr;
  3090. dma_addr_t dma_handle;
  3091. pRaidVolumePage0_t buffer = NULL;
  3092. RaidPhysDiskPage0_t phys_disk;
  3093. int i;
  3094. struct mptsas_phyinfo *phy_info;
  3095. struct mptsas_devinfo sas_device;
  3096. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  3097. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  3098. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
  3099. cfg.pageAddr = (channel << 8) + id;
  3100. cfg.cfghdr.hdr = &hdr;
  3101. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3102. if (mpt_config(ioc, &cfg) != 0)
  3103. goto out;
  3104. if (!hdr.PageLength)
  3105. goto out;
  3106. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  3107. &dma_handle);
  3108. if (!buffer)
  3109. goto out;
  3110. cfg.physAddr = dma_handle;
  3111. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3112. if (mpt_config(ioc, &cfg) != 0)
  3113. goto out;
  3114. if (!(buffer->VolumeStatus.Flags &
  3115. MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
  3116. goto out;
  3117. if (!buffer->NumPhysDisks)
  3118. goto out;
  3119. for (i = 0; i < buffer->NumPhysDisks; i++) {
  3120. if (mpt_raid_phys_disk_pg0(ioc,
  3121. buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
  3122. continue;
  3123. if (mptsas_sas_device_pg0(ioc, &sas_device,
  3124. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
  3125. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  3126. (phys_disk.PhysDiskBus << 8) +
  3127. phys_disk.PhysDiskID))
  3128. continue;
  3129. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  3130. sas_device.sas_address);
  3131. mptsas_add_end_device(ioc, phy_info);
  3132. }
  3133. out:
  3134. if (buffer)
  3135. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  3136. dma_handle);
  3137. }
  3138. /*
  3139. * Work queue thread to handle SAS hotplug events
  3140. */
  3141. static void
  3142. mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
  3143. struct mptsas_hotplug_event *hot_plug_info)
  3144. {
  3145. struct mptsas_phyinfo *phy_info;
  3146. struct scsi_target * starget;
  3147. struct mptsas_devinfo sas_device;
  3148. VirtTarget *vtarget;
  3149. int i;
  3150. switch (hot_plug_info->event_type) {
  3151. case MPTSAS_ADD_PHYSDISK:
  3152. if (!ioc->raid_data.pIocPg2)
  3153. break;
  3154. for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
  3155. if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
  3156. hot_plug_info->id) {
  3157. printk(MYIOC_s_WARN_FMT "firmware bug: unable "
  3158. "to add hidden disk - target_id matchs "
  3159. "volume_id\n", ioc->name);
  3160. mptsas_free_fw_event(ioc, fw_event);
  3161. return;
  3162. }
  3163. }
  3164. mpt_findImVolumes(ioc);
  3165. case MPTSAS_ADD_DEVICE:
  3166. memset(&sas_device, 0, sizeof(struct mptsas_devinfo));
  3167. mptsas_sas_device_pg0(ioc, &sas_device,
  3168. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
  3169. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  3170. (hot_plug_info->channel << 8) +
  3171. hot_plug_info->id);
  3172. if (!sas_device.handle)
  3173. return;
  3174. phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
  3175. if (!phy_info)
  3176. break;
  3177. if (mptsas_get_rphy(phy_info))
  3178. break;
  3179. mptsas_add_end_device(ioc, phy_info);
  3180. break;
  3181. case MPTSAS_DEL_DEVICE:
  3182. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  3183. hot_plug_info->sas_address);
  3184. mptsas_del_end_device(ioc, phy_info);
  3185. break;
  3186. case MPTSAS_DEL_PHYSDISK:
  3187. mpt_findImVolumes(ioc);
  3188. phy_info = mptsas_find_phyinfo_by_phys_disk_num(
  3189. ioc, hot_plug_info->channel,
  3190. hot_plug_info->phys_disk_num);
  3191. mptsas_del_end_device(ioc, phy_info);
  3192. break;
  3193. case MPTSAS_ADD_PHYSDISK_REPROBE:
  3194. if (mptsas_sas_device_pg0(ioc, &sas_device,
  3195. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
  3196. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  3197. (hot_plug_info->channel << 8) + hot_plug_info->id)) {
  3198. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3199. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  3200. __func__, hot_plug_info->id, __LINE__));
  3201. break;
  3202. }
  3203. phy_info = mptsas_find_phyinfo_by_sas_address(
  3204. ioc, sas_device.sas_address);
  3205. if (!phy_info) {
  3206. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3207. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  3208. __func__, hot_plug_info->id, __LINE__));
  3209. break;
  3210. }
  3211. starget = mptsas_get_starget(phy_info);
  3212. if (!starget) {
  3213. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3214. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  3215. __func__, hot_plug_info->id, __LINE__));
  3216. break;
  3217. }
  3218. vtarget = starget->hostdata;
  3219. if (!vtarget) {
  3220. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3221. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  3222. __func__, hot_plug_info->id, __LINE__));
  3223. break;
  3224. }
  3225. mpt_findImVolumes(ioc);
  3226. starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: "
  3227. "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
  3228. ioc->name, hot_plug_info->channel, hot_plug_info->id,
  3229. hot_plug_info->phys_disk_num, (unsigned long long)
  3230. sas_device.sas_address);
  3231. vtarget->id = hot_plug_info->phys_disk_num;
  3232. vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
  3233. phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num;
  3234. mptsas_reprobe_target(starget, 1);
  3235. break;
  3236. case MPTSAS_DEL_PHYSDISK_REPROBE:
  3237. if (mptsas_sas_device_pg0(ioc, &sas_device,
  3238. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
  3239. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  3240. (hot_plug_info->channel << 8) + hot_plug_info->id)) {
  3241. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3242. "%s: fw_id=%d exit at line=%d\n",
  3243. ioc->name, __func__,
  3244. hot_plug_info->id, __LINE__));
  3245. break;
  3246. }
  3247. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  3248. sas_device.sas_address);
  3249. if (!phy_info) {
  3250. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3251. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  3252. __func__, hot_plug_info->id, __LINE__));
  3253. break;
  3254. }
  3255. starget = mptsas_get_starget(phy_info);
  3256. if (!starget) {
  3257. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3258. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  3259. __func__, hot_plug_info->id, __LINE__));
  3260. break;
  3261. }
  3262. vtarget = starget->hostdata;
  3263. if (!vtarget) {
  3264. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3265. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  3266. __func__, hot_plug_info->id, __LINE__));
  3267. break;
  3268. }
  3269. if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) {
  3270. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  3271. "%s: fw_id=%d exit at line=%d\n", ioc->name,
  3272. __func__, hot_plug_info->id, __LINE__));
  3273. break;
  3274. }
  3275. mpt_findImVolumes(ioc);
  3276. starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:"
  3277. " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
  3278. ioc->name, hot_plug_info->channel, hot_plug_info->id,
  3279. hot_plug_info->phys_disk_num, (unsigned long long)
  3280. sas_device.sas_address);
  3281. vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
  3282. vtarget->id = hot_plug_info->id;
  3283. phy_info->attached.phys_disk_num = ~0;
  3284. mptsas_reprobe_target(starget, 0);
  3285. mptsas_add_device_component_by_fw(ioc,
  3286. hot_plug_info->channel, hot_plug_info->id);
  3287. break;
  3288. case MPTSAS_ADD_RAID:
  3289. mpt_findImVolumes(ioc);
  3290. printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
  3291. "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
  3292. hot_plug_info->id);
  3293. scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
  3294. hot_plug_info->id, 0);
  3295. break;
  3296. case MPTSAS_DEL_RAID:
  3297. mpt_findImVolumes(ioc);
  3298. printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
  3299. "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
  3300. hot_plug_info->id);
  3301. scsi_remove_device(hot_plug_info->sdev);
  3302. scsi_device_put(hot_plug_info->sdev);
  3303. break;
  3304. case MPTSAS_ADD_INACTIVE_VOLUME:
  3305. mpt_findImVolumes(ioc);
  3306. mptsas_adding_inactive_raid_components(ioc,
  3307. hot_plug_info->channel, hot_plug_info->id);
  3308. break;
  3309. default:
  3310. break;
  3311. }
  3312. mptsas_free_fw_event(ioc, fw_event);
  3313. }
  3314. static void
  3315. mptsas_send_sas_event(struct fw_event_work *fw_event)
  3316. {
  3317. MPT_ADAPTER *ioc;
  3318. struct mptsas_hotplug_event hot_plug_info;
  3319. EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
  3320. u32 device_info;
  3321. u64 sas_address;
  3322. ioc = fw_event->ioc;
  3323. sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
  3324. fw_event->event_data;
  3325. device_info = le32_to_cpu(sas_event_data->DeviceInfo);
  3326. if ((device_info &
  3327. (MPI_SAS_DEVICE_INFO_SSP_TARGET |
  3328. MPI_SAS_DEVICE_INFO_STP_TARGET |
  3329. MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) {
  3330. mptsas_free_fw_event(ioc, fw_event);
  3331. return;
  3332. }
  3333. if (sas_event_data->ReasonCode ==
  3334. MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) {
  3335. mptbase_sas_persist_operation(ioc,
  3336. MPI_SAS_OP_CLEAR_NOT_PRESENT);
  3337. mptsas_free_fw_event(ioc, fw_event);
  3338. return;
  3339. }
  3340. switch (sas_event_data->ReasonCode) {
  3341. case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
  3342. case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
  3343. memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
  3344. hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle);
  3345. hot_plug_info.channel = sas_event_data->Bus;
  3346. hot_plug_info.id = sas_event_data->TargetID;
  3347. hot_plug_info.phy_id = sas_event_data->PhyNum;
  3348. memcpy(&sas_address, &sas_event_data->SASAddress,
  3349. sizeof(u64));
  3350. hot_plug_info.sas_address = le64_to_cpu(sas_address);
  3351. hot_plug_info.device_info = device_info;
  3352. if (sas_event_data->ReasonCode &
  3353. MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
  3354. hot_plug_info.event_type = MPTSAS_ADD_DEVICE;
  3355. else
  3356. hot_plug_info.event_type = MPTSAS_DEL_DEVICE;
  3357. mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
  3358. break;
  3359. case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
  3360. mptbase_sas_persist_operation(ioc,
  3361. MPI_SAS_OP_CLEAR_NOT_PRESENT);
  3362. mptsas_free_fw_event(ioc, fw_event);
  3363. break;
  3364. case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  3365. /* TODO */
  3366. case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  3367. /* TODO */
  3368. default:
  3369. mptsas_free_fw_event(ioc, fw_event);
  3370. break;
  3371. }
  3372. }
  3373. static void
  3374. mptsas_send_raid_event(struct fw_event_work *fw_event)
  3375. {
  3376. MPT_ADAPTER *ioc;
  3377. EVENT_DATA_RAID *raid_event_data;
  3378. struct mptsas_hotplug_event hot_plug_info;
  3379. int status;
  3380. int state;
  3381. struct scsi_device *sdev = NULL;
  3382. VirtDevice *vdevice = NULL;
  3383. RaidPhysDiskPage0_t phys_disk;
  3384. ioc = fw_event->ioc;
  3385. raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data;
  3386. status = le32_to_cpu(raid_event_data->SettingsStatus);
  3387. state = (status >> 8) & 0xff;
  3388. memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
  3389. hot_plug_info.id = raid_event_data->VolumeID;
  3390. hot_plug_info.channel = raid_event_data->VolumeBus;
  3391. hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum;
  3392. if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED ||
  3393. raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED ||
  3394. raid_event_data->ReasonCode ==
  3395. MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) {
  3396. sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
  3397. hot_plug_info.id, 0);
  3398. hot_plug_info.sdev = sdev;
  3399. if (sdev)
  3400. vdevice = sdev->hostdata;
  3401. }
  3402. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
  3403. "ReasonCode=%02x\n", ioc->name, __func__,
  3404. raid_event_data->ReasonCode));
  3405. switch (raid_event_data->ReasonCode) {
  3406. case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
  3407. hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE;
  3408. break;
  3409. case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
  3410. hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE;
  3411. break;
  3412. case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
  3413. switch (state) {
  3414. case MPI_PD_STATE_ONLINE:
  3415. case MPI_PD_STATE_NOT_COMPATIBLE:
  3416. mpt_raid_phys_disk_pg0(ioc,
  3417. raid_event_data->PhysDiskNum, &phys_disk);
  3418. hot_plug_info.id = phys_disk.PhysDiskID;
  3419. hot_plug_info.channel = phys_disk.PhysDiskBus;
  3420. hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
  3421. break;
  3422. case MPI_PD_STATE_FAILED:
  3423. case MPI_PD_STATE_MISSING:
  3424. case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
  3425. case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
  3426. case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
  3427. hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
  3428. break;
  3429. default:
  3430. break;
  3431. }
  3432. break;
  3433. case MPI_EVENT_RAID_RC_VOLUME_DELETED:
  3434. if (!sdev)
  3435. break;
  3436. vdevice->vtarget->deleted = 1; /* block IO */
  3437. hot_plug_info.event_type = MPTSAS_DEL_RAID;
  3438. break;
  3439. case MPI_EVENT_RAID_RC_VOLUME_CREATED:
  3440. if (sdev) {
  3441. scsi_device_put(sdev);
  3442. break;
  3443. }
  3444. hot_plug_info.event_type = MPTSAS_ADD_RAID;
  3445. break;
  3446. case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
  3447. if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) {
  3448. if (!sdev)
  3449. break;
  3450. vdevice->vtarget->deleted = 1; /* block IO */
  3451. hot_plug_info.event_type = MPTSAS_DEL_RAID;
  3452. break;
  3453. }
  3454. switch (state) {
  3455. case MPI_RAIDVOL0_STATUS_STATE_FAILED:
  3456. case MPI_RAIDVOL0_STATUS_STATE_MISSING:
  3457. if (!sdev)
  3458. break;
  3459. vdevice->vtarget->deleted = 1; /* block IO */
  3460. hot_plug_info.event_type = MPTSAS_DEL_RAID;
  3461. break;
  3462. case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
  3463. case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
  3464. if (sdev) {
  3465. scsi_device_put(sdev);
  3466. break;
  3467. }
  3468. hot_plug_info.event_type = MPTSAS_ADD_RAID;
  3469. break;
  3470. default:
  3471. break;
  3472. }
  3473. break;
  3474. default:
  3475. break;
  3476. }
  3477. if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT)
  3478. mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
  3479. else
  3480. mptsas_free_fw_event(ioc, fw_event);
  3481. }
  3482. /*
  3483. * mptsas_send_ir2_event - handle exposing hidden disk when
  3484. * an inactive raid volume is added
  3485. *
  3486. * @ioc: Pointer to MPT_ADAPTER structure
  3487. * @ir2_data
  3488. *
  3489. */
  3490. static void
  3491. mptsas_send_ir2_event(struct fw_event_work *fw_event)
  3492. {
  3493. MPT_ADAPTER *ioc;
  3494. struct mptsas_hotplug_event hot_plug_info;
  3495. MPI_EVENT_DATA_IR2 *ir2_data;
  3496. u8 reasonCode;
  3497. ioc = fw_event->ioc;
  3498. ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data;
  3499. reasonCode = ir2_data->ReasonCode;
  3500. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
  3501. "ReasonCode=%02x\n", ioc->name, __func__, reasonCode));
  3502. memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
  3503. hot_plug_info.id = ir2_data->TargetID;
  3504. hot_plug_info.channel = ir2_data->Bus;
  3505. switch (reasonCode) {
  3506. case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
  3507. hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME;
  3508. break;
  3509. default:
  3510. mptsas_free_fw_event(ioc, fw_event);
  3511. return;
  3512. }
  3513. mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
  3514. }
  3515. static int
  3516. mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
  3517. {
  3518. u32 event = le32_to_cpu(reply->Event);
  3519. int sz, event_data_sz;
  3520. struct fw_event_work *fw_event;
  3521. unsigned long delay;
  3522. /* events turned off due to host reset or driver unloading */
  3523. if (ioc->fw_events_off)
  3524. return 0;
  3525. delay = msecs_to_jiffies(1);
  3526. switch (event) {
  3527. case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
  3528. {
  3529. EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data =
  3530. (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data;
  3531. if (sas_event_data->ReasonCode ==
  3532. MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) {
  3533. mptsas_target_reset_queue(ioc, sas_event_data);
  3534. return 0;
  3535. }
  3536. break;
  3537. }
  3538. case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
  3539. {
  3540. MpiEventDataSasExpanderStatusChange_t *expander_data =
  3541. (MpiEventDataSasExpanderStatusChange_t *)reply->Data;
  3542. if (ioc->old_sas_discovery_protocal)
  3543. return 0;
  3544. if (expander_data->ReasonCode ==
  3545. MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING &&
  3546. ioc->device_missing_delay)
  3547. delay = HZ * ioc->device_missing_delay;
  3548. break;
  3549. }
  3550. case MPI_EVENT_SAS_DISCOVERY:
  3551. {
  3552. u32 discovery_status;
  3553. EventDataSasDiscovery_t *discovery_data =
  3554. (EventDataSasDiscovery_t *)reply->Data;
  3555. discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
  3556. ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
  3557. if (ioc->old_sas_discovery_protocal && !discovery_status)
  3558. mptsas_queue_rescan(ioc);
  3559. return 0;
  3560. }
  3561. case MPI_EVENT_INTEGRATED_RAID:
  3562. case MPI_EVENT_PERSISTENT_TABLE_FULL:
  3563. case MPI_EVENT_IR2:
  3564. case MPI_EVENT_SAS_PHY_LINK_STATUS:
  3565. case MPI_EVENT_QUEUE_FULL:
  3566. break;
  3567. default:
  3568. return 0;
  3569. }
  3570. event_data_sz = ((reply->MsgLength * 4) -
  3571. offsetof(EventNotificationReply_t, Data));
  3572. sz = offsetof(struct fw_event_work, event_data) + event_data_sz;
  3573. fw_event = kzalloc(sz, GFP_ATOMIC);
  3574. if (!fw_event) {
  3575. printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name,
  3576. __func__, __LINE__);
  3577. return 0;
  3578. }
  3579. memcpy(fw_event->event_data, reply->Data, event_data_sz);
  3580. fw_event->event = event;
  3581. fw_event->ioc = ioc;
  3582. mptsas_add_fw_event(ioc, fw_event, delay);
  3583. return 0;
  3584. }
  3585. static int
  3586. mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  3587. {
  3588. struct Scsi_Host *sh;
  3589. MPT_SCSI_HOST *hd;
  3590. MPT_ADAPTER *ioc;
  3591. unsigned long flags;
  3592. int ii;
  3593. int numSGE = 0;
  3594. int scale;
  3595. int ioc_cap;
  3596. int error=0;
  3597. int r;
  3598. r = mpt_attach(pdev,id);
  3599. if (r)
  3600. return r;
  3601. ioc = pci_get_drvdata(pdev);
  3602. mptsas_fw_event_off(ioc);
  3603. ioc->DoneCtx = mptsasDoneCtx;
  3604. ioc->TaskCtx = mptsasTaskCtx;
  3605. ioc->InternalCtx = mptsasInternalCtx;
  3606. /* Added sanity check on readiness of the MPT adapter.
  3607. */
  3608. if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
  3609. printk(MYIOC_s_WARN_FMT
  3610. "Skipping because it's not operational!\n",
  3611. ioc->name);
  3612. error = -ENODEV;
  3613. goto out_mptsas_probe;
  3614. }
  3615. if (!ioc->active) {
  3616. printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
  3617. ioc->name);
  3618. error = -ENODEV;
  3619. goto out_mptsas_probe;
  3620. }
  3621. /* Sanity check - ensure at least 1 port is INITIATOR capable
  3622. */
  3623. ioc_cap = 0;
  3624. for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
  3625. if (ioc->pfacts[ii].ProtocolFlags &
  3626. MPI_PORTFACTS_PROTOCOL_INITIATOR)
  3627. ioc_cap++;
  3628. }
  3629. if (!ioc_cap) {
  3630. printk(MYIOC_s_WARN_FMT
  3631. "Skipping ioc=%p because SCSI Initiator mode "
  3632. "is NOT enabled!\n", ioc->name, ioc);
  3633. return 0;
  3634. }
  3635. sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
  3636. if (!sh) {
  3637. printk(MYIOC_s_WARN_FMT
  3638. "Unable to register controller with SCSI subsystem\n",
  3639. ioc->name);
  3640. error = -1;
  3641. goto out_mptsas_probe;
  3642. }
  3643. spin_lock_irqsave(&ioc->FreeQlock, flags);
  3644. /* Attach the SCSI Host to the IOC structure
  3645. */
  3646. ioc->sh = sh;
  3647. sh->io_port = 0;
  3648. sh->n_io_port = 0;
  3649. sh->irq = 0;
  3650. /* set 16 byte cdb's */
  3651. sh->max_cmd_len = 16;
  3652. sh->max_id = ioc->pfacts[0].PortSCSIID;
  3653. sh->max_lun = max_lun;
  3654. sh->transportt = mptsas_transport_template;
  3655. /* Required entry.
  3656. */
  3657. sh->unique_id = ioc->id;
  3658. INIT_LIST_HEAD(&ioc->sas_topology);
  3659. mutex_init(&ioc->sas_topology_mutex);
  3660. mutex_init(&ioc->sas_discovery_mutex);
  3661. mutex_init(&ioc->sas_mgmt.mutex);
  3662. init_completion(&ioc->sas_mgmt.done);
  3663. /* Verify that we won't exceed the maximum
  3664. * number of chain buffers
  3665. * We can optimize: ZZ = req_sz/sizeof(SGE)
  3666. * For 32bit SGE's:
  3667. * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
  3668. * + (req_sz - 64)/sizeof(SGE)
  3669. * A slightly different algorithm is required for
  3670. * 64bit SGEs.
  3671. */
  3672. scale = ioc->req_sz/ioc->SGE_size;
  3673. if (ioc->sg_addr_size == sizeof(u64)) {
  3674. numSGE = (scale - 1) *
  3675. (ioc->facts.MaxChainDepth-1) + scale +
  3676. (ioc->req_sz - 60) / ioc->SGE_size;
  3677. } else {
  3678. numSGE = 1 + (scale - 1) *
  3679. (ioc->facts.MaxChainDepth-1) + scale +
  3680. (ioc->req_sz - 64) / ioc->SGE_size;
  3681. }
  3682. if (numSGE < sh->sg_tablesize) {
  3683. /* Reset this value */
  3684. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3685. "Resetting sg_tablesize to %d from %d\n",
  3686. ioc->name, numSGE, sh->sg_tablesize));
  3687. sh->sg_tablesize = numSGE;
  3688. }
  3689. hd = shost_priv(sh);
  3690. hd->ioc = ioc;
  3691. /* SCSI needs scsi_cmnd lookup table!
  3692. * (with size equal to req_depth*PtrSz!)
  3693. */
  3694. ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
  3695. if (!ioc->ScsiLookup) {
  3696. error = -ENOMEM;
  3697. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  3698. goto out_mptsas_probe;
  3699. }
  3700. spin_lock_init(&ioc->scsi_lookup_lock);
  3701. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
  3702. ioc->name, ioc->ScsiLookup));
  3703. /* Clear the TM flags
  3704. */
  3705. hd->abortSCpnt = NULL;
  3706. /* Clear the pointer used to store
  3707. * single-threaded commands, i.e., those
  3708. * issued during a bus scan, dv and
  3709. * configuration pages.
  3710. */
  3711. hd->cmdPtr = NULL;
  3712. /* Initialize this SCSI Hosts' timers
  3713. * To use, set the timer expires field
  3714. * and add_timer
  3715. */
  3716. init_timer(&hd->timer);
  3717. hd->timer.data = (unsigned long) hd;
  3718. hd->timer.function = mptscsih_timer_expired;
  3719. ioc->sas_data.ptClear = mpt_pt_clear;
  3720. hd->last_queue_full = 0;
  3721. INIT_LIST_HEAD(&hd->target_reset_list);
  3722. INIT_LIST_HEAD(&ioc->sas_device_info_list);
  3723. mutex_init(&ioc->sas_device_info_mutex);
  3724. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  3725. if (ioc->sas_data.ptClear==1) {
  3726. mptbase_sas_persist_operation(
  3727. ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
  3728. }
  3729. error = scsi_add_host(sh, &ioc->pcidev->dev);
  3730. if (error) {
  3731. dprintk(ioc, printk(MYIOC_s_ERR_FMT
  3732. "scsi_add_host failed\n", ioc->name));
  3733. goto out_mptsas_probe;
  3734. }
  3735. /* older firmware doesn't support expander events */
  3736. if ((ioc->facts.HeaderVersion >> 8) < 0xE)
  3737. ioc->old_sas_discovery_protocal = 1;
  3738. mptsas_scan_sas_topology(ioc);
  3739. mptsas_fw_event_on(ioc);
  3740. return 0;
  3741. out_mptsas_probe:
  3742. mptscsih_remove(pdev);
  3743. return error;
  3744. }
  3745. void
  3746. mptsas_shutdown(struct pci_dev *pdev)
  3747. {
  3748. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  3749. mptsas_fw_event_off(ioc);
  3750. mptsas_cleanup_fw_event_q(ioc);
  3751. }
  3752. static void __devexit mptsas_remove(struct pci_dev *pdev)
  3753. {
  3754. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  3755. struct mptsas_portinfo *p, *n;
  3756. int i;
  3757. mptsas_shutdown(pdev);
  3758. mptsas_del_device_components(ioc);
  3759. ioc->sas_discovery_ignore_events = 1;
  3760. sas_remove_host(ioc->sh);
  3761. mutex_lock(&ioc->sas_topology_mutex);
  3762. list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
  3763. list_del(&p->list);
  3764. for (i = 0 ; i < p->num_phys ; i++)
  3765. mptsas_port_delete(ioc, p->phy_info[i].port_details);
  3766. kfree(p->phy_info);
  3767. kfree(p);
  3768. }
  3769. mutex_unlock(&ioc->sas_topology_mutex);
  3770. ioc->hba_port_info = NULL;
  3771. mptscsih_remove(pdev);
  3772. }
  3773. static struct pci_device_id mptsas_pci_table[] = {
  3774. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
  3775. PCI_ANY_ID, PCI_ANY_ID },
  3776. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
  3777. PCI_ANY_ID, PCI_ANY_ID },
  3778. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
  3779. PCI_ANY_ID, PCI_ANY_ID },
  3780. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
  3781. PCI_ANY_ID, PCI_ANY_ID },
  3782. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
  3783. PCI_ANY_ID, PCI_ANY_ID },
  3784. {0} /* Terminating entry */
  3785. };
  3786. MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
  3787. static struct pci_driver mptsas_driver = {
  3788. .name = "mptsas",
  3789. .id_table = mptsas_pci_table,
  3790. .probe = mptsas_probe,
  3791. .remove = __devexit_p(mptsas_remove),
  3792. .shutdown = mptsas_shutdown,
  3793. #ifdef CONFIG_PM
  3794. .suspend = mptscsih_suspend,
  3795. .resume = mptscsih_resume,
  3796. #endif
  3797. };
  3798. static int __init
  3799. mptsas_init(void)
  3800. {
  3801. int error;
  3802. show_mptmod_ver(my_NAME, my_VERSION);
  3803. mptsas_transport_template =
  3804. sas_attach_transport(&mptsas_transport_functions);
  3805. if (!mptsas_transport_template)
  3806. return -ENODEV;
  3807. mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
  3808. mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
  3809. mptsasInternalCtx =
  3810. mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
  3811. mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
  3812. mptsasDeviceResetCtx =
  3813. mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
  3814. mpt_event_register(mptsasDoneCtx, mptsas_event_process);
  3815. mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
  3816. error = pci_register_driver(&mptsas_driver);
  3817. if (error)
  3818. sas_release_transport(mptsas_transport_template);
  3819. return error;
  3820. }
  3821. static void __exit
  3822. mptsas_exit(void)
  3823. {
  3824. pci_unregister_driver(&mptsas_driver);
  3825. sas_release_transport(mptsas_transport_template);
  3826. mpt_reset_deregister(mptsasDoneCtx);
  3827. mpt_event_deregister(mptsasDoneCtx);
  3828. mpt_deregister(mptsasMgmtCtx);
  3829. mpt_deregister(mptsasInternalCtx);
  3830. mpt_deregister(mptsasTaskCtx);
  3831. mpt_deregister(mptsasDoneCtx);
  3832. mpt_deregister(mptsasDeviceResetCtx);
  3833. }
  3834. module_init(mptsas_init);
  3835. module_exit(mptsas_exit);