qeth_sys.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  1. /*
  2. *
  3. * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.53 $)
  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.53 $";
  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. if ((rc = qeth_set_large_send(card, type)))
  645. return rc;
  646. return count;
  647. }
  648. static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
  649. qeth_dev_large_send_store);
  650. static ssize_t
  651. qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value )
  652. {
  653. if (!card)
  654. return -EINVAL;
  655. return sprintf(buf, "%i\n", value);
  656. }
  657. static ssize_t
  658. qeth_dev_blkt_store(struct qeth_card *card, const char *buf, size_t count,
  659. int *value, int max_value)
  660. {
  661. char *tmp;
  662. int i;
  663. if (!card)
  664. return -EINVAL;
  665. if ((card->state != CARD_STATE_DOWN) &&
  666. (card->state != CARD_STATE_RECOVER))
  667. return -EPERM;
  668. i = simple_strtoul(buf, &tmp, 10);
  669. if (i <= max_value) {
  670. *value = i;
  671. } else {
  672. PRINT_WARN("blkt total time: write values between"
  673. " 0 and %d to this file!\n", max_value);
  674. return -EINVAL;
  675. }
  676. return count;
  677. }
  678. static ssize_t
  679. qeth_dev_blkt_total_show(struct device *dev, struct device_attribute *attr, char *buf)
  680. {
  681. struct qeth_card *card = dev->driver_data;
  682. return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
  683. }
  684. static ssize_t
  685. qeth_dev_blkt_total_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  686. {
  687. struct qeth_card *card = dev->driver_data;
  688. return qeth_dev_blkt_store(card, buf, count,
  689. &card->info.blkt.time_total,1000);
  690. }
  691. static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
  692. qeth_dev_blkt_total_store);
  693. static ssize_t
  694. qeth_dev_blkt_inter_show(struct device *dev, struct device_attribute *attr, char *buf)
  695. {
  696. struct qeth_card *card = dev->driver_data;
  697. return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
  698. }
  699. static ssize_t
  700. qeth_dev_blkt_inter_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  701. {
  702. struct qeth_card *card = dev->driver_data;
  703. return qeth_dev_blkt_store(card, buf, count,
  704. &card->info.blkt.inter_packet,100);
  705. }
  706. static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
  707. qeth_dev_blkt_inter_store);
  708. static ssize_t
  709. qeth_dev_blkt_inter_jumbo_show(struct device *dev, struct device_attribute *attr, char *buf)
  710. {
  711. struct qeth_card *card = dev->driver_data;
  712. return qeth_dev_blkt_show(buf, card,
  713. card->info.blkt.inter_packet_jumbo);
  714. }
  715. static ssize_t
  716. qeth_dev_blkt_inter_jumbo_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  717. {
  718. struct qeth_card *card = dev->driver_data;
  719. return qeth_dev_blkt_store(card, buf, count,
  720. &card->info.blkt.inter_packet_jumbo,100);
  721. }
  722. static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
  723. qeth_dev_blkt_inter_jumbo_store);
  724. static struct device_attribute * qeth_blkt_device_attrs[] = {
  725. &dev_attr_total,
  726. &dev_attr_inter,
  727. &dev_attr_inter_jumbo,
  728. NULL,
  729. };
  730. static struct attribute_group qeth_device_blkt_group = {
  731. .name = "blkt",
  732. .attrs = (struct attribute **)qeth_blkt_device_attrs,
  733. };
  734. static struct device_attribute * qeth_device_attrs[] = {
  735. &dev_attr_state,
  736. &dev_attr_chpid,
  737. &dev_attr_if_name,
  738. &dev_attr_card_type,
  739. &dev_attr_portno,
  740. &dev_attr_portname,
  741. &dev_attr_checksumming,
  742. &dev_attr_priority_queueing,
  743. &dev_attr_buffer_count,
  744. &dev_attr_route4,
  745. #ifdef CONFIG_QETH_IPV6
  746. &dev_attr_route6,
  747. #endif
  748. &dev_attr_add_hhlen,
  749. &dev_attr_fake_ll,
  750. &dev_attr_fake_broadcast,
  751. &dev_attr_recover,
  752. &dev_attr_broadcast_mode,
  753. &dev_attr_canonical_macaddr,
  754. &dev_attr_layer2,
  755. &dev_attr_large_send,
  756. NULL,
  757. };
  758. static struct attribute_group qeth_device_attr_group = {
  759. .attrs = (struct attribute **)qeth_device_attrs,
  760. };
  761. #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
  762. struct device_attribute dev_attr_##_id = { \
  763. .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
  764. .show = _show, \
  765. .store = _store, \
  766. };
  767. int
  768. qeth_check_layer2(struct qeth_card *card)
  769. {
  770. if (card->options.layer2)
  771. return -EPERM;
  772. return 0;
  773. }
  774. static ssize_t
  775. qeth_dev_ipato_enable_show(struct device *dev, struct device_attribute *attr, char *buf)
  776. {
  777. struct qeth_card *card = dev->driver_data;
  778. if (!card)
  779. return -EINVAL;
  780. if (qeth_check_layer2(card))
  781. return -EPERM;
  782. return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
  783. }
  784. static ssize_t
  785. qeth_dev_ipato_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  786. {
  787. struct qeth_card *card = dev->driver_data;
  788. char *tmp;
  789. if (!card)
  790. return -EINVAL;
  791. if ((card->state != CARD_STATE_DOWN) &&
  792. (card->state != CARD_STATE_RECOVER))
  793. return -EPERM;
  794. if (qeth_check_layer2(card))
  795. return -EPERM;
  796. tmp = strsep((char **) &buf, "\n");
  797. if (!strcmp(tmp, "toggle")){
  798. card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
  799. } else if (!strcmp(tmp, "1")){
  800. card->ipato.enabled = 1;
  801. } else if (!strcmp(tmp, "0")){
  802. card->ipato.enabled = 0;
  803. } else {
  804. PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
  805. "this file\n");
  806. return -EINVAL;
  807. }
  808. return count;
  809. }
  810. static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
  811. qeth_dev_ipato_enable_show,
  812. qeth_dev_ipato_enable_store);
  813. static ssize_t
  814. qeth_dev_ipato_invert4_show(struct device *dev, struct device_attribute *attr, char *buf)
  815. {
  816. struct qeth_card *card = dev->driver_data;
  817. if (!card)
  818. return -EINVAL;
  819. if (qeth_check_layer2(card))
  820. return -EPERM;
  821. return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
  822. }
  823. static ssize_t
  824. qeth_dev_ipato_invert4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  825. {
  826. struct qeth_card *card = dev->driver_data;
  827. char *tmp;
  828. if (!card)
  829. return -EINVAL;
  830. if (qeth_check_layer2(card))
  831. return -EPERM;
  832. tmp = strsep((char **) &buf, "\n");
  833. if (!strcmp(tmp, "toggle")){
  834. card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
  835. } else if (!strcmp(tmp, "1")){
  836. card->ipato.invert4 = 1;
  837. } else if (!strcmp(tmp, "0")){
  838. card->ipato.invert4 = 0;
  839. } else {
  840. PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
  841. "this file\n");
  842. return -EINVAL;
  843. }
  844. return count;
  845. }
  846. static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
  847. qeth_dev_ipato_invert4_show,
  848. qeth_dev_ipato_invert4_store);
  849. static inline ssize_t
  850. qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
  851. enum qeth_prot_versions proto)
  852. {
  853. struct qeth_ipato_entry *ipatoe;
  854. unsigned long flags;
  855. char addr_str[40];
  856. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  857. int i = 0;
  858. if (qeth_check_layer2(card))
  859. return -EPERM;
  860. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  861. /* add strlen for "/<mask>\n" */
  862. entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
  863. spin_lock_irqsave(&card->ip_lock, flags);
  864. list_for_each_entry(ipatoe, &card->ipato.entries, entry){
  865. if (ipatoe->proto != proto)
  866. continue;
  867. /* String must not be longer than PAGE_SIZE. So we check if
  868. * string length gets near PAGE_SIZE. Then we can savely display
  869. * the next IPv6 address (worst case, compared to IPv4) */
  870. if ((PAGE_SIZE - i) <= entry_len)
  871. break;
  872. qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
  873. i += snprintf(buf + i, PAGE_SIZE - i,
  874. "%s/%i\n", addr_str, ipatoe->mask_bits);
  875. }
  876. spin_unlock_irqrestore(&card->ip_lock, flags);
  877. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  878. return i;
  879. }
  880. static ssize_t
  881. qeth_dev_ipato_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  882. {
  883. struct qeth_card *card = dev->driver_data;
  884. if (!card)
  885. return -EINVAL;
  886. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  887. }
  888. static inline int
  889. qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
  890. u8 *addr, int *mask_bits)
  891. {
  892. const char *start, *end;
  893. char *tmp;
  894. char buffer[49] = {0, };
  895. start = buf;
  896. /* get address string */
  897. end = strchr(start, '/');
  898. if (!end){
  899. PRINT_WARN("Invalid format for ipato_addx/delx. "
  900. "Use <ip addr>/<mask bits>\n");
  901. return -EINVAL;
  902. }
  903. strncpy(buffer, start, end - start);
  904. if (qeth_string_to_ipaddr(buffer, proto, addr)){
  905. PRINT_WARN("Invalid IP address format!\n");
  906. return -EINVAL;
  907. }
  908. start = end + 1;
  909. *mask_bits = simple_strtoul(start, &tmp, 10);
  910. return 0;
  911. }
  912. static inline ssize_t
  913. qeth_dev_ipato_add_store(const char *buf, size_t count,
  914. struct qeth_card *card, enum qeth_prot_versions proto)
  915. {
  916. struct qeth_ipato_entry *ipatoe;
  917. u8 addr[16];
  918. int mask_bits;
  919. int rc;
  920. if (qeth_check_layer2(card))
  921. return -EPERM;
  922. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  923. return rc;
  924. if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
  925. PRINT_WARN("No memory to allocate ipato entry\n");
  926. return -ENOMEM;
  927. }
  928. memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
  929. ipatoe->proto = proto;
  930. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
  931. ipatoe->mask_bits = mask_bits;
  932. if ((rc = qeth_add_ipato_entry(card, ipatoe))){
  933. kfree(ipatoe);
  934. return rc;
  935. }
  936. return count;
  937. }
  938. static ssize_t
  939. qeth_dev_ipato_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  940. {
  941. struct qeth_card *card = dev->driver_data;
  942. if (!card)
  943. return -EINVAL;
  944. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  945. }
  946. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  947. qeth_dev_ipato_add4_show,
  948. qeth_dev_ipato_add4_store);
  949. static inline ssize_t
  950. qeth_dev_ipato_del_store(const char *buf, size_t count,
  951. struct qeth_card *card, enum qeth_prot_versions proto)
  952. {
  953. u8 addr[16];
  954. int mask_bits;
  955. int rc;
  956. if (qeth_check_layer2(card))
  957. return -EPERM;
  958. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  959. return rc;
  960. qeth_del_ipato_entry(card, proto, addr, mask_bits);
  961. return count;
  962. }
  963. static ssize_t
  964. qeth_dev_ipato_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  965. {
  966. struct qeth_card *card = dev->driver_data;
  967. if (!card)
  968. return -EINVAL;
  969. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  970. }
  971. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  972. qeth_dev_ipato_del4_store);
  973. #ifdef CONFIG_QETH_IPV6
  974. static ssize_t
  975. qeth_dev_ipato_invert6_show(struct device *dev, struct device_attribute *attr, char *buf)
  976. {
  977. struct qeth_card *card = dev->driver_data;
  978. if (!card)
  979. return -EINVAL;
  980. if (qeth_check_layer2(card))
  981. return -EPERM;
  982. return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
  983. }
  984. static ssize_t
  985. qeth_dev_ipato_invert6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  986. {
  987. struct qeth_card *card = dev->driver_data;
  988. char *tmp;
  989. if (!card)
  990. return -EINVAL;
  991. if (qeth_check_layer2(card))
  992. return -EPERM;
  993. tmp = strsep((char **) &buf, "\n");
  994. if (!strcmp(tmp, "toggle")){
  995. card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
  996. } else if (!strcmp(tmp, "1")){
  997. card->ipato.invert6 = 1;
  998. } else if (!strcmp(tmp, "0")){
  999. card->ipato.invert6 = 0;
  1000. } else {
  1001. PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
  1002. "this file\n");
  1003. return -EINVAL;
  1004. }
  1005. return count;
  1006. }
  1007. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  1008. qeth_dev_ipato_invert6_show,
  1009. qeth_dev_ipato_invert6_store);
  1010. static ssize_t
  1011. qeth_dev_ipato_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1012. {
  1013. struct qeth_card *card = dev->driver_data;
  1014. if (!card)
  1015. return -EINVAL;
  1016. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  1017. }
  1018. static ssize_t
  1019. qeth_dev_ipato_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1020. {
  1021. struct qeth_card *card = dev->driver_data;
  1022. if (!card)
  1023. return -EINVAL;
  1024. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  1025. }
  1026. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  1027. qeth_dev_ipato_add6_show,
  1028. qeth_dev_ipato_add6_store);
  1029. static ssize_t
  1030. qeth_dev_ipato_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1031. {
  1032. struct qeth_card *card = dev->driver_data;
  1033. if (!card)
  1034. return -EINVAL;
  1035. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  1036. }
  1037. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  1038. qeth_dev_ipato_del6_store);
  1039. #endif /* CONFIG_QETH_IPV6 */
  1040. static struct device_attribute * qeth_ipato_device_attrs[] = {
  1041. &dev_attr_ipato_enable,
  1042. &dev_attr_ipato_invert4,
  1043. &dev_attr_ipato_add4,
  1044. &dev_attr_ipato_del4,
  1045. #ifdef CONFIG_QETH_IPV6
  1046. &dev_attr_ipato_invert6,
  1047. &dev_attr_ipato_add6,
  1048. &dev_attr_ipato_del6,
  1049. #endif
  1050. NULL,
  1051. };
  1052. static struct attribute_group qeth_device_ipato_group = {
  1053. .name = "ipa_takeover",
  1054. .attrs = (struct attribute **)qeth_ipato_device_attrs,
  1055. };
  1056. static inline ssize_t
  1057. qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
  1058. enum qeth_prot_versions proto)
  1059. {
  1060. struct qeth_ipaddr *ipaddr;
  1061. char addr_str[40];
  1062. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1063. unsigned long flags;
  1064. int i = 0;
  1065. if (qeth_check_layer2(card))
  1066. return -EPERM;
  1067. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1068. entry_len += 2; /* \n + terminator */
  1069. spin_lock_irqsave(&card->ip_lock, flags);
  1070. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1071. if (ipaddr->proto != proto)
  1072. continue;
  1073. if (ipaddr->type != QETH_IP_TYPE_VIPA)
  1074. continue;
  1075. /* String must not be longer than PAGE_SIZE. So we check if
  1076. * string length gets near PAGE_SIZE. Then we can savely display
  1077. * the next IPv6 address (worst case, compared to IPv4) */
  1078. if ((PAGE_SIZE - i) <= entry_len)
  1079. break;
  1080. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1081. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1082. }
  1083. spin_unlock_irqrestore(&card->ip_lock, flags);
  1084. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1085. return i;
  1086. }
  1087. static ssize_t
  1088. qeth_dev_vipa_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1089. {
  1090. struct qeth_card *card = dev->driver_data;
  1091. if (!card)
  1092. return -EINVAL;
  1093. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
  1094. }
  1095. static inline int
  1096. qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
  1097. u8 *addr)
  1098. {
  1099. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1100. PRINT_WARN("Invalid IP address format!\n");
  1101. return -EINVAL;
  1102. }
  1103. return 0;
  1104. }
  1105. static inline ssize_t
  1106. qeth_dev_vipa_add_store(const char *buf, size_t count,
  1107. struct qeth_card *card, enum qeth_prot_versions proto)
  1108. {
  1109. u8 addr[16] = {0, };
  1110. int rc;
  1111. if (qeth_check_layer2(card))
  1112. return -EPERM;
  1113. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1114. return rc;
  1115. if ((rc = qeth_add_vipa(card, proto, addr)))
  1116. return rc;
  1117. return count;
  1118. }
  1119. static ssize_t
  1120. qeth_dev_vipa_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1121. {
  1122. struct qeth_card *card = dev->driver_data;
  1123. if (!card)
  1124. return -EINVAL;
  1125. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
  1126. }
  1127. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  1128. qeth_dev_vipa_add4_show,
  1129. qeth_dev_vipa_add4_store);
  1130. static inline ssize_t
  1131. qeth_dev_vipa_del_store(const char *buf, size_t count,
  1132. struct qeth_card *card, enum qeth_prot_versions proto)
  1133. {
  1134. u8 addr[16];
  1135. int rc;
  1136. if (qeth_check_layer2(card))
  1137. return -EPERM;
  1138. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1139. return rc;
  1140. qeth_del_vipa(card, proto, addr);
  1141. return count;
  1142. }
  1143. static ssize_t
  1144. qeth_dev_vipa_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1145. {
  1146. struct qeth_card *card = dev->driver_data;
  1147. if (!card)
  1148. return -EINVAL;
  1149. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
  1150. }
  1151. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  1152. qeth_dev_vipa_del4_store);
  1153. #ifdef CONFIG_QETH_IPV6
  1154. static ssize_t
  1155. qeth_dev_vipa_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1156. {
  1157. struct qeth_card *card = dev->driver_data;
  1158. if (!card)
  1159. return -EINVAL;
  1160. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
  1161. }
  1162. static ssize_t
  1163. qeth_dev_vipa_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1164. {
  1165. struct qeth_card *card = dev->driver_data;
  1166. if (!card)
  1167. return -EINVAL;
  1168. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
  1169. }
  1170. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  1171. qeth_dev_vipa_add6_show,
  1172. qeth_dev_vipa_add6_store);
  1173. static ssize_t
  1174. qeth_dev_vipa_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1175. {
  1176. struct qeth_card *card = dev->driver_data;
  1177. if (!card)
  1178. return -EINVAL;
  1179. if (qeth_check_layer2(card))
  1180. return -EPERM;
  1181. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
  1182. }
  1183. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  1184. qeth_dev_vipa_del6_store);
  1185. #endif /* CONFIG_QETH_IPV6 */
  1186. static struct device_attribute * qeth_vipa_device_attrs[] = {
  1187. &dev_attr_vipa_add4,
  1188. &dev_attr_vipa_del4,
  1189. #ifdef CONFIG_QETH_IPV6
  1190. &dev_attr_vipa_add6,
  1191. &dev_attr_vipa_del6,
  1192. #endif
  1193. NULL,
  1194. };
  1195. static struct attribute_group qeth_device_vipa_group = {
  1196. .name = "vipa",
  1197. .attrs = (struct attribute **)qeth_vipa_device_attrs,
  1198. };
  1199. static inline ssize_t
  1200. qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
  1201. enum qeth_prot_versions proto)
  1202. {
  1203. struct qeth_ipaddr *ipaddr;
  1204. char addr_str[40];
  1205. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1206. unsigned long flags;
  1207. int i = 0;
  1208. if (qeth_check_layer2(card))
  1209. return -EPERM;
  1210. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1211. entry_len += 2; /* \n + terminator */
  1212. spin_lock_irqsave(&card->ip_lock, flags);
  1213. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1214. if (ipaddr->proto != proto)
  1215. continue;
  1216. if (ipaddr->type != QETH_IP_TYPE_RXIP)
  1217. continue;
  1218. /* String must not be longer than PAGE_SIZE. So we check if
  1219. * string length gets near PAGE_SIZE. Then we can savely display
  1220. * the next IPv6 address (worst case, compared to IPv4) */
  1221. if ((PAGE_SIZE - i) <= entry_len)
  1222. break;
  1223. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1224. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1225. }
  1226. spin_unlock_irqrestore(&card->ip_lock, flags);
  1227. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1228. return i;
  1229. }
  1230. static ssize_t
  1231. qeth_dev_rxip_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1232. {
  1233. struct qeth_card *card = dev->driver_data;
  1234. if (!card)
  1235. return -EINVAL;
  1236. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
  1237. }
  1238. static inline int
  1239. qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
  1240. u8 *addr)
  1241. {
  1242. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1243. PRINT_WARN("Invalid IP address format!\n");
  1244. return -EINVAL;
  1245. }
  1246. return 0;
  1247. }
  1248. static inline ssize_t
  1249. qeth_dev_rxip_add_store(const char *buf, size_t count,
  1250. struct qeth_card *card, enum qeth_prot_versions proto)
  1251. {
  1252. u8 addr[16] = {0, };
  1253. int rc;
  1254. if (qeth_check_layer2(card))
  1255. return -EPERM;
  1256. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1257. return rc;
  1258. if ((rc = qeth_add_rxip(card, proto, addr)))
  1259. return rc;
  1260. return count;
  1261. }
  1262. static ssize_t
  1263. qeth_dev_rxip_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1264. {
  1265. struct qeth_card *card = dev->driver_data;
  1266. if (!card)
  1267. return -EINVAL;
  1268. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
  1269. }
  1270. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  1271. qeth_dev_rxip_add4_show,
  1272. qeth_dev_rxip_add4_store);
  1273. static inline ssize_t
  1274. qeth_dev_rxip_del_store(const char *buf, size_t count,
  1275. struct qeth_card *card, enum qeth_prot_versions proto)
  1276. {
  1277. u8 addr[16];
  1278. int rc;
  1279. if (qeth_check_layer2(card))
  1280. return -EPERM;
  1281. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1282. return rc;
  1283. qeth_del_rxip(card, proto, addr);
  1284. return count;
  1285. }
  1286. static ssize_t
  1287. qeth_dev_rxip_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1288. {
  1289. struct qeth_card *card = dev->driver_data;
  1290. if (!card)
  1291. return -EINVAL;
  1292. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
  1293. }
  1294. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  1295. qeth_dev_rxip_del4_store);
  1296. #ifdef CONFIG_QETH_IPV6
  1297. static ssize_t
  1298. qeth_dev_rxip_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1299. {
  1300. struct qeth_card *card = dev->driver_data;
  1301. if (!card)
  1302. return -EINVAL;
  1303. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
  1304. }
  1305. static ssize_t
  1306. qeth_dev_rxip_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1307. {
  1308. struct qeth_card *card = dev->driver_data;
  1309. if (!card)
  1310. return -EINVAL;
  1311. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
  1312. }
  1313. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  1314. qeth_dev_rxip_add6_show,
  1315. qeth_dev_rxip_add6_store);
  1316. static ssize_t
  1317. qeth_dev_rxip_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1318. {
  1319. struct qeth_card *card = dev->driver_data;
  1320. if (!card)
  1321. return -EINVAL;
  1322. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
  1323. }
  1324. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  1325. qeth_dev_rxip_del6_store);
  1326. #endif /* CONFIG_QETH_IPV6 */
  1327. static struct device_attribute * qeth_rxip_device_attrs[] = {
  1328. &dev_attr_rxip_add4,
  1329. &dev_attr_rxip_del4,
  1330. #ifdef CONFIG_QETH_IPV6
  1331. &dev_attr_rxip_add6,
  1332. &dev_attr_rxip_del6,
  1333. #endif
  1334. NULL,
  1335. };
  1336. static struct attribute_group qeth_device_rxip_group = {
  1337. .name = "rxip",
  1338. .attrs = (struct attribute **)qeth_rxip_device_attrs,
  1339. };
  1340. int
  1341. qeth_create_device_attributes(struct device *dev)
  1342. {
  1343. int ret;
  1344. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
  1345. return ret;
  1346. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
  1347. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1348. return ret;
  1349. }
  1350. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
  1351. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1352. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1353. return ret;
  1354. }
  1355. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
  1356. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1357. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1358. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1359. }
  1360. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group)))
  1361. return ret;
  1362. return ret;
  1363. }
  1364. void
  1365. qeth_remove_device_attributes(struct device *dev)
  1366. {
  1367. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1368. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1369. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1370. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  1371. sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
  1372. }
  1373. /**********************/
  1374. /* DRIVER ATTRIBUTES */
  1375. /**********************/
  1376. static ssize_t
  1377. qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
  1378. size_t count)
  1379. {
  1380. const char *start, *end;
  1381. char bus_ids[3][BUS_ID_SIZE], *argv[3];
  1382. int i;
  1383. int err;
  1384. start = buf;
  1385. for (i = 0; i < 3; i++) {
  1386. static const char delim[] = { ',', ',', '\n' };
  1387. int len;
  1388. if (!(end = strchr(start, delim[i])))
  1389. return -EINVAL;
  1390. len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
  1391. strncpy(bus_ids[i], start, len);
  1392. bus_ids[i][len] = '\0';
  1393. start = end + 1;
  1394. argv[i] = bus_ids[i];
  1395. }
  1396. err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
  1397. &qeth_ccw_driver, 3, argv);
  1398. if (err)
  1399. return err;
  1400. else
  1401. return count;
  1402. }
  1403. static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
  1404. static ssize_t
  1405. qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
  1406. size_t count)
  1407. {
  1408. int rc;
  1409. int signum;
  1410. char *tmp, *tmp2;
  1411. tmp = strsep((char **) &buf, "\n");
  1412. if (!strncmp(tmp, "unregister", 10)){
  1413. if ((rc = qeth_notifier_unregister(current)))
  1414. return rc;
  1415. return count;
  1416. }
  1417. signum = simple_strtoul(tmp, &tmp2, 10);
  1418. if ((signum < 0) || (signum > 32)){
  1419. PRINT_WARN("Signal number %d is out of range\n", signum);
  1420. return -EINVAL;
  1421. }
  1422. if ((rc = qeth_notifier_register(current, signum)))
  1423. return rc;
  1424. return count;
  1425. }
  1426. static DRIVER_ATTR(notifier_register, 0200, 0,
  1427. qeth_driver_notifier_register_store);
  1428. int
  1429. qeth_create_driver_attributes(void)
  1430. {
  1431. int rc;
  1432. if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
  1433. &driver_attr_group)))
  1434. return rc;
  1435. return driver_create_file(&qeth_ccwgroup_driver.driver,
  1436. &driver_attr_notifier_register);
  1437. }
  1438. void
  1439. qeth_remove_driver_attributes(void)
  1440. {
  1441. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1442. &driver_attr_group);
  1443. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1444. &driver_attr_notifier_register);
  1445. }