qeth_core_sys.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  2. * Copyright IBM Corp. 2007
  3. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
  4. * Frank Pavlic <fpavlic@de.ibm.com>,
  5. * Thomas Spatzier <tspat@de.ibm.com>,
  6. * Frank Blaschka <frank.blaschka@de.ibm.com>
  7. */
  8. #define KMSG_COMPONENT "qeth"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/list.h>
  11. #include <linux/rwsem.h>
  12. #include <asm/ebcdic.h>
  13. #include "qeth_core.h"
  14. static ssize_t qeth_dev_state_show(struct device *dev,
  15. struct device_attribute *attr, char *buf)
  16. {
  17. struct qeth_card *card = dev_get_drvdata(dev);
  18. if (!card)
  19. return -EINVAL;
  20. switch (card->state) {
  21. case CARD_STATE_DOWN:
  22. return sprintf(buf, "DOWN\n");
  23. case CARD_STATE_HARDSETUP:
  24. return sprintf(buf, "HARDSETUP\n");
  25. case CARD_STATE_SOFTSETUP:
  26. return sprintf(buf, "SOFTSETUP\n");
  27. case CARD_STATE_UP:
  28. if (card->lan_online)
  29. return sprintf(buf, "UP (LAN ONLINE)\n");
  30. else
  31. return sprintf(buf, "UP (LAN OFFLINE)\n");
  32. case CARD_STATE_RECOVER:
  33. return sprintf(buf, "RECOVER\n");
  34. default:
  35. return sprintf(buf, "UNKNOWN\n");
  36. }
  37. }
  38. static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
  39. static ssize_t qeth_dev_chpid_show(struct device *dev,
  40. struct device_attribute *attr, char *buf)
  41. {
  42. struct qeth_card *card = dev_get_drvdata(dev);
  43. if (!card)
  44. return -EINVAL;
  45. return sprintf(buf, "%02X\n", card->info.chpid);
  46. }
  47. static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
  48. static ssize_t qeth_dev_if_name_show(struct device *dev,
  49. struct device_attribute *attr, char *buf)
  50. {
  51. struct qeth_card *card = dev_get_drvdata(dev);
  52. if (!card)
  53. return -EINVAL;
  54. return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
  55. }
  56. static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
  57. static ssize_t qeth_dev_card_type_show(struct device *dev,
  58. struct device_attribute *attr, char *buf)
  59. {
  60. struct qeth_card *card = dev_get_drvdata(dev);
  61. if (!card)
  62. return -EINVAL;
  63. return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
  64. }
  65. static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
  66. static inline const char *qeth_get_bufsize_str(struct qeth_card *card)
  67. {
  68. if (card->qdio.in_buf_size == 16384)
  69. return "16k";
  70. else if (card->qdio.in_buf_size == 24576)
  71. return "24k";
  72. else if (card->qdio.in_buf_size == 32768)
  73. return "32k";
  74. else if (card->qdio.in_buf_size == 40960)
  75. return "40k";
  76. else
  77. return "64k";
  78. }
  79. static ssize_t qeth_dev_inbuf_size_show(struct device *dev,
  80. struct device_attribute *attr, char *buf)
  81. {
  82. struct qeth_card *card = dev_get_drvdata(dev);
  83. if (!card)
  84. return -EINVAL;
  85. return sprintf(buf, "%s\n", qeth_get_bufsize_str(card));
  86. }
  87. static DEVICE_ATTR(inbuf_size, 0444, qeth_dev_inbuf_size_show, NULL);
  88. static ssize_t qeth_dev_portno_show(struct device *dev,
  89. struct device_attribute *attr, char *buf)
  90. {
  91. struct qeth_card *card = dev_get_drvdata(dev);
  92. if (!card)
  93. return -EINVAL;
  94. return sprintf(buf, "%i\n", card->info.portno);
  95. }
  96. static ssize_t qeth_dev_portno_store(struct device *dev,
  97. struct device_attribute *attr, const char *buf, size_t count)
  98. {
  99. struct qeth_card *card = dev_get_drvdata(dev);
  100. char *tmp;
  101. unsigned int portno, limit;
  102. int rc = 0;
  103. if (!card)
  104. return -EINVAL;
  105. mutex_lock(&card->conf_mutex);
  106. if ((card->state != CARD_STATE_DOWN) &&
  107. (card->state != CARD_STATE_RECOVER)) {
  108. rc = -EPERM;
  109. goto out;
  110. }
  111. portno = simple_strtoul(buf, &tmp, 16);
  112. if (portno > QETH_MAX_PORTNO) {
  113. rc = -EINVAL;
  114. goto out;
  115. }
  116. limit = (card->ssqd.pcnt ? card->ssqd.pcnt - 1 : card->ssqd.pcnt);
  117. if (portno > limit) {
  118. rc = -EINVAL;
  119. goto out;
  120. }
  121. card->info.portno = portno;
  122. out:
  123. mutex_unlock(&card->conf_mutex);
  124. return rc ? rc : count;
  125. }
  126. static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
  127. static ssize_t qeth_dev_portname_show(struct device *dev,
  128. struct device_attribute *attr, char *buf)
  129. {
  130. return sprintf(buf, "no portname required\n");
  131. }
  132. static ssize_t qeth_dev_portname_store(struct device *dev,
  133. struct device_attribute *attr, const char *buf, size_t count)
  134. {
  135. struct qeth_card *card = dev_get_drvdata(dev);
  136. dev_warn_once(&card->gdev->dev,
  137. "portname is deprecated and is ignored\n");
  138. return count;
  139. }
  140. static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
  141. qeth_dev_portname_store);
  142. static ssize_t qeth_dev_prioqing_show(struct device *dev,
  143. struct device_attribute *attr, char *buf)
  144. {
  145. struct qeth_card *card = dev_get_drvdata(dev);
  146. if (!card)
  147. return -EINVAL;
  148. switch (card->qdio.do_prio_queueing) {
  149. case QETH_PRIO_Q_ING_PREC:
  150. return sprintf(buf, "%s\n", "by precedence");
  151. case QETH_PRIO_Q_ING_TOS:
  152. return sprintf(buf, "%s\n", "by type of service");
  153. case QETH_PRIO_Q_ING_SKB:
  154. return sprintf(buf, "%s\n", "by skb-priority");
  155. case QETH_PRIO_Q_ING_VLAN:
  156. return sprintf(buf, "%s\n", "by VLAN headers");
  157. default:
  158. return sprintf(buf, "always queue %i\n",
  159. card->qdio.default_out_queue);
  160. }
  161. }
  162. static ssize_t qeth_dev_prioqing_store(struct device *dev,
  163. struct device_attribute *attr, const char *buf, size_t count)
  164. {
  165. struct qeth_card *card = dev_get_drvdata(dev);
  166. int rc = 0;
  167. if (!card)
  168. return -EINVAL;
  169. mutex_lock(&card->conf_mutex);
  170. if ((card->state != CARD_STATE_DOWN) &&
  171. (card->state != CARD_STATE_RECOVER)) {
  172. rc = -EPERM;
  173. goto out;
  174. }
  175. /* check if 1920 devices are supported ,
  176. * if though we have to permit priority queueing
  177. */
  178. if (card->qdio.no_out_queues == 1) {
  179. card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
  180. rc = -EPERM;
  181. goto out;
  182. }
  183. if (sysfs_streq(buf, "prio_queueing_prec")) {
  184. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
  185. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  186. } else if (sysfs_streq(buf, "prio_queueing_skb")) {
  187. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_SKB;
  188. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  189. } else if (sysfs_streq(buf, "prio_queueing_tos")) {
  190. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
  191. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  192. } else if (sysfs_streq(buf, "prio_queueing_vlan")) {
  193. if (!card->options.layer2) {
  194. rc = -ENOTSUPP;
  195. goto out;
  196. }
  197. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_VLAN;
  198. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  199. } else if (sysfs_streq(buf, "no_prio_queueing:0")) {
  200. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  201. card->qdio.default_out_queue = 0;
  202. } else if (sysfs_streq(buf, "no_prio_queueing:1")) {
  203. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  204. card->qdio.default_out_queue = 1;
  205. } else if (sysfs_streq(buf, "no_prio_queueing:2")) {
  206. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  207. card->qdio.default_out_queue = 2;
  208. } else if (sysfs_streq(buf, "no_prio_queueing:3")) {
  209. if (card->info.type == QETH_CARD_TYPE_IQD) {
  210. rc = -EPERM;
  211. goto out;
  212. }
  213. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  214. card->qdio.default_out_queue = 3;
  215. } else if (sysfs_streq(buf, "no_prio_queueing")) {
  216. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  217. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  218. } else
  219. rc = -EINVAL;
  220. out:
  221. mutex_unlock(&card->conf_mutex);
  222. return rc ? rc : count;
  223. }
  224. static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
  225. qeth_dev_prioqing_store);
  226. static ssize_t qeth_dev_bufcnt_show(struct device *dev,
  227. struct device_attribute *attr, char *buf)
  228. {
  229. struct qeth_card *card = dev_get_drvdata(dev);
  230. if (!card)
  231. return -EINVAL;
  232. return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
  233. }
  234. static ssize_t qeth_dev_bufcnt_store(struct device *dev,
  235. struct device_attribute *attr, const char *buf, size_t count)
  236. {
  237. struct qeth_card *card = dev_get_drvdata(dev);
  238. char *tmp;
  239. int cnt, old_cnt;
  240. int rc = 0;
  241. if (!card)
  242. return -EINVAL;
  243. mutex_lock(&card->conf_mutex);
  244. if ((card->state != CARD_STATE_DOWN) &&
  245. (card->state != CARD_STATE_RECOVER)) {
  246. rc = -EPERM;
  247. goto out;
  248. }
  249. old_cnt = card->qdio.in_buf_pool.buf_count;
  250. cnt = simple_strtoul(buf, &tmp, 10);
  251. cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
  252. ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
  253. if (old_cnt != cnt) {
  254. rc = qeth_realloc_buffer_pool(card, cnt);
  255. }
  256. out:
  257. mutex_unlock(&card->conf_mutex);
  258. return rc ? rc : count;
  259. }
  260. static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
  261. qeth_dev_bufcnt_store);
  262. static ssize_t qeth_dev_recover_store(struct device *dev,
  263. struct device_attribute *attr, const char *buf, size_t count)
  264. {
  265. struct qeth_card *card = dev_get_drvdata(dev);
  266. char *tmp;
  267. int i;
  268. if (!card)
  269. return -EINVAL;
  270. if (card->state != CARD_STATE_UP)
  271. return -EPERM;
  272. i = simple_strtoul(buf, &tmp, 16);
  273. if (i == 1)
  274. qeth_schedule_recovery(card);
  275. return count;
  276. }
  277. static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
  278. static ssize_t qeth_dev_performance_stats_show(struct device *dev,
  279. struct device_attribute *attr, char *buf)
  280. {
  281. struct qeth_card *card = dev_get_drvdata(dev);
  282. if (!card)
  283. return -EINVAL;
  284. return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
  285. }
  286. static ssize_t qeth_dev_performance_stats_store(struct device *dev,
  287. struct device_attribute *attr, const char *buf, size_t count)
  288. {
  289. struct qeth_card *card = dev_get_drvdata(dev);
  290. char *tmp;
  291. int i, rc = 0;
  292. if (!card)
  293. return -EINVAL;
  294. mutex_lock(&card->conf_mutex);
  295. i = simple_strtoul(buf, &tmp, 16);
  296. if ((i == 0) || (i == 1)) {
  297. if (i == card->options.performance_stats)
  298. goto out;
  299. card->options.performance_stats = i;
  300. if (i == 0)
  301. memset(&card->perf_stats, 0,
  302. sizeof(struct qeth_perf_stats));
  303. card->perf_stats.initial_rx_packets = card->stats.rx_packets;
  304. card->perf_stats.initial_tx_packets = card->stats.tx_packets;
  305. } else
  306. rc = -EINVAL;
  307. out:
  308. mutex_unlock(&card->conf_mutex);
  309. return rc ? rc : count;
  310. }
  311. static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
  312. qeth_dev_performance_stats_store);
  313. static ssize_t qeth_dev_layer2_show(struct device *dev,
  314. struct device_attribute *attr, char *buf)
  315. {
  316. struct qeth_card *card = dev_get_drvdata(dev);
  317. if (!card)
  318. return -EINVAL;
  319. return sprintf(buf, "%i\n", card->options.layer2);
  320. }
  321. static ssize_t qeth_dev_layer2_store(struct device *dev,
  322. struct device_attribute *attr, const char *buf, size_t count)
  323. {
  324. struct qeth_card *card = dev_get_drvdata(dev);
  325. char *tmp;
  326. int i, rc = 0;
  327. enum qeth_discipline_id newdis;
  328. if (!card)
  329. return -EINVAL;
  330. mutex_lock(&card->discipline_mutex);
  331. if (card->state != CARD_STATE_DOWN) {
  332. rc = -EPERM;
  333. goto out;
  334. }
  335. i = simple_strtoul(buf, &tmp, 16);
  336. switch (i) {
  337. case 0:
  338. newdis = QETH_DISCIPLINE_LAYER3;
  339. break;
  340. case 1:
  341. newdis = QETH_DISCIPLINE_LAYER2;
  342. break;
  343. default:
  344. rc = -EINVAL;
  345. goto out;
  346. }
  347. if (card->options.layer2 == newdis)
  348. goto out;
  349. if (card->info.type == QETH_CARD_TYPE_OSM) {
  350. /* fixed layer, can't switch */
  351. rc = -EOPNOTSUPP;
  352. goto out;
  353. }
  354. card->info.mac_bits = 0;
  355. if (card->discipline) {
  356. card->discipline->remove(card->gdev);
  357. qeth_core_free_discipline(card);
  358. }
  359. rc = qeth_core_load_discipline(card, newdis);
  360. if (rc)
  361. goto out;
  362. rc = card->discipline->setup(card->gdev);
  363. if (rc)
  364. qeth_core_free_discipline(card);
  365. out:
  366. mutex_unlock(&card->discipline_mutex);
  367. return rc ? rc : count;
  368. }
  369. static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
  370. qeth_dev_layer2_store);
  371. #define ATTR_QETH_ISOLATION_NONE ("none")
  372. #define ATTR_QETH_ISOLATION_FWD ("forward")
  373. #define ATTR_QETH_ISOLATION_DROP ("drop")
  374. static ssize_t qeth_dev_isolation_show(struct device *dev,
  375. struct device_attribute *attr, char *buf)
  376. {
  377. struct qeth_card *card = dev_get_drvdata(dev);
  378. if (!card)
  379. return -EINVAL;
  380. switch (card->options.isolation) {
  381. case ISOLATION_MODE_NONE:
  382. return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_NONE);
  383. case ISOLATION_MODE_FWD:
  384. return snprintf(buf, 9, "%s\n", ATTR_QETH_ISOLATION_FWD);
  385. case ISOLATION_MODE_DROP:
  386. return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_DROP);
  387. default:
  388. return snprintf(buf, 5, "%s\n", "N/A");
  389. }
  390. }
  391. static ssize_t qeth_dev_isolation_store(struct device *dev,
  392. struct device_attribute *attr, const char *buf, size_t count)
  393. {
  394. struct qeth_card *card = dev_get_drvdata(dev);
  395. enum qeth_ipa_isolation_modes isolation;
  396. int rc = 0;
  397. if (!card)
  398. return -EINVAL;
  399. mutex_lock(&card->conf_mutex);
  400. /* check for unknown, too, in case we do not yet know who we are */
  401. if (card->info.type != QETH_CARD_TYPE_OSD &&
  402. card->info.type != QETH_CARD_TYPE_OSX &&
  403. card->info.type != QETH_CARD_TYPE_UNKNOWN) {
  404. rc = -EOPNOTSUPP;
  405. dev_err(&card->gdev->dev, "Adapter does not "
  406. "support QDIO data connection isolation\n");
  407. goto out;
  408. }
  409. /* parse input into isolation mode */
  410. if (sysfs_streq(buf, ATTR_QETH_ISOLATION_NONE)) {
  411. isolation = ISOLATION_MODE_NONE;
  412. } else if (sysfs_streq(buf, ATTR_QETH_ISOLATION_FWD)) {
  413. isolation = ISOLATION_MODE_FWD;
  414. } else if (sysfs_streq(buf, ATTR_QETH_ISOLATION_DROP)) {
  415. isolation = ISOLATION_MODE_DROP;
  416. } else {
  417. rc = -EINVAL;
  418. goto out;
  419. }
  420. rc = count;
  421. /* defer IP assist if device is offline (until discipline->set_online)*/
  422. card->options.prev_isolation = card->options.isolation;
  423. card->options.isolation = isolation;
  424. if (qeth_card_hw_is_reachable(card)) {
  425. int ipa_rc = qeth_set_access_ctrl_online(card, 1);
  426. if (ipa_rc != 0)
  427. rc = ipa_rc;
  428. }
  429. out:
  430. mutex_unlock(&card->conf_mutex);
  431. return rc;
  432. }
  433. static DEVICE_ATTR(isolation, 0644, qeth_dev_isolation_show,
  434. qeth_dev_isolation_store);
  435. static ssize_t qeth_dev_switch_attrs_show(struct device *dev,
  436. struct device_attribute *attr, char *buf)
  437. {
  438. struct qeth_card *card = dev_get_drvdata(dev);
  439. struct qeth_switch_info sw_info;
  440. int rc = 0;
  441. if (!card)
  442. return -EINVAL;
  443. if (!qeth_card_hw_is_reachable(card))
  444. return sprintf(buf, "n/a\n");
  445. rc = qeth_query_switch_attributes(card, &sw_info);
  446. if (rc)
  447. return rc;
  448. if (!sw_info.capabilities)
  449. rc = sprintf(buf, "unknown");
  450. if (sw_info.capabilities & QETH_SWITCH_FORW_802_1)
  451. rc = sprintf(buf, (sw_info.settings & QETH_SWITCH_FORW_802_1 ?
  452. "[802.1]" : "802.1"));
  453. if (sw_info.capabilities & QETH_SWITCH_FORW_REFL_RELAY)
  454. rc += sprintf(buf + rc,
  455. (sw_info.settings & QETH_SWITCH_FORW_REFL_RELAY ?
  456. " [rr]" : " rr"));
  457. rc += sprintf(buf + rc, "\n");
  458. return rc;
  459. }
  460. static DEVICE_ATTR(switch_attrs, 0444,
  461. qeth_dev_switch_attrs_show, NULL);
  462. static ssize_t qeth_hw_trap_show(struct device *dev,
  463. struct device_attribute *attr, char *buf)
  464. {
  465. struct qeth_card *card = dev_get_drvdata(dev);
  466. if (!card)
  467. return -EINVAL;
  468. if (card->info.hwtrap)
  469. return snprintf(buf, 5, "arm\n");
  470. else
  471. return snprintf(buf, 8, "disarm\n");
  472. }
  473. static ssize_t qeth_hw_trap_store(struct device *dev,
  474. struct device_attribute *attr, const char *buf, size_t count)
  475. {
  476. struct qeth_card *card = dev_get_drvdata(dev);
  477. int rc = 0;
  478. int state = 0;
  479. if (!card)
  480. return -EINVAL;
  481. mutex_lock(&card->conf_mutex);
  482. if (qeth_card_hw_is_reachable(card))
  483. state = 1;
  484. if (sysfs_streq(buf, "arm") && !card->info.hwtrap) {
  485. if (state) {
  486. if (qeth_is_diagass_supported(card,
  487. QETH_DIAGS_CMD_TRAP)) {
  488. rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM);
  489. if (!rc)
  490. card->info.hwtrap = 1;
  491. } else
  492. rc = -EINVAL;
  493. } else
  494. card->info.hwtrap = 1;
  495. } else if (sysfs_streq(buf, "disarm") && card->info.hwtrap) {
  496. if (state) {
  497. rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
  498. if (!rc)
  499. card->info.hwtrap = 0;
  500. } else
  501. card->info.hwtrap = 0;
  502. } else if (sysfs_streq(buf, "trap") && state && card->info.hwtrap)
  503. rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_CAPTURE);
  504. else
  505. rc = -EINVAL;
  506. mutex_unlock(&card->conf_mutex);
  507. return rc ? rc : count;
  508. }
  509. static DEVICE_ATTR(hw_trap, 0644, qeth_hw_trap_show,
  510. qeth_hw_trap_store);
  511. static ssize_t qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value)
  512. {
  513. if (!card)
  514. return -EINVAL;
  515. return sprintf(buf, "%i\n", value);
  516. }
  517. static ssize_t qeth_dev_blkt_store(struct qeth_card *card,
  518. const char *buf, size_t count, int *value, int max_value)
  519. {
  520. char *tmp;
  521. int i, rc = 0;
  522. if (!card)
  523. return -EINVAL;
  524. mutex_lock(&card->conf_mutex);
  525. if ((card->state != CARD_STATE_DOWN) &&
  526. (card->state != CARD_STATE_RECOVER)) {
  527. rc = -EPERM;
  528. goto out;
  529. }
  530. i = simple_strtoul(buf, &tmp, 10);
  531. if (i <= max_value)
  532. *value = i;
  533. else
  534. rc = -EINVAL;
  535. out:
  536. mutex_unlock(&card->conf_mutex);
  537. return rc ? rc : count;
  538. }
  539. static ssize_t qeth_dev_blkt_total_show(struct device *dev,
  540. struct device_attribute *attr, char *buf)
  541. {
  542. struct qeth_card *card = dev_get_drvdata(dev);
  543. return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
  544. }
  545. static ssize_t qeth_dev_blkt_total_store(struct device *dev,
  546. struct device_attribute *attr, const char *buf, size_t count)
  547. {
  548. struct qeth_card *card = dev_get_drvdata(dev);
  549. return qeth_dev_blkt_store(card, buf, count,
  550. &card->info.blkt.time_total, 5000);
  551. }
  552. static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
  553. qeth_dev_blkt_total_store);
  554. static ssize_t qeth_dev_blkt_inter_show(struct device *dev,
  555. struct device_attribute *attr, char *buf)
  556. {
  557. struct qeth_card *card = dev_get_drvdata(dev);
  558. return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
  559. }
  560. static ssize_t qeth_dev_blkt_inter_store(struct device *dev,
  561. struct device_attribute *attr, const char *buf, size_t count)
  562. {
  563. struct qeth_card *card = dev_get_drvdata(dev);
  564. return qeth_dev_blkt_store(card, buf, count,
  565. &card->info.blkt.inter_packet, 1000);
  566. }
  567. static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
  568. qeth_dev_blkt_inter_store);
  569. static ssize_t qeth_dev_blkt_inter_jumbo_show(struct device *dev,
  570. struct device_attribute *attr, char *buf)
  571. {
  572. struct qeth_card *card = dev_get_drvdata(dev);
  573. return qeth_dev_blkt_show(buf, card,
  574. card->info.blkt.inter_packet_jumbo);
  575. }
  576. static ssize_t qeth_dev_blkt_inter_jumbo_store(struct device *dev,
  577. struct device_attribute *attr, const char *buf, size_t count)
  578. {
  579. struct qeth_card *card = dev_get_drvdata(dev);
  580. return qeth_dev_blkt_store(card, buf, count,
  581. &card->info.blkt.inter_packet_jumbo, 1000);
  582. }
  583. static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
  584. qeth_dev_blkt_inter_jumbo_store);
  585. static struct attribute *qeth_blkt_device_attrs[] = {
  586. &dev_attr_total.attr,
  587. &dev_attr_inter.attr,
  588. &dev_attr_inter_jumbo.attr,
  589. NULL,
  590. };
  591. const struct attribute_group qeth_device_blkt_group = {
  592. .name = "blkt",
  593. .attrs = qeth_blkt_device_attrs,
  594. };
  595. EXPORT_SYMBOL_GPL(qeth_device_blkt_group);
  596. static struct attribute *qeth_device_attrs[] = {
  597. &dev_attr_state.attr,
  598. &dev_attr_chpid.attr,
  599. &dev_attr_if_name.attr,
  600. &dev_attr_card_type.attr,
  601. &dev_attr_inbuf_size.attr,
  602. &dev_attr_portno.attr,
  603. &dev_attr_portname.attr,
  604. &dev_attr_priority_queueing.attr,
  605. &dev_attr_buffer_count.attr,
  606. &dev_attr_recover.attr,
  607. &dev_attr_performance_stats.attr,
  608. &dev_attr_layer2.attr,
  609. &dev_attr_isolation.attr,
  610. &dev_attr_hw_trap.attr,
  611. &dev_attr_switch_attrs.attr,
  612. NULL,
  613. };
  614. const struct attribute_group qeth_device_attr_group = {
  615. .attrs = qeth_device_attrs,
  616. };
  617. EXPORT_SYMBOL_GPL(qeth_device_attr_group);
  618. const struct attribute_group *qeth_generic_attr_groups[] = {
  619. &qeth_device_attr_group,
  620. &qeth_device_blkt_group,
  621. NULL,
  622. };
  623. static struct attribute *qeth_osn_device_attrs[] = {
  624. &dev_attr_state.attr,
  625. &dev_attr_chpid.attr,
  626. &dev_attr_if_name.attr,
  627. &dev_attr_card_type.attr,
  628. &dev_attr_buffer_count.attr,
  629. &dev_attr_recover.attr,
  630. NULL,
  631. };
  632. static struct attribute_group qeth_osn_device_attr_group = {
  633. .attrs = qeth_osn_device_attrs,
  634. };
  635. const struct attribute_group *qeth_osn_attr_groups[] = {
  636. &qeth_osn_device_attr_group,
  637. NULL,
  638. };