mptsas.c 72 KB

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