lec.c 66 KB

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