lec.c 86 KB

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