scsi_transport_sas.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832
  1. /*
  2. * Copyright (C) 2005-2006 Dell Inc.
  3. * Released under GPL v2.
  4. *
  5. * Serial Attached SCSI (SAS) transport class.
  6. *
  7. * The SAS transport class contains common code to deal with SAS HBAs,
  8. * an aproximated representation of SAS topologies in the driver model,
  9. * and various sysfs attributes to expose these topologies and management
  10. * interfaces to userspace.
  11. *
  12. * In addition to the basic SCSI core objects this transport class
  13. * introduces two additional intermediate objects: The SAS PHY
  14. * as represented by struct sas_phy defines an "outgoing" PHY on
  15. * a SAS HBA or Expander, and the SAS remote PHY represented by
  16. * struct sas_rphy defines an "incoming" PHY on a SAS Expander or
  17. * end device. Note that this is purely a software concept, the
  18. * underlying hardware for a PHY and a remote PHY is the exactly
  19. * the same.
  20. *
  21. * There is no concept of a SAS port in this code, users can see
  22. * what PHYs form a wide port based on the port_identifier attribute,
  23. * which is the same for all PHYs in a port.
  24. */
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/err.h>
  29. #include <linux/slab.h>
  30. #include <linux/string.h>
  31. #include <linux/blkdev.h>
  32. #include <linux/bsg.h>
  33. #include <scsi/scsi.h>
  34. #include <scsi/scsi_device.h>
  35. #include <scsi/scsi_host.h>
  36. #include <scsi/scsi_transport.h>
  37. #include <scsi/scsi_transport_sas.h>
  38. #include "scsi_sas_internal.h"
  39. struct sas_host_attrs {
  40. struct list_head rphy_list;
  41. struct mutex lock;
  42. struct request_queue *q;
  43. u32 next_target_id;
  44. u32 next_expander_id;
  45. int next_port_id;
  46. };
  47. #define to_sas_host_attrs(host) ((struct sas_host_attrs *)(host)->shost_data)
  48. /*
  49. * Hack to allow attributes of the same name in different objects.
  50. */
  51. #define SAS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
  52. struct device_attribute dev_attr_##_prefix##_##_name = \
  53. __ATTR(_name,_mode,_show,_store)
  54. /*
  55. * Pretty printing helpers
  56. */
  57. #define sas_bitfield_name_match(title, table) \
  58. static ssize_t \
  59. get_sas_##title##_names(u32 table_key, char *buf) \
  60. { \
  61. char *prefix = ""; \
  62. ssize_t len = 0; \
  63. int i; \
  64. \
  65. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  66. if (table[i].value & table_key) { \
  67. len += sprintf(buf + len, "%s%s", \
  68. prefix, table[i].name); \
  69. prefix = ", "; \
  70. } \
  71. } \
  72. len += sprintf(buf + len, "\n"); \
  73. return len; \
  74. }
  75. #define sas_bitfield_name_set(title, table) \
  76. static ssize_t \
  77. set_sas_##title##_names(u32 *table_key, const char *buf) \
  78. { \
  79. ssize_t len = 0; \
  80. int i; \
  81. \
  82. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  83. len = strlen(table[i].name); \
  84. if (strncmp(buf, table[i].name, len) == 0 && \
  85. (buf[len] == '\n' || buf[len] == '\0')) { \
  86. *table_key = table[i].value; \
  87. return 0; \
  88. } \
  89. } \
  90. return -EINVAL; \
  91. }
  92. #define sas_bitfield_name_search(title, table) \
  93. static ssize_t \
  94. get_sas_##title##_names(u32 table_key, char *buf) \
  95. { \
  96. ssize_t len = 0; \
  97. int i; \
  98. \
  99. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  100. if (table[i].value == table_key) { \
  101. len += sprintf(buf + len, "%s", \
  102. table[i].name); \
  103. break; \
  104. } \
  105. } \
  106. len += sprintf(buf + len, "\n"); \
  107. return len; \
  108. }
  109. static struct {
  110. u32 value;
  111. char *name;
  112. } sas_device_type_names[] = {
  113. { SAS_PHY_UNUSED, "unused" },
  114. { SAS_END_DEVICE, "end device" },
  115. { SAS_EDGE_EXPANDER_DEVICE, "edge expander" },
  116. { SAS_FANOUT_EXPANDER_DEVICE, "fanout expander" },
  117. };
  118. sas_bitfield_name_search(device_type, sas_device_type_names)
  119. static struct {
  120. u32 value;
  121. char *name;
  122. } sas_protocol_names[] = {
  123. { SAS_PROTOCOL_SATA, "sata" },
  124. { SAS_PROTOCOL_SMP, "smp" },
  125. { SAS_PROTOCOL_STP, "stp" },
  126. { SAS_PROTOCOL_SSP, "ssp" },
  127. };
  128. sas_bitfield_name_match(protocol, sas_protocol_names)
  129. static struct {
  130. u32 value;
  131. char *name;
  132. } sas_linkspeed_names[] = {
  133. { SAS_LINK_RATE_UNKNOWN, "Unknown" },
  134. { SAS_PHY_DISABLED, "Phy disabled" },
  135. { SAS_LINK_RATE_FAILED, "Link Rate failed" },
  136. { SAS_SATA_SPINUP_HOLD, "Spin-up hold" },
  137. { SAS_LINK_RATE_1_5_GBPS, "1.5 Gbit" },
  138. { SAS_LINK_RATE_3_0_GBPS, "3.0 Gbit" },
  139. { SAS_LINK_RATE_6_0_GBPS, "6.0 Gbit" },
  140. };
  141. sas_bitfield_name_search(linkspeed, sas_linkspeed_names)
  142. sas_bitfield_name_set(linkspeed, sas_linkspeed_names)
  143. static void sas_smp_request(struct request_queue *q, struct Scsi_Host *shost,
  144. struct sas_rphy *rphy)
  145. {
  146. struct request *req;
  147. int ret;
  148. int (*handler)(struct Scsi_Host *, struct sas_rphy *, struct request *);
  149. while (!blk_queue_plugged(q)) {
  150. req = elv_next_request(q);
  151. if (!req)
  152. break;
  153. blkdev_dequeue_request(req);
  154. spin_unlock_irq(q->queue_lock);
  155. handler = to_sas_internal(shost->transportt)->f->smp_handler;
  156. ret = handler(shost, rphy, req);
  157. req->errors = ret;
  158. spin_lock_irq(q->queue_lock);
  159. req->end_io(req, ret);
  160. }
  161. }
  162. static void sas_host_smp_request(struct request_queue *q)
  163. {
  164. sas_smp_request(q, (struct Scsi_Host *)q->queuedata, NULL);
  165. }
  166. static void sas_non_host_smp_request(struct request_queue *q)
  167. {
  168. struct sas_rphy *rphy = q->queuedata;
  169. sas_smp_request(q, rphy_to_shost(rphy), rphy);
  170. }
  171. static void sas_host_release(struct device *dev)
  172. {
  173. struct Scsi_Host *shost = dev_to_shost(dev);
  174. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  175. struct request_queue *q = sas_host->q;
  176. if (q)
  177. blk_cleanup_queue(q);
  178. }
  179. static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy)
  180. {
  181. struct request_queue *q;
  182. int error;
  183. struct device *dev;
  184. char namebuf[20];
  185. const char *name;
  186. void (*release)(struct device *);
  187. if (!to_sas_internal(shost->transportt)->f->smp_handler) {
  188. printk("%s can't handle SMP requests\n", shost->hostt->name);
  189. return 0;
  190. }
  191. if (rphy) {
  192. q = blk_init_queue(sas_non_host_smp_request, NULL);
  193. dev = &rphy->dev;
  194. name = dev_name(dev);
  195. release = NULL;
  196. } else {
  197. q = blk_init_queue(sas_host_smp_request, NULL);
  198. dev = &shost->shost_gendev;
  199. snprintf(namebuf, sizeof(namebuf),
  200. "sas_host%d", shost->host_no);
  201. name = namebuf;
  202. release = sas_host_release;
  203. }
  204. if (!q)
  205. return -ENOMEM;
  206. error = bsg_register_queue(q, dev, name, release);
  207. if (error) {
  208. blk_cleanup_queue(q);
  209. return -ENOMEM;
  210. }
  211. if (rphy)
  212. rphy->q = q;
  213. else
  214. to_sas_host_attrs(shost)->q = q;
  215. if (rphy)
  216. q->queuedata = rphy;
  217. else
  218. q->queuedata = shost;
  219. queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
  220. return 0;
  221. }
  222. static void sas_bsg_remove(struct Scsi_Host *shost, struct sas_rphy *rphy)
  223. {
  224. struct request_queue *q;
  225. if (rphy)
  226. q = rphy->q;
  227. else
  228. q = to_sas_host_attrs(shost)->q;
  229. if (!q)
  230. return;
  231. bsg_unregister_queue(q);
  232. }
  233. /*
  234. * SAS host attributes
  235. */
  236. static int sas_host_setup(struct transport_container *tc, struct device *dev,
  237. struct device *cdev)
  238. {
  239. struct Scsi_Host *shost = dev_to_shost(dev);
  240. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  241. INIT_LIST_HEAD(&sas_host->rphy_list);
  242. mutex_init(&sas_host->lock);
  243. sas_host->next_target_id = 0;
  244. sas_host->next_expander_id = 0;
  245. sas_host->next_port_id = 0;
  246. if (sas_bsg_initialize(shost, NULL))
  247. dev_printk(KERN_ERR, dev, "fail to a bsg device %d\n",
  248. shost->host_no);
  249. return 0;
  250. }
  251. static int sas_host_remove(struct transport_container *tc, struct device *dev,
  252. struct device *cdev)
  253. {
  254. struct Scsi_Host *shost = dev_to_shost(dev);
  255. sas_bsg_remove(shost, NULL);
  256. return 0;
  257. }
  258. static DECLARE_TRANSPORT_CLASS(sas_host_class,
  259. "sas_host", sas_host_setup, sas_host_remove, NULL);
  260. static int sas_host_match(struct attribute_container *cont,
  261. struct device *dev)
  262. {
  263. struct Scsi_Host *shost;
  264. struct sas_internal *i;
  265. if (!scsi_is_host_device(dev))
  266. return 0;
  267. shost = dev_to_shost(dev);
  268. if (!shost->transportt)
  269. return 0;
  270. if (shost->transportt->host_attrs.ac.class !=
  271. &sas_host_class.class)
  272. return 0;
  273. i = to_sas_internal(shost->transportt);
  274. return &i->t.host_attrs.ac == cont;
  275. }
  276. static int do_sas_phy_delete(struct device *dev, void *data)
  277. {
  278. int pass = (int)(unsigned long)data;
  279. if (pass == 0 && scsi_is_sas_port(dev))
  280. sas_port_delete(dev_to_sas_port(dev));
  281. else if (pass == 1 && scsi_is_sas_phy(dev))
  282. sas_phy_delete(dev_to_phy(dev));
  283. return 0;
  284. }
  285. /**
  286. * sas_remove_children - tear down a devices SAS data structures
  287. * @dev: device belonging to the sas object
  288. *
  289. * Removes all SAS PHYs and remote PHYs for a given object
  290. */
  291. void sas_remove_children(struct device *dev)
  292. {
  293. device_for_each_child(dev, (void *)0, do_sas_phy_delete);
  294. device_for_each_child(dev, (void *)1, do_sas_phy_delete);
  295. }
  296. EXPORT_SYMBOL(sas_remove_children);
  297. /**
  298. * sas_remove_host - tear down a Scsi_Host's SAS data structures
  299. * @shost: Scsi Host that is torn down
  300. *
  301. * Removes all SAS PHYs and remote PHYs for a given Scsi_Host.
  302. * Must be called just before scsi_remove_host for SAS HBAs.
  303. */
  304. void sas_remove_host(struct Scsi_Host *shost)
  305. {
  306. sas_remove_children(&shost->shost_gendev);
  307. }
  308. EXPORT_SYMBOL(sas_remove_host);
  309. /*
  310. * SAS Phy attributes
  311. */
  312. #define sas_phy_show_simple(field, name, format_string, cast) \
  313. static ssize_t \
  314. show_sas_phy_##name(struct device *dev, \
  315. struct device_attribute *attr, char *buf) \
  316. { \
  317. struct sas_phy *phy = transport_class_to_phy(dev); \
  318. \
  319. return snprintf(buf, 20, format_string, cast phy->field); \
  320. }
  321. #define sas_phy_simple_attr(field, name, format_string, type) \
  322. sas_phy_show_simple(field, name, format_string, (type)) \
  323. static DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL)
  324. #define sas_phy_show_protocol(field, name) \
  325. static ssize_t \
  326. show_sas_phy_##name(struct device *dev, \
  327. struct device_attribute *attr, char *buf) \
  328. { \
  329. struct sas_phy *phy = transport_class_to_phy(dev); \
  330. \
  331. if (!phy->field) \
  332. return snprintf(buf, 20, "none\n"); \
  333. return get_sas_protocol_names(phy->field, buf); \
  334. }
  335. #define sas_phy_protocol_attr(field, name) \
  336. sas_phy_show_protocol(field, name) \
  337. static DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL)
  338. #define sas_phy_show_linkspeed(field) \
  339. static ssize_t \
  340. show_sas_phy_##field(struct device *dev, \
  341. struct device_attribute *attr, char *buf) \
  342. { \
  343. struct sas_phy *phy = transport_class_to_phy(dev); \
  344. \
  345. return get_sas_linkspeed_names(phy->field, buf); \
  346. }
  347. /* Fudge to tell if we're minimum or maximum */
  348. #define sas_phy_store_linkspeed(field) \
  349. static ssize_t \
  350. store_sas_phy_##field(struct device *dev, \
  351. struct device_attribute *attr, \
  352. const char *buf, size_t count) \
  353. { \
  354. struct sas_phy *phy = transport_class_to_phy(dev); \
  355. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
  356. struct sas_internal *i = to_sas_internal(shost->transportt); \
  357. u32 value; \
  358. struct sas_phy_linkrates rates = {0}; \
  359. int error; \
  360. \
  361. error = set_sas_linkspeed_names(&value, buf); \
  362. if (error) \
  363. return error; \
  364. rates.field = value; \
  365. error = i->f->set_phy_speed(phy, &rates); \
  366. \
  367. return error ? error : count; \
  368. }
  369. #define sas_phy_linkspeed_rw_attr(field) \
  370. sas_phy_show_linkspeed(field) \
  371. sas_phy_store_linkspeed(field) \
  372. static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, \
  373. store_sas_phy_##field)
  374. #define sas_phy_linkspeed_attr(field) \
  375. sas_phy_show_linkspeed(field) \
  376. static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL)
  377. #define sas_phy_show_linkerror(field) \
  378. static ssize_t \
  379. show_sas_phy_##field(struct device *dev, \
  380. struct device_attribute *attr, char *buf) \
  381. { \
  382. struct sas_phy *phy = transport_class_to_phy(dev); \
  383. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
  384. struct sas_internal *i = to_sas_internal(shost->transportt); \
  385. int error; \
  386. \
  387. error = i->f->get_linkerrors ? i->f->get_linkerrors(phy) : 0; \
  388. if (error) \
  389. return error; \
  390. return snprintf(buf, 20, "%u\n", phy->field); \
  391. }
  392. #define sas_phy_linkerror_attr(field) \
  393. sas_phy_show_linkerror(field) \
  394. static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL)
  395. static ssize_t
  396. show_sas_device_type(struct device *dev,
  397. struct device_attribute *attr, char *buf)
  398. {
  399. struct sas_phy *phy = transport_class_to_phy(dev);
  400. if (!phy->identify.device_type)
  401. return snprintf(buf, 20, "none\n");
  402. return get_sas_device_type_names(phy->identify.device_type, buf);
  403. }
  404. static DEVICE_ATTR(device_type, S_IRUGO, show_sas_device_type, NULL);
  405. static ssize_t do_sas_phy_enable(struct device *dev,
  406. size_t count, int enable)
  407. {
  408. struct sas_phy *phy = transport_class_to_phy(dev);
  409. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  410. struct sas_internal *i = to_sas_internal(shost->transportt);
  411. int error;
  412. error = i->f->phy_enable(phy, enable);
  413. if (error)
  414. return error;
  415. phy->enabled = enable;
  416. return count;
  417. };
  418. static ssize_t
  419. store_sas_phy_enable(struct device *dev, struct device_attribute *attr,
  420. const char *buf, size_t count)
  421. {
  422. if (count < 1)
  423. return -EINVAL;
  424. switch (buf[0]) {
  425. case '0':
  426. do_sas_phy_enable(dev, count, 0);
  427. break;
  428. case '1':
  429. do_sas_phy_enable(dev, count, 1);
  430. break;
  431. default:
  432. return -EINVAL;
  433. }
  434. return count;
  435. }
  436. static ssize_t
  437. show_sas_phy_enable(struct device *dev, struct device_attribute *attr,
  438. char *buf)
  439. {
  440. struct sas_phy *phy = transport_class_to_phy(dev);
  441. return snprintf(buf, 20, "%d", phy->enabled);
  442. }
  443. static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, show_sas_phy_enable,
  444. store_sas_phy_enable);
  445. static ssize_t
  446. do_sas_phy_reset(struct device *dev, size_t count, int hard_reset)
  447. {
  448. struct sas_phy *phy = transport_class_to_phy(dev);
  449. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  450. struct sas_internal *i = to_sas_internal(shost->transportt);
  451. int error;
  452. error = i->f->phy_reset(phy, hard_reset);
  453. if (error)
  454. return error;
  455. return count;
  456. };
  457. static ssize_t
  458. store_sas_link_reset(struct device *dev, struct device_attribute *attr,
  459. const char *buf, size_t count)
  460. {
  461. return do_sas_phy_reset(dev, count, 0);
  462. }
  463. static DEVICE_ATTR(link_reset, S_IWUSR, NULL, store_sas_link_reset);
  464. static ssize_t
  465. store_sas_hard_reset(struct device *dev, struct device_attribute *attr,
  466. const char *buf, size_t count)
  467. {
  468. return do_sas_phy_reset(dev, count, 1);
  469. }
  470. static DEVICE_ATTR(hard_reset, S_IWUSR, NULL, store_sas_hard_reset);
  471. sas_phy_protocol_attr(identify.initiator_port_protocols,
  472. initiator_port_protocols);
  473. sas_phy_protocol_attr(identify.target_port_protocols,
  474. target_port_protocols);
  475. sas_phy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
  476. unsigned long long);
  477. sas_phy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
  478. //sas_phy_simple_attr(port_identifier, port_identifier, "%d\n", int);
  479. sas_phy_linkspeed_attr(negotiated_linkrate);
  480. sas_phy_linkspeed_attr(minimum_linkrate_hw);
  481. sas_phy_linkspeed_rw_attr(minimum_linkrate);
  482. sas_phy_linkspeed_attr(maximum_linkrate_hw);
  483. sas_phy_linkspeed_rw_attr(maximum_linkrate);
  484. sas_phy_linkerror_attr(invalid_dword_count);
  485. sas_phy_linkerror_attr(running_disparity_error_count);
  486. sas_phy_linkerror_attr(loss_of_dword_sync_count);
  487. sas_phy_linkerror_attr(phy_reset_problem_count);
  488. static DECLARE_TRANSPORT_CLASS(sas_phy_class,
  489. "sas_phy", NULL, NULL, NULL);
  490. static int sas_phy_match(struct attribute_container *cont, struct device *dev)
  491. {
  492. struct Scsi_Host *shost;
  493. struct sas_internal *i;
  494. if (!scsi_is_sas_phy(dev))
  495. return 0;
  496. shost = dev_to_shost(dev->parent);
  497. if (!shost->transportt)
  498. return 0;
  499. if (shost->transportt->host_attrs.ac.class !=
  500. &sas_host_class.class)
  501. return 0;
  502. i = to_sas_internal(shost->transportt);
  503. return &i->phy_attr_cont.ac == cont;
  504. }
  505. static void sas_phy_release(struct device *dev)
  506. {
  507. struct sas_phy *phy = dev_to_phy(dev);
  508. put_device(dev->parent);
  509. kfree(phy);
  510. }
  511. /**
  512. * sas_phy_alloc - allocates and initialize a SAS PHY structure
  513. * @parent: Parent device
  514. * @number: Phy index
  515. *
  516. * Allocates an SAS PHY structure. It will be added in the device tree
  517. * below the device specified by @parent, which has to be either a Scsi_Host
  518. * or sas_rphy.
  519. *
  520. * Returns:
  521. * SAS PHY allocated or %NULL if the allocation failed.
  522. */
  523. struct sas_phy *sas_phy_alloc(struct device *parent, int number)
  524. {
  525. struct Scsi_Host *shost = dev_to_shost(parent);
  526. struct sas_phy *phy;
  527. phy = kzalloc(sizeof(*phy), GFP_KERNEL);
  528. if (!phy)
  529. return NULL;
  530. phy->number = number;
  531. phy->enabled = 1;
  532. device_initialize(&phy->dev);
  533. phy->dev.parent = get_device(parent);
  534. phy->dev.release = sas_phy_release;
  535. INIT_LIST_HEAD(&phy->port_siblings);
  536. if (scsi_is_sas_expander_device(parent)) {
  537. struct sas_rphy *rphy = dev_to_rphy(parent);
  538. dev_set_name(&phy->dev, "phy-%d:%d:%d", shost->host_no,
  539. rphy->scsi_target_id, number);
  540. } else
  541. dev_set_name(&phy->dev, "phy-%d:%d", shost->host_no, number);
  542. transport_setup_device(&phy->dev);
  543. return phy;
  544. }
  545. EXPORT_SYMBOL(sas_phy_alloc);
  546. /**
  547. * sas_phy_add - add a SAS PHY to the device hierarchy
  548. * @phy: The PHY to be added
  549. *
  550. * Publishes a SAS PHY to the rest of the system.
  551. */
  552. int sas_phy_add(struct sas_phy *phy)
  553. {
  554. int error;
  555. error = device_add(&phy->dev);
  556. if (!error) {
  557. transport_add_device(&phy->dev);
  558. transport_configure_device(&phy->dev);
  559. }
  560. return error;
  561. }
  562. EXPORT_SYMBOL(sas_phy_add);
  563. /**
  564. * sas_phy_free - free a SAS PHY
  565. * @phy: SAS PHY to free
  566. *
  567. * Frees the specified SAS PHY.
  568. *
  569. * Note:
  570. * This function must only be called on a PHY that has not
  571. * sucessfully been added using sas_phy_add().
  572. */
  573. void sas_phy_free(struct sas_phy *phy)
  574. {
  575. transport_destroy_device(&phy->dev);
  576. put_device(&phy->dev);
  577. }
  578. EXPORT_SYMBOL(sas_phy_free);
  579. /**
  580. * sas_phy_delete - remove SAS PHY
  581. * @phy: SAS PHY to remove
  582. *
  583. * Removes the specified SAS PHY. If the SAS PHY has an
  584. * associated remote PHY it is removed before.
  585. */
  586. void
  587. sas_phy_delete(struct sas_phy *phy)
  588. {
  589. struct device *dev = &phy->dev;
  590. /* this happens if the phy is still part of a port when deleted */
  591. BUG_ON(!list_empty(&phy->port_siblings));
  592. transport_remove_device(dev);
  593. device_del(dev);
  594. transport_destroy_device(dev);
  595. put_device(dev);
  596. }
  597. EXPORT_SYMBOL(sas_phy_delete);
  598. /**
  599. * scsi_is_sas_phy - check if a struct device represents a SAS PHY
  600. * @dev: device to check
  601. *
  602. * Returns:
  603. * %1 if the device represents a SAS PHY, %0 else
  604. */
  605. int scsi_is_sas_phy(const struct device *dev)
  606. {
  607. return dev->release == sas_phy_release;
  608. }
  609. EXPORT_SYMBOL(scsi_is_sas_phy);
  610. /*
  611. * SAS Port attributes
  612. */
  613. #define sas_port_show_simple(field, name, format_string, cast) \
  614. static ssize_t \
  615. show_sas_port_##name(struct device *dev, \
  616. struct device_attribute *attr, char *buf) \
  617. { \
  618. struct sas_port *port = transport_class_to_sas_port(dev); \
  619. \
  620. return snprintf(buf, 20, format_string, cast port->field); \
  621. }
  622. #define sas_port_simple_attr(field, name, format_string, type) \
  623. sas_port_show_simple(field, name, format_string, (type)) \
  624. static DEVICE_ATTR(name, S_IRUGO, show_sas_port_##name, NULL)
  625. sas_port_simple_attr(num_phys, num_phys, "%d\n", int);
  626. static DECLARE_TRANSPORT_CLASS(sas_port_class,
  627. "sas_port", NULL, NULL, NULL);
  628. static int sas_port_match(struct attribute_container *cont, struct device *dev)
  629. {
  630. struct Scsi_Host *shost;
  631. struct sas_internal *i;
  632. if (!scsi_is_sas_port(dev))
  633. return 0;
  634. shost = dev_to_shost(dev->parent);
  635. if (!shost->transportt)
  636. return 0;
  637. if (shost->transportt->host_attrs.ac.class !=
  638. &sas_host_class.class)
  639. return 0;
  640. i = to_sas_internal(shost->transportt);
  641. return &i->port_attr_cont.ac == cont;
  642. }
  643. static void sas_port_release(struct device *dev)
  644. {
  645. struct sas_port *port = dev_to_sas_port(dev);
  646. BUG_ON(!list_empty(&port->phy_list));
  647. put_device(dev->parent);
  648. kfree(port);
  649. }
  650. static void sas_port_create_link(struct sas_port *port,
  651. struct sas_phy *phy)
  652. {
  653. int res;
  654. res = sysfs_create_link(&port->dev.kobj, &phy->dev.kobj,
  655. dev_name(&phy->dev));
  656. if (res)
  657. goto err;
  658. res = sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port");
  659. if (res)
  660. goto err;
  661. return;
  662. err:
  663. printk(KERN_ERR "%s: Cannot create port links, err=%d\n",
  664. __func__, res);
  665. }
  666. static void sas_port_delete_link(struct sas_port *port,
  667. struct sas_phy *phy)
  668. {
  669. sysfs_remove_link(&port->dev.kobj, dev_name(&phy->dev));
  670. sysfs_remove_link(&phy->dev.kobj, "port");
  671. }
  672. /** sas_port_alloc - allocate and initialize a SAS port structure
  673. *
  674. * @parent: parent device
  675. * @port_id: port number
  676. *
  677. * Allocates a SAS port structure. It will be added to the device tree
  678. * below the device specified by @parent which must be either a Scsi_Host
  679. * or a sas_expander_device.
  680. *
  681. * Returns %NULL on error
  682. */
  683. struct sas_port *sas_port_alloc(struct device *parent, int port_id)
  684. {
  685. struct Scsi_Host *shost = dev_to_shost(parent);
  686. struct sas_port *port;
  687. port = kzalloc(sizeof(*port), GFP_KERNEL);
  688. if (!port)
  689. return NULL;
  690. port->port_identifier = port_id;
  691. device_initialize(&port->dev);
  692. port->dev.parent = get_device(parent);
  693. port->dev.release = sas_port_release;
  694. mutex_init(&port->phy_list_mutex);
  695. INIT_LIST_HEAD(&port->phy_list);
  696. if (scsi_is_sas_expander_device(parent)) {
  697. struct sas_rphy *rphy = dev_to_rphy(parent);
  698. dev_set_name(&port->dev, "port-%d:%d:%d", shost->host_no,
  699. rphy->scsi_target_id, port->port_identifier);
  700. } else
  701. dev_set_name(&port->dev, "port-%d:%d", shost->host_no,
  702. port->port_identifier);
  703. transport_setup_device(&port->dev);
  704. return port;
  705. }
  706. EXPORT_SYMBOL(sas_port_alloc);
  707. /** sas_port_alloc_num - allocate and initialize a SAS port structure
  708. *
  709. * @parent: parent device
  710. *
  711. * Allocates a SAS port structure and a number to go with it. This
  712. * interface is really for adapters where the port number has no
  713. * meansing, so the sas class should manage them. It will be added to
  714. * the device tree below the device specified by @parent which must be
  715. * either a Scsi_Host or a sas_expander_device.
  716. *
  717. * Returns %NULL on error
  718. */
  719. struct sas_port *sas_port_alloc_num(struct device *parent)
  720. {
  721. int index;
  722. struct Scsi_Host *shost = dev_to_shost(parent);
  723. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  724. /* FIXME: use idr for this eventually */
  725. mutex_lock(&sas_host->lock);
  726. if (scsi_is_sas_expander_device(parent)) {
  727. struct sas_rphy *rphy = dev_to_rphy(parent);
  728. struct sas_expander_device *exp = rphy_to_expander_device(rphy);
  729. index = exp->next_port_id++;
  730. } else
  731. index = sas_host->next_port_id++;
  732. mutex_unlock(&sas_host->lock);
  733. return sas_port_alloc(parent, index);
  734. }
  735. EXPORT_SYMBOL(sas_port_alloc_num);
  736. /**
  737. * sas_port_add - add a SAS port to the device hierarchy
  738. * @port: port to be added
  739. *
  740. * publishes a port to the rest of the system
  741. */
  742. int sas_port_add(struct sas_port *port)
  743. {
  744. int error;
  745. /* No phys should be added until this is made visible */
  746. BUG_ON(!list_empty(&port->phy_list));
  747. error = device_add(&port->dev);
  748. if (error)
  749. return error;
  750. transport_add_device(&port->dev);
  751. transport_configure_device(&port->dev);
  752. return 0;
  753. }
  754. EXPORT_SYMBOL(sas_port_add);
  755. /**
  756. * sas_port_free - free a SAS PORT
  757. * @port: SAS PORT to free
  758. *
  759. * Frees the specified SAS PORT.
  760. *
  761. * Note:
  762. * This function must only be called on a PORT that has not
  763. * sucessfully been added using sas_port_add().
  764. */
  765. void sas_port_free(struct sas_port *port)
  766. {
  767. transport_destroy_device(&port->dev);
  768. put_device(&port->dev);
  769. }
  770. EXPORT_SYMBOL(sas_port_free);
  771. /**
  772. * sas_port_delete - remove SAS PORT
  773. * @port: SAS PORT to remove
  774. *
  775. * Removes the specified SAS PORT. If the SAS PORT has an
  776. * associated phys, unlink them from the port as well.
  777. */
  778. void sas_port_delete(struct sas_port *port)
  779. {
  780. struct device *dev = &port->dev;
  781. struct sas_phy *phy, *tmp_phy;
  782. if (port->rphy) {
  783. sas_rphy_delete(port->rphy);
  784. port->rphy = NULL;
  785. }
  786. mutex_lock(&port->phy_list_mutex);
  787. list_for_each_entry_safe(phy, tmp_phy, &port->phy_list,
  788. port_siblings) {
  789. sas_port_delete_link(port, phy);
  790. list_del_init(&phy->port_siblings);
  791. }
  792. mutex_unlock(&port->phy_list_mutex);
  793. if (port->is_backlink) {
  794. struct device *parent = port->dev.parent;
  795. sysfs_remove_link(&port->dev.kobj, dev_name(parent));
  796. port->is_backlink = 0;
  797. }
  798. transport_remove_device(dev);
  799. device_del(dev);
  800. transport_destroy_device(dev);
  801. put_device(dev);
  802. }
  803. EXPORT_SYMBOL(sas_port_delete);
  804. /**
  805. * scsi_is_sas_port - check if a struct device represents a SAS port
  806. * @dev: device to check
  807. *
  808. * Returns:
  809. * %1 if the device represents a SAS Port, %0 else
  810. */
  811. int scsi_is_sas_port(const struct device *dev)
  812. {
  813. return dev->release == sas_port_release;
  814. }
  815. EXPORT_SYMBOL(scsi_is_sas_port);
  816. /**
  817. * sas_port_add_phy - add another phy to a port to form a wide port
  818. * @port: port to add the phy to
  819. * @phy: phy to add
  820. *
  821. * When a port is initially created, it is empty (has no phys). All
  822. * ports must have at least one phy to operated, and all wide ports
  823. * must have at least two. The current code makes no difference
  824. * between ports and wide ports, but the only object that can be
  825. * connected to a remote device is a port, so ports must be formed on
  826. * all devices with phys if they're connected to anything.
  827. */
  828. void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy)
  829. {
  830. mutex_lock(&port->phy_list_mutex);
  831. if (unlikely(!list_empty(&phy->port_siblings))) {
  832. /* make sure we're already on this port */
  833. struct sas_phy *tmp;
  834. list_for_each_entry(tmp, &port->phy_list, port_siblings)
  835. if (tmp == phy)
  836. break;
  837. /* If this trips, you added a phy that was already
  838. * part of a different port */
  839. if (unlikely(tmp != phy)) {
  840. dev_printk(KERN_ERR, &port->dev, "trying to add phy %s fails: it's already part of another port\n",
  841. dev_name(&phy->dev));
  842. BUG();
  843. }
  844. } else {
  845. sas_port_create_link(port, phy);
  846. list_add_tail(&phy->port_siblings, &port->phy_list);
  847. port->num_phys++;
  848. }
  849. mutex_unlock(&port->phy_list_mutex);
  850. }
  851. EXPORT_SYMBOL(sas_port_add_phy);
  852. /**
  853. * sas_port_delete_phy - remove a phy from a port or wide port
  854. * @port: port to remove the phy from
  855. * @phy: phy to remove
  856. *
  857. * This operation is used for tearing down ports again. It must be
  858. * done to every port or wide port before calling sas_port_delete.
  859. */
  860. void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy)
  861. {
  862. mutex_lock(&port->phy_list_mutex);
  863. sas_port_delete_link(port, phy);
  864. list_del_init(&phy->port_siblings);
  865. port->num_phys--;
  866. mutex_unlock(&port->phy_list_mutex);
  867. }
  868. EXPORT_SYMBOL(sas_port_delete_phy);
  869. void sas_port_mark_backlink(struct sas_port *port)
  870. {
  871. int res;
  872. struct device *parent = port->dev.parent->parent->parent;
  873. if (port->is_backlink)
  874. return;
  875. port->is_backlink = 1;
  876. res = sysfs_create_link(&port->dev.kobj, &parent->kobj,
  877. dev_name(parent));
  878. if (res)
  879. goto err;
  880. return;
  881. err:
  882. printk(KERN_ERR "%s: Cannot create port backlink, err=%d\n",
  883. __func__, res);
  884. }
  885. EXPORT_SYMBOL(sas_port_mark_backlink);
  886. /*
  887. * SAS remote PHY attributes.
  888. */
  889. #define sas_rphy_show_simple(field, name, format_string, cast) \
  890. static ssize_t \
  891. show_sas_rphy_##name(struct device *dev, \
  892. struct device_attribute *attr, char *buf) \
  893. { \
  894. struct sas_rphy *rphy = transport_class_to_rphy(dev); \
  895. \
  896. return snprintf(buf, 20, format_string, cast rphy->field); \
  897. }
  898. #define sas_rphy_simple_attr(field, name, format_string, type) \
  899. sas_rphy_show_simple(field, name, format_string, (type)) \
  900. static SAS_DEVICE_ATTR(rphy, name, S_IRUGO, \
  901. show_sas_rphy_##name, NULL)
  902. #define sas_rphy_show_protocol(field, name) \
  903. static ssize_t \
  904. show_sas_rphy_##name(struct device *dev, \
  905. struct device_attribute *attr, char *buf) \
  906. { \
  907. struct sas_rphy *rphy = transport_class_to_rphy(dev); \
  908. \
  909. if (!rphy->field) \
  910. return snprintf(buf, 20, "none\n"); \
  911. return get_sas_protocol_names(rphy->field, buf); \
  912. }
  913. #define sas_rphy_protocol_attr(field, name) \
  914. sas_rphy_show_protocol(field, name) \
  915. static SAS_DEVICE_ATTR(rphy, name, S_IRUGO, \
  916. show_sas_rphy_##name, NULL)
  917. static ssize_t
  918. show_sas_rphy_device_type(struct device *dev,
  919. struct device_attribute *attr, char *buf)
  920. {
  921. struct sas_rphy *rphy = transport_class_to_rphy(dev);
  922. if (!rphy->identify.device_type)
  923. return snprintf(buf, 20, "none\n");
  924. return get_sas_device_type_names(
  925. rphy->identify.device_type, buf);
  926. }
  927. static SAS_DEVICE_ATTR(rphy, device_type, S_IRUGO,
  928. show_sas_rphy_device_type, NULL);
  929. static ssize_t
  930. show_sas_rphy_enclosure_identifier(struct device *dev,
  931. struct device_attribute *attr, char *buf)
  932. {
  933. struct sas_rphy *rphy = transport_class_to_rphy(dev);
  934. struct sas_phy *phy = dev_to_phy(rphy->dev.parent);
  935. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  936. struct sas_internal *i = to_sas_internal(shost->transportt);
  937. u64 identifier;
  938. int error;
  939. /*
  940. * Only devices behind an expander are supported, because the
  941. * enclosure identifier is a SMP feature.
  942. */
  943. if (scsi_is_sas_phy_local(phy))
  944. return -EINVAL;
  945. error = i->f->get_enclosure_identifier(rphy, &identifier);
  946. if (error)
  947. return error;
  948. return sprintf(buf, "0x%llx\n", (unsigned long long)identifier);
  949. }
  950. static SAS_DEVICE_ATTR(rphy, enclosure_identifier, S_IRUGO,
  951. show_sas_rphy_enclosure_identifier, NULL);
  952. static ssize_t
  953. show_sas_rphy_bay_identifier(struct device *dev,
  954. struct device_attribute *attr, char *buf)
  955. {
  956. struct sas_rphy *rphy = transport_class_to_rphy(dev);
  957. struct sas_phy *phy = dev_to_phy(rphy->dev.parent);
  958. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  959. struct sas_internal *i = to_sas_internal(shost->transportt);
  960. int val;
  961. if (scsi_is_sas_phy_local(phy))
  962. return -EINVAL;
  963. val = i->f->get_bay_identifier(rphy);
  964. if (val < 0)
  965. return val;
  966. return sprintf(buf, "%d\n", val);
  967. }
  968. static SAS_DEVICE_ATTR(rphy, bay_identifier, S_IRUGO,
  969. show_sas_rphy_bay_identifier, NULL);
  970. sas_rphy_protocol_attr(identify.initiator_port_protocols,
  971. initiator_port_protocols);
  972. sas_rphy_protocol_attr(identify.target_port_protocols, target_port_protocols);
  973. sas_rphy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
  974. unsigned long long);
  975. sas_rphy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
  976. /* only need 8 bytes of data plus header (4 or 8) */
  977. #define BUF_SIZE 64
  978. int sas_read_port_mode_page(struct scsi_device *sdev)
  979. {
  980. char *buffer = kzalloc(BUF_SIZE, GFP_KERNEL), *msdata;
  981. struct sas_rphy *rphy = target_to_rphy(sdev->sdev_target);
  982. struct sas_end_device *rdev;
  983. struct scsi_mode_data mode_data;
  984. int res, error;
  985. BUG_ON(rphy->identify.device_type != SAS_END_DEVICE);
  986. rdev = rphy_to_end_device(rphy);
  987. if (!buffer)
  988. return -ENOMEM;
  989. res = scsi_mode_sense(sdev, 1, 0x19, buffer, BUF_SIZE, 30*HZ, 3,
  990. &mode_data, NULL);
  991. error = -EINVAL;
  992. if (!scsi_status_is_good(res))
  993. goto out;
  994. msdata = buffer + mode_data.header_length +
  995. mode_data.block_descriptor_length;
  996. if (msdata - buffer > BUF_SIZE - 8)
  997. goto out;
  998. error = 0;
  999. rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0;
  1000. rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5];
  1001. rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7];
  1002. out:
  1003. kfree(buffer);
  1004. return error;
  1005. }
  1006. EXPORT_SYMBOL(sas_read_port_mode_page);
  1007. static DECLARE_TRANSPORT_CLASS(sas_end_dev_class,
  1008. "sas_end_device", NULL, NULL, NULL);
  1009. #define sas_end_dev_show_simple(field, name, format_string, cast) \
  1010. static ssize_t \
  1011. show_sas_end_dev_##name(struct device *dev, \
  1012. struct device_attribute *attr, char *buf) \
  1013. { \
  1014. struct sas_rphy *rphy = transport_class_to_rphy(dev); \
  1015. struct sas_end_device *rdev = rphy_to_end_device(rphy); \
  1016. \
  1017. return snprintf(buf, 20, format_string, cast rdev->field); \
  1018. }
  1019. #define sas_end_dev_simple_attr(field, name, format_string, type) \
  1020. sas_end_dev_show_simple(field, name, format_string, (type)) \
  1021. static SAS_DEVICE_ATTR(end_dev, name, S_IRUGO, \
  1022. show_sas_end_dev_##name, NULL)
  1023. sas_end_dev_simple_attr(ready_led_meaning, ready_led_meaning, "%d\n", int);
  1024. sas_end_dev_simple_attr(I_T_nexus_loss_timeout, I_T_nexus_loss_timeout,
  1025. "%d\n", int);
  1026. sas_end_dev_simple_attr(initiator_response_timeout, initiator_response_timeout,
  1027. "%d\n", int);
  1028. static DECLARE_TRANSPORT_CLASS(sas_expander_class,
  1029. "sas_expander", NULL, NULL, NULL);
  1030. #define sas_expander_show_simple(field, name, format_string, cast) \
  1031. static ssize_t \
  1032. show_sas_expander_##name(struct device *dev, \
  1033. struct device_attribute *attr, char *buf) \
  1034. { \
  1035. struct sas_rphy *rphy = transport_class_to_rphy(dev); \
  1036. struct sas_expander_device *edev = rphy_to_expander_device(rphy); \
  1037. \
  1038. return snprintf(buf, 20, format_string, cast edev->field); \
  1039. }
  1040. #define sas_expander_simple_attr(field, name, format_string, type) \
  1041. sas_expander_show_simple(field, name, format_string, (type)) \
  1042. static SAS_DEVICE_ATTR(expander, name, S_IRUGO, \
  1043. show_sas_expander_##name, NULL)
  1044. sas_expander_simple_attr(vendor_id, vendor_id, "%s\n", char *);
  1045. sas_expander_simple_attr(product_id, product_id, "%s\n", char *);
  1046. sas_expander_simple_attr(product_rev, product_rev, "%s\n", char *);
  1047. sas_expander_simple_attr(component_vendor_id, component_vendor_id,
  1048. "%s\n", char *);
  1049. sas_expander_simple_attr(component_id, component_id, "%u\n", unsigned int);
  1050. sas_expander_simple_attr(component_revision_id, component_revision_id, "%u\n",
  1051. unsigned int);
  1052. sas_expander_simple_attr(level, level, "%d\n", int);
  1053. static DECLARE_TRANSPORT_CLASS(sas_rphy_class,
  1054. "sas_device", NULL, NULL, NULL);
  1055. static int sas_rphy_match(struct attribute_container *cont, struct device *dev)
  1056. {
  1057. struct Scsi_Host *shost;
  1058. struct sas_internal *i;
  1059. if (!scsi_is_sas_rphy(dev))
  1060. return 0;
  1061. shost = dev_to_shost(dev->parent->parent);
  1062. if (!shost->transportt)
  1063. return 0;
  1064. if (shost->transportt->host_attrs.ac.class !=
  1065. &sas_host_class.class)
  1066. return 0;
  1067. i = to_sas_internal(shost->transportt);
  1068. return &i->rphy_attr_cont.ac == cont;
  1069. }
  1070. static int sas_end_dev_match(struct attribute_container *cont,
  1071. struct device *dev)
  1072. {
  1073. struct Scsi_Host *shost;
  1074. struct sas_internal *i;
  1075. struct sas_rphy *rphy;
  1076. if (!scsi_is_sas_rphy(dev))
  1077. return 0;
  1078. shost = dev_to_shost(dev->parent->parent);
  1079. rphy = dev_to_rphy(dev);
  1080. if (!shost->transportt)
  1081. return 0;
  1082. if (shost->transportt->host_attrs.ac.class !=
  1083. &sas_host_class.class)
  1084. return 0;
  1085. i = to_sas_internal(shost->transportt);
  1086. return &i->end_dev_attr_cont.ac == cont &&
  1087. rphy->identify.device_type == SAS_END_DEVICE;
  1088. }
  1089. static int sas_expander_match(struct attribute_container *cont,
  1090. struct device *dev)
  1091. {
  1092. struct Scsi_Host *shost;
  1093. struct sas_internal *i;
  1094. struct sas_rphy *rphy;
  1095. if (!scsi_is_sas_rphy(dev))
  1096. return 0;
  1097. shost = dev_to_shost(dev->parent->parent);
  1098. rphy = dev_to_rphy(dev);
  1099. if (!shost->transportt)
  1100. return 0;
  1101. if (shost->transportt->host_attrs.ac.class !=
  1102. &sas_host_class.class)
  1103. return 0;
  1104. i = to_sas_internal(shost->transportt);
  1105. return &i->expander_attr_cont.ac == cont &&
  1106. (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE ||
  1107. rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE);
  1108. }
  1109. static void sas_expander_release(struct device *dev)
  1110. {
  1111. struct sas_rphy *rphy = dev_to_rphy(dev);
  1112. struct sas_expander_device *edev = rphy_to_expander_device(rphy);
  1113. if (rphy->q)
  1114. blk_cleanup_queue(rphy->q);
  1115. put_device(dev->parent);
  1116. kfree(edev);
  1117. }
  1118. static void sas_end_device_release(struct device *dev)
  1119. {
  1120. struct sas_rphy *rphy = dev_to_rphy(dev);
  1121. struct sas_end_device *edev = rphy_to_end_device(rphy);
  1122. if (rphy->q)
  1123. blk_cleanup_queue(rphy->q);
  1124. put_device(dev->parent);
  1125. kfree(edev);
  1126. }
  1127. /**
  1128. * sas_rphy_initialize - common rphy intialization
  1129. * @rphy: rphy to initialise
  1130. *
  1131. * Used by both sas_end_device_alloc() and sas_expander_alloc() to
  1132. * initialise the common rphy component of each.
  1133. */
  1134. static void sas_rphy_initialize(struct sas_rphy *rphy)
  1135. {
  1136. INIT_LIST_HEAD(&rphy->list);
  1137. }
  1138. /**
  1139. * sas_end_device_alloc - allocate an rphy for an end device
  1140. * @parent: which port
  1141. *
  1142. * Allocates an SAS remote PHY structure, connected to @parent.
  1143. *
  1144. * Returns:
  1145. * SAS PHY allocated or %NULL if the allocation failed.
  1146. */
  1147. struct sas_rphy *sas_end_device_alloc(struct sas_port *parent)
  1148. {
  1149. struct Scsi_Host *shost = dev_to_shost(&parent->dev);
  1150. struct sas_end_device *rdev;
  1151. rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
  1152. if (!rdev) {
  1153. return NULL;
  1154. }
  1155. device_initialize(&rdev->rphy.dev);
  1156. rdev->rphy.dev.parent = get_device(&parent->dev);
  1157. rdev->rphy.dev.release = sas_end_device_release;
  1158. if (scsi_is_sas_expander_device(parent->dev.parent)) {
  1159. struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent);
  1160. dev_set_name(&rdev->rphy.dev, "end_device-%d:%d:%d",
  1161. shost->host_no, rphy->scsi_target_id,
  1162. parent->port_identifier);
  1163. } else
  1164. dev_set_name(&rdev->rphy.dev, "end_device-%d:%d",
  1165. shost->host_no, parent->port_identifier);
  1166. rdev->rphy.identify.device_type = SAS_END_DEVICE;
  1167. sas_rphy_initialize(&rdev->rphy);
  1168. transport_setup_device(&rdev->rphy.dev);
  1169. return &rdev->rphy;
  1170. }
  1171. EXPORT_SYMBOL(sas_end_device_alloc);
  1172. /**
  1173. * sas_expander_alloc - allocate an rphy for an end device
  1174. * @parent: which port
  1175. * @type: SAS_EDGE_EXPANDER_DEVICE or SAS_FANOUT_EXPANDER_DEVICE
  1176. *
  1177. * Allocates an SAS remote PHY structure, connected to @parent.
  1178. *
  1179. * Returns:
  1180. * SAS PHY allocated or %NULL if the allocation failed.
  1181. */
  1182. struct sas_rphy *sas_expander_alloc(struct sas_port *parent,
  1183. enum sas_device_type type)
  1184. {
  1185. struct Scsi_Host *shost = dev_to_shost(&parent->dev);
  1186. struct sas_expander_device *rdev;
  1187. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1188. BUG_ON(type != SAS_EDGE_EXPANDER_DEVICE &&
  1189. type != SAS_FANOUT_EXPANDER_DEVICE);
  1190. rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
  1191. if (!rdev) {
  1192. return NULL;
  1193. }
  1194. device_initialize(&rdev->rphy.dev);
  1195. rdev->rphy.dev.parent = get_device(&parent->dev);
  1196. rdev->rphy.dev.release = sas_expander_release;
  1197. mutex_lock(&sas_host->lock);
  1198. rdev->rphy.scsi_target_id = sas_host->next_expander_id++;
  1199. mutex_unlock(&sas_host->lock);
  1200. dev_set_name(&rdev->rphy.dev, "expander-%d:%d",
  1201. shost->host_no, rdev->rphy.scsi_target_id);
  1202. rdev->rphy.identify.device_type = type;
  1203. sas_rphy_initialize(&rdev->rphy);
  1204. transport_setup_device(&rdev->rphy.dev);
  1205. return &rdev->rphy;
  1206. }
  1207. EXPORT_SYMBOL(sas_expander_alloc);
  1208. /**
  1209. * sas_rphy_add - add a SAS remote PHY to the device hierarchy
  1210. * @rphy: The remote PHY to be added
  1211. *
  1212. * Publishes a SAS remote PHY to the rest of the system.
  1213. */
  1214. int sas_rphy_add(struct sas_rphy *rphy)
  1215. {
  1216. struct sas_port *parent = dev_to_sas_port(rphy->dev.parent);
  1217. struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
  1218. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1219. struct sas_identify *identify = &rphy->identify;
  1220. int error;
  1221. if (parent->rphy)
  1222. return -ENXIO;
  1223. parent->rphy = rphy;
  1224. error = device_add(&rphy->dev);
  1225. if (error)
  1226. return error;
  1227. transport_add_device(&rphy->dev);
  1228. transport_configure_device(&rphy->dev);
  1229. if (sas_bsg_initialize(shost, rphy))
  1230. printk("fail to a bsg device %s\n", dev_name(&rphy->dev));
  1231. mutex_lock(&sas_host->lock);
  1232. list_add_tail(&rphy->list, &sas_host->rphy_list);
  1233. if (identify->device_type == SAS_END_DEVICE &&
  1234. (identify->target_port_protocols &
  1235. (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA)))
  1236. rphy->scsi_target_id = sas_host->next_target_id++;
  1237. else if (identify->device_type == SAS_END_DEVICE)
  1238. rphy->scsi_target_id = -1;
  1239. mutex_unlock(&sas_host->lock);
  1240. if (identify->device_type == SAS_END_DEVICE &&
  1241. rphy->scsi_target_id != -1) {
  1242. scsi_scan_target(&rphy->dev, 0,
  1243. rphy->scsi_target_id, SCAN_WILD_CARD, 0);
  1244. }
  1245. return 0;
  1246. }
  1247. EXPORT_SYMBOL(sas_rphy_add);
  1248. /**
  1249. * sas_rphy_free - free a SAS remote PHY
  1250. * @rphy: SAS remote PHY to free
  1251. *
  1252. * Frees the specified SAS remote PHY.
  1253. *
  1254. * Note:
  1255. * This function must only be called on a remote
  1256. * PHY that has not sucessfully been added using
  1257. * sas_rphy_add() (or has been sas_rphy_remove()'d)
  1258. */
  1259. void sas_rphy_free(struct sas_rphy *rphy)
  1260. {
  1261. struct device *dev = &rphy->dev;
  1262. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  1263. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1264. mutex_lock(&sas_host->lock);
  1265. list_del(&rphy->list);
  1266. mutex_unlock(&sas_host->lock);
  1267. sas_bsg_remove(shost, rphy);
  1268. transport_destroy_device(dev);
  1269. put_device(dev);
  1270. }
  1271. EXPORT_SYMBOL(sas_rphy_free);
  1272. /**
  1273. * sas_rphy_delete - remove and free SAS remote PHY
  1274. * @rphy: SAS remote PHY to remove and free
  1275. *
  1276. * Removes the specified SAS remote PHY and frees it.
  1277. */
  1278. void
  1279. sas_rphy_delete(struct sas_rphy *rphy)
  1280. {
  1281. sas_rphy_remove(rphy);
  1282. sas_rphy_free(rphy);
  1283. }
  1284. EXPORT_SYMBOL(sas_rphy_delete);
  1285. /**
  1286. * sas_rphy_remove - remove SAS remote PHY
  1287. * @rphy: SAS remote phy to remove
  1288. *
  1289. * Removes the specified SAS remote PHY.
  1290. */
  1291. void
  1292. sas_rphy_remove(struct sas_rphy *rphy)
  1293. {
  1294. struct device *dev = &rphy->dev;
  1295. struct sas_port *parent = dev_to_sas_port(dev->parent);
  1296. switch (rphy->identify.device_type) {
  1297. case SAS_END_DEVICE:
  1298. scsi_remove_target(dev);
  1299. break;
  1300. case SAS_EDGE_EXPANDER_DEVICE:
  1301. case SAS_FANOUT_EXPANDER_DEVICE:
  1302. sas_remove_children(dev);
  1303. break;
  1304. default:
  1305. break;
  1306. }
  1307. transport_remove_device(dev);
  1308. device_del(dev);
  1309. parent->rphy = NULL;
  1310. }
  1311. EXPORT_SYMBOL(sas_rphy_remove);
  1312. /**
  1313. * scsi_is_sas_rphy - check if a struct device represents a SAS remote PHY
  1314. * @dev: device to check
  1315. *
  1316. * Returns:
  1317. * %1 if the device represents a SAS remote PHY, %0 else
  1318. */
  1319. int scsi_is_sas_rphy(const struct device *dev)
  1320. {
  1321. return dev->release == sas_end_device_release ||
  1322. dev->release == sas_expander_release;
  1323. }
  1324. EXPORT_SYMBOL(scsi_is_sas_rphy);
  1325. /*
  1326. * SCSI scan helper
  1327. */
  1328. static int sas_user_scan(struct Scsi_Host *shost, uint channel,
  1329. uint id, uint lun)
  1330. {
  1331. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1332. struct sas_rphy *rphy;
  1333. mutex_lock(&sas_host->lock);
  1334. list_for_each_entry(rphy, &sas_host->rphy_list, list) {
  1335. if (rphy->identify.device_type != SAS_END_DEVICE ||
  1336. rphy->scsi_target_id == -1)
  1337. continue;
  1338. if ((channel == SCAN_WILD_CARD || channel == 0) &&
  1339. (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) {
  1340. scsi_scan_target(&rphy->dev, 0,
  1341. rphy->scsi_target_id, lun, 1);
  1342. }
  1343. }
  1344. mutex_unlock(&sas_host->lock);
  1345. return 0;
  1346. }
  1347. /*
  1348. * Setup / Teardown code
  1349. */
  1350. #define SETUP_TEMPLATE(attrb, field, perm, test) \
  1351. i->private_##attrb[count] = dev_attr_##field; \
  1352. i->private_##attrb[count].attr.mode = perm; \
  1353. i->attrb[count] = &i->private_##attrb[count]; \
  1354. if (test) \
  1355. count++
  1356. #define SETUP_TEMPLATE_RW(attrb, field, perm, test, ro_test, ro_perm) \
  1357. i->private_##attrb[count] = dev_attr_##field; \
  1358. i->private_##attrb[count].attr.mode = perm; \
  1359. if (ro_test) { \
  1360. i->private_##attrb[count].attr.mode = ro_perm; \
  1361. i->private_##attrb[count].store = NULL; \
  1362. } \
  1363. i->attrb[count] = &i->private_##attrb[count]; \
  1364. if (test) \
  1365. count++
  1366. #define SETUP_RPORT_ATTRIBUTE(field) \
  1367. SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, 1)
  1368. #define SETUP_OPTIONAL_RPORT_ATTRIBUTE(field, func) \
  1369. SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
  1370. #define SETUP_PHY_ATTRIBUTE(field) \
  1371. SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, 1)
  1372. #define SETUP_PHY_ATTRIBUTE_RW(field) \
  1373. SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \
  1374. !i->f->set_phy_speed, S_IRUGO)
  1375. #define SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(field, func) \
  1376. SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \
  1377. !i->f->func, S_IRUGO)
  1378. #define SETUP_PORT_ATTRIBUTE(field) \
  1379. SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
  1380. #define SETUP_OPTIONAL_PHY_ATTRIBUTE(field, func) \
  1381. SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
  1382. #define SETUP_PHY_ATTRIBUTE_WRONLY(field) \
  1383. SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, 1)
  1384. #define SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(field, func) \
  1385. SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func)
  1386. #define SETUP_END_DEV_ATTRIBUTE(field) \
  1387. SETUP_TEMPLATE(end_dev_attrs, field, S_IRUGO, 1)
  1388. #define SETUP_EXPANDER_ATTRIBUTE(field) \
  1389. SETUP_TEMPLATE(expander_attrs, expander_##field, S_IRUGO, 1)
  1390. /**
  1391. * sas_attach_transport - instantiate SAS transport template
  1392. * @ft: SAS transport class function template
  1393. */
  1394. struct scsi_transport_template *
  1395. sas_attach_transport(struct sas_function_template *ft)
  1396. {
  1397. struct sas_internal *i;
  1398. int count;
  1399. i = kzalloc(sizeof(struct sas_internal), GFP_KERNEL);
  1400. if (!i)
  1401. return NULL;
  1402. i->t.user_scan = sas_user_scan;
  1403. i->t.host_attrs.ac.attrs = &i->host_attrs[0];
  1404. i->t.host_attrs.ac.class = &sas_host_class.class;
  1405. i->t.host_attrs.ac.match = sas_host_match;
  1406. transport_container_register(&i->t.host_attrs);
  1407. i->t.host_size = sizeof(struct sas_host_attrs);
  1408. i->phy_attr_cont.ac.class = &sas_phy_class.class;
  1409. i->phy_attr_cont.ac.attrs = &i->phy_attrs[0];
  1410. i->phy_attr_cont.ac.match = sas_phy_match;
  1411. transport_container_register(&i->phy_attr_cont);
  1412. i->port_attr_cont.ac.class = &sas_port_class.class;
  1413. i->port_attr_cont.ac.attrs = &i->port_attrs[0];
  1414. i->port_attr_cont.ac.match = sas_port_match;
  1415. transport_container_register(&i->port_attr_cont);
  1416. i->rphy_attr_cont.ac.class = &sas_rphy_class.class;
  1417. i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0];
  1418. i->rphy_attr_cont.ac.match = sas_rphy_match;
  1419. transport_container_register(&i->rphy_attr_cont);
  1420. i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class;
  1421. i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0];
  1422. i->end_dev_attr_cont.ac.match = sas_end_dev_match;
  1423. transport_container_register(&i->end_dev_attr_cont);
  1424. i->expander_attr_cont.ac.class = &sas_expander_class.class;
  1425. i->expander_attr_cont.ac.attrs = &i->expander_attrs[0];
  1426. i->expander_attr_cont.ac.match = sas_expander_match;
  1427. transport_container_register(&i->expander_attr_cont);
  1428. i->f = ft;
  1429. count = 0;
  1430. SETUP_PORT_ATTRIBUTE(num_phys);
  1431. i->host_attrs[count] = NULL;
  1432. count = 0;
  1433. SETUP_PHY_ATTRIBUTE(initiator_port_protocols);
  1434. SETUP_PHY_ATTRIBUTE(target_port_protocols);
  1435. SETUP_PHY_ATTRIBUTE(device_type);
  1436. SETUP_PHY_ATTRIBUTE(sas_address);
  1437. SETUP_PHY_ATTRIBUTE(phy_identifier);
  1438. //SETUP_PHY_ATTRIBUTE(port_identifier);
  1439. SETUP_PHY_ATTRIBUTE(negotiated_linkrate);
  1440. SETUP_PHY_ATTRIBUTE(minimum_linkrate_hw);
  1441. SETUP_PHY_ATTRIBUTE_RW(minimum_linkrate);
  1442. SETUP_PHY_ATTRIBUTE(maximum_linkrate_hw);
  1443. SETUP_PHY_ATTRIBUTE_RW(maximum_linkrate);
  1444. SETUP_PHY_ATTRIBUTE(invalid_dword_count);
  1445. SETUP_PHY_ATTRIBUTE(running_disparity_error_count);
  1446. SETUP_PHY_ATTRIBUTE(loss_of_dword_sync_count);
  1447. SETUP_PHY_ATTRIBUTE(phy_reset_problem_count);
  1448. SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(link_reset, phy_reset);
  1449. SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(hard_reset, phy_reset);
  1450. SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(enable, phy_enable);
  1451. i->phy_attrs[count] = NULL;
  1452. count = 0;
  1453. SETUP_PORT_ATTRIBUTE(num_phys);
  1454. i->port_attrs[count] = NULL;
  1455. count = 0;
  1456. SETUP_RPORT_ATTRIBUTE(rphy_initiator_port_protocols);
  1457. SETUP_RPORT_ATTRIBUTE(rphy_target_port_protocols);
  1458. SETUP_RPORT_ATTRIBUTE(rphy_device_type);
  1459. SETUP_RPORT_ATTRIBUTE(rphy_sas_address);
  1460. SETUP_RPORT_ATTRIBUTE(rphy_phy_identifier);
  1461. SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_enclosure_identifier,
  1462. get_enclosure_identifier);
  1463. SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_bay_identifier,
  1464. get_bay_identifier);
  1465. i->rphy_attrs[count] = NULL;
  1466. count = 0;
  1467. SETUP_END_DEV_ATTRIBUTE(end_dev_ready_led_meaning);
  1468. SETUP_END_DEV_ATTRIBUTE(end_dev_I_T_nexus_loss_timeout);
  1469. SETUP_END_DEV_ATTRIBUTE(end_dev_initiator_response_timeout);
  1470. i->end_dev_attrs[count] = NULL;
  1471. count = 0;
  1472. SETUP_EXPANDER_ATTRIBUTE(vendor_id);
  1473. SETUP_EXPANDER_ATTRIBUTE(product_id);
  1474. SETUP_EXPANDER_ATTRIBUTE(product_rev);
  1475. SETUP_EXPANDER_ATTRIBUTE(component_vendor_id);
  1476. SETUP_EXPANDER_ATTRIBUTE(component_id);
  1477. SETUP_EXPANDER_ATTRIBUTE(component_revision_id);
  1478. SETUP_EXPANDER_ATTRIBUTE(level);
  1479. i->expander_attrs[count] = NULL;
  1480. return &i->t;
  1481. }
  1482. EXPORT_SYMBOL(sas_attach_transport);
  1483. /**
  1484. * sas_release_transport - release SAS transport template instance
  1485. * @t: transport template instance
  1486. */
  1487. void sas_release_transport(struct scsi_transport_template *t)
  1488. {
  1489. struct sas_internal *i = to_sas_internal(t);
  1490. transport_container_unregister(&i->t.host_attrs);
  1491. transport_container_unregister(&i->phy_attr_cont);
  1492. transport_container_unregister(&i->port_attr_cont);
  1493. transport_container_unregister(&i->rphy_attr_cont);
  1494. transport_container_unregister(&i->end_dev_attr_cont);
  1495. transport_container_unregister(&i->expander_attr_cont);
  1496. kfree(i);
  1497. }
  1498. EXPORT_SYMBOL(sas_release_transport);
  1499. static __init int sas_transport_init(void)
  1500. {
  1501. int error;
  1502. error = transport_class_register(&sas_host_class);
  1503. if (error)
  1504. goto out;
  1505. error = transport_class_register(&sas_phy_class);
  1506. if (error)
  1507. goto out_unregister_transport;
  1508. error = transport_class_register(&sas_port_class);
  1509. if (error)
  1510. goto out_unregister_phy;
  1511. error = transport_class_register(&sas_rphy_class);
  1512. if (error)
  1513. goto out_unregister_port;
  1514. error = transport_class_register(&sas_end_dev_class);
  1515. if (error)
  1516. goto out_unregister_rphy;
  1517. error = transport_class_register(&sas_expander_class);
  1518. if (error)
  1519. goto out_unregister_end_dev;
  1520. return 0;
  1521. out_unregister_end_dev:
  1522. transport_class_unregister(&sas_end_dev_class);
  1523. out_unregister_rphy:
  1524. transport_class_unregister(&sas_rphy_class);
  1525. out_unregister_port:
  1526. transport_class_unregister(&sas_port_class);
  1527. out_unregister_phy:
  1528. transport_class_unregister(&sas_phy_class);
  1529. out_unregister_transport:
  1530. transport_class_unregister(&sas_host_class);
  1531. out:
  1532. return error;
  1533. }
  1534. static void __exit sas_transport_exit(void)
  1535. {
  1536. transport_class_unregister(&sas_host_class);
  1537. transport_class_unregister(&sas_phy_class);
  1538. transport_class_unregister(&sas_port_class);
  1539. transport_class_unregister(&sas_rphy_class);
  1540. transport_class_unregister(&sas_end_dev_class);
  1541. transport_class_unregister(&sas_expander_class);
  1542. }
  1543. MODULE_AUTHOR("Christoph Hellwig");
  1544. MODULE_DESCRIPTION("SAS Transport Attributes");
  1545. MODULE_LICENSE("GPL");
  1546. module_init(sas_transport_init);
  1547. module_exit(sas_transport_exit);