eni.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340
  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 error;
  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(
  1665. sizeof(struct eni_free)*(eni_dev->free_list_size+1),GFP_KERNEL);
  1666. if (!eni_dev->free_list) {
  1667. printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n",
  1668. dev->number);
  1669. error = -ENOMEM;
  1670. goto free_irq;
  1671. }
  1672. eni_dev->free_len = 0;
  1673. eni_put_free(eni_dev,buf,buffer_mem);
  1674. memset_io(eni_dev->vci,0,16*NR_VCI); /* clear VCI table */
  1675. /*
  1676. * byte_addr free (k)
  1677. * 0x00000000 512 VCI table
  1678. * 0x00004000 496 RX DMA
  1679. * 0x00005000 492 TX DMA
  1680. * 0x00006000 488 service list
  1681. * 0x00007000 484 buffers
  1682. * 0x00080000 0 end (512kB)
  1683. */
  1684. eni_out(0xffffffff,MID_IE);
  1685. error = start_tx(dev);
  1686. if (error) goto free_list;
  1687. error = start_rx(dev);
  1688. if (error) goto free_list;
  1689. error = dev->phy->start(dev);
  1690. if (error) goto free_list;
  1691. eni_out(eni_in(MID_MC_S) | (1 << MID_INT_SEL_SHIFT) |
  1692. MID_TX_LOCK_MODE | MID_DMA_ENABLE | MID_TX_ENABLE | MID_RX_ENABLE,
  1693. MID_MC_S);
  1694. /* Tonga uses SBus INTReq1 */
  1695. (void) eni_in(MID_ISA); /* clear Midway interrupts */
  1696. return 0;
  1697. free_list:
  1698. kfree(eni_dev->free_list);
  1699. free_irq:
  1700. free_irq(eni_dev->irq, dev);
  1701. out:
  1702. return error;
  1703. }
  1704. static void eni_close(struct atm_vcc *vcc)
  1705. {
  1706. DPRINTK(">eni_close\n");
  1707. if (!ENI_VCC(vcc)) return;
  1708. clear_bit(ATM_VF_READY,&vcc->flags);
  1709. close_rx(vcc);
  1710. close_tx(vcc);
  1711. DPRINTK("eni_close: done waiting\n");
  1712. /* deallocate memory */
  1713. kfree(ENI_VCC(vcc));
  1714. vcc->dev_data = NULL;
  1715. clear_bit(ATM_VF_ADDR,&vcc->flags);
  1716. /*foo();*/
  1717. }
  1718. static int eni_open(struct atm_vcc *vcc)
  1719. {
  1720. struct eni_vcc *eni_vcc;
  1721. int error;
  1722. short vpi = vcc->vpi;
  1723. int vci = vcc->vci;
  1724. DPRINTK(">eni_open\n");
  1725. EVENT("eni_open\n",0,0);
  1726. if (!test_bit(ATM_VF_PARTIAL,&vcc->flags))
  1727. vcc->dev_data = NULL;
  1728. if (vci != ATM_VPI_UNSPEC && vpi != ATM_VCI_UNSPEC)
  1729. set_bit(ATM_VF_ADDR,&vcc->flags);
  1730. if (vcc->qos.aal != ATM_AAL0 && vcc->qos.aal != ATM_AAL5)
  1731. return -EINVAL;
  1732. DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n",vcc->dev->number,vcc->vpi,
  1733. vcc->vci);
  1734. if (!test_bit(ATM_VF_PARTIAL,&vcc->flags)) {
  1735. eni_vcc = kmalloc(sizeof(struct eni_vcc),GFP_KERNEL);
  1736. if (!eni_vcc) return -ENOMEM;
  1737. vcc->dev_data = eni_vcc;
  1738. eni_vcc->tx = NULL; /* for eni_close after open_rx */
  1739. if ((error = open_rx_first(vcc))) {
  1740. eni_close(vcc);
  1741. return error;
  1742. }
  1743. if ((error = open_tx_first(vcc))) {
  1744. eni_close(vcc);
  1745. return error;
  1746. }
  1747. }
  1748. if (vci == ATM_VPI_UNSPEC || vpi == ATM_VCI_UNSPEC) return 0;
  1749. if ((error = open_rx_second(vcc))) {
  1750. eni_close(vcc);
  1751. return error;
  1752. }
  1753. if ((error = open_tx_second(vcc))) {
  1754. eni_close(vcc);
  1755. return error;
  1756. }
  1757. set_bit(ATM_VF_READY,&vcc->flags);
  1758. /* should power down SUNI while !ref_count @@@ */
  1759. return 0;
  1760. }
  1761. static int eni_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flgs)
  1762. {
  1763. struct eni_dev *eni_dev = ENI_DEV(vcc->dev);
  1764. struct eni_tx *tx = ENI_VCC(vcc)->tx;
  1765. struct sk_buff *skb;
  1766. int error,rate,rsv,shp;
  1767. if (qos->txtp.traffic_class == ATM_NONE) return 0;
  1768. if (tx == eni_dev->ubr) return -EBADFD;
  1769. rate = atm_pcr_goal(&qos->txtp);
  1770. if (rate < 0) rate = -rate;
  1771. rsv = shp = 0;
  1772. if ((flgs & ATM_MF_DEC_RSV) && rate && rate < tx->reserved) rsv = 1;
  1773. if ((flgs & ATM_MF_INC_RSV) && (!rate || rate > tx->reserved)) rsv = 1;
  1774. if ((flgs & ATM_MF_DEC_SHP) && rate && rate < tx->shaping) shp = 1;
  1775. if ((flgs & ATM_MF_INC_SHP) && (!rate || rate > tx->shaping)) shp = 1;
  1776. if (!rsv && !shp) return 0;
  1777. error = reserve_or_set_tx(vcc,&qos->txtp,rsv,shp);
  1778. if (error) return error;
  1779. if (shp && !(flgs & ATM_MF_IMMED)) return 0;
  1780. /*
  1781. * Walk through the send buffer and patch the rate information in all
  1782. * segmentation buffer descriptors of this VCC.
  1783. */
  1784. tasklet_disable(&eni_dev->task);
  1785. skb_queue_walk(&eni_dev->tx_queue, skb) {
  1786. void __iomem *dsc;
  1787. if (ATM_SKB(skb)->vcc != vcc) continue;
  1788. dsc = tx->send+ENI_PRV_POS(skb)*4;
  1789. writel((readl(dsc) & ~(MID_SEG_RATE | MID_SEG_PR)) |
  1790. (tx->prescaler << MID_SEG_PR_SHIFT) |
  1791. (tx->resolution << MID_SEG_RATE_SHIFT), dsc);
  1792. }
  1793. tasklet_enable(&eni_dev->task);
  1794. return 0;
  1795. }
  1796. static int eni_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
  1797. {
  1798. struct eni_dev *eni_dev = ENI_DEV(dev);
  1799. if (cmd == ENI_MEMDUMP) {
  1800. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  1801. printk(KERN_WARNING "Please use /proc/atm/" DEV_LABEL ":%d "
  1802. "instead of obsolete ioctl ENI_MEMDUMP\n",dev->number);
  1803. dump(dev);
  1804. return 0;
  1805. }
  1806. if (cmd == ENI_SETMULT) {
  1807. struct eni_multipliers mult;
  1808. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  1809. if (copy_from_user(&mult, arg,
  1810. sizeof(struct eni_multipliers)))
  1811. return -EFAULT;
  1812. if ((mult.tx && mult.tx <= 100) || (mult.rx &&mult.rx <= 100) ||
  1813. mult.tx > 65536 || mult.rx > 65536)
  1814. return -EINVAL;
  1815. if (mult.tx) eni_dev->tx_mult = mult.tx;
  1816. if (mult.rx) eni_dev->rx_mult = mult.rx;
  1817. return 0;
  1818. }
  1819. if (cmd == ATM_SETCIRANGE) {
  1820. struct atm_cirange ci;
  1821. if (copy_from_user(&ci, arg,sizeof(struct atm_cirange)))
  1822. return -EFAULT;
  1823. if ((ci.vpi_bits == 0 || ci.vpi_bits == ATM_CI_MAX) &&
  1824. (ci.vci_bits == NR_VCI_LD || ci.vpi_bits == ATM_CI_MAX))
  1825. return 0;
  1826. return -EINVAL;
  1827. }
  1828. if (!dev->phy->ioctl) return -ENOIOCTLCMD;
  1829. return dev->phy->ioctl(dev,cmd,arg);
  1830. }
  1831. static int eni_getsockopt(struct atm_vcc *vcc,int level,int optname,
  1832. void __user *optval,int optlen)
  1833. {
  1834. return -EINVAL;
  1835. }
  1836. static int eni_setsockopt(struct atm_vcc *vcc,int level,int optname,
  1837. void __user *optval,unsigned int optlen)
  1838. {
  1839. return -EINVAL;
  1840. }
  1841. static int eni_send(struct atm_vcc *vcc,struct sk_buff *skb)
  1842. {
  1843. enum enq_res res;
  1844. DPRINTK(">eni_send\n");
  1845. if (!ENI_VCC(vcc)->tx) {
  1846. if (vcc->pop) vcc->pop(vcc,skb);
  1847. else dev_kfree_skb(skb);
  1848. return -EINVAL;
  1849. }
  1850. if (!skb) {
  1851. printk(KERN_CRIT "!skb in eni_send ?\n");
  1852. if (vcc->pop) vcc->pop(vcc,skb);
  1853. return -EINVAL;
  1854. }
  1855. if (vcc->qos.aal == ATM_AAL0) {
  1856. if (skb->len != ATM_CELL_SIZE-1) {
  1857. if (vcc->pop) vcc->pop(vcc,skb);
  1858. else dev_kfree_skb(skb);
  1859. return -EINVAL;
  1860. }
  1861. *(u32 *) skb->data = htonl(*(u32 *) skb->data);
  1862. }
  1863. submitted++;
  1864. ATM_SKB(skb)->vcc = vcc;
  1865. tasklet_disable(&ENI_DEV(vcc->dev)->task);
  1866. res = do_tx(skb);
  1867. tasklet_enable(&ENI_DEV(vcc->dev)->task);
  1868. if (res == enq_ok) return 0;
  1869. skb_queue_tail(&ENI_VCC(vcc)->tx->backlog,skb);
  1870. backlogged++;
  1871. tasklet_schedule(&ENI_DEV(vcc->dev)->task);
  1872. return 0;
  1873. }
  1874. static void eni_phy_put(struct atm_dev *dev,unsigned char value,
  1875. unsigned long addr)
  1876. {
  1877. writel(value,ENI_DEV(dev)->phy+addr*4);
  1878. }
  1879. static unsigned char eni_phy_get(struct atm_dev *dev,unsigned long addr)
  1880. {
  1881. return readl(ENI_DEV(dev)->phy+addr*4);
  1882. }
  1883. static int eni_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
  1884. {
  1885. struct sock *s;
  1886. static const char *signal[] = { "LOST","unknown","okay" };
  1887. struct eni_dev *eni_dev = ENI_DEV(dev);
  1888. struct atm_vcc *vcc;
  1889. int left,i;
  1890. left = *pos;
  1891. if (!left)
  1892. return sprintf(page,DEV_LABEL "(itf %d) signal %s, %dkB, "
  1893. "%d cps remaining\n",dev->number,signal[(int) dev->signal],
  1894. eni_dev->mem >> 10,eni_dev->tx_bw);
  1895. if (!--left)
  1896. return sprintf(page,"%4sBursts: TX"
  1897. #if !defined(CONFIG_ATM_ENI_BURST_TX_16W) && \
  1898. !defined(CONFIG_ATM_ENI_BURST_TX_8W) && \
  1899. !defined(CONFIG_ATM_ENI_BURST_TX_4W) && \
  1900. !defined(CONFIG_ATM_ENI_BURST_TX_2W)
  1901. " none"
  1902. #endif
  1903. #ifdef CONFIG_ATM_ENI_BURST_TX_16W
  1904. " 16W"
  1905. #endif
  1906. #ifdef CONFIG_ATM_ENI_BURST_TX_8W
  1907. " 8W"
  1908. #endif
  1909. #ifdef CONFIG_ATM_ENI_BURST_TX_4W
  1910. " 4W"
  1911. #endif
  1912. #ifdef CONFIG_ATM_ENI_BURST_TX_2W
  1913. " 2W"
  1914. #endif
  1915. ", RX"
  1916. #if !defined(CONFIG_ATM_ENI_BURST_RX_16W) && \
  1917. !defined(CONFIG_ATM_ENI_BURST_RX_8W) && \
  1918. !defined(CONFIG_ATM_ENI_BURST_RX_4W) && \
  1919. !defined(CONFIG_ATM_ENI_BURST_RX_2W)
  1920. " none"
  1921. #endif
  1922. #ifdef CONFIG_ATM_ENI_BURST_RX_16W
  1923. " 16W"
  1924. #endif
  1925. #ifdef CONFIG_ATM_ENI_BURST_RX_8W
  1926. " 8W"
  1927. #endif
  1928. #ifdef CONFIG_ATM_ENI_BURST_RX_4W
  1929. " 4W"
  1930. #endif
  1931. #ifdef CONFIG_ATM_ENI_BURST_RX_2W
  1932. " 2W"
  1933. #endif
  1934. #ifndef CONFIG_ATM_ENI_TUNE_BURST
  1935. " (default)"
  1936. #endif
  1937. "\n","");
  1938. if (!--left)
  1939. return sprintf(page,"%4sBuffer multipliers: tx %d%%, rx %d%%\n",
  1940. "",eni_dev->tx_mult,eni_dev->rx_mult);
  1941. for (i = 0; i < NR_CHAN; i++) {
  1942. struct eni_tx *tx = eni_dev->tx+i;
  1943. if (!tx->send) continue;
  1944. if (!--left) {
  1945. return sprintf(page, "tx[%d]: 0x%lx-0x%lx "
  1946. "(%6ld bytes), rsv %d cps, shp %d cps%s\n",i,
  1947. (unsigned long) (tx->send - eni_dev->ram),
  1948. tx->send-eni_dev->ram+tx->words*4-1,tx->words*4,
  1949. tx->reserved,tx->shaping,
  1950. tx == eni_dev->ubr ? " (UBR)" : "");
  1951. }
  1952. if (--left) continue;
  1953. return sprintf(page,"%10sbacklog %u packets\n","",
  1954. skb_queue_len(&tx->backlog));
  1955. }
  1956. read_lock(&vcc_sklist_lock);
  1957. for(i = 0; i < VCC_HTABLE_SIZE; ++i) {
  1958. struct hlist_head *head = &vcc_hash[i];
  1959. sk_for_each(s, head) {
  1960. struct eni_vcc *eni_vcc;
  1961. int length;
  1962. vcc = atm_sk(s);
  1963. if (vcc->dev != dev)
  1964. continue;
  1965. eni_vcc = ENI_VCC(vcc);
  1966. if (--left) continue;
  1967. length = sprintf(page,"vcc %4d: ",vcc->vci);
  1968. if (eni_vcc->rx) {
  1969. length += sprintf(page+length, "0x%lx-0x%lx "
  1970. "(%6ld bytes)",
  1971. (unsigned long) (eni_vcc->recv - eni_dev->ram),
  1972. eni_vcc->recv-eni_dev->ram+eni_vcc->words*4-1,
  1973. eni_vcc->words*4);
  1974. if (eni_vcc->tx) length += sprintf(page+length,", ");
  1975. }
  1976. if (eni_vcc->tx)
  1977. length += sprintf(page+length,"tx[%d], txing %d bytes",
  1978. eni_vcc->tx->index,eni_vcc->txing);
  1979. page[length] = '\n';
  1980. read_unlock(&vcc_sklist_lock);
  1981. return length+1;
  1982. }
  1983. }
  1984. read_unlock(&vcc_sklist_lock);
  1985. for (i = 0; i < eni_dev->free_len; i++) {
  1986. struct eni_free *fe = eni_dev->free_list+i;
  1987. unsigned long offset;
  1988. if (--left) continue;
  1989. offset = (unsigned long) eni_dev->ram+eni_dev->base_diff;
  1990. return sprintf(page,"free %p-%p (%6d bytes)\n",
  1991. fe->start-offset,fe->start-offset+(1 << fe->order)-1,
  1992. 1 << fe->order);
  1993. }
  1994. return 0;
  1995. }
  1996. static const struct atmdev_ops ops = {
  1997. .open = eni_open,
  1998. .close = eni_close,
  1999. .ioctl = eni_ioctl,
  2000. .getsockopt = eni_getsockopt,
  2001. .setsockopt = eni_setsockopt,
  2002. .send = eni_send,
  2003. .phy_put = eni_phy_put,
  2004. .phy_get = eni_phy_get,
  2005. .change_qos = eni_change_qos,
  2006. .proc_read = eni_proc_read
  2007. };
  2008. static int eni_init_one(struct pci_dev *pci_dev,
  2009. const struct pci_device_id *ent)
  2010. {
  2011. struct atm_dev *dev;
  2012. struct eni_dev *eni_dev;
  2013. struct eni_zero *zero;
  2014. int rc;
  2015. rc = pci_enable_device(pci_dev);
  2016. if (rc < 0)
  2017. goto out;
  2018. rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
  2019. if (rc < 0)
  2020. goto out;
  2021. rc = -ENOMEM;
  2022. eni_dev = kmalloc(sizeof(struct eni_dev), GFP_KERNEL);
  2023. if (!eni_dev)
  2024. goto err_disable;
  2025. zero = &eni_dev->zero;
  2026. zero->addr = dma_alloc_coherent(&pci_dev->dev,
  2027. ENI_ZEROES_SIZE, &zero->dma, GFP_KERNEL);
  2028. if (!zero->addr)
  2029. goto err_kfree;
  2030. dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &ops, -1, NULL);
  2031. if (!dev)
  2032. goto err_free_consistent;
  2033. dev->dev_data = eni_dev;
  2034. pci_set_drvdata(pci_dev, dev);
  2035. eni_dev->pci_dev = pci_dev;
  2036. eni_dev->asic = ent->driver_data;
  2037. rc = eni_do_init(dev);
  2038. if (rc < 0)
  2039. goto err_unregister;
  2040. rc = eni_start(dev);
  2041. if (rc < 0)
  2042. goto err_eni_release;
  2043. eni_dev->more = eni_boards;
  2044. eni_boards = dev;
  2045. out:
  2046. return rc;
  2047. err_eni_release:
  2048. eni_do_release(dev);
  2049. err_unregister:
  2050. atm_dev_deregister(dev);
  2051. err_free_consistent:
  2052. dma_free_coherent(&pci_dev->dev, ENI_ZEROES_SIZE, zero->addr, zero->dma);
  2053. err_kfree:
  2054. kfree(eni_dev);
  2055. err_disable:
  2056. pci_disable_device(pci_dev);
  2057. goto out;
  2058. }
  2059. static struct pci_device_id eni_pci_tbl[] = {
  2060. { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_FPGA), 0 /* FPGA */ },
  2061. { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_ASIC), 1 /* ASIC */ },
  2062. { 0, }
  2063. };
  2064. MODULE_DEVICE_TABLE(pci,eni_pci_tbl);
  2065. static void eni_remove_one(struct pci_dev *pdev)
  2066. {
  2067. struct atm_dev *dev = pci_get_drvdata(pdev);
  2068. struct eni_dev *ed = ENI_DEV(dev);
  2069. struct eni_zero *zero = &ed->zero;
  2070. eni_do_release(dev);
  2071. atm_dev_deregister(dev);
  2072. dma_free_coherent(&pdev->dev, ENI_ZEROES_SIZE, zero->addr, zero->dma);
  2073. kfree(ed);
  2074. pci_disable_device(pdev);
  2075. }
  2076. static struct pci_driver eni_driver = {
  2077. .name = DEV_LABEL,
  2078. .id_table = eni_pci_tbl,
  2079. .probe = eni_init_one,
  2080. .remove = eni_remove_one,
  2081. };
  2082. static int __init eni_init(void)
  2083. {
  2084. struct sk_buff *skb; /* dummy for sizeof */
  2085. if (sizeof(skb->cb) < sizeof(struct eni_skb_prv)) {
  2086. printk(KERN_ERR "eni_detect: skb->cb is too small (%Zd < %Zd)\n",
  2087. sizeof(skb->cb),sizeof(struct eni_skb_prv));
  2088. return -EIO;
  2089. }
  2090. return pci_register_driver(&eni_driver);
  2091. }
  2092. module_init(eni_init);
  2093. /* @@@ since exit routine not defined, this module can not be unloaded */
  2094. MODULE_LICENSE("GPL");