nicstar.c 72 KB

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