he.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869
  1. /*
  2. he.c
  3. ForeRunnerHE ATM Adapter driver for ATM on Linux
  4. Copyright (C) 1999-2001 Naval Research Laboratory
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /*
  18. he.c
  19. ForeRunnerHE ATM Adapter driver for ATM on Linux
  20. Copyright (C) 1999-2001 Naval Research Laboratory
  21. Permission to use, copy, modify and distribute this software and its
  22. documentation is hereby granted, provided that both the copyright
  23. notice and this permission notice appear in all copies of the software,
  24. derivative works or modified versions, and any portions thereof, and
  25. that both notices appear in supporting documentation.
  26. NRL ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
  27. DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
  28. RESULTING FROM THE USE OF THIS SOFTWARE.
  29. This driver was written using the "Programmer's Reference Manual for
  30. ForeRunnerHE(tm)", MANU0361-01 - Rev. A, 08/21/98.
  31. AUTHORS:
  32. chas williams <chas@cmf.nrl.navy.mil>
  33. eric kinzie <ekinzie@cmf.nrl.navy.mil>
  34. NOTES:
  35. 4096 supported 'connections'
  36. group 0 is used for all traffic
  37. interrupt queue 0 is used for all interrupts
  38. aal0 support (based on work from ulrich.u.muller@nokia.com)
  39. */
  40. #include <linux/module.h>
  41. #include <linux/kernel.h>
  42. #include <linux/skbuff.h>
  43. #include <linux/pci.h>
  44. #include <linux/errno.h>
  45. #include <linux/types.h>
  46. #include <linux/string.h>
  47. #include <linux/delay.h>
  48. #include <linux/init.h>
  49. #include <linux/mm.h>
  50. #include <linux/sched.h>
  51. #include <linux/timer.h>
  52. #include <linux/interrupt.h>
  53. #include <linux/dma-mapping.h>
  54. #include <linux/bitmap.h>
  55. #include <linux/slab.h>
  56. #include <asm/io.h>
  57. #include <asm/byteorder.h>
  58. #include <linux/uaccess.h>
  59. #include <linux/atmdev.h>
  60. #include <linux/atm.h>
  61. #include <linux/sonet.h>
  62. #undef USE_SCATTERGATHER
  63. #undef USE_CHECKSUM_HW /* still confused about this */
  64. /* #undef HE_DEBUG */
  65. #include "he.h"
  66. #include "suni.h"
  67. #include <linux/atm_he.h>
  68. #define hprintk(fmt,args...) printk(KERN_ERR DEV_LABEL "%d: " fmt, he_dev->number , ##args)
  69. #ifdef HE_DEBUG
  70. #define HPRINTK(fmt,args...) printk(KERN_DEBUG DEV_LABEL "%d: " fmt, he_dev->number , ##args)
  71. #else /* !HE_DEBUG */
  72. #define HPRINTK(fmt,args...) do { } while (0)
  73. #endif /* HE_DEBUG */
  74. /* declarations */
  75. static int he_open(struct atm_vcc *vcc);
  76. static void he_close(struct atm_vcc *vcc);
  77. static int he_send(struct atm_vcc *vcc, struct sk_buff *skb);
  78. static int he_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg);
  79. static irqreturn_t he_irq_handler(int irq, void *dev_id);
  80. static void he_tasklet(unsigned long data);
  81. static int he_proc_read(struct atm_dev *dev,loff_t *pos,char *page);
  82. static int he_start(struct atm_dev *dev);
  83. static void he_stop(struct he_dev *dev);
  84. static void he_phy_put(struct atm_dev *, unsigned char, unsigned long);
  85. static unsigned char he_phy_get(struct atm_dev *, unsigned long);
  86. static u8 read_prom_byte(struct he_dev *he_dev, int addr);
  87. /* globals */
  88. static struct he_dev *he_devs;
  89. static bool disable64;
  90. static short nvpibits = -1;
  91. static short nvcibits = -1;
  92. static short rx_skb_reserve = 16;
  93. static bool irq_coalesce = true;
  94. static bool sdh;
  95. /* Read from EEPROM = 0000 0011b */
  96. static unsigned int readtab[] = {
  97. CS_HIGH | CLK_HIGH,
  98. CS_LOW | CLK_LOW,
  99. CLK_HIGH, /* 0 */
  100. CLK_LOW,
  101. CLK_HIGH, /* 0 */
  102. CLK_LOW,
  103. CLK_HIGH, /* 0 */
  104. CLK_LOW,
  105. CLK_HIGH, /* 0 */
  106. CLK_LOW,
  107. CLK_HIGH, /* 0 */
  108. CLK_LOW,
  109. CLK_HIGH, /* 0 */
  110. CLK_LOW | SI_HIGH,
  111. CLK_HIGH | SI_HIGH, /* 1 */
  112. CLK_LOW | SI_HIGH,
  113. CLK_HIGH | SI_HIGH /* 1 */
  114. };
  115. /* Clock to read from/write to the EEPROM */
  116. static unsigned int clocktab[] = {
  117. CLK_LOW,
  118. CLK_HIGH,
  119. CLK_LOW,
  120. CLK_HIGH,
  121. CLK_LOW,
  122. CLK_HIGH,
  123. CLK_LOW,
  124. CLK_HIGH,
  125. CLK_LOW,
  126. CLK_HIGH,
  127. CLK_LOW,
  128. CLK_HIGH,
  129. CLK_LOW,
  130. CLK_HIGH,
  131. CLK_LOW,
  132. CLK_HIGH,
  133. CLK_LOW
  134. };
  135. static const struct atmdev_ops he_ops =
  136. {
  137. .open = he_open,
  138. .close = he_close,
  139. .ioctl = he_ioctl,
  140. .send = he_send,
  141. .phy_put = he_phy_put,
  142. .phy_get = he_phy_get,
  143. .proc_read = he_proc_read,
  144. .owner = THIS_MODULE
  145. };
  146. #define he_writel(dev, val, reg) do { writel(val, (dev)->membase + (reg)); wmb(); } while (0)
  147. #define he_readl(dev, reg) readl((dev)->membase + (reg))
  148. /* section 2.12 connection memory access */
  149. static __inline__ void
  150. he_writel_internal(struct he_dev *he_dev, unsigned val, unsigned addr,
  151. unsigned flags)
  152. {
  153. he_writel(he_dev, val, CON_DAT);
  154. (void) he_readl(he_dev, CON_DAT); /* flush posted writes */
  155. he_writel(he_dev, flags | CON_CTL_WRITE | CON_CTL_ADDR(addr), CON_CTL);
  156. while (he_readl(he_dev, CON_CTL) & CON_CTL_BUSY);
  157. }
  158. #define he_writel_rcm(dev, val, reg) \
  159. he_writel_internal(dev, val, reg, CON_CTL_RCM)
  160. #define he_writel_tcm(dev, val, reg) \
  161. he_writel_internal(dev, val, reg, CON_CTL_TCM)
  162. #define he_writel_mbox(dev, val, reg) \
  163. he_writel_internal(dev, val, reg, CON_CTL_MBOX)
  164. static unsigned
  165. he_readl_internal(struct he_dev *he_dev, unsigned addr, unsigned flags)
  166. {
  167. he_writel(he_dev, flags | CON_CTL_READ | CON_CTL_ADDR(addr), CON_CTL);
  168. while (he_readl(he_dev, CON_CTL) & CON_CTL_BUSY);
  169. return he_readl(he_dev, CON_DAT);
  170. }
  171. #define he_readl_rcm(dev, reg) \
  172. he_readl_internal(dev, reg, CON_CTL_RCM)
  173. #define he_readl_tcm(dev, reg) \
  174. he_readl_internal(dev, reg, CON_CTL_TCM)
  175. #define he_readl_mbox(dev, reg) \
  176. he_readl_internal(dev, reg, CON_CTL_MBOX)
  177. /* figure 2.2 connection id */
  178. #define he_mkcid(dev, vpi, vci) (((vpi << (dev)->vcibits) | vci) & 0x1fff)
  179. /* 2.5.1 per connection transmit state registers */
  180. #define he_writel_tsr0(dev, val, cid) \
  181. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 0)
  182. #define he_readl_tsr0(dev, cid) \
  183. he_readl_tcm(dev, CONFIG_TSRA | (cid << 3) | 0)
  184. #define he_writel_tsr1(dev, val, cid) \
  185. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 1)
  186. #define he_writel_tsr2(dev, val, cid) \
  187. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 2)
  188. #define he_writel_tsr3(dev, val, cid) \
  189. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 3)
  190. #define he_writel_tsr4(dev, val, cid) \
  191. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 4)
  192. /* from page 2-20
  193. *
  194. * NOTE While the transmit connection is active, bits 23 through 0
  195. * of this register must not be written by the host. Byte
  196. * enables should be used during normal operation when writing
  197. * the most significant byte.
  198. */
  199. #define he_writel_tsr4_upper(dev, val, cid) \
  200. he_writel_internal(dev, val, CONFIG_TSRA | (cid << 3) | 4, \
  201. CON_CTL_TCM \
  202. | CON_BYTE_DISABLE_2 \
  203. | CON_BYTE_DISABLE_1 \
  204. | CON_BYTE_DISABLE_0)
  205. #define he_readl_tsr4(dev, cid) \
  206. he_readl_tcm(dev, CONFIG_TSRA | (cid << 3) | 4)
  207. #define he_writel_tsr5(dev, val, cid) \
  208. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 5)
  209. #define he_writel_tsr6(dev, val, cid) \
  210. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 6)
  211. #define he_writel_tsr7(dev, val, cid) \
  212. he_writel_tcm(dev, val, CONFIG_TSRA | (cid << 3) | 7)
  213. #define he_writel_tsr8(dev, val, cid) \
  214. he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 0)
  215. #define he_writel_tsr9(dev, val, cid) \
  216. he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 1)
  217. #define he_writel_tsr10(dev, val, cid) \
  218. he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 2)
  219. #define he_writel_tsr11(dev, val, cid) \
  220. he_writel_tcm(dev, val, CONFIG_TSRB | (cid << 2) | 3)
  221. #define he_writel_tsr12(dev, val, cid) \
  222. he_writel_tcm(dev, val, CONFIG_TSRC | (cid << 1) | 0)
  223. #define he_writel_tsr13(dev, val, cid) \
  224. he_writel_tcm(dev, val, CONFIG_TSRC | (cid << 1) | 1)
  225. #define he_writel_tsr14(dev, val, cid) \
  226. he_writel_tcm(dev, val, CONFIG_TSRD | cid)
  227. #define he_writel_tsr14_upper(dev, val, cid) \
  228. he_writel_internal(dev, val, CONFIG_TSRD | cid, \
  229. CON_CTL_TCM \
  230. | CON_BYTE_DISABLE_2 \
  231. | CON_BYTE_DISABLE_1 \
  232. | CON_BYTE_DISABLE_0)
  233. /* 2.7.1 per connection receive state registers */
  234. #define he_writel_rsr0(dev, val, cid) \
  235. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 0)
  236. #define he_readl_rsr0(dev, cid) \
  237. he_readl_rcm(dev, 0x00000 | (cid << 3) | 0)
  238. #define he_writel_rsr1(dev, val, cid) \
  239. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 1)
  240. #define he_writel_rsr2(dev, val, cid) \
  241. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 2)
  242. #define he_writel_rsr3(dev, val, cid) \
  243. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 3)
  244. #define he_writel_rsr4(dev, val, cid) \
  245. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 4)
  246. #define he_writel_rsr5(dev, val, cid) \
  247. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 5)
  248. #define he_writel_rsr6(dev, val, cid) \
  249. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 6)
  250. #define he_writel_rsr7(dev, val, cid) \
  251. he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 7)
  252. static __inline__ struct atm_vcc*
  253. __find_vcc(struct he_dev *he_dev, unsigned cid)
  254. {
  255. struct hlist_head *head;
  256. struct atm_vcc *vcc;
  257. struct sock *s;
  258. short vpi;
  259. int vci;
  260. vpi = cid >> he_dev->vcibits;
  261. vci = cid & ((1 << he_dev->vcibits) - 1);
  262. head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
  263. sk_for_each(s, head) {
  264. vcc = atm_sk(s);
  265. if (vcc->dev == he_dev->atm_dev &&
  266. vcc->vci == vci && vcc->vpi == vpi &&
  267. vcc->qos.rxtp.traffic_class != ATM_NONE) {
  268. return vcc;
  269. }
  270. }
  271. return NULL;
  272. }
  273. static int he_init_one(struct pci_dev *pci_dev,
  274. const struct pci_device_id *pci_ent)
  275. {
  276. struct atm_dev *atm_dev = NULL;
  277. struct he_dev *he_dev = NULL;
  278. int err = 0;
  279. printk(KERN_INFO "ATM he driver\n");
  280. if (pci_enable_device(pci_dev))
  281. return -EIO;
  282. if (dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32)) != 0) {
  283. printk(KERN_WARNING "he: no suitable dma available\n");
  284. err = -EIO;
  285. goto init_one_failure;
  286. }
  287. atm_dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &he_ops, -1, NULL);
  288. if (!atm_dev) {
  289. err = -ENODEV;
  290. goto init_one_failure;
  291. }
  292. pci_set_drvdata(pci_dev, atm_dev);
  293. he_dev = kzalloc(sizeof(struct he_dev),
  294. GFP_KERNEL);
  295. if (!he_dev) {
  296. err = -ENOMEM;
  297. goto init_one_failure;
  298. }
  299. he_dev->pci_dev = pci_dev;
  300. he_dev->atm_dev = atm_dev;
  301. he_dev->atm_dev->dev_data = he_dev;
  302. atm_dev->dev_data = he_dev;
  303. he_dev->number = atm_dev->number;
  304. tasklet_init(&he_dev->tasklet, he_tasklet, (unsigned long) he_dev);
  305. spin_lock_init(&he_dev->global_lock);
  306. if (he_start(atm_dev)) {
  307. he_stop(he_dev);
  308. err = -ENODEV;
  309. goto init_one_failure;
  310. }
  311. he_dev->next = NULL;
  312. if (he_devs)
  313. he_dev->next = he_devs;
  314. he_devs = he_dev;
  315. return 0;
  316. init_one_failure:
  317. if (atm_dev)
  318. atm_dev_deregister(atm_dev);
  319. kfree(he_dev);
  320. pci_disable_device(pci_dev);
  321. return err;
  322. }
  323. static void he_remove_one(struct pci_dev *pci_dev)
  324. {
  325. struct atm_dev *atm_dev;
  326. struct he_dev *he_dev;
  327. atm_dev = pci_get_drvdata(pci_dev);
  328. he_dev = HE_DEV(atm_dev);
  329. /* need to remove from he_devs */
  330. he_stop(he_dev);
  331. atm_dev_deregister(atm_dev);
  332. kfree(he_dev);
  333. pci_disable_device(pci_dev);
  334. }
  335. static unsigned
  336. rate_to_atmf(unsigned rate) /* cps to atm forum format */
  337. {
  338. #define NONZERO (1 << 14)
  339. unsigned exp = 0;
  340. if (rate == 0)
  341. return 0;
  342. rate <<= 9;
  343. while (rate > 0x3ff) {
  344. ++exp;
  345. rate >>= 1;
  346. }
  347. return (NONZERO | (exp << 9) | (rate & 0x1ff));
  348. }
  349. static void he_init_rx_lbfp0(struct he_dev *he_dev)
  350. {
  351. unsigned i, lbm_offset, lbufd_index, lbuf_addr, lbuf_count;
  352. unsigned lbufs_per_row = he_dev->cells_per_row / he_dev->cells_per_lbuf;
  353. unsigned lbuf_bufsize = he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD;
  354. unsigned row_offset = he_dev->r0_startrow * he_dev->bytes_per_row;
  355. lbufd_index = 0;
  356. lbm_offset = he_readl(he_dev, RCMLBM_BA);
  357. he_writel(he_dev, lbufd_index, RLBF0_H);
  358. for (i = 0, lbuf_count = 0; i < he_dev->r0_numbuffs; ++i) {
  359. lbufd_index += 2;
  360. lbuf_addr = (row_offset + (lbuf_count * lbuf_bufsize)) / 32;
  361. he_writel_rcm(he_dev, lbuf_addr, lbm_offset);
  362. he_writel_rcm(he_dev, lbufd_index, lbm_offset + 1);
  363. if (++lbuf_count == lbufs_per_row) {
  364. lbuf_count = 0;
  365. row_offset += he_dev->bytes_per_row;
  366. }
  367. lbm_offset += 4;
  368. }
  369. he_writel(he_dev, lbufd_index - 2, RLBF0_T);
  370. he_writel(he_dev, he_dev->r0_numbuffs, RLBF0_C);
  371. }
  372. static void he_init_rx_lbfp1(struct he_dev *he_dev)
  373. {
  374. unsigned i, lbm_offset, lbufd_index, lbuf_addr, lbuf_count;
  375. unsigned lbufs_per_row = he_dev->cells_per_row / he_dev->cells_per_lbuf;
  376. unsigned lbuf_bufsize = he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD;
  377. unsigned row_offset = he_dev->r1_startrow * he_dev->bytes_per_row;
  378. lbufd_index = 1;
  379. lbm_offset = he_readl(he_dev, RCMLBM_BA) + (2 * lbufd_index);
  380. he_writel(he_dev, lbufd_index, RLBF1_H);
  381. for (i = 0, lbuf_count = 0; i < he_dev->r1_numbuffs; ++i) {
  382. lbufd_index += 2;
  383. lbuf_addr = (row_offset + (lbuf_count * lbuf_bufsize)) / 32;
  384. he_writel_rcm(he_dev, lbuf_addr, lbm_offset);
  385. he_writel_rcm(he_dev, lbufd_index, lbm_offset + 1);
  386. if (++lbuf_count == lbufs_per_row) {
  387. lbuf_count = 0;
  388. row_offset += he_dev->bytes_per_row;
  389. }
  390. lbm_offset += 4;
  391. }
  392. he_writel(he_dev, lbufd_index - 2, RLBF1_T);
  393. he_writel(he_dev, he_dev->r1_numbuffs, RLBF1_C);
  394. }
  395. static void he_init_tx_lbfp(struct he_dev *he_dev)
  396. {
  397. unsigned i, lbm_offset, lbufd_index, lbuf_addr, lbuf_count;
  398. unsigned lbufs_per_row = he_dev->cells_per_row / he_dev->cells_per_lbuf;
  399. unsigned lbuf_bufsize = he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD;
  400. unsigned row_offset = he_dev->tx_startrow * he_dev->bytes_per_row;
  401. lbufd_index = he_dev->r0_numbuffs + he_dev->r1_numbuffs;
  402. lbm_offset = he_readl(he_dev, RCMLBM_BA) + (2 * lbufd_index);
  403. he_writel(he_dev, lbufd_index, TLBF_H);
  404. for (i = 0, lbuf_count = 0; i < he_dev->tx_numbuffs; ++i) {
  405. lbufd_index += 1;
  406. lbuf_addr = (row_offset + (lbuf_count * lbuf_bufsize)) / 32;
  407. he_writel_rcm(he_dev, lbuf_addr, lbm_offset);
  408. he_writel_rcm(he_dev, lbufd_index, lbm_offset + 1);
  409. if (++lbuf_count == lbufs_per_row) {
  410. lbuf_count = 0;
  411. row_offset += he_dev->bytes_per_row;
  412. }
  413. lbm_offset += 2;
  414. }
  415. he_writel(he_dev, lbufd_index - 1, TLBF_T);
  416. }
  417. static int he_init_tpdrq(struct he_dev *he_dev)
  418. {
  419. he_dev->tpdrq_base = dma_zalloc_coherent(&he_dev->pci_dev->dev,
  420. CONFIG_TPDRQ_SIZE * sizeof(struct he_tpdrq),
  421. &he_dev->tpdrq_phys, GFP_KERNEL);
  422. if (he_dev->tpdrq_base == NULL) {
  423. hprintk("failed to alloc tpdrq\n");
  424. return -ENOMEM;
  425. }
  426. he_dev->tpdrq_tail = he_dev->tpdrq_base;
  427. he_dev->tpdrq_head = he_dev->tpdrq_base;
  428. he_writel(he_dev, he_dev->tpdrq_phys, TPDRQ_B_H);
  429. he_writel(he_dev, 0, TPDRQ_T);
  430. he_writel(he_dev, CONFIG_TPDRQ_SIZE - 1, TPDRQ_S);
  431. return 0;
  432. }
  433. static void he_init_cs_block(struct he_dev *he_dev)
  434. {
  435. unsigned clock, rate, delta;
  436. int reg;
  437. /* 5.1.7 cs block initialization */
  438. for (reg = 0; reg < 0x20; ++reg)
  439. he_writel_mbox(he_dev, 0x0, CS_STTIM0 + reg);
  440. /* rate grid timer reload values */
  441. clock = he_is622(he_dev) ? 66667000 : 50000000;
  442. rate = he_dev->atm_dev->link_rate;
  443. delta = rate / 16 / 2;
  444. for (reg = 0; reg < 0x10; ++reg) {
  445. /* 2.4 internal transmit function
  446. *
  447. * we initialize the first row in the rate grid.
  448. * values are period (in clock cycles) of timer
  449. */
  450. unsigned period = clock / rate;
  451. he_writel_mbox(he_dev, period, CS_TGRLD0 + reg);
  452. rate -= delta;
  453. }
  454. if (he_is622(he_dev)) {
  455. /* table 5.2 (4 cells per lbuf) */
  456. he_writel_mbox(he_dev, 0x000800fa, CS_ERTHR0);
  457. he_writel_mbox(he_dev, 0x000c33cb, CS_ERTHR1);
  458. he_writel_mbox(he_dev, 0x0010101b, CS_ERTHR2);
  459. he_writel_mbox(he_dev, 0x00181dac, CS_ERTHR3);
  460. he_writel_mbox(he_dev, 0x00280600, CS_ERTHR4);
  461. /* table 5.3, 5.4, 5.5, 5.6, 5.7 */
  462. he_writel_mbox(he_dev, 0x023de8b3, CS_ERCTL0);
  463. he_writel_mbox(he_dev, 0x1801, CS_ERCTL1);
  464. he_writel_mbox(he_dev, 0x68b3, CS_ERCTL2);
  465. he_writel_mbox(he_dev, 0x1280, CS_ERSTAT0);
  466. he_writel_mbox(he_dev, 0x68b3, CS_ERSTAT1);
  467. he_writel_mbox(he_dev, 0x14585, CS_RTFWR);
  468. he_writel_mbox(he_dev, 0x4680, CS_RTATR);
  469. /* table 5.8 */
  470. he_writel_mbox(he_dev, 0x00159ece, CS_TFBSET);
  471. he_writel_mbox(he_dev, 0x68b3, CS_WCRMAX);
  472. he_writel_mbox(he_dev, 0x5eb3, CS_WCRMIN);
  473. he_writel_mbox(he_dev, 0xe8b3, CS_WCRINC);
  474. he_writel_mbox(he_dev, 0xdeb3, CS_WCRDEC);
  475. he_writel_mbox(he_dev, 0x68b3, CS_WCRCEIL);
  476. /* table 5.9 */
  477. he_writel_mbox(he_dev, 0x5, CS_OTPPER);
  478. he_writel_mbox(he_dev, 0x14, CS_OTWPER);
  479. } else {
  480. /* table 5.1 (4 cells per lbuf) */
  481. he_writel_mbox(he_dev, 0x000400ea, CS_ERTHR0);
  482. he_writel_mbox(he_dev, 0x00063388, CS_ERTHR1);
  483. he_writel_mbox(he_dev, 0x00081018, CS_ERTHR2);
  484. he_writel_mbox(he_dev, 0x000c1dac, CS_ERTHR3);
  485. he_writel_mbox(he_dev, 0x0014051a, CS_ERTHR4);
  486. /* table 5.3, 5.4, 5.5, 5.6, 5.7 */
  487. he_writel_mbox(he_dev, 0x0235e4b1, CS_ERCTL0);
  488. he_writel_mbox(he_dev, 0x4701, CS_ERCTL1);
  489. he_writel_mbox(he_dev, 0x64b1, CS_ERCTL2);
  490. he_writel_mbox(he_dev, 0x1280, CS_ERSTAT0);
  491. he_writel_mbox(he_dev, 0x64b1, CS_ERSTAT1);
  492. he_writel_mbox(he_dev, 0xf424, CS_RTFWR);
  493. he_writel_mbox(he_dev, 0x4680, CS_RTATR);
  494. /* table 5.8 */
  495. he_writel_mbox(he_dev, 0x000563b7, CS_TFBSET);
  496. he_writel_mbox(he_dev, 0x64b1, CS_WCRMAX);
  497. he_writel_mbox(he_dev, 0x5ab1, CS_WCRMIN);
  498. he_writel_mbox(he_dev, 0xe4b1, CS_WCRINC);
  499. he_writel_mbox(he_dev, 0xdab1, CS_WCRDEC);
  500. he_writel_mbox(he_dev, 0x64b1, CS_WCRCEIL);
  501. /* table 5.9 */
  502. he_writel_mbox(he_dev, 0x6, CS_OTPPER);
  503. he_writel_mbox(he_dev, 0x1e, CS_OTWPER);
  504. }
  505. he_writel_mbox(he_dev, 0x8, CS_OTTLIM);
  506. for (reg = 0; reg < 0x8; ++reg)
  507. he_writel_mbox(he_dev, 0x0, CS_HGRRT0 + reg);
  508. }
  509. static int he_init_cs_block_rcm(struct he_dev *he_dev)
  510. {
  511. unsigned (*rategrid)[16][16];
  512. unsigned rate, delta;
  513. int i, j, reg;
  514. unsigned rate_atmf, exp, man;
  515. unsigned long long rate_cps;
  516. int mult, buf, buf_limit = 4;
  517. rategrid = kmalloc( sizeof(unsigned) * 16 * 16, GFP_KERNEL);
  518. if (!rategrid)
  519. return -ENOMEM;
  520. /* initialize rate grid group table */
  521. for (reg = 0x0; reg < 0xff; ++reg)
  522. he_writel_rcm(he_dev, 0x0, CONFIG_RCMABR + reg);
  523. /* initialize rate controller groups */
  524. for (reg = 0x100; reg < 0x1ff; ++reg)
  525. he_writel_rcm(he_dev, 0x0, CONFIG_RCMABR + reg);
  526. /* initialize tNrm lookup table */
  527. /* the manual makes reference to a routine in a sample driver
  528. for proper configuration; fortunately, we only need this
  529. in order to support abr connection */
  530. /* initialize rate to group table */
  531. rate = he_dev->atm_dev->link_rate;
  532. delta = rate / 32;
  533. /*
  534. * 2.4 transmit internal functions
  535. *
  536. * we construct a copy of the rate grid used by the scheduler
  537. * in order to construct the rate to group table below
  538. */
  539. for (j = 0; j < 16; j++) {
  540. (*rategrid)[0][j] = rate;
  541. rate -= delta;
  542. }
  543. for (i = 1; i < 16; i++)
  544. for (j = 0; j < 16; j++)
  545. if (i > 14)
  546. (*rategrid)[i][j] = (*rategrid)[i - 1][j] / 4;
  547. else
  548. (*rategrid)[i][j] = (*rategrid)[i - 1][j] / 2;
  549. /*
  550. * 2.4 transmit internal function
  551. *
  552. * this table maps the upper 5 bits of exponent and mantissa
  553. * of the atm forum representation of the rate into an index
  554. * on rate grid
  555. */
  556. rate_atmf = 0;
  557. while (rate_atmf < 0x400) {
  558. man = (rate_atmf & 0x1f) << 4;
  559. exp = rate_atmf >> 5;
  560. /*
  561. instead of '/ 512', use '>> 9' to prevent a call
  562. to divdu3 on x86 platforms
  563. */
  564. rate_cps = (unsigned long long) (1UL << exp) * (man + 512) >> 9;
  565. if (rate_cps < 10)
  566. rate_cps = 10; /* 2.2.1 minimum payload rate is 10 cps */
  567. for (i = 255; i > 0; i--)
  568. if ((*rategrid)[i/16][i%16] >= rate_cps)
  569. break; /* pick nearest rate instead? */
  570. /*
  571. * each table entry is 16 bits: (rate grid index (8 bits)
  572. * and a buffer limit (8 bits)
  573. * there are two table entries in each 32-bit register
  574. */
  575. #ifdef notdef
  576. buf = rate_cps * he_dev->tx_numbuffs /
  577. (he_dev->atm_dev->link_rate * 2);
  578. #else
  579. /* this is pretty, but avoids _divdu3 and is mostly correct */
  580. mult = he_dev->atm_dev->link_rate / ATM_OC3_PCR;
  581. if (rate_cps > (272ULL * mult))
  582. buf = 4;
  583. else if (rate_cps > (204ULL * mult))
  584. buf = 3;
  585. else if (rate_cps > (136ULL * mult))
  586. buf = 2;
  587. else if (rate_cps > (68ULL * mult))
  588. buf = 1;
  589. else
  590. buf = 0;
  591. #endif
  592. if (buf > buf_limit)
  593. buf = buf_limit;
  594. reg = (reg << 16) | ((i << 8) | buf);
  595. #define RTGTBL_OFFSET 0x400
  596. if (rate_atmf & 0x1)
  597. he_writel_rcm(he_dev, reg,
  598. CONFIG_RCMABR + RTGTBL_OFFSET + (rate_atmf >> 1));
  599. ++rate_atmf;
  600. }
  601. kfree(rategrid);
  602. return 0;
  603. }
  604. static int he_init_group(struct he_dev *he_dev, int group)
  605. {
  606. struct he_buff *heb, *next;
  607. dma_addr_t mapping;
  608. int i;
  609. he_writel(he_dev, 0x0, G0_RBPS_S + (group * 32));
  610. he_writel(he_dev, 0x0, G0_RBPS_T + (group * 32));
  611. he_writel(he_dev, 0x0, G0_RBPS_QI + (group * 32));
  612. he_writel(he_dev, RBP_THRESH(0x1) | RBP_QSIZE(0x0),
  613. G0_RBPS_BS + (group * 32));
  614. /* bitmap table */
  615. he_dev->rbpl_table = kmalloc_array(BITS_TO_LONGS(RBPL_TABLE_SIZE),
  616. sizeof(*he_dev->rbpl_table),
  617. GFP_KERNEL);
  618. if (!he_dev->rbpl_table) {
  619. hprintk("unable to allocate rbpl bitmap table\n");
  620. return -ENOMEM;
  621. }
  622. bitmap_zero(he_dev->rbpl_table, RBPL_TABLE_SIZE);
  623. /* rbpl_virt 64-bit pointers */
  624. he_dev->rbpl_virt = kmalloc_array(RBPL_TABLE_SIZE,
  625. sizeof(*he_dev->rbpl_virt),
  626. GFP_KERNEL);
  627. if (!he_dev->rbpl_virt) {
  628. hprintk("unable to allocate rbpl virt table\n");
  629. goto out_free_rbpl_table;
  630. }
  631. /* large buffer pool */
  632. he_dev->rbpl_pool = dma_pool_create("rbpl", &he_dev->pci_dev->dev,
  633. CONFIG_RBPL_BUFSIZE, 64, 0);
  634. if (he_dev->rbpl_pool == NULL) {
  635. hprintk("unable to create rbpl pool\n");
  636. goto out_free_rbpl_virt;
  637. }
  638. he_dev->rbpl_base = dma_zalloc_coherent(&he_dev->pci_dev->dev,
  639. CONFIG_RBPL_SIZE * sizeof(struct he_rbp),
  640. &he_dev->rbpl_phys, GFP_KERNEL);
  641. if (he_dev->rbpl_base == NULL) {
  642. hprintk("failed to alloc rbpl_base\n");
  643. goto out_destroy_rbpl_pool;
  644. }
  645. INIT_LIST_HEAD(&he_dev->rbpl_outstanding);
  646. for (i = 0; i < CONFIG_RBPL_SIZE; ++i) {
  647. heb = dma_pool_alloc(he_dev->rbpl_pool, GFP_KERNEL, &mapping);
  648. if (!heb)
  649. goto out_free_rbpl;
  650. heb->mapping = mapping;
  651. list_add(&heb->entry, &he_dev->rbpl_outstanding);
  652. set_bit(i, he_dev->rbpl_table);
  653. he_dev->rbpl_virt[i] = heb;
  654. he_dev->rbpl_hint = i + 1;
  655. he_dev->rbpl_base[i].idx = i << RBP_IDX_OFFSET;
  656. he_dev->rbpl_base[i].phys = mapping + offsetof(struct he_buff, data);
  657. }
  658. he_dev->rbpl_tail = &he_dev->rbpl_base[CONFIG_RBPL_SIZE - 1];
  659. he_writel(he_dev, he_dev->rbpl_phys, G0_RBPL_S + (group * 32));
  660. he_writel(he_dev, RBPL_MASK(he_dev->rbpl_tail),
  661. G0_RBPL_T + (group * 32));
  662. he_writel(he_dev, (CONFIG_RBPL_BUFSIZE - sizeof(struct he_buff))/4,
  663. G0_RBPL_BS + (group * 32));
  664. he_writel(he_dev,
  665. RBP_THRESH(CONFIG_RBPL_THRESH) |
  666. RBP_QSIZE(CONFIG_RBPL_SIZE - 1) |
  667. RBP_INT_ENB,
  668. G0_RBPL_QI + (group * 32));
  669. /* rx buffer ready queue */
  670. he_dev->rbrq_base = dma_zalloc_coherent(&he_dev->pci_dev->dev,
  671. CONFIG_RBRQ_SIZE * sizeof(struct he_rbrq),
  672. &he_dev->rbrq_phys, GFP_KERNEL);
  673. if (he_dev->rbrq_base == NULL) {
  674. hprintk("failed to allocate rbrq\n");
  675. goto out_free_rbpl;
  676. }
  677. he_dev->rbrq_head = he_dev->rbrq_base;
  678. he_writel(he_dev, he_dev->rbrq_phys, G0_RBRQ_ST + (group * 16));
  679. he_writel(he_dev, 0, G0_RBRQ_H + (group * 16));
  680. he_writel(he_dev,
  681. RBRQ_THRESH(CONFIG_RBRQ_THRESH) | RBRQ_SIZE(CONFIG_RBRQ_SIZE - 1),
  682. G0_RBRQ_Q + (group * 16));
  683. if (irq_coalesce) {
  684. hprintk("coalescing interrupts\n");
  685. he_writel(he_dev, RBRQ_TIME(768) | RBRQ_COUNT(7),
  686. G0_RBRQ_I + (group * 16));
  687. } else
  688. he_writel(he_dev, RBRQ_TIME(0) | RBRQ_COUNT(1),
  689. G0_RBRQ_I + (group * 16));
  690. /* tx buffer ready queue */
  691. he_dev->tbrq_base = dma_zalloc_coherent(&he_dev->pci_dev->dev,
  692. CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq),
  693. &he_dev->tbrq_phys, GFP_KERNEL);
  694. if (he_dev->tbrq_base == NULL) {
  695. hprintk("failed to allocate tbrq\n");
  696. goto out_free_rbpq_base;
  697. }
  698. he_dev->tbrq_head = he_dev->tbrq_base;
  699. he_writel(he_dev, he_dev->tbrq_phys, G0_TBRQ_B_T + (group * 16));
  700. he_writel(he_dev, 0, G0_TBRQ_H + (group * 16));
  701. he_writel(he_dev, CONFIG_TBRQ_SIZE - 1, G0_TBRQ_S + (group * 16));
  702. he_writel(he_dev, CONFIG_TBRQ_THRESH, G0_TBRQ_THRESH + (group * 16));
  703. return 0;
  704. out_free_rbpq_base:
  705. dma_free_coherent(&he_dev->pci_dev->dev, CONFIG_RBRQ_SIZE *
  706. sizeof(struct he_rbrq), he_dev->rbrq_base,
  707. he_dev->rbrq_phys);
  708. out_free_rbpl:
  709. list_for_each_entry_safe(heb, next, &he_dev->rbpl_outstanding, entry)
  710. dma_pool_free(he_dev->rbpl_pool, heb, heb->mapping);
  711. dma_free_coherent(&he_dev->pci_dev->dev, CONFIG_RBPL_SIZE *
  712. sizeof(struct he_rbp), he_dev->rbpl_base,
  713. he_dev->rbpl_phys);
  714. out_destroy_rbpl_pool:
  715. dma_pool_destroy(he_dev->rbpl_pool);
  716. out_free_rbpl_virt:
  717. kfree(he_dev->rbpl_virt);
  718. out_free_rbpl_table:
  719. kfree(he_dev->rbpl_table);
  720. return -ENOMEM;
  721. }
  722. static int he_init_irq(struct he_dev *he_dev)
  723. {
  724. int i;
  725. /* 2.9.3.5 tail offset for each interrupt queue is located after the
  726. end of the interrupt queue */
  727. he_dev->irq_base = dma_zalloc_coherent(&he_dev->pci_dev->dev,
  728. (CONFIG_IRQ_SIZE + 1)
  729. * sizeof(struct he_irq),
  730. &he_dev->irq_phys,
  731. GFP_KERNEL);
  732. if (he_dev->irq_base == NULL) {
  733. hprintk("failed to allocate irq\n");
  734. return -ENOMEM;
  735. }
  736. he_dev->irq_tailoffset = (unsigned *)
  737. &he_dev->irq_base[CONFIG_IRQ_SIZE];
  738. *he_dev->irq_tailoffset = 0;
  739. he_dev->irq_head = he_dev->irq_base;
  740. he_dev->irq_tail = he_dev->irq_base;
  741. for (i = 0; i < CONFIG_IRQ_SIZE; ++i)
  742. he_dev->irq_base[i].isw = ITYPE_INVALID;
  743. he_writel(he_dev, he_dev->irq_phys, IRQ0_BASE);
  744. he_writel(he_dev,
  745. IRQ_SIZE(CONFIG_IRQ_SIZE) | IRQ_THRESH(CONFIG_IRQ_THRESH),
  746. IRQ0_HEAD);
  747. he_writel(he_dev, IRQ_INT_A | IRQ_TYPE_LINE, IRQ0_CNTL);
  748. he_writel(he_dev, 0x0, IRQ0_DATA);
  749. he_writel(he_dev, 0x0, IRQ1_BASE);
  750. he_writel(he_dev, 0x0, IRQ1_HEAD);
  751. he_writel(he_dev, 0x0, IRQ1_CNTL);
  752. he_writel(he_dev, 0x0, IRQ1_DATA);
  753. he_writel(he_dev, 0x0, IRQ2_BASE);
  754. he_writel(he_dev, 0x0, IRQ2_HEAD);
  755. he_writel(he_dev, 0x0, IRQ2_CNTL);
  756. he_writel(he_dev, 0x0, IRQ2_DATA);
  757. he_writel(he_dev, 0x0, IRQ3_BASE);
  758. he_writel(he_dev, 0x0, IRQ3_HEAD);
  759. he_writel(he_dev, 0x0, IRQ3_CNTL);
  760. he_writel(he_dev, 0x0, IRQ3_DATA);
  761. /* 2.9.3.2 interrupt queue mapping registers */
  762. he_writel(he_dev, 0x0, GRP_10_MAP);
  763. he_writel(he_dev, 0x0, GRP_32_MAP);
  764. he_writel(he_dev, 0x0, GRP_54_MAP);
  765. he_writel(he_dev, 0x0, GRP_76_MAP);
  766. if (request_irq(he_dev->pci_dev->irq,
  767. he_irq_handler, IRQF_SHARED, DEV_LABEL, he_dev)) {
  768. hprintk("irq %d already in use\n", he_dev->pci_dev->irq);
  769. return -EINVAL;
  770. }
  771. he_dev->irq = he_dev->pci_dev->irq;
  772. return 0;
  773. }
  774. static int he_start(struct atm_dev *dev)
  775. {
  776. struct he_dev *he_dev;
  777. struct pci_dev *pci_dev;
  778. unsigned long membase;
  779. u16 command;
  780. u32 gen_cntl_0, host_cntl, lb_swap;
  781. u8 cache_size, timer;
  782. unsigned err;
  783. unsigned int status, reg;
  784. int i, group;
  785. he_dev = HE_DEV(dev);
  786. pci_dev = he_dev->pci_dev;
  787. membase = pci_resource_start(pci_dev, 0);
  788. HPRINTK("membase = 0x%lx irq = %d.\n", membase, pci_dev->irq);
  789. /*
  790. * pci bus controller initialization
  791. */
  792. /* 4.3 pci bus controller-specific initialization */
  793. if (pci_read_config_dword(pci_dev, GEN_CNTL_0, &gen_cntl_0) != 0) {
  794. hprintk("can't read GEN_CNTL_0\n");
  795. return -EINVAL;
  796. }
  797. gen_cntl_0 |= (MRL_ENB | MRM_ENB | IGNORE_TIMEOUT);
  798. if (pci_write_config_dword(pci_dev, GEN_CNTL_0, gen_cntl_0) != 0) {
  799. hprintk("can't write GEN_CNTL_0.\n");
  800. return -EINVAL;
  801. }
  802. if (pci_read_config_word(pci_dev, PCI_COMMAND, &command) != 0) {
  803. hprintk("can't read PCI_COMMAND.\n");
  804. return -EINVAL;
  805. }
  806. command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE);
  807. if (pci_write_config_word(pci_dev, PCI_COMMAND, command) != 0) {
  808. hprintk("can't enable memory.\n");
  809. return -EINVAL;
  810. }
  811. if (pci_read_config_byte(pci_dev, PCI_CACHE_LINE_SIZE, &cache_size)) {
  812. hprintk("can't read cache line size?\n");
  813. return -EINVAL;
  814. }
  815. if (cache_size < 16) {
  816. cache_size = 16;
  817. if (pci_write_config_byte(pci_dev, PCI_CACHE_LINE_SIZE, cache_size))
  818. hprintk("can't set cache line size to %d\n", cache_size);
  819. }
  820. if (pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &timer)) {
  821. hprintk("can't read latency timer?\n");
  822. return -EINVAL;
  823. }
  824. /* from table 3.9
  825. *
  826. * LAT_TIMER = 1 + AVG_LAT + BURST_SIZE/BUS_SIZE
  827. *
  828. * AVG_LAT: The average first data read/write latency [maximum 16 clock cycles]
  829. * BURST_SIZE: 1536 bytes (read) for 622, 768 bytes (read) for 155 [192 clock cycles]
  830. *
  831. */
  832. #define LAT_TIMER 209
  833. if (timer < LAT_TIMER) {
  834. HPRINTK("latency timer was %d, setting to %d\n", timer, LAT_TIMER);
  835. timer = LAT_TIMER;
  836. if (pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, timer))
  837. hprintk("can't set latency timer to %d\n", timer);
  838. }
  839. if (!(he_dev->membase = ioremap(membase, HE_REGMAP_SIZE))) {
  840. hprintk("can't set up page mapping\n");
  841. return -EINVAL;
  842. }
  843. /* 4.4 card reset */
  844. he_writel(he_dev, 0x0, RESET_CNTL);
  845. he_writel(he_dev, 0xff, RESET_CNTL);
  846. msleep(16); /* 16 ms */
  847. status = he_readl(he_dev, RESET_CNTL);
  848. if ((status & BOARD_RST_STATUS) == 0) {
  849. hprintk("reset failed\n");
  850. return -EINVAL;
  851. }
  852. /* 4.5 set bus width */
  853. host_cntl = he_readl(he_dev, HOST_CNTL);
  854. if (host_cntl & PCI_BUS_SIZE64)
  855. gen_cntl_0 |= ENBL_64;
  856. else
  857. gen_cntl_0 &= ~ENBL_64;
  858. if (disable64 == 1) {
  859. hprintk("disabling 64-bit pci bus transfers\n");
  860. gen_cntl_0 &= ~ENBL_64;
  861. }
  862. if (gen_cntl_0 & ENBL_64)
  863. hprintk("64-bit transfers enabled\n");
  864. pci_write_config_dword(pci_dev, GEN_CNTL_0, gen_cntl_0);
  865. /* 4.7 read prom contents */
  866. for (i = 0; i < PROD_ID_LEN; ++i)
  867. he_dev->prod_id[i] = read_prom_byte(he_dev, PROD_ID + i);
  868. he_dev->media = read_prom_byte(he_dev, MEDIA);
  869. for (i = 0; i < 6; ++i)
  870. dev->esi[i] = read_prom_byte(he_dev, MAC_ADDR + i);
  871. hprintk("%s%s, %pM\n", he_dev->prod_id,
  872. he_dev->media & 0x40 ? "SM" : "MM", dev->esi);
  873. he_dev->atm_dev->link_rate = he_is622(he_dev) ?
  874. ATM_OC12_PCR : ATM_OC3_PCR;
  875. /* 4.6 set host endianess */
  876. lb_swap = he_readl(he_dev, LB_SWAP);
  877. if (he_is622(he_dev))
  878. lb_swap &= ~XFER_SIZE; /* 4 cells */
  879. else
  880. lb_swap |= XFER_SIZE; /* 8 cells */
  881. #ifdef __BIG_ENDIAN
  882. lb_swap |= DESC_WR_SWAP | INTR_SWAP | BIG_ENDIAN_HOST;
  883. #else
  884. lb_swap &= ~(DESC_WR_SWAP | INTR_SWAP | BIG_ENDIAN_HOST |
  885. DATA_WR_SWAP | DATA_RD_SWAP | DESC_RD_SWAP);
  886. #endif /* __BIG_ENDIAN */
  887. he_writel(he_dev, lb_swap, LB_SWAP);
  888. /* 4.8 sdram controller initialization */
  889. he_writel(he_dev, he_is622(he_dev) ? LB_64_ENB : 0x0, SDRAM_CTL);
  890. /* 4.9 initialize rnum value */
  891. lb_swap |= SWAP_RNUM_MAX(0xf);
  892. he_writel(he_dev, lb_swap, LB_SWAP);
  893. /* 4.10 initialize the interrupt queues */
  894. if ((err = he_init_irq(he_dev)) != 0)
  895. return err;
  896. /* 4.11 enable pci bus controller state machines */
  897. host_cntl |= (OUTFF_ENB | CMDFF_ENB |
  898. QUICK_RD_RETRY | QUICK_WR_RETRY | PERR_INT_ENB);
  899. he_writel(he_dev, host_cntl, HOST_CNTL);
  900. gen_cntl_0 |= INT_PROC_ENBL|INIT_ENB;
  901. pci_write_config_dword(pci_dev, GEN_CNTL_0, gen_cntl_0);
  902. /*
  903. * atm network controller initialization
  904. */
  905. /* 5.1.1 generic configuration state */
  906. /*
  907. * local (cell) buffer memory map
  908. *
  909. * HE155 HE622
  910. *
  911. * 0 ____________1023 bytes 0 _______________________2047 bytes
  912. * | | | | |
  913. * | utility | | rx0 | |
  914. * 5|____________| 255|___________________| u |
  915. * 6| | 256| | t |
  916. * | | | | i |
  917. * | rx0 | row | tx | l |
  918. * | | | | i |
  919. * | | 767|___________________| t |
  920. * 517|____________| 768| | y |
  921. * row 518| | | rx1 | |
  922. * | | 1023|___________________|___|
  923. * | |
  924. * | tx |
  925. * | |
  926. * | |
  927. * 1535|____________|
  928. * 1536| |
  929. * | rx1 |
  930. * 2047|____________|
  931. *
  932. */
  933. /* total 4096 connections */
  934. he_dev->vcibits = CONFIG_DEFAULT_VCIBITS;
  935. he_dev->vpibits = CONFIG_DEFAULT_VPIBITS;
  936. if (nvpibits != -1 && nvcibits != -1 && nvpibits+nvcibits != HE_MAXCIDBITS) {
  937. hprintk("nvpibits + nvcibits != %d\n", HE_MAXCIDBITS);
  938. return -ENODEV;
  939. }
  940. if (nvpibits != -1) {
  941. he_dev->vpibits = nvpibits;
  942. he_dev->vcibits = HE_MAXCIDBITS - nvpibits;
  943. }
  944. if (nvcibits != -1) {
  945. he_dev->vcibits = nvcibits;
  946. he_dev->vpibits = HE_MAXCIDBITS - nvcibits;
  947. }
  948. if (he_is622(he_dev)) {
  949. he_dev->cells_per_row = 40;
  950. he_dev->bytes_per_row = 2048;
  951. he_dev->r0_numrows = 256;
  952. he_dev->tx_numrows = 512;
  953. he_dev->r1_numrows = 256;
  954. he_dev->r0_startrow = 0;
  955. he_dev->tx_startrow = 256;
  956. he_dev->r1_startrow = 768;
  957. } else {
  958. he_dev->cells_per_row = 20;
  959. he_dev->bytes_per_row = 1024;
  960. he_dev->r0_numrows = 512;
  961. he_dev->tx_numrows = 1018;
  962. he_dev->r1_numrows = 512;
  963. he_dev->r0_startrow = 6;
  964. he_dev->tx_startrow = 518;
  965. he_dev->r1_startrow = 1536;
  966. }
  967. he_dev->cells_per_lbuf = 4;
  968. he_dev->buffer_limit = 4;
  969. he_dev->r0_numbuffs = he_dev->r0_numrows *
  970. he_dev->cells_per_row / he_dev->cells_per_lbuf;
  971. if (he_dev->r0_numbuffs > 2560)
  972. he_dev->r0_numbuffs = 2560;
  973. he_dev->r1_numbuffs = he_dev->r1_numrows *
  974. he_dev->cells_per_row / he_dev->cells_per_lbuf;
  975. if (he_dev->r1_numbuffs > 2560)
  976. he_dev->r1_numbuffs = 2560;
  977. he_dev->tx_numbuffs = he_dev->tx_numrows *
  978. he_dev->cells_per_row / he_dev->cells_per_lbuf;
  979. if (he_dev->tx_numbuffs > 5120)
  980. he_dev->tx_numbuffs = 5120;
  981. /* 5.1.2 configure hardware dependent registers */
  982. he_writel(he_dev,
  983. SLICE_X(0x2) | ARB_RNUM_MAX(0xf) | TH_PRTY(0x3) |
  984. RH_PRTY(0x3) | TL_PRTY(0x2) | RL_PRTY(0x1) |
  985. (he_is622(he_dev) ? BUS_MULTI(0x28) : BUS_MULTI(0x46)) |
  986. (he_is622(he_dev) ? NET_PREF(0x50) : NET_PREF(0x8c)),
  987. LBARB);
  988. he_writel(he_dev, BANK_ON |
  989. (he_is622(he_dev) ? (REF_RATE(0x384) | WIDE_DATA) : REF_RATE(0x150)),
  990. SDRAMCON);
  991. he_writel(he_dev,
  992. (he_is622(he_dev) ? RM_BANK_WAIT(1) : RM_BANK_WAIT(0)) |
  993. RM_RW_WAIT(1), RCMCONFIG);
  994. he_writel(he_dev,
  995. (he_is622(he_dev) ? TM_BANK_WAIT(2) : TM_BANK_WAIT(1)) |
  996. TM_RW_WAIT(1), TCMCONFIG);
  997. he_writel(he_dev, he_dev->cells_per_lbuf * ATM_CELL_PAYLOAD, LB_CONFIG);
  998. he_writel(he_dev,
  999. (he_is622(he_dev) ? UT_RD_DELAY(8) : UT_RD_DELAY(0)) |
  1000. (he_is622(he_dev) ? RC_UT_MODE(0) : RC_UT_MODE(1)) |
  1001. RX_VALVP(he_dev->vpibits) |
  1002. RX_VALVC(he_dev->vcibits), RC_CONFIG);
  1003. he_writel(he_dev, DRF_THRESH(0x20) |
  1004. (he_is622(he_dev) ? TX_UT_MODE(0) : TX_UT_MODE(1)) |
  1005. TX_VCI_MASK(he_dev->vcibits) |
  1006. LBFREE_CNT(he_dev->tx_numbuffs), TX_CONFIG);
  1007. he_writel(he_dev, 0x0, TXAAL5_PROTO);
  1008. he_writel(he_dev, PHY_INT_ENB |
  1009. (he_is622(he_dev) ? PTMR_PRE(67 - 1) : PTMR_PRE(50 - 1)),
  1010. RH_CONFIG);
  1011. /* 5.1.3 initialize connection memory */
  1012. for (i = 0; i < TCM_MEM_SIZE; ++i)
  1013. he_writel_tcm(he_dev, 0, i);
  1014. for (i = 0; i < RCM_MEM_SIZE; ++i)
  1015. he_writel_rcm(he_dev, 0, i);
  1016. /*
  1017. * transmit connection memory map
  1018. *
  1019. * tx memory
  1020. * 0x0 ___________________
  1021. * | |
  1022. * | |
  1023. * | TSRa |
  1024. * | |
  1025. * | |
  1026. * 0x8000|___________________|
  1027. * | |
  1028. * | TSRb |
  1029. * 0xc000|___________________|
  1030. * | |
  1031. * | TSRc |
  1032. * 0xe000|___________________|
  1033. * | TSRd |
  1034. * 0xf000|___________________|
  1035. * | tmABR |
  1036. * 0x10000|___________________|
  1037. * | |
  1038. * | tmTPD |
  1039. * |___________________|
  1040. * | |
  1041. * ....
  1042. * 0x1ffff|___________________|
  1043. *
  1044. *
  1045. */
  1046. he_writel(he_dev, CONFIG_TSRB, TSRB_BA);
  1047. he_writel(he_dev, CONFIG_TSRC, TSRC_BA);
  1048. he_writel(he_dev, CONFIG_TSRD, TSRD_BA);
  1049. he_writel(he_dev, CONFIG_TMABR, TMABR_BA);
  1050. he_writel(he_dev, CONFIG_TPDBA, TPD_BA);
  1051. /*
  1052. * receive connection memory map
  1053. *
  1054. * 0x0 ___________________
  1055. * | |
  1056. * | |
  1057. * | RSRa |
  1058. * | |
  1059. * | |
  1060. * 0x8000|___________________|
  1061. * | |
  1062. * | rx0/1 |
  1063. * | LBM | link lists of local
  1064. * | tx | buffer memory
  1065. * | |
  1066. * 0xd000|___________________|
  1067. * | |
  1068. * | rmABR |
  1069. * 0xe000|___________________|
  1070. * | |
  1071. * | RSRb |
  1072. * |___________________|
  1073. * | |
  1074. * ....
  1075. * 0xffff|___________________|
  1076. */
  1077. he_writel(he_dev, 0x08000, RCMLBM_BA);
  1078. he_writel(he_dev, 0x0e000, RCMRSRB_BA);
  1079. he_writel(he_dev, 0x0d800, RCMABR_BA);
  1080. /* 5.1.4 initialize local buffer free pools linked lists */
  1081. he_init_rx_lbfp0(he_dev);
  1082. he_init_rx_lbfp1(he_dev);
  1083. he_writel(he_dev, 0x0, RLBC_H);
  1084. he_writel(he_dev, 0x0, RLBC_T);
  1085. he_writel(he_dev, 0x0, RLBC_H2);
  1086. he_writel(he_dev, 512, RXTHRSH); /* 10% of r0+r1 buffers */
  1087. he_writel(he_dev, 256, LITHRSH); /* 5% of r0+r1 buffers */
  1088. he_init_tx_lbfp(he_dev);
  1089. he_writel(he_dev, he_is622(he_dev) ? 0x104780 : 0x800, UBUFF_BA);
  1090. /* 5.1.5 initialize intermediate receive queues */
  1091. if (he_is622(he_dev)) {
  1092. he_writel(he_dev, 0x000f, G0_INMQ_S);
  1093. he_writel(he_dev, 0x200f, G0_INMQ_L);
  1094. he_writel(he_dev, 0x001f, G1_INMQ_S);
  1095. he_writel(he_dev, 0x201f, G1_INMQ_L);
  1096. he_writel(he_dev, 0x002f, G2_INMQ_S);
  1097. he_writel(he_dev, 0x202f, G2_INMQ_L);
  1098. he_writel(he_dev, 0x003f, G3_INMQ_S);
  1099. he_writel(he_dev, 0x203f, G3_INMQ_L);
  1100. he_writel(he_dev, 0x004f, G4_INMQ_S);
  1101. he_writel(he_dev, 0x204f, G4_INMQ_L);
  1102. he_writel(he_dev, 0x005f, G5_INMQ_S);
  1103. he_writel(he_dev, 0x205f, G5_INMQ_L);
  1104. he_writel(he_dev, 0x006f, G6_INMQ_S);
  1105. he_writel(he_dev, 0x206f, G6_INMQ_L);
  1106. he_writel(he_dev, 0x007f, G7_INMQ_S);
  1107. he_writel(he_dev, 0x207f, G7_INMQ_L);
  1108. } else {
  1109. he_writel(he_dev, 0x0000, G0_INMQ_S);
  1110. he_writel(he_dev, 0x0008, G0_INMQ_L);
  1111. he_writel(he_dev, 0x0001, G1_INMQ_S);
  1112. he_writel(he_dev, 0x0009, G1_INMQ_L);
  1113. he_writel(he_dev, 0x0002, G2_INMQ_S);
  1114. he_writel(he_dev, 0x000a, G2_INMQ_L);
  1115. he_writel(he_dev, 0x0003, G3_INMQ_S);
  1116. he_writel(he_dev, 0x000b, G3_INMQ_L);
  1117. he_writel(he_dev, 0x0004, G4_INMQ_S);
  1118. he_writel(he_dev, 0x000c, G4_INMQ_L);
  1119. he_writel(he_dev, 0x0005, G5_INMQ_S);
  1120. he_writel(he_dev, 0x000d, G5_INMQ_L);
  1121. he_writel(he_dev, 0x0006, G6_INMQ_S);
  1122. he_writel(he_dev, 0x000e, G6_INMQ_L);
  1123. he_writel(he_dev, 0x0007, G7_INMQ_S);
  1124. he_writel(he_dev, 0x000f, G7_INMQ_L);
  1125. }
  1126. /* 5.1.6 application tunable parameters */
  1127. he_writel(he_dev, 0x0, MCC);
  1128. he_writel(he_dev, 0x0, OEC);
  1129. he_writel(he_dev, 0x0, DCC);
  1130. he_writel(he_dev, 0x0, CEC);
  1131. /* 5.1.7 cs block initialization */
  1132. he_init_cs_block(he_dev);
  1133. /* 5.1.8 cs block connection memory initialization */
  1134. if (he_init_cs_block_rcm(he_dev) < 0)
  1135. return -ENOMEM;
  1136. /* 5.1.10 initialize host structures */
  1137. he_init_tpdrq(he_dev);
  1138. he_dev->tpd_pool = dma_pool_create("tpd", &he_dev->pci_dev->dev,
  1139. sizeof(struct he_tpd), TPD_ALIGNMENT, 0);
  1140. if (he_dev->tpd_pool == NULL) {
  1141. hprintk("unable to create tpd dma_pool\n");
  1142. return -ENOMEM;
  1143. }
  1144. INIT_LIST_HEAD(&he_dev->outstanding_tpds);
  1145. if (he_init_group(he_dev, 0) != 0)
  1146. return -ENOMEM;
  1147. for (group = 1; group < HE_NUM_GROUPS; ++group) {
  1148. he_writel(he_dev, 0x0, G0_RBPS_S + (group * 32));
  1149. he_writel(he_dev, 0x0, G0_RBPS_T + (group * 32));
  1150. he_writel(he_dev, 0x0, G0_RBPS_QI + (group * 32));
  1151. he_writel(he_dev, RBP_THRESH(0x1) | RBP_QSIZE(0x0),
  1152. G0_RBPS_BS + (group * 32));
  1153. he_writel(he_dev, 0x0, G0_RBPL_S + (group * 32));
  1154. he_writel(he_dev, 0x0, G0_RBPL_T + (group * 32));
  1155. he_writel(he_dev, RBP_THRESH(0x1) | RBP_QSIZE(0x0),
  1156. G0_RBPL_QI + (group * 32));
  1157. he_writel(he_dev, 0x0, G0_RBPL_BS + (group * 32));
  1158. he_writel(he_dev, 0x0, G0_RBRQ_ST + (group * 16));
  1159. he_writel(he_dev, 0x0, G0_RBRQ_H + (group * 16));
  1160. he_writel(he_dev, RBRQ_THRESH(0x1) | RBRQ_SIZE(0x0),
  1161. G0_RBRQ_Q + (group * 16));
  1162. he_writel(he_dev, 0x0, G0_RBRQ_I + (group * 16));
  1163. he_writel(he_dev, 0x0, G0_TBRQ_B_T + (group * 16));
  1164. he_writel(he_dev, 0x0, G0_TBRQ_H + (group * 16));
  1165. he_writel(he_dev, TBRQ_THRESH(0x1),
  1166. G0_TBRQ_THRESH + (group * 16));
  1167. he_writel(he_dev, 0x0, G0_TBRQ_S + (group * 16));
  1168. }
  1169. /* host status page */
  1170. he_dev->hsp = dma_zalloc_coherent(&he_dev->pci_dev->dev,
  1171. sizeof(struct he_hsp),
  1172. &he_dev->hsp_phys, GFP_KERNEL);
  1173. if (he_dev->hsp == NULL) {
  1174. hprintk("failed to allocate host status page\n");
  1175. return -ENOMEM;
  1176. }
  1177. he_writel(he_dev, he_dev->hsp_phys, HSP_BA);
  1178. /* initialize framer */
  1179. #ifdef CONFIG_ATM_HE_USE_SUNI
  1180. if (he_isMM(he_dev))
  1181. suni_init(he_dev->atm_dev);
  1182. if (he_dev->atm_dev->phy && he_dev->atm_dev->phy->start)
  1183. he_dev->atm_dev->phy->start(he_dev->atm_dev);
  1184. #endif /* CONFIG_ATM_HE_USE_SUNI */
  1185. if (sdh) {
  1186. /* this really should be in suni.c but for now... */
  1187. int val;
  1188. val = he_phy_get(he_dev->atm_dev, SUNI_TPOP_APM);
  1189. val = (val & ~SUNI_TPOP_APM_S) | (SUNI_TPOP_S_SDH << SUNI_TPOP_APM_S_SHIFT);
  1190. he_phy_put(he_dev->atm_dev, val, SUNI_TPOP_APM);
  1191. he_phy_put(he_dev->atm_dev, SUNI_TACP_IUCHP_CLP, SUNI_TACP_IUCHP);
  1192. }
  1193. /* 5.1.12 enable transmit and receive */
  1194. reg = he_readl_mbox(he_dev, CS_ERCTL0);
  1195. reg |= TX_ENABLE|ER_ENABLE;
  1196. he_writel_mbox(he_dev, reg, CS_ERCTL0);
  1197. reg = he_readl(he_dev, RC_CONFIG);
  1198. reg |= RX_ENABLE;
  1199. he_writel(he_dev, reg, RC_CONFIG);
  1200. for (i = 0; i < HE_NUM_CS_STPER; ++i) {
  1201. he_dev->cs_stper[i].inuse = 0;
  1202. he_dev->cs_stper[i].pcr = -1;
  1203. }
  1204. he_dev->total_bw = 0;
  1205. /* atm linux initialization */
  1206. he_dev->atm_dev->ci_range.vpi_bits = he_dev->vpibits;
  1207. he_dev->atm_dev->ci_range.vci_bits = he_dev->vcibits;
  1208. he_dev->irq_peak = 0;
  1209. he_dev->rbrq_peak = 0;
  1210. he_dev->rbpl_peak = 0;
  1211. he_dev->tbrq_peak = 0;
  1212. HPRINTK("hell bent for leather!\n");
  1213. return 0;
  1214. }
  1215. static void
  1216. he_stop(struct he_dev *he_dev)
  1217. {
  1218. struct he_buff *heb, *next;
  1219. struct pci_dev *pci_dev;
  1220. u32 gen_cntl_0, reg;
  1221. u16 command;
  1222. pci_dev = he_dev->pci_dev;
  1223. /* disable interrupts */
  1224. if (he_dev->membase) {
  1225. pci_read_config_dword(pci_dev, GEN_CNTL_0, &gen_cntl_0);
  1226. gen_cntl_0 &= ~(INT_PROC_ENBL | INIT_ENB);
  1227. pci_write_config_dword(pci_dev, GEN_CNTL_0, gen_cntl_0);
  1228. tasklet_disable(&he_dev->tasklet);
  1229. /* disable recv and transmit */
  1230. reg = he_readl_mbox(he_dev, CS_ERCTL0);
  1231. reg &= ~(TX_ENABLE|ER_ENABLE);
  1232. he_writel_mbox(he_dev, reg, CS_ERCTL0);
  1233. reg = he_readl(he_dev, RC_CONFIG);
  1234. reg &= ~(RX_ENABLE);
  1235. he_writel(he_dev, reg, RC_CONFIG);
  1236. }
  1237. #ifdef CONFIG_ATM_HE_USE_SUNI
  1238. if (he_dev->atm_dev->phy && he_dev->atm_dev->phy->stop)
  1239. he_dev->atm_dev->phy->stop(he_dev->atm_dev);
  1240. #endif /* CONFIG_ATM_HE_USE_SUNI */
  1241. if (he_dev->irq)
  1242. free_irq(he_dev->irq, he_dev);
  1243. if (he_dev->irq_base)
  1244. dma_free_coherent(&he_dev->pci_dev->dev, (CONFIG_IRQ_SIZE + 1)
  1245. * sizeof(struct he_irq), he_dev->irq_base, he_dev->irq_phys);
  1246. if (he_dev->hsp)
  1247. dma_free_coherent(&he_dev->pci_dev->dev, sizeof(struct he_hsp),
  1248. he_dev->hsp, he_dev->hsp_phys);
  1249. if (he_dev->rbpl_base) {
  1250. list_for_each_entry_safe(heb, next, &he_dev->rbpl_outstanding, entry)
  1251. dma_pool_free(he_dev->rbpl_pool, heb, heb->mapping);
  1252. dma_free_coherent(&he_dev->pci_dev->dev, CONFIG_RBPL_SIZE
  1253. * sizeof(struct he_rbp), he_dev->rbpl_base, he_dev->rbpl_phys);
  1254. }
  1255. kfree(he_dev->rbpl_virt);
  1256. kfree(he_dev->rbpl_table);
  1257. dma_pool_destroy(he_dev->rbpl_pool);
  1258. if (he_dev->rbrq_base)
  1259. dma_free_coherent(&he_dev->pci_dev->dev, CONFIG_RBRQ_SIZE * sizeof(struct he_rbrq),
  1260. he_dev->rbrq_base, he_dev->rbrq_phys);
  1261. if (he_dev->tbrq_base)
  1262. dma_free_coherent(&he_dev->pci_dev->dev, CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq),
  1263. he_dev->tbrq_base, he_dev->tbrq_phys);
  1264. if (he_dev->tpdrq_base)
  1265. dma_free_coherent(&he_dev->pci_dev->dev, CONFIG_TBRQ_SIZE * sizeof(struct he_tbrq),
  1266. he_dev->tpdrq_base, he_dev->tpdrq_phys);
  1267. dma_pool_destroy(he_dev->tpd_pool);
  1268. if (he_dev->pci_dev) {
  1269. pci_read_config_word(he_dev->pci_dev, PCI_COMMAND, &command);
  1270. command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  1271. pci_write_config_word(he_dev->pci_dev, PCI_COMMAND, command);
  1272. }
  1273. if (he_dev->membase)
  1274. iounmap(he_dev->membase);
  1275. }
  1276. static struct he_tpd *
  1277. __alloc_tpd(struct he_dev *he_dev)
  1278. {
  1279. struct he_tpd *tpd;
  1280. dma_addr_t mapping;
  1281. tpd = dma_pool_alloc(he_dev->tpd_pool, GFP_ATOMIC, &mapping);
  1282. if (tpd == NULL)
  1283. return NULL;
  1284. tpd->status = TPD_ADDR(mapping);
  1285. tpd->reserved = 0;
  1286. tpd->iovec[0].addr = 0; tpd->iovec[0].len = 0;
  1287. tpd->iovec[1].addr = 0; tpd->iovec[1].len = 0;
  1288. tpd->iovec[2].addr = 0; tpd->iovec[2].len = 0;
  1289. return tpd;
  1290. }
  1291. #define AAL5_LEN(buf,len) \
  1292. ((((unsigned char *)(buf))[(len)-6] << 8) | \
  1293. (((unsigned char *)(buf))[(len)-5]))
  1294. /* 2.10.1.2 receive
  1295. *
  1296. * aal5 packets can optionally return the tcp checksum in the lower
  1297. * 16 bits of the crc (RSR0_TCP_CKSUM)
  1298. */
  1299. #define TCP_CKSUM(buf,len) \
  1300. ((((unsigned char *)(buf))[(len)-2] << 8) | \
  1301. (((unsigned char *)(buf))[(len-1)]))
  1302. static int
  1303. he_service_rbrq(struct he_dev *he_dev, int group)
  1304. {
  1305. struct he_rbrq *rbrq_tail = (struct he_rbrq *)
  1306. ((unsigned long)he_dev->rbrq_base |
  1307. he_dev->hsp->group[group].rbrq_tail);
  1308. unsigned cid, lastcid = -1;
  1309. struct sk_buff *skb;
  1310. struct atm_vcc *vcc = NULL;
  1311. struct he_vcc *he_vcc;
  1312. struct he_buff *heb, *next;
  1313. int i;
  1314. int pdus_assembled = 0;
  1315. int updated = 0;
  1316. read_lock(&vcc_sklist_lock);
  1317. while (he_dev->rbrq_head != rbrq_tail) {
  1318. ++updated;
  1319. HPRINTK("%p rbrq%d 0x%x len=%d cid=0x%x %s%s%s%s%s%s\n",
  1320. he_dev->rbrq_head, group,
  1321. RBRQ_ADDR(he_dev->rbrq_head),
  1322. RBRQ_BUFLEN(he_dev->rbrq_head),
  1323. RBRQ_CID(he_dev->rbrq_head),
  1324. RBRQ_CRC_ERR(he_dev->rbrq_head) ? " CRC_ERR" : "",
  1325. RBRQ_LEN_ERR(he_dev->rbrq_head) ? " LEN_ERR" : "",
  1326. RBRQ_END_PDU(he_dev->rbrq_head) ? " END_PDU" : "",
  1327. RBRQ_AAL5_PROT(he_dev->rbrq_head) ? " AAL5_PROT" : "",
  1328. RBRQ_CON_CLOSED(he_dev->rbrq_head) ? " CON_CLOSED" : "",
  1329. RBRQ_HBUF_ERR(he_dev->rbrq_head) ? " HBUF_ERR" : "");
  1330. i = RBRQ_ADDR(he_dev->rbrq_head) >> RBP_IDX_OFFSET;
  1331. heb = he_dev->rbpl_virt[i];
  1332. cid = RBRQ_CID(he_dev->rbrq_head);
  1333. if (cid != lastcid)
  1334. vcc = __find_vcc(he_dev, cid);
  1335. lastcid = cid;
  1336. if (vcc == NULL || (he_vcc = HE_VCC(vcc)) == NULL) {
  1337. hprintk("vcc/he_vcc == NULL (cid 0x%x)\n", cid);
  1338. if (!RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
  1339. clear_bit(i, he_dev->rbpl_table);
  1340. list_del(&heb->entry);
  1341. dma_pool_free(he_dev->rbpl_pool, heb, heb->mapping);
  1342. }
  1343. goto next_rbrq_entry;
  1344. }
  1345. if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
  1346. hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
  1347. atomic_inc(&vcc->stats->rx_drop);
  1348. goto return_host_buffers;
  1349. }
  1350. heb->len = RBRQ_BUFLEN(he_dev->rbrq_head) * 4;
  1351. clear_bit(i, he_dev->rbpl_table);
  1352. list_move_tail(&heb->entry, &he_vcc->buffers);
  1353. he_vcc->pdu_len += heb->len;
  1354. if (RBRQ_CON_CLOSED(he_dev->rbrq_head)) {
  1355. lastcid = -1;
  1356. HPRINTK("wake_up rx_waitq (cid 0x%x)\n", cid);
  1357. wake_up(&he_vcc->rx_waitq);
  1358. goto return_host_buffers;
  1359. }
  1360. if (!RBRQ_END_PDU(he_dev->rbrq_head))
  1361. goto next_rbrq_entry;
  1362. if (RBRQ_LEN_ERR(he_dev->rbrq_head)
  1363. || RBRQ_CRC_ERR(he_dev->rbrq_head)) {
  1364. HPRINTK("%s%s (%d.%d)\n",
  1365. RBRQ_CRC_ERR(he_dev->rbrq_head)
  1366. ? "CRC_ERR " : "",
  1367. RBRQ_LEN_ERR(he_dev->rbrq_head)
  1368. ? "LEN_ERR" : "",
  1369. vcc->vpi, vcc->vci);
  1370. atomic_inc(&vcc->stats->rx_err);
  1371. goto return_host_buffers;
  1372. }
  1373. skb = atm_alloc_charge(vcc, he_vcc->pdu_len + rx_skb_reserve,
  1374. GFP_ATOMIC);
  1375. if (!skb) {
  1376. HPRINTK("charge failed (%d.%d)\n", vcc->vpi, vcc->vci);
  1377. goto return_host_buffers;
  1378. }
  1379. if (rx_skb_reserve > 0)
  1380. skb_reserve(skb, rx_skb_reserve);
  1381. __net_timestamp(skb);
  1382. list_for_each_entry(heb, &he_vcc->buffers, entry)
  1383. skb_put_data(skb, &heb->data, heb->len);
  1384. switch (vcc->qos.aal) {
  1385. case ATM_AAL0:
  1386. /* 2.10.1.5 raw cell receive */
  1387. skb->len = ATM_AAL0_SDU;
  1388. skb_set_tail_pointer(skb, skb->len);
  1389. break;
  1390. case ATM_AAL5:
  1391. /* 2.10.1.2 aal5 receive */
  1392. skb->len = AAL5_LEN(skb->data, he_vcc->pdu_len);
  1393. skb_set_tail_pointer(skb, skb->len);
  1394. #ifdef USE_CHECKSUM_HW
  1395. if (vcc->vpi == 0 && vcc->vci >= ATM_NOT_RSV_VCI) {
  1396. skb->ip_summed = CHECKSUM_COMPLETE;
  1397. skb->csum = TCP_CKSUM(skb->data,
  1398. he_vcc->pdu_len);
  1399. }
  1400. #endif
  1401. break;
  1402. }
  1403. #ifdef should_never_happen
  1404. if (skb->len > vcc->qos.rxtp.max_sdu)
  1405. hprintk("pdu_len (%d) > vcc->qos.rxtp.max_sdu (%d)! cid 0x%x\n", skb->len, vcc->qos.rxtp.max_sdu, cid);
  1406. #endif
  1407. #ifdef notdef
  1408. ATM_SKB(skb)->vcc = vcc;
  1409. #endif
  1410. spin_unlock(&he_dev->global_lock);
  1411. vcc->push(vcc, skb);
  1412. spin_lock(&he_dev->global_lock);
  1413. atomic_inc(&vcc->stats->rx);
  1414. return_host_buffers:
  1415. ++pdus_assembled;
  1416. list_for_each_entry_safe(heb, next, &he_vcc->buffers, entry)
  1417. dma_pool_free(he_dev->rbpl_pool, heb, heb->mapping);
  1418. INIT_LIST_HEAD(&he_vcc->buffers);
  1419. he_vcc->pdu_len = 0;
  1420. next_rbrq_entry:
  1421. he_dev->rbrq_head = (struct he_rbrq *)
  1422. ((unsigned long) he_dev->rbrq_base |
  1423. RBRQ_MASK(he_dev->rbrq_head + 1));
  1424. }
  1425. read_unlock(&vcc_sklist_lock);
  1426. if (updated) {
  1427. if (updated > he_dev->rbrq_peak)
  1428. he_dev->rbrq_peak = updated;
  1429. he_writel(he_dev, RBRQ_MASK(he_dev->rbrq_head),
  1430. G0_RBRQ_H + (group * 16));
  1431. }
  1432. return pdus_assembled;
  1433. }
  1434. static void
  1435. he_service_tbrq(struct he_dev *he_dev, int group)
  1436. {
  1437. struct he_tbrq *tbrq_tail = (struct he_tbrq *)
  1438. ((unsigned long)he_dev->tbrq_base |
  1439. he_dev->hsp->group[group].tbrq_tail);
  1440. struct he_tpd *tpd;
  1441. int slot, updated = 0;
  1442. struct he_tpd *__tpd;
  1443. /* 2.1.6 transmit buffer return queue */
  1444. while (he_dev->tbrq_head != tbrq_tail) {
  1445. ++updated;
  1446. HPRINTK("tbrq%d 0x%x%s%s\n",
  1447. group,
  1448. TBRQ_TPD(he_dev->tbrq_head),
  1449. TBRQ_EOS(he_dev->tbrq_head) ? " EOS" : "",
  1450. TBRQ_MULTIPLE(he_dev->tbrq_head) ? " MULTIPLE" : "");
  1451. tpd = NULL;
  1452. list_for_each_entry(__tpd, &he_dev->outstanding_tpds, entry) {
  1453. if (TPD_ADDR(__tpd->status) == TBRQ_TPD(he_dev->tbrq_head)) {
  1454. tpd = __tpd;
  1455. list_del(&__tpd->entry);
  1456. break;
  1457. }
  1458. }
  1459. if (tpd == NULL) {
  1460. hprintk("unable to locate tpd for dma buffer %x\n",
  1461. TBRQ_TPD(he_dev->tbrq_head));
  1462. goto next_tbrq_entry;
  1463. }
  1464. if (TBRQ_EOS(he_dev->tbrq_head)) {
  1465. HPRINTK("wake_up(tx_waitq) cid 0x%x\n",
  1466. he_mkcid(he_dev, tpd->vcc->vpi, tpd->vcc->vci));
  1467. if (tpd->vcc)
  1468. wake_up(&HE_VCC(tpd->vcc)->tx_waitq);
  1469. goto next_tbrq_entry;
  1470. }
  1471. for (slot = 0; slot < TPD_MAXIOV; ++slot) {
  1472. if (tpd->iovec[slot].addr)
  1473. dma_unmap_single(&he_dev->pci_dev->dev,
  1474. tpd->iovec[slot].addr,
  1475. tpd->iovec[slot].len & TPD_LEN_MASK,
  1476. DMA_TO_DEVICE);
  1477. if (tpd->iovec[slot].len & TPD_LST)
  1478. break;
  1479. }
  1480. if (tpd->skb) { /* && !TBRQ_MULTIPLE(he_dev->tbrq_head) */
  1481. if (tpd->vcc && tpd->vcc->pop)
  1482. tpd->vcc->pop(tpd->vcc, tpd->skb);
  1483. else
  1484. dev_kfree_skb_any(tpd->skb);
  1485. }
  1486. next_tbrq_entry:
  1487. if (tpd)
  1488. dma_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
  1489. he_dev->tbrq_head = (struct he_tbrq *)
  1490. ((unsigned long) he_dev->tbrq_base |
  1491. TBRQ_MASK(he_dev->tbrq_head + 1));
  1492. }
  1493. if (updated) {
  1494. if (updated > he_dev->tbrq_peak)
  1495. he_dev->tbrq_peak = updated;
  1496. he_writel(he_dev, TBRQ_MASK(he_dev->tbrq_head),
  1497. G0_TBRQ_H + (group * 16));
  1498. }
  1499. }
  1500. static void
  1501. he_service_rbpl(struct he_dev *he_dev, int group)
  1502. {
  1503. struct he_rbp *new_tail;
  1504. struct he_rbp *rbpl_head;
  1505. struct he_buff *heb;
  1506. dma_addr_t mapping;
  1507. int i;
  1508. int moved = 0;
  1509. rbpl_head = (struct he_rbp *) ((unsigned long)he_dev->rbpl_base |
  1510. RBPL_MASK(he_readl(he_dev, G0_RBPL_S)));
  1511. for (;;) {
  1512. new_tail = (struct he_rbp *) ((unsigned long)he_dev->rbpl_base |
  1513. RBPL_MASK(he_dev->rbpl_tail+1));
  1514. /* table 3.42 -- rbpl_tail should never be set to rbpl_head */
  1515. if (new_tail == rbpl_head)
  1516. break;
  1517. i = find_next_zero_bit(he_dev->rbpl_table, RBPL_TABLE_SIZE, he_dev->rbpl_hint);
  1518. if (i > (RBPL_TABLE_SIZE - 1)) {
  1519. i = find_first_zero_bit(he_dev->rbpl_table, RBPL_TABLE_SIZE);
  1520. if (i > (RBPL_TABLE_SIZE - 1))
  1521. break;
  1522. }
  1523. he_dev->rbpl_hint = i + 1;
  1524. heb = dma_pool_alloc(he_dev->rbpl_pool, GFP_ATOMIC, &mapping);
  1525. if (!heb)
  1526. break;
  1527. heb->mapping = mapping;
  1528. list_add(&heb->entry, &he_dev->rbpl_outstanding);
  1529. he_dev->rbpl_virt[i] = heb;
  1530. set_bit(i, he_dev->rbpl_table);
  1531. new_tail->idx = i << RBP_IDX_OFFSET;
  1532. new_tail->phys = mapping + offsetof(struct he_buff, data);
  1533. he_dev->rbpl_tail = new_tail;
  1534. ++moved;
  1535. }
  1536. if (moved)
  1537. he_writel(he_dev, RBPL_MASK(he_dev->rbpl_tail), G0_RBPL_T);
  1538. }
  1539. static void
  1540. he_tasklet(unsigned long data)
  1541. {
  1542. unsigned long flags;
  1543. struct he_dev *he_dev = (struct he_dev *) data;
  1544. int group, type;
  1545. int updated = 0;
  1546. HPRINTK("tasklet (0x%lx)\n", data);
  1547. spin_lock_irqsave(&he_dev->global_lock, flags);
  1548. while (he_dev->irq_head != he_dev->irq_tail) {
  1549. ++updated;
  1550. type = ITYPE_TYPE(he_dev->irq_head->isw);
  1551. group = ITYPE_GROUP(he_dev->irq_head->isw);
  1552. switch (type) {
  1553. case ITYPE_RBRQ_THRESH:
  1554. HPRINTK("rbrq%d threshold\n", group);
  1555. /* fall through */
  1556. case ITYPE_RBRQ_TIMER:
  1557. if (he_service_rbrq(he_dev, group))
  1558. he_service_rbpl(he_dev, group);
  1559. break;
  1560. case ITYPE_TBRQ_THRESH:
  1561. HPRINTK("tbrq%d threshold\n", group);
  1562. /* fall through */
  1563. case ITYPE_TPD_COMPLETE:
  1564. he_service_tbrq(he_dev, group);
  1565. break;
  1566. case ITYPE_RBPL_THRESH:
  1567. he_service_rbpl(he_dev, group);
  1568. break;
  1569. case ITYPE_RBPS_THRESH:
  1570. /* shouldn't happen unless small buffers enabled */
  1571. break;
  1572. case ITYPE_PHY:
  1573. HPRINTK("phy interrupt\n");
  1574. #ifdef CONFIG_ATM_HE_USE_SUNI
  1575. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1576. if (he_dev->atm_dev->phy && he_dev->atm_dev->phy->interrupt)
  1577. he_dev->atm_dev->phy->interrupt(he_dev->atm_dev);
  1578. spin_lock_irqsave(&he_dev->global_lock, flags);
  1579. #endif
  1580. break;
  1581. case ITYPE_OTHER:
  1582. switch (type|group) {
  1583. case ITYPE_PARITY:
  1584. hprintk("parity error\n");
  1585. break;
  1586. case ITYPE_ABORT:
  1587. hprintk("abort 0x%x\n", he_readl(he_dev, ABORT_ADDR));
  1588. break;
  1589. }
  1590. break;
  1591. case ITYPE_TYPE(ITYPE_INVALID):
  1592. /* see 8.1.1 -- check all queues */
  1593. HPRINTK("isw not updated 0x%x\n", he_dev->irq_head->isw);
  1594. he_service_rbrq(he_dev, 0);
  1595. he_service_rbpl(he_dev, 0);
  1596. he_service_tbrq(he_dev, 0);
  1597. break;
  1598. default:
  1599. hprintk("bad isw 0x%x?\n", he_dev->irq_head->isw);
  1600. }
  1601. he_dev->irq_head->isw = ITYPE_INVALID;
  1602. he_dev->irq_head = (struct he_irq *) NEXT_ENTRY(he_dev->irq_base, he_dev->irq_head, IRQ_MASK);
  1603. }
  1604. if (updated) {
  1605. if (updated > he_dev->irq_peak)
  1606. he_dev->irq_peak = updated;
  1607. he_writel(he_dev,
  1608. IRQ_SIZE(CONFIG_IRQ_SIZE) |
  1609. IRQ_THRESH(CONFIG_IRQ_THRESH) |
  1610. IRQ_TAIL(he_dev->irq_tail), IRQ0_HEAD);
  1611. (void) he_readl(he_dev, INT_FIFO); /* 8.1.2 controller errata; flush posted writes */
  1612. }
  1613. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1614. }
  1615. static irqreturn_t
  1616. he_irq_handler(int irq, void *dev_id)
  1617. {
  1618. unsigned long flags;
  1619. struct he_dev *he_dev = (struct he_dev * )dev_id;
  1620. int handled = 0;
  1621. if (he_dev == NULL)
  1622. return IRQ_NONE;
  1623. spin_lock_irqsave(&he_dev->global_lock, flags);
  1624. he_dev->irq_tail = (struct he_irq *) (((unsigned long)he_dev->irq_base) |
  1625. (*he_dev->irq_tailoffset << 2));
  1626. if (he_dev->irq_tail == he_dev->irq_head) {
  1627. HPRINTK("tailoffset not updated?\n");
  1628. he_dev->irq_tail = (struct he_irq *) ((unsigned long)he_dev->irq_base |
  1629. ((he_readl(he_dev, IRQ0_BASE) & IRQ_MASK) << 2));
  1630. (void) he_readl(he_dev, INT_FIFO); /* 8.1.2 controller errata */
  1631. }
  1632. #ifdef DEBUG
  1633. if (he_dev->irq_head == he_dev->irq_tail /* && !IRQ_PENDING */)
  1634. hprintk("spurious (or shared) interrupt?\n");
  1635. #endif
  1636. if (he_dev->irq_head != he_dev->irq_tail) {
  1637. handled = 1;
  1638. tasklet_schedule(&he_dev->tasklet);
  1639. he_writel(he_dev, INT_CLEAR_A, INT_FIFO); /* clear interrupt */
  1640. (void) he_readl(he_dev, INT_FIFO); /* flush posted writes */
  1641. }
  1642. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1643. return IRQ_RETVAL(handled);
  1644. }
  1645. static __inline__ void
  1646. __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
  1647. {
  1648. struct he_tpdrq *new_tail;
  1649. HPRINTK("tpdrq %p cid 0x%x -> tpdrq_tail %p\n",
  1650. tpd, cid, he_dev->tpdrq_tail);
  1651. /* new_tail = he_dev->tpdrq_tail; */
  1652. new_tail = (struct he_tpdrq *) ((unsigned long) he_dev->tpdrq_base |
  1653. TPDRQ_MASK(he_dev->tpdrq_tail+1));
  1654. /*
  1655. * check to see if we are about to set the tail == head
  1656. * if true, update the head pointer from the adapter
  1657. * to see if this is really the case (reading the queue
  1658. * head for every enqueue would be unnecessarily slow)
  1659. */
  1660. if (new_tail == he_dev->tpdrq_head) {
  1661. he_dev->tpdrq_head = (struct he_tpdrq *)
  1662. (((unsigned long)he_dev->tpdrq_base) |
  1663. TPDRQ_MASK(he_readl(he_dev, TPDRQ_B_H)));
  1664. if (new_tail == he_dev->tpdrq_head) {
  1665. int slot;
  1666. hprintk("tpdrq full (cid 0x%x)\n", cid);
  1667. /*
  1668. * FIXME
  1669. * push tpd onto a transmit backlog queue
  1670. * after service_tbrq, service the backlog
  1671. * for now, we just drop the pdu
  1672. */
  1673. for (slot = 0; slot < TPD_MAXIOV; ++slot) {
  1674. if (tpd->iovec[slot].addr)
  1675. dma_unmap_single(&he_dev->pci_dev->dev,
  1676. tpd->iovec[slot].addr,
  1677. tpd->iovec[slot].len & TPD_LEN_MASK,
  1678. DMA_TO_DEVICE);
  1679. }
  1680. if (tpd->skb) {
  1681. if (tpd->vcc->pop)
  1682. tpd->vcc->pop(tpd->vcc, tpd->skb);
  1683. else
  1684. dev_kfree_skb_any(tpd->skb);
  1685. atomic_inc(&tpd->vcc->stats->tx_err);
  1686. }
  1687. dma_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
  1688. return;
  1689. }
  1690. }
  1691. /* 2.1.5 transmit packet descriptor ready queue */
  1692. list_add_tail(&tpd->entry, &he_dev->outstanding_tpds);
  1693. he_dev->tpdrq_tail->tpd = TPD_ADDR(tpd->status);
  1694. he_dev->tpdrq_tail->cid = cid;
  1695. wmb();
  1696. he_dev->tpdrq_tail = new_tail;
  1697. he_writel(he_dev, TPDRQ_MASK(he_dev->tpdrq_tail), TPDRQ_T);
  1698. (void) he_readl(he_dev, TPDRQ_T); /* flush posted writes */
  1699. }
  1700. static int
  1701. he_open(struct atm_vcc *vcc)
  1702. {
  1703. unsigned long flags;
  1704. struct he_dev *he_dev = HE_DEV(vcc->dev);
  1705. struct he_vcc *he_vcc;
  1706. int err = 0;
  1707. unsigned cid, rsr0, rsr1, rsr4, tsr0, tsr0_aal, tsr4, period, reg, clock;
  1708. short vpi = vcc->vpi;
  1709. int vci = vcc->vci;
  1710. if (vci == ATM_VCI_UNSPEC || vpi == ATM_VPI_UNSPEC)
  1711. return 0;
  1712. HPRINTK("open vcc %p %d.%d\n", vcc, vpi, vci);
  1713. set_bit(ATM_VF_ADDR, &vcc->flags);
  1714. cid = he_mkcid(he_dev, vpi, vci);
  1715. he_vcc = kmalloc(sizeof(struct he_vcc), GFP_ATOMIC);
  1716. if (he_vcc == NULL) {
  1717. hprintk("unable to allocate he_vcc during open\n");
  1718. return -ENOMEM;
  1719. }
  1720. INIT_LIST_HEAD(&he_vcc->buffers);
  1721. he_vcc->pdu_len = 0;
  1722. he_vcc->rc_index = -1;
  1723. init_waitqueue_head(&he_vcc->rx_waitq);
  1724. init_waitqueue_head(&he_vcc->tx_waitq);
  1725. vcc->dev_data = he_vcc;
  1726. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  1727. int pcr_goal;
  1728. pcr_goal = atm_pcr_goal(&vcc->qos.txtp);
  1729. if (pcr_goal == 0)
  1730. pcr_goal = he_dev->atm_dev->link_rate;
  1731. if (pcr_goal < 0) /* means round down, technically */
  1732. pcr_goal = -pcr_goal;
  1733. HPRINTK("open tx cid 0x%x pcr_goal %d\n", cid, pcr_goal);
  1734. switch (vcc->qos.aal) {
  1735. case ATM_AAL5:
  1736. tsr0_aal = TSR0_AAL5;
  1737. tsr4 = TSR4_AAL5;
  1738. break;
  1739. case ATM_AAL0:
  1740. tsr0_aal = TSR0_AAL0_SDU;
  1741. tsr4 = TSR4_AAL0_SDU;
  1742. break;
  1743. default:
  1744. err = -EINVAL;
  1745. goto open_failed;
  1746. }
  1747. spin_lock_irqsave(&he_dev->global_lock, flags);
  1748. tsr0 = he_readl_tsr0(he_dev, cid);
  1749. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1750. if (TSR0_CONN_STATE(tsr0) != 0) {
  1751. hprintk("cid 0x%x not idle (tsr0 = 0x%x)\n", cid, tsr0);
  1752. err = -EBUSY;
  1753. goto open_failed;
  1754. }
  1755. switch (vcc->qos.txtp.traffic_class) {
  1756. case ATM_UBR:
  1757. /* 2.3.3.1 open connection ubr */
  1758. tsr0 = TSR0_UBR | TSR0_GROUP(0) | tsr0_aal |
  1759. TSR0_USE_WMIN | TSR0_UPDATE_GER;
  1760. break;
  1761. case ATM_CBR:
  1762. /* 2.3.3.2 open connection cbr */
  1763. /* 8.2.3 cbr scheduler wrap problem -- limit to 90% total link rate */
  1764. if ((he_dev->total_bw + pcr_goal)
  1765. > (he_dev->atm_dev->link_rate * 9 / 10))
  1766. {
  1767. err = -EBUSY;
  1768. goto open_failed;
  1769. }
  1770. spin_lock_irqsave(&he_dev->global_lock, flags); /* also protects he_dev->cs_stper[] */
  1771. /* find an unused cs_stper register */
  1772. for (reg = 0; reg < HE_NUM_CS_STPER; ++reg)
  1773. if (he_dev->cs_stper[reg].inuse == 0 ||
  1774. he_dev->cs_stper[reg].pcr == pcr_goal)
  1775. break;
  1776. if (reg == HE_NUM_CS_STPER) {
  1777. err = -EBUSY;
  1778. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1779. goto open_failed;
  1780. }
  1781. he_dev->total_bw += pcr_goal;
  1782. he_vcc->rc_index = reg;
  1783. ++he_dev->cs_stper[reg].inuse;
  1784. he_dev->cs_stper[reg].pcr = pcr_goal;
  1785. clock = he_is622(he_dev) ? 66667000 : 50000000;
  1786. period = clock / pcr_goal;
  1787. HPRINTK("rc_index = %d period = %d\n",
  1788. reg, period);
  1789. he_writel_mbox(he_dev, rate_to_atmf(period/2),
  1790. CS_STPER0 + reg);
  1791. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1792. tsr0 = TSR0_CBR | TSR0_GROUP(0) | tsr0_aal |
  1793. TSR0_RC_INDEX(reg);
  1794. break;
  1795. default:
  1796. err = -EINVAL;
  1797. goto open_failed;
  1798. }
  1799. spin_lock_irqsave(&he_dev->global_lock, flags);
  1800. he_writel_tsr0(he_dev, tsr0, cid);
  1801. he_writel_tsr4(he_dev, tsr4 | 1, cid);
  1802. he_writel_tsr1(he_dev, TSR1_MCR(rate_to_atmf(0)) |
  1803. TSR1_PCR(rate_to_atmf(pcr_goal)), cid);
  1804. he_writel_tsr2(he_dev, TSR2_ACR(rate_to_atmf(pcr_goal)), cid);
  1805. he_writel_tsr9(he_dev, TSR9_OPEN_CONN, cid);
  1806. he_writel_tsr3(he_dev, 0x0, cid);
  1807. he_writel_tsr5(he_dev, 0x0, cid);
  1808. he_writel_tsr6(he_dev, 0x0, cid);
  1809. he_writel_tsr7(he_dev, 0x0, cid);
  1810. he_writel_tsr8(he_dev, 0x0, cid);
  1811. he_writel_tsr10(he_dev, 0x0, cid);
  1812. he_writel_tsr11(he_dev, 0x0, cid);
  1813. he_writel_tsr12(he_dev, 0x0, cid);
  1814. he_writel_tsr13(he_dev, 0x0, cid);
  1815. he_writel_tsr14(he_dev, 0x0, cid);
  1816. (void) he_readl_tsr0(he_dev, cid); /* flush posted writes */
  1817. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1818. }
  1819. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  1820. unsigned aal;
  1821. HPRINTK("open rx cid 0x%x (rx_waitq %p)\n", cid,
  1822. &HE_VCC(vcc)->rx_waitq);
  1823. switch (vcc->qos.aal) {
  1824. case ATM_AAL5:
  1825. aal = RSR0_AAL5;
  1826. break;
  1827. case ATM_AAL0:
  1828. aal = RSR0_RAWCELL;
  1829. break;
  1830. default:
  1831. err = -EINVAL;
  1832. goto open_failed;
  1833. }
  1834. spin_lock_irqsave(&he_dev->global_lock, flags);
  1835. rsr0 = he_readl_rsr0(he_dev, cid);
  1836. if (rsr0 & RSR0_OPEN_CONN) {
  1837. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1838. hprintk("cid 0x%x not idle (rsr0 = 0x%x)\n", cid, rsr0);
  1839. err = -EBUSY;
  1840. goto open_failed;
  1841. }
  1842. rsr1 = RSR1_GROUP(0) | RSR1_RBPL_ONLY;
  1843. rsr4 = RSR4_GROUP(0) | RSR4_RBPL_ONLY;
  1844. rsr0 = vcc->qos.rxtp.traffic_class == ATM_UBR ?
  1845. (RSR0_EPD_ENABLE|RSR0_PPD_ENABLE) : 0;
  1846. #ifdef USE_CHECKSUM_HW
  1847. if (vpi == 0 && vci >= ATM_NOT_RSV_VCI)
  1848. rsr0 |= RSR0_TCP_CKSUM;
  1849. #endif
  1850. he_writel_rsr4(he_dev, rsr4, cid);
  1851. he_writel_rsr1(he_dev, rsr1, cid);
  1852. /* 5.1.11 last parameter initialized should be
  1853. the open/closed indication in rsr0 */
  1854. he_writel_rsr0(he_dev,
  1855. rsr0 | RSR0_START_PDU | RSR0_OPEN_CONN | aal, cid);
  1856. (void) he_readl_rsr0(he_dev, cid); /* flush posted writes */
  1857. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1858. }
  1859. open_failed:
  1860. if (err) {
  1861. kfree(he_vcc);
  1862. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1863. }
  1864. else
  1865. set_bit(ATM_VF_READY, &vcc->flags);
  1866. return err;
  1867. }
  1868. static void
  1869. he_close(struct atm_vcc *vcc)
  1870. {
  1871. unsigned long flags;
  1872. DECLARE_WAITQUEUE(wait, current);
  1873. struct he_dev *he_dev = HE_DEV(vcc->dev);
  1874. struct he_tpd *tpd;
  1875. unsigned cid;
  1876. struct he_vcc *he_vcc = HE_VCC(vcc);
  1877. #define MAX_RETRY 30
  1878. int retry = 0, sleep = 1, tx_inuse;
  1879. HPRINTK("close vcc %p %d.%d\n", vcc, vcc->vpi, vcc->vci);
  1880. clear_bit(ATM_VF_READY, &vcc->flags);
  1881. cid = he_mkcid(he_dev, vcc->vpi, vcc->vci);
  1882. if (vcc->qos.rxtp.traffic_class != ATM_NONE) {
  1883. int timeout;
  1884. HPRINTK("close rx cid 0x%x\n", cid);
  1885. /* 2.7.2.2 close receive operation */
  1886. /* wait for previous close (if any) to finish */
  1887. spin_lock_irqsave(&he_dev->global_lock, flags);
  1888. while (he_readl(he_dev, RCC_STAT) & RCC_BUSY) {
  1889. HPRINTK("close cid 0x%x RCC_BUSY\n", cid);
  1890. udelay(250);
  1891. }
  1892. set_current_state(TASK_UNINTERRUPTIBLE);
  1893. add_wait_queue(&he_vcc->rx_waitq, &wait);
  1894. he_writel_rsr0(he_dev, RSR0_CLOSE_CONN, cid);
  1895. (void) he_readl_rsr0(he_dev, cid); /* flush posted writes */
  1896. he_writel_mbox(he_dev, cid, RXCON_CLOSE);
  1897. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1898. timeout = schedule_timeout(30*HZ);
  1899. remove_wait_queue(&he_vcc->rx_waitq, &wait);
  1900. set_current_state(TASK_RUNNING);
  1901. if (timeout == 0)
  1902. hprintk("close rx timeout cid 0x%x\n", cid);
  1903. HPRINTK("close rx cid 0x%x complete\n", cid);
  1904. }
  1905. if (vcc->qos.txtp.traffic_class != ATM_NONE) {
  1906. volatile unsigned tsr4, tsr0;
  1907. int timeout;
  1908. HPRINTK("close tx cid 0x%x\n", cid);
  1909. /* 2.1.2
  1910. *
  1911. * ... the host must first stop queueing packets to the TPDRQ
  1912. * on the connection to be closed, then wait for all outstanding
  1913. * packets to be transmitted and their buffers returned to the
  1914. * TBRQ. When the last packet on the connection arrives in the
  1915. * TBRQ, the host issues the close command to the adapter.
  1916. */
  1917. while (((tx_inuse = refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) > 1) &&
  1918. (retry < MAX_RETRY)) {
  1919. msleep(sleep);
  1920. if (sleep < 250)
  1921. sleep = sleep * 2;
  1922. ++retry;
  1923. }
  1924. if (tx_inuse > 1)
  1925. hprintk("close tx cid 0x%x tx_inuse = %d\n", cid, tx_inuse);
  1926. /* 2.3.1.1 generic close operations with flush */
  1927. spin_lock_irqsave(&he_dev->global_lock, flags);
  1928. he_writel_tsr4_upper(he_dev, TSR4_FLUSH_CONN, cid);
  1929. /* also clears TSR4_SESSION_ENDED */
  1930. switch (vcc->qos.txtp.traffic_class) {
  1931. case ATM_UBR:
  1932. he_writel_tsr1(he_dev,
  1933. TSR1_MCR(rate_to_atmf(200000))
  1934. | TSR1_PCR(0), cid);
  1935. break;
  1936. case ATM_CBR:
  1937. he_writel_tsr14_upper(he_dev, TSR14_DELETE, cid);
  1938. break;
  1939. }
  1940. (void) he_readl_tsr4(he_dev, cid); /* flush posted writes */
  1941. tpd = __alloc_tpd(he_dev);
  1942. if (tpd == NULL) {
  1943. hprintk("close tx he_alloc_tpd failed cid 0x%x\n", cid);
  1944. goto close_tx_incomplete;
  1945. }
  1946. tpd->status |= TPD_EOS | TPD_INT;
  1947. tpd->skb = NULL;
  1948. tpd->vcc = vcc;
  1949. wmb();
  1950. set_current_state(TASK_UNINTERRUPTIBLE);
  1951. add_wait_queue(&he_vcc->tx_waitq, &wait);
  1952. __enqueue_tpd(he_dev, tpd, cid);
  1953. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1954. timeout = schedule_timeout(30*HZ);
  1955. remove_wait_queue(&he_vcc->tx_waitq, &wait);
  1956. set_current_state(TASK_RUNNING);
  1957. spin_lock_irqsave(&he_dev->global_lock, flags);
  1958. if (timeout == 0) {
  1959. hprintk("close tx timeout cid 0x%x\n", cid);
  1960. goto close_tx_incomplete;
  1961. }
  1962. while (!((tsr4 = he_readl_tsr4(he_dev, cid)) & TSR4_SESSION_ENDED)) {
  1963. HPRINTK("close tx cid 0x%x !TSR4_SESSION_ENDED (tsr4 = 0x%x)\n", cid, tsr4);
  1964. udelay(250);
  1965. }
  1966. while (TSR0_CONN_STATE(tsr0 = he_readl_tsr0(he_dev, cid)) != 0) {
  1967. HPRINTK("close tx cid 0x%x TSR0_CONN_STATE != 0 (tsr0 = 0x%x)\n", cid, tsr0);
  1968. udelay(250);
  1969. }
  1970. close_tx_incomplete:
  1971. if (vcc->qos.txtp.traffic_class == ATM_CBR) {
  1972. int reg = he_vcc->rc_index;
  1973. HPRINTK("cs_stper reg = %d\n", reg);
  1974. if (he_dev->cs_stper[reg].inuse == 0)
  1975. hprintk("cs_stper[%d].inuse = 0!\n", reg);
  1976. else
  1977. --he_dev->cs_stper[reg].inuse;
  1978. he_dev->total_bw -= he_dev->cs_stper[reg].pcr;
  1979. }
  1980. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  1981. HPRINTK("close tx cid 0x%x complete\n", cid);
  1982. }
  1983. kfree(he_vcc);
  1984. clear_bit(ATM_VF_ADDR, &vcc->flags);
  1985. }
  1986. static int
  1987. he_send(struct atm_vcc *vcc, struct sk_buff *skb)
  1988. {
  1989. unsigned long flags;
  1990. struct he_dev *he_dev = HE_DEV(vcc->dev);
  1991. unsigned cid = he_mkcid(he_dev, vcc->vpi, vcc->vci);
  1992. struct he_tpd *tpd;
  1993. #ifdef USE_SCATTERGATHER
  1994. int i, slot = 0;
  1995. #endif
  1996. #define HE_TPD_BUFSIZE 0xffff
  1997. HPRINTK("send %d.%d\n", vcc->vpi, vcc->vci);
  1998. if ((skb->len > HE_TPD_BUFSIZE) ||
  1999. ((vcc->qos.aal == ATM_AAL0) && (skb->len != ATM_AAL0_SDU))) {
  2000. hprintk("buffer too large (or small) -- %d bytes\n", skb->len );
  2001. if (vcc->pop)
  2002. vcc->pop(vcc, skb);
  2003. else
  2004. dev_kfree_skb_any(skb);
  2005. atomic_inc(&vcc->stats->tx_err);
  2006. return -EINVAL;
  2007. }
  2008. #ifndef USE_SCATTERGATHER
  2009. if (skb_shinfo(skb)->nr_frags) {
  2010. hprintk("no scatter/gather support\n");
  2011. if (vcc->pop)
  2012. vcc->pop(vcc, skb);
  2013. else
  2014. dev_kfree_skb_any(skb);
  2015. atomic_inc(&vcc->stats->tx_err);
  2016. return -EINVAL;
  2017. }
  2018. #endif
  2019. spin_lock_irqsave(&he_dev->global_lock, flags);
  2020. tpd = __alloc_tpd(he_dev);
  2021. if (tpd == NULL) {
  2022. if (vcc->pop)
  2023. vcc->pop(vcc, skb);
  2024. else
  2025. dev_kfree_skb_any(skb);
  2026. atomic_inc(&vcc->stats->tx_err);
  2027. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2028. return -ENOMEM;
  2029. }
  2030. if (vcc->qos.aal == ATM_AAL5)
  2031. tpd->status |= TPD_CELLTYPE(TPD_USERCELL);
  2032. else {
  2033. char *pti_clp = (void *) (skb->data + 3);
  2034. int clp, pti;
  2035. pti = (*pti_clp & ATM_HDR_PTI_MASK) >> ATM_HDR_PTI_SHIFT;
  2036. clp = (*pti_clp & ATM_HDR_CLP);
  2037. tpd->status |= TPD_CELLTYPE(pti);
  2038. if (clp)
  2039. tpd->status |= TPD_CLP;
  2040. skb_pull(skb, ATM_AAL0_SDU - ATM_CELL_PAYLOAD);
  2041. }
  2042. #ifdef USE_SCATTERGATHER
  2043. tpd->iovec[slot].addr = dma_map_single(&he_dev->pci_dev->dev, skb->data,
  2044. skb_headlen(skb), DMA_TO_DEVICE);
  2045. tpd->iovec[slot].len = skb_headlen(skb);
  2046. ++slot;
  2047. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2048. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2049. if (slot == TPD_MAXIOV) { /* queue tpd; start new tpd */
  2050. tpd->vcc = vcc;
  2051. tpd->skb = NULL; /* not the last fragment
  2052. so dont ->push() yet */
  2053. wmb();
  2054. __enqueue_tpd(he_dev, tpd, cid);
  2055. tpd = __alloc_tpd(he_dev);
  2056. if (tpd == NULL) {
  2057. if (vcc->pop)
  2058. vcc->pop(vcc, skb);
  2059. else
  2060. dev_kfree_skb_any(skb);
  2061. atomic_inc(&vcc->stats->tx_err);
  2062. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2063. return -ENOMEM;
  2064. }
  2065. tpd->status |= TPD_USERCELL;
  2066. slot = 0;
  2067. }
  2068. tpd->iovec[slot].addr = dma_map_single(&he_dev->pci_dev->dev,
  2069. (void *) page_address(frag->page) + frag->page_offset,
  2070. frag->size, DMA_TO_DEVICE);
  2071. tpd->iovec[slot].len = frag->size;
  2072. ++slot;
  2073. }
  2074. tpd->iovec[slot - 1].len |= TPD_LST;
  2075. #else
  2076. tpd->address0 = dma_map_single(&he_dev->pci_dev->dev, skb->data, skb->len, DMA_TO_DEVICE);
  2077. tpd->length0 = skb->len | TPD_LST;
  2078. #endif
  2079. tpd->status |= TPD_INT;
  2080. tpd->vcc = vcc;
  2081. tpd->skb = skb;
  2082. wmb();
  2083. ATM_SKB(skb)->vcc = vcc;
  2084. __enqueue_tpd(he_dev, tpd, cid);
  2085. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2086. atomic_inc(&vcc->stats->tx);
  2087. return 0;
  2088. }
  2089. static int
  2090. he_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user *arg)
  2091. {
  2092. unsigned long flags;
  2093. struct he_dev *he_dev = HE_DEV(atm_dev);
  2094. struct he_ioctl_reg reg;
  2095. int err = 0;
  2096. switch (cmd) {
  2097. case HE_GET_REG:
  2098. if (!capable(CAP_NET_ADMIN))
  2099. return -EPERM;
  2100. if (copy_from_user(&reg, arg,
  2101. sizeof(struct he_ioctl_reg)))
  2102. return -EFAULT;
  2103. spin_lock_irqsave(&he_dev->global_lock, flags);
  2104. switch (reg.type) {
  2105. case HE_REGTYPE_PCI:
  2106. if (reg.addr >= HE_REGMAP_SIZE) {
  2107. err = -EINVAL;
  2108. break;
  2109. }
  2110. reg.val = he_readl(he_dev, reg.addr);
  2111. break;
  2112. case HE_REGTYPE_RCM:
  2113. reg.val =
  2114. he_readl_rcm(he_dev, reg.addr);
  2115. break;
  2116. case HE_REGTYPE_TCM:
  2117. reg.val =
  2118. he_readl_tcm(he_dev, reg.addr);
  2119. break;
  2120. case HE_REGTYPE_MBOX:
  2121. reg.val =
  2122. he_readl_mbox(he_dev, reg.addr);
  2123. break;
  2124. default:
  2125. err = -EINVAL;
  2126. break;
  2127. }
  2128. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2129. if (err == 0)
  2130. if (copy_to_user(arg, &reg,
  2131. sizeof(struct he_ioctl_reg)))
  2132. return -EFAULT;
  2133. break;
  2134. default:
  2135. #ifdef CONFIG_ATM_HE_USE_SUNI
  2136. if (atm_dev->phy && atm_dev->phy->ioctl)
  2137. err = atm_dev->phy->ioctl(atm_dev, cmd, arg);
  2138. #else /* CONFIG_ATM_HE_USE_SUNI */
  2139. err = -EINVAL;
  2140. #endif /* CONFIG_ATM_HE_USE_SUNI */
  2141. break;
  2142. }
  2143. return err;
  2144. }
  2145. static void
  2146. he_phy_put(struct atm_dev *atm_dev, unsigned char val, unsigned long addr)
  2147. {
  2148. unsigned long flags;
  2149. struct he_dev *he_dev = HE_DEV(atm_dev);
  2150. HPRINTK("phy_put(val 0x%x, addr 0x%lx)\n", val, addr);
  2151. spin_lock_irqsave(&he_dev->global_lock, flags);
  2152. he_writel(he_dev, val, FRAMER + (addr*4));
  2153. (void) he_readl(he_dev, FRAMER + (addr*4)); /* flush posted writes */
  2154. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2155. }
  2156. static unsigned char
  2157. he_phy_get(struct atm_dev *atm_dev, unsigned long addr)
  2158. {
  2159. unsigned long flags;
  2160. struct he_dev *he_dev = HE_DEV(atm_dev);
  2161. unsigned reg;
  2162. spin_lock_irqsave(&he_dev->global_lock, flags);
  2163. reg = he_readl(he_dev, FRAMER + (addr*4));
  2164. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2165. HPRINTK("phy_get(addr 0x%lx) =0x%x\n", addr, reg);
  2166. return reg;
  2167. }
  2168. static int
  2169. he_proc_read(struct atm_dev *dev, loff_t *pos, char *page)
  2170. {
  2171. unsigned long flags;
  2172. struct he_dev *he_dev = HE_DEV(dev);
  2173. int left, i;
  2174. #ifdef notdef
  2175. struct he_rbrq *rbrq_tail;
  2176. struct he_tpdrq *tpdrq_head;
  2177. int rbpl_head, rbpl_tail;
  2178. #endif
  2179. static long mcc = 0, oec = 0, dcc = 0, cec = 0;
  2180. left = *pos;
  2181. if (!left--)
  2182. return sprintf(page, "ATM he driver\n");
  2183. if (!left--)
  2184. return sprintf(page, "%s%s\n\n",
  2185. he_dev->prod_id, he_dev->media & 0x40 ? "SM" : "MM");
  2186. if (!left--)
  2187. return sprintf(page, "Mismatched Cells VPI/VCI Not Open Dropped Cells RCM Dropped Cells\n");
  2188. spin_lock_irqsave(&he_dev->global_lock, flags);
  2189. mcc += he_readl(he_dev, MCC);
  2190. oec += he_readl(he_dev, OEC);
  2191. dcc += he_readl(he_dev, DCC);
  2192. cec += he_readl(he_dev, CEC);
  2193. spin_unlock_irqrestore(&he_dev->global_lock, flags);
  2194. if (!left--)
  2195. return sprintf(page, "%16ld %16ld %13ld %17ld\n\n",
  2196. mcc, oec, dcc, cec);
  2197. if (!left--)
  2198. return sprintf(page, "irq_size = %d inuse = ? peak = %d\n",
  2199. CONFIG_IRQ_SIZE, he_dev->irq_peak);
  2200. if (!left--)
  2201. return sprintf(page, "tpdrq_size = %d inuse = ?\n",
  2202. CONFIG_TPDRQ_SIZE);
  2203. if (!left--)
  2204. return sprintf(page, "rbrq_size = %d inuse = ? peak = %d\n",
  2205. CONFIG_RBRQ_SIZE, he_dev->rbrq_peak);
  2206. if (!left--)
  2207. return sprintf(page, "tbrq_size = %d peak = %d\n",
  2208. CONFIG_TBRQ_SIZE, he_dev->tbrq_peak);
  2209. #ifdef notdef
  2210. rbpl_head = RBPL_MASK(he_readl(he_dev, G0_RBPL_S));
  2211. rbpl_tail = RBPL_MASK(he_readl(he_dev, G0_RBPL_T));
  2212. inuse = rbpl_head - rbpl_tail;
  2213. if (inuse < 0)
  2214. inuse += CONFIG_RBPL_SIZE * sizeof(struct he_rbp);
  2215. inuse /= sizeof(struct he_rbp);
  2216. if (!left--)
  2217. return sprintf(page, "rbpl_size = %d inuse = %d\n\n",
  2218. CONFIG_RBPL_SIZE, inuse);
  2219. #endif
  2220. if (!left--)
  2221. return sprintf(page, "rate controller periods (cbr)\n pcr #vc\n");
  2222. for (i = 0; i < HE_NUM_CS_STPER; ++i)
  2223. if (!left--)
  2224. return sprintf(page, "cs_stper%-2d %8ld %3d\n", i,
  2225. he_dev->cs_stper[i].pcr,
  2226. he_dev->cs_stper[i].inuse);
  2227. if (!left--)
  2228. return sprintf(page, "total bw (cbr): %d (limit %d)\n",
  2229. he_dev->total_bw, he_dev->atm_dev->link_rate * 10 / 9);
  2230. return 0;
  2231. }
  2232. /* eeprom routines -- see 4.7 */
  2233. static u8 read_prom_byte(struct he_dev *he_dev, int addr)
  2234. {
  2235. u32 val = 0, tmp_read = 0;
  2236. int i, j = 0;
  2237. u8 byte_read = 0;
  2238. val = readl(he_dev->membase + HOST_CNTL);
  2239. val &= 0xFFFFE0FF;
  2240. /* Turn on write enable */
  2241. val |= 0x800;
  2242. he_writel(he_dev, val, HOST_CNTL);
  2243. /* Send READ instruction */
  2244. for (i = 0; i < ARRAY_SIZE(readtab); i++) {
  2245. he_writel(he_dev, val | readtab[i], HOST_CNTL);
  2246. udelay(EEPROM_DELAY);
  2247. }
  2248. /* Next, we need to send the byte address to read from */
  2249. for (i = 7; i >= 0; i--) {
  2250. he_writel(he_dev, val | clocktab[j++] | (((addr >> i) & 1) << 9), HOST_CNTL);
  2251. udelay(EEPROM_DELAY);
  2252. he_writel(he_dev, val | clocktab[j++] | (((addr >> i) & 1) << 9), HOST_CNTL);
  2253. udelay(EEPROM_DELAY);
  2254. }
  2255. j = 0;
  2256. val &= 0xFFFFF7FF; /* Turn off write enable */
  2257. he_writel(he_dev, val, HOST_CNTL);
  2258. /* Now, we can read data from the EEPROM by clocking it in */
  2259. for (i = 7; i >= 0; i--) {
  2260. he_writel(he_dev, val | clocktab[j++], HOST_CNTL);
  2261. udelay(EEPROM_DELAY);
  2262. tmp_read = he_readl(he_dev, HOST_CNTL);
  2263. byte_read |= (unsigned char)
  2264. ((tmp_read & ID_DOUT) >> ID_DOFFSET << i);
  2265. he_writel(he_dev, val | clocktab[j++], HOST_CNTL);
  2266. udelay(EEPROM_DELAY);
  2267. }
  2268. he_writel(he_dev, val | ID_CS, HOST_CNTL);
  2269. udelay(EEPROM_DELAY);
  2270. return byte_read;
  2271. }
  2272. MODULE_LICENSE("GPL");
  2273. MODULE_AUTHOR("chas williams <chas@cmf.nrl.navy.mil>");
  2274. MODULE_DESCRIPTION("ForeRunnerHE ATM Adapter driver");
  2275. module_param(disable64, bool, 0);
  2276. MODULE_PARM_DESC(disable64, "disable 64-bit pci bus transfers");
  2277. module_param(nvpibits, short, 0);
  2278. MODULE_PARM_DESC(nvpibits, "numbers of bits for vpi (default 0)");
  2279. module_param(nvcibits, short, 0);
  2280. MODULE_PARM_DESC(nvcibits, "numbers of bits for vci (default 12)");
  2281. module_param(rx_skb_reserve, short, 0);
  2282. MODULE_PARM_DESC(rx_skb_reserve, "padding for receive skb (default 16)");
  2283. module_param(irq_coalesce, bool, 0);
  2284. MODULE_PARM_DESC(irq_coalesce, "use interrupt coalescing (default 1)");
  2285. module_param(sdh, bool, 0);
  2286. MODULE_PARM_DESC(sdh, "use SDH framing (default 0)");
  2287. static const struct pci_device_id he_pci_tbl[] = {
  2288. { PCI_VDEVICE(FORE, PCI_DEVICE_ID_FORE_HE), 0 },
  2289. { 0, }
  2290. };
  2291. MODULE_DEVICE_TABLE(pci, he_pci_tbl);
  2292. static struct pci_driver he_driver = {
  2293. .name = "he",
  2294. .probe = he_init_one,
  2295. .remove = he_remove_one,
  2296. .id_table = he_pci_tbl,
  2297. };
  2298. module_pci_driver(he_driver);