eni.c 61 KB

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