nicstar.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755
  1. /*
  2. * nicstar.c
  3. *
  4. * Device driver supporting CBR for IDT 77201/77211 "NICStAR" based cards.
  5. *
  6. * IMPORTANT: The included file nicstarmac.c was NOT WRITTEN BY ME.
  7. * It was taken from the frle-0.22 device driver.
  8. * As the file doesn't have a copyright notice, in the file
  9. * nicstarmac.copyright I put the copyright notice from the
  10. * frle-0.22 device driver.
  11. * Some code is based on the nicstar driver by M. Welsh.
  12. *
  13. * Author: Rui Prior (rprior@inescn.pt)
  14. * PowerPC support by Jay Talbott (jay_talbott@mcg.mot.com) April 1999
  15. *
  16. *
  17. * (C) INESC 1999
  18. */
  19. /*
  20. * IMPORTANT INFORMATION
  21. *
  22. * There are currently three types of spinlocks:
  23. *
  24. * 1 - Per card interrupt spinlock (to protect structures and such)
  25. * 2 - Per SCQ scq spinlock
  26. * 3 - Per card resource spinlock (to access registers, etc.)
  27. *
  28. * These must NEVER be grabbed in reverse order.
  29. *
  30. */
  31. /* Header files */
  32. #include <linux/module.h>
  33. #include <linux/kernel.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/atmdev.h>
  36. #include <linux/atm.h>
  37. #include <linux/pci.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/types.h>
  40. #include <linux/string.h>
  41. #include <linux/delay.h>
  42. #include <linux/init.h>
  43. #include <linux/sched.h>
  44. #include <linux/timer.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/bitops.h>
  47. #include <linux/slab.h>
  48. #include <linux/idr.h>
  49. #include <asm/io.h>
  50. #include <linux/uaccess.h>
  51. #include <linux/atomic.h>
  52. #include <linux/etherdevice.h>
  53. #include "nicstar.h"
  54. #ifdef CONFIG_ATM_NICSTAR_USE_SUNI
  55. #include "suni.h"
  56. #endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
  57. #ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
  58. #include "idt77105.h"
  59. #endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
  60. /* Additional code */
  61. #include "nicstarmac.c"
  62. /* Configurable parameters */
  63. #undef PHY_LOOPBACK
  64. #undef TX_DEBUG
  65. #undef RX_DEBUG
  66. #undef GENERAL_DEBUG
  67. #undef EXTRA_DEBUG
  68. /* Do not touch these */
  69. #ifdef TX_DEBUG
  70. #define TXPRINTK(args...) printk(args)
  71. #else
  72. #define TXPRINTK(args...)
  73. #endif /* TX_DEBUG */
  74. #ifdef RX_DEBUG
  75. #define RXPRINTK(args...) printk(args)
  76. #else
  77. #define RXPRINTK(args...)
  78. #endif /* RX_DEBUG */
  79. #ifdef GENERAL_DEBUG
  80. #define PRINTK(args...) printk(args)
  81. #else
  82. #define PRINTK(args...)
  83. #endif /* GENERAL_DEBUG */
  84. #ifdef EXTRA_DEBUG
  85. #define XPRINTK(args...) printk(args)
  86. #else
  87. #define XPRINTK(args...)
  88. #endif /* EXTRA_DEBUG */
  89. /* Macros */
  90. #define CMD_BUSY(card) (readl((card)->membase + STAT) & NS_STAT_CMDBZ)
  91. #define NS_DELAY mdelay(1)
  92. #define PTR_DIFF(a, b) ((u32)((unsigned long)(a) - (unsigned long)(b)))
  93. #ifndef ATM_SKB
  94. #define ATM_SKB(s) (&(s)->atm)
  95. #endif
  96. #define scq_virt_to_bus(scq, p) \
  97. (scq->dma + ((unsigned long)(p) - (unsigned long)(scq)->org))
  98. /* Function declarations */
  99. static u32 ns_read_sram(ns_dev * card, u32 sram_address);
  100. static void ns_write_sram(ns_dev * card, u32 sram_address, u32 * value,
  101. int count);
  102. static int ns_init_card(int i, struct pci_dev *pcidev);
  103. static void ns_init_card_error(ns_dev * card, int error);
  104. static scq_info *get_scq(ns_dev *card, int size, u32 scd);
  105. static void free_scq(ns_dev *card, scq_info * scq, struct atm_vcc *vcc);
  106. static void push_rxbufs(ns_dev *, struct sk_buff *);
  107. static irqreturn_t ns_irq_handler(int irq, void *dev_id);
  108. static int ns_open(struct atm_vcc *vcc);
  109. static void ns_close(struct atm_vcc *vcc);
  110. static void fill_tst(ns_dev * card, int n, vc_map * vc);
  111. static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb);
  112. static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd,
  113. struct sk_buff *skb);
  114. static void process_tsq(ns_dev * card);
  115. static void drain_scq(ns_dev * card, scq_info * scq, int pos);
  116. static void process_rsq(ns_dev * card);
  117. static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe);
  118. static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb);
  119. static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count);
  120. static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb);
  121. static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb);
  122. static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb);
  123. static int ns_proc_read(struct atm_dev *dev, loff_t * pos, char *page);
  124. static int ns_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg);
  125. #ifdef EXTRA_DEBUG
  126. static void which_list(ns_dev * card, struct sk_buff *skb);
  127. #endif
  128. static void ns_poll(unsigned long arg);
  129. static void ns_phy_put(struct atm_dev *dev, unsigned char value,
  130. unsigned long addr);
  131. static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr);
  132. /* Global variables */
  133. static struct ns_dev *cards[NS_MAX_CARDS];
  134. static unsigned num_cards;
  135. static const struct atmdev_ops atm_ops = {
  136. .open = ns_open,
  137. .close = ns_close,
  138. .ioctl = ns_ioctl,
  139. .send = ns_send,
  140. .phy_put = ns_phy_put,
  141. .phy_get = ns_phy_get,
  142. .proc_read = ns_proc_read,
  143. .owner = THIS_MODULE,
  144. };
  145. static struct timer_list ns_timer;
  146. static char *mac[NS_MAX_CARDS];
  147. module_param_array(mac, charp, NULL, 0);
  148. MODULE_LICENSE("GPL");
  149. /* Functions */
  150. static int nicstar_init_one(struct pci_dev *pcidev,
  151. const struct pci_device_id *ent)
  152. {
  153. static int index = -1;
  154. unsigned int error;
  155. index++;
  156. cards[index] = NULL;
  157. error = ns_init_card(index, pcidev);
  158. if (error) {
  159. cards[index--] = NULL; /* don't increment index */
  160. goto err_out;
  161. }
  162. return 0;
  163. err_out:
  164. return -ENODEV;
  165. }
  166. static void nicstar_remove_one(struct pci_dev *pcidev)
  167. {
  168. int i, j;
  169. ns_dev *card = pci_get_drvdata(pcidev);
  170. struct sk_buff *hb;
  171. struct sk_buff *iovb;
  172. struct sk_buff *lb;
  173. struct sk_buff *sb;
  174. i = card->index;
  175. if (cards[i] == NULL)
  176. return;
  177. if (card->atmdev->phy && card->atmdev->phy->stop)
  178. card->atmdev->phy->stop(card->atmdev);
  179. /* Stop everything */
  180. writel(0x00000000, card->membase + CFG);
  181. /* De-register device */
  182. atm_dev_deregister(card->atmdev);
  183. /* Disable PCI device */
  184. pci_disable_device(pcidev);
  185. /* Free up resources */
  186. j = 0;
  187. PRINTK("nicstar%d: freeing %d huge buffers.\n", i, card->hbpool.count);
  188. while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL) {
  189. dev_kfree_skb_any(hb);
  190. j++;
  191. }
  192. PRINTK("nicstar%d: %d huge buffers freed.\n", i, j);
  193. j = 0;
  194. PRINTK("nicstar%d: freeing %d iovec buffers.\n", i,
  195. card->iovpool.count);
  196. while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL) {
  197. dev_kfree_skb_any(iovb);
  198. j++;
  199. }
  200. PRINTK("nicstar%d: %d iovec buffers freed.\n", i, j);
  201. while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL)
  202. dev_kfree_skb_any(lb);
  203. while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL)
  204. dev_kfree_skb_any(sb);
  205. free_scq(card, card->scq0, NULL);
  206. for (j = 0; j < NS_FRSCD_NUM; j++) {
  207. if (card->scd2vc[j] != NULL)
  208. free_scq(card, card->scd2vc[j]->scq, card->scd2vc[j]->tx_vcc);
  209. }
  210. idr_destroy(&card->idr);
  211. dma_free_coherent(&card->pcidev->dev, NS_RSQSIZE + NS_RSQ_ALIGNMENT,
  212. card->rsq.org, card->rsq.dma);
  213. dma_free_coherent(&card->pcidev->dev, NS_TSQSIZE + NS_TSQ_ALIGNMENT,
  214. card->tsq.org, card->tsq.dma);
  215. free_irq(card->pcidev->irq, card);
  216. iounmap(card->membase);
  217. kfree(card);
  218. }
  219. static const struct pci_device_id nicstar_pci_tbl[] = {
  220. { PCI_VDEVICE(IDT, PCI_DEVICE_ID_IDT_IDT77201), 0 },
  221. {0,} /* terminate list */
  222. };
  223. MODULE_DEVICE_TABLE(pci, nicstar_pci_tbl);
  224. static struct pci_driver nicstar_driver = {
  225. .name = "nicstar",
  226. .id_table = nicstar_pci_tbl,
  227. .probe = nicstar_init_one,
  228. .remove = nicstar_remove_one,
  229. };
  230. static int __init nicstar_init(void)
  231. {
  232. unsigned error = 0; /* Initialized to remove compile warning */
  233. XPRINTK("nicstar: nicstar_init() called.\n");
  234. error = pci_register_driver(&nicstar_driver);
  235. TXPRINTK("nicstar: TX debug enabled.\n");
  236. RXPRINTK("nicstar: RX debug enabled.\n");
  237. PRINTK("nicstar: General debug enabled.\n");
  238. #ifdef PHY_LOOPBACK
  239. printk("nicstar: using PHY loopback.\n");
  240. #endif /* PHY_LOOPBACK */
  241. XPRINTK("nicstar: nicstar_init() returned.\n");
  242. if (!error) {
  243. init_timer(&ns_timer);
  244. ns_timer.expires = jiffies + NS_POLL_PERIOD;
  245. ns_timer.data = 0UL;
  246. ns_timer.function = ns_poll;
  247. add_timer(&ns_timer);
  248. }
  249. return error;
  250. }
  251. static void __exit nicstar_cleanup(void)
  252. {
  253. XPRINTK("nicstar: nicstar_cleanup() called.\n");
  254. del_timer_sync(&ns_timer);
  255. pci_unregister_driver(&nicstar_driver);
  256. XPRINTK("nicstar: nicstar_cleanup() returned.\n");
  257. }
  258. static u32 ns_read_sram(ns_dev * card, u32 sram_address)
  259. {
  260. unsigned long flags;
  261. u32 data;
  262. sram_address <<= 2;
  263. sram_address &= 0x0007FFFC; /* address must be dword aligned */
  264. sram_address |= 0x50000000; /* SRAM read command */
  265. spin_lock_irqsave(&card->res_lock, flags);
  266. while (CMD_BUSY(card)) ;
  267. writel(sram_address, card->membase + CMD);
  268. while (CMD_BUSY(card)) ;
  269. data = readl(card->membase + DR0);
  270. spin_unlock_irqrestore(&card->res_lock, flags);
  271. return data;
  272. }
  273. static void ns_write_sram(ns_dev * card, u32 sram_address, u32 * value,
  274. int count)
  275. {
  276. unsigned long flags;
  277. int i, c;
  278. count--; /* count range now is 0..3 instead of 1..4 */
  279. c = count;
  280. c <<= 2; /* to use increments of 4 */
  281. spin_lock_irqsave(&card->res_lock, flags);
  282. while (CMD_BUSY(card)) ;
  283. for (i = 0; i <= c; i += 4)
  284. writel(*(value++), card->membase + i);
  285. /* Note: DR# registers are the first 4 dwords in nicstar's memspace,
  286. so card->membase + DR0 == card->membase */
  287. sram_address <<= 2;
  288. sram_address &= 0x0007FFFC;
  289. sram_address |= (0x40000000 | count);
  290. writel(sram_address, card->membase + CMD);
  291. spin_unlock_irqrestore(&card->res_lock, flags);
  292. }
  293. static int ns_init_card(int i, struct pci_dev *pcidev)
  294. {
  295. int j;
  296. struct ns_dev *card = NULL;
  297. unsigned char pci_latency;
  298. unsigned error;
  299. u32 data;
  300. u32 u32d[4];
  301. u32 ns_cfg_rctsize;
  302. int bcount;
  303. unsigned long membase;
  304. error = 0;
  305. if (pci_enable_device(pcidev)) {
  306. printk("nicstar%d: can't enable PCI device\n", i);
  307. error = 2;
  308. ns_init_card_error(card, error);
  309. return error;
  310. }
  311. if (dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)) != 0) {
  312. printk(KERN_WARNING
  313. "nicstar%d: No suitable DMA available.\n", i);
  314. error = 2;
  315. ns_init_card_error(card, error);
  316. return error;
  317. }
  318. card = kmalloc(sizeof(*card), GFP_KERNEL);
  319. if (!card) {
  320. printk
  321. ("nicstar%d: can't allocate memory for device structure.\n",
  322. i);
  323. error = 2;
  324. ns_init_card_error(card, error);
  325. return error;
  326. }
  327. cards[i] = card;
  328. spin_lock_init(&card->int_lock);
  329. spin_lock_init(&card->res_lock);
  330. pci_set_drvdata(pcidev, card);
  331. card->index = i;
  332. card->atmdev = NULL;
  333. card->pcidev = pcidev;
  334. membase = pci_resource_start(pcidev, 1);
  335. card->membase = ioremap(membase, NS_IOREMAP_SIZE);
  336. if (!card->membase) {
  337. printk("nicstar%d: can't ioremap() membase.\n", i);
  338. error = 3;
  339. ns_init_card_error(card, error);
  340. return error;
  341. }
  342. PRINTK("nicstar%d: membase at 0x%p.\n", i, card->membase);
  343. pci_set_master(pcidev);
  344. if (pci_read_config_byte(pcidev, PCI_LATENCY_TIMER, &pci_latency) != 0) {
  345. printk("nicstar%d: can't read PCI latency timer.\n", i);
  346. error = 6;
  347. ns_init_card_error(card, error);
  348. return error;
  349. }
  350. #ifdef NS_PCI_LATENCY
  351. if (pci_latency < NS_PCI_LATENCY) {
  352. PRINTK("nicstar%d: setting PCI latency timer to %d.\n", i,
  353. NS_PCI_LATENCY);
  354. for (j = 1; j < 4; j++) {
  355. if (pci_write_config_byte
  356. (pcidev, PCI_LATENCY_TIMER, NS_PCI_LATENCY) != 0)
  357. break;
  358. }
  359. if (j == 4) {
  360. printk
  361. ("nicstar%d: can't set PCI latency timer to %d.\n",
  362. i, NS_PCI_LATENCY);
  363. error = 7;
  364. ns_init_card_error(card, error);
  365. return error;
  366. }
  367. }
  368. #endif /* NS_PCI_LATENCY */
  369. /* Clear timer overflow */
  370. data = readl(card->membase + STAT);
  371. if (data & NS_STAT_TMROF)
  372. writel(NS_STAT_TMROF, card->membase + STAT);
  373. /* Software reset */
  374. writel(NS_CFG_SWRST, card->membase + CFG);
  375. NS_DELAY;
  376. writel(0x00000000, card->membase + CFG);
  377. /* PHY reset */
  378. writel(0x00000008, card->membase + GP);
  379. NS_DELAY;
  380. writel(0x00000001, card->membase + GP);
  381. NS_DELAY;
  382. while (CMD_BUSY(card)) ;
  383. writel(NS_CMD_WRITE_UTILITY | 0x00000100, card->membase + CMD); /* Sync UTOPIA with SAR clock */
  384. NS_DELAY;
  385. /* Detect PHY type */
  386. while (CMD_BUSY(card)) ;
  387. writel(NS_CMD_READ_UTILITY | 0x00000200, card->membase + CMD);
  388. while (CMD_BUSY(card)) ;
  389. data = readl(card->membase + DR0);
  390. switch (data) {
  391. case 0x00000009:
  392. printk("nicstar%d: PHY seems to be 25 Mbps.\n", i);
  393. card->max_pcr = ATM_25_PCR;
  394. while (CMD_BUSY(card)) ;
  395. writel(0x00000008, card->membase + DR0);
  396. writel(NS_CMD_WRITE_UTILITY | 0x00000200, card->membase + CMD);
  397. /* Clear an eventual pending interrupt */
  398. writel(NS_STAT_SFBQF, card->membase + STAT);
  399. #ifdef PHY_LOOPBACK
  400. while (CMD_BUSY(card)) ;
  401. writel(0x00000022, card->membase + DR0);
  402. writel(NS_CMD_WRITE_UTILITY | 0x00000202, card->membase + CMD);
  403. #endif /* PHY_LOOPBACK */
  404. break;
  405. case 0x00000030:
  406. case 0x00000031:
  407. printk("nicstar%d: PHY seems to be 155 Mbps.\n", i);
  408. card->max_pcr = ATM_OC3_PCR;
  409. #ifdef PHY_LOOPBACK
  410. while (CMD_BUSY(card)) ;
  411. writel(0x00000002, card->membase + DR0);
  412. writel(NS_CMD_WRITE_UTILITY | 0x00000205, card->membase + CMD);
  413. #endif /* PHY_LOOPBACK */
  414. break;
  415. default:
  416. printk("nicstar%d: unknown PHY type (0x%08X).\n", i, data);
  417. error = 8;
  418. ns_init_card_error(card, error);
  419. return error;
  420. }
  421. writel(0x00000000, card->membase + GP);
  422. /* Determine SRAM size */
  423. data = 0x76543210;
  424. ns_write_sram(card, 0x1C003, &data, 1);
  425. data = 0x89ABCDEF;
  426. ns_write_sram(card, 0x14003, &data, 1);
  427. if (ns_read_sram(card, 0x14003) == 0x89ABCDEF &&
  428. ns_read_sram(card, 0x1C003) == 0x76543210)
  429. card->sram_size = 128;
  430. else
  431. card->sram_size = 32;
  432. PRINTK("nicstar%d: %dK x 32bit SRAM size.\n", i, card->sram_size);
  433. card->rct_size = NS_MAX_RCTSIZE;
  434. #if (NS_MAX_RCTSIZE == 4096)
  435. if (card->sram_size == 128)
  436. printk
  437. ("nicstar%d: limiting maximum VCI. See NS_MAX_RCTSIZE in nicstar.h\n",
  438. i);
  439. #elif (NS_MAX_RCTSIZE == 16384)
  440. if (card->sram_size == 32) {
  441. printk
  442. ("nicstar%d: wasting memory. See NS_MAX_RCTSIZE in nicstar.h\n",
  443. i);
  444. card->rct_size = 4096;
  445. }
  446. #else
  447. #error NS_MAX_RCTSIZE must be either 4096 or 16384 in nicstar.c
  448. #endif
  449. card->vpibits = NS_VPIBITS;
  450. if (card->rct_size == 4096)
  451. card->vcibits = 12 - NS_VPIBITS;
  452. else /* card->rct_size == 16384 */
  453. card->vcibits = 14 - NS_VPIBITS;
  454. /* Initialize the nicstar eeprom/eprom stuff, for the MAC addr */
  455. if (mac[i] == NULL)
  456. nicstar_init_eprom(card->membase);
  457. /* Set the VPI/VCI MSb mask to zero so we can receive OAM cells */
  458. writel(0x00000000, card->membase + VPM);
  459. card->intcnt = 0;
  460. if (request_irq
  461. (pcidev->irq, &ns_irq_handler, IRQF_SHARED, "nicstar", card) != 0) {
  462. pr_err("nicstar%d: can't allocate IRQ %d.\n", i, pcidev->irq);
  463. error = 9;
  464. ns_init_card_error(card, error);
  465. return error;
  466. }
  467. /* Initialize TSQ */
  468. card->tsq.org = dma_alloc_coherent(&card->pcidev->dev,
  469. NS_TSQSIZE + NS_TSQ_ALIGNMENT,
  470. &card->tsq.dma, GFP_KERNEL);
  471. if (card->tsq.org == NULL) {
  472. printk("nicstar%d: can't allocate TSQ.\n", i);
  473. error = 10;
  474. ns_init_card_error(card, error);
  475. return error;
  476. }
  477. card->tsq.base = PTR_ALIGN(card->tsq.org, NS_TSQ_ALIGNMENT);
  478. card->tsq.next = card->tsq.base;
  479. card->tsq.last = card->tsq.base + (NS_TSQ_NUM_ENTRIES - 1);
  480. for (j = 0; j < NS_TSQ_NUM_ENTRIES; j++)
  481. ns_tsi_init(card->tsq.base + j);
  482. writel(0x00000000, card->membase + TSQH);
  483. writel(ALIGN(card->tsq.dma, NS_TSQ_ALIGNMENT), card->membase + TSQB);
  484. PRINTK("nicstar%d: TSQ base at 0x%p.\n", i, card->tsq.base);
  485. /* Initialize RSQ */
  486. card->rsq.org = dma_alloc_coherent(&card->pcidev->dev,
  487. NS_RSQSIZE + NS_RSQ_ALIGNMENT,
  488. &card->rsq.dma, GFP_KERNEL);
  489. if (card->rsq.org == NULL) {
  490. printk("nicstar%d: can't allocate RSQ.\n", i);
  491. error = 11;
  492. ns_init_card_error(card, error);
  493. return error;
  494. }
  495. card->rsq.base = PTR_ALIGN(card->rsq.org, NS_RSQ_ALIGNMENT);
  496. card->rsq.next = card->rsq.base;
  497. card->rsq.last = card->rsq.base + (NS_RSQ_NUM_ENTRIES - 1);
  498. for (j = 0; j < NS_RSQ_NUM_ENTRIES; j++)
  499. ns_rsqe_init(card->rsq.base + j);
  500. writel(0x00000000, card->membase + RSQH);
  501. writel(ALIGN(card->rsq.dma, NS_RSQ_ALIGNMENT), card->membase + RSQB);
  502. PRINTK("nicstar%d: RSQ base at 0x%p.\n", i, card->rsq.base);
  503. /* Initialize SCQ0, the only VBR SCQ used */
  504. card->scq1 = NULL;
  505. card->scq2 = NULL;
  506. card->scq0 = get_scq(card, VBR_SCQSIZE, NS_VRSCD0);
  507. if (card->scq0 == NULL) {
  508. printk("nicstar%d: can't get SCQ0.\n", i);
  509. error = 12;
  510. ns_init_card_error(card, error);
  511. return error;
  512. }
  513. u32d[0] = scq_virt_to_bus(card->scq0, card->scq0->base);
  514. u32d[1] = (u32) 0x00000000;
  515. u32d[2] = (u32) 0xffffffff;
  516. u32d[3] = (u32) 0x00000000;
  517. ns_write_sram(card, NS_VRSCD0, u32d, 4);
  518. ns_write_sram(card, NS_VRSCD1, u32d, 4); /* These last two won't be used */
  519. ns_write_sram(card, NS_VRSCD2, u32d, 4); /* but are initialized, just in case... */
  520. card->scq0->scd = NS_VRSCD0;
  521. PRINTK("nicstar%d: VBR-SCQ0 base at 0x%p.\n", i, card->scq0->base);
  522. /* Initialize TSTs */
  523. card->tst_addr = NS_TST0;
  524. card->tst_free_entries = NS_TST_NUM_ENTRIES;
  525. data = NS_TST_OPCODE_VARIABLE;
  526. for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
  527. ns_write_sram(card, NS_TST0 + j, &data, 1);
  528. data = ns_tste_make(NS_TST_OPCODE_END, NS_TST0);
  529. ns_write_sram(card, NS_TST0 + NS_TST_NUM_ENTRIES, &data, 1);
  530. for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
  531. ns_write_sram(card, NS_TST1 + j, &data, 1);
  532. data = ns_tste_make(NS_TST_OPCODE_END, NS_TST1);
  533. ns_write_sram(card, NS_TST1 + NS_TST_NUM_ENTRIES, &data, 1);
  534. for (j = 0; j < NS_TST_NUM_ENTRIES; j++)
  535. card->tste2vc[j] = NULL;
  536. writel(NS_TST0 << 2, card->membase + TSTB);
  537. /* Initialize RCT. AAL type is set on opening the VC. */
  538. #ifdef RCQ_SUPPORT
  539. u32d[0] = NS_RCTE_RAWCELLINTEN;
  540. #else
  541. u32d[0] = 0x00000000;
  542. #endif /* RCQ_SUPPORT */
  543. u32d[1] = 0x00000000;
  544. u32d[2] = 0x00000000;
  545. u32d[3] = 0xFFFFFFFF;
  546. for (j = 0; j < card->rct_size; j++)
  547. ns_write_sram(card, j * 4, u32d, 4);
  548. memset(card->vcmap, 0, sizeof(card->vcmap));
  549. for (j = 0; j < NS_FRSCD_NUM; j++)
  550. card->scd2vc[j] = NULL;
  551. /* Initialize buffer levels */
  552. card->sbnr.min = MIN_SB;
  553. card->sbnr.init = NUM_SB;
  554. card->sbnr.max = MAX_SB;
  555. card->lbnr.min = MIN_LB;
  556. card->lbnr.init = NUM_LB;
  557. card->lbnr.max = MAX_LB;
  558. card->iovnr.min = MIN_IOVB;
  559. card->iovnr.init = NUM_IOVB;
  560. card->iovnr.max = MAX_IOVB;
  561. card->hbnr.min = MIN_HB;
  562. card->hbnr.init = NUM_HB;
  563. card->hbnr.max = MAX_HB;
  564. card->sm_handle = NULL;
  565. card->sm_addr = 0x00000000;
  566. card->lg_handle = NULL;
  567. card->lg_addr = 0x00000000;
  568. card->efbie = 1; /* To prevent push_rxbufs from enabling the interrupt */
  569. idr_init(&card->idr);
  570. /* Pre-allocate some huge buffers */
  571. skb_queue_head_init(&card->hbpool.queue);
  572. card->hbpool.count = 0;
  573. for (j = 0; j < NUM_HB; j++) {
  574. struct sk_buff *hb;
  575. hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL);
  576. if (hb == NULL) {
  577. printk
  578. ("nicstar%d: can't allocate %dth of %d huge buffers.\n",
  579. i, j, NUM_HB);
  580. error = 13;
  581. ns_init_card_error(card, error);
  582. return error;
  583. }
  584. NS_PRV_BUFTYPE(hb) = BUF_NONE;
  585. skb_queue_tail(&card->hbpool.queue, hb);
  586. card->hbpool.count++;
  587. }
  588. /* Allocate large buffers */
  589. skb_queue_head_init(&card->lbpool.queue);
  590. card->lbpool.count = 0; /* Not used */
  591. for (j = 0; j < NUM_LB; j++) {
  592. struct sk_buff *lb;
  593. lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL);
  594. if (lb == NULL) {
  595. printk
  596. ("nicstar%d: can't allocate %dth of %d large buffers.\n",
  597. i, j, NUM_LB);
  598. error = 14;
  599. ns_init_card_error(card, error);
  600. return error;
  601. }
  602. NS_PRV_BUFTYPE(lb) = BUF_LG;
  603. skb_queue_tail(&card->lbpool.queue, lb);
  604. skb_reserve(lb, NS_SMBUFSIZE);
  605. push_rxbufs(card, lb);
  606. /* Due to the implementation of push_rxbufs() this is 1, not 0 */
  607. if (j == 1) {
  608. card->rcbuf = lb;
  609. card->rawcell = (struct ns_rcqe *) lb->data;
  610. card->rawch = NS_PRV_DMA(lb);
  611. }
  612. }
  613. /* Test for strange behaviour which leads to crashes */
  614. if ((bcount =
  615. ns_stat_lfbqc_get(readl(card->membase + STAT))) < card->lbnr.min) {
  616. printk
  617. ("nicstar%d: Strange... Just allocated %d large buffers and lfbqc = %d.\n",
  618. i, j, bcount);
  619. error = 14;
  620. ns_init_card_error(card, error);
  621. return error;
  622. }
  623. /* Allocate small buffers */
  624. skb_queue_head_init(&card->sbpool.queue);
  625. card->sbpool.count = 0; /* Not used */
  626. for (j = 0; j < NUM_SB; j++) {
  627. struct sk_buff *sb;
  628. sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL);
  629. if (sb == NULL) {
  630. printk
  631. ("nicstar%d: can't allocate %dth of %d small buffers.\n",
  632. i, j, NUM_SB);
  633. error = 15;
  634. ns_init_card_error(card, error);
  635. return error;
  636. }
  637. NS_PRV_BUFTYPE(sb) = BUF_SM;
  638. skb_queue_tail(&card->sbpool.queue, sb);
  639. skb_reserve(sb, NS_AAL0_HEADER);
  640. push_rxbufs(card, sb);
  641. }
  642. /* Test for strange behaviour which leads to crashes */
  643. if ((bcount =
  644. ns_stat_sfbqc_get(readl(card->membase + STAT))) < card->sbnr.min) {
  645. printk
  646. ("nicstar%d: Strange... Just allocated %d small buffers and sfbqc = %d.\n",
  647. i, j, bcount);
  648. error = 15;
  649. ns_init_card_error(card, error);
  650. return error;
  651. }
  652. /* Allocate iovec buffers */
  653. skb_queue_head_init(&card->iovpool.queue);
  654. card->iovpool.count = 0;
  655. for (j = 0; j < NUM_IOVB; j++) {
  656. struct sk_buff *iovb;
  657. iovb = alloc_skb(NS_IOVBUFSIZE, GFP_KERNEL);
  658. if (iovb == NULL) {
  659. printk
  660. ("nicstar%d: can't allocate %dth of %d iovec buffers.\n",
  661. i, j, NUM_IOVB);
  662. error = 16;
  663. ns_init_card_error(card, error);
  664. return error;
  665. }
  666. NS_PRV_BUFTYPE(iovb) = BUF_NONE;
  667. skb_queue_tail(&card->iovpool.queue, iovb);
  668. card->iovpool.count++;
  669. }
  670. /* Configure NICStAR */
  671. if (card->rct_size == 4096)
  672. ns_cfg_rctsize = NS_CFG_RCTSIZE_4096_ENTRIES;
  673. else /* (card->rct_size == 16384) */
  674. ns_cfg_rctsize = NS_CFG_RCTSIZE_16384_ENTRIES;
  675. card->efbie = 1;
  676. /* Register device */
  677. card->atmdev = atm_dev_register("nicstar", &card->pcidev->dev, &atm_ops,
  678. -1, NULL);
  679. if (card->atmdev == NULL) {
  680. printk("nicstar%d: can't register device.\n", i);
  681. error = 17;
  682. ns_init_card_error(card, error);
  683. return error;
  684. }
  685. if (mac[i] == NULL || !mac_pton(mac[i], card->atmdev->esi)) {
  686. nicstar_read_eprom(card->membase, NICSTAR_EPROM_MAC_ADDR_OFFSET,
  687. card->atmdev->esi, 6);
  688. if (ether_addr_equal(card->atmdev->esi, "\x00\x00\x00\x00\x00\x00")) {
  689. nicstar_read_eprom(card->membase,
  690. NICSTAR_EPROM_MAC_ADDR_OFFSET_ALT,
  691. card->atmdev->esi, 6);
  692. }
  693. }
  694. printk("nicstar%d: MAC address %pM\n", i, card->atmdev->esi);
  695. card->atmdev->dev_data = card;
  696. card->atmdev->ci_range.vpi_bits = card->vpibits;
  697. card->atmdev->ci_range.vci_bits = card->vcibits;
  698. card->atmdev->link_rate = card->max_pcr;
  699. card->atmdev->phy = NULL;
  700. #ifdef CONFIG_ATM_NICSTAR_USE_SUNI
  701. if (card->max_pcr == ATM_OC3_PCR)
  702. suni_init(card->atmdev);
  703. #endif /* CONFIG_ATM_NICSTAR_USE_SUNI */
  704. #ifdef CONFIG_ATM_NICSTAR_USE_IDT77105
  705. if (card->max_pcr == ATM_25_PCR)
  706. idt77105_init(card->atmdev);
  707. #endif /* CONFIG_ATM_NICSTAR_USE_IDT77105 */
  708. if (card->atmdev->phy && card->atmdev->phy->start)
  709. card->atmdev->phy->start(card->atmdev);
  710. writel(NS_CFG_RXPATH | NS_CFG_SMBUFSIZE | NS_CFG_LGBUFSIZE | NS_CFG_EFBIE | NS_CFG_RSQSIZE | NS_CFG_VPIBITS | ns_cfg_rctsize | NS_CFG_RXINT_NODELAY | NS_CFG_RAWIE | /* Only enabled if RCQ_SUPPORT */
  711. NS_CFG_RSQAFIE | NS_CFG_TXEN | NS_CFG_TXIE | NS_CFG_TSQFIE_OPT | /* Only enabled if ENABLE_TSQFIE */
  712. NS_CFG_PHYIE, card->membase + CFG);
  713. num_cards++;
  714. return error;
  715. }
  716. static void ns_init_card_error(ns_dev *card, int error)
  717. {
  718. if (error >= 17) {
  719. writel(0x00000000, card->membase + CFG);
  720. }
  721. if (error >= 16) {
  722. struct sk_buff *iovb;
  723. while ((iovb = skb_dequeue(&card->iovpool.queue)) != NULL)
  724. dev_kfree_skb_any(iovb);
  725. }
  726. if (error >= 15) {
  727. struct sk_buff *sb;
  728. while ((sb = skb_dequeue(&card->sbpool.queue)) != NULL)
  729. dev_kfree_skb_any(sb);
  730. free_scq(card, card->scq0, NULL);
  731. }
  732. if (error >= 14) {
  733. struct sk_buff *lb;
  734. while ((lb = skb_dequeue(&card->lbpool.queue)) != NULL)
  735. dev_kfree_skb_any(lb);
  736. }
  737. if (error >= 13) {
  738. struct sk_buff *hb;
  739. while ((hb = skb_dequeue(&card->hbpool.queue)) != NULL)
  740. dev_kfree_skb_any(hb);
  741. }
  742. if (error >= 12) {
  743. dma_free_coherent(&card->pcidev->dev, NS_RSQSIZE + NS_RSQ_ALIGNMENT,
  744. card->rsq.org, card->rsq.dma);
  745. }
  746. if (error >= 11) {
  747. dma_free_coherent(&card->pcidev->dev, NS_TSQSIZE + NS_TSQ_ALIGNMENT,
  748. card->tsq.org, card->tsq.dma);
  749. }
  750. if (error >= 10) {
  751. free_irq(card->pcidev->irq, card);
  752. }
  753. if (error >= 4) {
  754. iounmap(card->membase);
  755. }
  756. if (error >= 3) {
  757. pci_disable_device(card->pcidev);
  758. kfree(card);
  759. }
  760. }
  761. static scq_info *get_scq(ns_dev *card, int size, u32 scd)
  762. {
  763. scq_info *scq;
  764. int i;
  765. if (size != VBR_SCQSIZE && size != CBR_SCQSIZE)
  766. return NULL;
  767. scq = kmalloc(sizeof(*scq), GFP_KERNEL);
  768. if (!scq)
  769. return NULL;
  770. scq->org = dma_alloc_coherent(&card->pcidev->dev,
  771. 2 * size, &scq->dma, GFP_KERNEL);
  772. if (!scq->org) {
  773. kfree(scq);
  774. return NULL;
  775. }
  776. scq->skb = kmalloc_array(size / NS_SCQE_SIZE,
  777. sizeof(*scq->skb),
  778. GFP_KERNEL);
  779. if (!scq->skb) {
  780. dma_free_coherent(&card->pcidev->dev,
  781. 2 * size, scq->org, scq->dma);
  782. kfree(scq);
  783. return NULL;
  784. }
  785. scq->num_entries = size / NS_SCQE_SIZE;
  786. scq->base = PTR_ALIGN(scq->org, size);
  787. scq->next = scq->base;
  788. scq->last = scq->base + (scq->num_entries - 1);
  789. scq->tail = scq->last;
  790. scq->scd = scd;
  791. scq->num_entries = size / NS_SCQE_SIZE;
  792. scq->tbd_count = 0;
  793. init_waitqueue_head(&scq->scqfull_waitq);
  794. scq->full = 0;
  795. spin_lock_init(&scq->lock);
  796. for (i = 0; i < scq->num_entries; i++)
  797. scq->skb[i] = NULL;
  798. return scq;
  799. }
  800. /* For variable rate SCQ vcc must be NULL */
  801. static void free_scq(ns_dev *card, scq_info *scq, struct atm_vcc *vcc)
  802. {
  803. int i;
  804. if (scq->num_entries == VBR_SCQ_NUM_ENTRIES)
  805. for (i = 0; i < scq->num_entries; i++) {
  806. if (scq->skb[i] != NULL) {
  807. vcc = ATM_SKB(scq->skb[i])->vcc;
  808. if (vcc->pop != NULL)
  809. vcc->pop(vcc, scq->skb[i]);
  810. else
  811. dev_kfree_skb_any(scq->skb[i]);
  812. }
  813. } else { /* vcc must be != NULL */
  814. if (vcc == NULL) {
  815. printk
  816. ("nicstar: free_scq() called with vcc == NULL for fixed rate scq.");
  817. for (i = 0; i < scq->num_entries; i++)
  818. dev_kfree_skb_any(scq->skb[i]);
  819. } else
  820. for (i = 0; i < scq->num_entries; i++) {
  821. if (scq->skb[i] != NULL) {
  822. if (vcc->pop != NULL)
  823. vcc->pop(vcc, scq->skb[i]);
  824. else
  825. dev_kfree_skb_any(scq->skb[i]);
  826. }
  827. }
  828. }
  829. kfree(scq->skb);
  830. dma_free_coherent(&card->pcidev->dev,
  831. 2 * (scq->num_entries == VBR_SCQ_NUM_ENTRIES ?
  832. VBR_SCQSIZE : CBR_SCQSIZE),
  833. scq->org, scq->dma);
  834. kfree(scq);
  835. }
  836. /* The handles passed must be pointers to the sk_buff containing the small
  837. or large buffer(s) cast to u32. */
  838. static void push_rxbufs(ns_dev * card, struct sk_buff *skb)
  839. {
  840. struct sk_buff *handle1, *handle2;
  841. int id1, id2;
  842. u32 addr1, addr2;
  843. u32 stat;
  844. unsigned long flags;
  845. /* *BARF* */
  846. handle2 = NULL;
  847. addr2 = 0;
  848. handle1 = skb;
  849. addr1 = dma_map_single(&card->pcidev->dev,
  850. skb->data,
  851. (NS_PRV_BUFTYPE(skb) == BUF_SM
  852. ? NS_SMSKBSIZE : NS_LGSKBSIZE),
  853. DMA_TO_DEVICE);
  854. NS_PRV_DMA(skb) = addr1; /* save so we can unmap later */
  855. #ifdef GENERAL_DEBUG
  856. if (!addr1)
  857. printk("nicstar%d: push_rxbufs called with addr1 = 0.\n",
  858. card->index);
  859. #endif /* GENERAL_DEBUG */
  860. stat = readl(card->membase + STAT);
  861. card->sbfqc = ns_stat_sfbqc_get(stat);
  862. card->lbfqc = ns_stat_lfbqc_get(stat);
  863. if (NS_PRV_BUFTYPE(skb) == BUF_SM) {
  864. if (!addr2) {
  865. if (card->sm_addr) {
  866. addr2 = card->sm_addr;
  867. handle2 = card->sm_handle;
  868. card->sm_addr = 0x00000000;
  869. card->sm_handle = NULL;
  870. } else { /* (!sm_addr) */
  871. card->sm_addr = addr1;
  872. card->sm_handle = handle1;
  873. }
  874. }
  875. } else { /* buf_type == BUF_LG */
  876. if (!addr2) {
  877. if (card->lg_addr) {
  878. addr2 = card->lg_addr;
  879. handle2 = card->lg_handle;
  880. card->lg_addr = 0x00000000;
  881. card->lg_handle = NULL;
  882. } else { /* (!lg_addr) */
  883. card->lg_addr = addr1;
  884. card->lg_handle = handle1;
  885. }
  886. }
  887. }
  888. if (addr2) {
  889. if (NS_PRV_BUFTYPE(skb) == BUF_SM) {
  890. if (card->sbfqc >= card->sbnr.max) {
  891. skb_unlink(handle1, &card->sbpool.queue);
  892. dev_kfree_skb_any(handle1);
  893. skb_unlink(handle2, &card->sbpool.queue);
  894. dev_kfree_skb_any(handle2);
  895. return;
  896. } else
  897. card->sbfqc += 2;
  898. } else { /* (buf_type == BUF_LG) */
  899. if (card->lbfqc >= card->lbnr.max) {
  900. skb_unlink(handle1, &card->lbpool.queue);
  901. dev_kfree_skb_any(handle1);
  902. skb_unlink(handle2, &card->lbpool.queue);
  903. dev_kfree_skb_any(handle2);
  904. return;
  905. } else
  906. card->lbfqc += 2;
  907. }
  908. id1 = idr_alloc(&card->idr, handle1, 0, 0, GFP_ATOMIC);
  909. if (id1 < 0)
  910. goto out;
  911. id2 = idr_alloc(&card->idr, handle2, 0, 0, GFP_ATOMIC);
  912. if (id2 < 0)
  913. goto out;
  914. spin_lock_irqsave(&card->res_lock, flags);
  915. while (CMD_BUSY(card)) ;
  916. writel(addr2, card->membase + DR3);
  917. writel(id2, card->membase + DR2);
  918. writel(addr1, card->membase + DR1);
  919. writel(id1, card->membase + DR0);
  920. writel(NS_CMD_WRITE_FREEBUFQ | NS_PRV_BUFTYPE(skb),
  921. card->membase + CMD);
  922. spin_unlock_irqrestore(&card->res_lock, flags);
  923. XPRINTK("nicstar%d: Pushing %s buffers at 0x%x and 0x%x.\n",
  924. card->index,
  925. (NS_PRV_BUFTYPE(skb) == BUF_SM ? "small" : "large"),
  926. addr1, addr2);
  927. }
  928. if (!card->efbie && card->sbfqc >= card->sbnr.min &&
  929. card->lbfqc >= card->lbnr.min) {
  930. card->efbie = 1;
  931. writel((readl(card->membase + CFG) | NS_CFG_EFBIE),
  932. card->membase + CFG);
  933. }
  934. out:
  935. return;
  936. }
  937. static irqreturn_t ns_irq_handler(int irq, void *dev_id)
  938. {
  939. u32 stat_r;
  940. ns_dev *card;
  941. struct atm_dev *dev;
  942. unsigned long flags;
  943. card = (ns_dev *) dev_id;
  944. dev = card->atmdev;
  945. card->intcnt++;
  946. PRINTK("nicstar%d: NICStAR generated an interrupt\n", card->index);
  947. spin_lock_irqsave(&card->int_lock, flags);
  948. stat_r = readl(card->membase + STAT);
  949. /* Transmit Status Indicator has been written to T. S. Queue */
  950. if (stat_r & NS_STAT_TSIF) {
  951. TXPRINTK("nicstar%d: TSI interrupt\n", card->index);
  952. process_tsq(card);
  953. writel(NS_STAT_TSIF, card->membase + STAT);
  954. }
  955. /* Incomplete CS-PDU has been transmitted */
  956. if (stat_r & NS_STAT_TXICP) {
  957. writel(NS_STAT_TXICP, card->membase + STAT);
  958. TXPRINTK("nicstar%d: Incomplete CS-PDU transmitted.\n",
  959. card->index);
  960. }
  961. /* Transmit Status Queue 7/8 full */
  962. if (stat_r & NS_STAT_TSQF) {
  963. writel(NS_STAT_TSQF, card->membase + STAT);
  964. PRINTK("nicstar%d: TSQ full.\n", card->index);
  965. process_tsq(card);
  966. }
  967. /* Timer overflow */
  968. if (stat_r & NS_STAT_TMROF) {
  969. writel(NS_STAT_TMROF, card->membase + STAT);
  970. PRINTK("nicstar%d: Timer overflow.\n", card->index);
  971. }
  972. /* PHY device interrupt signal active */
  973. if (stat_r & NS_STAT_PHYI) {
  974. writel(NS_STAT_PHYI, card->membase + STAT);
  975. PRINTK("nicstar%d: PHY interrupt.\n", card->index);
  976. if (dev->phy && dev->phy->interrupt) {
  977. dev->phy->interrupt(dev);
  978. }
  979. }
  980. /* Small Buffer Queue is full */
  981. if (stat_r & NS_STAT_SFBQF) {
  982. writel(NS_STAT_SFBQF, card->membase + STAT);
  983. printk("nicstar%d: Small free buffer queue is full.\n",
  984. card->index);
  985. }
  986. /* Large Buffer Queue is full */
  987. if (stat_r & NS_STAT_LFBQF) {
  988. writel(NS_STAT_LFBQF, card->membase + STAT);
  989. printk("nicstar%d: Large free buffer queue is full.\n",
  990. card->index);
  991. }
  992. /* Receive Status Queue is full */
  993. if (stat_r & NS_STAT_RSQF) {
  994. writel(NS_STAT_RSQF, card->membase + STAT);
  995. printk("nicstar%d: RSQ full.\n", card->index);
  996. process_rsq(card);
  997. }
  998. /* Complete CS-PDU received */
  999. if (stat_r & NS_STAT_EOPDU) {
  1000. RXPRINTK("nicstar%d: End of CS-PDU received.\n", card->index);
  1001. process_rsq(card);
  1002. writel(NS_STAT_EOPDU, card->membase + STAT);
  1003. }
  1004. /* Raw cell received */
  1005. if (stat_r & NS_STAT_RAWCF) {
  1006. writel(NS_STAT_RAWCF, card->membase + STAT);
  1007. #ifndef RCQ_SUPPORT
  1008. printk("nicstar%d: Raw cell received and no support yet...\n",
  1009. card->index);
  1010. #endif /* RCQ_SUPPORT */
  1011. /* NOTE: the following procedure may keep a raw cell pending until the
  1012. next interrupt. As this preliminary support is only meant to
  1013. avoid buffer leakage, this is not an issue. */
  1014. while (readl(card->membase + RAWCT) != card->rawch) {
  1015. if (ns_rcqe_islast(card->rawcell)) {
  1016. struct sk_buff *oldbuf;
  1017. oldbuf = card->rcbuf;
  1018. card->rcbuf = idr_find(&card->idr,
  1019. ns_rcqe_nextbufhandle(card->rawcell));
  1020. card->rawch = NS_PRV_DMA(card->rcbuf);
  1021. card->rawcell = (struct ns_rcqe *)
  1022. card->rcbuf->data;
  1023. recycle_rx_buf(card, oldbuf);
  1024. } else {
  1025. card->rawch += NS_RCQE_SIZE;
  1026. card->rawcell++;
  1027. }
  1028. }
  1029. }
  1030. /* Small buffer queue is empty */
  1031. if (stat_r & NS_STAT_SFBQE) {
  1032. int i;
  1033. struct sk_buff *sb;
  1034. writel(NS_STAT_SFBQE, card->membase + STAT);
  1035. printk("nicstar%d: Small free buffer queue empty.\n",
  1036. card->index);
  1037. for (i = 0; i < card->sbnr.min; i++) {
  1038. sb = dev_alloc_skb(NS_SMSKBSIZE);
  1039. if (sb == NULL) {
  1040. writel(readl(card->membase + CFG) &
  1041. ~NS_CFG_EFBIE, card->membase + CFG);
  1042. card->efbie = 0;
  1043. break;
  1044. }
  1045. NS_PRV_BUFTYPE(sb) = BUF_SM;
  1046. skb_queue_tail(&card->sbpool.queue, sb);
  1047. skb_reserve(sb, NS_AAL0_HEADER);
  1048. push_rxbufs(card, sb);
  1049. }
  1050. card->sbfqc = i;
  1051. process_rsq(card);
  1052. }
  1053. /* Large buffer queue empty */
  1054. if (stat_r & NS_STAT_LFBQE) {
  1055. int i;
  1056. struct sk_buff *lb;
  1057. writel(NS_STAT_LFBQE, card->membase + STAT);
  1058. printk("nicstar%d: Large free buffer queue empty.\n",
  1059. card->index);
  1060. for (i = 0; i < card->lbnr.min; i++) {
  1061. lb = dev_alloc_skb(NS_LGSKBSIZE);
  1062. if (lb == NULL) {
  1063. writel(readl(card->membase + CFG) &
  1064. ~NS_CFG_EFBIE, card->membase + CFG);
  1065. card->efbie = 0;
  1066. break;
  1067. }
  1068. NS_PRV_BUFTYPE(lb) = BUF_LG;
  1069. skb_queue_tail(&card->lbpool.queue, lb);
  1070. skb_reserve(lb, NS_SMBUFSIZE);
  1071. push_rxbufs(card, lb);
  1072. }
  1073. card->lbfqc = i;
  1074. process_rsq(card);
  1075. }
  1076. /* Receive Status Queue is 7/8 full */
  1077. if (stat_r & NS_STAT_RSQAF) {
  1078. writel(NS_STAT_RSQAF, card->membase + STAT);
  1079. RXPRINTK("nicstar%d: RSQ almost full.\n", card->index);
  1080. process_rsq(card);
  1081. }
  1082. spin_unlock_irqrestore(&card->int_lock, flags);
  1083. PRINTK("nicstar%d: end of interrupt service\n", card->index);
  1084. return IRQ_HANDLED;
  1085. }
  1086. static int ns_open(struct atm_vcc *vcc)
  1087. {
  1088. ns_dev *card;
  1089. vc_map *vc;
  1090. unsigned long tmpl, modl;
  1091. int tcr, tcra; /* target cell rate, and absolute value */
  1092. int n = 0; /* Number of entries in the TST. Initialized to remove
  1093. the compiler warning. */
  1094. u32 u32d[4];
  1095. int frscdi = 0; /* Index of the SCD. Initialized to remove the compiler
  1096. warning. How I wish compilers were clever enough to
  1097. tell which variables can truly be used
  1098. uninitialized... */
  1099. int inuse; /* tx or rx vc already in use by another vcc */
  1100. short vpi = vcc->vpi;
  1101. int vci = vcc->vci;
  1102. card = (ns_dev *) vcc->dev->dev_data;
  1103. PRINTK("nicstar%d: opening vpi.vci %d.%d \n", card->index, (int)vpi,
  1104. vci);
  1105. if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
  1106. PRINTK("nicstar%d: unsupported AAL.\n", card->index);
  1107. return -EINVAL;
  1108. }
  1109. vc = &(card->vcmap[vpi << card->vcibits | vci]);
  1110. vcc->dev_data = vc;
  1111. inuse = 0;
  1112. if (vcc->qos.txtp.traffic_class != ATM_NONE && vc->tx)
  1113. inuse = 1;
  1114. if (vcc->qos.rxtp.traffic_class != ATM_NONE && vc->rx)
  1115. inuse += 2;
  1116. if (inuse) {
  1117. printk("nicstar%d: %s vci already in use.\n", card->index,
  1118. inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx");
  1119. return -EINVAL;
  1120. }
  1121. set_bit(ATM_VF_ADDR, &vcc->flags);
  1122. /* NOTE: You are not allowed to modify an open connection's QOS. To change
  1123. that, remove the ATM_VF_PARTIAL flag checking. There may be other changes
  1124. needed to do that. */
  1125. if (!test_bit(ATM_VF_PARTIAL, &vcc->flags)) {
  1126. scq_info *scq;
  1127. set_bit(ATM_VF_PARTIAL, &vcc->flags);
  1128. if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  1129. /* Check requested cell rate and availability of SCD */
  1130. if (vcc->qos.txtp.max_pcr == 0 && vcc->qos.txtp.pcr == 0
  1131. && vcc->qos.txtp.min_pcr == 0) {
  1132. PRINTK
  1133. ("nicstar%d: trying to open a CBR vc with cell rate = 0 \n",
  1134. card->index);
  1135. clear_bit(ATM_VF_PARTIAL, &vcc->flags);
  1136. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1137. return -EINVAL;
  1138. }
  1139. tcr = atm_pcr_goal(&(vcc->qos.txtp));
  1140. tcra = tcr >= 0 ? tcr : -tcr;
  1141. PRINTK("nicstar%d: target cell rate = %d.\n",
  1142. card->index, vcc->qos.txtp.max_pcr);
  1143. tmpl =
  1144. (unsigned long)tcra *(unsigned long)
  1145. NS_TST_NUM_ENTRIES;
  1146. modl = tmpl % card->max_pcr;
  1147. n = (int)(tmpl / card->max_pcr);
  1148. if (tcr > 0) {
  1149. if (modl > 0)
  1150. n++;
  1151. } else if (tcr == 0) {
  1152. if ((n =
  1153. (card->tst_free_entries -
  1154. NS_TST_RESERVED)) <= 0) {
  1155. PRINTK
  1156. ("nicstar%d: no CBR bandwidth free.\n",
  1157. card->index);
  1158. clear_bit(ATM_VF_PARTIAL, &vcc->flags);
  1159. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1160. return -EINVAL;
  1161. }
  1162. }
  1163. if (n == 0) {
  1164. printk
  1165. ("nicstar%d: selected bandwidth < granularity.\n",
  1166. card->index);
  1167. clear_bit(ATM_VF_PARTIAL, &vcc->flags);
  1168. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1169. return -EINVAL;
  1170. }
  1171. if (n > (card->tst_free_entries - NS_TST_RESERVED)) {
  1172. PRINTK
  1173. ("nicstar%d: not enough free CBR bandwidth.\n",
  1174. card->index);
  1175. clear_bit(ATM_VF_PARTIAL, &vcc->flags);
  1176. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1177. return -EINVAL;
  1178. } else
  1179. card->tst_free_entries -= n;
  1180. XPRINTK("nicstar%d: writing %d tst entries.\n",
  1181. card->index, n);
  1182. for (frscdi = 0; frscdi < NS_FRSCD_NUM; frscdi++) {
  1183. if (card->scd2vc[frscdi] == NULL) {
  1184. card->scd2vc[frscdi] = vc;
  1185. break;
  1186. }
  1187. }
  1188. if (frscdi == NS_FRSCD_NUM) {
  1189. PRINTK
  1190. ("nicstar%d: no SCD available for CBR channel.\n",
  1191. card->index);
  1192. card->tst_free_entries += n;
  1193. clear_bit(ATM_VF_PARTIAL, &vcc->flags);
  1194. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1195. return -EBUSY;
  1196. }
  1197. vc->cbr_scd = NS_FRSCD + frscdi * NS_FRSCD_SIZE;
  1198. scq = get_scq(card, CBR_SCQSIZE, vc->cbr_scd);
  1199. if (scq == NULL) {
  1200. PRINTK("nicstar%d: can't get fixed rate SCQ.\n",
  1201. card->index);
  1202. card->scd2vc[frscdi] = NULL;
  1203. card->tst_free_entries += n;
  1204. clear_bit(ATM_VF_PARTIAL, &vcc->flags);
  1205. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1206. return -ENOMEM;
  1207. }
  1208. vc->scq = scq;
  1209. u32d[0] = scq_virt_to_bus(scq, scq->base);
  1210. u32d[1] = (u32) 0x00000000;
  1211. u32d[2] = (u32) 0xffffffff;
  1212. u32d[3] = (u32) 0x00000000;
  1213. ns_write_sram(card, vc->cbr_scd, u32d, 4);
  1214. fill_tst(card, n, vc);
  1215. } else if (vcc->qos.txtp.traffic_class == ATM_UBR) {
  1216. vc->cbr_scd = 0x00000000;
  1217. vc->scq = card->scq0;
  1218. }
  1219. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  1220. vc->tx = 1;
  1221. vc->tx_vcc = vcc;
  1222. vc->tbd_count = 0;
  1223. }
  1224. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  1225. u32 status;
  1226. vc->rx = 1;
  1227. vc->rx_vcc = vcc;
  1228. vc->rx_iov = NULL;
  1229. /* Open the connection in hardware */
  1230. if (vcc->qos.aal == ATM_AAL5)
  1231. status = NS_RCTE_AAL5 | NS_RCTE_CONNECTOPEN;
  1232. else /* vcc->qos.aal == ATM_AAL0 */
  1233. status = NS_RCTE_AAL0 | NS_RCTE_CONNECTOPEN;
  1234. #ifdef RCQ_SUPPORT
  1235. status |= NS_RCTE_RAWCELLINTEN;
  1236. #endif /* RCQ_SUPPORT */
  1237. ns_write_sram(card,
  1238. NS_RCT +
  1239. (vpi << card->vcibits | vci) *
  1240. NS_RCT_ENTRY_SIZE, &status, 1);
  1241. }
  1242. }
  1243. set_bit(ATM_VF_READY, &vcc->flags);
  1244. return 0;
  1245. }
  1246. static void ns_close(struct atm_vcc *vcc)
  1247. {
  1248. vc_map *vc;
  1249. ns_dev *card;
  1250. u32 data;
  1251. int i;
  1252. vc = vcc->dev_data;
  1253. card = vcc->dev->dev_data;
  1254. PRINTK("nicstar%d: closing vpi.vci %d.%d \n", card->index,
  1255. (int)vcc->vpi, vcc->vci);
  1256. clear_bit(ATM_VF_READY, &vcc->flags);
  1257. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  1258. u32 addr;
  1259. unsigned long flags;
  1260. addr =
  1261. NS_RCT +
  1262. (vcc->vpi << card->vcibits | vcc->vci) * NS_RCT_ENTRY_SIZE;
  1263. spin_lock_irqsave(&card->res_lock, flags);
  1264. while (CMD_BUSY(card)) ;
  1265. writel(NS_CMD_CLOSE_CONNECTION | addr << 2,
  1266. card->membase + CMD);
  1267. spin_unlock_irqrestore(&card->res_lock, flags);
  1268. vc->rx = 0;
  1269. if (vc->rx_iov != NULL) {
  1270. struct sk_buff *iovb;
  1271. u32 stat;
  1272. stat = readl(card->membase + STAT);
  1273. card->sbfqc = ns_stat_sfbqc_get(stat);
  1274. card->lbfqc = ns_stat_lfbqc_get(stat);
  1275. PRINTK
  1276. ("nicstar%d: closing a VC with pending rx buffers.\n",
  1277. card->index);
  1278. iovb = vc->rx_iov;
  1279. recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
  1280. NS_PRV_IOVCNT(iovb));
  1281. NS_PRV_IOVCNT(iovb) = 0;
  1282. spin_lock_irqsave(&card->int_lock, flags);
  1283. recycle_iov_buf(card, iovb);
  1284. spin_unlock_irqrestore(&card->int_lock, flags);
  1285. vc->rx_iov = NULL;
  1286. }
  1287. }
  1288. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  1289. vc->tx = 0;
  1290. }
  1291. if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  1292. unsigned long flags;
  1293. ns_scqe *scqep;
  1294. scq_info *scq;
  1295. scq = vc->scq;
  1296. for (;;) {
  1297. spin_lock_irqsave(&scq->lock, flags);
  1298. scqep = scq->next;
  1299. if (scqep == scq->base)
  1300. scqep = scq->last;
  1301. else
  1302. scqep--;
  1303. if (scqep == scq->tail) {
  1304. spin_unlock_irqrestore(&scq->lock, flags);
  1305. break;
  1306. }
  1307. /* If the last entry is not a TSR, place one in the SCQ in order to
  1308. be able to completely drain it and then close. */
  1309. if (!ns_scqe_is_tsr(scqep) && scq->tail != scq->next) {
  1310. ns_scqe tsr;
  1311. u32 scdi, scqi;
  1312. u32 data;
  1313. int index;
  1314. tsr.word_1 = ns_tsr_mkword_1(NS_TSR_INTENABLE);
  1315. scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE;
  1316. scqi = scq->next - scq->base;
  1317. tsr.word_2 = ns_tsr_mkword_2(scdi, scqi);
  1318. tsr.word_3 = 0x00000000;
  1319. tsr.word_4 = 0x00000000;
  1320. *scq->next = tsr;
  1321. index = (int)scqi;
  1322. scq->skb[index] = NULL;
  1323. if (scq->next == scq->last)
  1324. scq->next = scq->base;
  1325. else
  1326. scq->next++;
  1327. data = scq_virt_to_bus(scq, scq->next);
  1328. ns_write_sram(card, scq->scd, &data, 1);
  1329. }
  1330. spin_unlock_irqrestore(&scq->lock, flags);
  1331. schedule();
  1332. }
  1333. /* Free all TST entries */
  1334. data = NS_TST_OPCODE_VARIABLE;
  1335. for (i = 0; i < NS_TST_NUM_ENTRIES; i++) {
  1336. if (card->tste2vc[i] == vc) {
  1337. ns_write_sram(card, card->tst_addr + i, &data,
  1338. 1);
  1339. card->tste2vc[i] = NULL;
  1340. card->tst_free_entries++;
  1341. }
  1342. }
  1343. card->scd2vc[(vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE] = NULL;
  1344. free_scq(card, vc->scq, vcc);
  1345. }
  1346. /* remove all references to vcc before deleting it */
  1347. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  1348. unsigned long flags;
  1349. scq_info *scq = card->scq0;
  1350. spin_lock_irqsave(&scq->lock, flags);
  1351. for (i = 0; i < scq->num_entries; i++) {
  1352. if (scq->skb[i] && ATM_SKB(scq->skb[i])->vcc == vcc) {
  1353. ATM_SKB(scq->skb[i])->vcc = NULL;
  1354. atm_return(vcc, scq->skb[i]->truesize);
  1355. PRINTK
  1356. ("nicstar: deleted pending vcc mapping\n");
  1357. }
  1358. }
  1359. spin_unlock_irqrestore(&scq->lock, flags);
  1360. }
  1361. vcc->dev_data = NULL;
  1362. clear_bit(ATM_VF_PARTIAL, &vcc->flags);
  1363. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1364. #ifdef RX_DEBUG
  1365. {
  1366. u32 stat, cfg;
  1367. stat = readl(card->membase + STAT);
  1368. cfg = readl(card->membase + CFG);
  1369. printk("STAT = 0x%08X CFG = 0x%08X \n", stat, cfg);
  1370. printk
  1371. ("TSQ: base = 0x%p next = 0x%p last = 0x%p TSQT = 0x%08X \n",
  1372. card->tsq.base, card->tsq.next,
  1373. card->tsq.last, readl(card->membase + TSQT));
  1374. printk
  1375. ("RSQ: base = 0x%p next = 0x%p last = 0x%p RSQT = 0x%08X \n",
  1376. card->rsq.base, card->rsq.next,
  1377. card->rsq.last, readl(card->membase + RSQT));
  1378. printk("Empty free buffer queue interrupt %s \n",
  1379. card->efbie ? "enabled" : "disabled");
  1380. printk("SBCNT = %d count = %d LBCNT = %d count = %d \n",
  1381. ns_stat_sfbqc_get(stat), card->sbpool.count,
  1382. ns_stat_lfbqc_get(stat), card->lbpool.count);
  1383. printk("hbpool.count = %d iovpool.count = %d \n",
  1384. card->hbpool.count, card->iovpool.count);
  1385. }
  1386. #endif /* RX_DEBUG */
  1387. }
  1388. static void fill_tst(ns_dev * card, int n, vc_map * vc)
  1389. {
  1390. u32 new_tst;
  1391. unsigned long cl;
  1392. int e, r;
  1393. u32 data;
  1394. /* It would be very complicated to keep the two TSTs synchronized while
  1395. assuring that writes are only made to the inactive TST. So, for now I
  1396. will use only one TST. If problems occur, I will change this again */
  1397. new_tst = card->tst_addr;
  1398. /* Fill procedure */
  1399. for (e = 0; e < NS_TST_NUM_ENTRIES; e++) {
  1400. if (card->tste2vc[e] == NULL)
  1401. break;
  1402. }
  1403. if (e == NS_TST_NUM_ENTRIES) {
  1404. printk("nicstar%d: No free TST entries found. \n", card->index);
  1405. return;
  1406. }
  1407. r = n;
  1408. cl = NS_TST_NUM_ENTRIES;
  1409. data = ns_tste_make(NS_TST_OPCODE_FIXED, vc->cbr_scd);
  1410. while (r > 0) {
  1411. if (cl >= NS_TST_NUM_ENTRIES && card->tste2vc[e] == NULL) {
  1412. card->tste2vc[e] = vc;
  1413. ns_write_sram(card, new_tst + e, &data, 1);
  1414. cl -= NS_TST_NUM_ENTRIES;
  1415. r--;
  1416. }
  1417. if (++e == NS_TST_NUM_ENTRIES) {
  1418. e = 0;
  1419. }
  1420. cl += n;
  1421. }
  1422. /* End of fill procedure */
  1423. data = ns_tste_make(NS_TST_OPCODE_END, new_tst);
  1424. ns_write_sram(card, new_tst + NS_TST_NUM_ENTRIES, &data, 1);
  1425. ns_write_sram(card, card->tst_addr + NS_TST_NUM_ENTRIES, &data, 1);
  1426. card->tst_addr = new_tst;
  1427. }
  1428. static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
  1429. {
  1430. ns_dev *card;
  1431. vc_map *vc;
  1432. scq_info *scq;
  1433. unsigned long buflen;
  1434. ns_scqe scqe;
  1435. u32 flags; /* TBD flags, not CPU flags */
  1436. card = vcc->dev->dev_data;
  1437. TXPRINTK("nicstar%d: ns_send() called.\n", card->index);
  1438. if ((vc = (vc_map *) vcc->dev_data) == NULL) {
  1439. printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
  1440. card->index);
  1441. atomic_inc(&vcc->stats->tx_err);
  1442. dev_kfree_skb_any(skb);
  1443. return -EINVAL;
  1444. }
  1445. if (!vc->tx) {
  1446. printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
  1447. card->index);
  1448. atomic_inc(&vcc->stats->tx_err);
  1449. dev_kfree_skb_any(skb);
  1450. return -EINVAL;
  1451. }
  1452. if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
  1453. printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
  1454. card->index);
  1455. atomic_inc(&vcc->stats->tx_err);
  1456. dev_kfree_skb_any(skb);
  1457. return -EINVAL;
  1458. }
  1459. if (skb_shinfo(skb)->nr_frags != 0) {
  1460. printk("nicstar%d: No scatter-gather yet.\n", card->index);
  1461. atomic_inc(&vcc->stats->tx_err);
  1462. dev_kfree_skb_any(skb);
  1463. return -EINVAL;
  1464. }
  1465. ATM_SKB(skb)->vcc = vcc;
  1466. NS_PRV_DMA(skb) = dma_map_single(&card->pcidev->dev, skb->data,
  1467. skb->len, DMA_TO_DEVICE);
  1468. if (vcc->qos.aal == ATM_AAL5) {
  1469. buflen = (skb->len + 47 + 8) / 48 * 48; /* Multiple of 48 */
  1470. flags = NS_TBD_AAL5;
  1471. scqe.word_2 = cpu_to_le32(NS_PRV_DMA(skb));
  1472. scqe.word_3 = cpu_to_le32(skb->len);
  1473. scqe.word_4 =
  1474. ns_tbd_mkword_4(0, (u32) vcc->vpi, (u32) vcc->vci, 0,
  1475. ATM_SKB(skb)->
  1476. atm_options & ATM_ATMOPT_CLP ? 1 : 0);
  1477. flags |= NS_TBD_EOPDU;
  1478. } else { /* (vcc->qos.aal == ATM_AAL0) */
  1479. buflen = ATM_CELL_PAYLOAD; /* i.e., 48 bytes */
  1480. flags = NS_TBD_AAL0;
  1481. scqe.word_2 = cpu_to_le32(NS_PRV_DMA(skb) + NS_AAL0_HEADER);
  1482. scqe.word_3 = cpu_to_le32(0x00000000);
  1483. if (*skb->data & 0x02) /* Payload type 1 - end of pdu */
  1484. flags |= NS_TBD_EOPDU;
  1485. scqe.word_4 =
  1486. cpu_to_le32(*((u32 *) skb->data) & ~NS_TBD_VC_MASK);
  1487. /* Force the VPI/VCI to be the same as in VCC struct */
  1488. scqe.word_4 |=
  1489. cpu_to_le32((((u32) vcc->
  1490. vpi) << NS_TBD_VPI_SHIFT | ((u32) vcc->
  1491. vci) <<
  1492. NS_TBD_VCI_SHIFT) & NS_TBD_VC_MASK);
  1493. }
  1494. if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  1495. scqe.word_1 = ns_tbd_mkword_1_novbr(flags, (u32) buflen);
  1496. scq = ((vc_map *) vcc->dev_data)->scq;
  1497. } else {
  1498. scqe.word_1 =
  1499. ns_tbd_mkword_1(flags, (u32) 1, (u32) 1, (u32) buflen);
  1500. scq = card->scq0;
  1501. }
  1502. if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
  1503. atomic_inc(&vcc->stats->tx_err);
  1504. dma_unmap_single(&card->pcidev->dev, NS_PRV_DMA(skb), skb->len,
  1505. DMA_TO_DEVICE);
  1506. dev_kfree_skb_any(skb);
  1507. return -EIO;
  1508. }
  1509. atomic_inc(&vcc->stats->tx);
  1510. return 0;
  1511. }
  1512. static int push_scqe(ns_dev * card, vc_map * vc, scq_info * scq, ns_scqe * tbd,
  1513. struct sk_buff *skb)
  1514. {
  1515. unsigned long flags;
  1516. ns_scqe tsr;
  1517. u32 scdi, scqi;
  1518. int scq_is_vbr;
  1519. u32 data;
  1520. int index;
  1521. spin_lock_irqsave(&scq->lock, flags);
  1522. while (scq->tail == scq->next) {
  1523. if (in_interrupt()) {
  1524. spin_unlock_irqrestore(&scq->lock, flags);
  1525. printk("nicstar%d: Error pushing TBD.\n", card->index);
  1526. return 1;
  1527. }
  1528. scq->full = 1;
  1529. wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq,
  1530. scq->tail != scq->next,
  1531. scq->lock,
  1532. SCQFULL_TIMEOUT);
  1533. if (scq->full) {
  1534. spin_unlock_irqrestore(&scq->lock, flags);
  1535. printk("nicstar%d: Timeout pushing TBD.\n",
  1536. card->index);
  1537. return 1;
  1538. }
  1539. }
  1540. *scq->next = *tbd;
  1541. index = (int)(scq->next - scq->base);
  1542. scq->skb[index] = skb;
  1543. XPRINTK("nicstar%d: sending skb at 0x%p (pos %d).\n",
  1544. card->index, skb, index);
  1545. XPRINTK("nicstar%d: TBD written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%p.\n",
  1546. card->index, le32_to_cpu(tbd->word_1), le32_to_cpu(tbd->word_2),
  1547. le32_to_cpu(tbd->word_3), le32_to_cpu(tbd->word_4),
  1548. scq->next);
  1549. if (scq->next == scq->last)
  1550. scq->next = scq->base;
  1551. else
  1552. scq->next++;
  1553. vc->tbd_count++;
  1554. if (scq->num_entries == VBR_SCQ_NUM_ENTRIES) {
  1555. scq->tbd_count++;
  1556. scq_is_vbr = 1;
  1557. } else
  1558. scq_is_vbr = 0;
  1559. if (vc->tbd_count >= MAX_TBD_PER_VC
  1560. || scq->tbd_count >= MAX_TBD_PER_SCQ) {
  1561. int has_run = 0;
  1562. while (scq->tail == scq->next) {
  1563. if (in_interrupt()) {
  1564. data = scq_virt_to_bus(scq, scq->next);
  1565. ns_write_sram(card, scq->scd, &data, 1);
  1566. spin_unlock_irqrestore(&scq->lock, flags);
  1567. printk("nicstar%d: Error pushing TSR.\n",
  1568. card->index);
  1569. return 0;
  1570. }
  1571. scq->full = 1;
  1572. if (has_run++)
  1573. break;
  1574. wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq,
  1575. scq->tail != scq->next,
  1576. scq->lock,
  1577. SCQFULL_TIMEOUT);
  1578. }
  1579. if (!scq->full) {
  1580. tsr.word_1 = ns_tsr_mkword_1(NS_TSR_INTENABLE);
  1581. if (scq_is_vbr)
  1582. scdi = NS_TSR_SCDISVBR;
  1583. else
  1584. scdi = (vc->cbr_scd - NS_FRSCD) / NS_FRSCD_SIZE;
  1585. scqi = scq->next - scq->base;
  1586. tsr.word_2 = ns_tsr_mkword_2(scdi, scqi);
  1587. tsr.word_3 = 0x00000000;
  1588. tsr.word_4 = 0x00000000;
  1589. *scq->next = tsr;
  1590. index = (int)scqi;
  1591. scq->skb[index] = NULL;
  1592. XPRINTK
  1593. ("nicstar%d: TSR written:\n0x%x\n0x%x\n0x%x\n0x%x\n at 0x%p.\n",
  1594. card->index, le32_to_cpu(tsr.word_1),
  1595. le32_to_cpu(tsr.word_2), le32_to_cpu(tsr.word_3),
  1596. le32_to_cpu(tsr.word_4), scq->next);
  1597. if (scq->next == scq->last)
  1598. scq->next = scq->base;
  1599. else
  1600. scq->next++;
  1601. vc->tbd_count = 0;
  1602. scq->tbd_count = 0;
  1603. } else
  1604. PRINTK("nicstar%d: Timeout pushing TSR.\n",
  1605. card->index);
  1606. }
  1607. data = scq_virt_to_bus(scq, scq->next);
  1608. ns_write_sram(card, scq->scd, &data, 1);
  1609. spin_unlock_irqrestore(&scq->lock, flags);
  1610. return 0;
  1611. }
  1612. static void process_tsq(ns_dev * card)
  1613. {
  1614. u32 scdi;
  1615. scq_info *scq;
  1616. ns_tsi *previous = NULL, *one_ahead, *two_ahead;
  1617. int serviced_entries; /* flag indicating at least on entry was serviced */
  1618. serviced_entries = 0;
  1619. if (card->tsq.next == card->tsq.last)
  1620. one_ahead = card->tsq.base;
  1621. else
  1622. one_ahead = card->tsq.next + 1;
  1623. if (one_ahead == card->tsq.last)
  1624. two_ahead = card->tsq.base;
  1625. else
  1626. two_ahead = one_ahead + 1;
  1627. while (!ns_tsi_isempty(card->tsq.next) || !ns_tsi_isempty(one_ahead) ||
  1628. !ns_tsi_isempty(two_ahead))
  1629. /* At most two empty, as stated in the 77201 errata */
  1630. {
  1631. serviced_entries = 1;
  1632. /* Skip the one or two possible empty entries */
  1633. while (ns_tsi_isempty(card->tsq.next)) {
  1634. if (card->tsq.next == card->tsq.last)
  1635. card->tsq.next = card->tsq.base;
  1636. else
  1637. card->tsq.next++;
  1638. }
  1639. if (!ns_tsi_tmrof(card->tsq.next)) {
  1640. scdi = ns_tsi_getscdindex(card->tsq.next);
  1641. if (scdi == NS_TSI_SCDISVBR)
  1642. scq = card->scq0;
  1643. else {
  1644. if (card->scd2vc[scdi] == NULL) {
  1645. printk
  1646. ("nicstar%d: could not find VC from SCD index.\n",
  1647. card->index);
  1648. ns_tsi_init(card->tsq.next);
  1649. return;
  1650. }
  1651. scq = card->scd2vc[scdi]->scq;
  1652. }
  1653. drain_scq(card, scq, ns_tsi_getscqpos(card->tsq.next));
  1654. scq->full = 0;
  1655. wake_up_interruptible(&(scq->scqfull_waitq));
  1656. }
  1657. ns_tsi_init(card->tsq.next);
  1658. previous = card->tsq.next;
  1659. if (card->tsq.next == card->tsq.last)
  1660. card->tsq.next = card->tsq.base;
  1661. else
  1662. card->tsq.next++;
  1663. if (card->tsq.next == card->tsq.last)
  1664. one_ahead = card->tsq.base;
  1665. else
  1666. one_ahead = card->tsq.next + 1;
  1667. if (one_ahead == card->tsq.last)
  1668. two_ahead = card->tsq.base;
  1669. else
  1670. two_ahead = one_ahead + 1;
  1671. }
  1672. if (serviced_entries)
  1673. writel(PTR_DIFF(previous, card->tsq.base),
  1674. card->membase + TSQH);
  1675. }
  1676. static void drain_scq(ns_dev * card, scq_info * scq, int pos)
  1677. {
  1678. struct atm_vcc *vcc;
  1679. struct sk_buff *skb;
  1680. int i;
  1681. unsigned long flags;
  1682. XPRINTK("nicstar%d: drain_scq() called, scq at 0x%p, pos %d.\n",
  1683. card->index, scq, pos);
  1684. if (pos >= scq->num_entries) {
  1685. printk("nicstar%d: Bad index on drain_scq().\n", card->index);
  1686. return;
  1687. }
  1688. spin_lock_irqsave(&scq->lock, flags);
  1689. i = (int)(scq->tail - scq->base);
  1690. if (++i == scq->num_entries)
  1691. i = 0;
  1692. while (i != pos) {
  1693. skb = scq->skb[i];
  1694. XPRINTK("nicstar%d: freeing skb at 0x%p (index %d).\n",
  1695. card->index, skb, i);
  1696. if (skb != NULL) {
  1697. dma_unmap_single(&card->pcidev->dev,
  1698. NS_PRV_DMA(skb),
  1699. skb->len,
  1700. DMA_TO_DEVICE);
  1701. vcc = ATM_SKB(skb)->vcc;
  1702. if (vcc && vcc->pop != NULL) {
  1703. vcc->pop(vcc, skb);
  1704. } else {
  1705. dev_kfree_skb_irq(skb);
  1706. }
  1707. scq->skb[i] = NULL;
  1708. }
  1709. if (++i == scq->num_entries)
  1710. i = 0;
  1711. }
  1712. scq->tail = scq->base + pos;
  1713. spin_unlock_irqrestore(&scq->lock, flags);
  1714. }
  1715. static void process_rsq(ns_dev * card)
  1716. {
  1717. ns_rsqe *previous;
  1718. if (!ns_rsqe_valid(card->rsq.next))
  1719. return;
  1720. do {
  1721. dequeue_rx(card, card->rsq.next);
  1722. ns_rsqe_init(card->rsq.next);
  1723. previous = card->rsq.next;
  1724. if (card->rsq.next == card->rsq.last)
  1725. card->rsq.next = card->rsq.base;
  1726. else
  1727. card->rsq.next++;
  1728. } while (ns_rsqe_valid(card->rsq.next));
  1729. writel(PTR_DIFF(previous, card->rsq.base), card->membase + RSQH);
  1730. }
  1731. static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
  1732. {
  1733. u32 vpi, vci;
  1734. vc_map *vc;
  1735. struct sk_buff *iovb;
  1736. struct iovec *iov;
  1737. struct atm_vcc *vcc;
  1738. struct sk_buff *skb;
  1739. unsigned short aal5_len;
  1740. int len;
  1741. u32 stat;
  1742. u32 id;
  1743. stat = readl(card->membase + STAT);
  1744. card->sbfqc = ns_stat_sfbqc_get(stat);
  1745. card->lbfqc = ns_stat_lfbqc_get(stat);
  1746. id = le32_to_cpu(rsqe->buffer_handle);
  1747. skb = idr_remove(&card->idr, id);
  1748. if (!skb) {
  1749. RXPRINTK(KERN_ERR
  1750. "nicstar%d: skb not found!\n", card->index);
  1751. return;
  1752. }
  1753. dma_sync_single_for_cpu(&card->pcidev->dev,
  1754. NS_PRV_DMA(skb),
  1755. (NS_PRV_BUFTYPE(skb) == BUF_SM
  1756. ? NS_SMSKBSIZE : NS_LGSKBSIZE),
  1757. DMA_FROM_DEVICE);
  1758. dma_unmap_single(&card->pcidev->dev,
  1759. NS_PRV_DMA(skb),
  1760. (NS_PRV_BUFTYPE(skb) == BUF_SM
  1761. ? NS_SMSKBSIZE : NS_LGSKBSIZE),
  1762. DMA_FROM_DEVICE);
  1763. vpi = ns_rsqe_vpi(rsqe);
  1764. vci = ns_rsqe_vci(rsqe);
  1765. if (vpi >= 1UL << card->vpibits || vci >= 1UL << card->vcibits) {
  1766. printk("nicstar%d: SDU received for out-of-range vc %d.%d.\n",
  1767. card->index, vpi, vci);
  1768. recycle_rx_buf(card, skb);
  1769. return;
  1770. }
  1771. vc = &(card->vcmap[vpi << card->vcibits | vci]);
  1772. if (!vc->rx) {
  1773. RXPRINTK("nicstar%d: SDU received on non-rx vc %d.%d.\n",
  1774. card->index, vpi, vci);
  1775. recycle_rx_buf(card, skb);
  1776. return;
  1777. }
  1778. vcc = vc->rx_vcc;
  1779. if (vcc->qos.aal == ATM_AAL0) {
  1780. struct sk_buff *sb;
  1781. unsigned char *cell;
  1782. int i;
  1783. cell = skb->data;
  1784. for (i = ns_rsqe_cellcount(rsqe); i; i--) {
  1785. sb = dev_alloc_skb(NS_SMSKBSIZE);
  1786. if (!sb) {
  1787. printk
  1788. ("nicstar%d: Can't allocate buffers for aal0.\n",
  1789. card->index);
  1790. atomic_add(i, &vcc->stats->rx_drop);
  1791. break;
  1792. }
  1793. if (!atm_charge(vcc, sb->truesize)) {
  1794. RXPRINTK
  1795. ("nicstar%d: atm_charge() dropped aal0 packets.\n",
  1796. card->index);
  1797. atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
  1798. dev_kfree_skb_any(sb);
  1799. break;
  1800. }
  1801. /* Rebuild the header */
  1802. *((u32 *) sb->data) = le32_to_cpu(rsqe->word_1) << 4 |
  1803. (ns_rsqe_clp(rsqe) ? 0x00000001 : 0x00000000);
  1804. if (i == 1 && ns_rsqe_eopdu(rsqe))
  1805. *((u32 *) sb->data) |= 0x00000002;
  1806. skb_put(sb, NS_AAL0_HEADER);
  1807. memcpy(skb_tail_pointer(sb), cell, ATM_CELL_PAYLOAD);
  1808. skb_put(sb, ATM_CELL_PAYLOAD);
  1809. ATM_SKB(sb)->vcc = vcc;
  1810. __net_timestamp(sb);
  1811. vcc->push(vcc, sb);
  1812. atomic_inc(&vcc->stats->rx);
  1813. cell += ATM_CELL_PAYLOAD;
  1814. }
  1815. recycle_rx_buf(card, skb);
  1816. return;
  1817. }
  1818. /* To reach this point, the AAL layer can only be AAL5 */
  1819. if ((iovb = vc->rx_iov) == NULL) {
  1820. iovb = skb_dequeue(&(card->iovpool.queue));
  1821. if (iovb == NULL) { /* No buffers in the queue */
  1822. iovb = alloc_skb(NS_IOVBUFSIZE, GFP_ATOMIC);
  1823. if (iovb == NULL) {
  1824. printk("nicstar%d: Out of iovec buffers.\n",
  1825. card->index);
  1826. atomic_inc(&vcc->stats->rx_drop);
  1827. recycle_rx_buf(card, skb);
  1828. return;
  1829. }
  1830. NS_PRV_BUFTYPE(iovb) = BUF_NONE;
  1831. } else if (--card->iovpool.count < card->iovnr.min) {
  1832. struct sk_buff *new_iovb;
  1833. if ((new_iovb =
  1834. alloc_skb(NS_IOVBUFSIZE, GFP_ATOMIC)) != NULL) {
  1835. NS_PRV_BUFTYPE(iovb) = BUF_NONE;
  1836. skb_queue_tail(&card->iovpool.queue, new_iovb);
  1837. card->iovpool.count++;
  1838. }
  1839. }
  1840. vc->rx_iov = iovb;
  1841. NS_PRV_IOVCNT(iovb) = 0;
  1842. iovb->len = 0;
  1843. iovb->data = iovb->head;
  1844. skb_reset_tail_pointer(iovb);
  1845. /* IMPORTANT: a pointer to the sk_buff containing the small or large
  1846. buffer is stored as iovec base, NOT a pointer to the
  1847. small or large buffer itself. */
  1848. } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
  1849. printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
  1850. atomic_inc(&vcc->stats->rx_err);
  1851. recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
  1852. NS_MAX_IOVECS);
  1853. NS_PRV_IOVCNT(iovb) = 0;
  1854. iovb->len = 0;
  1855. iovb->data = iovb->head;
  1856. skb_reset_tail_pointer(iovb);
  1857. }
  1858. iov = &((struct iovec *)iovb->data)[NS_PRV_IOVCNT(iovb)++];
  1859. iov->iov_base = (void *)skb;
  1860. iov->iov_len = ns_rsqe_cellcount(rsqe) * 48;
  1861. iovb->len += iov->iov_len;
  1862. #ifdef EXTRA_DEBUG
  1863. if (NS_PRV_IOVCNT(iovb) == 1) {
  1864. if (NS_PRV_BUFTYPE(skb) != BUF_SM) {
  1865. printk
  1866. ("nicstar%d: Expected a small buffer, and this is not one.\n",
  1867. card->index);
  1868. which_list(card, skb);
  1869. atomic_inc(&vcc->stats->rx_err);
  1870. recycle_rx_buf(card, skb);
  1871. vc->rx_iov = NULL;
  1872. recycle_iov_buf(card, iovb);
  1873. return;
  1874. }
  1875. } else { /* NS_PRV_IOVCNT(iovb) >= 2 */
  1876. if (NS_PRV_BUFTYPE(skb) != BUF_LG) {
  1877. printk
  1878. ("nicstar%d: Expected a large buffer, and this is not one.\n",
  1879. card->index);
  1880. which_list(card, skb);
  1881. atomic_inc(&vcc->stats->rx_err);
  1882. recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
  1883. NS_PRV_IOVCNT(iovb));
  1884. vc->rx_iov = NULL;
  1885. recycle_iov_buf(card, iovb);
  1886. return;
  1887. }
  1888. }
  1889. #endif /* EXTRA_DEBUG */
  1890. if (ns_rsqe_eopdu(rsqe)) {
  1891. /* This works correctly regardless of the endianness of the host */
  1892. unsigned char *L1L2 = (unsigned char *)
  1893. (skb->data + iov->iov_len - 6);
  1894. aal5_len = L1L2[0] << 8 | L1L2[1];
  1895. len = (aal5_len == 0x0000) ? 0x10000 : aal5_len;
  1896. if (ns_rsqe_crcerr(rsqe) ||
  1897. len + 8 > iovb->len || len + (47 + 8) < iovb->len) {
  1898. printk("nicstar%d: AAL5 CRC error", card->index);
  1899. if (len + 8 > iovb->len || len + (47 + 8) < iovb->len)
  1900. printk(" - PDU size mismatch.\n");
  1901. else
  1902. printk(".\n");
  1903. atomic_inc(&vcc->stats->rx_err);
  1904. recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
  1905. NS_PRV_IOVCNT(iovb));
  1906. vc->rx_iov = NULL;
  1907. recycle_iov_buf(card, iovb);
  1908. return;
  1909. }
  1910. /* By this point we (hopefully) have a complete SDU without errors. */
  1911. if (NS_PRV_IOVCNT(iovb) == 1) { /* Just a small buffer */
  1912. /* skb points to a small buffer */
  1913. if (!atm_charge(vcc, skb->truesize)) {
  1914. push_rxbufs(card, skb);
  1915. atomic_inc(&vcc->stats->rx_drop);
  1916. } else {
  1917. skb_put(skb, len);
  1918. dequeue_sm_buf(card, skb);
  1919. ATM_SKB(skb)->vcc = vcc;
  1920. __net_timestamp(skb);
  1921. vcc->push(vcc, skb);
  1922. atomic_inc(&vcc->stats->rx);
  1923. }
  1924. } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
  1925. struct sk_buff *sb;
  1926. sb = (struct sk_buff *)(iov - 1)->iov_base;
  1927. /* skb points to a large buffer */
  1928. if (len <= NS_SMBUFSIZE) {
  1929. if (!atm_charge(vcc, sb->truesize)) {
  1930. push_rxbufs(card, sb);
  1931. atomic_inc(&vcc->stats->rx_drop);
  1932. } else {
  1933. skb_put(sb, len);
  1934. dequeue_sm_buf(card, sb);
  1935. ATM_SKB(sb)->vcc = vcc;
  1936. __net_timestamp(sb);
  1937. vcc->push(vcc, sb);
  1938. atomic_inc(&vcc->stats->rx);
  1939. }
  1940. push_rxbufs(card, skb);
  1941. } else { /* len > NS_SMBUFSIZE, the usual case */
  1942. if (!atm_charge(vcc, skb->truesize)) {
  1943. push_rxbufs(card, skb);
  1944. atomic_inc(&vcc->stats->rx_drop);
  1945. } else {
  1946. dequeue_lg_buf(card, skb);
  1947. skb_push(skb, NS_SMBUFSIZE);
  1948. skb_copy_from_linear_data(sb, skb->data,
  1949. NS_SMBUFSIZE);
  1950. skb_put(skb, len - NS_SMBUFSIZE);
  1951. ATM_SKB(skb)->vcc = vcc;
  1952. __net_timestamp(skb);
  1953. vcc->push(vcc, skb);
  1954. atomic_inc(&vcc->stats->rx);
  1955. }
  1956. push_rxbufs(card, sb);
  1957. }
  1958. } else { /* Must push a huge buffer */
  1959. struct sk_buff *hb, *sb, *lb;
  1960. int remaining, tocopy;
  1961. int j;
  1962. hb = skb_dequeue(&(card->hbpool.queue));
  1963. if (hb == NULL) { /* No buffers in the queue */
  1964. hb = dev_alloc_skb(NS_HBUFSIZE);
  1965. if (hb == NULL) {
  1966. printk
  1967. ("nicstar%d: Out of huge buffers.\n",
  1968. card->index);
  1969. atomic_inc(&vcc->stats->rx_drop);
  1970. recycle_iovec_rx_bufs(card,
  1971. (struct iovec *)
  1972. iovb->data,
  1973. NS_PRV_IOVCNT(iovb));
  1974. vc->rx_iov = NULL;
  1975. recycle_iov_buf(card, iovb);
  1976. return;
  1977. } else if (card->hbpool.count < card->hbnr.min) {
  1978. struct sk_buff *new_hb;
  1979. if ((new_hb =
  1980. dev_alloc_skb(NS_HBUFSIZE)) !=
  1981. NULL) {
  1982. skb_queue_tail(&card->hbpool.
  1983. queue, new_hb);
  1984. card->hbpool.count++;
  1985. }
  1986. }
  1987. NS_PRV_BUFTYPE(hb) = BUF_NONE;
  1988. } else if (--card->hbpool.count < card->hbnr.min) {
  1989. struct sk_buff *new_hb;
  1990. if ((new_hb =
  1991. dev_alloc_skb(NS_HBUFSIZE)) != NULL) {
  1992. NS_PRV_BUFTYPE(new_hb) = BUF_NONE;
  1993. skb_queue_tail(&card->hbpool.queue,
  1994. new_hb);
  1995. card->hbpool.count++;
  1996. }
  1997. if (card->hbpool.count < card->hbnr.min) {
  1998. if ((new_hb =
  1999. dev_alloc_skb(NS_HBUFSIZE)) !=
  2000. NULL) {
  2001. NS_PRV_BUFTYPE(new_hb) =
  2002. BUF_NONE;
  2003. skb_queue_tail(&card->hbpool.
  2004. queue, new_hb);
  2005. card->hbpool.count++;
  2006. }
  2007. }
  2008. }
  2009. iov = (struct iovec *)iovb->data;
  2010. if (!atm_charge(vcc, hb->truesize)) {
  2011. recycle_iovec_rx_bufs(card, iov,
  2012. NS_PRV_IOVCNT(iovb));
  2013. if (card->hbpool.count < card->hbnr.max) {
  2014. skb_queue_tail(&card->hbpool.queue, hb);
  2015. card->hbpool.count++;
  2016. } else
  2017. dev_kfree_skb_any(hb);
  2018. atomic_inc(&vcc->stats->rx_drop);
  2019. } else {
  2020. /* Copy the small buffer to the huge buffer */
  2021. sb = (struct sk_buff *)iov->iov_base;
  2022. skb_copy_from_linear_data(sb, hb->data,
  2023. iov->iov_len);
  2024. skb_put(hb, iov->iov_len);
  2025. remaining = len - iov->iov_len;
  2026. iov++;
  2027. /* Free the small buffer */
  2028. push_rxbufs(card, sb);
  2029. /* Copy all large buffers to the huge buffer and free them */
  2030. for (j = 1; j < NS_PRV_IOVCNT(iovb); j++) {
  2031. lb = (struct sk_buff *)iov->iov_base;
  2032. tocopy =
  2033. min_t(int, remaining, iov->iov_len);
  2034. skb_copy_from_linear_data(lb,
  2035. skb_tail_pointer
  2036. (hb), tocopy);
  2037. skb_put(hb, tocopy);
  2038. iov++;
  2039. remaining -= tocopy;
  2040. push_rxbufs(card, lb);
  2041. }
  2042. #ifdef EXTRA_DEBUG
  2043. if (remaining != 0 || hb->len != len)
  2044. printk
  2045. ("nicstar%d: Huge buffer len mismatch.\n",
  2046. card->index);
  2047. #endif /* EXTRA_DEBUG */
  2048. ATM_SKB(hb)->vcc = vcc;
  2049. __net_timestamp(hb);
  2050. vcc->push(vcc, hb);
  2051. atomic_inc(&vcc->stats->rx);
  2052. }
  2053. }
  2054. vc->rx_iov = NULL;
  2055. recycle_iov_buf(card, iovb);
  2056. }
  2057. }
  2058. static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb)
  2059. {
  2060. if (unlikely(NS_PRV_BUFTYPE(skb) == BUF_NONE)) {
  2061. printk("nicstar%d: What kind of rx buffer is this?\n",
  2062. card->index);
  2063. dev_kfree_skb_any(skb);
  2064. } else
  2065. push_rxbufs(card, skb);
  2066. }
  2067. static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count)
  2068. {
  2069. while (count-- > 0)
  2070. recycle_rx_buf(card, (struct sk_buff *)(iov++)->iov_base);
  2071. }
  2072. static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb)
  2073. {
  2074. if (card->iovpool.count < card->iovnr.max) {
  2075. skb_queue_tail(&card->iovpool.queue, iovb);
  2076. card->iovpool.count++;
  2077. } else
  2078. dev_kfree_skb_any(iovb);
  2079. }
  2080. static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb)
  2081. {
  2082. skb_unlink(sb, &card->sbpool.queue);
  2083. if (card->sbfqc < card->sbnr.init) {
  2084. struct sk_buff *new_sb;
  2085. if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) {
  2086. NS_PRV_BUFTYPE(new_sb) = BUF_SM;
  2087. skb_queue_tail(&card->sbpool.queue, new_sb);
  2088. skb_reserve(new_sb, NS_AAL0_HEADER);
  2089. push_rxbufs(card, new_sb);
  2090. }
  2091. }
  2092. if (card->sbfqc < card->sbnr.init)
  2093. {
  2094. struct sk_buff *new_sb;
  2095. if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) {
  2096. NS_PRV_BUFTYPE(new_sb) = BUF_SM;
  2097. skb_queue_tail(&card->sbpool.queue, new_sb);
  2098. skb_reserve(new_sb, NS_AAL0_HEADER);
  2099. push_rxbufs(card, new_sb);
  2100. }
  2101. }
  2102. }
  2103. static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb)
  2104. {
  2105. skb_unlink(lb, &card->lbpool.queue);
  2106. if (card->lbfqc < card->lbnr.init) {
  2107. struct sk_buff *new_lb;
  2108. if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) {
  2109. NS_PRV_BUFTYPE(new_lb) = BUF_LG;
  2110. skb_queue_tail(&card->lbpool.queue, new_lb);
  2111. skb_reserve(new_lb, NS_SMBUFSIZE);
  2112. push_rxbufs(card, new_lb);
  2113. }
  2114. }
  2115. if (card->lbfqc < card->lbnr.init)
  2116. {
  2117. struct sk_buff *new_lb;
  2118. if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) {
  2119. NS_PRV_BUFTYPE(new_lb) = BUF_LG;
  2120. skb_queue_tail(&card->lbpool.queue, new_lb);
  2121. skb_reserve(new_lb, NS_SMBUFSIZE);
  2122. push_rxbufs(card, new_lb);
  2123. }
  2124. }
  2125. }
  2126. static int ns_proc_read(struct atm_dev *dev, loff_t * pos, char *page)
  2127. {
  2128. u32 stat;
  2129. ns_dev *card;
  2130. int left;
  2131. left = (int)*pos;
  2132. card = (ns_dev *) dev->dev_data;
  2133. stat = readl(card->membase + STAT);
  2134. if (!left--)
  2135. return sprintf(page, "Pool count min init max \n");
  2136. if (!left--)
  2137. return sprintf(page, "Small %5d %5d %5d %5d \n",
  2138. ns_stat_sfbqc_get(stat), card->sbnr.min,
  2139. card->sbnr.init, card->sbnr.max);
  2140. if (!left--)
  2141. return sprintf(page, "Large %5d %5d %5d %5d \n",
  2142. ns_stat_lfbqc_get(stat), card->lbnr.min,
  2143. card->lbnr.init, card->lbnr.max);
  2144. if (!left--)
  2145. return sprintf(page, "Huge %5d %5d %5d %5d \n",
  2146. card->hbpool.count, card->hbnr.min,
  2147. card->hbnr.init, card->hbnr.max);
  2148. if (!left--)
  2149. return sprintf(page, "Iovec %5d %5d %5d %5d \n",
  2150. card->iovpool.count, card->iovnr.min,
  2151. card->iovnr.init, card->iovnr.max);
  2152. if (!left--) {
  2153. int retval;
  2154. retval =
  2155. sprintf(page, "Interrupt counter: %u \n", card->intcnt);
  2156. card->intcnt = 0;
  2157. return retval;
  2158. }
  2159. #if 0
  2160. /* Dump 25.6 Mbps PHY registers */
  2161. /* Now there's a 25.6 Mbps PHY driver this code isn't needed. I left it
  2162. here just in case it's needed for debugging. */
  2163. if (card->max_pcr == ATM_25_PCR && !left--) {
  2164. u32 phy_regs[4];
  2165. u32 i;
  2166. for (i = 0; i < 4; i++) {
  2167. while (CMD_BUSY(card)) ;
  2168. writel(NS_CMD_READ_UTILITY | 0x00000200 | i,
  2169. card->membase + CMD);
  2170. while (CMD_BUSY(card)) ;
  2171. phy_regs[i] = readl(card->membase + DR0) & 0x000000FF;
  2172. }
  2173. return sprintf(page, "PHY regs: 0x%02X 0x%02X 0x%02X 0x%02X \n",
  2174. phy_regs[0], phy_regs[1], phy_regs[2],
  2175. phy_regs[3]);
  2176. }
  2177. #endif /* 0 - Dump 25.6 Mbps PHY registers */
  2178. #if 0
  2179. /* Dump TST */
  2180. if (left-- < NS_TST_NUM_ENTRIES) {
  2181. if (card->tste2vc[left + 1] == NULL)
  2182. return sprintf(page, "%5d - VBR/UBR \n", left + 1);
  2183. else
  2184. return sprintf(page, "%5d - %d %d \n", left + 1,
  2185. card->tste2vc[left + 1]->tx_vcc->vpi,
  2186. card->tste2vc[left + 1]->tx_vcc->vci);
  2187. }
  2188. #endif /* 0 */
  2189. return 0;
  2190. }
  2191. static int ns_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg)
  2192. {
  2193. ns_dev *card;
  2194. pool_levels pl;
  2195. long btype;
  2196. unsigned long flags;
  2197. card = dev->dev_data;
  2198. switch (cmd) {
  2199. case NS_GETPSTAT:
  2200. if (get_user
  2201. (pl.buftype, &((pool_levels __user *) arg)->buftype))
  2202. return -EFAULT;
  2203. switch (pl.buftype) {
  2204. case NS_BUFTYPE_SMALL:
  2205. pl.count =
  2206. ns_stat_sfbqc_get(readl(card->membase + STAT));
  2207. pl.level.min = card->sbnr.min;
  2208. pl.level.init = card->sbnr.init;
  2209. pl.level.max = card->sbnr.max;
  2210. break;
  2211. case NS_BUFTYPE_LARGE:
  2212. pl.count =
  2213. ns_stat_lfbqc_get(readl(card->membase + STAT));
  2214. pl.level.min = card->lbnr.min;
  2215. pl.level.init = card->lbnr.init;
  2216. pl.level.max = card->lbnr.max;
  2217. break;
  2218. case NS_BUFTYPE_HUGE:
  2219. pl.count = card->hbpool.count;
  2220. pl.level.min = card->hbnr.min;
  2221. pl.level.init = card->hbnr.init;
  2222. pl.level.max = card->hbnr.max;
  2223. break;
  2224. case NS_BUFTYPE_IOVEC:
  2225. pl.count = card->iovpool.count;
  2226. pl.level.min = card->iovnr.min;
  2227. pl.level.init = card->iovnr.init;
  2228. pl.level.max = card->iovnr.max;
  2229. break;
  2230. default:
  2231. return -ENOIOCTLCMD;
  2232. }
  2233. if (!copy_to_user((pool_levels __user *) arg, &pl, sizeof(pl)))
  2234. return (sizeof(pl));
  2235. else
  2236. return -EFAULT;
  2237. case NS_SETBUFLEV:
  2238. if (!capable(CAP_NET_ADMIN))
  2239. return -EPERM;
  2240. if (copy_from_user(&pl, (pool_levels __user *) arg, sizeof(pl)))
  2241. return -EFAULT;
  2242. if (pl.level.min >= pl.level.init
  2243. || pl.level.init >= pl.level.max)
  2244. return -EINVAL;
  2245. if (pl.level.min == 0)
  2246. return -EINVAL;
  2247. switch (pl.buftype) {
  2248. case NS_BUFTYPE_SMALL:
  2249. if (pl.level.max > TOP_SB)
  2250. return -EINVAL;
  2251. card->sbnr.min = pl.level.min;
  2252. card->sbnr.init = pl.level.init;
  2253. card->sbnr.max = pl.level.max;
  2254. break;
  2255. case NS_BUFTYPE_LARGE:
  2256. if (pl.level.max > TOP_LB)
  2257. return -EINVAL;
  2258. card->lbnr.min = pl.level.min;
  2259. card->lbnr.init = pl.level.init;
  2260. card->lbnr.max = pl.level.max;
  2261. break;
  2262. case NS_BUFTYPE_HUGE:
  2263. if (pl.level.max > TOP_HB)
  2264. return -EINVAL;
  2265. card->hbnr.min = pl.level.min;
  2266. card->hbnr.init = pl.level.init;
  2267. card->hbnr.max = pl.level.max;
  2268. break;
  2269. case NS_BUFTYPE_IOVEC:
  2270. if (pl.level.max > TOP_IOVB)
  2271. return -EINVAL;
  2272. card->iovnr.min = pl.level.min;
  2273. card->iovnr.init = pl.level.init;
  2274. card->iovnr.max = pl.level.max;
  2275. break;
  2276. default:
  2277. return -EINVAL;
  2278. }
  2279. return 0;
  2280. case NS_ADJBUFLEV:
  2281. if (!capable(CAP_NET_ADMIN))
  2282. return -EPERM;
  2283. btype = (long)arg; /* a long is the same size as a pointer or bigger */
  2284. switch (btype) {
  2285. case NS_BUFTYPE_SMALL:
  2286. while (card->sbfqc < card->sbnr.init) {
  2287. struct sk_buff *sb;
  2288. sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL);
  2289. if (sb == NULL)
  2290. return -ENOMEM;
  2291. NS_PRV_BUFTYPE(sb) = BUF_SM;
  2292. skb_queue_tail(&card->sbpool.queue, sb);
  2293. skb_reserve(sb, NS_AAL0_HEADER);
  2294. push_rxbufs(card, sb);
  2295. }
  2296. break;
  2297. case NS_BUFTYPE_LARGE:
  2298. while (card->lbfqc < card->lbnr.init) {
  2299. struct sk_buff *lb;
  2300. lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL);
  2301. if (lb == NULL)
  2302. return -ENOMEM;
  2303. NS_PRV_BUFTYPE(lb) = BUF_LG;
  2304. skb_queue_tail(&card->lbpool.queue, lb);
  2305. skb_reserve(lb, NS_SMBUFSIZE);
  2306. push_rxbufs(card, lb);
  2307. }
  2308. break;
  2309. case NS_BUFTYPE_HUGE:
  2310. while (card->hbpool.count > card->hbnr.init) {
  2311. struct sk_buff *hb;
  2312. spin_lock_irqsave(&card->int_lock, flags);
  2313. hb = skb_dequeue(&card->hbpool.queue);
  2314. card->hbpool.count--;
  2315. spin_unlock_irqrestore(&card->int_lock, flags);
  2316. if (hb == NULL)
  2317. printk
  2318. ("nicstar%d: huge buffer count inconsistent.\n",
  2319. card->index);
  2320. else
  2321. dev_kfree_skb_any(hb);
  2322. }
  2323. while (card->hbpool.count < card->hbnr.init) {
  2324. struct sk_buff *hb;
  2325. hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL);
  2326. if (hb == NULL)
  2327. return -ENOMEM;
  2328. NS_PRV_BUFTYPE(hb) = BUF_NONE;
  2329. spin_lock_irqsave(&card->int_lock, flags);
  2330. skb_queue_tail(&card->hbpool.queue, hb);
  2331. card->hbpool.count++;
  2332. spin_unlock_irqrestore(&card->int_lock, flags);
  2333. }
  2334. break;
  2335. case NS_BUFTYPE_IOVEC:
  2336. while (card->iovpool.count > card->iovnr.init) {
  2337. struct sk_buff *iovb;
  2338. spin_lock_irqsave(&card->int_lock, flags);
  2339. iovb = skb_dequeue(&card->iovpool.queue);
  2340. card->iovpool.count--;
  2341. spin_unlock_irqrestore(&card->int_lock, flags);
  2342. if (iovb == NULL)
  2343. printk
  2344. ("nicstar%d: iovec buffer count inconsistent.\n",
  2345. card->index);
  2346. else
  2347. dev_kfree_skb_any(iovb);
  2348. }
  2349. while (card->iovpool.count < card->iovnr.init) {
  2350. struct sk_buff *iovb;
  2351. iovb = alloc_skb(NS_IOVBUFSIZE, GFP_KERNEL);
  2352. if (iovb == NULL)
  2353. return -ENOMEM;
  2354. NS_PRV_BUFTYPE(iovb) = BUF_NONE;
  2355. spin_lock_irqsave(&card->int_lock, flags);
  2356. skb_queue_tail(&card->iovpool.queue, iovb);
  2357. card->iovpool.count++;
  2358. spin_unlock_irqrestore(&card->int_lock, flags);
  2359. }
  2360. break;
  2361. default:
  2362. return -EINVAL;
  2363. }
  2364. return 0;
  2365. default:
  2366. if (dev->phy && dev->phy->ioctl) {
  2367. return dev->phy->ioctl(dev, cmd, arg);
  2368. } else {
  2369. printk("nicstar%d: %s == NULL \n", card->index,
  2370. dev->phy ? "dev->phy->ioctl" : "dev->phy");
  2371. return -ENOIOCTLCMD;
  2372. }
  2373. }
  2374. }
  2375. #ifdef EXTRA_DEBUG
  2376. static void which_list(ns_dev * card, struct sk_buff *skb)
  2377. {
  2378. printk("skb buf_type: 0x%08x\n", NS_PRV_BUFTYPE(skb));
  2379. }
  2380. #endif /* EXTRA_DEBUG */
  2381. static void ns_poll(unsigned long arg)
  2382. {
  2383. int i;
  2384. ns_dev *card;
  2385. unsigned long flags;
  2386. u32 stat_r, stat_w;
  2387. PRINTK("nicstar: Entering ns_poll().\n");
  2388. for (i = 0; i < num_cards; i++) {
  2389. card = cards[i];
  2390. if (spin_is_locked(&card->int_lock)) {
  2391. /* Probably it isn't worth spinning */
  2392. continue;
  2393. }
  2394. spin_lock_irqsave(&card->int_lock, flags);
  2395. stat_w = 0;
  2396. stat_r = readl(card->membase + STAT);
  2397. if (stat_r & NS_STAT_TSIF)
  2398. stat_w |= NS_STAT_TSIF;
  2399. if (stat_r & NS_STAT_EOPDU)
  2400. stat_w |= NS_STAT_EOPDU;
  2401. process_tsq(card);
  2402. process_rsq(card);
  2403. writel(stat_w, card->membase + STAT);
  2404. spin_unlock_irqrestore(&card->int_lock, flags);
  2405. }
  2406. mod_timer(&ns_timer, jiffies + NS_POLL_PERIOD);
  2407. PRINTK("nicstar: Leaving ns_poll().\n");
  2408. }
  2409. static void ns_phy_put(struct atm_dev *dev, unsigned char value,
  2410. unsigned long addr)
  2411. {
  2412. ns_dev *card;
  2413. unsigned long flags;
  2414. card = dev->dev_data;
  2415. spin_lock_irqsave(&card->res_lock, flags);
  2416. while (CMD_BUSY(card)) ;
  2417. writel((u32) value, card->membase + DR0);
  2418. writel(NS_CMD_WRITE_UTILITY | 0x00000200 | (addr & 0x000000FF),
  2419. card->membase + CMD);
  2420. spin_unlock_irqrestore(&card->res_lock, flags);
  2421. }
  2422. static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr)
  2423. {
  2424. ns_dev *card;
  2425. unsigned long flags;
  2426. u32 data;
  2427. card = dev->dev_data;
  2428. spin_lock_irqsave(&card->res_lock, flags);
  2429. while (CMD_BUSY(card)) ;
  2430. writel(NS_CMD_READ_UTILITY | 0x00000200 | (addr & 0x000000FF),
  2431. card->membase + CMD);
  2432. while (CMD_BUSY(card)) ;
  2433. data = readl(card->membase + DR0) & 0x000000FF;
  2434. spin_unlock_irqrestore(&card->res_lock, flags);
  2435. return (unsigned char)data;
  2436. }
  2437. module_init(nicstar_init);
  2438. module_exit(nicstar_cleanup);