nicstar.c 75 KB

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