lec.c 66 KB

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