qeth_sys.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  1. /*
  2. *
  3. * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.51 $)
  4. *
  5. * Linux on zSeries OSA Express and HiperSockets support
  6. * This file contains code related to sysfs.
  7. *
  8. * Copyright 2000,2003 IBM Corporation
  9. *
  10. * Author(s): Thomas Spatzier <tspat@de.ibm.com>
  11. * Frank Pavlic <pavlic@de.ibm.com>
  12. *
  13. */
  14. #include <linux/list.h>
  15. #include <linux/rwsem.h>
  16. #include <asm/ebcdic.h>
  17. #include "qeth.h"
  18. #include "qeth_mpc.h"
  19. #include "qeth_fs.h"
  20. const char *VERSION_QETH_SYS_C = "$Revision: 1.51 $";
  21. /*****************************************************************************/
  22. /* */
  23. /* /sys-fs stuff UNDER DEVELOPMENT !!! */
  24. /* */
  25. /*****************************************************************************/
  26. //low/high watermark
  27. static ssize_t
  28. qeth_dev_state_show(struct device *dev, struct device_attribute *attr, char *buf)
  29. {
  30. struct qeth_card *card = dev->driver_data;
  31. if (!card)
  32. return -EINVAL;
  33. switch (card->state) {
  34. case CARD_STATE_DOWN:
  35. return sprintf(buf, "DOWN\n");
  36. case CARD_STATE_HARDSETUP:
  37. return sprintf(buf, "HARDSETUP\n");
  38. case CARD_STATE_SOFTSETUP:
  39. return sprintf(buf, "SOFTSETUP\n");
  40. case CARD_STATE_UP:
  41. if (card->lan_online)
  42. return sprintf(buf, "UP (LAN ONLINE)\n");
  43. else
  44. return sprintf(buf, "UP (LAN OFFLINE)\n");
  45. case CARD_STATE_RECOVER:
  46. return sprintf(buf, "RECOVER\n");
  47. default:
  48. return sprintf(buf, "UNKNOWN\n");
  49. }
  50. }
  51. static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
  52. static ssize_t
  53. qeth_dev_chpid_show(struct device *dev, struct device_attribute *attr, char *buf)
  54. {
  55. struct qeth_card *card = dev->driver_data;
  56. if (!card)
  57. return -EINVAL;
  58. return sprintf(buf, "%02X\n", card->info.chpid);
  59. }
  60. static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
  61. static ssize_t
  62. qeth_dev_if_name_show(struct device *dev, struct device_attribute *attr, char *buf)
  63. {
  64. struct qeth_card *card = dev->driver_data;
  65. if (!card)
  66. return -EINVAL;
  67. return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
  68. }
  69. static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
  70. static ssize_t
  71. qeth_dev_card_type_show(struct device *dev, struct device_attribute *attr, char *buf)
  72. {
  73. struct qeth_card *card = dev->driver_data;
  74. if (!card)
  75. return -EINVAL;
  76. return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
  77. }
  78. static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
  79. static ssize_t
  80. qeth_dev_portno_show(struct device *dev, struct device_attribute *attr, char *buf)
  81. {
  82. struct qeth_card *card = dev->driver_data;
  83. if (!card)
  84. return -EINVAL;
  85. return sprintf(buf, "%i\n", card->info.portno);
  86. }
  87. static ssize_t
  88. qeth_dev_portno_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  89. {
  90. struct qeth_card *card = dev->driver_data;
  91. char *tmp;
  92. unsigned int portno;
  93. if (!card)
  94. return -EINVAL;
  95. if ((card->state != CARD_STATE_DOWN) &&
  96. (card->state != CARD_STATE_RECOVER))
  97. return -EPERM;
  98. portno = simple_strtoul(buf, &tmp, 16);
  99. if ((portno < 0) || (portno > MAX_PORTNO)){
  100. PRINT_WARN("portno 0x%X is out of range\n", portno);
  101. return -EINVAL;
  102. }
  103. card->info.portno = portno;
  104. return count;
  105. }
  106. static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
  107. static ssize_t
  108. qeth_dev_portname_show(struct device *dev, struct device_attribute *attr, char *buf)
  109. {
  110. struct qeth_card *card = dev->driver_data;
  111. char portname[9] = {0, };
  112. if (!card)
  113. return -EINVAL;
  114. if (card->info.portname_required) {
  115. memcpy(portname, card->info.portname + 1, 8);
  116. EBCASC(portname, 8);
  117. return sprintf(buf, "%s\n", portname);
  118. } else
  119. return sprintf(buf, "no portname required\n");
  120. }
  121. static ssize_t
  122. qeth_dev_portname_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  123. {
  124. struct qeth_card *card = dev->driver_data;
  125. char *tmp;
  126. int i;
  127. if (!card)
  128. return -EINVAL;
  129. if ((card->state != CARD_STATE_DOWN) &&
  130. (card->state != CARD_STATE_RECOVER))
  131. return -EPERM;
  132. tmp = strsep((char **) &buf, "\n");
  133. if ((strlen(tmp) > 8) || (strlen(tmp) < 2))
  134. return -EINVAL;
  135. card->info.portname[0] = strlen(tmp);
  136. /* for beauty reasons */
  137. for (i = 1; i < 9; i++)
  138. card->info.portname[i] = ' ';
  139. strcpy(card->info.portname + 1, tmp);
  140. ASCEBC(card->info.portname + 1, 8);
  141. return count;
  142. }
  143. static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
  144. qeth_dev_portname_store);
  145. static ssize_t
  146. qeth_dev_checksum_show(struct device *dev, struct device_attribute *attr, char *buf)
  147. {
  148. struct qeth_card *card = dev->driver_data;
  149. if (!card)
  150. return -EINVAL;
  151. return sprintf(buf, "%s checksumming\n", qeth_get_checksum_str(card));
  152. }
  153. static ssize_t
  154. qeth_dev_checksum_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  155. {
  156. struct qeth_card *card = dev->driver_data;
  157. char *tmp;
  158. if (!card)
  159. return -EINVAL;
  160. if ((card->state != CARD_STATE_DOWN) &&
  161. (card->state != CARD_STATE_RECOVER))
  162. return -EPERM;
  163. tmp = strsep((char **) &buf, "\n");
  164. if (!strcmp(tmp, "sw_checksumming"))
  165. card->options.checksum_type = SW_CHECKSUMMING;
  166. else if (!strcmp(tmp, "hw_checksumming"))
  167. card->options.checksum_type = HW_CHECKSUMMING;
  168. else if (!strcmp(tmp, "no_checksumming"))
  169. card->options.checksum_type = NO_CHECKSUMMING;
  170. else {
  171. PRINT_WARN("Unknown checksumming type '%s'\n", tmp);
  172. return -EINVAL;
  173. }
  174. return count;
  175. }
  176. static DEVICE_ATTR(checksumming, 0644, qeth_dev_checksum_show,
  177. qeth_dev_checksum_store);
  178. static ssize_t
  179. qeth_dev_prioqing_show(struct device *dev, struct device_attribute *attr, char *buf)
  180. {
  181. struct qeth_card *card = dev->driver_data;
  182. if (!card)
  183. return -EINVAL;
  184. switch (card->qdio.do_prio_queueing) {
  185. case QETH_PRIO_Q_ING_PREC:
  186. return sprintf(buf, "%s\n", "by precedence");
  187. case QETH_PRIO_Q_ING_TOS:
  188. return sprintf(buf, "%s\n", "by type of service");
  189. default:
  190. return sprintf(buf, "always queue %i\n",
  191. card->qdio.default_out_queue);
  192. }
  193. }
  194. static ssize_t
  195. qeth_dev_prioqing_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  196. {
  197. struct qeth_card *card = dev->driver_data;
  198. char *tmp;
  199. if (!card)
  200. return -EINVAL;
  201. if ((card->state != CARD_STATE_DOWN) &&
  202. (card->state != CARD_STATE_RECOVER))
  203. return -EPERM;
  204. /* check if 1920 devices are supported ,
  205. * if though we have to permit priority queueing
  206. */
  207. if (card->qdio.no_out_queues == 1) {
  208. PRINT_WARN("Priority queueing disabled due "
  209. "to hardware limitations!\n");
  210. card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
  211. return -EPERM;
  212. }
  213. tmp = strsep((char **) &buf, "\n");
  214. if (!strcmp(tmp, "prio_queueing_prec"))
  215. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
  216. else if (!strcmp(tmp, "prio_queueing_tos"))
  217. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
  218. else if (!strcmp(tmp, "no_prio_queueing:0")) {
  219. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  220. card->qdio.default_out_queue = 0;
  221. } else if (!strcmp(tmp, "no_prio_queueing:1")) {
  222. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  223. card->qdio.default_out_queue = 1;
  224. } else if (!strcmp(tmp, "no_prio_queueing:2")) {
  225. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  226. card->qdio.default_out_queue = 2;
  227. } else if (!strcmp(tmp, "no_prio_queueing:3")) {
  228. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  229. card->qdio.default_out_queue = 3;
  230. } else if (!strcmp(tmp, "no_prio_queueing")) {
  231. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  232. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  233. } else {
  234. PRINT_WARN("Unknown queueing type '%s'\n", tmp);
  235. return -EINVAL;
  236. }
  237. return count;
  238. }
  239. static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
  240. qeth_dev_prioqing_store);
  241. static ssize_t
  242. qeth_dev_bufcnt_show(struct device *dev, struct device_attribute *attr, char *buf)
  243. {
  244. struct qeth_card *card = dev->driver_data;
  245. if (!card)
  246. return -EINVAL;
  247. return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
  248. }
  249. static ssize_t
  250. qeth_dev_bufcnt_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  251. {
  252. struct qeth_card *card = dev->driver_data;
  253. char *tmp;
  254. int cnt, old_cnt;
  255. int rc;
  256. if (!card)
  257. return -EINVAL;
  258. if ((card->state != CARD_STATE_DOWN) &&
  259. (card->state != CARD_STATE_RECOVER))
  260. return -EPERM;
  261. old_cnt = card->qdio.in_buf_pool.buf_count;
  262. cnt = simple_strtoul(buf, &tmp, 10);
  263. cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
  264. ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
  265. if (old_cnt != cnt) {
  266. if ((rc = qeth_realloc_buffer_pool(card, cnt)))
  267. PRINT_WARN("Error (%d) while setting "
  268. "buffer count.\n", rc);
  269. }
  270. return count;
  271. }
  272. static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
  273. qeth_dev_bufcnt_store);
  274. static inline ssize_t
  275. qeth_dev_route_show(struct qeth_card *card, struct qeth_routing_info *route,
  276. char *buf)
  277. {
  278. switch (route->type) {
  279. case PRIMARY_ROUTER:
  280. return sprintf(buf, "%s\n", "primary router");
  281. case SECONDARY_ROUTER:
  282. return sprintf(buf, "%s\n", "secondary router");
  283. case MULTICAST_ROUTER:
  284. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  285. return sprintf(buf, "%s\n", "multicast router+");
  286. else
  287. return sprintf(buf, "%s\n", "multicast router");
  288. case PRIMARY_CONNECTOR:
  289. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  290. return sprintf(buf, "%s\n", "primary connector+");
  291. else
  292. return sprintf(buf, "%s\n", "primary connector");
  293. case SECONDARY_CONNECTOR:
  294. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  295. return sprintf(buf, "%s\n", "secondary connector+");
  296. else
  297. return sprintf(buf, "%s\n", "secondary connector");
  298. default:
  299. return sprintf(buf, "%s\n", "no");
  300. }
  301. }
  302. static ssize_t
  303. qeth_dev_route4_show(struct device *dev, struct device_attribute *attr, char *buf)
  304. {
  305. struct qeth_card *card = dev->driver_data;
  306. if (!card)
  307. return -EINVAL;
  308. return qeth_dev_route_show(card, &card->options.route4, buf);
  309. }
  310. static inline ssize_t
  311. qeth_dev_route_store(struct qeth_card *card, struct qeth_routing_info *route,
  312. enum qeth_prot_versions prot, const char *buf, size_t count)
  313. {
  314. enum qeth_routing_types old_route_type = route->type;
  315. char *tmp;
  316. int rc;
  317. tmp = strsep((char **) &buf, "\n");
  318. if (!strcmp(tmp, "no_router")){
  319. route->type = NO_ROUTER;
  320. } else if (!strcmp(tmp, "primary_connector")) {
  321. route->type = PRIMARY_CONNECTOR;
  322. } else if (!strcmp(tmp, "secondary_connector")) {
  323. route->type = SECONDARY_CONNECTOR;
  324. } else if (!strcmp(tmp, "multicast_router")) {
  325. route->type = MULTICAST_ROUTER;
  326. } else if (!strcmp(tmp, "primary_router")) {
  327. route->type = PRIMARY_ROUTER;
  328. } else if (!strcmp(tmp, "secondary_router")) {
  329. route->type = SECONDARY_ROUTER;
  330. } else if (!strcmp(tmp, "multicast_router")) {
  331. route->type = MULTICAST_ROUTER;
  332. } else {
  333. PRINT_WARN("Invalid routing type '%s'.\n", tmp);
  334. return -EINVAL;
  335. }
  336. if (((card->state == CARD_STATE_SOFTSETUP) ||
  337. (card->state == CARD_STATE_UP)) &&
  338. (old_route_type != route->type)){
  339. if (prot == QETH_PROT_IPV4)
  340. rc = qeth_setrouting_v4(card);
  341. else if (prot == QETH_PROT_IPV6)
  342. rc = qeth_setrouting_v6(card);
  343. }
  344. return count;
  345. }
  346. static ssize_t
  347. qeth_dev_route4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  348. {
  349. struct qeth_card *card = dev->driver_data;
  350. if (!card)
  351. return -EINVAL;
  352. return qeth_dev_route_store(card, &card->options.route4,
  353. QETH_PROT_IPV4, buf, count);
  354. }
  355. static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
  356. #ifdef CONFIG_QETH_IPV6
  357. static ssize_t
  358. qeth_dev_route6_show(struct device *dev, struct device_attribute *attr, char *buf)
  359. {
  360. struct qeth_card *card = dev->driver_data;
  361. if (!card)
  362. return -EINVAL;
  363. if (!qeth_is_supported(card, IPA_IPV6))
  364. return sprintf(buf, "%s\n", "n/a");
  365. return qeth_dev_route_show(card, &card->options.route6, buf);
  366. }
  367. static ssize_t
  368. qeth_dev_route6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  369. {
  370. struct qeth_card *card = dev->driver_data;
  371. if (!card)
  372. return -EINVAL;
  373. if (!qeth_is_supported(card, IPA_IPV6)){
  374. PRINT_WARN("IPv6 not supported for interface %s.\n"
  375. "Routing status no changed.\n",
  376. QETH_CARD_IFNAME(card));
  377. return -ENOTSUPP;
  378. }
  379. return qeth_dev_route_store(card, &card->options.route6,
  380. QETH_PROT_IPV6, buf, count);
  381. }
  382. static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
  383. #endif
  384. static ssize_t
  385. qeth_dev_add_hhlen_show(struct device *dev, struct device_attribute *attr, char *buf)
  386. {
  387. struct qeth_card *card = dev->driver_data;
  388. if (!card)
  389. return -EINVAL;
  390. return sprintf(buf, "%i\n", card->options.add_hhlen);
  391. }
  392. static ssize_t
  393. qeth_dev_add_hhlen_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  394. {
  395. struct qeth_card *card = dev->driver_data;
  396. char *tmp;
  397. int i;
  398. if (!card)
  399. return -EINVAL;
  400. if ((card->state != CARD_STATE_DOWN) &&
  401. (card->state != CARD_STATE_RECOVER))
  402. return -EPERM;
  403. i = simple_strtoul(buf, &tmp, 10);
  404. if ((i < 0) || (i > MAX_ADD_HHLEN)) {
  405. PRINT_WARN("add_hhlen out of range\n");
  406. return -EINVAL;
  407. }
  408. card->options.add_hhlen = i;
  409. return count;
  410. }
  411. static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
  412. qeth_dev_add_hhlen_store);
  413. static ssize_t
  414. qeth_dev_fake_ll_show(struct device *dev, struct device_attribute *attr, char *buf)
  415. {
  416. struct qeth_card *card = dev->driver_data;
  417. if (!card)
  418. return -EINVAL;
  419. return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
  420. }
  421. static ssize_t
  422. qeth_dev_fake_ll_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  423. {
  424. struct qeth_card *card = dev->driver_data;
  425. char *tmp;
  426. int i;
  427. if (!card)
  428. return -EINVAL;
  429. if ((card->state != CARD_STATE_DOWN) &&
  430. (card->state != CARD_STATE_RECOVER))
  431. return -EPERM;
  432. i = simple_strtoul(buf, &tmp, 16);
  433. if ((i != 0) && (i != 1)) {
  434. PRINT_WARN("fake_ll: write 0 or 1 to this file!\n");
  435. return -EINVAL;
  436. }
  437. card->options.fake_ll = i;
  438. return count;
  439. }
  440. static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
  441. qeth_dev_fake_ll_store);
  442. static ssize_t
  443. qeth_dev_fake_broadcast_show(struct device *dev, struct device_attribute *attr, char *buf)
  444. {
  445. struct qeth_card *card = dev->driver_data;
  446. if (!card)
  447. return -EINVAL;
  448. return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
  449. }
  450. static ssize_t
  451. qeth_dev_fake_broadcast_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  452. {
  453. struct qeth_card *card = dev->driver_data;
  454. char *tmp;
  455. int i;
  456. if (!card)
  457. return -EINVAL;
  458. if ((card->state != CARD_STATE_DOWN) &&
  459. (card->state != CARD_STATE_RECOVER))
  460. return -EPERM;
  461. i = simple_strtoul(buf, &tmp, 16);
  462. if ((i == 0) || (i == 1))
  463. card->options.fake_broadcast = i;
  464. else {
  465. PRINT_WARN("fake_broadcast: write 0 or 1 to this file!\n");
  466. return -EINVAL;
  467. }
  468. return count;
  469. }
  470. static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
  471. qeth_dev_fake_broadcast_store);
  472. static ssize_t
  473. qeth_dev_recover_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  474. {
  475. struct qeth_card *card = dev->driver_data;
  476. char *tmp;
  477. int i;
  478. if (!card)
  479. return -EINVAL;
  480. if (card->state != CARD_STATE_UP)
  481. return -EPERM;
  482. i = simple_strtoul(buf, &tmp, 16);
  483. if (i == 1)
  484. qeth_schedule_recovery(card);
  485. return count;
  486. }
  487. static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
  488. static ssize_t
  489. qeth_dev_broadcast_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  490. {
  491. struct qeth_card *card = dev->driver_data;
  492. if (!card)
  493. return -EINVAL;
  494. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  495. (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
  496. return sprintf(buf, "n/a\n");
  497. return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
  498. QETH_TR_BROADCAST_ALLRINGS)?
  499. "all rings":"local");
  500. }
  501. static ssize_t
  502. qeth_dev_broadcast_mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  503. {
  504. struct qeth_card *card = dev->driver_data;
  505. char *tmp;
  506. if (!card)
  507. return -EINVAL;
  508. if ((card->state != CARD_STATE_DOWN) &&
  509. (card->state != CARD_STATE_RECOVER))
  510. return -EPERM;
  511. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  512. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
  513. PRINT_WARN("Device is not a tokenring device!\n");
  514. return -EINVAL;
  515. }
  516. tmp = strsep((char **) &buf, "\n");
  517. if (!strcmp(tmp, "local")){
  518. card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
  519. return count;
  520. } else if (!strcmp(tmp, "all_rings")) {
  521. card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
  522. return count;
  523. } else {
  524. PRINT_WARN("broadcast_mode: invalid mode %s!\n",
  525. tmp);
  526. return -EINVAL;
  527. }
  528. return count;
  529. }
  530. static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
  531. qeth_dev_broadcast_mode_store);
  532. static ssize_t
  533. qeth_dev_canonical_macaddr_show(struct device *dev, struct device_attribute *attr, char *buf)
  534. {
  535. struct qeth_card *card = dev->driver_data;
  536. if (!card)
  537. return -EINVAL;
  538. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  539. (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
  540. return sprintf(buf, "n/a\n");
  541. return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
  542. QETH_TR_MACADDR_CANONICAL)? 1:0);
  543. }
  544. static ssize_t
  545. qeth_dev_canonical_macaddr_store(struct device *dev, struct device_attribute *attr, const char *buf,
  546. size_t count)
  547. {
  548. struct qeth_card *card = dev->driver_data;
  549. char *tmp;
  550. int i;
  551. if (!card)
  552. return -EINVAL;
  553. if ((card->state != CARD_STATE_DOWN) &&
  554. (card->state != CARD_STATE_RECOVER))
  555. return -EPERM;
  556. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  557. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
  558. PRINT_WARN("Device is not a tokenring device!\n");
  559. return -EINVAL;
  560. }
  561. i = simple_strtoul(buf, &tmp, 16);
  562. if ((i == 0) || (i == 1))
  563. card->options.macaddr_mode = i?
  564. QETH_TR_MACADDR_CANONICAL :
  565. QETH_TR_MACADDR_NONCANONICAL;
  566. else {
  567. PRINT_WARN("canonical_macaddr: write 0 or 1 to this file!\n");
  568. return -EINVAL;
  569. }
  570. return count;
  571. }
  572. static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
  573. qeth_dev_canonical_macaddr_store);
  574. static ssize_t
  575. qeth_dev_layer2_show(struct device *dev, struct device_attribute *attr, char *buf)
  576. {
  577. struct qeth_card *card = dev->driver_data;
  578. if (!card)
  579. return -EINVAL;
  580. return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
  581. }
  582. static ssize_t
  583. qeth_dev_layer2_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  584. {
  585. struct qeth_card *card = dev->driver_data;
  586. char *tmp;
  587. int i;
  588. if (!card)
  589. return -EINVAL;
  590. if (((card->state != CARD_STATE_DOWN) &&
  591. (card->state != CARD_STATE_RECOVER)) ||
  592. (card->info.type != QETH_CARD_TYPE_OSAE))
  593. return -EPERM;
  594. i = simple_strtoul(buf, &tmp, 16);
  595. if ((i == 0) || (i == 1))
  596. card->options.layer2 = i;
  597. else {
  598. PRINT_WARN("layer2: write 0 or 1 to this file!\n");
  599. return -EINVAL;
  600. }
  601. return count;
  602. }
  603. static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
  604. qeth_dev_layer2_store);
  605. static ssize_t
  606. qeth_dev_large_send_show(struct device *dev, struct device_attribute *attr, char *buf)
  607. {
  608. struct qeth_card *card = dev->driver_data;
  609. if (!card)
  610. return -EINVAL;
  611. switch (card->options.large_send) {
  612. case QETH_LARGE_SEND_NO:
  613. return sprintf(buf, "%s\n", "no");
  614. case QETH_LARGE_SEND_EDDP:
  615. return sprintf(buf, "%s\n", "EDDP");
  616. case QETH_LARGE_SEND_TSO:
  617. return sprintf(buf, "%s\n", "TSO");
  618. default:
  619. return sprintf(buf, "%s\n", "N/A");
  620. }
  621. }
  622. static ssize_t
  623. qeth_dev_large_send_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  624. {
  625. struct qeth_card *card = dev->driver_data;
  626. enum qeth_large_send_types type;
  627. int rc = 0;
  628. char *tmp;
  629. if (!card)
  630. return -EINVAL;
  631. tmp = strsep((char **) &buf, "\n");
  632. if (!strcmp(tmp, "no")){
  633. type = QETH_LARGE_SEND_NO;
  634. } else if (!strcmp(tmp, "EDDP")) {
  635. type = QETH_LARGE_SEND_EDDP;
  636. } else if (!strcmp(tmp, "TSO")) {
  637. type = QETH_LARGE_SEND_TSO;
  638. } else {
  639. PRINT_WARN("large_send: invalid mode %s!\n", tmp);
  640. return -EINVAL;
  641. }
  642. if (card->options.large_send == type)
  643. return count;
  644. card->options.large_send = type;
  645. if ((rc = qeth_set_large_send(card)))
  646. return rc;
  647. return count;
  648. }
  649. static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
  650. qeth_dev_large_send_store);
  651. static ssize_t
  652. qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value )
  653. {
  654. if (!card)
  655. return -EINVAL;
  656. return sprintf(buf, "%i\n", value);
  657. }
  658. static ssize_t
  659. qeth_dev_blkt_store(struct qeth_card *card, const char *buf, size_t count,
  660. int *value, int max_value)
  661. {
  662. char *tmp;
  663. int i;
  664. if (!card)
  665. return -EINVAL;
  666. if ((card->state != CARD_STATE_DOWN) &&
  667. (card->state != CARD_STATE_RECOVER))
  668. return -EPERM;
  669. i = simple_strtoul(buf, &tmp, 10);
  670. if (i <= max_value) {
  671. *value = i;
  672. } else {
  673. PRINT_WARN("blkt total time: write values between"
  674. " 0 and %d to this file!\n", max_value);
  675. return -EINVAL;
  676. }
  677. return count;
  678. }
  679. static ssize_t
  680. qeth_dev_blkt_total_show(struct device *dev, struct device_attribute *attr, char *buf)
  681. {
  682. struct qeth_card *card = dev->driver_data;
  683. return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
  684. }
  685. static ssize_t
  686. qeth_dev_blkt_total_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  687. {
  688. struct qeth_card *card = dev->driver_data;
  689. return qeth_dev_blkt_store(card, buf, count,
  690. &card->info.blkt.time_total,1000);
  691. }
  692. static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
  693. qeth_dev_blkt_total_store);
  694. static ssize_t
  695. qeth_dev_blkt_inter_show(struct device *dev, struct device_attribute *attr, char *buf)
  696. {
  697. struct qeth_card *card = dev->driver_data;
  698. return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
  699. }
  700. static ssize_t
  701. qeth_dev_blkt_inter_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  702. {
  703. struct qeth_card *card = dev->driver_data;
  704. return qeth_dev_blkt_store(card, buf, count,
  705. &card->info.blkt.inter_packet,100);
  706. }
  707. static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
  708. qeth_dev_blkt_inter_store);
  709. static ssize_t
  710. qeth_dev_blkt_inter_jumbo_show(struct device *dev, struct device_attribute *attr, char *buf)
  711. {
  712. struct qeth_card *card = dev->driver_data;
  713. return qeth_dev_blkt_show(buf, card,
  714. card->info.blkt.inter_packet_jumbo);
  715. }
  716. static ssize_t
  717. qeth_dev_blkt_inter_jumbo_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  718. {
  719. struct qeth_card *card = dev->driver_data;
  720. return qeth_dev_blkt_store(card, buf, count,
  721. &card->info.blkt.inter_packet_jumbo,100);
  722. }
  723. static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
  724. qeth_dev_blkt_inter_jumbo_store);
  725. static struct device_attribute * qeth_blkt_device_attrs[] = {
  726. &dev_attr_total,
  727. &dev_attr_inter,
  728. &dev_attr_inter_jumbo,
  729. NULL,
  730. };
  731. static struct attribute_group qeth_device_blkt_group = {
  732. .name = "blkt",
  733. .attrs = (struct attribute **)qeth_blkt_device_attrs,
  734. };
  735. static struct device_attribute * qeth_device_attrs[] = {
  736. &dev_attr_state,
  737. &dev_attr_chpid,
  738. &dev_attr_if_name,
  739. &dev_attr_card_type,
  740. &dev_attr_portno,
  741. &dev_attr_portname,
  742. &dev_attr_checksumming,
  743. &dev_attr_priority_queueing,
  744. &dev_attr_buffer_count,
  745. &dev_attr_route4,
  746. #ifdef CONFIG_QETH_IPV6
  747. &dev_attr_route6,
  748. #endif
  749. &dev_attr_add_hhlen,
  750. &dev_attr_fake_ll,
  751. &dev_attr_fake_broadcast,
  752. &dev_attr_recover,
  753. &dev_attr_broadcast_mode,
  754. &dev_attr_canonical_macaddr,
  755. &dev_attr_layer2,
  756. &dev_attr_large_send,
  757. NULL,
  758. };
  759. static struct attribute_group qeth_device_attr_group = {
  760. .attrs = (struct attribute **)qeth_device_attrs,
  761. };
  762. #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
  763. struct device_attribute dev_attr_##_id = { \
  764. .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
  765. .show = _show, \
  766. .store = _store, \
  767. };
  768. int
  769. qeth_check_layer2(struct qeth_card *card)
  770. {
  771. if (card->options.layer2)
  772. return -EPERM;
  773. return 0;
  774. }
  775. static ssize_t
  776. qeth_dev_ipato_enable_show(struct device *dev, struct device_attribute *attr, char *buf)
  777. {
  778. struct qeth_card *card = dev->driver_data;
  779. if (!card)
  780. return -EINVAL;
  781. if (qeth_check_layer2(card))
  782. return -EPERM;
  783. return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
  784. }
  785. static ssize_t
  786. qeth_dev_ipato_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  787. {
  788. struct qeth_card *card = dev->driver_data;
  789. char *tmp;
  790. if (!card)
  791. return -EINVAL;
  792. if ((card->state != CARD_STATE_DOWN) &&
  793. (card->state != CARD_STATE_RECOVER))
  794. return -EPERM;
  795. if (qeth_check_layer2(card))
  796. return -EPERM;
  797. tmp = strsep((char **) &buf, "\n");
  798. if (!strcmp(tmp, "toggle")){
  799. card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
  800. } else if (!strcmp(tmp, "1")){
  801. card->ipato.enabled = 1;
  802. } else if (!strcmp(tmp, "0")){
  803. card->ipato.enabled = 0;
  804. } else {
  805. PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
  806. "this file\n");
  807. return -EINVAL;
  808. }
  809. return count;
  810. }
  811. static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
  812. qeth_dev_ipato_enable_show,
  813. qeth_dev_ipato_enable_store);
  814. static ssize_t
  815. qeth_dev_ipato_invert4_show(struct device *dev, struct device_attribute *attr, char *buf)
  816. {
  817. struct qeth_card *card = dev->driver_data;
  818. if (!card)
  819. return -EINVAL;
  820. if (qeth_check_layer2(card))
  821. return -EPERM;
  822. return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
  823. }
  824. static ssize_t
  825. qeth_dev_ipato_invert4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  826. {
  827. struct qeth_card *card = dev->driver_data;
  828. char *tmp;
  829. if (!card)
  830. return -EINVAL;
  831. if (qeth_check_layer2(card))
  832. return -EPERM;
  833. tmp = strsep((char **) &buf, "\n");
  834. if (!strcmp(tmp, "toggle")){
  835. card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
  836. } else if (!strcmp(tmp, "1")){
  837. card->ipato.invert4 = 1;
  838. } else if (!strcmp(tmp, "0")){
  839. card->ipato.invert4 = 0;
  840. } else {
  841. PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
  842. "this file\n");
  843. return -EINVAL;
  844. }
  845. return count;
  846. }
  847. static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
  848. qeth_dev_ipato_invert4_show,
  849. qeth_dev_ipato_invert4_store);
  850. static inline ssize_t
  851. qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
  852. enum qeth_prot_versions proto)
  853. {
  854. struct qeth_ipato_entry *ipatoe;
  855. unsigned long flags;
  856. char addr_str[40];
  857. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  858. int i = 0;
  859. if (qeth_check_layer2(card))
  860. return -EPERM;
  861. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  862. /* add strlen for "/<mask>\n" */
  863. entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
  864. spin_lock_irqsave(&card->ip_lock, flags);
  865. list_for_each_entry(ipatoe, &card->ipato.entries, entry){
  866. if (ipatoe->proto != proto)
  867. continue;
  868. /* String must not be longer than PAGE_SIZE. So we check if
  869. * string length gets near PAGE_SIZE. Then we can savely display
  870. * the next IPv6 address (worst case, compared to IPv4) */
  871. if ((PAGE_SIZE - i) <= entry_len)
  872. break;
  873. qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
  874. i += snprintf(buf + i, PAGE_SIZE - i,
  875. "%s/%i\n", addr_str, ipatoe->mask_bits);
  876. }
  877. spin_unlock_irqrestore(&card->ip_lock, flags);
  878. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  879. return i;
  880. }
  881. static ssize_t
  882. qeth_dev_ipato_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  883. {
  884. struct qeth_card *card = dev->driver_data;
  885. if (!card)
  886. return -EINVAL;
  887. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  888. }
  889. static inline int
  890. qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
  891. u8 *addr, int *mask_bits)
  892. {
  893. const char *start, *end;
  894. char *tmp;
  895. char buffer[49] = {0, };
  896. start = buf;
  897. /* get address string */
  898. end = strchr(start, '/');
  899. if (!end){
  900. PRINT_WARN("Invalid format for ipato_addx/delx. "
  901. "Use <ip addr>/<mask bits>\n");
  902. return -EINVAL;
  903. }
  904. strncpy(buffer, start, end - start);
  905. if (qeth_string_to_ipaddr(buffer, proto, addr)){
  906. PRINT_WARN("Invalid IP address format!\n");
  907. return -EINVAL;
  908. }
  909. start = end + 1;
  910. *mask_bits = simple_strtoul(start, &tmp, 10);
  911. return 0;
  912. }
  913. static inline ssize_t
  914. qeth_dev_ipato_add_store(const char *buf, size_t count,
  915. struct qeth_card *card, enum qeth_prot_versions proto)
  916. {
  917. struct qeth_ipato_entry *ipatoe;
  918. u8 addr[16];
  919. int mask_bits;
  920. int rc;
  921. if (qeth_check_layer2(card))
  922. return -EPERM;
  923. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  924. return rc;
  925. if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
  926. PRINT_WARN("No memory to allocate ipato entry\n");
  927. return -ENOMEM;
  928. }
  929. memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
  930. ipatoe->proto = proto;
  931. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
  932. ipatoe->mask_bits = mask_bits;
  933. if ((rc = qeth_add_ipato_entry(card, ipatoe))){
  934. kfree(ipatoe);
  935. return rc;
  936. }
  937. return count;
  938. }
  939. static ssize_t
  940. qeth_dev_ipato_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  941. {
  942. struct qeth_card *card = dev->driver_data;
  943. if (!card)
  944. return -EINVAL;
  945. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  946. }
  947. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  948. qeth_dev_ipato_add4_show,
  949. qeth_dev_ipato_add4_store);
  950. static inline ssize_t
  951. qeth_dev_ipato_del_store(const char *buf, size_t count,
  952. struct qeth_card *card, enum qeth_prot_versions proto)
  953. {
  954. u8 addr[16];
  955. int mask_bits;
  956. int rc;
  957. if (qeth_check_layer2(card))
  958. return -EPERM;
  959. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  960. return rc;
  961. qeth_del_ipato_entry(card, proto, addr, mask_bits);
  962. return count;
  963. }
  964. static ssize_t
  965. qeth_dev_ipato_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  966. {
  967. struct qeth_card *card = dev->driver_data;
  968. if (!card)
  969. return -EINVAL;
  970. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  971. }
  972. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  973. qeth_dev_ipato_del4_store);
  974. #ifdef CONFIG_QETH_IPV6
  975. static ssize_t
  976. qeth_dev_ipato_invert6_show(struct device *dev, struct device_attribute *attr, char *buf)
  977. {
  978. struct qeth_card *card = dev->driver_data;
  979. if (!card)
  980. return -EINVAL;
  981. if (qeth_check_layer2(card))
  982. return -EPERM;
  983. return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
  984. }
  985. static ssize_t
  986. qeth_dev_ipato_invert6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  987. {
  988. struct qeth_card *card = dev->driver_data;
  989. char *tmp;
  990. if (!card)
  991. return -EINVAL;
  992. if (qeth_check_layer2(card))
  993. return -EPERM;
  994. tmp = strsep((char **) &buf, "\n");
  995. if (!strcmp(tmp, "toggle")){
  996. card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
  997. } else if (!strcmp(tmp, "1")){
  998. card->ipato.invert6 = 1;
  999. } else if (!strcmp(tmp, "0")){
  1000. card->ipato.invert6 = 0;
  1001. } else {
  1002. PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
  1003. "this file\n");
  1004. return -EINVAL;
  1005. }
  1006. return count;
  1007. }
  1008. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  1009. qeth_dev_ipato_invert6_show,
  1010. qeth_dev_ipato_invert6_store);
  1011. static ssize_t
  1012. qeth_dev_ipato_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1013. {
  1014. struct qeth_card *card = dev->driver_data;
  1015. if (!card)
  1016. return -EINVAL;
  1017. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  1018. }
  1019. static ssize_t
  1020. qeth_dev_ipato_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1021. {
  1022. struct qeth_card *card = dev->driver_data;
  1023. if (!card)
  1024. return -EINVAL;
  1025. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  1026. }
  1027. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  1028. qeth_dev_ipato_add6_show,
  1029. qeth_dev_ipato_add6_store);
  1030. static ssize_t
  1031. qeth_dev_ipato_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1032. {
  1033. struct qeth_card *card = dev->driver_data;
  1034. if (!card)
  1035. return -EINVAL;
  1036. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  1037. }
  1038. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  1039. qeth_dev_ipato_del6_store);
  1040. #endif /* CONFIG_QETH_IPV6 */
  1041. static struct device_attribute * qeth_ipato_device_attrs[] = {
  1042. &dev_attr_ipato_enable,
  1043. &dev_attr_ipato_invert4,
  1044. &dev_attr_ipato_add4,
  1045. &dev_attr_ipato_del4,
  1046. #ifdef CONFIG_QETH_IPV6
  1047. &dev_attr_ipato_invert6,
  1048. &dev_attr_ipato_add6,
  1049. &dev_attr_ipato_del6,
  1050. #endif
  1051. NULL,
  1052. };
  1053. static struct attribute_group qeth_device_ipato_group = {
  1054. .name = "ipa_takeover",
  1055. .attrs = (struct attribute **)qeth_ipato_device_attrs,
  1056. };
  1057. static inline ssize_t
  1058. qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
  1059. enum qeth_prot_versions proto)
  1060. {
  1061. struct qeth_ipaddr *ipaddr;
  1062. char addr_str[40];
  1063. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1064. unsigned long flags;
  1065. int i = 0;
  1066. if (qeth_check_layer2(card))
  1067. return -EPERM;
  1068. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1069. entry_len += 2; /* \n + terminator */
  1070. spin_lock_irqsave(&card->ip_lock, flags);
  1071. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1072. if (ipaddr->proto != proto)
  1073. continue;
  1074. if (ipaddr->type != QETH_IP_TYPE_VIPA)
  1075. continue;
  1076. /* String must not be longer than PAGE_SIZE. So we check if
  1077. * string length gets near PAGE_SIZE. Then we can savely display
  1078. * the next IPv6 address (worst case, compared to IPv4) */
  1079. if ((PAGE_SIZE - i) <= entry_len)
  1080. break;
  1081. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1082. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1083. }
  1084. spin_unlock_irqrestore(&card->ip_lock, flags);
  1085. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1086. return i;
  1087. }
  1088. static ssize_t
  1089. qeth_dev_vipa_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1090. {
  1091. struct qeth_card *card = dev->driver_data;
  1092. if (!card)
  1093. return -EINVAL;
  1094. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
  1095. }
  1096. static inline int
  1097. qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
  1098. u8 *addr)
  1099. {
  1100. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1101. PRINT_WARN("Invalid IP address format!\n");
  1102. return -EINVAL;
  1103. }
  1104. return 0;
  1105. }
  1106. static inline ssize_t
  1107. qeth_dev_vipa_add_store(const char *buf, size_t count,
  1108. struct qeth_card *card, enum qeth_prot_versions proto)
  1109. {
  1110. u8 addr[16] = {0, };
  1111. int rc;
  1112. if (qeth_check_layer2(card))
  1113. return -EPERM;
  1114. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1115. return rc;
  1116. if ((rc = qeth_add_vipa(card, proto, addr)))
  1117. return rc;
  1118. return count;
  1119. }
  1120. static ssize_t
  1121. qeth_dev_vipa_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1122. {
  1123. struct qeth_card *card = dev->driver_data;
  1124. if (!card)
  1125. return -EINVAL;
  1126. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
  1127. }
  1128. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  1129. qeth_dev_vipa_add4_show,
  1130. qeth_dev_vipa_add4_store);
  1131. static inline ssize_t
  1132. qeth_dev_vipa_del_store(const char *buf, size_t count,
  1133. struct qeth_card *card, enum qeth_prot_versions proto)
  1134. {
  1135. u8 addr[16];
  1136. int rc;
  1137. if (qeth_check_layer2(card))
  1138. return -EPERM;
  1139. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1140. return rc;
  1141. qeth_del_vipa(card, proto, addr);
  1142. return count;
  1143. }
  1144. static ssize_t
  1145. qeth_dev_vipa_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1146. {
  1147. struct qeth_card *card = dev->driver_data;
  1148. if (!card)
  1149. return -EINVAL;
  1150. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
  1151. }
  1152. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  1153. qeth_dev_vipa_del4_store);
  1154. #ifdef CONFIG_QETH_IPV6
  1155. static ssize_t
  1156. qeth_dev_vipa_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1157. {
  1158. struct qeth_card *card = dev->driver_data;
  1159. if (!card)
  1160. return -EINVAL;
  1161. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
  1162. }
  1163. static ssize_t
  1164. qeth_dev_vipa_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1165. {
  1166. struct qeth_card *card = dev->driver_data;
  1167. if (!card)
  1168. return -EINVAL;
  1169. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
  1170. }
  1171. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  1172. qeth_dev_vipa_add6_show,
  1173. qeth_dev_vipa_add6_store);
  1174. static ssize_t
  1175. qeth_dev_vipa_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1176. {
  1177. struct qeth_card *card = dev->driver_data;
  1178. if (!card)
  1179. return -EINVAL;
  1180. if (qeth_check_layer2(card))
  1181. return -EPERM;
  1182. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
  1183. }
  1184. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  1185. qeth_dev_vipa_del6_store);
  1186. #endif /* CONFIG_QETH_IPV6 */
  1187. static struct device_attribute * qeth_vipa_device_attrs[] = {
  1188. &dev_attr_vipa_add4,
  1189. &dev_attr_vipa_del4,
  1190. #ifdef CONFIG_QETH_IPV6
  1191. &dev_attr_vipa_add6,
  1192. &dev_attr_vipa_del6,
  1193. #endif
  1194. NULL,
  1195. };
  1196. static struct attribute_group qeth_device_vipa_group = {
  1197. .name = "vipa",
  1198. .attrs = (struct attribute **)qeth_vipa_device_attrs,
  1199. };
  1200. static inline ssize_t
  1201. qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
  1202. enum qeth_prot_versions proto)
  1203. {
  1204. struct qeth_ipaddr *ipaddr;
  1205. char addr_str[40];
  1206. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1207. unsigned long flags;
  1208. int i = 0;
  1209. if (qeth_check_layer2(card))
  1210. return -EPERM;
  1211. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1212. entry_len += 2; /* \n + terminator */
  1213. spin_lock_irqsave(&card->ip_lock, flags);
  1214. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1215. if (ipaddr->proto != proto)
  1216. continue;
  1217. if (ipaddr->type != QETH_IP_TYPE_RXIP)
  1218. continue;
  1219. /* String must not be longer than PAGE_SIZE. So we check if
  1220. * string length gets near PAGE_SIZE. Then we can savely display
  1221. * the next IPv6 address (worst case, compared to IPv4) */
  1222. if ((PAGE_SIZE - i) <= entry_len)
  1223. break;
  1224. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1225. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1226. }
  1227. spin_unlock_irqrestore(&card->ip_lock, flags);
  1228. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1229. return i;
  1230. }
  1231. static ssize_t
  1232. qeth_dev_rxip_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1233. {
  1234. struct qeth_card *card = dev->driver_data;
  1235. if (!card)
  1236. return -EINVAL;
  1237. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
  1238. }
  1239. static inline int
  1240. qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
  1241. u8 *addr)
  1242. {
  1243. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1244. PRINT_WARN("Invalid IP address format!\n");
  1245. return -EINVAL;
  1246. }
  1247. return 0;
  1248. }
  1249. static inline ssize_t
  1250. qeth_dev_rxip_add_store(const char *buf, size_t count,
  1251. struct qeth_card *card, enum qeth_prot_versions proto)
  1252. {
  1253. u8 addr[16] = {0, };
  1254. int rc;
  1255. if (qeth_check_layer2(card))
  1256. return -EPERM;
  1257. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1258. return rc;
  1259. if ((rc = qeth_add_rxip(card, proto, addr)))
  1260. return rc;
  1261. return count;
  1262. }
  1263. static ssize_t
  1264. qeth_dev_rxip_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1265. {
  1266. struct qeth_card *card = dev->driver_data;
  1267. if (!card)
  1268. return -EINVAL;
  1269. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
  1270. }
  1271. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  1272. qeth_dev_rxip_add4_show,
  1273. qeth_dev_rxip_add4_store);
  1274. static inline ssize_t
  1275. qeth_dev_rxip_del_store(const char *buf, size_t count,
  1276. struct qeth_card *card, enum qeth_prot_versions proto)
  1277. {
  1278. u8 addr[16];
  1279. int rc;
  1280. if (qeth_check_layer2(card))
  1281. return -EPERM;
  1282. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1283. return rc;
  1284. qeth_del_rxip(card, proto, addr);
  1285. return count;
  1286. }
  1287. static ssize_t
  1288. qeth_dev_rxip_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1289. {
  1290. struct qeth_card *card = dev->driver_data;
  1291. if (!card)
  1292. return -EINVAL;
  1293. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
  1294. }
  1295. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  1296. qeth_dev_rxip_del4_store);
  1297. #ifdef CONFIG_QETH_IPV6
  1298. static ssize_t
  1299. qeth_dev_rxip_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1300. {
  1301. struct qeth_card *card = dev->driver_data;
  1302. if (!card)
  1303. return -EINVAL;
  1304. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
  1305. }
  1306. static ssize_t
  1307. qeth_dev_rxip_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1308. {
  1309. struct qeth_card *card = dev->driver_data;
  1310. if (!card)
  1311. return -EINVAL;
  1312. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
  1313. }
  1314. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  1315. qeth_dev_rxip_add6_show,
  1316. qeth_dev_rxip_add6_store);
  1317. static ssize_t
  1318. qeth_dev_rxip_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1319. {
  1320. struct qeth_card *card = dev->driver_data;
  1321. if (!card)
  1322. return -EINVAL;
  1323. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
  1324. }
  1325. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  1326. qeth_dev_rxip_del6_store);
  1327. #endif /* CONFIG_QETH_IPV6 */
  1328. static struct device_attribute * qeth_rxip_device_attrs[] = {
  1329. &dev_attr_rxip_add4,
  1330. &dev_attr_rxip_del4,
  1331. #ifdef CONFIG_QETH_IPV6
  1332. &dev_attr_rxip_add6,
  1333. &dev_attr_rxip_del6,
  1334. #endif
  1335. NULL,
  1336. };
  1337. static struct attribute_group qeth_device_rxip_group = {
  1338. .name = "rxip",
  1339. .attrs = (struct attribute **)qeth_rxip_device_attrs,
  1340. };
  1341. int
  1342. qeth_create_device_attributes(struct device *dev)
  1343. {
  1344. int ret;
  1345. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
  1346. return ret;
  1347. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
  1348. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1349. return ret;
  1350. }
  1351. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
  1352. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1353. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1354. return ret;
  1355. }
  1356. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
  1357. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1358. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1359. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1360. }
  1361. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group)))
  1362. return ret;
  1363. return ret;
  1364. }
  1365. void
  1366. qeth_remove_device_attributes(struct device *dev)
  1367. {
  1368. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1369. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1370. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1371. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  1372. sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
  1373. }
  1374. /**********************/
  1375. /* DRIVER ATTRIBUTES */
  1376. /**********************/
  1377. static ssize_t
  1378. qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
  1379. size_t count)
  1380. {
  1381. const char *start, *end;
  1382. char bus_ids[3][BUS_ID_SIZE], *argv[3];
  1383. int i;
  1384. int err;
  1385. start = buf;
  1386. for (i = 0; i < 3; i++) {
  1387. static const char delim[] = { ',', ',', '\n' };
  1388. int len;
  1389. if (!(end = strchr(start, delim[i])))
  1390. return -EINVAL;
  1391. len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
  1392. strncpy(bus_ids[i], start, len);
  1393. bus_ids[i][len] = '\0';
  1394. start = end + 1;
  1395. argv[i] = bus_ids[i];
  1396. }
  1397. err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
  1398. &qeth_ccw_driver, 3, argv);
  1399. if (err)
  1400. return err;
  1401. else
  1402. return count;
  1403. }
  1404. static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
  1405. static ssize_t
  1406. qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
  1407. size_t count)
  1408. {
  1409. int rc;
  1410. int signum;
  1411. char *tmp, *tmp2;
  1412. tmp = strsep((char **) &buf, "\n");
  1413. if (!strncmp(tmp, "unregister", 10)){
  1414. if ((rc = qeth_notifier_unregister(current)))
  1415. return rc;
  1416. return count;
  1417. }
  1418. signum = simple_strtoul(tmp, &tmp2, 10);
  1419. if ((signum < 0) || (signum > 32)){
  1420. PRINT_WARN("Signal number %d is out of range\n", signum);
  1421. return -EINVAL;
  1422. }
  1423. if ((rc = qeth_notifier_register(current, signum)))
  1424. return rc;
  1425. return count;
  1426. }
  1427. static DRIVER_ATTR(notifier_register, 0200, 0,
  1428. qeth_driver_notifier_register_store);
  1429. int
  1430. qeth_create_driver_attributes(void)
  1431. {
  1432. int rc;
  1433. if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
  1434. &driver_attr_group)))
  1435. return rc;
  1436. return driver_create_file(&qeth_ccwgroup_driver.driver,
  1437. &driver_attr_notifier_register);
  1438. }
  1439. void
  1440. qeth_remove_driver_attributes(void)
  1441. {
  1442. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1443. &driver_attr_group);
  1444. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1445. &driver_attr_notifier_register);
  1446. }