lec.c 67 KB

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