nicstar.c 72 KB

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