sysfs.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
  4. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include "core_priv.h"
  35. #include <linux/slab.h>
  36. #include <linux/stat.h>
  37. #include <linux/string.h>
  38. #include <linux/netdevice.h>
  39. #include <rdma/ib_mad.h>
  40. #include <rdma/ib_pma.h>
  41. struct ib_port;
  42. struct gid_attr_group {
  43. struct ib_port *port;
  44. struct kobject kobj;
  45. struct attribute_group ndev;
  46. struct attribute_group type;
  47. };
  48. struct ib_port {
  49. struct kobject kobj;
  50. struct ib_device *ibdev;
  51. struct gid_attr_group *gid_attr_group;
  52. struct attribute_group gid_group;
  53. struct attribute_group pkey_group;
  54. u8 port_num;
  55. struct attribute_group *pma_table;
  56. };
  57. struct port_attribute {
  58. struct attribute attr;
  59. ssize_t (*show)(struct ib_port *, struct port_attribute *, char *buf);
  60. ssize_t (*store)(struct ib_port *, struct port_attribute *,
  61. const char *buf, size_t count);
  62. };
  63. #define PORT_ATTR(_name, _mode, _show, _store) \
  64. struct port_attribute port_attr_##_name = __ATTR(_name, _mode, _show, _store)
  65. #define PORT_ATTR_RO(_name) \
  66. struct port_attribute port_attr_##_name = __ATTR_RO(_name)
  67. struct port_table_attribute {
  68. struct port_attribute attr;
  69. char name[8];
  70. int index;
  71. __be16 attr_id;
  72. };
  73. static ssize_t port_attr_show(struct kobject *kobj,
  74. struct attribute *attr, char *buf)
  75. {
  76. struct port_attribute *port_attr =
  77. container_of(attr, struct port_attribute, attr);
  78. struct ib_port *p = container_of(kobj, struct ib_port, kobj);
  79. if (!port_attr->show)
  80. return -EIO;
  81. return port_attr->show(p, port_attr, buf);
  82. }
  83. static const struct sysfs_ops port_sysfs_ops = {
  84. .show = port_attr_show
  85. };
  86. static ssize_t gid_attr_show(struct kobject *kobj,
  87. struct attribute *attr, char *buf)
  88. {
  89. struct port_attribute *port_attr =
  90. container_of(attr, struct port_attribute, attr);
  91. struct ib_port *p = container_of(kobj, struct gid_attr_group,
  92. kobj)->port;
  93. if (!port_attr->show)
  94. return -EIO;
  95. return port_attr->show(p, port_attr, buf);
  96. }
  97. static const struct sysfs_ops gid_attr_sysfs_ops = {
  98. .show = gid_attr_show
  99. };
  100. static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
  101. char *buf)
  102. {
  103. struct ib_port_attr attr;
  104. ssize_t ret;
  105. static const char *state_name[] = {
  106. [IB_PORT_NOP] = "NOP",
  107. [IB_PORT_DOWN] = "DOWN",
  108. [IB_PORT_INIT] = "INIT",
  109. [IB_PORT_ARMED] = "ARMED",
  110. [IB_PORT_ACTIVE] = "ACTIVE",
  111. [IB_PORT_ACTIVE_DEFER] = "ACTIVE_DEFER"
  112. };
  113. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  114. if (ret)
  115. return ret;
  116. return sprintf(buf, "%d: %s\n", attr.state,
  117. attr.state >= 0 && attr.state < ARRAY_SIZE(state_name) ?
  118. state_name[attr.state] : "UNKNOWN");
  119. }
  120. static ssize_t lid_show(struct ib_port *p, struct port_attribute *unused,
  121. char *buf)
  122. {
  123. struct ib_port_attr attr;
  124. ssize_t ret;
  125. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  126. if (ret)
  127. return ret;
  128. return sprintf(buf, "0x%x\n", attr.lid);
  129. }
  130. static ssize_t lid_mask_count_show(struct ib_port *p,
  131. struct port_attribute *unused,
  132. char *buf)
  133. {
  134. struct ib_port_attr attr;
  135. ssize_t ret;
  136. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  137. if (ret)
  138. return ret;
  139. return sprintf(buf, "%d\n", attr.lmc);
  140. }
  141. static ssize_t sm_lid_show(struct ib_port *p, struct port_attribute *unused,
  142. char *buf)
  143. {
  144. struct ib_port_attr attr;
  145. ssize_t ret;
  146. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  147. if (ret)
  148. return ret;
  149. return sprintf(buf, "0x%x\n", attr.sm_lid);
  150. }
  151. static ssize_t sm_sl_show(struct ib_port *p, struct port_attribute *unused,
  152. char *buf)
  153. {
  154. struct ib_port_attr attr;
  155. ssize_t ret;
  156. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  157. if (ret)
  158. return ret;
  159. return sprintf(buf, "%d\n", attr.sm_sl);
  160. }
  161. static ssize_t cap_mask_show(struct ib_port *p, struct port_attribute *unused,
  162. char *buf)
  163. {
  164. struct ib_port_attr attr;
  165. ssize_t ret;
  166. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  167. if (ret)
  168. return ret;
  169. return sprintf(buf, "0x%08x\n", attr.port_cap_flags);
  170. }
  171. static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
  172. char *buf)
  173. {
  174. struct ib_port_attr attr;
  175. char *speed = "";
  176. int rate; /* in deci-Gb/sec */
  177. ssize_t ret;
  178. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  179. if (ret)
  180. return ret;
  181. switch (attr.active_speed) {
  182. case IB_SPEED_DDR:
  183. speed = " DDR";
  184. rate = 50;
  185. break;
  186. case IB_SPEED_QDR:
  187. speed = " QDR";
  188. rate = 100;
  189. break;
  190. case IB_SPEED_FDR10:
  191. speed = " FDR10";
  192. rate = 100;
  193. break;
  194. case IB_SPEED_FDR:
  195. speed = " FDR";
  196. rate = 140;
  197. break;
  198. case IB_SPEED_EDR:
  199. speed = " EDR";
  200. rate = 250;
  201. break;
  202. case IB_SPEED_SDR:
  203. default: /* default to SDR for invalid rates */
  204. rate = 25;
  205. break;
  206. }
  207. rate *= ib_width_enum_to_int(attr.active_width);
  208. if (rate < 0)
  209. return -EINVAL;
  210. return sprintf(buf, "%d%s Gb/sec (%dX%s)\n",
  211. rate / 10, rate % 10 ? ".5" : "",
  212. ib_width_enum_to_int(attr.active_width), speed);
  213. }
  214. static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
  215. char *buf)
  216. {
  217. struct ib_port_attr attr;
  218. ssize_t ret;
  219. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  220. if (ret)
  221. return ret;
  222. switch (attr.phys_state) {
  223. case 1: return sprintf(buf, "1: Sleep\n");
  224. case 2: return sprintf(buf, "2: Polling\n");
  225. case 3: return sprintf(buf, "3: Disabled\n");
  226. case 4: return sprintf(buf, "4: PortConfigurationTraining\n");
  227. case 5: return sprintf(buf, "5: LinkUp\n");
  228. case 6: return sprintf(buf, "6: LinkErrorRecovery\n");
  229. case 7: return sprintf(buf, "7: Phy Test\n");
  230. default: return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
  231. }
  232. }
  233. static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
  234. char *buf)
  235. {
  236. switch (rdma_port_get_link_layer(p->ibdev, p->port_num)) {
  237. case IB_LINK_LAYER_INFINIBAND:
  238. return sprintf(buf, "%s\n", "InfiniBand");
  239. case IB_LINK_LAYER_ETHERNET:
  240. return sprintf(buf, "%s\n", "Ethernet");
  241. default:
  242. return sprintf(buf, "%s\n", "Unknown");
  243. }
  244. }
  245. static PORT_ATTR_RO(state);
  246. static PORT_ATTR_RO(lid);
  247. static PORT_ATTR_RO(lid_mask_count);
  248. static PORT_ATTR_RO(sm_lid);
  249. static PORT_ATTR_RO(sm_sl);
  250. static PORT_ATTR_RO(cap_mask);
  251. static PORT_ATTR_RO(rate);
  252. static PORT_ATTR_RO(phys_state);
  253. static PORT_ATTR_RO(link_layer);
  254. static struct attribute *port_default_attrs[] = {
  255. &port_attr_state.attr,
  256. &port_attr_lid.attr,
  257. &port_attr_lid_mask_count.attr,
  258. &port_attr_sm_lid.attr,
  259. &port_attr_sm_sl.attr,
  260. &port_attr_cap_mask.attr,
  261. &port_attr_rate.attr,
  262. &port_attr_phys_state.attr,
  263. &port_attr_link_layer.attr,
  264. NULL
  265. };
  266. static size_t print_ndev(struct ib_gid_attr *gid_attr, char *buf)
  267. {
  268. if (!gid_attr->ndev)
  269. return -EINVAL;
  270. return sprintf(buf, "%s\n", gid_attr->ndev->name);
  271. }
  272. static size_t print_gid_type(struct ib_gid_attr *gid_attr, char *buf)
  273. {
  274. return sprintf(buf, "%s\n", ib_cache_gid_type_str(gid_attr->gid_type));
  275. }
  276. static ssize_t _show_port_gid_attr(struct ib_port *p,
  277. struct port_attribute *attr,
  278. char *buf,
  279. size_t (*print)(struct ib_gid_attr *gid_attr,
  280. char *buf))
  281. {
  282. struct port_table_attribute *tab_attr =
  283. container_of(attr, struct port_table_attribute, attr);
  284. union ib_gid gid;
  285. struct ib_gid_attr gid_attr = {};
  286. ssize_t ret;
  287. ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid,
  288. &gid_attr);
  289. if (ret)
  290. goto err;
  291. ret = print(&gid_attr, buf);
  292. err:
  293. if (gid_attr.ndev)
  294. dev_put(gid_attr.ndev);
  295. return ret;
  296. }
  297. static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
  298. char *buf)
  299. {
  300. struct port_table_attribute *tab_attr =
  301. container_of(attr, struct port_table_attribute, attr);
  302. union ib_gid gid;
  303. ssize_t ret;
  304. ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid, NULL);
  305. if (ret)
  306. return ret;
  307. return sprintf(buf, "%pI6\n", gid.raw);
  308. }
  309. static ssize_t show_port_gid_attr_ndev(struct ib_port *p,
  310. struct port_attribute *attr, char *buf)
  311. {
  312. return _show_port_gid_attr(p, attr, buf, print_ndev);
  313. }
  314. static ssize_t show_port_gid_attr_gid_type(struct ib_port *p,
  315. struct port_attribute *attr,
  316. char *buf)
  317. {
  318. return _show_port_gid_attr(p, attr, buf, print_gid_type);
  319. }
  320. static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,
  321. char *buf)
  322. {
  323. struct port_table_attribute *tab_attr =
  324. container_of(attr, struct port_table_attribute, attr);
  325. u16 pkey;
  326. ssize_t ret;
  327. ret = ib_query_pkey(p->ibdev, p->port_num, tab_attr->index, &pkey);
  328. if (ret)
  329. return ret;
  330. return sprintf(buf, "0x%04x\n", pkey);
  331. }
  332. #define PORT_PMA_ATTR(_name, _counter, _width, _offset) \
  333. struct port_table_attribute port_pma_attr_##_name = { \
  334. .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
  335. .index = (_offset) | ((_width) << 16) | ((_counter) << 24), \
  336. .attr_id = IB_PMA_PORT_COUNTERS , \
  337. }
  338. #define PORT_PMA_ATTR_EXT(_name, _width, _offset) \
  339. struct port_table_attribute port_pma_attr_ext_##_name = { \
  340. .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
  341. .index = (_offset) | ((_width) << 16), \
  342. .attr_id = IB_PMA_PORT_COUNTERS_EXT , \
  343. }
  344. /*
  345. * Get a Perfmgmt MAD block of data.
  346. * Returns error code or the number of bytes retrieved.
  347. */
  348. static int get_perf_mad(struct ib_device *dev, int port_num, __be16 attr,
  349. void *data, int offset, size_t size)
  350. {
  351. struct ib_mad *in_mad;
  352. struct ib_mad *out_mad;
  353. size_t mad_size = sizeof(*out_mad);
  354. u16 out_mad_pkey_index = 0;
  355. ssize_t ret;
  356. if (!dev->process_mad)
  357. return -ENOSYS;
  358. in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
  359. out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
  360. if (!in_mad || !out_mad) {
  361. ret = -ENOMEM;
  362. goto out;
  363. }
  364. in_mad->mad_hdr.base_version = 1;
  365. in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT;
  366. in_mad->mad_hdr.class_version = 1;
  367. in_mad->mad_hdr.method = IB_MGMT_METHOD_GET;
  368. in_mad->mad_hdr.attr_id = attr;
  369. if (attr != IB_PMA_CLASS_PORT_INFO)
  370. in_mad->data[41] = port_num; /* PortSelect field */
  371. if ((dev->process_mad(dev, IB_MAD_IGNORE_MKEY,
  372. port_num, NULL, NULL,
  373. (const struct ib_mad_hdr *)in_mad, mad_size,
  374. (struct ib_mad_hdr *)out_mad, &mad_size,
  375. &out_mad_pkey_index) &
  376. (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) !=
  377. (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) {
  378. ret = -EINVAL;
  379. goto out;
  380. }
  381. memcpy(data, out_mad->data + offset, size);
  382. ret = size;
  383. out:
  384. kfree(in_mad);
  385. kfree(out_mad);
  386. return ret;
  387. }
  388. static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
  389. char *buf)
  390. {
  391. struct port_table_attribute *tab_attr =
  392. container_of(attr, struct port_table_attribute, attr);
  393. int offset = tab_attr->index & 0xffff;
  394. int width = (tab_attr->index >> 16) & 0xff;
  395. ssize_t ret;
  396. u8 data[8];
  397. ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, &data,
  398. 40 + offset / 8, sizeof(data));
  399. if (ret < 0)
  400. return sprintf(buf, "N/A (no PMA)\n");
  401. switch (width) {
  402. case 4:
  403. ret = sprintf(buf, "%u\n", (*data >>
  404. (4 - (offset % 8))) & 0xf);
  405. break;
  406. case 8:
  407. ret = sprintf(buf, "%u\n", *data);
  408. break;
  409. case 16:
  410. ret = sprintf(buf, "%u\n",
  411. be16_to_cpup((__be16 *)data));
  412. break;
  413. case 32:
  414. ret = sprintf(buf, "%u\n",
  415. be32_to_cpup((__be32 *)data));
  416. break;
  417. case 64:
  418. ret = sprintf(buf, "%llu\n",
  419. be64_to_cpup((__be64 *)data));
  420. break;
  421. default:
  422. ret = 0;
  423. }
  424. return ret;
  425. }
  426. static PORT_PMA_ATTR(symbol_error , 0, 16, 32);
  427. static PORT_PMA_ATTR(link_error_recovery , 1, 8, 48);
  428. static PORT_PMA_ATTR(link_downed , 2, 8, 56);
  429. static PORT_PMA_ATTR(port_rcv_errors , 3, 16, 64);
  430. static PORT_PMA_ATTR(port_rcv_remote_physical_errors, 4, 16, 80);
  431. static PORT_PMA_ATTR(port_rcv_switch_relay_errors , 5, 16, 96);
  432. static PORT_PMA_ATTR(port_xmit_discards , 6, 16, 112);
  433. static PORT_PMA_ATTR(port_xmit_constraint_errors , 7, 8, 128);
  434. static PORT_PMA_ATTR(port_rcv_constraint_errors , 8, 8, 136);
  435. static PORT_PMA_ATTR(local_link_integrity_errors , 9, 4, 152);
  436. static PORT_PMA_ATTR(excessive_buffer_overrun_errors, 10, 4, 156);
  437. static PORT_PMA_ATTR(VL15_dropped , 11, 16, 176);
  438. static PORT_PMA_ATTR(port_xmit_data , 12, 32, 192);
  439. static PORT_PMA_ATTR(port_rcv_data , 13, 32, 224);
  440. static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256);
  441. static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288);
  442. /*
  443. * Counters added by extended set
  444. */
  445. static PORT_PMA_ATTR_EXT(port_xmit_data , 64, 64);
  446. static PORT_PMA_ATTR_EXT(port_rcv_data , 64, 128);
  447. static PORT_PMA_ATTR_EXT(port_xmit_packets , 64, 192);
  448. static PORT_PMA_ATTR_EXT(port_rcv_packets , 64, 256);
  449. static PORT_PMA_ATTR_EXT(unicast_xmit_packets , 64, 320);
  450. static PORT_PMA_ATTR_EXT(unicast_rcv_packets , 64, 384);
  451. static PORT_PMA_ATTR_EXT(multicast_xmit_packets , 64, 448);
  452. static PORT_PMA_ATTR_EXT(multicast_rcv_packets , 64, 512);
  453. static struct attribute *pma_attrs[] = {
  454. &port_pma_attr_symbol_error.attr.attr,
  455. &port_pma_attr_link_error_recovery.attr.attr,
  456. &port_pma_attr_link_downed.attr.attr,
  457. &port_pma_attr_port_rcv_errors.attr.attr,
  458. &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
  459. &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
  460. &port_pma_attr_port_xmit_discards.attr.attr,
  461. &port_pma_attr_port_xmit_constraint_errors.attr.attr,
  462. &port_pma_attr_port_rcv_constraint_errors.attr.attr,
  463. &port_pma_attr_local_link_integrity_errors.attr.attr,
  464. &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
  465. &port_pma_attr_VL15_dropped.attr.attr,
  466. &port_pma_attr_port_xmit_data.attr.attr,
  467. &port_pma_attr_port_rcv_data.attr.attr,
  468. &port_pma_attr_port_xmit_packets.attr.attr,
  469. &port_pma_attr_port_rcv_packets.attr.attr,
  470. NULL
  471. };
  472. static struct attribute *pma_attrs_ext[] = {
  473. &port_pma_attr_symbol_error.attr.attr,
  474. &port_pma_attr_link_error_recovery.attr.attr,
  475. &port_pma_attr_link_downed.attr.attr,
  476. &port_pma_attr_port_rcv_errors.attr.attr,
  477. &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
  478. &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
  479. &port_pma_attr_port_xmit_discards.attr.attr,
  480. &port_pma_attr_port_xmit_constraint_errors.attr.attr,
  481. &port_pma_attr_port_rcv_constraint_errors.attr.attr,
  482. &port_pma_attr_local_link_integrity_errors.attr.attr,
  483. &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
  484. &port_pma_attr_VL15_dropped.attr.attr,
  485. &port_pma_attr_ext_port_xmit_data.attr.attr,
  486. &port_pma_attr_ext_port_rcv_data.attr.attr,
  487. &port_pma_attr_ext_port_xmit_packets.attr.attr,
  488. &port_pma_attr_ext_port_rcv_packets.attr.attr,
  489. &port_pma_attr_ext_unicast_rcv_packets.attr.attr,
  490. &port_pma_attr_ext_unicast_xmit_packets.attr.attr,
  491. &port_pma_attr_ext_multicast_rcv_packets.attr.attr,
  492. &port_pma_attr_ext_multicast_xmit_packets.attr.attr,
  493. NULL
  494. };
  495. static struct attribute *pma_attrs_noietf[] = {
  496. &port_pma_attr_symbol_error.attr.attr,
  497. &port_pma_attr_link_error_recovery.attr.attr,
  498. &port_pma_attr_link_downed.attr.attr,
  499. &port_pma_attr_port_rcv_errors.attr.attr,
  500. &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
  501. &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
  502. &port_pma_attr_port_xmit_discards.attr.attr,
  503. &port_pma_attr_port_xmit_constraint_errors.attr.attr,
  504. &port_pma_attr_port_rcv_constraint_errors.attr.attr,
  505. &port_pma_attr_local_link_integrity_errors.attr.attr,
  506. &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
  507. &port_pma_attr_VL15_dropped.attr.attr,
  508. &port_pma_attr_ext_port_xmit_data.attr.attr,
  509. &port_pma_attr_ext_port_rcv_data.attr.attr,
  510. &port_pma_attr_ext_port_xmit_packets.attr.attr,
  511. &port_pma_attr_ext_port_rcv_packets.attr.attr,
  512. NULL
  513. };
  514. static struct attribute_group pma_group = {
  515. .name = "counters",
  516. .attrs = pma_attrs
  517. };
  518. static struct attribute_group pma_group_ext = {
  519. .name = "counters",
  520. .attrs = pma_attrs_ext
  521. };
  522. static struct attribute_group pma_group_noietf = {
  523. .name = "counters",
  524. .attrs = pma_attrs_noietf
  525. };
  526. static void ib_port_release(struct kobject *kobj)
  527. {
  528. struct ib_port *p = container_of(kobj, struct ib_port, kobj);
  529. struct attribute *a;
  530. int i;
  531. if (p->gid_group.attrs) {
  532. for (i = 0; (a = p->gid_group.attrs[i]); ++i)
  533. kfree(a);
  534. kfree(p->gid_group.attrs);
  535. }
  536. if (p->pkey_group.attrs) {
  537. for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
  538. kfree(a);
  539. kfree(p->pkey_group.attrs);
  540. }
  541. kfree(p);
  542. }
  543. static void ib_port_gid_attr_release(struct kobject *kobj)
  544. {
  545. struct gid_attr_group *g = container_of(kobj, struct gid_attr_group,
  546. kobj);
  547. struct attribute *a;
  548. int i;
  549. if (g->ndev.attrs) {
  550. for (i = 0; (a = g->ndev.attrs[i]); ++i)
  551. kfree(a);
  552. kfree(g->ndev.attrs);
  553. }
  554. if (g->type.attrs) {
  555. for (i = 0; (a = g->type.attrs[i]); ++i)
  556. kfree(a);
  557. kfree(g->type.attrs);
  558. }
  559. kfree(g);
  560. }
  561. static struct kobj_type port_type = {
  562. .release = ib_port_release,
  563. .sysfs_ops = &port_sysfs_ops,
  564. .default_attrs = port_default_attrs
  565. };
  566. static struct kobj_type gid_attr_type = {
  567. .sysfs_ops = &gid_attr_sysfs_ops,
  568. .release = ib_port_gid_attr_release
  569. };
  570. static struct attribute **
  571. alloc_group_attrs(ssize_t (*show)(struct ib_port *,
  572. struct port_attribute *, char *buf),
  573. int len)
  574. {
  575. struct attribute **tab_attr;
  576. struct port_table_attribute *element;
  577. int i;
  578. tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
  579. if (!tab_attr)
  580. return NULL;
  581. for (i = 0; i < len; i++) {
  582. element = kzalloc(sizeof(struct port_table_attribute),
  583. GFP_KERNEL);
  584. if (!element)
  585. goto err;
  586. if (snprintf(element->name, sizeof(element->name),
  587. "%d", i) >= sizeof(element->name)) {
  588. kfree(element);
  589. goto err;
  590. }
  591. element->attr.attr.name = element->name;
  592. element->attr.attr.mode = S_IRUGO;
  593. element->attr.show = show;
  594. element->index = i;
  595. sysfs_attr_init(&element->attr.attr);
  596. tab_attr[i] = &element->attr.attr;
  597. }
  598. return tab_attr;
  599. err:
  600. while (--i >= 0)
  601. kfree(tab_attr[i]);
  602. kfree(tab_attr);
  603. return NULL;
  604. }
  605. /*
  606. * Figure out which counter table to use depending on
  607. * the device capabilities.
  608. */
  609. static struct attribute_group *get_counter_table(struct ib_device *dev,
  610. int port_num)
  611. {
  612. struct ib_class_port_info cpi;
  613. if (get_perf_mad(dev, port_num, IB_PMA_CLASS_PORT_INFO,
  614. &cpi, 40, sizeof(cpi)) >= 0) {
  615. if (cpi.capability_mask & IB_PMA_CLASS_CAP_EXT_WIDTH)
  616. /* We have extended counters */
  617. return &pma_group_ext;
  618. if (cpi.capability_mask & IB_PMA_CLASS_CAP_EXT_WIDTH_NOIETF)
  619. /* But not the IETF ones */
  620. return &pma_group_noietf;
  621. }
  622. /* Fall back to normal counters */
  623. return &pma_group;
  624. }
  625. static int add_port(struct ib_device *device, int port_num,
  626. int (*port_callback)(struct ib_device *,
  627. u8, struct kobject *))
  628. {
  629. struct ib_port *p;
  630. struct ib_port_attr attr;
  631. int i;
  632. int ret;
  633. ret = ib_query_port(device, port_num, &attr);
  634. if (ret)
  635. return ret;
  636. p = kzalloc(sizeof *p, GFP_KERNEL);
  637. if (!p)
  638. return -ENOMEM;
  639. p->ibdev = device;
  640. p->port_num = port_num;
  641. ret = kobject_init_and_add(&p->kobj, &port_type,
  642. device->ports_parent,
  643. "%d", port_num);
  644. if (ret) {
  645. kfree(p);
  646. return ret;
  647. }
  648. p->gid_attr_group = kzalloc(sizeof(*p->gid_attr_group), GFP_KERNEL);
  649. if (!p->gid_attr_group) {
  650. ret = -ENOMEM;
  651. goto err_put;
  652. }
  653. p->gid_attr_group->port = p;
  654. ret = kobject_init_and_add(&p->gid_attr_group->kobj, &gid_attr_type,
  655. &p->kobj, "gid_attrs");
  656. if (ret) {
  657. kfree(p->gid_attr_group);
  658. goto err_put;
  659. }
  660. p->pma_table = get_counter_table(device, port_num);
  661. ret = sysfs_create_group(&p->kobj, p->pma_table);
  662. if (ret)
  663. goto err_put_gid_attrs;
  664. p->gid_group.name = "gids";
  665. p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
  666. if (!p->gid_group.attrs) {
  667. ret = -ENOMEM;
  668. goto err_remove_pma;
  669. }
  670. ret = sysfs_create_group(&p->kobj, &p->gid_group);
  671. if (ret)
  672. goto err_free_gid;
  673. p->gid_attr_group->ndev.name = "ndevs";
  674. p->gid_attr_group->ndev.attrs = alloc_group_attrs(show_port_gid_attr_ndev,
  675. attr.gid_tbl_len);
  676. if (!p->gid_attr_group->ndev.attrs) {
  677. ret = -ENOMEM;
  678. goto err_remove_gid;
  679. }
  680. ret = sysfs_create_group(&p->gid_attr_group->kobj,
  681. &p->gid_attr_group->ndev);
  682. if (ret)
  683. goto err_free_gid_ndev;
  684. p->gid_attr_group->type.name = "types";
  685. p->gid_attr_group->type.attrs = alloc_group_attrs(show_port_gid_attr_gid_type,
  686. attr.gid_tbl_len);
  687. if (!p->gid_attr_group->type.attrs) {
  688. ret = -ENOMEM;
  689. goto err_remove_gid_ndev;
  690. }
  691. ret = sysfs_create_group(&p->gid_attr_group->kobj,
  692. &p->gid_attr_group->type);
  693. if (ret)
  694. goto err_free_gid_type;
  695. p->pkey_group.name = "pkeys";
  696. p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
  697. attr.pkey_tbl_len);
  698. if (!p->pkey_group.attrs) {
  699. ret = -ENOMEM;
  700. goto err_remove_gid_type;
  701. }
  702. ret = sysfs_create_group(&p->kobj, &p->pkey_group);
  703. if (ret)
  704. goto err_free_pkey;
  705. if (port_callback) {
  706. ret = port_callback(device, port_num, &p->kobj);
  707. if (ret)
  708. goto err_remove_pkey;
  709. }
  710. list_add_tail(&p->kobj.entry, &device->port_list);
  711. kobject_uevent(&p->kobj, KOBJ_ADD);
  712. return 0;
  713. err_remove_pkey:
  714. sysfs_remove_group(&p->kobj, &p->pkey_group);
  715. err_free_pkey:
  716. for (i = 0; i < attr.pkey_tbl_len; ++i)
  717. kfree(p->pkey_group.attrs[i]);
  718. kfree(p->pkey_group.attrs);
  719. p->pkey_group.attrs = NULL;
  720. err_remove_gid_type:
  721. sysfs_remove_group(&p->gid_attr_group->kobj,
  722. &p->gid_attr_group->type);
  723. err_free_gid_type:
  724. for (i = 0; i < attr.gid_tbl_len; ++i)
  725. kfree(p->gid_attr_group->type.attrs[i]);
  726. kfree(p->gid_attr_group->type.attrs);
  727. p->gid_attr_group->type.attrs = NULL;
  728. err_remove_gid_ndev:
  729. sysfs_remove_group(&p->gid_attr_group->kobj,
  730. &p->gid_attr_group->ndev);
  731. err_free_gid_ndev:
  732. for (i = 0; i < attr.gid_tbl_len; ++i)
  733. kfree(p->gid_attr_group->ndev.attrs[i]);
  734. kfree(p->gid_attr_group->ndev.attrs);
  735. p->gid_attr_group->ndev.attrs = NULL;
  736. err_remove_gid:
  737. sysfs_remove_group(&p->kobj, &p->gid_group);
  738. err_free_gid:
  739. for (i = 0; i < attr.gid_tbl_len; ++i)
  740. kfree(p->gid_group.attrs[i]);
  741. kfree(p->gid_group.attrs);
  742. p->gid_group.attrs = NULL;
  743. err_remove_pma:
  744. sysfs_remove_group(&p->kobj, p->pma_table);
  745. err_put_gid_attrs:
  746. kobject_put(&p->gid_attr_group->kobj);
  747. err_put:
  748. kobject_put(&p->kobj);
  749. return ret;
  750. }
  751. static ssize_t show_node_type(struct device *device,
  752. struct device_attribute *attr, char *buf)
  753. {
  754. struct ib_device *dev = container_of(device, struct ib_device, dev);
  755. switch (dev->node_type) {
  756. case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
  757. case RDMA_NODE_RNIC: return sprintf(buf, "%d: RNIC\n", dev->node_type);
  758. case RDMA_NODE_USNIC: return sprintf(buf, "%d: usNIC\n", dev->node_type);
  759. case RDMA_NODE_USNIC_UDP: return sprintf(buf, "%d: usNIC UDP\n", dev->node_type);
  760. case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
  761. case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
  762. default: return sprintf(buf, "%d: <unknown>\n", dev->node_type);
  763. }
  764. }
  765. static ssize_t show_sys_image_guid(struct device *device,
  766. struct device_attribute *dev_attr, char *buf)
  767. {
  768. struct ib_device *dev = container_of(device, struct ib_device, dev);
  769. return sprintf(buf, "%04x:%04x:%04x:%04x\n",
  770. be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[0]),
  771. be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[1]),
  772. be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[2]),
  773. be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[3]));
  774. }
  775. static ssize_t show_node_guid(struct device *device,
  776. struct device_attribute *attr, char *buf)
  777. {
  778. struct ib_device *dev = container_of(device, struct ib_device, dev);
  779. return sprintf(buf, "%04x:%04x:%04x:%04x\n",
  780. be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
  781. be16_to_cpu(((__be16 *) &dev->node_guid)[1]),
  782. be16_to_cpu(((__be16 *) &dev->node_guid)[2]),
  783. be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
  784. }
  785. static ssize_t show_node_desc(struct device *device,
  786. struct device_attribute *attr, char *buf)
  787. {
  788. struct ib_device *dev = container_of(device, struct ib_device, dev);
  789. return sprintf(buf, "%.64s\n", dev->node_desc);
  790. }
  791. static ssize_t set_node_desc(struct device *device,
  792. struct device_attribute *attr,
  793. const char *buf, size_t count)
  794. {
  795. struct ib_device *dev = container_of(device, struct ib_device, dev);
  796. struct ib_device_modify desc = {};
  797. int ret;
  798. if (!dev->modify_device)
  799. return -EIO;
  800. memcpy(desc.node_desc, buf, min_t(int, count, 64));
  801. ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
  802. if (ret)
  803. return ret;
  804. return count;
  805. }
  806. static DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
  807. static DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
  808. static DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
  809. static DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc, set_node_desc);
  810. static struct device_attribute *ib_class_attributes[] = {
  811. &dev_attr_node_type,
  812. &dev_attr_sys_image_guid,
  813. &dev_attr_node_guid,
  814. &dev_attr_node_desc
  815. };
  816. /* Show a given an attribute in the statistics group */
  817. static ssize_t show_protocol_stat(const struct device *device,
  818. struct device_attribute *attr, char *buf,
  819. unsigned offset)
  820. {
  821. struct ib_device *dev = container_of(device, struct ib_device, dev);
  822. union rdma_protocol_stats stats;
  823. ssize_t ret;
  824. ret = dev->get_protocol_stats(dev, &stats);
  825. if (ret)
  826. return ret;
  827. return sprintf(buf, "%llu\n",
  828. (unsigned long long) ((u64 *) &stats)[offset]);
  829. }
  830. /* generate a read-only iwarp statistics attribute */
  831. #define IW_STATS_ENTRY(name) \
  832. static ssize_t show_##name(struct device *device, \
  833. struct device_attribute *attr, char *buf) \
  834. { \
  835. return show_protocol_stat(device, attr, buf, \
  836. offsetof(struct iw_protocol_stats, name) / \
  837. sizeof (u64)); \
  838. } \
  839. static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
  840. IW_STATS_ENTRY(ipInReceives);
  841. IW_STATS_ENTRY(ipInHdrErrors);
  842. IW_STATS_ENTRY(ipInTooBigErrors);
  843. IW_STATS_ENTRY(ipInNoRoutes);
  844. IW_STATS_ENTRY(ipInAddrErrors);
  845. IW_STATS_ENTRY(ipInUnknownProtos);
  846. IW_STATS_ENTRY(ipInTruncatedPkts);
  847. IW_STATS_ENTRY(ipInDiscards);
  848. IW_STATS_ENTRY(ipInDelivers);
  849. IW_STATS_ENTRY(ipOutForwDatagrams);
  850. IW_STATS_ENTRY(ipOutRequests);
  851. IW_STATS_ENTRY(ipOutDiscards);
  852. IW_STATS_ENTRY(ipOutNoRoutes);
  853. IW_STATS_ENTRY(ipReasmTimeout);
  854. IW_STATS_ENTRY(ipReasmReqds);
  855. IW_STATS_ENTRY(ipReasmOKs);
  856. IW_STATS_ENTRY(ipReasmFails);
  857. IW_STATS_ENTRY(ipFragOKs);
  858. IW_STATS_ENTRY(ipFragFails);
  859. IW_STATS_ENTRY(ipFragCreates);
  860. IW_STATS_ENTRY(ipInMcastPkts);
  861. IW_STATS_ENTRY(ipOutMcastPkts);
  862. IW_STATS_ENTRY(ipInBcastPkts);
  863. IW_STATS_ENTRY(ipOutBcastPkts);
  864. IW_STATS_ENTRY(tcpRtoAlgorithm);
  865. IW_STATS_ENTRY(tcpRtoMin);
  866. IW_STATS_ENTRY(tcpRtoMax);
  867. IW_STATS_ENTRY(tcpMaxConn);
  868. IW_STATS_ENTRY(tcpActiveOpens);
  869. IW_STATS_ENTRY(tcpPassiveOpens);
  870. IW_STATS_ENTRY(tcpAttemptFails);
  871. IW_STATS_ENTRY(tcpEstabResets);
  872. IW_STATS_ENTRY(tcpCurrEstab);
  873. IW_STATS_ENTRY(tcpInSegs);
  874. IW_STATS_ENTRY(tcpOutSegs);
  875. IW_STATS_ENTRY(tcpRetransSegs);
  876. IW_STATS_ENTRY(tcpInErrs);
  877. IW_STATS_ENTRY(tcpOutRsts);
  878. static struct attribute *iw_proto_stats_attrs[] = {
  879. &dev_attr_ipInReceives.attr,
  880. &dev_attr_ipInHdrErrors.attr,
  881. &dev_attr_ipInTooBigErrors.attr,
  882. &dev_attr_ipInNoRoutes.attr,
  883. &dev_attr_ipInAddrErrors.attr,
  884. &dev_attr_ipInUnknownProtos.attr,
  885. &dev_attr_ipInTruncatedPkts.attr,
  886. &dev_attr_ipInDiscards.attr,
  887. &dev_attr_ipInDelivers.attr,
  888. &dev_attr_ipOutForwDatagrams.attr,
  889. &dev_attr_ipOutRequests.attr,
  890. &dev_attr_ipOutDiscards.attr,
  891. &dev_attr_ipOutNoRoutes.attr,
  892. &dev_attr_ipReasmTimeout.attr,
  893. &dev_attr_ipReasmReqds.attr,
  894. &dev_attr_ipReasmOKs.attr,
  895. &dev_attr_ipReasmFails.attr,
  896. &dev_attr_ipFragOKs.attr,
  897. &dev_attr_ipFragFails.attr,
  898. &dev_attr_ipFragCreates.attr,
  899. &dev_attr_ipInMcastPkts.attr,
  900. &dev_attr_ipOutMcastPkts.attr,
  901. &dev_attr_ipInBcastPkts.attr,
  902. &dev_attr_ipOutBcastPkts.attr,
  903. &dev_attr_tcpRtoAlgorithm.attr,
  904. &dev_attr_tcpRtoMin.attr,
  905. &dev_attr_tcpRtoMax.attr,
  906. &dev_attr_tcpMaxConn.attr,
  907. &dev_attr_tcpActiveOpens.attr,
  908. &dev_attr_tcpPassiveOpens.attr,
  909. &dev_attr_tcpAttemptFails.attr,
  910. &dev_attr_tcpEstabResets.attr,
  911. &dev_attr_tcpCurrEstab.attr,
  912. &dev_attr_tcpInSegs.attr,
  913. &dev_attr_tcpOutSegs.attr,
  914. &dev_attr_tcpRetransSegs.attr,
  915. &dev_attr_tcpInErrs.attr,
  916. &dev_attr_tcpOutRsts.attr,
  917. NULL
  918. };
  919. static struct attribute_group iw_stats_group = {
  920. .name = "proto_stats",
  921. .attrs = iw_proto_stats_attrs,
  922. };
  923. static void free_port_list_attributes(struct ib_device *device)
  924. {
  925. struct kobject *p, *t;
  926. list_for_each_entry_safe(p, t, &device->port_list, entry) {
  927. struct ib_port *port = container_of(p, struct ib_port, kobj);
  928. list_del(&p->entry);
  929. sysfs_remove_group(p, port->pma_table);
  930. sysfs_remove_group(p, &port->pkey_group);
  931. sysfs_remove_group(p, &port->gid_group);
  932. sysfs_remove_group(&port->gid_attr_group->kobj,
  933. &port->gid_attr_group->ndev);
  934. sysfs_remove_group(&port->gid_attr_group->kobj,
  935. &port->gid_attr_group->type);
  936. kobject_put(&port->gid_attr_group->kobj);
  937. kobject_put(p);
  938. }
  939. kobject_put(device->ports_parent);
  940. }
  941. int ib_device_register_sysfs(struct ib_device *device,
  942. int (*port_callback)(struct ib_device *,
  943. u8, struct kobject *))
  944. {
  945. struct device *class_dev = &device->dev;
  946. int ret;
  947. int i;
  948. device->dev.parent = device->dma_device;
  949. ret = dev_set_name(class_dev, "%s", device->name);
  950. if (ret)
  951. return ret;
  952. ret = device_add(class_dev);
  953. if (ret)
  954. goto err;
  955. for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
  956. ret = device_create_file(class_dev, ib_class_attributes[i]);
  957. if (ret)
  958. goto err_unregister;
  959. }
  960. device->ports_parent = kobject_create_and_add("ports",
  961. &class_dev->kobj);
  962. if (!device->ports_parent) {
  963. ret = -ENOMEM;
  964. goto err_put;
  965. }
  966. if (rdma_cap_ib_switch(device)) {
  967. ret = add_port(device, 0, port_callback);
  968. if (ret)
  969. goto err_put;
  970. } else {
  971. for (i = 1; i <= device->phys_port_cnt; ++i) {
  972. ret = add_port(device, i, port_callback);
  973. if (ret)
  974. goto err_put;
  975. }
  976. }
  977. if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) {
  978. ret = sysfs_create_group(&class_dev->kobj, &iw_stats_group);
  979. if (ret)
  980. goto err_put;
  981. }
  982. return 0;
  983. err_put:
  984. free_port_list_attributes(device);
  985. err_unregister:
  986. device_unregister(class_dev);
  987. err:
  988. return ret;
  989. }
  990. void ib_device_unregister_sysfs(struct ib_device *device)
  991. {
  992. /* Hold kobject until ib_dealloc_device() */
  993. struct kobject *kobj_dev = kobject_get(&device->dev.kobj);
  994. int i;
  995. if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats)
  996. sysfs_remove_group(kobj_dev, &iw_stats_group);
  997. free_port_list_attributes(device);
  998. for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i)
  999. device_remove_file(&device->dev, ib_class_attributes[i]);
  1000. device_unregister(&device->dev);
  1001. }