lec.c 67 KB

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