qeth_sys.c 44 KB

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