eni.c 61 KB

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