scsi_transport_sas.c 48 KB

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