idt77252.c 90 KB

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