scsi_transport_sas.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  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[BUS_ID_SIZE];
  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->bus_id;
  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. set_bit(QUEUE_FLAG_BIDI, &q->queue_flags);
  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. sprintf(phy->dev.bus_id, "phy-%d:%d:%d", shost->host_no,
  539. rphy->scsi_target_id, number);
  540. } else
  541. sprintf(phy->dev.bus_id, "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. phy->dev.bus_id);
  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. __FUNCTION__, 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, phy->dev.bus_id);
  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. sprintf(port->dev.bus_id, "port-%d:%d:%d", shost->host_no,
  699. rphy->scsi_target_id, port->port_identifier);
  700. } else
  701. sprintf(port->dev.bus_id, "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, parent->bus_id);
  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", phy->dev.bus_id);
  841. BUG();
  842. }
  843. } else {
  844. sas_port_create_link(port, phy);
  845. list_add_tail(&phy->port_siblings, &port->phy_list);
  846. port->num_phys++;
  847. }
  848. mutex_unlock(&port->phy_list_mutex);
  849. }
  850. EXPORT_SYMBOL(sas_port_add_phy);
  851. /**
  852. * sas_port_delete_phy - remove a phy from a port or wide port
  853. * @port: port to remove the phy from
  854. * @phy: phy to remove
  855. *
  856. * This operation is used for tearing down ports again. It must be
  857. * done to every port or wide port before calling sas_port_delete.
  858. */
  859. void sas_port_delete_phy(struct sas_port *port, struct sas_phy *phy)
  860. {
  861. mutex_lock(&port->phy_list_mutex);
  862. sas_port_delete_link(port, phy);
  863. list_del_init(&phy->port_siblings);
  864. port->num_phys--;
  865. mutex_unlock(&port->phy_list_mutex);
  866. }
  867. EXPORT_SYMBOL(sas_port_delete_phy);
  868. void sas_port_mark_backlink(struct sas_port *port)
  869. {
  870. int res;
  871. struct device *parent = port->dev.parent->parent->parent;
  872. if (port->is_backlink)
  873. return;
  874. port->is_backlink = 1;
  875. res = sysfs_create_link(&port->dev.kobj, &parent->kobj,
  876. parent->bus_id);
  877. if (res)
  878. goto err;
  879. return;
  880. err:
  881. printk(KERN_ERR "%s: Cannot create port backlink, err=%d\n",
  882. __FUNCTION__, res);
  883. }
  884. EXPORT_SYMBOL(sas_port_mark_backlink);
  885. /*
  886. * SAS remote PHY attributes.
  887. */
  888. #define sas_rphy_show_simple(field, name, format_string, cast) \
  889. static ssize_t \
  890. show_sas_rphy_##name(struct device *dev, \
  891. struct device_attribute *attr, char *buf) \
  892. { \
  893. struct sas_rphy *rphy = transport_class_to_rphy(dev); \
  894. \
  895. return snprintf(buf, 20, format_string, cast rphy->field); \
  896. }
  897. #define sas_rphy_simple_attr(field, name, format_string, type) \
  898. sas_rphy_show_simple(field, name, format_string, (type)) \
  899. static SAS_DEVICE_ATTR(rphy, name, S_IRUGO, \
  900. show_sas_rphy_##name, NULL)
  901. #define sas_rphy_show_protocol(field, name) \
  902. static ssize_t \
  903. show_sas_rphy_##name(struct device *dev, \
  904. struct device_attribute *attr, char *buf) \
  905. { \
  906. struct sas_rphy *rphy = transport_class_to_rphy(dev); \
  907. \
  908. if (!rphy->field) \
  909. return snprintf(buf, 20, "none\n"); \
  910. return get_sas_protocol_names(rphy->field, buf); \
  911. }
  912. #define sas_rphy_protocol_attr(field, name) \
  913. sas_rphy_show_protocol(field, name) \
  914. static SAS_DEVICE_ATTR(rphy, name, S_IRUGO, \
  915. show_sas_rphy_##name, NULL)
  916. static ssize_t
  917. show_sas_rphy_device_type(struct device *dev,
  918. struct device_attribute *attr, char *buf)
  919. {
  920. struct sas_rphy *rphy = transport_class_to_rphy(dev);
  921. if (!rphy->identify.device_type)
  922. return snprintf(buf, 20, "none\n");
  923. return get_sas_device_type_names(
  924. rphy->identify.device_type, buf);
  925. }
  926. static SAS_DEVICE_ATTR(rphy, device_type, S_IRUGO,
  927. show_sas_rphy_device_type, NULL);
  928. static ssize_t
  929. show_sas_rphy_enclosure_identifier(struct device *dev,
  930. struct device_attribute *attr, char *buf)
  931. {
  932. struct sas_rphy *rphy = transport_class_to_rphy(dev);
  933. struct sas_phy *phy = dev_to_phy(rphy->dev.parent);
  934. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  935. struct sas_internal *i = to_sas_internal(shost->transportt);
  936. u64 identifier;
  937. int error;
  938. /*
  939. * Only devices behind an expander are supported, because the
  940. * enclosure identifier is a SMP feature.
  941. */
  942. if (scsi_is_sas_phy_local(phy))
  943. return -EINVAL;
  944. error = i->f->get_enclosure_identifier(rphy, &identifier);
  945. if (error)
  946. return error;
  947. return sprintf(buf, "0x%llx\n", (unsigned long long)identifier);
  948. }
  949. static SAS_DEVICE_ATTR(rphy, enclosure_identifier, S_IRUGO,
  950. show_sas_rphy_enclosure_identifier, NULL);
  951. static ssize_t
  952. show_sas_rphy_bay_identifier(struct device *dev,
  953. struct device_attribute *attr, char *buf)
  954. {
  955. struct sas_rphy *rphy = transport_class_to_rphy(dev);
  956. struct sas_phy *phy = dev_to_phy(rphy->dev.parent);
  957. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  958. struct sas_internal *i = to_sas_internal(shost->transportt);
  959. int val;
  960. if (scsi_is_sas_phy_local(phy))
  961. return -EINVAL;
  962. val = i->f->get_bay_identifier(rphy);
  963. if (val < 0)
  964. return val;
  965. return sprintf(buf, "%d\n", val);
  966. }
  967. static SAS_DEVICE_ATTR(rphy, bay_identifier, S_IRUGO,
  968. show_sas_rphy_bay_identifier, NULL);
  969. sas_rphy_protocol_attr(identify.initiator_port_protocols,
  970. initiator_port_protocols);
  971. sas_rphy_protocol_attr(identify.target_port_protocols, target_port_protocols);
  972. sas_rphy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
  973. unsigned long long);
  974. sas_rphy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
  975. /* only need 8 bytes of data plus header (4 or 8) */
  976. #define BUF_SIZE 64
  977. int sas_read_port_mode_page(struct scsi_device *sdev)
  978. {
  979. char *buffer = kzalloc(BUF_SIZE, GFP_KERNEL), *msdata;
  980. struct sas_rphy *rphy = target_to_rphy(sdev->sdev_target);
  981. struct sas_end_device *rdev;
  982. struct scsi_mode_data mode_data;
  983. int res, error;
  984. BUG_ON(rphy->identify.device_type != SAS_END_DEVICE);
  985. rdev = rphy_to_end_device(rphy);
  986. if (!buffer)
  987. return -ENOMEM;
  988. res = scsi_mode_sense(sdev, 1, 0x19, buffer, BUF_SIZE, 30*HZ, 3,
  989. &mode_data, NULL);
  990. error = -EINVAL;
  991. if (!scsi_status_is_good(res))
  992. goto out;
  993. msdata = buffer + mode_data.header_length +
  994. mode_data.block_descriptor_length;
  995. if (msdata - buffer > BUF_SIZE - 8)
  996. goto out;
  997. error = 0;
  998. rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0;
  999. rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5];
  1000. rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7];
  1001. out:
  1002. kfree(buffer);
  1003. return error;
  1004. }
  1005. EXPORT_SYMBOL(sas_read_port_mode_page);
  1006. static DECLARE_TRANSPORT_CLASS(sas_end_dev_class,
  1007. "sas_end_device", NULL, NULL, NULL);
  1008. #define sas_end_dev_show_simple(field, name, format_string, cast) \
  1009. static ssize_t \
  1010. show_sas_end_dev_##name(struct device *dev, \
  1011. struct device_attribute *attr, char *buf) \
  1012. { \
  1013. struct sas_rphy *rphy = transport_class_to_rphy(dev); \
  1014. struct sas_end_device *rdev = rphy_to_end_device(rphy); \
  1015. \
  1016. return snprintf(buf, 20, format_string, cast rdev->field); \
  1017. }
  1018. #define sas_end_dev_simple_attr(field, name, format_string, type) \
  1019. sas_end_dev_show_simple(field, name, format_string, (type)) \
  1020. static SAS_DEVICE_ATTR(end_dev, name, S_IRUGO, \
  1021. show_sas_end_dev_##name, NULL)
  1022. sas_end_dev_simple_attr(ready_led_meaning, ready_led_meaning, "%d\n", int);
  1023. sas_end_dev_simple_attr(I_T_nexus_loss_timeout, I_T_nexus_loss_timeout,
  1024. "%d\n", int);
  1025. sas_end_dev_simple_attr(initiator_response_timeout, initiator_response_timeout,
  1026. "%d\n", int);
  1027. static DECLARE_TRANSPORT_CLASS(sas_expander_class,
  1028. "sas_expander", NULL, NULL, NULL);
  1029. #define sas_expander_show_simple(field, name, format_string, cast) \
  1030. static ssize_t \
  1031. show_sas_expander_##name(struct device *dev, \
  1032. struct device_attribute *attr, char *buf) \
  1033. { \
  1034. struct sas_rphy *rphy = transport_class_to_rphy(dev); \
  1035. struct sas_expander_device *edev = rphy_to_expander_device(rphy); \
  1036. \
  1037. return snprintf(buf, 20, format_string, cast edev->field); \
  1038. }
  1039. #define sas_expander_simple_attr(field, name, format_string, type) \
  1040. sas_expander_show_simple(field, name, format_string, (type)) \
  1041. static SAS_DEVICE_ATTR(expander, name, S_IRUGO, \
  1042. show_sas_expander_##name, NULL)
  1043. sas_expander_simple_attr(vendor_id, vendor_id, "%s\n", char *);
  1044. sas_expander_simple_attr(product_id, product_id, "%s\n", char *);
  1045. sas_expander_simple_attr(product_rev, product_rev, "%s\n", char *);
  1046. sas_expander_simple_attr(component_vendor_id, component_vendor_id,
  1047. "%s\n", char *);
  1048. sas_expander_simple_attr(component_id, component_id, "%u\n", unsigned int);
  1049. sas_expander_simple_attr(component_revision_id, component_revision_id, "%u\n",
  1050. unsigned int);
  1051. sas_expander_simple_attr(level, level, "%d\n", int);
  1052. static DECLARE_TRANSPORT_CLASS(sas_rphy_class,
  1053. "sas_device", NULL, NULL, NULL);
  1054. static int sas_rphy_match(struct attribute_container *cont, struct device *dev)
  1055. {
  1056. struct Scsi_Host *shost;
  1057. struct sas_internal *i;
  1058. if (!scsi_is_sas_rphy(dev))
  1059. return 0;
  1060. shost = dev_to_shost(dev->parent->parent);
  1061. if (!shost->transportt)
  1062. return 0;
  1063. if (shost->transportt->host_attrs.ac.class !=
  1064. &sas_host_class.class)
  1065. return 0;
  1066. i = to_sas_internal(shost->transportt);
  1067. return &i->rphy_attr_cont.ac == cont;
  1068. }
  1069. static int sas_end_dev_match(struct attribute_container *cont,
  1070. struct device *dev)
  1071. {
  1072. struct Scsi_Host *shost;
  1073. struct sas_internal *i;
  1074. struct sas_rphy *rphy;
  1075. if (!scsi_is_sas_rphy(dev))
  1076. return 0;
  1077. shost = dev_to_shost(dev->parent->parent);
  1078. rphy = dev_to_rphy(dev);
  1079. if (!shost->transportt)
  1080. return 0;
  1081. if (shost->transportt->host_attrs.ac.class !=
  1082. &sas_host_class.class)
  1083. return 0;
  1084. i = to_sas_internal(shost->transportt);
  1085. return &i->end_dev_attr_cont.ac == cont &&
  1086. rphy->identify.device_type == SAS_END_DEVICE;
  1087. }
  1088. static int sas_expander_match(struct attribute_container *cont,
  1089. struct device *dev)
  1090. {
  1091. struct Scsi_Host *shost;
  1092. struct sas_internal *i;
  1093. struct sas_rphy *rphy;
  1094. if (!scsi_is_sas_rphy(dev))
  1095. return 0;
  1096. shost = dev_to_shost(dev->parent->parent);
  1097. rphy = dev_to_rphy(dev);
  1098. if (!shost->transportt)
  1099. return 0;
  1100. if (shost->transportt->host_attrs.ac.class !=
  1101. &sas_host_class.class)
  1102. return 0;
  1103. i = to_sas_internal(shost->transportt);
  1104. return &i->expander_attr_cont.ac == cont &&
  1105. (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE ||
  1106. rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE);
  1107. }
  1108. static void sas_expander_release(struct device *dev)
  1109. {
  1110. struct sas_rphy *rphy = dev_to_rphy(dev);
  1111. struct sas_expander_device *edev = rphy_to_expander_device(rphy);
  1112. if (rphy->q)
  1113. blk_cleanup_queue(rphy->q);
  1114. put_device(dev->parent);
  1115. kfree(edev);
  1116. }
  1117. static void sas_end_device_release(struct device *dev)
  1118. {
  1119. struct sas_rphy *rphy = dev_to_rphy(dev);
  1120. struct sas_end_device *edev = rphy_to_end_device(rphy);
  1121. if (rphy->q)
  1122. blk_cleanup_queue(rphy->q);
  1123. put_device(dev->parent);
  1124. kfree(edev);
  1125. }
  1126. /**
  1127. * sas_rphy_initialize - common rphy intialization
  1128. * @rphy: rphy to initialise
  1129. *
  1130. * Used by both sas_end_device_alloc() and sas_expander_alloc() to
  1131. * initialise the common rphy component of each.
  1132. */
  1133. static void sas_rphy_initialize(struct sas_rphy *rphy)
  1134. {
  1135. INIT_LIST_HEAD(&rphy->list);
  1136. }
  1137. /**
  1138. * sas_end_device_alloc - allocate an rphy for an end device
  1139. * @parent: which port
  1140. *
  1141. * Allocates an SAS remote PHY structure, connected to @parent.
  1142. *
  1143. * Returns:
  1144. * SAS PHY allocated or %NULL if the allocation failed.
  1145. */
  1146. struct sas_rphy *sas_end_device_alloc(struct sas_port *parent)
  1147. {
  1148. struct Scsi_Host *shost = dev_to_shost(&parent->dev);
  1149. struct sas_end_device *rdev;
  1150. rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
  1151. if (!rdev) {
  1152. return NULL;
  1153. }
  1154. device_initialize(&rdev->rphy.dev);
  1155. rdev->rphy.dev.parent = get_device(&parent->dev);
  1156. rdev->rphy.dev.release = sas_end_device_release;
  1157. if (scsi_is_sas_expander_device(parent->dev.parent)) {
  1158. struct sas_rphy *rphy = dev_to_rphy(parent->dev.parent);
  1159. sprintf(rdev->rphy.dev.bus_id, "end_device-%d:%d:%d",
  1160. shost->host_no, rphy->scsi_target_id, parent->port_identifier);
  1161. } else
  1162. sprintf(rdev->rphy.dev.bus_id, "end_device-%d:%d",
  1163. shost->host_no, parent->port_identifier);
  1164. rdev->rphy.identify.device_type = SAS_END_DEVICE;
  1165. sas_rphy_initialize(&rdev->rphy);
  1166. transport_setup_device(&rdev->rphy.dev);
  1167. return &rdev->rphy;
  1168. }
  1169. EXPORT_SYMBOL(sas_end_device_alloc);
  1170. /**
  1171. * sas_expander_alloc - allocate an rphy for an end device
  1172. * @parent: which port
  1173. * @type: SAS_EDGE_EXPANDER_DEVICE or SAS_FANOUT_EXPANDER_DEVICE
  1174. *
  1175. * Allocates an SAS remote PHY structure, connected to @parent.
  1176. *
  1177. * Returns:
  1178. * SAS PHY allocated or %NULL if the allocation failed.
  1179. */
  1180. struct sas_rphy *sas_expander_alloc(struct sas_port *parent,
  1181. enum sas_device_type type)
  1182. {
  1183. struct Scsi_Host *shost = dev_to_shost(&parent->dev);
  1184. struct sas_expander_device *rdev;
  1185. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1186. BUG_ON(type != SAS_EDGE_EXPANDER_DEVICE &&
  1187. type != SAS_FANOUT_EXPANDER_DEVICE);
  1188. rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
  1189. if (!rdev) {
  1190. return NULL;
  1191. }
  1192. device_initialize(&rdev->rphy.dev);
  1193. rdev->rphy.dev.parent = get_device(&parent->dev);
  1194. rdev->rphy.dev.release = sas_expander_release;
  1195. mutex_lock(&sas_host->lock);
  1196. rdev->rphy.scsi_target_id = sas_host->next_expander_id++;
  1197. mutex_unlock(&sas_host->lock);
  1198. sprintf(rdev->rphy.dev.bus_id, "expander-%d:%d",
  1199. shost->host_no, rdev->rphy.scsi_target_id);
  1200. rdev->rphy.identify.device_type = type;
  1201. sas_rphy_initialize(&rdev->rphy);
  1202. transport_setup_device(&rdev->rphy.dev);
  1203. return &rdev->rphy;
  1204. }
  1205. EXPORT_SYMBOL(sas_expander_alloc);
  1206. /**
  1207. * sas_rphy_add - add a SAS remote PHY to the device hierarchy
  1208. * @rphy: The remote PHY to be added
  1209. *
  1210. * Publishes a SAS remote PHY to the rest of the system.
  1211. */
  1212. int sas_rphy_add(struct sas_rphy *rphy)
  1213. {
  1214. struct sas_port *parent = dev_to_sas_port(rphy->dev.parent);
  1215. struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
  1216. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1217. struct sas_identify *identify = &rphy->identify;
  1218. int error;
  1219. if (parent->rphy)
  1220. return -ENXIO;
  1221. parent->rphy = rphy;
  1222. error = device_add(&rphy->dev);
  1223. if (error)
  1224. return error;
  1225. transport_add_device(&rphy->dev);
  1226. transport_configure_device(&rphy->dev);
  1227. if (sas_bsg_initialize(shost, rphy))
  1228. printk("fail to a bsg device %s\n", rphy->dev.bus_id);
  1229. mutex_lock(&sas_host->lock);
  1230. list_add_tail(&rphy->list, &sas_host->rphy_list);
  1231. if (identify->device_type == SAS_END_DEVICE &&
  1232. (identify->target_port_protocols &
  1233. (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA)))
  1234. rphy->scsi_target_id = sas_host->next_target_id++;
  1235. else if (identify->device_type == SAS_END_DEVICE)
  1236. rphy->scsi_target_id = -1;
  1237. mutex_unlock(&sas_host->lock);
  1238. if (identify->device_type == SAS_END_DEVICE &&
  1239. rphy->scsi_target_id != -1) {
  1240. scsi_scan_target(&rphy->dev, 0,
  1241. rphy->scsi_target_id, SCAN_WILD_CARD, 0);
  1242. }
  1243. return 0;
  1244. }
  1245. EXPORT_SYMBOL(sas_rphy_add);
  1246. /**
  1247. * sas_rphy_free - free a SAS remote PHY
  1248. * @rphy: SAS remote PHY to free
  1249. *
  1250. * Frees the specified SAS remote PHY.
  1251. *
  1252. * Note:
  1253. * This function must only be called on a remote
  1254. * PHY that has not sucessfully been added using
  1255. * sas_rphy_add() (or has been sas_rphy_remove()'d)
  1256. */
  1257. void sas_rphy_free(struct sas_rphy *rphy)
  1258. {
  1259. struct device *dev = &rphy->dev;
  1260. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  1261. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1262. mutex_lock(&sas_host->lock);
  1263. list_del(&rphy->list);
  1264. mutex_unlock(&sas_host->lock);
  1265. sas_bsg_remove(shost, rphy);
  1266. transport_destroy_device(dev);
  1267. put_device(dev);
  1268. }
  1269. EXPORT_SYMBOL(sas_rphy_free);
  1270. /**
  1271. * sas_rphy_delete - remove and free SAS remote PHY
  1272. * @rphy: SAS remote PHY to remove and free
  1273. *
  1274. * Removes the specified SAS remote PHY and frees it.
  1275. */
  1276. void
  1277. sas_rphy_delete(struct sas_rphy *rphy)
  1278. {
  1279. sas_rphy_remove(rphy);
  1280. sas_rphy_free(rphy);
  1281. }
  1282. EXPORT_SYMBOL(sas_rphy_delete);
  1283. /**
  1284. * sas_rphy_remove - remove SAS remote PHY
  1285. * @rphy: SAS remote phy to remove
  1286. *
  1287. * Removes the specified SAS remote PHY.
  1288. */
  1289. void
  1290. sas_rphy_remove(struct sas_rphy *rphy)
  1291. {
  1292. struct device *dev = &rphy->dev;
  1293. struct sas_port *parent = dev_to_sas_port(dev->parent);
  1294. switch (rphy->identify.device_type) {
  1295. case SAS_END_DEVICE:
  1296. scsi_remove_target(dev);
  1297. break;
  1298. case SAS_EDGE_EXPANDER_DEVICE:
  1299. case SAS_FANOUT_EXPANDER_DEVICE:
  1300. sas_remove_children(dev);
  1301. break;
  1302. default:
  1303. break;
  1304. }
  1305. transport_remove_device(dev);
  1306. device_del(dev);
  1307. parent->rphy = NULL;
  1308. }
  1309. EXPORT_SYMBOL(sas_rphy_remove);
  1310. /**
  1311. * scsi_is_sas_rphy - check if a struct device represents a SAS remote PHY
  1312. * @dev: device to check
  1313. *
  1314. * Returns:
  1315. * %1 if the device represents a SAS remote PHY, %0 else
  1316. */
  1317. int scsi_is_sas_rphy(const struct device *dev)
  1318. {
  1319. return dev->release == sas_end_device_release ||
  1320. dev->release == sas_expander_release;
  1321. }
  1322. EXPORT_SYMBOL(scsi_is_sas_rphy);
  1323. /*
  1324. * SCSI scan helper
  1325. */
  1326. static int sas_user_scan(struct Scsi_Host *shost, uint channel,
  1327. uint id, uint lun)
  1328. {
  1329. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1330. struct sas_rphy *rphy;
  1331. mutex_lock(&sas_host->lock);
  1332. list_for_each_entry(rphy, &sas_host->rphy_list, list) {
  1333. if (rphy->identify.device_type != SAS_END_DEVICE ||
  1334. rphy->scsi_target_id == -1)
  1335. continue;
  1336. if ((channel == SCAN_WILD_CARD || channel == 0) &&
  1337. (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) {
  1338. scsi_scan_target(&rphy->dev, 0,
  1339. rphy->scsi_target_id, lun, 1);
  1340. }
  1341. }
  1342. mutex_unlock(&sas_host->lock);
  1343. return 0;
  1344. }
  1345. /*
  1346. * Setup / Teardown code
  1347. */
  1348. #define SETUP_TEMPLATE(attrb, field, perm, test) \
  1349. i->private_##attrb[count] = dev_attr_##field; \
  1350. i->private_##attrb[count].attr.mode = perm; \
  1351. i->attrb[count] = &i->private_##attrb[count]; \
  1352. if (test) \
  1353. count++
  1354. #define SETUP_TEMPLATE_RW(attrb, field, perm, test, ro_test, ro_perm) \
  1355. i->private_##attrb[count] = dev_attr_##field; \
  1356. i->private_##attrb[count].attr.mode = perm; \
  1357. if (ro_test) { \
  1358. i->private_##attrb[count].attr.mode = ro_perm; \
  1359. i->private_##attrb[count].store = NULL; \
  1360. } \
  1361. i->attrb[count] = &i->private_##attrb[count]; \
  1362. if (test) \
  1363. count++
  1364. #define SETUP_RPORT_ATTRIBUTE(field) \
  1365. SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, 1)
  1366. #define SETUP_OPTIONAL_RPORT_ATTRIBUTE(field, func) \
  1367. SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
  1368. #define SETUP_PHY_ATTRIBUTE(field) \
  1369. SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, 1)
  1370. #define SETUP_PHY_ATTRIBUTE_RW(field) \
  1371. SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \
  1372. !i->f->set_phy_speed, S_IRUGO)
  1373. #define SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(field, func) \
  1374. SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \
  1375. !i->f->func, S_IRUGO)
  1376. #define SETUP_PORT_ATTRIBUTE(field) \
  1377. SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
  1378. #define SETUP_OPTIONAL_PHY_ATTRIBUTE(field, func) \
  1379. SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
  1380. #define SETUP_PHY_ATTRIBUTE_WRONLY(field) \
  1381. SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, 1)
  1382. #define SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(field, func) \
  1383. SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func)
  1384. #define SETUP_END_DEV_ATTRIBUTE(field) \
  1385. SETUP_TEMPLATE(end_dev_attrs, field, S_IRUGO, 1)
  1386. #define SETUP_EXPANDER_ATTRIBUTE(field) \
  1387. SETUP_TEMPLATE(expander_attrs, expander_##field, S_IRUGO, 1)
  1388. /**
  1389. * sas_attach_transport - instantiate SAS transport template
  1390. * @ft: SAS transport class function template
  1391. */
  1392. struct scsi_transport_template *
  1393. sas_attach_transport(struct sas_function_template *ft)
  1394. {
  1395. struct sas_internal *i;
  1396. int count;
  1397. i = kzalloc(sizeof(struct sas_internal), GFP_KERNEL);
  1398. if (!i)
  1399. return NULL;
  1400. i->t.user_scan = sas_user_scan;
  1401. i->t.host_attrs.ac.attrs = &i->host_attrs[0];
  1402. i->t.host_attrs.ac.class = &sas_host_class.class;
  1403. i->t.host_attrs.ac.match = sas_host_match;
  1404. transport_container_register(&i->t.host_attrs);
  1405. i->t.host_size = sizeof(struct sas_host_attrs);
  1406. i->phy_attr_cont.ac.class = &sas_phy_class.class;
  1407. i->phy_attr_cont.ac.attrs = &i->phy_attrs[0];
  1408. i->phy_attr_cont.ac.match = sas_phy_match;
  1409. transport_container_register(&i->phy_attr_cont);
  1410. i->port_attr_cont.ac.class = &sas_port_class.class;
  1411. i->port_attr_cont.ac.attrs = &i->port_attrs[0];
  1412. i->port_attr_cont.ac.match = sas_port_match;
  1413. transport_container_register(&i->port_attr_cont);
  1414. i->rphy_attr_cont.ac.class = &sas_rphy_class.class;
  1415. i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0];
  1416. i->rphy_attr_cont.ac.match = sas_rphy_match;
  1417. transport_container_register(&i->rphy_attr_cont);
  1418. i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class;
  1419. i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0];
  1420. i->end_dev_attr_cont.ac.match = sas_end_dev_match;
  1421. transport_container_register(&i->end_dev_attr_cont);
  1422. i->expander_attr_cont.ac.class = &sas_expander_class.class;
  1423. i->expander_attr_cont.ac.attrs = &i->expander_attrs[0];
  1424. i->expander_attr_cont.ac.match = sas_expander_match;
  1425. transport_container_register(&i->expander_attr_cont);
  1426. i->f = ft;
  1427. count = 0;
  1428. SETUP_PORT_ATTRIBUTE(num_phys);
  1429. i->host_attrs[count] = NULL;
  1430. count = 0;
  1431. SETUP_PHY_ATTRIBUTE(initiator_port_protocols);
  1432. SETUP_PHY_ATTRIBUTE(target_port_protocols);
  1433. SETUP_PHY_ATTRIBUTE(device_type);
  1434. SETUP_PHY_ATTRIBUTE(sas_address);
  1435. SETUP_PHY_ATTRIBUTE(phy_identifier);
  1436. //SETUP_PHY_ATTRIBUTE(port_identifier);
  1437. SETUP_PHY_ATTRIBUTE(negotiated_linkrate);
  1438. SETUP_PHY_ATTRIBUTE(minimum_linkrate_hw);
  1439. SETUP_PHY_ATTRIBUTE_RW(minimum_linkrate);
  1440. SETUP_PHY_ATTRIBUTE(maximum_linkrate_hw);
  1441. SETUP_PHY_ATTRIBUTE_RW(maximum_linkrate);
  1442. SETUP_PHY_ATTRIBUTE(invalid_dword_count);
  1443. SETUP_PHY_ATTRIBUTE(running_disparity_error_count);
  1444. SETUP_PHY_ATTRIBUTE(loss_of_dword_sync_count);
  1445. SETUP_PHY_ATTRIBUTE(phy_reset_problem_count);
  1446. SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(link_reset, phy_reset);
  1447. SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(hard_reset, phy_reset);
  1448. SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(enable, phy_enable);
  1449. i->phy_attrs[count] = NULL;
  1450. count = 0;
  1451. SETUP_PORT_ATTRIBUTE(num_phys);
  1452. i->port_attrs[count] = NULL;
  1453. count = 0;
  1454. SETUP_RPORT_ATTRIBUTE(rphy_initiator_port_protocols);
  1455. SETUP_RPORT_ATTRIBUTE(rphy_target_port_protocols);
  1456. SETUP_RPORT_ATTRIBUTE(rphy_device_type);
  1457. SETUP_RPORT_ATTRIBUTE(rphy_sas_address);
  1458. SETUP_RPORT_ATTRIBUTE(rphy_phy_identifier);
  1459. SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_enclosure_identifier,
  1460. get_enclosure_identifier);
  1461. SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_bay_identifier,
  1462. get_bay_identifier);
  1463. i->rphy_attrs[count] = NULL;
  1464. count = 0;
  1465. SETUP_END_DEV_ATTRIBUTE(end_dev_ready_led_meaning);
  1466. SETUP_END_DEV_ATTRIBUTE(end_dev_I_T_nexus_loss_timeout);
  1467. SETUP_END_DEV_ATTRIBUTE(end_dev_initiator_response_timeout);
  1468. i->end_dev_attrs[count] = NULL;
  1469. count = 0;
  1470. SETUP_EXPANDER_ATTRIBUTE(vendor_id);
  1471. SETUP_EXPANDER_ATTRIBUTE(product_id);
  1472. SETUP_EXPANDER_ATTRIBUTE(product_rev);
  1473. SETUP_EXPANDER_ATTRIBUTE(component_vendor_id);
  1474. SETUP_EXPANDER_ATTRIBUTE(component_id);
  1475. SETUP_EXPANDER_ATTRIBUTE(component_revision_id);
  1476. SETUP_EXPANDER_ATTRIBUTE(level);
  1477. i->expander_attrs[count] = NULL;
  1478. return &i->t;
  1479. }
  1480. EXPORT_SYMBOL(sas_attach_transport);
  1481. /**
  1482. * sas_release_transport - release SAS transport template instance
  1483. * @t: transport template instance
  1484. */
  1485. void sas_release_transport(struct scsi_transport_template *t)
  1486. {
  1487. struct sas_internal *i = to_sas_internal(t);
  1488. transport_container_unregister(&i->t.host_attrs);
  1489. transport_container_unregister(&i->phy_attr_cont);
  1490. transport_container_unregister(&i->port_attr_cont);
  1491. transport_container_unregister(&i->rphy_attr_cont);
  1492. transport_container_unregister(&i->end_dev_attr_cont);
  1493. transport_container_unregister(&i->expander_attr_cont);
  1494. kfree(i);
  1495. }
  1496. EXPORT_SYMBOL(sas_release_transport);
  1497. static __init int sas_transport_init(void)
  1498. {
  1499. int error;
  1500. error = transport_class_register(&sas_host_class);
  1501. if (error)
  1502. goto out;
  1503. error = transport_class_register(&sas_phy_class);
  1504. if (error)
  1505. goto out_unregister_transport;
  1506. error = transport_class_register(&sas_port_class);
  1507. if (error)
  1508. goto out_unregister_phy;
  1509. error = transport_class_register(&sas_rphy_class);
  1510. if (error)
  1511. goto out_unregister_port;
  1512. error = transport_class_register(&sas_end_dev_class);
  1513. if (error)
  1514. goto out_unregister_rphy;
  1515. error = transport_class_register(&sas_expander_class);
  1516. if (error)
  1517. goto out_unregister_end_dev;
  1518. return 0;
  1519. out_unregister_end_dev:
  1520. transport_class_unregister(&sas_end_dev_class);
  1521. out_unregister_rphy:
  1522. transport_class_unregister(&sas_rphy_class);
  1523. out_unregister_port:
  1524. transport_class_unregister(&sas_port_class);
  1525. out_unregister_phy:
  1526. transport_class_unregister(&sas_phy_class);
  1527. out_unregister_transport:
  1528. transport_class_unregister(&sas_host_class);
  1529. out:
  1530. return error;
  1531. }
  1532. static void __exit sas_transport_exit(void)
  1533. {
  1534. transport_class_unregister(&sas_host_class);
  1535. transport_class_unregister(&sas_phy_class);
  1536. transport_class_unregister(&sas_port_class);
  1537. transport_class_unregister(&sas_rphy_class);
  1538. transport_class_unregister(&sas_end_dev_class);
  1539. transport_class_unregister(&sas_expander_class);
  1540. }
  1541. MODULE_AUTHOR("Christoph Hellwig");
  1542. MODULE_DESCRIPTION("SAS Transport Attributes");
  1543. MODULE_LICENSE("GPL");
  1544. module_init(sas_transport_init);
  1545. module_exit(sas_transport_exit);