lec.c 66 KB

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