123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804 |
- /*******************************************************************
- *
- * Copyright (c) 2000 ATecoM GmbH
- *
- * The author may be reached at ecd@atecom.com.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *******************************************************************/
- #include <linux/module.h>
- #include <linux/pci.h>
- #include <linux/poison.h>
- #include <linux/skbuff.h>
- #include <linux/kernel.h>
- #include <linux/vmalloc.h>
- #include <linux/netdevice.h>
- #include <linux/atmdev.h>
- #include <linux/atm.h>
- #include <linux/delay.h>
- #include <linux/init.h>
- #include <linux/interrupt.h>
- #include <linux/bitops.h>
- #include <linux/wait.h>
- #include <linux/jiffies.h>
- #include <linux/mutex.h>
- #include <linux/slab.h>
- #include <asm/io.h>
- #include <asm/uaccess.h>
- #include <linux/atomic.h>
- #include <asm/byteorder.h>
- #ifdef CONFIG_ATM_IDT77252_USE_SUNI
- #include "suni.h"
- #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
- #include "idt77252.h"
- #include "idt77252_tables.h"
- static unsigned int vpibits = 1;
- #define ATM_IDT77252_SEND_IDLE 1
- /*
- * Debug HACKs.
- */
- #define DEBUG_MODULE 1
- #undef HAVE_EEPROM /* does not work, yet. */
- #ifdef CONFIG_ATM_IDT77252_DEBUG
- static unsigned long debug = DBG_GENERAL;
- #endif
- #define SAR_RX_DELAY (SAR_CFG_RXINT_NODELAY)
- /*
- * SCQ Handling.
- */
- static struct scq_info *alloc_scq(struct idt77252_dev *, int);
- static void free_scq(struct idt77252_dev *, struct scq_info *);
- static int queue_skb(struct idt77252_dev *, struct vc_map *,
- struct sk_buff *, int oam);
- static void drain_scq(struct idt77252_dev *, struct vc_map *);
- static unsigned long get_free_scd(struct idt77252_dev *, struct vc_map *);
- static void fill_scd(struct idt77252_dev *, struct scq_info *, int);
- /*
- * FBQ Handling.
- */
- static int push_rx_skb(struct idt77252_dev *,
- struct sk_buff *, int queue);
- static void recycle_rx_skb(struct idt77252_dev *, struct sk_buff *);
- static void flush_rx_pool(struct idt77252_dev *, struct rx_pool *);
- static void recycle_rx_pool_skb(struct idt77252_dev *,
- struct rx_pool *);
- static void add_rx_skb(struct idt77252_dev *, int queue,
- unsigned int size, unsigned int count);
- /*
- * RSQ Handling.
- */
- static int init_rsq(struct idt77252_dev *);
- static void deinit_rsq(struct idt77252_dev *);
- static void idt77252_rx(struct idt77252_dev *);
- /*
- * TSQ handling.
- */
- static int init_tsq(struct idt77252_dev *);
- static void deinit_tsq(struct idt77252_dev *);
- static void idt77252_tx(struct idt77252_dev *);
- /*
- * ATM Interface.
- */
- static void idt77252_dev_close(struct atm_dev *dev);
- static int idt77252_open(struct atm_vcc *vcc);
- static void idt77252_close(struct atm_vcc *vcc);
- static int idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb);
- static int idt77252_send_oam(struct atm_vcc *vcc, void *cell,
- int flags);
- static void idt77252_phy_put(struct atm_dev *dev, unsigned char value,
- unsigned long addr);
- static unsigned char idt77252_phy_get(struct atm_dev *dev, unsigned long addr);
- static int idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos,
- int flags);
- static int idt77252_proc_read(struct atm_dev *dev, loff_t * pos,
- char *page);
- static void idt77252_softint(struct work_struct *work);
- static struct atmdev_ops idt77252_ops =
- {
- .dev_close = idt77252_dev_close,
- .open = idt77252_open,
- .close = idt77252_close,
- .send = idt77252_send,
- .send_oam = idt77252_send_oam,
- .phy_put = idt77252_phy_put,
- .phy_get = idt77252_phy_get,
- .change_qos = idt77252_change_qos,
- .proc_read = idt77252_proc_read,
- .owner = THIS_MODULE
- };
- static struct idt77252_dev *idt77252_chain = NULL;
- static unsigned int idt77252_sram_write_errors = 0;
- /*****************************************************************************/
- /* */
- /* I/O and Utility Bus */
- /* */
- /*****************************************************************************/
- static void
- waitfor_idle(struct idt77252_dev *card)
- {
- u32 stat;
- stat = readl(SAR_REG_STAT);
- while (stat & SAR_STAT_CMDBZ)
- stat = readl(SAR_REG_STAT);
- }
- static u32
- read_sram(struct idt77252_dev *card, unsigned long addr)
- {
- unsigned long flags;
- u32 value;
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel(SAR_CMD_READ_SRAM | (addr << 2), SAR_REG_CMD);
- waitfor_idle(card);
- value = readl(SAR_REG_DR0);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- return value;
- }
- static void
- write_sram(struct idt77252_dev *card, unsigned long addr, u32 value)
- {
- unsigned long flags;
- if ((idt77252_sram_write_errors == 0) &&
- (((addr > card->tst[0] + card->tst_size - 2) &&
- (addr < card->tst[0] + card->tst_size)) ||
- ((addr > card->tst[1] + card->tst_size - 2) &&
- (addr < card->tst[1] + card->tst_size)))) {
- printk("%s: ERROR: TST JMP section at %08lx written: %08x\n",
- card->name, addr, value);
- }
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel(value, SAR_REG_DR0);
- writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD);
- waitfor_idle(card);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- }
- static u8
- read_utility(void *dev, unsigned long ubus_addr)
- {
- struct idt77252_dev *card = dev;
- unsigned long flags;
- u8 value;
- if (!card) {
- printk("Error: No such device.\n");
- return -1;
- }
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel(SAR_CMD_READ_UTILITY + ubus_addr, SAR_REG_CMD);
- waitfor_idle(card);
- value = readl(SAR_REG_DR0);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- return value;
- }
- static void
- write_utility(void *dev, unsigned long ubus_addr, u8 value)
- {
- struct idt77252_dev *card = dev;
- unsigned long flags;
- if (!card) {
- printk("Error: No such device.\n");
- return;
- }
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel((u32) value, SAR_REG_DR0);
- writel(SAR_CMD_WRITE_UTILITY + ubus_addr, SAR_REG_CMD);
- waitfor_idle(card);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- }
- #ifdef HAVE_EEPROM
- static u32 rdsrtab[] =
- {
- SAR_GP_EECS | SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- SAR_GP_EEDO,
- SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- SAR_GP_EEDO,
- SAR_GP_EESCLK | SAR_GP_EEDO /* 1 */
- };
- static u32 wrentab[] =
- {
- SAR_GP_EECS | SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- SAR_GP_EEDO,
- SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
- SAR_GP_EEDO,
- SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK /* 0 */
- };
- static u32 rdtab[] =
- {
- SAR_GP_EECS | SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- SAR_GP_EEDO,
- SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
- SAR_GP_EEDO,
- SAR_GP_EESCLK | SAR_GP_EEDO /* 1 */
- };
- static u32 wrtab[] =
- {
- SAR_GP_EECS | SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- 0,
- SAR_GP_EESCLK, /* 0 */
- SAR_GP_EEDO,
- SAR_GP_EESCLK | SAR_GP_EEDO, /* 1 */
- 0,
- SAR_GP_EESCLK /* 0 */
- };
- static u32 clktab[] =
- {
- 0,
- SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK,
- 0,
- SAR_GP_EESCLK,
- 0
- };
- static u32
- idt77252_read_gp(struct idt77252_dev *card)
- {
- u32 gp;
- gp = readl(SAR_REG_GP);
- #if 0
- printk("RD: %s\n", gp & SAR_GP_EEDI ? "1" : "0");
- #endif
- return gp;
- }
- static void
- idt77252_write_gp(struct idt77252_dev *card, u32 value)
- {
- unsigned long flags;
- #if 0
- printk("WR: %s %s %s\n", value & SAR_GP_EECS ? " " : "/CS",
- value & SAR_GP_EESCLK ? "HIGH" : "LOW ",
- value & SAR_GP_EEDO ? "1" : "0");
- #endif
- spin_lock_irqsave(&card->cmd_lock, flags);
- waitfor_idle(card);
- writel(value, SAR_REG_GP);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- }
- static u8
- idt77252_eeprom_read_status(struct idt77252_dev *card)
- {
- u8 byte;
- u32 gp;
- int i, j;
- gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
- for (i = 0; i < ARRAY_SIZE(rdsrtab); i++) {
- idt77252_write_gp(card, gp | rdsrtab[i]);
- udelay(5);
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- byte = 0;
- for (i = 0, j = 0; i < 8; i++) {
- byte <<= 1;
- idt77252_write_gp(card, gp | clktab[j++]);
- udelay(5);
- byte |= idt77252_read_gp(card) & SAR_GP_EEDI ? 1 : 0;
- idt77252_write_gp(card, gp | clktab[j++]);
- udelay(5);
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- return byte;
- }
- static u8
- idt77252_eeprom_read_byte(struct idt77252_dev *card, u8 offset)
- {
- u8 byte;
- u32 gp;
- int i, j;
- gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
- for (i = 0; i < ARRAY_SIZE(rdtab); i++) {
- idt77252_write_gp(card, gp | rdtab[i]);
- udelay(5);
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- for (i = 0, j = 0; i < 8; i++) {
- idt77252_write_gp(card, gp | clktab[j++] |
- (offset & 1 ? SAR_GP_EEDO : 0));
- udelay(5);
- idt77252_write_gp(card, gp | clktab[j++] |
- (offset & 1 ? SAR_GP_EEDO : 0));
- udelay(5);
- offset >>= 1;
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- byte = 0;
- for (i = 0, j = 0; i < 8; i++) {
- byte <<= 1;
- idt77252_write_gp(card, gp | clktab[j++]);
- udelay(5);
- byte |= idt77252_read_gp(card) & SAR_GP_EEDI ? 1 : 0;
- idt77252_write_gp(card, gp | clktab[j++]);
- udelay(5);
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- return byte;
- }
- static void
- idt77252_eeprom_write_byte(struct idt77252_dev *card, u8 offset, u8 data)
- {
- u32 gp;
- int i, j;
- gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
- for (i = 0; i < ARRAY_SIZE(wrentab); i++) {
- idt77252_write_gp(card, gp | wrentab[i]);
- udelay(5);
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- for (i = 0; i < ARRAY_SIZE(wrtab); i++) {
- idt77252_write_gp(card, gp | wrtab[i]);
- udelay(5);
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- for (i = 0, j = 0; i < 8; i++) {
- idt77252_write_gp(card, gp | clktab[j++] |
- (offset & 1 ? SAR_GP_EEDO : 0));
- udelay(5);
- idt77252_write_gp(card, gp | clktab[j++] |
- (offset & 1 ? SAR_GP_EEDO : 0));
- udelay(5);
- offset >>= 1;
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- for (i = 0, j = 0; i < 8; i++) {
- idt77252_write_gp(card, gp | clktab[j++] |
- (data & 1 ? SAR_GP_EEDO : 0));
- udelay(5);
- idt77252_write_gp(card, gp | clktab[j++] |
- (data & 1 ? SAR_GP_EEDO : 0));
- udelay(5);
- data >>= 1;
- }
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- }
- static void
- idt77252_eeprom_init(struct idt77252_dev *card)
- {
- u32 gp;
- gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
- idt77252_write_gp(card, gp | SAR_GP_EECS | SAR_GP_EESCLK);
- udelay(5);
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- idt77252_write_gp(card, gp | SAR_GP_EECS | SAR_GP_EESCLK);
- udelay(5);
- idt77252_write_gp(card, gp | SAR_GP_EECS);
- udelay(5);
- }
- #endif /* HAVE_EEPROM */
- #ifdef CONFIG_ATM_IDT77252_DEBUG
- static void
- dump_tct(struct idt77252_dev *card, int index)
- {
- unsigned long tct;
- int i;
- tct = (unsigned long) (card->tct_base + index * SAR_SRAM_TCT_SIZE);
- printk("%s: TCT %x:", card->name, index);
- for (i = 0; i < 8; i++) {
- printk(" %08x", read_sram(card, tct + i));
- }
- printk("\n");
- }
- static void
- idt77252_tx_dump(struct idt77252_dev *card)
- {
- struct atm_vcc *vcc;
- struct vc_map *vc;
- int i;
- printk("%s\n", __func__);
- for (i = 0; i < card->tct_size; i++) {
- vc = card->vcs[i];
- if (!vc)
- continue;
- vcc = NULL;
- if (vc->rx_vcc)
- vcc = vc->rx_vcc;
- else if (vc->tx_vcc)
- vcc = vc->tx_vcc;
- if (!vcc)
- continue;
- printk("%s: Connection %d:\n", card->name, vc->index);
- dump_tct(card, vc->index);
- }
- }
- #endif
- /*****************************************************************************/
- /* */
- /* SCQ Handling */
- /* */
- /*****************************************************************************/
- static int
- sb_pool_add(struct idt77252_dev *card, struct sk_buff *skb, int queue)
- {
- struct sb_pool *pool = &card->sbpool[queue];
- int index;
- index = pool->index;
- while (pool->skb[index]) {
- index = (index + 1) & FBQ_MASK;
- if (index == pool->index)
- return -ENOBUFS;
- }
- pool->skb[index] = skb;
- IDT77252_PRV_POOL(skb) = POOL_HANDLE(queue, index);
- pool->index = (index + 1) & FBQ_MASK;
- return 0;
- }
- static void
- sb_pool_remove(struct idt77252_dev *card, struct sk_buff *skb)
- {
- unsigned int queue, index;
- u32 handle;
- handle = IDT77252_PRV_POOL(skb);
- queue = POOL_QUEUE(handle);
- if (queue > 3)
- return;
- index = POOL_INDEX(handle);
- if (index > FBQ_SIZE - 1)
- return;
- card->sbpool[queue].skb[index] = NULL;
- }
- static struct sk_buff *
- sb_pool_skb(struct idt77252_dev *card, u32 handle)
- {
- unsigned int queue, index;
- queue = POOL_QUEUE(handle);
- if (queue > 3)
- return NULL;
- index = POOL_INDEX(handle);
- if (index > FBQ_SIZE - 1)
- return NULL;
- return card->sbpool[queue].skb[index];
- }
- static struct scq_info *
- alloc_scq(struct idt77252_dev *card, int class)
- {
- struct scq_info *scq;
- scq = kzalloc(sizeof(struct scq_info), GFP_KERNEL);
- if (!scq)
- return NULL;
- scq->base = dma_zalloc_coherent(&card->pcidev->dev, SCQ_SIZE,
- &scq->paddr, GFP_KERNEL);
- if (scq->base == NULL) {
- kfree(scq);
- return NULL;
- }
- scq->next = scq->base;
- scq->last = scq->base + (SCQ_ENTRIES - 1);
- atomic_set(&scq->used, 0);
- spin_lock_init(&scq->lock);
- spin_lock_init(&scq->skblock);
- skb_queue_head_init(&scq->transmit);
- skb_queue_head_init(&scq->pending);
- TXPRINTK("idt77252: SCQ: base 0x%p, next 0x%p, last 0x%p, paddr %08llx\n",
- scq->base, scq->next, scq->last, (unsigned long long)scq->paddr);
- return scq;
- }
- static void
- free_scq(struct idt77252_dev *card, struct scq_info *scq)
- {
- struct sk_buff *skb;
- struct atm_vcc *vcc;
- dma_free_coherent(&card->pcidev->dev, SCQ_SIZE,
- scq->base, scq->paddr);
- while ((skb = skb_dequeue(&scq->transmit))) {
- dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb->len, DMA_TO_DEVICE);
- vcc = ATM_SKB(skb)->vcc;
- if (vcc->pop)
- vcc->pop(vcc, skb);
- else
- dev_kfree_skb(skb);
- }
- while ((skb = skb_dequeue(&scq->pending))) {
- dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb->len, DMA_TO_DEVICE);
- vcc = ATM_SKB(skb)->vcc;
- if (vcc->pop)
- vcc->pop(vcc, skb);
- else
- dev_kfree_skb(skb);
- }
- kfree(scq);
- }
- static int
- push_on_scq(struct idt77252_dev *card, struct vc_map *vc, struct sk_buff *skb)
- {
- struct scq_info *scq = vc->scq;
- unsigned long flags;
- struct scqe *tbd;
- int entries;
- TXPRINTK("%s: SCQ: next 0x%p\n", card->name, scq->next);
- atomic_inc(&scq->used);
- entries = atomic_read(&scq->used);
- if (entries > (SCQ_ENTRIES - 1)) {
- atomic_dec(&scq->used);
- goto out;
- }
- skb_queue_tail(&scq->transmit, skb);
- spin_lock_irqsave(&vc->lock, flags);
- if (vc->estimator) {
- struct atm_vcc *vcc = vc->tx_vcc;
- struct sock *sk = sk_atm(vcc);
- vc->estimator->cells += (skb->len + 47) / 48;
- if (atomic_read(&sk->sk_wmem_alloc) >
- (sk->sk_sndbuf >> 1)) {
- u32 cps = vc->estimator->maxcps;
- vc->estimator->cps = cps;
- vc->estimator->avcps = cps << 5;
- if (vc->lacr < vc->init_er) {
- vc->lacr = vc->init_er;
- writel(TCMDQ_LACR | (vc->lacr << 16) |
- vc->index, SAR_REG_TCMDQ);
- }
- }
- }
- spin_unlock_irqrestore(&vc->lock, flags);
- tbd = &IDT77252_PRV_TBD(skb);
- spin_lock_irqsave(&scq->lock, flags);
- scq->next->word_1 = cpu_to_le32(tbd->word_1 |
- SAR_TBD_TSIF | SAR_TBD_GTSI);
- scq->next->word_2 = cpu_to_le32(tbd->word_2);
- scq->next->word_3 = cpu_to_le32(tbd->word_3);
- scq->next->word_4 = cpu_to_le32(tbd->word_4);
- if (scq->next == scq->last)
- scq->next = scq->base;
- else
- scq->next++;
- write_sram(card, scq->scd,
- scq->paddr +
- (u32)((unsigned long)scq->next - (unsigned long)scq->base));
- spin_unlock_irqrestore(&scq->lock, flags);
- scq->trans_start = jiffies;
- if (test_and_clear_bit(VCF_IDLE, &vc->flags)) {
- writel(TCMDQ_START_LACR | (vc->lacr << 16) | vc->index,
- SAR_REG_TCMDQ);
- }
- TXPRINTK("%d entries in SCQ used (push).\n", atomic_read(&scq->used));
- XPRINTK("%s: SCQ (after push %2d) head = 0x%x, next = 0x%p.\n",
- card->name, atomic_read(&scq->used),
- read_sram(card, scq->scd + 1), scq->next);
- return 0;
- out:
- if (time_after(jiffies, scq->trans_start + HZ)) {
- printk("%s: Error pushing TBD for %d.%d\n",
- card->name, vc->tx_vcc->vpi, vc->tx_vcc->vci);
- #ifdef CONFIG_ATM_IDT77252_DEBUG
- idt77252_tx_dump(card);
- #endif
- scq->trans_start = jiffies;
- }
- return -ENOBUFS;
- }
- static void
- drain_scq(struct idt77252_dev *card, struct vc_map *vc)
- {
- struct scq_info *scq = vc->scq;
- struct sk_buff *skb;
- struct atm_vcc *vcc;
- TXPRINTK("%s: SCQ (before drain %2d) next = 0x%p.\n",
- card->name, atomic_read(&scq->used), scq->next);
- skb = skb_dequeue(&scq->transmit);
- if (skb) {
- TXPRINTK("%s: freeing skb at %p.\n", card->name, skb);
- dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb->len, DMA_TO_DEVICE);
- vcc = ATM_SKB(skb)->vcc;
- if (vcc->pop)
- vcc->pop(vcc, skb);
- else
- dev_kfree_skb(skb);
- atomic_inc(&vcc->stats->tx);
- }
- atomic_dec(&scq->used);
- spin_lock(&scq->skblock);
- while ((skb = skb_dequeue(&scq->pending))) {
- if (push_on_scq(card, vc, skb)) {
- skb_queue_head(&vc->scq->pending, skb);
- break;
- }
- }
- spin_unlock(&scq->skblock);
- }
- static int
- queue_skb(struct idt77252_dev *card, struct vc_map *vc,
- struct sk_buff *skb, int oam)
- {
- struct atm_vcc *vcc;
- struct scqe *tbd;
- unsigned long flags;
- int error;
- int aal;
- if (skb->len == 0) {
- printk("%s: invalid skb->len (%d)\n", card->name, skb->len);
- return -EINVAL;
- }
- TXPRINTK("%s: Sending %d bytes of data.\n",
- card->name, skb->len);
- tbd = &IDT77252_PRV_TBD(skb);
- vcc = ATM_SKB(skb)->vcc;
- IDT77252_PRV_PADDR(skb) = dma_map_single(&card->pcidev->dev, skb->data,
- skb->len, DMA_TO_DEVICE);
- error = -EINVAL;
- if (oam) {
- if (skb->len != 52)
- goto errout;
- tbd->word_1 = SAR_TBD_OAM | ATM_CELL_PAYLOAD | SAR_TBD_EPDU;
- tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4;
- tbd->word_3 = 0x00000000;
- tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) |
- (skb->data[2] << 8) | (skb->data[3] << 0);
- if (test_bit(VCF_RSV, &vc->flags))
- vc = card->vcs[0];
- goto done;
- }
- if (test_bit(VCF_RSV, &vc->flags)) {
- printk("%s: Trying to transmit on reserved VC\n", card->name);
- goto errout;
- }
- aal = vcc->qos.aal;
- switch (aal) {
- case ATM_AAL0:
- case ATM_AAL34:
- if (skb->len > 52)
- goto errout;
- if (aal == ATM_AAL0)
- tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL0 |
- ATM_CELL_PAYLOAD;
- else
- tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL34 |
- ATM_CELL_PAYLOAD;
- tbd->word_2 = IDT77252_PRV_PADDR(skb) + 4;
- tbd->word_3 = 0x00000000;
- tbd->word_4 = (skb->data[0] << 24) | (skb->data[1] << 16) |
- (skb->data[2] << 8) | (skb->data[3] << 0);
- break;
- case ATM_AAL5:
- tbd->word_1 = SAR_TBD_EPDU | SAR_TBD_AAL5 | skb->len;
- tbd->word_2 = IDT77252_PRV_PADDR(skb);
- tbd->word_3 = skb->len;
- tbd->word_4 = (vcc->vpi << SAR_TBD_VPI_SHIFT) |
- (vcc->vci << SAR_TBD_VCI_SHIFT);
- break;
- case ATM_AAL1:
- case ATM_AAL2:
- default:
- printk("%s: Traffic type not supported.\n", card->name);
- error = -EPROTONOSUPPORT;
- goto errout;
- }
- done:
- spin_lock_irqsave(&vc->scq->skblock, flags);
- skb_queue_tail(&vc->scq->pending, skb);
- while ((skb = skb_dequeue(&vc->scq->pending))) {
- if (push_on_scq(card, vc, skb)) {
- skb_queue_head(&vc->scq->pending, skb);
- break;
- }
- }
- spin_unlock_irqrestore(&vc->scq->skblock, flags);
- return 0;
- errout:
- dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb->len, DMA_TO_DEVICE);
- return error;
- }
- static unsigned long
- get_free_scd(struct idt77252_dev *card, struct vc_map *vc)
- {
- int i;
- for (i = 0; i < card->scd_size; i++) {
- if (!card->scd2vc[i]) {
- card->scd2vc[i] = vc;
- vc->scd_index = i;
- return card->scd_base + i * SAR_SRAM_SCD_SIZE;
- }
- }
- return 0;
- }
- static void
- fill_scd(struct idt77252_dev *card, struct scq_info *scq, int class)
- {
- write_sram(card, scq->scd, scq->paddr);
- write_sram(card, scq->scd + 1, 0x00000000);
- write_sram(card, scq->scd + 2, 0xffffffff);
- write_sram(card, scq->scd + 3, 0x00000000);
- }
- static void
- clear_scd(struct idt77252_dev *card, struct scq_info *scq, int class)
- {
- return;
- }
- /*****************************************************************************/
- /* */
- /* RSQ Handling */
- /* */
- /*****************************************************************************/
- static int
- init_rsq(struct idt77252_dev *card)
- {
- struct rsq_entry *rsqe;
- card->rsq.base = dma_zalloc_coherent(&card->pcidev->dev, RSQSIZE,
- &card->rsq.paddr, GFP_KERNEL);
- if (card->rsq.base == NULL) {
- printk("%s: can't allocate RSQ.\n", card->name);
- return -1;
- }
- card->rsq.last = card->rsq.base + RSQ_NUM_ENTRIES - 1;
- card->rsq.next = card->rsq.last;
- for (rsqe = card->rsq.base; rsqe <= card->rsq.last; rsqe++)
- rsqe->word_4 = 0;
- writel((unsigned long) card->rsq.last - (unsigned long) card->rsq.base,
- SAR_REG_RSQH);
- writel(card->rsq.paddr, SAR_REG_RSQB);
- IPRINTK("%s: RSQ base at 0x%lx (0x%x).\n", card->name,
- (unsigned long) card->rsq.base,
- readl(SAR_REG_RSQB));
- IPRINTK("%s: RSQ head = 0x%x, base = 0x%x, tail = 0x%x.\n",
- card->name,
- readl(SAR_REG_RSQH),
- readl(SAR_REG_RSQB),
- readl(SAR_REG_RSQT));
- return 0;
- }
- static void
- deinit_rsq(struct idt77252_dev *card)
- {
- dma_free_coherent(&card->pcidev->dev, RSQSIZE,
- card->rsq.base, card->rsq.paddr);
- }
- static void
- dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
- {
- struct atm_vcc *vcc;
- struct sk_buff *skb;
- struct rx_pool *rpp;
- struct vc_map *vc;
- u32 header, vpi, vci;
- u32 stat;
- int i;
- stat = le32_to_cpu(rsqe->word_4);
- if (stat & SAR_RSQE_IDLE) {
- RXPRINTK("%s: message about inactive connection.\n",
- card->name);
- return;
- }
- skb = sb_pool_skb(card, le32_to_cpu(rsqe->word_2));
- if (skb == NULL) {
- printk("%s: NULL skb in %s, rsqe: %08x %08x %08x %08x\n",
- card->name, __func__,
- le32_to_cpu(rsqe->word_1), le32_to_cpu(rsqe->word_2),
- le32_to_cpu(rsqe->word_3), le32_to_cpu(rsqe->word_4));
- return;
- }
- header = le32_to_cpu(rsqe->word_1);
- vpi = (header >> 16) & 0x00ff;
- vci = (header >> 0) & 0xffff;
- RXPRINTK("%s: SDU for %d.%d received in buffer 0x%p (data 0x%p).\n",
- card->name, vpi, vci, skb, skb->data);
- if ((vpi >= (1 << card->vpibits)) || (vci != (vci & card->vcimask))) {
- printk("%s: SDU received for out-of-range vc %u.%u\n",
- card->name, vpi, vci);
- recycle_rx_skb(card, skb);
- return;
- }
- vc = card->vcs[VPCI2VC(card, vpi, vci)];
- if (!vc || !test_bit(VCF_RX, &vc->flags)) {
- printk("%s: SDU received on non RX vc %u.%u\n",
- card->name, vpi, vci);
- recycle_rx_skb(card, skb);
- return;
- }
- vcc = vc->rx_vcc;
- dma_sync_single_for_cpu(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb_end_pointer(skb) - skb->data,
- DMA_FROM_DEVICE);
- if ((vcc->qos.aal == ATM_AAL0) ||
- (vcc->qos.aal == ATM_AAL34)) {
- struct sk_buff *sb;
- unsigned char *cell;
- u32 aal0;
- cell = skb->data;
- for (i = (stat & SAR_RSQE_CELLCNT); i; i--) {
- if ((sb = dev_alloc_skb(64)) == NULL) {
- printk("%s: Can't allocate buffers for aal0.\n",
- card->name);
- atomic_add(i, &vcc->stats->rx_drop);
- break;
- }
- if (!atm_charge(vcc, sb->truesize)) {
- RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
- card->name);
- atomic_add(i - 1, &vcc->stats->rx_drop);
- dev_kfree_skb(sb);
- break;
- }
- aal0 = (vpi << ATM_HDR_VPI_SHIFT) |
- (vci << ATM_HDR_VCI_SHIFT);
- aal0 |= (stat & SAR_RSQE_EPDU) ? 0x00000002 : 0;
- aal0 |= (stat & SAR_RSQE_CLP) ? 0x00000001 : 0;
- *((u32 *) sb->data) = aal0;
- skb_put(sb, sizeof(u32));
- memcpy(skb_put(sb, ATM_CELL_PAYLOAD),
- cell, ATM_CELL_PAYLOAD);
- ATM_SKB(sb)->vcc = vcc;
- __net_timestamp(sb);
- vcc->push(vcc, sb);
- atomic_inc(&vcc->stats->rx);
- cell += ATM_CELL_PAYLOAD;
- }
- recycle_rx_skb(card, skb);
- return;
- }
- if (vcc->qos.aal != ATM_AAL5) {
- printk("%s: Unexpected AAL type in dequeue_rx(): %d.\n",
- card->name, vcc->qos.aal);
- recycle_rx_skb(card, skb);
- return;
- }
- skb->len = (stat & SAR_RSQE_CELLCNT) * ATM_CELL_PAYLOAD;
- rpp = &vc->rcv.rx_pool;
- __skb_queue_tail(&rpp->queue, skb);
- rpp->len += skb->len;
- if (stat & SAR_RSQE_EPDU) {
- unsigned char *l1l2;
- unsigned int len;
- l1l2 = (unsigned char *) ((unsigned long) skb->data + skb->len - 6);
- len = (l1l2[0] << 8) | l1l2[1];
- len = len ? len : 0x10000;
- RXPRINTK("%s: PDU has %d bytes.\n", card->name, len);
- if ((len + 8 > rpp->len) || (len + (47 + 8) < rpp->len)) {
- RXPRINTK("%s: AAL5 PDU size mismatch: %d != %d. "
- "(CDC: %08x)\n",
- card->name, len, rpp->len, readl(SAR_REG_CDC));
- recycle_rx_pool_skb(card, rpp);
- atomic_inc(&vcc->stats->rx_err);
- return;
- }
- if (stat & SAR_RSQE_CRC) {
- RXPRINTK("%s: AAL5 CRC error.\n", card->name);
- recycle_rx_pool_skb(card, rpp);
- atomic_inc(&vcc->stats->rx_err);
- return;
- }
- if (skb_queue_len(&rpp->queue) > 1) {
- struct sk_buff *sb;
- skb = dev_alloc_skb(rpp->len);
- if (!skb) {
- RXPRINTK("%s: Can't alloc RX skb.\n",
- card->name);
- recycle_rx_pool_skb(card, rpp);
- atomic_inc(&vcc->stats->rx_err);
- return;
- }
- if (!atm_charge(vcc, skb->truesize)) {
- recycle_rx_pool_skb(card, rpp);
- dev_kfree_skb(skb);
- return;
- }
- skb_queue_walk(&rpp->queue, sb)
- memcpy(skb_put(skb, sb->len),
- sb->data, sb->len);
- recycle_rx_pool_skb(card, rpp);
- skb_trim(skb, len);
- ATM_SKB(skb)->vcc = vcc;
- __net_timestamp(skb);
- vcc->push(vcc, skb);
- atomic_inc(&vcc->stats->rx);
- return;
- }
- flush_rx_pool(card, rpp);
- if (!atm_charge(vcc, skb->truesize)) {
- recycle_rx_skb(card, skb);
- return;
- }
- dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb_end_pointer(skb) - skb->data,
- DMA_FROM_DEVICE);
- sb_pool_remove(card, skb);
- skb_trim(skb, len);
- ATM_SKB(skb)->vcc = vcc;
- __net_timestamp(skb);
- vcc->push(vcc, skb);
- atomic_inc(&vcc->stats->rx);
- if (skb->truesize > SAR_FB_SIZE_3)
- add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
- else if (skb->truesize > SAR_FB_SIZE_2)
- add_rx_skb(card, 2, SAR_FB_SIZE_2, 1);
- else if (skb->truesize > SAR_FB_SIZE_1)
- add_rx_skb(card, 1, SAR_FB_SIZE_1, 1);
- else
- add_rx_skb(card, 0, SAR_FB_SIZE_0, 1);
- return;
- }
- }
- static void
- idt77252_rx(struct idt77252_dev *card)
- {
- struct rsq_entry *rsqe;
- if (card->rsq.next == card->rsq.last)
- rsqe = card->rsq.base;
- else
- rsqe = card->rsq.next + 1;
- if (!(le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID)) {
- RXPRINTK("%s: no entry in RSQ.\n", card->name);
- return;
- }
- do {
- dequeue_rx(card, rsqe);
- rsqe->word_4 = 0;
- card->rsq.next = rsqe;
- if (card->rsq.next == card->rsq.last)
- rsqe = card->rsq.base;
- else
- rsqe = card->rsq.next + 1;
- } while (le32_to_cpu(rsqe->word_4) & SAR_RSQE_VALID);
- writel((unsigned long) card->rsq.next - (unsigned long) card->rsq.base,
- SAR_REG_RSQH);
- }
- static void
- idt77252_rx_raw(struct idt77252_dev *card)
- {
- struct sk_buff *queue;
- u32 head, tail;
- struct atm_vcc *vcc;
- struct vc_map *vc;
- struct sk_buff *sb;
- if (card->raw_cell_head == NULL) {
- u32 handle = le32_to_cpu(*(card->raw_cell_hnd + 1));
- card->raw_cell_head = sb_pool_skb(card, handle);
- }
- queue = card->raw_cell_head;
- if (!queue)
- return;
- head = IDT77252_PRV_PADDR(queue) + (queue->data - queue->head - 16);
- tail = readl(SAR_REG_RAWCT);
- dma_sync_single_for_cpu(&card->pcidev->dev, IDT77252_PRV_PADDR(queue),
- skb_end_offset(queue) - 16,
- DMA_FROM_DEVICE);
- while (head != tail) {
- unsigned int vpi, vci;
- u32 header;
- header = le32_to_cpu(*(u32 *) &queue->data[0]);
- vpi = (header & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT;
- vci = (header & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT;
- #ifdef CONFIG_ATM_IDT77252_DEBUG
- if (debug & DBG_RAW_CELL) {
- int i;
- printk("%s: raw cell %x.%02x.%04x.%x.%x\n",
- card->name, (header >> 28) & 0x000f,
- (header >> 20) & 0x00ff,
- (header >> 4) & 0xffff,
- (header >> 1) & 0x0007,
- (header >> 0) & 0x0001);
- for (i = 16; i < 64; i++)
- printk(" %02x", queue->data[i]);
- printk("\n");
- }
- #endif
- if (vpi >= (1<<card->vpibits) || vci >= (1<<card->vcibits)) {
- RPRINTK("%s: SDU received for out-of-range vc %u.%u\n",
- card->name, vpi, vci);
- goto drop;
- }
- vc = card->vcs[VPCI2VC(card, vpi, vci)];
- if (!vc || !test_bit(VCF_RX, &vc->flags)) {
- RPRINTK("%s: SDU received on non RX vc %u.%u\n",
- card->name, vpi, vci);
- goto drop;
- }
- vcc = vc->rx_vcc;
- if (vcc->qos.aal != ATM_AAL0) {
- RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
- card->name, vpi, vci);
- atomic_inc(&vcc->stats->rx_drop);
- goto drop;
- }
-
- if ((sb = dev_alloc_skb(64)) == NULL) {
- printk("%s: Can't allocate buffers for AAL0.\n",
- card->name);
- atomic_inc(&vcc->stats->rx_err);
- goto drop;
- }
- if (!atm_charge(vcc, sb->truesize)) {
- RXPRINTK("%s: atm_charge() dropped AAL0 packets.\n",
- card->name);
- dev_kfree_skb(sb);
- goto drop;
- }
- *((u32 *) sb->data) = header;
- skb_put(sb, sizeof(u32));
- memcpy(skb_put(sb, ATM_CELL_PAYLOAD), &(queue->data[16]),
- ATM_CELL_PAYLOAD);
- ATM_SKB(sb)->vcc = vcc;
- __net_timestamp(sb);
- vcc->push(vcc, sb);
- atomic_inc(&vcc->stats->rx);
- drop:
- skb_pull(queue, 64);
- head = IDT77252_PRV_PADDR(queue)
- + (queue->data - queue->head - 16);
- if (queue->len < 128) {
- struct sk_buff *next;
- u32 handle;
- head = le32_to_cpu(*(u32 *) &queue->data[0]);
- handle = le32_to_cpu(*(u32 *) &queue->data[4]);
- next = sb_pool_skb(card, handle);
- recycle_rx_skb(card, queue);
- if (next) {
- card->raw_cell_head = next;
- queue = card->raw_cell_head;
- dma_sync_single_for_cpu(&card->pcidev->dev,
- IDT77252_PRV_PADDR(queue),
- (skb_end_pointer(queue) -
- queue->data),
- DMA_FROM_DEVICE);
- } else {
- card->raw_cell_head = NULL;
- printk("%s: raw cell queue overrun\n",
- card->name);
- break;
- }
- }
- }
- }
- /*****************************************************************************/
- /* */
- /* TSQ Handling */
- /* */
- /*****************************************************************************/
- static int
- init_tsq(struct idt77252_dev *card)
- {
- struct tsq_entry *tsqe;
- card->tsq.base = dma_alloc_coherent(&card->pcidev->dev, RSQSIZE,
- &card->tsq.paddr, GFP_KERNEL);
- if (card->tsq.base == NULL) {
- printk("%s: can't allocate TSQ.\n", card->name);
- return -1;
- }
- memset(card->tsq.base, 0, TSQSIZE);
- card->tsq.last = card->tsq.base + TSQ_NUM_ENTRIES - 1;
- card->tsq.next = card->tsq.last;
- for (tsqe = card->tsq.base; tsqe <= card->tsq.last; tsqe++)
- tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID);
- writel(card->tsq.paddr, SAR_REG_TSQB);
- writel((unsigned long) card->tsq.next - (unsigned long) card->tsq.base,
- SAR_REG_TSQH);
- return 0;
- }
- static void
- deinit_tsq(struct idt77252_dev *card)
- {
- dma_free_coherent(&card->pcidev->dev, TSQSIZE,
- card->tsq.base, card->tsq.paddr);
- }
- static void
- idt77252_tx(struct idt77252_dev *card)
- {
- struct tsq_entry *tsqe;
- unsigned int vpi, vci;
- struct vc_map *vc;
- u32 conn, stat;
- if (card->tsq.next == card->tsq.last)
- tsqe = card->tsq.base;
- else
- tsqe = card->tsq.next + 1;
- TXPRINTK("idt77252_tx: tsq %p: base %p, next %p, last %p\n", tsqe,
- card->tsq.base, card->tsq.next, card->tsq.last);
- TXPRINTK("idt77252_tx: tsqb %08x, tsqt %08x, tsqh %08x, \n",
- readl(SAR_REG_TSQB),
- readl(SAR_REG_TSQT),
- readl(SAR_REG_TSQH));
- stat = le32_to_cpu(tsqe->word_2);
- if (stat & SAR_TSQE_INVALID)
- return;
- do {
- TXPRINTK("tsqe: 0x%p [0x%08x 0x%08x]\n", tsqe,
- le32_to_cpu(tsqe->word_1),
- le32_to_cpu(tsqe->word_2));
- switch (stat & SAR_TSQE_TYPE) {
- case SAR_TSQE_TYPE_TIMER:
- TXPRINTK("%s: Timer RollOver detected.\n", card->name);
- break;
- case SAR_TSQE_TYPE_IDLE:
- conn = le32_to_cpu(tsqe->word_1);
- if (SAR_TSQE_TAG(stat) == 0x10) {
- #ifdef NOTDEF
- printk("%s: Connection %d halted.\n",
- card->name,
- le32_to_cpu(tsqe->word_1) & 0x1fff);
- #endif
- break;
- }
- vc = card->vcs[conn & 0x1fff];
- if (!vc) {
- printk("%s: could not find VC from conn %d\n",
- card->name, conn & 0x1fff);
- break;
- }
- printk("%s: Connection %d IDLE.\n",
- card->name, vc->index);
- set_bit(VCF_IDLE, &vc->flags);
- break;
- case SAR_TSQE_TYPE_TSR:
- conn = le32_to_cpu(tsqe->word_1);
- vc = card->vcs[conn & 0x1fff];
- if (!vc) {
- printk("%s: no VC at index %d\n",
- card->name,
- le32_to_cpu(tsqe->word_1) & 0x1fff);
- break;
- }
- drain_scq(card, vc);
- break;
- case SAR_TSQE_TYPE_TBD_COMP:
- conn = le32_to_cpu(tsqe->word_1);
- vpi = (conn >> SAR_TBD_VPI_SHIFT) & 0x00ff;
- vci = (conn >> SAR_TBD_VCI_SHIFT) & 0xffff;
- if (vpi >= (1 << card->vpibits) ||
- vci >= (1 << card->vcibits)) {
- printk("%s: TBD complete: "
- "out of range VPI.VCI %u.%u\n",
- card->name, vpi, vci);
- break;
- }
- vc = card->vcs[VPCI2VC(card, vpi, vci)];
- if (!vc) {
- printk("%s: TBD complete: "
- "no VC at VPI.VCI %u.%u\n",
- card->name, vpi, vci);
- break;
- }
- drain_scq(card, vc);
- break;
- }
- tsqe->word_2 = cpu_to_le32(SAR_TSQE_INVALID);
- card->tsq.next = tsqe;
- if (card->tsq.next == card->tsq.last)
- tsqe = card->tsq.base;
- else
- tsqe = card->tsq.next + 1;
- TXPRINTK("tsqe: %p: base %p, next %p, last %p\n", tsqe,
- card->tsq.base, card->tsq.next, card->tsq.last);
- stat = le32_to_cpu(tsqe->word_2);
- } while (!(stat & SAR_TSQE_INVALID));
- writel((unsigned long)card->tsq.next - (unsigned long)card->tsq.base,
- SAR_REG_TSQH);
- XPRINTK("idt77252_tx-after writel%d: TSQ head = 0x%x, tail = 0x%x, next = 0x%p.\n",
- card->index, readl(SAR_REG_TSQH),
- readl(SAR_REG_TSQT), card->tsq.next);
- }
- static void
- tst_timer(unsigned long data)
- {
- struct idt77252_dev *card = (struct idt77252_dev *)data;
- unsigned long base, idle, jump;
- unsigned long flags;
- u32 pc;
- int e;
- spin_lock_irqsave(&card->tst_lock, flags);
- base = card->tst[card->tst_index];
- idle = card->tst[card->tst_index ^ 1];
- if (test_bit(TST_SWITCH_WAIT, &card->tst_state)) {
- jump = base + card->tst_size - 2;
- pc = readl(SAR_REG_NOW) >> 2;
- if ((pc ^ idle) & ~(card->tst_size - 1)) {
- mod_timer(&card->tst_timer, jiffies + 1);
- goto out;
- }
- clear_bit(TST_SWITCH_WAIT, &card->tst_state);
- card->tst_index ^= 1;
- write_sram(card, jump, TSTE_OPC_JMP | (base << 2));
- base = card->tst[card->tst_index];
- idle = card->tst[card->tst_index ^ 1];
- for (e = 0; e < card->tst_size - 2; e++) {
- if (card->soft_tst[e].tste & TSTE_PUSH_IDLE) {
- write_sram(card, idle + e,
- card->soft_tst[e].tste & TSTE_MASK);
- card->soft_tst[e].tste &= ~(TSTE_PUSH_IDLE);
- }
- }
- }
- if (test_and_clear_bit(TST_SWITCH_PENDING, &card->tst_state)) {
- for (e = 0; e < card->tst_size - 2; e++) {
- if (card->soft_tst[e].tste & TSTE_PUSH_ACTIVE) {
- write_sram(card, idle + e,
- card->soft_tst[e].tste & TSTE_MASK);
- card->soft_tst[e].tste &= ~(TSTE_PUSH_ACTIVE);
- card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
- }
- }
- jump = base + card->tst_size - 2;
- write_sram(card, jump, TSTE_OPC_NULL);
- set_bit(TST_SWITCH_WAIT, &card->tst_state);
- mod_timer(&card->tst_timer, jiffies + 1);
- }
- out:
- spin_unlock_irqrestore(&card->tst_lock, flags);
- }
- static int
- __fill_tst(struct idt77252_dev *card, struct vc_map *vc,
- int n, unsigned int opc)
- {
- unsigned long cl, avail;
- unsigned long idle;
- int e, r;
- u32 data;
- avail = card->tst_size - 2;
- for (e = 0; e < avail; e++) {
- if (card->soft_tst[e].vc == NULL)
- break;
- }
- if (e >= avail) {
- printk("%s: No free TST entries found\n", card->name);
- return -1;
- }
- NPRINTK("%s: conn %d: first TST entry at %d.\n",
- card->name, vc ? vc->index : -1, e);
- r = n;
- cl = avail;
- data = opc & TSTE_OPC_MASK;
- if (vc && (opc != TSTE_OPC_NULL))
- data = opc | vc->index;
- idle = card->tst[card->tst_index ^ 1];
- /*
- * Fill Soft TST.
- */
- while (r > 0) {
- if ((cl >= avail) && (card->soft_tst[e].vc == NULL)) {
- if (vc)
- card->soft_tst[e].vc = vc;
- else
- card->soft_tst[e].vc = (void *)-1;
- card->soft_tst[e].tste = data;
- if (timer_pending(&card->tst_timer))
- card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE;
- else {
- write_sram(card, idle + e, data);
- card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
- }
- cl -= card->tst_size;
- r--;
- }
- if (++e == avail)
- e = 0;
- cl += n;
- }
- return 0;
- }
- static int
- fill_tst(struct idt77252_dev *card, struct vc_map *vc, int n, unsigned int opc)
- {
- unsigned long flags;
- int res;
- spin_lock_irqsave(&card->tst_lock, flags);
- res = __fill_tst(card, vc, n, opc);
- set_bit(TST_SWITCH_PENDING, &card->tst_state);
- if (!timer_pending(&card->tst_timer))
- mod_timer(&card->tst_timer, jiffies + 1);
- spin_unlock_irqrestore(&card->tst_lock, flags);
- return res;
- }
- static int
- __clear_tst(struct idt77252_dev *card, struct vc_map *vc)
- {
- unsigned long idle;
- int e;
- idle = card->tst[card->tst_index ^ 1];
- for (e = 0; e < card->tst_size - 2; e++) {
- if (card->soft_tst[e].vc == vc) {
- card->soft_tst[e].vc = NULL;
- card->soft_tst[e].tste = TSTE_OPC_VAR;
- if (timer_pending(&card->tst_timer))
- card->soft_tst[e].tste |= TSTE_PUSH_ACTIVE;
- else {
- write_sram(card, idle + e, TSTE_OPC_VAR);
- card->soft_tst[e].tste |= TSTE_PUSH_IDLE;
- }
- }
- }
- return 0;
- }
- static int
- clear_tst(struct idt77252_dev *card, struct vc_map *vc)
- {
- unsigned long flags;
- int res;
- spin_lock_irqsave(&card->tst_lock, flags);
- res = __clear_tst(card, vc);
- set_bit(TST_SWITCH_PENDING, &card->tst_state);
- if (!timer_pending(&card->tst_timer))
- mod_timer(&card->tst_timer, jiffies + 1);
- spin_unlock_irqrestore(&card->tst_lock, flags);
- return res;
- }
- static int
- change_tst(struct idt77252_dev *card, struct vc_map *vc,
- int n, unsigned int opc)
- {
- unsigned long flags;
- int res;
- spin_lock_irqsave(&card->tst_lock, flags);
- __clear_tst(card, vc);
- res = __fill_tst(card, vc, n, opc);
- set_bit(TST_SWITCH_PENDING, &card->tst_state);
- if (!timer_pending(&card->tst_timer))
- mod_timer(&card->tst_timer, jiffies + 1);
- spin_unlock_irqrestore(&card->tst_lock, flags);
- return res;
- }
- static int
- set_tct(struct idt77252_dev *card, struct vc_map *vc)
- {
- unsigned long tct;
- tct = (unsigned long) (card->tct_base + vc->index * SAR_SRAM_TCT_SIZE);
- switch (vc->class) {
- case SCHED_CBR:
- OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n",
- card->name, tct, vc->scq->scd);
- write_sram(card, tct + 0, TCT_CBR | vc->scq->scd);
- write_sram(card, tct + 1, 0);
- write_sram(card, tct + 2, 0);
- write_sram(card, tct + 3, 0);
- write_sram(card, tct + 4, 0);
- write_sram(card, tct + 5, 0);
- write_sram(card, tct + 6, 0);
- write_sram(card, tct + 7, 0);
- break;
- case SCHED_UBR:
- OPRINTK("%s: writing TCT at 0x%lx, SCD 0x%lx.\n",
- card->name, tct, vc->scq->scd);
- write_sram(card, tct + 0, TCT_UBR | vc->scq->scd);
- write_sram(card, tct + 1, 0);
- write_sram(card, tct + 2, TCT_TSIF);
- write_sram(card, tct + 3, TCT_HALT | TCT_IDLE);
- write_sram(card, tct + 4, 0);
- write_sram(card, tct + 5, vc->init_er);
- write_sram(card, tct + 6, 0);
- write_sram(card, tct + 7, TCT_FLAG_UBR);
- break;
- case SCHED_VBR:
- case SCHED_ABR:
- default:
- return -ENOSYS;
- }
- return 0;
- }
- /*****************************************************************************/
- /* */
- /* FBQ Handling */
- /* */
- /*****************************************************************************/
- static __inline__ int
- idt77252_fbq_level(struct idt77252_dev *card, int queue)
- {
- return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) & 0x0f;
- }
- static __inline__ int
- idt77252_fbq_full(struct idt77252_dev *card, int queue)
- {
- return (readl(SAR_REG_STAT) >> (16 + (queue << 2))) == 0x0f;
- }
- static int
- push_rx_skb(struct idt77252_dev *card, struct sk_buff *skb, int queue)
- {
- unsigned long flags;
- u32 handle;
- u32 addr;
- skb->data = skb->head;
- skb_reset_tail_pointer(skb);
- skb->len = 0;
- skb_reserve(skb, 16);
- switch (queue) {
- case 0:
- skb_put(skb, SAR_FB_SIZE_0);
- break;
- case 1:
- skb_put(skb, SAR_FB_SIZE_1);
- break;
- case 2:
- skb_put(skb, SAR_FB_SIZE_2);
- break;
- case 3:
- skb_put(skb, SAR_FB_SIZE_3);
- break;
- default:
- return -1;
- }
- if (idt77252_fbq_full(card, queue))
- return -1;
- memset(&skb->data[(skb->len & ~(0x3f)) - 64], 0, 2 * sizeof(u32));
- handle = IDT77252_PRV_POOL(skb);
- addr = IDT77252_PRV_PADDR(skb);
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel(handle, card->fbq[queue]);
- writel(addr, card->fbq[queue]);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- return 0;
- }
- static void
- add_rx_skb(struct idt77252_dev *card, int queue,
- unsigned int size, unsigned int count)
- {
- struct sk_buff *skb;
- dma_addr_t paddr;
- u32 handle;
- while (count--) {
- skb = dev_alloc_skb(size);
- if (!skb)
- return;
- if (sb_pool_add(card, skb, queue)) {
- printk("%s: SB POOL full\n", __func__);
- goto outfree;
- }
- paddr = dma_map_single(&card->pcidev->dev, skb->data,
- skb_end_pointer(skb) - skb->data,
- DMA_FROM_DEVICE);
- IDT77252_PRV_PADDR(skb) = paddr;
- if (push_rx_skb(card, skb, queue)) {
- printk("%s: FB QUEUE full\n", __func__);
- goto outunmap;
- }
- }
- return;
- outunmap:
- dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb_end_pointer(skb) - skb->data, DMA_FROM_DEVICE);
- handle = IDT77252_PRV_POOL(skb);
- card->sbpool[POOL_QUEUE(handle)].skb[POOL_INDEX(handle)] = NULL;
- outfree:
- dev_kfree_skb(skb);
- }
- static void
- recycle_rx_skb(struct idt77252_dev *card, struct sk_buff *skb)
- {
- u32 handle = IDT77252_PRV_POOL(skb);
- int err;
- dma_sync_single_for_device(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb_end_pointer(skb) - skb->data,
- DMA_FROM_DEVICE);
- err = push_rx_skb(card, skb, POOL_QUEUE(handle));
- if (err) {
- dma_unmap_single(&card->pcidev->dev, IDT77252_PRV_PADDR(skb),
- skb_end_pointer(skb) - skb->data,
- DMA_FROM_DEVICE);
- sb_pool_remove(card, skb);
- dev_kfree_skb(skb);
- }
- }
- static void
- flush_rx_pool(struct idt77252_dev *card, struct rx_pool *rpp)
- {
- skb_queue_head_init(&rpp->queue);
- rpp->len = 0;
- }
- static void
- recycle_rx_pool_skb(struct idt77252_dev *card, struct rx_pool *rpp)
- {
- struct sk_buff *skb, *tmp;
- skb_queue_walk_safe(&rpp->queue, skb, tmp)
- recycle_rx_skb(card, skb);
- flush_rx_pool(card, rpp);
- }
- /*****************************************************************************/
- /* */
- /* ATM Interface */
- /* */
- /*****************************************************************************/
- static void
- idt77252_phy_put(struct atm_dev *dev, unsigned char value, unsigned long addr)
- {
- write_utility(dev->dev_data, 0x100 + (addr & 0x1ff), value);
- }
- static unsigned char
- idt77252_phy_get(struct atm_dev *dev, unsigned long addr)
- {
- return read_utility(dev->dev_data, 0x100 + (addr & 0x1ff));
- }
- static inline int
- idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
- {
- struct atm_dev *dev = vcc->dev;
- struct idt77252_dev *card = dev->dev_data;
- struct vc_map *vc = vcc->dev_data;
- int err;
- if (vc == NULL) {
- printk("%s: NULL connection in send().\n", card->name);
- atomic_inc(&vcc->stats->tx_err);
- dev_kfree_skb(skb);
- return -EINVAL;
- }
- if (!test_bit(VCF_TX, &vc->flags)) {
- printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
- atomic_inc(&vcc->stats->tx_err);
- dev_kfree_skb(skb);
- return -EINVAL;
- }
- switch (vcc->qos.aal) {
- case ATM_AAL0:
- case ATM_AAL1:
- case ATM_AAL5:
- break;
- default:
- printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
- atomic_inc(&vcc->stats->tx_err);
- dev_kfree_skb(skb);
- return -EINVAL;
- }
- if (skb_shinfo(skb)->nr_frags != 0) {
- printk("%s: No scatter-gather yet.\n", card->name);
- atomic_inc(&vcc->stats->tx_err);
- dev_kfree_skb(skb);
- return -EINVAL;
- }
- ATM_SKB(skb)->vcc = vcc;
- err = queue_skb(card, vc, skb, oam);
- if (err) {
- atomic_inc(&vcc->stats->tx_err);
- dev_kfree_skb(skb);
- return err;
- }
- return 0;
- }
- static int idt77252_send(struct atm_vcc *vcc, struct sk_buff *skb)
- {
- return idt77252_send_skb(vcc, skb, 0);
- }
- static int
- idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
- {
- struct atm_dev *dev = vcc->dev;
- struct idt77252_dev *card = dev->dev_data;
- struct sk_buff *skb;
- skb = dev_alloc_skb(64);
- if (!skb) {
- printk("%s: Out of memory in send_oam().\n", card->name);
- atomic_inc(&vcc->stats->tx_err);
- return -ENOMEM;
- }
- atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
- memcpy(skb_put(skb, 52), cell, 52);
- return idt77252_send_skb(vcc, skb, 1);
- }
- static __inline__ unsigned int
- idt77252_fls(unsigned int x)
- {
- int r = 1;
- if (x == 0)
- return 0;
- if (x & 0xffff0000) {
- x >>= 16;
- r += 16;
- }
- if (x & 0xff00) {
- x >>= 8;
- r += 8;
- }
- if (x & 0xf0) {
- x >>= 4;
- r += 4;
- }
- if (x & 0xc) {
- x >>= 2;
- r += 2;
- }
- if (x & 0x2)
- r += 1;
- return r;
- }
- static u16
- idt77252_int_to_atmfp(unsigned int rate)
- {
- u16 m, e;
- if (rate == 0)
- return 0;
- e = idt77252_fls(rate) - 1;
- if (e < 9)
- m = (rate - (1 << e)) << (9 - e);
- else if (e == 9)
- m = (rate - (1 << e));
- else /* e > 9 */
- m = (rate - (1 << e)) >> (e - 9);
- return 0x4000 | (e << 9) | m;
- }
- static u8
- idt77252_rate_logindex(struct idt77252_dev *card, int pcr)
- {
- u16 afp;
- afp = idt77252_int_to_atmfp(pcr < 0 ? -pcr : pcr);
- if (pcr < 0)
- return rate_to_log[(afp >> 5) & 0x1ff];
- return rate_to_log[((afp >> 5) + 1) & 0x1ff];
- }
- static void
- idt77252_est_timer(unsigned long data)
- {
- struct vc_map *vc = (struct vc_map *)data;
- struct idt77252_dev *card = vc->card;
- struct rate_estimator *est;
- unsigned long flags;
- u32 rate, cps;
- u64 ncells;
- u8 lacr;
- spin_lock_irqsave(&vc->lock, flags);
- est = vc->estimator;
- if (!est)
- goto out;
- ncells = est->cells;
- rate = ((u32)(ncells - est->last_cells)) << (7 - est->interval);
- est->last_cells = ncells;
- est->avcps += ((long)rate - (long)est->avcps) >> est->ewma_log;
- est->cps = (est->avcps + 0x1f) >> 5;
- cps = est->cps;
- if (cps < (est->maxcps >> 4))
- cps = est->maxcps >> 4;
- lacr = idt77252_rate_logindex(card, cps);
- if (lacr > vc->max_er)
- lacr = vc->max_er;
- if (lacr != vc->lacr) {
- vc->lacr = lacr;
- writel(TCMDQ_LACR|(vc->lacr << 16)|vc->index, SAR_REG_TCMDQ);
- }
- est->timer.expires = jiffies + ((HZ / 4) << est->interval);
- add_timer(&est->timer);
- out:
- spin_unlock_irqrestore(&vc->lock, flags);
- }
- static struct rate_estimator *
- idt77252_init_est(struct vc_map *vc, int pcr)
- {
- struct rate_estimator *est;
- est = kzalloc(sizeof(struct rate_estimator), GFP_KERNEL);
- if (!est)
- return NULL;
- est->maxcps = pcr < 0 ? -pcr : pcr;
- est->cps = est->maxcps;
- est->avcps = est->cps << 5;
- est->interval = 2; /* XXX: make this configurable */
- est->ewma_log = 2; /* XXX: make this configurable */
- init_timer(&est->timer);
- est->timer.data = (unsigned long)vc;
- est->timer.function = idt77252_est_timer;
- est->timer.expires = jiffies + ((HZ / 4) << est->interval);
- add_timer(&est->timer);
- return est;
- }
- static int
- idt77252_init_cbr(struct idt77252_dev *card, struct vc_map *vc,
- struct atm_vcc *vcc, struct atm_qos *qos)
- {
- int tst_free, tst_used, tst_entries;
- unsigned long tmpl, modl;
- int tcr, tcra;
- if ((qos->txtp.max_pcr == 0) &&
- (qos->txtp.pcr == 0) && (qos->txtp.min_pcr == 0)) {
- printk("%s: trying to open a CBR VC with cell rate = 0\n",
- card->name);
- return -EINVAL;
- }
- tst_used = 0;
- tst_free = card->tst_free;
- if (test_bit(VCF_TX, &vc->flags))
- tst_used = vc->ntste;
- tst_free += tst_used;
- tcr = atm_pcr_goal(&qos->txtp);
- tcra = tcr >= 0 ? tcr : -tcr;
- TXPRINTK("%s: CBR target cell rate = %d\n", card->name, tcra);
- tmpl = (unsigned long) tcra * ((unsigned long) card->tst_size - 2);
- modl = tmpl % (unsigned long)card->utopia_pcr;
- tst_entries = (int) (tmpl / card->utopia_pcr);
- if (tcr > 0) {
- if (modl > 0)
- tst_entries++;
- } else if (tcr == 0) {
- tst_entries = tst_free - SAR_TST_RESERVED;
- if (tst_entries <= 0) {
- printk("%s: no CBR bandwidth free.\n", card->name);
- return -ENOSR;
- }
- }
- if (tst_entries == 0) {
- printk("%s: selected CBR bandwidth < granularity.\n",
- card->name);
- return -EINVAL;
- }
- if (tst_entries > (tst_free - SAR_TST_RESERVED)) {
- printk("%s: not enough CBR bandwidth free.\n", card->name);
- return -ENOSR;
- }
- vc->ntste = tst_entries;
- card->tst_free = tst_free - tst_entries;
- if (test_bit(VCF_TX, &vc->flags)) {
- if (tst_used == tst_entries)
- return 0;
- OPRINTK("%s: modify %d -> %d entries in TST.\n",
- card->name, tst_used, tst_entries);
- change_tst(card, vc, tst_entries, TSTE_OPC_CBR);
- return 0;
- }
- OPRINTK("%s: setting %d entries in TST.\n", card->name, tst_entries);
- fill_tst(card, vc, tst_entries, TSTE_OPC_CBR);
- return 0;
- }
- static int
- idt77252_init_ubr(struct idt77252_dev *card, struct vc_map *vc,
- struct atm_vcc *vcc, struct atm_qos *qos)
- {
- unsigned long flags;
- int tcr;
- spin_lock_irqsave(&vc->lock, flags);
- if (vc->estimator) {
- del_timer(&vc->estimator->timer);
- kfree(vc->estimator);
- vc->estimator = NULL;
- }
- spin_unlock_irqrestore(&vc->lock, flags);
- tcr = atm_pcr_goal(&qos->txtp);
- if (tcr == 0)
- tcr = card->link_pcr;
- vc->estimator = idt77252_init_est(vc, tcr);
- vc->class = SCHED_UBR;
- vc->init_er = idt77252_rate_logindex(card, tcr);
- vc->lacr = vc->init_er;
- if (tcr < 0)
- vc->max_er = vc->init_er;
- else
- vc->max_er = 0xff;
- return 0;
- }
- static int
- idt77252_init_tx(struct idt77252_dev *card, struct vc_map *vc,
- struct atm_vcc *vcc, struct atm_qos *qos)
- {
- int error;
- if (test_bit(VCF_TX, &vc->flags))
- return -EBUSY;
- switch (qos->txtp.traffic_class) {
- case ATM_CBR:
- vc->class = SCHED_CBR;
- break;
- case ATM_UBR:
- vc->class = SCHED_UBR;
- break;
- case ATM_VBR:
- case ATM_ABR:
- default:
- return -EPROTONOSUPPORT;
- }
- vc->scq = alloc_scq(card, vc->class);
- if (!vc->scq) {
- printk("%s: can't get SCQ.\n", card->name);
- return -ENOMEM;
- }
- vc->scq->scd = get_free_scd(card, vc);
- if (vc->scq->scd == 0) {
- printk("%s: no SCD available.\n", card->name);
- free_scq(card, vc->scq);
- return -ENOMEM;
- }
- fill_scd(card, vc->scq, vc->class);
- if (set_tct(card, vc)) {
- printk("%s: class %d not supported.\n",
- card->name, qos->txtp.traffic_class);
- card->scd2vc[vc->scd_index] = NULL;
- free_scq(card, vc->scq);
- return -EPROTONOSUPPORT;
- }
- switch (vc->class) {
- case SCHED_CBR:
- error = idt77252_init_cbr(card, vc, vcc, qos);
- if (error) {
- card->scd2vc[vc->scd_index] = NULL;
- free_scq(card, vc->scq);
- return error;
- }
- clear_bit(VCF_IDLE, &vc->flags);
- writel(TCMDQ_START | vc->index, SAR_REG_TCMDQ);
- break;
- case SCHED_UBR:
- error = idt77252_init_ubr(card, vc, vcc, qos);
- if (error) {
- card->scd2vc[vc->scd_index] = NULL;
- free_scq(card, vc->scq);
- return error;
- }
- set_bit(VCF_IDLE, &vc->flags);
- break;
- }
- vc->tx_vcc = vcc;
- set_bit(VCF_TX, &vc->flags);
- return 0;
- }
- static int
- idt77252_init_rx(struct idt77252_dev *card, struct vc_map *vc,
- struct atm_vcc *vcc, struct atm_qos *qos)
- {
- unsigned long flags;
- unsigned long addr;
- u32 rcte = 0;
- if (test_bit(VCF_RX, &vc->flags))
- return -EBUSY;
- vc->rx_vcc = vcc;
- set_bit(VCF_RX, &vc->flags);
- if ((vcc->vci == 3) || (vcc->vci == 4))
- return 0;
- flush_rx_pool(card, &vc->rcv.rx_pool);
- rcte |= SAR_RCTE_CONNECTOPEN;
- rcte |= SAR_RCTE_RAWCELLINTEN;
- switch (qos->aal) {
- case ATM_AAL0:
- rcte |= SAR_RCTE_RCQ;
- break;
- case ATM_AAL1:
- rcte |= SAR_RCTE_OAM; /* Let SAR drop Video */
- break;
- case ATM_AAL34:
- rcte |= SAR_RCTE_AAL34;
- break;
- case ATM_AAL5:
- rcte |= SAR_RCTE_AAL5;
- break;
- default:
- rcte |= SAR_RCTE_RCQ;
- break;
- }
- if (qos->aal != ATM_AAL5)
- rcte |= SAR_RCTE_FBP_1;
- else if (qos->rxtp.max_sdu > SAR_FB_SIZE_2)
- rcte |= SAR_RCTE_FBP_3;
- else if (qos->rxtp.max_sdu > SAR_FB_SIZE_1)
- rcte |= SAR_RCTE_FBP_2;
- else if (qos->rxtp.max_sdu > SAR_FB_SIZE_0)
- rcte |= SAR_RCTE_FBP_1;
- else
- rcte |= SAR_RCTE_FBP_01;
- addr = card->rct_base + (vc->index << 2);
- OPRINTK("%s: writing RCT at 0x%lx\n", card->name, addr);
- write_sram(card, addr, rcte);
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel(SAR_CMD_OPEN_CONNECTION | (addr << 2), SAR_REG_CMD);
- waitfor_idle(card);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- return 0;
- }
- static int
- idt77252_open(struct atm_vcc *vcc)
- {
- struct atm_dev *dev = vcc->dev;
- struct idt77252_dev *card = dev->dev_data;
- struct vc_map *vc;
- unsigned int index;
- unsigned int inuse;
- int error;
- int vci = vcc->vci;
- short vpi = vcc->vpi;
- if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
- return 0;
- if (vpi >= (1 << card->vpibits)) {
- printk("%s: unsupported VPI: %d\n", card->name, vpi);
- return -EINVAL;
- }
- if (vci >= (1 << card->vcibits)) {
- printk("%s: unsupported VCI: %d\n", card->name, vci);
- return -EINVAL;
- }
- set_bit(ATM_VF_ADDR, &vcc->flags);
- mutex_lock(&card->mutex);
- OPRINTK("%s: opening vpi.vci: %d.%d\n", card->name, vpi, vci);
- switch (vcc->qos.aal) {
- case ATM_AAL0:
- case ATM_AAL1:
- case ATM_AAL5:
- break;
- default:
- printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
- mutex_unlock(&card->mutex);
- return -EPROTONOSUPPORT;
- }
- index = VPCI2VC(card, vpi, vci);
- if (!card->vcs[index]) {
- card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
- if (!card->vcs[index]) {
- printk("%s: can't alloc vc in open()\n", card->name);
- mutex_unlock(&card->mutex);
- return -ENOMEM;
- }
- card->vcs[index]->card = card;
- card->vcs[index]->index = index;
- spin_lock_init(&card->vcs[index]->lock);
- }
- vc = card->vcs[index];
- vcc->dev_data = vc;
- IPRINTK("%s: idt77252_open: vc = %d (%d.%d) %s/%s (max RX SDU: %u)\n",
- card->name, vc->index, vcc->vpi, vcc->vci,
- vcc->qos.rxtp.traffic_class != ATM_NONE ? "rx" : "--",
- vcc->qos.txtp.traffic_class != ATM_NONE ? "tx" : "--",
- vcc->qos.rxtp.max_sdu);
- inuse = 0;
- if (vcc->qos.txtp.traffic_class != ATM_NONE &&
- test_bit(VCF_TX, &vc->flags))
- inuse = 1;
- if (vcc->qos.rxtp.traffic_class != ATM_NONE &&
- test_bit(VCF_RX, &vc->flags))
- inuse += 2;
- if (inuse) {
- printk("%s: %s vci already in use.\n", card->name,
- inuse == 1 ? "tx" : inuse == 2 ? "rx" : "tx and rx");
- mutex_unlock(&card->mutex);
- return -EADDRINUSE;
- }
- if (vcc->qos.txtp.traffic_class != ATM_NONE) {
- error = idt77252_init_tx(card, vc, vcc, &vcc->qos);
- if (error) {
- mutex_unlock(&card->mutex);
- return error;
- }
- }
- if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
- error = idt77252_init_rx(card, vc, vcc, &vcc->qos);
- if (error) {
- mutex_unlock(&card->mutex);
- return error;
- }
- }
- set_bit(ATM_VF_READY, &vcc->flags);
- mutex_unlock(&card->mutex);
- return 0;
- }
- static void
- idt77252_close(struct atm_vcc *vcc)
- {
- struct atm_dev *dev = vcc->dev;
- struct idt77252_dev *card = dev->dev_data;
- struct vc_map *vc = vcc->dev_data;
- unsigned long flags;
- unsigned long addr;
- unsigned long timeout;
- mutex_lock(&card->mutex);
- IPRINTK("%s: idt77252_close: vc = %d (%d.%d)\n",
- card->name, vc->index, vcc->vpi, vcc->vci);
- clear_bit(ATM_VF_READY, &vcc->flags);
- if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
- spin_lock_irqsave(&vc->lock, flags);
- clear_bit(VCF_RX, &vc->flags);
- vc->rx_vcc = NULL;
- spin_unlock_irqrestore(&vc->lock, flags);
- if ((vcc->vci == 3) || (vcc->vci == 4))
- goto done;
- addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE;
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2), SAR_REG_CMD);
- waitfor_idle(card);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- if (skb_queue_len(&vc->rcv.rx_pool.queue) != 0) {
- DPRINTK("%s: closing a VC with pending rx buffers.\n",
- card->name);
- recycle_rx_pool_skb(card, &vc->rcv.rx_pool);
- }
- }
- done:
- if (vcc->qos.txtp.traffic_class != ATM_NONE) {
- spin_lock_irqsave(&vc->lock, flags);
- clear_bit(VCF_TX, &vc->flags);
- clear_bit(VCF_IDLE, &vc->flags);
- clear_bit(VCF_RSV, &vc->flags);
- vc->tx_vcc = NULL;
- if (vc->estimator) {
- del_timer(&vc->estimator->timer);
- kfree(vc->estimator);
- vc->estimator = NULL;
- }
- spin_unlock_irqrestore(&vc->lock, flags);
- timeout = 5 * 1000;
- while (atomic_read(&vc->scq->used) > 0) {
- timeout = msleep_interruptible(timeout);
- if (!timeout) {
- pr_warn("%s: SCQ drain timeout: %u used\n",
- card->name, atomic_read(&vc->scq->used));
- break;
- }
- }
- writel(TCMDQ_HALT | vc->index, SAR_REG_TCMDQ);
- clear_scd(card, vc->scq, vc->class);
- if (vc->class == SCHED_CBR) {
- clear_tst(card, vc);
- card->tst_free += vc->ntste;
- vc->ntste = 0;
- }
- card->scd2vc[vc->scd_index] = NULL;
- free_scq(card, vc->scq);
- }
- mutex_unlock(&card->mutex);
- }
- static int
- idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags)
- {
- struct atm_dev *dev = vcc->dev;
- struct idt77252_dev *card = dev->dev_data;
- struct vc_map *vc = vcc->dev_data;
- int error = 0;
- mutex_lock(&card->mutex);
- if (qos->txtp.traffic_class != ATM_NONE) {
- if (!test_bit(VCF_TX, &vc->flags)) {
- error = idt77252_init_tx(card, vc, vcc, qos);
- if (error)
- goto out;
- } else {
- switch (qos->txtp.traffic_class) {
- case ATM_CBR:
- error = idt77252_init_cbr(card, vc, vcc, qos);
- if (error)
- goto out;
- break;
- case ATM_UBR:
- error = idt77252_init_ubr(card, vc, vcc, qos);
- if (error)
- goto out;
- if (!test_bit(VCF_IDLE, &vc->flags)) {
- writel(TCMDQ_LACR | (vc->lacr << 16) |
- vc->index, SAR_REG_TCMDQ);
- }
- break;
- case ATM_VBR:
- case ATM_ABR:
- error = -EOPNOTSUPP;
- goto out;
- }
- }
- }
- if ((qos->rxtp.traffic_class != ATM_NONE) &&
- !test_bit(VCF_RX, &vc->flags)) {
- error = idt77252_init_rx(card, vc, vcc, qos);
- if (error)
- goto out;
- }
- memcpy(&vcc->qos, qos, sizeof(struct atm_qos));
- set_bit(ATM_VF_HASQOS, &vcc->flags);
- out:
- mutex_unlock(&card->mutex);
- return error;
- }
- static int
- idt77252_proc_read(struct atm_dev *dev, loff_t * pos, char *page)
- {
- struct idt77252_dev *card = dev->dev_data;
- int i, left;
- left = (int) *pos;
- if (!left--)
- return sprintf(page, "IDT77252 Interrupts:\n");
- if (!left--)
- return sprintf(page, "TSIF: %lu\n", card->irqstat[15]);
- if (!left--)
- return sprintf(page, "TXICP: %lu\n", card->irqstat[14]);
- if (!left--)
- return sprintf(page, "TSQF: %lu\n", card->irqstat[12]);
- if (!left--)
- return sprintf(page, "TMROF: %lu\n", card->irqstat[11]);
- if (!left--)
- return sprintf(page, "PHYI: %lu\n", card->irqstat[10]);
- if (!left--)
- return sprintf(page, "FBQ3A: %lu\n", card->irqstat[8]);
- if (!left--)
- return sprintf(page, "FBQ2A: %lu\n", card->irqstat[7]);
- if (!left--)
- return sprintf(page, "RSQF: %lu\n", card->irqstat[6]);
- if (!left--)
- return sprintf(page, "EPDU: %lu\n", card->irqstat[5]);
- if (!left--)
- return sprintf(page, "RAWCF: %lu\n", card->irqstat[4]);
- if (!left--)
- return sprintf(page, "FBQ1A: %lu\n", card->irqstat[3]);
- if (!left--)
- return sprintf(page, "FBQ0A: %lu\n", card->irqstat[2]);
- if (!left--)
- return sprintf(page, "RSQAF: %lu\n", card->irqstat[1]);
- if (!left--)
- return sprintf(page, "IDT77252 Transmit Connection Table:\n");
- for (i = 0; i < card->tct_size; i++) {
- unsigned long tct;
- struct atm_vcc *vcc;
- struct vc_map *vc;
- char *p;
- vc = card->vcs[i];
- if (!vc)
- continue;
- vcc = NULL;
- if (vc->tx_vcc)
- vcc = vc->tx_vcc;
- if (!vcc)
- continue;
- if (left--)
- continue;
- p = page;
- p += sprintf(p, " %4u: %u.%u: ", i, vcc->vpi, vcc->vci);
- tct = (unsigned long) (card->tct_base + i * SAR_SRAM_TCT_SIZE);
- for (i = 0; i < 8; i++)
- p += sprintf(p, " %08x", read_sram(card, tct + i));
- p += sprintf(p, "\n");
- return p - page;
- }
- return 0;
- }
- /*****************************************************************************/
- /* */
- /* Interrupt handler */
- /* */
- /*****************************************************************************/
- static void
- idt77252_collect_stat(struct idt77252_dev *card)
- {
- (void) readl(SAR_REG_CDC);
- (void) readl(SAR_REG_VPEC);
- (void) readl(SAR_REG_ICC);
- }
- static irqreturn_t
- idt77252_interrupt(int irq, void *dev_id)
- {
- struct idt77252_dev *card = dev_id;
- u32 stat;
- stat = readl(SAR_REG_STAT) & 0xffff;
- if (!stat) /* no interrupt for us */
- return IRQ_NONE;
- if (test_and_set_bit(IDT77252_BIT_INTERRUPT, &card->flags)) {
- printk("%s: Re-entering irq_handler()\n", card->name);
- goto out;
- }
- writel(stat, SAR_REG_STAT); /* reset interrupt */
- if (stat & SAR_STAT_TSIF) { /* entry written to TSQ */
- INTPRINTK("%s: TSIF\n", card->name);
- card->irqstat[15]++;
- idt77252_tx(card);
- }
- if (stat & SAR_STAT_TXICP) { /* Incomplete CS-PDU has */
- INTPRINTK("%s: TXICP\n", card->name);
- card->irqstat[14]++;
- #ifdef CONFIG_ATM_IDT77252_DEBUG
- idt77252_tx_dump(card);
- #endif
- }
- if (stat & SAR_STAT_TSQF) { /* TSQ 7/8 full */
- INTPRINTK("%s: TSQF\n", card->name);
- card->irqstat[12]++;
- idt77252_tx(card);
- }
- if (stat & SAR_STAT_TMROF) { /* Timer overflow */
- INTPRINTK("%s: TMROF\n", card->name);
- card->irqstat[11]++;
- idt77252_collect_stat(card);
- }
- if (stat & SAR_STAT_EPDU) { /* Got complete CS-PDU */
- INTPRINTK("%s: EPDU\n", card->name);
- card->irqstat[5]++;
- idt77252_rx(card);
- }
- if (stat & SAR_STAT_RSQAF) { /* RSQ is 7/8 full */
- INTPRINTK("%s: RSQAF\n", card->name);
- card->irqstat[1]++;
- idt77252_rx(card);
- }
- if (stat & SAR_STAT_RSQF) { /* RSQ is full */
- INTPRINTK("%s: RSQF\n", card->name);
- card->irqstat[6]++;
- idt77252_rx(card);
- }
- if (stat & SAR_STAT_RAWCF) { /* Raw cell received */
- INTPRINTK("%s: RAWCF\n", card->name);
- card->irqstat[4]++;
- idt77252_rx_raw(card);
- }
- if (stat & SAR_STAT_PHYI) { /* PHY device interrupt */
- INTPRINTK("%s: PHYI", card->name);
- card->irqstat[10]++;
- if (card->atmdev->phy && card->atmdev->phy->interrupt)
- card->atmdev->phy->interrupt(card->atmdev);
- }
- if (stat & (SAR_STAT_FBQ0A | SAR_STAT_FBQ1A |
- SAR_STAT_FBQ2A | SAR_STAT_FBQ3A)) {
- writel(readl(SAR_REG_CFG) & ~(SAR_CFG_FBIE), SAR_REG_CFG);
- INTPRINTK("%s: FBQA: %04x\n", card->name, stat);
- if (stat & SAR_STAT_FBQ0A)
- card->irqstat[2]++;
- if (stat & SAR_STAT_FBQ1A)
- card->irqstat[3]++;
- if (stat & SAR_STAT_FBQ2A)
- card->irqstat[7]++;
- if (stat & SAR_STAT_FBQ3A)
- card->irqstat[8]++;
- schedule_work(&card->tqueue);
- }
- out:
- clear_bit(IDT77252_BIT_INTERRUPT, &card->flags);
- return IRQ_HANDLED;
- }
- static void
- idt77252_softint(struct work_struct *work)
- {
- struct idt77252_dev *card =
- container_of(work, struct idt77252_dev, tqueue);
- u32 stat;
- int done;
- for (done = 1; ; done = 1) {
- stat = readl(SAR_REG_STAT) >> 16;
- if ((stat & 0x0f) < SAR_FBQ0_HIGH) {
- add_rx_skb(card, 0, SAR_FB_SIZE_0, 32);
- done = 0;
- }
- stat >>= 4;
- if ((stat & 0x0f) < SAR_FBQ1_HIGH) {
- add_rx_skb(card, 1, SAR_FB_SIZE_1, 32);
- done = 0;
- }
- stat >>= 4;
- if ((stat & 0x0f) < SAR_FBQ2_HIGH) {
- add_rx_skb(card, 2, SAR_FB_SIZE_2, 32);
- done = 0;
- }
- stat >>= 4;
- if ((stat & 0x0f) < SAR_FBQ3_HIGH) {
- add_rx_skb(card, 3, SAR_FB_SIZE_3, 32);
- done = 0;
- }
- if (done)
- break;
- }
- writel(readl(SAR_REG_CFG) | SAR_CFG_FBIE, SAR_REG_CFG);
- }
- static int
- open_card_oam(struct idt77252_dev *card)
- {
- unsigned long flags;
- unsigned long addr;
- struct vc_map *vc;
- int vpi, vci;
- int index;
- u32 rcte;
- for (vpi = 0; vpi < (1 << card->vpibits); vpi++) {
- for (vci = 3; vci < 5; vci++) {
- index = VPCI2VC(card, vpi, vci);
- vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
- if (!vc) {
- printk("%s: can't alloc vc\n", card->name);
- return -ENOMEM;
- }
- vc->index = index;
- card->vcs[index] = vc;
- flush_rx_pool(card, &vc->rcv.rx_pool);
- rcte = SAR_RCTE_CONNECTOPEN |
- SAR_RCTE_RAWCELLINTEN |
- SAR_RCTE_RCQ |
- SAR_RCTE_FBP_1;
- addr = card->rct_base + (vc->index << 2);
- write_sram(card, addr, rcte);
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel(SAR_CMD_OPEN_CONNECTION | (addr << 2),
- SAR_REG_CMD);
- waitfor_idle(card);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- }
- }
- return 0;
- }
- static void
- close_card_oam(struct idt77252_dev *card)
- {
- unsigned long flags;
- unsigned long addr;
- struct vc_map *vc;
- int vpi, vci;
- int index;
- for (vpi = 0; vpi < (1 << card->vpibits); vpi++) {
- for (vci = 3; vci < 5; vci++) {
- index = VPCI2VC(card, vpi, vci);
- vc = card->vcs[index];
- addr = card->rct_base + vc->index * SAR_SRAM_RCT_SIZE;
- spin_lock_irqsave(&card->cmd_lock, flags);
- writel(SAR_CMD_CLOSE_CONNECTION | (addr << 2),
- SAR_REG_CMD);
- waitfor_idle(card);
- spin_unlock_irqrestore(&card->cmd_lock, flags);
- if (skb_queue_len(&vc->rcv.rx_pool.queue) != 0) {
- DPRINTK("%s: closing a VC "
- "with pending rx buffers.\n",
- card->name);
- recycle_rx_pool_skb(card, &vc->rcv.rx_pool);
- }
- }
- }
- }
- static int
- open_card_ubr0(struct idt77252_dev *card)
- {
- struct vc_map *vc;
- vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
- if (!vc) {
- printk("%s: can't alloc vc\n", card->name);
- return -ENOMEM;
- }
- card->vcs[0] = vc;
- vc->class = SCHED_UBR0;
- vc->scq = alloc_scq(card, vc->class);
- if (!vc->scq) {
- printk("%s: can't get SCQ.\n", card->name);
- return -ENOMEM;
- }
- card->scd2vc[0] = vc;
- vc->scd_index = 0;
- vc->scq->scd = card->scd_base;
- fill_scd(card, vc->scq, vc->class);
- write_sram(card, card->tct_base + 0, TCT_UBR | card->scd_base);
- write_sram(card, card->tct_base + 1, 0);
- write_sram(card, card->tct_base + 2, 0);
- write_sram(card, card->tct_base + 3, 0);
- write_sram(card, card->tct_base + 4, 0);
- write_sram(card, card->tct_base + 5, 0);
- write_sram(card, card->tct_base + 6, 0);
- write_sram(card, card->tct_base + 7, TCT_FLAG_UBR);
- clear_bit(VCF_IDLE, &vc->flags);
- writel(TCMDQ_START | 0, SAR_REG_TCMDQ);
- return 0;
- }
- static int
- idt77252_dev_open(struct idt77252_dev *card)
- {
- u32 conf;
- if (!test_bit(IDT77252_BIT_INIT, &card->flags)) {
- printk("%s: SAR not yet initialized.\n", card->name);
- return -1;
- }
- conf = SAR_CFG_RXPTH| /* enable receive path */
- SAR_RX_DELAY | /* interrupt on complete PDU */
- SAR_CFG_RAWIE | /* interrupt enable on raw cells */
- SAR_CFG_RQFIE | /* interrupt on RSQ almost full */
- SAR_CFG_TMOIE | /* interrupt on timer overflow */
- SAR_CFG_FBIE | /* interrupt on low free buffers */
- SAR_CFG_TXEN | /* transmit operation enable */
- SAR_CFG_TXINT | /* interrupt on transmit status */
- SAR_CFG_TXUIE | /* interrupt on transmit underrun */
- SAR_CFG_TXSFI | /* interrupt on TSQ almost full */
- SAR_CFG_PHYIE /* enable PHY interrupts */
- ;
- #ifdef CONFIG_ATM_IDT77252_RCV_ALL
- /* Test RAW cell receive. */
- conf |= SAR_CFG_VPECA;
- #endif
- writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG);
- if (open_card_oam(card)) {
- printk("%s: Error initializing OAM.\n", card->name);
- return -1;
- }
- if (open_card_ubr0(card)) {
- printk("%s: Error initializing UBR0.\n", card->name);
- return -1;
- }
- IPRINTK("%s: opened IDT77252 ABR SAR.\n", card->name);
- return 0;
- }
- static void idt77252_dev_close(struct atm_dev *dev)
- {
- struct idt77252_dev *card = dev->dev_data;
- u32 conf;
- close_card_oam(card);
- conf = SAR_CFG_RXPTH | /* enable receive path */
- SAR_RX_DELAY | /* interrupt on complete PDU */
- SAR_CFG_RAWIE | /* interrupt enable on raw cells */
- SAR_CFG_RQFIE | /* interrupt on RSQ almost full */
- SAR_CFG_TMOIE | /* interrupt on timer overflow */
- SAR_CFG_FBIE | /* interrupt on low free buffers */
- SAR_CFG_TXEN | /* transmit operation enable */
- SAR_CFG_TXINT | /* interrupt on transmit status */
- SAR_CFG_TXUIE | /* interrupt on xmit underrun */
- SAR_CFG_TXSFI /* interrupt on TSQ almost full */
- ;
- writel(readl(SAR_REG_CFG) & ~(conf), SAR_REG_CFG);
- DIPRINTK("%s: closed IDT77252 ABR SAR.\n", card->name);
- }
- /*****************************************************************************/
- /* */
- /* Initialisation and Deinitialization of IDT77252 */
- /* */
- /*****************************************************************************/
- static void
- deinit_card(struct idt77252_dev *card)
- {
- struct sk_buff *skb;
- int i, j;
- if (!test_bit(IDT77252_BIT_INIT, &card->flags)) {
- printk("%s: SAR not yet initialized.\n", card->name);
- return;
- }
- DIPRINTK("idt77252: deinitialize card %u\n", card->index);
- writel(0, SAR_REG_CFG);
- if (card->atmdev)
- atm_dev_deregister(card->atmdev);
- for (i = 0; i < 4; i++) {
- for (j = 0; j < FBQ_SIZE; j++) {
- skb = card->sbpool[i].skb[j];
- if (skb) {
- dma_unmap_single(&card->pcidev->dev,
- IDT77252_PRV_PADDR(skb),
- (skb_end_pointer(skb) -
- skb->data),
- DMA_FROM_DEVICE);
- card->sbpool[i].skb[j] = NULL;
- dev_kfree_skb(skb);
- }
- }
- }
- vfree(card->soft_tst);
- vfree(card->scd2vc);
- vfree(card->vcs);
- if (card->raw_cell_hnd) {
- dma_free_coherent(&card->pcidev->dev, 2 * sizeof(u32),
- card->raw_cell_hnd, card->raw_cell_paddr);
- }
- if (card->rsq.base) {
- DIPRINTK("%s: Release RSQ ...\n", card->name);
- deinit_rsq(card);
- }
- if (card->tsq.base) {
- DIPRINTK("%s: Release TSQ ...\n", card->name);
- deinit_tsq(card);
- }
- DIPRINTK("idt77252: Release IRQ.\n");
- free_irq(card->pcidev->irq, card);
- for (i = 0; i < 4; i++) {
- if (card->fbq[i])
- iounmap(card->fbq[i]);
- }
- if (card->membase)
- iounmap(card->membase);
- clear_bit(IDT77252_BIT_INIT, &card->flags);
- DIPRINTK("%s: Card deinitialized.\n", card->name);
- }
- static void init_sram(struct idt77252_dev *card)
- {
- int i;
- for (i = 0; i < card->sramsize; i += 4)
- write_sram(card, (i >> 2), 0);
- /* set SRAM layout for THIS card */
- if (card->sramsize == (512 * 1024)) {
- card->tct_base = SAR_SRAM_TCT_128_BASE;
- card->tct_size = (SAR_SRAM_TCT_128_TOP - card->tct_base + 1)
- / SAR_SRAM_TCT_SIZE;
- card->rct_base = SAR_SRAM_RCT_128_BASE;
- card->rct_size = (SAR_SRAM_RCT_128_TOP - card->rct_base + 1)
- / SAR_SRAM_RCT_SIZE;
- card->rt_base = SAR_SRAM_RT_128_BASE;
- card->scd_base = SAR_SRAM_SCD_128_BASE;
- card->scd_size = (SAR_SRAM_SCD_128_TOP - card->scd_base + 1)
- / SAR_SRAM_SCD_SIZE;
- card->tst[0] = SAR_SRAM_TST1_128_BASE;
- card->tst[1] = SAR_SRAM_TST2_128_BASE;
- card->tst_size = SAR_SRAM_TST1_128_TOP - card->tst[0] + 1;
- card->abrst_base = SAR_SRAM_ABRSTD_128_BASE;
- card->abrst_size = SAR_ABRSTD_SIZE_8K;
- card->fifo_base = SAR_SRAM_FIFO_128_BASE;
- card->fifo_size = SAR_RXFD_SIZE_32K;
- } else {
- card->tct_base = SAR_SRAM_TCT_32_BASE;
- card->tct_size = (SAR_SRAM_TCT_32_TOP - card->tct_base + 1)
- / SAR_SRAM_TCT_SIZE;
- card->rct_base = SAR_SRAM_RCT_32_BASE;
- card->rct_size = (SAR_SRAM_RCT_32_TOP - card->rct_base + 1)
- / SAR_SRAM_RCT_SIZE;
- card->rt_base = SAR_SRAM_RT_32_BASE;
- card->scd_base = SAR_SRAM_SCD_32_BASE;
- card->scd_size = (SAR_SRAM_SCD_32_TOP - card->scd_base + 1)
- / SAR_SRAM_SCD_SIZE;
- card->tst[0] = SAR_SRAM_TST1_32_BASE;
- card->tst[1] = SAR_SRAM_TST2_32_BASE;
- card->tst_size = (SAR_SRAM_TST1_32_TOP - card->tst[0] + 1);
- card->abrst_base = SAR_SRAM_ABRSTD_32_BASE;
- card->abrst_size = SAR_ABRSTD_SIZE_1K;
- card->fifo_base = SAR_SRAM_FIFO_32_BASE;
- card->fifo_size = SAR_RXFD_SIZE_4K;
- }
- /* Initialize TCT */
- for (i = 0; i < card->tct_size; i++) {
- write_sram(card, i * SAR_SRAM_TCT_SIZE + 0, 0);
- write_sram(card, i * SAR_SRAM_TCT_SIZE + 1, 0);
- write_sram(card, i * SAR_SRAM_TCT_SIZE + 2, 0);
- write_sram(card, i * SAR_SRAM_TCT_SIZE + 3, 0);
- write_sram(card, i * SAR_SRAM_TCT_SIZE + 4, 0);
- write_sram(card, i * SAR_SRAM_TCT_SIZE + 5, 0);
- write_sram(card, i * SAR_SRAM_TCT_SIZE + 6, 0);
- write_sram(card, i * SAR_SRAM_TCT_SIZE + 7, 0);
- }
- /* Initialize RCT */
- for (i = 0; i < card->rct_size; i++) {
- write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE,
- (u32) SAR_RCTE_RAWCELLINTEN);
- write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 1,
- (u32) 0);
- write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 2,
- (u32) 0);
- write_sram(card, card->rct_base + i * SAR_SRAM_RCT_SIZE + 3,
- (u32) 0xffffffff);
- }
- writel((SAR_FBQ0_LOW << 28) | 0x00000000 | 0x00000000 |
- (SAR_FB_SIZE_0 / 48), SAR_REG_FBQS0);
- writel((SAR_FBQ1_LOW << 28) | 0x00000000 | 0x00000000 |
- (SAR_FB_SIZE_1 / 48), SAR_REG_FBQS1);
- writel((SAR_FBQ2_LOW << 28) | 0x00000000 | 0x00000000 |
- (SAR_FB_SIZE_2 / 48), SAR_REG_FBQS2);
- writel((SAR_FBQ3_LOW << 28) | 0x00000000 | 0x00000000 |
- (SAR_FB_SIZE_3 / 48), SAR_REG_FBQS3);
- /* Initialize rate table */
- for (i = 0; i < 256; i++) {
- write_sram(card, card->rt_base + i, log_to_rate[i]);
- }
- for (i = 0; i < 128; i++) {
- unsigned int tmp;
- tmp = rate_to_log[(i << 2) + 0] << 0;
- tmp |= rate_to_log[(i << 2) + 1] << 8;
- tmp |= rate_to_log[(i << 2) + 2] << 16;
- tmp |= rate_to_log[(i << 2) + 3] << 24;
- write_sram(card, card->rt_base + 256 + i, tmp);
- }
- #if 0 /* Fill RDF and AIR tables. */
- for (i = 0; i < 128; i++) {
- unsigned int tmp;
- tmp = RDF[0][(i << 1) + 0] << 16;
- tmp |= RDF[0][(i << 1) + 1] << 0;
- write_sram(card, card->rt_base + 512 + i, tmp);
- }
- for (i = 0; i < 128; i++) {
- unsigned int tmp;
- tmp = AIR[0][(i << 1) + 0] << 16;
- tmp |= AIR[0][(i << 1) + 1] << 0;
- write_sram(card, card->rt_base + 640 + i, tmp);
- }
- #endif
- IPRINTK("%s: initialize rate table ...\n", card->name);
- writel(card->rt_base << 2, SAR_REG_RTBL);
- /* Initialize TSTs */
- IPRINTK("%s: initialize TST ...\n", card->name);
- card->tst_free = card->tst_size - 2; /* last two are jumps */
- for (i = card->tst[0]; i < card->tst[0] + card->tst_size - 2; i++)
- write_sram(card, i, TSTE_OPC_VAR);
- write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2));
- idt77252_sram_write_errors = 1;
- write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2));
- idt77252_sram_write_errors = 0;
- for (i = card->tst[1]; i < card->tst[1] + card->tst_size - 2; i++)
- write_sram(card, i, TSTE_OPC_VAR);
- write_sram(card, i++, TSTE_OPC_JMP | (card->tst[1] << 2));
- idt77252_sram_write_errors = 1;
- write_sram(card, i++, TSTE_OPC_JMP | (card->tst[0] << 2));
- idt77252_sram_write_errors = 0;
- card->tst_index = 0;
- writel(card->tst[0] << 2, SAR_REG_TSTB);
- /* Initialize ABRSTD and Receive FIFO */
- IPRINTK("%s: initialize ABRSTD ...\n", card->name);
- writel(card->abrst_size | (card->abrst_base << 2),
- SAR_REG_ABRSTD);
- IPRINTK("%s: initialize receive fifo ...\n", card->name);
- writel(card->fifo_size | (card->fifo_base << 2),
- SAR_REG_RXFD);
- IPRINTK("%s: SRAM initialization complete.\n", card->name);
- }
- static int init_card(struct atm_dev *dev)
- {
- struct idt77252_dev *card = dev->dev_data;
- struct pci_dev *pcidev = card->pcidev;
- unsigned long tmpl, modl;
- unsigned int linkrate, rsvdcr;
- unsigned int tst_entries;
- struct net_device *tmp;
- char tname[10];
- u32 size;
- u_char pci_byte;
- u32 conf;
- int i, k;
- if (test_bit(IDT77252_BIT_INIT, &card->flags)) {
- printk("Error: SAR already initialized.\n");
- return -1;
- }
- /*****************************************************************/
- /* P C I C O N F I G U R A T I O N */
- /*****************************************************************/
- /* Set PCI Retry-Timeout and TRDY timeout */
- IPRINTK("%s: Checking PCI retries.\n", card->name);
- if (pci_read_config_byte(pcidev, 0x40, &pci_byte) != 0) {
- printk("%s: can't read PCI retry timeout.\n", card->name);
- deinit_card(card);
- return -1;
- }
- if (pci_byte != 0) {
- IPRINTK("%s: PCI retry timeout: %d, set to 0.\n",
- card->name, pci_byte);
- if (pci_write_config_byte(pcidev, 0x40, 0) != 0) {
- printk("%s: can't set PCI retry timeout.\n",
- card->name);
- deinit_card(card);
- return -1;
- }
- }
- IPRINTK("%s: Checking PCI TRDY.\n", card->name);
- if (pci_read_config_byte(pcidev, 0x41, &pci_byte) != 0) {
- printk("%s: can't read PCI TRDY timeout.\n", card->name);
- deinit_card(card);
- return -1;
- }
- if (pci_byte != 0) {
- IPRINTK("%s: PCI TRDY timeout: %d, set to 0.\n",
- card->name, pci_byte);
- if (pci_write_config_byte(pcidev, 0x41, 0) != 0) {
- printk("%s: can't set PCI TRDY timeout.\n", card->name);
- deinit_card(card);
- return -1;
- }
- }
- /* Reset Timer register */
- if (readl(SAR_REG_STAT) & SAR_STAT_TMROF) {
- printk("%s: resetting timer overflow.\n", card->name);
- writel(SAR_STAT_TMROF, SAR_REG_STAT);
- }
- IPRINTK("%s: Request IRQ ... ", card->name);
- if (request_irq(pcidev->irq, idt77252_interrupt, IRQF_SHARED,
- card->name, card) != 0) {
- printk("%s: can't allocate IRQ.\n", card->name);
- deinit_card(card);
- return -1;
- }
- IPRINTK("got %d.\n", pcidev->irq);
- /*****************************************************************/
- /* C H E C K A N D I N I T S R A M */
- /*****************************************************************/
- IPRINTK("%s: Initializing SRAM\n", card->name);
- /* preset size of connecton table, so that init_sram() knows about it */
- conf = SAR_CFG_TX_FIFO_SIZE_9 | /* Use maximum fifo size */
- SAR_CFG_RXSTQ_SIZE_8k | /* Receive Status Queue is 8k */
- SAR_CFG_IDLE_CLP | /* Set CLP on idle cells */
- #ifndef ATM_IDT77252_SEND_IDLE
- SAR_CFG_NO_IDLE | /* Do not send idle cells */
- #endif
- 0;
- if (card->sramsize == (512 * 1024))
- conf |= SAR_CFG_CNTBL_1k;
- else
- conf |= SAR_CFG_CNTBL_512;
- switch (vpibits) {
- case 0:
- conf |= SAR_CFG_VPVCS_0;
- break;
- default:
- case 1:
- conf |= SAR_CFG_VPVCS_1;
- break;
- case 2:
- conf |= SAR_CFG_VPVCS_2;
- break;
- case 8:
- conf |= SAR_CFG_VPVCS_8;
- break;
- }
- writel(readl(SAR_REG_CFG) | conf, SAR_REG_CFG);
- init_sram(card);
- /********************************************************************/
- /* 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 */
- /********************************************************************/
- /* Initialize TSQ */
- if (0 != init_tsq(card)) {
- deinit_card(card);
- return -1;
- }
- /* Initialize RSQ */
- if (0 != init_rsq(card)) {
- deinit_card(card);
- return -1;
- }
- card->vpibits = vpibits;
- if (card->sramsize == (512 * 1024)) {
- card->vcibits = 10 - card->vpibits;
- } else {
- card->vcibits = 9 - card->vpibits;
- }
- card->vcimask = 0;
- for (k = 0, i = 1; k < card->vcibits; k++) {
- card->vcimask |= i;
- i <<= 1;
- }
- IPRINTK("%s: Setting VPI/VCI mask to zero.\n", card->name);
- writel(0, SAR_REG_VPM);
- /* Little Endian Order */
- writel(0, SAR_REG_GP);
- /* Initialize RAW Cell Handle Register */
- card->raw_cell_hnd = dma_zalloc_coherent(&card->pcidev->dev,
- 2 * sizeof(u32),
- &card->raw_cell_paddr,
- GFP_KERNEL);
- if (!card->raw_cell_hnd) {
- printk("%s: memory allocation failure.\n", card->name);
- deinit_card(card);
- return -1;
- }
- writel(card->raw_cell_paddr, SAR_REG_RAWHND);
- IPRINTK("%s: raw cell handle is at 0x%p.\n", card->name,
- card->raw_cell_hnd);
- size = sizeof(struct vc_map *) * card->tct_size;
- IPRINTK("%s: allocate %d byte for VC map.\n", card->name, size);
- card->vcs = vzalloc(size);
- if (!card->vcs) {
- printk("%s: memory allocation failure.\n", card->name);
- deinit_card(card);
- return -1;
- }
- size = sizeof(struct vc_map *) * card->scd_size;
- IPRINTK("%s: allocate %d byte for SCD to VC mapping.\n",
- card->name, size);
- card->scd2vc = vzalloc(size);
- if (!card->scd2vc) {
- printk("%s: memory allocation failure.\n", card->name);
- deinit_card(card);
- return -1;
- }
- size = sizeof(struct tst_info) * (card->tst_size - 2);
- IPRINTK("%s: allocate %d byte for TST to VC mapping.\n",
- card->name, size);
- card->soft_tst = vmalloc(size);
- if (!card->soft_tst) {
- printk("%s: memory allocation failure.\n", card->name);
- deinit_card(card);
- return -1;
- }
- for (i = 0; i < card->tst_size - 2; i++) {
- card->soft_tst[i].tste = TSTE_OPC_VAR;
- card->soft_tst[i].vc = NULL;
- }
- if (dev->phy == NULL) {
- printk("%s: No LT device defined.\n", card->name);
- deinit_card(card);
- return -1;
- }
- if (dev->phy->ioctl == NULL) {
- printk("%s: LT had no IOCTL function defined.\n", card->name);
- deinit_card(card);
- return -1;
- }
- #ifdef CONFIG_ATM_IDT77252_USE_SUNI
- /*
- * this is a jhs hack to get around special functionality in the
- * phy driver for the atecom hardware; the functionality doesn't
- * exist in the linux atm suni driver
- *
- * it isn't the right way to do things, but as the guy from NIST
- * said, talking about their measurement of the fine structure
- * constant, "it's good enough for government work."
- */
- linkrate = 149760000;
- #endif
- card->link_pcr = (linkrate / 8 / 53);
- printk("%s: Linkrate on ATM line : %u bit/s, %u cell/s.\n",
- card->name, linkrate, card->link_pcr);
- #ifdef ATM_IDT77252_SEND_IDLE
- card->utopia_pcr = card->link_pcr;
- #else
- card->utopia_pcr = (160000000 / 8 / 54);
- #endif
- rsvdcr = 0;
- if (card->utopia_pcr > card->link_pcr)
- rsvdcr = card->utopia_pcr - card->link_pcr;
- tmpl = (unsigned long) rsvdcr * ((unsigned long) card->tst_size - 2);
- modl = tmpl % (unsigned long)card->utopia_pcr;
- tst_entries = (int) (tmpl / (unsigned long)card->utopia_pcr);
- if (modl)
- tst_entries++;
- card->tst_free -= tst_entries;
- fill_tst(card, NULL, tst_entries, TSTE_OPC_NULL);
- #ifdef HAVE_EEPROM
- idt77252_eeprom_init(card);
- printk("%s: EEPROM: %02x:", card->name,
- idt77252_eeprom_read_status(card));
- for (i = 0; i < 0x80; i++) {
- printk(" %02x",
- idt77252_eeprom_read_byte(card, i)
- );
- }
- printk("\n");
- #endif /* HAVE_EEPROM */
- /*
- * XXX: <hack>
- */
- sprintf(tname, "eth%d", card->index);
- tmp = dev_get_by_name(&init_net, tname); /* jhs: was "tmp = dev_get(tname);" */
- if (tmp) {
- memcpy(card->atmdev->esi, tmp->dev_addr, 6);
- dev_put(tmp);
- printk("%s: ESI %pM\n", card->name, card->atmdev->esi);
- }
- /*
- * XXX: </hack>
- */
- /* Set Maximum Deficit Count for now. */
- writel(0xffff, SAR_REG_MDFCT);
- set_bit(IDT77252_BIT_INIT, &card->flags);
- XPRINTK("%s: IDT77252 ABR SAR initialization complete.\n", card->name);
- return 0;
- }
- /*****************************************************************************/
- /* */
- /* Probing of IDT77252 ABR SAR */
- /* */
- /*****************************************************************************/
- static int idt77252_preset(struct idt77252_dev *card)
- {
- u16 pci_command;
- /*****************************************************************/
- /* P C I C O N F I G U R A T I O N */
- /*****************************************************************/
- XPRINTK("%s: Enable PCI master and memory access for SAR.\n",
- card->name);
- if (pci_read_config_word(card->pcidev, PCI_COMMAND, &pci_command)) {
- printk("%s: can't read PCI_COMMAND.\n", card->name);
- deinit_card(card);
- return -1;
- }
- if (!(pci_command & PCI_COMMAND_IO)) {
- printk("%s: PCI_COMMAND: %04x (???)\n",
- card->name, pci_command);
- deinit_card(card);
- return (-1);
- }
- pci_command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
- if (pci_write_config_word(card->pcidev, PCI_COMMAND, pci_command)) {
- printk("%s: can't write PCI_COMMAND.\n", card->name);
- deinit_card(card);
- return -1;
- }
- /*****************************************************************/
- /* G E N E R I C R E S E T */
- /*****************************************************************/
- /* Software reset */
- writel(SAR_CFG_SWRST, SAR_REG_CFG);
- mdelay(1);
- writel(0, SAR_REG_CFG);
- IPRINTK("%s: Software resetted.\n", card->name);
- return 0;
- }
- static unsigned long probe_sram(struct idt77252_dev *card)
- {
- u32 data, addr;
- writel(0, SAR_REG_DR0);
- writel(SAR_CMD_WRITE_SRAM | (0 << 2), SAR_REG_CMD);
- for (addr = 0x4000; addr < 0x80000; addr += 0x4000) {
- writel(ATM_POISON, SAR_REG_DR0);
- writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD);
- writel(SAR_CMD_READ_SRAM | (0 << 2), SAR_REG_CMD);
- data = readl(SAR_REG_DR0);
- if (data != 0)
- break;
- }
- return addr * sizeof(u32);
- }
- static int idt77252_init_one(struct pci_dev *pcidev,
- const struct pci_device_id *id)
- {
- static struct idt77252_dev **last = &idt77252_chain;
- static int index = 0;
- unsigned long membase, srambase;
- struct idt77252_dev *card;
- struct atm_dev *dev;
- int i, err;
- if ((err = pci_enable_device(pcidev))) {
- printk("idt77252: can't enable PCI device at %s\n", pci_name(pcidev));
- return err;
- }
- if ((err = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)))) {
- printk("idt77252: can't enable DMA for PCI device at %s\n", pci_name(pcidev));
- return err;
- }
- card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
- if (!card) {
- printk("idt77252-%d: can't allocate private data\n", index);
- err = -ENOMEM;
- goto err_out_disable_pdev;
- }
- card->revision = pcidev->revision;
- card->index = index;
- card->pcidev = pcidev;
- sprintf(card->name, "idt77252-%d", card->index);
- INIT_WORK(&card->tqueue, idt77252_softint);
- membase = pci_resource_start(pcidev, 1);
- srambase = pci_resource_start(pcidev, 2);
- mutex_init(&card->mutex);
- spin_lock_init(&card->cmd_lock);
- spin_lock_init(&card->tst_lock);
- init_timer(&card->tst_timer);
- card->tst_timer.data = (unsigned long)card;
- card->tst_timer.function = tst_timer;
- /* Do the I/O remapping... */
- card->membase = ioremap(membase, 1024);
- if (!card->membase) {
- printk("%s: can't ioremap() membase\n", card->name);
- err = -EIO;
- goto err_out_free_card;
- }
- if (idt77252_preset(card)) {
- printk("%s: preset failed\n", card->name);
- err = -EIO;
- goto err_out_iounmap;
- }
- dev = atm_dev_register("idt77252", &pcidev->dev, &idt77252_ops, -1,
- NULL);
- if (!dev) {
- printk("%s: can't register atm device\n", card->name);
- err = -EIO;
- goto err_out_iounmap;
- }
- dev->dev_data = card;
- card->atmdev = dev;
- #ifdef CONFIG_ATM_IDT77252_USE_SUNI
- suni_init(dev);
- if (!dev->phy) {
- printk("%s: can't init SUNI\n", card->name);
- err = -EIO;
- goto err_out_deinit_card;
- }
- #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
- card->sramsize = probe_sram(card);
- for (i = 0; i < 4; i++) {
- card->fbq[i] = ioremap(srambase | 0x200000 | (i << 18), 4);
- if (!card->fbq[i]) {
- printk("%s: can't ioremap() FBQ%d\n", card->name, i);
- err = -EIO;
- goto err_out_deinit_card;
- }
- }
- printk("%s: ABR SAR (Rev %c): MEM %08lx SRAM %08lx [%u KB]\n",
- card->name, ((card->revision > 1) && (card->revision < 25)) ?
- 'A' + card->revision - 1 : '?', membase, srambase,
- card->sramsize / 1024);
- if (init_card(dev)) {
- printk("%s: init_card failed\n", card->name);
- err = -EIO;
- goto err_out_deinit_card;
- }
- dev->ci_range.vpi_bits = card->vpibits;
- dev->ci_range.vci_bits = card->vcibits;
- dev->link_rate = card->link_pcr;
- if (dev->phy->start)
- dev->phy->start(dev);
- if (idt77252_dev_open(card)) {
- printk("%s: dev_open failed\n", card->name);
- err = -EIO;
- goto err_out_stop;
- }
- *last = card;
- last = &card->next;
- index++;
- return 0;
- err_out_stop:
- if (dev->phy->stop)
- dev->phy->stop(dev);
- err_out_deinit_card:
- deinit_card(card);
- err_out_iounmap:
- iounmap(card->membase);
- err_out_free_card:
- kfree(card);
- err_out_disable_pdev:
- pci_disable_device(pcidev);
- return err;
- }
- static struct pci_device_id idt77252_pci_tbl[] =
- {
- { PCI_VDEVICE(IDT, PCI_DEVICE_ID_IDT_IDT77252), 0 },
- { 0, }
- };
- MODULE_DEVICE_TABLE(pci, idt77252_pci_tbl);
- static struct pci_driver idt77252_driver = {
- .name = "idt77252",
- .id_table = idt77252_pci_tbl,
- .probe = idt77252_init_one,
- };
- static int __init idt77252_init(void)
- {
- struct sk_buff *skb;
- printk("%s: at %p\n", __func__, idt77252_init);
- if (sizeof(skb->cb) < sizeof(struct atm_skb_data) +
- sizeof(struct idt77252_skb_prv)) {
- printk(KERN_ERR "%s: skb->cb is too small (%lu < %lu)\n",
- __func__, (unsigned long) sizeof(skb->cb),
- (unsigned long) sizeof(struct atm_skb_data) +
- sizeof(struct idt77252_skb_prv));
- return -EIO;
- }
- return pci_register_driver(&idt77252_driver);
- }
- static void __exit idt77252_exit(void)
- {
- struct idt77252_dev *card;
- struct atm_dev *dev;
- pci_unregister_driver(&idt77252_driver);
- while (idt77252_chain) {
- card = idt77252_chain;
- dev = card->atmdev;
- idt77252_chain = card->next;
- if (dev->phy->stop)
- dev->phy->stop(dev);
- deinit_card(card);
- pci_disable_device(card->pcidev);
- kfree(card);
- }
- DIPRINTK("idt77252: finished cleanup-module().\n");
- }
- module_init(idt77252_init);
- module_exit(idt77252_exit);
- MODULE_LICENSE("GPL");
- module_param(vpibits, uint, 0);
- MODULE_PARM_DESC(vpibits, "number of VPI bits supported (0, 1, or 2)");
- #ifdef CONFIG_ATM_IDT77252_DEBUG
- module_param(debug, ulong, 0644);
- MODULE_PARM_DESC(debug, "debug bitmap, see drivers/atm/idt77252.h");
- #endif
- MODULE_AUTHOR("Eddie C. Dost <ecd@atecom.com>");
- MODULE_DESCRIPTION("IDT77252 ABR SAR Driver");
|