lec.c 67 KB

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