scsi_transport_sas.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830
  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 = blk_fetch_request(q);
  151. if (!req)
  152. break;
  153. spin_unlock_irq(q->queue_lock);
  154. handler = to_sas_internal(shost->transportt)->f->smp_handler;
  155. ret = handler(shost, rphy, req);
  156. req->errors = ret;
  157. blk_end_request_all(req, ret);
  158. spin_lock_irq(q->queue_lock);
  159. }
  160. }
  161. static void sas_host_smp_request(struct request_queue *q)
  162. {
  163. sas_smp_request(q, (struct Scsi_Host *)q->queuedata, NULL);
  164. }
  165. static void sas_non_host_smp_request(struct request_queue *q)
  166. {
  167. struct sas_rphy *rphy = q->queuedata;
  168. sas_smp_request(q, rphy_to_shost(rphy), rphy);
  169. }
  170. static void sas_host_release(struct device *dev)
  171. {
  172. struct Scsi_Host *shost = dev_to_shost(dev);
  173. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  174. struct request_queue *q = sas_host->q;
  175. if (q)
  176. blk_cleanup_queue(q);
  177. }
  178. static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy)
  179. {
  180. struct request_queue *q;
  181. int error;
  182. struct device *dev;
  183. char namebuf[20];
  184. const char *name;
  185. void (*release)(struct device *);
  186. if (!to_sas_internal(shost->transportt)->f->smp_handler) {
  187. printk("%s can't handle SMP requests\n", shost->hostt->name);
  188. return 0;
  189. }
  190. if (rphy) {
  191. q = blk_init_queue(sas_non_host_smp_request, NULL);
  192. dev = &rphy->dev;
  193. name = dev_name(dev);
  194. release = NULL;
  195. } else {
  196. q = blk_init_queue(sas_host_smp_request, NULL);
  197. dev = &shost->shost_gendev;
  198. snprintf(namebuf, sizeof(namebuf),
  199. "sas_host%d", shost->host_no);
  200. name = namebuf;
  201. release = sas_host_release;
  202. }
  203. if (!q)
  204. return -ENOMEM;
  205. error = bsg_register_queue(q, dev, name, release);
  206. if (error) {
  207. blk_cleanup_queue(q);
  208. return -ENOMEM;
  209. }
  210. if (rphy)
  211. rphy->q = q;
  212. else
  213. to_sas_host_attrs(shost)->q = q;
  214. if (rphy)
  215. q->queuedata = rphy;
  216. else
  217. q->queuedata = shost;
  218. queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
  219. return 0;
  220. }
  221. static void sas_bsg_remove(struct Scsi_Host *shost, struct sas_rphy *rphy)
  222. {
  223. struct request_queue *q;
  224. if (rphy)
  225. q = rphy->q;
  226. else
  227. q = to_sas_host_attrs(shost)->q;
  228. if (!q)
  229. return;
  230. bsg_unregister_queue(q);
  231. }
  232. /*
  233. * SAS host attributes
  234. */
  235. static int sas_host_setup(struct transport_container *tc, struct device *dev,
  236. struct device *cdev)
  237. {
  238. struct Scsi_Host *shost = dev_to_shost(dev);
  239. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  240. INIT_LIST_HEAD(&sas_host->rphy_list);
  241. mutex_init(&sas_host->lock);
  242. sas_host->next_target_id = 0;
  243. sas_host->next_expander_id = 0;
  244. sas_host->next_port_id = 0;
  245. if (sas_bsg_initialize(shost, NULL))
  246. dev_printk(KERN_ERR, dev, "fail to a bsg device %d\n",
  247. shost->host_no);
  248. return 0;
  249. }
  250. static int sas_host_remove(struct transport_container *tc, struct device *dev,
  251. struct device *cdev)
  252. {
  253. struct Scsi_Host *shost = dev_to_shost(dev);
  254. sas_bsg_remove(shost, NULL);
  255. return 0;
  256. }
  257. static DECLARE_TRANSPORT_CLASS(sas_host_class,
  258. "sas_host", sas_host_setup, sas_host_remove, NULL);
  259. static int sas_host_match(struct attribute_container *cont,
  260. struct device *dev)
  261. {
  262. struct Scsi_Host *shost;
  263. struct sas_internal *i;
  264. if (!scsi_is_host_device(dev))
  265. return 0;
  266. shost = dev_to_shost(dev);
  267. if (!shost->transportt)
  268. return 0;
  269. if (shost->transportt->host_attrs.ac.class !=
  270. &sas_host_class.class)
  271. return 0;
  272. i = to_sas_internal(shost->transportt);
  273. return &i->t.host_attrs.ac == cont;
  274. }
  275. static int do_sas_phy_delete(struct device *dev, void *data)
  276. {
  277. int pass = (int)(unsigned long)data;
  278. if (pass == 0 && scsi_is_sas_port(dev))
  279. sas_port_delete(dev_to_sas_port(dev));
  280. else if (pass == 1 && scsi_is_sas_phy(dev))
  281. sas_phy_delete(dev_to_phy(dev));
  282. return 0;
  283. }
  284. /**
  285. * sas_remove_children - tear down a devices SAS data structures
  286. * @dev: device belonging to the sas object
  287. *
  288. * Removes all SAS PHYs and remote PHYs for a given object
  289. */
  290. void sas_remove_children(struct device *dev)
  291. {
  292. device_for_each_child(dev, (void *)0, do_sas_phy_delete);
  293. device_for_each_child(dev, (void *)1, do_sas_phy_delete);
  294. }
  295. EXPORT_SYMBOL(sas_remove_children);
  296. /**
  297. * sas_remove_host - tear down a Scsi_Host's SAS data structures
  298. * @shost: Scsi Host that is torn down
  299. *
  300. * Removes all SAS PHYs and remote PHYs for a given Scsi_Host.
  301. * Must be called just before scsi_remove_host for SAS HBAs.
  302. */
  303. void sas_remove_host(struct Scsi_Host *shost)
  304. {
  305. sas_remove_children(&shost->shost_gendev);
  306. }
  307. EXPORT_SYMBOL(sas_remove_host);
  308. /*
  309. * SAS Phy attributes
  310. */
  311. #define sas_phy_show_simple(field, name, format_string, cast) \
  312. static ssize_t \
  313. show_sas_phy_##name(struct device *dev, \
  314. struct device_attribute *attr, char *buf) \
  315. { \
  316. struct sas_phy *phy = transport_class_to_phy(dev); \
  317. \
  318. return snprintf(buf, 20, format_string, cast phy->field); \
  319. }
  320. #define sas_phy_simple_attr(field, name, format_string, type) \
  321. sas_phy_show_simple(field, name, format_string, (type)) \
  322. static DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL)
  323. #define sas_phy_show_protocol(field, name) \
  324. static ssize_t \
  325. show_sas_phy_##name(struct device *dev, \
  326. struct device_attribute *attr, char *buf) \
  327. { \
  328. struct sas_phy *phy = transport_class_to_phy(dev); \
  329. \
  330. if (!phy->field) \
  331. return snprintf(buf, 20, "none\n"); \
  332. return get_sas_protocol_names(phy->field, buf); \
  333. }
  334. #define sas_phy_protocol_attr(field, name) \
  335. sas_phy_show_protocol(field, name) \
  336. static DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL)
  337. #define sas_phy_show_linkspeed(field) \
  338. static ssize_t \
  339. show_sas_phy_##field(struct device *dev, \
  340. struct device_attribute *attr, char *buf) \
  341. { \
  342. struct sas_phy *phy = transport_class_to_phy(dev); \
  343. \
  344. return get_sas_linkspeed_names(phy->field, buf); \
  345. }
  346. /* Fudge to tell if we're minimum or maximum */
  347. #define sas_phy_store_linkspeed(field) \
  348. static ssize_t \
  349. store_sas_phy_##field(struct device *dev, \
  350. struct device_attribute *attr, \
  351. const char *buf, size_t count) \
  352. { \
  353. struct sas_phy *phy = transport_class_to_phy(dev); \
  354. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
  355. struct sas_internal *i = to_sas_internal(shost->transportt); \
  356. u32 value; \
  357. struct sas_phy_linkrates rates = {0}; \
  358. int error; \
  359. \
  360. error = set_sas_linkspeed_names(&value, buf); \
  361. if (error) \
  362. return error; \
  363. rates.field = value; \
  364. error = i->f->set_phy_speed(phy, &rates); \
  365. \
  366. return error ? error : count; \
  367. }
  368. #define sas_phy_linkspeed_rw_attr(field) \
  369. sas_phy_show_linkspeed(field) \
  370. sas_phy_store_linkspeed(field) \
  371. static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, \
  372. store_sas_phy_##field)
  373. #define sas_phy_linkspeed_attr(field) \
  374. sas_phy_show_linkspeed(field) \
  375. static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL)
  376. #define sas_phy_show_linkerror(field) \
  377. static ssize_t \
  378. show_sas_phy_##field(struct device *dev, \
  379. struct device_attribute *attr, char *buf) \
  380. { \
  381. struct sas_phy *phy = transport_class_to_phy(dev); \
  382. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
  383. struct sas_internal *i = to_sas_internal(shost->transportt); \
  384. int error; \
  385. \
  386. error = i->f->get_linkerrors ? i->f->get_linkerrors(phy) : 0; \
  387. if (error) \
  388. return error; \
  389. return snprintf(buf, 20, "%u\n", phy->field); \
  390. }
  391. #define sas_phy_linkerror_attr(field) \
  392. sas_phy_show_linkerror(field) \
  393. static DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL)
  394. static ssize_t
  395. show_sas_device_type(struct device *dev,
  396. struct device_attribute *attr, char *buf)
  397. {
  398. struct sas_phy *phy = transport_class_to_phy(dev);
  399. if (!phy->identify.device_type)
  400. return snprintf(buf, 20, "none\n");
  401. return get_sas_device_type_names(phy->identify.device_type, buf);
  402. }
  403. static DEVICE_ATTR(device_type, S_IRUGO, show_sas_device_type, NULL);
  404. static ssize_t do_sas_phy_enable(struct device *dev,
  405. size_t count, int enable)
  406. {
  407. struct sas_phy *phy = transport_class_to_phy(dev);
  408. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  409. struct sas_internal *i = to_sas_internal(shost->transportt);
  410. int error;
  411. error = i->f->phy_enable(phy, enable);
  412. if (error)
  413. return error;
  414. phy->enabled = enable;
  415. return count;
  416. };
  417. static ssize_t
  418. store_sas_phy_enable(struct device *dev, struct device_attribute *attr,
  419. const char *buf, size_t count)
  420. {
  421. if (count < 1)
  422. return -EINVAL;
  423. switch (buf[0]) {
  424. case '0':
  425. do_sas_phy_enable(dev, count, 0);
  426. break;
  427. case '1':
  428. do_sas_phy_enable(dev, count, 1);
  429. break;
  430. default:
  431. return -EINVAL;
  432. }
  433. return count;
  434. }
  435. static ssize_t
  436. show_sas_phy_enable(struct device *dev, struct device_attribute *attr,
  437. char *buf)
  438. {
  439. struct sas_phy *phy = transport_class_to_phy(dev);
  440. return snprintf(buf, 20, "%d", phy->enabled);
  441. }
  442. static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, show_sas_phy_enable,
  443. store_sas_phy_enable);
  444. static ssize_t
  445. do_sas_phy_reset(struct device *dev, size_t count, int hard_reset)
  446. {
  447. struct sas_phy *phy = transport_class_to_phy(dev);
  448. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  449. struct sas_internal *i = to_sas_internal(shost->transportt);
  450. int error;
  451. error = i->f->phy_reset(phy, hard_reset);
  452. if (error)
  453. return error;
  454. return count;
  455. };
  456. static ssize_t
  457. store_sas_link_reset(struct device *dev, struct device_attribute *attr,
  458. const char *buf, size_t count)
  459. {
  460. return do_sas_phy_reset(dev, count, 0);
  461. }
  462. static DEVICE_ATTR(link_reset, S_IWUSR, NULL, store_sas_link_reset);
  463. static ssize_t
  464. store_sas_hard_reset(struct device *dev, struct device_attribute *attr,
  465. const char *buf, size_t count)
  466. {
  467. return do_sas_phy_reset(dev, count, 1);
  468. }
  469. static DEVICE_ATTR(hard_reset, S_IWUSR, NULL, store_sas_hard_reset);
  470. sas_phy_protocol_attr(identify.initiator_port_protocols,
  471. initiator_port_protocols);
  472. sas_phy_protocol_attr(identify.target_port_protocols,
  473. target_port_protocols);
  474. sas_phy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
  475. unsigned long long);
  476. sas_phy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
  477. //sas_phy_simple_attr(port_identifier, port_identifier, "%d\n", int);
  478. sas_phy_linkspeed_attr(negotiated_linkrate);
  479. sas_phy_linkspeed_attr(minimum_linkrate_hw);
  480. sas_phy_linkspeed_rw_attr(minimum_linkrate);
  481. sas_phy_linkspeed_attr(maximum_linkrate_hw);
  482. sas_phy_linkspeed_rw_attr(maximum_linkrate);
  483. sas_phy_linkerror_attr(invalid_dword_count);
  484. sas_phy_linkerror_attr(running_disparity_error_count);
  485. sas_phy_linkerror_attr(loss_of_dword_sync_count);
  486. sas_phy_linkerror_attr(phy_reset_problem_count);
  487. static DECLARE_TRANSPORT_CLASS(sas_phy_class,
  488. "sas_phy", NULL, NULL, NULL);
  489. static int sas_phy_match(struct attribute_container *cont, struct device *dev)
  490. {
  491. struct Scsi_Host *shost;
  492. struct sas_internal *i;
  493. if (!scsi_is_sas_phy(dev))
  494. return 0;
  495. shost = dev_to_shost(dev->parent);
  496. if (!shost->transportt)
  497. return 0;
  498. if (shost->transportt->host_attrs.ac.class !=
  499. &sas_host_class.class)
  500. return 0;
  501. i = to_sas_internal(shost->transportt);
  502. return &i->phy_attr_cont.ac == cont;
  503. }
  504. static void sas_phy_release(struct device *dev)
  505. {
  506. struct sas_phy *phy = dev_to_phy(dev);
  507. put_device(dev->parent);
  508. kfree(phy);
  509. }
  510. /**
  511. * sas_phy_alloc - allocates and initialize a SAS PHY structure
  512. * @parent: Parent device
  513. * @number: Phy index
  514. *
  515. * Allocates an SAS PHY structure. It will be added in the device tree
  516. * below the device specified by @parent, which has to be either a Scsi_Host
  517. * or sas_rphy.
  518. *
  519. * Returns:
  520. * SAS PHY allocated or %NULL if the allocation failed.
  521. */
  522. struct sas_phy *sas_phy_alloc(struct device *parent, int number)
  523. {
  524. struct Scsi_Host *shost = dev_to_shost(parent);
  525. struct sas_phy *phy;
  526. phy = kzalloc(sizeof(*phy), GFP_KERNEL);
  527. if (!phy)
  528. return NULL;
  529. phy->number = number;
  530. phy->enabled = 1;
  531. device_initialize(&phy->dev);
  532. phy->dev.parent = get_device(parent);
  533. phy->dev.release = sas_phy_release;
  534. INIT_LIST_HEAD(&phy->port_siblings);
  535. if (scsi_is_sas_expander_device(parent)) {
  536. struct sas_rphy *rphy = dev_to_rphy(parent);
  537. dev_set_name(&phy->dev, "phy-%d:%d:%d", shost->host_no,
  538. rphy->scsi_target_id, number);
  539. } else
  540. dev_set_name(&phy->dev, "phy-%d:%d", shost->host_no, number);
  541. transport_setup_device(&phy->dev);
  542. return phy;
  543. }
  544. EXPORT_SYMBOL(sas_phy_alloc);
  545. /**
  546. * sas_phy_add - add a SAS PHY to the device hierarchy
  547. * @phy: The PHY to be added
  548. *
  549. * Publishes a SAS PHY to the rest of the system.
  550. */
  551. int sas_phy_add(struct sas_phy *phy)
  552. {
  553. int error;
  554. error = device_add(&phy->dev);
  555. if (!error) {
  556. transport_add_device(&phy->dev);
  557. transport_configure_device(&phy->dev);
  558. }
  559. return error;
  560. }
  561. EXPORT_SYMBOL(sas_phy_add);
  562. /**
  563. * sas_phy_free - free a SAS PHY
  564. * @phy: SAS PHY to free
  565. *
  566. * Frees the specified SAS PHY.
  567. *
  568. * Note:
  569. * This function must only be called on a PHY that has not
  570. * sucessfully been added using sas_phy_add().
  571. */
  572. void sas_phy_free(struct sas_phy *phy)
  573. {
  574. transport_destroy_device(&phy->dev);
  575. put_device(&phy->dev);
  576. }
  577. EXPORT_SYMBOL(sas_phy_free);
  578. /**
  579. * sas_phy_delete - remove SAS PHY
  580. * @phy: SAS PHY to remove
  581. *
  582. * Removes the specified SAS PHY. If the SAS PHY has an
  583. * associated remote PHY it is removed before.
  584. */
  585. void
  586. sas_phy_delete(struct sas_phy *phy)
  587. {
  588. struct device *dev = &phy->dev;
  589. /* this happens if the phy is still part of a port when deleted */
  590. BUG_ON(!list_empty(&phy->port_siblings));
  591. transport_remove_device(dev);
  592. device_del(dev);
  593. transport_destroy_device(dev);
  594. put_device(dev);
  595. }
  596. EXPORT_SYMBOL(sas_phy_delete);
  597. /**
  598. * scsi_is_sas_phy - check if a struct device represents a SAS PHY
  599. * @dev: device to check
  600. *
  601. * Returns:
  602. * %1 if the device represents a SAS PHY, %0 else
  603. */
  604. int scsi_is_sas_phy(const struct device *dev)
  605. {
  606. return dev->release == sas_phy_release;
  607. }
  608. EXPORT_SYMBOL(scsi_is_sas_phy);
  609. /*
  610. * SAS Port attributes
  611. */
  612. #define sas_port_show_simple(field, name, format_string, cast) \
  613. static ssize_t \
  614. show_sas_port_##name(struct device *dev, \
  615. struct device_attribute *attr, char *buf) \
  616. { \
  617. struct sas_port *port = transport_class_to_sas_port(dev); \
  618. \
  619. return snprintf(buf, 20, format_string, cast port->field); \
  620. }
  621. #define sas_port_simple_attr(field, name, format_string, type) \
  622. sas_port_show_simple(field, name, format_string, (type)) \
  623. static DEVICE_ATTR(name, S_IRUGO, show_sas_port_##name, NULL)
  624. sas_port_simple_attr(num_phys, num_phys, "%d\n", int);
  625. static DECLARE_TRANSPORT_CLASS(sas_port_class,
  626. "sas_port", NULL, NULL, NULL);
  627. static int sas_port_match(struct attribute_container *cont, struct device *dev)
  628. {
  629. struct Scsi_Host *shost;
  630. struct sas_internal *i;
  631. if (!scsi_is_sas_port(dev))
  632. return 0;
  633. shost = dev_to_shost(dev->parent);
  634. if (!shost->transportt)
  635. return 0;
  636. if (shost->transportt->host_attrs.ac.class !=
  637. &sas_host_class.class)
  638. return 0;
  639. i = to_sas_internal(shost->transportt);
  640. return &i->port_attr_cont.ac == cont;
  641. }
  642. static void sas_port_release(struct device *dev)
  643. {
  644. struct sas_port *port = dev_to_sas_port(dev);
  645. BUG_ON(!list_empty(&port->phy_list));
  646. put_device(dev->parent);
  647. kfree(port);
  648. }
  649. static void sas_port_create_link(struct sas_port *port,
  650. struct sas_phy *phy)
  651. {
  652. int res;
  653. res = sysfs_create_link(&port->dev.kobj, &phy->dev.kobj,
  654. dev_name(&phy->dev));
  655. if (res)
  656. goto err;
  657. res = sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port");
  658. if (res)
  659. goto err;
  660. return;
  661. err:
  662. printk(KERN_ERR "%s: Cannot create port links, err=%d\n",
  663. __func__, res);
  664. }
  665. static void sas_port_delete_link(struct sas_port *port,
  666. struct sas_phy *phy)
  667. {
  668. sysfs_remove_link(&port->dev.kobj, dev_name(&phy->dev));
  669. sysfs_remove_link(&phy->dev.kobj, "port");
  670. }
  671. /** sas_port_alloc - allocate and initialize a SAS port structure
  672. *
  673. * @parent: parent device
  674. * @port_id: port number
  675. *
  676. * Allocates a SAS port structure. It will be added to the device tree
  677. * below the device specified by @parent which must be either a Scsi_Host
  678. * or a sas_expander_device.
  679. *
  680. * Returns %NULL on error
  681. */
  682. struct sas_port *sas_port_alloc(struct device *parent, int port_id)
  683. {
  684. struct Scsi_Host *shost = dev_to_shost(parent);
  685. struct sas_port *port;
  686. port = kzalloc(sizeof(*port), GFP_KERNEL);
  687. if (!port)
  688. return NULL;
  689. port->port_identifier = port_id;
  690. device_initialize(&port->dev);
  691. port->dev.parent = get_device(parent);
  692. port->dev.release = sas_port_release;
  693. mutex_init(&port->phy_list_mutex);
  694. INIT_LIST_HEAD(&port->phy_list);
  695. if (scsi_is_sas_expander_device(parent)) {
  696. struct sas_rphy *rphy = dev_to_rphy(parent);
  697. dev_set_name(&port->dev, "port-%d:%d:%d", shost->host_no,
  698. rphy->scsi_target_id, port->port_identifier);
  699. } else
  700. dev_set_name(&port->dev, "port-%d:%d", shost->host_no,
  701. port->port_identifier);
  702. transport_setup_device(&port->dev);
  703. return port;
  704. }
  705. EXPORT_SYMBOL(sas_port_alloc);
  706. /** sas_port_alloc_num - allocate and initialize a SAS port structure
  707. *
  708. * @parent: parent device
  709. *
  710. * Allocates a SAS port structure and a number to go with it. This
  711. * interface is really for adapters where the port number has no
  712. * meansing, so the sas class should manage them. It will be added to
  713. * the device tree below the device specified by @parent which must be
  714. * either a Scsi_Host or a sas_expander_device.
  715. *
  716. * Returns %NULL on error
  717. */
  718. struct sas_port *sas_port_alloc_num(struct device *parent)
  719. {
  720. int index;
  721. struct Scsi_Host *shost = dev_to_shost(parent);
  722. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  723. /* FIXME: use idr for this eventually */
  724. mutex_lock(&sas_host->lock);
  725. if (scsi_is_sas_expander_device(parent)) {
  726. struct sas_rphy *rphy = dev_to_rphy(parent);
  727. struct sas_expander_device *exp = rphy_to_expander_device(rphy);
  728. index = exp->next_port_id++;
  729. } else
  730. index = sas_host->next_port_id++;
  731. mutex_unlock(&sas_host->lock);
  732. return sas_port_alloc(parent, index);
  733. }
  734. EXPORT_SYMBOL(sas_port_alloc_num);
  735. /**
  736. * sas_port_add - add a SAS port to the device hierarchy
  737. * @port: port to be added
  738. *
  739. * publishes a port to the rest of the system
  740. */
  741. int sas_port_add(struct sas_port *port)
  742. {
  743. int error;
  744. /* No phys should be added until this is made visible */
  745. BUG_ON(!list_empty(&port->phy_list));
  746. error = device_add(&port->dev);
  747. if (error)
  748. return error;
  749. transport_add_device(&port->dev);
  750. transport_configure_device(&port->dev);
  751. return 0;
  752. }
  753. EXPORT_SYMBOL(sas_port_add);
  754. /**
  755. * sas_port_free - free a SAS PORT
  756. * @port: SAS PORT to free
  757. *
  758. * Frees the specified SAS PORT.
  759. *
  760. * Note:
  761. * This function must only be called on a PORT that has not
  762. * sucessfully been added using sas_port_add().
  763. */
  764. void sas_port_free(struct sas_port *port)
  765. {
  766. transport_destroy_device(&port->dev);
  767. put_device(&port->dev);
  768. }
  769. EXPORT_SYMBOL(sas_port_free);
  770. /**
  771. * sas_port_delete - remove SAS PORT
  772. * @port: SAS PORT to remove
  773. *
  774. * Removes the specified SAS PORT. If the SAS PORT has an
  775. * associated phys, unlink them from the port as well.
  776. */
  777. void sas_port_delete(struct sas_port *port)
  778. {
  779. struct device *dev = &port->dev;
  780. struct sas_phy *phy, *tmp_phy;
  781. if (port->rphy) {
  782. sas_rphy_delete(port->rphy);
  783. port->rphy = NULL;
  784. }
  785. mutex_lock(&port->phy_list_mutex);
  786. list_for_each_entry_safe(phy, tmp_phy, &port->phy_list,
  787. port_siblings) {
  788. sas_port_delete_link(port, phy);
  789. list_del_init(&phy->port_siblings);
  790. }
  791. mutex_unlock(&port->phy_list_mutex);
  792. if (port->is_backlink) {
  793. struct device *parent = port->dev.parent;
  794. sysfs_remove_link(&port->dev.kobj, dev_name(parent));
  795. port->is_backlink = 0;
  796. }
  797. transport_remove_device(dev);
  798. device_del(dev);
  799. transport_destroy_device(dev);
  800. put_device(dev);
  801. }
  802. EXPORT_SYMBOL(sas_port_delete);
  803. /**
  804. * scsi_is_sas_port - check if a struct device represents a SAS port
  805. * @dev: device to check
  806. *
  807. * Returns:
  808. * %1 if the device represents a SAS Port, %0 else
  809. */
  810. int scsi_is_sas_port(const struct device *dev)
  811. {
  812. return dev->release == sas_port_release;
  813. }
  814. EXPORT_SYMBOL(scsi_is_sas_port);
  815. /**
  816. * sas_port_add_phy - add another phy to a port to form a wide port
  817. * @port: port to add the phy to
  818. * @phy: phy to add
  819. *
  820. * When a port is initially created, it is empty (has no phys). All
  821. * ports must have at least one phy to operated, and all wide ports
  822. * must have at least two. The current code makes no difference
  823. * between ports and wide ports, but the only object that can be
  824. * connected to a remote device is a port, so ports must be formed on
  825. * all devices with phys if they're connected to anything.
  826. */
  827. void sas_port_add_phy(struct sas_port *port, struct sas_phy *phy)
  828. {
  829. mutex_lock(&port->phy_list_mutex);
  830. if (unlikely(!list_empty(&phy->port_siblings))) {
  831. /* make sure we're already on this port */
  832. struct sas_phy *tmp;
  833. list_for_each_entry(tmp, &port->phy_list, port_siblings)
  834. if (tmp == phy)
  835. break;
  836. /* If this trips, you added a phy that was already
  837. * part of a different port */
  838. if (unlikely(tmp != phy)) {
  839. dev_printk(KERN_ERR, &port->dev, "trying to add phy %s fails: it's already part of another port\n",
  840. dev_name(&phy->dev));
  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. dev_name(parent));
  877. if (res)
  878. goto err;
  879. return;
  880. err:
  881. printk(KERN_ERR "%s: Cannot create port backlink, err=%d\n",
  882. __func__, 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. dev_set_name(&rdev->rphy.dev, "end_device-%d:%d:%d",
  1160. shost->host_no, rphy->scsi_target_id,
  1161. parent->port_identifier);
  1162. } else
  1163. dev_set_name(&rdev->rphy.dev, "end_device-%d:%d",
  1164. shost->host_no, parent->port_identifier);
  1165. rdev->rphy.identify.device_type = SAS_END_DEVICE;
  1166. sas_rphy_initialize(&rdev->rphy);
  1167. transport_setup_device(&rdev->rphy.dev);
  1168. return &rdev->rphy;
  1169. }
  1170. EXPORT_SYMBOL(sas_end_device_alloc);
  1171. /**
  1172. * sas_expander_alloc - allocate an rphy for an end device
  1173. * @parent: which port
  1174. * @type: SAS_EDGE_EXPANDER_DEVICE or SAS_FANOUT_EXPANDER_DEVICE
  1175. *
  1176. * Allocates an SAS remote PHY structure, connected to @parent.
  1177. *
  1178. * Returns:
  1179. * SAS PHY allocated or %NULL if the allocation failed.
  1180. */
  1181. struct sas_rphy *sas_expander_alloc(struct sas_port *parent,
  1182. enum sas_device_type type)
  1183. {
  1184. struct Scsi_Host *shost = dev_to_shost(&parent->dev);
  1185. struct sas_expander_device *rdev;
  1186. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1187. BUG_ON(type != SAS_EDGE_EXPANDER_DEVICE &&
  1188. type != SAS_FANOUT_EXPANDER_DEVICE);
  1189. rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
  1190. if (!rdev) {
  1191. return NULL;
  1192. }
  1193. device_initialize(&rdev->rphy.dev);
  1194. rdev->rphy.dev.parent = get_device(&parent->dev);
  1195. rdev->rphy.dev.release = sas_expander_release;
  1196. mutex_lock(&sas_host->lock);
  1197. rdev->rphy.scsi_target_id = sas_host->next_expander_id++;
  1198. mutex_unlock(&sas_host->lock);
  1199. dev_set_name(&rdev->rphy.dev, "expander-%d:%d",
  1200. shost->host_no, rdev->rphy.scsi_target_id);
  1201. rdev->rphy.identify.device_type = type;
  1202. sas_rphy_initialize(&rdev->rphy);
  1203. transport_setup_device(&rdev->rphy.dev);
  1204. return &rdev->rphy;
  1205. }
  1206. EXPORT_SYMBOL(sas_expander_alloc);
  1207. /**
  1208. * sas_rphy_add - add a SAS remote PHY to the device hierarchy
  1209. * @rphy: The remote PHY to be added
  1210. *
  1211. * Publishes a SAS remote PHY to the rest of the system.
  1212. */
  1213. int sas_rphy_add(struct sas_rphy *rphy)
  1214. {
  1215. struct sas_port *parent = dev_to_sas_port(rphy->dev.parent);
  1216. struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
  1217. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1218. struct sas_identify *identify = &rphy->identify;
  1219. int error;
  1220. if (parent->rphy)
  1221. return -ENXIO;
  1222. parent->rphy = rphy;
  1223. error = device_add(&rphy->dev);
  1224. if (error)
  1225. return error;
  1226. transport_add_device(&rphy->dev);
  1227. transport_configure_device(&rphy->dev);
  1228. if (sas_bsg_initialize(shost, rphy))
  1229. printk("fail to a bsg device %s\n", dev_name(&rphy->dev));
  1230. mutex_lock(&sas_host->lock);
  1231. list_add_tail(&rphy->list, &sas_host->rphy_list);
  1232. if (identify->device_type == SAS_END_DEVICE &&
  1233. (identify->target_port_protocols &
  1234. (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA)))
  1235. rphy->scsi_target_id = sas_host->next_target_id++;
  1236. else if (identify->device_type == SAS_END_DEVICE)
  1237. rphy->scsi_target_id = -1;
  1238. mutex_unlock(&sas_host->lock);
  1239. if (identify->device_type == SAS_END_DEVICE &&
  1240. rphy->scsi_target_id != -1) {
  1241. scsi_scan_target(&rphy->dev, 0,
  1242. rphy->scsi_target_id, SCAN_WILD_CARD, 0);
  1243. }
  1244. return 0;
  1245. }
  1246. EXPORT_SYMBOL(sas_rphy_add);
  1247. /**
  1248. * sas_rphy_free - free a SAS remote PHY
  1249. * @rphy: SAS remote PHY to free
  1250. *
  1251. * Frees the specified SAS remote PHY.
  1252. *
  1253. * Note:
  1254. * This function must only be called on a remote
  1255. * PHY that has not sucessfully been added using
  1256. * sas_rphy_add() (or has been sas_rphy_remove()'d)
  1257. */
  1258. void sas_rphy_free(struct sas_rphy *rphy)
  1259. {
  1260. struct device *dev = &rphy->dev;
  1261. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  1262. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1263. mutex_lock(&sas_host->lock);
  1264. list_del(&rphy->list);
  1265. mutex_unlock(&sas_host->lock);
  1266. sas_bsg_remove(shost, rphy);
  1267. transport_destroy_device(dev);
  1268. put_device(dev);
  1269. }
  1270. EXPORT_SYMBOL(sas_rphy_free);
  1271. /**
  1272. * sas_rphy_delete - remove and free SAS remote PHY
  1273. * @rphy: SAS remote PHY to remove and free
  1274. *
  1275. * Removes the specified SAS remote PHY and frees it.
  1276. */
  1277. void
  1278. sas_rphy_delete(struct sas_rphy *rphy)
  1279. {
  1280. sas_rphy_remove(rphy);
  1281. sas_rphy_free(rphy);
  1282. }
  1283. EXPORT_SYMBOL(sas_rphy_delete);
  1284. /**
  1285. * sas_rphy_remove - remove SAS remote PHY
  1286. * @rphy: SAS remote phy to remove
  1287. *
  1288. * Removes the specified SAS remote PHY.
  1289. */
  1290. void
  1291. sas_rphy_remove(struct sas_rphy *rphy)
  1292. {
  1293. struct device *dev = &rphy->dev;
  1294. struct sas_port *parent = dev_to_sas_port(dev->parent);
  1295. switch (rphy->identify.device_type) {
  1296. case SAS_END_DEVICE:
  1297. scsi_remove_target(dev);
  1298. break;
  1299. case SAS_EDGE_EXPANDER_DEVICE:
  1300. case SAS_FANOUT_EXPANDER_DEVICE:
  1301. sas_remove_children(dev);
  1302. break;
  1303. default:
  1304. break;
  1305. }
  1306. transport_remove_device(dev);
  1307. device_del(dev);
  1308. parent->rphy = NULL;
  1309. }
  1310. EXPORT_SYMBOL(sas_rphy_remove);
  1311. /**
  1312. * scsi_is_sas_rphy - check if a struct device represents a SAS remote PHY
  1313. * @dev: device to check
  1314. *
  1315. * Returns:
  1316. * %1 if the device represents a SAS remote PHY, %0 else
  1317. */
  1318. int scsi_is_sas_rphy(const struct device *dev)
  1319. {
  1320. return dev->release == sas_end_device_release ||
  1321. dev->release == sas_expander_release;
  1322. }
  1323. EXPORT_SYMBOL(scsi_is_sas_rphy);
  1324. /*
  1325. * SCSI scan helper
  1326. */
  1327. static int sas_user_scan(struct Scsi_Host *shost, uint channel,
  1328. uint id, uint lun)
  1329. {
  1330. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  1331. struct sas_rphy *rphy;
  1332. mutex_lock(&sas_host->lock);
  1333. list_for_each_entry(rphy, &sas_host->rphy_list, list) {
  1334. if (rphy->identify.device_type != SAS_END_DEVICE ||
  1335. rphy->scsi_target_id == -1)
  1336. continue;
  1337. if ((channel == SCAN_WILD_CARD || channel == 0) &&
  1338. (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) {
  1339. scsi_scan_target(&rphy->dev, 0,
  1340. rphy->scsi_target_id, lun, 1);
  1341. }
  1342. }
  1343. mutex_unlock(&sas_host->lock);
  1344. return 0;
  1345. }
  1346. /*
  1347. * Setup / Teardown code
  1348. */
  1349. #define SETUP_TEMPLATE(attrb, field, perm, test) \
  1350. i->private_##attrb[count] = dev_attr_##field; \
  1351. i->private_##attrb[count].attr.mode = perm; \
  1352. i->attrb[count] = &i->private_##attrb[count]; \
  1353. if (test) \
  1354. count++
  1355. #define SETUP_TEMPLATE_RW(attrb, field, perm, test, ro_test, ro_perm) \
  1356. i->private_##attrb[count] = dev_attr_##field; \
  1357. i->private_##attrb[count].attr.mode = perm; \
  1358. if (ro_test) { \
  1359. i->private_##attrb[count].attr.mode = ro_perm; \
  1360. i->private_##attrb[count].store = NULL; \
  1361. } \
  1362. i->attrb[count] = &i->private_##attrb[count]; \
  1363. if (test) \
  1364. count++
  1365. #define SETUP_RPORT_ATTRIBUTE(field) \
  1366. SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, 1)
  1367. #define SETUP_OPTIONAL_RPORT_ATTRIBUTE(field, func) \
  1368. SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
  1369. #define SETUP_PHY_ATTRIBUTE(field) \
  1370. SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, 1)
  1371. #define SETUP_PHY_ATTRIBUTE_RW(field) \
  1372. SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \
  1373. !i->f->set_phy_speed, S_IRUGO)
  1374. #define SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(field, func) \
  1375. SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \
  1376. !i->f->func, S_IRUGO)
  1377. #define SETUP_PORT_ATTRIBUTE(field) \
  1378. SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
  1379. #define SETUP_OPTIONAL_PHY_ATTRIBUTE(field, func) \
  1380. SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
  1381. #define SETUP_PHY_ATTRIBUTE_WRONLY(field) \
  1382. SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, 1)
  1383. #define SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(field, func) \
  1384. SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func)
  1385. #define SETUP_END_DEV_ATTRIBUTE(field) \
  1386. SETUP_TEMPLATE(end_dev_attrs, field, S_IRUGO, 1)
  1387. #define SETUP_EXPANDER_ATTRIBUTE(field) \
  1388. SETUP_TEMPLATE(expander_attrs, expander_##field, S_IRUGO, 1)
  1389. /**
  1390. * sas_attach_transport - instantiate SAS transport template
  1391. * @ft: SAS transport class function template
  1392. */
  1393. struct scsi_transport_template *
  1394. sas_attach_transport(struct sas_function_template *ft)
  1395. {
  1396. struct sas_internal *i;
  1397. int count;
  1398. i = kzalloc(sizeof(struct sas_internal), GFP_KERNEL);
  1399. if (!i)
  1400. return NULL;
  1401. i->t.user_scan = sas_user_scan;
  1402. i->t.host_attrs.ac.attrs = &i->host_attrs[0];
  1403. i->t.host_attrs.ac.class = &sas_host_class.class;
  1404. i->t.host_attrs.ac.match = sas_host_match;
  1405. transport_container_register(&i->t.host_attrs);
  1406. i->t.host_size = sizeof(struct sas_host_attrs);
  1407. i->phy_attr_cont.ac.class = &sas_phy_class.class;
  1408. i->phy_attr_cont.ac.attrs = &i->phy_attrs[0];
  1409. i->phy_attr_cont.ac.match = sas_phy_match;
  1410. transport_container_register(&i->phy_attr_cont);
  1411. i->port_attr_cont.ac.class = &sas_port_class.class;
  1412. i->port_attr_cont.ac.attrs = &i->port_attrs[0];
  1413. i->port_attr_cont.ac.match = sas_port_match;
  1414. transport_container_register(&i->port_attr_cont);
  1415. i->rphy_attr_cont.ac.class = &sas_rphy_class.class;
  1416. i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0];
  1417. i->rphy_attr_cont.ac.match = sas_rphy_match;
  1418. transport_container_register(&i->rphy_attr_cont);
  1419. i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class;
  1420. i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0];
  1421. i->end_dev_attr_cont.ac.match = sas_end_dev_match;
  1422. transport_container_register(&i->end_dev_attr_cont);
  1423. i->expander_attr_cont.ac.class = &sas_expander_class.class;
  1424. i->expander_attr_cont.ac.attrs = &i->expander_attrs[0];
  1425. i->expander_attr_cont.ac.match = sas_expander_match;
  1426. transport_container_register(&i->expander_attr_cont);
  1427. i->f = ft;
  1428. count = 0;
  1429. SETUP_PORT_ATTRIBUTE(num_phys);
  1430. i->host_attrs[count] = NULL;
  1431. count = 0;
  1432. SETUP_PHY_ATTRIBUTE(initiator_port_protocols);
  1433. SETUP_PHY_ATTRIBUTE(target_port_protocols);
  1434. SETUP_PHY_ATTRIBUTE(device_type);
  1435. SETUP_PHY_ATTRIBUTE(sas_address);
  1436. SETUP_PHY_ATTRIBUTE(phy_identifier);
  1437. //SETUP_PHY_ATTRIBUTE(port_identifier);
  1438. SETUP_PHY_ATTRIBUTE(negotiated_linkrate);
  1439. SETUP_PHY_ATTRIBUTE(minimum_linkrate_hw);
  1440. SETUP_PHY_ATTRIBUTE_RW(minimum_linkrate);
  1441. SETUP_PHY_ATTRIBUTE(maximum_linkrate_hw);
  1442. SETUP_PHY_ATTRIBUTE_RW(maximum_linkrate);
  1443. SETUP_PHY_ATTRIBUTE(invalid_dword_count);
  1444. SETUP_PHY_ATTRIBUTE(running_disparity_error_count);
  1445. SETUP_PHY_ATTRIBUTE(loss_of_dword_sync_count);
  1446. SETUP_PHY_ATTRIBUTE(phy_reset_problem_count);
  1447. SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(link_reset, phy_reset);
  1448. SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(hard_reset, phy_reset);
  1449. SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(enable, phy_enable);
  1450. i->phy_attrs[count] = NULL;
  1451. count = 0;
  1452. SETUP_PORT_ATTRIBUTE(num_phys);
  1453. i->port_attrs[count] = NULL;
  1454. count = 0;
  1455. SETUP_RPORT_ATTRIBUTE(rphy_initiator_port_protocols);
  1456. SETUP_RPORT_ATTRIBUTE(rphy_target_port_protocols);
  1457. SETUP_RPORT_ATTRIBUTE(rphy_device_type);
  1458. SETUP_RPORT_ATTRIBUTE(rphy_sas_address);
  1459. SETUP_RPORT_ATTRIBUTE(rphy_phy_identifier);
  1460. SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_enclosure_identifier,
  1461. get_enclosure_identifier);
  1462. SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_bay_identifier,
  1463. get_bay_identifier);
  1464. i->rphy_attrs[count] = NULL;
  1465. count = 0;
  1466. SETUP_END_DEV_ATTRIBUTE(end_dev_ready_led_meaning);
  1467. SETUP_END_DEV_ATTRIBUTE(end_dev_I_T_nexus_loss_timeout);
  1468. SETUP_END_DEV_ATTRIBUTE(end_dev_initiator_response_timeout);
  1469. i->end_dev_attrs[count] = NULL;
  1470. count = 0;
  1471. SETUP_EXPANDER_ATTRIBUTE(vendor_id);
  1472. SETUP_EXPANDER_ATTRIBUTE(product_id);
  1473. SETUP_EXPANDER_ATTRIBUTE(product_rev);
  1474. SETUP_EXPANDER_ATTRIBUTE(component_vendor_id);
  1475. SETUP_EXPANDER_ATTRIBUTE(component_id);
  1476. SETUP_EXPANDER_ATTRIBUTE(component_revision_id);
  1477. SETUP_EXPANDER_ATTRIBUTE(level);
  1478. i->expander_attrs[count] = NULL;
  1479. return &i->t;
  1480. }
  1481. EXPORT_SYMBOL(sas_attach_transport);
  1482. /**
  1483. * sas_release_transport - release SAS transport template instance
  1484. * @t: transport template instance
  1485. */
  1486. void sas_release_transport(struct scsi_transport_template *t)
  1487. {
  1488. struct sas_internal *i = to_sas_internal(t);
  1489. transport_container_unregister(&i->t.host_attrs);
  1490. transport_container_unregister(&i->phy_attr_cont);
  1491. transport_container_unregister(&i->port_attr_cont);
  1492. transport_container_unregister(&i->rphy_attr_cont);
  1493. transport_container_unregister(&i->end_dev_attr_cont);
  1494. transport_container_unregister(&i->expander_attr_cont);
  1495. kfree(i);
  1496. }
  1497. EXPORT_SYMBOL(sas_release_transport);
  1498. static __init int sas_transport_init(void)
  1499. {
  1500. int error;
  1501. error = transport_class_register(&sas_host_class);
  1502. if (error)
  1503. goto out;
  1504. error = transport_class_register(&sas_phy_class);
  1505. if (error)
  1506. goto out_unregister_transport;
  1507. error = transport_class_register(&sas_port_class);
  1508. if (error)
  1509. goto out_unregister_phy;
  1510. error = transport_class_register(&sas_rphy_class);
  1511. if (error)
  1512. goto out_unregister_port;
  1513. error = transport_class_register(&sas_end_dev_class);
  1514. if (error)
  1515. goto out_unregister_rphy;
  1516. error = transport_class_register(&sas_expander_class);
  1517. if (error)
  1518. goto out_unregister_end_dev;
  1519. return 0;
  1520. out_unregister_end_dev:
  1521. transport_class_unregister(&sas_end_dev_class);
  1522. out_unregister_rphy:
  1523. transport_class_unregister(&sas_rphy_class);
  1524. out_unregister_port:
  1525. transport_class_unregister(&sas_port_class);
  1526. out_unregister_phy:
  1527. transport_class_unregister(&sas_phy_class);
  1528. out_unregister_transport:
  1529. transport_class_unregister(&sas_host_class);
  1530. out:
  1531. return error;
  1532. }
  1533. static void __exit sas_transport_exit(void)
  1534. {
  1535. transport_class_unregister(&sas_host_class);
  1536. transport_class_unregister(&sas_phy_class);
  1537. transport_class_unregister(&sas_port_class);
  1538. transport_class_unregister(&sas_rphy_class);
  1539. transport_class_unregister(&sas_end_dev_class);
  1540. transport_class_unregister(&sas_expander_class);
  1541. }
  1542. MODULE_AUTHOR("Christoph Hellwig");
  1543. MODULE_DESCRIPTION("SAS Transport Attributes");
  1544. MODULE_LICENSE("GPL");
  1545. module_init(sas_transport_init);
  1546. module_exit(sas_transport_exit);