mptsas.c 72 KB

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