iphase.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299
  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. }
  1722. else
  1723. printk("iadev: Non UBR, ABR and CBR traffic not supportedn");
  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(iadev->num_tx_desc*sizeof(struct cpcs_trailer_desc), GFP_KERNEL);
  1801. if (!iadev->tx_buf) {
  1802. printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
  1803. goto err_free_dle;
  1804. }
  1805. for (i= 0; i< iadev->num_tx_desc; i++)
  1806. {
  1807. struct cpcs_trailer *cpcs;
  1808. cpcs = kmalloc(sizeof(*cpcs), GFP_KERNEL|GFP_DMA);
  1809. if(!cpcs) {
  1810. printk(KERN_ERR DEV_LABEL " couldn't get freepage\n");
  1811. goto err_free_tx_bufs;
  1812. }
  1813. iadev->tx_buf[i].cpcs = cpcs;
  1814. iadev->tx_buf[i].dma_addr = dma_map_single(&iadev->pci->dev,
  1815. cpcs,
  1816. sizeof(*cpcs),
  1817. DMA_TO_DEVICE);
  1818. }
  1819. iadev->desc_tbl = kmalloc(iadev->num_tx_desc *
  1820. sizeof(struct desc_tbl_t), GFP_KERNEL);
  1821. if (!iadev->desc_tbl) {
  1822. printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
  1823. goto err_free_all_tx_bufs;
  1824. }
  1825. /* Communication Queues base address */
  1826. i = TX_COMP_Q * iadev->memSize;
  1827. writew(i >> 16, iadev->seg_reg+SEG_QUEUE_BASE);
  1828. /* Transmit Complete Queue */
  1829. writew(i, iadev->seg_reg+TCQ_ST_ADR);
  1830. writew(i, iadev->seg_reg+TCQ_RD_PTR);
  1831. writew(i+iadev->num_tx_desc*sizeof(u_short),iadev->seg_reg+TCQ_WR_PTR);
  1832. iadev->host_tcq_wr = i + iadev->num_tx_desc*sizeof(u_short);
  1833. writew(i+2 * iadev->num_tx_desc * sizeof(u_short),
  1834. iadev->seg_reg+TCQ_ED_ADR);
  1835. /* Fill the TCQ with all the free descriptors. */
  1836. tcq_st_adr = readw(iadev->seg_reg+TCQ_ST_ADR);
  1837. tcq_start = (u_short *)(iadev->seg_ram+tcq_st_adr);
  1838. for(i=1; i<=iadev->num_tx_desc; i++)
  1839. {
  1840. *tcq_start = (u_short)i;
  1841. tcq_start++;
  1842. }
  1843. /* Packet Ready Queue */
  1844. i = PKT_RDY_Q * iadev->memSize;
  1845. writew(i, iadev->seg_reg+PRQ_ST_ADR);
  1846. writew(i+2 * iadev->num_tx_desc * sizeof(u_short),
  1847. iadev->seg_reg+PRQ_ED_ADR);
  1848. writew(i, iadev->seg_reg+PRQ_RD_PTR);
  1849. writew(i, iadev->seg_reg+PRQ_WR_PTR);
  1850. /* Load local copy of PRQ and TCQ ptrs */
  1851. iadev->ffL.prq_st = readw(iadev->seg_reg+PRQ_ST_ADR) & 0xffff;
  1852. iadev->ffL.prq_ed = readw(iadev->seg_reg+PRQ_ED_ADR) & 0xffff;
  1853. iadev->ffL.prq_wr = readw(iadev->seg_reg+PRQ_WR_PTR) & 0xffff;
  1854. iadev->ffL.tcq_st = readw(iadev->seg_reg+TCQ_ST_ADR) & 0xffff;
  1855. iadev->ffL.tcq_ed = readw(iadev->seg_reg+TCQ_ED_ADR) & 0xffff;
  1856. iadev->ffL.tcq_rd = readw(iadev->seg_reg+TCQ_RD_PTR) & 0xffff;
  1857. /* Just for safety initializing the queue to have desc 1 always */
  1858. /* Fill the PRQ with all the free descriptors. */
  1859. prq_st_adr = readw(iadev->seg_reg+PRQ_ST_ADR);
  1860. prq_start = (u_short *)(iadev->seg_ram+prq_st_adr);
  1861. for(i=1; i<=iadev->num_tx_desc; i++)
  1862. {
  1863. *prq_start = (u_short)0; /* desc 1 in all entries */
  1864. prq_start++;
  1865. }
  1866. /* CBR Table */
  1867. IF_INIT(printk("Start CBR Init\n");)
  1868. #if 1 /* for 1K VC board, CBR_PTR_BASE is 0 */
  1869. writew(0,iadev->seg_reg+CBR_PTR_BASE);
  1870. #else /* Charlie's logic is wrong ? */
  1871. tmp16 = (iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize)>>17;
  1872. IF_INIT(printk("cbr_ptr_base = 0x%x ", tmp16);)
  1873. writew(tmp16,iadev->seg_reg+CBR_PTR_BASE);
  1874. #endif
  1875. IF_INIT(printk("value in register = 0x%x\n",
  1876. readw(iadev->seg_reg+CBR_PTR_BASE));)
  1877. tmp16 = (CBR_SCHED_TABLE*iadev->memSize) >> 1;
  1878. writew(tmp16, iadev->seg_reg+CBR_TAB_BEG);
  1879. IF_INIT(printk("cbr_tab_beg = 0x%x in reg = 0x%x \n", tmp16,
  1880. readw(iadev->seg_reg+CBR_TAB_BEG));)
  1881. writew(tmp16, iadev->seg_reg+CBR_TAB_END+1); // CBR_PTR;
  1882. tmp16 = (CBR_SCHED_TABLE*iadev->memSize + iadev->num_vc*6 - 2) >> 1;
  1883. writew(tmp16, iadev->seg_reg+CBR_TAB_END);
  1884. IF_INIT(printk("iadev->seg_reg = 0x%p CBR_PTR_BASE = 0x%x\n",
  1885. iadev->seg_reg, readw(iadev->seg_reg+CBR_PTR_BASE));)
  1886. IF_INIT(printk("CBR_TAB_BEG = 0x%x, CBR_TAB_END = 0x%x, CBR_PTR = 0x%x\n",
  1887. readw(iadev->seg_reg+CBR_TAB_BEG), readw(iadev->seg_reg+CBR_TAB_END),
  1888. readw(iadev->seg_reg+CBR_TAB_END+1));)
  1889. /* Initialize the CBR Schedualing Table */
  1890. memset_io(iadev->seg_ram+CBR_SCHED_TABLE*iadev->memSize,
  1891. 0, iadev->num_vc*6);
  1892. iadev->CbrRemEntries = iadev->CbrTotEntries = iadev->num_vc*3;
  1893. iadev->CbrEntryPt = 0;
  1894. iadev->Granularity = MAX_ATM_155 / iadev->CbrTotEntries;
  1895. iadev->NumEnabledCBR = 0;
  1896. /* UBR scheduling Table and wait queue */
  1897. /* initialize all bytes of UBR scheduler table and wait queue to 0
  1898. - SCHEDSZ is 1K (# of entries).
  1899. - UBR Table size is 4K
  1900. - UBR wait queue is 4K
  1901. since the table and wait queues are contiguous, all the bytes
  1902. can be initialized by one memeset.
  1903. */
  1904. vcsize_sel = 0;
  1905. i = 8*1024;
  1906. while (i != iadev->num_vc) {
  1907. i /= 2;
  1908. vcsize_sel++;
  1909. }
  1910. i = MAIN_VC_TABLE * iadev->memSize;
  1911. writew(vcsize_sel | ((i >> 8) & 0xfff8),iadev->seg_reg+VCT_BASE);
  1912. i = EXT_VC_TABLE * iadev->memSize;
  1913. writew((i >> 8) & 0xfffe, iadev->seg_reg+VCTE_BASE);
  1914. i = UBR_SCHED_TABLE * iadev->memSize;
  1915. writew((i & 0xffff) >> 11, iadev->seg_reg+UBR_SBPTR_BASE);
  1916. i = UBR_WAIT_Q * iadev->memSize;
  1917. writew((i >> 7) & 0xffff, iadev->seg_reg+UBRWQ_BASE);
  1918. memset((caddr_t)(iadev->seg_ram+UBR_SCHED_TABLE*iadev->memSize),
  1919. 0, iadev->num_vc*8);
  1920. /* ABR scheduling Table(0x5000-0x57ff) and wait queue(0x5800-0x5fff)*/
  1921. /* initialize all bytes of ABR scheduler table and wait queue to 0
  1922. - SCHEDSZ is 1K (# of entries).
  1923. - ABR Table size is 2K
  1924. - ABR wait queue is 2K
  1925. since the table and wait queues are contiguous, all the bytes
  1926. can be initialized by one memeset.
  1927. */
  1928. i = ABR_SCHED_TABLE * iadev->memSize;
  1929. writew((i >> 11) & 0xffff, iadev->seg_reg+ABR_SBPTR_BASE);
  1930. i = ABR_WAIT_Q * iadev->memSize;
  1931. writew((i >> 7) & 0xffff, iadev->seg_reg+ABRWQ_BASE);
  1932. i = ABR_SCHED_TABLE*iadev->memSize;
  1933. memset((caddr_t)(iadev->seg_ram+i), 0, iadev->num_vc*4);
  1934. vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR;
  1935. evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR;
  1936. iadev->testTable = kmalloc(sizeof(long)*iadev->num_vc, GFP_KERNEL);
  1937. if (!iadev->testTable) {
  1938. printk("Get freepage failed\n");
  1939. goto err_free_desc_tbl;
  1940. }
  1941. for(i=0; i<iadev->num_vc; i++)
  1942. {
  1943. memset((caddr_t)vc, 0, sizeof(*vc));
  1944. memset((caddr_t)evc, 0, sizeof(*evc));
  1945. iadev->testTable[i] = kmalloc(sizeof(struct testTable_t),
  1946. GFP_KERNEL);
  1947. if (!iadev->testTable[i])
  1948. goto err_free_test_tables;
  1949. iadev->testTable[i]->lastTime = 0;
  1950. iadev->testTable[i]->fract = 0;
  1951. iadev->testTable[i]->vc_status = VC_UBR;
  1952. vc++;
  1953. evc++;
  1954. }
  1955. /* Other Initialization */
  1956. /* Max Rate Register */
  1957. if (iadev->phy_type & FE_25MBIT_PHY) {
  1958. writew(RATE25, iadev->seg_reg+MAXRATE);
  1959. writew((UBR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS);
  1960. }
  1961. else {
  1962. writew(cellrate_to_float(iadev->LineRate),iadev->seg_reg+MAXRATE);
  1963. writew((UBR_EN | ABR_EN | (0x23 << 2)), iadev->seg_reg+STPARMS);
  1964. }
  1965. /* Set Idle Header Reigisters to be sure */
  1966. writew(0, iadev->seg_reg+IDLEHEADHI);
  1967. writew(0, iadev->seg_reg+IDLEHEADLO);
  1968. /* Program ABR UBR Priority Register as PRI_ABR_UBR_EQUAL */
  1969. writew(0xaa00, iadev->seg_reg+ABRUBR_ARB);
  1970. iadev->close_pending = 0;
  1971. init_waitqueue_head(&iadev->close_wait);
  1972. init_waitqueue_head(&iadev->timeout_wait);
  1973. skb_queue_head_init(&iadev->tx_dma_q);
  1974. ia_init_rtn_q(&iadev->tx_return_q);
  1975. /* RM Cell Protocol ID and Message Type */
  1976. writew(RM_TYPE_4_0, iadev->seg_reg+RM_TYPE);
  1977. skb_queue_head_init (&iadev->tx_backlog);
  1978. /* Mode Register 1 */
  1979. writew(MODE_REG_1_VAL, iadev->seg_reg+MODE_REG_1);
  1980. /* Mode Register 0 */
  1981. writew(T_ONLINE, iadev->seg_reg+MODE_REG_0);
  1982. /* Interrupt Status Register - read to clear */
  1983. readw(iadev->seg_reg+SEG_INTR_STATUS_REG);
  1984. /* Interrupt Mask Reg- don't mask TCQ_NOT_EMPTY interrupt generation */
  1985. writew(~(TRANSMIT_DONE | TCQ_NOT_EMPTY), iadev->seg_reg+SEG_MASK_REG);
  1986. writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
  1987. iadev->tx_pkt_cnt = 0;
  1988. iadev->rate_limit = iadev->LineRate / 3;
  1989. return 0;
  1990. err_free_test_tables:
  1991. while (--i >= 0)
  1992. kfree(iadev->testTable[i]);
  1993. kfree(iadev->testTable);
  1994. err_free_desc_tbl:
  1995. kfree(iadev->desc_tbl);
  1996. err_free_all_tx_bufs:
  1997. i = iadev->num_tx_desc;
  1998. err_free_tx_bufs:
  1999. while (--i >= 0) {
  2000. struct cpcs_trailer_desc *desc = iadev->tx_buf + i;
  2001. dma_unmap_single(&iadev->pci->dev, desc->dma_addr,
  2002. sizeof(*desc->cpcs), DMA_TO_DEVICE);
  2003. kfree(desc->cpcs);
  2004. }
  2005. kfree(iadev->tx_buf);
  2006. err_free_dle:
  2007. dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->tx_dle_q.start,
  2008. iadev->tx_dle_dma);
  2009. err_out:
  2010. return -ENOMEM;
  2011. }
  2012. static irqreturn_t ia_int(int irq, void *dev_id)
  2013. {
  2014. struct atm_dev *dev;
  2015. IADEV *iadev;
  2016. unsigned int status;
  2017. int handled = 0;
  2018. dev = dev_id;
  2019. iadev = INPH_IA_DEV(dev);
  2020. while( (status = readl(iadev->reg+IPHASE5575_BUS_STATUS_REG) & 0x7f))
  2021. {
  2022. handled = 1;
  2023. IF_EVENT(printk("ia_int: status = 0x%x\n", status);)
  2024. if (status & STAT_REASSINT)
  2025. {
  2026. /* do something */
  2027. IF_EVENT(printk("REASSINT Bus status reg: %08x\n", status);)
  2028. rx_intr(dev);
  2029. }
  2030. if (status & STAT_DLERINT)
  2031. {
  2032. /* Clear this bit by writing a 1 to it. */
  2033. writel(STAT_DLERINT, iadev->reg + IPHASE5575_BUS_STATUS_REG);
  2034. rx_dle_intr(dev);
  2035. }
  2036. if (status & STAT_SEGINT)
  2037. {
  2038. /* do something */
  2039. IF_EVENT(printk("IA: tx_intr \n");)
  2040. tx_intr(dev);
  2041. }
  2042. if (status & STAT_DLETINT)
  2043. {
  2044. writel(STAT_DLETINT, iadev->reg + IPHASE5575_BUS_STATUS_REG);
  2045. tx_dle_intr(dev);
  2046. }
  2047. if (status & (STAT_FEINT | STAT_ERRINT | STAT_MARKINT))
  2048. {
  2049. if (status & STAT_FEINT)
  2050. ia_frontend_intr(iadev);
  2051. }
  2052. }
  2053. return IRQ_RETVAL(handled);
  2054. }
  2055. /*----------------------------- entries --------------------------------*/
  2056. static int get_esi(struct atm_dev *dev)
  2057. {
  2058. IADEV *iadev;
  2059. int i;
  2060. u32 mac1;
  2061. u16 mac2;
  2062. iadev = INPH_IA_DEV(dev);
  2063. mac1 = cpu_to_be32(le32_to_cpu(readl(
  2064. iadev->reg+IPHASE5575_MAC1)));
  2065. mac2 = cpu_to_be16(le16_to_cpu(readl(iadev->reg+IPHASE5575_MAC2)));
  2066. IF_INIT(printk("ESI: 0x%08x%04x\n", mac1, mac2);)
  2067. for (i=0; i<MAC1_LEN; i++)
  2068. dev->esi[i] = mac1 >>(8*(MAC1_LEN-1-i));
  2069. for (i=0; i<MAC2_LEN; i++)
  2070. dev->esi[i+MAC1_LEN] = mac2 >>(8*(MAC2_LEN - 1 -i));
  2071. return 0;
  2072. }
  2073. static int reset_sar(struct atm_dev *dev)
  2074. {
  2075. IADEV *iadev;
  2076. int i, error = 1;
  2077. unsigned int pci[64];
  2078. iadev = INPH_IA_DEV(dev);
  2079. for(i=0; i<64; i++)
  2080. if ((error = pci_read_config_dword(iadev->pci,
  2081. i*4, &pci[i])) != PCIBIOS_SUCCESSFUL)
  2082. return error;
  2083. writel(0, iadev->reg+IPHASE5575_EXT_RESET);
  2084. for(i=0; i<64; i++)
  2085. if ((error = pci_write_config_dword(iadev->pci,
  2086. i*4, pci[i])) != PCIBIOS_SUCCESSFUL)
  2087. return error;
  2088. udelay(5);
  2089. return 0;
  2090. }
  2091. static int ia_init(struct atm_dev *dev)
  2092. {
  2093. IADEV *iadev;
  2094. unsigned long real_base;
  2095. void __iomem *base;
  2096. unsigned short command;
  2097. int error, i;
  2098. /* The device has been identified and registered. Now we read
  2099. necessary configuration info like memory base address,
  2100. interrupt number etc */
  2101. IF_INIT(printk(">ia_init\n");)
  2102. dev->ci_range.vpi_bits = 0;
  2103. dev->ci_range.vci_bits = NR_VCI_LD;
  2104. iadev = INPH_IA_DEV(dev);
  2105. real_base = pci_resource_start (iadev->pci, 0);
  2106. iadev->irq = iadev->pci->irq;
  2107. error = pci_read_config_word(iadev->pci, PCI_COMMAND, &command);
  2108. if (error) {
  2109. printk(KERN_ERR DEV_LABEL "(itf %d): init error 0x%x\n",
  2110. dev->number,error);
  2111. return -EINVAL;
  2112. }
  2113. IF_INIT(printk(DEV_LABEL "(itf %d): rev.%d,realbase=0x%lx,irq=%d\n",
  2114. dev->number, iadev->pci->revision, real_base, iadev->irq);)
  2115. /* find mapping size of board */
  2116. iadev->pci_map_size = pci_resource_len(iadev->pci, 0);
  2117. if (iadev->pci_map_size == 0x100000){
  2118. iadev->num_vc = 4096;
  2119. dev->ci_range.vci_bits = NR_VCI_4K_LD;
  2120. iadev->memSize = 4;
  2121. }
  2122. else if (iadev->pci_map_size == 0x40000) {
  2123. iadev->num_vc = 1024;
  2124. iadev->memSize = 1;
  2125. }
  2126. else {
  2127. printk("Unknown pci_map_size = 0x%x\n", iadev->pci_map_size);
  2128. return -EINVAL;
  2129. }
  2130. IF_INIT(printk (DEV_LABEL "map size: %i\n", iadev->pci_map_size);)
  2131. /* enable bus mastering */
  2132. pci_set_master(iadev->pci);
  2133. /*
  2134. * Delay at least 1us before doing any mem accesses (how 'bout 10?)
  2135. */
  2136. udelay(10);
  2137. /* mapping the physical address to a virtual address in address space */
  2138. base = ioremap(real_base,iadev->pci_map_size); /* ioremap is not resolved ??? */
  2139. if (!base)
  2140. {
  2141. printk(DEV_LABEL " (itf %d): can't set up page mapping\n",
  2142. dev->number);
  2143. return -ENOMEM;
  2144. }
  2145. IF_INIT(printk(DEV_LABEL " (itf %d): rev.%d,base=%p,irq=%d\n",
  2146. dev->number, iadev->pci->revision, base, iadev->irq);)
  2147. /* filling the iphase dev structure */
  2148. iadev->mem = iadev->pci_map_size /2;
  2149. iadev->real_base = real_base;
  2150. iadev->base = base;
  2151. /* Bus Interface Control Registers */
  2152. iadev->reg = base + REG_BASE;
  2153. /* Segmentation Control Registers */
  2154. iadev->seg_reg = base + SEG_BASE;
  2155. /* Reassembly Control Registers */
  2156. iadev->reass_reg = base + REASS_BASE;
  2157. /* Front end/ DMA control registers */
  2158. iadev->phy = base + PHY_BASE;
  2159. iadev->dma = base + PHY_BASE;
  2160. /* RAM - Segmentation RAm and Reassembly RAM */
  2161. iadev->ram = base + ACTUAL_RAM_BASE;
  2162. iadev->seg_ram = base + ACTUAL_SEG_RAM_BASE;
  2163. iadev->reass_ram = base + ACTUAL_REASS_RAM_BASE;
  2164. /* lets print out the above */
  2165. IF_INIT(printk("Base addrs: %p %p %p \n %p %p %p %p\n",
  2166. iadev->reg,iadev->seg_reg,iadev->reass_reg,
  2167. iadev->phy, iadev->ram, iadev->seg_ram,
  2168. iadev->reass_ram);)
  2169. /* lets try reading the MAC address */
  2170. error = get_esi(dev);
  2171. if (error) {
  2172. iounmap(iadev->base);
  2173. return error;
  2174. }
  2175. printk("IA: ");
  2176. for (i=0; i < ESI_LEN; i++)
  2177. printk("%s%02X",i ? "-" : "",dev->esi[i]);
  2178. printk("\n");
  2179. /* reset SAR */
  2180. if (reset_sar(dev)) {
  2181. iounmap(iadev->base);
  2182. printk("IA: reset SAR fail, please try again\n");
  2183. return 1;
  2184. }
  2185. return 0;
  2186. }
  2187. static void ia_update_stats(IADEV *iadev) {
  2188. if (!iadev->carrier_detect)
  2189. return;
  2190. iadev->rx_cell_cnt += readw(iadev->reass_reg+CELL_CTR0)&0xffff;
  2191. iadev->rx_cell_cnt += (readw(iadev->reass_reg+CELL_CTR1) & 0xffff) << 16;
  2192. iadev->drop_rxpkt += readw(iadev->reass_reg + DRP_PKT_CNTR ) & 0xffff;
  2193. iadev->drop_rxcell += readw(iadev->reass_reg + ERR_CNTR) & 0xffff;
  2194. iadev->tx_cell_cnt += readw(iadev->seg_reg + CELL_CTR_LO_AUTO)&0xffff;
  2195. iadev->tx_cell_cnt += (readw(iadev->seg_reg+CELL_CTR_HIGH_AUTO)&0xffff)<<16;
  2196. return;
  2197. }
  2198. static void ia_led_timer(unsigned long arg) {
  2199. unsigned long flags;
  2200. static u_char blinking[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  2201. u_char i;
  2202. static u32 ctrl_reg;
  2203. for (i = 0; i < iadev_count; i++) {
  2204. if (ia_dev[i]) {
  2205. ctrl_reg = readl(ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
  2206. if (blinking[i] == 0) {
  2207. blinking[i]++;
  2208. ctrl_reg &= (~CTRL_LED);
  2209. writel(ctrl_reg, ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
  2210. ia_update_stats(ia_dev[i]);
  2211. }
  2212. else {
  2213. blinking[i] = 0;
  2214. ctrl_reg |= CTRL_LED;
  2215. writel(ctrl_reg, ia_dev[i]->reg+IPHASE5575_BUS_CONTROL_REG);
  2216. spin_lock_irqsave(&ia_dev[i]->tx_lock, flags);
  2217. if (ia_dev[i]->close_pending)
  2218. wake_up(&ia_dev[i]->close_wait);
  2219. ia_tx_poll(ia_dev[i]);
  2220. spin_unlock_irqrestore(&ia_dev[i]->tx_lock, flags);
  2221. }
  2222. }
  2223. }
  2224. mod_timer(&ia_timer, jiffies + HZ / 4);
  2225. return;
  2226. }
  2227. static void ia_phy_put(struct atm_dev *dev, unsigned char value,
  2228. unsigned long addr)
  2229. {
  2230. writel(value, INPH_IA_DEV(dev)->phy+addr);
  2231. }
  2232. static unsigned char ia_phy_get(struct atm_dev *dev, unsigned long addr)
  2233. {
  2234. return readl(INPH_IA_DEV(dev)->phy+addr);
  2235. }
  2236. static void ia_free_tx(IADEV *iadev)
  2237. {
  2238. int i;
  2239. kfree(iadev->desc_tbl);
  2240. for (i = 0; i < iadev->num_vc; i++)
  2241. kfree(iadev->testTable[i]);
  2242. kfree(iadev->testTable);
  2243. for (i = 0; i < iadev->num_tx_desc; i++) {
  2244. struct cpcs_trailer_desc *desc = iadev->tx_buf + i;
  2245. dma_unmap_single(&iadev->pci->dev, desc->dma_addr,
  2246. sizeof(*desc->cpcs), DMA_TO_DEVICE);
  2247. kfree(desc->cpcs);
  2248. }
  2249. kfree(iadev->tx_buf);
  2250. dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->tx_dle_q.start,
  2251. iadev->tx_dle_dma);
  2252. }
  2253. static void ia_free_rx(IADEV *iadev)
  2254. {
  2255. kfree(iadev->rx_open);
  2256. dma_free_coherent(&iadev->pci->dev, DLE_TOTAL_SIZE, iadev->rx_dle_q.start,
  2257. iadev->rx_dle_dma);
  2258. }
  2259. static int ia_start(struct atm_dev *dev)
  2260. {
  2261. IADEV *iadev;
  2262. int error;
  2263. unsigned char phy;
  2264. u32 ctrl_reg;
  2265. IF_EVENT(printk(">ia_start\n");)
  2266. iadev = INPH_IA_DEV(dev);
  2267. if (request_irq(iadev->irq, &ia_int, IRQF_SHARED, DEV_LABEL, dev)) {
  2268. printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n",
  2269. dev->number, iadev->irq);
  2270. error = -EAGAIN;
  2271. goto err_out;
  2272. }
  2273. /* @@@ should release IRQ on error */
  2274. /* enabling memory + master */
  2275. if ((error = pci_write_config_word(iadev->pci,
  2276. PCI_COMMAND,
  2277. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER )))
  2278. {
  2279. printk(KERN_ERR DEV_LABEL "(itf %d): can't enable memory+"
  2280. "master (0x%x)\n",dev->number, error);
  2281. error = -EIO;
  2282. goto err_free_irq;
  2283. }
  2284. udelay(10);
  2285. /* Maybe we should reset the front end, initialize Bus Interface Control
  2286. Registers and see. */
  2287. IF_INIT(printk("Bus ctrl reg: %08x\n",
  2288. readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));)
  2289. ctrl_reg = readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG);
  2290. ctrl_reg = (ctrl_reg & (CTRL_LED | CTRL_FE_RST))
  2291. | CTRL_B8
  2292. | CTRL_B16
  2293. | CTRL_B32
  2294. | CTRL_B48
  2295. | CTRL_B64
  2296. | CTRL_B128
  2297. | CTRL_ERRMASK
  2298. | CTRL_DLETMASK /* shud be removed l8r */
  2299. | CTRL_DLERMASK
  2300. | CTRL_SEGMASK
  2301. | CTRL_REASSMASK
  2302. | CTRL_FEMASK
  2303. | CTRL_CSPREEMPT;
  2304. writel(ctrl_reg, iadev->reg+IPHASE5575_BUS_CONTROL_REG);
  2305. IF_INIT(printk("Bus ctrl reg after initializing: %08x\n",
  2306. readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));
  2307. printk("Bus status reg after init: %08x\n",
  2308. readl(iadev->reg+IPHASE5575_BUS_STATUS_REG));)
  2309. ia_hw_type(iadev);
  2310. error = tx_init(dev);
  2311. if (error)
  2312. goto err_free_irq;
  2313. error = rx_init(dev);
  2314. if (error)
  2315. goto err_free_tx;
  2316. ctrl_reg = readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG);
  2317. writel(ctrl_reg | CTRL_FE_RST, iadev->reg+IPHASE5575_BUS_CONTROL_REG);
  2318. IF_INIT(printk("Bus ctrl reg after initializing: %08x\n",
  2319. readl(iadev->reg+IPHASE5575_BUS_CONTROL_REG));)
  2320. phy = 0; /* resolve compiler complaint */
  2321. IF_INIT (
  2322. if ((phy=ia_phy_get(dev,0)) == 0x30)
  2323. printk("IA: pm5346,rev.%d\n",phy&0x0f);
  2324. else
  2325. printk("IA: utopia,rev.%0x\n",phy);)
  2326. if (iadev->phy_type & FE_25MBIT_PHY)
  2327. ia_mb25_init(iadev);
  2328. else if (iadev->phy_type & (FE_DS3_PHY | FE_E3_PHY))
  2329. ia_suni_pm7345_init(iadev);
  2330. else {
  2331. error = suni_init(dev);
  2332. if (error)
  2333. goto err_free_rx;
  2334. if (dev->phy->start) {
  2335. error = dev->phy->start(dev);
  2336. if (error)
  2337. goto err_free_rx;
  2338. }
  2339. /* Get iadev->carrier_detect status */
  2340. ia_frontend_intr(iadev);
  2341. }
  2342. return 0;
  2343. err_free_rx:
  2344. ia_free_rx(iadev);
  2345. err_free_tx:
  2346. ia_free_tx(iadev);
  2347. err_free_irq:
  2348. free_irq(iadev->irq, dev);
  2349. err_out:
  2350. return error;
  2351. }
  2352. static void ia_close(struct atm_vcc *vcc)
  2353. {
  2354. DEFINE_WAIT(wait);
  2355. u16 *vc_table;
  2356. IADEV *iadev;
  2357. struct ia_vcc *ia_vcc;
  2358. struct sk_buff *skb = NULL;
  2359. struct sk_buff_head tmp_tx_backlog, tmp_vcc_backlog;
  2360. unsigned long closetime, flags;
  2361. iadev = INPH_IA_DEV(vcc->dev);
  2362. ia_vcc = INPH_IA_VCC(vcc);
  2363. if (!ia_vcc) return;
  2364. IF_EVENT(printk("ia_close: ia_vcc->vc_desc_cnt = %d vci = %d\n",
  2365. ia_vcc->vc_desc_cnt,vcc->vci);)
  2366. clear_bit(ATM_VF_READY,&vcc->flags);
  2367. skb_queue_head_init (&tmp_tx_backlog);
  2368. skb_queue_head_init (&tmp_vcc_backlog);
  2369. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  2370. iadev->close_pending++;
  2371. prepare_to_wait(&iadev->timeout_wait, &wait, TASK_UNINTERRUPTIBLE);
  2372. schedule_timeout(msecs_to_jiffies(500));
  2373. finish_wait(&iadev->timeout_wait, &wait);
  2374. spin_lock_irqsave(&iadev->tx_lock, flags);
  2375. while((skb = skb_dequeue(&iadev->tx_backlog))) {
  2376. if (ATM_SKB(skb)->vcc == vcc){
  2377. if (vcc->pop) vcc->pop(vcc, skb);
  2378. else dev_kfree_skb_any(skb);
  2379. }
  2380. else
  2381. skb_queue_tail(&tmp_tx_backlog, skb);
  2382. }
  2383. while((skb = skb_dequeue(&tmp_tx_backlog)))
  2384. skb_queue_tail(&iadev->tx_backlog, skb);
  2385. IF_EVENT(printk("IA TX Done decs_cnt = %d\n", ia_vcc->vc_desc_cnt);)
  2386. closetime = 300000 / ia_vcc->pcr;
  2387. if (closetime == 0)
  2388. closetime = 1;
  2389. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  2390. wait_event_timeout(iadev->close_wait, (ia_vcc->vc_desc_cnt <= 0), closetime);
  2391. spin_lock_irqsave(&iadev->tx_lock, flags);
  2392. iadev->close_pending--;
  2393. iadev->testTable[vcc->vci]->lastTime = 0;
  2394. iadev->testTable[vcc->vci]->fract = 0;
  2395. iadev->testTable[vcc->vci]->vc_status = VC_UBR;
  2396. if (vcc->qos.txtp.traffic_class == ATM_ABR) {
  2397. if (vcc->qos.txtp.min_pcr > 0)
  2398. iadev->sum_mcr -= vcc->qos.txtp.min_pcr;
  2399. }
  2400. if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  2401. ia_vcc = INPH_IA_VCC(vcc);
  2402. iadev->sum_mcr -= ia_vcc->NumCbrEntry*iadev->Granularity;
  2403. ia_cbrVc_close (vcc);
  2404. }
  2405. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  2406. }
  2407. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  2408. // reset reass table
  2409. vc_table = (u16 *)(iadev->reass_ram+REASS_TABLE*iadev->memSize);
  2410. vc_table += vcc->vci;
  2411. *vc_table = NO_AAL5_PKT;
  2412. // reset vc table
  2413. vc_table = (u16 *)(iadev->reass_ram+RX_VC_TABLE*iadev->memSize);
  2414. vc_table += vcc->vci;
  2415. *vc_table = (vcc->vci << 6) | 15;
  2416. if (vcc->qos.rxtp.traffic_class == ATM_ABR) {
  2417. struct abr_vc_table __iomem *abr_vc_table =
  2418. (iadev->reass_ram+ABR_VC_TABLE*iadev->memSize);
  2419. abr_vc_table += vcc->vci;
  2420. abr_vc_table->rdf = 0x0003;
  2421. abr_vc_table->air = 0x5eb1;
  2422. }
  2423. // Drain the packets
  2424. rx_dle_intr(vcc->dev);
  2425. iadev->rx_open[vcc->vci] = NULL;
  2426. }
  2427. kfree(INPH_IA_VCC(vcc));
  2428. ia_vcc = NULL;
  2429. vcc->dev_data = NULL;
  2430. clear_bit(ATM_VF_ADDR,&vcc->flags);
  2431. return;
  2432. }
  2433. static int ia_open(struct atm_vcc *vcc)
  2434. {
  2435. struct ia_vcc *ia_vcc;
  2436. int error;
  2437. if (!test_bit(ATM_VF_PARTIAL,&vcc->flags))
  2438. {
  2439. IF_EVENT(printk("ia: not partially allocated resources\n");)
  2440. vcc->dev_data = NULL;
  2441. }
  2442. if (vcc->vci != ATM_VPI_UNSPEC && vcc->vpi != ATM_VCI_UNSPEC)
  2443. {
  2444. IF_EVENT(printk("iphase open: unspec part\n");)
  2445. set_bit(ATM_VF_ADDR,&vcc->flags);
  2446. }
  2447. if (vcc->qos.aal != ATM_AAL5)
  2448. return -EINVAL;
  2449. IF_EVENT(printk(DEV_LABEL "(itf %d): open %d.%d\n",
  2450. vcc->dev->number, vcc->vpi, vcc->vci);)
  2451. /* Device dependent initialization */
  2452. ia_vcc = kmalloc(sizeof(*ia_vcc), GFP_KERNEL);
  2453. if (!ia_vcc) return -ENOMEM;
  2454. vcc->dev_data = ia_vcc;
  2455. if ((error = open_rx(vcc)))
  2456. {
  2457. IF_EVENT(printk("iadev: error in open_rx, closing\n");)
  2458. ia_close(vcc);
  2459. return error;
  2460. }
  2461. if ((error = open_tx(vcc)))
  2462. {
  2463. IF_EVENT(printk("iadev: error in open_tx, closing\n");)
  2464. ia_close(vcc);
  2465. return error;
  2466. }
  2467. set_bit(ATM_VF_READY,&vcc->flags);
  2468. #if 0
  2469. {
  2470. static u8 first = 1;
  2471. if (first) {
  2472. ia_timer.expires = jiffies + 3*HZ;
  2473. add_timer(&ia_timer);
  2474. first = 0;
  2475. }
  2476. }
  2477. #endif
  2478. IF_EVENT(printk("ia open returning\n");)
  2479. return 0;
  2480. }
  2481. static int ia_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags)
  2482. {
  2483. IF_EVENT(printk(">ia_change_qos\n");)
  2484. return 0;
  2485. }
  2486. static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
  2487. {
  2488. IA_CMDBUF ia_cmds;
  2489. IADEV *iadev;
  2490. int i, board;
  2491. u16 __user *tmps;
  2492. IF_EVENT(printk(">ia_ioctl\n");)
  2493. if (cmd != IA_CMD) {
  2494. if (!dev->phy->ioctl) return -EINVAL;
  2495. return dev->phy->ioctl(dev,cmd,arg);
  2496. }
  2497. if (copy_from_user(&ia_cmds, arg, sizeof ia_cmds)) return -EFAULT;
  2498. board = ia_cmds.status;
  2499. if ((board < 0) || (board > iadev_count))
  2500. board = 0;
  2501. iadev = ia_dev[board];
  2502. switch (ia_cmds.cmd) {
  2503. case MEMDUMP:
  2504. {
  2505. switch (ia_cmds.sub_cmd) {
  2506. case MEMDUMP_DEV:
  2507. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2508. if (copy_to_user(ia_cmds.buf, iadev, sizeof(IADEV)))
  2509. return -EFAULT;
  2510. ia_cmds.status = 0;
  2511. break;
  2512. case MEMDUMP_SEGREG:
  2513. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2514. tmps = (u16 __user *)ia_cmds.buf;
  2515. for(i=0; i<0x80; i+=2, tmps++)
  2516. if(put_user((u16)(readl(iadev->seg_reg+i) & 0xffff), tmps)) return -EFAULT;
  2517. ia_cmds.status = 0;
  2518. ia_cmds.len = 0x80;
  2519. break;
  2520. case MEMDUMP_REASSREG:
  2521. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2522. tmps = (u16 __user *)ia_cmds.buf;
  2523. for(i=0; i<0x80; i+=2, tmps++)
  2524. if(put_user((u16)(readl(iadev->reass_reg+i) & 0xffff), tmps)) return -EFAULT;
  2525. ia_cmds.status = 0;
  2526. ia_cmds.len = 0x80;
  2527. break;
  2528. case MEMDUMP_FFL:
  2529. {
  2530. ia_regs_t *regs_local;
  2531. ffredn_t *ffL;
  2532. rfredn_t *rfL;
  2533. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2534. regs_local = kmalloc(sizeof(*regs_local), GFP_KERNEL);
  2535. if (!regs_local) return -ENOMEM;
  2536. ffL = &regs_local->ffredn;
  2537. rfL = &regs_local->rfredn;
  2538. /* Copy real rfred registers into the local copy */
  2539. for (i=0; i<(sizeof (rfredn_t))/4; i++)
  2540. ((u_int *)rfL)[i] = readl(iadev->reass_reg + i) & 0xffff;
  2541. /* Copy real ffred registers into the local copy */
  2542. for (i=0; i<(sizeof (ffredn_t))/4; i++)
  2543. ((u_int *)ffL)[i] = readl(iadev->seg_reg + i) & 0xffff;
  2544. if (copy_to_user(ia_cmds.buf, regs_local,sizeof(ia_regs_t))) {
  2545. kfree(regs_local);
  2546. return -EFAULT;
  2547. }
  2548. kfree(regs_local);
  2549. printk("Board %d registers dumped\n", board);
  2550. ia_cmds.status = 0;
  2551. }
  2552. break;
  2553. case READ_REG:
  2554. {
  2555. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2556. desc_dbg(iadev);
  2557. ia_cmds.status = 0;
  2558. }
  2559. break;
  2560. case 0x6:
  2561. {
  2562. ia_cmds.status = 0;
  2563. printk("skb = 0x%lx\n", (long)skb_peek(&iadev->tx_backlog));
  2564. printk("rtn_q: 0x%lx\n",(long)ia_deque_rtn_q(&iadev->tx_return_q));
  2565. }
  2566. break;
  2567. case 0x8:
  2568. {
  2569. struct k_sonet_stats *stats;
  2570. stats = &PRIV(_ia_dev[board])->sonet_stats;
  2571. printk("section_bip: %d\n", atomic_read(&stats->section_bip));
  2572. printk("line_bip : %d\n", atomic_read(&stats->line_bip));
  2573. printk("path_bip : %d\n", atomic_read(&stats->path_bip));
  2574. printk("line_febe : %d\n", atomic_read(&stats->line_febe));
  2575. printk("path_febe : %d\n", atomic_read(&stats->path_febe));
  2576. printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
  2577. printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
  2578. printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
  2579. printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
  2580. }
  2581. ia_cmds.status = 0;
  2582. break;
  2583. case 0x9:
  2584. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2585. for (i = 1; i <= iadev->num_rx_desc; i++)
  2586. free_desc(_ia_dev[board], i);
  2587. writew( ~(RX_FREEQ_EMPT | RX_EXCP_RCVD),
  2588. iadev->reass_reg+REASS_MASK_REG);
  2589. iadev->rxing = 1;
  2590. ia_cmds.status = 0;
  2591. break;
  2592. case 0xb:
  2593. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2594. ia_frontend_intr(iadev);
  2595. break;
  2596. case 0xa:
  2597. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2598. {
  2599. ia_cmds.status = 0;
  2600. IADebugFlag = ia_cmds.maddr;
  2601. printk("New debug option loaded\n");
  2602. }
  2603. break;
  2604. default:
  2605. ia_cmds.status = 0;
  2606. break;
  2607. }
  2608. }
  2609. break;
  2610. default:
  2611. break;
  2612. }
  2613. return 0;
  2614. }
  2615. static int ia_getsockopt(struct atm_vcc *vcc, int level, int optname,
  2616. void __user *optval, int optlen)
  2617. {
  2618. IF_EVENT(printk(">ia_getsockopt\n");)
  2619. return -EINVAL;
  2620. }
  2621. static int ia_setsockopt(struct atm_vcc *vcc, int level, int optname,
  2622. void __user *optval, unsigned int optlen)
  2623. {
  2624. IF_EVENT(printk(">ia_setsockopt\n");)
  2625. return -EINVAL;
  2626. }
  2627. static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
  2628. IADEV *iadev;
  2629. struct dle *wr_ptr;
  2630. struct tx_buf_desc __iomem *buf_desc_ptr;
  2631. int desc;
  2632. int comp_code;
  2633. int total_len;
  2634. struct cpcs_trailer *trailer;
  2635. struct ia_vcc *iavcc;
  2636. iadev = INPH_IA_DEV(vcc->dev);
  2637. iavcc = INPH_IA_VCC(vcc);
  2638. if (!iavcc->txing) {
  2639. printk("discard packet on closed VC\n");
  2640. if (vcc->pop)
  2641. vcc->pop(vcc, skb);
  2642. else
  2643. dev_kfree_skb_any(skb);
  2644. return 0;
  2645. }
  2646. if (skb->len > iadev->tx_buf_sz - 8) {
  2647. printk("Transmit size over tx buffer size\n");
  2648. if (vcc->pop)
  2649. vcc->pop(vcc, skb);
  2650. else
  2651. dev_kfree_skb_any(skb);
  2652. return 0;
  2653. }
  2654. if ((unsigned long)skb->data & 3) {
  2655. printk("Misaligned SKB\n");
  2656. if (vcc->pop)
  2657. vcc->pop(vcc, skb);
  2658. else
  2659. dev_kfree_skb_any(skb);
  2660. return 0;
  2661. }
  2662. /* Get a descriptor number from our free descriptor queue
  2663. We get the descr number from the TCQ now, since I am using
  2664. the TCQ as a free buffer queue. Initially TCQ will be
  2665. initialized with all the descriptors and is hence, full.
  2666. */
  2667. desc = get_desc (iadev, iavcc);
  2668. if (desc == 0xffff)
  2669. return 1;
  2670. comp_code = desc >> 13;
  2671. desc &= 0x1fff;
  2672. if ((desc == 0) || (desc > iadev->num_tx_desc))
  2673. {
  2674. IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
  2675. atomic_inc(&vcc->stats->tx);
  2676. if (vcc->pop)
  2677. vcc->pop(vcc, skb);
  2678. else
  2679. dev_kfree_skb_any(skb);
  2680. return 0; /* return SUCCESS */
  2681. }
  2682. if (comp_code)
  2683. {
  2684. IF_ERR(printk(DEV_LABEL "send desc:%d completion code %d error\n",
  2685. desc, comp_code);)
  2686. }
  2687. /* remember the desc and vcc mapping */
  2688. iavcc->vc_desc_cnt++;
  2689. iadev->desc_tbl[desc-1].iavcc = iavcc;
  2690. iadev->desc_tbl[desc-1].txskb = skb;
  2691. IA_SKB_STATE(skb) = 0;
  2692. iadev->ffL.tcq_rd += 2;
  2693. if (iadev->ffL.tcq_rd > iadev->ffL.tcq_ed)
  2694. iadev->ffL.tcq_rd = iadev->ffL.tcq_st;
  2695. writew(iadev->ffL.tcq_rd, iadev->seg_reg+TCQ_RD_PTR);
  2696. /* Put the descriptor number in the packet ready queue
  2697. and put the updated write pointer in the DLE field
  2698. */
  2699. *(u16*)(iadev->seg_ram+iadev->ffL.prq_wr) = desc;
  2700. iadev->ffL.prq_wr += 2;
  2701. if (iadev->ffL.prq_wr > iadev->ffL.prq_ed)
  2702. iadev->ffL.prq_wr = iadev->ffL.prq_st;
  2703. /* Figure out the exact length of the packet and padding required to
  2704. make it aligned on a 48 byte boundary. */
  2705. total_len = skb->len + sizeof(struct cpcs_trailer);
  2706. total_len = ((total_len + 47) / 48) * 48;
  2707. IF_TX(printk("ia packet len:%d padding:%d\n", total_len, total_len - skb->len);)
  2708. /* Put the packet in a tx buffer */
  2709. trailer = iadev->tx_buf[desc-1].cpcs;
  2710. IF_TX(printk("Sent: skb = 0x%p skb->data: 0x%p len: %d, desc: %d\n",
  2711. skb, skb->data, skb->len, desc);)
  2712. trailer->control = 0;
  2713. /*big endian*/
  2714. trailer->length = ((skb->len & 0xff) << 8) | ((skb->len & 0xff00) >> 8);
  2715. trailer->crc32 = 0; /* not needed - dummy bytes */
  2716. /* Display the packet */
  2717. IF_TXPKT(printk("Sent data: len = %d MsgNum = %d\n",
  2718. skb->len, tcnter++);
  2719. xdump(skb->data, skb->len, "TX: ");
  2720. printk("\n");)
  2721. /* Build the buffer descriptor */
  2722. buf_desc_ptr = iadev->seg_ram+TX_DESC_BASE;
  2723. buf_desc_ptr += desc; /* points to the corresponding entry */
  2724. buf_desc_ptr->desc_mode = AAL5 | EOM_EN | APP_CRC32 | CMPL_INT;
  2725. /* Huh ? p.115 of users guide describes this as a read-only register */
  2726. writew(TRANSMIT_DONE, iadev->seg_reg+SEG_INTR_STATUS_REG);
  2727. buf_desc_ptr->vc_index = vcc->vci;
  2728. buf_desc_ptr->bytes = total_len;
  2729. if (vcc->qos.txtp.traffic_class == ATM_ABR)
  2730. clear_lockup (vcc, iadev);
  2731. /* Build the DLE structure */
  2732. wr_ptr = iadev->tx_dle_q.write;
  2733. memset((caddr_t)wr_ptr, 0, sizeof(*wr_ptr));
  2734. wr_ptr->sys_pkt_addr = dma_map_single(&iadev->pci->dev, skb->data,
  2735. skb->len, DMA_TO_DEVICE);
  2736. wr_ptr->local_pkt_addr = (buf_desc_ptr->buf_start_hi << 16) |
  2737. buf_desc_ptr->buf_start_lo;
  2738. /* wr_ptr->bytes = swap_byte_order(total_len); didn't seem to affect?? */
  2739. wr_ptr->bytes = skb->len;
  2740. /* hw bug - DLEs of 0x2d, 0x2e, 0x2f cause DMA lockup */
  2741. if ((wr_ptr->bytes >> 2) == 0xb)
  2742. wr_ptr->bytes = 0x30;
  2743. wr_ptr->mode = TX_DLE_PSI;
  2744. wr_ptr->prq_wr_ptr_data = 0;
  2745. /* end is not to be used for the DLE q */
  2746. if (++wr_ptr == iadev->tx_dle_q.end)
  2747. wr_ptr = iadev->tx_dle_q.start;
  2748. /* Build trailer dle */
  2749. wr_ptr->sys_pkt_addr = iadev->tx_buf[desc-1].dma_addr;
  2750. wr_ptr->local_pkt_addr = ((buf_desc_ptr->buf_start_hi << 16) |
  2751. buf_desc_ptr->buf_start_lo) + total_len - sizeof(struct cpcs_trailer);
  2752. wr_ptr->bytes = sizeof(struct cpcs_trailer);
  2753. wr_ptr->mode = DMA_INT_ENABLE;
  2754. wr_ptr->prq_wr_ptr_data = iadev->ffL.prq_wr;
  2755. /* end is not to be used for the DLE q */
  2756. if (++wr_ptr == iadev->tx_dle_q.end)
  2757. wr_ptr = iadev->tx_dle_q.start;
  2758. iadev->tx_dle_q.write = wr_ptr;
  2759. ATM_DESC(skb) = vcc->vci;
  2760. skb_queue_tail(&iadev->tx_dma_q, skb);
  2761. atomic_inc(&vcc->stats->tx);
  2762. iadev->tx_pkt_cnt++;
  2763. /* Increment transaction counter */
  2764. writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
  2765. #if 0
  2766. /* add flow control logic */
  2767. if (atomic_read(&vcc->stats->tx) % 20 == 0) {
  2768. if (iavcc->vc_desc_cnt > 10) {
  2769. vcc->tx_quota = vcc->tx_quota * 3 / 4;
  2770. printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
  2771. iavcc->flow_inc = -1;
  2772. iavcc->saved_tx_quota = vcc->tx_quota;
  2773. } else if ((iavcc->flow_inc < 0) && (iavcc->vc_desc_cnt < 3)) {
  2774. // vcc->tx_quota = 3 * iavcc->saved_tx_quota / 4;
  2775. printk("Tx2: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
  2776. iavcc->flow_inc = 0;
  2777. }
  2778. }
  2779. #endif
  2780. IF_TX(printk("ia send done\n");)
  2781. return 0;
  2782. }
  2783. static int ia_send(struct atm_vcc *vcc, struct sk_buff *skb)
  2784. {
  2785. IADEV *iadev;
  2786. unsigned long flags;
  2787. iadev = INPH_IA_DEV(vcc->dev);
  2788. if ((!skb)||(skb->len>(iadev->tx_buf_sz-sizeof(struct cpcs_trailer))))
  2789. {
  2790. if (!skb)
  2791. printk(KERN_CRIT "null skb in ia_send\n");
  2792. else dev_kfree_skb_any(skb);
  2793. return -EINVAL;
  2794. }
  2795. spin_lock_irqsave(&iadev->tx_lock, flags);
  2796. if (!test_bit(ATM_VF_READY,&vcc->flags)){
  2797. dev_kfree_skb_any(skb);
  2798. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  2799. return -EINVAL;
  2800. }
  2801. ATM_SKB(skb)->vcc = vcc;
  2802. if (skb_peek(&iadev->tx_backlog)) {
  2803. skb_queue_tail(&iadev->tx_backlog, skb);
  2804. }
  2805. else {
  2806. if (ia_pkt_tx (vcc, skb)) {
  2807. skb_queue_tail(&iadev->tx_backlog, skb);
  2808. }
  2809. }
  2810. spin_unlock_irqrestore(&iadev->tx_lock, flags);
  2811. return 0;
  2812. }
  2813. static int ia_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
  2814. {
  2815. int left = *pos, n;
  2816. char *tmpPtr;
  2817. IADEV *iadev = INPH_IA_DEV(dev);
  2818. if(!left--) {
  2819. if (iadev->phy_type == FE_25MBIT_PHY) {
  2820. n = sprintf(page, " Board Type : Iphase5525-1KVC-128K\n");
  2821. return n;
  2822. }
  2823. if (iadev->phy_type == FE_DS3_PHY)
  2824. n = sprintf(page, " Board Type : Iphase-ATM-DS3");
  2825. else if (iadev->phy_type == FE_E3_PHY)
  2826. n = sprintf(page, " Board Type : Iphase-ATM-E3");
  2827. else if (iadev->phy_type == FE_UTP_OPTION)
  2828. n = sprintf(page, " Board Type : Iphase-ATM-UTP155");
  2829. else
  2830. n = sprintf(page, " Board Type : Iphase-ATM-OC3");
  2831. tmpPtr = page + n;
  2832. if (iadev->pci_map_size == 0x40000)
  2833. n += sprintf(tmpPtr, "-1KVC-");
  2834. else
  2835. n += sprintf(tmpPtr, "-4KVC-");
  2836. tmpPtr = page + n;
  2837. if ((iadev->memType & MEM_SIZE_MASK) == MEM_SIZE_1M)
  2838. n += sprintf(tmpPtr, "1M \n");
  2839. else if ((iadev->memType & MEM_SIZE_MASK) == MEM_SIZE_512K)
  2840. n += sprintf(tmpPtr, "512K\n");
  2841. else
  2842. n += sprintf(tmpPtr, "128K\n");
  2843. return n;
  2844. }
  2845. if (!left) {
  2846. return sprintf(page, " Number of Tx Buffer: %u\n"
  2847. " Size of Tx Buffer : %u\n"
  2848. " Number of Rx Buffer: %u\n"
  2849. " Size of Rx Buffer : %u\n"
  2850. " Packets Receiverd : %u\n"
  2851. " Packets Transmitted: %u\n"
  2852. " Cells Received : %u\n"
  2853. " Cells Transmitted : %u\n"
  2854. " Board Dropped Cells: %u\n"
  2855. " Board Dropped Pkts : %u\n",
  2856. iadev->num_tx_desc, iadev->tx_buf_sz,
  2857. iadev->num_rx_desc, iadev->rx_buf_sz,
  2858. iadev->rx_pkt_cnt, iadev->tx_pkt_cnt,
  2859. iadev->rx_cell_cnt, iadev->tx_cell_cnt,
  2860. iadev->drop_rxcell, iadev->drop_rxpkt);
  2861. }
  2862. return 0;
  2863. }
  2864. static const struct atmdev_ops ops = {
  2865. .open = ia_open,
  2866. .close = ia_close,
  2867. .ioctl = ia_ioctl,
  2868. .getsockopt = ia_getsockopt,
  2869. .setsockopt = ia_setsockopt,
  2870. .send = ia_send,
  2871. .phy_put = ia_phy_put,
  2872. .phy_get = ia_phy_get,
  2873. .change_qos = ia_change_qos,
  2874. .proc_read = ia_proc_read,
  2875. .owner = THIS_MODULE,
  2876. };
  2877. static int ia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  2878. {
  2879. struct atm_dev *dev;
  2880. IADEV *iadev;
  2881. int ret;
  2882. iadev = kzalloc(sizeof(*iadev), GFP_KERNEL);
  2883. if (!iadev) {
  2884. ret = -ENOMEM;
  2885. goto err_out;
  2886. }
  2887. iadev->pci = pdev;
  2888. IF_INIT(printk("ia detected at bus:%d dev: %d function:%d\n",
  2889. pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));)
  2890. if (pci_enable_device(pdev)) {
  2891. ret = -ENODEV;
  2892. goto err_out_free_iadev;
  2893. }
  2894. dev = atm_dev_register(DEV_LABEL, &pdev->dev, &ops, -1, NULL);
  2895. if (!dev) {
  2896. ret = -ENOMEM;
  2897. goto err_out_disable_dev;
  2898. }
  2899. dev->dev_data = iadev;
  2900. IF_INIT(printk(DEV_LABEL "registered at (itf :%d)\n", dev->number);)
  2901. IF_INIT(printk("dev_id = 0x%p iadev->LineRate = %d \n", dev,
  2902. iadev->LineRate);)
  2903. pci_set_drvdata(pdev, dev);
  2904. ia_dev[iadev_count] = iadev;
  2905. _ia_dev[iadev_count] = dev;
  2906. iadev_count++;
  2907. if (ia_init(dev) || ia_start(dev)) {
  2908. IF_INIT(printk("IA register failed!\n");)
  2909. iadev_count--;
  2910. ia_dev[iadev_count] = NULL;
  2911. _ia_dev[iadev_count] = NULL;
  2912. ret = -EINVAL;
  2913. goto err_out_deregister_dev;
  2914. }
  2915. IF_EVENT(printk("iadev_count = %d\n", iadev_count);)
  2916. iadev->next_board = ia_boards;
  2917. ia_boards = dev;
  2918. return 0;
  2919. err_out_deregister_dev:
  2920. atm_dev_deregister(dev);
  2921. err_out_disable_dev:
  2922. pci_disable_device(pdev);
  2923. err_out_free_iadev:
  2924. kfree(iadev);
  2925. err_out:
  2926. return ret;
  2927. }
  2928. static void ia_remove_one(struct pci_dev *pdev)
  2929. {
  2930. struct atm_dev *dev = pci_get_drvdata(pdev);
  2931. IADEV *iadev = INPH_IA_DEV(dev);
  2932. /* Disable phy interrupts */
  2933. ia_phy_put(dev, ia_phy_get(dev, SUNI_RSOP_CIE) & ~(SUNI_RSOP_CIE_LOSE),
  2934. SUNI_RSOP_CIE);
  2935. udelay(1);
  2936. if (dev->phy && dev->phy->stop)
  2937. dev->phy->stop(dev);
  2938. /* De-register device */
  2939. free_irq(iadev->irq, dev);
  2940. iadev_count--;
  2941. ia_dev[iadev_count] = NULL;
  2942. _ia_dev[iadev_count] = NULL;
  2943. IF_EVENT(printk("deregistering iav at (itf:%d)\n", dev->number);)
  2944. atm_dev_deregister(dev);
  2945. iounmap(iadev->base);
  2946. pci_disable_device(pdev);
  2947. ia_free_rx(iadev);
  2948. ia_free_tx(iadev);
  2949. kfree(iadev);
  2950. }
  2951. static struct pci_device_id ia_pci_tbl[] = {
  2952. { PCI_VENDOR_ID_IPHASE, 0x0008, PCI_ANY_ID, PCI_ANY_ID, },
  2953. { PCI_VENDOR_ID_IPHASE, 0x0009, PCI_ANY_ID, PCI_ANY_ID, },
  2954. { 0,}
  2955. };
  2956. MODULE_DEVICE_TABLE(pci, ia_pci_tbl);
  2957. static struct pci_driver ia_driver = {
  2958. .name = DEV_LABEL,
  2959. .id_table = ia_pci_tbl,
  2960. .probe = ia_init_one,
  2961. .remove = ia_remove_one,
  2962. };
  2963. static int __init ia_module_init(void)
  2964. {
  2965. int ret;
  2966. ret = pci_register_driver(&ia_driver);
  2967. if (ret >= 0) {
  2968. ia_timer.expires = jiffies + 3*HZ;
  2969. add_timer(&ia_timer);
  2970. } else
  2971. printk(KERN_ERR DEV_LABEL ": no adapter found\n");
  2972. return ret;
  2973. }
  2974. static void __exit ia_module_exit(void)
  2975. {
  2976. pci_unregister_driver(&ia_driver);
  2977. del_timer(&ia_timer);
  2978. }
  2979. module_init(ia_module_init);
  2980. module_exit(ia_module_exit);