scsi_transport_sas.c 48 KB

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