nicstar.c 72 KB

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