scsi_transport_sas.c 48 KB

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