mptsas.c 72 KB

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