lec.c 67 KB

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