scsi_transport_sas.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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/err.h>
  28. #include <linux/slab.h>
  29. #include <linux/string.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport.h>
  34. #include <scsi/scsi_transport_sas.h>
  35. #define SAS_HOST_ATTRS 0
  36. #define SAS_PORT_ATTRS 17
  37. #define SAS_RPORT_ATTRS 7
  38. #define SAS_END_DEV_ATTRS 3
  39. #define SAS_EXPANDER_ATTRS 7
  40. struct sas_internal {
  41. struct scsi_transport_template t;
  42. struct sas_function_template *f;
  43. struct class_device_attribute private_host_attrs[SAS_HOST_ATTRS];
  44. struct class_device_attribute private_phy_attrs[SAS_PORT_ATTRS];
  45. struct class_device_attribute private_rphy_attrs[SAS_RPORT_ATTRS];
  46. struct class_device_attribute private_end_dev_attrs[SAS_END_DEV_ATTRS];
  47. struct class_device_attribute private_expander_attrs[SAS_EXPANDER_ATTRS];
  48. struct transport_container phy_attr_cont;
  49. struct transport_container rphy_attr_cont;
  50. struct transport_container end_dev_attr_cont;
  51. struct transport_container expander_attr_cont;
  52. /*
  53. * The array of null terminated pointers to attributes
  54. * needed by scsi_sysfs.c
  55. */
  56. struct class_device_attribute *host_attrs[SAS_HOST_ATTRS + 1];
  57. struct class_device_attribute *phy_attrs[SAS_PORT_ATTRS + 1];
  58. struct class_device_attribute *rphy_attrs[SAS_RPORT_ATTRS + 1];
  59. struct class_device_attribute *end_dev_attrs[SAS_END_DEV_ATTRS + 1];
  60. struct class_device_attribute *expander_attrs[SAS_EXPANDER_ATTRS + 1];
  61. };
  62. #define to_sas_internal(tmpl) container_of(tmpl, struct sas_internal, t)
  63. struct sas_host_attrs {
  64. struct list_head rphy_list;
  65. struct mutex lock;
  66. u32 next_target_id;
  67. u32 next_expander_id;
  68. };
  69. #define to_sas_host_attrs(host) ((struct sas_host_attrs *)(host)->shost_data)
  70. /*
  71. * Hack to allow attributes of the same name in different objects.
  72. */
  73. #define SAS_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
  74. struct class_device_attribute class_device_attr_##_prefix##_##_name = \
  75. __ATTR(_name,_mode,_show,_store)
  76. /*
  77. * Pretty printing helpers
  78. */
  79. #define sas_bitfield_name_match(title, table) \
  80. static ssize_t \
  81. get_sas_##title##_names(u32 table_key, char *buf) \
  82. { \
  83. char *prefix = ""; \
  84. ssize_t len = 0; \
  85. int i; \
  86. \
  87. for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
  88. if (table[i].value & table_key) { \
  89. len += sprintf(buf + len, "%s%s", \
  90. prefix, table[i].name); \
  91. prefix = ", "; \
  92. } \
  93. } \
  94. len += sprintf(buf + len, "\n"); \
  95. return len; \
  96. }
  97. #define sas_bitfield_name_search(title, table) \
  98. static ssize_t \
  99. get_sas_##title##_names(u32 table_key, char *buf) \
  100. { \
  101. ssize_t len = 0; \
  102. int i; \
  103. \
  104. for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
  105. if (table[i].value == table_key) { \
  106. len += sprintf(buf + len, "%s", \
  107. table[i].name); \
  108. break; \
  109. } \
  110. } \
  111. len += sprintf(buf + len, "\n"); \
  112. return len; \
  113. }
  114. static struct {
  115. u32 value;
  116. char *name;
  117. } sas_device_type_names[] = {
  118. { SAS_PHY_UNUSED, "unused" },
  119. { SAS_END_DEVICE, "end device" },
  120. { SAS_EDGE_EXPANDER_DEVICE, "edge expander" },
  121. { SAS_FANOUT_EXPANDER_DEVICE, "fanout expander" },
  122. };
  123. sas_bitfield_name_search(device_type, sas_device_type_names)
  124. static struct {
  125. u32 value;
  126. char *name;
  127. } sas_protocol_names[] = {
  128. { SAS_PROTOCOL_SATA, "sata" },
  129. { SAS_PROTOCOL_SMP, "smp" },
  130. { SAS_PROTOCOL_STP, "stp" },
  131. { SAS_PROTOCOL_SSP, "ssp" },
  132. };
  133. sas_bitfield_name_match(protocol, sas_protocol_names)
  134. static struct {
  135. u32 value;
  136. char *name;
  137. } sas_linkspeed_names[] = {
  138. { SAS_LINK_RATE_UNKNOWN, "Unknown" },
  139. { SAS_PHY_DISABLED, "Phy disabled" },
  140. { SAS_LINK_RATE_FAILED, "Link Rate failed" },
  141. { SAS_SATA_SPINUP_HOLD, "Spin-up hold" },
  142. { SAS_LINK_RATE_1_5_GBPS, "1.5 Gbit" },
  143. { SAS_LINK_RATE_3_0_GBPS, "3.0 Gbit" },
  144. { SAS_LINK_RATE_6_0_GBPS, "6.0 Gbit" },
  145. };
  146. sas_bitfield_name_search(linkspeed, sas_linkspeed_names)
  147. /*
  148. * SAS host attributes
  149. */
  150. static int sas_host_setup(struct transport_container *tc, struct device *dev,
  151. struct class_device *cdev)
  152. {
  153. struct Scsi_Host *shost = dev_to_shost(dev);
  154. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  155. INIT_LIST_HEAD(&sas_host->rphy_list);
  156. mutex_init(&sas_host->lock);
  157. sas_host->next_target_id = 0;
  158. sas_host->next_expander_id = 0;
  159. return 0;
  160. }
  161. static DECLARE_TRANSPORT_CLASS(sas_host_class,
  162. "sas_host", sas_host_setup, NULL, NULL);
  163. static int sas_host_match(struct attribute_container *cont,
  164. struct device *dev)
  165. {
  166. struct Scsi_Host *shost;
  167. struct sas_internal *i;
  168. if (!scsi_is_host_device(dev))
  169. return 0;
  170. shost = dev_to_shost(dev);
  171. if (!shost->transportt)
  172. return 0;
  173. if (shost->transportt->host_attrs.ac.class !=
  174. &sas_host_class.class)
  175. return 0;
  176. i = to_sas_internal(shost->transportt);
  177. return &i->t.host_attrs.ac == cont;
  178. }
  179. static int do_sas_phy_delete(struct device *dev, void *data)
  180. {
  181. if (scsi_is_sas_phy(dev))
  182. sas_phy_delete(dev_to_phy(dev));
  183. return 0;
  184. }
  185. /**
  186. * sas_remove_host -- tear down a Scsi_Host's SAS data structures
  187. * @shost: Scsi Host that is torn down
  188. *
  189. * Removes all SAS PHYs and remote PHYs for a given Scsi_Host.
  190. * Must be called just before scsi_remove_host for SAS HBAs.
  191. */
  192. void sas_remove_host(struct Scsi_Host *shost)
  193. {
  194. device_for_each_child(&shost->shost_gendev, NULL, do_sas_phy_delete);
  195. }
  196. EXPORT_SYMBOL(sas_remove_host);
  197. /*
  198. * SAS Port attributes
  199. */
  200. #define sas_phy_show_simple(field, name, format_string, cast) \
  201. static ssize_t \
  202. show_sas_phy_##name(struct class_device *cdev, char *buf) \
  203. { \
  204. struct sas_phy *phy = transport_class_to_phy(cdev); \
  205. \
  206. return snprintf(buf, 20, format_string, cast phy->field); \
  207. }
  208. #define sas_phy_simple_attr(field, name, format_string, type) \
  209. sas_phy_show_simple(field, name, format_string, (type)) \
  210. static CLASS_DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL)
  211. #define sas_phy_show_protocol(field, name) \
  212. static ssize_t \
  213. show_sas_phy_##name(struct class_device *cdev, char *buf) \
  214. { \
  215. struct sas_phy *phy = transport_class_to_phy(cdev); \
  216. \
  217. if (!phy->field) \
  218. return snprintf(buf, 20, "none\n"); \
  219. return get_sas_protocol_names(phy->field, buf); \
  220. }
  221. #define sas_phy_protocol_attr(field, name) \
  222. sas_phy_show_protocol(field, name) \
  223. static CLASS_DEVICE_ATTR(name, S_IRUGO, show_sas_phy_##name, NULL)
  224. #define sas_phy_show_linkspeed(field) \
  225. static ssize_t \
  226. show_sas_phy_##field(struct class_device *cdev, char *buf) \
  227. { \
  228. struct sas_phy *phy = transport_class_to_phy(cdev); \
  229. \
  230. return get_sas_linkspeed_names(phy->field, buf); \
  231. }
  232. #define sas_phy_linkspeed_attr(field) \
  233. sas_phy_show_linkspeed(field) \
  234. static CLASS_DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL)
  235. #define sas_phy_show_linkerror(field) \
  236. static ssize_t \
  237. show_sas_phy_##field(struct class_device *cdev, char *buf) \
  238. { \
  239. struct sas_phy *phy = transport_class_to_phy(cdev); \
  240. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent); \
  241. struct sas_internal *i = to_sas_internal(shost->transportt); \
  242. int error; \
  243. \
  244. if (!phy->local_attached) \
  245. return -EINVAL; \
  246. \
  247. error = i->f->get_linkerrors ? i->f->get_linkerrors(phy) : 0; \
  248. if (error) \
  249. return error; \
  250. return snprintf(buf, 20, "%u\n", phy->field); \
  251. }
  252. #define sas_phy_linkerror_attr(field) \
  253. sas_phy_show_linkerror(field) \
  254. static CLASS_DEVICE_ATTR(field, S_IRUGO, show_sas_phy_##field, NULL)
  255. static ssize_t
  256. show_sas_device_type(struct class_device *cdev, char *buf)
  257. {
  258. struct sas_phy *phy = transport_class_to_phy(cdev);
  259. if (!phy->identify.device_type)
  260. return snprintf(buf, 20, "none\n");
  261. return get_sas_device_type_names(phy->identify.device_type, buf);
  262. }
  263. static CLASS_DEVICE_ATTR(device_type, S_IRUGO, show_sas_device_type, NULL);
  264. static ssize_t do_sas_phy_reset(struct class_device *cdev,
  265. size_t count, int hard_reset)
  266. {
  267. struct sas_phy *phy = transport_class_to_phy(cdev);
  268. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  269. struct sas_internal *i = to_sas_internal(shost->transportt);
  270. int error;
  271. if (!phy->local_attached)
  272. return -EINVAL;
  273. error = i->f->phy_reset(phy, hard_reset);
  274. if (error)
  275. return error;
  276. return count;
  277. };
  278. static ssize_t store_sas_link_reset(struct class_device *cdev,
  279. const char *buf, size_t count)
  280. {
  281. return do_sas_phy_reset(cdev, count, 0);
  282. }
  283. static CLASS_DEVICE_ATTR(link_reset, S_IWUSR, NULL, store_sas_link_reset);
  284. static ssize_t store_sas_hard_reset(struct class_device *cdev,
  285. const char *buf, size_t count)
  286. {
  287. return do_sas_phy_reset(cdev, count, 1);
  288. }
  289. static CLASS_DEVICE_ATTR(hard_reset, S_IWUSR, NULL, store_sas_hard_reset);
  290. sas_phy_protocol_attr(identify.initiator_port_protocols,
  291. initiator_port_protocols);
  292. sas_phy_protocol_attr(identify.target_port_protocols,
  293. target_port_protocols);
  294. sas_phy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
  295. unsigned long long);
  296. sas_phy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
  297. sas_phy_simple_attr(port_identifier, port_identifier, "%d\n", u8);
  298. sas_phy_linkspeed_attr(negotiated_linkrate);
  299. sas_phy_linkspeed_attr(minimum_linkrate_hw);
  300. sas_phy_linkspeed_attr(minimum_linkrate);
  301. sas_phy_linkspeed_attr(maximum_linkrate_hw);
  302. sas_phy_linkspeed_attr(maximum_linkrate);
  303. sas_phy_linkerror_attr(invalid_dword_count);
  304. sas_phy_linkerror_attr(running_disparity_error_count);
  305. sas_phy_linkerror_attr(loss_of_dword_sync_count);
  306. sas_phy_linkerror_attr(phy_reset_problem_count);
  307. static DECLARE_TRANSPORT_CLASS(sas_phy_class,
  308. "sas_phy", NULL, NULL, NULL);
  309. static int sas_phy_match(struct attribute_container *cont, struct device *dev)
  310. {
  311. struct Scsi_Host *shost;
  312. struct sas_internal *i;
  313. if (!scsi_is_sas_phy(dev))
  314. return 0;
  315. shost = dev_to_shost(dev->parent);
  316. if (!shost->transportt)
  317. return 0;
  318. if (shost->transportt->host_attrs.ac.class !=
  319. &sas_host_class.class)
  320. return 0;
  321. i = to_sas_internal(shost->transportt);
  322. return &i->phy_attr_cont.ac == cont;
  323. }
  324. static void sas_phy_release(struct device *dev)
  325. {
  326. struct sas_phy *phy = dev_to_phy(dev);
  327. put_device(dev->parent);
  328. kfree(phy);
  329. }
  330. /**
  331. * sas_phy_alloc -- allocates and initialize a SAS PHY structure
  332. * @parent: Parent device
  333. * @number: Phy index
  334. *
  335. * Allocates an SAS PHY structure. It will be added in the device tree
  336. * below the device specified by @parent, which has to be either a Scsi_Host
  337. * or sas_rphy.
  338. *
  339. * Returns:
  340. * SAS PHY allocated or %NULL if the allocation failed.
  341. */
  342. struct sas_phy *sas_phy_alloc(struct device *parent, int number)
  343. {
  344. struct Scsi_Host *shost = dev_to_shost(parent);
  345. struct sas_phy *phy;
  346. phy = kzalloc(sizeof(*phy), GFP_KERNEL);
  347. if (!phy)
  348. return NULL;
  349. get_device(parent);
  350. phy->number = number;
  351. device_initialize(&phy->dev);
  352. phy->dev.parent = get_device(parent);
  353. phy->dev.release = sas_phy_release;
  354. if (scsi_is_sas_expander_device(parent)) {
  355. struct sas_rphy *rphy = dev_to_rphy(parent);
  356. sprintf(phy->dev.bus_id, "phy-%d-%d:%d", shost->host_no,
  357. rphy->scsi_target_id, number);
  358. } else
  359. sprintf(phy->dev.bus_id, "phy-%d:%d", shost->host_no, number);
  360. transport_setup_device(&phy->dev);
  361. return phy;
  362. }
  363. EXPORT_SYMBOL(sas_phy_alloc);
  364. /**
  365. * sas_phy_add -- add a SAS PHY to the device hierachy
  366. * @phy: The PHY to be added
  367. *
  368. * Publishes a SAS PHY to the rest of the system.
  369. */
  370. int sas_phy_add(struct sas_phy *phy)
  371. {
  372. int error;
  373. error = device_add(&phy->dev);
  374. if (!error) {
  375. transport_add_device(&phy->dev);
  376. transport_configure_device(&phy->dev);
  377. }
  378. return error;
  379. }
  380. EXPORT_SYMBOL(sas_phy_add);
  381. /**
  382. * sas_phy_free -- free a SAS PHY
  383. * @phy: SAS PHY to free
  384. *
  385. * Frees the specified SAS PHY.
  386. *
  387. * Note:
  388. * This function must only be called on a PHY that has not
  389. * sucessfully been added using sas_phy_add().
  390. */
  391. void sas_phy_free(struct sas_phy *phy)
  392. {
  393. transport_destroy_device(&phy->dev);
  394. put_device(phy->dev.parent);
  395. put_device(phy->dev.parent);
  396. put_device(phy->dev.parent);
  397. kfree(phy);
  398. }
  399. EXPORT_SYMBOL(sas_phy_free);
  400. /**
  401. * sas_phy_delete -- remove SAS PHY
  402. * @phy: SAS PHY to remove
  403. *
  404. * Removes the specified SAS PHY. If the SAS PHY has an
  405. * associated remote PHY it is removed before.
  406. */
  407. void
  408. sas_phy_delete(struct sas_phy *phy)
  409. {
  410. struct device *dev = &phy->dev;
  411. if (phy->rphy)
  412. sas_rphy_delete(phy->rphy);
  413. transport_remove_device(dev);
  414. device_del(dev);
  415. transport_destroy_device(dev);
  416. put_device(dev->parent);
  417. }
  418. EXPORT_SYMBOL(sas_phy_delete);
  419. /**
  420. * scsi_is_sas_phy -- check if a struct device represents a SAS PHY
  421. * @dev: device to check
  422. *
  423. * Returns:
  424. * %1 if the device represents a SAS PHY, %0 else
  425. */
  426. int scsi_is_sas_phy(const struct device *dev)
  427. {
  428. return dev->release == sas_phy_release;
  429. }
  430. EXPORT_SYMBOL(scsi_is_sas_phy);
  431. /*
  432. * SAS remote PHY attributes.
  433. */
  434. #define sas_rphy_show_simple(field, name, format_string, cast) \
  435. static ssize_t \
  436. show_sas_rphy_##name(struct class_device *cdev, char *buf) \
  437. { \
  438. struct sas_rphy *rphy = transport_class_to_rphy(cdev); \
  439. \
  440. return snprintf(buf, 20, format_string, cast rphy->field); \
  441. }
  442. #define sas_rphy_simple_attr(field, name, format_string, type) \
  443. sas_rphy_show_simple(field, name, format_string, (type)) \
  444. static SAS_CLASS_DEVICE_ATTR(rphy, name, S_IRUGO, \
  445. show_sas_rphy_##name, NULL)
  446. #define sas_rphy_show_protocol(field, name) \
  447. static ssize_t \
  448. show_sas_rphy_##name(struct class_device *cdev, char *buf) \
  449. { \
  450. struct sas_rphy *rphy = transport_class_to_rphy(cdev); \
  451. \
  452. if (!rphy->field) \
  453. return snprintf(buf, 20, "none\n"); \
  454. return get_sas_protocol_names(rphy->field, buf); \
  455. }
  456. #define sas_rphy_protocol_attr(field, name) \
  457. sas_rphy_show_protocol(field, name) \
  458. static SAS_CLASS_DEVICE_ATTR(rphy, name, S_IRUGO, \
  459. show_sas_rphy_##name, NULL)
  460. static ssize_t
  461. show_sas_rphy_device_type(struct class_device *cdev, char *buf)
  462. {
  463. struct sas_rphy *rphy = transport_class_to_rphy(cdev);
  464. if (!rphy->identify.device_type)
  465. return snprintf(buf, 20, "none\n");
  466. return get_sas_device_type_names(
  467. rphy->identify.device_type, buf);
  468. }
  469. static SAS_CLASS_DEVICE_ATTR(rphy, device_type, S_IRUGO,
  470. show_sas_rphy_device_type, NULL);
  471. static ssize_t
  472. show_sas_rphy_enclosure_identifier(struct class_device *cdev, char *buf)
  473. {
  474. struct sas_rphy *rphy = transport_class_to_rphy(cdev);
  475. struct sas_phy *phy = dev_to_phy(rphy->dev.parent);
  476. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  477. struct sas_internal *i = to_sas_internal(shost->transportt);
  478. u64 identifier;
  479. int error;
  480. /*
  481. * Only devices behind an expander are supported, because the
  482. * enclosure identifier is a SMP feature.
  483. */
  484. if (phy->local_attached)
  485. return -EINVAL;
  486. error = i->f->get_enclosure_identifier(rphy, &identifier);
  487. if (error)
  488. return error;
  489. return sprintf(buf, "0x%llx\n", (unsigned long long)identifier);
  490. }
  491. static SAS_CLASS_DEVICE_ATTR(rphy, enclosure_identifier, S_IRUGO,
  492. show_sas_rphy_enclosure_identifier, NULL);
  493. static ssize_t
  494. show_sas_rphy_bay_identifier(struct class_device *cdev, char *buf)
  495. {
  496. struct sas_rphy *rphy = transport_class_to_rphy(cdev);
  497. struct sas_phy *phy = dev_to_phy(rphy->dev.parent);
  498. struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
  499. struct sas_internal *i = to_sas_internal(shost->transportt);
  500. int val;
  501. if (phy->local_attached)
  502. return -EINVAL;
  503. val = i->f->get_bay_identifier(rphy);
  504. if (val < 0)
  505. return val;
  506. return sprintf(buf, "%d\n", val);
  507. }
  508. static SAS_CLASS_DEVICE_ATTR(rphy, bay_identifier, S_IRUGO,
  509. show_sas_rphy_bay_identifier, NULL);
  510. sas_rphy_protocol_attr(identify.initiator_port_protocols,
  511. initiator_port_protocols);
  512. sas_rphy_protocol_attr(identify.target_port_protocols, target_port_protocols);
  513. sas_rphy_simple_attr(identify.sas_address, sas_address, "0x%016llx\n",
  514. unsigned long long);
  515. sas_rphy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
  516. /* only need 8 bytes of data plus header (4 or 8) */
  517. #define BUF_SIZE 64
  518. int sas_read_port_mode_page(struct scsi_device *sdev)
  519. {
  520. char *buffer = kzalloc(BUF_SIZE, GFP_KERNEL), *msdata;
  521. struct sas_rphy *rphy = target_to_rphy(sdev->sdev_target);
  522. struct sas_end_device *rdev;
  523. struct scsi_mode_data mode_data;
  524. int res, error;
  525. BUG_ON(rphy->identify.device_type != SAS_END_DEVICE);
  526. rdev = rphy_to_end_device(rphy);
  527. if (!buffer)
  528. return -ENOMEM;
  529. res = scsi_mode_sense(sdev, 1, 0x19, buffer, BUF_SIZE, 30*HZ, 3,
  530. &mode_data, NULL);
  531. error = -EINVAL;
  532. if (!scsi_status_is_good(res))
  533. goto out;
  534. msdata = buffer + mode_data.header_length +
  535. mode_data.block_descriptor_length;
  536. if (msdata - buffer > BUF_SIZE - 8)
  537. goto out;
  538. error = 0;
  539. rdev->ready_led_meaning = msdata[2] & 0x10 ? 1 : 0;
  540. rdev->I_T_nexus_loss_timeout = (msdata[4] << 8) + msdata[5];
  541. rdev->initiator_response_timeout = (msdata[6] << 8) + msdata[7];
  542. out:
  543. kfree(buffer);
  544. return error;
  545. }
  546. EXPORT_SYMBOL(sas_read_port_mode_page);
  547. static DECLARE_TRANSPORT_CLASS(sas_end_dev_class,
  548. "sas_end_device", NULL, NULL, NULL);
  549. #define sas_end_dev_show_simple(field, name, format_string, cast) \
  550. static ssize_t \
  551. show_sas_end_dev_##name(struct class_device *cdev, char *buf) \
  552. { \
  553. struct sas_rphy *rphy = transport_class_to_rphy(cdev); \
  554. struct sas_end_device *rdev = rphy_to_end_device(rphy); \
  555. \
  556. return snprintf(buf, 20, format_string, cast rdev->field); \
  557. }
  558. #define sas_end_dev_simple_attr(field, name, format_string, type) \
  559. sas_end_dev_show_simple(field, name, format_string, (type)) \
  560. static SAS_CLASS_DEVICE_ATTR(end_dev, name, S_IRUGO, \
  561. show_sas_end_dev_##name, NULL)
  562. sas_end_dev_simple_attr(ready_led_meaning, ready_led_meaning, "%d\n", int);
  563. sas_end_dev_simple_attr(I_T_nexus_loss_timeout, I_T_nexus_loss_timeout,
  564. "%d\n", int);
  565. sas_end_dev_simple_attr(initiator_response_timeout, initiator_response_timeout,
  566. "%d\n", int);
  567. static DECLARE_TRANSPORT_CLASS(sas_expander_class,
  568. "sas_expander", NULL, NULL, NULL);
  569. #define sas_expander_show_simple(field, name, format_string, cast) \
  570. static ssize_t \
  571. show_sas_expander_##name(struct class_device *cdev, char *buf) \
  572. { \
  573. struct sas_rphy *rphy = transport_class_to_rphy(cdev); \
  574. struct sas_expander_device *edev = rphy_to_expander_device(rphy); \
  575. \
  576. return snprintf(buf, 20, format_string, cast edev->field); \
  577. }
  578. #define sas_expander_simple_attr(field, name, format_string, type) \
  579. sas_expander_show_simple(field, name, format_string, (type)) \
  580. static SAS_CLASS_DEVICE_ATTR(expander, name, S_IRUGO, \
  581. show_sas_expander_##name, NULL)
  582. sas_expander_simple_attr(vendor_id, vendor_id, "%s\n", char *);
  583. sas_expander_simple_attr(product_id, product_id, "%s\n", char *);
  584. sas_expander_simple_attr(product_rev, product_rev, "%s\n", char *);
  585. sas_expander_simple_attr(component_vendor_id, component_vendor_id,
  586. "%s\n", char *);
  587. sas_expander_simple_attr(component_id, component_id, "%u\n", unsigned int);
  588. sas_expander_simple_attr(component_revision_id, component_revision_id, "%u\n",
  589. unsigned int);
  590. sas_expander_simple_attr(level, level, "%d\n", int);
  591. static DECLARE_TRANSPORT_CLASS(sas_rphy_class,
  592. "sas_rphy", NULL, NULL, NULL);
  593. static int sas_rphy_match(struct attribute_container *cont, struct device *dev)
  594. {
  595. struct Scsi_Host *shost;
  596. struct sas_internal *i;
  597. if (!scsi_is_sas_rphy(dev))
  598. return 0;
  599. shost = dev_to_shost(dev->parent->parent);
  600. if (!shost->transportt)
  601. return 0;
  602. if (shost->transportt->host_attrs.ac.class !=
  603. &sas_host_class.class)
  604. return 0;
  605. i = to_sas_internal(shost->transportt);
  606. return &i->rphy_attr_cont.ac == cont;
  607. }
  608. static int sas_end_dev_match(struct attribute_container *cont,
  609. struct device *dev)
  610. {
  611. struct Scsi_Host *shost;
  612. struct sas_internal *i;
  613. struct sas_rphy *rphy;
  614. if (!scsi_is_sas_rphy(dev))
  615. return 0;
  616. shost = dev_to_shost(dev->parent->parent);
  617. rphy = dev_to_rphy(dev);
  618. if (!shost->transportt)
  619. return 0;
  620. if (shost->transportt->host_attrs.ac.class !=
  621. &sas_host_class.class)
  622. return 0;
  623. i = to_sas_internal(shost->transportt);
  624. return &i->end_dev_attr_cont.ac == cont &&
  625. rphy->identify.device_type == SAS_END_DEVICE &&
  626. /* FIXME: remove contained eventually */
  627. rphy->contained;
  628. }
  629. static int sas_expander_match(struct attribute_container *cont,
  630. struct device *dev)
  631. {
  632. struct Scsi_Host *shost;
  633. struct sas_internal *i;
  634. struct sas_rphy *rphy;
  635. if (!scsi_is_sas_rphy(dev))
  636. return 0;
  637. shost = dev_to_shost(dev->parent->parent);
  638. rphy = dev_to_rphy(dev);
  639. if (!shost->transportt)
  640. return 0;
  641. if (shost->transportt->host_attrs.ac.class !=
  642. &sas_host_class.class)
  643. return 0;
  644. i = to_sas_internal(shost->transportt);
  645. return &i->expander_attr_cont.ac == cont &&
  646. (rphy->identify.device_type == SAS_EDGE_EXPANDER_DEVICE ||
  647. rphy->identify.device_type == SAS_FANOUT_EXPANDER_DEVICE) &&
  648. /* FIXME: remove contained eventually */
  649. rphy->contained;
  650. }
  651. static void sas_rphy_release(struct device *dev)
  652. {
  653. struct sas_rphy *rphy = dev_to_rphy(dev);
  654. put_device(dev->parent);
  655. kfree(rphy);
  656. }
  657. /**
  658. * sas_rphy_alloc -- allocates and initialize a SAS remote PHY structure
  659. * @parent: SAS PHY this remote PHY is conneted to
  660. *
  661. * Allocates an SAS remote PHY structure, connected to @parent.
  662. *
  663. * Returns:
  664. * SAS PHY allocated or %NULL if the allocation failed.
  665. */
  666. struct sas_rphy *sas_rphy_alloc(struct sas_phy *parent)
  667. {
  668. struct Scsi_Host *shost = dev_to_shost(&parent->dev);
  669. struct sas_rphy *rphy;
  670. rphy = kzalloc(sizeof(*rphy), GFP_KERNEL);
  671. if (!rphy) {
  672. put_device(&parent->dev);
  673. return NULL;
  674. }
  675. device_initialize(&rphy->dev);
  676. rphy->dev.parent = get_device(&parent->dev);
  677. rphy->dev.release = sas_rphy_release;
  678. sprintf(rphy->dev.bus_id, "rphy-%d:%d-%d",
  679. shost->host_no, parent->port_identifier, parent->number);
  680. transport_setup_device(&rphy->dev);
  681. return rphy;
  682. }
  683. EXPORT_SYMBOL(sas_rphy_alloc);
  684. /**
  685. * sas_end_device_alloc - allocate an rphy for an end device
  686. *
  687. * Allocates an SAS remote PHY structure, connected to @parent.
  688. *
  689. * Returns:
  690. * SAS PHY allocated or %NULL if the allocation failed.
  691. */
  692. struct sas_rphy *sas_end_device_alloc(struct sas_phy *parent)
  693. {
  694. struct Scsi_Host *shost = dev_to_shost(&parent->dev);
  695. struct sas_end_device *rdev;
  696. rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
  697. if (!rdev) {
  698. put_device(&parent->dev);
  699. return NULL;
  700. }
  701. device_initialize(&rdev->rphy.dev);
  702. rdev->rphy.dev.parent = get_device(&parent->dev);
  703. rdev->rphy.dev.release = sas_rphy_release;
  704. sprintf(rdev->rphy.dev.bus_id, "rphy-%d:%d-%d",
  705. shost->host_no, parent->port_identifier, parent->number);
  706. rdev->rphy.identify.device_type = SAS_END_DEVICE;
  707. /* FIXME: mark the rphy as being contained in a larger structure */
  708. rdev->rphy.contained = 1;
  709. transport_setup_device(&rdev->rphy.dev);
  710. return &rdev->rphy;
  711. }
  712. EXPORT_SYMBOL(sas_end_device_alloc);
  713. /**
  714. * sas_expander_alloc - allocate an rphy for an end device
  715. *
  716. * Allocates an SAS remote PHY structure, connected to @parent.
  717. *
  718. * Returns:
  719. * SAS PHY allocated or %NULL if the allocation failed.
  720. */
  721. struct sas_rphy *sas_expander_alloc(struct sas_phy *parent,
  722. enum sas_device_type type)
  723. {
  724. struct Scsi_Host *shost = dev_to_shost(&parent->dev);
  725. struct sas_expander_device *rdev;
  726. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  727. BUG_ON(type != SAS_EDGE_EXPANDER_DEVICE &&
  728. type != SAS_FANOUT_EXPANDER_DEVICE);
  729. rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
  730. if (!rdev) {
  731. put_device(&parent->dev);
  732. return NULL;
  733. }
  734. device_initialize(&rdev->rphy.dev);
  735. rdev->rphy.dev.parent = get_device(&parent->dev);
  736. rdev->rphy.dev.release = sas_rphy_release;
  737. mutex_lock(&sas_host->lock);
  738. rdev->rphy.scsi_target_id = sas_host->next_expander_id++;
  739. mutex_unlock(&sas_host->lock);
  740. sprintf(rdev->rphy.dev.bus_id, "expander-%d:%d",
  741. shost->host_no, rdev->rphy.scsi_target_id);
  742. rdev->rphy.identify.device_type = type;
  743. /* FIXME: mark the rphy as being contained in a larger structure */
  744. rdev->rphy.contained = 1;
  745. transport_setup_device(&rdev->rphy.dev);
  746. return &rdev->rphy;
  747. }
  748. EXPORT_SYMBOL(sas_expander_alloc);
  749. /**
  750. * sas_rphy_add -- add a SAS remote PHY to the device hierachy
  751. * @rphy: The remote PHY to be added
  752. *
  753. * Publishes a SAS remote PHY to the rest of the system.
  754. */
  755. int sas_rphy_add(struct sas_rphy *rphy)
  756. {
  757. struct sas_phy *parent = dev_to_phy(rphy->dev.parent);
  758. struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
  759. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  760. struct sas_identify *identify = &rphy->identify;
  761. int error;
  762. if (parent->rphy)
  763. return -ENXIO;
  764. parent->rphy = rphy;
  765. error = device_add(&rphy->dev);
  766. if (error)
  767. return error;
  768. transport_add_device(&rphy->dev);
  769. transport_configure_device(&rphy->dev);
  770. mutex_lock(&sas_host->lock);
  771. list_add_tail(&rphy->list, &sas_host->rphy_list);
  772. if (identify->device_type == SAS_END_DEVICE &&
  773. (identify->target_port_protocols &
  774. (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA)))
  775. rphy->scsi_target_id = sas_host->next_target_id++;
  776. mutex_unlock(&sas_host->lock);
  777. if (identify->device_type == SAS_END_DEVICE &&
  778. rphy->scsi_target_id != -1) {
  779. scsi_scan_target(&rphy->dev, parent->port_identifier,
  780. rphy->scsi_target_id, ~0, 0);
  781. }
  782. return 0;
  783. }
  784. EXPORT_SYMBOL(sas_rphy_add);
  785. /**
  786. * sas_rphy_free -- free a SAS remote PHY
  787. * @rphy SAS remote PHY to free
  788. *
  789. * Frees the specified SAS remote PHY.
  790. *
  791. * Note:
  792. * This function must only be called on a remote
  793. * PHY that has not sucessfully been added using
  794. * sas_rphy_add().
  795. */
  796. void sas_rphy_free(struct sas_rphy *rphy)
  797. {
  798. struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
  799. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  800. mutex_lock(&sas_host->lock);
  801. list_del(&rphy->list);
  802. mutex_unlock(&sas_host->lock);
  803. transport_destroy_device(&rphy->dev);
  804. put_device(rphy->dev.parent);
  805. put_device(rphy->dev.parent);
  806. put_device(rphy->dev.parent);
  807. kfree(rphy);
  808. }
  809. EXPORT_SYMBOL(sas_rphy_free);
  810. /**
  811. * sas_rphy_delete -- remove SAS remote PHY
  812. * @rphy: SAS remote PHY to remove
  813. *
  814. * Removes the specified SAS remote PHY.
  815. */
  816. void
  817. sas_rphy_delete(struct sas_rphy *rphy)
  818. {
  819. struct device *dev = &rphy->dev;
  820. struct sas_phy *parent = dev_to_phy(dev->parent);
  821. struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
  822. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  823. switch (rphy->identify.device_type) {
  824. case SAS_END_DEVICE:
  825. scsi_remove_target(dev);
  826. break;
  827. case SAS_EDGE_EXPANDER_DEVICE:
  828. case SAS_FANOUT_EXPANDER_DEVICE:
  829. device_for_each_child(dev, NULL, do_sas_phy_delete);
  830. break;
  831. default:
  832. break;
  833. }
  834. transport_remove_device(dev);
  835. device_del(dev);
  836. transport_destroy_device(dev);
  837. mutex_lock(&sas_host->lock);
  838. list_del(&rphy->list);
  839. mutex_unlock(&sas_host->lock);
  840. parent->rphy = NULL;
  841. put_device(&parent->dev);
  842. }
  843. EXPORT_SYMBOL(sas_rphy_delete);
  844. /**
  845. * scsi_is_sas_rphy -- check if a struct device represents a SAS remote PHY
  846. * @dev: device to check
  847. *
  848. * Returns:
  849. * %1 if the device represents a SAS remote PHY, %0 else
  850. */
  851. int scsi_is_sas_rphy(const struct device *dev)
  852. {
  853. return dev->release == sas_rphy_release;
  854. }
  855. EXPORT_SYMBOL(scsi_is_sas_rphy);
  856. /*
  857. * SCSI scan helper
  858. */
  859. static int sas_user_scan(struct Scsi_Host *shost, uint channel,
  860. uint id, uint lun)
  861. {
  862. struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
  863. struct sas_rphy *rphy;
  864. mutex_lock(&sas_host->lock);
  865. list_for_each_entry(rphy, &sas_host->rphy_list, list) {
  866. struct sas_phy *parent = dev_to_phy(rphy->dev.parent);
  867. if (rphy->scsi_target_id == -1)
  868. continue;
  869. if ((channel == SCAN_WILD_CARD || channel == parent->port_identifier) &&
  870. (id == SCAN_WILD_CARD || id == rphy->scsi_target_id)) {
  871. scsi_scan_target(&rphy->dev, parent->port_identifier,
  872. rphy->scsi_target_id, lun, 1);
  873. }
  874. }
  875. mutex_unlock(&sas_host->lock);
  876. return 0;
  877. }
  878. /*
  879. * Setup / Teardown code
  880. */
  881. #define SETUP_TEMPLATE(attrb, field, perm, test) \
  882. i->private_##attrb[count] = class_device_attr_##field; \
  883. i->private_##attrb[count].attr.mode = perm; \
  884. i->private_##attrb[count].store = NULL; \
  885. i->attrb[count] = &i->private_##attrb[count]; \
  886. if (test) \
  887. count++
  888. #define SETUP_RPORT_ATTRIBUTE(field) \
  889. SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, 1)
  890. #define SETUP_OPTIONAL_RPORT_ATTRIBUTE(field, func) \
  891. SETUP_TEMPLATE(rphy_attrs, field, S_IRUGO, i->f->func)
  892. #define SETUP_PORT_ATTRIBUTE(field) \
  893. SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, 1)
  894. #define SETUP_OPTIONAL_PORT_ATTRIBUTE(field, func) \
  895. SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
  896. #define SETUP_PORT_ATTRIBUTE_WRONLY(field) \
  897. SETUP_TEMPLATE(phy_attrs, field, S_IWUGO, 1)
  898. #define SETUP_OPTIONAL_PORT_ATTRIBUTE_WRONLY(field, func) \
  899. SETUP_TEMPLATE(phy_attrs, field, S_IWUGO, i->f->func)
  900. #define SETUP_END_DEV_ATTRIBUTE(field) \
  901. SETUP_TEMPLATE(end_dev_attrs, field, S_IRUGO, 1)
  902. #define SETUP_EXPANDER_ATTRIBUTE(field) \
  903. SETUP_TEMPLATE(expander_attrs, expander_##field, S_IRUGO, 1)
  904. /**
  905. * sas_attach_transport -- instantiate SAS transport template
  906. * @ft: SAS transport class function template
  907. */
  908. struct scsi_transport_template *
  909. sas_attach_transport(struct sas_function_template *ft)
  910. {
  911. struct sas_internal *i;
  912. int count;
  913. i = kzalloc(sizeof(struct sas_internal), GFP_KERNEL);
  914. if (!i)
  915. return NULL;
  916. i->t.user_scan = sas_user_scan;
  917. i->t.host_attrs.ac.attrs = &i->host_attrs[0];
  918. i->t.host_attrs.ac.class = &sas_host_class.class;
  919. i->t.host_attrs.ac.match = sas_host_match;
  920. transport_container_register(&i->t.host_attrs);
  921. i->t.host_size = sizeof(struct sas_host_attrs);
  922. i->phy_attr_cont.ac.class = &sas_phy_class.class;
  923. i->phy_attr_cont.ac.attrs = &i->phy_attrs[0];
  924. i->phy_attr_cont.ac.match = sas_phy_match;
  925. transport_container_register(&i->phy_attr_cont);
  926. i->rphy_attr_cont.ac.class = &sas_rphy_class.class;
  927. i->rphy_attr_cont.ac.attrs = &i->rphy_attrs[0];
  928. i->rphy_attr_cont.ac.match = sas_rphy_match;
  929. transport_container_register(&i->rphy_attr_cont);
  930. i->end_dev_attr_cont.ac.class = &sas_end_dev_class.class;
  931. i->end_dev_attr_cont.ac.attrs = &i->end_dev_attrs[0];
  932. i->end_dev_attr_cont.ac.match = sas_end_dev_match;
  933. transport_container_register(&i->end_dev_attr_cont);
  934. i->expander_attr_cont.ac.class = &sas_expander_class.class;
  935. i->expander_attr_cont.ac.attrs = &i->expander_attrs[0];
  936. i->expander_attr_cont.ac.match = sas_expander_match;
  937. transport_container_register(&i->expander_attr_cont);
  938. i->f = ft;
  939. count = 0;
  940. i->host_attrs[count] = NULL;
  941. count = 0;
  942. SETUP_PORT_ATTRIBUTE(initiator_port_protocols);
  943. SETUP_PORT_ATTRIBUTE(target_port_protocols);
  944. SETUP_PORT_ATTRIBUTE(device_type);
  945. SETUP_PORT_ATTRIBUTE(sas_address);
  946. SETUP_PORT_ATTRIBUTE(phy_identifier);
  947. SETUP_PORT_ATTRIBUTE(port_identifier);
  948. SETUP_PORT_ATTRIBUTE(negotiated_linkrate);
  949. SETUP_PORT_ATTRIBUTE(minimum_linkrate_hw);
  950. SETUP_PORT_ATTRIBUTE(minimum_linkrate);
  951. SETUP_PORT_ATTRIBUTE(maximum_linkrate_hw);
  952. SETUP_PORT_ATTRIBUTE(maximum_linkrate);
  953. SETUP_PORT_ATTRIBUTE(invalid_dword_count);
  954. SETUP_PORT_ATTRIBUTE(running_disparity_error_count);
  955. SETUP_PORT_ATTRIBUTE(loss_of_dword_sync_count);
  956. SETUP_PORT_ATTRIBUTE(phy_reset_problem_count);
  957. SETUP_OPTIONAL_PORT_ATTRIBUTE_WRONLY(link_reset, phy_reset);
  958. SETUP_OPTIONAL_PORT_ATTRIBUTE_WRONLY(hard_reset, phy_reset);
  959. i->phy_attrs[count] = NULL;
  960. count = 0;
  961. SETUP_RPORT_ATTRIBUTE(rphy_initiator_port_protocols);
  962. SETUP_RPORT_ATTRIBUTE(rphy_target_port_protocols);
  963. SETUP_RPORT_ATTRIBUTE(rphy_device_type);
  964. SETUP_RPORT_ATTRIBUTE(rphy_sas_address);
  965. SETUP_RPORT_ATTRIBUTE(rphy_phy_identifier);
  966. SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_enclosure_identifier,
  967. get_enclosure_identifier);
  968. SETUP_OPTIONAL_RPORT_ATTRIBUTE(rphy_bay_identifier,
  969. get_bay_identifier);
  970. i->rphy_attrs[count] = NULL;
  971. count = 0;
  972. SETUP_END_DEV_ATTRIBUTE(end_dev_ready_led_meaning);
  973. SETUP_END_DEV_ATTRIBUTE(end_dev_I_T_nexus_loss_timeout);
  974. SETUP_END_DEV_ATTRIBUTE(end_dev_initiator_response_timeout);
  975. i->end_dev_attrs[count] = NULL;
  976. count = 0;
  977. SETUP_EXPANDER_ATTRIBUTE(vendor_id);
  978. SETUP_EXPANDER_ATTRIBUTE(product_id);
  979. SETUP_EXPANDER_ATTRIBUTE(product_rev);
  980. SETUP_EXPANDER_ATTRIBUTE(component_vendor_id);
  981. SETUP_EXPANDER_ATTRIBUTE(component_id);
  982. SETUP_EXPANDER_ATTRIBUTE(component_revision_id);
  983. SETUP_EXPANDER_ATTRIBUTE(level);
  984. i->expander_attrs[count] = NULL;
  985. return &i->t;
  986. }
  987. EXPORT_SYMBOL(sas_attach_transport);
  988. /**
  989. * sas_release_transport -- release SAS transport template instance
  990. * @t: transport template instance
  991. */
  992. void sas_release_transport(struct scsi_transport_template *t)
  993. {
  994. struct sas_internal *i = to_sas_internal(t);
  995. transport_container_unregister(&i->t.host_attrs);
  996. transport_container_unregister(&i->phy_attr_cont);
  997. transport_container_unregister(&i->rphy_attr_cont);
  998. transport_container_unregister(&i->end_dev_attr_cont);
  999. transport_container_unregister(&i->expander_attr_cont);
  1000. kfree(i);
  1001. }
  1002. EXPORT_SYMBOL(sas_release_transport);
  1003. static __init int sas_transport_init(void)
  1004. {
  1005. int error;
  1006. error = transport_class_register(&sas_host_class);
  1007. if (error)
  1008. goto out;
  1009. error = transport_class_register(&sas_phy_class);
  1010. if (error)
  1011. goto out_unregister_transport;
  1012. error = transport_class_register(&sas_rphy_class);
  1013. if (error)
  1014. goto out_unregister_phy;
  1015. error = transport_class_register(&sas_end_dev_class);
  1016. if (error)
  1017. goto out_unregister_rphy;
  1018. error = transport_class_register(&sas_expander_class);
  1019. if (error)
  1020. goto out_unregister_end_dev;
  1021. return 0;
  1022. out_unregister_end_dev:
  1023. transport_class_unregister(&sas_end_dev_class);
  1024. out_unregister_rphy:
  1025. transport_class_unregister(&sas_rphy_class);
  1026. out_unregister_phy:
  1027. transport_class_unregister(&sas_phy_class);
  1028. out_unregister_transport:
  1029. transport_class_unregister(&sas_host_class);
  1030. out:
  1031. return error;
  1032. }
  1033. static void __exit sas_transport_exit(void)
  1034. {
  1035. transport_class_unregister(&sas_host_class);
  1036. transport_class_unregister(&sas_phy_class);
  1037. transport_class_unregister(&sas_rphy_class);
  1038. transport_class_unregister(&sas_end_dev_class);
  1039. transport_class_unregister(&sas_expander_class);
  1040. }
  1041. MODULE_AUTHOR("Christoph Hellwig");
  1042. MODULE_DESCRIPTION("SAS Transphy Attributes");
  1043. MODULE_LICENSE("GPL");
  1044. module_init(sas_transport_init);
  1045. module_exit(sas_transport_exit);