iphase.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305
  1. /******************************************************************************
  2. iphase.c: Device driver for Interphase ATM PCI adapter cards
  3. Author: Peter Wang <pwang@iphase.com>
  4. Some fixes: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  5. Interphase Corporation <www.iphase.com>
  6. Version: 1.0
  7. *******************************************************************************
  8. This software may be used and distributed according to the terms
  9. of the GNU General Public License (GPL), incorporated herein by reference.
  10. Drivers based on this skeleton fall under the GPL and must retain
  11. the authorship (implicit copyright) notice.
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. General Public License for more details.
  16. Modified from an incomplete driver for Interphase 5575 1KVC 1M card which
  17. was originally written by Monalisa Agrawal at UNH. Now this driver
  18. supports a variety of varients of Interphase ATM PCI (i)Chip adapter
  19. card family (See www.iphase.com/products/ClassSheet.cfm?ClassID=ATM)
  20. in terms of PHY type, the size of control memory and the size of
  21. packet memory. The followings are the change log and history:
  22. Bugfix the Mona's UBR driver.
  23. Modify the basic memory allocation and dma logic.
  24. Port the driver to the latest kernel from 2.0.46.
  25. Complete the ABR logic of the driver, and added the ABR work-
  26. around for the hardware anormalies.
  27. Add the CBR support.
  28. Add the flow control logic to the driver to allow rate-limit VC.
  29. Add 4K VC support to the board with 512K control memory.
  30. Add the support of all the variants of the Interphase ATM PCI
  31. (i)Chip adapter cards including x575 (155M OC3 and UTP155), x525
  32. (25M UTP25) and x531 (DS3 and E3).
  33. Add SMP support.
  34. Support and updates available at: ftp://ftp.iphase.com/pub/atm
  35. *******************************************************************************/
  36. #include <linux/module.h>
  37. #include <linux/kernel.h>
  38. #include <linux/mm.h>
  39. #include <linux/pci.h>
  40. #include <linux/errno.h>
  41. #include <linux/atm.h>
  42. #include <linux/atmdev.h>
  43. #include <linux/sonet.h>
  44. #include <linux/skbuff.h>
  45. #include <linux/time.h>
  46. #include <linux/delay.h>
  47. #include <linux/uio.h>
  48. #include <linux/init.h>
  49. #include <linux/interrupt.h>
  50. #include <linux/wait.h>
  51. #include <linux/slab.h>
  52. #include <asm/io.h>
  53. #include <linux/atomic.h>
  54. #include <asm/uaccess.h>
  55. #include <asm/string.h>
  56. #include <asm/byteorder.h>
  57. #include <linux/vmalloc.h>
  58. #include <linux/jiffies.h>
  59. #include "iphase.h"
  60. #include "suni.h"
  61. #define swap_byte_order(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8))
  62. #define PRIV(dev) ((struct suni_priv *) dev->phy_data)
  63. static unsigned char ia_phy_get(struct atm_dev *dev, unsigned long addr);
  64. static void desc_dbg(IADEV *iadev);
  65. static IADEV *ia_dev[8];
  66. static struct atm_dev *_ia_dev[8];
  67. static int iadev_count;
  68. static void ia_led_timer(unsigned long arg);
  69. static DEFINE_TIMER(ia_timer, ia_led_timer, 0, 0);
  70. static int IA_TX_BUF = DFL_TX_BUFFERS, IA_TX_BUF_SZ = DFL_TX_BUF_SZ;
  71. static int IA_RX_BUF = DFL_RX_BUFFERS, IA_RX_BUF_SZ = DFL_RX_BUF_SZ;
  72. static uint IADebugFlag = /* IF_IADBG_ERR | IF_IADBG_CBR| IF_IADBG_INIT_ADAPTER
  73. |IF_IADBG_ABR | IF_IADBG_EVENT*/ 0;
  74. module_param(IA_TX_BUF, int, 0);
  75. module_param(IA_TX_BUF_SZ, int, 0);
  76. module_param(IA_RX_BUF, int, 0);
  77. module_param(IA_RX_BUF_SZ, int, 0);
  78. module_param(IADebugFlag, uint, 0644);
  79. MODULE_LICENSE("GPL");
  80. /**************************** IA_LIB **********************************/
  81. static void ia_init_rtn_q (IARTN_Q *que)
  82. {
  83. que->next = NULL;
  84. que->tail = NULL;
  85. }
  86. static void ia_enque_head_rtn_q (IARTN_Q *que, IARTN_Q * data)
  87. {
  88. data->next = NULL;
  89. if (que->next == NULL)
  90. que->next = que->tail = data;
  91. else {
  92. data->next = que->next;
  93. que->next = data;
  94. }
  95. return;
  96. }
  97. static int ia_enque_rtn_q (IARTN_Q *que, struct desc_tbl_t data) {
  98. IARTN_Q *entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  99. if (!entry)
  100. return -ENOMEM;
  101. entry->data = data;
  102. entry->next = NULL;
  103. if (que->next == NULL)
  104. que->next = que->tail = entry;
  105. else {
  106. que->tail->next = entry;
  107. que->tail = que->tail->next;
  108. }
  109. return 1;
  110. }
  111. static IARTN_Q * ia_deque_rtn_q (IARTN_Q *que) {
  112. IARTN_Q *tmpdata;
  113. if (que->next == NULL)
  114. return NULL;
  115. tmpdata = que->next;
  116. if ( que->next == que->tail)
  117. que->next = que->tail = NULL;
  118. else
  119. que->next = que->next->next;
  120. return tmpdata;
  121. }
  122. static void ia_hack_tcq(IADEV *dev) {
  123. u_short desc1;
  124. u_short tcq_wr;
  125. struct ia_vcc *iavcc_r = NULL;
  126. tcq_wr = readl(dev->seg_reg+TCQ_WR_PTR) & 0xffff;
  127. while (dev->host_tcq_wr != tcq_wr) {
  128. desc1 = *(u_short *)(dev->seg_ram + dev->host_tcq_wr);
  129. if (!desc1) ;
  130. else if (!dev->desc_tbl[desc1 -1].timestamp) {
  131. IF_ABR(printk(" Desc %d is reset at %ld\n", desc1 -1, jiffies);)
  132. *(u_short *) (dev->seg_ram + dev->host_tcq_wr) = 0;
  133. }
  134. else if (dev->desc_tbl[desc1 -1].timestamp) {
  135. if (!(iavcc_r = dev->desc_tbl[desc1 -1].iavcc)) {
  136. printk("IA: Fatal err in get_desc\n");
  137. continue;
  138. }
  139. iavcc_r->vc_desc_cnt--;
  140. dev->desc_tbl[desc1 -1].timestamp = 0;
  141. IF_EVENT(printk("ia_hack: return_q skb = 0x%p desc = %d\n",
  142. dev->desc_tbl[desc1 -1].txskb, desc1);)
  143. if (iavcc_r->pcr < dev->rate_limit) {
  144. IA_SKB_STATE (dev->desc_tbl[desc1-1].txskb) |= IA_TX_DONE;
  145. if (ia_enque_rtn_q(&dev->tx_return_q, dev->desc_tbl[desc1 -1]) < 0)
  146. printk("ia_hack_tcq: No memory available\n");
  147. }
  148. dev->desc_tbl[desc1 -1].iavcc = NULL;
  149. dev->desc_tbl[desc1 -1].txskb = NULL;
  150. }
  151. dev->host_tcq_wr += 2;
  152. if (dev->host_tcq_wr > dev->ffL.tcq_ed)
  153. dev->host_tcq_wr = dev->ffL.tcq_st;
  154. }
  155. } /* ia_hack_tcq */
  156. static u16 get_desc (IADEV *dev, struct ia_vcc *iavcc) {
  157. u_short desc_num, i;
  158. struct sk_buff *skb;
  159. struct ia_vcc *iavcc_r = NULL;
  160. unsigned long delta;
  161. static unsigned long timer = 0;
  162. int ltimeout;
  163. ia_hack_tcq (dev);
  164. if((time_after(jiffies,timer+50)) || ((dev->ffL.tcq_rd==dev->host_tcq_wr))) {
  165. timer = jiffies;
  166. i=0;
  167. while (i < dev->num_tx_desc) {
  168. if (!dev->desc_tbl[i].timestamp) {
  169. i++;
  170. continue;
  171. }
  172. ltimeout = dev->desc_tbl[i].iavcc->ltimeout;
  173. delta = jiffies - dev->desc_tbl[i].timestamp;
  174. if (delta >= ltimeout) {
  175. IF_ABR(printk("RECOVER run!! desc_tbl %d = %d delta = %ld, time = %ld\n", i,dev->desc_tbl[i].timestamp, delta, jiffies);)
  176. if (dev->ffL.tcq_rd == dev->ffL.tcq_st)
  177. dev->ffL.tcq_rd = dev->ffL.tcq_ed;
  178. else
  179. dev->ffL.tcq_rd -= 2;
  180. *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd) = i+1;
  181. if (!(skb = dev->desc_tbl[i].txskb) ||
  182. !(iavcc_r = dev->desc_tbl[i].iavcc))
  183. printk("Fatal err, desc table vcc or skb is NULL\n");
  184. else
  185. iavcc_r->vc_desc_cnt--;
  186. dev->desc_tbl[i].timestamp = 0;
  187. dev->desc_tbl[i].iavcc = NULL;
  188. dev->desc_tbl[i].txskb = NULL;
  189. }
  190. i++;
  191. } /* while */
  192. }
  193. if (dev->ffL.tcq_rd == dev->host_tcq_wr)
  194. return 0xFFFF;
  195. /* Get the next available descriptor number from TCQ */
  196. desc_num = *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd);
  197. while (!desc_num || (dev->desc_tbl[desc_num -1]).timestamp) {
  198. dev->ffL.tcq_rd += 2;
  199. if (dev->ffL.tcq_rd > dev->ffL.tcq_ed)
  200. dev->ffL.tcq_rd = dev->ffL.tcq_st;
  201. if (dev->ffL.tcq_rd == dev->host_tcq_wr)
  202. return 0xFFFF;
  203. desc_num = *(u_short *)(dev->seg_ram + dev->ffL.tcq_rd);
  204. }
  205. /* get system time */
  206. dev->desc_tbl[desc_num -1].timestamp = jiffies;
  207. return desc_num;
  208. }
  209. static void clear_lockup (struct atm_vcc *vcc, IADEV *dev) {
  210. u_char foundLockUp;
  211. vcstatus_t *vcstatus;
  212. u_short *shd_tbl;
  213. u_short tempCellSlot, tempFract;
  214. struct main_vc *abr_vc = (struct main_vc *)dev->MAIN_VC_TABLE_ADDR;
  215. struct ext_vc *eabr_vc = (struct ext_vc *)dev->EXT_VC_TABLE_ADDR;
  216. u_int i;
  217. if (vcc->qos.txtp.traffic_class == ATM_ABR) {
  218. vcstatus = (vcstatus_t *) &(dev->testTable[vcc->vci]->vc_status);
  219. vcstatus->cnt++;
  220. foundLockUp = 0;
  221. if( vcstatus->cnt == 0x05 ) {
  222. abr_vc += vcc->vci;
  223. eabr_vc += vcc->vci;
  224. if( eabr_vc->last_desc ) {
  225. if( (abr_vc->status & 0x07) == ABR_STATE /* 0x2 */ ) {
  226. /* Wait for 10 Micro sec */
  227. udelay(10);
  228. if ((eabr_vc->last_desc)&&((abr_vc->status & 0x07)==ABR_STATE))
  229. foundLockUp = 1;
  230. }
  231. else {
  232. tempCellSlot = abr_vc->last_cell_slot;
  233. tempFract = abr_vc->fraction;
  234. if((tempCellSlot == dev->testTable[vcc->vci]->lastTime)
  235. && (tempFract == dev->testTable[vcc->vci]->fract))
  236. foundLockUp = 1;
  237. dev->testTable[vcc->vci]->lastTime = tempCellSlot;
  238. dev->testTable[vcc->vci]->fract = tempFract;
  239. }
  240. } /* last descriptor */
  241. vcstatus->cnt = 0;
  242. } /* vcstatus->cnt */
  243. if (foundLockUp) {
  244. IF_ABR(printk("LOCK UP found\n");)
  245. writew(0xFFFD, dev->seg_reg+MODE_REG_0);
  246. /* Wait for 10 Micro sec */
  247. udelay(10);
  248. abr_vc->status &= 0xFFF8;
  249. abr_vc->status |= 0x0001; /* state is idle */
  250. shd_tbl = (u_short *)dev->ABR_SCHED_TABLE_ADDR;
  251. for( i = 0; ((i < dev->num_vc) && (shd_tbl[i])); i++ );
  252. if (i < dev->num_vc)
  253. shd_tbl[i] = vcc->vci;
  254. else
  255. IF_ERR(printk("ABR Seg. may not continue on VC %x\n",vcc->vci);)
  256. writew(T_ONLINE, dev->seg_reg+MODE_REG_0);
  257. writew(~(TRANSMIT_DONE|TCQ_NOT_EMPTY), dev->seg_reg+SEG_MASK_REG);
  258. writew(TRANSMIT_DONE, dev->seg_reg+SEG_INTR_STATUS_REG);
  259. vcstatus->cnt = 0;
  260. } /* foundLockUp */
  261. } /* if an ABR VC */
  262. }
  263. /*
  264. ** Conversion of 24-bit cellrate (cells/sec) to 16-bit floating point format.
  265. **
  266. ** +----+----+------------------+-------------------------------+
  267. ** | R | NZ | 5-bit exponent | 9-bit mantissa |
  268. ** +----+----+------------------+-------------------------------+
  269. **
  270. ** R = reserved (written as 0)
  271. ** NZ = 0 if 0 cells/sec; 1 otherwise
  272. **
  273. ** if NZ = 1, rate = 1.mmmmmmmmm x 2^(eeeee) cells/sec
  274. */
  275. static u16
  276. cellrate_to_float(u32 cr)
  277. {
  278. #define NZ 0x4000
  279. #define M_BITS 9 /* Number of bits in mantissa */
  280. #define E_BITS 5 /* Number of bits in exponent */
  281. #define M_MASK 0x1ff
  282. #define E_MASK 0x1f
  283. u16 flot;
  284. u32 tmp = cr & 0x00ffffff;
  285. int i = 0;
  286. if (cr == 0)
  287. return 0;
  288. while (tmp != 1) {
  289. tmp >>= 1;
  290. i++;
  291. }
  292. if (i == M_BITS)
  293. flot = NZ | (i << M_BITS) | (cr & M_MASK);
  294. else if (i < M_BITS)
  295. flot = NZ | (i << M_BITS) | ((cr << (M_BITS - i)) & M_MASK);
  296. else
  297. flot = NZ | (i << M_BITS) | ((cr >> (i - M_BITS)) & M_MASK);
  298. return flot;
  299. }
  300. #if 0
  301. /*
  302. ** Conversion of 16-bit floating point format to 24-bit cellrate (cells/sec).
  303. */
  304. static u32
  305. float_to_cellrate(u16 rate)
  306. {
  307. u32 exp, mantissa, cps;
  308. if ((rate & NZ) == 0)
  309. return 0;
  310. exp = (rate >> M_BITS) & E_MASK;
  311. mantissa = rate & M_MASK;
  312. if (exp == 0)
  313. return 1;
  314. cps = (1 << M_BITS) | mantissa;
  315. if (exp == M_BITS)
  316. cps = cps;
  317. else if (exp > M_BITS)
  318. cps <<= (exp - M_BITS);
  319. else
  320. cps >>= (M_BITS - exp);
  321. return cps;
  322. }
  323. #endif
  324. static void init_abr_vc (IADEV *dev, srv_cls_param_t *srv_p) {
  325. srv_p->class_type = ATM_ABR;
  326. srv_p->pcr = dev->LineRate;
  327. srv_p->mcr = 0;
  328. srv_p->icr = 0x055cb7;
  329. srv_p->tbe = 0xffffff;
  330. srv_p->frtt = 0x3a;
  331. srv_p->rif = 0xf;
  332. srv_p->rdf = 0xb;
  333. srv_p->nrm = 0x4;
  334. srv_p->trm = 0x7;
  335. srv_p->cdf = 0x3;
  336. srv_p->adtf = 50;
  337. }
  338. static int
  339. ia_open_abr_vc(IADEV *dev, srv_cls_param_t *srv_p,
  340. struct atm_vcc *vcc, u8 flag)
  341. {
  342. f_vc_abr_entry *f_abr_vc;
  343. r_vc_abr_entry *r_abr_vc;
  344. u32 icr;
  345. u8 trm, nrm, crm;
  346. u16 adtf, air, *ptr16;
  347. f_abr_vc =(f_vc_abr_entry *)dev->MAIN_VC_TABLE_ADDR;
  348. f_abr_vc += vcc->vci;
  349. switch (flag) {
  350. case 1: /* FFRED initialization */
  351. #if 0 /* sanity check */
  352. if (srv_p->pcr == 0)
  353. return INVALID_PCR;
  354. if (srv_p->pcr > dev->LineRate)
  355. srv_p->pcr = dev->LineRate;
  356. if ((srv_p->mcr + dev->sum_mcr) > dev->LineRate)
  357. return MCR_UNAVAILABLE;
  358. if (srv_p->mcr > srv_p->pcr)
  359. return INVALID_MCR;
  360. if (!(srv_p->icr))
  361. srv_p->icr = srv_p->pcr;
  362. if ((srv_p->icr < srv_p->mcr) || (srv_p->icr > srv_p->pcr))
  363. return INVALID_ICR;
  364. if ((srv_p->tbe < MIN_TBE) || (srv_p->tbe > MAX_TBE))
  365. return INVALID_TBE;
  366. if ((srv_p->frtt < MIN_FRTT) || (srv_p->frtt > MAX_FRTT))
  367. return INVALID_FRTT;
  368. if (srv_p->nrm > MAX_NRM)
  369. return INVALID_NRM;
  370. if (srv_p->trm > MAX_TRM)
  371. return INVALID_TRM;
  372. if (srv_p->adtf > MAX_ADTF)
  373. return INVALID_ADTF;
  374. else if (srv_p->adtf == 0)
  375. srv_p->adtf = 1;
  376. if (srv_p->cdf > MAX_CDF)
  377. return INVALID_CDF;
  378. if (srv_p->rif > MAX_RIF)
  379. return INVALID_RIF;
  380. if (srv_p->rdf > MAX_RDF)
  381. return INVALID_RDF;
  382. #endif
  383. memset ((caddr_t)f_abr_vc, 0, sizeof(*f_abr_vc));
  384. f_abr_vc->f_vc_type = ABR;
  385. nrm = 2 << srv_p->nrm; /* (2 ** (srv_p->nrm +1)) */
  386. /* i.e 2**n = 2 << (n-1) */
  387. f_abr_vc->f_nrm = nrm << 8 | nrm;
  388. trm = 100000/(2 << (16 - srv_p->trm));
  389. if ( trm == 0) trm = 1;
  390. f_abr_vc->f_nrmexp =(((srv_p->nrm +1) & 0x0f) << 12)|(MRM << 8) | trm;
  391. crm = srv_p->tbe / nrm;
  392. if (crm == 0) crm = 1;
  393. f_abr_vc->f_crm = crm & 0xff;
  394. f_abr_vc->f_pcr = cellrate_to_float(srv_p->pcr);
  395. icr = min( srv_p->icr, (srv_p->tbe > srv_p->frtt) ?
  396. ((srv_p->tbe/srv_p->frtt)*1000000) :
  397. (1000000/(srv_p->frtt/srv_p->tbe)));
  398. f_abr_vc->f_icr = cellrate_to_float(icr);
  399. adtf = (10000 * srv_p->adtf)/8192;
  400. if (adtf == 0) adtf = 1;
  401. f_abr_vc->f_cdf = ((7 - srv_p->cdf) << 12 | adtf) & 0xfff;
  402. f_abr_vc->f_mcr = cellrate_to_float(srv_p->mcr);
  403. f_abr_vc->f_acr = f_abr_vc->f_icr;
  404. f_abr_vc->f_status = 0x0042;
  405. break;
  406. case 0: /* RFRED initialization */
  407. ptr16 = (u_short *)(dev->reass_ram + REASS_TABLE*dev->memSize);
  408. *(ptr16 + vcc->vci) = NO_AAL5_PKT | REASS_ABR;
  409. r_abr_vc = (r_vc_abr_entry*)(dev->reass_ram+ABR_VC_TABLE*dev->memSize);
  410. r_abr_vc += vcc->vci;
  411. r_abr_vc->r_status_rdf = (15 - srv_p->rdf) & 0x000f;
  412. air = srv_p->pcr << (15 - srv_p->rif);
  413. if (air == 0) air = 1;
  414. r_abr_vc->r_air = cellrate_to_float(air);
  415. dev->testTable[vcc->vci]->vc_status = VC_ACTIVE | VC_ABR;
  416. dev->sum_mcr += srv_p->mcr;
  417. dev->n_abr++;
  418. break;
  419. default:
  420. break;
  421. }
  422. return 0;
  423. }
  424. static int ia_cbr_setup (IADEV *dev, struct atm_vcc *vcc) {
  425. u32 rateLow=0, rateHigh, rate;
  426. int entries;
  427. struct ia_vcc *ia_vcc;
  428. int idealSlot =0, testSlot, toBeAssigned, inc;
  429. u32 spacing;
  430. u16 *SchedTbl, *TstSchedTbl;
  431. u16 cbrVC, vcIndex;
  432. u32 fracSlot = 0;
  433. u32 sp_mod = 0;
  434. u32 sp_mod2 = 0;
  435. /* IpAdjustTrafficParams */
  436. if (vcc->qos.txtp.max_pcr <= 0) {
  437. IF_ERR(printk("PCR for CBR not defined\n");)
  438. return -1;
  439. }
  440. rate = vcc->qos.txtp.max_pcr;
  441. entries = rate / dev->Granularity;
  442. IF_CBR(printk("CBR: CBR entries=0x%x for rate=0x%x & Gran=0x%x\n",
  443. entries, rate, dev->Granularity);)
  444. if (entries < 1)
  445. IF_CBR(printk("CBR: Bandwidth smaller than granularity of CBR table\n");)
  446. rateLow = entries * dev->Granularity;
  447. rateHigh = (entries + 1) * dev->Granularity;
  448. if (3*(rate - rateLow) > (rateHigh - rate))
  449. entries++;
  450. if (entries > dev->CbrRemEntries) {
  451. IF_CBR(printk("CBR: Not enough bandwidth to support this PCR.\n");)
  452. IF_CBR(printk("Entries = 0x%x, CbrRemEntries = 0x%x.\n",
  453. entries, dev->CbrRemEntries);)
  454. return -EBUSY;
  455. }
  456. ia_vcc = INPH_IA_VCC(vcc);
  457. ia_vcc->NumCbrEntry = entries;
  458. dev->sum_mcr += entries * dev->Granularity;
  459. /* IaFFrednInsertCbrSched */
  460. // Starting at an arbitrary location, place the entries into the table
  461. // as smoothly as possible
  462. cbrVC = 0;
  463. spacing = dev->CbrTotEntries / entries;
  464. sp_mod = dev->CbrTotEntries % entries; // get modulo
  465. toBeAssigned = entries;
  466. fracSlot = 0;
  467. vcIndex = vcc->vci;
  468. IF_CBR(printk("Vci=0x%x,Spacing=0x%x,Sp_mod=0x%x\n",vcIndex,spacing,sp_mod);)
  469. while (toBeAssigned)
  470. {
  471. // If this is the first time, start the table loading for this connection
  472. // as close to entryPoint as possible.
  473. if (toBeAssigned == entries)
  474. {
  475. idealSlot = dev->CbrEntryPt;
  476. dev->CbrEntryPt += 2; // Adding 2 helps to prevent clumping
  477. if (dev->CbrEntryPt >= dev->CbrTotEntries)
  478. dev->CbrEntryPt -= dev->CbrTotEntries;// Wrap if necessary
  479. } else {
  480. idealSlot += (u32)(spacing + fracSlot); // Point to the next location
  481. // in the table that would be smoothest
  482. fracSlot = ((sp_mod + sp_mod2) / entries); // get new integer part
  483. sp_mod2 = ((sp_mod + sp_mod2) % entries); // calc new fractional part
  484. }
  485. if (idealSlot >= (int)dev->CbrTotEntries)
  486. idealSlot -= dev->CbrTotEntries;
  487. // Continuously check around this ideal value until a null
  488. // location is encountered.
  489. SchedTbl = (u16*)(dev->seg_ram+CBR_SCHED_TABLE*dev->memSize);
  490. inc = 0;
  491. testSlot = idealSlot;
  492. TstSchedTbl = (u16*)(SchedTbl+testSlot); //set index and read in value
  493. IF_CBR(printk("CBR Testslot 0x%x AT Location 0x%p, NumToAssign=%d\n",
  494. testSlot, TstSchedTbl,toBeAssigned);)
  495. memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC));
  496. while (cbrVC) // If another VC at this location, we have to keep looking
  497. {
  498. inc++;
  499. testSlot = idealSlot - inc;
  500. if (testSlot < 0) { // Wrap if necessary
  501. testSlot += dev->CbrTotEntries;
  502. IF_CBR(printk("Testslot Wrap. STable Start=0x%p,Testslot=%d\n",
  503. SchedTbl,testSlot);)
  504. }
  505. TstSchedTbl = (u16 *)(SchedTbl + testSlot); // set table index
  506. memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC));
  507. if (!cbrVC)
  508. break;
  509. testSlot = idealSlot + inc;
  510. if (testSlot >= (int)dev->CbrTotEntries) { // Wrap if necessary
  511. testSlot -= dev->CbrTotEntries;
  512. IF_CBR(printk("TotCbrEntries=%d",dev->CbrTotEntries);)
  513. IF_CBR(printk(" Testslot=0x%x ToBeAssgned=%d\n",
  514. testSlot, toBeAssigned);)
  515. }
  516. // set table index and read in value
  517. TstSchedTbl = (u16*)(SchedTbl + testSlot);
  518. IF_CBR(printk("Reading CBR Tbl from 0x%p, CbrVal=0x%x Iteration %d\n",
  519. TstSchedTbl,cbrVC,inc);)
  520. memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC));
  521. } /* while */
  522. // Move this VCI number into this location of the CBR Sched table.
  523. memcpy((caddr_t)TstSchedTbl, (caddr_t)&vcIndex, sizeof(*TstSchedTbl));
  524. dev->CbrRemEntries--;
  525. toBeAssigned--;
  526. } /* while */
  527. /* IaFFrednCbrEnable */
  528. dev->NumEnabledCBR++;
  529. if (dev->NumEnabledCBR == 1) {
  530. writew((CBR_EN | UBR_EN | ABR_EN | (0x23 << 2)), dev->seg_reg+STPARMS);
  531. IF_CBR(printk("CBR is enabled\n");)
  532. }
  533. return 0;
  534. }
  535. static void ia_cbrVc_close (struct atm_vcc *vcc) {
  536. IADEV *iadev;
  537. u16 *SchedTbl, NullVci = 0;
  538. u32 i, NumFound;
  539. iadev = INPH_IA_DEV(vcc->dev);
  540. iadev->NumEnabledCBR--;
  541. SchedTbl = (u16*)(iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize);
  542. if (iadev->NumEnabledCBR == 0) {
  543. writew((UBR_EN | ABR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS);
  544. IF_CBR (printk("CBR support disabled\n");)
  545. }
  546. NumFound = 0;
  547. for (i=0; i < iadev->CbrTotEntries; i++)
  548. {
  549. if (*SchedTbl == vcc->vci) {
  550. iadev->CbrRemEntries++;
  551. *SchedTbl = NullVci;
  552. IF_CBR(NumFound++;)
  553. }
  554. SchedTbl++;
  555. }
  556. IF_CBR(printk("Exit ia_cbrVc_close, NumRemoved=%d\n",NumFound);)
  557. }
  558. static int ia_avail_descs(IADEV *iadev) {
  559. int tmp = 0;
  560. ia_hack_tcq(iadev);
  561. if (iadev->host_tcq_wr >= iadev->ffL.tcq_rd)
  562. tmp = (iadev->host_tcq_wr - iadev->ffL.tcq_rd) / 2;
  563. else
  564. tmp = (iadev->ffL.tcq_ed - iadev->ffL.tcq_rd + 2 + iadev->host_tcq_wr -
  565. iadev->ffL.tcq_st) / 2;
  566. return tmp;
  567. }
  568. static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb);
  569. static int ia_que_tx (IADEV *iadev) {
  570. struct sk_buff *skb;
  571. int num_desc;
  572. struct atm_vcc *vcc;
  573. num_desc = ia_avail_descs(iadev);
  574. while (num_desc && (skb = skb_dequeue(&iadev->tx_backlog))) {
  575. if (!(vcc = ATM_SKB(skb)->vcc)) {
  576. dev_kfree_skb_any(skb);
  577. printk("ia_que_tx: Null vcc\n");
  578. break;
  579. }
  580. if (!test_bit(ATM_VF_READY,&vcc->flags)) {
  581. dev_kfree_skb_any(skb);
  582. printk("Free the SKB on closed vci %d \n", vcc->vci);
  583. break;
  584. }
  585. if (ia_pkt_tx (vcc, skb)) {
  586. skb_queue_head(&iadev->tx_backlog, skb);
  587. }
  588. num_desc--;
  589. }
  590. return 0;
  591. }
  592. static void ia_tx_poll (IADEV *iadev) {
  593. struct atm_vcc *vcc = NULL;
  594. struct sk_buff *skb = NULL, *skb1 = NULL;
  595. struct ia_vcc *iavcc;
  596. IARTN_Q * rtne;
  597. ia_hack_tcq(iadev);
  598. while ( (rtne = ia_deque_rtn_q(&iadev->tx_return_q))) {
  599. skb = rtne->data.txskb;
  600. if (!skb) {
  601. printk("ia_tx_poll: skb is null\n");
  602. goto out;
  603. }
  604. vcc = ATM_SKB(skb)->vcc;
  605. if (!vcc) {
  606. printk("ia_tx_poll: vcc is null\n");
  607. dev_kfree_skb_any(skb);
  608. goto out;
  609. }
  610. iavcc = INPH_IA_VCC(vcc);
  611. if (!iavcc) {
  612. printk("ia_tx_poll: iavcc is null\n");
  613. dev_kfree_skb_any(skb);
  614. goto out;
  615. }
  616. skb1 = skb_dequeue(&iavcc->txing_skb);
  617. while (skb1 && (skb1 != skb)) {
  618. if (!(IA_SKB_STATE(skb1) & IA_TX_DONE)) {
  619. printk("IA_tx_intr: Vci %d lost pkt!!!\n", vcc->vci);
  620. }
  621. IF_ERR(printk("Release the SKB not match\n");)
  622. if ((vcc->pop) && (skb1->len != 0))
  623. {
  624. vcc->pop(vcc, skb1);
  625. IF_EVENT(printk("Tansmit Done - skb 0x%lx return\n",
  626. (long)skb1);)
  627. }
  628. else
  629. dev_kfree_skb_any(skb1);
  630. skb1 = skb_dequeue(&iavcc->txing_skb);
  631. }
  632. if (!skb1) {
  633. IF_EVENT(printk("IA: Vci %d - skb not found requed\n",vcc->vci);)
  634. ia_enque_head_rtn_q (&iadev->tx_return_q, rtne);
  635. break;
  636. }
  637. if ((vcc->pop) && (skb->len != 0))
  638. {
  639. vcc->pop(vcc, skb);
  640. IF_EVENT(printk("Tx Done - skb 0x%lx return\n",(long)skb);)
  641. }
  642. else
  643. dev_kfree_skb_any(skb);
  644. kfree(rtne);
  645. }
  646. ia_que_tx(iadev);
  647. out:
  648. return;
  649. }
  650. #if 0
  651. static void ia_eeprom_put (IADEV *iadev, u32 addr, u_short val)
  652. {
  653. u32 t;
  654. int i;
  655. /*
  656. * Issue a command to enable writes to the NOVRAM
  657. */
  658. NVRAM_CMD (EXTEND + EWEN);
  659. NVRAM_CLR_CE;
  660. /*
  661. * issue the write command
  662. */
  663. NVRAM_CMD(IAWRITE + addr);
  664. /*
  665. * Send the data, starting with D15, then D14, and so on for 16 bits
  666. */
  667. for (i=15; i>=0; i--) {
  668. NVRAM_CLKOUT (val & 0x8000);
  669. val <<= 1;
  670. }
  671. NVRAM_CLR_CE;
  672. CFG_OR(NVCE);
  673. t = readl(iadev->reg+IPHASE5575_EEPROM_ACCESS);
  674. while (!(t & NVDO))
  675. t = readl(iadev->reg+IPHASE5575_EEPROM_ACCESS);
  676. NVRAM_CLR_CE;
  677. /*
  678. * disable writes again
  679. */
  680. NVRAM_CMD(EXTEND + EWDS)
  681. NVRAM_CLR_CE;
  682. CFG_AND(~NVDI);
  683. }
  684. #endif
  685. static u16 ia_eeprom_get (IADEV *iadev, u32 addr)
  686. {
  687. u_short val;
  688. u32 t;
  689. int i;
  690. /*
  691. * Read the first bit that was clocked with the falling edge of the
  692. * the last command data clock
  693. */
  694. NVRAM_CMD(IAREAD + addr);
  695. /*
  696. * Now read the rest of the bits, the next bit read is D14, then D13,
  697. * and so on.
  698. */
  699. val = 0;
  700. for (i=15; i>=0; i--) {
  701. NVRAM_CLKIN(t);
  702. val |= (t << i);
  703. }
  704. NVRAM_CLR_CE;
  705. CFG_AND(~NVDI);
  706. return val;
  707. }
  708. static void ia_hw_type(IADEV *iadev) {
  709. u_short memType = ia_eeprom_get(iadev, 25);
  710. iadev->memType = memType;
  711. if ((memType & MEM_SIZE_MASK) == MEM_SIZE_1M) {
  712. iadev->num_tx_desc = IA_TX_BUF;
  713. iadev->tx_buf_sz = IA_TX_BUF_SZ;
  714. iadev->num_rx_desc = IA_RX_BUF;
  715. iadev->rx_buf_sz = IA_RX_BUF_SZ;
  716. } else if ((memType & MEM_SIZE_MASK) == MEM_SIZE_512K) {
  717. if (IA_TX_BUF == DFL_TX_BUFFERS)
  718. iadev->num_tx_desc = IA_TX_BUF / 2;
  719. else
  720. iadev->num_tx_desc = IA_TX_BUF;
  721. iadev->tx_buf_sz = IA_TX_BUF_SZ;
  722. if (IA_RX_BUF == DFL_RX_BUFFERS)
  723. iadev->num_rx_desc = IA_RX_BUF / 2;
  724. else
  725. iadev->num_rx_desc = IA_RX_BUF;
  726. iadev->rx_buf_sz = IA_RX_BUF_SZ;
  727. }
  728. else {
  729. if (IA_TX_BUF == DFL_TX_BUFFERS)
  730. iadev->num_tx_desc = IA_TX_BUF / 8;
  731. else
  732. iadev->num_tx_desc = IA_TX_BUF;
  733. iadev->tx_buf_sz = IA_TX_BUF_SZ;
  734. if (IA_RX_BUF == DFL_RX_BUFFERS)
  735. iadev->num_rx_desc = IA_RX_BUF / 8;
  736. else
  737. iadev->num_rx_desc = IA_RX_BUF;
  738. iadev->rx_buf_sz = IA_RX_BUF_SZ;
  739. }
  740. iadev->rx_pkt_ram = TX_PACKET_RAM + (iadev->num_tx_desc * iadev->tx_buf_sz);
  741. IF_INIT(printk("BUF: tx=%d,sz=%d rx=%d sz= %d rx_pkt_ram=%d\n",
  742. iadev->num_tx_desc, iadev->tx_buf_sz, iadev->num_rx_desc,
  743. iadev->rx_buf_sz, iadev->rx_pkt_ram);)
  744. #if 0
  745. if ((memType & FE_MASK) == FE_SINGLE_MODE) {
  746. iadev->phy_type = PHY_OC3C_S;
  747. else if ((memType & FE_MASK) == FE_UTP_OPTION)
  748. iadev->phy_type = PHY_UTP155;
  749. else
  750. iadev->phy_type = PHY_OC3C_M;
  751. #endif
  752. iadev->phy_type = memType & FE_MASK;
  753. IF_INIT(printk("memType = 0x%x iadev->phy_type = 0x%x\n",
  754. memType,iadev->phy_type);)
  755. if (iadev->phy_type == FE_25MBIT_PHY)
  756. iadev->LineRate = (u32)(((25600000/8)*26)/(27*53));
  757. else if (iadev->phy_type == FE_DS3_PHY)
  758. iadev->LineRate = (u32)(((44736000/8)*26)/(27*53));
  759. else if (iadev->phy_type == FE_E3_PHY)
  760. iadev->LineRate = (u32)(((34368000/8)*26)/(27*53));
  761. else
  762. iadev->LineRate = (u32)(ATM_OC3_PCR);
  763. IF_INIT(printk("iadev->LineRate = %d \n", iadev->LineRate);)
  764. }
  765. static u32 ia_phy_read32(struct iadev_priv *ia, unsigned int reg)
  766. {
  767. return readl(ia->phy + (reg >> 2));
  768. }
  769. static void ia_phy_write32(struct iadev_priv *ia, unsigned int reg, u32 val)
  770. {
  771. writel(val, ia->phy + (reg >> 2));
  772. }
  773. static void ia_frontend_intr(struct iadev_priv *iadev)
  774. {
  775. u32 status;
  776. if (iadev->phy_type & FE_25MBIT_PHY) {
  777. status = ia_phy_read32(iadev, MB25_INTR_STATUS);
  778. iadev->carrier_detect = (status & MB25_IS_GSB) ? 1 : 0;
  779. } else if (iadev->phy_type & FE_DS3_PHY) {
  780. ia_phy_read32(iadev, SUNI_DS3_FRM_INTR_STAT);
  781. status = ia_phy_read32(iadev, SUNI_DS3_FRM_STAT);
  782. iadev->carrier_detect = (status & SUNI_DS3_LOSV) ? 0 : 1;
  783. } else if (iadev->phy_type & FE_E3_PHY) {
  784. ia_phy_read32(iadev, SUNI_E3_FRM_MAINT_INTR_IND);
  785. status = ia_phy_read32(iadev, SUNI_E3_FRM_FRAM_INTR_IND_STAT);
  786. iadev->carrier_detect = (status & SUNI_E3_LOS) ? 0 : 1;
  787. } else {
  788. status = ia_phy_read32(iadev, SUNI_RSOP_STATUS);
  789. iadev->carrier_detect = (status & SUNI_LOSV) ? 0 : 1;
  790. }
  791. printk(KERN_INFO "IA: SUNI carrier %s\n",
  792. iadev->carrier_detect ? "detected" : "lost signal");
  793. }
  794. static void ia_mb25_init(struct iadev_priv *iadev)
  795. {
  796. #if 0
  797. mb25->mb25_master_ctrl = MB25_MC_DRIC | MB25_MC_DREC | MB25_MC_ENABLED;
  798. #endif
  799. ia_phy_write32(iadev, MB25_MASTER_CTRL, MB25_MC_DRIC | MB25_MC_DREC);
  800. ia_phy_write32(iadev, MB25_DIAG_CONTROL, 0);
  801. iadev->carrier_detect =
  802. (ia_phy_read32(iadev, MB25_INTR_STATUS) & MB25_IS_GSB) ? 1 : 0;
  803. }
  804. struct ia_reg {
  805. u16 reg;
  806. u16 val;
  807. };
  808. static void ia_phy_write(struct iadev_priv *iadev,
  809. const struct ia_reg *regs, int len)
  810. {
  811. while (len--) {
  812. ia_phy_write32(iadev, regs->reg, regs->val);
  813. regs++;
  814. }
  815. }
  816. static void ia_suni_pm7345_init_ds3(struct iadev_priv *iadev)
  817. {
  818. static const struct ia_reg suni_ds3_init [] = {
  819. { SUNI_DS3_FRM_INTR_ENBL, 0x17 },
  820. { SUNI_DS3_FRM_CFG, 0x01 },
  821. { SUNI_DS3_TRAN_CFG, 0x01 },
  822. { SUNI_CONFIG, 0 },
  823. { SUNI_SPLR_CFG, 0 },
  824. { SUNI_SPLT_CFG, 0 }
  825. };
  826. u32 status;
  827. status = ia_phy_read32(iadev, SUNI_DS3_FRM_STAT);
  828. iadev->carrier_detect = (status & SUNI_DS3_LOSV) ? 0 : 1;
  829. ia_phy_write(iadev, suni_ds3_init, ARRAY_SIZE(suni_ds3_init));
  830. }
  831. static void ia_suni_pm7345_init_e3(struct iadev_priv *iadev)
  832. {
  833. static const struct ia_reg suni_e3_init [] = {
  834. { SUNI_E3_FRM_FRAM_OPTIONS, 0x04 },
  835. { SUNI_E3_FRM_MAINT_OPTIONS, 0x20 },
  836. { SUNI_E3_FRM_FRAM_INTR_ENBL, 0x1d },
  837. { SUNI_E3_FRM_MAINT_INTR_ENBL, 0x30 },
  838. { SUNI_E3_TRAN_STAT_DIAG_OPTIONS, 0 },
  839. { SUNI_E3_TRAN_FRAM_OPTIONS, 0x01 },
  840. { SUNI_CONFIG, SUNI_PM7345_E3ENBL },
  841. { SUNI_SPLR_CFG, 0x41 },
  842. { SUNI_SPLT_CFG, 0x41 }
  843. };
  844. u32 status;
  845. status = ia_phy_read32(iadev, SUNI_E3_FRM_FRAM_INTR_IND_STAT);
  846. iadev->carrier_detect = (status & SUNI_E3_LOS) ? 0 : 1;
  847. ia_phy_write(iadev, suni_e3_init, ARRAY_SIZE(suni_e3_init));
  848. }
  849. static void ia_suni_pm7345_init(struct iadev_priv *iadev)
  850. {
  851. static const struct ia_reg suni_init [] = {
  852. /* Enable RSOP loss of signal interrupt. */
  853. { SUNI_INTR_ENBL, 0x28 },
  854. /* Clear error counters. */
  855. { SUNI_ID_RESET, 0 },
  856. /* Clear "PMCTST" in master test register. */
  857. { SUNI_MASTER_TEST, 0 },
  858. { SUNI_RXCP_CTRL, 0x2c },
  859. { SUNI_RXCP_FCTRL, 0x81 },
  860. { SUNI_RXCP_IDLE_PAT_H1, 0 },
  861. { SUNI_RXCP_IDLE_PAT_H2, 0 },
  862. { SUNI_RXCP_IDLE_PAT_H3, 0 },
  863. { SUNI_RXCP_IDLE_PAT_H4, 0x01 },
  864. { SUNI_RXCP_IDLE_MASK_H1, 0xff },
  865. { SUNI_RXCP_IDLE_MASK_H2, 0xff },
  866. { SUNI_RXCP_IDLE_MASK_H3, 0xff },
  867. { SUNI_RXCP_IDLE_MASK_H4, 0xfe },
  868. { SUNI_RXCP_CELL_PAT_H1, 0 },
  869. { SUNI_RXCP_CELL_PAT_H2, 0 },
  870. { SUNI_RXCP_CELL_PAT_H3, 0 },
  871. { SUNI_RXCP_CELL_PAT_H4, 0x01 },
  872. { SUNI_RXCP_CELL_MASK_H1, 0xff },
  873. { SUNI_RXCP_CELL_MASK_H2, 0xff },
  874. { SUNI_RXCP_CELL_MASK_H3, 0xff },
  875. { SUNI_RXCP_CELL_MASK_H4, 0xff },
  876. { SUNI_TXCP_CTRL, 0xa4 },
  877. { SUNI_TXCP_INTR_EN_STS, 0x10 },
  878. { SUNI_TXCP_IDLE_PAT_H5, 0x55 }
  879. };
  880. if (iadev->phy_type & FE_DS3_PHY)
  881. ia_suni_pm7345_init_ds3(iadev);
  882. else
  883. ia_suni_pm7345_init_e3(iadev);
  884. ia_phy_write(iadev, suni_init, ARRAY_SIZE(suni_init));
  885. ia_phy_write32(iadev, SUNI_CONFIG, ia_phy_read32(iadev, SUNI_CONFIG) &
  886. ~(SUNI_PM7345_LLB | SUNI_PM7345_CLB |
  887. SUNI_PM7345_DLB | SUNI_PM7345_PLB));
  888. #ifdef __SNMP__
  889. suni_pm7345->suni_rxcp_intr_en_sts |= SUNI_OOCDE;
  890. #endif /* __SNMP__ */
  891. return;
  892. }
  893. /***************************** IA_LIB END *****************************/
  894. #ifdef CONFIG_ATM_IA_DEBUG
  895. static int tcnter = 0;
  896. static void xdump( u_char* cp, int length, char* prefix )
  897. {
  898. int col, count;
  899. u_char prntBuf[120];
  900. u_char* pBuf = prntBuf;
  901. count = 0;
  902. while(count < length){
  903. pBuf += sprintf( pBuf, "%s", prefix );
  904. for(col = 0;count + col < length && col < 16; col++){
  905. if (col != 0 && (col % 4) == 0)
  906. pBuf += sprintf( pBuf, " " );
  907. pBuf += sprintf( pBuf, "%02X ", cp[count + col] );
  908. }
  909. while(col++ < 16){ /* pad end of buffer with blanks */
  910. if ((col % 4) == 0)
  911. sprintf( pBuf, " " );
  912. pBuf += sprintf( pBuf, " " );
  913. }
  914. pBuf += sprintf( pBuf, " " );
  915. for(col = 0;count + col < length && col < 16; col++){
  916. if (isprint((int)cp[count + col]))
  917. pBuf += sprintf( pBuf, "%c", cp[count + col] );
  918. else
  919. pBuf += sprintf( pBuf, "." );
  920. }
  921. printk("%s\n", prntBuf);
  922. count += col;
  923. pBuf = prntBuf;
  924. }
  925. } /* close xdump(... */
  926. #endif /* CONFIG_ATM_IA_DEBUG */
  927. static struct atm_dev *ia_boards = NULL;
  928. #define ACTUAL_RAM_BASE \
  929. RAM_BASE*((iadev->mem)/(128 * 1024))
  930. #define ACTUAL_SEG_RAM_BASE \
  931. IPHASE5575_FRAG_CONTROL_RAM_BASE*((iadev->mem)/(128 * 1024))
  932. #define ACTUAL_REASS_RAM_BASE \
  933. IPHASE5575_REASS_CONTROL_RAM_BASE*((iadev->mem)/(128 * 1024))
  934. /*-- some utilities and memory allocation stuff will come here -------------*/
  935. static void desc_dbg(IADEV *iadev) {
  936. u_short tcq_wr_ptr, tcq_st_ptr, tcq_ed_ptr;
  937. u32 i;
  938. void __iomem *tmp;
  939. // regval = readl((u32)ia_cmds->maddr);
  940. tcq_wr_ptr = readw(iadev->seg_reg+TCQ_WR_PTR);
  941. printk("B_tcq_wr = 0x%x desc = %d last desc = %d\n",
  942. tcq_wr_ptr, readw(iadev->seg_ram+tcq_wr_ptr),
  943. readw(iadev->seg_ram+tcq_wr_ptr-2));
  944. printk(" host_tcq_wr = 0x%x host_tcq_rd = 0x%x \n", iadev->host_tcq_wr,
  945. iadev->ffL.tcq_rd);
  946. tcq_st_ptr = readw(iadev->seg_reg+TCQ_ST_ADR);
  947. tcq_ed_ptr = readw(iadev->seg_reg+TCQ_ED_ADR);
  948. printk("tcq_st_ptr = 0x%x tcq_ed_ptr = 0x%x \n", tcq_st_ptr, tcq_ed_ptr);
  949. i = 0;
  950. while (tcq_st_ptr != tcq_ed_ptr) {
  951. tmp = iadev->seg_ram+tcq_st_ptr;
  952. printk("TCQ slot %d desc = %d Addr = %p\n", i++, readw(tmp), tmp);
  953. tcq_st_ptr += 2;
  954. }
  955. for(i=0; i <iadev->num_tx_desc; i++)
  956. printk("Desc_tbl[%d] = %d \n", i, iadev->desc_tbl[i].timestamp);
  957. }
  958. /*----------------------------- Receiving side stuff --------------------------*/
  959. static void rx_excp_rcvd(struct atm_dev *dev)
  960. {
  961. #if 0 /* closing the receiving size will cause too many excp int */
  962. IADEV *iadev;
  963. u_short state;
  964. u_short excpq_rd_ptr;
  965. //u_short *ptr;
  966. int vci, error = 1;
  967. iadev = INPH_IA_DEV(dev);
  968. state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
  969. while((state & EXCPQ_EMPTY) != EXCPQ_EMPTY)
  970. { printk("state = %x \n", state);
  971. excpq_rd_ptr = readw(iadev->reass_reg + EXCP_Q_RD_PTR) & 0xffff;
  972. printk("state = %x excpq_rd_ptr = %x \n", state, excpq_rd_ptr);
  973. if (excpq_rd_ptr == *(u16*)(iadev->reass_reg + EXCP_Q_WR_PTR))
  974. IF_ERR(printk("excpq_rd_ptr is wrong!!!\n");)
  975. // TODO: update exception stat
  976. vci = readw(iadev->reass_ram+excpq_rd_ptr);
  977. error = readw(iadev->reass_ram+excpq_rd_ptr+2) & 0x0007;
  978. // pwang_test
  979. excpq_rd_ptr += 4;
  980. if (excpq_rd_ptr > (readw(iadev->reass_reg + EXCP_Q_ED_ADR)& 0xffff))
  981. excpq_rd_ptr = readw(iadev->reass_reg + EXCP_Q_ST_ADR)& 0xffff;
  982. writew( excpq_rd_ptr, iadev->reass_reg + EXCP_Q_RD_PTR);
  983. state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
  984. }
  985. #endif
  986. }
  987. static void free_desc(struct atm_dev *dev, int desc)
  988. {
  989. IADEV *iadev;
  990. iadev = INPH_IA_DEV(dev);
  991. writew(desc, iadev->reass_ram+iadev->rfL.fdq_wr);
  992. iadev->rfL.fdq_wr +=2;
  993. if (iadev->rfL.fdq_wr > iadev->rfL.fdq_ed)
  994. iadev->rfL.fdq_wr = iadev->rfL.fdq_st;
  995. writew(iadev->rfL.fdq_wr, iadev->reass_reg+FREEQ_WR_PTR);
  996. }
  997. static int rx_pkt(struct atm_dev *dev)
  998. {
  999. IADEV *iadev;
  1000. struct atm_vcc *vcc;
  1001. unsigned short status;
  1002. struct rx_buf_desc __iomem *buf_desc_ptr;
  1003. int desc;
  1004. struct dle* wr_ptr;
  1005. int len;
  1006. struct sk_buff *skb;
  1007. u_int buf_addr, dma_addr;
  1008. iadev = INPH_IA_DEV(dev);
  1009. if (iadev->rfL.pcq_rd == (readw(iadev->reass_reg+PCQ_WR_PTR)&0xffff))
  1010. {
  1011. printk(KERN_ERR DEV_LABEL "(itf %d) Receive queue empty\n", dev->number);
  1012. return -EINVAL;
  1013. }
  1014. /* mask 1st 3 bits to get the actual descno. */
  1015. desc = readw(iadev->reass_ram+iadev->rfL.pcq_rd) & 0x1fff;
  1016. IF_RX(printk("reass_ram = %p iadev->rfL.pcq_rd = 0x%x desc = %d\n",
  1017. iadev->reass_ram, iadev->rfL.pcq_rd, desc);
  1018. printk(" pcq_wr_ptr = 0x%x\n",
  1019. readw(iadev->reass_reg+PCQ_WR_PTR)&0xffff);)
  1020. /* update the read pointer - maybe we shud do this in the end*/
  1021. if ( iadev->rfL.pcq_rd== iadev->rfL.pcq_ed)
  1022. iadev->rfL.pcq_rd = iadev->rfL.pcq_st;
  1023. else
  1024. iadev->rfL.pcq_rd += 2;
  1025. writew(iadev->rfL.pcq_rd, iadev->reass_reg+PCQ_RD_PTR);
  1026. /* get the buffer desc entry.
  1027. update stuff. - doesn't seem to be any update necessary
  1028. */
  1029. buf_desc_ptr = iadev->RX_DESC_BASE_ADDR;
  1030. /* make the ptr point to the corresponding buffer desc entry */
  1031. buf_desc_ptr += desc;
  1032. if (!desc || (desc > iadev->num_rx_desc) ||
  1033. ((buf_desc_ptr->vc_index & 0xffff) >= iadev->num_vc)) {
  1034. free_desc(dev, desc);
  1035. IF_ERR(printk("IA: bad descriptor desc = %d \n", desc);)
  1036. return -1;
  1037. }
  1038. vcc = iadev->rx_open[buf_desc_ptr->vc_index & 0xffff];
  1039. if (!vcc)
  1040. {
  1041. free_desc(dev, desc);
  1042. printk("IA: null vcc, drop PDU\n");
  1043. return -1;
  1044. }
  1045. /* might want to check the status bits for errors */
  1046. status = (u_short) (buf_desc_ptr->desc_mode);
  1047. if (status & (RX_CER | RX_PTE | RX_OFL))
  1048. {
  1049. atomic_inc(&vcc->stats->rx_err);
  1050. IF_ERR(printk("IA: bad packet, dropping it");)
  1051. if (status & RX_CER) {
  1052. IF_ERR(printk(" cause: packet CRC error\n");)
  1053. }
  1054. else if (status & RX_PTE) {
  1055. IF_ERR(printk(" cause: packet time out\n");)
  1056. }
  1057. else {
  1058. IF_ERR(printk(" cause: buffer overflow\n");)
  1059. }
  1060. goto out_free_desc;
  1061. }
  1062. /*
  1063. build DLE.
  1064. */
  1065. buf_addr = (buf_desc_ptr->buf_start_hi << 16) | buf_desc_ptr->buf_start_lo;
  1066. dma_addr = (buf_desc_ptr->dma_start_hi << 16) | buf_desc_ptr->dma_start_lo;
  1067. len = dma_addr - buf_addr;
  1068. if (len > iadev->rx_buf_sz) {
  1069. printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
  1070. atomic_inc(&vcc->stats->rx_err);
  1071. goto out_free_desc;
  1072. }
  1073. if (!(skb = atm_alloc_charge(vcc, len, GFP_ATOMIC))) {
  1074. if (vcc->vci < 32)
  1075. printk("Drop control packets\n");
  1076. goto out_free_desc;
  1077. }
  1078. skb_put(skb,len);
  1079. // pwang_test
  1080. ATM_SKB(skb)->vcc = vcc;
  1081. ATM_DESC(skb) = desc;
  1082. skb_queue_tail(&iadev->rx_dma_q, skb);
  1083. /* Build the DLE structure */
  1084. wr_ptr = iadev->rx_dle_q.write;
  1085. wr_ptr->sys_pkt_addr = dma_map_single(&iadev->pci->dev, skb->data,
  1086. len, DMA_FROM_DEVICE);
  1087. wr_ptr->local_pkt_addr = buf_addr;
  1088. wr_ptr->bytes = len; /* We don't know this do we ?? */
  1089. wr_ptr->mode = DMA_INT_ENABLE;
  1090. /* shud take care of wrap around here too. */
  1091. if(++wr_ptr == iadev->rx_dle_q.end)
  1092. wr_ptr = iadev->rx_dle_q.start;
  1093. iadev->rx_dle_q.write = wr_ptr;
  1094. udelay(1);
  1095. /* Increment transaction counter */
  1096. writel(1, iadev->dma+IPHASE5575_RX_COUNTER);
  1097. out: return 0;
  1098. out_free_desc:
  1099. free_desc(dev, desc);
  1100. goto out;
  1101. }
  1102. static void rx_intr(struct atm_dev *dev)
  1103. {
  1104. IADEV *iadev;
  1105. u_short status;
  1106. u_short state, i;
  1107. iadev = INPH_IA_DEV(dev);
  1108. status = readl(iadev->reass_reg+REASS_INTR_STATUS_REG) & 0xffff;
  1109. IF_EVENT(printk("rx_intr: status = 0x%x\n", status);)
  1110. if (status & RX_PKT_RCVD)
  1111. {
  1112. /* do something */
  1113. /* Basically recvd an interrupt for receiving a packet.
  1114. A descriptor would have been written to the packet complete
  1115. queue. Get all the descriptors and set up dma to move the
  1116. packets till the packet complete queue is empty..
  1117. */
  1118. state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
  1119. IF_EVENT(printk("Rx intr status: RX_PKT_RCVD %08x\n", status);)
  1120. while(!(state & PCQ_EMPTY))
  1121. {
  1122. rx_pkt(dev);
  1123. state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
  1124. }
  1125. iadev->rxing = 1;
  1126. }
  1127. if (status & RX_FREEQ_EMPT)
  1128. {
  1129. if (iadev->rxing) {
  1130. iadev->rx_tmp_cnt = iadev->rx_pkt_cnt;
  1131. iadev->rx_tmp_jif = jiffies;
  1132. iadev->rxing = 0;
  1133. }
  1134. else if ((time_after(jiffies, iadev->rx_tmp_jif + 50)) &&
  1135. ((iadev->rx_pkt_cnt - iadev->rx_tmp_cnt) == 0)) {
  1136. for (i = 1; i <= iadev->num_rx_desc; i++)
  1137. free_desc(dev, i);
  1138. printk("Test logic RUN!!!!\n");
  1139. writew( ~(RX_FREEQ_EMPT|RX_EXCP_RCVD),iadev->reass_reg+REASS_MASK_REG);
  1140. iadev->rxing = 1;
  1141. }
  1142. IF_EVENT(printk("Rx intr status: RX_FREEQ_EMPT %08x\n", status);)
  1143. }
  1144. if (status & RX_EXCP_RCVD)
  1145. {
  1146. /* probably need to handle the exception queue also. */
  1147. IF_EVENT(printk("Rx intr status: RX_EXCP_RCVD %08x\n", status);)
  1148. rx_excp_rcvd(dev);
  1149. }
  1150. if (status & RX_RAW_RCVD)
  1151. {
  1152. /* need to handle the raw incoming cells. This deepnds on
  1153. whether we have programmed to receive the raw cells or not.
  1154. Else ignore. */
  1155. IF_EVENT(printk("Rx intr status: RX_RAW_RCVD %08x\n", status);)
  1156. }
  1157. }
  1158. static void rx_dle_intr(struct atm_dev *dev)
  1159. {
  1160. IADEV *iadev;
  1161. struct atm_vcc *vcc;
  1162. struct sk_buff *skb;
  1163. int desc;
  1164. u_short state;
  1165. struct dle *dle, *cur_dle;
  1166. u_int dle_lp;
  1167. int len;
  1168. iadev = INPH_IA_DEV(dev);
  1169. /* free all the dles done, that is just update our own dle read pointer
  1170. - do we really need to do this. Think not. */
  1171. /* DMA is done, just get all the recevie buffers from the rx dma queue
  1172. and push them up to the higher layer protocol. Also free the desc
  1173. associated with the buffer. */
  1174. dle = iadev->rx_dle_q.read;
  1175. dle_lp = readl(iadev->dma+IPHASE5575_RX_LIST_ADDR) & (sizeof(struct dle)*DLE_ENTRIES - 1);
  1176. cur_dle = (struct dle*)(iadev->rx_dle_q.start + (dle_lp >> 4));
  1177. while(dle != cur_dle)
  1178. {
  1179. /* free the DMAed skb */
  1180. skb = skb_dequeue(&iadev->rx_dma_q);
  1181. if (!skb)
  1182. goto INCR_DLE;
  1183. desc = ATM_DESC(skb);
  1184. free_desc(dev, desc);
  1185. if (!(len = skb->len))
  1186. {
  1187. printk("rx_dle_intr: skb len 0\n");
  1188. dev_kfree_skb_any(skb);
  1189. }
  1190. else
  1191. {
  1192. struct cpcs_trailer *trailer;
  1193. u_short length;
  1194. struct ia_vcc *ia_vcc;
  1195. dma_unmap_single(&iadev->pci->dev, iadev->rx_dle_q.write->sys_pkt_addr,
  1196. len, DMA_FROM_DEVICE);
  1197. /* no VCC related housekeeping done as yet. lets see */
  1198. vcc = ATM_SKB(skb)->vcc;
  1199. if (!vcc) {
  1200. printk("IA: null vcc\n");
  1201. dev_kfree_skb_any(skb);
  1202. goto INCR_DLE;
  1203. }
  1204. ia_vcc = INPH_IA_VCC(vcc);
  1205. if (ia_vcc == NULL)
  1206. {
  1207. atomic_inc(&vcc->stats->rx_err);
  1208. atm_return(vcc, skb->truesize);
  1209. dev_kfree_skb_any(skb);
  1210. goto INCR_DLE;
  1211. }
  1212. // get real pkt length pwang_test
  1213. trailer = (struct cpcs_trailer*)((u_char *)skb->data +
  1214. skb->len - sizeof(*trailer));
  1215. length = swap_byte_order(trailer->length);
  1216. if ((length > iadev->rx_buf_sz) || (length >
  1217. (skb->len - sizeof(struct cpcs_trailer))))
  1218. {
  1219. atomic_inc(&vcc->stats->rx_err);
  1220. IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
  1221. length, skb->len);)
  1222. atm_return(vcc, skb->truesize);
  1223. dev_kfree_skb_any(skb);
  1224. goto INCR_DLE;
  1225. }
  1226. skb_trim(skb, length);
  1227. /* Display the packet */
  1228. IF_RXPKT(printk("\nDmad Recvd data: len = %d \n", skb->len);
  1229. xdump(skb->data, skb->len, "RX: ");
  1230. printk("\n");)
  1231. IF_RX(printk("rx_dle_intr: skb push");)
  1232. vcc->push(vcc,skb);
  1233. atomic_inc(&vcc->stats->rx);
  1234. iadev->rx_pkt_cnt++;
  1235. }
  1236. INCR_DLE:
  1237. if (++dle == iadev->rx_dle_q.end)
  1238. dle = iadev->rx_dle_q.start;
  1239. }
  1240. iadev->rx_dle_q.read = dle;
  1241. /* if the interrupts are masked because there were no free desc available,
  1242. unmask them now. */
  1243. if (!iadev->rxing) {
  1244. state = readl(iadev->reass_reg + STATE_REG) & 0xffff;
  1245. if (!(state & FREEQ_EMPTY)) {
  1246. state = readl(iadev->reass_reg + REASS_MASK_REG) & 0xffff;
  1247. writel(state & ~(RX_FREEQ_EMPT |/* RX_EXCP_RCVD |*/ RX_PKT_RCVD),
  1248. iadev->reass_reg+REASS_MASK_REG);
  1249. iadev->rxing++;
  1250. }
  1251. }
  1252. }
  1253. static int open_rx(struct atm_vcc *vcc)
  1254. {
  1255. IADEV *iadev;
  1256. u_short __iomem *vc_table;
  1257. u_short __iomem *reass_ptr;
  1258. IF_EVENT(printk("iadev: open_rx %d.%d\n", vcc->vpi, vcc->vci);)
  1259. if (vcc->qos.rxtp.traffic_class == ATM_NONE) return 0;
  1260. iadev = INPH_IA_DEV(vcc->dev);
  1261. if (vcc->qos.rxtp.traffic_class == ATM_ABR) {
  1262. if (iadev->phy_type & FE_25MBIT_PHY) {
  1263. printk("IA: ABR not support\n");
  1264. return -EINVAL;
  1265. }
  1266. }
  1267. /* Make only this VCI in the vc table valid and let all
  1268. others be invalid entries */
  1269. vc_table = iadev->reass_ram+RX_VC_TABLE*iadev->memSize;
  1270. vc_table += vcc->vci;
  1271. /* mask the last 6 bits and OR it with 3 for 1K VCs */
  1272. *vc_table = vcc->vci << 6;
  1273. /* Also keep a list of open rx vcs so that we can attach them with
  1274. incoming PDUs later. */
  1275. if ((vcc->qos.rxtp.traffic_class == ATM_ABR) ||
  1276. (vcc->qos.txtp.traffic_class == ATM_ABR))
  1277. {
  1278. srv_cls_param_t srv_p;
  1279. init_abr_vc(iadev, &srv_p);
  1280. ia_open_abr_vc(iadev, &srv_p, vcc, 0);
  1281. }
  1282. else { /* for UBR later may need to add CBR logic */
  1283. reass_ptr = iadev->reass_ram+REASS_TABLE*iadev->memSize;
  1284. reass_ptr += vcc->vci;
  1285. *reass_ptr = NO_AAL5_PKT;
  1286. }
  1287. if (iadev->rx_open[vcc->vci])
  1288. printk(KERN_CRIT DEV_LABEL "(itf %d): VCI %d already open\n",
  1289. vcc->dev->number, vcc->vci);
  1290. iadev->rx_open[vcc->vci] = vcc;
  1291. return 0;
  1292. }
  1293. static int rx_init(struct atm_dev *dev)
  1294. {
  1295. IADEV *iadev;
  1296. struct rx_buf_desc __iomem *buf_desc_ptr;
  1297. unsigned long rx_pkt_start = 0;
  1298. void *dle_addr;
  1299. struct abr_vc_table *abr_vc_table;
  1300. u16 *vc_table;
  1301. u16 *reass_table;
  1302. int i,j, vcsize_sel;
  1303. u_short freeq_st_adr;
  1304. u_short *freeq_start;
  1305. iadev = INPH_IA_DEV(dev);
  1306. // spin_lock_init(&iadev->rx_lock);
  1307. /* Allocate 4k bytes - more aligned than needed (4k boundary) */
  1308. dle_addr = dma_alloc_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE,
  1309. &iadev->rx_dle_dma, GFP_KERNEL);
  1310. if (!dle_addr) {
  1311. printk(KERN_ERR DEV_LABEL "can't allocate DLEs\n");
  1312. goto err_out;
  1313. }
  1314. iadev->rx_dle_q.start = (struct dle *)dle_addr;
  1315. iadev->rx_dle_q.read = iadev->rx_dle_q.start;
  1316. iadev->rx_dle_q.write = iadev->rx_dle_q.start;
  1317. iadev->rx_dle_q.end = (struct dle*)((unsigned long)dle_addr+sizeof(struct dle)*DLE_ENTRIES);
  1318. /* the end of the dle q points to the entry after the last
  1319. DLE that can be used. */
  1320. /* write the upper 20 bits of the start address to rx list address register */
  1321. /* We know this is 32bit bus addressed so the following is safe */
  1322. writel(iadev->rx_dle_dma & 0xfffff000,
  1323. iadev->dma + IPHASE5575_RX_LIST_ADDR);
  1324. IF_INIT(printk("Tx Dle list addr: 0x%p value: 0x%0x\n",
  1325. iadev->dma+IPHASE5575_TX_LIST_ADDR,
  1326. readl(iadev->dma + IPHASE5575_TX_LIST_ADDR));
  1327. printk("Rx Dle list addr: 0x%p value: 0x%0x\n",
  1328. iadev->dma+IPHASE5575_RX_LIST_ADDR,
  1329. readl(iadev->dma + IPHASE5575_RX_LIST_ADDR));)
  1330. writew(0xffff, iadev->reass_reg+REASS_MASK_REG);
  1331. writew(0, iadev->reass_reg+MODE_REG);
  1332. writew(RESET_REASS, iadev->reass_reg+REASS_COMMAND_REG);
  1333. /* Receive side control memory map
  1334. -------------------------------
  1335. Buffer descr 0x0000 (736 - 23K)
  1336. VP Table 0x5c00 (256 - 512)
  1337. Except q 0x5e00 (128 - 512)
  1338. Free buffer q 0x6000 (1K - 2K)
  1339. Packet comp q 0x6800 (1K - 2K)
  1340. Reass Table 0x7000 (1K - 2K)
  1341. VC Table 0x7800 (1K - 2K)
  1342. ABR VC Table 0x8000 (1K - 32K)
  1343. */
  1344. /* Base address for Buffer Descriptor Table */
  1345. writew(RX_DESC_BASE >> 16, iadev->reass_reg+REASS_DESC_BASE);
  1346. /* Set the buffer size register */
  1347. writew(iadev->rx_buf_sz, iadev->reass_reg+BUF_SIZE);
  1348. /* Initialize each entry in the Buffer Descriptor Table */
  1349. iadev->RX_DESC_BASE_ADDR = iadev->reass_ram+RX_DESC_BASE*iadev->memSize;
  1350. buf_desc_ptr = iadev->RX_DESC_BASE_ADDR;
  1351. memset_io(buf_desc_ptr, 0, sizeof(*buf_desc_ptr));
  1352. buf_desc_ptr++;
  1353. rx_pkt_start = iadev->rx_pkt_ram;
  1354. for(i=1; i<=iadev->num_rx_desc; i++)
  1355. {
  1356. memset_io(buf_desc_ptr, 0, sizeof(*buf_desc_ptr));
  1357. buf_desc_ptr->buf_start_hi = rx_pkt_start >> 16;
  1358. buf_desc_ptr->buf_start_lo = rx_pkt_start & 0x0000ffff;
  1359. buf_desc_ptr++;
  1360. rx_pkt_start += iadev->rx_buf_sz;
  1361. }
  1362. IF_INIT(printk("Rx Buffer desc ptr: 0x%p\n", buf_desc_ptr);)
  1363. i = FREE_BUF_DESC_Q*iadev->memSize;
  1364. writew(i >> 16, iadev->reass_reg+REASS_QUEUE_BASE);
  1365. writew(i, iadev->reass_reg+FREEQ_ST_ADR);
  1366. writew(i+iadev->num_rx_desc*sizeof(u_short),
  1367. iadev->reass_reg+FREEQ_ED_ADR);
  1368. writew(i, iadev->reass_reg+FREEQ_RD_PTR);
  1369. writew(i+iadev->num_rx_desc*sizeof(u_short),
  1370. iadev->reass_reg+FREEQ_WR_PTR);
  1371. /* Fill the FREEQ with all the free descriptors. */
  1372. freeq_st_adr = readw(iadev->reass_reg+FREEQ_ST_ADR);
  1373. freeq_start = (u_short *)(iadev->reass_ram+freeq_st_adr);
  1374. for(i=1; i<=iadev->num_rx_desc; i++)
  1375. {
  1376. *freeq_start = (u_short)i;
  1377. freeq_start++;
  1378. }
  1379. IF_INIT(printk("freeq_start: 0x%p\n", freeq_start);)
  1380. /* Packet Complete Queue */
  1381. i = (PKT_COMP_Q * iadev->memSize) & 0xffff;
  1382. writew(i, iadev->reass_reg+PCQ_ST_ADR);
  1383. writew(i+iadev->num_vc*sizeof(u_short), iadev->reass_reg+PCQ_ED_ADR);
  1384. writew(i, iadev->reass_reg+PCQ_RD_PTR);
  1385. writew(i, iadev->reass_reg+PCQ_WR_PTR);
  1386. /* Exception Queue */
  1387. i = (EXCEPTION_Q * iadev->memSize) & 0xffff;
  1388. writew(i, iadev->reass_reg+EXCP_Q_ST_ADR);
  1389. writew(i + NUM_RX_EXCP * sizeof(RX_ERROR_Q),
  1390. iadev->reass_reg+EXCP_Q_ED_ADR);
  1391. writew(i, iadev->reass_reg+EXCP_Q_RD_PTR);
  1392. writew(i, iadev->reass_reg+EXCP_Q_WR_PTR);
  1393. /* Load local copy of FREEQ and PCQ ptrs */
  1394. iadev->rfL.fdq_st = readw(iadev->reass_reg+FREEQ_ST_ADR) & 0xffff;
  1395. iadev->rfL.fdq_ed = readw(iadev->reass_reg+FREEQ_ED_ADR) & 0xffff ;
  1396. iadev->rfL.fdq_rd = readw(iadev->reass_reg+FREEQ_RD_PTR) & 0xffff;
  1397. iadev->rfL.fdq_wr = readw(iadev->reass_reg+FREEQ_WR_PTR) & 0xffff;
  1398. iadev->rfL.pcq_st = readw(iadev->reass_reg+PCQ_ST_ADR) & 0xffff;
  1399. iadev->rfL.pcq_ed = readw(iadev->reass_reg+PCQ_ED_ADR) & 0xffff;
  1400. iadev->rfL.pcq_rd = readw(iadev->reass_reg+PCQ_RD_PTR) & 0xffff;
  1401. iadev->rfL.pcq_wr = readw(iadev->reass_reg+PCQ_WR_PTR) & 0xffff;
  1402. IF_INIT(printk("INIT:pcq_st:0x%x pcq_ed:0x%x pcq_rd:0x%x pcq_wr:0x%x",
  1403. iadev->rfL.pcq_st, iadev->rfL.pcq_ed, iadev->rfL.pcq_rd,
  1404. iadev->rfL.pcq_wr);)
  1405. /* just for check - no VP TBL */
  1406. /* VP Table */
  1407. /* writew(0x0b80, iadev->reass_reg+VP_LKUP_BASE); */
  1408. /* initialize VP Table for invalid VPIs
  1409. - I guess we can write all 1s or 0x000f in the entire memory
  1410. space or something similar.
  1411. */
  1412. /* This seems to work and looks right to me too !!! */
  1413. i = REASS_TABLE * iadev->memSize;
  1414. writew((i >> 3), iadev->reass_reg+REASS_TABLE_BASE);
  1415. /* initialize Reassembly table to I don't know what ???? */
  1416. reass_table = (u16 *)(iadev->reass_ram+i);
  1417. j = REASS_TABLE_SZ * iadev->memSize;
  1418. for(i=0; i < j; i++)
  1419. *reass_table++ = NO_AAL5_PKT;
  1420. i = 8*1024;
  1421. vcsize_sel = 0;
  1422. while (i != iadev->num_vc) {
  1423. i /= 2;
  1424. vcsize_sel++;
  1425. }
  1426. i = RX_VC_TABLE * iadev->memSize;
  1427. writew(((i>>3) & 0xfff8) | vcsize_sel, iadev->reass_reg+VC_LKUP_BASE);
  1428. vc_table = (u16 *)(iadev->reass_ram+RX_VC_TABLE*iadev->memSize);
  1429. j = RX_VC_TABLE_SZ * iadev->memSize;
  1430. for(i = 0; i < j; i++)
  1431. {
  1432. /* shift the reassembly pointer by 3 + lower 3 bits of
  1433. vc_lkup_base register (=3 for 1K VCs) and the last byte
  1434. is those low 3 bits.
  1435. Shall program this later.
  1436. */
  1437. *vc_table = (i << 6) | 15; /* for invalid VCI */
  1438. vc_table++;
  1439. }
  1440. /* ABR VC table */
  1441. i = ABR_VC_TABLE * iadev->memSize;
  1442. writew(i >> 3, iadev->reass_reg+ABR_LKUP_BASE);
  1443. i = ABR_VC_TABLE * iadev->memSize;
  1444. abr_vc_table = (struct abr_vc_table *)(iadev->reass_ram+i);
  1445. j = REASS_TABLE_SZ * iadev->memSize;
  1446. memset ((char*)abr_vc_table, 0, j * sizeof(*abr_vc_table));
  1447. for(i = 0; i < j; i++) {
  1448. abr_vc_table->rdf = 0x0003;
  1449. abr_vc_table->air = 0x5eb1;
  1450. abr_vc_table++;
  1451. }
  1452. /* Initialize other registers */
  1453. /* VP Filter Register set for VC Reassembly only */
  1454. writew(0xff00, iadev->reass_reg+VP_FILTER);
  1455. writew(0, iadev->reass_reg+XTRA_RM_OFFSET);
  1456. writew(0x1, iadev->reass_reg+PROTOCOL_ID);
  1457. /* Packet Timeout Count related Registers :
  1458. Set packet timeout to occur in about 3 seconds
  1459. Set Packet Aging Interval count register to overflow in about 4 us
  1460. */
  1461. writew(0xF6F8, iadev->reass_reg+PKT_TM_CNT );
  1462. i = (j >> 6) & 0xFF;
  1463. j += 2 * (j - 1);
  1464. i |= ((j << 2) & 0xFF00);
  1465. writew(i, iadev->reass_reg+TMOUT_RANGE);
  1466. /* initiate the desc_tble */
  1467. for(i=0; i<iadev->num_tx_desc;i++)
  1468. iadev->desc_tbl[i].timestamp = 0;
  1469. /* to clear the interrupt status register - read it */
  1470. readw(iadev->reass_reg+REASS_INTR_STATUS_REG);
  1471. /* Mask Register - clear it */
  1472. writew(~(RX_FREEQ_EMPT|RX_PKT_RCVD), iadev->reass_reg+REASS_MASK_REG);
  1473. skb_queue_head_init(&iadev->rx_dma_q);
  1474. iadev->rx_free_desc_qhead = NULL;
  1475. iadev->rx_open = kzalloc(4 * iadev->num_vc, GFP_KERNEL);
  1476. if (!iadev->rx_open) {
  1477. printk(KERN_ERR DEV_LABEL "itf %d couldn't get free page\n",
  1478. dev->number);
  1479. goto err_free_dle;
  1480. }
  1481. iadev->rxing = 1;
  1482. iadev->rx_pkt_cnt = 0;
  1483. /* Mode Register */
  1484. writew(R_ONLINE, iadev->reass_reg+MODE_REG);
  1485. return 0;
  1486. err_free_dle:
  1487. dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->rx_dle_q.start,
  1488. iadev->rx_dle_dma);
  1489. err_out:
  1490. return -ENOMEM;
  1491. }
  1492. /*
  1493. The memory map suggested in appendix A and the coding for it.
  1494. Keeping it around just in case we change our mind later.
  1495. Buffer descr 0x0000 (128 - 4K)
  1496. UBR sched 0x1000 (1K - 4K)
  1497. UBR Wait q 0x2000 (1K - 4K)
  1498. Commn queues 0x3000 Packet Ready, Trasmit comp(0x3100)
  1499. (128 - 256) each
  1500. extended VC 0x4000 (1K - 8K)
  1501. ABR sched 0x6000 and ABR wait queue (1K - 2K) each
  1502. CBR sched 0x7000 (as needed)
  1503. VC table 0x8000 (1K - 32K)
  1504. */
  1505. static void tx_intr(struct atm_dev *dev)
  1506. {
  1507. IADEV *iadev;
  1508. unsigned short status;
  1509. unsigned long flags;
  1510. iadev = INPH_IA_DEV(dev);
  1511. status = readl(iadev->seg_reg+SEG_INTR_STATUS_REG);
  1512. if (status & TRANSMIT_DONE){
  1513. IF_EVENT(printk("Tansmit Done Intr logic run\n");)
  1514. spin_lock_irqsave(&iadev->tx_lock, flags);
  1515. ia_tx_poll(iadev);
  1516. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  1517. writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
  1518. if (iadev->close_pending)
  1519. wake_up(&iadev->close_wait);
  1520. }
  1521. if (status & TCQ_NOT_EMPTY)
  1522. {
  1523. IF_EVENT(printk("TCQ_NOT_EMPTY int received\n");)
  1524. }
  1525. }
  1526. static void tx_dle_intr(struct atm_dev *dev)
  1527. {
  1528. IADEV *iadev;
  1529. struct dle *dle, *cur_dle;
  1530. struct sk_buff *skb;
  1531. struct atm_vcc *vcc;
  1532. struct ia_vcc *iavcc;
  1533. u_int dle_lp;
  1534. unsigned long flags;
  1535. iadev = INPH_IA_DEV(dev);
  1536. spin_lock_irqsave(&iadev->tx_lock, flags);
  1537. dle = iadev->tx_dle_q.read;
  1538. dle_lp = readl(iadev->dma+IPHASE5575_TX_LIST_ADDR) &
  1539. (sizeof(struct dle)*DLE_ENTRIES - 1);
  1540. cur_dle = (struct dle*)(iadev->tx_dle_q.start + (dle_lp >> 4));
  1541. while (dle != cur_dle)
  1542. {
  1543. /* free the DMAed skb */
  1544. skb = skb_dequeue(&iadev->tx_dma_q);
  1545. if (!skb) break;
  1546. /* Revenge of the 2 dle (skb + trailer) used in ia_pkt_tx() */
  1547. if (!((dle - iadev->tx_dle_q.start)%(2*sizeof(struct dle)))) {
  1548. dma_unmap_single(&iadev->pci->dev, dle->sys_pkt_addr, skb->len,
  1549. DMA_TO_DEVICE);
  1550. }
  1551. vcc = ATM_SKB(skb)->vcc;
  1552. if (!vcc) {
  1553. printk("tx_dle_intr: vcc is null\n");
  1554. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  1555. dev_kfree_skb_any(skb);
  1556. return;
  1557. }
  1558. iavcc = INPH_IA_VCC(vcc);
  1559. if (!iavcc) {
  1560. printk("tx_dle_intr: iavcc is null\n");
  1561. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  1562. dev_kfree_skb_any(skb);
  1563. return;
  1564. }
  1565. if (vcc->qos.txtp.pcr >= iadev->rate_limit) {
  1566. if ((vcc->pop) && (skb->len != 0))
  1567. {
  1568. vcc->pop(vcc, skb);
  1569. }
  1570. else {
  1571. dev_kfree_skb_any(skb);
  1572. }
  1573. }
  1574. else { /* Hold the rate-limited skb for flow control */
  1575. IA_SKB_STATE(skb) |= IA_DLED;
  1576. skb_queue_tail(&iavcc->txing_skb, skb);
  1577. }
  1578. IF_EVENT(printk("tx_dle_intr: enque skb = 0x%p \n", skb);)
  1579. if (++dle == iadev->tx_dle_q.end)
  1580. dle = iadev->tx_dle_q.start;
  1581. }
  1582. iadev->tx_dle_q.read = dle;
  1583. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  1584. }
  1585. static int open_tx(struct atm_vcc *vcc)
  1586. {
  1587. struct ia_vcc *ia_vcc;
  1588. IADEV *iadev;
  1589. struct main_vc *vc;
  1590. struct ext_vc *evc;
  1591. int ret;
  1592. IF_EVENT(printk("iadev: open_tx entered vcc->vci = %d\n", vcc->vci);)
  1593. if (vcc->qos.txtp.traffic_class == ATM_NONE) return 0;
  1594. iadev = INPH_IA_DEV(vcc->dev);
  1595. if (iadev->phy_type & FE_25MBIT_PHY) {
  1596. if (vcc->qos.txtp.traffic_class == ATM_ABR) {
  1597. printk("IA: ABR not support\n");
  1598. return -EINVAL;
  1599. }
  1600. if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  1601. printk("IA: CBR not support\n");
  1602. return -EINVAL;
  1603. }
  1604. }
  1605. ia_vcc = INPH_IA_VCC(vcc);
  1606. memset((caddr_t)ia_vcc, 0, sizeof(*ia_vcc));
  1607. if (vcc->qos.txtp.max_sdu >
  1608. (iadev->tx_buf_sz - sizeof(struct cpcs_trailer))){
  1609. printk("IA: SDU size over (%d) the configured SDU size %d\n",
  1610. vcc->qos.txtp.max_sdu,iadev->tx_buf_sz);
  1611. vcc->dev_data = NULL;
  1612. kfree(ia_vcc);
  1613. return -EINVAL;
  1614. }
  1615. ia_vcc->vc_desc_cnt = 0;
  1616. ia_vcc->txing = 1;
  1617. /* find pcr */
  1618. if (vcc->qos.txtp.max_pcr == ATM_MAX_PCR)
  1619. vcc->qos.txtp.pcr = iadev->LineRate;
  1620. else if ((vcc->qos.txtp.max_pcr == 0)&&( vcc->qos.txtp.pcr <= 0))
  1621. vcc->qos.txtp.pcr = iadev->LineRate;
  1622. else if ((vcc->qos.txtp.max_pcr > vcc->qos.txtp.pcr) && (vcc->qos.txtp.max_pcr> 0))
  1623. vcc->qos.txtp.pcr = vcc->qos.txtp.max_pcr;
  1624. if (vcc->qos.txtp.pcr > iadev->LineRate)
  1625. vcc->qos.txtp.pcr = iadev->LineRate;
  1626. ia_vcc->pcr = vcc->qos.txtp.pcr;
  1627. if (ia_vcc->pcr > (iadev->LineRate / 6) ) ia_vcc->ltimeout = HZ / 10;
  1628. else if (ia_vcc->pcr > (iadev->LineRate / 130)) ia_vcc->ltimeout = HZ;
  1629. else if (ia_vcc->pcr <= 170) ia_vcc->ltimeout = 16 * HZ;
  1630. else ia_vcc->ltimeout = 2700 * HZ / ia_vcc->pcr;
  1631. if (ia_vcc->pcr < iadev->rate_limit)
  1632. skb_queue_head_init (&ia_vcc->txing_skb);
  1633. if (ia_vcc->pcr < iadev->rate_limit) {
  1634. struct sock *sk = sk_atm(vcc);
  1635. if (vcc->qos.txtp.max_sdu != 0) {
  1636. if (ia_vcc->pcr > 60000)
  1637. sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 5;
  1638. else if (ia_vcc->pcr > 2000)
  1639. sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 4;
  1640. else
  1641. sk->sk_sndbuf = vcc->qos.txtp.max_sdu * 3;
  1642. }
  1643. else
  1644. sk->sk_sndbuf = 24576;
  1645. }
  1646. vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR;
  1647. evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR;
  1648. vc += vcc->vci;
  1649. evc += vcc->vci;
  1650. memset((caddr_t)vc, 0, sizeof(*vc));
  1651. memset((caddr_t)evc, 0, sizeof(*evc));
  1652. /* store the most significant 4 bits of vci as the last 4 bits
  1653. of first part of atm header.
  1654. store the last 12 bits of vci as first 12 bits of the second
  1655. part of the atm header.
  1656. */
  1657. evc->atm_hdr1 = (vcc->vci >> 12) & 0x000f;
  1658. evc->atm_hdr2 = (vcc->vci & 0x0fff) << 4;
  1659. /* check the following for different traffic classes */
  1660. if (vcc->qos.txtp.traffic_class == ATM_UBR)
  1661. {
  1662. vc->type = UBR;
  1663. vc->status = CRC_APPEND;
  1664. vc->acr = cellrate_to_float(iadev->LineRate);
  1665. if (vcc->qos.txtp.pcr > 0)
  1666. vc->acr = cellrate_to_float(vcc->qos.txtp.pcr);
  1667. IF_UBR(printk("UBR: txtp.pcr = 0x%x f_rate = 0x%x\n",
  1668. vcc->qos.txtp.max_pcr,vc->acr);)
  1669. }
  1670. else if (vcc->qos.txtp.traffic_class == ATM_ABR)
  1671. { srv_cls_param_t srv_p;
  1672. IF_ABR(printk("Tx ABR VCC\n");)
  1673. init_abr_vc(iadev, &srv_p);
  1674. if (vcc->qos.txtp.pcr > 0)
  1675. srv_p.pcr = vcc->qos.txtp.pcr;
  1676. if (vcc->qos.txtp.min_pcr > 0) {
  1677. int tmpsum = iadev->sum_mcr+iadev->sum_cbr+vcc->qos.txtp.min_pcr;
  1678. if (tmpsum > iadev->LineRate)
  1679. return -EBUSY;
  1680. srv_p.mcr = vcc->qos.txtp.min_pcr;
  1681. iadev->sum_mcr += vcc->qos.txtp.min_pcr;
  1682. }
  1683. else srv_p.mcr = 0;
  1684. if (vcc->qos.txtp.icr)
  1685. srv_p.icr = vcc->qos.txtp.icr;
  1686. if (vcc->qos.txtp.tbe)
  1687. srv_p.tbe = vcc->qos.txtp.tbe;
  1688. if (vcc->qos.txtp.frtt)
  1689. srv_p.frtt = vcc->qos.txtp.frtt;
  1690. if (vcc->qos.txtp.rif)
  1691. srv_p.rif = vcc->qos.txtp.rif;
  1692. if (vcc->qos.txtp.rdf)
  1693. srv_p.rdf = vcc->qos.txtp.rdf;
  1694. if (vcc->qos.txtp.nrm_pres)
  1695. srv_p.nrm = vcc->qos.txtp.nrm;
  1696. if (vcc->qos.txtp.trm_pres)
  1697. srv_p.trm = vcc->qos.txtp.trm;
  1698. if (vcc->qos.txtp.adtf_pres)
  1699. srv_p.adtf = vcc->qos.txtp.adtf;
  1700. if (vcc->qos.txtp.cdf_pres)
  1701. srv_p.cdf = vcc->qos.txtp.cdf;
  1702. if (srv_p.icr > srv_p.pcr)
  1703. srv_p.icr = srv_p.pcr;
  1704. IF_ABR(printk("ABR:vcc->qos.txtp.max_pcr = %d mcr = %d\n",
  1705. srv_p.pcr, srv_p.mcr);)
  1706. ia_open_abr_vc(iadev, &srv_p, vcc, 1);
  1707. } else if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  1708. if (iadev->phy_type & FE_25MBIT_PHY) {
  1709. printk("IA: CBR not support\n");
  1710. return -EINVAL;
  1711. }
  1712. if (vcc->qos.txtp.max_pcr > iadev->LineRate) {
  1713. IF_CBR(printk("PCR is not available\n");)
  1714. return -1;
  1715. }
  1716. vc->type = CBR;
  1717. vc->status = CRC_APPEND;
  1718. if ((ret = ia_cbr_setup (iadev, vcc)) < 0) {
  1719. return ret;
  1720. }
  1721. } else {
  1722. printk("iadev: Non UBR, ABR and CBR traffic not supported\n");
  1723. }
  1724. iadev->testTable[vcc->vci]->vc_status |= VC_ACTIVE;
  1725. IF_EVENT(printk("ia open_tx returning \n");)
  1726. return 0;
  1727. }
  1728. static int tx_init(struct atm_dev *dev)
  1729. {
  1730. IADEV *iadev;
  1731. struct tx_buf_desc *buf_desc_ptr;
  1732. unsigned int tx_pkt_start;
  1733. void *dle_addr;
  1734. int i;
  1735. u_short tcq_st_adr;
  1736. u_short *tcq_start;
  1737. u_short prq_st_adr;
  1738. u_short *prq_start;
  1739. struct main_vc *vc;
  1740. struct ext_vc *evc;
  1741. u_short tmp16;
  1742. u32 vcsize_sel;
  1743. iadev = INPH_IA_DEV(dev);
  1744. spin_lock_init(&iadev->tx_lock);
  1745. IF_INIT(printk("Tx MASK REG: 0x%0x\n",
  1746. readw(iadev->seg_reg+SEG_MASK_REG));)
  1747. /* Allocate 4k (boundary aligned) bytes */
  1748. dle_addr = dma_alloc_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE,
  1749. &iadev->tx_dle_dma, GFP_KERNEL);
  1750. if (!dle_addr) {
  1751. printk(KERN_ERR DEV_LABEL "can't allocate DLEs\n");
  1752. goto err_out;
  1753. }
  1754. iadev->tx_dle_q.start = (struct dle*)dle_addr;
  1755. iadev->tx_dle_q.read = iadev->tx_dle_q.start;
  1756. iadev->tx_dle_q.write = iadev->tx_dle_q.start;
  1757. iadev->tx_dle_q.end = (struct dle*)((unsigned long)dle_addr+sizeof(struct dle)*DLE_ENTRIES);
  1758. /* write the upper 20 bits of the start address to tx list address register */
  1759. writel(iadev->tx_dle_dma & 0xfffff000,
  1760. iadev->dma + IPHASE5575_TX_LIST_ADDR);
  1761. writew(0xffff, iadev->seg_reg+SEG_MASK_REG);
  1762. writew(0, iadev->seg_reg+MODE_REG_0);
  1763. writew(RESET_SEG, iadev->seg_reg+SEG_COMMAND_REG);
  1764. iadev->MAIN_VC_TABLE_ADDR = iadev->seg_ram+MAIN_VC_TABLE*iadev->memSize;
  1765. iadev->EXT_VC_TABLE_ADDR = iadev->seg_ram+EXT_VC_TABLE*iadev->memSize;
  1766. iadev->ABR_SCHED_TABLE_ADDR=iadev->seg_ram+ABR_SCHED_TABLE*iadev->memSize;
  1767. /*
  1768. Transmit side control memory map
  1769. --------------------------------
  1770. Buffer descr 0x0000 (128 - 4K)
  1771. Commn queues 0x1000 Transmit comp, Packet ready(0x1400)
  1772. (512 - 1K) each
  1773. TCQ - 4K, PRQ - 5K
  1774. CBR Table 0x1800 (as needed) - 6K
  1775. UBR Table 0x3000 (1K - 4K) - 12K
  1776. UBR Wait queue 0x4000 (1K - 4K) - 16K
  1777. ABR sched 0x5000 and ABR wait queue (1K - 2K) each
  1778. ABR Tbl - 20K, ABR Wq - 22K
  1779. extended VC 0x6000 (1K - 8K) - 24K
  1780. VC Table 0x8000 (1K - 32K) - 32K
  1781. Between 0x2000 (8K) and 0x3000 (12K) there is 4K space left for VBR Tbl
  1782. and Wait q, which can be allotted later.
  1783. */
  1784. /* Buffer Descriptor Table Base address */
  1785. writew(TX_DESC_BASE, iadev->seg_reg+SEG_DESC_BASE);
  1786. /* initialize each entry in the buffer descriptor table */
  1787. buf_desc_ptr =(struct tx_buf_desc *)(iadev->seg_ram+TX_DESC_BASE);
  1788. memset((caddr_t)buf_desc_ptr, 0, sizeof(*buf_desc_ptr));
  1789. buf_desc_ptr++;
  1790. tx_pkt_start = TX_PACKET_RAM;
  1791. for(i=1; i<=iadev->num_tx_desc; i++)
  1792. {
  1793. memset((caddr_t)buf_desc_ptr, 0, sizeof(*buf_desc_ptr));
  1794. buf_desc_ptr->desc_mode = AAL5;
  1795. buf_desc_ptr->buf_start_hi = tx_pkt_start >> 16;
  1796. buf_desc_ptr->buf_start_lo = tx_pkt_start & 0x0000ffff;
  1797. buf_desc_ptr++;
  1798. tx_pkt_start += iadev->tx_buf_sz;
  1799. }
  1800. iadev->tx_buf = kmalloc_array(iadev->num_tx_desc,
  1801. sizeof(*iadev->tx_buf),
  1802. GFP_KERNEL);
  1803. if (!iadev->tx_buf) {
  1804. printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
  1805. goto err_free_dle;
  1806. }
  1807. for (i= 0; i< iadev->num_tx_desc; i++)
  1808. {
  1809. struct cpcs_trailer *cpcs;
  1810. cpcs = kmalloc(sizeof(*cpcs), GFP_KERNEL|GFP_DMA);
  1811. if(!cpcs) {
  1812. printk(KERN_ERR DEV_LABEL " couldn't get freepage\n");
  1813. goto err_free_tx_bufs;
  1814. }
  1815. iadev->tx_buf[i].cpcs = cpcs;
  1816. iadev->tx_buf[i].dma_addr = dma_map_single(&iadev->pci->dev,
  1817. cpcs,
  1818. sizeof(*cpcs),
  1819. DMA_TO_DEVICE);
  1820. }
  1821. iadev->desc_tbl = kmalloc_array(iadev->num_tx_desc,
  1822. sizeof(*iadev->desc_tbl),
  1823. GFP_KERNEL);
  1824. if (!iadev->desc_tbl) {
  1825. printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
  1826. goto err_free_all_tx_bufs;
  1827. }
  1828. /* Communication Queues base address */
  1829. i = TX_COMP_Q * iadev->memSize;
  1830. writew(i >> 16, iadev->seg_reg+SEG_QUEUE_BASE);
  1831. /* Transmit Complete Queue */
  1832. writew(i, iadev->seg_reg+TCQ_ST_ADR);
  1833. writew(i, iadev->seg_reg+TCQ_RD_PTR);
  1834. writew(i+iadev->num_tx_desc*sizeof(u_short),iadev->seg_reg+TCQ_WR_PTR);
  1835. iadev->host_tcq_wr = i + iadev->num_tx_desc*sizeof(u_short);
  1836. writew(i+2 * iadev->num_tx_desc * sizeof(u_short),
  1837. iadev->seg_reg+TCQ_ED_ADR);
  1838. /* Fill the TCQ with all the free descriptors. */
  1839. tcq_st_adr = readw(iadev->seg_reg+TCQ_ST_ADR);
  1840. tcq_start = (u_short *)(iadev->seg_ram+tcq_st_adr);
  1841. for(i=1; i<=iadev->num_tx_desc; i++)
  1842. {
  1843. *tcq_start = (u_short)i;
  1844. tcq_start++;
  1845. }
  1846. /* Packet Ready Queue */
  1847. i = PKT_RDY_Q * iadev->memSize;
  1848. writew(i, iadev->seg_reg+PRQ_ST_ADR);
  1849. writew(i+2 * iadev->num_tx_desc * sizeof(u_short),
  1850. iadev->seg_reg+PRQ_ED_ADR);
  1851. writew(i, iadev->seg_reg+PRQ_RD_PTR);
  1852. writew(i, iadev->seg_reg+PRQ_WR_PTR);
  1853. /* Load local copy of PRQ and TCQ ptrs */
  1854. iadev->ffL.prq_st = readw(iadev->seg_reg+PRQ_ST_ADR) & 0xffff;
  1855. iadev->ffL.prq_ed = readw(iadev->seg_reg+PRQ_ED_ADR) & 0xffff;
  1856. iadev->ffL.prq_wr = readw(iadev->seg_reg+PRQ_WR_PTR) & 0xffff;
  1857. iadev->ffL.tcq_st = readw(iadev->seg_reg+TCQ_ST_ADR) & 0xffff;
  1858. iadev->ffL.tcq_ed = readw(iadev->seg_reg+TCQ_ED_ADR) & 0xffff;
  1859. iadev->ffL.tcq_rd = readw(iadev->seg_reg+TCQ_RD_PTR) & 0xffff;
  1860. /* Just for safety initializing the queue to have desc 1 always */
  1861. /* Fill the PRQ with all the free descriptors. */
  1862. prq_st_adr = readw(iadev->seg_reg+PRQ_ST_ADR);
  1863. prq_start = (u_short *)(iadev->seg_ram+prq_st_adr);
  1864. for(i=1; i<=iadev->num_tx_desc; i++)
  1865. {
  1866. *prq_start = (u_short)0; /* desc 1 in all entries */
  1867. prq_start++;
  1868. }
  1869. /* CBR Table */
  1870. IF_INIT(printk("Start CBR Init\n");)
  1871. #if 1 /* for 1K VC board, CBR_PTR_BASE is 0 */
  1872. writew(0,iadev->seg_reg+CBR_PTR_BASE);
  1873. #else /* Charlie's logic is wrong ? */
  1874. tmp16 = (iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize)>>17;
  1875. IF_INIT(printk("cbr_ptr_base = 0x%x ", tmp16);)
  1876. writew(tmp16,iadev->seg_reg+CBR_PTR_BASE);
  1877. #endif
  1878. IF_INIT(printk("value in register = 0x%x\n",
  1879. readw(iadev->seg_reg+CBR_PTR_BASE));)
  1880. tmp16 = (CBR_SCHED_TABLE*iadev->memSize) >> 1;
  1881. writew(tmp16, iadev->seg_reg+CBR_TAB_BEG);
  1882. IF_INIT(printk("cbr_tab_beg = 0x%x in reg = 0x%x \n", tmp16,
  1883. readw(iadev->seg_reg+CBR_TAB_BEG));)
  1884. writew(tmp16, iadev->seg_reg+CBR_TAB_END+1); // CBR_PTR;
  1885. tmp16 = (CBR_SCHED_TABLE*iadev->memSize + iadev->num_vc*6 - 2) >> 1;
  1886. writew(tmp16, iadev->seg_reg+CBR_TAB_END);
  1887. IF_INIT(printk("iadev->seg_reg = 0x%p CBR_PTR_BASE = 0x%x\n",
  1888. iadev->seg_reg, readw(iadev->seg_reg+CBR_PTR_BASE));)
  1889. IF_INIT(printk("CBR_TAB_BEG = 0x%x, CBR_TAB_END = 0x%x, CBR_PTR = 0x%x\n",
  1890. readw(iadev->seg_reg+CBR_TAB_BEG), readw(iadev->seg_reg+CBR_TAB_END),
  1891. readw(iadev->seg_reg+CBR_TAB_END+1));)
  1892. /* Initialize the CBR Schedualing Table */
  1893. memset_io(iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize,
  1894. 0, iadev->num_vc*6);
  1895. iadev->CbrRemEntries = iadev->CbrTotEntries = iadev->num_vc*3;
  1896. iadev->CbrEntryPt = 0;
  1897. iadev->Granularity = MAX_ATM_155 / iadev->CbrTotEntries;
  1898. iadev->NumEnabledCBR = 0;
  1899. /* UBR scheduling Table and wait queue */
  1900. /* initialize all bytes of UBR scheduler table and wait queue to 0
  1901. - SCHEDSZ is 1K (# of entries).
  1902. - UBR Table size is 4K
  1903. - UBR wait queue is 4K
  1904. since the table and wait queues are contiguous, all the bytes
  1905. can be initialized by one memeset.
  1906. */
  1907. vcsize_sel = 0;
  1908. i = 8*1024;
  1909. while (i != iadev->num_vc) {
  1910. i /= 2;
  1911. vcsize_sel++;
  1912. }
  1913. i = MAIN_VC_TABLE * iadev->memSize;
  1914. writew(vcsize_sel | ((i >> 8) & 0xfff8),iadev->seg_reg+VCT_BASE);
  1915. i = EXT_VC_TABLE * iadev->memSize;
  1916. writew((i >> 8) & 0xfffe, iadev->seg_reg+VCTE_BASE);
  1917. i = UBR_SCHED_TABLE * iadev->memSize;
  1918. writew((i & 0xffff) >> 11, iadev->seg_reg+UBR_SBPTR_BASE);
  1919. i = UBR_WAIT_Q * iadev->memSize;
  1920. writew((i >> 7) & 0xffff, iadev->seg_reg+UBRWQ_BASE);
  1921. memset((caddr_t)(iadev->seg_ram+UBR_SCHED_TABLE*iadev->memSize),
  1922. 0, iadev->num_vc*8);
  1923. /* ABR scheduling Table(0x5000-0x57ff) and wait queue(0x5800-0x5fff)*/
  1924. /* initialize all bytes of ABR scheduler table and wait queue to 0
  1925. - SCHEDSZ is 1K (# of entries).
  1926. - ABR Table size is 2K
  1927. - ABR wait queue is 2K
  1928. since the table and wait queues are contiguous, all the bytes
  1929. can be initialized by one memeset.
  1930. */
  1931. i = ABR_SCHED_TABLE * iadev->memSize;
  1932. writew((i >> 11) & 0xffff, iadev->seg_reg+ABR_SBPTR_BASE);
  1933. i = ABR_WAIT_Q * iadev->memSize;
  1934. writew((i >> 7) & 0xffff, iadev->seg_reg+ABRWQ_BASE);
  1935. i = ABR_SCHED_TABLE*iadev->memSize;
  1936. memset((caddr_t)(iadev->seg_ram+i), 0, iadev->num_vc*4);
  1937. vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR;
  1938. evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR;
  1939. iadev->testTable = kmalloc_array(iadev->num_vc,
  1940. sizeof(*iadev->testTable),
  1941. GFP_KERNEL);
  1942. if (!iadev->testTable) {
  1943. printk("Get freepage failed\n");
  1944. goto err_free_desc_tbl;
  1945. }
  1946. for(i=0; i<iadev->num_vc; i++)
  1947. {
  1948. memset((caddr_t)vc, 0, sizeof(*vc));
  1949. memset((caddr_t)evc, 0, sizeof(*evc));
  1950. iadev->testTable[i] = kmalloc(sizeof(struct testTable_t),
  1951. GFP_KERNEL);
  1952. if (!iadev->testTable[i])
  1953. goto err_free_test_tables;
  1954. iadev->testTable[i]->lastTime = 0;
  1955. iadev->testTable[i]->fract = 0;
  1956. iadev->testTable[i]->vc_status = VC_UBR;
  1957. vc++;
  1958. evc++;
  1959. }
  1960. /* Other Initialization */
  1961. /* Max Rate Register */
  1962. if (iadev->phy_type & FE_25MBIT_PHY) {
  1963. writew(RATE25, iadev->seg_reg+MAXRATE);
  1964. writew((UBR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS);
  1965. }
  1966. else {
  1967. writew(cellrate_to_float(iadev->LineRate),iadev->seg_reg+MAXRATE);
  1968. writew((UBR_EN | ABR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS);
  1969. }
  1970. /* Set Idle Header Reigisters to be sure */
  1971. writew(0, iadev->seg_reg+IDLEHEADHI);
  1972. writew(0, iadev->seg_reg+IDLEHEADLO);
  1973. /* Program ABR UBR Priority Register as PRI_ABR_UBR_EQUAL */
  1974. writew(0xaa00, iadev->seg_reg+ABRUBR_ARB);
  1975. iadev->close_pending = 0;
  1976. init_waitqueue_head(&iadev->close_wait);
  1977. init_waitqueue_head(&iadev->timeout_wait);
  1978. skb_queue_head_init(&iadev->tx_dma_q);
  1979. ia_init_rtn_q(&iadev->tx_return_q);
  1980. /* RM Cell Protocol ID and Message Type */
  1981. writew(RM_TYPE_4_0, iadev->seg_reg+RM_TYPE);
  1982. skb_queue_head_init (&iadev->tx_backlog);
  1983. /* Mode Register 1 */
  1984. writew(MODE_REG_1_VAL, iadev->seg_reg+MODE_REG_1);
  1985. /* Mode Register 0 */
  1986. writew(T_ONLINE, iadev->seg_reg+MODE_REG_0);
  1987. /* Interrupt Status Register - read to clear */
  1988. readw(iadev->seg_reg+SEG_INTR_STATUS_REG);
  1989. /* Interrupt Mask Reg- don't mask TCQ_NOT_EMPTY interrupt generation */
  1990. writew(~(TRANSMIT_DONE | TCQ_NOT_EMPTY), iadev->seg_reg+SEG_MASK_REG);
  1991. writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
  1992. iadev->tx_pkt_cnt = 0;
  1993. iadev->rate_limit = iadev->LineRate / 3;
  1994. return 0;
  1995. err_free_test_tables:
  1996. while (--i >= 0)
  1997. kfree(iadev->testTable[i]);
  1998. kfree(iadev->testTable);
  1999. err_free_desc_tbl:
  2000. kfree(iadev->desc_tbl);
  2001. err_free_all_tx_bufs:
  2002. i = iadev->num_tx_desc;
  2003. err_free_tx_bufs:
  2004. while (--i >= 0) {
  2005. struct cpcs_trailer_desc *desc = iadev->tx_buf + i;
  2006. dma_unmap_single(&iadev->pci->dev, desc->dma_addr,
  2007. sizeof(*desc->cpcs), DMA_TO_DEVICE);
  2008. kfree(desc->cpcs);
  2009. }
  2010. kfree(iadev->tx_buf);
  2011. err_free_dle:
  2012. dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->tx_dle_q.start,
  2013. iadev->tx_dle_dma);
  2014. err_out:
  2015. return -ENOMEM;
  2016. }
  2017. static irqreturn_t ia_int(int irq, void *dev_id)
  2018. {
  2019. struct atm_dev *dev;
  2020. IADEV *iadev;
  2021. unsigned int status;
  2022. int handled = 0;
  2023. dev = dev_id;
  2024. iadev = INPH_IA_DEV(dev);
  2025. while( (status = readl(iadev->reg+IPHASE5575_BUS_STATUS_REG) & 0x7f))
  2026. {
  2027. handled = 1;
  2028. IF_EVENT(printk("ia_int: status = 0x%x\n", status);)
  2029. if (status & STAT_REASSINT)
  2030. {
  2031. /* do something */
  2032. IF_EVENT(printk("REASSINT Bus status reg: %08x\n", status);)
  2033. rx_intr(dev);
  2034. }
  2035. if (status & STAT_DLERINT)
  2036. {
  2037. /* Clear this bit by writing a 1 to it. */
  2038. writel(STAT_DLERINT, iadev->reg + IPHASE5575_BUS_STATUS_REG);
  2039. rx_dle_intr(dev);
  2040. }
  2041. if (status & STAT_SEGINT)
  2042. {
  2043. /* do something */
  2044. IF_EVENT(printk("IA: tx_intr \n");)
  2045. tx_intr(dev);
  2046. }
  2047. if (status & STAT_DLETINT)
  2048. {
  2049. writel(STAT_DLETINT, iadev->reg + IPHASE5575_BUS_STATUS_REG);
  2050. tx_dle_intr(dev);
  2051. }
  2052. if (status & (STAT_FEINT | STAT_ERRINT | STAT_MARKINT))
  2053. {
  2054. if (status & STAT_FEINT)
  2055. ia_frontend_intr(iadev);
  2056. }
  2057. }
  2058. return IRQ_RETVAL(handled);
  2059. }
  2060. /*----------------------------- entries --------------------------------*/
  2061. static int get_esi(struct atm_dev *dev)
  2062. {
  2063. IADEV *iadev;
  2064. int i;
  2065. u32 mac1;
  2066. u16 mac2;
  2067. iadev = INPH_IA_DEV(dev);
  2068. mac1 = cpu_to_be32(le32_to_cpu(readl(
  2069. iadev->reg+IPHASE5575_MAC1)));
  2070. mac2 = cpu_to_be16(le16_to_cpu(readl(iadev->reg+IPHASE5575_MAC2)));
  2071. IF_INIT(printk("ESI: 0x%08x%04x\n", mac1, mac2);)
  2072. for (i=0; i<MAC1_LEN; i++)
  2073. dev->esi[i] = mac1 >>(8*(MAC1_LEN-1-i));
  2074. for (i=0; i<MAC2_LEN; i++)
  2075. dev->esi[i+MAC1_LEN] = mac2 >>(8*(MAC2_LEN - 1 -i));
  2076. return 0;
  2077. }
  2078. static int reset_sar(struct atm_dev *dev)
  2079. {
  2080. IADEV *iadev;
  2081. int i, error = 1;
  2082. unsigned int pci[64];
  2083. iadev = INPH_IA_DEV(dev);
  2084. for(i=0; i<64; i++)
  2085. if ((error = pci_read_config_dword(iadev->pci,
  2086. i*4, &pci[i])) != PCIBIOS_SUCCESSFUL)
  2087. return error;
  2088. writel(0, iadev->reg+IPHASE5575_EXT_RESET);
  2089. for(i=0; i<64; i++)
  2090. if ((error = pci_write_config_dword(iadev->pci,
  2091. i*4, pci[i])) != PCIBIOS_SUCCESSFUL)
  2092. return error;
  2093. udelay(5);
  2094. return 0;
  2095. }
  2096. static int ia_init(struct atm_dev *dev)
  2097. {
  2098. IADEV *iadev;
  2099. unsigned long real_base;
  2100. void __iomem *base;
  2101. unsigned short command;
  2102. int error, i;
  2103. /* The device has been identified and registered. Now we read
  2104. necessary configuration info like memory base address,
  2105. interrupt number etc */
  2106. IF_INIT(printk(">ia_init\n");)
  2107. dev->ci_range.vpi_bits = 0;
  2108. dev->ci_range.vci_bits = NR_VCI_LD;
  2109. iadev = INPH_IA_DEV(dev);
  2110. real_base = pci_resource_start (iadev->pci, 0);
  2111. iadev->irq = iadev->pci->irq;
  2112. error = pci_read_config_word(iadev->pci, PCI_COMMAND, &command);
  2113. if (error) {
  2114. printk(KERN_ERR DEV_LABEL "(itf %d): init error 0x%x\n",
  2115. dev->number,error);
  2116. return -EINVAL;
  2117. }
  2118. IF_INIT(printk(DEV_LABEL "(itf %d): rev.%d,realbase=0x%lx,irq=%d\n",
  2119. dev->number, iadev->pci->revision, real_base, iadev->irq);)
  2120. /* find mapping size of board */
  2121. iadev->pci_map_size = pci_resource_len(iadev->pci, 0);
  2122. if (iadev->pci_map_size == 0x100000){
  2123. iadev->num_vc = 4096;
  2124. dev->ci_range.vci_bits = NR_VCI_4K_LD;
  2125. iadev->memSize = 4;
  2126. }
  2127. else if (iadev->pci_map_size == 0x40000) {
  2128. iadev->num_vc = 1024;
  2129. iadev->memSize = 1;
  2130. }
  2131. else {
  2132. printk("Unknown pci_map_size = 0x%x\n", iadev->pci_map_size);
  2133. return -EINVAL;
  2134. }
  2135. IF_INIT(printk (DEV_LABEL "map size: %i\n", iadev->pci_map_size);)
  2136. /* enable bus mastering */
  2137. pci_set_master(iadev->pci);
  2138. /*
  2139. * Delay at least 1us before doing any mem accesses (how 'bout 10?)
  2140. */
  2141. udelay(10);
  2142. /* mapping the physical address to a virtual address in address space */
  2143. base = ioremap(real_base,iadev->pci_map_size); /* ioremap is not resolved ??? */
  2144. if (!base)
  2145. {
  2146. printk(DEV_LABEL " (itf %d): can't set up page mapping\n",
  2147. dev->number);
  2148. return -ENOMEM;
  2149. }
  2150. IF_INIT(printk(DEV_LABEL " (itf %d): rev.%d,base=%p,irq=%d\n",
  2151. dev->number, iadev->pci->revision, base, iadev->irq);)
  2152. /* filling the iphase dev structure */
  2153. iadev->mem = iadev->pci_map_size /2;
  2154. iadev->real_base = real_base;
  2155. iadev->base = base;
  2156. /* Bus Interface Control Registers */
  2157. iadev->reg = base + REG_BASE;
  2158. /* Segmentation Control Registers */
  2159. iadev->seg_reg = base + SEG_BASE;
  2160. /* Reassembly Control Registers */
  2161. iadev->reass_reg = base + REASS_BASE;
  2162. /* Front end/ DMA control registers */
  2163. iadev->phy = base + PHY_BASE;
  2164. iadev->dma = base + PHY_BASE;
  2165. /* RAM - Segmentation RAm and Reassembly RAM */
  2166. iadev->ram = base + ACTUAL_RAM_BASE;
  2167. iadev->seg_ram = base + ACTUAL_SEG_RAM_BASE;
  2168. iadev->reass_ram = base + ACTUAL_REASS_RAM_BASE;
  2169. /* lets print out the above */
  2170. IF_INIT(printk("Base addrs: %p %p %p \n %p %p %p %p\n",
  2171. iadev->reg,iadev->seg_reg,iadev->reass_reg,
  2172. iadev->phy, iadev->ram, iadev->seg_ram,
  2173. iadev->reass_ram);)
  2174. /* lets try reading the MAC address */
  2175. error = get_esi(dev);
  2176. if (error) {
  2177. iounmap(iadev->base);
  2178. return error;
  2179. }
  2180. printk("IA: ");
  2181. for (i=0; i < ESI_LEN; i++)
  2182. printk("%s%02X",i ? "-" : "",dev->esi[i]);
  2183. printk("\n");
  2184. /* reset SAR */
  2185. if (reset_sar(dev)) {
  2186. iounmap(iadev->base);
  2187. printk("IA: reset SAR fail, please try again\n");
  2188. return 1;
  2189. }
  2190. return 0;
  2191. }
  2192. static void ia_update_stats(IADEV *iadev) {
  2193. if (!iadev->carrier_detect)
  2194. return;
  2195. iadev->rx_cell_cnt += readw(iadev->reass_reg+CELL_CTR0)&0xffff;
  2196. iadev->rx_cell_cnt += (readw(iadev->reass_reg+CELL_CTR1) & 0xffff) << 16;
  2197. iadev->drop_rxpkt += readw(iadev->reass_reg + DRP_PKT_CNTR ) & 0xffff;
  2198. iadev->drop_rxcell += readw(iadev->reass_reg + ERR_CNTR) & 0xffff;
  2199. iadev->tx_cell_cnt += readw(iadev->seg_reg + CELL_CTR_LO_AUTO)&0xffff;
  2200. iadev->tx_cell_cnt += (readw(iadev->seg_reg+CELL_CTR_HIGH_AUTO)&0xffff)<<16;
  2201. return;
  2202. }
  2203. static void ia_led_timer(unsigned long arg) {
  2204. unsigned long flags;
  2205. static u_char blinking[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  2206. u_char i;
  2207. static u32 ctrl_reg;
  2208. for (i = 0; i < iadev_count; i++) {
  2209. if (ia_dev[i]) {
  2210. ctrl_reg = readl(ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
  2211. if (blinking[i] == 0) {
  2212. blinking[i]++;
  2213. ctrl_reg &= (~CTRL_LED);
  2214. writel(ctrl_reg, ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
  2215. ia_update_stats(ia_dev[i]);
  2216. }
  2217. else {
  2218. blinking[i] = 0;
  2219. ctrl_reg |= CTRL_LED;
  2220. writel(ctrl_reg, ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
  2221. spin_lock_irqsave(&ia_dev[i]->tx_lock, flags);
  2222. if (ia_dev[i]->close_pending)
  2223. wake_up(&ia_dev[i]->close_wait);
  2224. ia_tx_poll(ia_dev[i]);
  2225. spin_unlock_irqrestore(&ia_dev[i]->tx_lock, flags);
  2226. }
  2227. }
  2228. }
  2229. mod_timer(&ia_timer, jiffies + HZ / 4);
  2230. return;
  2231. }
  2232. static void ia_phy_put(struct atm_dev *dev, unsigned char value,
  2233. unsigned long addr)
  2234. {
  2235. writel(value, INPH_IA_DEV(dev)->phy+addr);
  2236. }
  2237. static unsigned char ia_phy_get(struct atm_dev *dev, unsigned long addr)
  2238. {
  2239. return readl(INPH_IA_DEV(dev)->phy+addr);
  2240. }
  2241. static void ia_free_tx(IADEV *iadev)
  2242. {
  2243. int i;
  2244. kfree(iadev->desc_tbl);
  2245. for (i = 0; i < iadev->num_vc; i++)
  2246. kfree(iadev->testTable[i]);
  2247. kfree(iadev->testTable);
  2248. for (i = 0; i < iadev->num_tx_desc; i++) {
  2249. struct cpcs_trailer_desc *desc = iadev->tx_buf + i;
  2250. dma_unmap_single(&iadev->pci->dev, desc->dma_addr,
  2251. sizeof(*desc->cpcs), DMA_TO_DEVICE);
  2252. kfree(desc->cpcs);
  2253. }
  2254. kfree(iadev->tx_buf);
  2255. dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->tx_dle_q.start,
  2256. iadev->tx_dle_dma);
  2257. }
  2258. static void ia_free_rx(IADEV *iadev)
  2259. {
  2260. kfree(iadev->rx_open);
  2261. dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->rx_dle_q.start,
  2262. iadev->rx_dle_dma);
  2263. }
  2264. static int ia_start(struct atm_dev *dev)
  2265. {
  2266. IADEV *iadev;
  2267. int error;
  2268. unsigned char phy;
  2269. u32 ctrl_reg;
  2270. IF_EVENT(printk(">ia_start\n");)
  2271. iadev = INPH_IA_DEV(dev);
  2272. if (request_irq(iadev->irq, &ia_int, IRQF_SHARED, DEV_LABEL, dev)) {
  2273. printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n",
  2274. dev->number, iadev->irq);
  2275. error = -EAGAIN;
  2276. goto err_out;
  2277. }
  2278. /* @@@ should release IRQ on error */
  2279. /* enabling memory + master */
  2280. if ((error = pci_write_config_word(iadev->pci,
  2281. PCI_COMMAND,
  2282. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER )))
  2283. {
  2284. printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory+"
  2285. "master (0x%x)\n",dev->number, error);
  2286. error = -EIO;
  2287. goto err_free_irq;
  2288. }
  2289. udelay(10);
  2290. /* Maybe we should reset the front end, initialize Bus Interface Control
  2291. Registers and see. */
  2292. IF_INIT(printk("Bus ctrl reg: %08x\n",
  2293. readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));)
  2294. ctrl_reg = readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG);
  2295. ctrl_reg = (ctrl_reg & (CTRL_LED | CTRL_FE_RST))
  2296. | CTRL_B8
  2297. | CTRL_B16
  2298. | CTRL_B32
  2299. | CTRL_B48
  2300. | CTRL_B64
  2301. | CTRL_B128
  2302. | CTRL_ERRMASK
  2303. | CTRL_DLETMASK /* shud be removed l8r */
  2304. | CTRL_DLERMASK
  2305. | CTRL_SEGMASK
  2306. | CTRL_REASSMASK
  2307. | CTRL_FEMASK
  2308. | CTRL_CSPREEMPT;
  2309. writel(ctrl_reg, iadev->reg+IPHASE5575_BUS_CONTROL_REG);
  2310. IF_INIT(printk("Bus ctrl reg after initializing: %08x\n",
  2311. readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));
  2312. printk("Bus status reg after init: %08x\n",
  2313. readl(iadev->reg+IPHASE5575_BUS_STATUS_REG));)
  2314. ia_hw_type(iadev);
  2315. error = tx_init(dev);
  2316. if (error)
  2317. goto err_free_irq;
  2318. error = rx_init(dev);
  2319. if (error)
  2320. goto err_free_tx;
  2321. ctrl_reg = readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG);
  2322. writel(ctrl_reg | CTRL_FE_RST, iadev->reg+IPHASE5575_BUS_CONTROL_REG);
  2323. IF_INIT(printk("Bus ctrl reg after initializing: %08x\n",
  2324. readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));)
  2325. phy = 0; /* resolve compiler complaint */
  2326. IF_INIT (
  2327. if ((phy=ia_phy_get(dev,0)) == 0x30)
  2328. printk("IA: pm5346,rev.%d\n",phy&0x0f);
  2329. else
  2330. printk("IA: utopia,rev.%0x\n",phy);)
  2331. if (iadev->phy_type & FE_25MBIT_PHY)
  2332. ia_mb25_init(iadev);
  2333. else if (iadev->phy_type & (FE_DS3_PHY | FE_E3_PHY))
  2334. ia_suni_pm7345_init(iadev);
  2335. else {
  2336. error = suni_init(dev);
  2337. if (error)
  2338. goto err_free_rx;
  2339. if (dev->phy->start) {
  2340. error = dev->phy->start(dev);
  2341. if (error)
  2342. goto err_free_rx;
  2343. }
  2344. /* Get iadev->carrier_detect status */
  2345. ia_frontend_intr(iadev);
  2346. }
  2347. return 0;
  2348. err_free_rx:
  2349. ia_free_rx(iadev);
  2350. err_free_tx:
  2351. ia_free_tx(iadev);
  2352. err_free_irq:
  2353. free_irq(iadev->irq, dev);
  2354. err_out:
  2355. return error;
  2356. }
  2357. static void ia_close(struct atm_vcc *vcc)
  2358. {
  2359. DEFINE_WAIT(wait);
  2360. u16 *vc_table;
  2361. IADEV *iadev;
  2362. struct ia_vcc *ia_vcc;
  2363. struct sk_buff *skb = NULL;
  2364. struct sk_buff_head tmp_tx_backlog, tmp_vcc_backlog;
  2365. unsigned long closetime, flags;
  2366. iadev = INPH_IA_DEV(vcc->dev);
  2367. ia_vcc = INPH_IA_VCC(vcc);
  2368. if (!ia_vcc) return;
  2369. IF_EVENT(printk("ia_close: ia_vcc->vc_desc_cnt = %d vci = %d\n",
  2370. ia_vcc->vc_desc_cnt,vcc->vci);)
  2371. clear_bit(ATM_VF_READY,&vcc->flags);
  2372. skb_queue_head_init (&tmp_tx_backlog);
  2373. skb_queue_head_init (&tmp_vcc_backlog);
  2374. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  2375. iadev->close_pending++;
  2376. prepare_to_wait(&iadev->timeout_wait, &wait, TASK_UNINTERRUPTIBLE);
  2377. schedule_timeout(msecs_to_jiffies(500));
  2378. finish_wait(&iadev->timeout_wait, &wait);
  2379. spin_lock_irqsave(&iadev->tx_lock, flags);
  2380. while((skb = skb_dequeue(&iadev->tx_backlog))) {
  2381. if (ATM_SKB(skb)->vcc == vcc){
  2382. if (vcc->pop) vcc->pop(vcc, skb);
  2383. else dev_kfree_skb_any(skb);
  2384. }
  2385. else
  2386. skb_queue_tail(&tmp_tx_backlog, skb);
  2387. }
  2388. while((skb = skb_dequeue(&tmp_tx_backlog)))
  2389. skb_queue_tail(&iadev->tx_backlog, skb);
  2390. IF_EVENT(printk("IA TX Done decs_cnt = %d\n", ia_vcc->vc_desc_cnt);)
  2391. closetime = 300000 / ia_vcc->pcr;
  2392. if (closetime == 0)
  2393. closetime = 1;
  2394. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  2395. wait_event_timeout(iadev->close_wait, (ia_vcc->vc_desc_cnt <= 0), closetime);
  2396. spin_lock_irqsave(&iadev->tx_lock, flags);
  2397. iadev->close_pending--;
  2398. iadev->testTable[vcc->vci]->lastTime = 0;
  2399. iadev->testTable[vcc->vci]->fract = 0;
  2400. iadev->testTable[vcc->vci]->vc_status = VC_UBR;
  2401. if (vcc->qos.txtp.traffic_class == ATM_ABR) {
  2402. if (vcc->qos.txtp.min_pcr > 0)
  2403. iadev->sum_mcr -= vcc->qos.txtp.min_pcr;
  2404. }
  2405. if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  2406. ia_vcc = INPH_IA_VCC(vcc);
  2407. iadev->sum_mcr -= ia_vcc->NumCbrEntry*iadev->Granularity;
  2408. ia_cbrVc_close (vcc);
  2409. }
  2410. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  2411. }
  2412. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  2413. // reset reass table
  2414. vc_table = (u16 *)(iadev->reass_ram+REASS_TABLE*iadev->memSize);
  2415. vc_table += vcc->vci;
  2416. *vc_table = NO_AAL5_PKT;
  2417. // reset vc table
  2418. vc_table = (u16 *)(iadev->reass_ram+RX_VC_TABLE*iadev->memSize);
  2419. vc_table += vcc->vci;
  2420. *vc_table = (vcc->vci << 6) | 15;
  2421. if (vcc->qos.rxtp.traffic_class == ATM_ABR) {
  2422. struct abr_vc_table __iomem *abr_vc_table =
  2423. (iadev->reass_ram+ABR_VC_TABLE*iadev->memSize);
  2424. abr_vc_table += vcc->vci;
  2425. abr_vc_table->rdf = 0x0003;
  2426. abr_vc_table->air = 0x5eb1;
  2427. }
  2428. // Drain the packets
  2429. rx_dle_intr(vcc->dev);
  2430. iadev->rx_open[vcc->vci] = NULL;
  2431. }
  2432. kfree(INPH_IA_VCC(vcc));
  2433. ia_vcc = NULL;
  2434. vcc->dev_data = NULL;
  2435. clear_bit(ATM_VF_ADDR,&vcc->flags);
  2436. return;
  2437. }
  2438. static int ia_open(struct atm_vcc *vcc)
  2439. {
  2440. struct ia_vcc *ia_vcc;
  2441. int error;
  2442. if (!test_bit(ATM_VF_PARTIAL,&vcc->flags))
  2443. {
  2444. IF_EVENT(printk("ia: not partially allocated resources\n");)
  2445. vcc->dev_data = NULL;
  2446. }
  2447. if (vcc->vci != ATM_VPI_UNSPEC && vcc->vpi != ATM_VCI_UNSPEC)
  2448. {
  2449. IF_EVENT(printk("iphase open: unspec part\n");)
  2450. set_bit(ATM_VF_ADDR,&vcc->flags);
  2451. }
  2452. if (vcc->qos.aal != ATM_AAL5)
  2453. return -EINVAL;
  2454. IF_EVENT(printk(DEV_LABEL "(itf %d): open %d.%d\n",
  2455. vcc->dev->number, vcc->vpi, vcc->vci);)
  2456. /* Device dependent initialization */
  2457. ia_vcc = kmalloc(sizeof(*ia_vcc), GFP_KERNEL);
  2458. if (!ia_vcc) return -ENOMEM;
  2459. vcc->dev_data = ia_vcc;
  2460. if ((error = open_rx(vcc)))
  2461. {
  2462. IF_EVENT(printk("iadev: error in open_rx, closing\n");)
  2463. ia_close(vcc);
  2464. return error;
  2465. }
  2466. if ((error = open_tx(vcc)))
  2467. {
  2468. IF_EVENT(printk("iadev: error in open_tx, closing\n");)
  2469. ia_close(vcc);
  2470. return error;
  2471. }
  2472. set_bit(ATM_VF_READY,&vcc->flags);
  2473. #if 0
  2474. {
  2475. static u8 first = 1;
  2476. if (first) {
  2477. ia_timer.expires = jiffies + 3*HZ;
  2478. add_timer(&ia_timer);
  2479. first = 0;
  2480. }
  2481. }
  2482. #endif
  2483. IF_EVENT(printk("ia open returning\n");)
  2484. return 0;
  2485. }
  2486. static int ia_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags)
  2487. {
  2488. IF_EVENT(printk(">ia_change_qos\n");)
  2489. return 0;
  2490. }
  2491. static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
  2492. {
  2493. IA_CMDBUF ia_cmds;
  2494. IADEV *iadev;
  2495. int i, board;
  2496. u16 __user *tmps;
  2497. IF_EVENT(printk(">ia_ioctl\n");)
  2498. if (cmd != IA_CMD) {
  2499. if (!dev->phy->ioctl) return -EINVAL;
  2500. return dev->phy->ioctl(dev,cmd,arg);
  2501. }
  2502. if (copy_from_user(&ia_cmds, arg, sizeof ia_cmds)) return -EFAULT;
  2503. board = ia_cmds.status;
  2504. if ((board < 0) || (board > iadev_count))
  2505. board = 0;
  2506. iadev = ia_dev[board];
  2507. switch (ia_cmds.cmd) {
  2508. case MEMDUMP:
  2509. {
  2510. switch (ia_cmds.sub_cmd) {
  2511. case MEMDUMP_DEV:
  2512. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2513. if (copy_to_user(ia_cmds.buf, iadev, sizeof(IADEV)))
  2514. return -EFAULT;
  2515. ia_cmds.status = 0;
  2516. break;
  2517. case MEMDUMP_SEGREG:
  2518. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2519. tmps = (u16 __user *)ia_cmds.buf;
  2520. for(i=0; i<0x80; i+=2, tmps++)
  2521. if(put_user((u16)(readl(iadev->seg_reg+i) & 0xffff), tmps)) return -EFAULT;
  2522. ia_cmds.status = 0;
  2523. ia_cmds.len = 0x80;
  2524. break;
  2525. case MEMDUMP_REASSREG:
  2526. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2527. tmps = (u16 __user *)ia_cmds.buf;
  2528. for(i=0; i<0x80; i+=2, tmps++)
  2529. if(put_user((u16)(readl(iadev->reass_reg+i) & 0xffff), tmps)) return -EFAULT;
  2530. ia_cmds.status = 0;
  2531. ia_cmds.len = 0x80;
  2532. break;
  2533. case MEMDUMP_FFL:
  2534. {
  2535. ia_regs_t *regs_local;
  2536. ffredn_t *ffL;
  2537. rfredn_t *rfL;
  2538. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2539. regs_local = kmalloc(sizeof(*regs_local), GFP_KERNEL);
  2540. if (!regs_local) return -ENOMEM;
  2541. ffL = &regs_local->ffredn;
  2542. rfL = &regs_local->rfredn;
  2543. /* Copy real rfred registers into the local copy */
  2544. for (i=0; i<(sizeof (rfredn_t))/4; i++)
  2545. ((u_int *)rfL)[i] = readl(iadev->reass_reg + i) & 0xffff;
  2546. /* Copy real ffred registers into the local copy */
  2547. for (i=0; i<(sizeof (ffredn_t))/4; i++)
  2548. ((u_int *)ffL)[i] = readl(iadev->seg_reg + i) & 0xffff;
  2549. if (copy_to_user(ia_cmds.buf, regs_local,sizeof(ia_regs_t))) {
  2550. kfree(regs_local);
  2551. return -EFAULT;
  2552. }
  2553. kfree(regs_local);
  2554. printk("Board %d registers dumped\n", board);
  2555. ia_cmds.status = 0;
  2556. }
  2557. break;
  2558. case READ_REG:
  2559. {
  2560. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2561. desc_dbg(iadev);
  2562. ia_cmds.status = 0;
  2563. }
  2564. break;
  2565. case 0x6:
  2566. {
  2567. ia_cmds.status = 0;
  2568. printk("skb = 0x%lx\n", (long)skb_peek(&iadev->tx_backlog));
  2569. printk("rtn_q: 0x%lx\n",(long)ia_deque_rtn_q(&iadev->tx_return_q));
  2570. }
  2571. break;
  2572. case 0x8:
  2573. {
  2574. struct k_sonet_stats *stats;
  2575. stats = &PRIV(_ia_dev[board])->sonet_stats;
  2576. printk("section_bip: %d\n", atomic_read(&stats->section_bip));
  2577. printk("line_bip : %d\n", atomic_read(&stats->line_bip));
  2578. printk("path_bip : %d\n", atomic_read(&stats->path_bip));
  2579. printk("line_febe : %d\n", atomic_read(&stats->line_febe));
  2580. printk("path_febe : %d\n", atomic_read(&stats->path_febe));
  2581. printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
  2582. printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
  2583. printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
  2584. printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
  2585. }
  2586. ia_cmds.status = 0;
  2587. break;
  2588. case 0x9:
  2589. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2590. for (i = 1; i <= iadev->num_rx_desc; i++)
  2591. free_desc(_ia_dev[board], i);
  2592. writew( ~(RX_FREEQ_EMPT | RX_EXCP_RCVD),
  2593. iadev->reass_reg+REASS_MASK_REG);
  2594. iadev->rxing = 1;
  2595. ia_cmds.status = 0;
  2596. break;
  2597. case 0xb:
  2598. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2599. ia_frontend_intr(iadev);
  2600. break;
  2601. case 0xa:
  2602. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2603. {
  2604. ia_cmds.status = 0;
  2605. IADebugFlag = ia_cmds.maddr;
  2606. printk("New debug option loaded\n");
  2607. }
  2608. break;
  2609. default:
  2610. ia_cmds.status = 0;
  2611. break;
  2612. }
  2613. }
  2614. break;
  2615. default:
  2616. break;
  2617. }
  2618. return 0;
  2619. }
  2620. static int ia_getsockopt(struct atm_vcc *vcc, int level, int optname,
  2621. void __user *optval, int optlen)
  2622. {
  2623. IF_EVENT(printk(">ia_getsockopt\n");)
  2624. return -EINVAL;
  2625. }
  2626. static int ia_setsockopt(struct atm_vcc *vcc, int level, int optname,
  2627. void __user *optval, unsigned int optlen)
  2628. {
  2629. IF_EVENT(printk(">ia_setsockopt\n");)
  2630. return -EINVAL;
  2631. }
  2632. static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
  2633. IADEV *iadev;
  2634. struct dle *wr_ptr;
  2635. struct tx_buf_desc __iomem *buf_desc_ptr;
  2636. int desc;
  2637. int comp_code;
  2638. int total_len;
  2639. struct cpcs_trailer *trailer;
  2640. struct ia_vcc *iavcc;
  2641. iadev = INPH_IA_DEV(vcc->dev);
  2642. iavcc = INPH_IA_VCC(vcc);
  2643. if (!iavcc->txing) {
  2644. printk("discard packet on closed VC\n");
  2645. if (vcc->pop)
  2646. vcc->pop(vcc, skb);
  2647. else
  2648. dev_kfree_skb_any(skb);
  2649. return 0;
  2650. }
  2651. if (skb->len > iadev->tx_buf_sz - 8) {
  2652. printk("Transmit size over tx buffer size\n");
  2653. if (vcc->pop)
  2654. vcc->pop(vcc, skb);
  2655. else
  2656. dev_kfree_skb_any(skb);
  2657. return 0;
  2658. }
  2659. if ((unsigned long)skb->data & 3) {
  2660. printk("Misaligned SKB\n");
  2661. if (vcc->pop)
  2662. vcc->pop(vcc, skb);
  2663. else
  2664. dev_kfree_skb_any(skb);
  2665. return 0;
  2666. }
  2667. /* Get a descriptor number from our free descriptor queue
  2668. We get the descr number from the TCQ now, since I am using
  2669. the TCQ as a free buffer queue. Initially TCQ will be
  2670. initialized with all the descriptors and is hence, full.
  2671. */
  2672. desc = get_desc (iadev, iavcc);
  2673. if (desc == 0xffff)
  2674. return 1;
  2675. comp_code = desc >> 13;
  2676. desc &= 0x1fff;
  2677. if ((desc == 0) || (desc > iadev->num_tx_desc))
  2678. {
  2679. IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
  2680. atomic_inc(&vcc->stats->tx);
  2681. if (vcc->pop)
  2682. vcc->pop(vcc, skb);
  2683. else
  2684. dev_kfree_skb_any(skb);
  2685. return 0; /* return SUCCESS */
  2686. }
  2687. if (comp_code)
  2688. {
  2689. IF_ERR(printk(DEV_LABEL "send desc:%d completion code %d error\n",
  2690. desc, comp_code);)
  2691. }
  2692. /* remember the desc and vcc mapping */
  2693. iavcc->vc_desc_cnt++;
  2694. iadev->desc_tbl[desc-1].iavcc = iavcc;
  2695. iadev->desc_tbl[desc-1].txskb = skb;
  2696. IA_SKB_STATE(skb) = 0;
  2697. iadev->ffL.tcq_rd += 2;
  2698. if (iadev->ffL.tcq_rd > iadev->ffL.tcq_ed)
  2699. iadev->ffL.tcq_rd = iadev->ffL.tcq_st;
  2700. writew(iadev->ffL.tcq_rd, iadev->seg_reg+TCQ_RD_PTR);
  2701. /* Put the descriptor number in the packet ready queue
  2702. and put the updated write pointer in the DLE field
  2703. */
  2704. *(u16*)(iadev->seg_ram+iadev->ffL.prq_wr) = desc;
  2705. iadev->ffL.prq_wr += 2;
  2706. if (iadev->ffL.prq_wr > iadev->ffL.prq_ed)
  2707. iadev->ffL.prq_wr = iadev->ffL.prq_st;
  2708. /* Figure out the exact length of the packet and padding required to
  2709. make it aligned on a 48 byte boundary. */
  2710. total_len = skb->len + sizeof(struct cpcs_trailer);
  2711. total_len = ((total_len + 47) / 48) * 48;
  2712. IF_TX(printk("ia packet len:%d padding:%d\n", total_len, total_len - skb->len);)
  2713. /* Put the packet in a tx buffer */
  2714. trailer = iadev->tx_buf[desc-1].cpcs;
  2715. IF_TX(printk("Sent: skb = 0x%p skb->data: 0x%p len: %d, desc: %d\n",
  2716. skb, skb->data, skb->len, desc);)
  2717. trailer->control = 0;
  2718. /*big endian*/
  2719. trailer->length = ((skb->len & 0xff) << 8) | ((skb->len & 0xff00) >> 8);
  2720. trailer->crc32 = 0; /* not needed - dummy bytes */
  2721. /* Display the packet */
  2722. IF_TXPKT(printk("Sent data: len = %d MsgNum = %d\n",
  2723. skb->len, tcnter++);
  2724. xdump(skb->data, skb->len, "TX: ");
  2725. printk("\n");)
  2726. /* Build the buffer descriptor */
  2727. buf_desc_ptr = iadev->seg_ram+TX_DESC_BASE;
  2728. buf_desc_ptr += desc; /* points to the corresponding entry */
  2729. buf_desc_ptr->desc_mode = AAL5 | EOM_EN | APP_CRC32 | CMPL_INT;
  2730. /* Huh ? p.115 of users guide describes this as a read-only register */
  2731. writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
  2732. buf_desc_ptr->vc_index = vcc->vci;
  2733. buf_desc_ptr->bytes = total_len;
  2734. if (vcc->qos.txtp.traffic_class == ATM_ABR)
  2735. clear_lockup (vcc, iadev);
  2736. /* Build the DLE structure */
  2737. wr_ptr = iadev->tx_dle_q.write;
  2738. memset((caddr_t)wr_ptr, 0, sizeof(*wr_ptr));
  2739. wr_ptr->sys_pkt_addr = dma_map_single(&iadev->pci->dev, skb->data,
  2740. skb->len, DMA_TO_DEVICE);
  2741. wr_ptr->local_pkt_addr = (buf_desc_ptr->buf_start_hi << 16) |
  2742. buf_desc_ptr->buf_start_lo;
  2743. /* wr_ptr->bytes = swap_byte_order(total_len); didn't seem to affect?? */
  2744. wr_ptr->bytes = skb->len;
  2745. /* hw bug - DLEs of 0x2d, 0x2e, 0x2f cause DMA lockup */
  2746. if ((wr_ptr->bytes >> 2) == 0xb)
  2747. wr_ptr->bytes = 0x30;
  2748. wr_ptr->mode = TX_DLE_PSI;
  2749. wr_ptr->prq_wr_ptr_data = 0;
  2750. /* end is not to be used for the DLE q */
  2751. if (++wr_ptr == iadev->tx_dle_q.end)
  2752. wr_ptr = iadev->tx_dle_q.start;
  2753. /* Build trailer dle */
  2754. wr_ptr->sys_pkt_addr = iadev->tx_buf[desc-1].dma_addr;
  2755. wr_ptr->local_pkt_addr = ((buf_desc_ptr->buf_start_hi << 16) |
  2756. buf_desc_ptr->buf_start_lo) + total_len - sizeof(struct cpcs_trailer);
  2757. wr_ptr->bytes = sizeof(struct cpcs_trailer);
  2758. wr_ptr->mode = DMA_INT_ENABLE;
  2759. wr_ptr->prq_wr_ptr_data = iadev->ffL.prq_wr;
  2760. /* end is not to be used for the DLE q */
  2761. if (++wr_ptr == iadev->tx_dle_q.end)
  2762. wr_ptr = iadev->tx_dle_q.start;
  2763. iadev->tx_dle_q.write = wr_ptr;
  2764. ATM_DESC(skb) = vcc->vci;
  2765. skb_queue_tail(&iadev->tx_dma_q, skb);
  2766. atomic_inc(&vcc->stats->tx);
  2767. iadev->tx_pkt_cnt++;
  2768. /* Increment transaction counter */
  2769. writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
  2770. #if 0
  2771. /* add flow control logic */
  2772. if (atomic_read(&vcc->stats->tx) % 20 == 0) {
  2773. if (iavcc->vc_desc_cnt > 10) {
  2774. vcc->tx_quota = vcc->tx_quota * 3 / 4;
  2775. printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
  2776. iavcc->flow_inc = -1;
  2777. iavcc->saved_tx_quota = vcc->tx_quota;
  2778. } else if ((iavcc->flow_inc < 0) && (iavcc->vc_desc_cnt < 3)) {
  2779. // vcc->tx_quota = 3 * iavcc->saved_tx_quota / 4;
  2780. printk("Tx2: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
  2781. iavcc->flow_inc = 0;
  2782. }
  2783. }
  2784. #endif
  2785. IF_TX(printk("ia send done\n");)
  2786. return 0;
  2787. }
  2788. static int ia_send(struct atm_vcc *vcc, struct sk_buff *skb)
  2789. {
  2790. IADEV *iadev;
  2791. unsigned long flags;
  2792. iadev = INPH_IA_DEV(vcc->dev);
  2793. if ((!skb)||(skb->len>(iadev->tx_buf_sz-sizeof(struct cpcs_trailer))))
  2794. {
  2795. if (!skb)
  2796. printk(KERN_CRIT "null skb in ia_send\n");
  2797. else dev_kfree_skb_any(skb);
  2798. return -EINVAL;
  2799. }
  2800. spin_lock_irqsave(&iadev->tx_lock, flags);
  2801. if (!test_bit(ATM_VF_READY,&vcc->flags)){
  2802. dev_kfree_skb_any(skb);
  2803. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  2804. return -EINVAL;
  2805. }
  2806. ATM_SKB(skb)->vcc = vcc;
  2807. if (skb_peek(&iadev->tx_backlog)) {
  2808. skb_queue_tail(&iadev->tx_backlog, skb);
  2809. }
  2810. else {
  2811. if (ia_pkt_tx (vcc, skb)) {
  2812. skb_queue_tail(&iadev->tx_backlog, skb);
  2813. }
  2814. }
  2815. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  2816. return 0;
  2817. }
  2818. static int ia_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
  2819. {
  2820. int left = *pos, n;
  2821. char *tmpPtr;
  2822. IADEV *iadev = INPH_IA_DEV(dev);
  2823. if(!left--) {
  2824. if (iadev->phy_type == FE_25MBIT_PHY) {
  2825. n = sprintf(page, " Board Type : Iphase5525-1KVC-128K\n");
  2826. return n;
  2827. }
  2828. if (iadev->phy_type == FE_DS3_PHY)
  2829. n = sprintf(page, " Board Type : Iphase-ATM-DS3");
  2830. else if (iadev->phy_type == FE_E3_PHY)
  2831. n = sprintf(page, " Board Type : Iphase-ATM-E3");
  2832. else if (iadev->phy_type == FE_UTP_OPTION)
  2833. n = sprintf(page, " Board Type : Iphase-ATM-UTP155");
  2834. else
  2835. n = sprintf(page, " Board Type : Iphase-ATM-OC3");
  2836. tmpPtr = page + n;
  2837. if (iadev->pci_map_size == 0x40000)
  2838. n += sprintf(tmpPtr, "-1KVC-");
  2839. else
  2840. n += sprintf(tmpPtr, "-4KVC-");
  2841. tmpPtr = page + n;
  2842. if ((iadev->memType & MEM_SIZE_MASK) == MEM_SIZE_1M)
  2843. n += sprintf(tmpPtr, "1M \n");
  2844. else if ((iadev->memType & MEM_SIZE_MASK) == MEM_SIZE_512K)
  2845. n += sprintf(tmpPtr, "512K\n");
  2846. else
  2847. n += sprintf(tmpPtr, "128K\n");
  2848. return n;
  2849. }
  2850. if (!left) {
  2851. return sprintf(page, " Number of Tx Buffer: %u\n"
  2852. " Size of Tx Buffer : %u\n"
  2853. " Number of Rx Buffer: %u\n"
  2854. " Size of Rx Buffer : %u\n"
  2855. " Packets Receiverd : %u\n"
  2856. " Packets Transmitted: %u\n"
  2857. " Cells Received : %u\n"
  2858. " Cells Transmitted : %u\n"
  2859. " Board Dropped Cells: %u\n"
  2860. " Board Dropped Pkts : %u\n",
  2861. iadev->num_tx_desc, iadev->tx_buf_sz,
  2862. iadev->num_rx_desc, iadev->rx_buf_sz,
  2863. iadev->rx_pkt_cnt, iadev->tx_pkt_cnt,
  2864. iadev->rx_cell_cnt, iadev->tx_cell_cnt,
  2865. iadev->drop_rxcell, iadev->drop_rxpkt);
  2866. }
  2867. return 0;
  2868. }
  2869. static const struct atmdev_ops ops = {
  2870. .open = ia_open,
  2871. .close = ia_close,
  2872. .ioctl = ia_ioctl,
  2873. .getsockopt = ia_getsockopt,
  2874. .setsockopt = ia_setsockopt,
  2875. .send = ia_send,
  2876. .phy_put = ia_phy_put,
  2877. .phy_get = ia_phy_get,
  2878. .change_qos = ia_change_qos,
  2879. .proc_read = ia_proc_read,
  2880. .owner = THIS_MODULE,
  2881. };
  2882. static int ia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  2883. {
  2884. struct atm_dev *dev;
  2885. IADEV *iadev;
  2886. int ret;
  2887. iadev = kzalloc(sizeof(*iadev), GFP_KERNEL);
  2888. if (!iadev) {
  2889. ret = -ENOMEM;
  2890. goto err_out;
  2891. }
  2892. iadev->pci = pdev;
  2893. IF_INIT(printk("ia detected at bus:%d dev: %d function:%d\n",
  2894. pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));)
  2895. if (pci_enable_device(pdev)) {
  2896. ret = -ENODEV;
  2897. goto err_out_free_iadev;
  2898. }
  2899. dev = atm_dev_register(DEV_LABEL, &pdev->dev, &ops, -1, NULL);
  2900. if (!dev) {
  2901. ret = -ENOMEM;
  2902. goto err_out_disable_dev;
  2903. }
  2904. dev->dev_data = iadev;
  2905. IF_INIT(printk(DEV_LABEL "registered at (itf :%d)\n", dev->number);)
  2906. IF_INIT(printk("dev_id = 0x%p iadev->LineRate = %d \n", dev,
  2907. iadev->LineRate);)
  2908. pci_set_drvdata(pdev, dev);
  2909. ia_dev[iadev_count] = iadev;
  2910. _ia_dev[iadev_count] = dev;
  2911. iadev_count++;
  2912. if (ia_init(dev) || ia_start(dev)) {
  2913. IF_INIT(printk("IA register failed!\n");)
  2914. iadev_count--;
  2915. ia_dev[iadev_count] = NULL;
  2916. _ia_dev[iadev_count] = NULL;
  2917. ret = -EINVAL;
  2918. goto err_out_deregister_dev;
  2919. }
  2920. IF_EVENT(printk("iadev_count = %d\n", iadev_count);)
  2921. iadev->next_board = ia_boards;
  2922. ia_boards = dev;
  2923. return 0;
  2924. err_out_deregister_dev:
  2925. atm_dev_deregister(dev);
  2926. err_out_disable_dev:
  2927. pci_disable_device(pdev);
  2928. err_out_free_iadev:
  2929. kfree(iadev);
  2930. err_out:
  2931. return ret;
  2932. }
  2933. static void ia_remove_one(struct pci_dev *pdev)
  2934. {
  2935. struct atm_dev *dev = pci_get_drvdata(pdev);
  2936. IADEV *iadev = INPH_IA_DEV(dev);
  2937. /* Disable phy interrupts */
  2938. ia_phy_put(dev, ia_phy_get(dev, SUNI_RSOP_CIE) & ~(SUNI_RSOP_CIE_LOSE),
  2939. SUNI_RSOP_CIE);
  2940. udelay(1);
  2941. if (dev->phy && dev->phy->stop)
  2942. dev->phy->stop(dev);
  2943. /* De-register device */
  2944. free_irq(iadev->irq, dev);
  2945. iadev_count--;
  2946. ia_dev[iadev_count] = NULL;
  2947. _ia_dev[iadev_count] = NULL;
  2948. IF_EVENT(printk("deregistering iav at (itf:%d)\n", dev->number);)
  2949. atm_dev_deregister(dev);
  2950. iounmap(iadev->base);
  2951. pci_disable_device(pdev);
  2952. ia_free_rx(iadev);
  2953. ia_free_tx(iadev);
  2954. kfree(iadev);
  2955. }
  2956. static struct pci_device_id ia_pci_tbl[] = {
  2957. { PCI_VENDOR_ID_IPHASE, 0x0008, PCI_ANY_ID, PCI_ANY_ID, },
  2958. { PCI_VENDOR_ID_IPHASE, 0x0009, PCI_ANY_ID, PCI_ANY_ID, },
  2959. { 0,}
  2960. };
  2961. MODULE_DEVICE_TABLE(pci, ia_pci_tbl);
  2962. static struct pci_driver ia_driver = {
  2963. .name = DEV_LABEL,
  2964. .id_table = ia_pci_tbl,
  2965. .probe = ia_init_one,
  2966. .remove = ia_remove_one,
  2967. };
  2968. static int __init ia_module_init(void)
  2969. {
  2970. int ret;
  2971. ret = pci_register_driver(&ia_driver);
  2972. if (ret >= 0) {
  2973. ia_timer.expires = jiffies + 3*HZ;
  2974. add_timer(&ia_timer);
  2975. } else
  2976. printk(KERN_ERR DEV_LABEL ": no adapter found\n");
  2977. return ret;
  2978. }
  2979. static void __exit ia_module_exit(void)
  2980. {
  2981. pci_unregister_driver(&ia_driver);
  2982. del_timer(&ia_timer);
  2983. }
  2984. module_init(ia_module_init);
  2985. module_exit(ia_module_exit);