qeth_l3_main.c 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665
  1. /*
  2. * Copyright IBM Corp. 2007, 2009
  3. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
  4. * Frank Pavlic <fpavlic@de.ibm.com>,
  5. * Thomas Spatzier <tspat@de.ibm.com>,
  6. * Frank Blaschka <frank.blaschka@de.ibm.com>
  7. */
  8. #define KMSG_COMPONENT "qeth"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/module.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/bitops.h>
  13. #include <linux/string.h>
  14. #include <linux/errno.h>
  15. #include <linux/kernel.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/mii.h>
  18. #include <linux/ip.h>
  19. #include <linux/ipv6.h>
  20. #include <linux/inetdevice.h>
  21. #include <linux/igmp.h>
  22. #include <linux/slab.h>
  23. #include <linux/if_vlan.h>
  24. #include <net/ip.h>
  25. #include <net/arp.h>
  26. #include <net/route.h>
  27. #include <net/ip6_fib.h>
  28. #include <net/ip6_checksum.h>
  29. #include <net/iucv/af_iucv.h>
  30. #include "qeth_l3.h"
  31. static int qeth_l3_set_offline(struct ccwgroup_device *);
  32. static int qeth_l3_recover(void *);
  33. static int qeth_l3_stop(struct net_device *);
  34. static void qeth_l3_set_multicast_list(struct net_device *);
  35. static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *);
  36. static int qeth_l3_register_addr_entry(struct qeth_card *,
  37. struct qeth_ipaddr *);
  38. static int qeth_l3_deregister_addr_entry(struct qeth_card *,
  39. struct qeth_ipaddr *);
  40. static int __qeth_l3_set_online(struct ccwgroup_device *, int);
  41. static int __qeth_l3_set_offline(struct ccwgroup_device *, int);
  42. static int qeth_l3_isxdigit(char *buf)
  43. {
  44. while (*buf) {
  45. if (!isxdigit(*buf++))
  46. return 0;
  47. }
  48. return 1;
  49. }
  50. static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf)
  51. {
  52. sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
  53. }
  54. static int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr)
  55. {
  56. int count = 0, rc = 0;
  57. unsigned int in[4];
  58. char c;
  59. rc = sscanf(buf, "%u.%u.%u.%u%c",
  60. &in[0], &in[1], &in[2], &in[3], &c);
  61. if (rc != 4 && (rc != 5 || c != '\n'))
  62. return -EINVAL;
  63. for (count = 0; count < 4; count++) {
  64. if (in[count] > 255)
  65. return -EINVAL;
  66. addr[count] = in[count];
  67. }
  68. return 0;
  69. }
  70. static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf)
  71. {
  72. sprintf(buf, "%pI6", addr);
  73. }
  74. static int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr)
  75. {
  76. const char *end, *end_tmp, *start;
  77. __u16 *in;
  78. char num[5];
  79. int num2, cnt, out, found, save_cnt;
  80. unsigned short in_tmp[8] = {0, };
  81. cnt = out = found = save_cnt = num2 = 0;
  82. end = start = buf;
  83. in = (__u16 *) addr;
  84. memset(in, 0, 16);
  85. while (*end) {
  86. end = strchr(start, ':');
  87. if (end == NULL) {
  88. end = buf + strlen(buf);
  89. end_tmp = strchr(start, '\n');
  90. if (end_tmp != NULL)
  91. end = end_tmp;
  92. out = 1;
  93. }
  94. if ((end - start)) {
  95. memset(num, 0, 5);
  96. if ((end - start) > 4)
  97. return -EINVAL;
  98. memcpy(num, start, end - start);
  99. if (!qeth_l3_isxdigit(num))
  100. return -EINVAL;
  101. sscanf(start, "%x", &num2);
  102. if (found)
  103. in_tmp[save_cnt++] = num2;
  104. else
  105. in[cnt++] = num2;
  106. if (out)
  107. break;
  108. } else {
  109. if (found)
  110. return -EINVAL;
  111. found = 1;
  112. }
  113. start = ++end;
  114. }
  115. if (cnt + save_cnt > 8)
  116. return -EINVAL;
  117. cnt = 7;
  118. while (save_cnt)
  119. in[cnt--] = in_tmp[--save_cnt];
  120. return 0;
  121. }
  122. void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
  123. char *buf)
  124. {
  125. if (proto == QETH_PROT_IPV4)
  126. qeth_l3_ipaddr4_to_string(addr, buf);
  127. else if (proto == QETH_PROT_IPV6)
  128. qeth_l3_ipaddr6_to_string(addr, buf);
  129. }
  130. int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
  131. __u8 *addr)
  132. {
  133. if (proto == QETH_PROT_IPV4)
  134. return qeth_l3_string_to_ipaddr4(buf, addr);
  135. else if (proto == QETH_PROT_IPV6)
  136. return qeth_l3_string_to_ipaddr6(buf, addr);
  137. else
  138. return -EINVAL;
  139. }
  140. static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
  141. {
  142. int i, j;
  143. u8 octet;
  144. for (i = 0; i < len; ++i) {
  145. octet = addr[i];
  146. for (j = 7; j >= 0; --j) {
  147. bits[i*8 + j] = octet & 1;
  148. octet >>= 1;
  149. }
  150. }
  151. }
  152. int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
  153. struct qeth_ipaddr *addr)
  154. {
  155. struct qeth_ipato_entry *ipatoe;
  156. u8 addr_bits[128] = {0, };
  157. u8 ipatoe_bits[128] = {0, };
  158. int rc = 0;
  159. if (!card->ipato.enabled)
  160. return 0;
  161. qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
  162. (addr->proto == QETH_PROT_IPV4)? 4:16);
  163. list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
  164. if (addr->proto != ipatoe->proto)
  165. continue;
  166. qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
  167. (ipatoe->proto == QETH_PROT_IPV4) ?
  168. 4 : 16);
  169. if (addr->proto == QETH_PROT_IPV4)
  170. rc = !memcmp(addr_bits, ipatoe_bits,
  171. min(32, ipatoe->mask_bits));
  172. else
  173. rc = !memcmp(addr_bits, ipatoe_bits,
  174. min(128, ipatoe->mask_bits));
  175. if (rc)
  176. break;
  177. }
  178. /* invert? */
  179. if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
  180. rc = !rc;
  181. else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
  182. rc = !rc;
  183. return rc;
  184. }
  185. /*
  186. * Add IP to be added to todo list. If there is already an "add todo"
  187. * in this list we just incremenent the reference count.
  188. * Returns 0 if we just incremented reference count.
  189. */
  190. static int __qeth_l3_insert_ip_todo(struct qeth_card *card,
  191. struct qeth_ipaddr *addr, int add)
  192. {
  193. struct qeth_ipaddr *tmp, *t;
  194. int found = 0;
  195. if (card->options.sniffer)
  196. return 0;
  197. list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) {
  198. if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) &&
  199. (tmp->type == QETH_IP_TYPE_DEL_ALL_MC))
  200. return 0;
  201. if ((tmp->proto == QETH_PROT_IPV4) &&
  202. (addr->proto == QETH_PROT_IPV4) &&
  203. (tmp->type == addr->type) &&
  204. (tmp->is_multicast == addr->is_multicast) &&
  205. (tmp->u.a4.addr == addr->u.a4.addr) &&
  206. (tmp->u.a4.mask == addr->u.a4.mask)) {
  207. found = 1;
  208. break;
  209. }
  210. if ((tmp->proto == QETH_PROT_IPV6) &&
  211. (addr->proto == QETH_PROT_IPV6) &&
  212. (tmp->type == addr->type) &&
  213. (tmp->is_multicast == addr->is_multicast) &&
  214. (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) &&
  215. (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
  216. sizeof(struct in6_addr)) == 0)) {
  217. found = 1;
  218. break;
  219. }
  220. }
  221. if (found) {
  222. if (addr->users != 0)
  223. tmp->users += addr->users;
  224. else
  225. tmp->users += add ? 1 : -1;
  226. if (tmp->users == 0) {
  227. list_del(&tmp->entry);
  228. kfree(tmp);
  229. }
  230. return 0;
  231. } else {
  232. if (addr->type == QETH_IP_TYPE_DEL_ALL_MC)
  233. list_add(&addr->entry, card->ip_tbd_list);
  234. else {
  235. if (addr->users == 0)
  236. addr->users += add ? 1 : -1;
  237. if (add && (addr->type == QETH_IP_TYPE_NORMAL) &&
  238. qeth_l3_is_addr_covered_by_ipato(card, addr)) {
  239. QETH_CARD_TEXT(card, 2, "tkovaddr");
  240. addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG;
  241. }
  242. list_add_tail(&addr->entry, card->ip_tbd_list);
  243. }
  244. return 1;
  245. }
  246. }
  247. int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
  248. {
  249. unsigned long flags;
  250. int rc = 0;
  251. QETH_CARD_TEXT(card, 4, "delip");
  252. if (addr->proto == QETH_PROT_IPV4)
  253. QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
  254. else {
  255. QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
  256. QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
  257. }
  258. spin_lock_irqsave(&card->ip_lock, flags);
  259. rc = __qeth_l3_insert_ip_todo(card, addr, 0);
  260. spin_unlock_irqrestore(&card->ip_lock, flags);
  261. return rc;
  262. }
  263. int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr)
  264. {
  265. unsigned long flags;
  266. int rc = 0;
  267. QETH_CARD_TEXT(card, 4, "addip");
  268. if (addr->proto == QETH_PROT_IPV4)
  269. QETH_CARD_HEX(card, 4, &addr->u.a4.addr, 4);
  270. else {
  271. QETH_CARD_HEX(card, 4, &addr->u.a6.addr, 8);
  272. QETH_CARD_HEX(card, 4, ((char *)&addr->u.a6.addr) + 8, 8);
  273. }
  274. spin_lock_irqsave(&card->ip_lock, flags);
  275. rc = __qeth_l3_insert_ip_todo(card, addr, 1);
  276. spin_unlock_irqrestore(&card->ip_lock, flags);
  277. return rc;
  278. }
  279. struct qeth_ipaddr *qeth_l3_get_addr_buffer(
  280. enum qeth_prot_versions prot)
  281. {
  282. struct qeth_ipaddr *addr;
  283. addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
  284. if (addr == NULL) {
  285. return NULL;
  286. }
  287. addr->type = QETH_IP_TYPE_NORMAL;
  288. addr->proto = prot;
  289. return addr;
  290. }
  291. static void qeth_l3_delete_mc_addresses(struct qeth_card *card)
  292. {
  293. struct qeth_ipaddr *iptodo;
  294. unsigned long flags;
  295. QETH_CARD_TEXT(card, 4, "delmc");
  296. iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
  297. if (!iptodo) {
  298. QETH_CARD_TEXT(card, 2, "dmcnomem");
  299. return;
  300. }
  301. iptodo->type = QETH_IP_TYPE_DEL_ALL_MC;
  302. spin_lock_irqsave(&card->ip_lock, flags);
  303. if (!__qeth_l3_insert_ip_todo(card, iptodo, 0))
  304. kfree(iptodo);
  305. spin_unlock_irqrestore(&card->ip_lock, flags);
  306. }
  307. /*
  308. * Add/remove address to/from card's ip list, i.e. try to add or remove
  309. * reference to/from an IP address that is already registered on the card.
  310. * Returns:
  311. * 0 address was on card and its reference count has been adjusted,
  312. * but is still > 0, so nothing has to be done
  313. * also returns 0 if card was not on card and the todo was to delete
  314. * the address -> there is also nothing to be done
  315. * 1 address was not on card and the todo is to add it to the card's ip
  316. * list
  317. * -1 address was on card and its reference count has been decremented
  318. * to <= 0 by the todo -> address must be removed from card
  319. */
  320. static int __qeth_l3_ref_ip_on_card(struct qeth_card *card,
  321. struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr)
  322. {
  323. struct qeth_ipaddr *addr;
  324. int found = 0;
  325. list_for_each_entry(addr, &card->ip_list, entry) {
  326. if ((addr->proto == QETH_PROT_IPV4) &&
  327. (todo->proto == QETH_PROT_IPV4) &&
  328. (addr->type == todo->type) &&
  329. (addr->u.a4.addr == todo->u.a4.addr) &&
  330. (addr->u.a4.mask == todo->u.a4.mask)) {
  331. found = 1;
  332. break;
  333. }
  334. if ((addr->proto == QETH_PROT_IPV6) &&
  335. (todo->proto == QETH_PROT_IPV6) &&
  336. (addr->type == todo->type) &&
  337. (addr->u.a6.pfxlen == todo->u.a6.pfxlen) &&
  338. (memcmp(&addr->u.a6.addr, &todo->u.a6.addr,
  339. sizeof(struct in6_addr)) == 0)) {
  340. found = 1;
  341. break;
  342. }
  343. }
  344. if (found) {
  345. addr->users += todo->users;
  346. if (addr->users <= 0) {
  347. *__addr = addr;
  348. return -1;
  349. } else {
  350. /* for VIPA and RXIP limit refcount to 1 */
  351. if (addr->type != QETH_IP_TYPE_NORMAL)
  352. addr->users = 1;
  353. return 0;
  354. }
  355. }
  356. if (todo->users > 0) {
  357. /* for VIPA and RXIP limit refcount to 1 */
  358. if (todo->type != QETH_IP_TYPE_NORMAL)
  359. todo->users = 1;
  360. return 1;
  361. } else
  362. return 0;
  363. }
  364. static void __qeth_l3_delete_all_mc(struct qeth_card *card,
  365. unsigned long *flags)
  366. {
  367. struct list_head fail_list;
  368. struct qeth_ipaddr *addr, *tmp;
  369. int rc;
  370. INIT_LIST_HEAD(&fail_list);
  371. again:
  372. list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) {
  373. if (addr->is_multicast) {
  374. list_del(&addr->entry);
  375. spin_unlock_irqrestore(&card->ip_lock, *flags);
  376. rc = qeth_l3_deregister_addr_entry(card, addr);
  377. spin_lock_irqsave(&card->ip_lock, *flags);
  378. if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND))
  379. kfree(addr);
  380. else
  381. list_add_tail(&addr->entry, &fail_list);
  382. goto again;
  383. }
  384. }
  385. list_splice(&fail_list, &card->ip_list);
  386. }
  387. void qeth_l3_set_ip_addr_list(struct qeth_card *card)
  388. {
  389. struct list_head *tbd_list;
  390. struct qeth_ipaddr *todo, *addr;
  391. unsigned long flags;
  392. int rc;
  393. QETH_CARD_TEXT(card, 2, "sdiplist");
  394. QETH_CARD_HEX(card, 2, &card, sizeof(void *));
  395. if (!qeth_card_hw_is_reachable(card) || card->options.sniffer)
  396. return;
  397. spin_lock_irqsave(&card->ip_lock, flags);
  398. tbd_list = card->ip_tbd_list;
  399. card->ip_tbd_list = kzalloc(sizeof(struct list_head), GFP_ATOMIC);
  400. if (!card->ip_tbd_list) {
  401. QETH_CARD_TEXT(card, 0, "silnomem");
  402. card->ip_tbd_list = tbd_list;
  403. spin_unlock_irqrestore(&card->ip_lock, flags);
  404. return;
  405. } else
  406. INIT_LIST_HEAD(card->ip_tbd_list);
  407. while (!list_empty(tbd_list)) {
  408. todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry);
  409. list_del(&todo->entry);
  410. if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) {
  411. __qeth_l3_delete_all_mc(card, &flags);
  412. kfree(todo);
  413. continue;
  414. }
  415. rc = __qeth_l3_ref_ip_on_card(card, todo, &addr);
  416. if (rc == 0) {
  417. /* nothing to be done; only adjusted refcount */
  418. kfree(todo);
  419. } else if (rc == 1) {
  420. /* new entry to be added to on-card list */
  421. spin_unlock_irqrestore(&card->ip_lock, flags);
  422. rc = qeth_l3_register_addr_entry(card, todo);
  423. spin_lock_irqsave(&card->ip_lock, flags);
  424. if (!rc || (rc == IPA_RC_LAN_OFFLINE))
  425. list_add_tail(&todo->entry, &card->ip_list);
  426. else
  427. kfree(todo);
  428. } else if (rc == -1) {
  429. /* on-card entry to be removed */
  430. list_del_init(&addr->entry);
  431. spin_unlock_irqrestore(&card->ip_lock, flags);
  432. rc = qeth_l3_deregister_addr_entry(card, addr);
  433. spin_lock_irqsave(&card->ip_lock, flags);
  434. if (!rc || (rc == IPA_RC_IP_ADDRESS_NOT_DEFINED))
  435. kfree(addr);
  436. else
  437. list_add_tail(&addr->entry, &card->ip_list);
  438. kfree(todo);
  439. }
  440. }
  441. spin_unlock_irqrestore(&card->ip_lock, flags);
  442. kfree(tbd_list);
  443. }
  444. static void qeth_l3_clear_ip_list(struct qeth_card *card, int recover)
  445. {
  446. struct qeth_ipaddr *addr, *tmp;
  447. unsigned long flags;
  448. QETH_CARD_TEXT(card, 4, "clearip");
  449. if (recover && card->options.sniffer)
  450. return;
  451. spin_lock_irqsave(&card->ip_lock, flags);
  452. /* clear todo list */
  453. list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) {
  454. list_del(&addr->entry);
  455. kfree(addr);
  456. }
  457. while (!list_empty(&card->ip_list)) {
  458. addr = list_entry(card->ip_list.next,
  459. struct qeth_ipaddr, entry);
  460. list_del_init(&addr->entry);
  461. if (!recover || addr->is_multicast) {
  462. kfree(addr);
  463. continue;
  464. }
  465. list_add_tail(&addr->entry, card->ip_tbd_list);
  466. }
  467. spin_unlock_irqrestore(&card->ip_lock, flags);
  468. }
  469. static int qeth_l3_address_exists_in_list(struct list_head *list,
  470. struct qeth_ipaddr *addr, int same_type)
  471. {
  472. struct qeth_ipaddr *tmp;
  473. list_for_each_entry(tmp, list, entry) {
  474. if ((tmp->proto == QETH_PROT_IPV4) &&
  475. (addr->proto == QETH_PROT_IPV4) &&
  476. ((same_type && (tmp->type == addr->type)) ||
  477. (!same_type && (tmp->type != addr->type))) &&
  478. (tmp->u.a4.addr == addr->u.a4.addr))
  479. return 1;
  480. if ((tmp->proto == QETH_PROT_IPV6) &&
  481. (addr->proto == QETH_PROT_IPV6) &&
  482. ((same_type && (tmp->type == addr->type)) ||
  483. (!same_type && (tmp->type != addr->type))) &&
  484. (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr,
  485. sizeof(struct in6_addr)) == 0))
  486. return 1;
  487. }
  488. return 0;
  489. }
  490. static int qeth_l3_send_setdelmc(struct qeth_card *card,
  491. struct qeth_ipaddr *addr, int ipacmd)
  492. {
  493. int rc;
  494. struct qeth_cmd_buffer *iob;
  495. struct qeth_ipa_cmd *cmd;
  496. QETH_CARD_TEXT(card, 4, "setdelmc");
  497. iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
  498. if (!iob)
  499. return -ENOMEM;
  500. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  501. memcpy(&cmd->data.setdelipm.mac, addr->mac, OSA_ADDR_LEN);
  502. if (addr->proto == QETH_PROT_IPV6)
  503. memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr,
  504. sizeof(struct in6_addr));
  505. else
  506. memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4);
  507. rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
  508. return rc;
  509. }
  510. static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len)
  511. {
  512. int i, j;
  513. for (i = 0; i < 16; i++) {
  514. j = (len) - (i * 8);
  515. if (j >= 8)
  516. netmask[i] = 0xff;
  517. else if (j > 0)
  518. netmask[i] = (u8)(0xFF00 >> j);
  519. else
  520. netmask[i] = 0;
  521. }
  522. }
  523. static int qeth_l3_send_setdelip(struct qeth_card *card,
  524. struct qeth_ipaddr *addr, int ipacmd, unsigned int flags)
  525. {
  526. int rc;
  527. struct qeth_cmd_buffer *iob;
  528. struct qeth_ipa_cmd *cmd;
  529. __u8 netmask[16];
  530. QETH_CARD_TEXT(card, 4, "setdelip");
  531. QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
  532. iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto);
  533. if (!iob)
  534. return -ENOMEM;
  535. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  536. if (addr->proto == QETH_PROT_IPV6) {
  537. memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr,
  538. sizeof(struct in6_addr));
  539. qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen);
  540. memcpy(cmd->data.setdelip6.mask, netmask,
  541. sizeof(struct in6_addr));
  542. cmd->data.setdelip6.flags = flags;
  543. } else {
  544. memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4);
  545. memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4);
  546. cmd->data.setdelip4.flags = flags;
  547. }
  548. rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
  549. return rc;
  550. }
  551. static int qeth_l3_send_setrouting(struct qeth_card *card,
  552. enum qeth_routing_types type, enum qeth_prot_versions prot)
  553. {
  554. int rc;
  555. struct qeth_ipa_cmd *cmd;
  556. struct qeth_cmd_buffer *iob;
  557. QETH_CARD_TEXT(card, 4, "setroutg");
  558. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot);
  559. if (!iob)
  560. return -ENOMEM;
  561. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  562. cmd->data.setrtg.type = (type);
  563. rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
  564. return rc;
  565. }
  566. static int qeth_l3_correct_routing_type(struct qeth_card *card,
  567. enum qeth_routing_types *type, enum qeth_prot_versions prot)
  568. {
  569. if (card->info.type == QETH_CARD_TYPE_IQD) {
  570. switch (*type) {
  571. case NO_ROUTER:
  572. case PRIMARY_CONNECTOR:
  573. case SECONDARY_CONNECTOR:
  574. case MULTICAST_ROUTER:
  575. return 0;
  576. default:
  577. goto out_inval;
  578. }
  579. } else {
  580. switch (*type) {
  581. case NO_ROUTER:
  582. case PRIMARY_ROUTER:
  583. case SECONDARY_ROUTER:
  584. return 0;
  585. case MULTICAST_ROUTER:
  586. if (qeth_is_ipafunc_supported(card, prot,
  587. IPA_OSA_MC_ROUTER))
  588. return 0;
  589. default:
  590. goto out_inval;
  591. }
  592. }
  593. out_inval:
  594. *type = NO_ROUTER;
  595. return -EINVAL;
  596. }
  597. int qeth_l3_setrouting_v4(struct qeth_card *card)
  598. {
  599. int rc;
  600. QETH_CARD_TEXT(card, 3, "setrtg4");
  601. rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
  602. QETH_PROT_IPV4);
  603. if (rc)
  604. return rc;
  605. rc = qeth_l3_send_setrouting(card, card->options.route4.type,
  606. QETH_PROT_IPV4);
  607. if (rc) {
  608. card->options.route4.type = NO_ROUTER;
  609. QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
  610. " on %s. Type set to 'no router'.\n", rc,
  611. QETH_CARD_IFNAME(card));
  612. }
  613. return rc;
  614. }
  615. int qeth_l3_setrouting_v6(struct qeth_card *card)
  616. {
  617. int rc = 0;
  618. QETH_CARD_TEXT(card, 3, "setrtg6");
  619. #ifdef CONFIG_QETH_IPV6
  620. if (!qeth_is_supported(card, IPA_IPV6))
  621. return 0;
  622. rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
  623. QETH_PROT_IPV6);
  624. if (rc)
  625. return rc;
  626. rc = qeth_l3_send_setrouting(card, card->options.route6.type,
  627. QETH_PROT_IPV6);
  628. if (rc) {
  629. card->options.route6.type = NO_ROUTER;
  630. QETH_DBF_MESSAGE(2, "Error (0x%04x) while setting routing type"
  631. " on %s. Type set to 'no router'.\n", rc,
  632. QETH_CARD_IFNAME(card));
  633. }
  634. #endif
  635. return rc;
  636. }
  637. /*
  638. * IP address takeover related functions
  639. */
  640. static void qeth_l3_clear_ipato_list(struct qeth_card *card)
  641. {
  642. struct qeth_ipato_entry *ipatoe, *tmp;
  643. unsigned long flags;
  644. spin_lock_irqsave(&card->ip_lock, flags);
  645. list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
  646. list_del(&ipatoe->entry);
  647. kfree(ipatoe);
  648. }
  649. spin_unlock_irqrestore(&card->ip_lock, flags);
  650. }
  651. int qeth_l3_add_ipato_entry(struct qeth_card *card,
  652. struct qeth_ipato_entry *new)
  653. {
  654. struct qeth_ipato_entry *ipatoe;
  655. unsigned long flags;
  656. int rc = 0;
  657. QETH_CARD_TEXT(card, 2, "addipato");
  658. spin_lock_irqsave(&card->ip_lock, flags);
  659. list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
  660. if (ipatoe->proto != new->proto)
  661. continue;
  662. if (!memcmp(ipatoe->addr, new->addr,
  663. (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
  664. (ipatoe->mask_bits == new->mask_bits)) {
  665. rc = -EEXIST;
  666. break;
  667. }
  668. }
  669. if (!rc)
  670. list_add_tail(&new->entry, &card->ipato.entries);
  671. spin_unlock_irqrestore(&card->ip_lock, flags);
  672. return rc;
  673. }
  674. void qeth_l3_del_ipato_entry(struct qeth_card *card,
  675. enum qeth_prot_versions proto, u8 *addr, int mask_bits)
  676. {
  677. struct qeth_ipato_entry *ipatoe, *tmp;
  678. unsigned long flags;
  679. QETH_CARD_TEXT(card, 2, "delipato");
  680. spin_lock_irqsave(&card->ip_lock, flags);
  681. list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
  682. if (ipatoe->proto != proto)
  683. continue;
  684. if (!memcmp(ipatoe->addr, addr,
  685. (proto == QETH_PROT_IPV4)? 4:16) &&
  686. (ipatoe->mask_bits == mask_bits)) {
  687. list_del(&ipatoe->entry);
  688. kfree(ipatoe);
  689. }
  690. }
  691. spin_unlock_irqrestore(&card->ip_lock, flags);
  692. }
  693. /*
  694. * VIPA related functions
  695. */
  696. int qeth_l3_add_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
  697. const u8 *addr)
  698. {
  699. struct qeth_ipaddr *ipaddr;
  700. unsigned long flags;
  701. int rc = 0;
  702. ipaddr = qeth_l3_get_addr_buffer(proto);
  703. if (ipaddr) {
  704. if (proto == QETH_PROT_IPV4) {
  705. QETH_CARD_TEXT(card, 2, "addvipa4");
  706. memcpy(&ipaddr->u.a4.addr, addr, 4);
  707. ipaddr->u.a4.mask = 0;
  708. } else if (proto == QETH_PROT_IPV6) {
  709. QETH_CARD_TEXT(card, 2, "addvipa6");
  710. memcpy(&ipaddr->u.a6.addr, addr, 16);
  711. ipaddr->u.a6.pfxlen = 0;
  712. }
  713. ipaddr->type = QETH_IP_TYPE_VIPA;
  714. ipaddr->set_flags = QETH_IPA_SETIP_VIPA_FLAG;
  715. ipaddr->del_flags = QETH_IPA_DELIP_VIPA_FLAG;
  716. } else
  717. return -ENOMEM;
  718. spin_lock_irqsave(&card->ip_lock, flags);
  719. if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
  720. qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
  721. rc = -EEXIST;
  722. spin_unlock_irqrestore(&card->ip_lock, flags);
  723. if (rc) {
  724. kfree(ipaddr);
  725. return rc;
  726. }
  727. if (!qeth_l3_add_ip(card, ipaddr))
  728. kfree(ipaddr);
  729. qeth_l3_set_ip_addr_list(card);
  730. return rc;
  731. }
  732. void qeth_l3_del_vipa(struct qeth_card *card, enum qeth_prot_versions proto,
  733. const u8 *addr)
  734. {
  735. struct qeth_ipaddr *ipaddr;
  736. ipaddr = qeth_l3_get_addr_buffer(proto);
  737. if (ipaddr) {
  738. if (proto == QETH_PROT_IPV4) {
  739. QETH_CARD_TEXT(card, 2, "delvipa4");
  740. memcpy(&ipaddr->u.a4.addr, addr, 4);
  741. ipaddr->u.a4.mask = 0;
  742. } else if (proto == QETH_PROT_IPV6) {
  743. QETH_CARD_TEXT(card, 2, "delvipa6");
  744. memcpy(&ipaddr->u.a6.addr, addr, 16);
  745. ipaddr->u.a6.pfxlen = 0;
  746. }
  747. ipaddr->type = QETH_IP_TYPE_VIPA;
  748. } else
  749. return;
  750. if (!qeth_l3_delete_ip(card, ipaddr))
  751. kfree(ipaddr);
  752. qeth_l3_set_ip_addr_list(card);
  753. }
  754. /*
  755. * proxy ARP related functions
  756. */
  757. int qeth_l3_add_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
  758. const u8 *addr)
  759. {
  760. struct qeth_ipaddr *ipaddr;
  761. unsigned long flags;
  762. int rc = 0;
  763. ipaddr = qeth_l3_get_addr_buffer(proto);
  764. if (ipaddr) {
  765. if (proto == QETH_PROT_IPV4) {
  766. QETH_CARD_TEXT(card, 2, "addrxip4");
  767. memcpy(&ipaddr->u.a4.addr, addr, 4);
  768. ipaddr->u.a4.mask = 0;
  769. } else if (proto == QETH_PROT_IPV6) {
  770. QETH_CARD_TEXT(card, 2, "addrxip6");
  771. memcpy(&ipaddr->u.a6.addr, addr, 16);
  772. ipaddr->u.a6.pfxlen = 0;
  773. }
  774. ipaddr->type = QETH_IP_TYPE_RXIP;
  775. ipaddr->set_flags = QETH_IPA_SETIP_TAKEOVER_FLAG;
  776. ipaddr->del_flags = 0;
  777. } else
  778. return -ENOMEM;
  779. spin_lock_irqsave(&card->ip_lock, flags);
  780. if (qeth_l3_address_exists_in_list(&card->ip_list, ipaddr, 0) ||
  781. qeth_l3_address_exists_in_list(card->ip_tbd_list, ipaddr, 0))
  782. rc = -EEXIST;
  783. spin_unlock_irqrestore(&card->ip_lock, flags);
  784. if (rc) {
  785. kfree(ipaddr);
  786. return rc;
  787. }
  788. if (!qeth_l3_add_ip(card, ipaddr))
  789. kfree(ipaddr);
  790. qeth_l3_set_ip_addr_list(card);
  791. return 0;
  792. }
  793. void qeth_l3_del_rxip(struct qeth_card *card, enum qeth_prot_versions proto,
  794. const u8 *addr)
  795. {
  796. struct qeth_ipaddr *ipaddr;
  797. ipaddr = qeth_l3_get_addr_buffer(proto);
  798. if (ipaddr) {
  799. if (proto == QETH_PROT_IPV4) {
  800. QETH_CARD_TEXT(card, 2, "addrxip4");
  801. memcpy(&ipaddr->u.a4.addr, addr, 4);
  802. ipaddr->u.a4.mask = 0;
  803. } else if (proto == QETH_PROT_IPV6) {
  804. QETH_CARD_TEXT(card, 2, "addrxip6");
  805. memcpy(&ipaddr->u.a6.addr, addr, 16);
  806. ipaddr->u.a6.pfxlen = 0;
  807. }
  808. ipaddr->type = QETH_IP_TYPE_RXIP;
  809. } else
  810. return;
  811. if (!qeth_l3_delete_ip(card, ipaddr))
  812. kfree(ipaddr);
  813. qeth_l3_set_ip_addr_list(card);
  814. }
  815. static int qeth_l3_register_addr_entry(struct qeth_card *card,
  816. struct qeth_ipaddr *addr)
  817. {
  818. char buf[50];
  819. int rc = 0;
  820. int cnt = 3;
  821. if (addr->proto == QETH_PROT_IPV4) {
  822. QETH_CARD_TEXT(card, 2, "setaddr4");
  823. QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
  824. } else if (addr->proto == QETH_PROT_IPV6) {
  825. QETH_CARD_TEXT(card, 2, "setaddr6");
  826. QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
  827. QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
  828. } else {
  829. QETH_CARD_TEXT(card, 2, "setaddr?");
  830. QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
  831. }
  832. do {
  833. if (addr->is_multicast)
  834. rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
  835. else
  836. rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP,
  837. addr->set_flags);
  838. if (rc)
  839. QETH_CARD_TEXT(card, 2, "failed");
  840. } while ((--cnt > 0) && rc);
  841. if (rc) {
  842. QETH_CARD_TEXT(card, 2, "FAILED");
  843. qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
  844. dev_warn(&card->gdev->dev,
  845. "Registering IP address %s failed\n", buf);
  846. }
  847. return rc;
  848. }
  849. static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
  850. struct qeth_ipaddr *addr)
  851. {
  852. int rc = 0;
  853. if (addr->proto == QETH_PROT_IPV4) {
  854. QETH_CARD_TEXT(card, 2, "deladdr4");
  855. QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
  856. } else if (addr->proto == QETH_PROT_IPV6) {
  857. QETH_CARD_TEXT(card, 2, "deladdr6");
  858. QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
  859. QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
  860. } else {
  861. QETH_CARD_TEXT(card, 2, "deladdr?");
  862. QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
  863. }
  864. if (addr->is_multicast)
  865. rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
  866. else
  867. rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP,
  868. addr->del_flags);
  869. if (rc)
  870. QETH_CARD_TEXT(card, 2, "failed");
  871. return rc;
  872. }
  873. static inline u8 qeth_l3_get_qeth_hdr_flags4(int cast_type)
  874. {
  875. if (cast_type == RTN_MULTICAST)
  876. return QETH_CAST_MULTICAST;
  877. if (cast_type == RTN_BROADCAST)
  878. return QETH_CAST_BROADCAST;
  879. return QETH_CAST_UNICAST;
  880. }
  881. static inline u8 qeth_l3_get_qeth_hdr_flags6(int cast_type)
  882. {
  883. u8 ct = QETH_HDR_PASSTHRU | QETH_HDR_IPV6;
  884. if (cast_type == RTN_MULTICAST)
  885. return ct | QETH_CAST_MULTICAST;
  886. if (cast_type == RTN_ANYCAST)
  887. return ct | QETH_CAST_ANYCAST;
  888. if (cast_type == RTN_BROADCAST)
  889. return ct | QETH_CAST_BROADCAST;
  890. return ct | QETH_CAST_UNICAST;
  891. }
  892. static int qeth_l3_setadapter_parms(struct qeth_card *card)
  893. {
  894. int rc;
  895. QETH_DBF_TEXT(SETUP, 2, "setadprm");
  896. if (!qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
  897. dev_info(&card->gdev->dev,
  898. "set adapter parameters not supported.\n");
  899. QETH_DBF_TEXT(SETUP, 2, " notsupp");
  900. return 0;
  901. }
  902. rc = qeth_query_setadapterparms(card);
  903. if (rc) {
  904. QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
  905. "0x%x\n", dev_name(&card->gdev->dev), rc);
  906. return rc;
  907. }
  908. if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
  909. rc = qeth_setadpparms_change_macaddr(card);
  910. if (rc)
  911. dev_warn(&card->gdev->dev, "Reading the adapter MAC"
  912. " address failed\n");
  913. }
  914. return rc;
  915. }
  916. static int qeth_l3_default_setassparms_cb(struct qeth_card *card,
  917. struct qeth_reply *reply, unsigned long data)
  918. {
  919. struct qeth_ipa_cmd *cmd;
  920. QETH_CARD_TEXT(card, 4, "defadpcb");
  921. cmd = (struct qeth_ipa_cmd *) data;
  922. if (cmd->hdr.return_code == 0) {
  923. cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
  924. if (cmd->hdr.prot_version == QETH_PROT_IPV4)
  925. card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled;
  926. if (cmd->hdr.prot_version == QETH_PROT_IPV6)
  927. card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled;
  928. }
  929. if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM &&
  930. cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
  931. card->info.csum_mask = cmd->data.setassparms.data.flags_32bit;
  932. QETH_CARD_TEXT_(card, 3, "csum:%d", card->info.csum_mask);
  933. }
  934. if (cmd->data.setassparms.hdr.assist_no == IPA_OUTBOUND_CHECKSUM &&
  935. cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) {
  936. card->info.tx_csum_mask =
  937. cmd->data.setassparms.data.flags_32bit;
  938. QETH_CARD_TEXT_(card, 3, "tcsu:%d", card->info.tx_csum_mask);
  939. }
  940. return 0;
  941. }
  942. static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd(
  943. struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code,
  944. __u16 len, enum qeth_prot_versions prot)
  945. {
  946. struct qeth_cmd_buffer *iob;
  947. struct qeth_ipa_cmd *cmd;
  948. QETH_CARD_TEXT(card, 4, "getasscm");
  949. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot);
  950. if (iob) {
  951. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  952. cmd->data.setassparms.hdr.assist_no = ipa_func;
  953. cmd->data.setassparms.hdr.length = 8 + len;
  954. cmd->data.setassparms.hdr.command_code = cmd_code;
  955. cmd->data.setassparms.hdr.return_code = 0;
  956. cmd->data.setassparms.hdr.seq_no = 0;
  957. }
  958. return iob;
  959. }
  960. #ifdef CONFIG_QETH_IPV6
  961. static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card,
  962. enum qeth_ipa_funcs ipa_func, __u16 cmd_code)
  963. {
  964. int rc;
  965. struct qeth_cmd_buffer *iob;
  966. QETH_CARD_TEXT(card, 4, "simassp6");
  967. iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code,
  968. 0, QETH_PROT_IPV6);
  969. if (!iob)
  970. return -ENOMEM;
  971. rc = qeth_send_setassparms(card, iob, 0, 0,
  972. qeth_l3_default_setassparms_cb, NULL);
  973. return rc;
  974. }
  975. #endif
  976. static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
  977. {
  978. int rc;
  979. QETH_CARD_TEXT(card, 3, "ipaarp");
  980. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  981. dev_info(&card->gdev->dev,
  982. "ARP processing not supported on %s!\n",
  983. QETH_CARD_IFNAME(card));
  984. return 0;
  985. }
  986. rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
  987. IPA_CMD_ASS_START, 0);
  988. if (rc) {
  989. dev_warn(&card->gdev->dev,
  990. "Starting ARP processing support for %s failed\n",
  991. QETH_CARD_IFNAME(card));
  992. }
  993. return rc;
  994. }
  995. static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card)
  996. {
  997. int rc;
  998. QETH_CARD_TEXT(card, 3, "ipaipfrg");
  999. if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) {
  1000. dev_info(&card->gdev->dev,
  1001. "Hardware IP fragmentation not supported on %s\n",
  1002. QETH_CARD_IFNAME(card));
  1003. return -EOPNOTSUPP;
  1004. }
  1005. rc = qeth_send_simple_setassparms(card, IPA_IP_FRAGMENTATION,
  1006. IPA_CMD_ASS_START, 0);
  1007. if (rc) {
  1008. dev_warn(&card->gdev->dev,
  1009. "Starting IP fragmentation support for %s failed\n",
  1010. QETH_CARD_IFNAME(card));
  1011. } else
  1012. dev_info(&card->gdev->dev,
  1013. "Hardware IP fragmentation enabled \n");
  1014. return rc;
  1015. }
  1016. static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
  1017. {
  1018. int rc;
  1019. QETH_CARD_TEXT(card, 3, "stsrcmac");
  1020. if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
  1021. dev_info(&card->gdev->dev,
  1022. "Inbound source MAC-address not supported on %s\n",
  1023. QETH_CARD_IFNAME(card));
  1024. return -EOPNOTSUPP;
  1025. }
  1026. rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
  1027. IPA_CMD_ASS_START, 0);
  1028. if (rc)
  1029. dev_warn(&card->gdev->dev,
  1030. "Starting source MAC-address support for %s failed\n",
  1031. QETH_CARD_IFNAME(card));
  1032. return rc;
  1033. }
  1034. static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
  1035. {
  1036. int rc = 0;
  1037. QETH_CARD_TEXT(card, 3, "strtvlan");
  1038. if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
  1039. dev_info(&card->gdev->dev,
  1040. "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
  1041. return -EOPNOTSUPP;
  1042. }
  1043. rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
  1044. IPA_CMD_ASS_START, 0);
  1045. if (rc) {
  1046. dev_warn(&card->gdev->dev,
  1047. "Starting VLAN support for %s failed\n",
  1048. QETH_CARD_IFNAME(card));
  1049. } else {
  1050. dev_info(&card->gdev->dev, "VLAN enabled\n");
  1051. }
  1052. return rc;
  1053. }
  1054. static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
  1055. {
  1056. int rc;
  1057. QETH_CARD_TEXT(card, 3, "stmcast");
  1058. if (!qeth_is_supported(card, IPA_MULTICASTING)) {
  1059. dev_info(&card->gdev->dev,
  1060. "Multicast not supported on %s\n",
  1061. QETH_CARD_IFNAME(card));
  1062. return -EOPNOTSUPP;
  1063. }
  1064. rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
  1065. IPA_CMD_ASS_START, 0);
  1066. if (rc) {
  1067. dev_warn(&card->gdev->dev,
  1068. "Starting multicast support for %s failed\n",
  1069. QETH_CARD_IFNAME(card));
  1070. } else {
  1071. dev_info(&card->gdev->dev, "Multicast enabled\n");
  1072. card->dev->flags |= IFF_MULTICAST;
  1073. }
  1074. return rc;
  1075. }
  1076. #ifdef CONFIG_QETH_IPV6
  1077. static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
  1078. {
  1079. int rc;
  1080. QETH_CARD_TEXT(card, 3, "softipv6");
  1081. if (card->info.type == QETH_CARD_TYPE_IQD)
  1082. goto out;
  1083. rc = qeth_query_ipassists(card, QETH_PROT_IPV6);
  1084. if (rc) {
  1085. dev_err(&card->gdev->dev,
  1086. "Activating IPv6 support for %s failed\n",
  1087. QETH_CARD_IFNAME(card));
  1088. return rc;
  1089. }
  1090. rc = qeth_send_simple_setassparms(card, IPA_IPV6,
  1091. IPA_CMD_ASS_START, 3);
  1092. if (rc) {
  1093. dev_err(&card->gdev->dev,
  1094. "Activating IPv6 support for %s failed\n",
  1095. QETH_CARD_IFNAME(card));
  1096. return rc;
  1097. }
  1098. rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6,
  1099. IPA_CMD_ASS_START);
  1100. if (rc) {
  1101. dev_err(&card->gdev->dev,
  1102. "Activating IPv6 support for %s failed\n",
  1103. QETH_CARD_IFNAME(card));
  1104. return rc;
  1105. }
  1106. rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU,
  1107. IPA_CMD_ASS_START);
  1108. if (rc) {
  1109. dev_warn(&card->gdev->dev,
  1110. "Enabling the passthrough mode for %s failed\n",
  1111. QETH_CARD_IFNAME(card));
  1112. return rc;
  1113. }
  1114. out:
  1115. dev_info(&card->gdev->dev, "IPV6 enabled\n");
  1116. return 0;
  1117. }
  1118. #endif
  1119. static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
  1120. {
  1121. int rc = 0;
  1122. QETH_CARD_TEXT(card, 3, "strtipv6");
  1123. if (!qeth_is_supported(card, IPA_IPV6)) {
  1124. dev_info(&card->gdev->dev,
  1125. "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
  1126. return 0;
  1127. }
  1128. #ifdef CONFIG_QETH_IPV6
  1129. rc = qeth_l3_softsetup_ipv6(card);
  1130. #endif
  1131. return rc ;
  1132. }
  1133. static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
  1134. {
  1135. int rc;
  1136. QETH_CARD_TEXT(card, 3, "stbrdcst");
  1137. card->info.broadcast_capable = 0;
  1138. if (!qeth_is_supported(card, IPA_FILTERING)) {
  1139. dev_info(&card->gdev->dev,
  1140. "Broadcast not supported on %s\n",
  1141. QETH_CARD_IFNAME(card));
  1142. rc = -EOPNOTSUPP;
  1143. goto out;
  1144. }
  1145. rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
  1146. IPA_CMD_ASS_START, 0);
  1147. if (rc) {
  1148. dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
  1149. "%s failed\n", QETH_CARD_IFNAME(card));
  1150. goto out;
  1151. }
  1152. rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
  1153. IPA_CMD_ASS_CONFIGURE, 1);
  1154. if (rc) {
  1155. dev_warn(&card->gdev->dev,
  1156. "Setting up broadcast filtering for %s failed\n",
  1157. QETH_CARD_IFNAME(card));
  1158. goto out;
  1159. }
  1160. card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
  1161. dev_info(&card->gdev->dev, "Broadcast enabled\n");
  1162. rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
  1163. IPA_CMD_ASS_ENABLE, 1);
  1164. if (rc) {
  1165. dev_warn(&card->gdev->dev, "Setting up broadcast echo "
  1166. "filtering for %s failed\n", QETH_CARD_IFNAME(card));
  1167. goto out;
  1168. }
  1169. card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
  1170. out:
  1171. if (card->info.broadcast_capable)
  1172. card->dev->flags |= IFF_BROADCAST;
  1173. else
  1174. card->dev->flags &= ~IFF_BROADCAST;
  1175. return rc;
  1176. }
  1177. static void qeth_l3_start_ipa_checksum(struct qeth_card *card)
  1178. {
  1179. QETH_CARD_TEXT(card, 3, "strtcsum");
  1180. if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)
  1181. && (card->dev->features & NETIF_F_RXCSUM))
  1182. qeth_set_rx_csum(card, 1);
  1183. }
  1184. static void qeth_l3_start_ipa_tx_checksum(struct qeth_card *card)
  1185. {
  1186. QETH_CARD_TEXT(card, 3, "strttxcs");
  1187. qeth_start_ipa_tx_checksum(card);
  1188. }
  1189. static int qeth_l3_start_ipa_tso(struct qeth_card *card)
  1190. {
  1191. int rc;
  1192. QETH_CARD_TEXT(card, 3, "sttso");
  1193. if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
  1194. dev_info(&card->gdev->dev,
  1195. "Outbound TSO not supported on %s\n",
  1196. QETH_CARD_IFNAME(card));
  1197. rc = -EOPNOTSUPP;
  1198. } else {
  1199. rc = qeth_send_simple_setassparms(card, IPA_OUTBOUND_TSO,
  1200. IPA_CMD_ASS_START, 0);
  1201. if (rc)
  1202. dev_warn(&card->gdev->dev, "Starting outbound TCP "
  1203. "segmentation offload for %s failed\n",
  1204. QETH_CARD_IFNAME(card));
  1205. else
  1206. dev_info(&card->gdev->dev,
  1207. "Outbound TSO enabled\n");
  1208. }
  1209. if (rc)
  1210. card->dev->features &= ~NETIF_F_TSO;
  1211. return rc;
  1212. }
  1213. static int qeth_l3_start_ipassists(struct qeth_card *card)
  1214. {
  1215. QETH_CARD_TEXT(card, 3, "strtipas");
  1216. if (qeth_set_access_ctrl_online(card, 0))
  1217. return -EIO;
  1218. qeth_l3_start_ipa_arp_processing(card); /* go on*/
  1219. qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/
  1220. qeth_l3_start_ipa_source_mac(card); /* go on*/
  1221. qeth_l3_start_ipa_vlan(card); /* go on*/
  1222. qeth_l3_start_ipa_multicast(card); /* go on*/
  1223. qeth_l3_start_ipa_ipv6(card); /* go on*/
  1224. qeth_l3_start_ipa_broadcast(card); /* go on*/
  1225. qeth_l3_start_ipa_checksum(card); /* go on*/
  1226. qeth_l3_start_ipa_tx_checksum(card);
  1227. qeth_l3_start_ipa_tso(card); /* go on*/
  1228. return 0;
  1229. }
  1230. static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
  1231. struct qeth_reply *reply, unsigned long data)
  1232. {
  1233. struct qeth_ipa_cmd *cmd;
  1234. cmd = (struct qeth_ipa_cmd *) data;
  1235. if (cmd->hdr.return_code == 0)
  1236. memcpy(card->dev->dev_addr,
  1237. cmd->data.create_destroy_addr.unique_id, ETH_ALEN);
  1238. else
  1239. eth_random_addr(card->dev->dev_addr);
  1240. return 0;
  1241. }
  1242. static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
  1243. {
  1244. int rc = 0;
  1245. struct qeth_cmd_buffer *iob;
  1246. struct qeth_ipa_cmd *cmd;
  1247. QETH_DBF_TEXT(SETUP, 2, "hsrmac");
  1248. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
  1249. QETH_PROT_IPV6);
  1250. if (!iob)
  1251. return -ENOMEM;
  1252. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  1253. *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
  1254. card->info.unique_id;
  1255. rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
  1256. NULL);
  1257. return rc;
  1258. }
  1259. static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
  1260. struct qeth_reply *reply, unsigned long data)
  1261. {
  1262. struct qeth_ipa_cmd *cmd;
  1263. cmd = (struct qeth_ipa_cmd *) data;
  1264. if (cmd->hdr.return_code == 0)
  1265. card->info.unique_id = *((__u16 *)
  1266. &cmd->data.create_destroy_addr.unique_id[6]);
  1267. else {
  1268. card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
  1269. UNIQUE_ID_NOT_BY_CARD;
  1270. dev_warn(&card->gdev->dev, "The network adapter failed to "
  1271. "generate a unique ID\n");
  1272. }
  1273. return 0;
  1274. }
  1275. static int qeth_l3_get_unique_id(struct qeth_card *card)
  1276. {
  1277. int rc = 0;
  1278. struct qeth_cmd_buffer *iob;
  1279. struct qeth_ipa_cmd *cmd;
  1280. QETH_DBF_TEXT(SETUP, 2, "guniqeid");
  1281. if (!qeth_is_supported(card, IPA_IPV6)) {
  1282. card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
  1283. UNIQUE_ID_NOT_BY_CARD;
  1284. return 0;
  1285. }
  1286. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR,
  1287. QETH_PROT_IPV6);
  1288. if (!iob)
  1289. return -ENOMEM;
  1290. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  1291. *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
  1292. card->info.unique_id;
  1293. rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
  1294. return rc;
  1295. }
  1296. static int
  1297. qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
  1298. unsigned long data)
  1299. {
  1300. struct qeth_ipa_cmd *cmd;
  1301. __u16 rc;
  1302. QETH_DBF_TEXT(SETUP, 2, "diastrcb");
  1303. cmd = (struct qeth_ipa_cmd *)data;
  1304. rc = cmd->hdr.return_code;
  1305. if (rc)
  1306. QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
  1307. switch (cmd->data.diagass.action) {
  1308. case QETH_DIAGS_CMD_TRACE_QUERY:
  1309. break;
  1310. case QETH_DIAGS_CMD_TRACE_DISABLE:
  1311. switch (rc) {
  1312. case 0:
  1313. case IPA_RC_INVALID_SUBCMD:
  1314. card->info.promisc_mode = SET_PROMISC_MODE_OFF;
  1315. dev_info(&card->gdev->dev, "The HiperSockets network "
  1316. "traffic analyzer is deactivated\n");
  1317. break;
  1318. default:
  1319. break;
  1320. }
  1321. break;
  1322. case QETH_DIAGS_CMD_TRACE_ENABLE:
  1323. switch (rc) {
  1324. case 0:
  1325. card->info.promisc_mode = SET_PROMISC_MODE_ON;
  1326. dev_info(&card->gdev->dev, "The HiperSockets network "
  1327. "traffic analyzer is activated\n");
  1328. break;
  1329. case IPA_RC_HARDWARE_AUTH_ERROR:
  1330. dev_warn(&card->gdev->dev, "The device is not "
  1331. "authorized to run as a HiperSockets network "
  1332. "traffic analyzer\n");
  1333. break;
  1334. case IPA_RC_TRACE_ALREADY_ACTIVE:
  1335. dev_warn(&card->gdev->dev, "A HiperSockets "
  1336. "network traffic analyzer is already "
  1337. "active in the HiperSockets LAN\n");
  1338. break;
  1339. default:
  1340. break;
  1341. }
  1342. break;
  1343. default:
  1344. QETH_DBF_MESSAGE(2, "Unknown sniffer action (0x%04x) on %s\n",
  1345. cmd->data.diagass.action, QETH_CARD_IFNAME(card));
  1346. }
  1347. return 0;
  1348. }
  1349. static int
  1350. qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
  1351. {
  1352. struct qeth_cmd_buffer *iob;
  1353. struct qeth_ipa_cmd *cmd;
  1354. QETH_DBF_TEXT(SETUP, 2, "diagtrac");
  1355. iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
  1356. if (!iob)
  1357. return -ENOMEM;
  1358. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  1359. cmd->data.diagass.subcmd_len = 16;
  1360. cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
  1361. cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
  1362. cmd->data.diagass.action = diags_cmd;
  1363. return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
  1364. }
  1365. static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac,
  1366. struct net_device *dev)
  1367. {
  1368. ip_eth_mc_map(ipm, mac);
  1369. }
  1370. static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev)
  1371. {
  1372. struct qeth_ipaddr *ipm;
  1373. struct ip_mc_list *im4;
  1374. char buf[MAX_ADDR_LEN];
  1375. QETH_CARD_TEXT(card, 4, "addmc");
  1376. for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL;
  1377. im4 = rcu_dereference(im4->next_rcu)) {
  1378. qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev);
  1379. ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
  1380. if (!ipm)
  1381. continue;
  1382. ipm->u.a4.addr = im4->multiaddr;
  1383. memcpy(ipm->mac, buf, OSA_ADDR_LEN);
  1384. ipm->is_multicast = 1;
  1385. if (!qeth_l3_add_ip(card, ipm))
  1386. kfree(ipm);
  1387. }
  1388. }
  1389. /* called with rcu_read_lock */
  1390. static void qeth_l3_add_vlan_mc(struct qeth_card *card)
  1391. {
  1392. struct in_device *in_dev;
  1393. u16 vid;
  1394. QETH_CARD_TEXT(card, 4, "addmcvl");
  1395. if (!qeth_is_supported(card, IPA_FULL_VLAN))
  1396. return;
  1397. for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
  1398. struct net_device *netdev;
  1399. netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
  1400. vid);
  1401. if (netdev == NULL ||
  1402. !(netdev->flags & IFF_UP))
  1403. continue;
  1404. in_dev = __in_dev_get_rcu(netdev);
  1405. if (!in_dev)
  1406. continue;
  1407. qeth_l3_add_mc(card, in_dev);
  1408. }
  1409. }
  1410. static void qeth_l3_add_multicast_ipv4(struct qeth_card *card)
  1411. {
  1412. struct in_device *in4_dev;
  1413. QETH_CARD_TEXT(card, 4, "chkmcv4");
  1414. rcu_read_lock();
  1415. in4_dev = __in_dev_get_rcu(card->dev);
  1416. if (in4_dev == NULL)
  1417. goto unlock;
  1418. qeth_l3_add_mc(card, in4_dev);
  1419. qeth_l3_add_vlan_mc(card);
  1420. unlock:
  1421. rcu_read_unlock();
  1422. }
  1423. #ifdef CONFIG_QETH_IPV6
  1424. static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev)
  1425. {
  1426. struct qeth_ipaddr *ipm;
  1427. struct ifmcaddr6 *im6;
  1428. char buf[MAX_ADDR_LEN];
  1429. QETH_CARD_TEXT(card, 4, "addmc6");
  1430. for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
  1431. ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0);
  1432. ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
  1433. if (!ipm)
  1434. continue;
  1435. ipm->is_multicast = 1;
  1436. memcpy(ipm->mac, buf, OSA_ADDR_LEN);
  1437. memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr,
  1438. sizeof(struct in6_addr));
  1439. if (!qeth_l3_add_ip(card, ipm))
  1440. kfree(ipm);
  1441. }
  1442. }
  1443. /* called with rcu_read_lock */
  1444. static void qeth_l3_add_vlan_mc6(struct qeth_card *card)
  1445. {
  1446. struct inet6_dev *in_dev;
  1447. u16 vid;
  1448. QETH_CARD_TEXT(card, 4, "admc6vl");
  1449. if (!qeth_is_supported(card, IPA_FULL_VLAN))
  1450. return;
  1451. for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
  1452. struct net_device *netdev;
  1453. netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
  1454. vid);
  1455. if (netdev == NULL ||
  1456. !(netdev->flags & IFF_UP))
  1457. continue;
  1458. in_dev = in6_dev_get(netdev);
  1459. if (!in_dev)
  1460. continue;
  1461. read_lock_bh(&in_dev->lock);
  1462. qeth_l3_add_mc6(card, in_dev);
  1463. read_unlock_bh(&in_dev->lock);
  1464. in6_dev_put(in_dev);
  1465. }
  1466. }
  1467. static void qeth_l3_add_multicast_ipv6(struct qeth_card *card)
  1468. {
  1469. struct inet6_dev *in6_dev;
  1470. QETH_CARD_TEXT(card, 4, "chkmcv6");
  1471. if (!qeth_is_supported(card, IPA_IPV6))
  1472. return ;
  1473. in6_dev = in6_dev_get(card->dev);
  1474. if (in6_dev == NULL)
  1475. return;
  1476. rcu_read_lock();
  1477. read_lock_bh(&in6_dev->lock);
  1478. qeth_l3_add_mc6(card, in6_dev);
  1479. qeth_l3_add_vlan_mc6(card);
  1480. read_unlock_bh(&in6_dev->lock);
  1481. rcu_read_unlock();
  1482. in6_dev_put(in6_dev);
  1483. }
  1484. #endif /* CONFIG_QETH_IPV6 */
  1485. static void qeth_l3_free_vlan_addresses4(struct qeth_card *card,
  1486. unsigned short vid)
  1487. {
  1488. struct in_device *in_dev;
  1489. struct in_ifaddr *ifa;
  1490. struct qeth_ipaddr *addr;
  1491. struct net_device *netdev;
  1492. QETH_CARD_TEXT(card, 4, "frvaddr4");
  1493. netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
  1494. if (!netdev)
  1495. return;
  1496. in_dev = in_dev_get(netdev);
  1497. if (!in_dev)
  1498. return;
  1499. for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
  1500. addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
  1501. if (addr) {
  1502. addr->u.a4.addr = ifa->ifa_address;
  1503. addr->u.a4.mask = ifa->ifa_mask;
  1504. addr->type = QETH_IP_TYPE_NORMAL;
  1505. if (!qeth_l3_delete_ip(card, addr))
  1506. kfree(addr);
  1507. }
  1508. }
  1509. in_dev_put(in_dev);
  1510. }
  1511. static void qeth_l3_free_vlan_addresses6(struct qeth_card *card,
  1512. unsigned short vid)
  1513. {
  1514. #ifdef CONFIG_QETH_IPV6
  1515. struct inet6_dev *in6_dev;
  1516. struct inet6_ifaddr *ifa;
  1517. struct qeth_ipaddr *addr;
  1518. struct net_device *netdev;
  1519. QETH_CARD_TEXT(card, 4, "frvaddr6");
  1520. netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), vid);
  1521. if (!netdev)
  1522. return;
  1523. in6_dev = in6_dev_get(netdev);
  1524. if (!in6_dev)
  1525. return;
  1526. list_for_each_entry(ifa, &in6_dev->addr_list, if_list) {
  1527. addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
  1528. if (addr) {
  1529. memcpy(&addr->u.a6.addr, &ifa->addr,
  1530. sizeof(struct in6_addr));
  1531. addr->u.a6.pfxlen = ifa->prefix_len;
  1532. addr->type = QETH_IP_TYPE_NORMAL;
  1533. if (!qeth_l3_delete_ip(card, addr))
  1534. kfree(addr);
  1535. }
  1536. }
  1537. in6_dev_put(in6_dev);
  1538. #endif /* CONFIG_QETH_IPV6 */
  1539. }
  1540. static void qeth_l3_free_vlan_addresses(struct qeth_card *card,
  1541. unsigned short vid)
  1542. {
  1543. rcu_read_lock();
  1544. qeth_l3_free_vlan_addresses4(card, vid);
  1545. qeth_l3_free_vlan_addresses6(card, vid);
  1546. rcu_read_unlock();
  1547. }
  1548. static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
  1549. __be16 proto, u16 vid)
  1550. {
  1551. struct qeth_card *card = dev->ml_priv;
  1552. set_bit(vid, card->active_vlans);
  1553. return 0;
  1554. }
  1555. static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
  1556. __be16 proto, u16 vid)
  1557. {
  1558. struct qeth_card *card = dev->ml_priv;
  1559. unsigned long flags;
  1560. QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
  1561. if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
  1562. QETH_CARD_TEXT(card, 3, "kidREC");
  1563. return 0;
  1564. }
  1565. spin_lock_irqsave(&card->vlanlock, flags);
  1566. /* unregister IP addresses of vlan device */
  1567. qeth_l3_free_vlan_addresses(card, vid);
  1568. clear_bit(vid, card->active_vlans);
  1569. spin_unlock_irqrestore(&card->vlanlock, flags);
  1570. qeth_l3_set_multicast_list(card->dev);
  1571. return 0;
  1572. }
  1573. static inline int qeth_l3_rebuild_skb(struct qeth_card *card,
  1574. struct sk_buff *skb, struct qeth_hdr *hdr,
  1575. unsigned short *vlan_id)
  1576. {
  1577. __be16 prot;
  1578. struct iphdr *ip_hdr;
  1579. unsigned char tg_addr[MAX_ADDR_LEN];
  1580. int is_vlan = 0;
  1581. if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) {
  1582. prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 :
  1583. ETH_P_IP);
  1584. switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) {
  1585. case QETH_CAST_MULTICAST:
  1586. switch (prot) {
  1587. #ifdef CONFIG_QETH_IPV6
  1588. case __constant_htons(ETH_P_IPV6):
  1589. ndisc_mc_map((struct in6_addr *)
  1590. skb->data + 24,
  1591. tg_addr, card->dev, 0);
  1592. break;
  1593. #endif
  1594. case __constant_htons(ETH_P_IP):
  1595. ip_hdr = (struct iphdr *)skb->data;
  1596. ip_eth_mc_map(ip_hdr->daddr, tg_addr);
  1597. break;
  1598. default:
  1599. memcpy(tg_addr, card->dev->broadcast,
  1600. card->dev->addr_len);
  1601. }
  1602. card->stats.multicast++;
  1603. skb->pkt_type = PACKET_MULTICAST;
  1604. break;
  1605. case QETH_CAST_BROADCAST:
  1606. memcpy(tg_addr, card->dev->broadcast,
  1607. card->dev->addr_len);
  1608. card->stats.multicast++;
  1609. skb->pkt_type = PACKET_BROADCAST;
  1610. break;
  1611. case QETH_CAST_UNICAST:
  1612. case QETH_CAST_ANYCAST:
  1613. case QETH_CAST_NOCAST:
  1614. default:
  1615. if (card->options.sniffer)
  1616. skb->pkt_type = PACKET_OTHERHOST;
  1617. else
  1618. skb->pkt_type = PACKET_HOST;
  1619. memcpy(tg_addr, card->dev->dev_addr,
  1620. card->dev->addr_len);
  1621. }
  1622. if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR)
  1623. card->dev->header_ops->create(skb, card->dev, prot,
  1624. tg_addr, &hdr->hdr.l3.dest_addr[2],
  1625. card->dev->addr_len);
  1626. else
  1627. card->dev->header_ops->create(skb, card->dev, prot,
  1628. tg_addr, "FAKELL", card->dev->addr_len);
  1629. }
  1630. skb->protocol = eth_type_trans(skb, card->dev);
  1631. if (hdr->hdr.l3.ext_flags &
  1632. (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) {
  1633. *vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ?
  1634. hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]);
  1635. is_vlan = 1;
  1636. }
  1637. if (card->dev->features & NETIF_F_RXCSUM) {
  1638. if ((hdr->hdr.l3.ext_flags &
  1639. (QETH_HDR_EXT_CSUM_HDR_REQ |
  1640. QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
  1641. (QETH_HDR_EXT_CSUM_HDR_REQ |
  1642. QETH_HDR_EXT_CSUM_TRANSP_REQ))
  1643. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1644. else
  1645. skb->ip_summed = CHECKSUM_NONE;
  1646. } else
  1647. skb->ip_summed = CHECKSUM_NONE;
  1648. return is_vlan;
  1649. }
  1650. static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
  1651. int budget, int *done)
  1652. {
  1653. int work_done = 0;
  1654. struct sk_buff *skb;
  1655. struct qeth_hdr *hdr;
  1656. __u16 vlan_tag = 0;
  1657. int is_vlan;
  1658. unsigned int len;
  1659. __u16 magic;
  1660. *done = 0;
  1661. WARN_ON_ONCE(!budget);
  1662. while (budget) {
  1663. skb = qeth_core_get_next_skb(card,
  1664. &card->qdio.in_q->bufs[card->rx.b_index],
  1665. &card->rx.b_element, &card->rx.e_offset, &hdr);
  1666. if (!skb) {
  1667. *done = 1;
  1668. break;
  1669. }
  1670. skb->dev = card->dev;
  1671. switch (hdr->hdr.l3.id) {
  1672. case QETH_HEADER_TYPE_LAYER3:
  1673. magic = *(__u16 *)skb->data;
  1674. if ((card->info.type == QETH_CARD_TYPE_IQD) &&
  1675. (magic == ETH_P_AF_IUCV)) {
  1676. skb->protocol = ETH_P_AF_IUCV;
  1677. skb->pkt_type = PACKET_HOST;
  1678. skb->mac_header = NET_SKB_PAD;
  1679. skb->dev = card->dev;
  1680. len = skb->len;
  1681. card->dev->header_ops->create(skb, card->dev, 0,
  1682. card->dev->dev_addr, "FAKELL",
  1683. card->dev->addr_len);
  1684. netif_receive_skb(skb);
  1685. } else {
  1686. is_vlan = qeth_l3_rebuild_skb(card, skb, hdr,
  1687. &vlan_tag);
  1688. len = skb->len;
  1689. if (is_vlan && !card->options.sniffer)
  1690. __vlan_hwaccel_put_tag(skb,
  1691. htons(ETH_P_8021Q), vlan_tag);
  1692. napi_gro_receive(&card->napi, skb);
  1693. }
  1694. break;
  1695. case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */
  1696. skb->pkt_type = PACKET_HOST;
  1697. skb->protocol = eth_type_trans(skb, skb->dev);
  1698. len = skb->len;
  1699. netif_receive_skb(skb);
  1700. break;
  1701. default:
  1702. dev_kfree_skb_any(skb);
  1703. QETH_CARD_TEXT(card, 3, "inbunkno");
  1704. QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
  1705. continue;
  1706. }
  1707. work_done++;
  1708. budget--;
  1709. card->stats.rx_packets++;
  1710. card->stats.rx_bytes += len;
  1711. }
  1712. return work_done;
  1713. }
  1714. static int qeth_l3_poll(struct napi_struct *napi, int budget)
  1715. {
  1716. struct qeth_card *card = container_of(napi, struct qeth_card, napi);
  1717. int work_done = 0;
  1718. struct qeth_qdio_buffer *buffer;
  1719. int done;
  1720. int new_budget = budget;
  1721. if (card->options.performance_stats) {
  1722. card->perf_stats.inbound_cnt++;
  1723. card->perf_stats.inbound_start_time = qeth_get_micros();
  1724. }
  1725. while (1) {
  1726. if (!card->rx.b_count) {
  1727. card->rx.qdio_err = 0;
  1728. card->rx.b_count = qdio_get_next_buffers(
  1729. card->data.ccwdev, 0, &card->rx.b_index,
  1730. &card->rx.qdio_err);
  1731. if (card->rx.b_count <= 0) {
  1732. card->rx.b_count = 0;
  1733. break;
  1734. }
  1735. card->rx.b_element =
  1736. &card->qdio.in_q->bufs[card->rx.b_index]
  1737. .buffer->element[0];
  1738. card->rx.e_offset = 0;
  1739. }
  1740. while (card->rx.b_count) {
  1741. buffer = &card->qdio.in_q->bufs[card->rx.b_index];
  1742. if (!(card->rx.qdio_err &&
  1743. qeth_check_qdio_errors(card, buffer->buffer,
  1744. card->rx.qdio_err, "qinerr")))
  1745. work_done += qeth_l3_process_inbound_buffer(
  1746. card, new_budget, &done);
  1747. else
  1748. done = 1;
  1749. if (done) {
  1750. if (card->options.performance_stats)
  1751. card->perf_stats.bufs_rec++;
  1752. qeth_put_buffer_pool_entry(card,
  1753. buffer->pool_entry);
  1754. qeth_queue_input_buffer(card, card->rx.b_index);
  1755. card->rx.b_count--;
  1756. if (card->rx.b_count) {
  1757. card->rx.b_index =
  1758. (card->rx.b_index + 1) %
  1759. QDIO_MAX_BUFFERS_PER_Q;
  1760. card->rx.b_element =
  1761. &card->qdio.in_q
  1762. ->bufs[card->rx.b_index]
  1763. .buffer->element[0];
  1764. card->rx.e_offset = 0;
  1765. }
  1766. }
  1767. if (work_done >= budget)
  1768. goto out;
  1769. else
  1770. new_budget = budget - work_done;
  1771. }
  1772. }
  1773. napi_complete(napi);
  1774. if (qdio_start_irq(card->data.ccwdev, 0))
  1775. napi_schedule(&card->napi);
  1776. out:
  1777. if (card->options.performance_stats)
  1778. card->perf_stats.inbound_time += qeth_get_micros() -
  1779. card->perf_stats.inbound_start_time;
  1780. return work_done;
  1781. }
  1782. static int qeth_l3_verify_vlan_dev(struct net_device *dev,
  1783. struct qeth_card *card)
  1784. {
  1785. int rc = 0;
  1786. u16 vid;
  1787. for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) {
  1788. struct net_device *netdev;
  1789. rcu_read_lock();
  1790. netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q),
  1791. vid);
  1792. rcu_read_unlock();
  1793. if (netdev == dev) {
  1794. rc = QETH_VLAN_CARD;
  1795. break;
  1796. }
  1797. }
  1798. if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card))
  1799. return 0;
  1800. return rc;
  1801. }
  1802. static int qeth_l3_verify_dev(struct net_device *dev)
  1803. {
  1804. struct qeth_card *card;
  1805. unsigned long flags;
  1806. int rc = 0;
  1807. read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
  1808. list_for_each_entry(card, &qeth_core_card_list.list, list) {
  1809. if (card->dev == dev) {
  1810. rc = QETH_REAL_CARD;
  1811. break;
  1812. }
  1813. rc = qeth_l3_verify_vlan_dev(dev, card);
  1814. if (rc)
  1815. break;
  1816. }
  1817. read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
  1818. return rc;
  1819. }
  1820. static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
  1821. {
  1822. struct qeth_card *card = NULL;
  1823. int rc;
  1824. rc = qeth_l3_verify_dev(dev);
  1825. if (rc == QETH_REAL_CARD)
  1826. card = dev->ml_priv;
  1827. else if (rc == QETH_VLAN_CARD)
  1828. card = vlan_dev_real_dev(dev)->ml_priv;
  1829. if (card && card->options.layer2)
  1830. card = NULL;
  1831. if (card)
  1832. QETH_CARD_TEXT_(card, 4, "%d", rc);
  1833. return card ;
  1834. }
  1835. static void qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
  1836. {
  1837. QETH_DBF_TEXT(SETUP, 2, "stopcard");
  1838. QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
  1839. qeth_set_allowed_threads(card, 0, 1);
  1840. if (card->options.sniffer &&
  1841. (card->info.promisc_mode == SET_PROMISC_MODE_ON))
  1842. qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
  1843. if (card->read.state == CH_STATE_UP &&
  1844. card->write.state == CH_STATE_UP &&
  1845. (card->state == CARD_STATE_UP)) {
  1846. if (recovery_mode)
  1847. qeth_l3_stop(card->dev);
  1848. else {
  1849. rtnl_lock();
  1850. dev_close(card->dev);
  1851. rtnl_unlock();
  1852. }
  1853. card->state = CARD_STATE_SOFTSETUP;
  1854. }
  1855. if (card->state == CARD_STATE_SOFTSETUP) {
  1856. qeth_l3_clear_ip_list(card, 1);
  1857. qeth_clear_ipacmd_list(card);
  1858. card->state = CARD_STATE_HARDSETUP;
  1859. }
  1860. if (card->state == CARD_STATE_HARDSETUP) {
  1861. qeth_qdio_clear_card(card, 0);
  1862. qeth_clear_qdio_buffers(card);
  1863. qeth_clear_working_pool_list(card);
  1864. card->state = CARD_STATE_DOWN;
  1865. }
  1866. if (card->state == CARD_STATE_DOWN) {
  1867. qeth_clear_cmd_buffers(&card->read);
  1868. qeth_clear_cmd_buffers(&card->write);
  1869. }
  1870. }
  1871. /*
  1872. * test for and Switch promiscuous mode (on or off)
  1873. * either for guestlan or HiperSocket Sniffer
  1874. */
  1875. static void
  1876. qeth_l3_handle_promisc_mode(struct qeth_card *card)
  1877. {
  1878. struct net_device *dev = card->dev;
  1879. if (((dev->flags & IFF_PROMISC) &&
  1880. (card->info.promisc_mode == SET_PROMISC_MODE_ON)) ||
  1881. (!(dev->flags & IFF_PROMISC) &&
  1882. (card->info.promisc_mode == SET_PROMISC_MODE_OFF)))
  1883. return;
  1884. if (card->info.guestlan) { /* Guestlan trace */
  1885. if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
  1886. qeth_setadp_promisc_mode(card);
  1887. } else if (card->options.sniffer && /* HiperSockets trace */
  1888. qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
  1889. if (dev->flags & IFF_PROMISC) {
  1890. QETH_CARD_TEXT(card, 3, "+promisc");
  1891. qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
  1892. } else {
  1893. QETH_CARD_TEXT(card, 3, "-promisc");
  1894. qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
  1895. }
  1896. }
  1897. }
  1898. static void qeth_l3_set_multicast_list(struct net_device *dev)
  1899. {
  1900. struct qeth_card *card = dev->ml_priv;
  1901. QETH_CARD_TEXT(card, 3, "setmulti");
  1902. if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
  1903. (card->state != CARD_STATE_UP))
  1904. return;
  1905. if (!card->options.sniffer) {
  1906. qeth_l3_delete_mc_addresses(card);
  1907. qeth_l3_add_multicast_ipv4(card);
  1908. #ifdef CONFIG_QETH_IPV6
  1909. qeth_l3_add_multicast_ipv6(card);
  1910. #endif
  1911. qeth_l3_set_ip_addr_list(card);
  1912. if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
  1913. return;
  1914. }
  1915. qeth_l3_handle_promisc_mode(card);
  1916. }
  1917. static const char *qeth_l3_arp_get_error_cause(int *rc)
  1918. {
  1919. switch (*rc) {
  1920. case QETH_IPA_ARP_RC_FAILED:
  1921. *rc = -EIO;
  1922. return "operation failed";
  1923. case QETH_IPA_ARP_RC_NOTSUPP:
  1924. *rc = -EOPNOTSUPP;
  1925. return "operation not supported";
  1926. case QETH_IPA_ARP_RC_OUT_OF_RANGE:
  1927. *rc = -EINVAL;
  1928. return "argument out of range";
  1929. case QETH_IPA_ARP_RC_Q_NOTSUPP:
  1930. *rc = -EOPNOTSUPP;
  1931. return "query operation not supported";
  1932. case QETH_IPA_ARP_RC_Q_NO_DATA:
  1933. *rc = -ENOENT;
  1934. return "no query data available";
  1935. default:
  1936. return "unknown error";
  1937. }
  1938. }
  1939. static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
  1940. {
  1941. int tmp;
  1942. int rc;
  1943. QETH_CARD_TEXT(card, 3, "arpstnoe");
  1944. /*
  1945. * currently GuestLAN only supports the ARP assist function
  1946. * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
  1947. * thus we say EOPNOTSUPP for this ARP function
  1948. */
  1949. if (card->info.guestlan)
  1950. return -EOPNOTSUPP;
  1951. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  1952. return -EOPNOTSUPP;
  1953. }
  1954. rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
  1955. IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
  1956. no_entries);
  1957. if (rc) {
  1958. tmp = rc;
  1959. QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on "
  1960. "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card),
  1961. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  1962. }
  1963. return rc;
  1964. }
  1965. static __u32 get_arp_entry_size(struct qeth_card *card,
  1966. struct qeth_arp_query_data *qdata,
  1967. struct qeth_arp_entrytype *type, __u8 strip_entries)
  1968. {
  1969. __u32 rc;
  1970. __u8 is_hsi;
  1971. is_hsi = qdata->reply_bits == 5;
  1972. if (type->ip == QETHARP_IP_ADDR_V4) {
  1973. QETH_CARD_TEXT(card, 4, "arpev4");
  1974. if (strip_entries) {
  1975. rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
  1976. sizeof(struct qeth_arp_qi_entry7_short);
  1977. } else {
  1978. rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
  1979. sizeof(struct qeth_arp_qi_entry7);
  1980. }
  1981. } else if (type->ip == QETHARP_IP_ADDR_V6) {
  1982. QETH_CARD_TEXT(card, 4, "arpev6");
  1983. if (strip_entries) {
  1984. rc = is_hsi ?
  1985. sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
  1986. sizeof(struct qeth_arp_qi_entry7_short_ipv6);
  1987. } else {
  1988. rc = is_hsi ?
  1989. sizeof(struct qeth_arp_qi_entry5_ipv6) :
  1990. sizeof(struct qeth_arp_qi_entry7_ipv6);
  1991. }
  1992. } else {
  1993. QETH_CARD_TEXT(card, 4, "arpinv");
  1994. rc = 0;
  1995. }
  1996. return rc;
  1997. }
  1998. static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
  1999. {
  2000. return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
  2001. (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
  2002. }
  2003. static int qeth_l3_arp_query_cb(struct qeth_card *card,
  2004. struct qeth_reply *reply, unsigned long data)
  2005. {
  2006. struct qeth_ipa_cmd *cmd;
  2007. struct qeth_arp_query_data *qdata;
  2008. struct qeth_arp_query_info *qinfo;
  2009. int i;
  2010. int e;
  2011. int entrybytes_done;
  2012. int stripped_bytes;
  2013. __u8 do_strip_entries;
  2014. QETH_CARD_TEXT(card, 3, "arpquecb");
  2015. qinfo = (struct qeth_arp_query_info *) reply->param;
  2016. cmd = (struct qeth_ipa_cmd *) data;
  2017. QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
  2018. if (cmd->hdr.return_code) {
  2019. QETH_CARD_TEXT(card, 4, "arpcberr");
  2020. QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
  2021. return 0;
  2022. }
  2023. if (cmd->data.setassparms.hdr.return_code) {
  2024. cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
  2025. QETH_CARD_TEXT(card, 4, "setaperr");
  2026. QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
  2027. return 0;
  2028. }
  2029. qdata = &cmd->data.setassparms.data.query_arp;
  2030. QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
  2031. do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
  2032. stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
  2033. entrybytes_done = 0;
  2034. for (e = 0; e < qdata->no_entries; ++e) {
  2035. char *cur_entry;
  2036. __u32 esize;
  2037. struct qeth_arp_entrytype *etype;
  2038. cur_entry = &qdata->data + entrybytes_done;
  2039. etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
  2040. if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
  2041. QETH_CARD_TEXT(card, 4, "pmis");
  2042. QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
  2043. break;
  2044. }
  2045. esize = get_arp_entry_size(card, qdata, etype,
  2046. do_strip_entries);
  2047. QETH_CARD_TEXT_(card, 5, "esz%i", esize);
  2048. if (!esize)
  2049. break;
  2050. if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
  2051. QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOMEM);
  2052. cmd->hdr.return_code = IPA_RC_ENOMEM;
  2053. goto out_error;
  2054. }
  2055. memcpy(qinfo->udata + qinfo->udata_offset,
  2056. &qdata->data + entrybytes_done + stripped_bytes,
  2057. esize);
  2058. entrybytes_done += esize + stripped_bytes;
  2059. qinfo->udata_offset += esize;
  2060. ++qinfo->no_entries;
  2061. }
  2062. /* check if all replies received ... */
  2063. if (cmd->data.setassparms.hdr.seq_no <
  2064. cmd->data.setassparms.hdr.number_of_replies)
  2065. return 1;
  2066. QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
  2067. memcpy(qinfo->udata, &qinfo->no_entries, 4);
  2068. /* keep STRIP_ENTRIES flag so the user program can distinguish
  2069. * stripped entries from normal ones */
  2070. if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
  2071. qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
  2072. memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
  2073. QETH_CARD_TEXT_(card, 4, "rc%i", 0);
  2074. return 0;
  2075. out_error:
  2076. i = 0;
  2077. memcpy(qinfo->udata, &i, 4);
  2078. return 0;
  2079. }
  2080. static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card,
  2081. struct qeth_cmd_buffer *iob, int len,
  2082. int (*reply_cb)(struct qeth_card *, struct qeth_reply *,
  2083. unsigned long),
  2084. void *reply_param)
  2085. {
  2086. QETH_CARD_TEXT(card, 4, "sendarp");
  2087. memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
  2088. memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
  2089. &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
  2090. return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob,
  2091. reply_cb, reply_param);
  2092. }
  2093. static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
  2094. enum qeth_prot_versions prot,
  2095. struct qeth_arp_query_info *qinfo)
  2096. {
  2097. struct qeth_cmd_buffer *iob;
  2098. struct qeth_ipa_cmd *cmd;
  2099. int tmp;
  2100. int rc;
  2101. QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
  2102. iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
  2103. IPA_CMD_ASS_ARP_QUERY_INFO,
  2104. sizeof(struct qeth_arp_query_data) - sizeof(char),
  2105. prot);
  2106. if (!iob)
  2107. return -ENOMEM;
  2108. cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
  2109. cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
  2110. cmd->data.setassparms.data.query_arp.reply_bits = 0;
  2111. cmd->data.setassparms.data.query_arp.no_entries = 0;
  2112. rc = qeth_l3_send_ipa_arp_cmd(card, iob,
  2113. QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN,
  2114. qeth_l3_arp_query_cb, (void *)qinfo);
  2115. if (rc) {
  2116. tmp = rc;
  2117. QETH_DBF_MESSAGE(2,
  2118. "Error while querying ARP cache on %s: %s "
  2119. "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
  2120. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2121. }
  2122. return rc;
  2123. }
  2124. static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
  2125. {
  2126. struct qeth_arp_query_info qinfo = {0, };
  2127. int rc;
  2128. QETH_CARD_TEXT(card, 3, "arpquery");
  2129. if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
  2130. IPA_ARP_PROCESSING)) {
  2131. QETH_CARD_TEXT(card, 3, "arpqnsup");
  2132. rc = -EOPNOTSUPP;
  2133. goto out;
  2134. }
  2135. /* get size of userspace buffer and mask_bits -> 6 bytes */
  2136. if (copy_from_user(&qinfo, udata, 6)) {
  2137. rc = -EFAULT;
  2138. goto out;
  2139. }
  2140. qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
  2141. if (!qinfo.udata) {
  2142. rc = -ENOMEM;
  2143. goto out;
  2144. }
  2145. qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
  2146. rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
  2147. if (rc) {
  2148. if (copy_to_user(udata, qinfo.udata, 4))
  2149. rc = -EFAULT;
  2150. goto free_and_out;
  2151. } else {
  2152. #ifdef CONFIG_QETH_IPV6
  2153. if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
  2154. /* fails in case of GuestLAN QDIO mode */
  2155. qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6,
  2156. &qinfo);
  2157. }
  2158. #endif
  2159. if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
  2160. QETH_CARD_TEXT(card, 4, "qactf");
  2161. rc = -EFAULT;
  2162. goto free_and_out;
  2163. }
  2164. QETH_CARD_TEXT(card, 4, "qacts");
  2165. }
  2166. free_and_out:
  2167. kfree(qinfo.udata);
  2168. out:
  2169. return rc;
  2170. }
  2171. static int qeth_l3_arp_add_entry(struct qeth_card *card,
  2172. struct qeth_arp_cache_entry *entry)
  2173. {
  2174. struct qeth_cmd_buffer *iob;
  2175. char buf[16];
  2176. int tmp;
  2177. int rc;
  2178. QETH_CARD_TEXT(card, 3, "arpadent");
  2179. /*
  2180. * currently GuestLAN only supports the ARP assist function
  2181. * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
  2182. * thus we say EOPNOTSUPP for this ARP function
  2183. */
  2184. if (card->info.guestlan)
  2185. return -EOPNOTSUPP;
  2186. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  2187. return -EOPNOTSUPP;
  2188. }
  2189. iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
  2190. IPA_CMD_ASS_ARP_ADD_ENTRY,
  2191. sizeof(struct qeth_arp_cache_entry),
  2192. QETH_PROT_IPV4);
  2193. if (!iob)
  2194. return -ENOMEM;
  2195. rc = qeth_send_setassparms(card, iob,
  2196. sizeof(struct qeth_arp_cache_entry),
  2197. (unsigned long) entry,
  2198. qeth_l3_default_setassparms_cb, NULL);
  2199. if (rc) {
  2200. tmp = rc;
  2201. qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
  2202. QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s "
  2203. "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
  2204. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2205. }
  2206. return rc;
  2207. }
  2208. static int qeth_l3_arp_remove_entry(struct qeth_card *card,
  2209. struct qeth_arp_cache_entry *entry)
  2210. {
  2211. struct qeth_cmd_buffer *iob;
  2212. char buf[16] = {0, };
  2213. int tmp;
  2214. int rc;
  2215. QETH_CARD_TEXT(card, 3, "arprment");
  2216. /*
  2217. * currently GuestLAN only supports the ARP assist function
  2218. * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY;
  2219. * thus we say EOPNOTSUPP for this ARP function
  2220. */
  2221. if (card->info.guestlan)
  2222. return -EOPNOTSUPP;
  2223. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  2224. return -EOPNOTSUPP;
  2225. }
  2226. memcpy(buf, entry, 12);
  2227. iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
  2228. IPA_CMD_ASS_ARP_REMOVE_ENTRY,
  2229. 12,
  2230. QETH_PROT_IPV4);
  2231. if (!iob)
  2232. return -ENOMEM;
  2233. rc = qeth_send_setassparms(card, iob,
  2234. 12, (unsigned long)buf,
  2235. qeth_l3_default_setassparms_cb, NULL);
  2236. if (rc) {
  2237. tmp = rc;
  2238. memset(buf, 0, 16);
  2239. qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf);
  2240. QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s"
  2241. " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card),
  2242. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2243. }
  2244. return rc;
  2245. }
  2246. static int qeth_l3_arp_flush_cache(struct qeth_card *card)
  2247. {
  2248. int rc;
  2249. int tmp;
  2250. QETH_CARD_TEXT(card, 3, "arpflush");
  2251. /*
  2252. * currently GuestLAN only supports the ARP assist function
  2253. * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
  2254. * thus we say EOPNOTSUPP for this ARP function
  2255. */
  2256. if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD))
  2257. return -EOPNOTSUPP;
  2258. if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
  2259. return -EOPNOTSUPP;
  2260. }
  2261. rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
  2262. IPA_CMD_ASS_ARP_FLUSH_CACHE, 0);
  2263. if (rc) {
  2264. tmp = rc;
  2265. QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s "
  2266. "(0x%x/%d)\n", QETH_CARD_IFNAME(card),
  2267. qeth_l3_arp_get_error_cause(&rc), tmp, tmp);
  2268. }
  2269. return rc;
  2270. }
  2271. static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2272. {
  2273. struct qeth_card *card = dev->ml_priv;
  2274. struct qeth_arp_cache_entry arp_entry;
  2275. struct mii_ioctl_data *mii_data;
  2276. int rc = 0;
  2277. if (!card)
  2278. return -ENODEV;
  2279. if (!qeth_card_hw_is_reachable(card))
  2280. return -ENODEV;
  2281. switch (cmd) {
  2282. case SIOC_QETH_ARP_SET_NO_ENTRIES:
  2283. if (!capable(CAP_NET_ADMIN)) {
  2284. rc = -EPERM;
  2285. break;
  2286. }
  2287. rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
  2288. break;
  2289. case SIOC_QETH_ARP_QUERY_INFO:
  2290. if (!capable(CAP_NET_ADMIN)) {
  2291. rc = -EPERM;
  2292. break;
  2293. }
  2294. rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
  2295. break;
  2296. case SIOC_QETH_ARP_ADD_ENTRY:
  2297. if (!capable(CAP_NET_ADMIN)) {
  2298. rc = -EPERM;
  2299. break;
  2300. }
  2301. if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
  2302. sizeof(struct qeth_arp_cache_entry)))
  2303. rc = -EFAULT;
  2304. else
  2305. rc = qeth_l3_arp_add_entry(card, &arp_entry);
  2306. break;
  2307. case SIOC_QETH_ARP_REMOVE_ENTRY:
  2308. if (!capable(CAP_NET_ADMIN)) {
  2309. rc = -EPERM;
  2310. break;
  2311. }
  2312. if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data,
  2313. sizeof(struct qeth_arp_cache_entry)))
  2314. rc = -EFAULT;
  2315. else
  2316. rc = qeth_l3_arp_remove_entry(card, &arp_entry);
  2317. break;
  2318. case SIOC_QETH_ARP_FLUSH_CACHE:
  2319. if (!capable(CAP_NET_ADMIN)) {
  2320. rc = -EPERM;
  2321. break;
  2322. }
  2323. rc = qeth_l3_arp_flush_cache(card);
  2324. break;
  2325. case SIOC_QETH_ADP_SET_SNMP_CONTROL:
  2326. rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
  2327. break;
  2328. case SIOC_QETH_GET_CARD_TYPE:
  2329. if ((card->info.type == QETH_CARD_TYPE_OSD ||
  2330. card->info.type == QETH_CARD_TYPE_OSX) &&
  2331. !card->info.guestlan)
  2332. return 1;
  2333. return 0;
  2334. break;
  2335. case SIOCGMIIPHY:
  2336. mii_data = if_mii(rq);
  2337. mii_data->phy_id = 0;
  2338. break;
  2339. case SIOCGMIIREG:
  2340. mii_data = if_mii(rq);
  2341. if (mii_data->phy_id != 0)
  2342. rc = -EINVAL;
  2343. else
  2344. mii_data->val_out = qeth_mdio_read(dev,
  2345. mii_data->phy_id,
  2346. mii_data->reg_num);
  2347. break;
  2348. case SIOC_QETH_QUERY_OAT:
  2349. rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
  2350. break;
  2351. default:
  2352. rc = -EOPNOTSUPP;
  2353. }
  2354. if (rc)
  2355. QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
  2356. return rc;
  2357. }
  2358. int inline qeth_l3_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
  2359. {
  2360. int cast_type = RTN_UNSPEC;
  2361. struct neighbour *n = NULL;
  2362. struct dst_entry *dst;
  2363. rcu_read_lock();
  2364. dst = skb_dst(skb);
  2365. if (dst)
  2366. n = dst_neigh_lookup_skb(dst, skb);
  2367. if (n) {
  2368. cast_type = n->type;
  2369. rcu_read_unlock();
  2370. neigh_release(n);
  2371. if ((cast_type == RTN_BROADCAST) ||
  2372. (cast_type == RTN_MULTICAST) ||
  2373. (cast_type == RTN_ANYCAST))
  2374. return cast_type;
  2375. else
  2376. return RTN_UNSPEC;
  2377. }
  2378. rcu_read_unlock();
  2379. /* try something else */
  2380. if (skb->protocol == ETH_P_IPV6)
  2381. return (skb_network_header(skb)[24] == 0xff) ?
  2382. RTN_MULTICAST : 0;
  2383. else if (skb->protocol == ETH_P_IP)
  2384. return ((skb_network_header(skb)[16] & 0xf0) == 0xe0) ?
  2385. RTN_MULTICAST : 0;
  2386. /* ... */
  2387. if (!memcmp(skb->data, skb->dev->broadcast, 6))
  2388. return RTN_BROADCAST;
  2389. else {
  2390. u16 hdr_mac;
  2391. hdr_mac = *((u16 *)skb->data);
  2392. /* tr multicast? */
  2393. switch (card->info.link_type) {
  2394. case QETH_LINK_TYPE_HSTR:
  2395. case QETH_LINK_TYPE_LANE_TR:
  2396. if ((hdr_mac == QETH_TR_MAC_NC) ||
  2397. (hdr_mac == QETH_TR_MAC_C))
  2398. return RTN_MULTICAST;
  2399. break;
  2400. /* eth or so multicast? */
  2401. default:
  2402. if ((hdr_mac == QETH_ETH_MAC_V4) ||
  2403. (hdr_mac == QETH_ETH_MAC_V6))
  2404. return RTN_MULTICAST;
  2405. }
  2406. }
  2407. return cast_type;
  2408. }
  2409. static void qeth_l3_fill_af_iucv_hdr(struct qeth_card *card,
  2410. struct qeth_hdr *hdr, struct sk_buff *skb)
  2411. {
  2412. char daddr[16];
  2413. struct af_iucv_trans_hdr *iucv_hdr;
  2414. memset(hdr, 0, sizeof(struct qeth_hdr));
  2415. hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
  2416. hdr->hdr.l3.ext_flags = 0;
  2417. hdr->hdr.l3.length = skb->len - ETH_HLEN;
  2418. hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
  2419. iucv_hdr = (struct af_iucv_trans_hdr *) (skb->data + ETH_HLEN);
  2420. memset(daddr, 0, sizeof(daddr));
  2421. daddr[0] = 0xfe;
  2422. daddr[1] = 0x80;
  2423. memcpy(&daddr[8], iucv_hdr->destUserID, 8);
  2424. memcpy(hdr->hdr.l3.dest_addr, daddr, 16);
  2425. }
  2426. static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
  2427. struct sk_buff *skb, int ipv, int cast_type)
  2428. {
  2429. struct dst_entry *dst;
  2430. memset(hdr, 0, sizeof(struct qeth_hdr));
  2431. hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
  2432. hdr->hdr.l3.ext_flags = 0;
  2433. /*
  2434. * before we're going to overwrite this location with next hop ip.
  2435. * v6 uses passthrough, v4 sets the tag in the QDIO header.
  2436. */
  2437. if (skb_vlan_tag_present(skb)) {
  2438. if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
  2439. hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
  2440. else
  2441. hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
  2442. hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
  2443. }
  2444. hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr);
  2445. rcu_read_lock();
  2446. dst = skb_dst(skb);
  2447. if (ipv == 4) {
  2448. struct rtable *rt = (struct rtable *) dst;
  2449. __be32 *pkey = &ip_hdr(skb)->daddr;
  2450. if (rt->rt_gateway)
  2451. pkey = &rt->rt_gateway;
  2452. /* IPv4 */
  2453. hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type);
  2454. memset(hdr->hdr.l3.dest_addr, 0, 12);
  2455. *((__be32 *) (&hdr->hdr.l3.dest_addr[12])) = *pkey;
  2456. } else if (ipv == 6) {
  2457. struct rt6_info *rt = (struct rt6_info *) dst;
  2458. struct in6_addr *pkey = &ipv6_hdr(skb)->daddr;
  2459. if (!ipv6_addr_any(&rt->rt6i_gateway))
  2460. pkey = &rt->rt6i_gateway;
  2461. /* IPv6 */
  2462. hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type);
  2463. if (card->info.type == QETH_CARD_TYPE_IQD)
  2464. hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU;
  2465. memcpy(hdr->hdr.l3.dest_addr, pkey, 16);
  2466. } else {
  2467. if (!memcmp(skb->data + sizeof(struct qeth_hdr),
  2468. skb->dev->broadcast, 6)) {
  2469. /* broadcast? */
  2470. hdr->hdr.l3.flags = QETH_CAST_BROADCAST |
  2471. QETH_HDR_PASSTHRU;
  2472. } else {
  2473. hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ?
  2474. QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU :
  2475. QETH_CAST_UNICAST | QETH_HDR_PASSTHRU;
  2476. }
  2477. }
  2478. rcu_read_unlock();
  2479. }
  2480. static inline void qeth_l3_hdr_csum(struct qeth_card *card,
  2481. struct qeth_hdr *hdr, struct sk_buff *skb)
  2482. {
  2483. struct iphdr *iph = ip_hdr(skb);
  2484. /* tcph->check contains already the pseudo hdr checksum
  2485. * so just set the header flags
  2486. */
  2487. if (iph->protocol == IPPROTO_UDP)
  2488. hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_UDP;
  2489. hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
  2490. QETH_HDR_EXT_CSUM_HDR_REQ;
  2491. iph->check = 0;
  2492. if (card->options.performance_stats)
  2493. card->perf_stats.tx_csum++;
  2494. }
  2495. static void qeth_tso_fill_header(struct qeth_card *card,
  2496. struct qeth_hdr *qhdr, struct sk_buff *skb)
  2497. {
  2498. struct qeth_hdr_tso *hdr = (struct qeth_hdr_tso *)qhdr;
  2499. struct tcphdr *tcph = tcp_hdr(skb);
  2500. struct iphdr *iph = ip_hdr(skb);
  2501. struct ipv6hdr *ip6h = ipv6_hdr(skb);
  2502. /*fix header to TSO values ...*/
  2503. hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
  2504. hdr->hdr.hdr.l3.length = skb->len - sizeof(struct qeth_hdr_tso);
  2505. /*set values which are fix for the first approach ...*/
  2506. hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
  2507. hdr->ext.imb_hdr_no = 1;
  2508. hdr->ext.hdr_type = 1;
  2509. hdr->ext.hdr_version = 1;
  2510. hdr->ext.hdr_len = 28;
  2511. /*insert non-fix values */
  2512. hdr->ext.mss = skb_shinfo(skb)->gso_size;
  2513. hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
  2514. hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
  2515. sizeof(struct qeth_hdr_tso));
  2516. tcph->check = 0;
  2517. if (skb->protocol == ETH_P_IPV6) {
  2518. ip6h->payload_len = 0;
  2519. tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
  2520. 0, IPPROTO_TCP, 0);
  2521. } else {
  2522. /*OSA want us to set these values ...*/
  2523. tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
  2524. 0, IPPROTO_TCP, 0);
  2525. iph->tot_len = 0;
  2526. iph->check = 0;
  2527. }
  2528. }
  2529. static inline int qeth_l3_tso_elements(struct sk_buff *skb)
  2530. {
  2531. unsigned long tcpd = (unsigned long)tcp_hdr(skb) +
  2532. tcp_hdr(skb)->doff * 4;
  2533. int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
  2534. int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
  2535. elements += qeth_get_elements_for_frags(skb);
  2536. return elements;
  2537. }
  2538. static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
  2539. {
  2540. int rc;
  2541. u16 *tag;
  2542. struct qeth_hdr *hdr = NULL;
  2543. int elements_needed = 0;
  2544. int elems;
  2545. struct qeth_card *card = dev->ml_priv;
  2546. struct sk_buff *new_skb = NULL;
  2547. int ipv = qeth_get_ip_version(skb);
  2548. int cast_type = qeth_l3_get_cast_type(card, skb);
  2549. struct qeth_qdio_out_q *queue =
  2550. card->qdio.out_qs[card->qdio.do_prio_queueing
  2551. || (cast_type && card->info.is_multicast_different) ?
  2552. qeth_get_priority_queue(card, skb, ipv, cast_type) :
  2553. card->qdio.default_out_queue];
  2554. int tx_bytes = skb->len;
  2555. bool large_send;
  2556. int data_offset = -1;
  2557. int nr_frags;
  2558. if (((card->info.type == QETH_CARD_TYPE_IQD) &&
  2559. (((card->options.cq != QETH_CQ_ENABLED) && !ipv) ||
  2560. ((card->options.cq == QETH_CQ_ENABLED) &&
  2561. (skb->protocol != ETH_P_AF_IUCV)))) ||
  2562. card->options.sniffer)
  2563. goto tx_drop;
  2564. if ((card->state != CARD_STATE_UP) || !card->lan_online) {
  2565. card->stats.tx_carrier_errors++;
  2566. goto tx_drop;
  2567. }
  2568. if ((cast_type == RTN_BROADCAST) &&
  2569. (card->info.broadcast_capable == 0))
  2570. goto tx_drop;
  2571. if (card->options.performance_stats) {
  2572. card->perf_stats.outbound_cnt++;
  2573. card->perf_stats.outbound_start_time = qeth_get_micros();
  2574. }
  2575. large_send = skb_is_gso(skb);
  2576. if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
  2577. (skb_shinfo(skb)->nr_frags == 0)) {
  2578. new_skb = skb;
  2579. data_offset = ETH_HLEN;
  2580. hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
  2581. if (!hdr)
  2582. goto tx_drop;
  2583. elements_needed++;
  2584. } else {
  2585. /* create a clone with writeable headroom */
  2586. new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso)
  2587. + VLAN_HLEN);
  2588. if (!new_skb)
  2589. goto tx_drop;
  2590. }
  2591. if (card->info.type == QETH_CARD_TYPE_IQD) {
  2592. if (data_offset < 0)
  2593. skb_pull(new_skb, ETH_HLEN);
  2594. } else {
  2595. if (ipv == 4) {
  2596. skb_pull(new_skb, ETH_HLEN);
  2597. }
  2598. if (ipv != 4 && skb_vlan_tag_present(new_skb)) {
  2599. skb_push(new_skb, VLAN_HLEN);
  2600. skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4);
  2601. skb_copy_to_linear_data_offset(new_skb, 4,
  2602. new_skb->data + 8, 4);
  2603. skb_copy_to_linear_data_offset(new_skb, 8,
  2604. new_skb->data + 12, 4);
  2605. tag = (u16 *)(new_skb->data + 12);
  2606. *tag = __constant_htons(ETH_P_8021Q);
  2607. *(tag + 1) = htons(skb_vlan_tag_get(new_skb));
  2608. }
  2609. }
  2610. netif_stop_queue(dev);
  2611. /* fix hardware limitation: as long as we do not have sbal
  2612. * chaining we can not send long frag lists
  2613. */
  2614. if (large_send) {
  2615. if (qeth_l3_tso_elements(new_skb) + 1 > 16) {
  2616. if (skb_linearize(new_skb))
  2617. goto tx_drop;
  2618. if (card->options.performance_stats)
  2619. card->perf_stats.tx_lin++;
  2620. }
  2621. }
  2622. if (large_send && (cast_type == RTN_UNSPEC)) {
  2623. hdr = (struct qeth_hdr *)skb_push(new_skb,
  2624. sizeof(struct qeth_hdr_tso));
  2625. memset(hdr, 0, sizeof(struct qeth_hdr_tso));
  2626. qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type);
  2627. qeth_tso_fill_header(card, hdr, new_skb);
  2628. elements_needed++;
  2629. } else {
  2630. if (data_offset < 0) {
  2631. hdr = (struct qeth_hdr *)skb_push(new_skb,
  2632. sizeof(struct qeth_hdr));
  2633. qeth_l3_fill_header(card, hdr, new_skb, ipv,
  2634. cast_type);
  2635. } else {
  2636. if (new_skb->protocol == ETH_P_AF_IUCV)
  2637. qeth_l3_fill_af_iucv_hdr(card, hdr, new_skb);
  2638. else {
  2639. qeth_l3_fill_header(card, hdr, new_skb, ipv,
  2640. cast_type);
  2641. hdr->hdr.l3.length = new_skb->len - data_offset;
  2642. }
  2643. }
  2644. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2645. qeth_l3_hdr_csum(card, hdr, new_skb);
  2646. }
  2647. elems = qeth_get_elements_no(card, new_skb, elements_needed);
  2648. if (!elems) {
  2649. if (data_offset >= 0)
  2650. kmem_cache_free(qeth_core_header_cache, hdr);
  2651. goto tx_drop;
  2652. }
  2653. elements_needed += elems;
  2654. nr_frags = skb_shinfo(new_skb)->nr_frags;
  2655. if (card->info.type != QETH_CARD_TYPE_IQD) {
  2656. int len;
  2657. if (large_send)
  2658. len = ((unsigned long)tcp_hdr(new_skb) +
  2659. tcp_hdr(new_skb)->doff * 4) -
  2660. (unsigned long)new_skb->data;
  2661. else
  2662. len = sizeof(struct qeth_hdr_layer3);
  2663. if (qeth_hdr_chk_and_bounce(new_skb, &hdr, len))
  2664. goto tx_drop;
  2665. rc = qeth_do_send_packet(card, queue, new_skb, hdr,
  2666. elements_needed);
  2667. } else
  2668. rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
  2669. elements_needed, data_offset, 0);
  2670. if (!rc) {
  2671. card->stats.tx_packets++;
  2672. card->stats.tx_bytes += tx_bytes;
  2673. if (new_skb != skb)
  2674. dev_kfree_skb_any(skb);
  2675. if (card->options.performance_stats) {
  2676. if (large_send) {
  2677. card->perf_stats.large_send_bytes += tx_bytes;
  2678. card->perf_stats.large_send_cnt++;
  2679. }
  2680. if (nr_frags) {
  2681. card->perf_stats.sg_skbs_sent++;
  2682. /* nr_frags + skb->data */
  2683. card->perf_stats.sg_frags_sent += nr_frags + 1;
  2684. }
  2685. }
  2686. rc = NETDEV_TX_OK;
  2687. } else {
  2688. if (data_offset >= 0)
  2689. kmem_cache_free(qeth_core_header_cache, hdr);
  2690. if (rc == -EBUSY) {
  2691. if (new_skb != skb)
  2692. dev_kfree_skb_any(new_skb);
  2693. return NETDEV_TX_BUSY;
  2694. } else
  2695. goto tx_drop;
  2696. }
  2697. netif_wake_queue(dev);
  2698. if (card->options.performance_stats)
  2699. card->perf_stats.outbound_time += qeth_get_micros() -
  2700. card->perf_stats.outbound_start_time;
  2701. return rc;
  2702. tx_drop:
  2703. card->stats.tx_dropped++;
  2704. card->stats.tx_errors++;
  2705. if ((new_skb != skb) && new_skb)
  2706. dev_kfree_skb_any(new_skb);
  2707. dev_kfree_skb_any(skb);
  2708. netif_wake_queue(dev);
  2709. return NETDEV_TX_OK;
  2710. }
  2711. static int __qeth_l3_open(struct net_device *dev)
  2712. {
  2713. struct qeth_card *card = dev->ml_priv;
  2714. int rc = 0;
  2715. QETH_CARD_TEXT(card, 4, "qethopen");
  2716. if (card->state == CARD_STATE_UP)
  2717. return rc;
  2718. if (card->state != CARD_STATE_SOFTSETUP)
  2719. return -ENODEV;
  2720. card->data.state = CH_STATE_UP;
  2721. card->state = CARD_STATE_UP;
  2722. netif_start_queue(dev);
  2723. if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
  2724. napi_enable(&card->napi);
  2725. napi_schedule(&card->napi);
  2726. } else
  2727. rc = -EIO;
  2728. return rc;
  2729. }
  2730. static int qeth_l3_open(struct net_device *dev)
  2731. {
  2732. struct qeth_card *card = dev->ml_priv;
  2733. QETH_CARD_TEXT(card, 5, "qethope_");
  2734. if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
  2735. QETH_CARD_TEXT(card, 3, "openREC");
  2736. return -ERESTARTSYS;
  2737. }
  2738. return __qeth_l3_open(dev);
  2739. }
  2740. static int qeth_l3_stop(struct net_device *dev)
  2741. {
  2742. struct qeth_card *card = dev->ml_priv;
  2743. QETH_CARD_TEXT(card, 4, "qethstop");
  2744. netif_tx_disable(dev);
  2745. if (card->state == CARD_STATE_UP) {
  2746. card->state = CARD_STATE_SOFTSETUP;
  2747. napi_disable(&card->napi);
  2748. }
  2749. return 0;
  2750. }
  2751. static netdev_features_t qeth_l3_fix_features(struct net_device *dev,
  2752. netdev_features_t features)
  2753. {
  2754. struct qeth_card *card = dev->ml_priv;
  2755. if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
  2756. features &= ~NETIF_F_IP_CSUM;
  2757. if (!qeth_is_supported(card, IPA_OUTBOUND_TSO))
  2758. features &= ~NETIF_F_TSO;
  2759. if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
  2760. features &= ~NETIF_F_RXCSUM;
  2761. return features;
  2762. }
  2763. static int qeth_l3_set_features(struct net_device *dev,
  2764. netdev_features_t features)
  2765. {
  2766. struct qeth_card *card = dev->ml_priv;
  2767. netdev_features_t changed = dev->features ^ features;
  2768. if (!(changed & NETIF_F_RXCSUM))
  2769. return 0;
  2770. if (card->state == CARD_STATE_DOWN ||
  2771. card->state == CARD_STATE_RECOVER)
  2772. return 0;
  2773. return qeth_set_rx_csum(card, features & NETIF_F_RXCSUM ? 1 : 0);
  2774. }
  2775. static const struct ethtool_ops qeth_l3_ethtool_ops = {
  2776. .get_link = ethtool_op_get_link,
  2777. .get_strings = qeth_core_get_strings,
  2778. .get_ethtool_stats = qeth_core_get_ethtool_stats,
  2779. .get_sset_count = qeth_core_get_sset_count,
  2780. .get_drvinfo = qeth_core_get_drvinfo,
  2781. .get_settings = qeth_core_ethtool_get_settings,
  2782. };
  2783. /*
  2784. * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
  2785. * NOARP on the netdevice is no option because it also turns off neighbor
  2786. * solicitation. For IPv4 we install a neighbor_setup function. We don't want
  2787. * arp resolution but we want the hard header (packet socket will work
  2788. * e.g. tcpdump)
  2789. */
  2790. static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
  2791. {
  2792. n->nud_state = NUD_NOARP;
  2793. memcpy(n->ha, "FAKELL", 6);
  2794. n->output = n->ops->connected_output;
  2795. return 0;
  2796. }
  2797. static int
  2798. qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
  2799. {
  2800. if (np->tbl->family == AF_INET)
  2801. np->neigh_setup = qeth_l3_neigh_setup_noarp;
  2802. return 0;
  2803. }
  2804. static const struct net_device_ops qeth_l3_netdev_ops = {
  2805. .ndo_open = qeth_l3_open,
  2806. .ndo_stop = qeth_l3_stop,
  2807. .ndo_get_stats = qeth_get_stats,
  2808. .ndo_start_xmit = qeth_l3_hard_start_xmit,
  2809. .ndo_validate_addr = eth_validate_addr,
  2810. .ndo_set_rx_mode = qeth_l3_set_multicast_list,
  2811. .ndo_do_ioctl = qeth_l3_do_ioctl,
  2812. .ndo_change_mtu = qeth_change_mtu,
  2813. .ndo_fix_features = qeth_l3_fix_features,
  2814. .ndo_set_features = qeth_l3_set_features,
  2815. .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
  2816. .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
  2817. .ndo_tx_timeout = qeth_tx_timeout,
  2818. };
  2819. static const struct net_device_ops qeth_l3_osa_netdev_ops = {
  2820. .ndo_open = qeth_l3_open,
  2821. .ndo_stop = qeth_l3_stop,
  2822. .ndo_get_stats = qeth_get_stats,
  2823. .ndo_start_xmit = qeth_l3_hard_start_xmit,
  2824. .ndo_validate_addr = eth_validate_addr,
  2825. .ndo_set_rx_mode = qeth_l3_set_multicast_list,
  2826. .ndo_do_ioctl = qeth_l3_do_ioctl,
  2827. .ndo_change_mtu = qeth_change_mtu,
  2828. .ndo_fix_features = qeth_l3_fix_features,
  2829. .ndo_set_features = qeth_l3_set_features,
  2830. .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
  2831. .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
  2832. .ndo_tx_timeout = qeth_tx_timeout,
  2833. .ndo_neigh_setup = qeth_l3_neigh_setup,
  2834. };
  2835. static int qeth_l3_setup_netdev(struct qeth_card *card)
  2836. {
  2837. int rc;
  2838. if (card->info.type == QETH_CARD_TYPE_OSD ||
  2839. card->info.type == QETH_CARD_TYPE_OSX) {
  2840. if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
  2841. (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
  2842. pr_info("qeth_l3: ignoring TR device\n");
  2843. return -ENODEV;
  2844. } else {
  2845. card->dev = alloc_etherdev(0);
  2846. if (!card->dev)
  2847. return -ENODEV;
  2848. card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
  2849. /*IPv6 address autoconfiguration stuff*/
  2850. qeth_l3_get_unique_id(card);
  2851. if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
  2852. card->dev->dev_id = card->info.unique_id &
  2853. 0xffff;
  2854. if (!card->info.guestlan) {
  2855. card->dev->hw_features = NETIF_F_SG |
  2856. NETIF_F_RXCSUM | NETIF_F_IP_CSUM |
  2857. NETIF_F_TSO;
  2858. card->dev->features = NETIF_F_RXCSUM;
  2859. }
  2860. }
  2861. } else if (card->info.type == QETH_CARD_TYPE_IQD) {
  2862. card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
  2863. ether_setup);
  2864. if (!card->dev)
  2865. return -ENODEV;
  2866. card->dev->flags |= IFF_NOARP;
  2867. card->dev->netdev_ops = &qeth_l3_netdev_ops;
  2868. rc = qeth_l3_iqd_read_initial_mac(card);
  2869. if (rc)
  2870. return rc;
  2871. if (card->options.hsuid[0])
  2872. memcpy(card->dev->perm_addr, card->options.hsuid, 9);
  2873. } else
  2874. return -ENODEV;
  2875. card->dev->ml_priv = card;
  2876. card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
  2877. card->dev->mtu = card->info.initial_mtu;
  2878. card->dev->ethtool_ops = &qeth_l3_ethtool_ops;
  2879. card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
  2880. NETIF_F_HW_VLAN_CTAG_RX |
  2881. NETIF_F_HW_VLAN_CTAG_FILTER;
  2882. netif_keep_dst(card->dev);
  2883. card->dev->gso_max_size = 15 * PAGE_SIZE;
  2884. SET_NETDEV_DEV(card->dev, &card->gdev->dev);
  2885. netif_napi_add(card->dev, &card->napi, qeth_l3_poll, QETH_NAPI_WEIGHT);
  2886. netif_carrier_off(card->dev);
  2887. return register_netdev(card->dev);
  2888. }
  2889. static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
  2890. {
  2891. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  2892. int rc;
  2893. rc = qeth_l3_create_device_attributes(&gdev->dev);
  2894. if (rc)
  2895. return rc;
  2896. card->options.layer2 = 0;
  2897. card->info.hwtrap = 0;
  2898. return 0;
  2899. }
  2900. static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
  2901. {
  2902. struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
  2903. qeth_l3_remove_device_attributes(&cgdev->dev);
  2904. qeth_set_allowed_threads(card, 0, 1);
  2905. wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
  2906. if (cgdev->state == CCWGROUP_ONLINE)
  2907. qeth_l3_set_offline(cgdev);
  2908. if (card->dev) {
  2909. unregister_netdev(card->dev);
  2910. free_netdev(card->dev);
  2911. card->dev = NULL;
  2912. }
  2913. qeth_l3_clear_ip_list(card, 0);
  2914. qeth_l3_clear_ipato_list(card);
  2915. return;
  2916. }
  2917. static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
  2918. {
  2919. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  2920. int rc = 0;
  2921. enum qeth_card_states recover_flag;
  2922. mutex_lock(&card->discipline_mutex);
  2923. mutex_lock(&card->conf_mutex);
  2924. QETH_DBF_TEXT(SETUP, 2, "setonlin");
  2925. QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
  2926. recover_flag = card->state;
  2927. rc = qeth_core_hardsetup_card(card);
  2928. if (rc) {
  2929. QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
  2930. rc = -ENODEV;
  2931. goto out_remove;
  2932. }
  2933. if (!card->dev && qeth_l3_setup_netdev(card)) {
  2934. rc = -ENODEV;
  2935. goto out_remove;
  2936. }
  2937. if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
  2938. if (card->info.hwtrap &&
  2939. qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
  2940. card->info.hwtrap = 0;
  2941. } else
  2942. card->info.hwtrap = 0;
  2943. card->state = CARD_STATE_HARDSETUP;
  2944. memset(&card->rx, 0, sizeof(struct qeth_rx));
  2945. qeth_print_status_message(card);
  2946. /* softsetup */
  2947. QETH_DBF_TEXT(SETUP, 2, "softsetp");
  2948. rc = qeth_l3_setadapter_parms(card);
  2949. if (rc)
  2950. QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
  2951. if (!card->options.sniffer) {
  2952. rc = qeth_l3_start_ipassists(card);
  2953. if (rc) {
  2954. QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc);
  2955. goto out_remove;
  2956. }
  2957. rc = qeth_l3_setrouting_v4(card);
  2958. if (rc)
  2959. QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc);
  2960. rc = qeth_l3_setrouting_v6(card);
  2961. if (rc)
  2962. QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc);
  2963. }
  2964. netif_tx_disable(card->dev);
  2965. rc = qeth_init_qdio_queues(card);
  2966. if (rc) {
  2967. QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
  2968. rc = -ENODEV;
  2969. goto out_remove;
  2970. }
  2971. card->state = CARD_STATE_SOFTSETUP;
  2972. qeth_set_allowed_threads(card, 0xffffffff, 0);
  2973. qeth_l3_set_ip_addr_list(card);
  2974. if (card->lan_online)
  2975. netif_carrier_on(card->dev);
  2976. else
  2977. netif_carrier_off(card->dev);
  2978. if (recover_flag == CARD_STATE_RECOVER) {
  2979. rtnl_lock();
  2980. if (recovery_mode)
  2981. __qeth_l3_open(card->dev);
  2982. else
  2983. dev_open(card->dev);
  2984. qeth_l3_set_multicast_list(card->dev);
  2985. rtnl_unlock();
  2986. }
  2987. qeth_trace_features(card);
  2988. /* let user_space know that device is online */
  2989. kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
  2990. mutex_unlock(&card->conf_mutex);
  2991. mutex_unlock(&card->discipline_mutex);
  2992. return 0;
  2993. out_remove:
  2994. qeth_l3_stop_card(card, 0);
  2995. ccw_device_set_offline(CARD_DDEV(card));
  2996. ccw_device_set_offline(CARD_WDEV(card));
  2997. ccw_device_set_offline(CARD_RDEV(card));
  2998. qdio_free(CARD_DDEV(card));
  2999. if (recover_flag == CARD_STATE_RECOVER)
  3000. card->state = CARD_STATE_RECOVER;
  3001. else
  3002. card->state = CARD_STATE_DOWN;
  3003. mutex_unlock(&card->conf_mutex);
  3004. mutex_unlock(&card->discipline_mutex);
  3005. return rc;
  3006. }
  3007. static int qeth_l3_set_online(struct ccwgroup_device *gdev)
  3008. {
  3009. return __qeth_l3_set_online(gdev, 0);
  3010. }
  3011. static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
  3012. int recovery_mode)
  3013. {
  3014. struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
  3015. int rc = 0, rc2 = 0, rc3 = 0;
  3016. enum qeth_card_states recover_flag;
  3017. mutex_lock(&card->discipline_mutex);
  3018. mutex_lock(&card->conf_mutex);
  3019. QETH_DBF_TEXT(SETUP, 3, "setoffl");
  3020. QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
  3021. if (card->dev && netif_carrier_ok(card->dev))
  3022. netif_carrier_off(card->dev);
  3023. recover_flag = card->state;
  3024. if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
  3025. qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
  3026. card->info.hwtrap = 1;
  3027. }
  3028. qeth_l3_stop_card(card, recovery_mode);
  3029. if ((card->options.cq == QETH_CQ_ENABLED) && card->dev) {
  3030. rtnl_lock();
  3031. call_netdevice_notifiers(NETDEV_REBOOT, card->dev);
  3032. rtnl_unlock();
  3033. }
  3034. rc = ccw_device_set_offline(CARD_DDEV(card));
  3035. rc2 = ccw_device_set_offline(CARD_WDEV(card));
  3036. rc3 = ccw_device_set_offline(CARD_RDEV(card));
  3037. if (!rc)
  3038. rc = (rc2) ? rc2 : rc3;
  3039. if (rc)
  3040. QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
  3041. qdio_free(CARD_DDEV(card));
  3042. if (recover_flag == CARD_STATE_UP)
  3043. card->state = CARD_STATE_RECOVER;
  3044. /* let user_space know that device is offline */
  3045. kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
  3046. mutex_unlock(&card->conf_mutex);
  3047. mutex_unlock(&card->discipline_mutex);
  3048. return 0;
  3049. }
  3050. static int qeth_l3_set_offline(struct ccwgroup_device *cgdev)
  3051. {
  3052. return __qeth_l3_set_offline(cgdev, 0);
  3053. }
  3054. static int qeth_l3_recover(void *ptr)
  3055. {
  3056. struct qeth_card *card;
  3057. int rc = 0;
  3058. card = (struct qeth_card *) ptr;
  3059. QETH_CARD_TEXT(card, 2, "recover1");
  3060. QETH_CARD_HEX(card, 2, &card, sizeof(void *));
  3061. if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
  3062. return 0;
  3063. QETH_CARD_TEXT(card, 2, "recover2");
  3064. dev_warn(&card->gdev->dev,
  3065. "A recovery process has been started for the device\n");
  3066. qeth_set_recovery_task(card);
  3067. __qeth_l3_set_offline(card->gdev, 1);
  3068. rc = __qeth_l3_set_online(card->gdev, 1);
  3069. if (!rc)
  3070. dev_info(&card->gdev->dev,
  3071. "Device successfully recovered!\n");
  3072. else {
  3073. qeth_close_dev(card);
  3074. dev_warn(&card->gdev->dev, "The qeth device driver "
  3075. "failed to recover an error on the device\n");
  3076. }
  3077. qeth_clear_recovery_task(card);
  3078. qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
  3079. qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
  3080. return 0;
  3081. }
  3082. static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
  3083. {
  3084. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3085. qeth_set_allowed_threads(card, 0, 1);
  3086. if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
  3087. qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
  3088. qeth_qdio_clear_card(card, 0);
  3089. qeth_clear_qdio_buffers(card);
  3090. qdio_free(CARD_DDEV(card));
  3091. }
  3092. static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
  3093. {
  3094. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3095. if (card->dev)
  3096. netif_device_detach(card->dev);
  3097. qeth_set_allowed_threads(card, 0, 1);
  3098. wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
  3099. if (gdev->state == CCWGROUP_OFFLINE)
  3100. return 0;
  3101. if (card->state == CARD_STATE_UP) {
  3102. if (card->info.hwtrap)
  3103. qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
  3104. __qeth_l3_set_offline(card->gdev, 1);
  3105. } else
  3106. __qeth_l3_set_offline(card->gdev, 0);
  3107. return 0;
  3108. }
  3109. static int qeth_l3_pm_resume(struct ccwgroup_device *gdev)
  3110. {
  3111. struct qeth_card *card = dev_get_drvdata(&gdev->dev);
  3112. int rc = 0;
  3113. if (gdev->state == CCWGROUP_OFFLINE)
  3114. goto out;
  3115. if (card->state == CARD_STATE_RECOVER) {
  3116. rc = __qeth_l3_set_online(card->gdev, 1);
  3117. if (rc) {
  3118. rtnl_lock();
  3119. dev_close(card->dev);
  3120. rtnl_unlock();
  3121. }
  3122. } else
  3123. rc = __qeth_l3_set_online(card->gdev, 0);
  3124. out:
  3125. qeth_set_allowed_threads(card, 0xffffffff, 0);
  3126. if (card->dev)
  3127. netif_device_attach(card->dev);
  3128. if (rc)
  3129. dev_warn(&card->gdev->dev, "The qeth device driver "
  3130. "failed to recover an error on the device\n");
  3131. return rc;
  3132. }
  3133. /* Returns zero if the command is successfully "consumed" */
  3134. static int qeth_l3_control_event(struct qeth_card *card,
  3135. struct qeth_ipa_cmd *cmd)
  3136. {
  3137. return 1;
  3138. }
  3139. struct qeth_discipline qeth_l3_discipline = {
  3140. .devtype = &qeth_generic_devtype,
  3141. .start_poll = qeth_qdio_start_poll,
  3142. .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
  3143. .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
  3144. .recover = qeth_l3_recover,
  3145. .setup = qeth_l3_probe_device,
  3146. .remove = qeth_l3_remove_device,
  3147. .set_online = qeth_l3_set_online,
  3148. .set_offline = qeth_l3_set_offline,
  3149. .shutdown = qeth_l3_shutdown,
  3150. .freeze = qeth_l3_pm_suspend,
  3151. .thaw = qeth_l3_pm_resume,
  3152. .restore = qeth_l3_pm_resume,
  3153. .control_event_handler = qeth_l3_control_event,
  3154. };
  3155. EXPORT_SYMBOL_GPL(qeth_l3_discipline);
  3156. static int qeth_l3_ip_event(struct notifier_block *this,
  3157. unsigned long event, void *ptr)
  3158. {
  3159. struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
  3160. struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev;
  3161. struct qeth_ipaddr *addr;
  3162. struct qeth_card *card;
  3163. if (dev_net(dev) != &init_net)
  3164. return NOTIFY_DONE;
  3165. card = qeth_l3_get_card_from_dev(dev);
  3166. if (!card)
  3167. return NOTIFY_DONE;
  3168. QETH_CARD_TEXT(card, 3, "ipevent");
  3169. addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4);
  3170. if (addr != NULL) {
  3171. addr->u.a4.addr = ifa->ifa_address;
  3172. addr->u.a4.mask = ifa->ifa_mask;
  3173. addr->type = QETH_IP_TYPE_NORMAL;
  3174. } else
  3175. goto out;
  3176. switch (event) {
  3177. case NETDEV_UP:
  3178. if (!qeth_l3_add_ip(card, addr))
  3179. kfree(addr);
  3180. break;
  3181. case NETDEV_DOWN:
  3182. if (!qeth_l3_delete_ip(card, addr))
  3183. kfree(addr);
  3184. break;
  3185. default:
  3186. break;
  3187. }
  3188. qeth_l3_set_ip_addr_list(card);
  3189. out:
  3190. return NOTIFY_DONE;
  3191. }
  3192. static struct notifier_block qeth_l3_ip_notifier = {
  3193. qeth_l3_ip_event,
  3194. NULL,
  3195. };
  3196. #ifdef CONFIG_QETH_IPV6
  3197. /**
  3198. * IPv6 event handler
  3199. */
  3200. static int qeth_l3_ip6_event(struct notifier_block *this,
  3201. unsigned long event, void *ptr)
  3202. {
  3203. struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
  3204. struct net_device *dev = (struct net_device *)ifa->idev->dev;
  3205. struct qeth_ipaddr *addr;
  3206. struct qeth_card *card;
  3207. card = qeth_l3_get_card_from_dev(dev);
  3208. if (!card)
  3209. return NOTIFY_DONE;
  3210. QETH_CARD_TEXT(card, 3, "ip6event");
  3211. if (!qeth_is_supported(card, IPA_IPV6))
  3212. return NOTIFY_DONE;
  3213. addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6);
  3214. if (addr != NULL) {
  3215. memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr));
  3216. addr->u.a6.pfxlen = ifa->prefix_len;
  3217. addr->type = QETH_IP_TYPE_NORMAL;
  3218. } else
  3219. goto out;
  3220. switch (event) {
  3221. case NETDEV_UP:
  3222. if (!qeth_l3_add_ip(card, addr))
  3223. kfree(addr);
  3224. break;
  3225. case NETDEV_DOWN:
  3226. if (!qeth_l3_delete_ip(card, addr))
  3227. kfree(addr);
  3228. break;
  3229. default:
  3230. break;
  3231. }
  3232. qeth_l3_set_ip_addr_list(card);
  3233. out:
  3234. return NOTIFY_DONE;
  3235. }
  3236. static struct notifier_block qeth_l3_ip6_notifier = {
  3237. qeth_l3_ip6_event,
  3238. NULL,
  3239. };
  3240. #endif
  3241. static int qeth_l3_register_notifiers(void)
  3242. {
  3243. int rc;
  3244. QETH_DBF_TEXT(SETUP, 5, "regnotif");
  3245. rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
  3246. if (rc)
  3247. return rc;
  3248. #ifdef CONFIG_QETH_IPV6
  3249. rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
  3250. if (rc) {
  3251. unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
  3252. return rc;
  3253. }
  3254. #else
  3255. pr_warning("There is no IPv6 support for the layer 3 discipline\n");
  3256. #endif
  3257. return 0;
  3258. }
  3259. static void qeth_l3_unregister_notifiers(void)
  3260. {
  3261. QETH_DBF_TEXT(SETUP, 5, "unregnot");
  3262. WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
  3263. #ifdef CONFIG_QETH_IPV6
  3264. WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
  3265. #endif /* QETH_IPV6 */
  3266. }
  3267. static int __init qeth_l3_init(void)
  3268. {
  3269. int rc = 0;
  3270. pr_info("register layer 3 discipline\n");
  3271. rc = qeth_l3_register_notifiers();
  3272. return rc;
  3273. }
  3274. static void __exit qeth_l3_exit(void)
  3275. {
  3276. qeth_l3_unregister_notifiers();
  3277. pr_info("unregister layer 3 discipline\n");
  3278. }
  3279. module_init(qeth_l3_init);
  3280. module_exit(qeth_l3_exit);
  3281. MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
  3282. MODULE_DESCRIPTION("qeth layer 3 discipline");
  3283. MODULE_LICENSE("GPL");