idt77252.c 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805
  1. /*******************************************************************
  2. *
  3. * Copyright (c) 2000 ATecoM GmbH
  4. *
  5. * The author may be reached at ecd@atecom.com.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  13. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  15. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  18. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  19. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *
  27. *******************************************************************/
  28. #include <linux/module.h>
  29. #include <linux/pci.h>
  30. #include <linux/poison.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/kernel.h>
  33. #include <linux/vmalloc.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/atmdev.h>
  36. #include <linux/atm.h>
  37. #include <linux/delay.h>
  38. #include <linux/init.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/bitops.h>
  41. #include <linux/wait.h>
  42. #include <linux/jiffies.h>
  43. #include <linux/mutex.h>
  44. #include <linux/slab.h>
  45. #include <asm/io.h>
  46. #include <asm/uaccess.h>
  47. #include <linux/atomic.h>
  48. #include <asm/byteorder.h>
  49. #ifdef CONFIG_ATM_IDT77252_USE_SUNI
  50. #include "suni.h"
  51. #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
  52. #include "idt77252.h"
  53. #include "idt77252_tables.h"
  54. static unsigned int vpibits = 1;
  55. #define ATM_IDT77252_SEND_IDLE 1
  56. /*
  57. * Debug HACKs.
  58. */
  59. #define DEBUG_MODULE 1
  60. #undef HAVE_EEPROM /* does not work, yet. */
  61. #ifdef CONFIG_ATM_IDT77252_DEBUG
  62. static unsigned long debug = DBG_GENERAL;
  63. #endif
  64. #define SAR_RX_DELAY (SAR_CFG_RXINT_NODELAY)
  65. /*
  66. * SCQ Handling.
  67. */
  68. static struct scq_info *alloc_scq(struct idt77252_dev *, int);
  69. static void free_scq(struct idt77252_dev *, struct scq_info *);
  70. static int queue_skb(struct idt77252_dev *, struct vc_map *,
  71. struct sk_buff *, int oam);
  72. static void drain_scq(struct idt77252_dev *, struct vc_map *);
  73. static unsigned long get_free_scd(struct idt77252_dev *, struct vc_map *);
  74. static void fill_scd(struct idt77252_dev *, struct scq_info *, int);
  75. /*
  76. * FBQ Handling.
  77. */
  78. static int push_rx_skb(struct idt77252_dev *,
  79. struct sk_buff *, int queue);
  80. static void recycle_rx_skb(struct idt77252_dev *, struct sk_buff *);
  81. static void flush_rx_pool(struct idt77252_dev *, struct rx_pool *);
  82. static void recycle_rx_pool_skb(struct idt77252_dev *,
  83. struct rx_pool *);
  84. static void add_rx_skb(struct idt77252_dev *, int queue,
  85. unsigned int size, unsigned int count);
  86. /*
  87. * RSQ Handling.
  88. */
  89. static int init_rsq(struct idt77252_dev *);
  90. static void deinit_rsq(struct idt77252_dev *);
  91. static void idt77252_rx(struct idt77252_dev *);
  92. /*
  93. * TSQ handling.
  94. */
  95. static int init_tsq(struct idt77252_dev *);
  96. static void deinit_tsq(struct idt77252_dev *);
  97. static void idt77252_tx(struct idt77252_dev *);
  98. /*
  99. * ATM Interface.
  100. */
  101. static void idt77252_dev_close(struct atm_dev *dev);
  102. static int idt77252_open(struct atm_vcc *vcc);
  103. static void idt77252_close(struct atm_vcc *vcc);
  104. static int idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb);
  105. static int idt77252_send_oam(struct atm_vcc *vcc, void *cell,
  106. int flags);
  107. static void idt77252_phy_put(struct atm_dev *dev, unsigned char value,
  108. unsigned long addr);
  109. static unsigned char idt77252_phy_get(struct atm_dev *dev, unsigned long addr);
  110. static int idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos,
  111. int flags);
  112. static int idt77252_proc_read(struct atm_dev *dev, loff_t * pos,
  113. char *page);
  114. static void idt77252_softint(struct work_struct *work);
  115. static struct atmdev_ops idt77252_ops =
  116. {
  117. .dev_close = idt77252_dev_close,
  118. .open = idt77252_open,
  119. .close = idt77252_close,
  120. .send = idt77252_send,
  121. .send_oam = idt77252_send_oam,
  122. .phy_put = idt77252_phy_put,
  123. .phy_get = idt77252_phy_get,
  124. .change_qos = idt77252_change_qos,
  125. .proc_read = idt77252_proc_read,
  126. .owner = THIS_MODULE
  127. };
  128. static struct idt77252_dev *idt77252_chain = NULL;
  129. static unsigned int idt77252_sram_write_errors = 0;
  130. /*****************************************************************************/
  131. /* */
  132. /* I/O and Utility Bus */
  133. /* */
  134. /*****************************************************************************/
  135. static void
  136. waitfor_idle(struct idt77252_dev *card)
  137. {
  138. u32 stat;
  139. stat = readl(SAR_REG_STAT);
  140. while (stat & SAR_STAT_CMDBZ)
  141. stat = readl(SAR_REG_STAT);
  142. }
  143. static u32
  144. read_sram(struct idt77252_dev *card, unsigned long addr)
  145. {
  146. unsigned long flags;
  147. u32 value;
  148. spin_lock_irqsave(&card->cmd_lock, flags);
  149. writel(SAR_CMD_READ_SRAM | (addr << 2), SAR_REG_CMD);
  150. waitfor_idle(card);
  151. value = readl(SAR_REG_DR0);
  152. spin_unlock_irqrestore(&card->cmd_lock, flags);
  153. return value;
  154. }
  155. static void
  156. write_sram(struct idt77252_dev *card, unsigned long addr, u32 value)
  157. {
  158. unsigned long flags;
  159. if ((idt77252_sram_write_errors == 0) &&
  160. (((addr > card->tst[0] + card->tst_size - 2) &&
  161. (addr < card->tst[0] + card->tst_size)) ||
  162. ((addr > card->tst[1] + card->tst_size - 2) &&
  163. (addr < card->tst[1] + card->tst_size)))) {
  164. printk("%s: ERROR: TST JMP section at %08lx written: %08x\n",
  165. card->name, addr, value);
  166. }
  167. spin_lock_irqsave(&card->cmd_lock, flags);
  168. writel(value, SAR_REG_DR0);
  169. writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD);
  170. waitfor_idle(card);
  171. spin_unlock_irqrestore(&card->cmd_lock, flags);
  172. }
  173. static u8
  174. read_utility(void *dev, unsigned long ubus_addr)
  175. {
  176. struct idt77252_dev *card = dev;
  177. unsigned long flags;
  178. u8 value;
  179. if (!card) {
  180. printk("Error: No such device.\n");
  181. return -1;
  182. }
  183. spin_lock_irqsave(&card->cmd_lock, flags);
  184. writel(SAR_CMD_READ_UTILITY + ubus_addr, SAR_REG_CMD);
  185. waitfor_idle(card);
  186. value = readl(SAR_REG_DR0);
  187. spin_unlock_irqrestore(&card->cmd_lock, flags);
  188. return value;
  189. }
  190. static void
  191. write_utility(void *dev, unsigned long ubus_addr, u8 value)
  192. {
  193. struct idt77252_dev *card = dev;
  194. unsigned long flags;
  195. if (!card) {
  196. printk("Error: No such device.\n");
  197. return;
  198. }
  199. spin_lock_irqsave(&card->cmd_lock, flags);
  200. writel((u32) value, SAR_REG_DR0);
  201. writel(SAR_CMD_WRITE_UTILITY + ubus_addr, SAR_REG_CMD);
  202. waitfor_idle(card);
  203. spin_unlock_irqrestore(&card->cmd_lock, flags);
  204. }
  205. #ifdef HAVE_EEPROM
  206. static u32 rdsrtab[] =
  207. {
  208. SAR_GP_EECS | SAR_GP_EESCLK,
  209. 0,
  210. SAR_GP_EESCLK, /* 0 */
  211. 0,
  212. SAR_GP_EESCLK, /* 0 */
  213. 0,
  214. SAR_GP_EESCLK, /* 0 */
  215. 0,
  216. SAR_GP_EESCLK, /* 0 */
  217. 0,
  218. SAR_GP_EESCLK, /* 0 */
  219. SAR_GP_EEDO,
  220. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  221. 0,
  222. SAR_GP_EESCLK, /* 0 */
  223. SAR_GP_EEDO,
  224. SAR_GP_EESCLK | SAR_GP_EEDO /* 1 */
  225. };
  226. static u32 wrentab[] =
  227. {
  228. SAR_GP_EECS | SAR_GP_EESCLK,
  229. 0,
  230. SAR_GP_EESCLK, /* 0 */
  231. 0,
  232. SAR_GP_EESCLK, /* 0 */
  233. 0,
  234. SAR_GP_EESCLK, /* 0 */
  235. 0,
  236. SAR_GP_EESCLK, /* 0 */
  237. SAR_GP_EEDO,
  238. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  239. SAR_GP_EEDO,
  240. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  241. 0,
  242. SAR_GP_EESCLK, /* 0 */
  243. 0,
  244. SAR_GP_EESCLK /* 0 */
  245. };
  246. static u32 rdtab[] =
  247. {
  248. SAR_GP_EECS | SAR_GP_EESCLK,
  249. 0,
  250. SAR_GP_EESCLK, /* 0 */
  251. 0,
  252. SAR_GP_EESCLK, /* 0 */
  253. 0,
  254. SAR_GP_EESCLK, /* 0 */
  255. 0,
  256. SAR_GP_EESCLK, /* 0 */
  257. 0,
  258. SAR_GP_EESCLK, /* 0 */
  259. 0,
  260. SAR_GP_EESCLK, /* 0 */
  261. SAR_GP_EEDO,
  262. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  263. SAR_GP_EEDO,
  264. SAR_GP_EESCLK | SAR_GP_EEDO /* 1 */
  265. };
  266. static u32 wrtab[] =
  267. {
  268. SAR_GP_EECS | SAR_GP_EESCLK,
  269. 0,
  270. SAR_GP_EESCLK, /* 0 */
  271. 0,
  272. SAR_GP_EESCLK, /* 0 */
  273. 0,
  274. SAR_GP_EESCLK, /* 0 */
  275. 0,
  276. SAR_GP_EESCLK, /* 0 */
  277. 0,
  278. SAR_GP_EESCLK, /* 0 */
  279. 0,
  280. SAR_GP_EESCLK, /* 0 */
  281. SAR_GP_EEDO,
  282. SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
  283. 0,
  284. SAR_GP_EESCLK /* 0 */
  285. };
  286. static u32 clktab[] =
  287. {
  288. 0,
  289. SAR_GP_EESCLK,
  290. 0,
  291. SAR_GP_EESCLK,
  292. 0,
  293. SAR_GP_EESCLK,
  294. 0,
  295. SAR_GP_EESCLK,
  296. 0,
  297. SAR_GP_EESCLK,
  298. 0,
  299. SAR_GP_EESCLK,
  300. 0,
  301. SAR_GP_EESCLK,
  302. 0,
  303. SAR_GP_EESCLK,
  304. 0
  305. };
  306. static u32
  307. idt77252_read_gp(struct idt77252_dev *card)
  308. {
  309. u32 gp;
  310. gp = readl(SAR_REG_GP);
  311. #if 0
  312. printk("RD: %s\n", gp & SAR_GP_EEDI ? "1" : "0");
  313. #endif
  314. return gp;
  315. }
  316. static void
  317. idt77252_write_gp(struct idt77252_dev *card, u32 value)
  318. {
  319. unsigned long flags;
  320. #if 0
  321. printk("WR: %s %s %s\n", value & SAR_GP_EECS ? " " : "/CS",
  322. value & SAR_GP_EESCLK ? "HIGH" : "LOW ",
  323. value & SAR_GP_EEDO ? "1" : "0");
  324. #endif
  325. spin_lock_irqsave(&card->cmd_lock, flags);
  326. waitfor_idle(card);
  327. writel(value, SAR_REG_GP);
  328. spin_unlock_irqrestore(&card->cmd_lock, flags);
  329. }
  330. static u8
  331. idt77252_eeprom_read_status(struct idt77252_dev *card)
  332. {
  333. u8 byte;
  334. u32 gp;
  335. int i, j;
  336. gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
  337. for (i = 0; i < ARRAY_SIZE(rdsrtab); i++) {
  338. idt77252_write_gp(card, gp | rdsrtab[i]);
  339. udelay(5);
  340. }
  341. idt77252_write_gp(card, gp | SAR_GP_EECS);
  342. udelay(5);
  343. byte = 0;
  344. for (i = 0, j = 0; i < 8; i++) {
  345. byte <<= 1;
  346. idt77252_write_gp(card, gp | clktab[j++]);
  347. udelay(5);
  348. byte |= idt77252_read_gp(card) & SAR_GP_EEDI ? 1 : 0;
  349. idt77252_write_gp(card, gp | clktab[j++]);
  350. udelay(5);
  351. }
  352. idt77252_write_gp(card, gp | SAR_GP_EECS);
  353. udelay(5);
  354. return byte;
  355. }
  356. static u8
  357. idt77252_eeprom_read_byte(struct idt77252_dev *card, u8 offset)
  358. {
  359. u8 byte;
  360. u32 gp;
  361. int i, j;
  362. gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
  363. for (i = 0; i < ARRAY_SIZE(rdtab); i++) {
  364. idt77252_write_gp(card, gp | rdtab[i]);
  365. udelay(5);
  366. }
  367. idt77252_write_gp(card, gp | SAR_GP_EECS);
  368. udelay(5);
  369. for (i = 0, j = 0; i < 8; i++) {
  370. idt77252_write_gp(card, gp | clktab[j++] |
  371. (offset & 1 ? SAR_GP_EEDO : 0));
  372. udelay(5);
  373. idt77252_write_gp(card, gp | clktab[j++] |
  374. (offset & 1 ? SAR_GP_EEDO : 0));
  375. udelay(5);
  376. offset >>= 1;
  377. }
  378. idt77252_write_gp(card, gp | SAR_GP_EECS);
  379. udelay(5);
  380. byte = 0;
  381. for (i = 0, j = 0; i < 8; i++) {
  382. byte <<= 1;
  383. idt77252_write_gp(card, gp | clktab[j++]);
  384. udelay(5);
  385. byte |= idt77252_read_gp(card) & SAR_GP_EEDI ? 1 : 0;
  386. idt77252_write_gp(card, gp | clktab[j++]);
  387. udelay(5);
  388. }
  389. idt77252_write_gp(card, gp | SAR_GP_EECS);
  390. udelay(5);
  391. return byte;
  392. }
  393. static void
  394. idt77252_eeprom_write_byte(struct idt77252_dev *card, u8 offset, u8 data)
  395. {
  396. u32 gp;
  397. int i, j;
  398. gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
  399. for (i = 0; i < ARRAY_SIZE(wrentab); i++) {
  400. idt77252_write_gp(card, gp | wrentab[i]);
  401. udelay(5);
  402. }
  403. idt77252_write_gp(card, gp | SAR_GP_EECS);
  404. udelay(5);
  405. for (i = 0; i < ARRAY_SIZE(wrtab); i++) {
  406. idt77252_write_gp(card, gp | wrtab[i]);
  407. udelay(5);
  408. }
  409. idt77252_write_gp(card, gp | SAR_GP_EECS);
  410. udelay(5);
  411. for (i = 0, j = 0; i < 8; i++) {
  412. idt77252_write_gp(card, gp | clktab[j++] |
  413. (offset & 1 ? SAR_GP_EEDO : 0));
  414. udelay(5);
  415. idt77252_write_gp(card, gp | clktab[j++] |
  416. (offset & 1 ? SAR_GP_EEDO : 0));
  417. udelay(5);
  418. offset >>= 1;
  419. }
  420. idt77252_write_gp(card, gp | SAR_GP_EECS);
  421. udelay(5);
  422. for (i = 0, j = 0; i < 8; i++) {
  423. idt77252_write_gp(card, gp | clktab[j++] |
  424. (data & 1 ? SAR_GP_EEDO : 0));
  425. udelay(5);
  426. idt77252_write_gp(card, gp | clktab[j++] |
  427. (data & 1 ? SAR_GP_EEDO : 0));
  428. udelay(5);
  429. data >>= 1;
  430. }
  431. idt77252_write_gp(card, gp | SAR_GP_EECS);
  432. udelay(5);
  433. }
  434. static void
  435. idt77252_eeprom_init(struct idt77252_dev *card)
  436. {
  437. u32 gp;
  438. gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
  439. idt77252_write_gp(card, gp | SAR_GP_EECS | SAR_GP_EESCLK);
  440. udelay(5);
  441. idt77252_write_gp(card, gp | SAR_GP_EECS);
  442. udelay(5);
  443. idt77252_write_gp(card, gp | SAR_GP_EECS | SAR_GP_EESCLK);
  444. udelay(5);
  445. idt77252_write_gp(card, gp | SAR_GP_EECS);
  446. udelay(5);
  447. }
  448. #endif /* HAVE_EEPROM */
  449. #ifdef CONFIG_ATM_IDT77252_DEBUG
  450. static void
  451. dump_tct(struct idt77252_dev *card, int index)
  452. {
  453. unsigned long tct;
  454. int i;
  455. tct = (unsigned long) (card->tct_base + index * SAR_SRAM_TCT_SIZE);
  456. printk("%s: TCT %x:", card->name, index);
  457. for (i = 0; i < 8; i++) {
  458. printk(" %08x", read_sram(card, tct + i));
  459. }
  460. printk("\n");
  461. }
  462. static void
  463. idt77252_tx_dump(struct idt77252_dev *card)
  464. {
  465. struct atm_vcc *vcc;
  466. struct vc_map *vc;
  467. int i;
  468. printk("%s\n", __func__);
  469. for (i = 0; i < card->tct_size; i++) {
  470. vc = card->vcs[i];
  471. if (!vc)
  472. continue;
  473. vcc = NULL;
  474. if (vc->rx_vcc)
  475. vcc = vc->rx_vcc;
  476. else if (vc->tx_vcc)
  477. vcc = vc->tx_vcc;
  478. if (!vcc)
  479. continue;
  480. printk("%s: Connection %d:\n", card->name, vc->index);
  481. dump_tct(card, vc->index);
  482. }
  483. }
  484. #endif
  485. /*****************************************************************************/
  486. /* */
  487. /* SCQ Handling */
  488. /* */
  489. /*****************************************************************************/
  490. static int
  491. sb_pool_add(struct idt77252_dev *card, struct sk_buff *skb, int queue)
  492. {
  493. struct sb_pool *pool = &card->sbpool[queue];
  494. int index;
  495. index = pool->index;
  496. while (pool->skb[index]) {
  497. index = (index + 1) & FBQ_MASK;
  498. if (index == pool->index)
  499. return -ENOBUFS;
  500. }
  501. pool->skb[index] = skb;
  502. IDT77252_PRV_POOL(skb) = POOL_HANDLE(queue, index);
  503. pool->index = (index + 1) & FBQ_MASK;
  504. return 0;
  505. }
  506. static void
  507. sb_pool_remove(struct idt77252_dev *card, struct sk_buff *skb)
  508. {
  509. unsigned int queue, index;
  510. u32 handle;
  511. handle = IDT77252_PRV_POOL(skb);
  512. queue = POOL_QUEUE(handle);
  513. if (queue > 3)
  514. return;
  515. index = POOL_INDEX(handle);
  516. if (index > FBQ_SIZE - 1)
  517. return;
  518. card->sbpool[queue].skb[index] = NULL;
  519. }
  520. static struct sk_buff *
  521. sb_pool_skb(struct idt77252_dev *card, u32 handle)
  522. {
  523. unsigned int queue, index;
  524. queue = POOL_QUEUE(handle);
  525. if (queue > 3)
  526. return NULL;
  527. index = POOL_INDEX(handle);
  528. if (index > FBQ_SIZE - 1)
  529. return NULL;
  530. return card->sbpool[queue].skb[index];
  531. }
  532. static struct scq_info *
  533. alloc_scq(struct idt77252_dev *card, int class)
  534. {
  535. struct scq_info *scq;
  536. scq = kzalloc(sizeof(struct scq_info), GFP_KERNEL);
  537. if (!scq)
  538. return NULL;
  539. scq->base = pci_alloc_consistent(card->pcidev, SCQ_SIZE,
  540. &scq->paddr);
  541. if (scq->base == NULL) {
  542. kfree(scq);
  543. return NULL;
  544. }
  545. memset(scq->base, 0, SCQ_SIZE);
  546. scq->next = scq->base;
  547. scq->last = scq->base + (SCQ_ENTRIES - 1);
  548. atomic_set(&scq->used, 0);
  549. spin_lock_init(&scq->lock);
  550. spin_lock_init(&scq->skblock);
  551. skb_queue_head_init(&scq->transmit);
  552. skb_queue_head_init(&scq->pending);
  553. TXPRINTK("idt77252: SCQ: base 0x%p, next 0x%p, last 0x%p, paddr %08llx\n",
  554. scq->base, scq->next, scq->last, (unsigned long long)scq->paddr);
  555. return scq;
  556. }
  557. static void
  558. free_scq(struct idt77252_dev *card, struct scq_info *scq)
  559. {
  560. struct sk_buff *skb;
  561. struct atm_vcc *vcc;
  562. pci_free_consistent(card->pcidev, SCQ_SIZE,
  563. scq->base, scq->paddr);
  564. while ((skb = skb_dequeue(&scq->transmit))) {
  565. pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb),
  566. skb->len, PCI_DMA_TODEVICE);
  567. vcc = ATM_SKB(skb)->vcc;
  568. if (vcc->pop)
  569. vcc->pop(vcc, skb);
  570. else
  571. dev_kfree_skb(skb);
  572. }
  573. while ((skb = skb_dequeue(&scq->pending))) {
  574. pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb),
  575. skb->len, PCI_DMA_TODEVICE);
  576. vcc = ATM_SKB(skb)->vcc;
  577. if (vcc->pop)
  578. vcc->pop(vcc, skb);
  579. else
  580. dev_kfree_skb(skb);
  581. }
  582. kfree(scq);
  583. }
  584. static int
  585. push_on_scq(struct idt77252_dev *card, struct vc_map *vc, struct sk_buff *skb)
  586. {
  587. struct scq_info *scq = vc->scq;
  588. unsigned long flags;
  589. struct scqe *tbd;
  590. int entries;
  591. TXPRINTK("%s: SCQ: next 0x%p\n", card->name, scq->next);
  592. atomic_inc(&scq->used);
  593. entries = atomic_read(&scq->used);
  594. if (entries > (SCQ_ENTRIES - 1)) {
  595. atomic_dec(&scq->used);
  596. goto out;
  597. }
  598. skb_queue_tail(&scq->transmit, skb);
  599. spin_lock_irqsave(&vc->lock, flags);
  600. if (vc->estimator) {
  601. struct atm_vcc *vcc = vc->tx_vcc;
  602. struct sock *sk = sk_atm(vcc);
  603. vc->estimator->cells += (skb->len + 47) / 48;
  604. if (atomic_read(&sk->sk_wmem_alloc) >
  605. (sk->sk_sndbuf >> 1)) {
  606. u32 cps = vc->estimator->maxcps;
  607. vc->estimator->cps = cps;
  608. vc->estimator->avcps = cps << 5;
  609. if (vc->lacr < vc->init_er) {
  610. vc->lacr = vc->init_er;
  611. writel(TCMDQ_LACR | (vc->lacr << 16) |
  612. vc->index, SAR_REG_TCMDQ);
  613. }
  614. }
  615. }
  616. spin_unlock_irqrestore(&vc->lock, flags);
  617. tbd = &IDT77252_PRV_TBD(skb);
  618. spin_lock_irqsave(&scq->lock, flags);
  619. scq->next->word_1 = cpu_to_le32(tbd->word_1 |
  620. SAR_TBD_TSIF | SAR_TBD_GTSI);
  621. scq->next->word_2 = cpu_to_le32(tbd->word_2);
  622. scq->next->word_3 = cpu_to_le32(tbd->word_3);
  623. scq->next->word_4 = cpu_to_le32(tbd->word_4);
  624. if (scq->next == scq->last)
  625. scq->next = scq->base;
  626. else
  627. scq->next++;
  628. write_sram(card, scq->scd,
  629. scq->paddr +
  630. (u32)((unsigned long)scq->next - (unsigned long)scq->base));
  631. spin_unlock_irqrestore(&scq->lock, flags);
  632. scq->trans_start = jiffies;
  633. if (test_and_clear_bit(VCF_IDLE, &vc->flags)) {
  634. writel(TCMDQ_START_LACR | (vc->lacr << 16) | vc->index,
  635. SAR_REG_TCMDQ);
  636. }
  637. TXPRINTK("%d entries in SCQ used (push).\n", atomic_read(&scq->used));
  638. XPRINTK("%s: SCQ (after push %2d) head = 0x%x, next = 0x%p.\n",
  639. card->name, atomic_read(&scq->used),
  640. read_sram(card, scq->scd + 1), scq->next);
  641. return 0;
  642. out:
  643. if (time_after(jiffies, scq->trans_start + HZ)) {
  644. printk("%s: Error pushing TBD for %d.%d\n",
  645. card->name, vc->tx_vcc->vpi, vc->tx_vcc->vci);
  646. #ifdef CONFIG_ATM_IDT77252_DEBUG
  647. idt77252_tx_dump(card);
  648. #endif
  649. scq->trans_start = jiffies;
  650. }
  651. return -ENOBUFS;
  652. }
  653. static void
  654. drain_scq(struct idt77252_dev *card, struct vc_map *vc)
  655. {
  656. struct scq_info *scq = vc->scq;
  657. struct sk_buff *skb;
  658. struct atm_vcc *vcc;
  659. TXPRINTK("%s: SCQ (before drain %2d) next = 0x%p.\n",
  660. card->name, atomic_read(&scq->used), scq->next);
  661. skb = skb_dequeue(&scq->transmit);
  662. if (skb) {
  663. TXPRINTK("%s: freeing skb at %p.\n", card->name, skb);
  664. pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb),
  665. skb->len, PCI_DMA_TODEVICE);
  666. vcc = ATM_SKB(skb)->vcc;
  667. if (vcc->pop)
  668. vcc->pop(vcc, skb);
  669. else
  670. dev_kfree_skb(skb);
  671. atomic_inc(&vcc->stats->tx);
  672. }
  673. atomic_dec(&scq->used);
  674. spin_lock(&scq->skblock);
  675. while ((skb = skb_dequeue(&scq->pending))) {
  676. if (push_on_scq(card, vc, skb)) {
  677. skb_queue_head(&vc->scq->pending, skb);
  678. break;
  679. }
  680. }
  681. spin_unlock(&scq->skblock);
  682. }
  683. static int
  684. queue_skb(struct idt77252_dev *card, struct vc_map *vc,
  685. struct sk_buff *skb, int oam)
  686. {
  687. struct atm_vcc *vcc;
  688. struct scqe *tbd;
  689. unsigned long flags;
  690. int error;
  691. int aal;
  692. if (skb->len == 0) {
  693. printk("%s: invalid skb->len (%d)\n", card->name, skb->len);
  694. return -EINVAL;
  695. }
  696. TXPRINTK("%s: Sending %d bytes of data.\n",
  697. card->name, skb->len);
  698. tbd = &IDT77252_PRV_TBD(skb);
  699. vcc = ATM_SKB(skb)->vcc;
  700. IDT77252_PRV_PADDR(skb) = pci_map_single(card->pcidev, skb->data,
  701. skb->len, PCI_DMA_TODEVICE);
  702. error = -EINVAL;
  703. if (oam) {
  704. if (skb->len != 52)
  705. goto errout;
  706. tbd->word_1 = SAR_TBD_OAM | ATM_CELL_PAYLOAD | SAR_TBD_EPDU;
  707. tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4;
  708. tbd->word_3 = 0x00000000;
  709. tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) |
  710. (skb->data[2] << 8) | (skb->data[3] << 0);
  711. if (test_bit(VCF_RSV, &vc->flags))
  712. vc = card->vcs[0];
  713. goto done;
  714. }
  715. if (test_bit(VCF_RSV, &vc->flags)) {
  716. printk("%s: Trying to transmit on reserved VC\n", card->name);
  717. goto errout;
  718. }
  719. aal = vcc->qos.aal;
  720. switch (aal) {
  721. case ATM_AAL0:
  722. case ATM_AAL34:
  723. if (skb->len > 52)
  724. goto errout;
  725. if (aal == ATM_AAL0)
  726. tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL0 |
  727. ATM_CELL_PAYLOAD;
  728. else
  729. tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL34 |
  730. ATM_CELL_PAYLOAD;
  731. tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4;
  732. tbd->word_3 = 0x00000000;
  733. tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) |
  734. (skb->data[2] << 8) | (skb->data[3] << 0);
  735. break;
  736. case ATM_AAL5:
  737. tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL5 | skb->len;
  738. tbd->word_2 = IDT77252_PRV_PADDR(skb);
  739. tbd->word_3 = skb->len;
  740. tbd->word_4 = (vcc->vpi << SAR_TBD_VPI_SHIFT) |
  741. (vcc->vci << SAR_TBD_VCI_SHIFT);
  742. break;
  743. case ATM_AAL1:
  744. case ATM_AAL2:
  745. default:
  746. printk("%s: Traffic type not supported.\n", card->name);
  747. error = -EPROTONOSUPPORT;
  748. goto errout;
  749. }
  750. done:
  751. spin_lock_irqsave(&vc->scq->skblock, flags);
  752. skb_queue_tail(&vc->scq->pending, skb);
  753. while ((skb = skb_dequeue(&vc->scq->pending))) {
  754. if (push_on_scq(card, vc, skb)) {
  755. skb_queue_head(&vc->scq->pending, skb);
  756. break;
  757. }
  758. }
  759. spin_unlock_irqrestore(&vc->scq->skblock, flags);
  760. return 0;
  761. errout:
  762. pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb),
  763. skb->len, PCI_DMA_TODEVICE);
  764. return error;
  765. }
  766. static unsigned long
  767. get_free_scd(struct idt77252_dev *card, struct vc_map *vc)
  768. {
  769. int i;
  770. for (i = 0; i < card->scd_size; i++) {
  771. if (!card->scd2vc[i]) {
  772. card->scd2vc[i] = vc;
  773. vc->scd_index = i;
  774. return card->scd_base + i * SAR_SRAM_SCD_SIZE;
  775. }
  776. }
  777. return 0;
  778. }
  779. static void
  780. fill_scd(struct idt77252_dev *card, struct scq_info *scq, int class)
  781. {
  782. write_sram(card, scq->scd, scq->paddr);
  783. write_sram(card, scq->scd + 1, 0x00000000);
  784. write_sram(card, scq->scd + 2, 0xffffffff);
  785. write_sram(card, scq->scd + 3, 0x00000000);
  786. }
  787. static void
  788. clear_scd(struct idt77252_dev *card, struct scq_info *scq, int class)
  789. {
  790. return;
  791. }
  792. /*****************************************************************************/
  793. /* */
  794. /* RSQ Handling */
  795. /* */
  796. /*****************************************************************************/
  797. static int
  798. init_rsq(struct idt77252_dev *card)
  799. {
  800. struct rsq_entry *rsqe;
  801. card->rsq.base = pci_alloc_consistent(card->pcidev, RSQSIZE,
  802. &card->rsq.paddr);
  803. if (card->rsq.base == NULL) {
  804. printk("%s: can't allocate RSQ.\n", card->name);
  805. return -1;
  806. }
  807. memset(card->rsq.base, 0, RSQSIZE);
  808. card->rsq.last = card->rsq.base + RSQ_NUM_ENTRIES - 1;
  809. card->rsq.next = card->rsq.last;
  810. for (rsqe = card->rsq.base; rsqe <= card->rsq.last; rsqe++)
  811. rsqe->word_4 = 0;
  812. writel((unsigned long) card->rsq.last - (unsigned long) card->rsq.base,
  813. SAR_REG_RSQH);
  814. writel(card->rsq.paddr, SAR_REG_RSQB);
  815. IPRINTK("%s: RSQ base at 0x%lx (0x%x).\n", card->name,
  816. (unsigned long) card->rsq.base,
  817. readl(SAR_REG_RSQB));
  818. IPRINTK("%s: RSQ head = 0x%x, base = 0x%x, tail = 0x%x.\n",
  819. card->name,
  820. readl(SAR_REG_RSQH),
  821. readl(SAR_REG_RSQB),
  822. readl(SAR_REG_RSQT));
  823. return 0;
  824. }
  825. static void
  826. deinit_rsq(struct idt77252_dev *card)
  827. {
  828. pci_free_consistent(card->pcidev, RSQSIZE,
  829. card->rsq.base, card->rsq.paddr);
  830. }
  831. static void
  832. dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
  833. {
  834. struct atm_vcc *vcc;
  835. struct sk_buff *skb;
  836. struct rx_pool *rpp;
  837. struct vc_map *vc;
  838. u32 header, vpi, vci;
  839. u32 stat;
  840. int i;
  841. stat = le32_to_cpu(rsqe->word_4);
  842. if (stat & SAR_RSQE_IDLE) {
  843. RXPRINTK("%s: message about inactive connection.\n",
  844. card->name);
  845. return;
  846. }
  847. skb = sb_pool_skb(card, le32_to_cpu(rsqe->word_2));
  848. if (skb == NULL) {
  849. printk("%s: NULL skb in %s, rsqe: %08x %08x %08x %08x\n",
  850. card->name, __func__,
  851. le32_to_cpu(rsqe->word_1), le32_to_cpu(rsqe->word_2),
  852. le32_to_cpu(rsqe->word_3), le32_to_cpu(rsqe->word_4));
  853. return;
  854. }
  855. header = le32_to_cpu(rsqe->word_1);
  856. vpi = (header >> 16) & 0x00ff;
  857. vci = (header >> 0) & 0xffff;
  858. RXPRINTK("%s: SDU for %d.%d received in buffer 0x%p (data 0x%p).\n",
  859. card->name, vpi, vci, skb, skb->data);
  860. if ((vpi >= (1 << card->vpibits)) || (vci != (vci & card->vcimask))) {
  861. printk("%s: SDU received for out-of-range vc %u.%u\n",
  862. card->name, vpi, vci);
  863. recycle_rx_skb(card, skb);
  864. return;
  865. }
  866. vc = card->vcs[VPCI2VC(card, vpi, vci)];
  867. if (!vc || !test_bit(VCF_RX, &vc->flags)) {
  868. printk("%s: SDU received on non RX vc %u.%u\n",
  869. card->name, vpi, vci);
  870. recycle_rx_skb(card, skb);
  871. return;
  872. }
  873. vcc = vc->rx_vcc;
  874. pci_dma_sync_single_for_cpu(card->pcidev, IDT77252_PRV_PADDR(skb),
  875. skb_end_pointer(skb) - skb->data,
  876. PCI_DMA_FROMDEVICE);
  877. if ((vcc->qos.aal == ATM_AAL0) ||
  878. (vcc->qos.aal == ATM_AAL34)) {
  879. struct sk_buff *sb;
  880. unsigned char *cell;
  881. u32 aal0;
  882. cell = skb->data;
  883. for (i = (stat & SAR_RSQE_CELLCNT); i; i--) {
  884. if ((sb = dev_alloc_skb(64)) == NULL) {
  885. printk("%s: Can't allocate buffers for aal0.\n",
  886. card->name);
  887. atomic_add(i, &vcc->stats->rx_drop);
  888. break;
  889. }
  890. if (!atm_charge(vcc, sb->truesize)) {
  891. RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
  892. card->name);
  893. atomic_add(i - 1, &vcc->stats->rx_drop);
  894. dev_kfree_skb(sb);
  895. break;
  896. }
  897. aal0 = (vpi << ATM_HDR_VPI_SHIFT) |
  898. (vci << ATM_HDR_VCI_SHIFT);
  899. aal0 |= (stat & SAR_RSQE_EPDU) ? 0x00000002 : 0;
  900. aal0 |= (stat & SAR_RSQE_CLP) ? 0x00000001 : 0;
  901. *((u32 *) sb->data) = aal0;
  902. skb_put(sb, sizeof(u32));
  903. memcpy(skb_put(sb, ATM_CELL_PAYLOAD),
  904. cell, ATM_CELL_PAYLOAD);
  905. ATM_SKB(sb)->vcc = vcc;
  906. __net_timestamp(sb);
  907. vcc->push(vcc, sb);
  908. atomic_inc(&vcc->stats->rx);
  909. cell += ATM_CELL_PAYLOAD;
  910. }
  911. recycle_rx_skb(card, skb);
  912. return;
  913. }
  914. if (vcc->qos.aal != ATM_AAL5) {
  915. printk("%s: Unexpected AAL type in dequeue_rx(): %d.\n",
  916. card->name, vcc->qos.aal);
  917. recycle_rx_skb(card, skb);
  918. return;
  919. }
  920. skb->len = (stat & SAR_RSQE_CELLCNT) * ATM_CELL_PAYLOAD;
  921. rpp = &vc->rcv.rx_pool;
  922. __skb_queue_tail(&rpp->queue, skb);
  923. rpp->len += skb->len;
  924. if (stat & SAR_RSQE_EPDU) {
  925. unsigned char *l1l2;
  926. unsigned int len;
  927. l1l2 = (unsigned char *) ((unsigned long) skb->data + skb->len - 6);
  928. len = (l1l2[0] << 8) | l1l2[1];
  929. len = len ? len : 0x10000;
  930. RXPRINTK("%s: PDU has %d bytes.\n", card->name, len);
  931. if ((len + 8 > rpp->len) || (len + (47 + 8) < rpp->len)) {
  932. RXPRINTK("%s: AAL5 PDU size mismatch: %d != %d. "
  933. "(CDC: %08x)\n",
  934. card->name, len, rpp->len, readl(SAR_REG_CDC));
  935. recycle_rx_pool_skb(card, rpp);
  936. atomic_inc(&vcc->stats->rx_err);
  937. return;
  938. }
  939. if (stat & SAR_RSQE_CRC) {
  940. RXPRINTK("%s: AAL5 CRC error.\n", card->name);
  941. recycle_rx_pool_skb(card, rpp);
  942. atomic_inc(&vcc->stats->rx_err);
  943. return;
  944. }
  945. if (skb_queue_len(&rpp->queue) > 1) {
  946. struct sk_buff *sb;
  947. skb = dev_alloc_skb(rpp->len);
  948. if (!skb) {
  949. RXPRINTK("%s: Can't alloc RX skb.\n",
  950. card->name);
  951. recycle_rx_pool_skb(card, rpp);
  952. atomic_inc(&vcc->stats->rx_err);
  953. return;
  954. }
  955. if (!atm_charge(vcc, skb->truesize)) {
  956. recycle_rx_pool_skb(card, rpp);
  957. dev_kfree_skb(skb);
  958. return;
  959. }
  960. skb_queue_walk(&rpp->queue, sb)
  961. memcpy(skb_put(skb, sb->len),
  962. sb->data, sb->len);
  963. recycle_rx_pool_skb(card, rpp);
  964. skb_trim(skb, len);
  965. ATM_SKB(skb)->vcc = vcc;
  966. __net_timestamp(skb);
  967. vcc->push(vcc, skb);
  968. atomic_inc(&vcc->stats->rx);
  969. return;
  970. }
  971. flush_rx_pool(card, rpp);
  972. if (!atm_charge(vcc, skb->truesize)) {
  973. recycle_rx_skb(card, skb);
  974. return;
  975. }
  976. pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb),
  977. skb_end_pointer(skb) - skb->data,
  978. PCI_DMA_FROMDEVICE);
  979. sb_pool_remove(card, skb);
  980. skb_trim(skb, len);
  981. ATM_SKB(skb)->vcc = vcc;
  982. __net_timestamp(skb);
  983. vcc->push(vcc, skb);
  984. atomic_inc(&vcc->stats->rx);
  985. if (skb->truesize > SAR_FB_SIZE_3)
  986. add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
  987. else if (skb->truesize > SAR_FB_SIZE_2)
  988. add_rx_skb(card, 2, SAR_FB_SIZE_2, 1);
  989. else if (skb->truesize > SAR_FB_SIZE_1)
  990. add_rx_skb(card, 1, SAR_FB_SIZE_1, 1);
  991. else
  992. add_rx_skb(card, 0, SAR_FB_SIZE_0, 1);
  993. return;
  994. }
  995. }
  996. static void
  997. idt77252_rx(struct idt77252_dev *card)
  998. {
  999. struct rsq_entry *rsqe;
  1000. if (card->rsq.next == card->rsq.last)
  1001. rsqe = card->rsq.base;
  1002. else
  1003. rsqe = card->rsq.next + 1;
  1004. if (!(le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID)) {
  1005. RXPRINTK("%s: no entry in RSQ.\n", card->name);
  1006. return;
  1007. }
  1008. do {
  1009. dequeue_rx(card, rsqe);
  1010. rsqe->word_4 = 0;
  1011. card->rsq.next = rsqe;
  1012. if (card->rsq.next == card->rsq.last)
  1013. rsqe = card->rsq.base;
  1014. else
  1015. rsqe = card->rsq.next + 1;
  1016. } while (le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID);
  1017. writel((unsigned long) card->rsq.next - (unsigned long) card->rsq.base,
  1018. SAR_REG_RSQH);
  1019. }
  1020. static void
  1021. idt77252_rx_raw(struct idt77252_dev *card)
  1022. {
  1023. struct sk_buff *queue;
  1024. u32 head, tail;
  1025. struct atm_vcc *vcc;
  1026. struct vc_map *vc;
  1027. struct sk_buff *sb;
  1028. if (card->raw_cell_head == NULL) {
  1029. u32 handle = le32_to_cpu(*(card->raw_cell_hnd + 1));
  1030. card->raw_cell_head = sb_pool_skb(card, handle);
  1031. }
  1032. queue = card->raw_cell_head;
  1033. if (!queue)
  1034. return;
  1035. head = IDT77252_PRV_PADDR(queue) + (queue->data - queue->head - 16);
  1036. tail = readl(SAR_REG_RAWCT);
  1037. pci_dma_sync_single_for_cpu(card->pcidev, IDT77252_PRV_PADDR(queue),
  1038. skb_end_offset(queue) - 16,
  1039. PCI_DMA_FROMDEVICE);
  1040. while (head != tail) {
  1041. unsigned int vpi, vci;
  1042. u32 header;
  1043. header = le32_to_cpu(*(u32 *) &queue->data[0]);
  1044. vpi = (header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
  1045. vci = (header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
  1046. #ifdef CONFIG_ATM_IDT77252_DEBUG
  1047. if (debug & DBG_RAW_CELL) {
  1048. int i;
  1049. printk("%s: raw cell %x.%02x.%04x.%x.%x\n",
  1050. card->name, (header >> 28) & 0x000f,
  1051. (header >> 20) & 0x00ff,
  1052. (header >> 4) & 0xffff,
  1053. (header >> 1) & 0x0007,
  1054. (header >> 0) & 0x0001);
  1055. for (i = 16; i < 64; i++)
  1056. printk(" %02x", queue->data[i]);
  1057. printk("\n");
  1058. }
  1059. #endif
  1060. if (vpi >= (1<<card->vpibits) || vci >= (1<<card->vcibits)) {
  1061. RPRINTK("%s: SDU received for out-of-range vc %u.%u\n",
  1062. card->name, vpi, vci);
  1063. goto drop;
  1064. }
  1065. vc = card->vcs[VPCI2VC(card, vpi, vci)];
  1066. if (!vc || !test_bit(VCF_RX, &vc->flags)) {
  1067. RPRINTK("%s: SDU received on non RX vc %u.%u\n",
  1068. card->name, vpi, vci);
  1069. goto drop;
  1070. }
  1071. vcc = vc->rx_vcc;
  1072. if (vcc->qos.aal != ATM_AAL0) {
  1073. RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
  1074. card->name, vpi, vci);
  1075. atomic_inc(&vcc->stats->rx_drop);
  1076. goto drop;
  1077. }
  1078. if ((sb = dev_alloc_skb(64)) == NULL) {
  1079. printk("%s: Can't allocate buffers for AAL0.\n",
  1080. card->name);
  1081. atomic_inc(&vcc->stats->rx_err);
  1082. goto drop;
  1083. }
  1084. if (!atm_charge(vcc, sb->truesize)) {
  1085. RXPRINTK("%s: atm_charge() dropped AAL0 packets.\n",
  1086. card->name);
  1087. dev_kfree_skb(sb);
  1088. goto drop;
  1089. }
  1090. *((u32 *) sb->data) = header;
  1091. skb_put(sb, sizeof(u32));
  1092. memcpy(skb_put(sb, ATM_CELL_PAYLOAD), &(queue->data[16]),
  1093. ATM_CELL_PAYLOAD);
  1094. ATM_SKB(sb)->vcc = vcc;
  1095. __net_timestamp(sb);
  1096. vcc->push(vcc, sb);
  1097. atomic_inc(&vcc->stats->rx);
  1098. drop:
  1099. skb_pull(queue, 64);
  1100. head = IDT77252_PRV_PADDR(queue)
  1101. + (queue->data - queue->head - 16);
  1102. if (queue->len < 128) {
  1103. struct sk_buff *next;
  1104. u32 handle;
  1105. head = le32_to_cpu(*(u32 *) &queue->data[0]);
  1106. handle = le32_to_cpu(*(u32 *) &queue->data[4]);
  1107. next = sb_pool_skb(card, handle);
  1108. recycle_rx_skb(card, queue);
  1109. if (next) {
  1110. card->raw_cell_head = next;
  1111. queue = card->raw_cell_head;
  1112. pci_dma_sync_single_for_cpu(card->pcidev,
  1113. IDT77252_PRV_PADDR(queue),
  1114. (skb_end_pointer(queue) -
  1115. queue->data),
  1116. PCI_DMA_FROMDEVICE);
  1117. } else {
  1118. card->raw_cell_head = NULL;
  1119. printk("%s: raw cell queue overrun\n",
  1120. card->name);
  1121. break;
  1122. }
  1123. }
  1124. }
  1125. }
  1126. /*****************************************************************************/
  1127. /* */
  1128. /* TSQ Handling */
  1129. /* */
  1130. /*****************************************************************************/
  1131. static int
  1132. init_tsq(struct idt77252_dev *card)
  1133. {
  1134. struct tsq_entry *tsqe;
  1135. card->tsq.base = pci_alloc_consistent(card->pcidev, RSQSIZE,
  1136. &card->tsq.paddr);
  1137. if (card->tsq.base == NULL) {
  1138. printk("%s: can't allocate TSQ.\n", card->name);
  1139. return -1;
  1140. }
  1141. memset(card->tsq.base, 0, TSQSIZE);
  1142. card->tsq.last = card->tsq.base + TSQ_NUM_ENTRIES - 1;
  1143. card->tsq.next = card->tsq.last;
  1144. for (tsqe = card->tsq.base; tsqe <= card->tsq.last; tsqe++)
  1145. tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID);
  1146. writel(card->tsq.paddr, SAR_REG_TSQB);
  1147. writel((unsigned long) card->tsq.next - (unsigned long) card->tsq.base,
  1148. SAR_REG_TSQH);
  1149. return 0;
  1150. }
  1151. static void
  1152. deinit_tsq(struct idt77252_dev *card)
  1153. {
  1154. pci_free_consistent(card->pcidev, TSQSIZE,
  1155. card->tsq.base, card->tsq.paddr);
  1156. }
  1157. static void
  1158. idt77252_tx(struct idt77252_dev *card)
  1159. {
  1160. struct tsq_entry *tsqe;
  1161. unsigned int vpi, vci;
  1162. struct vc_map *vc;
  1163. u32 conn, stat;
  1164. if (card->tsq.next == card->tsq.last)
  1165. tsqe = card->tsq.base;
  1166. else
  1167. tsqe = card->tsq.next + 1;
  1168. TXPRINTK("idt77252_tx: tsq %p: base %p, next %p, last %p\n", tsqe,
  1169. card->tsq.base, card->tsq.next, card->tsq.last);
  1170. TXPRINTK("idt77252_tx: tsqb %08x, tsqt %08x, tsqh %08x, \n",
  1171. readl(SAR_REG_TSQB),
  1172. readl(SAR_REG_TSQT),
  1173. readl(SAR_REG_TSQH));
  1174. stat = le32_to_cpu(tsqe->word_2);
  1175. if (stat & SAR_TSQE_INVALID)
  1176. return;
  1177. do {
  1178. TXPRINTK("tsqe: 0x%p [0x%08x 0x%08x]\n", tsqe,
  1179. le32_to_cpu(tsqe->word_1),
  1180. le32_to_cpu(tsqe->word_2));
  1181. switch (stat & SAR_TSQE_TYPE) {
  1182. case SAR_TSQE_TYPE_TIMER:
  1183. TXPRINTK("%s: Timer RollOver detected.\n", card->name);
  1184. break;
  1185. case SAR_TSQE_TYPE_IDLE:
  1186. conn = le32_to_cpu(tsqe->word_1);
  1187. if (SAR_TSQE_TAG(stat) == 0x10) {
  1188. #ifdef NOTDEF
  1189. printk("%s: Connection %d halted.\n",
  1190. card->name,
  1191. le32_to_cpu(tsqe->word_1) & 0x1fff);
  1192. #endif
  1193. break;
  1194. }
  1195. vc = card->vcs[conn & 0x1fff];
  1196. if (!vc) {
  1197. printk("%s: could not find VC from conn %d\n",
  1198. card->name, conn & 0x1fff);
  1199. break;
  1200. }
  1201. printk("%s: Connection %d IDLE.\n",
  1202. card->name, vc->index);
  1203. set_bit(VCF_IDLE, &vc->flags);
  1204. break;
  1205. case SAR_TSQE_TYPE_TSR:
  1206. conn = le32_to_cpu(tsqe->word_1);
  1207. vc = card->vcs[conn & 0x1fff];
  1208. if (!vc) {
  1209. printk("%s: no VC at index %d\n",
  1210. card->name,
  1211. le32_to_cpu(tsqe->word_1) & 0x1fff);
  1212. break;
  1213. }
  1214. drain_scq(card, vc);
  1215. break;
  1216. case SAR_TSQE_TYPE_TBD_COMP:
  1217. conn = le32_to_cpu(tsqe->word_1);
  1218. vpi = (conn >> SAR_TBD_VPI_SHIFT) & 0x00ff;
  1219. vci = (conn >> SAR_TBD_VCI_SHIFT) & 0xffff;
  1220. if (vpi >= (1 << card->vpibits) ||
  1221. vci >= (1 << card->vcibits)) {
  1222. printk("%s: TBD complete: "
  1223. "out of range VPI.VCI %u.%u\n",
  1224. card->name, vpi, vci);
  1225. break;
  1226. }
  1227. vc = card->vcs[VPCI2VC(card, vpi, vci)];
  1228. if (!vc) {
  1229. printk("%s: TBD complete: "
  1230. "no VC at VPI.VCI %u.%u\n",
  1231. card->name, vpi, vci);
  1232. break;
  1233. }
  1234. drain_scq(card, vc);
  1235. break;
  1236. }
  1237. tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID);
  1238. card->tsq.next = tsqe;
  1239. if (card->tsq.next == card->tsq.last)
  1240. tsqe = card->tsq.base;
  1241. else
  1242. tsqe = card->tsq.next + 1;
  1243. TXPRINTK("tsqe: %p: base %p, next %p, last %p\n", tsqe,
  1244. card->tsq.base, card->tsq.next, card->tsq.last);
  1245. stat = le32_to_cpu(tsqe->word_2);
  1246. } while (!(stat & SAR_TSQE_INVALID));
  1247. writel((unsigned long)card->tsq.next - (unsigned long)card->tsq.base,
  1248. SAR_REG_TSQH);
  1249. XPRINTK("idt77252_tx-after writel%d: TSQ head = 0x%x, tail = 0x%x, next = 0x%p.\n",
  1250. card->index, readl(SAR_REG_TSQH),
  1251. readl(SAR_REG_TSQT), card->tsq.next);
  1252. }
  1253. static void
  1254. tst_timer(unsigned long data)
  1255. {
  1256. struct idt77252_dev *card = (struct idt77252_dev *)data;
  1257. unsigned long base, idle, jump;
  1258. unsigned long flags;
  1259. u32 pc;
  1260. int e;
  1261. spin_lock_irqsave(&card->tst_lock, flags);
  1262. base = card->tst[card->tst_index];
  1263. idle = card->tst[card->tst_index ^ 1];
  1264. if (test_bit(TST_SWITCH_WAIT, &card->tst_state)) {
  1265. jump = base + card->tst_size - 2;
  1266. pc = readl(SAR_REG_NOW) >> 2;
  1267. if ((pc ^ idle) & ~(card->tst_size - 1)) {
  1268. mod_timer(&card->tst_timer, jiffies + 1);
  1269. goto out;
  1270. }
  1271. clear_bit(TST_SWITCH_WAIT, &card->tst_state);
  1272. card->tst_index ^= 1;
  1273. write_sram(card, jump, TSTE_OPC_JMP | (base << 2));
  1274. base = card->tst[card->tst_index];
  1275. idle = card->tst[card->tst_index ^ 1];
  1276. for (e = 0; e < card->tst_size - 2; e++) {
  1277. if (card->soft_tst[e].tste & TSTE_PUSH_IDLE) {
  1278. write_sram(card, idle + e,
  1279. card->soft_tst[e].tste & TSTE_MASK);
  1280. card->soft_tst[e].tste &= ~(TSTE_PUSH_IDLE);
  1281. }
  1282. }
  1283. }
  1284. if (test_and_clear_bit(TST_SWITCH_PENDING, &card->tst_state)) {
  1285. for (e = 0; e < card->tst_size - 2; e++) {
  1286. if (card->soft_tst[e].tste & TSTE_PUSH_ACTIVE) {
  1287. write_sram(card, idle + e,
  1288. card->soft_tst[e].tste & TSTE_MASK);
  1289. card->soft_tst[e].tste &= ~(TSTE_PUSH_ACTIVE);
  1290. card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
  1291. }
  1292. }
  1293. jump = base + card->tst_size - 2;
  1294. write_sram(card, jump, TSTE_OPC_NULL);
  1295. set_bit(TST_SWITCH_WAIT, &card->tst_state);
  1296. mod_timer(&card->tst_timer, jiffies + 1);
  1297. }
  1298. out:
  1299. spin_unlock_irqrestore(&card->tst_lock, flags);
  1300. }
  1301. static int
  1302. __fill_tst(struct idt77252_dev *card, struct vc_map *vc,
  1303. int n, unsigned int opc)
  1304. {
  1305. unsigned long cl, avail;
  1306. unsigned long idle;
  1307. int e, r;
  1308. u32 data;
  1309. avail = card->tst_size - 2;
  1310. for (e = 0; e < avail; e++) {
  1311. if (card->soft_tst[e].vc == NULL)
  1312. break;
  1313. }
  1314. if (e >= avail) {
  1315. printk("%s: No free TST entries found\n", card->name);
  1316. return -1;
  1317. }
  1318. NPRINTK("%s: conn %d: first TST entry at %d.\n",
  1319. card->name, vc ? vc->index : -1, e);
  1320. r = n;
  1321. cl = avail;
  1322. data = opc & TSTE_OPC_MASK;
  1323. if (vc && (opc != TSTE_OPC_NULL))
  1324. data = opc | vc->index;
  1325. idle = card->tst[card->tst_index ^ 1];
  1326. /*
  1327. * Fill Soft TST.
  1328. */
  1329. while (r > 0) {
  1330. if ((cl >= avail) && (card->soft_tst[e].vc == NULL)) {
  1331. if (vc)
  1332. card->soft_tst[e].vc = vc;
  1333. else
  1334. card->soft_tst[e].vc = (void *)-1;
  1335. card->soft_tst[e].tste = data;
  1336. if (timer_pending(&card->tst_timer))
  1337. card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE;
  1338. else {
  1339. write_sram(card, idle + e, data);
  1340. card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
  1341. }
  1342. cl -= card->tst_size;
  1343. r--;
  1344. }
  1345. if (++e == avail)
  1346. e = 0;
  1347. cl += n;
  1348. }
  1349. return 0;
  1350. }
  1351. static int
  1352. fill_tst(struct idt77252_dev *card, struct vc_map *vc, int n, unsigned int opc)
  1353. {
  1354. unsigned long flags;
  1355. int res;
  1356. spin_lock_irqsave(&card->tst_lock, flags);
  1357. res = __fill_tst(card, vc, n, opc);
  1358. set_bit(TST_SWITCH_PENDING, &card->tst_state);
  1359. if (!timer_pending(&card->tst_timer))
  1360. mod_timer(&card->tst_timer, jiffies + 1);
  1361. spin_unlock_irqrestore(&card->tst_lock, flags);
  1362. return res;
  1363. }
  1364. static int
  1365. __clear_tst(struct idt77252_dev *card, struct vc_map *vc)
  1366. {
  1367. unsigned long idle;
  1368. int e;
  1369. idle = card->tst[card->tst_index ^ 1];
  1370. for (e = 0; e < card->tst_size - 2; e++) {
  1371. if (card->soft_tst[e].vc == vc) {
  1372. card->soft_tst[e].vc = NULL;
  1373. card->soft_tst[e].tste = TSTE_OPC_VAR;
  1374. if (timer_pending(&card->tst_timer))
  1375. card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE;
  1376. else {
  1377. write_sram(card, idle + e, TSTE_OPC_VAR);
  1378. card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
  1379. }
  1380. }
  1381. }
  1382. return 0;
  1383. }
  1384. static int
  1385. clear_tst(struct idt77252_dev *card, struct vc_map *vc)
  1386. {
  1387. unsigned long flags;
  1388. int res;
  1389. spin_lock_irqsave(&card->tst_lock, flags);
  1390. res = __clear_tst(card, vc);
  1391. set_bit(TST_SWITCH_PENDING, &card->tst_state);
  1392. if (!timer_pending(&card->tst_timer))
  1393. mod_timer(&card->tst_timer, jiffies + 1);
  1394. spin_unlock_irqrestore(&card->tst_lock, flags);
  1395. return res;
  1396. }
  1397. static int
  1398. change_tst(struct idt77252_dev *card, struct vc_map *vc,
  1399. int n, unsigned int opc)
  1400. {
  1401. unsigned long flags;
  1402. int res;
  1403. spin_lock_irqsave(&card->tst_lock, flags);
  1404. __clear_tst(card, vc);
  1405. res = __fill_tst(card, vc, n, opc);
  1406. set_bit(TST_SWITCH_PENDING, &card->tst_state);
  1407. if (!timer_pending(&card->tst_timer))
  1408. mod_timer(&card->tst_timer, jiffies + 1);
  1409. spin_unlock_irqrestore(&card->tst_lock, flags);
  1410. return res;
  1411. }
  1412. static int
  1413. set_tct(struct idt77252_dev *card, struct vc_map *vc)
  1414. {
  1415. unsigned long tct;
  1416. tct = (unsigned long) (card->tct_base + vc->index * SAR_SRAM_TCT_SIZE);
  1417. switch (vc->class) {
  1418. case SCHED_CBR:
  1419. OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n",
  1420. card->name, tct, vc->scq->scd);
  1421. write_sram(card, tct + 0, TCT_CBR | vc->scq->scd);
  1422. write_sram(card, tct + 1, 0);
  1423. write_sram(card, tct + 2, 0);
  1424. write_sram(card, tct + 3, 0);
  1425. write_sram(card, tct + 4, 0);
  1426. write_sram(card, tct + 5, 0);
  1427. write_sram(card, tct + 6, 0);
  1428. write_sram(card, tct + 7, 0);
  1429. break;
  1430. case SCHED_UBR:
  1431. OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n",
  1432. card->name, tct, vc->scq->scd);
  1433. write_sram(card, tct + 0, TCT_UBR | vc->scq->scd);
  1434. write_sram(card, tct + 1, 0);
  1435. write_sram(card, tct + 2, TCT_TSIF);
  1436. write_sram(card, tct + 3, TCT_HALT | TCT_IDLE);
  1437. write_sram(card, tct + 4, 0);
  1438. write_sram(card, tct + 5, vc->init_er);
  1439. write_sram(card, tct + 6, 0);
  1440. write_sram(card, tct + 7, TCT_FLAG_UBR);
  1441. break;
  1442. case SCHED_VBR:
  1443. case SCHED_ABR:
  1444. default:
  1445. return -ENOSYS;
  1446. }
  1447. return 0;
  1448. }
  1449. /*****************************************************************************/
  1450. /* */
  1451. /* FBQ Handling */
  1452. /* */
  1453. /*****************************************************************************/
  1454. static __inline__ int
  1455. idt77252_fbq_level(struct idt77252_dev *card, int queue)
  1456. {
  1457. return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) & 0x0f;
  1458. }
  1459. static __inline__ int
  1460. idt77252_fbq_full(struct idt77252_dev *card, int queue)
  1461. {
  1462. return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) == 0x0f;
  1463. }
  1464. static int
  1465. push_rx_skb(struct idt77252_dev *card, struct sk_buff *skb, int queue)
  1466. {
  1467. unsigned long flags;
  1468. u32 handle;
  1469. u32 addr;
  1470. skb->data = skb->head;
  1471. skb_reset_tail_pointer(skb);
  1472. skb->len = 0;
  1473. skb_reserve(skb, 16);
  1474. switch (queue) {
  1475. case 0:
  1476. skb_put(skb, SAR_FB_SIZE_0);
  1477. break;
  1478. case 1:
  1479. skb_put(skb, SAR_FB_SIZE_1);
  1480. break;
  1481. case 2:
  1482. skb_put(skb, SAR_FB_SIZE_2);
  1483. break;
  1484. case 3:
  1485. skb_put(skb, SAR_FB_SIZE_3);
  1486. break;
  1487. default:
  1488. return -1;
  1489. }
  1490. if (idt77252_fbq_full(card, queue))
  1491. return -1;
  1492. memset(&skb->data[(skb->len & ~(0x3f)) - 64], 0, 2 * sizeof(u32));
  1493. handle = IDT77252_PRV_POOL(skb);
  1494. addr = IDT77252_PRV_PADDR(skb);
  1495. spin_lock_irqsave(&card->cmd_lock, flags);
  1496. writel(handle, card->fbq[queue]);
  1497. writel(addr, card->fbq[queue]);
  1498. spin_unlock_irqrestore(&card->cmd_lock, flags);
  1499. return 0;
  1500. }
  1501. static void
  1502. add_rx_skb(struct idt77252_dev *card, int queue,
  1503. unsigned int size, unsigned int count)
  1504. {
  1505. struct sk_buff *skb;
  1506. dma_addr_t paddr;
  1507. u32 handle;
  1508. while (count--) {
  1509. skb = dev_alloc_skb(size);
  1510. if (!skb)
  1511. return;
  1512. if (sb_pool_add(card, skb, queue)) {
  1513. printk("%s: SB POOL full\n", __func__);
  1514. goto outfree;
  1515. }
  1516. paddr = pci_map_single(card->pcidev, skb->data,
  1517. skb_end_pointer(skb) - skb->data,
  1518. PCI_DMA_FROMDEVICE);
  1519. IDT77252_PRV_PADDR(skb) = paddr;
  1520. if (push_rx_skb(card, skb, queue)) {
  1521. printk("%s: FB QUEUE full\n", __func__);
  1522. goto outunmap;
  1523. }
  1524. }
  1525. return;
  1526. outunmap:
  1527. pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb),
  1528. skb_end_pointer(skb) - skb->data, PCI_DMA_FROMDEVICE);
  1529. handle = IDT77252_PRV_POOL(skb);
  1530. card->sbpool[POOL_QUEUE(handle)].skb[POOL_INDEX(handle)] = NULL;
  1531. outfree:
  1532. dev_kfree_skb(skb);
  1533. }
  1534. static void
  1535. recycle_rx_skb(struct idt77252_dev *card, struct sk_buff *skb)
  1536. {
  1537. u32 handle = IDT77252_PRV_POOL(skb);
  1538. int err;
  1539. pci_dma_sync_single_for_device(card->pcidev, IDT77252_PRV_PADDR(skb),
  1540. skb_end_pointer(skb) - skb->data,
  1541. PCI_DMA_FROMDEVICE);
  1542. err = push_rx_skb(card, skb, POOL_QUEUE(handle));
  1543. if (err) {
  1544. pci_unmap_single(card->pcidev, IDT77252_PRV_PADDR(skb),
  1545. skb_end_pointer(skb) - skb->data,
  1546. PCI_DMA_FROMDEVICE);
  1547. sb_pool_remove(card, skb);
  1548. dev_kfree_skb(skb);
  1549. }
  1550. }
  1551. static void
  1552. flush_rx_pool(struct idt77252_dev *card, struct rx_pool *rpp)
  1553. {
  1554. skb_queue_head_init(&rpp->queue);
  1555. rpp->len = 0;
  1556. }
  1557. static void
  1558. recycle_rx_pool_skb(struct idt77252_dev *card, struct rx_pool *rpp)
  1559. {
  1560. struct sk_buff *skb, *tmp;
  1561. skb_queue_walk_safe(&rpp->queue, skb, tmp)
  1562. recycle_rx_skb(card, skb);
  1563. flush_rx_pool(card, rpp);
  1564. }
  1565. /*****************************************************************************/
  1566. /* */
  1567. /* ATM Interface */
  1568. /* */
  1569. /*****************************************************************************/
  1570. static void
  1571. idt77252_phy_put(struct atm_dev *dev, unsigned char value, unsigned long addr)
  1572. {
  1573. write_utility(dev->dev_data, 0x100 + (addr & 0x1ff), value);
  1574. }
  1575. static unsigned char
  1576. idt77252_phy_get(struct atm_dev *dev, unsigned long addr)
  1577. {
  1578. return read_utility(dev->dev_data, 0x100 + (addr & 0x1ff));
  1579. }
  1580. static inline int
  1581. idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
  1582. {
  1583. struct atm_dev *dev = vcc->dev;
  1584. struct idt77252_dev *card = dev->dev_data;
  1585. struct vc_map *vc = vcc->dev_data;
  1586. int err;
  1587. if (vc == NULL) {
  1588. printk("%s: NULL connection in send().\n", card->name);
  1589. atomic_inc(&vcc->stats->tx_err);
  1590. dev_kfree_skb(skb);
  1591. return -EINVAL;
  1592. }
  1593. if (!test_bit(VCF_TX, &vc->flags)) {
  1594. printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
  1595. atomic_inc(&vcc->stats->tx_err);
  1596. dev_kfree_skb(skb);
  1597. return -EINVAL;
  1598. }
  1599. switch (vcc->qos.aal) {
  1600. case ATM_AAL0:
  1601. case ATM_AAL1:
  1602. case ATM_AAL5:
  1603. break;
  1604. default:
  1605. printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
  1606. atomic_inc(&vcc->stats->tx_err);
  1607. dev_kfree_skb(skb);
  1608. return -EINVAL;
  1609. }
  1610. if (skb_shinfo(skb)->nr_frags != 0) {
  1611. printk("%s: No scatter-gather yet.\n", card->name);
  1612. atomic_inc(&vcc->stats->tx_err);
  1613. dev_kfree_skb(skb);
  1614. return -EINVAL;
  1615. }
  1616. ATM_SKB(skb)->vcc = vcc;
  1617. err = queue_skb(card, vc, skb, oam);
  1618. if (err) {
  1619. atomic_inc(&vcc->stats->tx_err);
  1620. dev_kfree_skb(skb);
  1621. return err;
  1622. }
  1623. return 0;
  1624. }
  1625. static int idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb)
  1626. {
  1627. return idt77252_send_skb(vcc, skb, 0);
  1628. }
  1629. static int
  1630. idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
  1631. {
  1632. struct atm_dev *dev = vcc->dev;
  1633. struct idt77252_dev *card = dev->dev_data;
  1634. struct sk_buff *skb;
  1635. skb = dev_alloc_skb(64);
  1636. if (!skb) {
  1637. printk("%s: Out of memory in send_oam().\n", card->name);
  1638. atomic_inc(&vcc->stats->tx_err);
  1639. return -ENOMEM;
  1640. }
  1641. atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  1642. memcpy(skb_put(skb, 52), cell, 52);
  1643. return idt77252_send_skb(vcc, skb, 1);
  1644. }
  1645. static __inline__ unsigned int
  1646. idt77252_fls(unsigned int x)
  1647. {
  1648. int r = 1;
  1649. if (x == 0)
  1650. return 0;
  1651. if (x & 0xffff0000) {
  1652. x >>= 16;
  1653. r += 16;
  1654. }
  1655. if (x & 0xff00) {
  1656. x >>= 8;
  1657. r += 8;
  1658. }
  1659. if (x & 0xf0) {
  1660. x >>= 4;
  1661. r += 4;
  1662. }
  1663. if (x & 0xc) {
  1664. x >>= 2;
  1665. r += 2;
  1666. }
  1667. if (x & 0x2)
  1668. r += 1;
  1669. return r;
  1670. }
  1671. static u16
  1672. idt77252_int_to_atmfp(unsigned int rate)
  1673. {
  1674. u16 m, e;
  1675. if (rate == 0)
  1676. return 0;
  1677. e = idt77252_fls(rate) - 1;
  1678. if (e < 9)
  1679. m = (rate - (1 << e)) << (9 - e);
  1680. else if (e == 9)
  1681. m = (rate - (1 << e));
  1682. else /* e > 9 */
  1683. m = (rate - (1 << e)) >> (e - 9);
  1684. return 0x4000 | (e << 9) | m;
  1685. }
  1686. static u8
  1687. idt77252_rate_logindex(struct idt77252_dev *card, int pcr)
  1688. {
  1689. u16 afp;
  1690. afp = idt77252_int_to_atmfp(pcr < 0 ? -pcr : pcr);
  1691. if (pcr < 0)
  1692. return rate_to_log[(afp >> 5) & 0x1ff];
  1693. return rate_to_log[((afp >> 5) + 1) & 0x1ff];
  1694. }
  1695. static void
  1696. idt77252_est_timer(unsigned long data)
  1697. {
  1698. struct vc_map *vc = (struct vc_map *)data;
  1699. struct idt77252_dev *card = vc->card;
  1700. struct rate_estimator *est;
  1701. unsigned long flags;
  1702. u32 rate, cps;
  1703. u64 ncells;
  1704. u8 lacr;
  1705. spin_lock_irqsave(&vc->lock, flags);
  1706. est = vc->estimator;
  1707. if (!est)
  1708. goto out;
  1709. ncells = est->cells;
  1710. rate = ((u32)(ncells - est->last_cells)) << (7 - est->interval);
  1711. est->last_cells = ncells;
  1712. est->avcps += ((long)rate - (long)est->avcps) >> est->ewma_log;
  1713. est->cps = (est->avcps + 0x1f) >> 5;
  1714. cps = est->cps;
  1715. if (cps < (est->maxcps >> 4))
  1716. cps = est->maxcps >> 4;
  1717. lacr = idt77252_rate_logindex(card, cps);
  1718. if (lacr > vc->max_er)
  1719. lacr = vc->max_er;
  1720. if (lacr != vc->lacr) {
  1721. vc->lacr = lacr;
  1722. writel(TCMDQ_LACR|(vc->lacr << 16)|vc->index, SAR_REG_TCMDQ);
  1723. }
  1724. est->timer.expires = jiffies + ((HZ / 4) << est->interval);
  1725. add_timer(&est->timer);
  1726. out:
  1727. spin_unlock_irqrestore(&vc->lock, flags);
  1728. }
  1729. static struct rate_estimator *
  1730. idt77252_init_est(struct vc_map *vc, int pcr)
  1731. {
  1732. struct rate_estimator *est;
  1733. est = kzalloc(sizeof(struct rate_estimator), GFP_KERNEL);
  1734. if (!est)
  1735. return NULL;
  1736. est->maxcps = pcr < 0 ? -pcr : pcr;
  1737. est->cps = est->maxcps;
  1738. est->avcps = est->cps << 5;
  1739. est->interval = 2; /* XXX: make this configurable */
  1740. est->ewma_log = 2; /* XXX: make this configurable */
  1741. init_timer(&est->timer);
  1742. est->timer.data = (unsigned long)vc;
  1743. est->timer.function = idt77252_est_timer;
  1744. est->timer.expires = jiffies + ((HZ / 4) << est->interval);
  1745. add_timer(&est->timer);
  1746. return est;
  1747. }
  1748. static int
  1749. idt77252_init_cbr(struct idt77252_dev *card, struct vc_map *vc,
  1750. struct atm_vcc *vcc, struct atm_qos *qos)
  1751. {
  1752. int tst_free, tst_used, tst_entries;
  1753. unsigned long tmpl, modl;
  1754. int tcr, tcra;
  1755. if ((qos->txtp.max_pcr == 0) &&
  1756. (qos->txtp.pcr == 0) && (qos->txtp.min_pcr == 0)) {
  1757. printk("%s: trying to open a CBR VC with cell rate = 0\n",
  1758. card->name);
  1759. return -EINVAL;
  1760. }
  1761. tst_used = 0;
  1762. tst_free = card->tst_free;
  1763. if (test_bit(VCF_TX, &vc->flags))
  1764. tst_used = vc->ntste;
  1765. tst_free += tst_used;
  1766. tcr = atm_pcr_goal(&qos->txtp);
  1767. tcra = tcr >= 0 ? tcr : -tcr;
  1768. TXPRINTK("%s: CBR target cell rate = %d\n", card->name, tcra);
  1769. tmpl = (unsigned long) tcra * ((unsigned long) card->tst_size - 2);
  1770. modl = tmpl % (unsigned long)card->utopia_pcr;
  1771. tst_entries = (int) (tmpl / card->utopia_pcr);
  1772. if (tcr > 0) {
  1773. if (modl > 0)
  1774. tst_entries++;
  1775. } else if (tcr == 0) {
  1776. tst_entries = tst_free - SAR_TST_RESERVED;
  1777. if (tst_entries <= 0) {
  1778. printk("%s: no CBR bandwidth free.\n", card->name);
  1779. return -ENOSR;
  1780. }
  1781. }
  1782. if (tst_entries == 0) {
  1783. printk("%s: selected CBR bandwidth < granularity.\n",
  1784. card->name);
  1785. return -EINVAL;
  1786. }
  1787. if (tst_entries > (tst_free - SAR_TST_RESERVED)) {
  1788. printk("%s: not enough CBR bandwidth free.\n", card->name);
  1789. return -ENOSR;
  1790. }
  1791. vc->ntste = tst_entries;
  1792. card->tst_free = tst_free - tst_entries;
  1793. if (test_bit(VCF_TX, &vc->flags)) {
  1794. if (tst_used == tst_entries)
  1795. return 0;
  1796. OPRINTK("%s: modify %d -> %d entries in TST.\n",
  1797. card->name, tst_used, tst_entries);
  1798. change_tst(card, vc, tst_entries, TSTE_OPC_CBR);
  1799. return 0;
  1800. }
  1801. OPRINTK("%s: setting %d entries in TST.\n", card->name, tst_entries);
  1802. fill_tst(card, vc, tst_entries, TSTE_OPC_CBR);
  1803. return 0;
  1804. }
  1805. static int
  1806. idt77252_init_ubr(struct idt77252_dev *card, struct vc_map *vc,
  1807. struct atm_vcc *vcc, struct atm_qos *qos)
  1808. {
  1809. unsigned long flags;
  1810. int tcr;
  1811. spin_lock_irqsave(&vc->lock, flags);
  1812. if (vc->estimator) {
  1813. del_timer(&vc->estimator->timer);
  1814. kfree(vc->estimator);
  1815. vc->estimator = NULL;
  1816. }
  1817. spin_unlock_irqrestore(&vc->lock, flags);
  1818. tcr = atm_pcr_goal(&qos->txtp);
  1819. if (tcr == 0)
  1820. tcr = card->link_pcr;
  1821. vc->estimator = idt77252_init_est(vc, tcr);
  1822. vc->class = SCHED_UBR;
  1823. vc->init_er = idt77252_rate_logindex(card, tcr);
  1824. vc->lacr = vc->init_er;
  1825. if (tcr < 0)
  1826. vc->max_er = vc->init_er;
  1827. else
  1828. vc->max_er = 0xff;
  1829. return 0;
  1830. }
  1831. static int
  1832. idt77252_init_tx(struct idt77252_dev *card, struct vc_map *vc,
  1833. struct atm_vcc *vcc, struct atm_qos *qos)
  1834. {
  1835. int error;
  1836. if (test_bit(VCF_TX, &vc->flags))
  1837. return -EBUSY;
  1838. switch (qos->txtp.traffic_class) {
  1839. case ATM_CBR:
  1840. vc->class = SCHED_CBR;
  1841. break;
  1842. case ATM_UBR:
  1843. vc->class = SCHED_UBR;
  1844. break;
  1845. case ATM_VBR:
  1846. case ATM_ABR:
  1847. default:
  1848. return -EPROTONOSUPPORT;
  1849. }
  1850. vc->scq = alloc_scq(card, vc->class);
  1851. if (!vc->scq) {
  1852. printk("%s: can't get SCQ.\n", card->name);
  1853. return -ENOMEM;
  1854. }
  1855. vc->scq->scd = get_free_scd(card, vc);
  1856. if (vc->scq->scd == 0) {
  1857. printk("%s: no SCD available.\n", card->name);
  1858. free_scq(card, vc->scq);
  1859. return -ENOMEM;
  1860. }
  1861. fill_scd(card, vc->scq, vc->class);
  1862. if (set_tct(card, vc)) {
  1863. printk("%s: class %d not supported.\n",
  1864. card->name, qos->txtp.traffic_class);
  1865. card->scd2vc[vc->scd_index] = NULL;
  1866. free_scq(card, vc->scq);
  1867. return -EPROTONOSUPPORT;
  1868. }
  1869. switch (vc->class) {
  1870. case SCHED_CBR:
  1871. error = idt77252_init_cbr(card, vc, vcc, qos);
  1872. if (error) {
  1873. card->scd2vc[vc->scd_index] = NULL;
  1874. free_scq(card, vc->scq);
  1875. return error;
  1876. }
  1877. clear_bit(VCF_IDLE, &vc->flags);
  1878. writel(TCMDQ_START | vc->index, SAR_REG_TCMDQ);
  1879. break;
  1880. case SCHED_UBR:
  1881. error = idt77252_init_ubr(card, vc, vcc, qos);
  1882. if (error) {
  1883. card->scd2vc[vc->scd_index] = NULL;
  1884. free_scq(card, vc->scq);
  1885. return error;
  1886. }
  1887. set_bit(VCF_IDLE, &vc->flags);
  1888. break;
  1889. }
  1890. vc->tx_vcc = vcc;
  1891. set_bit(VCF_TX, &vc->flags);
  1892. return 0;
  1893. }
  1894. static int
  1895. idt77252_init_rx(struct idt77252_dev *card, struct vc_map *vc,
  1896. struct atm_vcc *vcc, struct atm_qos *qos)
  1897. {
  1898. unsigned long flags;
  1899. unsigned long addr;
  1900. u32 rcte = 0;
  1901. if (test_bit(VCF_RX, &vc->flags))
  1902. return -EBUSY;
  1903. vc->rx_vcc = vcc;
  1904. set_bit(VCF_RX, &vc->flags);
  1905. if ((vcc->vci == 3) || (vcc->vci == 4))
  1906. return 0;
  1907. flush_rx_pool(card, &vc->rcv.rx_pool);
  1908. rcte |= SAR_RCTE_CONNECTOPEN;
  1909. rcte |= SAR_RCTE_RAWCELLINTEN;
  1910. switch (qos->aal) {
  1911. case ATM_AAL0:
  1912. rcte |= SAR_RCTE_RCQ;
  1913. break;
  1914. case ATM_AAL1:
  1915. rcte |= SAR_RCTE_OAM; /* Let SAR drop Video */
  1916. break;
  1917. case ATM_AAL34:
  1918. rcte |= SAR_RCTE_AAL34;
  1919. break;
  1920. case ATM_AAL5:
  1921. rcte |= SAR_RCTE_AAL5;
  1922. break;
  1923. default:
  1924. rcte |= SAR_RCTE_RCQ;
  1925. break;
  1926. }
  1927. if (qos->aal != ATM_AAL5)
  1928. rcte |= SAR_RCTE_FBP_1;
  1929. else if (qos->rxtp.max_sdu > SAR_FB_SIZE_2)
  1930. rcte |= SAR_RCTE_FBP_3;
  1931. else if (qos->rxtp.max_sdu > SAR_FB_SIZE_1)
  1932. rcte |= SAR_RCTE_FBP_2;
  1933. else if (qos->rxtp.max_sdu > SAR_FB_SIZE_0)
  1934. rcte |= SAR_RCTE_FBP_1;
  1935. else
  1936. rcte |= SAR_RCTE_FBP_01;
  1937. addr = card->rct_base + (vc->index << 2);
  1938. OPRINTK("%s: writing RCT at 0x%lx\n", card->name, addr);
  1939. write_sram(card, addr, rcte);
  1940. spin_lock_irqsave(&card->cmd_lock, flags);
  1941. writel(SAR_CMD_OPEN_CONNECTION | (addr << 2), SAR_REG_CMD);
  1942. waitfor_idle(card);
  1943. spin_unlock_irqrestore(&card->cmd_lock, flags);
  1944. return 0;
  1945. }
  1946. static int
  1947. idt77252_open(struct atm_vcc *vcc)
  1948. {
  1949. struct atm_dev *dev = vcc->dev;
  1950. struct idt77252_dev *card = dev->dev_data;
  1951. struct vc_map *vc;
  1952. unsigned int index;
  1953. unsigned int inuse;
  1954. int error;
  1955. int vci = vcc->vci;
  1956. short vpi = vcc->vpi;
  1957. if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
  1958. return 0;
  1959. if (vpi >= (1 << card->vpibits)) {
  1960. printk("%s: unsupported VPI: %d\n", card->name, vpi);
  1961. return -EINVAL;
  1962. }
  1963. if (vci >= (1 << card->vcibits)) {
  1964. printk("%s: unsupported VCI: %d\n", card->name, vci);
  1965. return -EINVAL;
  1966. }
  1967. set_bit(ATM_VF_ADDR, &vcc->flags);
  1968. mutex_lock(&card->mutex);
  1969. OPRINTK("%s: opening vpi.vci: %d.%d\n", card->name, vpi, vci);
  1970. switch (vcc->qos.aal) {
  1971. case ATM_AAL0:
  1972. case ATM_AAL1:
  1973. case ATM_AAL5:
  1974. break;
  1975. default:
  1976. printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
  1977. mutex_unlock(&card->mutex);
  1978. return -EPROTONOSUPPORT;
  1979. }
  1980. index = VPCI2VC(card, vpi, vci);
  1981. if (!card->vcs[index]) {
  1982. card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
  1983. if (!card->vcs[index]) {
  1984. printk("%s: can't alloc vc in open()\n", card->name);
  1985. mutex_unlock(&card->mutex);
  1986. return -ENOMEM;
  1987. }
  1988. card->vcs[index]->card = card;
  1989. card->vcs[index]->index = index;
  1990. spin_lock_init(&card->vcs[index]->lock);
  1991. }
  1992. vc = card->vcs[index];
  1993. vcc->dev_data = vc;
  1994. IPRINTK("%s: idt77252_open: vc = %d (%d.%d) %s/%s (max RX SDU: %u)\n",
  1995. card->name, vc->index, vcc->vpi, vcc->vci,
  1996. vcc->qos.rxtp.traffic_class != ATM_NONE ? "rx" : "--",
  1997. vcc->qos.txtp.traffic_class != ATM_NONE ? "tx" : "--",
  1998. vcc->qos.rxtp.max_sdu);
  1999. inuse = 0;
  2000. if (vcc->qos.txtp.traffic_class != ATM_NONE &&
  2001. test_bit(VCF_TX, &vc->flags))
  2002. inuse = 1;
  2003. if (vcc->qos.rxtp.traffic_class != ATM_NONE &&
  2004. test_bit(VCF_RX, &vc->flags))
  2005. inuse += 2;
  2006. if (inuse) {
  2007. printk("%s: %s vci already in use.\n", card->name,
  2008. inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx");
  2009. mutex_unlock(&card->mutex);
  2010. return -EADDRINUSE;
  2011. }
  2012. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  2013. error = idt77252_init_tx(card, vc, vcc, &vcc->qos);
  2014. if (error) {
  2015. mutex_unlock(&card->mutex);
  2016. return error;
  2017. }
  2018. }
  2019. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  2020. error = idt77252_init_rx(card, vc, vcc, &vcc->qos);
  2021. if (error) {
  2022. mutex_unlock(&card->mutex);
  2023. return error;
  2024. }
  2025. }
  2026. set_bit(ATM_VF_READY, &vcc->flags);
  2027. mutex_unlock(&card->mutex);
  2028. return 0;
  2029. }
  2030. static void
  2031. idt77252_close(struct atm_vcc *vcc)
  2032. {
  2033. struct atm_dev *dev = vcc->dev;
  2034. struct idt77252_dev *card = dev->dev_data;
  2035. struct vc_map *vc = vcc->dev_data;
  2036. unsigned long flags;
  2037. unsigned long addr;
  2038. unsigned long timeout;
  2039. mutex_lock(&card->mutex);
  2040. IPRINTK("%s: idt77252_close: vc = %d (%d.%d)\n",
  2041. card->name, vc->index, vcc->vpi, vcc->vci);
  2042. clear_bit(ATM_VF_READY, &vcc->flags);
  2043. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  2044. spin_lock_irqsave(&vc->lock, flags);
  2045. clear_bit(VCF_RX, &vc->flags);
  2046. vc->rx_vcc = NULL;
  2047. spin_unlock_irqrestore(&vc->lock, flags);
  2048. if ((vcc->vci == 3) || (vcc->vci == 4))
  2049. goto done;
  2050. addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE;
  2051. spin_lock_irqsave(&card->cmd_lock, flags);
  2052. writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2), SAR_REG_CMD);
  2053. waitfor_idle(card);
  2054. spin_unlock_irqrestore(&card->cmd_lock, flags);
  2055. if (skb_queue_len(&vc->rcv.rx_pool.queue) != 0) {
  2056. DPRINTK("%s: closing a VC with pending rx buffers.\n",
  2057. card->name);
  2058. recycle_rx_pool_skb(card, &vc->rcv.rx_pool);
  2059. }
  2060. }
  2061. done:
  2062. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  2063. spin_lock_irqsave(&vc->lock, flags);
  2064. clear_bit(VCF_TX, &vc->flags);
  2065. clear_bit(VCF_IDLE, &vc->flags);
  2066. clear_bit(VCF_RSV, &vc->flags);
  2067. vc->tx_vcc = NULL;
  2068. if (vc->estimator) {
  2069. del_timer(&vc->estimator->timer);
  2070. kfree(vc->estimator);
  2071. vc->estimator = NULL;
  2072. }
  2073. spin_unlock_irqrestore(&vc->lock, flags);
  2074. timeout = 5 * 1000;
  2075. while (atomic_read(&vc->scq->used) > 0) {
  2076. timeout = msleep_interruptible(timeout);
  2077. if (!timeout)
  2078. break;
  2079. }
  2080. if (!timeout)
  2081. printk("%s: SCQ drain timeout: %u used\n",
  2082. card->name, atomic_read(&vc->scq->used));
  2083. writel(TCMDQ_HALT | vc->index, SAR_REG_TCMDQ);
  2084. clear_scd(card, vc->scq, vc->class);
  2085. if (vc->class == SCHED_CBR) {
  2086. clear_tst(card, vc);
  2087. card->tst_free += vc->ntste;
  2088. vc->ntste = 0;
  2089. }
  2090. card->scd2vc[vc->scd_index] = NULL;
  2091. free_scq(card, vc->scq);
  2092. }
  2093. mutex_unlock(&card->mutex);
  2094. }
  2095. static int
  2096. idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags)
  2097. {
  2098. struct atm_dev *dev = vcc->dev;
  2099. struct idt77252_dev *card = dev->dev_data;
  2100. struct vc_map *vc = vcc->dev_data;
  2101. int error = 0;
  2102. mutex_lock(&card->mutex);
  2103. if (qos->txtp.traffic_class != ATM_NONE) {
  2104. if (!test_bit(VCF_TX, &vc->flags)) {
  2105. error = idt77252_init_tx(card, vc, vcc, qos);
  2106. if (error)
  2107. goto out;
  2108. } else {
  2109. switch (qos->txtp.traffic_class) {
  2110. case ATM_CBR:
  2111. error = idt77252_init_cbr(card, vc, vcc, qos);
  2112. if (error)
  2113. goto out;
  2114. break;
  2115. case ATM_UBR:
  2116. error = idt77252_init_ubr(card, vc, vcc, qos);
  2117. if (error)
  2118. goto out;
  2119. if (!test_bit(VCF_IDLE, &vc->flags)) {
  2120. writel(TCMDQ_LACR | (vc->lacr << 16) |
  2121. vc->index, SAR_REG_TCMDQ);
  2122. }
  2123. break;
  2124. case ATM_VBR:
  2125. case ATM_ABR:
  2126. error = -EOPNOTSUPP;
  2127. goto out;
  2128. }
  2129. }
  2130. }
  2131. if ((qos->rxtp.traffic_class != ATM_NONE) &&
  2132. !test_bit(VCF_RX, &vc->flags)) {
  2133. error = idt77252_init_rx(card, vc, vcc, qos);
  2134. if (error)
  2135. goto out;
  2136. }
  2137. memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
  2138. set_bit(ATM_VF_HASQOS, &vcc->flags);
  2139. out:
  2140. mutex_unlock(&card->mutex);
  2141. return error;
  2142. }
  2143. static int
  2144. idt77252_proc_read(struct atm_dev *dev, loff_t * pos, char *page)
  2145. {
  2146. struct idt77252_dev *card = dev->dev_data;
  2147. int i, left;
  2148. left = (int) *pos;
  2149. if (!left--)
  2150. return sprintf(page, "IDT77252 Interrupts:\n");
  2151. if (!left--)
  2152. return sprintf(page, "TSIF: %lu\n", card->irqstat[15]);
  2153. if (!left--)
  2154. return sprintf(page, "TXICP: %lu\n", card->irqstat[14]);
  2155. if (!left--)
  2156. return sprintf(page, "TSQF: %lu\n", card->irqstat[12]);
  2157. if (!left--)
  2158. return sprintf(page, "TMROF: %lu\n", card->irqstat[11]);
  2159. if (!left--)
  2160. return sprintf(page, "PHYI: %lu\n", card->irqstat[10]);
  2161. if (!left--)
  2162. return sprintf(page, "FBQ3A: %lu\n", card->irqstat[8]);
  2163. if (!left--)
  2164. return sprintf(page, "FBQ2A: %lu\n", card->irqstat[7]);
  2165. if (!left--)
  2166. return sprintf(page, "RSQF: %lu\n", card->irqstat[6]);
  2167. if (!left--)
  2168. return sprintf(page, "EPDU: %lu\n", card->irqstat[5]);
  2169. if (!left--)
  2170. return sprintf(page, "RAWCF: %lu\n", card->irqstat[4]);
  2171. if (!left--)
  2172. return sprintf(page, "FBQ1A: %lu\n", card->irqstat[3]);
  2173. if (!left--)
  2174. return sprintf(page, "FBQ0A: %lu\n", card->irqstat[2]);
  2175. if (!left--)
  2176. return sprintf(page, "RSQAF: %lu\n", card->irqstat[1]);
  2177. if (!left--)
  2178. return sprintf(page, "IDT77252 Transmit Connection Table:\n");
  2179. for (i = 0; i < card->tct_size; i++) {
  2180. unsigned long tct;
  2181. struct atm_vcc *vcc;
  2182. struct vc_map *vc;
  2183. char *p;
  2184. vc = card->vcs[i];
  2185. if (!vc)
  2186. continue;
  2187. vcc = NULL;
  2188. if (vc->tx_vcc)
  2189. vcc = vc->tx_vcc;
  2190. if (!vcc)
  2191. continue;
  2192. if (left--)
  2193. continue;
  2194. p = page;
  2195. p += sprintf(p, " %4u: %u.%u: ", i, vcc->vpi, vcc->vci);
  2196. tct = (unsigned long) (card->tct_base + i * SAR_SRAM_TCT_SIZE);
  2197. for (i = 0; i < 8; i++)
  2198. p += sprintf(p, " %08x", read_sram(card, tct + i));
  2199. p += sprintf(p, "\n");
  2200. return p - page;
  2201. }
  2202. return 0;
  2203. }
  2204. /*****************************************************************************/
  2205. /* */
  2206. /* Interrupt handler */
  2207. /* */
  2208. /*****************************************************************************/
  2209. static void
  2210. idt77252_collect_stat(struct idt77252_dev *card)
  2211. {
  2212. (void) readl(SAR_REG_CDC);
  2213. (void) readl(SAR_REG_VPEC);
  2214. (void) readl(SAR_REG_ICC);
  2215. }
  2216. static irqreturn_t
  2217. idt77252_interrupt(int irq, void *dev_id)
  2218. {
  2219. struct idt77252_dev *card = dev_id;
  2220. u32 stat;
  2221. stat = readl(SAR_REG_STAT) & 0xffff;
  2222. if (!stat) /* no interrupt for us */
  2223. return IRQ_NONE;
  2224. if (test_and_set_bit(IDT77252_BIT_INTERRUPT, &card->flags)) {
  2225. printk("%s: Re-entering irq_handler()\n", card->name);
  2226. goto out;
  2227. }
  2228. writel(stat, SAR_REG_STAT); /* reset interrupt */
  2229. if (stat & SAR_STAT_TSIF) { /* entry written to TSQ */
  2230. INTPRINTK("%s: TSIF\n", card->name);
  2231. card->irqstat[15]++;
  2232. idt77252_tx(card);
  2233. }
  2234. if (stat & SAR_STAT_TXICP) { /* Incomplete CS-PDU has */
  2235. INTPRINTK("%s: TXICP\n", card->name);
  2236. card->irqstat[14]++;
  2237. #ifdef CONFIG_ATM_IDT77252_DEBUG
  2238. idt77252_tx_dump(card);
  2239. #endif
  2240. }
  2241. if (stat & SAR_STAT_TSQF) { /* TSQ 7/8 full */
  2242. INTPRINTK("%s: TSQF\n", card->name);
  2243. card->irqstat[12]++;
  2244. idt77252_tx(card);
  2245. }
  2246. if (stat & SAR_STAT_TMROF) { /* Timer overflow */
  2247. INTPRINTK("%s: TMROF\n", card->name);
  2248. card->irqstat[11]++;
  2249. idt77252_collect_stat(card);
  2250. }
  2251. if (stat & SAR_STAT_EPDU) { /* Got complete CS-PDU */
  2252. INTPRINTK("%s: EPDU\n", card->name);
  2253. card->irqstat[5]++;
  2254. idt77252_rx(card);
  2255. }
  2256. if (stat & SAR_STAT_RSQAF) { /* RSQ is 7/8 full */
  2257. INTPRINTK("%s: RSQAF\n", card->name);
  2258. card->irqstat[1]++;
  2259. idt77252_rx(card);
  2260. }
  2261. if (stat & SAR_STAT_RSQF) { /* RSQ is full */
  2262. INTPRINTK("%s: RSQF\n", card->name);
  2263. card->irqstat[6]++;
  2264. idt77252_rx(card);
  2265. }
  2266. if (stat & SAR_STAT_RAWCF) { /* Raw cell received */
  2267. INTPRINTK("%s: RAWCF\n", card->name);
  2268. card->irqstat[4]++;
  2269. idt77252_rx_raw(card);
  2270. }
  2271. if (stat & SAR_STAT_PHYI) { /* PHY device interrupt */
  2272. INTPRINTK("%s: PHYI", card->name);
  2273. card->irqstat[10]++;
  2274. if (card->atmdev->phy && card->atmdev->phy->interrupt)
  2275. card->atmdev->phy->interrupt(card->atmdev);
  2276. }
  2277. if (stat & (SAR_STAT_FBQ0A | SAR_STAT_FBQ1A |
  2278. SAR_STAT_FBQ2A | SAR_STAT_FBQ3A)) {
  2279. writel(readl(SAR_REG_CFG) & ~(SAR_CFG_FBIE), SAR_REG_CFG);
  2280. INTPRINTK("%s: FBQA: %04x\n", card->name, stat);
  2281. if (stat & SAR_STAT_FBQ0A)
  2282. card->irqstat[2]++;
  2283. if (stat & SAR_STAT_FBQ1A)
  2284. card->irqstat[3]++;
  2285. if (stat & SAR_STAT_FBQ2A)
  2286. card->irqstat[7]++;
  2287. if (stat & SAR_STAT_FBQ3A)
  2288. card->irqstat[8]++;
  2289. schedule_work(&card->tqueue);
  2290. }
  2291. out:
  2292. clear_bit(IDT77252_BIT_INTERRUPT, &card->flags);
  2293. return IRQ_HANDLED;
  2294. }
  2295. static void
  2296. idt77252_softint(struct work_struct *work)
  2297. {
  2298. struct idt77252_dev *card =
  2299. container_of(work, struct idt77252_dev, tqueue);
  2300. u32 stat;
  2301. int done;
  2302. for (done = 1; ; done = 1) {
  2303. stat = readl(SAR_REG_STAT) >> 16;
  2304. if ((stat & 0x0f) < SAR_FBQ0_HIGH) {
  2305. add_rx_skb(card, 0, SAR_FB_SIZE_0, 32);
  2306. done = 0;
  2307. }
  2308. stat >>= 4;
  2309. if ((stat & 0x0f) < SAR_FBQ1_HIGH) {
  2310. add_rx_skb(card, 1, SAR_FB_SIZE_1, 32);
  2311. done = 0;
  2312. }
  2313. stat >>= 4;
  2314. if ((stat & 0x0f) < SAR_FBQ2_HIGH) {
  2315. add_rx_skb(card, 2, SAR_FB_SIZE_2, 32);
  2316. done = 0;
  2317. }
  2318. stat >>= 4;
  2319. if ((stat & 0x0f) < SAR_FBQ3_HIGH) {
  2320. add_rx_skb(card, 3, SAR_FB_SIZE_3, 32);
  2321. done = 0;
  2322. }
  2323. if (done)
  2324. break;
  2325. }
  2326. writel(readl(SAR_REG_CFG) | SAR_CFG_FBIE, SAR_REG_CFG);
  2327. }
  2328. static int
  2329. open_card_oam(struct idt77252_dev *card)
  2330. {
  2331. unsigned long flags;
  2332. unsigned long addr;
  2333. struct vc_map *vc;
  2334. int vpi, vci;
  2335. int index;
  2336. u32 rcte;
  2337. for (vpi = 0; vpi < (1 << card->vpibits); vpi++) {
  2338. for (vci = 3; vci < 5; vci++) {
  2339. index = VPCI2VC(card, vpi, vci);
  2340. vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
  2341. if (!vc) {
  2342. printk("%s: can't alloc vc\n", card->name);
  2343. return -ENOMEM;
  2344. }
  2345. vc->index = index;
  2346. card->vcs[index] = vc;
  2347. flush_rx_pool(card, &vc->rcv.rx_pool);
  2348. rcte = SAR_RCTE_CONNECTOPEN |
  2349. SAR_RCTE_RAWCELLINTEN |
  2350. SAR_RCTE_RCQ |
  2351. SAR_RCTE_FBP_1;
  2352. addr = card->rct_base + (vc->index << 2);
  2353. write_sram(card, addr, rcte);
  2354. spin_lock_irqsave(&card->cmd_lock, flags);
  2355. writel(SAR_CMD_OPEN_CONNECTION | (addr << 2),
  2356. SAR_REG_CMD);
  2357. waitfor_idle(card);
  2358. spin_unlock_irqrestore(&card->cmd_lock, flags);
  2359. }
  2360. }
  2361. return 0;
  2362. }
  2363. static void
  2364. close_card_oam(struct idt77252_dev *card)
  2365. {
  2366. unsigned long flags;
  2367. unsigned long addr;
  2368. struct vc_map *vc;
  2369. int vpi, vci;
  2370. int index;
  2371. for (vpi = 0; vpi < (1 << card->vpibits); vpi++) {
  2372. for (vci = 3; vci < 5; vci++) {
  2373. index = VPCI2VC(card, vpi, vci);
  2374. vc = card->vcs[index];
  2375. addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE;
  2376. spin_lock_irqsave(&card->cmd_lock, flags);
  2377. writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2),
  2378. SAR_REG_CMD);
  2379. waitfor_idle(card);
  2380. spin_unlock_irqrestore(&card->cmd_lock, flags);
  2381. if (skb_queue_len(&vc->rcv.rx_pool.queue) != 0) {
  2382. DPRINTK("%s: closing a VC "
  2383. "with pending rx buffers.\n",
  2384. card->name);
  2385. recycle_rx_pool_skb(card, &vc->rcv.rx_pool);
  2386. }
  2387. }
  2388. }
  2389. }
  2390. static int
  2391. open_card_ubr0(struct idt77252_dev *card)
  2392. {
  2393. struct vc_map *vc;
  2394. vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
  2395. if (!vc) {
  2396. printk("%s: can't alloc vc\n", card->name);
  2397. return -ENOMEM;
  2398. }
  2399. card->vcs[0] = vc;
  2400. vc->class = SCHED_UBR0;
  2401. vc->scq = alloc_scq(card, vc->class);
  2402. if (!vc->scq) {
  2403. printk("%s: can't get SCQ.\n", card->name);
  2404. return -ENOMEM;
  2405. }
  2406. card->scd2vc[0] = vc;
  2407. vc->scd_index = 0;
  2408. vc->scq->scd = card->scd_base;
  2409. fill_scd(card, vc->scq, vc->class);
  2410. write_sram(card, card->tct_base + 0, TCT_UBR | card->scd_base);
  2411. write_sram(card, card->tct_base + 1, 0);
  2412. write_sram(card, card->tct_base + 2, 0);
  2413. write_sram(card, card->tct_base + 3, 0);
  2414. write_sram(card, card->tct_base + 4, 0);
  2415. write_sram(card, card->tct_base + 5, 0);
  2416. write_sram(card, card->tct_base + 6, 0);
  2417. write_sram(card, card->tct_base + 7, TCT_FLAG_UBR);
  2418. clear_bit(VCF_IDLE, &vc->flags);
  2419. writel(TCMDQ_START | 0, SAR_REG_TCMDQ);
  2420. return 0;
  2421. }
  2422. static int
  2423. idt77252_dev_open(struct idt77252_dev *card)
  2424. {
  2425. u32 conf;
  2426. if (!test_bit(IDT77252_BIT_INIT, &card->flags)) {
  2427. printk("%s: SAR not yet initialized.\n", card->name);
  2428. return -1;
  2429. }
  2430. conf = SAR_CFG_RXPTH| /* enable receive path */
  2431. SAR_RX_DELAY | /* interrupt on complete PDU */
  2432. SAR_CFG_RAWIE | /* interrupt enable on raw cells */
  2433. SAR_CFG_RQFIE | /* interrupt on RSQ almost full */
  2434. SAR_CFG_TMOIE | /* interrupt on timer overflow */
  2435. SAR_CFG_FBIE | /* interrupt on low free buffers */
  2436. SAR_CFG_TXEN | /* transmit operation enable */
  2437. SAR_CFG_TXINT | /* interrupt on transmit status */
  2438. SAR_CFG_TXUIE | /* interrupt on transmit underrun */
  2439. SAR_CFG_TXSFI | /* interrupt on TSQ almost full */
  2440. SAR_CFG_PHYIE /* enable PHY interrupts */
  2441. ;
  2442. #ifdef CONFIG_ATM_IDT77252_RCV_ALL
  2443. /* Test RAW cell receive. */
  2444. conf |= SAR_CFG_VPECA;
  2445. #endif
  2446. writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG);
  2447. if (open_card_oam(card)) {
  2448. printk("%s: Error initializing OAM.\n", card->name);
  2449. return -1;
  2450. }
  2451. if (open_card_ubr0(card)) {
  2452. printk("%s: Error initializing UBR0.\n", card->name);
  2453. return -1;
  2454. }
  2455. IPRINTK("%s: opened IDT77252 ABR SAR.\n", card->name);
  2456. return 0;
  2457. }
  2458. static void idt77252_dev_close(struct atm_dev *dev)
  2459. {
  2460. struct idt77252_dev *card = dev->dev_data;
  2461. u32 conf;
  2462. close_card_oam(card);
  2463. conf = SAR_CFG_RXPTH | /* enable receive path */
  2464. SAR_RX_DELAY | /* interrupt on complete PDU */
  2465. SAR_CFG_RAWIE | /* interrupt enable on raw cells */
  2466. SAR_CFG_RQFIE | /* interrupt on RSQ almost full */
  2467. SAR_CFG_TMOIE | /* interrupt on timer overflow */
  2468. SAR_CFG_FBIE | /* interrupt on low free buffers */
  2469. SAR_CFG_TXEN | /* transmit operation enable */
  2470. SAR_CFG_TXINT | /* interrupt on transmit status */
  2471. SAR_CFG_TXUIE | /* interrupt on xmit underrun */
  2472. SAR_CFG_TXSFI /* interrupt on TSQ almost full */
  2473. ;
  2474. writel(readl(SAR_REG_CFG) & ~(conf), SAR_REG_CFG);
  2475. DIPRINTK("%s: closed IDT77252 ABR SAR.\n", card->name);
  2476. }
  2477. /*****************************************************************************/
  2478. /* */
  2479. /* Initialisation and Deinitialization of IDT77252 */
  2480. /* */
  2481. /*****************************************************************************/
  2482. static void
  2483. deinit_card(struct idt77252_dev *card)
  2484. {
  2485. struct sk_buff *skb;
  2486. int i, j;
  2487. if (!test_bit(IDT77252_BIT_INIT, &card->flags)) {
  2488. printk("%s: SAR not yet initialized.\n", card->name);
  2489. return;
  2490. }
  2491. DIPRINTK("idt77252: deinitialize card %u\n", card->index);
  2492. writel(0, SAR_REG_CFG);
  2493. if (card->atmdev)
  2494. atm_dev_deregister(card->atmdev);
  2495. for (i = 0; i < 4; i++) {
  2496. for (j = 0; j < FBQ_SIZE; j++) {
  2497. skb = card->sbpool[i].skb[j];
  2498. if (skb) {
  2499. pci_unmap_single(card->pcidev,
  2500. IDT77252_PRV_PADDR(skb),
  2501. (skb_end_pointer(skb) -
  2502. skb->data),
  2503. PCI_DMA_FROMDEVICE);
  2504. card->sbpool[i].skb[j] = NULL;
  2505. dev_kfree_skb(skb);
  2506. }
  2507. }
  2508. }
  2509. vfree(card->soft_tst);
  2510. vfree(card->scd2vc);
  2511. vfree(card->vcs);
  2512. if (card->raw_cell_hnd) {
  2513. pci_free_consistent(card->pcidev, 2 * sizeof(u32),
  2514. card->raw_cell_hnd, card->raw_cell_paddr);
  2515. }
  2516. if (card->rsq.base) {
  2517. DIPRINTK("%s: Release RSQ ...\n", card->name);
  2518. deinit_rsq(card);
  2519. }
  2520. if (card->tsq.base) {
  2521. DIPRINTK("%s: Release TSQ ...\n", card->name);
  2522. deinit_tsq(card);
  2523. }
  2524. DIPRINTK("idt77252: Release IRQ.\n");
  2525. free_irq(card->pcidev->irq, card);
  2526. for (i = 0; i < 4; i++) {
  2527. if (card->fbq[i])
  2528. iounmap(card->fbq[i]);
  2529. }
  2530. if (card->membase)
  2531. iounmap(card->membase);
  2532. clear_bit(IDT77252_BIT_INIT, &card->flags);
  2533. DIPRINTK("%s: Card deinitialized.\n", card->name);
  2534. }
  2535. static void __devinit
  2536. init_sram(struct idt77252_dev *card)
  2537. {
  2538. int i;
  2539. for (i = 0; i < card->sramsize; i += 4)
  2540. write_sram(card, (i >> 2), 0);
  2541. /* set SRAM layout for THIS card */
  2542. if (card->sramsize == (512 * 1024)) {
  2543. card->tct_base = SAR_SRAM_TCT_128_BASE;
  2544. card->tct_size = (SAR_SRAM_TCT_128_TOP - card->tct_base + 1)
  2545. / SAR_SRAM_TCT_SIZE;
  2546. card->rct_base = SAR_SRAM_RCT_128_BASE;
  2547. card->rct_size = (SAR_SRAM_RCT_128_TOP - card->rct_base + 1)
  2548. / SAR_SRAM_RCT_SIZE;
  2549. card->rt_base = SAR_SRAM_RT_128_BASE;
  2550. card->scd_base = SAR_SRAM_SCD_128_BASE;
  2551. card->scd_size = (SAR_SRAM_SCD_128_TOP - card->scd_base + 1)
  2552. / SAR_SRAM_SCD_SIZE;
  2553. card->tst[0] = SAR_SRAM_TST1_128_BASE;
  2554. card->tst[1] = SAR_SRAM_TST2_128_BASE;
  2555. card->tst_size = SAR_SRAM_TST1_128_TOP - card->tst[0] + 1;
  2556. card->abrst_base = SAR_SRAM_ABRSTD_128_BASE;
  2557. card->abrst_size = SAR_ABRSTD_SIZE_8K;
  2558. card->fifo_base = SAR_SRAM_FIFO_128_BASE;
  2559. card->fifo_size = SAR_RXFD_SIZE_32K;
  2560. } else {
  2561. card->tct_base = SAR_SRAM_TCT_32_BASE;
  2562. card->tct_size = (SAR_SRAM_TCT_32_TOP - card->tct_base + 1)
  2563. / SAR_SRAM_TCT_SIZE;
  2564. card->rct_base = SAR_SRAM_RCT_32_BASE;
  2565. card->rct_size = (SAR_SRAM_RCT_32_TOP - card->rct_base + 1)
  2566. / SAR_SRAM_RCT_SIZE;
  2567. card->rt_base = SAR_SRAM_RT_32_BASE;
  2568. card->scd_base = SAR_SRAM_SCD_32_BASE;
  2569. card->scd_size = (SAR_SRAM_SCD_32_TOP - card->scd_base + 1)
  2570. / SAR_SRAM_SCD_SIZE;
  2571. card->tst[0] = SAR_SRAM_TST1_32_BASE;
  2572. card->tst[1] = SAR_SRAM_TST2_32_BASE;
  2573. card->tst_size = (SAR_SRAM_TST1_32_TOP - card->tst[0] + 1);
  2574. card->abrst_base = SAR_SRAM_ABRSTD_32_BASE;
  2575. card->abrst_size = SAR_ABRSTD_SIZE_1K;
  2576. card->fifo_base = SAR_SRAM_FIFO_32_BASE;
  2577. card->fifo_size = SAR_RXFD_SIZE_4K;
  2578. }
  2579. /* Initialize TCT */
  2580. for (i = 0; i < card->tct_size; i++) {
  2581. write_sram(card, i * SAR_SRAM_TCT_SIZE + 0, 0);
  2582. write_sram(card, i * SAR_SRAM_TCT_SIZE + 1, 0);
  2583. write_sram(card, i * SAR_SRAM_TCT_SIZE + 2, 0);
  2584. write_sram(card, i * SAR_SRAM_TCT_SIZE + 3, 0);
  2585. write_sram(card, i * SAR_SRAM_TCT_SIZE + 4, 0);
  2586. write_sram(card, i * SAR_SRAM_TCT_SIZE + 5, 0);
  2587. write_sram(card, i * SAR_SRAM_TCT_SIZE + 6, 0);
  2588. write_sram(card, i * SAR_SRAM_TCT_SIZE + 7, 0);
  2589. }
  2590. /* Initialize RCT */
  2591. for (i = 0; i < card->rct_size; i++) {
  2592. write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE,
  2593. (u32) SAR_RCTE_RAWCELLINTEN);
  2594. write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 1,
  2595. (u32) 0);
  2596. write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 2,
  2597. (u32) 0);
  2598. write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 3,
  2599. (u32) 0xffffffff);
  2600. }
  2601. writel((SAR_FBQ0_LOW << 28) | 0x00000000 | 0x00000000 |
  2602. (SAR_FB_SIZE_0 / 48), SAR_REG_FBQS0);
  2603. writel((SAR_FBQ1_LOW << 28) | 0x00000000 | 0x00000000 |
  2604. (SAR_FB_SIZE_1 / 48), SAR_REG_FBQS1);
  2605. writel((SAR_FBQ2_LOW << 28) | 0x00000000 | 0x00000000 |
  2606. (SAR_FB_SIZE_2 / 48), SAR_REG_FBQS2);
  2607. writel((SAR_FBQ3_LOW << 28) | 0x00000000 | 0x00000000 |
  2608. (SAR_FB_SIZE_3 / 48), SAR_REG_FBQS3);
  2609. /* Initialize rate table */
  2610. for (i = 0; i < 256; i++) {
  2611. write_sram(card, card->rt_base + i, log_to_rate[i]);
  2612. }
  2613. for (i = 0; i < 128; i++) {
  2614. unsigned int tmp;
  2615. tmp = rate_to_log[(i << 2) + 0] << 0;
  2616. tmp |= rate_to_log[(i << 2) + 1] << 8;
  2617. tmp |= rate_to_log[(i << 2) + 2] << 16;
  2618. tmp |= rate_to_log[(i << 2) + 3] << 24;
  2619. write_sram(card, card->rt_base + 256 + i, tmp);
  2620. }
  2621. #if 0 /* Fill RDF and AIR tables. */
  2622. for (i = 0; i < 128; i++) {
  2623. unsigned int tmp;
  2624. tmp = RDF[0][(i << 1) + 0] << 16;
  2625. tmp |= RDF[0][(i << 1) + 1] << 0;
  2626. write_sram(card, card->rt_base + 512 + i, tmp);
  2627. }
  2628. for (i = 0; i < 128; i++) {
  2629. unsigned int tmp;
  2630. tmp = AIR[0][(i << 1) + 0] << 16;
  2631. tmp |= AIR[0][(i << 1) + 1] << 0;
  2632. write_sram(card, card->rt_base + 640 + i, tmp);
  2633. }
  2634. #endif
  2635. IPRINTK("%s: initialize rate table ...\n", card->name);
  2636. writel(card->rt_base << 2, SAR_REG_RTBL);
  2637. /* Initialize TSTs */
  2638. IPRINTK("%s: initialize TST ...\n", card->name);
  2639. card->tst_free = card->tst_size - 2; /* last two are jumps */
  2640. for (i = card->tst[0]; i < card->tst[0] + card->tst_size - 2; i++)
  2641. write_sram(card, i, TSTE_OPC_VAR);
  2642. write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2));
  2643. idt77252_sram_write_errors = 1;
  2644. write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2));
  2645. idt77252_sram_write_errors = 0;
  2646. for (i = card->tst[1]; i < card->tst[1] + card->tst_size - 2; i++)
  2647. write_sram(card, i, TSTE_OPC_VAR);
  2648. write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2));
  2649. idt77252_sram_write_errors = 1;
  2650. write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2));
  2651. idt77252_sram_write_errors = 0;
  2652. card->tst_index = 0;
  2653. writel(card->tst[0] << 2, SAR_REG_TSTB);
  2654. /* Initialize ABRSTD and Receive FIFO */
  2655. IPRINTK("%s: initialize ABRSTD ...\n", card->name);
  2656. writel(card->abrst_size | (card->abrst_base << 2),
  2657. SAR_REG_ABRSTD);
  2658. IPRINTK("%s: initialize receive fifo ...\n", card->name);
  2659. writel(card->fifo_size | (card->fifo_base << 2),
  2660. SAR_REG_RXFD);
  2661. IPRINTK("%s: SRAM initialization complete.\n", card->name);
  2662. }
  2663. static int __devinit
  2664. init_card(struct atm_dev *dev)
  2665. {
  2666. struct idt77252_dev *card = dev->dev_data;
  2667. struct pci_dev *pcidev = card->pcidev;
  2668. unsigned long tmpl, modl;
  2669. unsigned int linkrate, rsvdcr;
  2670. unsigned int tst_entries;
  2671. struct net_device *tmp;
  2672. char tname[10];
  2673. u32 size;
  2674. u_char pci_byte;
  2675. u32 conf;
  2676. int i, k;
  2677. if (test_bit(IDT77252_BIT_INIT, &card->flags)) {
  2678. printk("Error: SAR already initialized.\n");
  2679. return -1;
  2680. }
  2681. /*****************************************************************/
  2682. /* P C I C O N F I G U R A T I O N */
  2683. /*****************************************************************/
  2684. /* Set PCI Retry-Timeout and TRDY timeout */
  2685. IPRINTK("%s: Checking PCI retries.\n", card->name);
  2686. if (pci_read_config_byte(pcidev, 0x40, &pci_byte) != 0) {
  2687. printk("%s: can't read PCI retry timeout.\n", card->name);
  2688. deinit_card(card);
  2689. return -1;
  2690. }
  2691. if (pci_byte != 0) {
  2692. IPRINTK("%s: PCI retry timeout: %d, set to 0.\n",
  2693. card->name, pci_byte);
  2694. if (pci_write_config_byte(pcidev, 0x40, 0) != 0) {
  2695. printk("%s: can't set PCI retry timeout.\n",
  2696. card->name);
  2697. deinit_card(card);
  2698. return -1;
  2699. }
  2700. }
  2701. IPRINTK("%s: Checking PCI TRDY.\n", card->name);
  2702. if (pci_read_config_byte(pcidev, 0x41, &pci_byte) != 0) {
  2703. printk("%s: can't read PCI TRDY timeout.\n", card->name);
  2704. deinit_card(card);
  2705. return -1;
  2706. }
  2707. if (pci_byte != 0) {
  2708. IPRINTK("%s: PCI TRDY timeout: %d, set to 0.\n",
  2709. card->name, pci_byte);
  2710. if (pci_write_config_byte(pcidev, 0x41, 0) != 0) {
  2711. printk("%s: can't set PCI TRDY timeout.\n", card->name);
  2712. deinit_card(card);
  2713. return -1;
  2714. }
  2715. }
  2716. /* Reset Timer register */
  2717. if (readl(SAR_REG_STAT) & SAR_STAT_TMROF) {
  2718. printk("%s: resetting timer overflow.\n", card->name);
  2719. writel(SAR_STAT_TMROF, SAR_REG_STAT);
  2720. }
  2721. IPRINTK("%s: Request IRQ ... ", card->name);
  2722. if (request_irq(pcidev->irq, idt77252_interrupt, IRQF_SHARED,
  2723. card->name, card) != 0) {
  2724. printk("%s: can't allocate IRQ.\n", card->name);
  2725. deinit_card(card);
  2726. return -1;
  2727. }
  2728. IPRINTK("got %d.\n", pcidev->irq);
  2729. /*****************************************************************/
  2730. /* C H E C K A N D I N I T S R A M */
  2731. /*****************************************************************/
  2732. IPRINTK("%s: Initializing SRAM\n", card->name);
  2733. /* preset size of connecton table, so that init_sram() knows about it */
  2734. conf = SAR_CFG_TX_FIFO_SIZE_9 | /* Use maximum fifo size */
  2735. SAR_CFG_RXSTQ_SIZE_8k | /* Receive Status Queue is 8k */
  2736. SAR_CFG_IDLE_CLP | /* Set CLP on idle cells */
  2737. #ifndef ATM_IDT77252_SEND_IDLE
  2738. SAR_CFG_NO_IDLE | /* Do not send idle cells */
  2739. #endif
  2740. 0;
  2741. if (card->sramsize == (512 * 1024))
  2742. conf |= SAR_CFG_CNTBL_1k;
  2743. else
  2744. conf |= SAR_CFG_CNTBL_512;
  2745. switch (vpibits) {
  2746. case 0:
  2747. conf |= SAR_CFG_VPVCS_0;
  2748. break;
  2749. default:
  2750. case 1:
  2751. conf |= SAR_CFG_VPVCS_1;
  2752. break;
  2753. case 2:
  2754. conf |= SAR_CFG_VPVCS_2;
  2755. break;
  2756. case 8:
  2757. conf |= SAR_CFG_VPVCS_8;
  2758. break;
  2759. }
  2760. writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG);
  2761. init_sram(card);
  2762. /********************************************************************/
  2763. /* A L L O C R A M A N D S E T V A R I O U S T H I N G S */
  2764. /********************************************************************/
  2765. /* Initialize TSQ */
  2766. if (0 != init_tsq(card)) {
  2767. deinit_card(card);
  2768. return -1;
  2769. }
  2770. /* Initialize RSQ */
  2771. if (0 != init_rsq(card)) {
  2772. deinit_card(card);
  2773. return -1;
  2774. }
  2775. card->vpibits = vpibits;
  2776. if (card->sramsize == (512 * 1024)) {
  2777. card->vcibits = 10 - card->vpibits;
  2778. } else {
  2779. card->vcibits = 9 - card->vpibits;
  2780. }
  2781. card->vcimask = 0;
  2782. for (k = 0, i = 1; k < card->vcibits; k++) {
  2783. card->vcimask |= i;
  2784. i <<= 1;
  2785. }
  2786. IPRINTK("%s: Setting VPI/VCI mask to zero.\n", card->name);
  2787. writel(0, SAR_REG_VPM);
  2788. /* Little Endian Order */
  2789. writel(0, SAR_REG_GP);
  2790. /* Initialize RAW Cell Handle Register */
  2791. card->raw_cell_hnd = pci_alloc_consistent(card->pcidev, 2 * sizeof(u32),
  2792. &card->raw_cell_paddr);
  2793. if (!card->raw_cell_hnd) {
  2794. printk("%s: memory allocation failure.\n", card->name);
  2795. deinit_card(card);
  2796. return -1;
  2797. }
  2798. memset(card->raw_cell_hnd, 0, 2 * sizeof(u32));
  2799. writel(card->raw_cell_paddr, SAR_REG_RAWHND);
  2800. IPRINTK("%s: raw cell handle is at 0x%p.\n", card->name,
  2801. card->raw_cell_hnd);
  2802. size = sizeof(struct vc_map *) * card->tct_size;
  2803. IPRINTK("%s: allocate %d byte for VC map.\n", card->name, size);
  2804. card->vcs = vzalloc(size);
  2805. if (!card->vcs) {
  2806. printk("%s: memory allocation failure.\n", card->name);
  2807. deinit_card(card);
  2808. return -1;
  2809. }
  2810. size = sizeof(struct vc_map *) * card->scd_size;
  2811. IPRINTK("%s: allocate %d byte for SCD to VC mapping.\n",
  2812. card->name, size);
  2813. card->scd2vc = vzalloc(size);
  2814. if (!card->scd2vc) {
  2815. printk("%s: memory allocation failure.\n", card->name);
  2816. deinit_card(card);
  2817. return -1;
  2818. }
  2819. size = sizeof(struct tst_info) * (card->tst_size - 2);
  2820. IPRINTK("%s: allocate %d byte for TST to VC mapping.\n",
  2821. card->name, size);
  2822. card->soft_tst = vmalloc(size);
  2823. if (!card->soft_tst) {
  2824. printk("%s: memory allocation failure.\n", card->name);
  2825. deinit_card(card);
  2826. return -1;
  2827. }
  2828. for (i = 0; i < card->tst_size - 2; i++) {
  2829. card->soft_tst[i].tste = TSTE_OPC_VAR;
  2830. card->soft_tst[i].vc = NULL;
  2831. }
  2832. if (dev->phy == NULL) {
  2833. printk("%s: No LT device defined.\n", card->name);
  2834. deinit_card(card);
  2835. return -1;
  2836. }
  2837. if (dev->phy->ioctl == NULL) {
  2838. printk("%s: LT had no IOCTL function defined.\n", card->name);
  2839. deinit_card(card);
  2840. return -1;
  2841. }
  2842. #ifdef CONFIG_ATM_IDT77252_USE_SUNI
  2843. /*
  2844. * this is a jhs hack to get around special functionality in the
  2845. * phy driver for the atecom hardware; the functionality doesn't
  2846. * exist in the linux atm suni driver
  2847. *
  2848. * it isn't the right way to do things, but as the guy from NIST
  2849. * said, talking about their measurement of the fine structure
  2850. * constant, "it's good enough for government work."
  2851. */
  2852. linkrate = 149760000;
  2853. #endif
  2854. card->link_pcr = (linkrate / 8 / 53);
  2855. printk("%s: Linkrate on ATM line : %u bit/s, %u cell/s.\n",
  2856. card->name, linkrate, card->link_pcr);
  2857. #ifdef ATM_IDT77252_SEND_IDLE
  2858. card->utopia_pcr = card->link_pcr;
  2859. #else
  2860. card->utopia_pcr = (160000000 / 8 / 54);
  2861. #endif
  2862. rsvdcr = 0;
  2863. if (card->utopia_pcr > card->link_pcr)
  2864. rsvdcr = card->utopia_pcr - card->link_pcr;
  2865. tmpl = (unsigned long) rsvdcr * ((unsigned long) card->tst_size - 2);
  2866. modl = tmpl % (unsigned long)card->utopia_pcr;
  2867. tst_entries = (int) (tmpl / (unsigned long)card->utopia_pcr);
  2868. if (modl)
  2869. tst_entries++;
  2870. card->tst_free -= tst_entries;
  2871. fill_tst(card, NULL, tst_entries, TSTE_OPC_NULL);
  2872. #ifdef HAVE_EEPROM
  2873. idt77252_eeprom_init(card);
  2874. printk("%s: EEPROM: %02x:", card->name,
  2875. idt77252_eeprom_read_status(card));
  2876. for (i = 0; i < 0x80; i++) {
  2877. printk(" %02x",
  2878. idt77252_eeprom_read_byte(card, i)
  2879. );
  2880. }
  2881. printk("\n");
  2882. #endif /* HAVE_EEPROM */
  2883. /*
  2884. * XXX: <hack>
  2885. */
  2886. sprintf(tname, "eth%d", card->index);
  2887. tmp = dev_get_by_name(&init_net, tname); /* jhs: was "tmp = dev_get(tname);" */
  2888. if (tmp) {
  2889. memcpy(card->atmdev->esi, tmp->dev_addr, 6);
  2890. dev_put(tmp);
  2891. printk("%s: ESI %pM\n", card->name, card->atmdev->esi);
  2892. }
  2893. /*
  2894. * XXX: </hack>
  2895. */
  2896. /* Set Maximum Deficit Count for now. */
  2897. writel(0xffff, SAR_REG_MDFCT);
  2898. set_bit(IDT77252_BIT_INIT, &card->flags);
  2899. XPRINTK("%s: IDT77252 ABR SAR initialization complete.\n", card->name);
  2900. return 0;
  2901. }
  2902. /*****************************************************************************/
  2903. /* */
  2904. /* Probing of IDT77252 ABR SAR */
  2905. /* */
  2906. /*****************************************************************************/
  2907. static int __devinit
  2908. idt77252_preset(struct idt77252_dev *card)
  2909. {
  2910. u16 pci_command;
  2911. /*****************************************************************/
  2912. /* P C I C O N F I G U R A T I O N */
  2913. /*****************************************************************/
  2914. XPRINTK("%s: Enable PCI master and memory access for SAR.\n",
  2915. card->name);
  2916. if (pci_read_config_word(card->pcidev, PCI_COMMAND, &pci_command)) {
  2917. printk("%s: can't read PCI_COMMAND.\n", card->name);
  2918. deinit_card(card);
  2919. return -1;
  2920. }
  2921. if (!(pci_command & PCI_COMMAND_IO)) {
  2922. printk("%s: PCI_COMMAND: %04x (???)\n",
  2923. card->name, pci_command);
  2924. deinit_card(card);
  2925. return (-1);
  2926. }
  2927. pci_command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  2928. if (pci_write_config_word(card->pcidev, PCI_COMMAND, pci_command)) {
  2929. printk("%s: can't write PCI_COMMAND.\n", card->name);
  2930. deinit_card(card);
  2931. return -1;
  2932. }
  2933. /*****************************************************************/
  2934. /* G E N E R I C R E S E T */
  2935. /*****************************************************************/
  2936. /* Software reset */
  2937. writel(SAR_CFG_SWRST, SAR_REG_CFG);
  2938. mdelay(1);
  2939. writel(0, SAR_REG_CFG);
  2940. IPRINTK("%s: Software resetted.\n", card->name);
  2941. return 0;
  2942. }
  2943. static unsigned long __devinit
  2944. probe_sram(struct idt77252_dev *card)
  2945. {
  2946. u32 data, addr;
  2947. writel(0, SAR_REG_DR0);
  2948. writel(SAR_CMD_WRITE_SRAM | (0 << 2), SAR_REG_CMD);
  2949. for (addr = 0x4000; addr < 0x80000; addr += 0x4000) {
  2950. writel(ATM_POISON, SAR_REG_DR0);
  2951. writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD);
  2952. writel(SAR_CMD_READ_SRAM | (0 << 2), SAR_REG_CMD);
  2953. data = readl(SAR_REG_DR0);
  2954. if (data != 0)
  2955. break;
  2956. }
  2957. return addr * sizeof(u32);
  2958. }
  2959. static int __devinit
  2960. idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id)
  2961. {
  2962. static struct idt77252_dev **last = &idt77252_chain;
  2963. static int index = 0;
  2964. unsigned long membase, srambase;
  2965. struct idt77252_dev *card;
  2966. struct atm_dev *dev;
  2967. int i, err;
  2968. if ((err = pci_enable_device(pcidev))) {
  2969. printk("idt77252: can't enable PCI device at %s\n", pci_name(pcidev));
  2970. return err;
  2971. }
  2972. card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
  2973. if (!card) {
  2974. printk("idt77252-%d: can't allocate private data\n", index);
  2975. err = -ENOMEM;
  2976. goto err_out_disable_pdev;
  2977. }
  2978. card->revision = pcidev->revision;
  2979. card->index = index;
  2980. card->pcidev = pcidev;
  2981. sprintf(card->name, "idt77252-%d", card->index);
  2982. INIT_WORK(&card->tqueue, idt77252_softint);
  2983. membase = pci_resource_start(pcidev, 1);
  2984. srambase = pci_resource_start(pcidev, 2);
  2985. mutex_init(&card->mutex);
  2986. spin_lock_init(&card->cmd_lock);
  2987. spin_lock_init(&card->tst_lock);
  2988. init_timer(&card->tst_timer);
  2989. card->tst_timer.data = (unsigned long)card;
  2990. card->tst_timer.function = tst_timer;
  2991. /* Do the I/O remapping... */
  2992. card->membase = ioremap(membase, 1024);
  2993. if (!card->membase) {
  2994. printk("%s: can't ioremap() membase\n", card->name);
  2995. err = -EIO;
  2996. goto err_out_free_card;
  2997. }
  2998. if (idt77252_preset(card)) {
  2999. printk("%s: preset failed\n", card->name);
  3000. err = -EIO;
  3001. goto err_out_iounmap;
  3002. }
  3003. dev = atm_dev_register("idt77252", &pcidev->dev, &idt77252_ops, -1,
  3004. NULL);
  3005. if (!dev) {
  3006. printk("%s: can't register atm device\n", card->name);
  3007. err = -EIO;
  3008. goto err_out_iounmap;
  3009. }
  3010. dev->dev_data = card;
  3011. card->atmdev = dev;
  3012. #ifdef CONFIG_ATM_IDT77252_USE_SUNI
  3013. suni_init(dev);
  3014. if (!dev->phy) {
  3015. printk("%s: can't init SUNI\n", card->name);
  3016. err = -EIO;
  3017. goto err_out_deinit_card;
  3018. }
  3019. #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
  3020. card->sramsize = probe_sram(card);
  3021. for (i = 0; i < 4; i++) {
  3022. card->fbq[i] = ioremap(srambase | 0x200000 | (i << 18), 4);
  3023. if (!card->fbq[i]) {
  3024. printk("%s: can't ioremap() FBQ%d\n", card->name, i);
  3025. err = -EIO;
  3026. goto err_out_deinit_card;
  3027. }
  3028. }
  3029. printk("%s: ABR SAR (Rev %c): MEM %08lx SRAM %08lx [%u KB]\n",
  3030. card->name, ((card->revision > 1) && (card->revision < 25)) ?
  3031. 'A' + card->revision - 1 : '?', membase, srambase,
  3032. card->sramsize / 1024);
  3033. if (init_card(dev)) {
  3034. printk("%s: init_card failed\n", card->name);
  3035. err = -EIO;
  3036. goto err_out_deinit_card;
  3037. }
  3038. dev->ci_range.vpi_bits = card->vpibits;
  3039. dev->ci_range.vci_bits = card->vcibits;
  3040. dev->link_rate = card->link_pcr;
  3041. if (dev->phy->start)
  3042. dev->phy->start(dev);
  3043. if (idt77252_dev_open(card)) {
  3044. printk("%s: dev_open failed\n", card->name);
  3045. err = -EIO;
  3046. goto err_out_stop;
  3047. }
  3048. *last = card;
  3049. last = &card->next;
  3050. index++;
  3051. return 0;
  3052. err_out_stop:
  3053. if (dev->phy->stop)
  3054. dev->phy->stop(dev);
  3055. err_out_deinit_card:
  3056. deinit_card(card);
  3057. err_out_iounmap:
  3058. iounmap(card->membase);
  3059. err_out_free_card:
  3060. kfree(card);
  3061. err_out_disable_pdev:
  3062. pci_disable_device(pcidev);
  3063. return err;
  3064. }
  3065. static struct pci_device_id idt77252_pci_tbl[] =
  3066. {
  3067. { PCI_VDEVICE(IDT, PCI_DEVICE_ID_IDT_IDT77252), 0 },
  3068. { 0, }
  3069. };
  3070. MODULE_DEVICE_TABLE(pci, idt77252_pci_tbl);
  3071. static struct pci_driver idt77252_driver = {
  3072. .name = "idt77252",
  3073. .id_table = idt77252_pci_tbl,
  3074. .probe = idt77252_init_one,
  3075. };
  3076. static int __init idt77252_init(void)
  3077. {
  3078. struct sk_buff *skb;
  3079. printk("%s: at %p\n", __func__, idt77252_init);
  3080. if (sizeof(skb->cb) < sizeof(struct atm_skb_data) +
  3081. sizeof(struct idt77252_skb_prv)) {
  3082. printk(KERN_ERR "%s: skb->cb is too small (%lu < %lu)\n",
  3083. __func__, (unsigned long) sizeof(skb->cb),
  3084. (unsigned long) sizeof(struct atm_skb_data) +
  3085. sizeof(struct idt77252_skb_prv));
  3086. return -EIO;
  3087. }
  3088. return pci_register_driver(&idt77252_driver);
  3089. }
  3090. static void __exit idt77252_exit(void)
  3091. {
  3092. struct idt77252_dev *card;
  3093. struct atm_dev *dev;
  3094. pci_unregister_driver(&idt77252_driver);
  3095. while (idt77252_chain) {
  3096. card = idt77252_chain;
  3097. dev = card->atmdev;
  3098. idt77252_chain = card->next;
  3099. if (dev->phy->stop)
  3100. dev->phy->stop(dev);
  3101. deinit_card(card);
  3102. pci_disable_device(card->pcidev);
  3103. kfree(card);
  3104. }
  3105. DIPRINTK("idt77252: finished cleanup-module().\n");
  3106. }
  3107. module_init(idt77252_init);
  3108. module_exit(idt77252_exit);
  3109. MODULE_LICENSE("GPL");
  3110. module_param(vpibits, uint, 0);
  3111. MODULE_PARM_DESC(vpibits, "number of VPI bits supported (0, 1, or 2)");
  3112. #ifdef CONFIG_ATM_IDT77252_DEBUG
  3113. module_param(debug, ulong, 0644);
  3114. MODULE_PARM_DESC(debug, "debug bitmap, see drivers/atm/idt77252.h");
  3115. #endif
  3116. MODULE_AUTHOR("Eddie C. Dost <ecd@atecom.com>");
  3117. MODULE_DESCRIPTION("IDT77252 ABR SAR Driver");