lec.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522
  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,
  246. (long)skb->end);
  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. memcpy(skb2->data, mesg,
  516. sizeof(struct atmlec_msg));
  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
  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. {
  745. skb->dev = dev;
  746. skb->protocol = eth_type_trans(skb, dev);
  747. }
  748. priv->stats.rx_packets++;
  749. priv->stats.rx_bytes += skb->len;
  750. memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
  751. netif_rx(skb);
  752. }
  753. }
  754. static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
  755. {
  756. struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
  757. struct net_device *dev = skb->dev;
  758. if (vpriv == NULL) {
  759. printk("lec_pop(): vpriv = NULL!?!?!?\n");
  760. return;
  761. }
  762. vpriv->old_pop(vcc, skb);
  763. if (vpriv->xoff && atm_may_send(vcc, 0)) {
  764. vpriv->xoff = 0;
  765. if (netif_running(dev) && netif_queue_stopped(dev))
  766. netif_wake_queue(dev);
  767. }
  768. }
  769. static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
  770. {
  771. struct lec_vcc_priv *vpriv;
  772. int bytes_left;
  773. struct atmlec_ioc ioc_data;
  774. /* Lecd must be up in this case */
  775. bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
  776. if (bytes_left != 0) {
  777. printk
  778. ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
  779. bytes_left);
  780. }
  781. if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
  782. !dev_lec[ioc_data.dev_num])
  783. return -EINVAL;
  784. if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
  785. return -ENOMEM;
  786. vpriv->xoff = 0;
  787. vpriv->old_pop = vcc->pop;
  788. vcc->user_back = vpriv;
  789. vcc->pop = lec_pop;
  790. lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
  791. &ioc_data, vcc, vcc->push);
  792. vcc->proto_data = dev_lec[ioc_data.dev_num];
  793. vcc->push = lec_push;
  794. return 0;
  795. }
  796. static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
  797. {
  798. if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
  799. return -EINVAL;
  800. vcc->proto_data = dev_lec[arg];
  801. return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
  802. }
  803. /* Initialize device. */
  804. static int lecd_attach(struct atm_vcc *vcc, int arg)
  805. {
  806. int i;
  807. struct lec_priv *priv;
  808. if (arg < 0)
  809. i = 0;
  810. else
  811. i = arg;
  812. #ifdef CONFIG_TR
  813. if (arg >= MAX_LEC_ITF)
  814. return -EINVAL;
  815. #else /* Reserve the top NUM_TR_DEVS for TR */
  816. if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
  817. return -EINVAL;
  818. #endif
  819. if (!dev_lec[i]) {
  820. int is_trdev, size;
  821. is_trdev = 0;
  822. if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
  823. is_trdev = 1;
  824. size = sizeof(struct lec_priv);
  825. #ifdef CONFIG_TR
  826. if (is_trdev)
  827. dev_lec[i] = alloc_trdev(size);
  828. else
  829. #endif
  830. dev_lec[i] = alloc_etherdev(size);
  831. if (!dev_lec[i])
  832. return -ENOMEM;
  833. snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
  834. if (register_netdev(dev_lec[i])) {
  835. free_netdev(dev_lec[i]);
  836. return -EINVAL;
  837. }
  838. priv = dev_lec[i]->priv;
  839. priv->is_trdev = is_trdev;
  840. lec_init(dev_lec[i]);
  841. } else {
  842. priv = dev_lec[i]->priv;
  843. if (priv->lecd)
  844. return -EADDRINUSE;
  845. }
  846. lec_arp_init(priv);
  847. priv->itfnum = i; /* LANE2 addition */
  848. priv->lecd = vcc;
  849. vcc->dev = &lecatm_dev;
  850. vcc_insert_socket(sk_atm(vcc));
  851. vcc->proto_data = dev_lec[i];
  852. set_bit(ATM_VF_META, &vcc->flags);
  853. set_bit(ATM_VF_READY, &vcc->flags);
  854. /* Set default values to these variables */
  855. priv->maximum_unknown_frame_count = 1;
  856. priv->max_unknown_frame_time = (1 * HZ);
  857. priv->vcc_timeout_period = (1200 * HZ);
  858. priv->max_retry_count = 1;
  859. priv->aging_time = (300 * HZ);
  860. priv->forward_delay_time = (15 * HZ);
  861. priv->topology_change = 0;
  862. priv->arp_response_time = (1 * HZ);
  863. priv->flush_timeout = (4 * HZ);
  864. priv->path_switching_delay = (6 * HZ);
  865. if (dev_lec[i]->flags & IFF_UP) {
  866. netif_start_queue(dev_lec[i]);
  867. }
  868. __module_get(THIS_MODULE);
  869. return i;
  870. }
  871. #ifdef CONFIG_PROC_FS
  872. static char *lec_arp_get_status_string(unsigned char status)
  873. {
  874. static char *lec_arp_status_string[] = {
  875. "ESI_UNKNOWN ",
  876. "ESI_ARP_PENDING ",
  877. "ESI_VC_PENDING ",
  878. "<Undefined> ",
  879. "ESI_FLUSH_PENDING ",
  880. "ESI_FORWARD_DIRECT"
  881. };
  882. if (status > ESI_FORWARD_DIRECT)
  883. status = 3; /* ESI_UNDEFINED */
  884. return lec_arp_status_string[status];
  885. }
  886. static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
  887. {
  888. int i;
  889. for (i = 0; i < ETH_ALEN; i++)
  890. seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
  891. seq_printf(seq, " ");
  892. for (i = 0; i < ATM_ESA_LEN; i++)
  893. seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
  894. seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
  895. entry->flags & 0xffff);
  896. if (entry->vcc)
  897. seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
  898. else
  899. seq_printf(seq, " ");
  900. if (entry->recv_vcc) {
  901. seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
  902. entry->recv_vcc->vci);
  903. }
  904. seq_putc(seq, '\n');
  905. }
  906. struct lec_state {
  907. unsigned long flags;
  908. struct lec_priv *locked;
  909. struct hlist_node *node;
  910. struct net_device *dev;
  911. int itf;
  912. int arp_table;
  913. int misc_table;
  914. };
  915. static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
  916. loff_t *l)
  917. {
  918. struct hlist_node *e = state->node;
  919. struct lec_arp_table *tmp;
  920. if (!e)
  921. e = tbl->first;
  922. if (e == (void *)1) {
  923. e = tbl->first;
  924. --*l;
  925. }
  926. hlist_for_each_entry_from(tmp, e, next) {
  927. if (--*l < 0)
  928. break;
  929. }
  930. state->node = e;
  931. return (*l < 0) ? state : NULL;
  932. }
  933. static void *lec_arp_walk(struct lec_state *state, loff_t *l,
  934. struct lec_priv *priv)
  935. {
  936. void *v = NULL;
  937. int p;
  938. for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
  939. v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
  940. if (v)
  941. break;
  942. }
  943. state->arp_table = p;
  944. return v;
  945. }
  946. static void *lec_misc_walk(struct lec_state *state, loff_t *l,
  947. struct lec_priv *priv)
  948. {
  949. struct hlist_head *lec_misc_tables[] = {
  950. &priv->lec_arp_empty_ones,
  951. &priv->lec_no_forward,
  952. &priv->mcast_fwds
  953. };
  954. void *v = NULL;
  955. int q;
  956. for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
  957. v = lec_tbl_walk(state, lec_misc_tables[q], l);
  958. if (v)
  959. break;
  960. }
  961. state->misc_table = q;
  962. return v;
  963. }
  964. static void *lec_priv_walk(struct lec_state *state, loff_t *l,
  965. struct lec_priv *priv)
  966. {
  967. if (!state->locked) {
  968. state->locked = priv;
  969. spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
  970. }
  971. if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
  972. spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
  973. state->locked = NULL;
  974. /* Partial state reset for the next time we get called */
  975. state->arp_table = state->misc_table = 0;
  976. }
  977. return state->locked;
  978. }
  979. static void *lec_itf_walk(struct lec_state *state, loff_t *l)
  980. {
  981. struct net_device *dev;
  982. void *v;
  983. dev = state->dev ? state->dev : dev_lec[state->itf];
  984. v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
  985. if (!v && dev) {
  986. dev_put(dev);
  987. /* Partial state reset for the next time we get called */
  988. dev = NULL;
  989. }
  990. state->dev = dev;
  991. return v;
  992. }
  993. static void *lec_get_idx(struct lec_state *state, loff_t l)
  994. {
  995. void *v = NULL;
  996. for (; state->itf < MAX_LEC_ITF; state->itf++) {
  997. v = lec_itf_walk(state, &l);
  998. if (v)
  999. break;
  1000. }
  1001. return v;
  1002. }
  1003. static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
  1004. {
  1005. struct lec_state *state = seq->private;
  1006. state->itf = 0;
  1007. state->dev = NULL;
  1008. state->locked = NULL;
  1009. state->arp_table = 0;
  1010. state->misc_table = 0;
  1011. state->node = (void *)1;
  1012. return *pos ? lec_get_idx(state, *pos) : (void *)1;
  1013. }
  1014. static void lec_seq_stop(struct seq_file *seq, void *v)
  1015. {
  1016. struct lec_state *state = seq->private;
  1017. if (state->dev) {
  1018. spin_unlock_irqrestore(&state->locked->lec_arp_lock,
  1019. state->flags);
  1020. dev_put(state->dev);
  1021. }
  1022. }
  1023. static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  1024. {
  1025. struct lec_state *state = seq->private;
  1026. v = lec_get_idx(state, 1);
  1027. *pos += !!PTR_ERR(v);
  1028. return v;
  1029. }
  1030. static int lec_seq_show(struct seq_file *seq, void *v)
  1031. {
  1032. static char lec_banner[] = "Itf MAC ATM destination"
  1033. " Status Flags "
  1034. "VPI/VCI Recv VPI/VCI\n";
  1035. if (v == (void *)1)
  1036. seq_puts(seq, lec_banner);
  1037. else {
  1038. struct lec_state *state = seq->private;
  1039. struct net_device *dev = state->dev;
  1040. struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
  1041. seq_printf(seq, "%s ", dev->name);
  1042. lec_info(seq, entry);
  1043. }
  1044. return 0;
  1045. }
  1046. static struct seq_operations lec_seq_ops = {
  1047. .start = lec_seq_start,
  1048. .next = lec_seq_next,
  1049. .stop = lec_seq_stop,
  1050. .show = lec_seq_show,
  1051. };
  1052. static int lec_seq_open(struct inode *inode, struct file *file)
  1053. {
  1054. struct lec_state *state;
  1055. struct seq_file *seq;
  1056. int rc = -EAGAIN;
  1057. state = kmalloc(sizeof(*state), GFP_KERNEL);
  1058. if (!state) {
  1059. rc = -ENOMEM;
  1060. goto out;
  1061. }
  1062. rc = seq_open(file, &lec_seq_ops);
  1063. if (rc)
  1064. goto out_kfree;
  1065. seq = file->private_data;
  1066. seq->private = state;
  1067. out:
  1068. return rc;
  1069. out_kfree:
  1070. kfree(state);
  1071. goto out;
  1072. }
  1073. static int lec_seq_release(struct inode *inode, struct file *file)
  1074. {
  1075. return seq_release_private(inode, file);
  1076. }
  1077. static const struct file_operations lec_seq_fops = {
  1078. .owner = THIS_MODULE,
  1079. .open = lec_seq_open,
  1080. .read = seq_read,
  1081. .llseek = seq_lseek,
  1082. .release = lec_seq_release,
  1083. };
  1084. #endif
  1085. static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1086. {
  1087. struct atm_vcc *vcc = ATM_SD(sock);
  1088. int err = 0;
  1089. switch (cmd) {
  1090. case ATMLEC_CTRL:
  1091. case ATMLEC_MCAST:
  1092. case ATMLEC_DATA:
  1093. if (!capable(CAP_NET_ADMIN))
  1094. return -EPERM;
  1095. break;
  1096. default:
  1097. return -ENOIOCTLCMD;
  1098. }
  1099. switch (cmd) {
  1100. case ATMLEC_CTRL:
  1101. err = lecd_attach(vcc, (int)arg);
  1102. if (err >= 0)
  1103. sock->state = SS_CONNECTED;
  1104. break;
  1105. case ATMLEC_MCAST:
  1106. err = lec_mcast_attach(vcc, (int)arg);
  1107. break;
  1108. case ATMLEC_DATA:
  1109. err = lec_vcc_attach(vcc, (void __user *)arg);
  1110. break;
  1111. }
  1112. return err;
  1113. }
  1114. static struct atm_ioctl lane_ioctl_ops = {
  1115. .owner = THIS_MODULE,
  1116. .ioctl = lane_ioctl,
  1117. };
  1118. static int __init lane_module_init(void)
  1119. {
  1120. #ifdef CONFIG_PROC_FS
  1121. struct proc_dir_entry *p;
  1122. p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
  1123. if (p)
  1124. p->proc_fops = &lec_seq_fops;
  1125. #endif
  1126. register_atm_ioctl(&lane_ioctl_ops);
  1127. printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
  1128. return 0;
  1129. }
  1130. static void __exit lane_module_cleanup(void)
  1131. {
  1132. int i;
  1133. struct lec_priv *priv;
  1134. remove_proc_entry("lec", atm_proc_root);
  1135. deregister_atm_ioctl(&lane_ioctl_ops);
  1136. for (i = 0; i < MAX_LEC_ITF; i++) {
  1137. if (dev_lec[i] != NULL) {
  1138. priv = (struct lec_priv *)dev_lec[i]->priv;
  1139. unregister_netdev(dev_lec[i]);
  1140. free_netdev(dev_lec[i]);
  1141. dev_lec[i] = NULL;
  1142. }
  1143. }
  1144. return;
  1145. }
  1146. module_init(lane_module_init);
  1147. module_exit(lane_module_cleanup);
  1148. /*
  1149. * LANE2: 3.1.3, LE_RESOLVE.request
  1150. * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
  1151. * If sizeoftlvs == NULL the default TLVs associated with with this
  1152. * lec will be used.
  1153. * If dst_mac == NULL, targetless LE_ARP will be sent
  1154. */
  1155. static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
  1156. u8 **tlvs, u32 *sizeoftlvs)
  1157. {
  1158. unsigned long flags;
  1159. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  1160. struct lec_arp_table *table;
  1161. struct sk_buff *skb;
  1162. int retval;
  1163. if (force == 0) {
  1164. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1165. table = lec_arp_find(priv, dst_mac);
  1166. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1167. if (table == NULL)
  1168. return -1;
  1169. *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
  1170. if (*tlvs == NULL)
  1171. return -1;
  1172. *sizeoftlvs = table->sizeoftlvs;
  1173. return 0;
  1174. }
  1175. if (sizeoftlvs == NULL)
  1176. retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
  1177. else {
  1178. skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
  1179. if (skb == NULL)
  1180. return -1;
  1181. skb->len = *sizeoftlvs;
  1182. memcpy(skb->data, *tlvs, *sizeoftlvs);
  1183. retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
  1184. }
  1185. return retval;
  1186. }
  1187. /*
  1188. * LANE2: 3.1.4, LE_ASSOCIATE.request
  1189. * Associate the *tlvs with the *lan_dst address.
  1190. * Will overwrite any previous association
  1191. * Returns 1 for success, 0 for failure (out of memory)
  1192. *
  1193. */
  1194. static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
  1195. u8 *tlvs, u32 sizeoftlvs)
  1196. {
  1197. int retval;
  1198. struct sk_buff *skb;
  1199. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  1200. if (compare_ether_addr(lan_dst, dev->dev_addr))
  1201. return (0); /* not our mac address */
  1202. kfree(priv->tlvs); /* NULL if there was no previous association */
  1203. priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
  1204. if (priv->tlvs == NULL)
  1205. return (0);
  1206. priv->sizeoftlvs = sizeoftlvs;
  1207. skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
  1208. if (skb == NULL)
  1209. return 0;
  1210. skb->len = sizeoftlvs;
  1211. memcpy(skb->data, tlvs, sizeoftlvs);
  1212. retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
  1213. if (retval != 0)
  1214. printk("lec.c: lane2_associate_req() failed\n");
  1215. /*
  1216. * If the previous association has changed we must
  1217. * somehow notify other LANE entities about the change
  1218. */
  1219. return (1);
  1220. }
  1221. /*
  1222. * LANE2: 3.1.5, LE_ASSOCIATE.indication
  1223. *
  1224. */
  1225. static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
  1226. u8 *tlvs, u32 sizeoftlvs)
  1227. {
  1228. #if 0
  1229. int i = 0;
  1230. #endif
  1231. struct lec_priv *priv = (struct lec_priv *)dev->priv;
  1232. #if 0 /*
  1233. * Why have the TLVs in LE_ARP entries
  1234. * since we do not use them? When you
  1235. * uncomment this code, make sure the
  1236. * TLVs get freed when entry is killed
  1237. */
  1238. struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
  1239. if (entry == NULL)
  1240. return; /* should not happen */
  1241. kfree(entry->tlvs);
  1242. entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
  1243. if (entry->tlvs == NULL)
  1244. return;
  1245. entry->sizeoftlvs = sizeoftlvs;
  1246. #endif
  1247. #if 0
  1248. printk("lec.c: lane2_associate_ind()\n");
  1249. printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
  1250. while (i < sizeoftlvs)
  1251. printk("%02x ", tlvs[i++]);
  1252. printk("\n");
  1253. #endif
  1254. /* tell MPOA about the TLVs we saw */
  1255. if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
  1256. priv->lane2_ops->associate_indicator(dev, mac_addr,
  1257. tlvs, sizeoftlvs);
  1258. }
  1259. return;
  1260. }
  1261. /*
  1262. * Here starts what used to lec_arpc.c
  1263. *
  1264. * lec_arpc.c was added here when making
  1265. * lane client modular. October 1997
  1266. */
  1267. #include <linux/types.h>
  1268. #include <linux/timer.h>
  1269. #include <asm/param.h>
  1270. #include <asm/atomic.h>
  1271. #include <linux/inetdevice.h>
  1272. #include <net/route.h>
  1273. #if 0
  1274. #define DPRINTK(format,args...)
  1275. /*
  1276. #define DPRINTK printk
  1277. */
  1278. #endif
  1279. #define DEBUG_ARP_TABLE 0
  1280. #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
  1281. static void lec_arp_check_expire(struct work_struct *work);
  1282. static void lec_arp_expire_arp(unsigned long data);
  1283. /*
  1284. * Arp table funcs
  1285. */
  1286. #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
  1287. /*
  1288. * Initialization of arp-cache
  1289. */
  1290. static void lec_arp_init(struct lec_priv *priv)
  1291. {
  1292. unsigned short i;
  1293. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1294. INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
  1295. }
  1296. INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
  1297. INIT_HLIST_HEAD(&priv->lec_no_forward);
  1298. INIT_HLIST_HEAD(&priv->mcast_fwds);
  1299. spin_lock_init(&priv->lec_arp_lock);
  1300. INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
  1301. schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
  1302. }
  1303. static void lec_arp_clear_vccs(struct lec_arp_table *entry)
  1304. {
  1305. if (entry->vcc) {
  1306. struct atm_vcc *vcc = entry->vcc;
  1307. struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
  1308. struct net_device *dev = (struct net_device *)vcc->proto_data;
  1309. vcc->pop = vpriv->old_pop;
  1310. if (vpriv->xoff)
  1311. netif_wake_queue(dev);
  1312. kfree(vpriv);
  1313. vcc->user_back = NULL;
  1314. vcc->push = entry->old_push;
  1315. vcc_release_async(vcc, -EPIPE);
  1316. entry->vcc = NULL;
  1317. }
  1318. if (entry->recv_vcc) {
  1319. entry->recv_vcc->push = entry->old_recv_push;
  1320. vcc_release_async(entry->recv_vcc, -EPIPE);
  1321. entry->recv_vcc = NULL;
  1322. }
  1323. }
  1324. /*
  1325. * Insert entry to lec_arp_table
  1326. * LANE2: Add to the end of the list to satisfy 8.1.13
  1327. */
  1328. static inline void
  1329. lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
  1330. {
  1331. struct hlist_head *tmp;
  1332. tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
  1333. hlist_add_head(&entry->next, tmp);
  1334. DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
  1335. 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
  1336. 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
  1337. 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
  1338. }
  1339. /*
  1340. * Remove entry from lec_arp_table
  1341. */
  1342. static int
  1343. lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
  1344. {
  1345. struct hlist_node *node;
  1346. struct lec_arp_table *entry;
  1347. int i, remove_vcc = 1;
  1348. if (!to_remove) {
  1349. return -1;
  1350. }
  1351. hlist_del(&to_remove->next);
  1352. del_timer(&to_remove->timer);
  1353. /* If this is the only MAC connected to this VCC, also tear down the VCC */
  1354. if (to_remove->status >= ESI_FLUSH_PENDING) {
  1355. /*
  1356. * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
  1357. */
  1358. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1359. hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
  1360. if (memcmp(to_remove->atm_addr,
  1361. entry->atm_addr, ATM_ESA_LEN) == 0) {
  1362. remove_vcc = 0;
  1363. break;
  1364. }
  1365. }
  1366. }
  1367. if (remove_vcc)
  1368. lec_arp_clear_vccs(to_remove);
  1369. }
  1370. skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
  1371. DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
  1372. 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
  1373. 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
  1374. 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
  1375. return 0;
  1376. }
  1377. #if DEBUG_ARP_TABLE
  1378. static char *get_status_string(unsigned char st)
  1379. {
  1380. switch (st) {
  1381. case ESI_UNKNOWN:
  1382. return "ESI_UNKNOWN";
  1383. case ESI_ARP_PENDING:
  1384. return "ESI_ARP_PENDING";
  1385. case ESI_VC_PENDING:
  1386. return "ESI_VC_PENDING";
  1387. case ESI_FLUSH_PENDING:
  1388. return "ESI_FLUSH_PENDING";
  1389. case ESI_FORWARD_DIRECT:
  1390. return "ESI_FORWARD_DIRECT";
  1391. default:
  1392. return "<UNKNOWN>";
  1393. }
  1394. }
  1395. static void dump_arp_table(struct lec_priv *priv)
  1396. {
  1397. struct hlist_node *node;
  1398. struct lec_arp_table *rulla;
  1399. char buf[256];
  1400. int i, j, offset;
  1401. printk("Dump %p:\n", priv);
  1402. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1403. hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
  1404. offset = 0;
  1405. offset += sprintf(buf, "%d: %p\n", i, rulla);
  1406. offset += sprintf(buf + offset, "Mac:");
  1407. for (j = 0; j < ETH_ALEN; j++) {
  1408. offset += sprintf(buf + offset,
  1409. "%2.2x ",
  1410. rulla->mac_addr[j] & 0xff);
  1411. }
  1412. offset += sprintf(buf + offset, "Atm:");
  1413. for (j = 0; j < ATM_ESA_LEN; j++) {
  1414. offset += sprintf(buf + offset,
  1415. "%2.2x ",
  1416. rulla->atm_addr[j] & 0xff);
  1417. }
  1418. offset += sprintf(buf + offset,
  1419. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1420. rulla->vcc ? rulla->vcc->vpi : 0,
  1421. rulla->vcc ? rulla->vcc->vci : 0,
  1422. rulla->recv_vcc ? rulla->recv_vcc->
  1423. vpi : 0,
  1424. rulla->recv_vcc ? rulla->recv_vcc->
  1425. vci : 0, rulla->last_used,
  1426. rulla->timestamp, rulla->no_tries);
  1427. offset +=
  1428. sprintf(buf + offset,
  1429. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1430. rulla->flags, rulla->packets_flooded,
  1431. get_status_string(rulla->status));
  1432. printk("%s\n", buf);
  1433. }
  1434. }
  1435. if (!hlist_empty(&priv->lec_no_forward))
  1436. printk("No forward\n");
  1437. hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
  1438. offset = 0;
  1439. offset += sprintf(buf + offset, "Mac:");
  1440. for (j = 0; j < ETH_ALEN; j++) {
  1441. offset += sprintf(buf + offset, "%2.2x ",
  1442. rulla->mac_addr[j] & 0xff);
  1443. }
  1444. offset += sprintf(buf + offset, "Atm:");
  1445. for (j = 0; j < ATM_ESA_LEN; j++) {
  1446. offset += sprintf(buf + offset, "%2.2x ",
  1447. rulla->atm_addr[j] & 0xff);
  1448. }
  1449. offset += sprintf(buf + offset,
  1450. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1451. rulla->vcc ? rulla->vcc->vpi : 0,
  1452. rulla->vcc ? rulla->vcc->vci : 0,
  1453. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1454. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1455. rulla->last_used,
  1456. rulla->timestamp, rulla->no_tries);
  1457. offset += sprintf(buf + offset,
  1458. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1459. rulla->flags, rulla->packets_flooded,
  1460. get_status_string(rulla->status));
  1461. printk("%s\n", buf);
  1462. }
  1463. if (!hlist_empty(&priv->lec_arp_empty_ones))
  1464. printk("Empty ones\n");
  1465. hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
  1466. offset = 0;
  1467. offset += sprintf(buf + offset, "Mac:");
  1468. for (j = 0; j < ETH_ALEN; j++) {
  1469. offset += sprintf(buf + offset, "%2.2x ",
  1470. rulla->mac_addr[j] & 0xff);
  1471. }
  1472. offset += sprintf(buf + offset, "Atm:");
  1473. for (j = 0; j < ATM_ESA_LEN; j++) {
  1474. offset += sprintf(buf + offset, "%2.2x ",
  1475. rulla->atm_addr[j] & 0xff);
  1476. }
  1477. offset += sprintf(buf + offset,
  1478. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1479. rulla->vcc ? rulla->vcc->vpi : 0,
  1480. rulla->vcc ? rulla->vcc->vci : 0,
  1481. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1482. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1483. rulla->last_used,
  1484. rulla->timestamp, rulla->no_tries);
  1485. offset += sprintf(buf + offset,
  1486. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1487. rulla->flags, rulla->packets_flooded,
  1488. get_status_string(rulla->status));
  1489. printk("%s", buf);
  1490. }
  1491. if (!hlist_empty(&priv->mcast_fwds))
  1492. printk("Multicast Forward VCCs\n");
  1493. hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
  1494. offset = 0;
  1495. offset += sprintf(buf + offset, "Mac:");
  1496. for (j = 0; j < ETH_ALEN; j++) {
  1497. offset += sprintf(buf + offset, "%2.2x ",
  1498. rulla->mac_addr[j] & 0xff);
  1499. }
  1500. offset += sprintf(buf + offset, "Atm:");
  1501. for (j = 0; j < ATM_ESA_LEN; j++) {
  1502. offset += sprintf(buf + offset, "%2.2x ",
  1503. rulla->atm_addr[j] & 0xff);
  1504. }
  1505. offset += sprintf(buf + offset,
  1506. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1507. rulla->vcc ? rulla->vcc->vpi : 0,
  1508. rulla->vcc ? rulla->vcc->vci : 0,
  1509. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1510. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1511. rulla->last_used,
  1512. rulla->timestamp, rulla->no_tries);
  1513. offset += sprintf(buf + offset,
  1514. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1515. rulla->flags, rulla->packets_flooded,
  1516. get_status_string(rulla->status));
  1517. printk("%s\n", buf);
  1518. }
  1519. }
  1520. #else
  1521. #define dump_arp_table(priv) do { } while (0)
  1522. #endif
  1523. /*
  1524. * Destruction of arp-cache
  1525. */
  1526. static void lec_arp_destroy(struct lec_priv *priv)
  1527. {
  1528. unsigned long flags;
  1529. struct hlist_node *node, *next;
  1530. struct lec_arp_table *entry;
  1531. int i;
  1532. cancel_rearming_delayed_work(&priv->lec_arp_work);
  1533. /*
  1534. * Remove all entries
  1535. */
  1536. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1537. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1538. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
  1539. lec_arp_remove(priv, entry);
  1540. lec_arp_put(entry);
  1541. }
  1542. INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
  1543. }
  1544. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
  1545. del_timer_sync(&entry->timer);
  1546. lec_arp_clear_vccs(entry);
  1547. hlist_del(&entry->next);
  1548. lec_arp_put(entry);
  1549. }
  1550. INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
  1551. hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
  1552. del_timer_sync(&entry->timer);
  1553. lec_arp_clear_vccs(entry);
  1554. hlist_del(&entry->next);
  1555. lec_arp_put(entry);
  1556. }
  1557. INIT_HLIST_HEAD(&priv->lec_no_forward);
  1558. hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
  1559. /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
  1560. lec_arp_clear_vccs(entry);
  1561. hlist_del(&entry->next);
  1562. lec_arp_put(entry);
  1563. }
  1564. INIT_HLIST_HEAD(&priv->mcast_fwds);
  1565. priv->mcast_vcc = NULL;
  1566. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1567. }
  1568. /*
  1569. * Find entry by mac_address
  1570. */
  1571. static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
  1572. unsigned char *mac_addr)
  1573. {
  1574. struct hlist_node *node;
  1575. struct hlist_head *head;
  1576. struct lec_arp_table *entry;
  1577. DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
  1578. mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
  1579. mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
  1580. head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
  1581. hlist_for_each_entry(entry, node, head, next) {
  1582. if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
  1583. return entry;
  1584. }
  1585. }
  1586. return NULL;
  1587. }
  1588. static struct lec_arp_table *make_entry(struct lec_priv *priv,
  1589. unsigned char *mac_addr)
  1590. {
  1591. struct lec_arp_table *to_return;
  1592. to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
  1593. if (!to_return) {
  1594. printk("LEC: Arp entry kmalloc failed\n");
  1595. return NULL;
  1596. }
  1597. memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
  1598. INIT_HLIST_NODE(&to_return->next);
  1599. init_timer(&to_return->timer);
  1600. to_return->timer.function = lec_arp_expire_arp;
  1601. to_return->timer.data = (unsigned long)to_return;
  1602. to_return->last_used = jiffies;
  1603. to_return->priv = priv;
  1604. skb_queue_head_init(&to_return->tx_wait);
  1605. atomic_set(&to_return->usage, 1);
  1606. return to_return;
  1607. }
  1608. /* Arp sent timer expired */
  1609. static void lec_arp_expire_arp(unsigned long data)
  1610. {
  1611. struct lec_arp_table *entry;
  1612. entry = (struct lec_arp_table *)data;
  1613. DPRINTK("lec_arp_expire_arp\n");
  1614. if (entry->status == ESI_ARP_PENDING) {
  1615. if (entry->no_tries <= entry->priv->max_retry_count) {
  1616. if (entry->is_rdesc)
  1617. send_to_lecd(entry->priv, l_rdesc_arp_xmt,
  1618. entry->mac_addr, NULL, NULL);
  1619. else
  1620. send_to_lecd(entry->priv, l_arp_xmt,
  1621. entry->mac_addr, NULL, NULL);
  1622. entry->no_tries++;
  1623. }
  1624. mod_timer(&entry->timer, jiffies + (1 * HZ));
  1625. }
  1626. }
  1627. /* Unknown/unused vcc expire, remove associated entry */
  1628. static void lec_arp_expire_vcc(unsigned long data)
  1629. {
  1630. unsigned long flags;
  1631. struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
  1632. struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
  1633. del_timer(&to_remove->timer);
  1634. DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
  1635. to_remove, priv,
  1636. to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
  1637. to_remove->vcc ? to_remove->recv_vcc->vci : 0);
  1638. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1639. hlist_del(&to_remove->next);
  1640. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1641. lec_arp_clear_vccs(to_remove);
  1642. lec_arp_put(to_remove);
  1643. }
  1644. /*
  1645. * Expire entries.
  1646. * 1. Re-set timer
  1647. * 2. For each entry, delete entries that have aged past the age limit.
  1648. * 3. For each entry, depending on the status of the entry, perform
  1649. * the following maintenance.
  1650. * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
  1651. * tick_count is above the max_unknown_frame_time, clear
  1652. * the tick_count to zero and clear the packets_flooded counter
  1653. * to zero. This supports the packet rate limit per address
  1654. * while flooding unknowns.
  1655. * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
  1656. * than or equal to the path_switching_delay, change the status
  1657. * to ESI_FORWARD_DIRECT. This causes the flush period to end
  1658. * regardless of the progress of the flush protocol.
  1659. */
  1660. static void lec_arp_check_expire(struct work_struct *work)
  1661. {
  1662. unsigned long flags;
  1663. struct lec_priv *priv =
  1664. container_of(work, struct lec_priv, lec_arp_work.work);
  1665. struct hlist_node *node, *next;
  1666. struct lec_arp_table *entry;
  1667. unsigned long now;
  1668. unsigned long time_to_check;
  1669. int i;
  1670. DPRINTK("lec_arp_check_expire %p\n", priv);
  1671. now = jiffies;
  1672. restart:
  1673. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1674. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1675. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
  1676. if ((entry->flags) & LEC_REMOTE_FLAG &&
  1677. priv->topology_change)
  1678. time_to_check = priv->forward_delay_time;
  1679. else
  1680. time_to_check = priv->aging_time;
  1681. DPRINTK("About to expire: %lx - %lx > %lx\n",
  1682. now, entry->last_used, time_to_check);
  1683. if (time_after(now, entry->last_used + time_to_check)
  1684. && !(entry->flags & LEC_PERMANENT_FLAG)
  1685. && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
  1686. /* Remove entry */
  1687. DPRINTK("LEC:Entry timed out\n");
  1688. lec_arp_remove(priv, entry);
  1689. lec_arp_put(entry);
  1690. } else {
  1691. /* Something else */
  1692. if ((entry->status == ESI_VC_PENDING ||
  1693. entry->status == ESI_ARP_PENDING)
  1694. && time_after_eq(now,
  1695. entry->timestamp +
  1696. priv->
  1697. max_unknown_frame_time)) {
  1698. entry->timestamp = jiffies;
  1699. entry->packets_flooded = 0;
  1700. if (entry->status == ESI_VC_PENDING)
  1701. send_to_lecd(priv, l_svc_setup,
  1702. entry->mac_addr,
  1703. entry->atm_addr,
  1704. NULL);
  1705. }
  1706. if (entry->status == ESI_FLUSH_PENDING
  1707. &&
  1708. time_after_eq(now, entry->timestamp +
  1709. priv->path_switching_delay)) {
  1710. struct sk_buff *skb;
  1711. struct atm_vcc *vcc = entry->vcc;
  1712. lec_arp_hold(entry);
  1713. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1714. while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
  1715. lec_send(vcc, skb, entry->priv);
  1716. entry->last_used = jiffies;
  1717. entry->status = ESI_FORWARD_DIRECT;
  1718. lec_arp_put(entry);
  1719. goto restart;
  1720. }
  1721. }
  1722. }
  1723. }
  1724. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1725. schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
  1726. }
  1727. /*
  1728. * Try to find vcc where mac_address is attached.
  1729. *
  1730. */
  1731. static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
  1732. unsigned char *mac_to_find, int is_rdesc,
  1733. struct lec_arp_table **ret_entry)
  1734. {
  1735. unsigned long flags;
  1736. struct lec_arp_table *entry;
  1737. struct atm_vcc *found;
  1738. if (mac_to_find[0] & 0x01) {
  1739. switch (priv->lane_version) {
  1740. case 1:
  1741. return priv->mcast_vcc;
  1742. break;
  1743. case 2: /* LANE2 wants arp for multicast addresses */
  1744. if (!compare_ether_addr(mac_to_find, bus_mac))
  1745. return priv->mcast_vcc;
  1746. break;
  1747. default:
  1748. break;
  1749. }
  1750. }
  1751. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1752. entry = lec_arp_find(priv, mac_to_find);
  1753. if (entry) {
  1754. if (entry->status == ESI_FORWARD_DIRECT) {
  1755. /* Connection Ok */
  1756. entry->last_used = jiffies;
  1757. lec_arp_hold(entry);
  1758. *ret_entry = entry;
  1759. found = entry->vcc;
  1760. goto out;
  1761. }
  1762. /*
  1763. * If the LE_ARP cache entry is still pending, reset count to 0
  1764. * so another LE_ARP request can be made for this frame.
  1765. */
  1766. if (entry->status == ESI_ARP_PENDING) {
  1767. entry->no_tries = 0;
  1768. }
  1769. /*
  1770. * Data direct VC not yet set up, check to see if the unknown
  1771. * frame count is greater than the limit. If the limit has
  1772. * not been reached, allow the caller to send packet to
  1773. * BUS.
  1774. */
  1775. if (entry->status != ESI_FLUSH_PENDING &&
  1776. entry->packets_flooded <
  1777. priv->maximum_unknown_frame_count) {
  1778. entry->packets_flooded++;
  1779. DPRINTK("LEC_ARP: Flooding..\n");
  1780. found = priv->mcast_vcc;
  1781. goto out;
  1782. }
  1783. /*
  1784. * We got here because entry->status == ESI_FLUSH_PENDING
  1785. * or BUS flood limit was reached for an entry which is
  1786. * in ESI_ARP_PENDING or ESI_VC_PENDING state.
  1787. */
  1788. lec_arp_hold(entry);
  1789. *ret_entry = entry;
  1790. DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status,
  1791. entry->vcc);
  1792. found = NULL;
  1793. } else {
  1794. /* No matching entry was found */
  1795. entry = make_entry(priv, mac_to_find);
  1796. DPRINTK("LEC_ARP: Making entry\n");
  1797. if (!entry) {
  1798. found = priv->mcast_vcc;
  1799. goto out;
  1800. }
  1801. lec_arp_add(priv, entry);
  1802. /* We want arp-request(s) to be sent */
  1803. entry->packets_flooded = 1;
  1804. entry->status = ESI_ARP_PENDING;
  1805. entry->no_tries = 1;
  1806. entry->last_used = entry->timestamp = jiffies;
  1807. entry->is_rdesc = is_rdesc;
  1808. if (entry->is_rdesc)
  1809. send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
  1810. NULL);
  1811. else
  1812. send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
  1813. entry->timer.expires = jiffies + (1 * HZ);
  1814. entry->timer.function = lec_arp_expire_arp;
  1815. add_timer(&entry->timer);
  1816. found = priv->mcast_vcc;
  1817. }
  1818. out:
  1819. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1820. return found;
  1821. }
  1822. static int
  1823. lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
  1824. unsigned long permanent)
  1825. {
  1826. unsigned long flags;
  1827. struct hlist_node *node, *next;
  1828. struct lec_arp_table *entry;
  1829. int i;
  1830. DPRINTK("lec_addr_delete\n");
  1831. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1832. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1833. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
  1834. if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
  1835. && (permanent ||
  1836. !(entry->flags & LEC_PERMANENT_FLAG))) {
  1837. lec_arp_remove(priv, entry);
  1838. lec_arp_put(entry);
  1839. }
  1840. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1841. return 0;
  1842. }
  1843. }
  1844. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1845. return -1;
  1846. }
  1847. /*
  1848. * Notifies: Response to arp_request (atm_addr != NULL)
  1849. */
  1850. static void
  1851. lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
  1852. unsigned char *atm_addr, unsigned long remoteflag,
  1853. unsigned int targetless_le_arp)
  1854. {
  1855. unsigned long flags;
  1856. struct hlist_node *node, *next;
  1857. struct lec_arp_table *entry, *tmp;
  1858. int i;
  1859. DPRINTK("lec:%s", (targetless_le_arp) ? "targetless " : " ");
  1860. DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
  1861. mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
  1862. mac_addr[4], mac_addr[5]);
  1863. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1864. entry = lec_arp_find(priv, mac_addr);
  1865. if (entry == NULL && targetless_le_arp)
  1866. goto out; /*
  1867. * LANE2: ignore targetless LE_ARPs for which
  1868. * we have no entry in the cache. 7.1.30
  1869. */
  1870. if (!hlist_empty(&priv->lec_arp_empty_ones)) {
  1871. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
  1872. if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
  1873. hlist_del(&entry->next);
  1874. del_timer(&entry->timer);
  1875. tmp = lec_arp_find(priv, mac_addr);
  1876. if (tmp) {
  1877. del_timer(&tmp->timer);
  1878. tmp->status = ESI_FORWARD_DIRECT;
  1879. memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
  1880. tmp->vcc = entry->vcc;
  1881. tmp->old_push = entry->old_push;
  1882. tmp->last_used = jiffies;
  1883. del_timer(&entry->timer);
  1884. lec_arp_put(entry);
  1885. entry = tmp;
  1886. } else {
  1887. entry->status = ESI_FORWARD_DIRECT;
  1888. memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
  1889. entry->last_used = jiffies;
  1890. lec_arp_add(priv, entry);
  1891. }
  1892. if (remoteflag)
  1893. entry->flags |= LEC_REMOTE_FLAG;
  1894. else
  1895. entry->flags &= ~LEC_REMOTE_FLAG;
  1896. DPRINTK("After update\n");
  1897. dump_arp_table(priv);
  1898. goto out;
  1899. }
  1900. }
  1901. }
  1902. entry = lec_arp_find(priv, mac_addr);
  1903. if (!entry) {
  1904. entry = make_entry(priv, mac_addr);
  1905. if (!entry)
  1906. goto out;
  1907. entry->status = ESI_UNKNOWN;
  1908. lec_arp_add(priv, entry);
  1909. /* Temporary, changes before end of function */
  1910. }
  1911. memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
  1912. del_timer(&entry->timer);
  1913. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1914. hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
  1915. if (entry != tmp &&
  1916. !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
  1917. /* Vcc to this host exists */
  1918. if (tmp->status > ESI_VC_PENDING) {
  1919. /*
  1920. * ESI_FLUSH_PENDING,
  1921. * ESI_FORWARD_DIRECT
  1922. */
  1923. entry->vcc = tmp->vcc;
  1924. entry->old_push = tmp->old_push;
  1925. }
  1926. entry->status = tmp->status;
  1927. break;
  1928. }
  1929. }
  1930. }
  1931. if (remoteflag)
  1932. entry->flags |= LEC_REMOTE_FLAG;
  1933. else
  1934. entry->flags &= ~LEC_REMOTE_FLAG;
  1935. if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
  1936. entry->status = ESI_VC_PENDING;
  1937. send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
  1938. }
  1939. DPRINTK("After update2\n");
  1940. dump_arp_table(priv);
  1941. out:
  1942. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1943. }
  1944. /*
  1945. * Notifies: Vcc setup ready
  1946. */
  1947. static void
  1948. lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
  1949. struct atm_vcc *vcc,
  1950. void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
  1951. {
  1952. unsigned long flags;
  1953. struct hlist_node *node;
  1954. struct lec_arp_table *entry;
  1955. int i, found_entry = 0;
  1956. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1957. if (ioc_data->receive == 2) {
  1958. /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
  1959. DPRINTK("LEC_ARP: Attaching mcast forward\n");
  1960. #if 0
  1961. entry = lec_arp_find(priv, bus_mac);
  1962. if (!entry) {
  1963. printk("LEC_ARP: Multicast entry not found!\n");
  1964. goto out;
  1965. }
  1966. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1967. entry->recv_vcc = vcc;
  1968. entry->old_recv_push = old_push;
  1969. #endif
  1970. entry = make_entry(priv, bus_mac);
  1971. if (entry == NULL)
  1972. goto out;
  1973. del_timer(&entry->timer);
  1974. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1975. entry->recv_vcc = vcc;
  1976. entry->old_recv_push = old_push;
  1977. hlist_add_head(&entry->next, &priv->mcast_fwds);
  1978. goto out;
  1979. } else if (ioc_data->receive == 1) {
  1980. /*
  1981. * Vcc which we don't want to make default vcc,
  1982. * attach it anyway.
  1983. */
  1984. DPRINTK
  1985. ("LEC_ARP:Attaching data direct, not default: "
  1986. "%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",
  1987. ioc_data->atm_addr[0], ioc_data->atm_addr[1],
  1988. ioc_data->atm_addr[2], ioc_data->atm_addr[3],
  1989. ioc_data->atm_addr[4], ioc_data->atm_addr[5],
  1990. ioc_data->atm_addr[6], ioc_data->atm_addr[7],
  1991. ioc_data->atm_addr[8], ioc_data->atm_addr[9],
  1992. ioc_data->atm_addr[10], ioc_data->atm_addr[11],
  1993. ioc_data->atm_addr[12], ioc_data->atm_addr[13],
  1994. ioc_data->atm_addr[14], ioc_data->atm_addr[15],
  1995. ioc_data->atm_addr[16], ioc_data->atm_addr[17],
  1996. ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
  1997. entry = make_entry(priv, bus_mac);
  1998. if (entry == NULL)
  1999. goto out;
  2000. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  2001. memset(entry->mac_addr, 0, ETH_ALEN);
  2002. entry->recv_vcc = vcc;
  2003. entry->old_recv_push = old_push;
  2004. entry->status = ESI_UNKNOWN;
  2005. entry->timer.expires = jiffies + priv->vcc_timeout_period;
  2006. entry->timer.function = lec_arp_expire_vcc;
  2007. hlist_add_head(&entry->next, &priv->lec_no_forward);
  2008. add_timer(&entry->timer);
  2009. dump_arp_table(priv);
  2010. goto out;
  2011. }
  2012. DPRINTK
  2013. ("LEC_ARP:Attaching data direct, default: "
  2014. "%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",
  2015. ioc_data->atm_addr[0], ioc_data->atm_addr[1],
  2016. ioc_data->atm_addr[2], ioc_data->atm_addr[3],
  2017. ioc_data->atm_addr[4], ioc_data->atm_addr[5],
  2018. ioc_data->atm_addr[6], ioc_data->atm_addr[7],
  2019. ioc_data->atm_addr[8], ioc_data->atm_addr[9],
  2020. ioc_data->atm_addr[10], ioc_data->atm_addr[11],
  2021. ioc_data->atm_addr[12], ioc_data->atm_addr[13],
  2022. ioc_data->atm_addr[14], ioc_data->atm_addr[15],
  2023. ioc_data->atm_addr[16], ioc_data->atm_addr[17],
  2024. ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
  2025. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  2026. hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
  2027. if (memcmp
  2028. (ioc_data->atm_addr, entry->atm_addr,
  2029. ATM_ESA_LEN) == 0) {
  2030. DPRINTK("LEC_ARP: Attaching data direct\n");
  2031. DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
  2032. entry->vcc ? entry->vcc->vci : 0,
  2033. entry->recv_vcc ? entry->recv_vcc->
  2034. vci : 0);
  2035. found_entry = 1;
  2036. del_timer(&entry->timer);
  2037. entry->vcc = vcc;
  2038. entry->old_push = old_push;
  2039. if (entry->status == ESI_VC_PENDING) {
  2040. if (priv->maximum_unknown_frame_count
  2041. == 0)
  2042. entry->status =
  2043. ESI_FORWARD_DIRECT;
  2044. else {
  2045. entry->timestamp = jiffies;
  2046. entry->status =
  2047. ESI_FLUSH_PENDING;
  2048. #if 0
  2049. send_to_lecd(priv, l_flush_xmt,
  2050. NULL,
  2051. entry->atm_addr,
  2052. NULL);
  2053. #endif
  2054. }
  2055. } else {
  2056. /*
  2057. * They were forming a connection
  2058. * to us, and we to them. Our
  2059. * ATM address is numerically lower
  2060. * than theirs, so we make connection
  2061. * we formed into default VCC (8.1.11).
  2062. * Connection they made gets torn
  2063. * down. This might confuse some
  2064. * clients. Can be changed if
  2065. * someone reports trouble...
  2066. */
  2067. ;
  2068. }
  2069. }
  2070. }
  2071. }
  2072. if (found_entry) {
  2073. DPRINTK("After vcc was added\n");
  2074. dump_arp_table(priv);
  2075. goto out;
  2076. }
  2077. /*
  2078. * Not found, snatch address from first data packet that arrives
  2079. * from this vcc
  2080. */
  2081. entry = make_entry(priv, bus_mac);
  2082. if (!entry)
  2083. goto out;
  2084. entry->vcc = vcc;
  2085. entry->old_push = old_push;
  2086. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  2087. memset(entry->mac_addr, 0, ETH_ALEN);
  2088. entry->status = ESI_UNKNOWN;
  2089. hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
  2090. entry->timer.expires = jiffies + priv->vcc_timeout_period;
  2091. entry->timer.function = lec_arp_expire_vcc;
  2092. add_timer(&entry->timer);
  2093. DPRINTK("After vcc was added\n");
  2094. dump_arp_table(priv);
  2095. out:
  2096. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2097. }
  2098. static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
  2099. {
  2100. unsigned long flags;
  2101. struct hlist_node *node;
  2102. struct lec_arp_table *entry;
  2103. int i;
  2104. DPRINTK("LEC:lec_flush_complete %lx\n", tran_id);
  2105. restart:
  2106. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2107. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  2108. hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
  2109. if (entry->flush_tran_id == tran_id
  2110. && entry->status == ESI_FLUSH_PENDING) {
  2111. struct sk_buff *skb;
  2112. struct atm_vcc *vcc = entry->vcc;
  2113. lec_arp_hold(entry);
  2114. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2115. while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
  2116. lec_send(vcc, skb, entry->priv);
  2117. entry->last_used = jiffies;
  2118. entry->status = ESI_FORWARD_DIRECT;
  2119. lec_arp_put(entry);
  2120. DPRINTK("LEC_ARP: Flushed\n");
  2121. goto restart;
  2122. }
  2123. }
  2124. }
  2125. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2126. dump_arp_table(priv);
  2127. }
  2128. static void
  2129. lec_set_flush_tran_id(struct lec_priv *priv,
  2130. unsigned char *atm_addr, unsigned long tran_id)
  2131. {
  2132. unsigned long flags;
  2133. struct hlist_node *node;
  2134. struct lec_arp_table *entry;
  2135. int i;
  2136. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2137. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
  2138. hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
  2139. if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
  2140. entry->flush_tran_id = tran_id;
  2141. DPRINTK("Set flush transaction id to %lx for %p\n",
  2142. tran_id, entry);
  2143. }
  2144. }
  2145. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2146. }
  2147. static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
  2148. {
  2149. unsigned long flags;
  2150. unsigned char mac_addr[] = {
  2151. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  2152. };
  2153. struct lec_arp_table *to_add;
  2154. struct lec_vcc_priv *vpriv;
  2155. int err = 0;
  2156. if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
  2157. return -ENOMEM;
  2158. vpriv->xoff = 0;
  2159. vpriv->old_pop = vcc->pop;
  2160. vcc->user_back = vpriv;
  2161. vcc->pop = lec_pop;
  2162. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2163. to_add = make_entry(priv, mac_addr);
  2164. if (!to_add) {
  2165. vcc->pop = vpriv->old_pop;
  2166. kfree(vpriv);
  2167. err = -ENOMEM;
  2168. goto out;
  2169. }
  2170. memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
  2171. to_add->status = ESI_FORWARD_DIRECT;
  2172. to_add->flags |= LEC_PERMANENT_FLAG;
  2173. to_add->vcc = vcc;
  2174. to_add->old_push = vcc->push;
  2175. vcc->push = lec_push;
  2176. priv->mcast_vcc = vcc;
  2177. lec_arp_add(priv, to_add);
  2178. out:
  2179. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2180. return err;
  2181. }
  2182. static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
  2183. {
  2184. unsigned long flags;
  2185. struct hlist_node *node, *next;
  2186. struct lec_arp_table *entry;
  2187. int i;
  2188. DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
  2189. dump_arp_table(priv);
  2190. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2191. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  2192. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
  2193. if (vcc == entry->vcc) {
  2194. lec_arp_remove(priv, entry);
  2195. lec_arp_put(entry);
  2196. if (priv->mcast_vcc == vcc) {
  2197. priv->mcast_vcc = NULL;
  2198. }
  2199. }
  2200. }
  2201. }
  2202. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
  2203. if (entry->vcc == vcc) {
  2204. lec_arp_clear_vccs(entry);
  2205. del_timer(&entry->timer);
  2206. hlist_del(&entry->next);
  2207. lec_arp_put(entry);
  2208. }
  2209. }
  2210. hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
  2211. if (entry->recv_vcc == vcc) {
  2212. lec_arp_clear_vccs(entry);
  2213. del_timer(&entry->timer);
  2214. hlist_del(&entry->next);
  2215. lec_arp_put(entry);
  2216. }
  2217. }
  2218. hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
  2219. if (entry->recv_vcc == vcc) {
  2220. lec_arp_clear_vccs(entry);
  2221. /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
  2222. hlist_del(&entry->next);
  2223. lec_arp_put(entry);
  2224. }
  2225. }
  2226. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2227. dump_arp_table(priv);
  2228. }
  2229. static void
  2230. lec_arp_check_empties(struct lec_priv *priv,
  2231. struct atm_vcc *vcc, struct sk_buff *skb)
  2232. {
  2233. unsigned long flags;
  2234. struct hlist_node *node, *next;
  2235. struct lec_arp_table *entry, *tmp;
  2236. struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
  2237. unsigned char *src;
  2238. #ifdef CONFIG_TR
  2239. struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
  2240. if (priv->is_trdev)
  2241. src = tr_hdr->h_source;
  2242. else
  2243. #endif
  2244. src = hdr->h_source;
  2245. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2246. hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
  2247. if (vcc == entry->vcc) {
  2248. del_timer(&entry->timer);
  2249. memcpy(entry->mac_addr, src, ETH_ALEN);
  2250. entry->status = ESI_FORWARD_DIRECT;
  2251. entry->last_used = jiffies;
  2252. /* We might have got an entry */
  2253. if ((tmp = lec_arp_find(priv, src))) {
  2254. lec_arp_remove(priv, tmp);
  2255. lec_arp_put(tmp);
  2256. }
  2257. hlist_del(&entry->next);
  2258. lec_arp_add(priv, entry);
  2259. goto out;
  2260. }
  2261. }
  2262. DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
  2263. out:
  2264. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2265. }
  2266. MODULE_LICENSE("GPL");