lec.c 86 KB

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