lec.c 67 KB

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