lec.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496
  1. /*
  2. * lec.c: Lan Emulation driver
  3. *
  4. * Marko Kiiskila <mkiiskila@yahoo.com>
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/bitops.h>
  8. #include <linux/capability.h>
  9. /* We are ethernet device */
  10. #include <linux/if_ether.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/etherdevice.h>
  13. #include <net/sock.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/ip.h>
  16. #include <asm/byteorder.h>
  17. #include <asm/uaccess.h>
  18. #include <net/arp.h>
  19. #include <net/dst.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/proc_fs.h>
  23. #include <linux/seq_file.h>
  24. /* TokenRing if needed */
  25. #ifdef CONFIG_TR
  26. #include <linux/trdevice.h>
  27. #endif
  28. /* And atm device */
  29. #include <linux/atmdev.h>
  30. #include <linux/atmlec.h>
  31. /* Proxy LEC knows about bridging */
  32. #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
  33. #include <linux/if_bridge.h>
  34. #include "../bridge/br_private.h"
  35. static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
  36. #endif
  37. /* Modular too */
  38. #include <linux/module.h>
  39. #include <linux/init.h>
  40. #include "lec.h"
  41. #include "lec_arpc.h"
  42. #include "resources.h"
  43. #if 0
  44. #define DPRINTK printk
  45. #else
  46. #define DPRINTK(format,args...)
  47. #endif
  48. #define DUMP_PACKETS 0 /*
  49. * 0 = None,
  50. * 1 = 30 first bytes
  51. * 2 = Whole packet
  52. */
  53. #define LEC_UNRES_QUE_LEN 8 /*
  54. * number of tx packets to queue for a
  55. * single destination while waiting for SVC
  56. */
  57. static int lec_open(struct net_device *dev);
  58. static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
  59. static int lec_close(struct net_device *dev);
  60. static struct net_device_stats *lec_get_stats(struct net_device *dev);
  61. static void lec_init(struct net_device *dev);
  62. static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
  63. unsigned char *mac_addr);
  64. static int lec_arp_remove(struct lec_priv *priv,
  65. struct lec_arp_table *to_remove);
  66. /* LANE2 functions */
  67. static void lane2_associate_ind(struct net_device *dev, u8 *mac_address,
  68. u8 *tlvs, u32 sizeoftlvs);
  69. static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
  70. u8 **tlvs, u32 *sizeoftlvs);
  71. static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
  72. u8 *tlvs, u32 sizeoftlvs);
  73. static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
  74. unsigned long permanent);
  75. static void lec_arp_check_empties(struct lec_priv *priv,
  76. struct atm_vcc *vcc, struct sk_buff *skb);
  77. static void lec_arp_destroy(struct lec_priv *priv);
  78. static void lec_arp_init(struct lec_priv *priv);
  79. static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
  80. unsigned char *mac_to_find,
  81. int is_rdesc,
  82. struct lec_arp_table **ret_entry);
  83. static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
  84. unsigned char *atm_addr, unsigned long remoteflag,
  85. unsigned int targetless_le_arp);
  86. static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
  87. static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
  88. static void lec_set_flush_tran_id(struct lec_priv *priv,
  89. unsigned char *atm_addr,
  90. unsigned long tran_id);
  91. static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
  92. struct atm_vcc *vcc,
  93. void (*old_push) (struct atm_vcc *vcc,
  94. struct sk_buff *skb));
  95. static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
  96. static struct lane2_ops lane2_ops = {
  97. lane2_resolve, /* resolve, spec 3.1.3 */
  98. lane2_associate_req, /* associate_req, spec 3.1.4 */
  99. NULL /* associate indicator, spec 3.1.5 */
  100. };
  101. static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  102. /* Device structures */
  103. static struct net_device *dev_lec[MAX_LEC_ITF];
  104. #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
  105. static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
  106. {
  107. struct ethhdr *eth;
  108. char *buff;
  109. struct lec_priv *priv;
  110. /*
  111. * Check if this is a BPDU. If so, ask zeppelin to send
  112. * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
  113. * as the Config BPDU has
  114. */
  115. eth = (struct ethhdr *)skb->data;
  116. buff = skb->data + skb->dev->hard_header_len;
  117. if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
  118. struct sock *sk;
  119. struct sk_buff *skb2;
  120. struct atmlec_msg *mesg;
  121. skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
  122. if (skb2 == NULL)
  123. return;
  124. skb2->len = sizeof(struct atmlec_msg);
  125. mesg = (struct atmlec_msg *)skb2->data;
  126. mesg->type = l_topology_change;
  127. buff += 4;
  128. mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
  129. priv = (struct lec_priv *)dev->priv;
  130. atm_force_charge(priv->lecd, skb2->truesize);
  131. sk = sk_atm(priv->lecd);
  132. skb_queue_tail(&sk->sk_receive_queue, skb2);
  133. sk->sk_data_ready(sk, skb2->len);
  134. }
  135. return;
  136. }
  137. #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
  138. /*
  139. * Modelled after tr_type_trans
  140. * All multicast and ARE or STE frames go to BUS.
  141. * Non source routed frames go by destination address.
  142. * Last hop source routed frames go by destination address.
  143. * Not last hop source routed frames go by _next_ route descriptor.
  144. * Returns pointer to destination MAC address or fills in rdesc
  145. * and returns NULL.
  146. */
  147. #ifdef CONFIG_TR
  148. static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
  149. {
  150. struct trh_hdr *trh;
  151. int riflen, num_rdsc;
  152. trh = (struct trh_hdr *)packet;
  153. if (trh->daddr[0] & (uint8_t) 0x80)
  154. return bus_mac; /* multicast */
  155. if (trh->saddr[0] & TR_RII) {
  156. riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
  157. if ((ntohs(trh->rcf) >> 13) != 0)
  158. return bus_mac; /* ARE or STE */
  159. } else
  160. return trh->daddr; /* not source routed */
  161. if (riflen < 6)
  162. return trh->daddr; /* last hop, source routed */
  163. /* riflen is 6 or more, packet has more than one route descriptor */
  164. num_rdsc = (riflen / 2) - 1;
  165. memset(rdesc, 0, ETH_ALEN);
  166. /* offset 4 comes from LAN destination field in LE control frames */
  167. if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
  168. memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(uint16_t));
  169. else {
  170. memcpy(&rdesc[4], &trh->rseg[1], sizeof(uint16_t));
  171. rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
  172. }
  173. return NULL;
  174. }
  175. #endif /* CONFIG_TR */
  176. /*
  177. * Open/initialize the netdevice. This is called (in the current kernel)
  178. * sometime after booting when the 'ifconfig' program is run.
  179. *
  180. * This routine should set everything up anew at each open, even
  181. * registers that "should" only need to be set once at boot, so that
  182. * there is non-reboot way to recover if something goes wrong.
  183. */
  184. static int lec_open(struct net_device *dev)
  185. {
  186. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  187. netif_start_queue(dev);
  188. memset(&priv->stats, 0, sizeof(struct net_device_stats));
  189. return 0;
  190. }
  191. static __inline__ void
  192. lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
  193. {
  194. ATM_SKB(skb)->vcc = vcc;
  195. ATM_SKB(skb)->atm_options = vcc->atm_options;
  196. atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  197. if (vcc->send(vcc, skb) < 0) {
  198. priv->stats.tx_dropped++;
  199. return;
  200. }
  201. priv->stats.tx_packets++;
  202. priv->stats.tx_bytes += skb->len;
  203. }
  204. static void lec_tx_timeout(struct net_device *dev)
  205. {
  206. printk(KERN_INFO "%s: tx timeout\n", dev->name);
  207. dev->trans_start = jiffies;
  208. netif_wake_queue(dev);
  209. }
  210. static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
  211. {
  212. struct sk_buff *skb2;
  213. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  214. struct lecdatahdr_8023 *lec_h;
  215. struct atm_vcc *vcc;
  216. struct lec_arp_table *entry;
  217. unsigned char *dst;
  218. int min_frame_size;
  219. #ifdef CONFIG_TR
  220. unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
  221. #endif
  222. int is_rdesc;
  223. #if DUMP_PACKETS > 0
  224. char buf[300];
  225. int i = 0;
  226. #endif /* DUMP_PACKETS >0 */
  227. DPRINTK("lec_start_xmit called\n");
  228. if (!priv->lecd) {
  229. printk("%s:No lecd attached\n", dev->name);
  230. priv->stats.tx_errors++;
  231. netif_stop_queue(dev);
  232. return -EUNATCH;
  233. }
  234. DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
  235. (long)skb->head, (long)skb->data, (long)skb->tail,
  236. (long)skb->end);
  237. #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
  238. if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
  239. lec_handle_bridge(skb, dev);
  240. #endif
  241. /* Make sure we have room for lec_id */
  242. if (skb_headroom(skb) < 2) {
  243. DPRINTK("lec_start_xmit: reallocating skb\n");
  244. skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
  245. kfree_skb(skb);
  246. if (skb2 == NULL)
  247. return 0;
  248. skb = skb2;
  249. }
  250. skb_push(skb, 2);
  251. /* Put le header to place, works for TokenRing too */
  252. lec_h = (struct lecdatahdr_8023 *)skb->data;
  253. lec_h->le_header = htons(priv->lecid);
  254. #ifdef CONFIG_TR
  255. /*
  256. * Ugly. Use this to realign Token Ring packets for
  257. * e.g. PCA-200E driver.
  258. */
  259. if (priv->is_trdev) {
  260. skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
  261. kfree_skb(skb);
  262. if (skb2 == NULL)
  263. return 0;
  264. skb = skb2;
  265. }
  266. #endif
  267. #if DUMP_PACKETS > 0
  268. printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
  269. skb->len, priv->lecid);
  270. #if DUMP_PACKETS >= 2
  271. for (i = 0; i < skb->len && i < 99; i++) {
  272. sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
  273. }
  274. #elif DUMP_PACKETS >= 1
  275. for (i = 0; i < skb->len && i < 30; i++) {
  276. sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
  277. }
  278. #endif /* DUMP_PACKETS >= 1 */
  279. if (i == skb->len)
  280. printk("%s\n", buf);
  281. else
  282. printk("%s...\n", buf);
  283. #endif /* DUMP_PACKETS > 0 */
  284. /* Minimum ethernet-frame size */
  285. #ifdef CONFIG_TR
  286. if (priv->is_trdev)
  287. min_frame_size = LEC_MINIMUM_8025_SIZE;
  288. else
  289. #endif
  290. min_frame_size = LEC_MINIMUM_8023_SIZE;
  291. if (skb->len < min_frame_size) {
  292. if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
  293. skb2 = skb_copy_expand(skb, 0,
  294. min_frame_size - skb->truesize,
  295. GFP_ATOMIC);
  296. dev_kfree_skb(skb);
  297. if (skb2 == NULL) {
  298. priv->stats.tx_dropped++;
  299. return 0;
  300. }
  301. skb = skb2;
  302. }
  303. skb_put(skb, min_frame_size - skb->len);
  304. }
  305. /* Send to right vcc */
  306. is_rdesc = 0;
  307. dst = lec_h->h_dest;
  308. #ifdef CONFIG_TR
  309. if (priv->is_trdev) {
  310. dst = get_tr_dst(skb->data + 2, rdesc);
  311. if (dst == NULL) {
  312. dst = rdesc;
  313. is_rdesc = 1;
  314. }
  315. }
  316. #endif
  317. entry = NULL;
  318. vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
  319. DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
  320. vcc, vcc ? vcc->flags : 0, entry);
  321. if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
  322. if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
  323. DPRINTK("%s:lec_start_xmit: queuing packet, ",
  324. dev->name);
  325. DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
  326. lec_h->h_dest[0], lec_h->h_dest[1],
  327. lec_h->h_dest[2], lec_h->h_dest[3],
  328. lec_h->h_dest[4], lec_h->h_dest[5]);
  329. skb_queue_tail(&entry->tx_wait, skb);
  330. } else {
  331. DPRINTK
  332. ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
  333. dev->name);
  334. DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
  335. lec_h->h_dest[0], lec_h->h_dest[1],
  336. lec_h->h_dest[2], lec_h->h_dest[3],
  337. lec_h->h_dest[4], lec_h->h_dest[5]);
  338. priv->stats.tx_dropped++;
  339. dev_kfree_skb(skb);
  340. }
  341. return 0;
  342. }
  343. #if DUMP_PACKETS > 0
  344. printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
  345. #endif /* DUMP_PACKETS > 0 */
  346. while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
  347. DPRINTK("lec.c: emptying tx queue, ");
  348. DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
  349. lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
  350. lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
  351. lec_send(vcc, skb2, priv);
  352. }
  353. lec_send(vcc, skb, priv);
  354. if (!atm_may_send(vcc, 0)) {
  355. struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
  356. vpriv->xoff = 1;
  357. netif_stop_queue(dev);
  358. /*
  359. * vcc->pop() might have occurred in between, making
  360. * the vcc usuable again. Since xmit is serialized,
  361. * this is the only situation we have to re-test.
  362. */
  363. if (atm_may_send(vcc, 0))
  364. netif_wake_queue(dev);
  365. }
  366. dev->trans_start = jiffies;
  367. return 0;
  368. }
  369. /* The inverse routine to net_open(). */
  370. static int lec_close(struct net_device *dev)
  371. {
  372. netif_stop_queue(dev);
  373. return 0;
  374. }
  375. /*
  376. * Get the current statistics.
  377. * This may be called with the card open or closed.
  378. */
  379. static struct net_device_stats *lec_get_stats(struct net_device *dev)
  380. {
  381. return &((struct lec_priv *)dev->priv)->stats;
  382. }
  383. static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
  384. {
  385. unsigned long flags;
  386. struct net_device *dev = (struct net_device *)vcc->proto_data;
  387. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  388. struct atmlec_msg *mesg;
  389. struct lec_arp_table *entry;
  390. int i;
  391. char *tmp; /* FIXME */
  392. atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  393. mesg = (struct atmlec_msg *)skb->data;
  394. tmp = skb->data;
  395. tmp += sizeof(struct atmlec_msg);
  396. DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
  397. switch (mesg->type) {
  398. case l_set_mac_addr:
  399. for (i = 0; i < 6; i++) {
  400. dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
  401. }
  402. break;
  403. case l_del_mac_addr:
  404. for (i = 0; i < 6; i++) {
  405. dev->dev_addr[i] = 0;
  406. }
  407. break;
  408. case l_addr_delete:
  409. lec_addr_delete(priv, mesg->content.normal.atm_addr,
  410. mesg->content.normal.flag);
  411. break;
  412. case l_topology_change:
  413. priv->topology_change = mesg->content.normal.flag;
  414. break;
  415. case l_flush_complete:
  416. lec_flush_complete(priv, mesg->content.normal.flag);
  417. break;
  418. case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
  419. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  420. entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
  421. lec_arp_remove(priv, entry);
  422. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  423. if (mesg->content.normal.no_source_le_narp)
  424. break;
  425. /* FALL THROUGH */
  426. case l_arp_update:
  427. lec_arp_update(priv, mesg->content.normal.mac_addr,
  428. mesg->content.normal.atm_addr,
  429. mesg->content.normal.flag,
  430. mesg->content.normal.targetless_le_arp);
  431. DPRINTK("lec: in l_arp_update\n");
  432. if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
  433. DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n",
  434. mesg->sizeoftlvs);
  435. lane2_associate_ind(dev, mesg->content.normal.mac_addr,
  436. tmp, mesg->sizeoftlvs);
  437. }
  438. break;
  439. case l_config:
  440. priv->maximum_unknown_frame_count =
  441. mesg->content.config.maximum_unknown_frame_count;
  442. priv->max_unknown_frame_time =
  443. (mesg->content.config.max_unknown_frame_time * HZ);
  444. priv->max_retry_count = mesg->content.config.max_retry_count;
  445. priv->aging_time = (mesg->content.config.aging_time * HZ);
  446. priv->forward_delay_time =
  447. (mesg->content.config.forward_delay_time * HZ);
  448. priv->arp_response_time =
  449. (mesg->content.config.arp_response_time * HZ);
  450. priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
  451. priv->path_switching_delay =
  452. (mesg->content.config.path_switching_delay * HZ);
  453. priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
  454. priv->lane2_ops = NULL;
  455. if (priv->lane_version > 1)
  456. priv->lane2_ops = &lane2_ops;
  457. if (dev->change_mtu(dev, mesg->content.config.mtu))
  458. printk("%s: change_mtu to %d failed\n", dev->name,
  459. mesg->content.config.mtu);
  460. priv->is_proxy = mesg->content.config.is_proxy;
  461. break;
  462. case l_flush_tran_id:
  463. lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
  464. mesg->content.normal.flag);
  465. break;
  466. case l_set_lecid:
  467. priv->lecid =
  468. (unsigned short)(0xffff & mesg->content.normal.flag);
  469. break;
  470. case l_should_bridge:
  471. #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
  472. {
  473. struct net_bridge_fdb_entry *f;
  474. DPRINTK
  475. ("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
  476. dev->name, mesg->content.proxy.mac_addr[0],
  477. mesg->content.proxy.mac_addr[1],
  478. mesg->content.proxy.mac_addr[2],
  479. mesg->content.proxy.mac_addr[3],
  480. mesg->content.proxy.mac_addr[4],
  481. mesg->content.proxy.mac_addr[5]);
  482. if (br_fdb_get_hook == NULL || dev->br_port == NULL)
  483. break;
  484. f = br_fdb_get_hook(dev->br_port->br,
  485. mesg->content.proxy.mac_addr);
  486. if (f != NULL && f->dst->dev != dev
  487. && f->dst->state == BR_STATE_FORWARDING) {
  488. /* hit from bridge table, send LE_ARP_RESPONSE */
  489. struct sk_buff *skb2;
  490. struct sock *sk;
  491. DPRINTK
  492. ("%s: entry found, responding to zeppelin\n",
  493. dev->name);
  494. skb2 =
  495. alloc_skb(sizeof(struct atmlec_msg),
  496. GFP_ATOMIC);
  497. if (skb2 == NULL) {
  498. br_fdb_put_hook(f);
  499. break;
  500. }
  501. skb2->len = sizeof(struct atmlec_msg);
  502. memcpy(skb2->data, mesg,
  503. sizeof(struct atmlec_msg));
  504. atm_force_charge(priv->lecd, skb2->truesize);
  505. sk = sk_atm(priv->lecd);
  506. skb_queue_tail(&sk->sk_receive_queue, skb2);
  507. sk->sk_data_ready(sk, skb2->len);
  508. }
  509. if (f != NULL)
  510. br_fdb_put_hook(f);
  511. }
  512. #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
  513. break;
  514. default:
  515. printk("%s: Unknown message type %d\n", dev->name, mesg->type);
  516. dev_kfree_skb(skb);
  517. return -EINVAL;
  518. }
  519. dev_kfree_skb(skb);
  520. return 0;
  521. }
  522. static void lec_atm_close(struct atm_vcc *vcc)
  523. {
  524. struct sk_buff *skb;
  525. struct net_device *dev = (struct net_device *)vcc->proto_data;
  526. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  527. priv->lecd = NULL;
  528. /* Do something needful? */
  529. netif_stop_queue(dev);
  530. lec_arp_destroy(priv);
  531. if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
  532. printk("%s lec_atm_close: closing with messages pending\n",
  533. dev->name);
  534. while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
  535. atm_return(vcc, skb->truesize);
  536. dev_kfree_skb(skb);
  537. }
  538. printk("%s: Shut down!\n", dev->name);
  539. module_put(THIS_MODULE);
  540. }
  541. static struct atmdev_ops lecdev_ops = {
  542. .close = lec_atm_close,
  543. .send = lec_atm_send
  544. };
  545. static struct atm_dev lecatm_dev = {
  546. .ops = &lecdev_ops,
  547. .type = "lec",
  548. .number = 999, /* dummy device number */
  549. .lock = SPIN_LOCK_UNLOCKED
  550. };
  551. /*
  552. * LANE2: new argument struct sk_buff *data contains
  553. * the LE_ARP based TLVs introduced in the LANE2 spec
  554. */
  555. static int
  556. send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
  557. unsigned char *mac_addr, unsigned char *atm_addr,
  558. struct sk_buff *data)
  559. {
  560. struct sock *sk;
  561. struct sk_buff *skb;
  562. struct atmlec_msg *mesg;
  563. if (!priv || !priv->lecd) {
  564. return -1;
  565. }
  566. skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
  567. if (!skb)
  568. return -1;
  569. skb->len = sizeof(struct atmlec_msg);
  570. mesg = (struct atmlec_msg *)skb->data;
  571. memset(mesg, 0, sizeof(struct atmlec_msg));
  572. mesg->type = type;
  573. if (data != NULL)
  574. mesg->sizeoftlvs = data->len;
  575. if (mac_addr)
  576. memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
  577. else
  578. mesg->content.normal.targetless_le_arp = 1;
  579. if (atm_addr)
  580. memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
  581. atm_force_charge(priv->lecd, skb->truesize);
  582. sk = sk_atm(priv->lecd);
  583. skb_queue_tail(&sk->sk_receive_queue, skb);
  584. sk->sk_data_ready(sk, skb->len);
  585. if (data != NULL) {
  586. DPRINTK("lec: about to send %d bytes of data\n", data->len);
  587. atm_force_charge(priv->lecd, data->truesize);
  588. skb_queue_tail(&sk->sk_receive_queue, data);
  589. sk->sk_data_ready(sk, skb->len);
  590. }
  591. return 0;
  592. }
  593. /* shamelessly stolen from drivers/net/net_init.c */
  594. static int lec_change_mtu(struct net_device *dev, int new_mtu)
  595. {
  596. if ((new_mtu < 68) || (new_mtu > 18190))
  597. return -EINVAL;
  598. dev->mtu = new_mtu;
  599. return 0;
  600. }
  601. static void lec_set_multicast_list(struct net_device *dev)
  602. {
  603. /*
  604. * by default, all multicast frames arrive over the bus.
  605. * eventually support selective multicast service
  606. */
  607. return;
  608. }
  609. static void lec_init(struct net_device *dev)
  610. {
  611. dev->change_mtu = lec_change_mtu;
  612. dev->open = lec_open;
  613. dev->stop = lec_close;
  614. dev->hard_start_xmit = lec_start_xmit;
  615. dev->tx_timeout = lec_tx_timeout;
  616. dev->get_stats = lec_get_stats;
  617. dev->set_multicast_list = lec_set_multicast_list;
  618. dev->do_ioctl = NULL;
  619. printk("%s: Initialized!\n", dev->name);
  620. return;
  621. }
  622. static unsigned char lec_ctrl_magic[] = {
  623. 0xff,
  624. 0x00,
  625. 0x01,
  626. 0x01
  627. };
  628. #define LEC_DATA_DIRECT_8023 2
  629. #define LEC_DATA_DIRECT_8025 3
  630. static int lec_is_data_direct(struct atm_vcc *vcc)
  631. {
  632. return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
  633. (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
  634. }
  635. static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
  636. {
  637. unsigned long flags;
  638. struct net_device *dev = (struct net_device *)vcc->proto_data;
  639. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  640. #if DUMP_PACKETS >0
  641. int i = 0;
  642. char buf[300];
  643. printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
  644. vcc->vpi, vcc->vci);
  645. #endif
  646. if (!skb) {
  647. DPRINTK("%s: null skb\n", dev->name);
  648. lec_vcc_close(priv, vcc);
  649. return;
  650. }
  651. #if DUMP_PACKETS > 0
  652. printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
  653. skb->len, priv->lecid);
  654. #if DUMP_PACKETS >= 2
  655. for (i = 0; i < skb->len && i < 99; i++) {
  656. sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
  657. }
  658. #elif DUMP_PACKETS >= 1
  659. for (i = 0; i < skb->len && i < 30; i++) {
  660. sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
  661. }
  662. #endif /* DUMP_PACKETS >= 1 */
  663. if (i == skb->len)
  664. printk("%s\n", buf);
  665. else
  666. printk("%s...\n", buf);
  667. #endif /* DUMP_PACKETS > 0 */
  668. if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
  669. struct sock *sk = sk_atm(vcc);
  670. DPRINTK("%s: To daemon\n", dev->name);
  671. skb_queue_tail(&sk->sk_receive_queue, skb);
  672. sk->sk_data_ready(sk, skb->len);
  673. } else { /* Data frame, queue to protocol handlers */
  674. struct lec_arp_table *entry;
  675. unsigned char *src, *dst;
  676. atm_return(vcc, skb->truesize);
  677. if (*(uint16_t *) skb->data == htons(priv->lecid) ||
  678. !priv->lecd || !(dev->flags & IFF_UP)) {
  679. /*
  680. * Probably looping back, or if lecd is missing,
  681. * lecd has gone down
  682. */
  683. DPRINTK("Ignoring frame...\n");
  684. dev_kfree_skb(skb);
  685. return;
  686. }
  687. #ifdef CONFIG_TR
  688. if (priv->is_trdev)
  689. dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
  690. else
  691. #endif
  692. dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
  693. /*
  694. * If this is a Data Direct VCC, and the VCC does not match
  695. * the LE_ARP cache entry, delete the LE_ARP cache entry.
  696. */
  697. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  698. if (lec_is_data_direct(vcc)) {
  699. #ifdef CONFIG_TR
  700. if (priv->is_trdev)
  701. src =
  702. ((struct lecdatahdr_8025 *)skb->data)->
  703. h_source;
  704. else
  705. #endif
  706. src =
  707. ((struct lecdatahdr_8023 *)skb->data)->
  708. h_source;
  709. entry = lec_arp_find(priv, src);
  710. if (entry && entry->vcc != vcc) {
  711. lec_arp_remove(priv, entry);
  712. kfree(entry);
  713. }
  714. }
  715. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  716. if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
  717. !priv->is_proxy && /* Proxy wants all the packets */
  718. memcmp(dst, dev->dev_addr, dev->addr_len)) {
  719. dev_kfree_skb(skb);
  720. return;
  721. }
  722. if (!hlist_empty(&priv->lec_arp_empty_ones)) {
  723. lec_arp_check_empties(priv, vcc, skb);
  724. }
  725. skb->dev = dev;
  726. skb_pull(skb, 2); /* skip lec_id */
  727. #ifdef CONFIG_TR
  728. if (priv->is_trdev)
  729. skb->protocol = tr_type_trans(skb, dev);
  730. else
  731. #endif
  732. skb->protocol = eth_type_trans(skb, dev);
  733. priv->stats.rx_packets++;
  734. priv->stats.rx_bytes += skb->len;
  735. memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
  736. netif_rx(skb);
  737. }
  738. }
  739. static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
  740. {
  741. struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
  742. struct net_device *dev = skb->dev;
  743. if (vpriv == NULL) {
  744. printk("lec_pop(): vpriv = NULL!?!?!?\n");
  745. return;
  746. }
  747. vpriv->old_pop(vcc, skb);
  748. if (vpriv->xoff && atm_may_send(vcc, 0)) {
  749. vpriv->xoff = 0;
  750. if (netif_running(dev) && netif_queue_stopped(dev))
  751. netif_wake_queue(dev);
  752. }
  753. }
  754. static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
  755. {
  756. struct lec_vcc_priv *vpriv;
  757. int bytes_left;
  758. struct atmlec_ioc ioc_data;
  759. /* Lecd must be up in this case */
  760. bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
  761. if (bytes_left != 0) {
  762. printk
  763. ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
  764. bytes_left);
  765. }
  766. if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
  767. !dev_lec[ioc_data.dev_num])
  768. return -EINVAL;
  769. if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
  770. return -ENOMEM;
  771. vpriv->xoff = 0;
  772. vpriv->old_pop = vcc->pop;
  773. vcc->user_back = vpriv;
  774. vcc->pop = lec_pop;
  775. lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
  776. &ioc_data, vcc, vcc->push);
  777. vcc->proto_data = dev_lec[ioc_data.dev_num];
  778. vcc->push = lec_push;
  779. return 0;
  780. }
  781. static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
  782. {
  783. if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
  784. return -EINVAL;
  785. vcc->proto_data = dev_lec[arg];
  786. return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
  787. }
  788. /* Initialize device. */
  789. static int lecd_attach(struct atm_vcc *vcc, int arg)
  790. {
  791. int i;
  792. struct lec_priv *priv;
  793. if (arg < 0)
  794. i = 0;
  795. else
  796. i = arg;
  797. #ifdef CONFIG_TR
  798. if (arg >= MAX_LEC_ITF)
  799. return -EINVAL;
  800. #else /* Reserve the top NUM_TR_DEVS for TR */
  801. if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
  802. return -EINVAL;
  803. #endif
  804. if (!dev_lec[i]) {
  805. int is_trdev, size;
  806. is_trdev = 0;
  807. if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
  808. is_trdev = 1;
  809. size = sizeof(struct lec_priv);
  810. #ifdef CONFIG_TR
  811. if (is_trdev)
  812. dev_lec[i] = alloc_trdev(size);
  813. else
  814. #endif
  815. dev_lec[i] = alloc_etherdev(size);
  816. if (!dev_lec[i])
  817. return -ENOMEM;
  818. snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
  819. if (register_netdev(dev_lec[i])) {
  820. free_netdev(dev_lec[i]);
  821. return -EINVAL;
  822. }
  823. priv = dev_lec[i]->priv;
  824. priv->is_trdev = is_trdev;
  825. lec_init(dev_lec[i]);
  826. } else {
  827. priv = dev_lec[i]->priv;
  828. if (priv->lecd)
  829. return -EADDRINUSE;
  830. }
  831. lec_arp_init(priv);
  832. priv->itfnum = i; /* LANE2 addition */
  833. priv->lecd = vcc;
  834. vcc->dev = &lecatm_dev;
  835. vcc_insert_socket(sk_atm(vcc));
  836. vcc->proto_data = dev_lec[i];
  837. set_bit(ATM_VF_META, &vcc->flags);
  838. set_bit(ATM_VF_READY, &vcc->flags);
  839. /* Set default values to these variables */
  840. priv->maximum_unknown_frame_count = 1;
  841. priv->max_unknown_frame_time = (1 * HZ);
  842. priv->vcc_timeout_period = (1200 * HZ);
  843. priv->max_retry_count = 1;
  844. priv->aging_time = (300 * HZ);
  845. priv->forward_delay_time = (15 * HZ);
  846. priv->topology_change = 0;
  847. priv->arp_response_time = (1 * HZ);
  848. priv->flush_timeout = (4 * HZ);
  849. priv->path_switching_delay = (6 * HZ);
  850. if (dev_lec[i]->flags & IFF_UP) {
  851. netif_start_queue(dev_lec[i]);
  852. }
  853. __module_get(THIS_MODULE);
  854. return i;
  855. }
  856. #ifdef CONFIG_PROC_FS
  857. static char *lec_arp_get_status_string(unsigned char status)
  858. {
  859. static char *lec_arp_status_string[] = {
  860. "ESI_UNKNOWN ",
  861. "ESI_ARP_PENDING ",
  862. "ESI_VC_PENDING ",
  863. "<Undefined> ",
  864. "ESI_FLUSH_PENDING ",
  865. "ESI_FORWARD_DIRECT"
  866. };
  867. if (status > ESI_FORWARD_DIRECT)
  868. status = 3; /* ESI_UNDEFINED */
  869. return lec_arp_status_string[status];
  870. }
  871. static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
  872. {
  873. int i;
  874. for (i = 0; i < ETH_ALEN; i++)
  875. seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
  876. seq_printf(seq, " ");
  877. for (i = 0; i < ATM_ESA_LEN; i++)
  878. seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
  879. seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
  880. entry->flags & 0xffff);
  881. if (entry->vcc)
  882. seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
  883. else
  884. seq_printf(seq, " ");
  885. if (entry->recv_vcc) {
  886. seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
  887. entry->recv_vcc->vci);
  888. }
  889. seq_putc(seq, '\n');
  890. }
  891. struct lec_state {
  892. unsigned long flags;
  893. struct lec_priv *locked;
  894. struct hlist_node *node;
  895. struct net_device *dev;
  896. int itf;
  897. int arp_table;
  898. int misc_table;
  899. };
  900. static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
  901. loff_t *l)
  902. {
  903. struct hlist_node *e = state->node;
  904. struct lec_arp_table *tmp;
  905. if (!e)
  906. e = tbl->first;
  907. if (e == (void *)1) {
  908. e = tbl->first;
  909. --*l;
  910. }
  911. hlist_for_each_entry_from(tmp, e, next) {
  912. if (--*l < 0)
  913. break;
  914. }
  915. state->node = e;
  916. return (*l < 0) ? state : NULL;
  917. }
  918. static void *lec_arp_walk(struct lec_state *state, loff_t *l,
  919. struct lec_priv *priv)
  920. {
  921. void *v = NULL;
  922. int p;
  923. for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
  924. v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
  925. if (v)
  926. break;
  927. }
  928. state->arp_table = p;
  929. return v;
  930. }
  931. static void *lec_misc_walk(struct lec_state *state, loff_t *l,
  932. struct lec_priv *priv)
  933. {
  934. struct hlist_head *lec_misc_tables[] = {
  935. &priv->lec_arp_empty_ones,
  936. &priv->lec_no_forward,
  937. &priv->mcast_fwds
  938. };
  939. void *v = NULL;
  940. int q;
  941. for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
  942. v = lec_tbl_walk(state, lec_misc_tables[q], l);
  943. if (v)
  944. break;
  945. }
  946. state->misc_table = q;
  947. return v;
  948. }
  949. static void *lec_priv_walk(struct lec_state *state, loff_t *l,
  950. struct lec_priv *priv)
  951. {
  952. if (!state->locked) {
  953. state->locked = priv;
  954. spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
  955. }
  956. if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
  957. spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
  958. state->locked = NULL;
  959. /* Partial state reset for the next time we get called */
  960. state->arp_table = state->misc_table = 0;
  961. }
  962. return state->locked;
  963. }
  964. static void *lec_itf_walk(struct lec_state *state, loff_t *l)
  965. {
  966. struct net_device *dev;
  967. void *v;
  968. dev = state->dev ? state->dev : dev_lec[state->itf];
  969. v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
  970. if (!v && dev) {
  971. dev_put(dev);
  972. /* Partial state reset for the next time we get called */
  973. dev = NULL;
  974. }
  975. state->dev = dev;
  976. return v;
  977. }
  978. static void *lec_get_idx(struct lec_state *state, loff_t l)
  979. {
  980. void *v = NULL;
  981. for (; state->itf < MAX_LEC_ITF; state->itf++) {
  982. v = lec_itf_walk(state, &l);
  983. if (v)
  984. break;
  985. }
  986. return v;
  987. }
  988. static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
  989. {
  990. struct lec_state *state = seq->private;
  991. state->itf = 0;
  992. state->dev = NULL;
  993. state->locked = NULL;
  994. state->arp_table = 0;
  995. state->misc_table = 0;
  996. state->node = (void *)1;
  997. return *pos ? lec_get_idx(state, *pos) : (void *)1;
  998. }
  999. static void lec_seq_stop(struct seq_file *seq, void *v)
  1000. {
  1001. struct lec_state *state = seq->private;
  1002. if (state->dev) {
  1003. spin_unlock_irqrestore(&state->locked->lec_arp_lock,
  1004. state->flags);
  1005. dev_put(state->dev);
  1006. }
  1007. }
  1008. static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  1009. {
  1010. struct lec_state *state = seq->private;
  1011. v = lec_get_idx(state, 1);
  1012. *pos += !!PTR_ERR(v);
  1013. return v;
  1014. }
  1015. static int lec_seq_show(struct seq_file *seq, void *v)
  1016. {
  1017. static char lec_banner[] = "Itf MAC ATM destination"
  1018. " Status Flags "
  1019. "VPI/VCI Recv VPI/VCI\n";
  1020. if (v == (void *)1)
  1021. seq_puts(seq, lec_banner);
  1022. else {
  1023. struct lec_state *state = seq->private;
  1024. struct net_device *dev = state->dev;
  1025. struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
  1026. seq_printf(seq, "%s ", dev->name);
  1027. lec_info(seq, entry);
  1028. }
  1029. return 0;
  1030. }
  1031. static struct seq_operations lec_seq_ops = {
  1032. .start = lec_seq_start,
  1033. .next = lec_seq_next,
  1034. .stop = lec_seq_stop,
  1035. .show = lec_seq_show,
  1036. };
  1037. static int lec_seq_open(struct inode *inode, struct file *file)
  1038. {
  1039. struct lec_state *state;
  1040. struct seq_file *seq;
  1041. int rc = -EAGAIN;
  1042. state = kmalloc(sizeof(*state), GFP_KERNEL);
  1043. if (!state) {
  1044. rc = -ENOMEM;
  1045. goto out;
  1046. }
  1047. rc = seq_open(file, &lec_seq_ops);
  1048. if (rc)
  1049. goto out_kfree;
  1050. seq = file->private_data;
  1051. seq->private = state;
  1052. out:
  1053. return rc;
  1054. out_kfree:
  1055. kfree(state);
  1056. goto out;
  1057. }
  1058. static int lec_seq_release(struct inode *inode, struct file *file)
  1059. {
  1060. return seq_release_private(inode, file);
  1061. }
  1062. static struct file_operations lec_seq_fops = {
  1063. .owner = THIS_MODULE,
  1064. .open = lec_seq_open,
  1065. .read = seq_read,
  1066. .llseek = seq_lseek,
  1067. .release = lec_seq_release,
  1068. };
  1069. #endif
  1070. static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1071. {
  1072. struct atm_vcc *vcc = ATM_SD(sock);
  1073. int err = 0;
  1074. switch (cmd) {
  1075. case ATMLEC_CTRL:
  1076. case ATMLEC_MCAST:
  1077. case ATMLEC_DATA:
  1078. if (!capable(CAP_NET_ADMIN))
  1079. return -EPERM;
  1080. break;
  1081. default:
  1082. return -ENOIOCTLCMD;
  1083. }
  1084. switch (cmd) {
  1085. case ATMLEC_CTRL:
  1086. err = lecd_attach(vcc, (int)arg);
  1087. if (err >= 0)
  1088. sock->state = SS_CONNECTED;
  1089. break;
  1090. case ATMLEC_MCAST:
  1091. err = lec_mcast_attach(vcc, (int)arg);
  1092. break;
  1093. case ATMLEC_DATA:
  1094. err = lec_vcc_attach(vcc, (void __user *)arg);
  1095. break;
  1096. }
  1097. return err;
  1098. }
  1099. static struct atm_ioctl lane_ioctl_ops = {
  1100. .owner = THIS_MODULE,
  1101. .ioctl = lane_ioctl,
  1102. };
  1103. static int __init lane_module_init(void)
  1104. {
  1105. #ifdef CONFIG_PROC_FS
  1106. struct proc_dir_entry *p;
  1107. p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
  1108. if (p)
  1109. p->proc_fops = &lec_seq_fops;
  1110. #endif
  1111. register_atm_ioctl(&lane_ioctl_ops);
  1112. printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
  1113. return 0;
  1114. }
  1115. static void __exit lane_module_cleanup(void)
  1116. {
  1117. int i;
  1118. struct lec_priv *priv;
  1119. remove_proc_entry("lec", atm_proc_root);
  1120. deregister_atm_ioctl(&lane_ioctl_ops);
  1121. for (i = 0; i < MAX_LEC_ITF; i++) {
  1122. if (dev_lec[i] != NULL) {
  1123. priv = (struct lec_priv *)dev_lec[i]->priv;
  1124. unregister_netdev(dev_lec[i]);
  1125. free_netdev(dev_lec[i]);
  1126. dev_lec[i] = NULL;
  1127. }
  1128. }
  1129. return;
  1130. }
  1131. module_init(lane_module_init);
  1132. module_exit(lane_module_cleanup);
  1133. /*
  1134. * LANE2: 3.1.3, LE_RESOLVE.request
  1135. * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
  1136. * If sizeoftlvs == NULL the default TLVs associated with with this
  1137. * lec will be used.
  1138. * If dst_mac == NULL, targetless LE_ARP will be sent
  1139. */
  1140. static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
  1141. u8 **tlvs, u32 *sizeoftlvs)
  1142. {
  1143. unsigned long flags;
  1144. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  1145. struct lec_arp_table *table;
  1146. struct sk_buff *skb;
  1147. int retval;
  1148. if (force == 0) {
  1149. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1150. table = lec_arp_find(priv, dst_mac);
  1151. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1152. if (table == NULL)
  1153. return -1;
  1154. *tlvs = kmalloc(table->sizeoftlvs, GFP_ATOMIC);
  1155. if (*tlvs == NULL)
  1156. return -1;
  1157. memcpy(*tlvs, table->tlvs, table->sizeoftlvs);
  1158. *sizeoftlvs = table->sizeoftlvs;
  1159. return 0;
  1160. }
  1161. if (sizeoftlvs == NULL)
  1162. retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
  1163. else {
  1164. skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
  1165. if (skb == NULL)
  1166. return -1;
  1167. skb->len = *sizeoftlvs;
  1168. memcpy(skb->data, *tlvs, *sizeoftlvs);
  1169. retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
  1170. }
  1171. return retval;
  1172. }
  1173. /*
  1174. * LANE2: 3.1.4, LE_ASSOCIATE.request
  1175. * Associate the *tlvs with the *lan_dst address.
  1176. * Will overwrite any previous association
  1177. * Returns 1 for success, 0 for failure (out of memory)
  1178. *
  1179. */
  1180. static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
  1181. u8 *tlvs, u32 sizeoftlvs)
  1182. {
  1183. int retval;
  1184. struct sk_buff *skb;
  1185. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  1186. if (compare_ether_addr(lan_dst, dev->dev_addr))
  1187. return (0); /* not our mac address */
  1188. kfree(priv->tlvs); /* NULL if there was no previous association */
  1189. priv->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
  1190. if (priv->tlvs == NULL)
  1191. return (0);
  1192. priv->sizeoftlvs = sizeoftlvs;
  1193. memcpy(priv->tlvs, tlvs, sizeoftlvs);
  1194. skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
  1195. if (skb == NULL)
  1196. return 0;
  1197. skb->len = sizeoftlvs;
  1198. memcpy(skb->data, tlvs, sizeoftlvs);
  1199. retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
  1200. if (retval != 0)
  1201. printk("lec.c: lane2_associate_req() failed\n");
  1202. /*
  1203. * If the previous association has changed we must
  1204. * somehow notify other LANE entities about the change
  1205. */
  1206. return (1);
  1207. }
  1208. /*
  1209. * LANE2: 3.1.5, LE_ASSOCIATE.indication
  1210. *
  1211. */
  1212. static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
  1213. u8 *tlvs, u32 sizeoftlvs)
  1214. {
  1215. #if 0
  1216. int i = 0;
  1217. #endif
  1218. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  1219. #if 0 /*
  1220. * Why have the TLVs in LE_ARP entries
  1221. * since we do not use them? When you
  1222. * uncomment this code, make sure the
  1223. * TLVs get freed when entry is killed
  1224. */
  1225. struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
  1226. if (entry == NULL)
  1227. return; /* should not happen */
  1228. kfree(entry->tlvs);
  1229. entry->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
  1230. if (entry->tlvs == NULL)
  1231. return;
  1232. entry->sizeoftlvs = sizeoftlvs;
  1233. memcpy(entry->tlvs, tlvs, sizeoftlvs);
  1234. #endif
  1235. #if 0
  1236. printk("lec.c: lane2_associate_ind()\n");
  1237. printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
  1238. while (i < sizeoftlvs)
  1239. printk("%02x ", tlvs[i++]);
  1240. printk("\n");
  1241. #endif
  1242. /* tell MPOA about the TLVs we saw */
  1243. if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
  1244. priv->lane2_ops->associate_indicator(dev, mac_addr,
  1245. tlvs, sizeoftlvs);
  1246. }
  1247. return;
  1248. }
  1249. /*
  1250. * Here starts what used to lec_arpc.c
  1251. *
  1252. * lec_arpc.c was added here when making
  1253. * lane client modular. October 1997
  1254. */
  1255. #include <linux/types.h>
  1256. #include <linux/sched.h>
  1257. #include <linux/timer.h>
  1258. #include <asm/param.h>
  1259. #include <asm/atomic.h>
  1260. #include <linux/inetdevice.h>
  1261. #include <net/route.h>
  1262. #if 0
  1263. #define DPRINTK(format,args...)
  1264. /*
  1265. #define DPRINTK printk
  1266. */
  1267. #endif
  1268. #define DEBUG_ARP_TABLE 0
  1269. #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
  1270. static void lec_arp_check_expire(void *data);
  1271. static void lec_arp_expire_arp(unsigned long data);
  1272. /*
  1273. * Arp table funcs
  1274. */
  1275. #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
  1276. /*
  1277. * Initialization of arp-cache
  1278. */
  1279. static void lec_arp_init(struct lec_priv *priv)
  1280. {
  1281. unsigned short i;
  1282. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1283. INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
  1284. }
  1285. INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
  1286. INIT_HLIST_HEAD(&priv->lec_no_forward);
  1287. INIT_HLIST_HEAD(&priv->mcast_fwds);
  1288. spin_lock_init(&priv->lec_arp_lock);
  1289. INIT_WORK(&priv->lec_arp_work, lec_arp_check_expire, priv);
  1290. schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
  1291. }
  1292. static void lec_arp_clear_vccs(struct lec_arp_table *entry)
  1293. {
  1294. if (entry->vcc) {
  1295. struct atm_vcc *vcc = entry->vcc;
  1296. struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
  1297. struct net_device *dev = (struct net_device *)vcc->proto_data;
  1298. vcc->pop = vpriv->old_pop;
  1299. if (vpriv->xoff)
  1300. netif_wake_queue(dev);
  1301. kfree(vpriv);
  1302. vcc->user_back = NULL;
  1303. vcc->push = entry->old_push;
  1304. vcc_release_async(vcc, -EPIPE);
  1305. entry->vcc = NULL;
  1306. }
  1307. if (entry->recv_vcc) {
  1308. entry->recv_vcc->push = entry->old_recv_push;
  1309. vcc_release_async(entry->recv_vcc, -EPIPE);
  1310. entry->recv_vcc = NULL;
  1311. }
  1312. }
  1313. /*
  1314. * Insert entry to lec_arp_table
  1315. * LANE2: Add to the end of the list to satisfy 8.1.13
  1316. */
  1317. static inline void
  1318. lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
  1319. {
  1320. struct hlist_head *tmp;
  1321. tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
  1322. hlist_add_head(&entry->next, tmp);
  1323. DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
  1324. 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
  1325. 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
  1326. 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
  1327. }
  1328. /*
  1329. * Remove entry from lec_arp_table
  1330. */
  1331. static int
  1332. lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
  1333. {
  1334. struct hlist_node *node;
  1335. struct lec_arp_table *entry;
  1336. int i, remove_vcc = 1;
  1337. if (!to_remove) {
  1338. return -1;
  1339. }
  1340. hlist_del(&to_remove->next);
  1341. del_timer(&to_remove->timer);
  1342. /* If this is the only MAC connected to this VCC, also tear down the VCC */
  1343. if (to_remove->status >= ESI_FLUSH_PENDING) {
  1344. /*
  1345. * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
  1346. */
  1347. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1348. hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
  1349. if (memcmp(to_remove->atm_addr,
  1350. entry->atm_addr, ATM_ESA_LEN) == 0) {
  1351. remove_vcc = 0;
  1352. break;
  1353. }
  1354. }
  1355. }
  1356. if (remove_vcc)
  1357. lec_arp_clear_vccs(to_remove);
  1358. }
  1359. skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
  1360. DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
  1361. 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
  1362. 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
  1363. 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
  1364. return 0;
  1365. }
  1366. #if DEBUG_ARP_TABLE
  1367. static char *get_status_string(unsigned char st)
  1368. {
  1369. switch (st) {
  1370. case ESI_UNKNOWN:
  1371. return "ESI_UNKNOWN";
  1372. case ESI_ARP_PENDING:
  1373. return "ESI_ARP_PENDING";
  1374. case ESI_VC_PENDING:
  1375. return "ESI_VC_PENDING";
  1376. case ESI_FLUSH_PENDING:
  1377. return "ESI_FLUSH_PENDING";
  1378. case ESI_FORWARD_DIRECT:
  1379. return "ESI_FORWARD_DIRECT";
  1380. default:
  1381. return "<UNKNOWN>";
  1382. }
  1383. }
  1384. static void dump_arp_table(struct lec_priv *priv)
  1385. {
  1386. struct hlist_node *node;
  1387. struct lec_arp_table *rulla;
  1388. char buf[256];
  1389. int i, j, offset;
  1390. printk("Dump %p:\n", priv);
  1391. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1392. hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
  1393. offset = 0;
  1394. offset += sprintf(buf, "%d: %p\n", i, rulla);
  1395. offset += sprintf(buf + offset, "Mac:");
  1396. for (j = 0; j < ETH_ALEN; j++) {
  1397. offset += sprintf(buf + offset,
  1398. "%2.2x ",
  1399. rulla->mac_addr[j] & 0xff);
  1400. }
  1401. offset += sprintf(buf + offset, "Atm:");
  1402. for (j = 0; j < ATM_ESA_LEN; j++) {
  1403. offset += sprintf(buf + offset,
  1404. "%2.2x ",
  1405. rulla->atm_addr[j] & 0xff);
  1406. }
  1407. offset += sprintf(buf + offset,
  1408. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1409. rulla->vcc ? rulla->vcc->vpi : 0,
  1410. rulla->vcc ? rulla->vcc->vci : 0,
  1411. rulla->recv_vcc ? rulla->recv_vcc->
  1412. vpi : 0,
  1413. rulla->recv_vcc ? rulla->recv_vcc->
  1414. vci : 0, rulla->last_used,
  1415. rulla->timestamp, rulla->no_tries);
  1416. offset +=
  1417. sprintf(buf + offset,
  1418. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1419. rulla->flags, rulla->packets_flooded,
  1420. get_status_string(rulla->status));
  1421. printk("%s\n", buf);
  1422. }
  1423. }
  1424. if (!hlist_empty(&priv->lec_no_forward))
  1425. printk("No forward\n");
  1426. hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
  1427. offset = 0;
  1428. offset += sprintf(buf + offset, "Mac:");
  1429. for (j = 0; j < ETH_ALEN; j++) {
  1430. offset += sprintf(buf + offset, "%2.2x ",
  1431. rulla->mac_addr[j] & 0xff);
  1432. }
  1433. offset += sprintf(buf + offset, "Atm:");
  1434. for (j = 0; j < ATM_ESA_LEN; j++) {
  1435. offset += sprintf(buf + offset, "%2.2x ",
  1436. rulla->atm_addr[j] & 0xff);
  1437. }
  1438. offset += sprintf(buf + offset,
  1439. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1440. rulla->vcc ? rulla->vcc->vpi : 0,
  1441. rulla->vcc ? rulla->vcc->vci : 0,
  1442. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1443. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1444. rulla->last_used,
  1445. rulla->timestamp, rulla->no_tries);
  1446. offset += sprintf(buf + offset,
  1447. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1448. rulla->flags, rulla->packets_flooded,
  1449. get_status_string(rulla->status));
  1450. printk("%s\n", buf);
  1451. }
  1452. if (!hlist_empty(&priv->lec_arp_empty_ones))
  1453. printk("Empty ones\n");
  1454. hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
  1455. offset = 0;
  1456. offset += sprintf(buf + offset, "Mac:");
  1457. for (j = 0; j < ETH_ALEN; j++) {
  1458. offset += sprintf(buf + offset, "%2.2x ",
  1459. rulla->mac_addr[j] & 0xff);
  1460. }
  1461. offset += sprintf(buf + offset, "Atm:");
  1462. for (j = 0; j < ATM_ESA_LEN; j++) {
  1463. offset += sprintf(buf + offset, "%2.2x ",
  1464. rulla->atm_addr[j] & 0xff);
  1465. }
  1466. offset += sprintf(buf + offset,
  1467. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1468. rulla->vcc ? rulla->vcc->vpi : 0,
  1469. rulla->vcc ? rulla->vcc->vci : 0,
  1470. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1471. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1472. rulla->last_used,
  1473. rulla->timestamp, rulla->no_tries);
  1474. offset += sprintf(buf + offset,
  1475. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1476. rulla->flags, rulla->packets_flooded,
  1477. get_status_string(rulla->status));
  1478. printk("%s", buf);
  1479. }
  1480. if (!hlist_empty(&priv->mcast_fwds))
  1481. printk("Multicast Forward VCCs\n");
  1482. hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
  1483. offset = 0;
  1484. offset += sprintf(buf + offset, "Mac:");
  1485. for (j = 0; j < ETH_ALEN; j++) {
  1486. offset += sprintf(buf + offset, "%2.2x ",
  1487. rulla->mac_addr[j] & 0xff);
  1488. }
  1489. offset += sprintf(buf + offset, "Atm:");
  1490. for (j = 0; j < ATM_ESA_LEN; j++) {
  1491. offset += sprintf(buf + offset, "%2.2x ",
  1492. rulla->atm_addr[j] & 0xff);
  1493. }
  1494. offset += sprintf(buf + offset,
  1495. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1496. rulla->vcc ? rulla->vcc->vpi : 0,
  1497. rulla->vcc ? rulla->vcc->vci : 0,
  1498. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1499. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1500. rulla->last_used,
  1501. rulla->timestamp, rulla->no_tries);
  1502. offset += sprintf(buf + offset,
  1503. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1504. rulla->flags, rulla->packets_flooded,
  1505. get_status_string(rulla->status));
  1506. printk("%s\n", buf);
  1507. }
  1508. }
  1509. #else
  1510. #define dump_arp_table(priv) do { } while (0)
  1511. #endif
  1512. /*
  1513. * Destruction of arp-cache
  1514. */
  1515. static void lec_arp_destroy(struct lec_priv *priv)
  1516. {
  1517. unsigned long flags;
  1518. struct hlist_node *node, *next;
  1519. struct lec_arp_table *entry;
  1520. int i;
  1521. cancel_rearming_delayed_work(&priv->lec_arp_work);
  1522. /*
  1523. * Remove all entries
  1524. */
  1525. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1526. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1527. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
  1528. lec_arp_remove(priv, entry);
  1529. kfree(entry);
  1530. }
  1531. INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
  1532. }
  1533. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
  1534. del_timer_sync(&entry->timer);
  1535. lec_arp_clear_vccs(entry);
  1536. hlist_del(&entry->next);
  1537. kfree(entry);
  1538. }
  1539. INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
  1540. hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
  1541. del_timer_sync(&entry->timer);
  1542. lec_arp_clear_vccs(entry);
  1543. hlist_del(&entry->next);
  1544. kfree(entry);
  1545. }
  1546. INIT_HLIST_HEAD(&priv->lec_no_forward);
  1547. hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
  1548. /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
  1549. lec_arp_clear_vccs(entry);
  1550. hlist_del(&entry->next);
  1551. kfree(entry);
  1552. }
  1553. INIT_HLIST_HEAD(&priv->mcast_fwds);
  1554. priv->mcast_vcc = NULL;
  1555. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1556. }
  1557. /*
  1558. * Find entry by mac_address
  1559. */
  1560. static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
  1561. unsigned char *mac_addr)
  1562. {
  1563. struct hlist_node *node;
  1564. struct hlist_head *head;
  1565. struct lec_arp_table *entry;
  1566. DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
  1567. mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
  1568. mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
  1569. head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
  1570. hlist_for_each_entry(entry, node, head, next) {
  1571. if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
  1572. return entry;
  1573. }
  1574. }
  1575. return NULL;
  1576. }
  1577. static struct lec_arp_table *make_entry(struct lec_priv *priv,
  1578. unsigned char *mac_addr)
  1579. {
  1580. struct lec_arp_table *to_return;
  1581. to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
  1582. if (!to_return) {
  1583. printk("LEC: Arp entry kmalloc failed\n");
  1584. return NULL;
  1585. }
  1586. memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
  1587. INIT_HLIST_NODE(&to_return->next);
  1588. init_timer(&to_return->timer);
  1589. to_return->timer.function = lec_arp_expire_arp;
  1590. to_return->timer.data = (unsigned long)to_return;
  1591. to_return->last_used = jiffies;
  1592. to_return->priv = priv;
  1593. skb_queue_head_init(&to_return->tx_wait);
  1594. return to_return;
  1595. }
  1596. /* Arp sent timer expired */
  1597. static void lec_arp_expire_arp(unsigned long data)
  1598. {
  1599. struct lec_arp_table *entry;
  1600. entry = (struct lec_arp_table *)data;
  1601. DPRINTK("lec_arp_expire_arp\n");
  1602. if (entry->status == ESI_ARP_PENDING) {
  1603. if (entry->no_tries <= entry->priv->max_retry_count) {
  1604. if (entry->is_rdesc)
  1605. send_to_lecd(entry->priv, l_rdesc_arp_xmt,
  1606. entry->mac_addr, NULL, NULL);
  1607. else
  1608. send_to_lecd(entry->priv, l_arp_xmt,
  1609. entry->mac_addr, NULL, NULL);
  1610. entry->no_tries++;
  1611. }
  1612. mod_timer(&entry->timer, jiffies + (1 * HZ));
  1613. }
  1614. }
  1615. /* Unknown/unused vcc expire, remove associated entry */
  1616. static void lec_arp_expire_vcc(unsigned long data)
  1617. {
  1618. unsigned long flags;
  1619. struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
  1620. struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
  1621. del_timer(&to_remove->timer);
  1622. DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
  1623. to_remove, priv,
  1624. to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
  1625. to_remove->vcc ? to_remove->recv_vcc->vci : 0);
  1626. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1627. hlist_del(&to_remove->next);
  1628. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1629. lec_arp_clear_vccs(to_remove);
  1630. kfree(to_remove);
  1631. }
  1632. /*
  1633. * Expire entries.
  1634. * 1. Re-set timer
  1635. * 2. For each entry, delete entries that have aged past the age limit.
  1636. * 3. For each entry, depending on the status of the entry, perform
  1637. * the following maintenance.
  1638. * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
  1639. * tick_count is above the max_unknown_frame_time, clear
  1640. * the tick_count to zero and clear the packets_flooded counter
  1641. * to zero. This supports the packet rate limit per address
  1642. * while flooding unknowns.
  1643. * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
  1644. * than or equal to the path_switching_delay, change the status
  1645. * to ESI_FORWARD_DIRECT. This causes the flush period to end
  1646. * regardless of the progress of the flush protocol.
  1647. */
  1648. static void lec_arp_check_expire(void *data)
  1649. {
  1650. unsigned long flags;
  1651. struct lec_priv *priv = data;
  1652. struct hlist_node *node, *next;
  1653. struct lec_arp_table *entry;
  1654. unsigned long now;
  1655. unsigned long time_to_check;
  1656. int i;
  1657. DPRINTK("lec_arp_check_expire %p\n", priv);
  1658. now = jiffies;
  1659. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1660. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1661. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
  1662. if ((entry->flags) & LEC_REMOTE_FLAG &&
  1663. priv->topology_change)
  1664. time_to_check = priv->forward_delay_time;
  1665. else
  1666. time_to_check = priv->aging_time;
  1667. DPRINTK("About to expire: %lx - %lx > %lx\n",
  1668. now, entry->last_used, time_to_check);
  1669. if (time_after(now, entry->last_used + time_to_check)
  1670. && !(entry->flags & LEC_PERMANENT_FLAG)
  1671. && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
  1672. /* Remove entry */
  1673. DPRINTK("LEC:Entry timed out\n");
  1674. lec_arp_remove(priv, entry);
  1675. kfree(entry);
  1676. } else {
  1677. /* Something else */
  1678. if ((entry->status == ESI_VC_PENDING ||
  1679. entry->status == ESI_ARP_PENDING)
  1680. && time_after_eq(now,
  1681. entry->timestamp +
  1682. priv->
  1683. max_unknown_frame_time)) {
  1684. entry->timestamp = jiffies;
  1685. entry->packets_flooded = 0;
  1686. if (entry->status == ESI_VC_PENDING)
  1687. send_to_lecd(priv, l_svc_setup,
  1688. entry->mac_addr,
  1689. entry->atm_addr,
  1690. NULL);
  1691. }
  1692. if (entry->status == ESI_FLUSH_PENDING
  1693. &&
  1694. time_after_eq(now, entry->timestamp +
  1695. priv->path_switching_delay)) {
  1696. struct sk_buff *skb;
  1697. while ((skb =
  1698. skb_dequeue(&entry->tx_wait)) !=
  1699. NULL)
  1700. lec_send(entry->vcc, skb,
  1701. entry->priv);
  1702. entry->last_used = jiffies;
  1703. entry->status = ESI_FORWARD_DIRECT;
  1704. }
  1705. }
  1706. }
  1707. }
  1708. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1709. schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
  1710. }
  1711. /*
  1712. * Try to find vcc where mac_address is attached.
  1713. *
  1714. */
  1715. static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
  1716. unsigned char *mac_to_find, int is_rdesc,
  1717. struct lec_arp_table **ret_entry)
  1718. {
  1719. unsigned long flags;
  1720. struct lec_arp_table *entry;
  1721. struct atm_vcc *found;
  1722. if (mac_to_find[0] & 0x01) {
  1723. switch (priv->lane_version) {
  1724. case 1:
  1725. return priv->mcast_vcc;
  1726. break;
  1727. case 2: /* LANE2 wants arp for multicast addresses */
  1728. if (!compare_ether_addr(mac_to_find, bus_mac))
  1729. return priv->mcast_vcc;
  1730. break;
  1731. default:
  1732. break;
  1733. }
  1734. }
  1735. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1736. entry = lec_arp_find(priv, mac_to_find);
  1737. if (entry) {
  1738. if (entry->status == ESI_FORWARD_DIRECT) {
  1739. /* Connection Ok */
  1740. entry->last_used = jiffies;
  1741. *ret_entry = entry;
  1742. found = entry->vcc;
  1743. goto out;
  1744. }
  1745. /*
  1746. * If the LE_ARP cache entry is still pending, reset count to 0
  1747. * so another LE_ARP request can be made for this frame.
  1748. */
  1749. if (entry->status == ESI_ARP_PENDING) {
  1750. entry->no_tries = 0;
  1751. }
  1752. /*
  1753. * Data direct VC not yet set up, check to see if the unknown
  1754. * frame count is greater than the limit. If the limit has
  1755. * not been reached, allow the caller to send packet to
  1756. * BUS.
  1757. */
  1758. if (entry->status != ESI_FLUSH_PENDING &&
  1759. entry->packets_flooded <
  1760. priv->maximum_unknown_frame_count) {
  1761. entry->packets_flooded++;
  1762. DPRINTK("LEC_ARP: Flooding..\n");
  1763. found = priv->mcast_vcc;
  1764. goto out;
  1765. }
  1766. /*
  1767. * We got here because entry->status == ESI_FLUSH_PENDING
  1768. * or BUS flood limit was reached for an entry which is
  1769. * in ESI_ARP_PENDING or ESI_VC_PENDING state.
  1770. */
  1771. *ret_entry = entry;
  1772. DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status,
  1773. entry->vcc);
  1774. found = NULL;
  1775. } else {
  1776. /* No matching entry was found */
  1777. entry = make_entry(priv, mac_to_find);
  1778. DPRINTK("LEC_ARP: Making entry\n");
  1779. if (!entry) {
  1780. found = priv->mcast_vcc;
  1781. goto out;
  1782. }
  1783. lec_arp_add(priv, entry);
  1784. /* We want arp-request(s) to be sent */
  1785. entry->packets_flooded = 1;
  1786. entry->status = ESI_ARP_PENDING;
  1787. entry->no_tries = 1;
  1788. entry->last_used = entry->timestamp = jiffies;
  1789. entry->is_rdesc = is_rdesc;
  1790. if (entry->is_rdesc)
  1791. send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
  1792. NULL);
  1793. else
  1794. send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
  1795. entry->timer.expires = jiffies + (1 * HZ);
  1796. entry->timer.function = lec_arp_expire_arp;
  1797. add_timer(&entry->timer);
  1798. found = priv->mcast_vcc;
  1799. }
  1800. out:
  1801. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1802. return found;
  1803. }
  1804. static int
  1805. lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
  1806. unsigned long permanent)
  1807. {
  1808. unsigned long flags;
  1809. struct hlist_node *node, *next;
  1810. struct lec_arp_table *entry;
  1811. int i;
  1812. DPRINTK("lec_addr_delete\n");
  1813. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1814. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1815. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
  1816. if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
  1817. && (permanent ||
  1818. !(entry->flags & LEC_PERMANENT_FLAG))) {
  1819. lec_arp_remove(priv, entry);
  1820. kfree(entry);
  1821. }
  1822. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1823. return 0;
  1824. }
  1825. }
  1826. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1827. return -1;
  1828. }
  1829. /*
  1830. * Notifies: Response to arp_request (atm_addr != NULL)
  1831. */
  1832. static void
  1833. lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
  1834. unsigned char *atm_addr, unsigned long remoteflag,
  1835. unsigned int targetless_le_arp)
  1836. {
  1837. unsigned long flags;
  1838. struct hlist_node *node, *next;
  1839. struct lec_arp_table *entry, *tmp;
  1840. int i;
  1841. DPRINTK("lec:%s", (targetless_le_arp) ? "targetless " : " ");
  1842. DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
  1843. mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
  1844. mac_addr[4], mac_addr[5]);
  1845. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1846. entry = lec_arp_find(priv, mac_addr);
  1847. if (entry == NULL && targetless_le_arp)
  1848. goto out; /*
  1849. * LANE2: ignore targetless LE_ARPs for which
  1850. * we have no entry in the cache. 7.1.30
  1851. */
  1852. if (!hlist_empty(&priv->lec_arp_empty_ones)) {
  1853. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
  1854. if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
  1855. hlist_del(&entry->next);
  1856. del_timer(&entry->timer);
  1857. tmp = lec_arp_find(priv, mac_addr);
  1858. if (tmp) {
  1859. del_timer(&tmp->timer);
  1860. tmp->status = ESI_FORWARD_DIRECT;
  1861. memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
  1862. tmp->vcc = entry->vcc;
  1863. tmp->old_push = entry->old_push;
  1864. tmp->last_used = jiffies;
  1865. del_timer(&entry->timer);
  1866. kfree(entry);
  1867. entry = tmp;
  1868. } else {
  1869. entry->status = ESI_FORWARD_DIRECT;
  1870. memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
  1871. entry->last_used = jiffies;
  1872. lec_arp_add(priv, entry);
  1873. }
  1874. if (remoteflag)
  1875. entry->flags |= LEC_REMOTE_FLAG;
  1876. else
  1877. entry->flags &= ~LEC_REMOTE_FLAG;
  1878. DPRINTK("After update\n");
  1879. dump_arp_table(priv);
  1880. goto out;
  1881. }
  1882. }
  1883. }
  1884. entry = lec_arp_find(priv, mac_addr);
  1885. if (!entry) {
  1886. entry = make_entry(priv, mac_addr);
  1887. if (!entry)
  1888. goto out;
  1889. entry->status = ESI_UNKNOWN;
  1890. lec_arp_add(priv, entry);
  1891. /* Temporary, changes before end of function */
  1892. }
  1893. memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
  1894. del_timer(&entry->timer);
  1895. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1896. hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
  1897. if (entry != tmp &&
  1898. !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
  1899. /* Vcc to this host exists */
  1900. if (tmp->status > ESI_VC_PENDING) {
  1901. /*
  1902. * ESI_FLUSH_PENDING,
  1903. * ESI_FORWARD_DIRECT
  1904. */
  1905. entry->vcc = tmp->vcc;
  1906. entry->old_push = tmp->old_push;
  1907. }
  1908. entry->status = tmp->status;
  1909. break;
  1910. }
  1911. }
  1912. }
  1913. if (remoteflag)
  1914. entry->flags |= LEC_REMOTE_FLAG;
  1915. else
  1916. entry->flags &= ~LEC_REMOTE_FLAG;
  1917. if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
  1918. entry->status = ESI_VC_PENDING;
  1919. send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
  1920. }
  1921. DPRINTK("After update2\n");
  1922. dump_arp_table(priv);
  1923. out:
  1924. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1925. }
  1926. /*
  1927. * Notifies: Vcc setup ready
  1928. */
  1929. static void
  1930. lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
  1931. struct atm_vcc *vcc,
  1932. void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
  1933. {
  1934. unsigned long flags;
  1935. struct hlist_node *node;
  1936. struct lec_arp_table *entry;
  1937. int i, found_entry = 0;
  1938. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1939. if (ioc_data->receive == 2) {
  1940. /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
  1941. DPRINTK("LEC_ARP: Attaching mcast forward\n");
  1942. #if 0
  1943. entry = lec_arp_find(priv, bus_mac);
  1944. if (!entry) {
  1945. printk("LEC_ARP: Multicast entry not found!\n");
  1946. goto out;
  1947. }
  1948. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1949. entry->recv_vcc = vcc;
  1950. entry->old_recv_push = old_push;
  1951. #endif
  1952. entry = make_entry(priv, bus_mac);
  1953. if (entry == NULL)
  1954. goto out;
  1955. del_timer(&entry->timer);
  1956. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1957. entry->recv_vcc = vcc;
  1958. entry->old_recv_push = old_push;
  1959. hlist_add_head(&entry->next, &priv->mcast_fwds);
  1960. goto out;
  1961. } else if (ioc_data->receive == 1) {
  1962. /*
  1963. * Vcc which we don't want to make default vcc,
  1964. * attach it anyway.
  1965. */
  1966. DPRINTK
  1967. ("LEC_ARP:Attaching data direct, not default: "
  1968. "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
  1969. ioc_data->atm_addr[0], ioc_data->atm_addr[1],
  1970. ioc_data->atm_addr[2], ioc_data->atm_addr[3],
  1971. ioc_data->atm_addr[4], ioc_data->atm_addr[5],
  1972. ioc_data->atm_addr[6], ioc_data->atm_addr[7],
  1973. ioc_data->atm_addr[8], ioc_data->atm_addr[9],
  1974. ioc_data->atm_addr[10], ioc_data->atm_addr[11],
  1975. ioc_data->atm_addr[12], ioc_data->atm_addr[13],
  1976. ioc_data->atm_addr[14], ioc_data->atm_addr[15],
  1977. ioc_data->atm_addr[16], ioc_data->atm_addr[17],
  1978. ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
  1979. entry = make_entry(priv, bus_mac);
  1980. if (entry == NULL)
  1981. goto out;
  1982. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1983. memset(entry->mac_addr, 0, ETH_ALEN);
  1984. entry->recv_vcc = vcc;
  1985. entry->old_recv_push = old_push;
  1986. entry->status = ESI_UNKNOWN;
  1987. entry->timer.expires = jiffies + priv->vcc_timeout_period;
  1988. entry->timer.function = lec_arp_expire_vcc;
  1989. hlist_add_head(&entry->next, &priv->lec_no_forward);
  1990. add_timer(&entry->timer);
  1991. dump_arp_table(priv);
  1992. goto out;
  1993. }
  1994. DPRINTK
  1995. ("LEC_ARP:Attaching data direct, default: "
  1996. "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
  1997. ioc_data->atm_addr[0], ioc_data->atm_addr[1],
  1998. ioc_data->atm_addr[2], ioc_data->atm_addr[3],
  1999. ioc_data->atm_addr[4], ioc_data->atm_addr[5],
  2000. ioc_data->atm_addr[6], ioc_data->atm_addr[7],
  2001. ioc_data->atm_addr[8], ioc_data->atm_addr[9],
  2002. ioc_data->atm_addr[10], ioc_data->atm_addr[11],
  2003. ioc_data->atm_addr[12], ioc_data->atm_addr[13],
  2004. ioc_data->atm_addr[14], ioc_data->atm_addr[15],
  2005. ioc_data->atm_addr[16], ioc_data->atm_addr[17],
  2006. ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
  2007. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  2008. hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
  2009. if (memcmp
  2010. (ioc_data->atm_addr, entry->atm_addr,
  2011. ATM_ESA_LEN) == 0) {
  2012. DPRINTK("LEC_ARP: Attaching data direct\n");
  2013. DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
  2014. entry->vcc ? entry->vcc->vci : 0,
  2015. entry->recv_vcc ? entry->recv_vcc->
  2016. vci : 0);
  2017. found_entry = 1;
  2018. del_timer(&entry->timer);
  2019. entry->vcc = vcc;
  2020. entry->old_push = old_push;
  2021. if (entry->status == ESI_VC_PENDING) {
  2022. if (priv->maximum_unknown_frame_count
  2023. == 0)
  2024. entry->status =
  2025. ESI_FORWARD_DIRECT;
  2026. else {
  2027. entry->timestamp = jiffies;
  2028. entry->status =
  2029. ESI_FLUSH_PENDING;
  2030. #if 0
  2031. send_to_lecd(priv, l_flush_xmt,
  2032. NULL,
  2033. entry->atm_addr,
  2034. NULL);
  2035. #endif
  2036. }
  2037. } else {
  2038. /*
  2039. * They were forming a connection
  2040. * to us, and we to them. Our
  2041. * ATM address is numerically lower
  2042. * than theirs, so we make connection
  2043. * we formed into default VCC (8.1.11).
  2044. * Connection they made gets torn
  2045. * down. This might confuse some
  2046. * clients. Can be changed if
  2047. * someone reports trouble...
  2048. */
  2049. ;
  2050. }
  2051. }
  2052. }
  2053. }
  2054. if (found_entry) {
  2055. DPRINTK("After vcc was added\n");
  2056. dump_arp_table(priv);
  2057. goto out;
  2058. }
  2059. /*
  2060. * Not found, snatch address from first data packet that arrives
  2061. * from this vcc
  2062. */
  2063. entry = make_entry(priv, bus_mac);
  2064. if (!entry)
  2065. goto out;
  2066. entry->vcc = vcc;
  2067. entry->old_push = old_push;
  2068. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  2069. memset(entry->mac_addr, 0, ETH_ALEN);
  2070. entry->status = ESI_UNKNOWN;
  2071. hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
  2072. entry->timer.expires = jiffies + priv->vcc_timeout_period;
  2073. entry->timer.function = lec_arp_expire_vcc;
  2074. add_timer(&entry->timer);
  2075. DPRINTK("After vcc was added\n");
  2076. dump_arp_table(priv);
  2077. out:
  2078. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2079. }
  2080. static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
  2081. {
  2082. unsigned long flags;
  2083. struct hlist_node *node;
  2084. struct lec_arp_table *entry;
  2085. int i;
  2086. DPRINTK("LEC:lec_flush_complete %lx\n", tran_id);
  2087. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2088. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  2089. hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
  2090. if (entry->flush_tran_id == tran_id
  2091. && entry->status == ESI_FLUSH_PENDING) {
  2092. struct sk_buff *skb;
  2093. while ((skb =
  2094. skb_dequeue(&entry->tx_wait)) != NULL)
  2095. lec_send(entry->vcc, skb, entry->priv);
  2096. entry->status = ESI_FORWARD_DIRECT;
  2097. DPRINTK("LEC_ARP: Flushed\n");
  2098. }
  2099. }
  2100. }
  2101. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2102. dump_arp_table(priv);
  2103. }
  2104. static void
  2105. lec_set_flush_tran_id(struct lec_priv *priv,
  2106. unsigned char *atm_addr, unsigned long tran_id)
  2107. {
  2108. unsigned long flags;
  2109. struct hlist_node *node;
  2110. struct lec_arp_table *entry;
  2111. int i;
  2112. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2113. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
  2114. hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
  2115. if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
  2116. entry->flush_tran_id = tran_id;
  2117. DPRINTK("Set flush transaction id to %lx for %p\n",
  2118. tran_id, entry);
  2119. }
  2120. }
  2121. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2122. }
  2123. static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
  2124. {
  2125. unsigned long flags;
  2126. unsigned char mac_addr[] = {
  2127. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  2128. };
  2129. struct lec_arp_table *to_add;
  2130. struct lec_vcc_priv *vpriv;
  2131. int err = 0;
  2132. if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
  2133. return -ENOMEM;
  2134. vpriv->xoff = 0;
  2135. vpriv->old_pop = vcc->pop;
  2136. vcc->user_back = vpriv;
  2137. vcc->pop = lec_pop;
  2138. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2139. to_add = make_entry(priv, mac_addr);
  2140. if (!to_add) {
  2141. vcc->pop = vpriv->old_pop;
  2142. kfree(vpriv);
  2143. err = -ENOMEM;
  2144. goto out;
  2145. }
  2146. memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
  2147. to_add->status = ESI_FORWARD_DIRECT;
  2148. to_add->flags |= LEC_PERMANENT_FLAG;
  2149. to_add->vcc = vcc;
  2150. to_add->old_push = vcc->push;
  2151. vcc->push = lec_push;
  2152. priv->mcast_vcc = vcc;
  2153. lec_arp_add(priv, to_add);
  2154. out:
  2155. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2156. return err;
  2157. }
  2158. static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
  2159. {
  2160. unsigned long flags;
  2161. struct hlist_node *node, *next;
  2162. struct lec_arp_table *entry;
  2163. int i;
  2164. DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
  2165. dump_arp_table(priv);
  2166. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2167. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  2168. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
  2169. if (vcc == entry->vcc) {
  2170. lec_arp_remove(priv, entry);
  2171. kfree(entry);
  2172. if (priv->mcast_vcc == vcc) {
  2173. priv->mcast_vcc = NULL;
  2174. }
  2175. }
  2176. }
  2177. }
  2178. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
  2179. if (entry->vcc == vcc) {
  2180. lec_arp_clear_vccs(entry);
  2181. del_timer(&entry->timer);
  2182. hlist_del(&entry->next);
  2183. kfree(entry);
  2184. }
  2185. }
  2186. hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
  2187. if (entry->recv_vcc == vcc) {
  2188. lec_arp_clear_vccs(entry);
  2189. del_timer(&entry->timer);
  2190. hlist_del(&entry->next);
  2191. kfree(entry);
  2192. }
  2193. }
  2194. hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
  2195. if (entry->recv_vcc == vcc) {
  2196. lec_arp_clear_vccs(entry);
  2197. /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
  2198. hlist_del(&entry->next);
  2199. kfree(entry);
  2200. }
  2201. }
  2202. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2203. dump_arp_table(priv);
  2204. }
  2205. static void
  2206. lec_arp_check_empties(struct lec_priv *priv,
  2207. struct atm_vcc *vcc, struct sk_buff *skb)
  2208. {
  2209. unsigned long flags;
  2210. struct hlist_node *node, *next;
  2211. struct lec_arp_table *entry, *tmp;
  2212. struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
  2213. unsigned char *src;
  2214. #ifdef CONFIG_TR
  2215. struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
  2216. if (priv->is_trdev)
  2217. src = tr_hdr->h_source;
  2218. else
  2219. #endif
  2220. src = hdr->h_source;
  2221. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2222. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
  2223. if (vcc == entry->vcc) {
  2224. del_timer(&entry->timer);
  2225. memcpy(entry->mac_addr, src, ETH_ALEN);
  2226. entry->status = ESI_FORWARD_DIRECT;
  2227. entry->last_used = jiffies;
  2228. /* We might have got an entry */
  2229. if ((tmp = lec_arp_find(priv, src))) {
  2230. lec_arp_remove(priv, tmp);
  2231. kfree(tmp);
  2232. }
  2233. hlist_del(&entry->next);
  2234. lec_arp_add(priv, entry);
  2235. goto out;
  2236. }
  2237. }
  2238. DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
  2239. out:
  2240. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2241. }
  2242. MODULE_LICENSE("GPL");