mptsas.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326
  1. /*
  2. * linux/drivers/message/fusion/mptsas.c
  3. * For use with LSI Logic PCI chip/adapter(s)
  4. * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
  5. *
  6. * Copyright (c) 1999-2007 LSI Logic Corporation
  7. * (mailto:DL-MPTFusionLinux@lsi.com)
  8. * Copyright (c) 2005-2007 Dell
  9. */
  10. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  11. /*
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; version 2 of the License.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. NO WARRANTY
  20. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. solely responsible for determining the appropriateness of using and
  25. distributing the Program and assumes all risks associated with its
  26. exercise of rights under this Agreement, including but not limited to
  27. the risks and costs of program errors, damage to or loss of data,
  28. programs or equipment, and unavailability or interruption of operations.
  29. DISCLAIMER OF LIABILITY
  30. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. You should have received a copy of the GNU General Public License
  38. along with this program; if not, write to the Free Software
  39. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  40. */
  41. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/init.h>
  45. #include <linux/errno.h>
  46. #include <linux/jiffies.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/delay.h> /* for mdelay */
  49. #include <scsi/scsi.h>
  50. #include <scsi/scsi_cmnd.h>
  51. #include <scsi/scsi_device.h>
  52. #include <scsi/scsi_host.h>
  53. #include <scsi/scsi_transport_sas.h>
  54. #include <scsi/scsi_dbg.h>
  55. #include "mptbase.h"
  56. #include "mptscsih.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 int mptsasDoneCtx = -1;
  79. static int mptsasTaskCtx = -1;
  80. static int mptsasInternalCtx = -1; /* Used only for internal commands */
  81. static int mptsasMgmtCtx = -1;
  82. static void mptsas_hotplug_work(struct work_struct *work);
  83. struct mptsas_target_reset_event {
  84. struct list_head list;
  85. EVENT_DATA_SAS_DEVICE_STATUS_CHANGE sas_event_data;
  86. u8 target_reset_issued;
  87. };
  88. enum mptsas_hotplug_action {
  89. MPTSAS_ADD_DEVICE,
  90. MPTSAS_DEL_DEVICE,
  91. MPTSAS_ADD_RAID,
  92. MPTSAS_DEL_RAID,
  93. MPTSAS_ADD_INACTIVE_VOLUME,
  94. MPTSAS_IGNORE_EVENT,
  95. };
  96. struct mptsas_hotplug_event {
  97. struct work_struct work;
  98. MPT_ADAPTER *ioc;
  99. enum mptsas_hotplug_action event_type;
  100. u64 sas_address;
  101. u8 channel;
  102. u8 id;
  103. u32 device_info;
  104. u16 handle;
  105. u16 parent_handle;
  106. u8 phy_id;
  107. u8 phys_disk_num_valid; /* hrc (hidden raid component) */
  108. u8 phys_disk_num; /* hrc - unique index*/
  109. u8 hidden_raid_component; /* hrc - don't expose*/
  110. };
  111. struct mptsas_discovery_event {
  112. struct work_struct work;
  113. MPT_ADAPTER *ioc;
  114. };
  115. /*
  116. * SAS topology structures
  117. *
  118. * The MPT Fusion firmware interface spreads information about the
  119. * SAS topology over many manufacture pages, thus we need some data
  120. * structure to collect it and process it for the SAS transport class.
  121. */
  122. struct mptsas_devinfo {
  123. u16 handle; /* unique id to address this device */
  124. u16 handle_parent; /* unique id to address parent device */
  125. u16 handle_enclosure; /* enclosure identifier of the enclosure */
  126. u16 slot; /* physical slot in enclosure */
  127. u8 phy_id; /* phy number of parent device */
  128. u8 port_id; /* sas physical port this device
  129. is assoc'd with */
  130. u8 id; /* logical target id of this device */
  131. u32 phys_disk_num; /* phys disk id, for csmi-ioctls */
  132. u8 channel; /* logical bus number of this device */
  133. u64 sas_address; /* WWN of this device,
  134. SATA is assigned by HBA,expander */
  135. u32 device_info; /* bitfield detailed info about this device */
  136. };
  137. /*
  138. * Specific details on ports, wide/narrow
  139. */
  140. struct mptsas_portinfo_details{
  141. u16 num_phys; /* number of phys belong to this port */
  142. u64 phy_bitmask; /* TODO, extend support for 255 phys */
  143. struct sas_rphy *rphy; /* transport layer rphy object */
  144. struct sas_port *port; /* transport layer port object */
  145. struct scsi_target *starget;
  146. struct mptsas_portinfo *port_info;
  147. };
  148. struct mptsas_phyinfo {
  149. u16 handle; /* unique id to address this */
  150. u8 phy_id; /* phy index */
  151. u8 port_id; /* firmware port identifier */
  152. u8 negotiated_link_rate; /* nego'd link rate for this phy */
  153. u8 hw_link_rate; /* hardware max/min phys link rate */
  154. u8 programmed_link_rate; /* programmed max/min phy link rate */
  155. u8 sas_port_add_phy; /* flag to request sas_port_add_phy*/
  156. struct mptsas_devinfo identify; /* point to phy device info */
  157. struct mptsas_devinfo attached; /* point to attached device info */
  158. struct sas_phy *phy; /* transport layer phy object */
  159. struct mptsas_portinfo *portinfo;
  160. struct mptsas_portinfo_details * port_details;
  161. };
  162. struct mptsas_portinfo {
  163. struct list_head list;
  164. u16 num_phys; /* number of phys */
  165. struct mptsas_phyinfo *phy_info;
  166. };
  167. struct mptsas_enclosure {
  168. u64 enclosure_logical_id; /* The WWN for the enclosure */
  169. u16 enclosure_handle; /* unique id to address this */
  170. u16 flags; /* details enclosure management */
  171. u16 num_slot; /* num slots */
  172. u16 start_slot; /* first slot */
  173. u8 start_id; /* starting logical target id */
  174. u8 start_channel; /* starting logical channel id */
  175. u8 sep_id; /* SEP device logical target id */
  176. u8 sep_channel; /* SEP channel logical channel id */
  177. };
  178. static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
  179. MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
  180. {
  181. dsasprintk(ioc, printk(KERN_DEBUG "---- IO UNIT PAGE 0 ------------\n"));
  182. dsasprintk(ioc, printk(KERN_DEBUG "Handle=0x%X\n",
  183. le16_to_cpu(phy_data->AttachedDeviceHandle)));
  184. dsasprintk(ioc, printk(KERN_DEBUG "Controller Handle=0x%X\n",
  185. le16_to_cpu(phy_data->ControllerDevHandle)));
  186. dsasprintk(ioc, printk(KERN_DEBUG "Port=0x%X\n", phy_data->Port));
  187. dsasprintk(ioc, printk(KERN_DEBUG "Port Flags=0x%X\n", phy_data->PortFlags));
  188. dsasprintk(ioc, printk(KERN_DEBUG "PHY Flags=0x%X\n", phy_data->PhyFlags));
  189. dsasprintk(ioc, printk(KERN_DEBUG "Negotiated Link Rate=0x%X\n", phy_data->NegotiatedLinkRate));
  190. dsasprintk(ioc, printk(KERN_DEBUG "Controller PHY Device Info=0x%X\n",
  191. le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
  192. dsasprintk(ioc, printk(KERN_DEBUG "DiscoveryStatus=0x%X\n\n",
  193. le32_to_cpu(phy_data->DiscoveryStatus)));
  194. }
  195. static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
  196. {
  197. __le64 sas_address;
  198. memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
  199. dsasprintk(ioc, printk(KERN_DEBUG "---- SAS PHY PAGE 0 ------------\n"));
  200. dsasprintk(ioc, printk(KERN_DEBUG "Attached Device Handle=0x%X\n",
  201. le16_to_cpu(pg0->AttachedDevHandle)));
  202. dsasprintk(ioc, printk(KERN_DEBUG "SAS Address=0x%llX\n",
  203. (unsigned long long)le64_to_cpu(sas_address)));
  204. dsasprintk(ioc, printk(KERN_DEBUG "Attached PHY Identifier=0x%X\n", pg0->AttachedPhyIdentifier));
  205. dsasprintk(ioc, printk(KERN_DEBUG "Attached Device Info=0x%X\n",
  206. le32_to_cpu(pg0->AttachedDeviceInfo)));
  207. dsasprintk(ioc, printk(KERN_DEBUG "Programmed Link Rate=0x%X\n", pg0->ProgrammedLinkRate));
  208. dsasprintk(ioc, printk(KERN_DEBUG "Change Count=0x%X\n", pg0->ChangeCount));
  209. dsasprintk(ioc, printk(KERN_DEBUG "PHY Info=0x%X\n\n", le32_to_cpu(pg0->PhyInfo)));
  210. }
  211. static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
  212. {
  213. dsasprintk(ioc, printk(KERN_DEBUG "---- SAS PHY PAGE 1 ------------\n"));
  214. dsasprintk(ioc, printk(KERN_DEBUG "Invalid Dword Count=0x%x\n", pg1->InvalidDwordCount));
  215. dsasprintk(ioc, printk(KERN_DEBUG "Running Disparity Error Count=0x%x\n",
  216. pg1->RunningDisparityErrorCount));
  217. dsasprintk(ioc, printk(KERN_DEBUG "Loss Dword Synch Count=0x%x\n", pg1->LossDwordSynchCount));
  218. dsasprintk(ioc, printk(KERN_DEBUG "PHY Reset Problem Count=0x%x\n\n", pg1->PhyResetProblemCount));
  219. }
  220. static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
  221. {
  222. __le64 sas_address;
  223. memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
  224. dsasprintk(ioc, printk(KERN_DEBUG "---- SAS DEVICE PAGE 0 ---------\n"));
  225. dsasprintk(ioc, printk(KERN_DEBUG "Handle=0x%X\n" ,le16_to_cpu(pg0->DevHandle)));
  226. dsasprintk(ioc, printk(KERN_DEBUG "Parent Handle=0x%X\n" ,le16_to_cpu(pg0->ParentDevHandle)));
  227. dsasprintk(ioc, printk(KERN_DEBUG "Enclosure Handle=0x%X\n", le16_to_cpu(pg0->EnclosureHandle)));
  228. dsasprintk(ioc, printk(KERN_DEBUG "Slot=0x%X\n", le16_to_cpu(pg0->Slot)));
  229. dsasprintk(ioc, printk(KERN_DEBUG "SAS Address=0x%llX\n", (unsigned long long)
  230. le64_to_cpu(sas_address)));
  231. dsasprintk(ioc, printk(KERN_DEBUG "Target ID=0x%X\n", pg0->TargetID));
  232. dsasprintk(ioc, printk(KERN_DEBUG "Bus=0x%X\n", pg0->Bus));
  233. /* The PhyNum field specifies the PHY number of the parent
  234. * device this device is linked to
  235. */
  236. dsasprintk(ioc, printk(KERN_DEBUG "Parent Phy Num=0x%X\n", pg0->PhyNum));
  237. dsasprintk(ioc, printk(KERN_DEBUG "Access Status=0x%X\n", le16_to_cpu(pg0->AccessStatus)));
  238. dsasprintk(ioc, printk(KERN_DEBUG "Device Info=0x%X\n", le32_to_cpu(pg0->DeviceInfo)));
  239. dsasprintk(ioc, printk(KERN_DEBUG "Flags=0x%X\n", le16_to_cpu(pg0->Flags)));
  240. dsasprintk(ioc, printk(KERN_DEBUG "Physical Port=0x%X\n\n", pg0->PhysicalPort));
  241. }
  242. static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
  243. {
  244. dsasprintk(ioc, printk(KERN_DEBUG "---- SAS EXPANDER PAGE 1 ------------\n"));
  245. dsasprintk(ioc, printk(KERN_DEBUG "Physical Port=0x%X\n", pg1->PhysicalPort));
  246. dsasprintk(ioc, printk(KERN_DEBUG "PHY Identifier=0x%X\n", pg1->PhyIdentifier));
  247. dsasprintk(ioc, printk(KERN_DEBUG "Negotiated Link Rate=0x%X\n", pg1->NegotiatedLinkRate));
  248. dsasprintk(ioc, printk(KERN_DEBUG "Programmed Link Rate=0x%X\n", pg1->ProgrammedLinkRate));
  249. dsasprintk(ioc, printk(KERN_DEBUG "Hardware Link Rate=0x%X\n", pg1->HwLinkRate));
  250. dsasprintk(ioc, printk(KERN_DEBUG "Owner Device Handle=0x%X\n",
  251. le16_to_cpu(pg1->OwnerDevHandle)));
  252. dsasprintk(ioc, printk(KERN_DEBUG "Attached Device Handle=0x%X\n\n",
  253. le16_to_cpu(pg1->AttachedDevHandle)));
  254. }
  255. static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
  256. {
  257. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  258. return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
  259. }
  260. static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
  261. {
  262. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  263. return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
  264. }
  265. /*
  266. * mptsas_find_portinfo_by_handle
  267. *
  268. * This function should be called with the sas_topology_mutex already held
  269. */
  270. static struct mptsas_portinfo *
  271. mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
  272. {
  273. struct mptsas_portinfo *port_info, *rc=NULL;
  274. int i;
  275. list_for_each_entry(port_info, &ioc->sas_topology, list)
  276. for (i = 0; i < port_info->num_phys; i++)
  277. if (port_info->phy_info[i].identify.handle == handle) {
  278. rc = port_info;
  279. goto out;
  280. }
  281. out:
  282. return rc;
  283. }
  284. /*
  285. * Returns true if there is a scsi end device
  286. */
  287. static inline int
  288. mptsas_is_end_device(struct mptsas_devinfo * attached)
  289. {
  290. if ((attached->sas_address) &&
  291. (attached->device_info &
  292. MPI_SAS_DEVICE_INFO_END_DEVICE) &&
  293. ((attached->device_info &
  294. MPI_SAS_DEVICE_INFO_SSP_TARGET) |
  295. (attached->device_info &
  296. MPI_SAS_DEVICE_INFO_STP_TARGET) |
  297. (attached->device_info &
  298. MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
  299. return 1;
  300. else
  301. return 0;
  302. }
  303. /* no mutex */
  304. static void
  305. mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
  306. {
  307. struct mptsas_portinfo *port_info;
  308. struct mptsas_phyinfo *phy_info;
  309. u8 i;
  310. if (!port_details)
  311. return;
  312. port_info = port_details->port_info;
  313. phy_info = port_info->phy_info;
  314. dsaswideprintk(ioc, printk(KERN_DEBUG "%s: [%p]: num_phys=%02d "
  315. "bitmask=0x%016llX\n", __FUNCTION__, port_details,
  316. port_details->num_phys, (unsigned long long)
  317. port_details->phy_bitmask));
  318. for (i = 0; i < port_info->num_phys; i++, phy_info++) {
  319. if(phy_info->port_details != port_details)
  320. continue;
  321. memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
  322. phy_info->port_details = NULL;
  323. }
  324. kfree(port_details);
  325. }
  326. static inline struct sas_rphy *
  327. mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
  328. {
  329. if (phy_info->port_details)
  330. return phy_info->port_details->rphy;
  331. else
  332. return NULL;
  333. }
  334. static inline void
  335. mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
  336. {
  337. if (phy_info->port_details) {
  338. phy_info->port_details->rphy = rphy;
  339. dsaswideprintk(ioc, printk(KERN_DEBUG "sas_rphy_add: rphy=%p\n", rphy));
  340. }
  341. if (rphy) {
  342. dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
  343. &rphy->dev, "add:"));
  344. dsaswideprintk(ioc, printk(KERN_DEBUG "rphy=%p release=%p\n",
  345. rphy, rphy->dev.release));
  346. }
  347. }
  348. static inline struct sas_port *
  349. mptsas_get_port(struct mptsas_phyinfo *phy_info)
  350. {
  351. if (phy_info->port_details)
  352. return phy_info->port_details->port;
  353. else
  354. return NULL;
  355. }
  356. static inline void
  357. mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
  358. {
  359. if (phy_info->port_details)
  360. phy_info->port_details->port = port;
  361. if (port) {
  362. dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
  363. &port->dev, "add:"));
  364. dsaswideprintk(ioc, printk(KERN_DEBUG "port=%p release=%p\n",
  365. port, port->dev.release));
  366. }
  367. }
  368. static inline struct scsi_target *
  369. mptsas_get_starget(struct mptsas_phyinfo *phy_info)
  370. {
  371. if (phy_info->port_details)
  372. return phy_info->port_details->starget;
  373. else
  374. return NULL;
  375. }
  376. static inline void
  377. mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
  378. starget)
  379. {
  380. if (phy_info->port_details)
  381. phy_info->port_details->starget = starget;
  382. }
  383. /*
  384. * mptsas_setup_wide_ports
  385. *
  386. * Updates for new and existing narrow/wide port configuration
  387. * in the sas_topology
  388. */
  389. static void
  390. mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
  391. {
  392. struct mptsas_portinfo_details * port_details;
  393. struct mptsas_phyinfo *phy_info, *phy_info_cmp;
  394. u64 sas_address;
  395. int i, j;
  396. mutex_lock(&ioc->sas_topology_mutex);
  397. phy_info = port_info->phy_info;
  398. for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
  399. if (phy_info->attached.handle)
  400. continue;
  401. port_details = phy_info->port_details;
  402. if (!port_details)
  403. continue;
  404. if (port_details->num_phys < 2)
  405. continue;
  406. /*
  407. * Removing a phy from a port, letting the last
  408. * phy be removed by firmware events.
  409. */
  410. dsaswideprintk(ioc, printk(KERN_DEBUG
  411. "%s: [%p]: deleting phy = %d\n",
  412. __FUNCTION__, port_details, i));
  413. port_details->num_phys--;
  414. port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
  415. memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
  416. sas_port_delete_phy(port_details->port, phy_info->phy);
  417. phy_info->port_details = NULL;
  418. }
  419. /*
  420. * Populate and refresh the tree
  421. */
  422. phy_info = port_info->phy_info;
  423. for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
  424. sas_address = phy_info->attached.sas_address;
  425. dsaswideprintk(ioc, printk(KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n",
  426. i, (unsigned long long)sas_address));
  427. if (!sas_address)
  428. continue;
  429. port_details = phy_info->port_details;
  430. /*
  431. * Forming a port
  432. */
  433. if (!port_details) {
  434. port_details = kzalloc(sizeof(*port_details),
  435. GFP_KERNEL);
  436. if (!port_details)
  437. goto out;
  438. port_details->num_phys = 1;
  439. port_details->port_info = port_info;
  440. if (phy_info->phy_id < 64 )
  441. port_details->phy_bitmask |=
  442. (1 << phy_info->phy_id);
  443. phy_info->sas_port_add_phy=1;
  444. dsaswideprintk(ioc, printk(KERN_DEBUG "\t\tForming port\n\t\t"
  445. "phy_id=%d sas_address=0x%018llX\n",
  446. i, (unsigned long long)sas_address));
  447. phy_info->port_details = port_details;
  448. }
  449. if (i == port_info->num_phys - 1)
  450. continue;
  451. phy_info_cmp = &port_info->phy_info[i + 1];
  452. for (j = i + 1 ; j < port_info->num_phys ; j++,
  453. phy_info_cmp++) {
  454. if (!phy_info_cmp->attached.sas_address)
  455. continue;
  456. if (sas_address != phy_info_cmp->attached.sas_address)
  457. continue;
  458. if (phy_info_cmp->port_details == port_details )
  459. continue;
  460. dsaswideprintk(ioc, printk(KERN_DEBUG
  461. "\t\tphy_id=%d sas_address=0x%018llX\n",
  462. j, (unsigned long long)
  463. phy_info_cmp->attached.sas_address));
  464. if (phy_info_cmp->port_details) {
  465. port_details->rphy =
  466. mptsas_get_rphy(phy_info_cmp);
  467. port_details->port =
  468. mptsas_get_port(phy_info_cmp);
  469. port_details->starget =
  470. mptsas_get_starget(phy_info_cmp);
  471. port_details->num_phys =
  472. phy_info_cmp->port_details->num_phys;
  473. if (!phy_info_cmp->port_details->num_phys)
  474. kfree(phy_info_cmp->port_details);
  475. } else
  476. phy_info_cmp->sas_port_add_phy=1;
  477. /*
  478. * Adding a phy to a port
  479. */
  480. phy_info_cmp->port_details = port_details;
  481. if (phy_info_cmp->phy_id < 64 )
  482. port_details->phy_bitmask |=
  483. (1 << phy_info_cmp->phy_id);
  484. port_details->num_phys++;
  485. }
  486. }
  487. out:
  488. for (i = 0; i < port_info->num_phys; i++) {
  489. port_details = port_info->phy_info[i].port_details;
  490. if (!port_details)
  491. continue;
  492. dsaswideprintk(ioc, printk(KERN_DEBUG
  493. "%s: [%p]: phy_id=%02d num_phys=%02d "
  494. "bitmask=0x%016llX\n", __FUNCTION__,
  495. port_details, i, port_details->num_phys,
  496. (unsigned long long)port_details->phy_bitmask));
  497. dsaswideprintk(ioc, printk(KERN_DEBUG"\t\tport = %p rphy=%p\n",
  498. port_details->port, port_details->rphy));
  499. }
  500. dsaswideprintk(ioc, printk(KERN_DEBUG"\n"));
  501. mutex_unlock(&ioc->sas_topology_mutex);
  502. }
  503. /**
  504. * csmisas_find_vtarget
  505. *
  506. * @ioc
  507. * @volume_id
  508. * @volume_bus
  509. *
  510. **/
  511. static VirtTarget *
  512. mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
  513. {
  514. struct scsi_device *sdev;
  515. VirtDevice *vdev;
  516. VirtTarget *vtarget = NULL;
  517. shost_for_each_device(sdev, ioc->sh) {
  518. if ((vdev = sdev->hostdata) == NULL)
  519. continue;
  520. if (vdev->vtarget->id == id &&
  521. vdev->vtarget->channel == channel)
  522. vtarget = vdev->vtarget;
  523. }
  524. return vtarget;
  525. }
  526. /**
  527. * mptsas_target_reset
  528. *
  529. * Issues TARGET_RESET to end device using handshaking method
  530. *
  531. * @ioc
  532. * @channel
  533. * @id
  534. *
  535. * Returns (1) success
  536. * (0) failure
  537. *
  538. **/
  539. static int
  540. mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
  541. {
  542. MPT_FRAME_HDR *mf;
  543. SCSITaskMgmt_t *pScsiTm;
  544. if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
  545. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames @%d!!\n",
  546. ioc->name,__FUNCTION__, __LINE__));
  547. return 0;
  548. }
  549. /* Format the Request
  550. */
  551. pScsiTm = (SCSITaskMgmt_t *) mf;
  552. memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
  553. pScsiTm->TargetID = id;
  554. pScsiTm->Bus = channel;
  555. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  556. pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  557. pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
  558. DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
  559. if (mpt_send_handshake_request(ioc->TaskCtx, ioc,
  560. sizeof(SCSITaskMgmt_t), (u32 *)mf, NO_SLEEP)) {
  561. mpt_free_msg_frame(ioc, mf);
  562. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, tm handshake failed @%d!!\n",
  563. ioc->name,__FUNCTION__, __LINE__));
  564. return 0;
  565. }
  566. return 1;
  567. }
  568. /**
  569. * mptsas_target_reset_queue
  570. *
  571. * Receive request for TARGET_RESET after recieving an firmware
  572. * event NOT_RESPONDING_EVENT, then put command in link list
  573. * and queue if task_queue already in use.
  574. *
  575. * @ioc
  576. * @sas_event_data
  577. *
  578. **/
  579. static void
  580. mptsas_target_reset_queue(MPT_ADAPTER *ioc,
  581. EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
  582. {
  583. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
  584. VirtTarget *vtarget = NULL;
  585. struct mptsas_target_reset_event *target_reset_list;
  586. u8 id, channel;
  587. id = sas_event_data->TargetID;
  588. channel = sas_event_data->Bus;
  589. if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
  590. return;
  591. vtarget->deleted = 1; /* block IO */
  592. target_reset_list = kzalloc(sizeof(*target_reset_list),
  593. GFP_ATOMIC);
  594. if (!target_reset_list) {
  595. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
  596. ioc->name,__FUNCTION__, __LINE__));
  597. return;
  598. }
  599. memcpy(&target_reset_list->sas_event_data, sas_event_data,
  600. sizeof(*sas_event_data));
  601. list_add_tail(&target_reset_list->list, &hd->target_reset_list);
  602. if (hd->resetPending)
  603. return;
  604. if (mptsas_target_reset(ioc, channel, id)) {
  605. target_reset_list->target_reset_issued = 1;
  606. hd->resetPending = 1;
  607. }
  608. }
  609. /**
  610. * mptsas_dev_reset_complete
  611. *
  612. * Completion for TARGET_RESET after NOT_RESPONDING_EVENT,
  613. * enable work queue to finish off removing device from upper layers.
  614. * then send next TARGET_RESET in the queue.
  615. *
  616. * @ioc
  617. *
  618. **/
  619. static void
  620. mptsas_dev_reset_complete(MPT_ADAPTER *ioc)
  621. {
  622. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
  623. struct list_head *head = &hd->target_reset_list;
  624. struct mptsas_target_reset_event *target_reset_list;
  625. struct mptsas_hotplug_event *ev;
  626. EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
  627. u8 id, channel;
  628. __le64 sas_address;
  629. if (list_empty(head))
  630. return;
  631. target_reset_list = list_entry(head->next, struct mptsas_target_reset_event, list);
  632. sas_event_data = &target_reset_list->sas_event_data;
  633. id = sas_event_data->TargetID;
  634. channel = sas_event_data->Bus;
  635. hd->resetPending = 0;
  636. /*
  637. * retry target reset
  638. */
  639. if (!target_reset_list->target_reset_issued) {
  640. if (mptsas_target_reset(ioc, channel, id)) {
  641. target_reset_list->target_reset_issued = 1;
  642. hd->resetPending = 1;
  643. }
  644. return;
  645. }
  646. /*
  647. * enable work queue to remove device from upper layers
  648. */
  649. list_del(&target_reset_list->list);
  650. ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
  651. if (!ev) {
  652. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
  653. ioc->name,__FUNCTION__, __LINE__));
  654. return;
  655. }
  656. INIT_WORK(&ev->work, mptsas_hotplug_work);
  657. ev->ioc = ioc;
  658. ev->handle = le16_to_cpu(sas_event_data->DevHandle);
  659. ev->parent_handle =
  660. le16_to_cpu(sas_event_data->ParentDevHandle);
  661. ev->channel = channel;
  662. ev->id =id;
  663. ev->phy_id = sas_event_data->PhyNum;
  664. memcpy(&sas_address, &sas_event_data->SASAddress,
  665. sizeof(__le64));
  666. ev->sas_address = le64_to_cpu(sas_address);
  667. ev->device_info = le32_to_cpu(sas_event_data->DeviceInfo);
  668. ev->event_type = MPTSAS_DEL_DEVICE;
  669. schedule_work(&ev->work);
  670. kfree(target_reset_list);
  671. /*
  672. * issue target reset to next device in the queue
  673. */
  674. head = &hd->target_reset_list;
  675. if (list_empty(head))
  676. return;
  677. target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
  678. list);
  679. sas_event_data = &target_reset_list->sas_event_data;
  680. id = sas_event_data->TargetID;
  681. channel = sas_event_data->Bus;
  682. if (mptsas_target_reset(ioc, channel, id)) {
  683. target_reset_list->target_reset_issued = 1;
  684. hd->resetPending = 1;
  685. }
  686. }
  687. /**
  688. * mptsas_taskmgmt_complete
  689. *
  690. * @ioc
  691. * @mf
  692. * @mr
  693. *
  694. **/
  695. static int
  696. mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  697. {
  698. mptsas_dev_reset_complete(ioc);
  699. return mptscsih_taskmgmt_complete(ioc, mf, mr);
  700. }
  701. /**
  702. * mptscsih_ioc_reset
  703. *
  704. * @ioc
  705. * @reset_phase
  706. *
  707. **/
  708. static int
  709. mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  710. {
  711. MPT_SCSI_HOST *hd;
  712. struct mptsas_target_reset_event *target_reset_list, *n;
  713. int rc;
  714. rc = mptscsih_ioc_reset(ioc, reset_phase);
  715. if (ioc->bus_type != SAS)
  716. goto out;
  717. if (reset_phase != MPT_IOC_POST_RESET)
  718. goto out;
  719. if (!ioc->sh || !ioc->sh->hostdata)
  720. goto out;
  721. hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
  722. if (!hd->ioc)
  723. goto out;
  724. if (list_empty(&hd->target_reset_list))
  725. goto out;
  726. /* flush the target_reset_list */
  727. list_for_each_entry_safe(target_reset_list, n,
  728. &hd->target_reset_list, list) {
  729. list_del(&target_reset_list->list);
  730. kfree(target_reset_list);
  731. }
  732. out:
  733. return rc;
  734. }
  735. static int
  736. mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
  737. u32 form, u32 form_specific)
  738. {
  739. ConfigExtendedPageHeader_t hdr;
  740. CONFIGPARMS cfg;
  741. SasEnclosurePage0_t *buffer;
  742. dma_addr_t dma_handle;
  743. int error;
  744. __le64 le_identifier;
  745. memset(&hdr, 0, sizeof(hdr));
  746. hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
  747. hdr.PageNumber = 0;
  748. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  749. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
  750. cfg.cfghdr.ehdr = &hdr;
  751. cfg.physAddr = -1;
  752. cfg.pageAddr = form + form_specific;
  753. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  754. cfg.dir = 0; /* read */
  755. cfg.timeout = 10;
  756. error = mpt_config(ioc, &cfg);
  757. if (error)
  758. goto out;
  759. if (!hdr.ExtPageLength) {
  760. error = -ENXIO;
  761. goto out;
  762. }
  763. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  764. &dma_handle);
  765. if (!buffer) {
  766. error = -ENOMEM;
  767. goto out;
  768. }
  769. cfg.physAddr = dma_handle;
  770. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  771. error = mpt_config(ioc, &cfg);
  772. if (error)
  773. goto out_free_consistent;
  774. /* save config data */
  775. memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
  776. enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
  777. enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
  778. enclosure->flags = le16_to_cpu(buffer->Flags);
  779. enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
  780. enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
  781. enclosure->start_id = buffer->StartTargetID;
  782. enclosure->start_channel = buffer->StartBus;
  783. enclosure->sep_id = buffer->SEPTargetID;
  784. enclosure->sep_channel = buffer->SEPBus;
  785. out_free_consistent:
  786. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  787. buffer, dma_handle);
  788. out:
  789. return error;
  790. }
  791. static int
  792. mptsas_slave_configure(struct scsi_device *sdev)
  793. {
  794. if (sdev->channel == MPTSAS_RAID_CHANNEL)
  795. goto out;
  796. sas_read_port_mode_page(sdev);
  797. out:
  798. return mptscsih_slave_configure(sdev);
  799. }
  800. static int
  801. mptsas_target_alloc(struct scsi_target *starget)
  802. {
  803. struct Scsi_Host *host = dev_to_shost(&starget->dev);
  804. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  805. VirtTarget *vtarget;
  806. u8 id, channel;
  807. struct sas_rphy *rphy;
  808. struct mptsas_portinfo *p;
  809. int i;
  810. vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
  811. if (!vtarget)
  812. return -ENOMEM;
  813. vtarget->starget = starget;
  814. vtarget->ioc_id = hd->ioc->id;
  815. vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
  816. id = starget->id;
  817. channel = 0;
  818. /*
  819. * RAID volumes placed beyond the last expected port.
  820. */
  821. if (starget->channel == MPTSAS_RAID_CHANNEL) {
  822. for (i=0; i < hd->ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
  823. if (id == hd->ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
  824. channel = hd->ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
  825. goto out;
  826. }
  827. rphy = dev_to_rphy(starget->dev.parent);
  828. mutex_lock(&hd->ioc->sas_topology_mutex);
  829. list_for_each_entry(p, &hd->ioc->sas_topology, list) {
  830. for (i = 0; i < p->num_phys; i++) {
  831. if (p->phy_info[i].attached.sas_address !=
  832. rphy->identify.sas_address)
  833. continue;
  834. id = p->phy_info[i].attached.id;
  835. channel = p->phy_info[i].attached.channel;
  836. mptsas_set_starget(&p->phy_info[i], starget);
  837. /*
  838. * Exposing hidden raid components
  839. */
  840. if (mptscsih_is_phys_disk(hd->ioc, channel, id)) {
  841. id = mptscsih_raid_id_to_num(hd->ioc,
  842. channel, id);
  843. vtarget->tflags |=
  844. MPT_TARGET_FLAGS_RAID_COMPONENT;
  845. p->phy_info[i].attached.phys_disk_num = id;
  846. }
  847. mutex_unlock(&hd->ioc->sas_topology_mutex);
  848. goto out;
  849. }
  850. }
  851. mutex_unlock(&hd->ioc->sas_topology_mutex);
  852. kfree(vtarget);
  853. return -ENXIO;
  854. out:
  855. vtarget->id = id;
  856. vtarget->channel = channel;
  857. starget->hostdata = vtarget;
  858. return 0;
  859. }
  860. static void
  861. mptsas_target_destroy(struct scsi_target *starget)
  862. {
  863. struct Scsi_Host *host = dev_to_shost(&starget->dev);
  864. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  865. struct sas_rphy *rphy;
  866. struct mptsas_portinfo *p;
  867. int i;
  868. if (!starget->hostdata)
  869. return;
  870. if (starget->channel == MPTSAS_RAID_CHANNEL)
  871. goto out;
  872. rphy = dev_to_rphy(starget->dev.parent);
  873. list_for_each_entry(p, &hd->ioc->sas_topology, list) {
  874. for (i = 0; i < p->num_phys; i++) {
  875. if (p->phy_info[i].attached.sas_address !=
  876. rphy->identify.sas_address)
  877. continue;
  878. mptsas_set_starget(&p->phy_info[i], NULL);
  879. goto out;
  880. }
  881. }
  882. out:
  883. kfree(starget->hostdata);
  884. starget->hostdata = NULL;
  885. }
  886. static int
  887. mptsas_slave_alloc(struct scsi_device *sdev)
  888. {
  889. struct Scsi_Host *host = sdev->host;
  890. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  891. struct sas_rphy *rphy;
  892. struct mptsas_portinfo *p;
  893. VirtDevice *vdev;
  894. struct scsi_target *starget;
  895. int i;
  896. vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
  897. if (!vdev) {
  898. printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
  899. hd->ioc->name, sizeof(VirtDevice));
  900. return -ENOMEM;
  901. }
  902. starget = scsi_target(sdev);
  903. vdev->vtarget = starget->hostdata;
  904. if (sdev->channel == MPTSAS_RAID_CHANNEL)
  905. goto out;
  906. rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
  907. mutex_lock(&hd->ioc->sas_topology_mutex);
  908. list_for_each_entry(p, &hd->ioc->sas_topology, list) {
  909. for (i = 0; i < p->num_phys; i++) {
  910. if (p->phy_info[i].attached.sas_address !=
  911. rphy->identify.sas_address)
  912. continue;
  913. vdev->lun = sdev->lun;
  914. /*
  915. * Exposing hidden raid components
  916. */
  917. if (mptscsih_is_phys_disk(hd->ioc,
  918. p->phy_info[i].attached.channel,
  919. p->phy_info[i].attached.id))
  920. sdev->no_uld_attach = 1;
  921. mutex_unlock(&hd->ioc->sas_topology_mutex);
  922. goto out;
  923. }
  924. }
  925. mutex_unlock(&hd->ioc->sas_topology_mutex);
  926. kfree(vdev);
  927. return -ENXIO;
  928. out:
  929. vdev->vtarget->num_luns++;
  930. sdev->hostdata = vdev;
  931. return 0;
  932. }
  933. static int
  934. mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
  935. {
  936. VirtDevice *vdev = SCpnt->device->hostdata;
  937. if (!vdev || !vdev->vtarget || vdev->vtarget->deleted) {
  938. SCpnt->result = DID_NO_CONNECT << 16;
  939. done(SCpnt);
  940. return 0;
  941. }
  942. // scsi_print_command(SCpnt);
  943. return mptscsih_qcmd(SCpnt,done);
  944. }
  945. static struct scsi_host_template mptsas_driver_template = {
  946. .module = THIS_MODULE,
  947. .proc_name = "mptsas",
  948. .proc_info = mptscsih_proc_info,
  949. .name = "MPT SPI Host",
  950. .info = mptscsih_info,
  951. .queuecommand = mptsas_qcmd,
  952. .target_alloc = mptsas_target_alloc,
  953. .slave_alloc = mptsas_slave_alloc,
  954. .slave_configure = mptsas_slave_configure,
  955. .target_destroy = mptsas_target_destroy,
  956. .slave_destroy = mptscsih_slave_destroy,
  957. .change_queue_depth = mptscsih_change_queue_depth,
  958. .eh_abort_handler = mptscsih_abort,
  959. .eh_device_reset_handler = mptscsih_dev_reset,
  960. .eh_bus_reset_handler = mptscsih_bus_reset,
  961. .eh_host_reset_handler = mptscsih_host_reset,
  962. .bios_param = mptscsih_bios_param,
  963. .can_queue = MPT_FC_CAN_QUEUE,
  964. .this_id = -1,
  965. .sg_tablesize = MPT_SCSI_SG_DEPTH,
  966. .max_sectors = 8192,
  967. .cmd_per_lun = 7,
  968. .use_clustering = ENABLE_CLUSTERING,
  969. .shost_attrs = mptscsih_host_attrs,
  970. };
  971. static int mptsas_get_linkerrors(struct sas_phy *phy)
  972. {
  973. MPT_ADAPTER *ioc = phy_to_ioc(phy);
  974. ConfigExtendedPageHeader_t hdr;
  975. CONFIGPARMS cfg;
  976. SasPhyPage1_t *buffer;
  977. dma_addr_t dma_handle;
  978. int error;
  979. /* FIXME: only have link errors on local phys */
  980. if (!scsi_is_sas_phy_local(phy))
  981. return -EINVAL;
  982. hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
  983. hdr.ExtPageLength = 0;
  984. hdr.PageNumber = 1 /* page number 1*/;
  985. hdr.Reserved1 = 0;
  986. hdr.Reserved2 = 0;
  987. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  988. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
  989. cfg.cfghdr.ehdr = &hdr;
  990. cfg.physAddr = -1;
  991. cfg.pageAddr = phy->identify.phy_identifier;
  992. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  993. cfg.dir = 0; /* read */
  994. cfg.timeout = 10;
  995. error = mpt_config(ioc, &cfg);
  996. if (error)
  997. return error;
  998. if (!hdr.ExtPageLength)
  999. return -ENXIO;
  1000. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1001. &dma_handle);
  1002. if (!buffer)
  1003. return -ENOMEM;
  1004. cfg.physAddr = dma_handle;
  1005. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1006. error = mpt_config(ioc, &cfg);
  1007. if (error)
  1008. goto out_free_consistent;
  1009. mptsas_print_phy_pg1(ioc, buffer);
  1010. phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
  1011. phy->running_disparity_error_count =
  1012. le32_to_cpu(buffer->RunningDisparityErrorCount);
  1013. phy->loss_of_dword_sync_count =
  1014. le32_to_cpu(buffer->LossDwordSynchCount);
  1015. phy->phy_reset_problem_count =
  1016. le32_to_cpu(buffer->PhyResetProblemCount);
  1017. out_free_consistent:
  1018. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1019. buffer, dma_handle);
  1020. return error;
  1021. }
  1022. static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
  1023. MPT_FRAME_HDR *reply)
  1024. {
  1025. ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_COMMAND_GOOD;
  1026. if (reply != NULL) {
  1027. ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_RF_VALID;
  1028. memcpy(ioc->sas_mgmt.reply, reply,
  1029. min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
  1030. }
  1031. complete(&ioc->sas_mgmt.done);
  1032. return 1;
  1033. }
  1034. static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
  1035. {
  1036. MPT_ADAPTER *ioc = phy_to_ioc(phy);
  1037. SasIoUnitControlRequest_t *req;
  1038. SasIoUnitControlReply_t *reply;
  1039. MPT_FRAME_HDR *mf;
  1040. MPIHeader_t *hdr;
  1041. unsigned long timeleft;
  1042. int error = -ERESTARTSYS;
  1043. /* FIXME: fusion doesn't allow non-local phy reset */
  1044. if (!scsi_is_sas_phy_local(phy))
  1045. return -EINVAL;
  1046. /* not implemented for expanders */
  1047. if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
  1048. return -ENXIO;
  1049. if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
  1050. goto out;
  1051. mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
  1052. if (!mf) {
  1053. error = -ENOMEM;
  1054. goto out_unlock;
  1055. }
  1056. hdr = (MPIHeader_t *) mf;
  1057. req = (SasIoUnitControlRequest_t *)mf;
  1058. memset(req, 0, sizeof(SasIoUnitControlRequest_t));
  1059. req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
  1060. req->MsgContext = hdr->MsgContext;
  1061. req->Operation = hard_reset ?
  1062. MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
  1063. req->PhyNum = phy->identify.phy_identifier;
  1064. mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
  1065. timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
  1066. 10 * HZ);
  1067. if (!timeleft) {
  1068. /* On timeout reset the board */
  1069. mpt_free_msg_frame(ioc, mf);
  1070. mpt_HardResetHandler(ioc, CAN_SLEEP);
  1071. error = -ETIMEDOUT;
  1072. goto out_unlock;
  1073. }
  1074. /* a reply frame is expected */
  1075. if ((ioc->sas_mgmt.status &
  1076. MPT_IOCTL_STATUS_RF_VALID) == 0) {
  1077. error = -ENXIO;
  1078. goto out_unlock;
  1079. }
  1080. /* process the completed Reply Message Frame */
  1081. reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
  1082. if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
  1083. printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
  1084. __FUNCTION__,
  1085. reply->IOCStatus,
  1086. reply->IOCLogInfo);
  1087. error = -ENXIO;
  1088. goto out_unlock;
  1089. }
  1090. error = 0;
  1091. out_unlock:
  1092. mutex_unlock(&ioc->sas_mgmt.mutex);
  1093. out:
  1094. return error;
  1095. }
  1096. static int
  1097. mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
  1098. {
  1099. MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
  1100. int i, error;
  1101. struct mptsas_portinfo *p;
  1102. struct mptsas_enclosure enclosure_info;
  1103. u64 enclosure_handle;
  1104. mutex_lock(&ioc->sas_topology_mutex);
  1105. list_for_each_entry(p, &ioc->sas_topology, list) {
  1106. for (i = 0; i < p->num_phys; i++) {
  1107. if (p->phy_info[i].attached.sas_address ==
  1108. rphy->identify.sas_address) {
  1109. enclosure_handle = p->phy_info[i].
  1110. attached.handle_enclosure;
  1111. goto found_info;
  1112. }
  1113. }
  1114. }
  1115. mutex_unlock(&ioc->sas_topology_mutex);
  1116. return -ENXIO;
  1117. found_info:
  1118. mutex_unlock(&ioc->sas_topology_mutex);
  1119. memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
  1120. error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
  1121. (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
  1122. MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
  1123. if (!error)
  1124. *identifier = enclosure_info.enclosure_logical_id;
  1125. return error;
  1126. }
  1127. static int
  1128. mptsas_get_bay_identifier(struct sas_rphy *rphy)
  1129. {
  1130. MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
  1131. struct mptsas_portinfo *p;
  1132. int i, rc;
  1133. mutex_lock(&ioc->sas_topology_mutex);
  1134. list_for_each_entry(p, &ioc->sas_topology, list) {
  1135. for (i = 0; i < p->num_phys; i++) {
  1136. if (p->phy_info[i].attached.sas_address ==
  1137. rphy->identify.sas_address) {
  1138. rc = p->phy_info[i].attached.slot;
  1139. goto out;
  1140. }
  1141. }
  1142. }
  1143. rc = -ENXIO;
  1144. out:
  1145. mutex_unlock(&ioc->sas_topology_mutex);
  1146. return rc;
  1147. }
  1148. static struct sas_function_template mptsas_transport_functions = {
  1149. .get_linkerrors = mptsas_get_linkerrors,
  1150. .get_enclosure_identifier = mptsas_get_enclosure_identifier,
  1151. .get_bay_identifier = mptsas_get_bay_identifier,
  1152. .phy_reset = mptsas_phy_reset,
  1153. };
  1154. static struct scsi_transport_template *mptsas_transport_template;
  1155. static int
  1156. mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
  1157. {
  1158. ConfigExtendedPageHeader_t hdr;
  1159. CONFIGPARMS cfg;
  1160. SasIOUnitPage0_t *buffer;
  1161. dma_addr_t dma_handle;
  1162. int error, i;
  1163. hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
  1164. hdr.ExtPageLength = 0;
  1165. hdr.PageNumber = 0;
  1166. hdr.Reserved1 = 0;
  1167. hdr.Reserved2 = 0;
  1168. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1169. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  1170. cfg.cfghdr.ehdr = &hdr;
  1171. cfg.physAddr = -1;
  1172. cfg.pageAddr = 0;
  1173. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1174. cfg.dir = 0; /* read */
  1175. cfg.timeout = 10;
  1176. error = mpt_config(ioc, &cfg);
  1177. if (error)
  1178. goto out;
  1179. if (!hdr.ExtPageLength) {
  1180. error = -ENXIO;
  1181. goto out;
  1182. }
  1183. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1184. &dma_handle);
  1185. if (!buffer) {
  1186. error = -ENOMEM;
  1187. goto out;
  1188. }
  1189. cfg.physAddr = dma_handle;
  1190. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1191. error = mpt_config(ioc, &cfg);
  1192. if (error)
  1193. goto out_free_consistent;
  1194. port_info->num_phys = buffer->NumPhys;
  1195. port_info->phy_info = kcalloc(port_info->num_phys,
  1196. sizeof(*port_info->phy_info),GFP_KERNEL);
  1197. if (!port_info->phy_info) {
  1198. error = -ENOMEM;
  1199. goto out_free_consistent;
  1200. }
  1201. ioc->nvdata_version_persistent =
  1202. le16_to_cpu(buffer->NvdataVersionPersistent);
  1203. ioc->nvdata_version_default =
  1204. le16_to_cpu(buffer->NvdataVersionDefault);
  1205. for (i = 0; i < port_info->num_phys; i++) {
  1206. mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
  1207. port_info->phy_info[i].phy_id = i;
  1208. port_info->phy_info[i].port_id =
  1209. buffer->PhyData[i].Port;
  1210. port_info->phy_info[i].negotiated_link_rate =
  1211. buffer->PhyData[i].NegotiatedLinkRate;
  1212. port_info->phy_info[i].portinfo = port_info;
  1213. port_info->phy_info[i].handle =
  1214. le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
  1215. }
  1216. out_free_consistent:
  1217. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1218. buffer, dma_handle);
  1219. out:
  1220. return error;
  1221. }
  1222. static int
  1223. mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
  1224. {
  1225. ConfigExtendedPageHeader_t hdr;
  1226. CONFIGPARMS cfg;
  1227. SasIOUnitPage1_t *buffer;
  1228. dma_addr_t dma_handle;
  1229. int error;
  1230. u16 device_missing_delay;
  1231. memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
  1232. memset(&cfg, 0, sizeof(CONFIGPARMS));
  1233. cfg.cfghdr.ehdr = &hdr;
  1234. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1235. cfg.timeout = 10;
  1236. cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1237. cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  1238. cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
  1239. cfg.cfghdr.ehdr->PageNumber = 1;
  1240. error = mpt_config(ioc, &cfg);
  1241. if (error)
  1242. goto out;
  1243. if (!hdr.ExtPageLength) {
  1244. error = -ENXIO;
  1245. goto out;
  1246. }
  1247. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1248. &dma_handle);
  1249. if (!buffer) {
  1250. error = -ENOMEM;
  1251. goto out;
  1252. }
  1253. cfg.physAddr = dma_handle;
  1254. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1255. error = mpt_config(ioc, &cfg);
  1256. if (error)
  1257. goto out_free_consistent;
  1258. ioc->io_missing_delay =
  1259. le16_to_cpu(buffer->IODeviceMissingDelay);
  1260. device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay);
  1261. ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
  1262. (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
  1263. device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  1264. out_free_consistent:
  1265. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1266. buffer, dma_handle);
  1267. out:
  1268. return error;
  1269. }
  1270. static int
  1271. mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
  1272. u32 form, u32 form_specific)
  1273. {
  1274. ConfigExtendedPageHeader_t hdr;
  1275. CONFIGPARMS cfg;
  1276. SasPhyPage0_t *buffer;
  1277. dma_addr_t dma_handle;
  1278. int error;
  1279. hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
  1280. hdr.ExtPageLength = 0;
  1281. hdr.PageNumber = 0;
  1282. hdr.Reserved1 = 0;
  1283. hdr.Reserved2 = 0;
  1284. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1285. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
  1286. cfg.cfghdr.ehdr = &hdr;
  1287. cfg.dir = 0; /* read */
  1288. cfg.timeout = 10;
  1289. /* Get Phy Pg 0 for each Phy. */
  1290. cfg.physAddr = -1;
  1291. cfg.pageAddr = form + form_specific;
  1292. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1293. error = mpt_config(ioc, &cfg);
  1294. if (error)
  1295. goto out;
  1296. if (!hdr.ExtPageLength) {
  1297. error = -ENXIO;
  1298. goto out;
  1299. }
  1300. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1301. &dma_handle);
  1302. if (!buffer) {
  1303. error = -ENOMEM;
  1304. goto out;
  1305. }
  1306. cfg.physAddr = dma_handle;
  1307. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1308. error = mpt_config(ioc, &cfg);
  1309. if (error)
  1310. goto out_free_consistent;
  1311. mptsas_print_phy_pg0(ioc, buffer);
  1312. phy_info->hw_link_rate = buffer->HwLinkRate;
  1313. phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
  1314. phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
  1315. phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
  1316. out_free_consistent:
  1317. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1318. buffer, dma_handle);
  1319. out:
  1320. return error;
  1321. }
  1322. static int
  1323. mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
  1324. u32 form, u32 form_specific)
  1325. {
  1326. ConfigExtendedPageHeader_t hdr;
  1327. CONFIGPARMS cfg;
  1328. SasDevicePage0_t *buffer;
  1329. dma_addr_t dma_handle;
  1330. __le64 sas_address;
  1331. int error=0;
  1332. if (ioc->sas_discovery_runtime &&
  1333. mptsas_is_end_device(device_info))
  1334. goto out;
  1335. hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
  1336. hdr.ExtPageLength = 0;
  1337. hdr.PageNumber = 0;
  1338. hdr.Reserved1 = 0;
  1339. hdr.Reserved2 = 0;
  1340. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1341. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
  1342. cfg.cfghdr.ehdr = &hdr;
  1343. cfg.pageAddr = form + form_specific;
  1344. cfg.physAddr = -1;
  1345. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1346. cfg.dir = 0; /* read */
  1347. cfg.timeout = 10;
  1348. memset(device_info, 0, sizeof(struct mptsas_devinfo));
  1349. error = mpt_config(ioc, &cfg);
  1350. if (error)
  1351. goto out;
  1352. if (!hdr.ExtPageLength) {
  1353. error = -ENXIO;
  1354. goto out;
  1355. }
  1356. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1357. &dma_handle);
  1358. if (!buffer) {
  1359. error = -ENOMEM;
  1360. goto out;
  1361. }
  1362. cfg.physAddr = dma_handle;
  1363. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1364. error = mpt_config(ioc, &cfg);
  1365. if (error)
  1366. goto out_free_consistent;
  1367. mptsas_print_device_pg0(ioc, buffer);
  1368. device_info->handle = le16_to_cpu(buffer->DevHandle);
  1369. device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
  1370. device_info->handle_enclosure =
  1371. le16_to_cpu(buffer->EnclosureHandle);
  1372. device_info->slot = le16_to_cpu(buffer->Slot);
  1373. device_info->phy_id = buffer->PhyNum;
  1374. device_info->port_id = buffer->PhysicalPort;
  1375. device_info->id = buffer->TargetID;
  1376. device_info->phys_disk_num = ~0;
  1377. device_info->channel = buffer->Bus;
  1378. memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
  1379. device_info->sas_address = le64_to_cpu(sas_address);
  1380. device_info->device_info =
  1381. le32_to_cpu(buffer->DeviceInfo);
  1382. out_free_consistent:
  1383. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1384. buffer, dma_handle);
  1385. out:
  1386. return error;
  1387. }
  1388. static int
  1389. mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
  1390. u32 form, u32 form_specific)
  1391. {
  1392. ConfigExtendedPageHeader_t hdr;
  1393. CONFIGPARMS cfg;
  1394. SasExpanderPage0_t *buffer;
  1395. dma_addr_t dma_handle;
  1396. int i, error;
  1397. hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
  1398. hdr.ExtPageLength = 0;
  1399. hdr.PageNumber = 0;
  1400. hdr.Reserved1 = 0;
  1401. hdr.Reserved2 = 0;
  1402. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1403. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
  1404. cfg.cfghdr.ehdr = &hdr;
  1405. cfg.physAddr = -1;
  1406. cfg.pageAddr = form + form_specific;
  1407. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1408. cfg.dir = 0; /* read */
  1409. cfg.timeout = 10;
  1410. memset(port_info, 0, sizeof(struct mptsas_portinfo));
  1411. error = mpt_config(ioc, &cfg);
  1412. if (error)
  1413. goto out;
  1414. if (!hdr.ExtPageLength) {
  1415. error = -ENXIO;
  1416. goto out;
  1417. }
  1418. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1419. &dma_handle);
  1420. if (!buffer) {
  1421. error = -ENOMEM;
  1422. goto out;
  1423. }
  1424. cfg.physAddr = dma_handle;
  1425. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1426. error = mpt_config(ioc, &cfg);
  1427. if (error)
  1428. goto out_free_consistent;
  1429. /* save config data */
  1430. port_info->num_phys = buffer->NumPhys;
  1431. port_info->phy_info = kcalloc(port_info->num_phys,
  1432. sizeof(*port_info->phy_info),GFP_KERNEL);
  1433. if (!port_info->phy_info) {
  1434. error = -ENOMEM;
  1435. goto out_free_consistent;
  1436. }
  1437. for (i = 0; i < port_info->num_phys; i++) {
  1438. port_info->phy_info[i].portinfo = port_info;
  1439. port_info->phy_info[i].handle =
  1440. le16_to_cpu(buffer->DevHandle);
  1441. }
  1442. out_free_consistent:
  1443. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1444. buffer, dma_handle);
  1445. out:
  1446. return error;
  1447. }
  1448. static int
  1449. mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
  1450. u32 form, u32 form_specific)
  1451. {
  1452. ConfigExtendedPageHeader_t hdr;
  1453. CONFIGPARMS cfg;
  1454. SasExpanderPage1_t *buffer;
  1455. dma_addr_t dma_handle;
  1456. int error=0;
  1457. if (ioc->sas_discovery_runtime &&
  1458. mptsas_is_end_device(&phy_info->attached))
  1459. goto out;
  1460. hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
  1461. hdr.ExtPageLength = 0;
  1462. hdr.PageNumber = 1;
  1463. hdr.Reserved1 = 0;
  1464. hdr.Reserved2 = 0;
  1465. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  1466. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
  1467. cfg.cfghdr.ehdr = &hdr;
  1468. cfg.physAddr = -1;
  1469. cfg.pageAddr = form + form_specific;
  1470. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  1471. cfg.dir = 0; /* read */
  1472. cfg.timeout = 10;
  1473. error = mpt_config(ioc, &cfg);
  1474. if (error)
  1475. goto out;
  1476. if (!hdr.ExtPageLength) {
  1477. error = -ENXIO;
  1478. goto out;
  1479. }
  1480. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1481. &dma_handle);
  1482. if (!buffer) {
  1483. error = -ENOMEM;
  1484. goto out;
  1485. }
  1486. cfg.physAddr = dma_handle;
  1487. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  1488. error = mpt_config(ioc, &cfg);
  1489. if (error)
  1490. goto out_free_consistent;
  1491. mptsas_print_expander_pg1(ioc, buffer);
  1492. /* save config data */
  1493. phy_info->phy_id = buffer->PhyIdentifier;
  1494. phy_info->port_id = buffer->PhysicalPort;
  1495. phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
  1496. phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
  1497. phy_info->hw_link_rate = buffer->HwLinkRate;
  1498. phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
  1499. phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
  1500. out_free_consistent:
  1501. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  1502. buffer, dma_handle);
  1503. out:
  1504. return error;
  1505. }
  1506. static void
  1507. mptsas_parse_device_info(struct sas_identify *identify,
  1508. struct mptsas_devinfo *device_info)
  1509. {
  1510. u16 protocols;
  1511. identify->sas_address = device_info->sas_address;
  1512. identify->phy_identifier = device_info->phy_id;
  1513. /*
  1514. * Fill in Phy Initiator Port Protocol.
  1515. * Bits 6:3, more than one bit can be set, fall through cases.
  1516. */
  1517. protocols = device_info->device_info & 0x78;
  1518. identify->initiator_port_protocols = 0;
  1519. if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
  1520. identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
  1521. if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
  1522. identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
  1523. if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
  1524. identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
  1525. if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
  1526. identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
  1527. /*
  1528. * Fill in Phy Target Port Protocol.
  1529. * Bits 10:7, more than one bit can be set, fall through cases.
  1530. */
  1531. protocols = device_info->device_info & 0x780;
  1532. identify->target_port_protocols = 0;
  1533. if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
  1534. identify->target_port_protocols |= SAS_PROTOCOL_SSP;
  1535. if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
  1536. identify->target_port_protocols |= SAS_PROTOCOL_STP;
  1537. if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
  1538. identify->target_port_protocols |= SAS_PROTOCOL_SMP;
  1539. if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
  1540. identify->target_port_protocols |= SAS_PROTOCOL_SATA;
  1541. /*
  1542. * Fill in Attached device type.
  1543. */
  1544. switch (device_info->device_info &
  1545. MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
  1546. case MPI_SAS_DEVICE_INFO_NO_DEVICE:
  1547. identify->device_type = SAS_PHY_UNUSED;
  1548. break;
  1549. case MPI_SAS_DEVICE_INFO_END_DEVICE:
  1550. identify->device_type = SAS_END_DEVICE;
  1551. break;
  1552. case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
  1553. identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
  1554. break;
  1555. case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
  1556. identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
  1557. break;
  1558. }
  1559. }
  1560. static int mptsas_probe_one_phy(struct device *dev,
  1561. struct mptsas_phyinfo *phy_info, int index, int local)
  1562. {
  1563. MPT_ADAPTER *ioc;
  1564. struct sas_phy *phy;
  1565. struct sas_port *port;
  1566. int error = 0;
  1567. if (!dev) {
  1568. error = -ENODEV;
  1569. goto out;
  1570. }
  1571. if (!phy_info->phy) {
  1572. phy = sas_phy_alloc(dev, index);
  1573. if (!phy) {
  1574. error = -ENOMEM;
  1575. goto out;
  1576. }
  1577. } else
  1578. phy = phy_info->phy;
  1579. mptsas_parse_device_info(&phy->identify, &phy_info->identify);
  1580. /*
  1581. * Set Negotiated link rate.
  1582. */
  1583. switch (phy_info->negotiated_link_rate) {
  1584. case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
  1585. phy->negotiated_linkrate = SAS_PHY_DISABLED;
  1586. break;
  1587. case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
  1588. phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
  1589. break;
  1590. case MPI_SAS_IOUNIT0_RATE_1_5:
  1591. phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
  1592. break;
  1593. case MPI_SAS_IOUNIT0_RATE_3_0:
  1594. phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
  1595. break;
  1596. case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
  1597. case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
  1598. default:
  1599. phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
  1600. break;
  1601. }
  1602. /*
  1603. * Set Max hardware link rate.
  1604. */
  1605. switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
  1606. case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
  1607. phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
  1608. break;
  1609. case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
  1610. phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
  1611. break;
  1612. default:
  1613. break;
  1614. }
  1615. /*
  1616. * Set Max programmed link rate.
  1617. */
  1618. switch (phy_info->programmed_link_rate &
  1619. MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
  1620. case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
  1621. phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  1622. break;
  1623. case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
  1624. phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
  1625. break;
  1626. default:
  1627. break;
  1628. }
  1629. /*
  1630. * Set Min hardware link rate.
  1631. */
  1632. switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
  1633. case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
  1634. phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
  1635. break;
  1636. case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
  1637. phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
  1638. break;
  1639. default:
  1640. break;
  1641. }
  1642. /*
  1643. * Set Min programmed link rate.
  1644. */
  1645. switch (phy_info->programmed_link_rate &
  1646. MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
  1647. case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
  1648. phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
  1649. break;
  1650. case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
  1651. phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
  1652. break;
  1653. default:
  1654. break;
  1655. }
  1656. if (!phy_info->phy) {
  1657. error = sas_phy_add(phy);
  1658. if (error) {
  1659. sas_phy_free(phy);
  1660. goto out;
  1661. }
  1662. phy_info->phy = phy;
  1663. }
  1664. if (!phy_info->attached.handle ||
  1665. !phy_info->port_details)
  1666. goto out;
  1667. port = mptsas_get_port(phy_info);
  1668. ioc = phy_to_ioc(phy_info->phy);
  1669. if (phy_info->sas_port_add_phy) {
  1670. if (!port) {
  1671. port = sas_port_alloc_num(dev);
  1672. if (!port) {
  1673. error = -ENOMEM;
  1674. goto out;
  1675. }
  1676. error = sas_port_add(port);
  1677. if (error) {
  1678. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1679. "%s: exit at line=%d\n", ioc->name,
  1680. __FUNCTION__, __LINE__));
  1681. goto out;
  1682. }
  1683. mptsas_set_port(ioc, phy_info, port);
  1684. dsaswideprintk(ioc, printk(KERN_DEBUG
  1685. "sas_port_alloc: port=%p dev=%p port_id=%d\n",
  1686. port, dev, port->port_identifier));
  1687. }
  1688. dsaswideprintk(ioc, printk(KERN_DEBUG "sas_port_add_phy: phy_id=%d\n",
  1689. phy_info->phy_id));
  1690. sas_port_add_phy(port, phy_info->phy);
  1691. phy_info->sas_port_add_phy = 0;
  1692. }
  1693. if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
  1694. struct sas_rphy *rphy;
  1695. struct device *parent;
  1696. struct sas_identify identify;
  1697. parent = dev->parent->parent;
  1698. /*
  1699. * Let the hotplug_work thread handle processing
  1700. * the adding/removing of devices that occur
  1701. * after start of day.
  1702. */
  1703. if (ioc->sas_discovery_runtime &&
  1704. mptsas_is_end_device(&phy_info->attached))
  1705. goto out;
  1706. mptsas_parse_device_info(&identify, &phy_info->attached);
  1707. if (scsi_is_host_device(parent)) {
  1708. struct mptsas_portinfo *port_info;
  1709. int i;
  1710. mutex_lock(&ioc->sas_topology_mutex);
  1711. port_info = mptsas_find_portinfo_by_handle(ioc,
  1712. ioc->handle);
  1713. mutex_unlock(&ioc->sas_topology_mutex);
  1714. for (i = 0; i < port_info->num_phys; i++)
  1715. if (port_info->phy_info[i].identify.sas_address ==
  1716. identify.sas_address) {
  1717. sas_port_mark_backlink(port);
  1718. goto out;
  1719. }
  1720. } else if (scsi_is_sas_rphy(parent)) {
  1721. struct sas_rphy *parent_rphy = dev_to_rphy(parent);
  1722. if (identify.sas_address ==
  1723. parent_rphy->identify.sas_address) {
  1724. sas_port_mark_backlink(port);
  1725. goto out;
  1726. }
  1727. }
  1728. switch (identify.device_type) {
  1729. case SAS_END_DEVICE:
  1730. rphy = sas_end_device_alloc(port);
  1731. break;
  1732. case SAS_EDGE_EXPANDER_DEVICE:
  1733. case SAS_FANOUT_EXPANDER_DEVICE:
  1734. rphy = sas_expander_alloc(port, identify.device_type);
  1735. break;
  1736. default:
  1737. rphy = NULL;
  1738. break;
  1739. }
  1740. if (!rphy) {
  1741. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1742. "%s: exit at line=%d\n", ioc->name,
  1743. __FUNCTION__, __LINE__));
  1744. goto out;
  1745. }
  1746. rphy->identify = identify;
  1747. error = sas_rphy_add(rphy);
  1748. if (error) {
  1749. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  1750. "%s: exit at line=%d\n", ioc->name,
  1751. __FUNCTION__, __LINE__));
  1752. sas_rphy_free(rphy);
  1753. goto out;
  1754. }
  1755. mptsas_set_rphy(ioc, phy_info, rphy);
  1756. }
  1757. out:
  1758. return error;
  1759. }
  1760. static int
  1761. mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
  1762. {
  1763. struct mptsas_portinfo *port_info, *hba;
  1764. int error = -ENOMEM, i;
  1765. hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
  1766. if (! hba)
  1767. goto out;
  1768. error = mptsas_sas_io_unit_pg0(ioc, hba);
  1769. if (error)
  1770. goto out_free_port_info;
  1771. mptsas_sas_io_unit_pg1(ioc);
  1772. mutex_lock(&ioc->sas_topology_mutex);
  1773. ioc->handle = hba->phy_info[0].handle;
  1774. port_info = mptsas_find_portinfo_by_handle(ioc, ioc->handle);
  1775. if (!port_info) {
  1776. port_info = hba;
  1777. list_add_tail(&port_info->list, &ioc->sas_topology);
  1778. } else {
  1779. for (i = 0; i < hba->num_phys; i++) {
  1780. port_info->phy_info[i].negotiated_link_rate =
  1781. hba->phy_info[i].negotiated_link_rate;
  1782. port_info->phy_info[i].handle =
  1783. hba->phy_info[i].handle;
  1784. port_info->phy_info[i].port_id =
  1785. hba->phy_info[i].port_id;
  1786. }
  1787. kfree(hba->phy_info);
  1788. kfree(hba);
  1789. hba = NULL;
  1790. }
  1791. mutex_unlock(&ioc->sas_topology_mutex);
  1792. for (i = 0; i < port_info->num_phys; i++) {
  1793. mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
  1794. (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
  1795. MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
  1796. mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
  1797. (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
  1798. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  1799. port_info->phy_info[i].handle);
  1800. port_info->phy_info[i].identify.phy_id =
  1801. port_info->phy_info[i].phy_id = i;
  1802. if (port_info->phy_info[i].attached.handle)
  1803. mptsas_sas_device_pg0(ioc,
  1804. &port_info->phy_info[i].attached,
  1805. (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
  1806. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  1807. port_info->phy_info[i].attached.handle);
  1808. }
  1809. mptsas_setup_wide_ports(ioc, port_info);
  1810. for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
  1811. mptsas_probe_one_phy(&ioc->sh->shost_gendev,
  1812. &port_info->phy_info[i], ioc->sas_index, 1);
  1813. return 0;
  1814. out_free_port_info:
  1815. kfree(hba);
  1816. out:
  1817. return error;
  1818. }
  1819. static int
  1820. mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
  1821. {
  1822. struct mptsas_portinfo *port_info, *p, *ex;
  1823. struct device *parent;
  1824. struct sas_rphy *rphy;
  1825. int error = -ENOMEM, i, j;
  1826. ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
  1827. if (!ex)
  1828. goto out;
  1829. error = mptsas_sas_expander_pg0(ioc, ex,
  1830. (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
  1831. MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
  1832. if (error)
  1833. goto out_free_port_info;
  1834. *handle = ex->phy_info[0].handle;
  1835. mutex_lock(&ioc->sas_topology_mutex);
  1836. port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
  1837. if (!port_info) {
  1838. port_info = ex;
  1839. list_add_tail(&port_info->list, &ioc->sas_topology);
  1840. } else {
  1841. for (i = 0; i < ex->num_phys; i++) {
  1842. port_info->phy_info[i].handle =
  1843. ex->phy_info[i].handle;
  1844. port_info->phy_info[i].port_id =
  1845. ex->phy_info[i].port_id;
  1846. }
  1847. kfree(ex->phy_info);
  1848. kfree(ex);
  1849. ex = NULL;
  1850. }
  1851. mutex_unlock(&ioc->sas_topology_mutex);
  1852. for (i = 0; i < port_info->num_phys; i++) {
  1853. mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
  1854. (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
  1855. MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
  1856. if (port_info->phy_info[i].identify.handle) {
  1857. mptsas_sas_device_pg0(ioc,
  1858. &port_info->phy_info[i].identify,
  1859. (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
  1860. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  1861. port_info->phy_info[i].identify.handle);
  1862. port_info->phy_info[i].identify.phy_id =
  1863. port_info->phy_info[i].phy_id;
  1864. }
  1865. if (port_info->phy_info[i].attached.handle) {
  1866. mptsas_sas_device_pg0(ioc,
  1867. &port_info->phy_info[i].attached,
  1868. (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
  1869. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  1870. port_info->phy_info[i].attached.handle);
  1871. port_info->phy_info[i].attached.phy_id =
  1872. port_info->phy_info[i].phy_id;
  1873. }
  1874. }
  1875. parent = &ioc->sh->shost_gendev;
  1876. for (i = 0; i < port_info->num_phys; i++) {
  1877. mutex_lock(&ioc->sas_topology_mutex);
  1878. list_for_each_entry(p, &ioc->sas_topology, list) {
  1879. for (j = 0; j < p->num_phys; j++) {
  1880. if (port_info->phy_info[i].identify.handle !=
  1881. p->phy_info[j].attached.handle)
  1882. continue;
  1883. rphy = mptsas_get_rphy(&p->phy_info[j]);
  1884. parent = &rphy->dev;
  1885. }
  1886. }
  1887. mutex_unlock(&ioc->sas_topology_mutex);
  1888. }
  1889. mptsas_setup_wide_ports(ioc, port_info);
  1890. for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
  1891. mptsas_probe_one_phy(parent, &port_info->phy_info[i],
  1892. ioc->sas_index, 0);
  1893. return 0;
  1894. out_free_port_info:
  1895. if (ex) {
  1896. kfree(ex->phy_info);
  1897. kfree(ex);
  1898. }
  1899. out:
  1900. return error;
  1901. }
  1902. /*
  1903. * mptsas_delete_expander_phys
  1904. *
  1905. *
  1906. * This will traverse topology, and remove expanders
  1907. * that are no longer present
  1908. */
  1909. static void
  1910. mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
  1911. {
  1912. struct mptsas_portinfo buffer;
  1913. struct mptsas_portinfo *port_info, *n, *parent;
  1914. struct mptsas_phyinfo *phy_info;
  1915. struct sas_port * port;
  1916. int i;
  1917. u64 expander_sas_address;
  1918. mutex_lock(&ioc->sas_topology_mutex);
  1919. list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
  1920. if (port_info->phy_info &&
  1921. (!(port_info->phy_info[0].identify.device_info &
  1922. MPI_SAS_DEVICE_INFO_SMP_TARGET)))
  1923. continue;
  1924. if (mptsas_sas_expander_pg0(ioc, &buffer,
  1925. (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
  1926. MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
  1927. port_info->phy_info[0].handle)) {
  1928. /*
  1929. * Obtain the port_info instance to the parent port
  1930. */
  1931. parent = mptsas_find_portinfo_by_handle(ioc,
  1932. port_info->phy_info[0].identify.handle_parent);
  1933. if (!parent)
  1934. goto next_port;
  1935. expander_sas_address =
  1936. port_info->phy_info[0].identify.sas_address;
  1937. /*
  1938. * Delete rphys in the parent that point
  1939. * to this expander. The transport layer will
  1940. * cleanup all the children.
  1941. */
  1942. phy_info = parent->phy_info;
  1943. for (i = 0; i < parent->num_phys; i++, phy_info++) {
  1944. port = mptsas_get_port(phy_info);
  1945. if (!port)
  1946. continue;
  1947. if (phy_info->attached.sas_address !=
  1948. expander_sas_address)
  1949. continue;
  1950. dsaswideprintk(ioc,
  1951. dev_printk(KERN_DEBUG, &port->dev,
  1952. "delete port (%d)\n", port->port_identifier));
  1953. sas_port_delete(port);
  1954. mptsas_port_delete(ioc, phy_info->port_details);
  1955. }
  1956. next_port:
  1957. phy_info = port_info->phy_info;
  1958. for (i = 0; i < port_info->num_phys; i++, phy_info++)
  1959. mptsas_port_delete(ioc, phy_info->port_details);
  1960. list_del(&port_info->list);
  1961. kfree(port_info->phy_info);
  1962. kfree(port_info);
  1963. }
  1964. /*
  1965. * Free this memory allocated from inside
  1966. * mptsas_sas_expander_pg0
  1967. */
  1968. kfree(buffer.phy_info);
  1969. }
  1970. mutex_unlock(&ioc->sas_topology_mutex);
  1971. }
  1972. /*
  1973. * Start of day discovery
  1974. */
  1975. static void
  1976. mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
  1977. {
  1978. u32 handle = 0xFFFF;
  1979. int i;
  1980. mutex_lock(&ioc->sas_discovery_mutex);
  1981. mptsas_probe_hba_phys(ioc);
  1982. while (!mptsas_probe_expander_phys(ioc, &handle))
  1983. ;
  1984. /*
  1985. Reporting RAID volumes.
  1986. */
  1987. if (!ioc->ir_firmware)
  1988. goto out;
  1989. if (!ioc->raid_data.pIocPg2)
  1990. goto out;
  1991. if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
  1992. goto out;
  1993. for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
  1994. scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
  1995. ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
  1996. }
  1997. out:
  1998. mutex_unlock(&ioc->sas_discovery_mutex);
  1999. }
  2000. /*
  2001. * Work queue thread to handle Runtime discovery
  2002. * Mere purpose is the hot add/delete of expanders
  2003. *(Mutex UNLOCKED)
  2004. */
  2005. static void
  2006. __mptsas_discovery_work(MPT_ADAPTER *ioc)
  2007. {
  2008. u32 handle = 0xFFFF;
  2009. ioc->sas_discovery_runtime=1;
  2010. mptsas_delete_expander_phys(ioc);
  2011. mptsas_probe_hba_phys(ioc);
  2012. while (!mptsas_probe_expander_phys(ioc, &handle))
  2013. ;
  2014. ioc->sas_discovery_runtime=0;
  2015. }
  2016. /*
  2017. * Work queue thread to handle Runtime discovery
  2018. * Mere purpose is the hot add/delete of expanders
  2019. *(Mutex LOCKED)
  2020. */
  2021. static void
  2022. mptsas_discovery_work(struct work_struct *work)
  2023. {
  2024. struct mptsas_discovery_event *ev =
  2025. container_of(work, struct mptsas_discovery_event, work);
  2026. MPT_ADAPTER *ioc = ev->ioc;
  2027. mutex_lock(&ioc->sas_discovery_mutex);
  2028. __mptsas_discovery_work(ioc);
  2029. mutex_unlock(&ioc->sas_discovery_mutex);
  2030. kfree(ev);
  2031. }
  2032. static struct mptsas_phyinfo *
  2033. mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
  2034. {
  2035. struct mptsas_portinfo *port_info;
  2036. struct mptsas_phyinfo *phy_info = NULL;
  2037. int i;
  2038. mutex_lock(&ioc->sas_topology_mutex);
  2039. list_for_each_entry(port_info, &ioc->sas_topology, list) {
  2040. for (i = 0; i < port_info->num_phys; i++) {
  2041. if (!mptsas_is_end_device(
  2042. &port_info->phy_info[i].attached))
  2043. continue;
  2044. if (port_info->phy_info[i].attached.sas_address
  2045. != sas_address)
  2046. continue;
  2047. phy_info = &port_info->phy_info[i];
  2048. break;
  2049. }
  2050. }
  2051. mutex_unlock(&ioc->sas_topology_mutex);
  2052. return phy_info;
  2053. }
  2054. static struct mptsas_phyinfo *
  2055. mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u8 channel, u8 id)
  2056. {
  2057. struct mptsas_portinfo *port_info;
  2058. struct mptsas_phyinfo *phy_info = NULL;
  2059. int i;
  2060. mutex_lock(&ioc->sas_topology_mutex);
  2061. list_for_each_entry(port_info, &ioc->sas_topology, list) {
  2062. for (i = 0; i < port_info->num_phys; i++) {
  2063. if (!mptsas_is_end_device(
  2064. &port_info->phy_info[i].attached))
  2065. continue;
  2066. if (port_info->phy_info[i].attached.id != id)
  2067. continue;
  2068. if (port_info->phy_info[i].attached.channel != channel)
  2069. continue;
  2070. phy_info = &port_info->phy_info[i];
  2071. break;
  2072. }
  2073. }
  2074. mutex_unlock(&ioc->sas_topology_mutex);
  2075. return phy_info;
  2076. }
  2077. static struct mptsas_phyinfo *
  2078. mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
  2079. {
  2080. struct mptsas_portinfo *port_info;
  2081. struct mptsas_phyinfo *phy_info = NULL;
  2082. int i;
  2083. mutex_lock(&ioc->sas_topology_mutex);
  2084. list_for_each_entry(port_info, &ioc->sas_topology, list) {
  2085. for (i = 0; i < port_info->num_phys; i++) {
  2086. if (!mptsas_is_end_device(
  2087. &port_info->phy_info[i].attached))
  2088. continue;
  2089. if (port_info->phy_info[i].attached.phys_disk_num == ~0)
  2090. continue;
  2091. if (port_info->phy_info[i].attached.phys_disk_num != id)
  2092. continue;
  2093. if (port_info->phy_info[i].attached.channel != channel)
  2094. continue;
  2095. phy_info = &port_info->phy_info[i];
  2096. break;
  2097. }
  2098. }
  2099. mutex_unlock(&ioc->sas_topology_mutex);
  2100. return phy_info;
  2101. }
  2102. /*
  2103. * Work queue thread to clear the persitency table
  2104. */
  2105. static void
  2106. mptsas_persist_clear_table(struct work_struct *work)
  2107. {
  2108. MPT_ADAPTER *ioc = container_of(work, MPT_ADAPTER, sas_persist_task);
  2109. mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
  2110. }
  2111. static void
  2112. mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
  2113. {
  2114. int rc;
  2115. sdev->no_uld_attach = data ? 1 : 0;
  2116. rc = scsi_device_reprobe(sdev);
  2117. }
  2118. static void
  2119. mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
  2120. {
  2121. starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
  2122. mptsas_reprobe_lun);
  2123. }
  2124. static void
  2125. mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
  2126. {
  2127. CONFIGPARMS cfg;
  2128. ConfigPageHeader_t hdr;
  2129. dma_addr_t dma_handle;
  2130. pRaidVolumePage0_t buffer = NULL;
  2131. RaidPhysDiskPage0_t phys_disk;
  2132. int i;
  2133. struct mptsas_hotplug_event *ev;
  2134. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  2135. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  2136. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
  2137. cfg.pageAddr = (channel << 8) + id;
  2138. cfg.cfghdr.hdr = &hdr;
  2139. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  2140. if (mpt_config(ioc, &cfg) != 0)
  2141. goto out;
  2142. if (!hdr.PageLength)
  2143. goto out;
  2144. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  2145. &dma_handle);
  2146. if (!buffer)
  2147. goto out;
  2148. cfg.physAddr = dma_handle;
  2149. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  2150. if (mpt_config(ioc, &cfg) != 0)
  2151. goto out;
  2152. if (!(buffer->VolumeStatus.Flags &
  2153. MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
  2154. goto out;
  2155. if (!buffer->NumPhysDisks)
  2156. goto out;
  2157. for (i = 0; i < buffer->NumPhysDisks; i++) {
  2158. if (mpt_raid_phys_disk_pg0(ioc,
  2159. buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
  2160. continue;
  2161. ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
  2162. if (!ev) {
  2163. printk(KERN_WARNING "mptsas: lost hotplug event\n");
  2164. goto out;
  2165. }
  2166. INIT_WORK(&ev->work, mptsas_hotplug_work);
  2167. ev->ioc = ioc;
  2168. ev->id = phys_disk.PhysDiskID;
  2169. ev->channel = phys_disk.PhysDiskBus;
  2170. ev->phys_disk_num_valid = 1;
  2171. ev->phys_disk_num = phys_disk.PhysDiskNum;
  2172. ev->event_type = MPTSAS_ADD_DEVICE;
  2173. schedule_work(&ev->work);
  2174. }
  2175. out:
  2176. if (buffer)
  2177. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  2178. dma_handle);
  2179. }
  2180. /*
  2181. * Work queue thread to handle SAS hotplug events
  2182. */
  2183. static void
  2184. mptsas_hotplug_work(struct work_struct *work)
  2185. {
  2186. struct mptsas_hotplug_event *ev =
  2187. container_of(work, struct mptsas_hotplug_event, work);
  2188. MPT_ADAPTER *ioc = ev->ioc;
  2189. struct mptsas_phyinfo *phy_info;
  2190. struct sas_rphy *rphy;
  2191. struct sas_port *port;
  2192. struct scsi_device *sdev;
  2193. struct scsi_target * starget;
  2194. struct sas_identify identify;
  2195. char *ds = NULL;
  2196. struct mptsas_devinfo sas_device;
  2197. VirtTarget *vtarget;
  2198. VirtDevice *vdevice;
  2199. mutex_lock(&ioc->sas_discovery_mutex);
  2200. switch (ev->event_type) {
  2201. case MPTSAS_DEL_DEVICE:
  2202. phy_info = NULL;
  2203. if (ev->phys_disk_num_valid) {
  2204. if (ev->hidden_raid_component){
  2205. if (mptsas_sas_device_pg0(ioc, &sas_device,
  2206. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
  2207. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  2208. (ev->channel << 8) + ev->id)) {
  2209. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2210. "%s: exit at line=%d\n", ioc->name,
  2211. __FUNCTION__, __LINE__));
  2212. break;
  2213. }
  2214. phy_info = mptsas_find_phyinfo_by_sas_address(
  2215. ioc, sas_device.sas_address);
  2216. }else
  2217. phy_info = mptsas_find_phyinfo_by_phys_disk_num(
  2218. ioc, ev->channel, ev->phys_disk_num);
  2219. }
  2220. if (!phy_info)
  2221. phy_info = mptsas_find_phyinfo_by_target(ioc,
  2222. ev->channel, ev->id);
  2223. /*
  2224. * Sanity checks, for non-existing phys and remote rphys.
  2225. */
  2226. if (!phy_info){
  2227. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2228. "%s: exit at line=%d\n", ioc->name,
  2229. __FUNCTION__, __LINE__));
  2230. break;
  2231. }
  2232. if (!phy_info->port_details) {
  2233. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2234. "%s: exit at line=%d\n", ioc->name,
  2235. __FUNCTION__, __LINE__));
  2236. break;
  2237. }
  2238. rphy = mptsas_get_rphy(phy_info);
  2239. if (!rphy) {
  2240. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2241. "%s: exit at line=%d\n", ioc->name,
  2242. __FUNCTION__, __LINE__));
  2243. break;
  2244. }
  2245. port = mptsas_get_port(phy_info);
  2246. if (!port) {
  2247. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2248. "%s: exit at line=%d\n", ioc->name,
  2249. __FUNCTION__, __LINE__));
  2250. break;
  2251. }
  2252. starget = mptsas_get_starget(phy_info);
  2253. if (starget) {
  2254. vtarget = starget->hostdata;
  2255. if (!vtarget) {
  2256. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2257. "%s: exit at line=%d\n", ioc->name,
  2258. __FUNCTION__, __LINE__));
  2259. break;
  2260. }
  2261. /*
  2262. * Handling RAID components
  2263. */
  2264. if (ev->phys_disk_num_valid &&
  2265. ev->hidden_raid_component) {
  2266. printk(MYIOC_s_INFO_FMT
  2267. "RAID Hidding: channel=%d, id=%d, "
  2268. "physdsk %d \n", ioc->name, ev->channel,
  2269. ev->id, ev->phys_disk_num);
  2270. vtarget->id = ev->phys_disk_num;
  2271. vtarget->tflags |=
  2272. MPT_TARGET_FLAGS_RAID_COMPONENT;
  2273. mptsas_reprobe_target(starget, 1);
  2274. phy_info->attached.phys_disk_num =
  2275. ev->phys_disk_num;
  2276. break;
  2277. }
  2278. }
  2279. if (phy_info->attached.device_info &
  2280. MPI_SAS_DEVICE_INFO_SSP_TARGET)
  2281. ds = "ssp";
  2282. if (phy_info->attached.device_info &
  2283. MPI_SAS_DEVICE_INFO_STP_TARGET)
  2284. ds = "stp";
  2285. if (phy_info->attached.device_info &
  2286. MPI_SAS_DEVICE_INFO_SATA_DEVICE)
  2287. ds = "sata";
  2288. printk(MYIOC_s_INFO_FMT
  2289. "removing %s device, channel %d, id %d, phy %d\n",
  2290. ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
  2291. dev_printk(KERN_DEBUG, &port->dev,
  2292. "delete port (%d)\n", port->port_identifier);
  2293. sas_port_delete(port);
  2294. mptsas_port_delete(ioc, phy_info->port_details);
  2295. break;
  2296. case MPTSAS_ADD_DEVICE:
  2297. if (ev->phys_disk_num_valid)
  2298. mpt_findImVolumes(ioc);
  2299. /*
  2300. * Refresh sas device pg0 data
  2301. */
  2302. if (mptsas_sas_device_pg0(ioc, &sas_device,
  2303. (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
  2304. MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
  2305. (ev->channel << 8) + ev->id)) {
  2306. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2307. "%s: exit at line=%d\n", ioc->name,
  2308. __FUNCTION__, __LINE__));
  2309. break;
  2310. }
  2311. __mptsas_discovery_work(ioc);
  2312. phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
  2313. sas_device.sas_address);
  2314. if (!phy_info || !phy_info->port_details) {
  2315. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2316. "%s: exit at line=%d\n", ioc->name,
  2317. __FUNCTION__, __LINE__));
  2318. break;
  2319. }
  2320. starget = mptsas_get_starget(phy_info);
  2321. if (starget && (!ev->hidden_raid_component)){
  2322. vtarget = starget->hostdata;
  2323. if (!vtarget) {
  2324. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2325. "%s: exit at line=%d\n", ioc->name,
  2326. __FUNCTION__, __LINE__));
  2327. break;
  2328. }
  2329. /*
  2330. * Handling RAID components
  2331. */
  2332. if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2333. printk(MYIOC_s_INFO_FMT
  2334. "RAID Exposing: channel=%d, id=%d, "
  2335. "physdsk %d \n", ioc->name, ev->channel,
  2336. ev->id, ev->phys_disk_num);
  2337. vtarget->tflags &=
  2338. ~MPT_TARGET_FLAGS_RAID_COMPONENT;
  2339. vtarget->id = ev->id;
  2340. mptsas_reprobe_target(starget, 0);
  2341. phy_info->attached.phys_disk_num = ~0;
  2342. }
  2343. break;
  2344. }
  2345. if (mptsas_get_rphy(phy_info)) {
  2346. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2347. "%s: exit at line=%d\n", ioc->name,
  2348. __FUNCTION__, __LINE__));
  2349. if (ev->channel) printk("%d\n", __LINE__);
  2350. break;
  2351. }
  2352. port = mptsas_get_port(phy_info);
  2353. if (!port) {
  2354. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2355. "%s: exit at line=%d\n", ioc->name,
  2356. __FUNCTION__, __LINE__));
  2357. break;
  2358. }
  2359. memcpy(&phy_info->attached, &sas_device,
  2360. sizeof(struct mptsas_devinfo));
  2361. if (phy_info->attached.device_info &
  2362. MPI_SAS_DEVICE_INFO_SSP_TARGET)
  2363. ds = "ssp";
  2364. if (phy_info->attached.device_info &
  2365. MPI_SAS_DEVICE_INFO_STP_TARGET)
  2366. ds = "stp";
  2367. if (phy_info->attached.device_info &
  2368. MPI_SAS_DEVICE_INFO_SATA_DEVICE)
  2369. ds = "sata";
  2370. printk(MYIOC_s_INFO_FMT
  2371. "attaching %s device, channel %d, id %d, phy %d\n",
  2372. ioc->name, ds, ev->channel, ev->id, ev->phy_id);
  2373. mptsas_parse_device_info(&identify, &phy_info->attached);
  2374. rphy = sas_end_device_alloc(port);
  2375. if (!rphy) {
  2376. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2377. "%s: exit at line=%d\n", ioc->name,
  2378. __FUNCTION__, __LINE__));
  2379. break; /* non-fatal: an rphy can be added later */
  2380. }
  2381. rphy->identify = identify;
  2382. if (sas_rphy_add(rphy)) {
  2383. dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
  2384. "%s: exit at line=%d\n", ioc->name,
  2385. __FUNCTION__, __LINE__));
  2386. sas_rphy_free(rphy);
  2387. break;
  2388. }
  2389. mptsas_set_rphy(ioc, phy_info, rphy);
  2390. break;
  2391. case MPTSAS_ADD_RAID:
  2392. sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
  2393. ev->id, 0);
  2394. if (sdev) {
  2395. scsi_device_put(sdev);
  2396. break;
  2397. }
  2398. printk(MYIOC_s_INFO_FMT
  2399. "attaching raid volume, channel %d, id %d\n",
  2400. ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
  2401. scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, ev->id, 0);
  2402. mpt_findImVolumes(ioc);
  2403. break;
  2404. case MPTSAS_DEL_RAID:
  2405. sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
  2406. ev->id, 0);
  2407. if (!sdev)
  2408. break;
  2409. printk(MYIOC_s_INFO_FMT
  2410. "removing raid volume, channel %d, id %d\n",
  2411. ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
  2412. vdevice = sdev->hostdata;
  2413. scsi_remove_device(sdev);
  2414. scsi_device_put(sdev);
  2415. mpt_findImVolumes(ioc);
  2416. break;
  2417. case MPTSAS_ADD_INACTIVE_VOLUME:
  2418. mptsas_adding_inactive_raid_components(ioc,
  2419. ev->channel, ev->id);
  2420. break;
  2421. case MPTSAS_IGNORE_EVENT:
  2422. default:
  2423. break;
  2424. }
  2425. mutex_unlock(&ioc->sas_discovery_mutex);
  2426. kfree(ev);
  2427. }
  2428. static void
  2429. mptsas_send_sas_event(MPT_ADAPTER *ioc,
  2430. EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
  2431. {
  2432. struct mptsas_hotplug_event *ev;
  2433. u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
  2434. __le64 sas_address;
  2435. if ((device_info &
  2436. (MPI_SAS_DEVICE_INFO_SSP_TARGET |
  2437. MPI_SAS_DEVICE_INFO_STP_TARGET |
  2438. MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
  2439. return;
  2440. switch (sas_event_data->ReasonCode) {
  2441. case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
  2442. mptsas_target_reset_queue(ioc, sas_event_data);
  2443. break;
  2444. case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
  2445. ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
  2446. if (!ev) {
  2447. printk(KERN_WARNING "mptsas: lost hotplug event\n");
  2448. break;
  2449. }
  2450. INIT_WORK(&ev->work, mptsas_hotplug_work);
  2451. ev->ioc = ioc;
  2452. ev->handle = le16_to_cpu(sas_event_data->DevHandle);
  2453. ev->parent_handle =
  2454. le16_to_cpu(sas_event_data->ParentDevHandle);
  2455. ev->channel = sas_event_data->Bus;
  2456. ev->id = sas_event_data->TargetID;
  2457. ev->phy_id = sas_event_data->PhyNum;
  2458. memcpy(&sas_address, &sas_event_data->SASAddress,
  2459. sizeof(__le64));
  2460. ev->sas_address = le64_to_cpu(sas_address);
  2461. ev->device_info = device_info;
  2462. if (sas_event_data->ReasonCode &
  2463. MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
  2464. ev->event_type = MPTSAS_ADD_DEVICE;
  2465. else
  2466. ev->event_type = MPTSAS_DEL_DEVICE;
  2467. schedule_work(&ev->work);
  2468. break;
  2469. case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
  2470. /*
  2471. * Persistent table is full.
  2472. */
  2473. INIT_WORK(&ioc->sas_persist_task,
  2474. mptsas_persist_clear_table);
  2475. schedule_work(&ioc->sas_persist_task);
  2476. break;
  2477. /*
  2478. * TODO, handle other events
  2479. */
  2480. case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  2481. case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
  2482. case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  2483. case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  2484. case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  2485. case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  2486. case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  2487. default:
  2488. break;
  2489. }
  2490. }
  2491. static void
  2492. mptsas_send_raid_event(MPT_ADAPTER *ioc,
  2493. EVENT_DATA_RAID *raid_event_data)
  2494. {
  2495. struct mptsas_hotplug_event *ev;
  2496. int status = le32_to_cpu(raid_event_data->SettingsStatus);
  2497. int state = (status >> 8) & 0xff;
  2498. if (ioc->bus_type != SAS)
  2499. return;
  2500. ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
  2501. if (!ev) {
  2502. printk(KERN_WARNING "mptsas: lost hotplug event\n");
  2503. return;
  2504. }
  2505. INIT_WORK(&ev->work, mptsas_hotplug_work);
  2506. ev->ioc = ioc;
  2507. ev->id = raid_event_data->VolumeID;
  2508. ev->channel = raid_event_data->VolumeBus;
  2509. ev->event_type = MPTSAS_IGNORE_EVENT;
  2510. switch (raid_event_data->ReasonCode) {
  2511. case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
  2512. ev->phys_disk_num_valid = 1;
  2513. ev->phys_disk_num = raid_event_data->PhysDiskNum;
  2514. ev->event_type = MPTSAS_ADD_DEVICE;
  2515. break;
  2516. case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
  2517. ev->phys_disk_num_valid = 1;
  2518. ev->phys_disk_num = raid_event_data->PhysDiskNum;
  2519. ev->hidden_raid_component = 1;
  2520. ev->event_type = MPTSAS_DEL_DEVICE;
  2521. break;
  2522. case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
  2523. switch (state) {
  2524. case MPI_PD_STATE_ONLINE:
  2525. case MPI_PD_STATE_NOT_COMPATIBLE:
  2526. ev->phys_disk_num_valid = 1;
  2527. ev->phys_disk_num = raid_event_data->PhysDiskNum;
  2528. ev->hidden_raid_component = 1;
  2529. ev->event_type = MPTSAS_ADD_DEVICE;
  2530. break;
  2531. case MPI_PD_STATE_MISSING:
  2532. case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
  2533. case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
  2534. case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
  2535. ev->phys_disk_num_valid = 1;
  2536. ev->phys_disk_num = raid_event_data->PhysDiskNum;
  2537. ev->event_type = MPTSAS_DEL_DEVICE;
  2538. break;
  2539. default:
  2540. break;
  2541. }
  2542. break;
  2543. case MPI_EVENT_RAID_RC_VOLUME_DELETED:
  2544. ev->event_type = MPTSAS_DEL_RAID;
  2545. break;
  2546. case MPI_EVENT_RAID_RC_VOLUME_CREATED:
  2547. ev->event_type = MPTSAS_ADD_RAID;
  2548. break;
  2549. case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
  2550. switch (state) {
  2551. case MPI_RAIDVOL0_STATUS_STATE_FAILED:
  2552. case MPI_RAIDVOL0_STATUS_STATE_MISSING:
  2553. ev->event_type = MPTSAS_DEL_RAID;
  2554. break;
  2555. case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
  2556. case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
  2557. ev->event_type = MPTSAS_ADD_RAID;
  2558. break;
  2559. default:
  2560. break;
  2561. }
  2562. break;
  2563. default:
  2564. break;
  2565. }
  2566. schedule_work(&ev->work);
  2567. }
  2568. static void
  2569. mptsas_send_discovery_event(MPT_ADAPTER *ioc,
  2570. EVENT_DATA_SAS_DISCOVERY *discovery_data)
  2571. {
  2572. struct mptsas_discovery_event *ev;
  2573. /*
  2574. * DiscoveryStatus
  2575. *
  2576. * This flag will be non-zero when firmware
  2577. * kicks off discovery, and return to zero
  2578. * once its completed.
  2579. */
  2580. if (discovery_data->DiscoveryStatus)
  2581. return;
  2582. ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
  2583. if (!ev)
  2584. return;
  2585. INIT_WORK(&ev->work, mptsas_discovery_work);
  2586. ev->ioc = ioc;
  2587. schedule_work(&ev->work);
  2588. };
  2589. /*
  2590. * mptsas_send_ir2_event - handle exposing hidden disk when
  2591. * an inactive raid volume is added
  2592. *
  2593. * @ioc: Pointer to MPT_ADAPTER structure
  2594. * @ir2_data
  2595. *
  2596. */
  2597. static void
  2598. mptsas_send_ir2_event(MPT_ADAPTER *ioc, PTR_MPI_EVENT_DATA_IR2 ir2_data)
  2599. {
  2600. struct mptsas_hotplug_event *ev;
  2601. if (ir2_data->ReasonCode !=
  2602. MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED)
  2603. return;
  2604. ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
  2605. if (!ev)
  2606. return;
  2607. INIT_WORK(&ev->work, mptsas_hotplug_work);
  2608. ev->ioc = ioc;
  2609. ev->id = ir2_data->TargetID;
  2610. ev->channel = ir2_data->Bus;
  2611. ev->event_type = MPTSAS_ADD_INACTIVE_VOLUME;
  2612. schedule_work(&ev->work);
  2613. };
  2614. static int
  2615. mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
  2616. {
  2617. int rc=1;
  2618. u8 event = le32_to_cpu(reply->Event) & 0xFF;
  2619. if (!ioc->sh)
  2620. goto out;
  2621. /*
  2622. * sas_discovery_ignore_events
  2623. *
  2624. * This flag is to prevent anymore processing of
  2625. * sas events once mptsas_remove function is called.
  2626. */
  2627. if (ioc->sas_discovery_ignore_events) {
  2628. rc = mptscsih_event_process(ioc, reply);
  2629. goto out;
  2630. }
  2631. switch (event) {
  2632. case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
  2633. mptsas_send_sas_event(ioc,
  2634. (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
  2635. break;
  2636. case MPI_EVENT_INTEGRATED_RAID:
  2637. mptsas_send_raid_event(ioc,
  2638. (EVENT_DATA_RAID *)reply->Data);
  2639. break;
  2640. case MPI_EVENT_PERSISTENT_TABLE_FULL:
  2641. INIT_WORK(&ioc->sas_persist_task,
  2642. mptsas_persist_clear_table);
  2643. schedule_work(&ioc->sas_persist_task);
  2644. break;
  2645. case MPI_EVENT_SAS_DISCOVERY:
  2646. mptsas_send_discovery_event(ioc,
  2647. (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
  2648. break;
  2649. case MPI_EVENT_IR2:
  2650. mptsas_send_ir2_event(ioc,
  2651. (PTR_MPI_EVENT_DATA_IR2)reply->Data);
  2652. break;
  2653. default:
  2654. rc = mptscsih_event_process(ioc, reply);
  2655. break;
  2656. }
  2657. out:
  2658. return rc;
  2659. }
  2660. static int
  2661. mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  2662. {
  2663. struct Scsi_Host *sh;
  2664. MPT_SCSI_HOST *hd;
  2665. MPT_ADAPTER *ioc;
  2666. unsigned long flags;
  2667. int ii;
  2668. int numSGE = 0;
  2669. int scale;
  2670. int ioc_cap;
  2671. int error=0;
  2672. int r;
  2673. r = mpt_attach(pdev,id);
  2674. if (r)
  2675. return r;
  2676. ioc = pci_get_drvdata(pdev);
  2677. ioc->DoneCtx = mptsasDoneCtx;
  2678. ioc->TaskCtx = mptsasTaskCtx;
  2679. ioc->InternalCtx = mptsasInternalCtx;
  2680. /* Added sanity check on readiness of the MPT adapter.
  2681. */
  2682. if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
  2683. printk(MYIOC_s_WARN_FMT
  2684. "Skipping because it's not operational!\n",
  2685. ioc->name);
  2686. error = -ENODEV;
  2687. goto out_mptsas_probe;
  2688. }
  2689. if (!ioc->active) {
  2690. printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
  2691. ioc->name);
  2692. error = -ENODEV;
  2693. goto out_mptsas_probe;
  2694. }
  2695. /* Sanity check - ensure at least 1 port is INITIATOR capable
  2696. */
  2697. ioc_cap = 0;
  2698. for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
  2699. if (ioc->pfacts[ii].ProtocolFlags &
  2700. MPI_PORTFACTS_PROTOCOL_INITIATOR)
  2701. ioc_cap++;
  2702. }
  2703. if (!ioc_cap) {
  2704. printk(MYIOC_s_WARN_FMT
  2705. "Skipping ioc=%p because SCSI Initiator mode "
  2706. "is NOT enabled!\n", ioc->name, ioc);
  2707. return 0;
  2708. }
  2709. sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
  2710. if (!sh) {
  2711. printk(MYIOC_s_WARN_FMT
  2712. "Unable to register controller with SCSI subsystem\n",
  2713. ioc->name);
  2714. error = -1;
  2715. goto out_mptsas_probe;
  2716. }
  2717. spin_lock_irqsave(&ioc->FreeQlock, flags);
  2718. /* Attach the SCSI Host to the IOC structure
  2719. */
  2720. ioc->sh = sh;
  2721. sh->io_port = 0;
  2722. sh->n_io_port = 0;
  2723. sh->irq = 0;
  2724. /* set 16 byte cdb's */
  2725. sh->max_cmd_len = 16;
  2726. sh->max_id = ioc->pfacts[0].PortSCSIID;
  2727. sh->max_lun = max_lun;
  2728. sh->transportt = mptsas_transport_template;
  2729. sh->this_id = ioc->pfacts[0].PortSCSIID;
  2730. /* Required entry.
  2731. */
  2732. sh->unique_id = ioc->id;
  2733. INIT_LIST_HEAD(&ioc->sas_topology);
  2734. mutex_init(&ioc->sas_topology_mutex);
  2735. mutex_init(&ioc->sas_discovery_mutex);
  2736. mutex_init(&ioc->sas_mgmt.mutex);
  2737. init_completion(&ioc->sas_mgmt.done);
  2738. /* Verify that we won't exceed the maximum
  2739. * number of chain buffers
  2740. * We can optimize: ZZ = req_sz/sizeof(SGE)
  2741. * For 32bit SGE's:
  2742. * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
  2743. * + (req_sz - 64)/sizeof(SGE)
  2744. * A slightly different algorithm is required for
  2745. * 64bit SGEs.
  2746. */
  2747. scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
  2748. if (sizeof(dma_addr_t) == sizeof(u64)) {
  2749. numSGE = (scale - 1) *
  2750. (ioc->facts.MaxChainDepth-1) + scale +
  2751. (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
  2752. sizeof(u32));
  2753. } else {
  2754. numSGE = 1 + (scale - 1) *
  2755. (ioc->facts.MaxChainDepth-1) + scale +
  2756. (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
  2757. sizeof(u32));
  2758. }
  2759. if (numSGE < sh->sg_tablesize) {
  2760. /* Reset this value */
  2761. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2762. "Resetting sg_tablesize to %d from %d\n",
  2763. ioc->name, numSGE, sh->sg_tablesize));
  2764. sh->sg_tablesize = numSGE;
  2765. }
  2766. hd = (MPT_SCSI_HOST *) sh->hostdata;
  2767. hd->ioc = ioc;
  2768. /* SCSI needs scsi_cmnd lookup table!
  2769. * (with size equal to req_depth*PtrSz!)
  2770. */
  2771. hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
  2772. if (!hd->ScsiLookup) {
  2773. error = -ENOMEM;
  2774. goto out_mptsas_probe;
  2775. }
  2776. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
  2777. ioc->name, hd->ScsiLookup));
  2778. /* Clear the TM flags
  2779. */
  2780. hd->tmPending = 0;
  2781. hd->tmState = TM_STATE_NONE;
  2782. hd->resetPending = 0;
  2783. hd->abortSCpnt = NULL;
  2784. /* Clear the pointer used to store
  2785. * single-threaded commands, i.e., those
  2786. * issued during a bus scan, dv and
  2787. * configuration pages.
  2788. */
  2789. hd->cmdPtr = NULL;
  2790. /* Initialize this SCSI Hosts' timers
  2791. * To use, set the timer expires field
  2792. * and add_timer
  2793. */
  2794. init_timer(&hd->timer);
  2795. hd->timer.data = (unsigned long) hd;
  2796. hd->timer.function = mptscsih_timer_expired;
  2797. ioc->sas_data.ptClear = mpt_pt_clear;
  2798. init_waitqueue_head(&hd->scandv_waitq);
  2799. hd->scandv_wait_done = 0;
  2800. hd->last_queue_full = 0;
  2801. INIT_LIST_HEAD(&hd->target_reset_list);
  2802. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  2803. if (ioc->sas_data.ptClear==1) {
  2804. mptbase_sas_persist_operation(
  2805. ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
  2806. }
  2807. error = scsi_add_host(sh, &ioc->pcidev->dev);
  2808. if (error) {
  2809. dprintk(ioc, printk(KERN_ERR MYNAM
  2810. "scsi_add_host failed\n"));
  2811. goto out_mptsas_probe;
  2812. }
  2813. mptsas_scan_sas_topology(ioc);
  2814. return 0;
  2815. out_mptsas_probe:
  2816. mptscsih_remove(pdev);
  2817. return error;
  2818. }
  2819. static void __devexit mptsas_remove(struct pci_dev *pdev)
  2820. {
  2821. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  2822. struct mptsas_portinfo *p, *n;
  2823. int i;
  2824. ioc->sas_discovery_ignore_events = 1;
  2825. sas_remove_host(ioc->sh);
  2826. mutex_lock(&ioc->sas_topology_mutex);
  2827. list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
  2828. list_del(&p->list);
  2829. for (i = 0 ; i < p->num_phys ; i++)
  2830. mptsas_port_delete(ioc, p->phy_info[i].port_details);
  2831. kfree(p->phy_info);
  2832. kfree(p);
  2833. }
  2834. mutex_unlock(&ioc->sas_topology_mutex);
  2835. mptscsih_remove(pdev);
  2836. }
  2837. static struct pci_device_id mptsas_pci_table[] = {
  2838. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
  2839. PCI_ANY_ID, PCI_ANY_ID },
  2840. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
  2841. PCI_ANY_ID, PCI_ANY_ID },
  2842. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
  2843. PCI_ANY_ID, PCI_ANY_ID },
  2844. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
  2845. PCI_ANY_ID, PCI_ANY_ID },
  2846. { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
  2847. PCI_ANY_ID, PCI_ANY_ID },
  2848. {0} /* Terminating entry */
  2849. };
  2850. MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
  2851. static struct pci_driver mptsas_driver = {
  2852. .name = "mptsas",
  2853. .id_table = mptsas_pci_table,
  2854. .probe = mptsas_probe,
  2855. .remove = __devexit_p(mptsas_remove),
  2856. .shutdown = mptscsih_shutdown,
  2857. #ifdef CONFIG_PM
  2858. .suspend = mptscsih_suspend,
  2859. .resume = mptscsih_resume,
  2860. #endif
  2861. };
  2862. static int __init
  2863. mptsas_init(void)
  2864. {
  2865. int error;
  2866. show_mptmod_ver(my_NAME, my_VERSION);
  2867. mptsas_transport_template =
  2868. sas_attach_transport(&mptsas_transport_functions);
  2869. if (!mptsas_transport_template)
  2870. return -ENODEV;
  2871. mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
  2872. mptsasTaskCtx = mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
  2873. mptsasInternalCtx =
  2874. mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
  2875. mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
  2876. mpt_event_register(mptsasDoneCtx, mptsas_event_process);
  2877. mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
  2878. error = pci_register_driver(&mptsas_driver);
  2879. if (error)
  2880. sas_release_transport(mptsas_transport_template);
  2881. return error;
  2882. }
  2883. static void __exit
  2884. mptsas_exit(void)
  2885. {
  2886. pci_unregister_driver(&mptsas_driver);
  2887. sas_release_transport(mptsas_transport_template);
  2888. mpt_reset_deregister(mptsasDoneCtx);
  2889. mpt_event_deregister(mptsasDoneCtx);
  2890. mpt_deregister(mptsasMgmtCtx);
  2891. mpt_deregister(mptsasInternalCtx);
  2892. mpt_deregister(mptsasTaskCtx);
  2893. mpt_deregister(mptsasDoneCtx);
  2894. }
  2895. module_init(mptsas_init);
  2896. module_exit(mptsas_exit);