lec.c 66 KB

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