eni.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342
  1. /* drivers/atm/eni.c - Efficient Networks ENI155P device driver */
  2. /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  3. #include <linux/module.h>
  4. #include <linux/kernel.h>
  5. #include <linux/mm.h>
  6. #include <linux/pci.h>
  7. #include <linux/errno.h>
  8. #include <linux/atm.h>
  9. #include <linux/atmdev.h>
  10. #include <linux/sonet.h>
  11. #include <linux/skbuff.h>
  12. #include <linux/time.h>
  13. #include <linux/delay.h>
  14. #include <linux/uio.h>
  15. #include <linux/init.h>
  16. #include <linux/atm_eni.h>
  17. #include <linux/bitops.h>
  18. #include <linux/slab.h>
  19. #include <asm/io.h>
  20. #include <linux/atomic.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/string.h>
  23. #include <asm/byteorder.h>
  24. #include "tonga.h"
  25. #include "midway.h"
  26. #include "suni.h"
  27. #include "eni.h"
  28. #if !defined(__i386__) && !defined(__x86_64__)
  29. #ifndef ioremap_nocache
  30. #define ioremap_nocache(X,Y) ioremap(X,Y)
  31. #endif
  32. #endif
  33. /*
  34. * TODO:
  35. *
  36. * Show stoppers
  37. * none
  38. *
  39. * Minor
  40. * - OAM support
  41. * - fix bugs listed below
  42. */
  43. /*
  44. * KNOWN BUGS:
  45. *
  46. * - may run into JK-JK bug and deadlock
  47. * - should allocate UBR channel first
  48. * - buffer space allocation algorithm is stupid
  49. * (RX: should be maxSDU+maxdelay*rate
  50. * TX: should be maxSDU+min(maxSDU,maxdelay*rate) )
  51. * - doesn't support OAM cells
  52. * - eni_put_free may hang if not putting memory fragments that _complete_
  53. * 2^n block (never happens in real life, though)
  54. */
  55. #if 0
  56. #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
  57. #else
  58. #define DPRINTK(format,args...)
  59. #endif
  60. #ifndef CONFIG_ATM_ENI_TUNE_BURST
  61. #define CONFIG_ATM_ENI_BURST_TX_8W
  62. #define CONFIG_ATM_ENI_BURST_RX_4W
  63. #endif
  64. #ifndef CONFIG_ATM_ENI_DEBUG
  65. #define NULLCHECK(x)
  66. #define EVENT(s,a,b)
  67. static void event_dump(void)
  68. {
  69. }
  70. #else
  71. /*
  72. * NULL pointer checking
  73. */
  74. #define NULLCHECK(x) \
  75. if ((unsigned long) (x) < 0x30) \
  76. printk(KERN_CRIT #x "==0x%lx\n",(unsigned long) (x))
  77. /*
  78. * Very extensive activity logging. Greatly improves bug detection speed but
  79. * costs a few Mbps if enabled.
  80. */
  81. #define EV 64
  82. static const char *ev[EV];
  83. static unsigned long ev_a[EV],ev_b[EV];
  84. static int ec = 0;
  85. static void EVENT(const char *s,unsigned long a,unsigned long b)
  86. {
  87. ev[ec] = s;
  88. ev_a[ec] = a;
  89. ev_b[ec] = b;
  90. ec = (ec+1) % EV;
  91. }
  92. static void event_dump(void)
  93. {
  94. int n,i;
  95. for (n = 0; n < EV; n++) {
  96. i = (ec+n) % EV;
  97. printk(KERN_NOTICE);
  98. printk(ev[i] ? ev[i] : "(null)",ev_a[i],ev_b[i]);
  99. }
  100. }
  101. #endif /* CONFIG_ATM_ENI_DEBUG */
  102. /*
  103. * NExx must not be equal at end
  104. * EExx may be equal at end
  105. * xxPJOK verify validity of pointer jumps
  106. * xxPMOK operating on a circular buffer of "c" words
  107. */
  108. #define NEPJOK(a0,a1,b) \
  109. ((a0) < (a1) ? (b) <= (a0) || (b) > (a1) : (b) <= (a0) && (b) > (a1))
  110. #define EEPJOK(a0,a1,b) \
  111. ((a0) < (a1) ? (b) < (a0) || (b) >= (a1) : (b) < (a0) && (b) >= (a1))
  112. #define NEPMOK(a0,d,b,c) NEPJOK(a0,(a0+d) & (c-1),b)
  113. #define EEPMOK(a0,d,b,c) EEPJOK(a0,(a0+d) & (c-1),b)
  114. static int tx_complete = 0,dma_complete = 0,queued = 0,requeued = 0,
  115. backlogged = 0,rx_enqueued = 0,rx_dequeued = 0,pushed = 0,submitted = 0,
  116. putting = 0;
  117. static struct atm_dev *eni_boards = NULL;
  118. /* Read/write registers on card */
  119. #define eni_in(r) readl(eni_dev->reg+(r)*4)
  120. #define eni_out(v,r) writel((v),eni_dev->reg+(r)*4)
  121. /*-------------------------------- utilities --------------------------------*/
  122. static void dump_mem(struct eni_dev *eni_dev)
  123. {
  124. int i;
  125. for (i = 0; i < eni_dev->free_len; i++)
  126. printk(KERN_DEBUG " %d: %p %d\n",i,
  127. eni_dev->free_list[i].start,
  128. 1 << eni_dev->free_list[i].order);
  129. }
  130. static void dump(struct atm_dev *dev)
  131. {
  132. struct eni_dev *eni_dev;
  133. int i;
  134. eni_dev = ENI_DEV(dev);
  135. printk(KERN_NOTICE "Free memory\n");
  136. dump_mem(eni_dev);
  137. printk(KERN_NOTICE "TX buffers\n");
  138. for (i = 0; i < NR_CHAN; i++)
  139. if (eni_dev->tx[i].send)
  140. printk(KERN_NOTICE " TX %d @ %p: %ld\n",i,
  141. eni_dev->tx[i].send,eni_dev->tx[i].words*4);
  142. printk(KERN_NOTICE "RX buffers\n");
  143. for (i = 0; i < 1024; i++)
  144. if (eni_dev->rx_map[i] && ENI_VCC(eni_dev->rx_map[i])->rx)
  145. printk(KERN_NOTICE " RX %d @ %p: %ld\n",i,
  146. ENI_VCC(eni_dev->rx_map[i])->recv,
  147. ENI_VCC(eni_dev->rx_map[i])->words*4);
  148. printk(KERN_NOTICE "----\n");
  149. }
  150. static void eni_put_free(struct eni_dev *eni_dev, void __iomem *start,
  151. unsigned long size)
  152. {
  153. struct eni_free *list;
  154. int len,order;
  155. DPRINTK("init 0x%lx+%ld(0x%lx)\n",start,size,size);
  156. start += eni_dev->base_diff;
  157. list = eni_dev->free_list;
  158. len = eni_dev->free_len;
  159. while (size) {
  160. if (len >= eni_dev->free_list_size) {
  161. printk(KERN_CRIT "eni_put_free overflow (%p,%ld)\n",
  162. start,size);
  163. break;
  164. }
  165. for (order = 0; !(((unsigned long)start | size) & (1 << order)); order++);
  166. if (MID_MIN_BUF_SIZE > (1 << order)) {
  167. printk(KERN_CRIT "eni_put_free: order %d too small\n",
  168. order);
  169. break;
  170. }
  171. list[len].start = (void __iomem *) start;
  172. list[len].order = order;
  173. len++;
  174. start += 1 << order;
  175. size -= 1 << order;
  176. }
  177. eni_dev->free_len = len;
  178. /*dump_mem(eni_dev);*/
  179. }
  180. static void __iomem *eni_alloc_mem(struct eni_dev *eni_dev, unsigned long *size)
  181. {
  182. struct eni_free *list;
  183. void __iomem *start;
  184. int len,i,order,best_order,index;
  185. list = eni_dev->free_list;
  186. len = eni_dev->free_len;
  187. if (*size < MID_MIN_BUF_SIZE) *size = MID_MIN_BUF_SIZE;
  188. if (*size > MID_MAX_BUF_SIZE) return NULL;
  189. for (order = 0; (1 << order) < *size; order++);
  190. DPRINTK("trying: %ld->%d\n",*size,order);
  191. best_order = 65; /* we don't have more than 2^64 of anything ... */
  192. index = 0; /* silence GCC */
  193. for (i = 0; i < len; i++)
  194. if (list[i].order == order) {
  195. best_order = order;
  196. index = i;
  197. break;
  198. }
  199. else if (best_order > list[i].order && list[i].order > order) {
  200. best_order = list[i].order;
  201. index = i;
  202. }
  203. if (best_order == 65) return NULL;
  204. start = list[index].start-eni_dev->base_diff;
  205. list[index] = list[--len];
  206. eni_dev->free_len = len;
  207. *size = 1 << order;
  208. eni_put_free(eni_dev,start+*size,(1 << best_order)-*size);
  209. DPRINTK("%ld bytes (order %d) at 0x%lx\n",*size,order,start);
  210. memset_io(start,0,*size); /* never leak data */
  211. /*dump_mem(eni_dev);*/
  212. return start;
  213. }
  214. static void eni_free_mem(struct eni_dev *eni_dev, void __iomem *start,
  215. unsigned long size)
  216. {
  217. struct eni_free *list;
  218. int len,i,order;
  219. start += eni_dev->base_diff;
  220. list = eni_dev->free_list;
  221. len = eni_dev->free_len;
  222. for (order = -1; size; order++) size >>= 1;
  223. DPRINTK("eni_free_mem: %p+0x%lx (order %d)\n",start,size,order);
  224. for (i = 0; i < len; i++)
  225. if (((unsigned long) list[i].start) == ((unsigned long)start^(1 << order)) &&
  226. list[i].order == order) {
  227. DPRINTK("match[%d]: 0x%lx/0x%lx(0x%x), %d/%d\n",i,
  228. list[i].start,start,1 << order,list[i].order,order);
  229. list[i] = list[--len];
  230. start = (void __iomem *) ((unsigned long) start & ~(unsigned long) (1 << order));
  231. order++;
  232. i = -1;
  233. continue;
  234. }
  235. if (len >= eni_dev->free_list_size) {
  236. printk(KERN_ALERT "eni_free_mem overflow (%p,%d)\n",start,
  237. order);
  238. return;
  239. }
  240. list[len].start = start;
  241. list[len].order = order;
  242. eni_dev->free_len = len+1;
  243. /*dump_mem(eni_dev);*/
  244. }
  245. /*----------------------------------- RX ------------------------------------*/
  246. #define ENI_VCC_NOS ((struct atm_vcc *) 1)
  247. static void rx_ident_err(struct atm_vcc *vcc)
  248. {
  249. struct atm_dev *dev;
  250. struct eni_dev *eni_dev;
  251. struct eni_vcc *eni_vcc;
  252. dev = vcc->dev;
  253. eni_dev = ENI_DEV(dev);
  254. /* immediately halt adapter */
  255. eni_out(eni_in(MID_MC_S) &
  256. ~(MID_DMA_ENABLE | MID_TX_ENABLE | MID_RX_ENABLE),MID_MC_S);
  257. /* dump useful information */
  258. eni_vcc = ENI_VCC(vcc);
  259. printk(KERN_ALERT DEV_LABEL "(itf %d): driver error - RX ident "
  260. "mismatch\n",dev->number);
  261. printk(KERN_ALERT " VCI %d, rxing %d, words %ld\n",vcc->vci,
  262. eni_vcc->rxing,eni_vcc->words);
  263. printk(KERN_ALERT " host descr 0x%lx, rx pos 0x%lx, descr value "
  264. "0x%x\n",eni_vcc->descr,eni_vcc->rx_pos,
  265. (unsigned) readl(eni_vcc->recv+eni_vcc->descr*4));
  266. printk(KERN_ALERT " last %p, servicing %d\n",eni_vcc->last,
  267. eni_vcc->servicing);
  268. EVENT("---dump ends here---\n",0,0);
  269. printk(KERN_NOTICE "---recent events---\n");
  270. event_dump();
  271. ENI_DEV(dev)->fast = NULL; /* really stop it */
  272. ENI_DEV(dev)->slow = NULL;
  273. skb_queue_head_init(&ENI_DEV(dev)->rx_queue);
  274. }
  275. static int do_rx_dma(struct atm_vcc *vcc,struct sk_buff *skb,
  276. unsigned long skip,unsigned long size,unsigned long eff)
  277. {
  278. struct eni_dev *eni_dev;
  279. struct eni_vcc *eni_vcc;
  280. u32 dma_rd,dma_wr;
  281. u32 dma[RX_DMA_BUF*2];
  282. dma_addr_t paddr;
  283. unsigned long here;
  284. int i,j;
  285. eni_dev = ENI_DEV(vcc->dev);
  286. eni_vcc = ENI_VCC(vcc);
  287. paddr = 0; /* GCC, shut up */
  288. if (skb) {
  289. paddr = dma_map_single(&eni_dev->pci_dev->dev,skb->data,skb->len,
  290. DMA_FROM_DEVICE);
  291. if (dma_mapping_error(&eni_dev->pci_dev->dev, paddr))
  292. goto dma_map_error;
  293. ENI_PRV_PADDR(skb) = paddr;
  294. if (paddr & 3)
  295. printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %d has "
  296. "mis-aligned RX data (0x%lx)\n",vcc->dev->number,
  297. vcc->vci,(unsigned long) paddr);
  298. ENI_PRV_SIZE(skb) = size+skip;
  299. /* PDU plus descriptor */
  300. ATM_SKB(skb)->vcc = vcc;
  301. }
  302. j = 0;
  303. if ((eff && skip) || 1) { /* @@@ actually, skip is always == 1 ... */
  304. here = (eni_vcc->descr+skip) & (eni_vcc->words-1);
  305. dma[j++] = (here << MID_DMA_COUNT_SHIFT) | (vcc->vci
  306. << MID_DMA_VCI_SHIFT) | MID_DT_JK;
  307. j++;
  308. }
  309. here = (eni_vcc->descr+size+skip) & (eni_vcc->words-1);
  310. if (!eff) size += skip;
  311. else {
  312. unsigned long words;
  313. if (!size) {
  314. DPRINTK("strange things happen ...\n");
  315. EVENT("strange things happen ... (skip=%ld,eff=%ld)\n",
  316. size,eff);
  317. }
  318. words = eff;
  319. if (paddr & 15) {
  320. unsigned long init;
  321. init = 4-((paddr & 15) >> 2);
  322. if (init > words) init = words;
  323. dma[j++] = MID_DT_WORD | (init << MID_DMA_COUNT_SHIFT) |
  324. (vcc->vci << MID_DMA_VCI_SHIFT);
  325. dma[j++] = paddr;
  326. paddr += init << 2;
  327. words -= init;
  328. }
  329. #ifdef CONFIG_ATM_ENI_BURST_RX_16W /* may work with some PCI chipsets ... */
  330. if (words & ~15) {
  331. dma[j++] = MID_DT_16W | ((words >> 4) <<
  332. MID_DMA_COUNT_SHIFT) | (vcc->vci <<
  333. MID_DMA_VCI_SHIFT);
  334. dma[j++] = paddr;
  335. paddr += (words & ~15) << 2;
  336. words &= 15;
  337. }
  338. #endif
  339. #ifdef CONFIG_ATM_ENI_BURST_RX_8W /* works only with *some* PCI chipsets ... */
  340. if (words & ~7) {
  341. dma[j++] = MID_DT_8W | ((words >> 3) <<
  342. MID_DMA_COUNT_SHIFT) | (vcc->vci <<
  343. MID_DMA_VCI_SHIFT);
  344. dma[j++] = paddr;
  345. paddr += (words & ~7) << 2;
  346. words &= 7;
  347. }
  348. #endif
  349. #ifdef CONFIG_ATM_ENI_BURST_RX_4W /* recommended */
  350. if (words & ~3) {
  351. dma[j++] = MID_DT_4W | ((words >> 2) <<
  352. MID_DMA_COUNT_SHIFT) | (vcc->vci <<
  353. MID_DMA_VCI_SHIFT);
  354. dma[j++] = paddr;
  355. paddr += (words & ~3) << 2;
  356. words &= 3;
  357. }
  358. #endif
  359. #ifdef CONFIG_ATM_ENI_BURST_RX_2W /* probably useless if RX_4W, RX_8W, ... */
  360. if (words & ~1) {
  361. dma[j++] = MID_DT_2W | ((words >> 1) <<
  362. MID_DMA_COUNT_SHIFT) | (vcc->vci <<
  363. MID_DMA_VCI_SHIFT);
  364. dma[j++] = paddr;
  365. paddr += (words & ~1) << 2;
  366. words &= 1;
  367. }
  368. #endif
  369. if (words) {
  370. dma[j++] = MID_DT_WORD | (words << MID_DMA_COUNT_SHIFT)
  371. | (vcc->vci << MID_DMA_VCI_SHIFT);
  372. dma[j++] = paddr;
  373. }
  374. }
  375. if (size != eff) {
  376. dma[j++] = (here << MID_DMA_COUNT_SHIFT) |
  377. (vcc->vci << MID_DMA_VCI_SHIFT) | MID_DT_JK;
  378. j++;
  379. }
  380. if (!j || j > 2*RX_DMA_BUF) {
  381. printk(KERN_CRIT DEV_LABEL "!j or j too big!!!\n");
  382. goto trouble;
  383. }
  384. dma[j-2] |= MID_DMA_END;
  385. j = j >> 1;
  386. dma_wr = eni_in(MID_DMA_WR_RX);
  387. dma_rd = eni_in(MID_DMA_RD_RX);
  388. /*
  389. * Can I move the dma_wr pointer by 2j+1 positions without overwriting
  390. * data that hasn't been read (position of dma_rd) yet ?
  391. */
  392. if (!NEPMOK(dma_wr,j+j+1,dma_rd,NR_DMA_RX)) { /* @@@ +1 is ugly */
  393. printk(KERN_WARNING DEV_LABEL "(itf %d): RX DMA full\n",
  394. vcc->dev->number);
  395. goto trouble;
  396. }
  397. for (i = 0; i < j; i++) {
  398. writel(dma[i*2],eni_dev->rx_dma+dma_wr*8);
  399. writel(dma[i*2+1],eni_dev->rx_dma+dma_wr*8+4);
  400. dma_wr = (dma_wr+1) & (NR_DMA_RX-1);
  401. }
  402. if (skb) {
  403. ENI_PRV_POS(skb) = eni_vcc->descr+size+1;
  404. skb_queue_tail(&eni_dev->rx_queue,skb);
  405. eni_vcc->last = skb;
  406. rx_enqueued++;
  407. }
  408. eni_vcc->descr = here;
  409. eni_out(dma_wr,MID_DMA_WR_RX);
  410. return 0;
  411. trouble:
  412. if (paddr)
  413. dma_unmap_single(&eni_dev->pci_dev->dev,paddr,skb->len,
  414. DMA_FROM_DEVICE);
  415. dma_map_error:
  416. if (skb) dev_kfree_skb_irq(skb);
  417. return -1;
  418. }
  419. static void discard(struct atm_vcc *vcc,unsigned long size)
  420. {
  421. struct eni_vcc *eni_vcc;
  422. eni_vcc = ENI_VCC(vcc);
  423. EVENT("discard (size=%ld)\n",size,0);
  424. while (do_rx_dma(vcc,NULL,1,size,0)) EVENT("BUSY LOOP",0,0);
  425. /* could do a full fallback, but that might be more expensive */
  426. if (eni_vcc->rxing) ENI_PRV_POS(eni_vcc->last) += size+1;
  427. else eni_vcc->rx_pos = (eni_vcc->rx_pos+size+1) & (eni_vcc->words-1);
  428. }
  429. /*
  430. * TODO: should check whether direct copies (without DMA setup, dequeuing on
  431. * interrupt, etc.) aren't much faster for AAL0
  432. */
  433. static int rx_aal0(struct atm_vcc *vcc)
  434. {
  435. struct eni_vcc *eni_vcc;
  436. unsigned long descr;
  437. unsigned long length;
  438. struct sk_buff *skb;
  439. DPRINTK(">rx_aal0\n");
  440. eni_vcc = ENI_VCC(vcc);
  441. descr = readl(eni_vcc->recv+eni_vcc->descr*4);
  442. if ((descr & MID_RED_IDEN) != (MID_RED_RX_ID << MID_RED_SHIFT)) {
  443. rx_ident_err(vcc);
  444. return 1;
  445. }
  446. if (descr & MID_RED_T) {
  447. DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
  448. vcc->dev->number);
  449. length = 0;
  450. atomic_inc(&vcc->stats->rx_err);
  451. }
  452. else {
  453. length = ATM_CELL_SIZE-1; /* no HEC */
  454. }
  455. skb = length ? atm_alloc_charge(vcc,length,GFP_ATOMIC) : NULL;
  456. if (!skb) {
  457. discard(vcc,length >> 2);
  458. return 0;
  459. }
  460. skb_put(skb,length);
  461. skb->tstamp = eni_vcc->timestamp;
  462. DPRINTK("got len %ld\n",length);
  463. if (do_rx_dma(vcc,skb,1,length >> 2,length >> 2)) return 1;
  464. eni_vcc->rxing++;
  465. return 0;
  466. }
  467. static int rx_aal5(struct atm_vcc *vcc)
  468. {
  469. struct eni_vcc *eni_vcc;
  470. unsigned long descr;
  471. unsigned long size,eff,length;
  472. struct sk_buff *skb;
  473. EVENT("rx_aal5\n",0,0);
  474. DPRINTK(">rx_aal5\n");
  475. eni_vcc = ENI_VCC(vcc);
  476. descr = readl(eni_vcc->recv+eni_vcc->descr*4);
  477. if ((descr & MID_RED_IDEN) != (MID_RED_RX_ID << MID_RED_SHIFT)) {
  478. rx_ident_err(vcc);
  479. return 1;
  480. }
  481. if (descr & (MID_RED_T | MID_RED_CRC_ERR)) {
  482. if (descr & MID_RED_T) {
  483. EVENT("empty cell (descr=0x%lx)\n",descr,0);
  484. DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
  485. vcc->dev->number);
  486. size = 0;
  487. }
  488. else {
  489. static unsigned long silence = 0;
  490. if (time_after(jiffies, silence) || silence == 0) {
  491. printk(KERN_WARNING DEV_LABEL "(itf %d): "
  492. "discarding PDU(s) with CRC error\n",
  493. vcc->dev->number);
  494. silence = (jiffies+2*HZ)|1;
  495. }
  496. size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
  497. EVENT("CRC error (descr=0x%lx,size=%ld)\n",descr,
  498. size);
  499. }
  500. eff = length = 0;
  501. atomic_inc(&vcc->stats->rx_err);
  502. }
  503. else {
  504. size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
  505. DPRINTK("size=%ld\n",size);
  506. length = readl(eni_vcc->recv+(((eni_vcc->descr+size-1) &
  507. (eni_vcc->words-1)))*4) & 0xffff;
  508. /* -trailer(2)+header(1) */
  509. if (length && length <= (size << 2)-8 && length <=
  510. ATM_MAX_AAL5_PDU) eff = (length+3) >> 2;
  511. else { /* ^ trailer length (8) */
  512. EVENT("bad PDU (descr=0x08%lx,length=%ld)\n",descr,
  513. length);
  514. printk(KERN_ERR DEV_LABEL "(itf %d): bad AAL5 PDU "
  515. "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
  516. vcc->dev->number,vcc->vci,length,size << 2,descr);
  517. length = eff = 0;
  518. atomic_inc(&vcc->stats->rx_err);
  519. }
  520. }
  521. skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
  522. if (!skb) {
  523. discard(vcc,size);
  524. return 0;
  525. }
  526. skb_put(skb,length);
  527. DPRINTK("got len %ld\n",length);
  528. if (do_rx_dma(vcc,skb,1,size,eff)) return 1;
  529. eni_vcc->rxing++;
  530. return 0;
  531. }
  532. static inline int rx_vcc(struct atm_vcc *vcc)
  533. {
  534. void __iomem *vci_dsc;
  535. unsigned long tmp;
  536. struct eni_vcc *eni_vcc;
  537. eni_vcc = ENI_VCC(vcc);
  538. vci_dsc = ENI_DEV(vcc->dev)->vci+vcc->vci*16;
  539. EVENT("rx_vcc(1)\n",0,0);
  540. while (eni_vcc->descr != (tmp = (readl(vci_dsc+4) & MID_VCI_DESCR) >>
  541. MID_VCI_DESCR_SHIFT)) {
  542. EVENT("rx_vcc(2: host dsc=0x%lx, nic dsc=0x%lx)\n",
  543. eni_vcc->descr,tmp);
  544. DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc)->descr,
  545. (((unsigned) readl(vci_dsc+4) & MID_VCI_DESCR) >>
  546. MID_VCI_DESCR_SHIFT));
  547. if (ENI_VCC(vcc)->rx(vcc)) return 1;
  548. }
  549. /* clear IN_SERVICE flag */
  550. writel(readl(vci_dsc) & ~MID_VCI_IN_SERVICE,vci_dsc);
  551. /*
  552. * If new data has arrived between evaluating the while condition and
  553. * clearing IN_SERVICE, we wouldn't be notified until additional data
  554. * follows. So we have to loop again to be sure.
  555. */
  556. EVENT("rx_vcc(3)\n",0,0);
  557. while (ENI_VCC(vcc)->descr != (tmp = (readl(vci_dsc+4) & MID_VCI_DESCR)
  558. >> MID_VCI_DESCR_SHIFT)) {
  559. EVENT("rx_vcc(4: host dsc=0x%lx, nic dsc=0x%lx)\n",
  560. eni_vcc->descr,tmp);
  561. DPRINTK("CB_DESCR %ld REG_DESCR %d\n",ENI_VCC(vcc)->descr,
  562. (((unsigned) readl(vci_dsc+4) & MID_VCI_DESCR) >>
  563. MID_VCI_DESCR_SHIFT));
  564. if (ENI_VCC(vcc)->rx(vcc)) return 1;
  565. }
  566. return 0;
  567. }
  568. static void poll_rx(struct atm_dev *dev)
  569. {
  570. struct eni_dev *eni_dev;
  571. struct atm_vcc *curr;
  572. eni_dev = ENI_DEV(dev);
  573. while ((curr = eni_dev->fast)) {
  574. EVENT("poll_rx.fast\n",0,0);
  575. if (rx_vcc(curr)) return;
  576. eni_dev->fast = ENI_VCC(curr)->next;
  577. ENI_VCC(curr)->next = ENI_VCC_NOS;
  578. barrier();
  579. ENI_VCC(curr)->servicing--;
  580. }
  581. while ((curr = eni_dev->slow)) {
  582. EVENT("poll_rx.slow\n",0,0);
  583. if (rx_vcc(curr)) return;
  584. eni_dev->slow = ENI_VCC(curr)->next;
  585. ENI_VCC(curr)->next = ENI_VCC_NOS;
  586. barrier();
  587. ENI_VCC(curr)->servicing--;
  588. }
  589. }
  590. static void get_service(struct atm_dev *dev)
  591. {
  592. struct eni_dev *eni_dev;
  593. struct atm_vcc *vcc;
  594. unsigned long vci;
  595. DPRINTK(">get_service\n");
  596. eni_dev = ENI_DEV(dev);
  597. while (eni_in(MID_SERV_WRITE) != eni_dev->serv_read) {
  598. vci = readl(eni_dev->service+eni_dev->serv_read*4);
  599. eni_dev->serv_read = (eni_dev->serv_read+1) & (NR_SERVICE-1);
  600. vcc = eni_dev->rx_map[vci & 1023];
  601. if (!vcc) {
  602. printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %ld not "
  603. "found\n",dev->number,vci);
  604. continue; /* nasty but we try to go on anyway */
  605. /* @@@ nope, doesn't work */
  606. }
  607. EVENT("getting from service\n",0,0);
  608. if (ENI_VCC(vcc)->next != ENI_VCC_NOS) {
  609. EVENT("double service\n",0,0);
  610. DPRINTK("Grr, servicing VCC %ld twice\n",vci);
  611. continue;
  612. }
  613. ENI_VCC(vcc)->timestamp = ktime_get_real();
  614. ENI_VCC(vcc)->next = NULL;
  615. if (vcc->qos.rxtp.traffic_class == ATM_CBR) {
  616. if (eni_dev->fast)
  617. ENI_VCC(eni_dev->last_fast)->next = vcc;
  618. else eni_dev->fast = vcc;
  619. eni_dev->last_fast = vcc;
  620. }
  621. else {
  622. if (eni_dev->slow)
  623. ENI_VCC(eni_dev->last_slow)->next = vcc;
  624. else eni_dev->slow = vcc;
  625. eni_dev->last_slow = vcc;
  626. }
  627. putting++;
  628. ENI_VCC(vcc)->servicing++;
  629. }
  630. }
  631. static void dequeue_rx(struct atm_dev *dev)
  632. {
  633. struct eni_dev *eni_dev;
  634. struct eni_vcc *eni_vcc;
  635. struct atm_vcc *vcc;
  636. struct sk_buff *skb;
  637. void __iomem *vci_dsc;
  638. int first;
  639. eni_dev = ENI_DEV(dev);
  640. first = 1;
  641. while (1) {
  642. skb = skb_dequeue(&eni_dev->rx_queue);
  643. if (!skb) {
  644. if (first) {
  645. DPRINTK(DEV_LABEL "(itf %d): RX but not "
  646. "rxing\n",dev->number);
  647. EVENT("nothing to dequeue\n",0,0);
  648. }
  649. break;
  650. }
  651. EVENT("dequeued (size=%ld,pos=0x%lx)\n",ENI_PRV_SIZE(skb),
  652. ENI_PRV_POS(skb));
  653. rx_dequeued++;
  654. vcc = ATM_SKB(skb)->vcc;
  655. eni_vcc = ENI_VCC(vcc);
  656. first = 0;
  657. vci_dsc = eni_dev->vci+vcc->vci*16;
  658. if (!EEPMOK(eni_vcc->rx_pos,ENI_PRV_SIZE(skb),
  659. (readl(vci_dsc+4) & MID_VCI_READ) >> MID_VCI_READ_SHIFT,
  660. eni_vcc->words)) {
  661. EVENT("requeuing\n",0,0);
  662. skb_queue_head(&eni_dev->rx_queue,skb);
  663. break;
  664. }
  665. eni_vcc->rxing--;
  666. eni_vcc->rx_pos = ENI_PRV_POS(skb) & (eni_vcc->words-1);
  667. dma_unmap_single(&eni_dev->pci_dev->dev,ENI_PRV_PADDR(skb),skb->len,
  668. DMA_TO_DEVICE);
  669. if (!skb->len) dev_kfree_skb_irq(skb);
  670. else {
  671. EVENT("pushing (len=%ld)\n",skb->len,0);
  672. if (vcc->qos.aal == ATM_AAL0)
  673. *(unsigned long *) skb->data =
  674. ntohl(*(unsigned long *) skb->data);
  675. memset(skb->cb,0,sizeof(struct eni_skb_prv));
  676. vcc->push(vcc,skb);
  677. pushed++;
  678. }
  679. atomic_inc(&vcc->stats->rx);
  680. }
  681. wake_up(&eni_dev->rx_wait);
  682. }
  683. static int open_rx_first(struct atm_vcc *vcc)
  684. {
  685. struct eni_dev *eni_dev;
  686. struct eni_vcc *eni_vcc;
  687. unsigned long size;
  688. DPRINTK("open_rx_first\n");
  689. eni_dev = ENI_DEV(vcc->dev);
  690. eni_vcc = ENI_VCC(vcc);
  691. eni_vcc->rx = NULL;
  692. if (vcc->qos.rxtp.traffic_class == ATM_NONE) return 0;
  693. size = vcc->qos.rxtp.max_sdu*eni_dev->rx_mult/100;
  694. if (size > MID_MAX_BUF_SIZE && vcc->qos.rxtp.max_sdu <=
  695. MID_MAX_BUF_SIZE)
  696. size = MID_MAX_BUF_SIZE;
  697. eni_vcc->recv = eni_alloc_mem(eni_dev,&size);
  698. DPRINTK("rx at 0x%lx\n",eni_vcc->recv);
  699. eni_vcc->words = size >> 2;
  700. if (!eni_vcc->recv) return -ENOBUFS;
  701. eni_vcc->rx = vcc->qos.aal == ATM_AAL5 ? rx_aal5 : rx_aal0;
  702. eni_vcc->descr = 0;
  703. eni_vcc->rx_pos = 0;
  704. eni_vcc->rxing = 0;
  705. eni_vcc->servicing = 0;
  706. eni_vcc->next = ENI_VCC_NOS;
  707. return 0;
  708. }
  709. static int open_rx_second(struct atm_vcc *vcc)
  710. {
  711. void __iomem *here;
  712. struct eni_dev *eni_dev;
  713. struct eni_vcc *eni_vcc;
  714. unsigned long size;
  715. int order;
  716. DPRINTK("open_rx_second\n");
  717. eni_dev = ENI_DEV(vcc->dev);
  718. eni_vcc = ENI_VCC(vcc);
  719. if (!eni_vcc->rx) return 0;
  720. /* set up VCI descriptor */
  721. here = eni_dev->vci+vcc->vci*16;
  722. DPRINTK("loc 0x%x\n",(unsigned) (eni_vcc->recv-eni_dev->ram)/4);
  723. size = eni_vcc->words >> 8;
  724. for (order = -1; size; order++) size >>= 1;
  725. writel(0,here+4); /* descr, read = 0 */
  726. writel(0,here+8); /* write, state, count = 0 */
  727. if (eni_dev->rx_map[vcc->vci])
  728. printk(KERN_CRIT DEV_LABEL "(itf %d): BUG - VCI %d already "
  729. "in use\n",vcc->dev->number,vcc->vci);
  730. eni_dev->rx_map[vcc->vci] = vcc; /* now it counts */
  731. writel(((vcc->qos.aal != ATM_AAL5 ? MID_MODE_RAW : MID_MODE_AAL5) <<
  732. MID_VCI_MODE_SHIFT) | MID_VCI_PTI_MODE |
  733. (((eni_vcc->recv-eni_dev->ram) >> (MID_LOC_SKIP+2)) <<
  734. MID_VCI_LOCATION_SHIFT) | (order << MID_VCI_SIZE_SHIFT),here);
  735. return 0;
  736. }
  737. static void close_rx(struct atm_vcc *vcc)
  738. {
  739. DECLARE_WAITQUEUE(wait,current);
  740. void __iomem *here;
  741. struct eni_dev *eni_dev;
  742. struct eni_vcc *eni_vcc;
  743. eni_vcc = ENI_VCC(vcc);
  744. if (!eni_vcc->rx) return;
  745. eni_dev = ENI_DEV(vcc->dev);
  746. if (vcc->vpi != ATM_VPI_UNSPEC && vcc->vci != ATM_VCI_UNSPEC) {
  747. here = eni_dev->vci+vcc->vci*16;
  748. /* block receiver */
  749. writel((readl(here) & ~MID_VCI_MODE) | (MID_MODE_TRASH <<
  750. MID_VCI_MODE_SHIFT),here);
  751. /* wait for receiver to become idle */
  752. udelay(27);
  753. /* discard pending cell */
  754. writel(readl(here) & ~MID_VCI_IN_SERVICE,here);
  755. /* don't accept any new ones */
  756. eni_dev->rx_map[vcc->vci] = NULL;
  757. /* wait for RX queue to drain */
  758. DPRINTK("eni_close: waiting for RX ...\n");
  759. EVENT("RX closing\n",0,0);
  760. add_wait_queue(&eni_dev->rx_wait,&wait);
  761. set_current_state(TASK_UNINTERRUPTIBLE);
  762. barrier();
  763. for (;;) {
  764. /* transition service->rx: rxing++, servicing-- */
  765. if (!eni_vcc->servicing) {
  766. barrier();
  767. if (!eni_vcc->rxing) break;
  768. }
  769. EVENT("drain PDUs (rx %ld, serv %ld)\n",eni_vcc->rxing,
  770. eni_vcc->servicing);
  771. printk(KERN_INFO "%d+%d RX left\n",eni_vcc->servicing,
  772. eni_vcc->rxing);
  773. schedule();
  774. set_current_state(TASK_UNINTERRUPTIBLE);
  775. }
  776. for (;;) {
  777. int at_end;
  778. u32 tmp;
  779. tasklet_disable(&eni_dev->task);
  780. tmp = readl(eni_dev->vci+vcc->vci*16+4) & MID_VCI_READ;
  781. at_end = eni_vcc->rx_pos == tmp >> MID_VCI_READ_SHIFT;
  782. tasklet_enable(&eni_dev->task);
  783. if (at_end) break;
  784. EVENT("drain discard (host 0x%lx, nic 0x%lx)\n",
  785. eni_vcc->rx_pos,tmp);
  786. printk(KERN_INFO "draining RX: host 0x%lx, nic 0x%x\n",
  787. eni_vcc->rx_pos,tmp);
  788. schedule();
  789. set_current_state(TASK_UNINTERRUPTIBLE);
  790. }
  791. set_current_state(TASK_RUNNING);
  792. remove_wait_queue(&eni_dev->rx_wait,&wait);
  793. }
  794. eni_free_mem(eni_dev,eni_vcc->recv,eni_vcc->words << 2);
  795. eni_vcc->rx = NULL;
  796. }
  797. static int start_rx(struct atm_dev *dev)
  798. {
  799. struct eni_dev *eni_dev;
  800. eni_dev = ENI_DEV(dev);
  801. eni_dev->rx_map = (struct atm_vcc **) get_zeroed_page(GFP_KERNEL);
  802. if (!eni_dev->rx_map) {
  803. printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n",
  804. dev->number);
  805. free_page((unsigned long) eni_dev->free_list);
  806. return -ENOMEM;
  807. }
  808. eni_dev->rx_mult = DEFAULT_RX_MULT;
  809. eni_dev->fast = eni_dev->last_fast = NULL;
  810. eni_dev->slow = eni_dev->last_slow = NULL;
  811. init_waitqueue_head(&eni_dev->rx_wait);
  812. skb_queue_head_init(&eni_dev->rx_queue);
  813. eni_dev->serv_read = eni_in(MID_SERV_WRITE);
  814. eni_out(0,MID_DMA_WR_RX);
  815. return 0;
  816. }
  817. /*----------------------------------- TX ------------------------------------*/
  818. enum enq_res { enq_ok,enq_next,enq_jam };
  819. static inline void put_dma(int chan,u32 *dma,int *j,dma_addr_t paddr,
  820. u32 size)
  821. {
  822. u32 init,words;
  823. DPRINTK("put_dma: 0x%lx+0x%x\n",(unsigned long) paddr,size);
  824. EVENT("put_dma: 0x%lx+0x%lx\n",(unsigned long) paddr,size);
  825. #if 0 /* don't complain anymore */
  826. if (paddr & 3)
  827. printk(KERN_ERR "put_dma: unaligned addr (0x%lx)\n",paddr);
  828. if (size & 3)
  829. printk(KERN_ERR "put_dma: unaligned size (0x%lx)\n",size);
  830. #endif
  831. if (paddr & 3) {
  832. init = 4-(paddr & 3);
  833. if (init > size || size < 7) init = size;
  834. DPRINTK("put_dma: %lx DMA: %d/%d bytes\n",
  835. (unsigned long) paddr,init,size);
  836. dma[(*j)++] = MID_DT_BYTE | (init << MID_DMA_COUNT_SHIFT) |
  837. (chan << MID_DMA_CHAN_SHIFT);
  838. dma[(*j)++] = paddr;
  839. paddr += init;
  840. size -= init;
  841. }
  842. words = size >> 2;
  843. size &= 3;
  844. if (words && (paddr & 31)) {
  845. init = 8-((paddr & 31) >> 2);
  846. if (init > words) init = words;
  847. DPRINTK("put_dma: %lx DMA: %d/%d words\n",
  848. (unsigned long) paddr,init,words);
  849. dma[(*j)++] = MID_DT_WORD | (init << MID_DMA_COUNT_SHIFT) |
  850. (chan << MID_DMA_CHAN_SHIFT);
  851. dma[(*j)++] = paddr;
  852. paddr += init << 2;
  853. words -= init;
  854. }
  855. #ifdef CONFIG_ATM_ENI_BURST_TX_16W /* may work with some PCI chipsets ... */
  856. if (words & ~15) {
  857. DPRINTK("put_dma: %lx DMA: %d*16/%d words\n",
  858. (unsigned long) paddr,words >> 4,words);
  859. dma[(*j)++] = MID_DT_16W | ((words >> 4) << MID_DMA_COUNT_SHIFT)
  860. | (chan << MID_DMA_CHAN_SHIFT);
  861. dma[(*j)++] = paddr;
  862. paddr += (words & ~15) << 2;
  863. words &= 15;
  864. }
  865. #endif
  866. #ifdef CONFIG_ATM_ENI_BURST_TX_8W /* recommended */
  867. if (words & ~7) {
  868. DPRINTK("put_dma: %lx DMA: %d*8/%d words\n",
  869. (unsigned long) paddr,words >> 3,words);
  870. dma[(*j)++] = MID_DT_8W | ((words >> 3) << MID_DMA_COUNT_SHIFT)
  871. | (chan << MID_DMA_CHAN_SHIFT);
  872. dma[(*j)++] = paddr;
  873. paddr += (words & ~7) << 2;
  874. words &= 7;
  875. }
  876. #endif
  877. #ifdef CONFIG_ATM_ENI_BURST_TX_4W /* probably useless if TX_8W or TX_16W */
  878. if (words & ~3) {
  879. DPRINTK("put_dma: %lx DMA: %d*4/%d words\n",
  880. (unsigned long) paddr,words >> 2,words);
  881. dma[(*j)++] = MID_DT_4W | ((words >> 2) << MID_DMA_COUNT_SHIFT)
  882. | (chan << MID_DMA_CHAN_SHIFT);
  883. dma[(*j)++] = paddr;
  884. paddr += (words & ~3) << 2;
  885. words &= 3;
  886. }
  887. #endif
  888. #ifdef CONFIG_ATM_ENI_BURST_TX_2W /* probably useless if TX_4W, TX_8W, ... */
  889. if (words & ~1) {
  890. DPRINTK("put_dma: %lx DMA: %d*2/%d words\n",
  891. (unsigned long) paddr,words >> 1,words);
  892. dma[(*j)++] = MID_DT_2W | ((words >> 1) << MID_DMA_COUNT_SHIFT)
  893. | (chan << MID_DMA_CHAN_SHIFT);
  894. dma[(*j)++] = paddr;
  895. paddr += (words & ~1) << 2;
  896. words &= 1;
  897. }
  898. #endif
  899. if (words) {
  900. DPRINTK("put_dma: %lx DMA: %d words\n",(unsigned long) paddr,
  901. words);
  902. dma[(*j)++] = MID_DT_WORD | (words << MID_DMA_COUNT_SHIFT) |
  903. (chan << MID_DMA_CHAN_SHIFT);
  904. dma[(*j)++] = paddr;
  905. paddr += words << 2;
  906. }
  907. if (size) {
  908. DPRINTK("put_dma: %lx DMA: %d bytes\n",(unsigned long) paddr,
  909. size);
  910. dma[(*j)++] = MID_DT_BYTE | (size << MID_DMA_COUNT_SHIFT) |
  911. (chan << MID_DMA_CHAN_SHIFT);
  912. dma[(*j)++] = paddr;
  913. }
  914. }
  915. static enum enq_res do_tx(struct sk_buff *skb)
  916. {
  917. struct atm_vcc *vcc;
  918. struct eni_dev *eni_dev;
  919. struct eni_vcc *eni_vcc;
  920. struct eni_tx *tx;
  921. dma_addr_t paddr;
  922. u32 dma_rd,dma_wr;
  923. u32 size; /* in words */
  924. int aal5,dma_size,i,j;
  925. DPRINTK(">do_tx\n");
  926. NULLCHECK(skb);
  927. EVENT("do_tx: skb=0x%lx, %ld bytes\n",(unsigned long) skb,skb->len);
  928. vcc = ATM_SKB(skb)->vcc;
  929. NULLCHECK(vcc);
  930. eni_dev = ENI_DEV(vcc->dev);
  931. NULLCHECK(eni_dev);
  932. eni_vcc = ENI_VCC(vcc);
  933. tx = eni_vcc->tx;
  934. NULLCHECK(tx);
  935. #if 0 /* Enable this for testing with the "align" program */
  936. {
  937. unsigned int hack = *((char *) skb->data)-'0';
  938. if (hack < 8) {
  939. skb->data += hack;
  940. skb->len -= hack;
  941. }
  942. }
  943. #endif
  944. #if 0 /* should work now */
  945. if ((unsigned long) skb->data & 3)
  946. printk(KERN_ERR DEV_LABEL "(itf %d): VCI %d has mis-aligned "
  947. "TX data\n",vcc->dev->number,vcc->vci);
  948. #endif
  949. /*
  950. * Potential future IP speedup: make hard_header big enough to put
  951. * segmentation descriptor directly into PDU. Saves: 4 slave writes,
  952. * 1 DMA xfer & 2 DMA'ed bytes (protocol layering is for wimps :-)
  953. */
  954. aal5 = vcc->qos.aal == ATM_AAL5;
  955. /* check space in buffer */
  956. if (!aal5)
  957. size = (ATM_CELL_PAYLOAD >> 2)+TX_DESCR_SIZE;
  958. /* cell without HEC plus segmentation header (includes
  959. four-byte cell header) */
  960. else {
  961. size = skb->len+4*AAL5_TRAILER+ATM_CELL_PAYLOAD-1;
  962. /* add AAL5 trailer */
  963. size = ((size-(size % ATM_CELL_PAYLOAD)) >> 2)+TX_DESCR_SIZE;
  964. /* add segmentation header */
  965. }
  966. /*
  967. * Can I move tx_pos by size bytes without getting closer than TX_GAP
  968. * to the read pointer ? TX_GAP means to leave some space for what
  969. * the manual calls "too close".
  970. */
  971. if (!NEPMOK(tx->tx_pos,size+TX_GAP,
  972. eni_in(MID_TX_RDPTR(tx->index)),tx->words)) {
  973. DPRINTK(DEV_LABEL "(itf %d): TX full (size %d)\n",
  974. vcc->dev->number,size);
  975. return enq_next;
  976. }
  977. /* check DMA */
  978. dma_wr = eni_in(MID_DMA_WR_TX);
  979. dma_rd = eni_in(MID_DMA_RD_TX);
  980. dma_size = 3; /* JK for descriptor and final fill, plus final size
  981. mis-alignment fix */
  982. DPRINTK("iovcnt = %d\n",skb_shinfo(skb)->nr_frags);
  983. if (!skb_shinfo(skb)->nr_frags) dma_size += 5;
  984. else dma_size += 5*(skb_shinfo(skb)->nr_frags+1);
  985. if (dma_size > TX_DMA_BUF) {
  986. printk(KERN_CRIT DEV_LABEL "(itf %d): needs %d DMA entries "
  987. "(got only %d)\n",vcc->dev->number,dma_size,TX_DMA_BUF);
  988. }
  989. DPRINTK("dma_wr is %d, tx_pos is %ld\n",dma_wr,tx->tx_pos);
  990. if (dma_wr != dma_rd && ((dma_rd+NR_DMA_TX-dma_wr) & (NR_DMA_TX-1)) <
  991. dma_size) {
  992. printk(KERN_WARNING DEV_LABEL "(itf %d): TX DMA full\n",
  993. vcc->dev->number);
  994. return enq_jam;
  995. }
  996. paddr = dma_map_single(&eni_dev->pci_dev->dev,skb->data,skb->len,
  997. DMA_TO_DEVICE);
  998. ENI_PRV_PADDR(skb) = paddr;
  999. /* prepare DMA queue entries */
  1000. j = 0;
  1001. eni_dev->dma[j++] = (((tx->tx_pos+TX_DESCR_SIZE) & (tx->words-1)) <<
  1002. MID_DMA_COUNT_SHIFT) | (tx->index << MID_DMA_CHAN_SHIFT) |
  1003. MID_DT_JK;
  1004. j++;
  1005. if (!skb_shinfo(skb)->nr_frags)
  1006. if (aal5) put_dma(tx->index,eni_dev->dma,&j,paddr,skb->len);
  1007. else put_dma(tx->index,eni_dev->dma,&j,paddr+4,skb->len-4);
  1008. else {
  1009. DPRINTK("doing direct send\n"); /* @@@ well, this doesn't work anyway */
  1010. for (i = -1; i < skb_shinfo(skb)->nr_frags; i++)
  1011. if (i == -1)
  1012. put_dma(tx->index,eni_dev->dma,&j,(unsigned long)
  1013. skb->data,
  1014. skb_headlen(skb));
  1015. else
  1016. put_dma(tx->index,eni_dev->dma,&j,(unsigned long)
  1017. skb_frag_page(&skb_shinfo(skb)->frags[i]) +
  1018. skb_shinfo(skb)->frags[i].page_offset,
  1019. skb_frag_size(&skb_shinfo(skb)->frags[i]));
  1020. }
  1021. if (skb->len & 3) {
  1022. put_dma(tx->index, eni_dev->dma, &j, eni_dev->zero.dma,
  1023. 4 - (skb->len & 3));
  1024. }
  1025. /* JK for AAL5 trailer - AAL0 doesn't need it, but who cares ... */
  1026. eni_dev->dma[j++] = (((tx->tx_pos+size) & (tx->words-1)) <<
  1027. MID_DMA_COUNT_SHIFT) | (tx->index << MID_DMA_CHAN_SHIFT) |
  1028. MID_DMA_END | MID_DT_JK;
  1029. j++;
  1030. DPRINTK("DMA at end: %d\n",j);
  1031. /* store frame */
  1032. writel((MID_SEG_TX_ID << MID_SEG_ID_SHIFT) |
  1033. (aal5 ? MID_SEG_AAL5 : 0) | (tx->prescaler << MID_SEG_PR_SHIFT) |
  1034. (tx->resolution << MID_SEG_RATE_SHIFT) |
  1035. (size/(ATM_CELL_PAYLOAD/4)),tx->send+tx->tx_pos*4);
  1036. /*printk("dsc = 0x%08lx\n",(unsigned long) readl(tx->send+tx->tx_pos*4));*/
  1037. writel((vcc->vci << MID_SEG_VCI_SHIFT) |
  1038. (aal5 ? 0 : (skb->data[3] & 0xf)) |
  1039. (ATM_SKB(skb)->atm_options & ATM_ATMOPT_CLP ? MID_SEG_CLP : 0),
  1040. tx->send+((tx->tx_pos+1) & (tx->words-1))*4);
  1041. DPRINTK("size: %d, len:%d\n",size,skb->len);
  1042. if (aal5)
  1043. writel(skb->len,tx->send+
  1044. ((tx->tx_pos+size-AAL5_TRAILER) & (tx->words-1))*4);
  1045. j = j >> 1;
  1046. for (i = 0; i < j; i++) {
  1047. writel(eni_dev->dma[i*2],eni_dev->tx_dma+dma_wr*8);
  1048. writel(eni_dev->dma[i*2+1],eni_dev->tx_dma+dma_wr*8+4);
  1049. dma_wr = (dma_wr+1) & (NR_DMA_TX-1);
  1050. }
  1051. ENI_PRV_POS(skb) = tx->tx_pos;
  1052. ENI_PRV_SIZE(skb) = size;
  1053. ENI_VCC(vcc)->txing += size;
  1054. tx->tx_pos = (tx->tx_pos+size) & (tx->words-1);
  1055. DPRINTK("dma_wr set to %d, tx_pos is now %ld\n",dma_wr,tx->tx_pos);
  1056. eni_out(dma_wr,MID_DMA_WR_TX);
  1057. skb_queue_tail(&eni_dev->tx_queue,skb);
  1058. queued++;
  1059. return enq_ok;
  1060. }
  1061. static void poll_tx(struct atm_dev *dev)
  1062. {
  1063. struct eni_tx *tx;
  1064. struct sk_buff *skb;
  1065. enum enq_res res;
  1066. int i;
  1067. DPRINTK(">poll_tx\n");
  1068. for (i = NR_CHAN-1; i >= 0; i--) {
  1069. tx = &ENI_DEV(dev)->tx[i];
  1070. if (tx->send)
  1071. while ((skb = skb_dequeue(&tx->backlog))) {
  1072. res = do_tx(skb);
  1073. if (res == enq_ok) continue;
  1074. DPRINTK("re-queuing TX PDU\n");
  1075. skb_queue_head(&tx->backlog,skb);
  1076. requeued++;
  1077. if (res == enq_jam) return;
  1078. break;
  1079. }
  1080. }
  1081. }
  1082. static void dequeue_tx(struct atm_dev *dev)
  1083. {
  1084. struct eni_dev *eni_dev;
  1085. struct atm_vcc *vcc;
  1086. struct sk_buff *skb;
  1087. struct eni_tx *tx;
  1088. NULLCHECK(dev);
  1089. eni_dev = ENI_DEV(dev);
  1090. NULLCHECK(eni_dev);
  1091. while ((skb = skb_dequeue(&eni_dev->tx_queue))) {
  1092. vcc = ATM_SKB(skb)->vcc;
  1093. NULLCHECK(vcc);
  1094. tx = ENI_VCC(vcc)->tx;
  1095. NULLCHECK(ENI_VCC(vcc)->tx);
  1096. DPRINTK("dequeue_tx: next 0x%lx curr 0x%x\n",ENI_PRV_POS(skb),
  1097. (unsigned) eni_in(MID_TX_DESCRSTART(tx->index)));
  1098. if (ENI_VCC(vcc)->txing < tx->words && ENI_PRV_POS(skb) ==
  1099. eni_in(MID_TX_DESCRSTART(tx->index))) {
  1100. skb_queue_head(&eni_dev->tx_queue,skb);
  1101. break;
  1102. }
  1103. ENI_VCC(vcc)->txing -= ENI_PRV_SIZE(skb);
  1104. dma_unmap_single(&eni_dev->pci_dev->dev,ENI_PRV_PADDR(skb),skb->len,
  1105. DMA_TO_DEVICE);
  1106. if (vcc->pop) vcc->pop(vcc,skb);
  1107. else dev_kfree_skb_irq(skb);
  1108. atomic_inc(&vcc->stats->tx);
  1109. wake_up(&eni_dev->tx_wait);
  1110. dma_complete++;
  1111. }
  1112. }
  1113. static struct eni_tx *alloc_tx(struct eni_dev *eni_dev,int ubr)
  1114. {
  1115. int i;
  1116. for (i = !ubr; i < NR_CHAN; i++)
  1117. if (!eni_dev->tx[i].send) return eni_dev->tx+i;
  1118. return NULL;
  1119. }
  1120. static int comp_tx(struct eni_dev *eni_dev,int *pcr,int reserved,int *pre,
  1121. int *res,int unlimited)
  1122. {
  1123. static const int pre_div[] = { 4,16,128,2048 };
  1124. /* 2^(((x+2)^2-(x+2))/2+1) */
  1125. if (unlimited) *pre = *res = 0;
  1126. else {
  1127. if (*pcr > 0) {
  1128. int div;
  1129. for (*pre = 0; *pre < 3; (*pre)++)
  1130. if (TS_CLOCK/pre_div[*pre]/64 <= *pcr) break;
  1131. div = pre_div[*pre]**pcr;
  1132. DPRINTK("min div %d\n",div);
  1133. *res = TS_CLOCK/div-1;
  1134. }
  1135. else {
  1136. int div;
  1137. if (!*pcr) *pcr = eni_dev->tx_bw+reserved;
  1138. for (*pre = 3; *pre >= 0; (*pre)--)
  1139. if (TS_CLOCK/pre_div[*pre]/64 > -*pcr) break;
  1140. if (*pre < 3) (*pre)++; /* else fail later */
  1141. div = pre_div[*pre]*-*pcr;
  1142. DPRINTK("max div %d\n",div);
  1143. *res = DIV_ROUND_UP(TS_CLOCK, div)-1;
  1144. }
  1145. if (*res < 0) *res = 0;
  1146. if (*res > MID_SEG_MAX_RATE) *res = MID_SEG_MAX_RATE;
  1147. }
  1148. *pcr = TS_CLOCK/pre_div[*pre]/(*res+1);
  1149. DPRINTK("out pcr: %d (%d:%d)\n",*pcr,*pre,*res);
  1150. return 0;
  1151. }
  1152. static int reserve_or_set_tx(struct atm_vcc *vcc,struct atm_trafprm *txtp,
  1153. int set_rsv,int set_shp)
  1154. {
  1155. struct eni_dev *eni_dev = ENI_DEV(vcc->dev);
  1156. struct eni_vcc *eni_vcc = ENI_VCC(vcc);
  1157. struct eni_tx *tx;
  1158. unsigned long size;
  1159. void __iomem *mem;
  1160. int rate,ubr,unlimited,new_tx;
  1161. int pre,res,order;
  1162. int error;
  1163. rate = atm_pcr_goal(txtp);
  1164. ubr = txtp->traffic_class == ATM_UBR;
  1165. unlimited = ubr && (!rate || rate <= -ATM_OC3_PCR ||
  1166. rate >= ATM_OC3_PCR);
  1167. if (!unlimited) {
  1168. size = txtp->max_sdu*eni_dev->tx_mult/100;
  1169. if (size > MID_MAX_BUF_SIZE && txtp->max_sdu <=
  1170. MID_MAX_BUF_SIZE)
  1171. size = MID_MAX_BUF_SIZE;
  1172. }
  1173. else {
  1174. if (eni_dev->ubr) {
  1175. eni_vcc->tx = eni_dev->ubr;
  1176. txtp->pcr = ATM_OC3_PCR;
  1177. return 0;
  1178. }
  1179. size = UBR_BUFFER;
  1180. }
  1181. new_tx = !eni_vcc->tx;
  1182. mem = NULL; /* for gcc */
  1183. if (!new_tx) tx = eni_vcc->tx;
  1184. else {
  1185. mem = eni_alloc_mem(eni_dev,&size);
  1186. if (!mem) return -ENOBUFS;
  1187. tx = alloc_tx(eni_dev,unlimited);
  1188. if (!tx) {
  1189. eni_free_mem(eni_dev,mem,size);
  1190. return -EBUSY;
  1191. }
  1192. DPRINTK("got chan %d\n",tx->index);
  1193. tx->reserved = tx->shaping = 0;
  1194. tx->send = mem;
  1195. tx->words = size >> 2;
  1196. skb_queue_head_init(&tx->backlog);
  1197. for (order = 0; size > (1 << (order+10)); order++);
  1198. eni_out((order << MID_SIZE_SHIFT) |
  1199. ((tx->send-eni_dev->ram) >> (MID_LOC_SKIP+2)),
  1200. MID_TX_PLACE(tx->index));
  1201. tx->tx_pos = eni_in(MID_TX_DESCRSTART(tx->index)) &
  1202. MID_DESCR_START;
  1203. }
  1204. error = comp_tx(eni_dev,&rate,tx->reserved,&pre,&res,unlimited);
  1205. if (!error && txtp->min_pcr > rate) error = -EINVAL;
  1206. if (!error && txtp->max_pcr && txtp->max_pcr != ATM_MAX_PCR &&
  1207. txtp->max_pcr < rate) error = -EINVAL;
  1208. if (!error && !ubr && rate > eni_dev->tx_bw+tx->reserved)
  1209. error = -EINVAL;
  1210. if (!error && set_rsv && !set_shp && rate < tx->shaping)
  1211. error = -EINVAL;
  1212. if (!error && !set_rsv && rate > tx->reserved && !ubr)
  1213. error = -EINVAL;
  1214. if (error) {
  1215. if (new_tx) {
  1216. tx->send = NULL;
  1217. eni_free_mem(eni_dev,mem,size);
  1218. }
  1219. return error;
  1220. }
  1221. txtp->pcr = rate;
  1222. if (set_rsv && !ubr) {
  1223. eni_dev->tx_bw += tx->reserved;
  1224. tx->reserved = rate;
  1225. eni_dev->tx_bw -= rate;
  1226. }
  1227. if (set_shp || (unlimited && new_tx)) {
  1228. if (unlimited && new_tx) eni_dev->ubr = tx;
  1229. tx->prescaler = pre;
  1230. tx->resolution = res;
  1231. tx->shaping = rate;
  1232. }
  1233. if (set_shp) eni_vcc->tx = tx;
  1234. DPRINTK("rsv %d shp %d\n",tx->reserved,tx->shaping);
  1235. return 0;
  1236. }
  1237. static int open_tx_first(struct atm_vcc *vcc)
  1238. {
  1239. ENI_VCC(vcc)->tx = NULL;
  1240. if (vcc->qos.txtp.traffic_class == ATM_NONE) return 0;
  1241. ENI_VCC(vcc)->txing = 0;
  1242. return reserve_or_set_tx(vcc,&vcc->qos.txtp,1,1);
  1243. }
  1244. static int open_tx_second(struct atm_vcc *vcc)
  1245. {
  1246. return 0; /* nothing to do */
  1247. }
  1248. static void close_tx(struct atm_vcc *vcc)
  1249. {
  1250. DECLARE_WAITQUEUE(wait,current);
  1251. struct eni_dev *eni_dev;
  1252. struct eni_vcc *eni_vcc;
  1253. eni_vcc = ENI_VCC(vcc);
  1254. if (!eni_vcc->tx) return;
  1255. eni_dev = ENI_DEV(vcc->dev);
  1256. /* wait for TX queue to drain */
  1257. DPRINTK("eni_close: waiting for TX ...\n");
  1258. add_wait_queue(&eni_dev->tx_wait,&wait);
  1259. set_current_state(TASK_UNINTERRUPTIBLE);
  1260. for (;;) {
  1261. int txing;
  1262. tasklet_disable(&eni_dev->task);
  1263. txing = skb_peek(&eni_vcc->tx->backlog) || eni_vcc->txing;
  1264. tasklet_enable(&eni_dev->task);
  1265. if (!txing) break;
  1266. DPRINTK("%d TX left\n",eni_vcc->txing);
  1267. schedule();
  1268. set_current_state(TASK_UNINTERRUPTIBLE);
  1269. }
  1270. set_current_state(TASK_RUNNING);
  1271. remove_wait_queue(&eni_dev->tx_wait,&wait);
  1272. if (eni_vcc->tx != eni_dev->ubr) {
  1273. /*
  1274. * Looping a few times in here is probably far cheaper than
  1275. * keeping track of TX completions all the time, so let's poll
  1276. * a bit ...
  1277. */
  1278. while (eni_in(MID_TX_RDPTR(eni_vcc->tx->index)) !=
  1279. eni_in(MID_TX_DESCRSTART(eni_vcc->tx->index)))
  1280. schedule();
  1281. eni_free_mem(eni_dev,eni_vcc->tx->send,eni_vcc->tx->words << 2);
  1282. eni_vcc->tx->send = NULL;
  1283. eni_dev->tx_bw += eni_vcc->tx->reserved;
  1284. }
  1285. eni_vcc->tx = NULL;
  1286. }
  1287. static int start_tx(struct atm_dev *dev)
  1288. {
  1289. struct eni_dev *eni_dev;
  1290. int i;
  1291. eni_dev = ENI_DEV(dev);
  1292. eni_dev->lost = 0;
  1293. eni_dev->tx_bw = ATM_OC3_PCR;
  1294. eni_dev->tx_mult = DEFAULT_TX_MULT;
  1295. init_waitqueue_head(&eni_dev->tx_wait);
  1296. eni_dev->ubr = NULL;
  1297. skb_queue_head_init(&eni_dev->tx_queue);
  1298. eni_out(0,MID_DMA_WR_TX);
  1299. for (i = 0; i < NR_CHAN; i++) {
  1300. eni_dev->tx[i].send = NULL;
  1301. eni_dev->tx[i].index = i;
  1302. }
  1303. return 0;
  1304. }
  1305. /*--------------------------------- common ----------------------------------*/
  1306. #if 0 /* may become useful again when tuning things */
  1307. static void foo(void)
  1308. {
  1309. printk(KERN_INFO
  1310. "tx_complete=%d,dma_complete=%d,queued=%d,requeued=%d,sub=%d,\n"
  1311. "backlogged=%d,rx_enqueued=%d,rx_dequeued=%d,putting=%d,pushed=%d\n",
  1312. tx_complete,dma_complete,queued,requeued,submitted,backlogged,
  1313. rx_enqueued,rx_dequeued,putting,pushed);
  1314. if (eni_boards) printk(KERN_INFO "loss: %ld\n",ENI_DEV(eni_boards)->lost);
  1315. }
  1316. #endif
  1317. static void bug_int(struct atm_dev *dev,unsigned long reason)
  1318. {
  1319. DPRINTK(">bug_int\n");
  1320. if (reason & MID_DMA_ERR_ACK)
  1321. printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - DMA "
  1322. "error\n",dev->number);
  1323. if (reason & MID_TX_IDENT_MISM)
  1324. printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - ident "
  1325. "mismatch\n",dev->number);
  1326. if (reason & MID_TX_DMA_OVFL)
  1327. printk(KERN_CRIT DEV_LABEL "(itf %d): driver error - DMA "
  1328. "overflow\n",dev->number);
  1329. EVENT("---dump ends here---\n",0,0);
  1330. printk(KERN_NOTICE "---recent events---\n");
  1331. event_dump();
  1332. }
  1333. static irqreturn_t eni_int(int irq,void *dev_id)
  1334. {
  1335. struct atm_dev *dev;
  1336. struct eni_dev *eni_dev;
  1337. u32 reason;
  1338. DPRINTK(">eni_int\n");
  1339. dev = dev_id;
  1340. eni_dev = ENI_DEV(dev);
  1341. reason = eni_in(MID_ISA);
  1342. DPRINTK(DEV_LABEL ": int 0x%lx\n",(unsigned long) reason);
  1343. /*
  1344. * Must handle these two right now, because reading ISA doesn't clear
  1345. * them, so they re-occur and we never make it to the tasklet. Since
  1346. * they're rare, we don't mind the occasional invocation of eni_tasklet
  1347. * with eni_dev->events == 0.
  1348. */
  1349. if (reason & MID_STAT_OVFL) {
  1350. EVENT("stat overflow\n",0,0);
  1351. eni_dev->lost += eni_in(MID_STAT) & MID_OVFL_TRASH;
  1352. }
  1353. if (reason & MID_SUNI_INT) {
  1354. EVENT("SUNI int\n",0,0);
  1355. dev->phy->interrupt(dev);
  1356. #if 0
  1357. foo();
  1358. #endif
  1359. }
  1360. spin_lock(&eni_dev->lock);
  1361. eni_dev->events |= reason;
  1362. spin_unlock(&eni_dev->lock);
  1363. tasklet_schedule(&eni_dev->task);
  1364. return IRQ_HANDLED;
  1365. }
  1366. static void eni_tasklet(unsigned long data)
  1367. {
  1368. struct atm_dev *dev = (struct atm_dev *) data;
  1369. struct eni_dev *eni_dev = ENI_DEV(dev);
  1370. unsigned long flags;
  1371. u32 events;
  1372. DPRINTK("eni_tasklet (dev %p)\n",dev);
  1373. spin_lock_irqsave(&eni_dev->lock,flags);
  1374. events = xchg(&eni_dev->events,0);
  1375. spin_unlock_irqrestore(&eni_dev->lock,flags);
  1376. if (events & MID_RX_DMA_COMPLETE) {
  1377. EVENT("INT: RX DMA complete, starting dequeue_rx\n",0,0);
  1378. dequeue_rx(dev);
  1379. EVENT("dequeue_rx done, starting poll_rx\n",0,0);
  1380. poll_rx(dev);
  1381. EVENT("poll_rx done\n",0,0);
  1382. /* poll_tx ? */
  1383. }
  1384. if (events & MID_SERVICE) {
  1385. EVENT("INT: service, starting get_service\n",0,0);
  1386. get_service(dev);
  1387. EVENT("get_service done, starting poll_rx\n",0,0);
  1388. poll_rx(dev);
  1389. EVENT("poll_rx done\n",0,0);
  1390. }
  1391. if (events & MID_TX_DMA_COMPLETE) {
  1392. EVENT("INT: TX DMA COMPLETE\n",0,0);
  1393. dequeue_tx(dev);
  1394. }
  1395. if (events & MID_TX_COMPLETE) {
  1396. EVENT("INT: TX COMPLETE\n",0,0);
  1397. tx_complete++;
  1398. wake_up(&eni_dev->tx_wait);
  1399. /* poll_rx ? */
  1400. }
  1401. if (events & (MID_DMA_ERR_ACK | MID_TX_IDENT_MISM | MID_TX_DMA_OVFL)) {
  1402. EVENT("bug interrupt\n",0,0);
  1403. bug_int(dev,events);
  1404. }
  1405. poll_tx(dev);
  1406. }
  1407. /*--------------------------------- entries ---------------------------------*/
  1408. static char * const media_name[] = {
  1409. "MMF", "SMF", "MMF", "03?", /* 0- 3 */
  1410. "UTP", "05?", "06?", "07?", /* 4- 7 */
  1411. "TAXI","09?", "10?", "11?", /* 8-11 */
  1412. "12?", "13?", "14?", "15?", /* 12-15 */
  1413. "MMF", "SMF", "18?", "19?", /* 16-19 */
  1414. "UTP", "21?", "22?", "23?", /* 20-23 */
  1415. "24?", "25?", "26?", "27?", /* 24-27 */
  1416. "28?", "29?", "30?", "31?" /* 28-31 */
  1417. };
  1418. #define SET_SEPROM \
  1419. ({ if (!error && !pci_error) { \
  1420. pci_error = pci_write_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,tonga); \
  1421. udelay(10); /* 10 usecs */ \
  1422. } })
  1423. #define GET_SEPROM \
  1424. ({ if (!error && !pci_error) { \
  1425. pci_error = pci_read_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,&tonga); \
  1426. udelay(10); /* 10 usecs */ \
  1427. } })
  1428. static int get_esi_asic(struct atm_dev *dev)
  1429. {
  1430. struct eni_dev *eni_dev;
  1431. unsigned char tonga;
  1432. int error,failed,pci_error;
  1433. int address,i,j;
  1434. eni_dev = ENI_DEV(dev);
  1435. error = pci_error = 0;
  1436. tonga = SEPROM_MAGIC | SEPROM_DATA | SEPROM_CLK;
  1437. SET_SEPROM;
  1438. for (i = 0; i < ESI_LEN && !error && !pci_error; i++) {
  1439. /* start operation */
  1440. tonga |= SEPROM_DATA;
  1441. SET_SEPROM;
  1442. tonga |= SEPROM_CLK;
  1443. SET_SEPROM;
  1444. tonga &= ~SEPROM_DATA;
  1445. SET_SEPROM;
  1446. tonga &= ~SEPROM_CLK;
  1447. SET_SEPROM;
  1448. /* send address */
  1449. address = ((i+SEPROM_ESI_BASE) << 1)+1;
  1450. for (j = 7; j >= 0; j--) {
  1451. tonga = (address >> j) & 1 ? tonga | SEPROM_DATA :
  1452. tonga & ~SEPROM_DATA;
  1453. SET_SEPROM;
  1454. tonga |= SEPROM_CLK;
  1455. SET_SEPROM;
  1456. tonga &= ~SEPROM_CLK;
  1457. SET_SEPROM;
  1458. }
  1459. /* get ack */
  1460. tonga |= SEPROM_DATA;
  1461. SET_SEPROM;
  1462. tonga |= SEPROM_CLK;
  1463. SET_SEPROM;
  1464. GET_SEPROM;
  1465. failed = tonga & SEPROM_DATA;
  1466. tonga &= ~SEPROM_CLK;
  1467. SET_SEPROM;
  1468. tonga |= SEPROM_DATA;
  1469. SET_SEPROM;
  1470. if (failed) error = -EIO;
  1471. else {
  1472. dev->esi[i] = 0;
  1473. for (j = 7; j >= 0; j--) {
  1474. dev->esi[i] <<= 1;
  1475. tonga |= SEPROM_DATA;
  1476. SET_SEPROM;
  1477. tonga |= SEPROM_CLK;
  1478. SET_SEPROM;
  1479. GET_SEPROM;
  1480. if (tonga & SEPROM_DATA) dev->esi[i] |= 1;
  1481. tonga &= ~SEPROM_CLK;
  1482. SET_SEPROM;
  1483. tonga |= SEPROM_DATA;
  1484. SET_SEPROM;
  1485. }
  1486. /* get ack */
  1487. tonga |= SEPROM_DATA;
  1488. SET_SEPROM;
  1489. tonga |= SEPROM_CLK;
  1490. SET_SEPROM;
  1491. GET_SEPROM;
  1492. if (!(tonga & SEPROM_DATA)) error = -EIO;
  1493. tonga &= ~SEPROM_CLK;
  1494. SET_SEPROM;
  1495. tonga |= SEPROM_DATA;
  1496. SET_SEPROM;
  1497. }
  1498. /* stop operation */
  1499. tonga &= ~SEPROM_DATA;
  1500. SET_SEPROM;
  1501. tonga |= SEPROM_CLK;
  1502. SET_SEPROM;
  1503. tonga |= SEPROM_DATA;
  1504. SET_SEPROM;
  1505. }
  1506. if (pci_error) {
  1507. printk(KERN_ERR DEV_LABEL "(itf %d): error reading ESI "
  1508. "(0x%02x)\n",dev->number,pci_error);
  1509. error = -EIO;
  1510. }
  1511. return error;
  1512. }
  1513. #undef SET_SEPROM
  1514. #undef GET_SEPROM
  1515. static int get_esi_fpga(struct atm_dev *dev, void __iomem *base)
  1516. {
  1517. void __iomem *mac_base;
  1518. int i;
  1519. mac_base = base+EPROM_SIZE-sizeof(struct midway_eprom);
  1520. for (i = 0; i < ESI_LEN; i++) dev->esi[i] = readb(mac_base+(i^3));
  1521. return 0;
  1522. }
  1523. static int eni_do_init(struct atm_dev *dev)
  1524. {
  1525. struct midway_eprom __iomem *eprom;
  1526. struct eni_dev *eni_dev;
  1527. struct pci_dev *pci_dev;
  1528. unsigned long real_base;
  1529. void __iomem *base;
  1530. int error,i,last;
  1531. DPRINTK(">eni_init\n");
  1532. dev->ci_range.vpi_bits = 0;
  1533. dev->ci_range.vci_bits = NR_VCI_LD;
  1534. dev->link_rate = ATM_OC3_PCR;
  1535. eni_dev = ENI_DEV(dev);
  1536. pci_dev = eni_dev->pci_dev;
  1537. real_base = pci_resource_start(pci_dev, 0);
  1538. eni_dev->irq = pci_dev->irq;
  1539. if ((error = pci_write_config_word(pci_dev,PCI_COMMAND,
  1540. PCI_COMMAND_MEMORY |
  1541. (eni_dev->asic ? PCI_COMMAND_PARITY | PCI_COMMAND_SERR : 0)))) {
  1542. printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory "
  1543. "(0x%02x)\n",dev->number,error);
  1544. return -EIO;
  1545. }
  1546. printk(KERN_NOTICE DEV_LABEL "(itf %d): rev.%d,base=0x%lx,irq=%d,",
  1547. dev->number,pci_dev->revision,real_base,eni_dev->irq);
  1548. if (!(base = ioremap_nocache(real_base,MAP_MAX_SIZE))) {
  1549. printk("\n");
  1550. printk(KERN_ERR DEV_LABEL "(itf %d): can't set up page "
  1551. "mapping\n",dev->number);
  1552. return -ENOMEM;
  1553. }
  1554. eni_dev->ioaddr = base;
  1555. eni_dev->base_diff = real_base - (unsigned long) base;
  1556. /* id may not be present in ASIC Tonga boards - check this @@@ */
  1557. if (!eni_dev->asic) {
  1558. eprom = (base+EPROM_SIZE-sizeof(struct midway_eprom));
  1559. if (readl(&eprom->magic) != ENI155_MAGIC) {
  1560. printk("\n");
  1561. printk(KERN_ERR DEV_LABEL
  1562. "(itf %d): bad magic - expected 0x%x, got 0x%x\n",
  1563. dev->number, ENI155_MAGIC,
  1564. (unsigned)readl(&eprom->magic));
  1565. error = -EINVAL;
  1566. goto unmap;
  1567. }
  1568. }
  1569. eni_dev->phy = base+PHY_BASE;
  1570. eni_dev->reg = base+REG_BASE;
  1571. eni_dev->ram = base+RAM_BASE;
  1572. last = MAP_MAX_SIZE-RAM_BASE;
  1573. for (i = last-RAM_INCREMENT; i >= 0; i -= RAM_INCREMENT) {
  1574. writel(0x55555555,eni_dev->ram+i);
  1575. if (readl(eni_dev->ram+i) != 0x55555555) last = i;
  1576. else {
  1577. writel(0xAAAAAAAA,eni_dev->ram+i);
  1578. if (readl(eni_dev->ram+i) != 0xAAAAAAAA) last = i;
  1579. else writel(i,eni_dev->ram+i);
  1580. }
  1581. }
  1582. for (i = 0; i < last; i += RAM_INCREMENT)
  1583. if (readl(eni_dev->ram+i) != i) break;
  1584. eni_dev->mem = i;
  1585. memset_io(eni_dev->ram,0,eni_dev->mem);
  1586. /* TODO: should shrink allocation now */
  1587. printk("mem=%dkB (",eni_dev->mem >> 10);
  1588. /* TODO: check for non-SUNI, check for TAXI ? */
  1589. if (!(eni_in(MID_RES_ID_MCON) & 0x200) != !eni_dev->asic) {
  1590. printk(")\n");
  1591. printk(KERN_ERR DEV_LABEL "(itf %d): ERROR - wrong id 0x%x\n",
  1592. dev->number,(unsigned) eni_in(MID_RES_ID_MCON));
  1593. error = -EINVAL;
  1594. goto unmap;
  1595. }
  1596. error = eni_dev->asic ? get_esi_asic(dev) : get_esi_fpga(dev,base);
  1597. if (error)
  1598. goto unmap;
  1599. for (i = 0; i < ESI_LEN; i++)
  1600. printk("%s%02X",i ? "-" : "",dev->esi[i]);
  1601. printk(")\n");
  1602. printk(KERN_NOTICE DEV_LABEL "(itf %d): %s,%s\n",dev->number,
  1603. eni_in(MID_RES_ID_MCON) & 0x200 ? "ASIC" : "FPGA",
  1604. media_name[eni_in(MID_RES_ID_MCON) & DAUGTHER_ID]);
  1605. error = suni_init(dev);
  1606. if (error)
  1607. goto unmap;
  1608. out:
  1609. return error;
  1610. unmap:
  1611. iounmap(base);
  1612. goto out;
  1613. }
  1614. static void eni_do_release(struct atm_dev *dev)
  1615. {
  1616. struct eni_dev *ed = ENI_DEV(dev);
  1617. dev->phy->stop(dev);
  1618. dev->phy = NULL;
  1619. iounmap(ed->ioaddr);
  1620. }
  1621. static int eni_start(struct atm_dev *dev)
  1622. {
  1623. struct eni_dev *eni_dev;
  1624. void __iomem *buf;
  1625. unsigned long buffer_mem;
  1626. int error;
  1627. DPRINTK(">eni_start\n");
  1628. eni_dev = ENI_DEV(dev);
  1629. if (request_irq(eni_dev->irq,&eni_int,IRQF_SHARED,DEV_LABEL,dev)) {
  1630. printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n",
  1631. dev->number,eni_dev->irq);
  1632. error = -EAGAIN;
  1633. goto out;
  1634. }
  1635. pci_set_master(eni_dev->pci_dev);
  1636. if ((error = pci_write_config_word(eni_dev->pci_dev,PCI_COMMAND,
  1637. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
  1638. (eni_dev->asic ? PCI_COMMAND_PARITY | PCI_COMMAND_SERR : 0)))) {
  1639. printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory+"
  1640. "master (0x%02x)\n",dev->number,error);
  1641. goto free_irq;
  1642. }
  1643. if ((error = pci_write_config_byte(eni_dev->pci_dev,PCI_TONGA_CTRL,
  1644. END_SWAP_DMA))) {
  1645. printk(KERN_ERR DEV_LABEL "(itf %d): can't set endian swap "
  1646. "(0x%02x)\n",dev->number,error);
  1647. goto free_irq;
  1648. }
  1649. /* determine addresses of internal tables */
  1650. eni_dev->vci = eni_dev->ram;
  1651. eni_dev->rx_dma = eni_dev->ram+NR_VCI*16;
  1652. eni_dev->tx_dma = eni_dev->rx_dma+NR_DMA_RX*8;
  1653. eni_dev->service = eni_dev->tx_dma+NR_DMA_TX*8;
  1654. buf = eni_dev->service+NR_SERVICE*4;
  1655. DPRINTK("vci 0x%lx,rx 0x%lx, tx 0x%lx,srv 0x%lx,buf 0x%lx\n",
  1656. eni_dev->vci,eni_dev->rx_dma,eni_dev->tx_dma,
  1657. eni_dev->service,buf);
  1658. spin_lock_init(&eni_dev->lock);
  1659. tasklet_init(&eni_dev->task,eni_tasklet,(unsigned long) dev);
  1660. eni_dev->events = 0;
  1661. /* initialize memory management */
  1662. buffer_mem = eni_dev->mem - (buf - eni_dev->ram);
  1663. eni_dev->free_list_size = buffer_mem/MID_MIN_BUF_SIZE/2;
  1664. eni_dev->free_list = kmalloc_array(eni_dev->free_list_size + 1,
  1665. sizeof(*eni_dev->free_list),
  1666. GFP_KERNEL);
  1667. if (!eni_dev->free_list) {
  1668. printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n",
  1669. dev->number);
  1670. error = -ENOMEM;
  1671. goto free_irq;
  1672. }
  1673. eni_dev->free_len = 0;
  1674. eni_put_free(eni_dev,buf,buffer_mem);
  1675. memset_io(eni_dev->vci,0,16*NR_VCI); /* clear VCI table */
  1676. /*
  1677. * byte_addr free (k)
  1678. * 0x00000000 512 VCI table
  1679. * 0x00004000 496 RX DMA
  1680. * 0x00005000 492 TX DMA
  1681. * 0x00006000 488 service list
  1682. * 0x00007000 484 buffers
  1683. * 0x00080000 0 end (512kB)
  1684. */
  1685. eni_out(0xffffffff,MID_IE);
  1686. error = start_tx(dev);
  1687. if (error) goto free_list;
  1688. error = start_rx(dev);
  1689. if (error) goto free_list;
  1690. error = dev->phy->start(dev);
  1691. if (error) goto free_list;
  1692. eni_out(eni_in(MID_MC_S) | (1 << MID_INT_SEL_SHIFT) |
  1693. MID_TX_LOCK_MODE | MID_DMA_ENABLE | MID_TX_ENABLE | MID_RX_ENABLE,
  1694. MID_MC_S);
  1695. /* Tonga uses SBus INTReq1 */
  1696. (void) eni_in(MID_ISA); /* clear Midway interrupts */
  1697. return 0;
  1698. free_list:
  1699. kfree(eni_dev->free_list);
  1700. free_irq:
  1701. free_irq(eni_dev->irq, dev);
  1702. out:
  1703. return error;
  1704. }
  1705. static void eni_close(struct atm_vcc *vcc)
  1706. {
  1707. DPRINTK(">eni_close\n");
  1708. if (!ENI_VCC(vcc)) return;
  1709. clear_bit(ATM_VF_READY,&vcc->flags);
  1710. close_rx(vcc);
  1711. close_tx(vcc);
  1712. DPRINTK("eni_close: done waiting\n");
  1713. /* deallocate memory */
  1714. kfree(ENI_VCC(vcc));
  1715. vcc->dev_data = NULL;
  1716. clear_bit(ATM_VF_ADDR,&vcc->flags);
  1717. /*foo();*/
  1718. }
  1719. static int eni_open(struct atm_vcc *vcc)
  1720. {
  1721. struct eni_vcc *eni_vcc;
  1722. int error;
  1723. short vpi = vcc->vpi;
  1724. int vci = vcc->vci;
  1725. DPRINTK(">eni_open\n");
  1726. EVENT("eni_open\n",0,0);
  1727. if (!test_bit(ATM_VF_PARTIAL,&vcc->flags))
  1728. vcc->dev_data = NULL;
  1729. if (vci != ATM_VPI_UNSPEC && vpi != ATM_VCI_UNSPEC)
  1730. set_bit(ATM_VF_ADDR,&vcc->flags);
  1731. if (vcc->qos.aal != ATM_AAL0 && vcc->qos.aal != ATM_AAL5)
  1732. return -EINVAL;
  1733. DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n",vcc->dev->number,vcc->vpi,
  1734. vcc->vci);
  1735. if (!test_bit(ATM_VF_PARTIAL,&vcc->flags)) {
  1736. eni_vcc = kmalloc(sizeof(struct eni_vcc),GFP_KERNEL);
  1737. if (!eni_vcc) return -ENOMEM;
  1738. vcc->dev_data = eni_vcc;
  1739. eni_vcc->tx = NULL; /* for eni_close after open_rx */
  1740. if ((error = open_rx_first(vcc))) {
  1741. eni_close(vcc);
  1742. return error;
  1743. }
  1744. if ((error = open_tx_first(vcc))) {
  1745. eni_close(vcc);
  1746. return error;
  1747. }
  1748. }
  1749. if (vci == ATM_VPI_UNSPEC || vpi == ATM_VCI_UNSPEC) return 0;
  1750. if ((error = open_rx_second(vcc))) {
  1751. eni_close(vcc);
  1752. return error;
  1753. }
  1754. if ((error = open_tx_second(vcc))) {
  1755. eni_close(vcc);
  1756. return error;
  1757. }
  1758. set_bit(ATM_VF_READY,&vcc->flags);
  1759. /* should power down SUNI while !ref_count @@@ */
  1760. return 0;
  1761. }
  1762. static int eni_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flgs)
  1763. {
  1764. struct eni_dev *eni_dev = ENI_DEV(vcc->dev);
  1765. struct eni_tx *tx = ENI_VCC(vcc)->tx;
  1766. struct sk_buff *skb;
  1767. int error,rate,rsv,shp;
  1768. if (qos->txtp.traffic_class == ATM_NONE) return 0;
  1769. if (tx == eni_dev->ubr) return -EBADFD;
  1770. rate = atm_pcr_goal(&qos->txtp);
  1771. if (rate < 0) rate = -rate;
  1772. rsv = shp = 0;
  1773. if ((flgs & ATM_MF_DEC_RSV) && rate && rate < tx->reserved) rsv = 1;
  1774. if ((flgs & ATM_MF_INC_RSV) && (!rate || rate > tx->reserved)) rsv = 1;
  1775. if ((flgs & ATM_MF_DEC_SHP) && rate && rate < tx->shaping) shp = 1;
  1776. if ((flgs & ATM_MF_INC_SHP) && (!rate || rate > tx->shaping)) shp = 1;
  1777. if (!rsv && !shp) return 0;
  1778. error = reserve_or_set_tx(vcc,&qos->txtp,rsv,shp);
  1779. if (error) return error;
  1780. if (shp && !(flgs & ATM_MF_IMMED)) return 0;
  1781. /*
  1782. * Walk through the send buffer and patch the rate information in all
  1783. * segmentation buffer descriptors of this VCC.
  1784. */
  1785. tasklet_disable(&eni_dev->task);
  1786. skb_queue_walk(&eni_dev->tx_queue, skb) {
  1787. void __iomem *dsc;
  1788. if (ATM_SKB(skb)->vcc != vcc) continue;
  1789. dsc = tx->send+ENI_PRV_POS(skb)*4;
  1790. writel((readl(dsc) & ~(MID_SEG_RATE | MID_SEG_PR)) |
  1791. (tx->prescaler << MID_SEG_PR_SHIFT) |
  1792. (tx->resolution << MID_SEG_RATE_SHIFT), dsc);
  1793. }
  1794. tasklet_enable(&eni_dev->task);
  1795. return 0;
  1796. }
  1797. static int eni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
  1798. {
  1799. struct eni_dev *eni_dev = ENI_DEV(dev);
  1800. if (cmd == ENI_MEMDUMP) {
  1801. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  1802. printk(KERN_WARNING "Please use /proc/atm/" DEV_LABEL ":%d "
  1803. "instead of obsolete ioctl ENI_MEMDUMP\n",dev->number);
  1804. dump(dev);
  1805. return 0;
  1806. }
  1807. if (cmd == ENI_SETMULT) {
  1808. struct eni_multipliers mult;
  1809. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  1810. if (copy_from_user(&mult, arg,
  1811. sizeof(struct eni_multipliers)))
  1812. return -EFAULT;
  1813. if ((mult.tx && mult.tx <= 100) || (mult.rx &&mult.rx <= 100) ||
  1814. mult.tx > 65536 || mult.rx > 65536)
  1815. return -EINVAL;
  1816. if (mult.tx) eni_dev->tx_mult = mult.tx;
  1817. if (mult.rx) eni_dev->rx_mult = mult.rx;
  1818. return 0;
  1819. }
  1820. if (cmd == ATM_SETCIRANGE) {
  1821. struct atm_cirange ci;
  1822. if (copy_from_user(&ci, arg,sizeof(struct atm_cirange)))
  1823. return -EFAULT;
  1824. if ((ci.vpi_bits == 0 || ci.vpi_bits == ATM_CI_MAX) &&
  1825. (ci.vci_bits == NR_VCI_LD || ci.vpi_bits == ATM_CI_MAX))
  1826. return 0;
  1827. return -EINVAL;
  1828. }
  1829. if (!dev->phy->ioctl) return -ENOIOCTLCMD;
  1830. return dev->phy->ioctl(dev,cmd,arg);
  1831. }
  1832. static int eni_getsockopt(struct atm_vcc *vcc,int level,int optname,
  1833. void __user *optval,int optlen)
  1834. {
  1835. return -EINVAL;
  1836. }
  1837. static int eni_setsockopt(struct atm_vcc *vcc,int level,int optname,
  1838. void __user *optval,unsigned int optlen)
  1839. {
  1840. return -EINVAL;
  1841. }
  1842. static int eni_send(struct atm_vcc *vcc,struct sk_buff *skb)
  1843. {
  1844. enum enq_res res;
  1845. DPRINTK(">eni_send\n");
  1846. if (!ENI_VCC(vcc)->tx) {
  1847. if (vcc->pop) vcc->pop(vcc,skb);
  1848. else dev_kfree_skb(skb);
  1849. return -EINVAL;
  1850. }
  1851. if (!skb) {
  1852. printk(KERN_CRIT "!skb in eni_send ?\n");
  1853. if (vcc->pop) vcc->pop(vcc,skb);
  1854. return -EINVAL;
  1855. }
  1856. if (vcc->qos.aal == ATM_AAL0) {
  1857. if (skb->len != ATM_CELL_SIZE-1) {
  1858. if (vcc->pop) vcc->pop(vcc,skb);
  1859. else dev_kfree_skb(skb);
  1860. return -EINVAL;
  1861. }
  1862. *(u32 *) skb->data = htonl(*(u32 *) skb->data);
  1863. }
  1864. submitted++;
  1865. ATM_SKB(skb)->vcc = vcc;
  1866. tasklet_disable(&ENI_DEV(vcc->dev)->task);
  1867. res = do_tx(skb);
  1868. tasklet_enable(&ENI_DEV(vcc->dev)->task);
  1869. if (res == enq_ok) return 0;
  1870. skb_queue_tail(&ENI_VCC(vcc)->tx->backlog,skb);
  1871. backlogged++;
  1872. tasklet_schedule(&ENI_DEV(vcc->dev)->task);
  1873. return 0;
  1874. }
  1875. static void eni_phy_put(struct atm_dev *dev,unsigned char value,
  1876. unsigned long addr)
  1877. {
  1878. writel(value,ENI_DEV(dev)->phy+addr*4);
  1879. }
  1880. static unsigned char eni_phy_get(struct atm_dev *dev,unsigned long addr)
  1881. {
  1882. return readl(ENI_DEV(dev)->phy+addr*4);
  1883. }
  1884. static int eni_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
  1885. {
  1886. struct sock *s;
  1887. static const char *signal[] = { "LOST","unknown","okay" };
  1888. struct eni_dev *eni_dev = ENI_DEV(dev);
  1889. struct atm_vcc *vcc;
  1890. int left,i;
  1891. left = *pos;
  1892. if (!left)
  1893. return sprintf(page,DEV_LABEL "(itf %d) signal %s, %dkB, "
  1894. "%d cps remaining\n",dev->number,signal[(int) dev->signal],
  1895. eni_dev->mem >> 10,eni_dev->tx_bw);
  1896. if (!--left)
  1897. return sprintf(page,"%4sBursts: TX"
  1898. #if !defined(CONFIG_ATM_ENI_BURST_TX_16W) && \
  1899. !defined(CONFIG_ATM_ENI_BURST_TX_8W) && \
  1900. !defined(CONFIG_ATM_ENI_BURST_TX_4W) && \
  1901. !defined(CONFIG_ATM_ENI_BURST_TX_2W)
  1902. " none"
  1903. #endif
  1904. #ifdef CONFIG_ATM_ENI_BURST_TX_16W
  1905. " 16W"
  1906. #endif
  1907. #ifdef CONFIG_ATM_ENI_BURST_TX_8W
  1908. " 8W"
  1909. #endif
  1910. #ifdef CONFIG_ATM_ENI_BURST_TX_4W
  1911. " 4W"
  1912. #endif
  1913. #ifdef CONFIG_ATM_ENI_BURST_TX_2W
  1914. " 2W"
  1915. #endif
  1916. ", RX"
  1917. #if !defined(CONFIG_ATM_ENI_BURST_RX_16W) && \
  1918. !defined(CONFIG_ATM_ENI_BURST_RX_8W) && \
  1919. !defined(CONFIG_ATM_ENI_BURST_RX_4W) && \
  1920. !defined(CONFIG_ATM_ENI_BURST_RX_2W)
  1921. " none"
  1922. #endif
  1923. #ifdef CONFIG_ATM_ENI_BURST_RX_16W
  1924. " 16W"
  1925. #endif
  1926. #ifdef CONFIG_ATM_ENI_BURST_RX_8W
  1927. " 8W"
  1928. #endif
  1929. #ifdef CONFIG_ATM_ENI_BURST_RX_4W
  1930. " 4W"
  1931. #endif
  1932. #ifdef CONFIG_ATM_ENI_BURST_RX_2W
  1933. " 2W"
  1934. #endif
  1935. #ifndef CONFIG_ATM_ENI_TUNE_BURST
  1936. " (default)"
  1937. #endif
  1938. "\n","");
  1939. if (!--left)
  1940. return sprintf(page,"%4sBuffer multipliers: tx %d%%, rx %d%%\n",
  1941. "",eni_dev->tx_mult,eni_dev->rx_mult);
  1942. for (i = 0; i < NR_CHAN; i++) {
  1943. struct eni_tx *tx = eni_dev->tx+i;
  1944. if (!tx->send) continue;
  1945. if (!--left) {
  1946. return sprintf(page, "tx[%d]: 0x%lx-0x%lx "
  1947. "(%6ld bytes), rsv %d cps, shp %d cps%s\n",i,
  1948. (unsigned long) (tx->send - eni_dev->ram),
  1949. tx->send-eni_dev->ram+tx->words*4-1,tx->words*4,
  1950. tx->reserved,tx->shaping,
  1951. tx == eni_dev->ubr ? " (UBR)" : "");
  1952. }
  1953. if (--left) continue;
  1954. return sprintf(page,"%10sbacklog %u packets\n","",
  1955. skb_queue_len(&tx->backlog));
  1956. }
  1957. read_lock(&vcc_sklist_lock);
  1958. for(i = 0; i < VCC_HTABLE_SIZE; ++i) {
  1959. struct hlist_head *head = &vcc_hash[i];
  1960. sk_for_each(s, head) {
  1961. struct eni_vcc *eni_vcc;
  1962. int length;
  1963. vcc = atm_sk(s);
  1964. if (vcc->dev != dev)
  1965. continue;
  1966. eni_vcc = ENI_VCC(vcc);
  1967. if (--left) continue;
  1968. length = sprintf(page,"vcc %4d: ",vcc->vci);
  1969. if (eni_vcc->rx) {
  1970. length += sprintf(page+length, "0x%lx-0x%lx "
  1971. "(%6ld bytes)",
  1972. (unsigned long) (eni_vcc->recv - eni_dev->ram),
  1973. eni_vcc->recv-eni_dev->ram+eni_vcc->words*4-1,
  1974. eni_vcc->words*4);
  1975. if (eni_vcc->tx) length += sprintf(page+length,", ");
  1976. }
  1977. if (eni_vcc->tx)
  1978. length += sprintf(page+length,"tx[%d], txing %d bytes",
  1979. eni_vcc->tx->index,eni_vcc->txing);
  1980. page[length] = '\n';
  1981. read_unlock(&vcc_sklist_lock);
  1982. return length+1;
  1983. }
  1984. }
  1985. read_unlock(&vcc_sklist_lock);
  1986. for (i = 0; i < eni_dev->free_len; i++) {
  1987. struct eni_free *fe = eni_dev->free_list+i;
  1988. unsigned long offset;
  1989. if (--left) continue;
  1990. offset = (unsigned long) eni_dev->ram+eni_dev->base_diff;
  1991. return sprintf(page,"free %p-%p (%6d bytes)\n",
  1992. fe->start-offset,fe->start-offset+(1 << fe->order)-1,
  1993. 1 << fe->order);
  1994. }
  1995. return 0;
  1996. }
  1997. static const struct atmdev_ops ops = {
  1998. .open = eni_open,
  1999. .close = eni_close,
  2000. .ioctl = eni_ioctl,
  2001. .getsockopt = eni_getsockopt,
  2002. .setsockopt = eni_setsockopt,
  2003. .send = eni_send,
  2004. .phy_put = eni_phy_put,
  2005. .phy_get = eni_phy_get,
  2006. .change_qos = eni_change_qos,
  2007. .proc_read = eni_proc_read
  2008. };
  2009. static int eni_init_one(struct pci_dev *pci_dev,
  2010. const struct pci_device_id *ent)
  2011. {
  2012. struct atm_dev *dev;
  2013. struct eni_dev *eni_dev;
  2014. struct eni_zero *zero;
  2015. int rc;
  2016. rc = pci_enable_device(pci_dev);
  2017. if (rc < 0)
  2018. goto out;
  2019. rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
  2020. if (rc < 0)
  2021. goto out;
  2022. rc = -ENOMEM;
  2023. eni_dev = kmalloc(sizeof(struct eni_dev), GFP_KERNEL);
  2024. if (!eni_dev)
  2025. goto err_disable;
  2026. zero = &eni_dev->zero;
  2027. zero->addr = dma_alloc_coherent(&pci_dev->dev,
  2028. ENI_ZEROES_SIZE, &zero->dma, GFP_KERNEL);
  2029. if (!zero->addr)
  2030. goto err_kfree;
  2031. dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &ops, -1, NULL);
  2032. if (!dev)
  2033. goto err_free_consistent;
  2034. dev->dev_data = eni_dev;
  2035. pci_set_drvdata(pci_dev, dev);
  2036. eni_dev->pci_dev = pci_dev;
  2037. eni_dev->asic = ent->driver_data;
  2038. rc = eni_do_init(dev);
  2039. if (rc < 0)
  2040. goto err_unregister;
  2041. rc = eni_start(dev);
  2042. if (rc < 0)
  2043. goto err_eni_release;
  2044. eni_dev->more = eni_boards;
  2045. eni_boards = dev;
  2046. out:
  2047. return rc;
  2048. err_eni_release:
  2049. eni_do_release(dev);
  2050. err_unregister:
  2051. atm_dev_deregister(dev);
  2052. err_free_consistent:
  2053. dma_free_coherent(&pci_dev->dev, ENI_ZEROES_SIZE, zero->addr, zero->dma);
  2054. err_kfree:
  2055. kfree(eni_dev);
  2056. err_disable:
  2057. pci_disable_device(pci_dev);
  2058. goto out;
  2059. }
  2060. static struct pci_device_id eni_pci_tbl[] = {
  2061. { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_FPGA), 0 /* FPGA */ },
  2062. { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_ASIC), 1 /* ASIC */ },
  2063. { 0, }
  2064. };
  2065. MODULE_DEVICE_TABLE(pci,eni_pci_tbl);
  2066. static void eni_remove_one(struct pci_dev *pdev)
  2067. {
  2068. struct atm_dev *dev = pci_get_drvdata(pdev);
  2069. struct eni_dev *ed = ENI_DEV(dev);
  2070. struct eni_zero *zero = &ed->zero;
  2071. eni_do_release(dev);
  2072. atm_dev_deregister(dev);
  2073. dma_free_coherent(&pdev->dev, ENI_ZEROES_SIZE, zero->addr, zero->dma);
  2074. kfree(ed);
  2075. pci_disable_device(pdev);
  2076. }
  2077. static struct pci_driver eni_driver = {
  2078. .name = DEV_LABEL,
  2079. .id_table = eni_pci_tbl,
  2080. .probe = eni_init_one,
  2081. .remove = eni_remove_one,
  2082. };
  2083. static int __init eni_init(void)
  2084. {
  2085. struct sk_buff *skb; /* dummy for sizeof */
  2086. if (sizeof(skb->cb) < sizeof(struct eni_skb_prv)) {
  2087. printk(KERN_ERR "eni_detect: skb->cb is too small (%Zd < %Zd)\n",
  2088. sizeof(skb->cb),sizeof(struct eni_skb_prv));
  2089. return -EIO;
  2090. }
  2091. return pci_register_driver(&eni_driver);
  2092. }
  2093. module_init(eni_init);
  2094. /* @@@ since exit routine not defined, this module can not be unloaded */
  2095. MODULE_LICENSE("GPL");