lec.c 66 KB

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