qeth_l3_main.c 99 KB

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