lec.c 66 KB

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