lec.c 67 KB

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