lanai.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* lanai.c -- Copyright 1999-2003 by Mitchell Blank Jr <[email protected]>
  3. *
  4. * This driver supports ATM cards based on the Efficient "Lanai"
  5. * chipset such as the Speedstream 3010 and the ENI-25p. The
  6. * Speedstream 3060 is currently not supported since we don't
  7. * have the code to drive the on-board Alcatel DSL chipset (yet).
  8. *
  9. * Thanks to Efficient for supporting this project with hardware,
  10. * documentation, and by answering my questions.
  11. *
  12. * Things not working yet:
  13. *
  14. * o We don't support the Speedstream 3060 yet - this card has
  15. * an on-board DSL modem chip by Alcatel and the driver will
  16. * need some extra code added to handle it
  17. *
  18. * o Note that due to limitations of the Lanai only one VCC can be
  19. * in CBR at once
  20. *
  21. * o We don't currently parse the EEPROM at all. The code is all
  22. * there as per the spec, but it doesn't actually work. I think
  23. * there may be some issues with the docs. Anyway, do NOT
  24. * enable it yet - bugs in that code may actually damage your
  25. * hardware! Because of this you should hardware an ESI before
  26. * trying to use this in a LANE or MPOA environment.
  27. *
  28. * o AAL0 is stubbed in but the actual rx/tx path isn't written yet:
  29. * vcc_tx_aal0() needs to send or queue a SKB
  30. * vcc_tx_unqueue_aal0() needs to attempt to send queued SKBs
  31. * vcc_rx_aal0() needs to handle AAL0 interrupts
  32. * This isn't too much work - I just wanted to get other things
  33. * done first.
  34. *
  35. * o lanai_change_qos() isn't written yet
  36. *
  37. * o There aren't any ioctl's yet -- I'd like to eventually support
  38. * setting loopback and LED modes that way.
  39. *
  40. * o If the segmentation engine or DMA gets shut down we should restart
  41. * card as per section 17.0i. (see lanai_reset)
  42. *
  43. * o setsockopt(SO_CIRANGE) isn't done (although despite what the
  44. * API says it isn't exactly commonly implemented)
  45. */
  46. /* Version history:
  47. * v.1.00 -- 26-JUL-2003 -- PCI/DMA updates
  48. * v.0.02 -- 11-JAN-2000 -- Endian fixes
  49. * v.0.01 -- 30-NOV-1999 -- Initial release
  50. */
  51. #include <linux/module.h>
  52. #include <linux/slab.h>
  53. #include <linux/mm.h>
  54. #include <linux/atmdev.h>
  55. #include <asm/io.h>
  56. #include <asm/byteorder.h>
  57. #include <linux/spinlock.h>
  58. #include <linux/pci.h>
  59. #include <linux/dma-mapping.h>
  60. #include <linux/init.h>
  61. #include <linux/delay.h>
  62. #include <linux/interrupt.h>
  63. /* -------------------- TUNABLE PARAMATERS: */
  64. /*
  65. * Maximum number of VCIs per card. Setting it lower could theoretically
  66. * save some memory, but since we allocate our vcc list with get_free_pages,
  67. * it's not really likely for most architectures
  68. */
  69. #define NUM_VCI (1024)
  70. /*
  71. * Enable extra debugging
  72. */
  73. #define DEBUG
  74. /*
  75. * Debug _all_ register operations with card, except the memory test.
  76. * Also disables the timed poll to prevent extra chattiness. This
  77. * isn't for normal use
  78. */
  79. #undef DEBUG_RW
  80. /*
  81. * The programming guide specifies a full test of the on-board SRAM
  82. * at initialization time. Undefine to remove this
  83. */
  84. #define FULL_MEMORY_TEST
  85. /*
  86. * This is the number of (4 byte) service entries that we will
  87. * try to allocate at startup. Note that we will end up with
  88. * one PAGE_SIZE's worth regardless of what this is set to
  89. */
  90. #define SERVICE_ENTRIES (1024)
  91. /* TODO: make above a module load-time option */
  92. /*
  93. * We normally read the onboard EEPROM in order to discover our MAC
  94. * address. Undefine to _not_ do this
  95. */
  96. /* #define READ_EEPROM */ /* ***DONT ENABLE YET*** */
  97. /* TODO: make above a module load-time option (also) */
  98. /*
  99. * Depth of TX fifo (in 128 byte units; range 2-31)
  100. * Smaller numbers are better for network latency
  101. * Larger numbers are better for PCI latency
  102. * I'm really sure where the best tradeoff is, but the BSD driver uses
  103. * 7 and it seems to work ok.
  104. */
  105. #define TX_FIFO_DEPTH (7)
  106. /* TODO: make above a module load-time option */
  107. /*
  108. * How often (in jiffies) we will try to unstick stuck connections -
  109. * shouldn't need to happen much
  110. */
  111. #define LANAI_POLL_PERIOD (10*HZ)
  112. /* TODO: make above a module load-time option */
  113. /*
  114. * When allocating an AAL5 receiving buffer, try to make it at least
  115. * large enough to hold this many max_sdu sized PDUs
  116. */
  117. #define AAL5_RX_MULTIPLIER (3)
  118. /* TODO: make above a module load-time option */
  119. /*
  120. * Same for transmitting buffer
  121. */
  122. #define AAL5_TX_MULTIPLIER (3)
  123. /* TODO: make above a module load-time option */
  124. /*
  125. * When allocating an AAL0 transmiting buffer, how many cells should fit.
  126. * Remember we'll end up with a PAGE_SIZE of them anyway, so this isn't
  127. * really critical
  128. */
  129. #define AAL0_TX_MULTIPLIER (40)
  130. /* TODO: make above a module load-time option */
  131. /*
  132. * How large should we make the AAL0 receiving buffer. Remember that this
  133. * is shared between all AAL0 VC's
  134. */
  135. #define AAL0_RX_BUFFER_SIZE (PAGE_SIZE)
  136. /* TODO: make above a module load-time option */
  137. /*
  138. * Should we use Lanai's "powerdown" feature when no vcc's are bound?
  139. */
  140. /* #define USE_POWERDOWN */
  141. /* TODO: make above a module load-time option (also) */
  142. /* -------------------- DEBUGGING AIDS: */
  143. #define DEV_LABEL "lanai"
  144. #ifdef DEBUG
  145. #define DPRINTK(format, args...) \
  146. printk(KERN_DEBUG DEV_LABEL ": " format, ##args)
  147. #define APRINTK(truth, format, args...) \
  148. do { \
  149. if (unlikely(!(truth))) \
  150. printk(KERN_ERR DEV_LABEL ": " format, ##args); \
  151. } while (0)
  152. #else /* !DEBUG */
  153. #define DPRINTK(format, args...)
  154. #define APRINTK(truth, format, args...)
  155. #endif /* DEBUG */
  156. #ifdef DEBUG_RW
  157. #define RWDEBUG(format, args...) \
  158. printk(KERN_DEBUG DEV_LABEL ": " format, ##args)
  159. #else /* !DEBUG_RW */
  160. #define RWDEBUG(format, args...)
  161. #endif
  162. /* -------------------- DATA DEFINITIONS: */
  163. #define LANAI_MAPPING_SIZE (0x40000)
  164. #define LANAI_EEPROM_SIZE (128)
  165. typedef int vci_t;
  166. typedef void __iomem *bus_addr_t;
  167. /* DMA buffer in host memory for TX, RX, or service list. */
  168. struct lanai_buffer {
  169. u32 *start; /* From get_free_pages */
  170. u32 *end; /* One past last byte */
  171. u32 *ptr; /* Pointer to current host location */
  172. dma_addr_t dmaaddr;
  173. };
  174. struct lanai_vcc_stats {
  175. unsigned rx_nomem;
  176. union {
  177. struct {
  178. unsigned rx_badlen;
  179. unsigned service_trash;
  180. unsigned service_stream;
  181. unsigned service_rxcrc;
  182. } aal5;
  183. struct {
  184. } aal0;
  185. } x;
  186. };
  187. struct lanai_dev; /* Forward declaration */
  188. /*
  189. * This is the card-specific per-vcc data. Note that unlike some other
  190. * drivers there is NOT a 1-to-1 correspondance between these and
  191. * atm_vcc's - each one of these represents an actual 2-way vcc, but
  192. * an atm_vcc can be 1-way and share with a 1-way vcc in the other
  193. * direction. To make it weirder, there can even be 0-way vccs
  194. * bound to us, waiting to do a change_qos
  195. */
  196. struct lanai_vcc {
  197. bus_addr_t vbase; /* Base of VCC's registers */
  198. struct lanai_vcc_stats stats;
  199. int nref; /* # of atm_vcc's who reference us */
  200. vci_t vci;
  201. struct {
  202. struct lanai_buffer buf;
  203. struct atm_vcc *atmvcc; /* atm_vcc who is receiver */
  204. } rx;
  205. struct {
  206. struct lanai_buffer buf;
  207. struct atm_vcc *atmvcc; /* atm_vcc who is transmitter */
  208. int endptr; /* last endptr from service entry */
  209. struct sk_buff_head backlog;
  210. void (*unqueue)(struct lanai_dev *, struct lanai_vcc *, int);
  211. } tx;
  212. };
  213. enum lanai_type {
  214. lanai2 = PCI_DEVICE_ID_EF_ATM_LANAI2,
  215. lanaihb = PCI_DEVICE_ID_EF_ATM_LANAIHB
  216. };
  217. struct lanai_dev_stats {
  218. unsigned ovfl_trash; /* # of cells dropped - buffer overflow */
  219. unsigned vci_trash; /* # of cells dropped - closed vci */
  220. unsigned hec_err; /* # of cells dropped - bad HEC */
  221. unsigned atm_ovfl; /* # of cells dropped - rx fifo overflow */
  222. unsigned pcierr_parity_detect;
  223. unsigned pcierr_serr_set;
  224. unsigned pcierr_master_abort;
  225. unsigned pcierr_m_target_abort;
  226. unsigned pcierr_s_target_abort;
  227. unsigned pcierr_master_parity;
  228. unsigned service_notx;
  229. unsigned service_norx;
  230. unsigned service_rxnotaal5;
  231. unsigned dma_reenable;
  232. unsigned card_reset;
  233. };
  234. struct lanai_dev {
  235. bus_addr_t base;
  236. struct lanai_dev_stats stats;
  237. struct lanai_buffer service;
  238. struct lanai_vcc **vccs;
  239. #ifdef USE_POWERDOWN
  240. int nbound; /* number of bound vccs */
  241. #endif
  242. enum lanai_type type;
  243. vci_t num_vci; /* Currently just NUM_VCI */
  244. u8 eeprom[LANAI_EEPROM_SIZE];
  245. u32 serialno, magicno;
  246. struct pci_dev *pci;
  247. DECLARE_BITMAP(backlog_vccs, NUM_VCI); /* VCCs with tx backlog */
  248. DECLARE_BITMAP(transmit_ready, NUM_VCI); /* VCCs with transmit space */
  249. struct timer_list timer;
  250. int naal0;
  251. struct lanai_buffer aal0buf; /* AAL0 RX buffers */
  252. u32 conf1, conf2; /* CONFIG[12] registers */
  253. u32 status; /* STATUS register */
  254. spinlock_t endtxlock;
  255. spinlock_t servicelock;
  256. struct atm_vcc *cbrvcc;
  257. int number;
  258. int board_rev;
  259. /* TODO - look at race conditions with maintence of conf1/conf2 */
  260. /* TODO - transmit locking: should we use _irq not _irqsave? */
  261. /* TODO - organize above in some rational fashion (see <asm/cache.h>) */
  262. };
  263. /*
  264. * Each device has two bitmaps for each VCC (baclog_vccs and transmit_ready)
  265. * This function iterates one of these, calling a given function for each
  266. * vci with their bit set
  267. */
  268. static void vci_bitfield_iterate(struct lanai_dev *lanai,
  269. const unsigned long *lp,
  270. void (*func)(struct lanai_dev *,vci_t vci))
  271. {
  272. vci_t vci;
  273. for_each_set_bit(vci, lp, NUM_VCI)
  274. func(lanai, vci);
  275. }
  276. /* -------------------- BUFFER UTILITIES: */
  277. /*
  278. * Lanai needs DMA buffers aligned to 256 bytes of at least 1024 bytes -
  279. * usually any page allocation will do. Just to be safe in case
  280. * PAGE_SIZE is insanely tiny, though...
  281. */
  282. #define LANAI_PAGE_SIZE ((PAGE_SIZE >= 1024) ? PAGE_SIZE : 1024)
  283. /*
  284. * Allocate a buffer in host RAM for service list, RX, or TX
  285. * Returns buf->start==NULL if no memory
  286. * Note that the size will be rounded up 2^n bytes, and
  287. * if we can't allocate that we'll settle for something smaller
  288. * until minbytes
  289. */
  290. static void lanai_buf_allocate(struct lanai_buffer *buf,
  291. size_t bytes, size_t minbytes, struct pci_dev *pci)
  292. {
  293. int size;
  294. if (bytes > (128 * 1024)) /* max lanai buffer size */
  295. bytes = 128 * 1024;
  296. for (size = LANAI_PAGE_SIZE; size < bytes; size *= 2)
  297. ;
  298. if (minbytes < LANAI_PAGE_SIZE)
  299. minbytes = LANAI_PAGE_SIZE;
  300. do {
  301. /*
  302. * Technically we could use non-consistent mappings for
  303. * everything, but the way the lanai uses DMA memory would
  304. * make that a terrific pain. This is much simpler.
  305. */
  306. buf->start = dma_alloc_coherent(&pci->dev,
  307. size, &buf->dmaaddr, GFP_KERNEL);
  308. if (buf->start != NULL) { /* Success */
  309. /* Lanai requires 256-byte alignment of DMA bufs */
  310. APRINTK((buf->dmaaddr & ~0xFFFFFF00) == 0,
  311. "bad dmaaddr: 0x%lx\n",
  312. (unsigned long) buf->dmaaddr);
  313. buf->ptr = buf->start;
  314. buf->end = (u32 *)
  315. (&((unsigned char *) buf->start)[size]);
  316. memset(buf->start, 0, size);
  317. break;
  318. }
  319. size /= 2;
  320. } while (size >= minbytes);
  321. }
  322. /* size of buffer in bytes */
  323. static inline size_t lanai_buf_size(const struct lanai_buffer *buf)
  324. {
  325. return ((unsigned long) buf->end) - ((unsigned long) buf->start);
  326. }
  327. static void lanai_buf_deallocate(struct lanai_buffer *buf,
  328. struct pci_dev *pci)
  329. {
  330. if (buf->start != NULL) {
  331. dma_free_coherent(&pci->dev, lanai_buf_size(buf),
  332. buf->start, buf->dmaaddr);
  333. buf->start = buf->end = buf->ptr = NULL;
  334. }
  335. }
  336. /* size of buffer as "card order" (0=1k .. 7=128k) */
  337. static int lanai_buf_size_cardorder(const struct lanai_buffer *buf)
  338. {
  339. int order = get_order(lanai_buf_size(buf)) + (PAGE_SHIFT - 10);
  340. /* This can only happen if PAGE_SIZE is gigantic, but just in case */
  341. if (order > 7)
  342. order = 7;
  343. return order;
  344. }
  345. /* -------------------- PORT I/O UTILITIES: */
  346. /* Registers (and their bit-fields) */
  347. enum lanai_register {
  348. Reset_Reg = 0x00, /* Reset; read for chip type; bits: */
  349. #define RESET_GET_BOARD_REV(x) (((x)>> 0)&0x03) /* Board revision */
  350. #define RESET_GET_BOARD_ID(x) (((x)>> 2)&0x03) /* Board ID */
  351. #define BOARD_ID_LANAI256 (0) /* 25.6M adapter card */
  352. Endian_Reg = 0x04, /* Endian setting */
  353. IntStatus_Reg = 0x08, /* Interrupt status */
  354. IntStatusMasked_Reg = 0x0C, /* Interrupt status (masked) */
  355. IntAck_Reg = 0x10, /* Interrupt acknowledge */
  356. IntAckMasked_Reg = 0x14, /* Interrupt acknowledge (masked) */
  357. IntStatusSet_Reg = 0x18, /* Get status + enable/disable */
  358. IntStatusSetMasked_Reg = 0x1C, /* Get status + en/di (masked) */
  359. IntControlEna_Reg = 0x20, /* Interrupt control enable */
  360. IntControlDis_Reg = 0x24, /* Interrupt control disable */
  361. Status_Reg = 0x28, /* Status */
  362. #define STATUS_PROMDATA (0x00000001) /* PROM_DATA pin */
  363. #define STATUS_WAITING (0x00000002) /* Interrupt being delayed */
  364. #define STATUS_SOOL (0x00000004) /* SOOL alarm */
  365. #define STATUS_LOCD (0x00000008) /* LOCD alarm */
  366. #define STATUS_LED (0x00000010) /* LED (HAPPI) output */
  367. #define STATUS_GPIN (0x00000020) /* GPIN pin */
  368. #define STATUS_BUTTBUSY (0x00000040) /* Butt register is pending */
  369. Config1_Reg = 0x2C, /* Config word 1; bits: */
  370. #define CONFIG1_PROMDATA (0x00000001) /* PROM_DATA pin */
  371. #define CONFIG1_PROMCLK (0x00000002) /* PROM_CLK pin */
  372. #define CONFIG1_SET_READMODE(x) ((x)*0x004) /* PCI BM reads; values: */
  373. #define READMODE_PLAIN (0) /* Plain memory read */
  374. #define READMODE_LINE (2) /* Memory read line */
  375. #define READMODE_MULTIPLE (3) /* Memory read multiple */
  376. #define CONFIG1_DMA_ENABLE (0x00000010) /* Turn on DMA */
  377. #define CONFIG1_POWERDOWN (0x00000020) /* Turn off clocks */
  378. #define CONFIG1_SET_LOOPMODE(x) ((x)*0x080) /* Clock&loop mode; values: */
  379. #define LOOPMODE_NORMAL (0) /* Normal - no loop */
  380. #define LOOPMODE_TIME (1)
  381. #define LOOPMODE_DIAG (2)
  382. #define LOOPMODE_LINE (3)
  383. #define CONFIG1_MASK_LOOPMODE (0x00000180)
  384. #define CONFIG1_SET_LEDMODE(x) ((x)*0x0200) /* Mode of LED; values: */
  385. #define LEDMODE_NOT_SOOL (0) /* !SOOL */
  386. #define LEDMODE_OFF (1) /* 0 */
  387. #define LEDMODE_ON (2) /* 1 */
  388. #define LEDMODE_NOT_LOCD (3) /* !LOCD */
  389. #define LEDMORE_GPIN (4) /* GPIN */
  390. #define LEDMODE_NOT_GPIN (7) /* !GPIN */
  391. #define CONFIG1_MASK_LEDMODE (0x00000E00)
  392. #define CONFIG1_GPOUT1 (0x00001000) /* Toggle for reset */
  393. #define CONFIG1_GPOUT2 (0x00002000) /* Loopback PHY */
  394. #define CONFIG1_GPOUT3 (0x00004000) /* Loopback lanai */
  395. Config2_Reg = 0x30, /* Config word 2; bits: */
  396. #define CONFIG2_HOWMANY (0x00000001) /* >512 VCIs? */
  397. #define CONFIG2_PTI7_MODE (0x00000002) /* Make PTI=7 RM, not OAM */
  398. #define CONFIG2_VPI_CHK_DIS (0x00000004) /* Ignore RX VPI value */
  399. #define CONFIG2_HEC_DROP (0x00000008) /* Drop cells w/ HEC errors */
  400. #define CONFIG2_VCI0_NORMAL (0x00000010) /* Treat VCI=0 normally */
  401. #define CONFIG2_CBR_ENABLE (0x00000020) /* Deal with CBR traffic */
  402. #define CONFIG2_TRASH_ALL (0x00000040) /* Trashing incoming cells */
  403. #define CONFIG2_TX_DISABLE (0x00000080) /* Trashing outgoing cells */
  404. #define CONFIG2_SET_TRASH (0x00000100) /* Turn trashing on */
  405. Statistics_Reg = 0x34, /* Statistics; bits: */
  406. #define STATS_GET_FIFO_OVFL(x) (((x)>> 0)&0xFF) /* FIFO overflowed */
  407. #define STATS_GET_HEC_ERR(x) (((x)>> 8)&0xFF) /* HEC was bad */
  408. #define STATS_GET_BAD_VCI(x) (((x)>>16)&0xFF) /* VCI not open */
  409. #define STATS_GET_BUF_OVFL(x) (((x)>>24)&0xFF) /* VCC buffer full */
  410. ServiceStuff_Reg = 0x38, /* Service stuff; bits: */
  411. #define SSTUFF_SET_SIZE(x) ((x)*0x20000000) /* size of service buffer */
  412. #define SSTUFF_SET_ADDR(x) ((x)>>8) /* set address of buffer */
  413. ServWrite_Reg = 0x3C, /* ServWrite Pointer */
  414. ServRead_Reg = 0x40, /* ServRead Pointer */
  415. TxDepth_Reg = 0x44, /* FIFO Transmit Depth */
  416. Butt_Reg = 0x48, /* Butt register */
  417. CBR_ICG_Reg = 0x50,
  418. CBR_PTR_Reg = 0x54,
  419. PingCount_Reg = 0x58, /* Ping count */
  420. DMA_Addr_Reg = 0x5C /* DMA address */
  421. };
  422. static inline bus_addr_t reg_addr(const struct lanai_dev *lanai,
  423. enum lanai_register reg)
  424. {
  425. return lanai->base + reg;
  426. }
  427. static inline u32 reg_read(const struct lanai_dev *lanai,
  428. enum lanai_register reg)
  429. {
  430. u32 t;
  431. t = readl(reg_addr(lanai, reg));
  432. RWDEBUG("R [0x%08X] 0x%02X = 0x%08X\n", (unsigned int) lanai->base,
  433. (int) reg, t);
  434. return t;
  435. }
  436. static inline void reg_write(const struct lanai_dev *lanai, u32 val,
  437. enum lanai_register reg)
  438. {
  439. RWDEBUG("W [0x%08X] 0x%02X < 0x%08X\n", (unsigned int) lanai->base,
  440. (int) reg, val);
  441. writel(val, reg_addr(lanai, reg));
  442. }
  443. static inline void conf1_write(const struct lanai_dev *lanai)
  444. {
  445. reg_write(lanai, lanai->conf1, Config1_Reg);
  446. }
  447. static inline void conf2_write(const struct lanai_dev *lanai)
  448. {
  449. reg_write(lanai, lanai->conf2, Config2_Reg);
  450. }
  451. /* Same as conf2_write(), but defers I/O if we're powered down */
  452. static inline void conf2_write_if_powerup(const struct lanai_dev *lanai)
  453. {
  454. #ifdef USE_POWERDOWN
  455. if (unlikely((lanai->conf1 & CONFIG1_POWERDOWN) != 0))
  456. return;
  457. #endif /* USE_POWERDOWN */
  458. conf2_write(lanai);
  459. }
  460. static inline void reset_board(const struct lanai_dev *lanai)
  461. {
  462. DPRINTK("about to reset board\n");
  463. reg_write(lanai, 0, Reset_Reg);
  464. /*
  465. * If we don't delay a little while here then we can end up
  466. * leaving the card in a VERY weird state and lock up the
  467. * PCI bus. This isn't documented anywhere but I've convinced
  468. * myself after a lot of painful experimentation
  469. */
  470. udelay(5);
  471. }
  472. /* -------------------- CARD SRAM UTILITIES: */
  473. /* The SRAM is mapped into normal PCI memory space - the only catch is
  474. * that it is only 16-bits wide but must be accessed as 32-bit. The
  475. * 16 high bits will be zero. We don't hide this, since they get
  476. * programmed mostly like discrete registers anyway
  477. */
  478. #define SRAM_START (0x20000)
  479. #define SRAM_BYTES (0x20000) /* Again, half don't really exist */
  480. static inline bus_addr_t sram_addr(const struct lanai_dev *lanai, int offset)
  481. {
  482. return lanai->base + SRAM_START + offset;
  483. }
  484. static inline u32 sram_read(const struct lanai_dev *lanai, int offset)
  485. {
  486. return readl(sram_addr(lanai, offset));
  487. }
  488. static inline void sram_write(const struct lanai_dev *lanai,
  489. u32 val, int offset)
  490. {
  491. writel(val, sram_addr(lanai, offset));
  492. }
  493. static int sram_test_word(const struct lanai_dev *lanai, int offset,
  494. u32 pattern)
  495. {
  496. u32 readback;
  497. sram_write(lanai, pattern, offset);
  498. readback = sram_read(lanai, offset);
  499. if (likely(readback == pattern))
  500. return 0;
  501. printk(KERN_ERR DEV_LABEL
  502. "(itf %d): SRAM word at %d bad: wrote 0x%X, read 0x%X\n",
  503. lanai->number, offset,
  504. (unsigned int) pattern, (unsigned int) readback);
  505. return -EIO;
  506. }
  507. static int sram_test_pass(const struct lanai_dev *lanai, u32 pattern)
  508. {
  509. int offset, result = 0;
  510. for (offset = 0; offset < SRAM_BYTES && result == 0; offset += 4)
  511. result = sram_test_word(lanai, offset, pattern);
  512. return result;
  513. }
  514. static int sram_test_and_clear(const struct lanai_dev *lanai)
  515. {
  516. #ifdef FULL_MEMORY_TEST
  517. int result;
  518. DPRINTK("testing SRAM\n");
  519. if ((result = sram_test_pass(lanai, 0x5555)) != 0)
  520. return result;
  521. if ((result = sram_test_pass(lanai, 0xAAAA)) != 0)
  522. return result;
  523. #endif
  524. DPRINTK("clearing SRAM\n");
  525. return sram_test_pass(lanai, 0x0000);
  526. }
  527. /* -------------------- CARD-BASED VCC TABLE UTILITIES: */
  528. /* vcc table */
  529. enum lanai_vcc_offset {
  530. vcc_rxaddr1 = 0x00, /* Location1, plus bits: */
  531. #define RXADDR1_SET_SIZE(x) ((x)*0x0000100) /* size of RX buffer */
  532. #define RXADDR1_SET_RMMODE(x) ((x)*0x00800) /* RM cell action; values: */
  533. #define RMMODE_TRASH (0) /* discard */
  534. #define RMMODE_PRESERVE (1) /* input as AAL0 */
  535. #define RMMODE_PIPE (2) /* pipe to coscheduler */
  536. #define RMMODE_PIPEALL (3) /* pipe non-RM too */
  537. #define RXADDR1_OAM_PRESERVE (0x00002000) /* Input OAM cells as AAL0 */
  538. #define RXADDR1_SET_MODE(x) ((x)*0x0004000) /* Reassembly mode */
  539. #define RXMODE_TRASH (0) /* discard */
  540. #define RXMODE_AAL0 (1) /* non-AAL5 mode */
  541. #define RXMODE_AAL5 (2) /* AAL5, intr. each PDU */
  542. #define RXMODE_AAL5_STREAM (3) /* AAL5 w/o per-PDU intr */
  543. vcc_rxaddr2 = 0x04, /* Location2 */
  544. vcc_rxcrc1 = 0x08, /* RX CRC claculation space */
  545. vcc_rxcrc2 = 0x0C,
  546. vcc_rxwriteptr = 0x10, /* RX writeptr, plus bits: */
  547. #define RXWRITEPTR_LASTEFCI (0x00002000) /* Last PDU had EFCI bit */
  548. #define RXWRITEPTR_DROPPING (0x00004000) /* Had error, dropping */
  549. #define RXWRITEPTR_TRASHING (0x00008000) /* Trashing */
  550. vcc_rxbufstart = 0x14, /* RX bufstart, plus bits: */
  551. #define RXBUFSTART_CLP (0x00004000)
  552. #define RXBUFSTART_CI (0x00008000)
  553. vcc_rxreadptr = 0x18, /* RX readptr */
  554. vcc_txicg = 0x1C, /* TX ICG */
  555. vcc_txaddr1 = 0x20, /* Location1, plus bits: */
  556. #define TXADDR1_SET_SIZE(x) ((x)*0x0000100) /* size of TX buffer */
  557. #define TXADDR1_ABR (0x00008000) /* use ABR (doesn't work) */
  558. vcc_txaddr2 = 0x24, /* Location2 */
  559. vcc_txcrc1 = 0x28, /* TX CRC claculation space */
  560. vcc_txcrc2 = 0x2C,
  561. vcc_txreadptr = 0x30, /* TX Readptr, plus bits: */
  562. #define TXREADPTR_GET_PTR(x) ((x)&0x01FFF)
  563. #define TXREADPTR_MASK_DELTA (0x0000E000) /* ? */
  564. vcc_txendptr = 0x34, /* TX Endptr, plus bits: */
  565. #define TXENDPTR_CLP (0x00002000)
  566. #define TXENDPTR_MASK_PDUMODE (0x0000C000) /* PDU mode; values: */
  567. #define PDUMODE_AAL0 (0*0x04000)
  568. #define PDUMODE_AAL5 (2*0x04000)
  569. #define PDUMODE_AAL5STREAM (3*0x04000)
  570. vcc_txwriteptr = 0x38, /* TX Writeptr */
  571. #define TXWRITEPTR_GET_PTR(x) ((x)&0x1FFF)
  572. vcc_txcbr_next = 0x3C /* # of next CBR VCI in ring */
  573. #define TXCBR_NEXT_BOZO (0x00008000) /* "bozo bit" */
  574. };
  575. #define CARDVCC_SIZE (0x40)
  576. static inline bus_addr_t cardvcc_addr(const struct lanai_dev *lanai,
  577. vci_t vci)
  578. {
  579. return sram_addr(lanai, vci * CARDVCC_SIZE);
  580. }
  581. static inline u32 cardvcc_read(const struct lanai_vcc *lvcc,
  582. enum lanai_vcc_offset offset)
  583. {
  584. u32 val;
  585. APRINTK(lvcc->vbase != NULL, "cardvcc_read: unbound vcc!\n");
  586. val= readl(lvcc->vbase + offset);
  587. RWDEBUG("VR vci=%04d 0x%02X = 0x%08X\n",
  588. lvcc->vci, (int) offset, val);
  589. return val;
  590. }
  591. static inline void cardvcc_write(const struct lanai_vcc *lvcc,
  592. u32 val, enum lanai_vcc_offset offset)
  593. {
  594. APRINTK(lvcc->vbase != NULL, "cardvcc_write: unbound vcc!\n");
  595. APRINTK((val & ~0xFFFF) == 0,
  596. "cardvcc_write: bad val 0x%X (vci=%d, addr=0x%02X)\n",
  597. (unsigned int) val, lvcc->vci, (unsigned int) offset);
  598. RWDEBUG("VW vci=%04d 0x%02X > 0x%08X\n",
  599. lvcc->vci, (unsigned int) offset, (unsigned int) val);
  600. writel(val, lvcc->vbase + offset);
  601. }
  602. /* -------------------- COMPUTE SIZE OF AN AAL5 PDU: */
  603. /* How many bytes will an AAL5 PDU take to transmit - remember that:
  604. * o we need to add 8 bytes for length, CPI, UU, and CRC
  605. * o we need to round up to 48 bytes for cells
  606. */
  607. static inline int aal5_size(int size)
  608. {
  609. int cells = (size + 8 + 47) / 48;
  610. return cells * 48;
  611. }
  612. /* -------------------- FREE AN ATM SKB: */
  613. static inline void lanai_free_skb(struct atm_vcc *atmvcc, struct sk_buff *skb)
  614. {
  615. if (atmvcc->pop != NULL)
  616. atmvcc->pop(atmvcc, skb);
  617. else
  618. dev_kfree_skb_any(skb);
  619. }
  620. /* -------------------- TURN VCCS ON AND OFF: */
  621. static void host_vcc_start_rx(const struct lanai_vcc *lvcc)
  622. {
  623. u32 addr1;
  624. if (lvcc->rx.atmvcc->qos.aal == ATM_AAL5) {
  625. dma_addr_t dmaaddr = lvcc->rx.buf.dmaaddr;
  626. cardvcc_write(lvcc, 0xFFFF, vcc_rxcrc1);
  627. cardvcc_write(lvcc, 0xFFFF, vcc_rxcrc2);
  628. cardvcc_write(lvcc, 0, vcc_rxwriteptr);
  629. cardvcc_write(lvcc, 0, vcc_rxbufstart);
  630. cardvcc_write(lvcc, 0, vcc_rxreadptr);
  631. cardvcc_write(lvcc, (dmaaddr >> 16) & 0xFFFF, vcc_rxaddr2);
  632. addr1 = ((dmaaddr >> 8) & 0xFF) |
  633. RXADDR1_SET_SIZE(lanai_buf_size_cardorder(&lvcc->rx.buf))|
  634. RXADDR1_SET_RMMODE(RMMODE_TRASH) | /* ??? */
  635. /* RXADDR1_OAM_PRESERVE | --- no OAM support yet */
  636. RXADDR1_SET_MODE(RXMODE_AAL5);
  637. } else
  638. addr1 = RXADDR1_SET_RMMODE(RMMODE_PRESERVE) | /* ??? */
  639. RXADDR1_OAM_PRESERVE | /* ??? */
  640. RXADDR1_SET_MODE(RXMODE_AAL0);
  641. /* This one must be last! */
  642. cardvcc_write(lvcc, addr1, vcc_rxaddr1);
  643. }
  644. static void host_vcc_start_tx(const struct lanai_vcc *lvcc)
  645. {
  646. dma_addr_t dmaaddr = lvcc->tx.buf.dmaaddr;
  647. cardvcc_write(lvcc, 0, vcc_txicg);
  648. cardvcc_write(lvcc, 0xFFFF, vcc_txcrc1);
  649. cardvcc_write(lvcc, 0xFFFF, vcc_txcrc2);
  650. cardvcc_write(lvcc, 0, vcc_txreadptr);
  651. cardvcc_write(lvcc, 0, vcc_txendptr);
  652. cardvcc_write(lvcc, 0, vcc_txwriteptr);
  653. cardvcc_write(lvcc,
  654. (lvcc->tx.atmvcc->qos.txtp.traffic_class == ATM_CBR) ?
  655. TXCBR_NEXT_BOZO | lvcc->vci : 0, vcc_txcbr_next);
  656. cardvcc_write(lvcc, (dmaaddr >> 16) & 0xFFFF, vcc_txaddr2);
  657. cardvcc_write(lvcc,
  658. ((dmaaddr >> 8) & 0xFF) |
  659. TXADDR1_SET_SIZE(lanai_buf_size_cardorder(&lvcc->tx.buf)),
  660. vcc_txaddr1);
  661. }
  662. /* Shutdown receiving on card */
  663. static void lanai_shutdown_rx_vci(const struct lanai_vcc *lvcc)
  664. {
  665. if (lvcc->vbase == NULL) /* We were never bound to a VCI */
  666. return;
  667. /* 15.1.1 - set to trashing, wait one cell time (15us) */
  668. cardvcc_write(lvcc,
  669. RXADDR1_SET_RMMODE(RMMODE_TRASH) |
  670. RXADDR1_SET_MODE(RXMODE_TRASH), vcc_rxaddr1);
  671. udelay(15);
  672. /* 15.1.2 - clear rest of entries */
  673. cardvcc_write(lvcc, 0, vcc_rxaddr2);
  674. cardvcc_write(lvcc, 0, vcc_rxcrc1);
  675. cardvcc_write(lvcc, 0, vcc_rxcrc2);
  676. cardvcc_write(lvcc, 0, vcc_rxwriteptr);
  677. cardvcc_write(lvcc, 0, vcc_rxbufstart);
  678. cardvcc_write(lvcc, 0, vcc_rxreadptr);
  679. }
  680. /* Shutdown transmitting on card.
  681. * Unfortunately the lanai needs us to wait until all the data
  682. * drains out of the buffer before we can dealloc it, so this
  683. * can take awhile -- up to 370ms for a full 128KB buffer
  684. * assuming everone else is quiet. In theory the time is
  685. * boundless if there's a CBR VCC holding things up.
  686. */
  687. static void lanai_shutdown_tx_vci(struct lanai_dev *lanai,
  688. struct lanai_vcc *lvcc)
  689. {
  690. struct sk_buff *skb;
  691. unsigned long flags, timeout;
  692. int read, write, lastread = -1;
  693. if (lvcc->vbase == NULL) /* We were never bound to a VCI */
  694. return;
  695. /* 15.2.1 - wait for queue to drain */
  696. while ((skb = skb_dequeue(&lvcc->tx.backlog)) != NULL)
  697. lanai_free_skb(lvcc->tx.atmvcc, skb);
  698. read_lock_irqsave(&vcc_sklist_lock, flags);
  699. __clear_bit(lvcc->vci, lanai->backlog_vccs);
  700. read_unlock_irqrestore(&vcc_sklist_lock, flags);
  701. /*
  702. * We need to wait for the VCC to drain but don't wait forever. We
  703. * give each 1K of buffer size 1/128th of a second to clear out.
  704. * TODO: maybe disable CBR if we're about to timeout?
  705. */
  706. timeout = jiffies +
  707. (((lanai_buf_size(&lvcc->tx.buf) / 1024) * HZ) >> 7);
  708. write = TXWRITEPTR_GET_PTR(cardvcc_read(lvcc, vcc_txwriteptr));
  709. for (;;) {
  710. read = TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr));
  711. if (read == write && /* Is TX buffer empty? */
  712. (lvcc->tx.atmvcc->qos.txtp.traffic_class != ATM_CBR ||
  713. (cardvcc_read(lvcc, vcc_txcbr_next) &
  714. TXCBR_NEXT_BOZO) == 0))
  715. break;
  716. if (read != lastread) { /* Has there been any progress? */
  717. lastread = read;
  718. timeout += HZ / 10;
  719. }
  720. if (unlikely(time_after(jiffies, timeout))) {
  721. printk(KERN_ERR DEV_LABEL "(itf %d): Timed out on "
  722. "backlog closing vci %d\n",
  723. lvcc->tx.atmvcc->dev->number, lvcc->vci);
  724. DPRINTK("read, write = %d, %d\n", read, write);
  725. break;
  726. }
  727. msleep(40);
  728. }
  729. /* 15.2.2 - clear out all tx registers */
  730. cardvcc_write(lvcc, 0, vcc_txreadptr);
  731. cardvcc_write(lvcc, 0, vcc_txwriteptr);
  732. cardvcc_write(lvcc, 0, vcc_txendptr);
  733. cardvcc_write(lvcc, 0, vcc_txcrc1);
  734. cardvcc_write(lvcc, 0, vcc_txcrc2);
  735. cardvcc_write(lvcc, 0, vcc_txaddr2);
  736. cardvcc_write(lvcc, 0, vcc_txaddr1);
  737. }
  738. /* -------------------- MANAGING AAL0 RX BUFFER: */
  739. static inline int aal0_buffer_allocate(struct lanai_dev *lanai)
  740. {
  741. DPRINTK("aal0_buffer_allocate: allocating AAL0 RX buffer\n");
  742. lanai_buf_allocate(&lanai->aal0buf, AAL0_RX_BUFFER_SIZE, 80,
  743. lanai->pci);
  744. return (lanai->aal0buf.start == NULL) ? -ENOMEM : 0;
  745. }
  746. static inline void aal0_buffer_free(struct lanai_dev *lanai)
  747. {
  748. DPRINTK("aal0_buffer_allocate: freeing AAL0 RX buffer\n");
  749. lanai_buf_deallocate(&lanai->aal0buf, lanai->pci);
  750. }
  751. /* -------------------- EEPROM UTILITIES: */
  752. /* Offsets of data in the EEPROM */
  753. #define EEPROM_COPYRIGHT (0)
  754. #define EEPROM_COPYRIGHT_LEN (44)
  755. #define EEPROM_CHECKSUM (62)
  756. #define EEPROM_CHECKSUM_REV (63)
  757. #define EEPROM_MAC (64)
  758. #define EEPROM_MAC_REV (70)
  759. #define EEPROM_SERIAL (112)
  760. #define EEPROM_SERIAL_REV (116)
  761. #define EEPROM_MAGIC (120)
  762. #define EEPROM_MAGIC_REV (124)
  763. #define EEPROM_MAGIC_VALUE (0x5AB478D2)
  764. #ifndef READ_EEPROM
  765. /* Stub functions to use if EEPROM reading is disabled */
  766. static int eeprom_read(struct lanai_dev *lanai)
  767. {
  768. printk(KERN_INFO DEV_LABEL "(itf %d): *NOT* reading EEPROM\n",
  769. lanai->number);
  770. memset(&lanai->eeprom[EEPROM_MAC], 0, 6);
  771. return 0;
  772. }
  773. static int eeprom_validate(struct lanai_dev *lanai)
  774. {
  775. lanai->serialno = 0;
  776. lanai->magicno = EEPROM_MAGIC_VALUE;
  777. return 0;
  778. }
  779. #else /* READ_EEPROM */
  780. static int eeprom_read(struct lanai_dev *lanai)
  781. {
  782. int i, address;
  783. u8 data;
  784. u32 tmp;
  785. #define set_config1(x) do { lanai->conf1 = x; conf1_write(lanai); \
  786. } while (0)
  787. #define clock_h() set_config1(lanai->conf1 | CONFIG1_PROMCLK)
  788. #define clock_l() set_config1(lanai->conf1 &~ CONFIG1_PROMCLK)
  789. #define data_h() set_config1(lanai->conf1 | CONFIG1_PROMDATA)
  790. #define data_l() set_config1(lanai->conf1 &~ CONFIG1_PROMDATA)
  791. #define pre_read() do { data_h(); clock_h(); udelay(5); } while (0)
  792. #define read_pin() (reg_read(lanai, Status_Reg) & STATUS_PROMDATA)
  793. #define send_stop() do { data_l(); udelay(5); clock_h(); udelay(5); \
  794. data_h(); udelay(5); } while (0)
  795. /* start with both clock and data high */
  796. data_h(); clock_h(); udelay(5);
  797. for (address = 0; address < LANAI_EEPROM_SIZE; address++) {
  798. data = (address << 1) | 1; /* Command=read + address */
  799. /* send start bit */
  800. data_l(); udelay(5);
  801. clock_l(); udelay(5);
  802. for (i = 128; i != 0; i >>= 1) { /* write command out */
  803. tmp = (lanai->conf1 & ~CONFIG1_PROMDATA) |
  804. ((data & i) ? CONFIG1_PROMDATA : 0);
  805. if (lanai->conf1 != tmp) {
  806. set_config1(tmp);
  807. udelay(5); /* Let new data settle */
  808. }
  809. clock_h(); udelay(5); clock_l(); udelay(5);
  810. }
  811. /* look for ack */
  812. data_h(); clock_h(); udelay(5);
  813. if (read_pin() != 0)
  814. goto error; /* No ack seen */
  815. clock_l(); udelay(5);
  816. /* read back result */
  817. for (data = 0, i = 7; i >= 0; i--) {
  818. data_h(); clock_h(); udelay(5);
  819. data = (data << 1) | !!read_pin();
  820. clock_l(); udelay(5);
  821. }
  822. /* look again for ack */
  823. data_h(); clock_h(); udelay(5);
  824. if (read_pin() == 0)
  825. goto error; /* Spurious ack */
  826. clock_l(); udelay(5);
  827. send_stop();
  828. lanai->eeprom[address] = data;
  829. DPRINTK("EEPROM 0x%04X %02X\n",
  830. (unsigned int) address, (unsigned int) data);
  831. }
  832. return 0;
  833. error:
  834. clock_l(); udelay(5); /* finish read */
  835. send_stop();
  836. printk(KERN_ERR DEV_LABEL "(itf %d): error reading EEPROM byte %d\n",
  837. lanai->number, address);
  838. return -EIO;
  839. #undef set_config1
  840. #undef clock_h
  841. #undef clock_l
  842. #undef data_h
  843. #undef data_l
  844. #undef pre_read
  845. #undef read_pin
  846. #undef send_stop
  847. }
  848. /* read a big-endian 4-byte value out of eeprom */
  849. static inline u32 eeprom_be4(const struct lanai_dev *lanai, int address)
  850. {
  851. return be32_to_cpup((const u32 *) &lanai->eeprom[address]);
  852. }
  853. /* Checksum/validate EEPROM contents */
  854. static int eeprom_validate(struct lanai_dev *lanai)
  855. {
  856. int i, s;
  857. u32 v;
  858. const u8 *e = lanai->eeprom;
  859. #ifdef DEBUG
  860. /* First, see if we can get an ASCIIZ string out of the copyright */
  861. for (i = EEPROM_COPYRIGHT;
  862. i < (EEPROM_COPYRIGHT + EEPROM_COPYRIGHT_LEN); i++)
  863. if (e[i] < 0x20 || e[i] > 0x7E)
  864. break;
  865. if ( i != EEPROM_COPYRIGHT &&
  866. i != EEPROM_COPYRIGHT + EEPROM_COPYRIGHT_LEN && e[i] == '\0')
  867. DPRINTK("eeprom: copyright = \"%s\"\n",
  868. (char *) &e[EEPROM_COPYRIGHT]);
  869. else
  870. DPRINTK("eeprom: copyright not found\n");
  871. #endif
  872. /* Validate checksum */
  873. for (i = s = 0; i < EEPROM_CHECKSUM; i++)
  874. s += e[i];
  875. s &= 0xFF;
  876. if (s != e[EEPROM_CHECKSUM]) {
  877. printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM checksum bad "
  878. "(wanted 0x%02X, got 0x%02X)\n", lanai->number,
  879. (unsigned int) s, (unsigned int) e[EEPROM_CHECKSUM]);
  880. return -EIO;
  881. }
  882. s ^= 0xFF;
  883. if (s != e[EEPROM_CHECKSUM_REV]) {
  884. printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM inverse checksum "
  885. "bad (wanted 0x%02X, got 0x%02X)\n", lanai->number,
  886. (unsigned int) s, (unsigned int) e[EEPROM_CHECKSUM_REV]);
  887. return -EIO;
  888. }
  889. /* Verify MAC address */
  890. for (i = 0; i < 6; i++)
  891. if ((e[EEPROM_MAC + i] ^ e[EEPROM_MAC_REV + i]) != 0xFF) {
  892. printk(KERN_ERR DEV_LABEL
  893. "(itf %d) : EEPROM MAC addresses don't match "
  894. "(0x%02X, inverse 0x%02X)\n", lanai->number,
  895. (unsigned int) e[EEPROM_MAC + i],
  896. (unsigned int) e[EEPROM_MAC_REV + i]);
  897. return -EIO;
  898. }
  899. DPRINTK("eeprom: MAC address = %pM\n", &e[EEPROM_MAC]);
  900. /* Verify serial number */
  901. lanai->serialno = eeprom_be4(lanai, EEPROM_SERIAL);
  902. v = eeprom_be4(lanai, EEPROM_SERIAL_REV);
  903. if ((lanai->serialno ^ v) != 0xFFFFFFFF) {
  904. printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM serial numbers "
  905. "don't match (0x%08X, inverse 0x%08X)\n", lanai->number,
  906. (unsigned int) lanai->serialno, (unsigned int) v);
  907. return -EIO;
  908. }
  909. DPRINTK("eeprom: Serial number = %d\n", (unsigned int) lanai->serialno);
  910. /* Verify magic number */
  911. lanai->magicno = eeprom_be4(lanai, EEPROM_MAGIC);
  912. v = eeprom_be4(lanai, EEPROM_MAGIC_REV);
  913. if ((lanai->magicno ^ v) != 0xFFFFFFFF) {
  914. printk(KERN_ERR DEV_LABEL "(itf %d): EEPROM magic numbers "
  915. "don't match (0x%08X, inverse 0x%08X)\n", lanai->number,
  916. lanai->magicno, v);
  917. return -EIO;
  918. }
  919. DPRINTK("eeprom: Magic number = 0x%08X\n", lanai->magicno);
  920. if (lanai->magicno != EEPROM_MAGIC_VALUE)
  921. printk(KERN_WARNING DEV_LABEL "(itf %d): warning - EEPROM "
  922. "magic not what expected (got 0x%08X, not 0x%08X)\n",
  923. lanai->number, (unsigned int) lanai->magicno,
  924. (unsigned int) EEPROM_MAGIC_VALUE);
  925. return 0;
  926. }
  927. #endif /* READ_EEPROM */
  928. static inline const u8 *eeprom_mac(const struct lanai_dev *lanai)
  929. {
  930. return &lanai->eeprom[EEPROM_MAC];
  931. }
  932. /* -------------------- INTERRUPT HANDLING UTILITIES: */
  933. /* Interrupt types */
  934. #define INT_STATS (0x00000002) /* Statistics counter overflow */
  935. #define INT_SOOL (0x00000004) /* SOOL changed state */
  936. #define INT_LOCD (0x00000008) /* LOCD changed state */
  937. #define INT_LED (0x00000010) /* LED (HAPPI) changed state */
  938. #define INT_GPIN (0x00000020) /* GPIN changed state */
  939. #define INT_PING (0x00000040) /* PING_COUNT fulfilled */
  940. #define INT_WAKE (0x00000080) /* Lanai wants bus */
  941. #define INT_CBR0 (0x00000100) /* CBR sched hit VCI 0 */
  942. #define INT_LOCK (0x00000200) /* Service list overflow */
  943. #define INT_MISMATCH (0x00000400) /* TX magic list mismatch */
  944. #define INT_AAL0_STR (0x00000800) /* Non-AAL5 buffer half filled */
  945. #define INT_AAL0 (0x00001000) /* Non-AAL5 data available */
  946. #define INT_SERVICE (0x00002000) /* Service list entries available */
  947. #define INT_TABORTSENT (0x00004000) /* Target abort sent by lanai */
  948. #define INT_TABORTBM (0x00008000) /* Abort rcv'd as bus master */
  949. #define INT_TIMEOUTBM (0x00010000) /* No response to bus master */
  950. #define INT_PCIPARITY (0x00020000) /* Parity error on PCI */
  951. /* Sets of the above */
  952. #define INT_ALL (0x0003FFFE) /* All interrupts */
  953. #define INT_STATUS (0x0000003C) /* Some status pin changed */
  954. #define INT_DMASHUT (0x00038000) /* DMA engine got shut down */
  955. #define INT_SEGSHUT (0x00000700) /* Segmentation got shut down */
  956. static inline u32 intr_pending(const struct lanai_dev *lanai)
  957. {
  958. return reg_read(lanai, IntStatusMasked_Reg);
  959. }
  960. static inline void intr_enable(const struct lanai_dev *lanai, u32 i)
  961. {
  962. reg_write(lanai, i, IntControlEna_Reg);
  963. }
  964. static inline void intr_disable(const struct lanai_dev *lanai, u32 i)
  965. {
  966. reg_write(lanai, i, IntControlDis_Reg);
  967. }
  968. /* -------------------- CARD/PCI STATUS: */
  969. static void status_message(int itf, const char *name, int status)
  970. {
  971. static const char *onoff[2] = { "off to on", "on to off" };
  972. printk(KERN_INFO DEV_LABEL "(itf %d): %s changed from %s\n",
  973. itf, name, onoff[!status]);
  974. }
  975. static void lanai_check_status(struct lanai_dev *lanai)
  976. {
  977. u32 new = reg_read(lanai, Status_Reg);
  978. u32 changes = new ^ lanai->status;
  979. lanai->status = new;
  980. #define e(flag, name) \
  981. if (changes & flag) \
  982. status_message(lanai->number, name, new & flag)
  983. e(STATUS_SOOL, "SOOL");
  984. e(STATUS_LOCD, "LOCD");
  985. e(STATUS_LED, "LED");
  986. e(STATUS_GPIN, "GPIN");
  987. #undef e
  988. }
  989. static void pcistatus_got(int itf, const char *name)
  990. {
  991. printk(KERN_INFO DEV_LABEL "(itf %d): PCI got %s error\n", itf, name);
  992. }
  993. static void pcistatus_check(struct lanai_dev *lanai, int clearonly)
  994. {
  995. u16 s;
  996. int result;
  997. result = pci_read_config_word(lanai->pci, PCI_STATUS, &s);
  998. if (result != PCIBIOS_SUCCESSFUL) {
  999. printk(KERN_ERR DEV_LABEL "(itf %d): can't read PCI_STATUS: "
  1000. "%d\n", lanai->number, result);
  1001. return;
  1002. }
  1003. s &= PCI_STATUS_DETECTED_PARITY | PCI_STATUS_SIG_SYSTEM_ERROR |
  1004. PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT |
  1005. PCI_STATUS_SIG_TARGET_ABORT | PCI_STATUS_PARITY;
  1006. if (s == 0)
  1007. return;
  1008. result = pci_write_config_word(lanai->pci, PCI_STATUS, s);
  1009. if (result != PCIBIOS_SUCCESSFUL)
  1010. printk(KERN_ERR DEV_LABEL "(itf %d): can't write PCI_STATUS: "
  1011. "%d\n", lanai->number, result);
  1012. if (clearonly)
  1013. return;
  1014. #define e(flag, name, stat) \
  1015. if (s & flag) { \
  1016. pcistatus_got(lanai->number, name); \
  1017. ++lanai->stats.pcierr_##stat; \
  1018. }
  1019. e(PCI_STATUS_DETECTED_PARITY, "parity", parity_detect);
  1020. e(PCI_STATUS_SIG_SYSTEM_ERROR, "signalled system", serr_set);
  1021. e(PCI_STATUS_REC_MASTER_ABORT, "master", master_abort);
  1022. e(PCI_STATUS_REC_TARGET_ABORT, "master target", m_target_abort);
  1023. e(PCI_STATUS_SIG_TARGET_ABORT, "slave", s_target_abort);
  1024. e(PCI_STATUS_PARITY, "master parity", master_parity);
  1025. #undef e
  1026. }
  1027. /* -------------------- VCC TX BUFFER UTILITIES: */
  1028. /* space left in tx buffer in bytes */
  1029. static inline int vcc_tx_space(const struct lanai_vcc *lvcc, int endptr)
  1030. {
  1031. int r;
  1032. r = endptr * 16;
  1033. r -= ((unsigned long) lvcc->tx.buf.ptr) -
  1034. ((unsigned long) lvcc->tx.buf.start);
  1035. r -= 16; /* Leave "bubble" - if start==end it looks empty */
  1036. if (r < 0)
  1037. r += lanai_buf_size(&lvcc->tx.buf);
  1038. return r;
  1039. }
  1040. /* test if VCC is currently backlogged */
  1041. static inline int vcc_is_backlogged(const struct lanai_vcc *lvcc)
  1042. {
  1043. return !skb_queue_empty(&lvcc->tx.backlog);
  1044. }
  1045. /* Bit fields in the segmentation buffer descriptor */
  1046. #define DESCRIPTOR_MAGIC (0xD0000000)
  1047. #define DESCRIPTOR_AAL5 (0x00008000)
  1048. #define DESCRIPTOR_AAL5_STREAM (0x00004000)
  1049. #define DESCRIPTOR_CLP (0x00002000)
  1050. /* Add 32-bit descriptor with its padding */
  1051. static inline void vcc_tx_add_aal5_descriptor(struct lanai_vcc *lvcc,
  1052. u32 flags, int len)
  1053. {
  1054. int pos;
  1055. APRINTK((((unsigned long) lvcc->tx.buf.ptr) & 15) == 0,
  1056. "vcc_tx_add_aal5_descriptor: bad ptr=%p\n", lvcc->tx.buf.ptr);
  1057. lvcc->tx.buf.ptr += 4; /* Hope the values REALLY don't matter */
  1058. pos = ((unsigned char *) lvcc->tx.buf.ptr) -
  1059. (unsigned char *) lvcc->tx.buf.start;
  1060. APRINTK((pos & ~0x0001FFF0) == 0,
  1061. "vcc_tx_add_aal5_descriptor: bad pos (%d) before, vci=%d, "
  1062. "start,ptr,end=%p,%p,%p\n", pos, lvcc->vci,
  1063. lvcc->tx.buf.start, lvcc->tx.buf.ptr, lvcc->tx.buf.end);
  1064. pos = (pos + len) & (lanai_buf_size(&lvcc->tx.buf) - 1);
  1065. APRINTK((pos & ~0x0001FFF0) == 0,
  1066. "vcc_tx_add_aal5_descriptor: bad pos (%d) after, vci=%d, "
  1067. "start,ptr,end=%p,%p,%p\n", pos, lvcc->vci,
  1068. lvcc->tx.buf.start, lvcc->tx.buf.ptr, lvcc->tx.buf.end);
  1069. lvcc->tx.buf.ptr[-1] =
  1070. cpu_to_le32(DESCRIPTOR_MAGIC | DESCRIPTOR_AAL5 |
  1071. ((lvcc->tx.atmvcc->atm_options & ATM_ATMOPT_CLP) ?
  1072. DESCRIPTOR_CLP : 0) | flags | pos >> 4);
  1073. if (lvcc->tx.buf.ptr >= lvcc->tx.buf.end)
  1074. lvcc->tx.buf.ptr = lvcc->tx.buf.start;
  1075. }
  1076. /* Add 32-bit AAL5 trailer and leave room for its CRC */
  1077. static inline void vcc_tx_add_aal5_trailer(struct lanai_vcc *lvcc,
  1078. int len, int cpi, int uu)
  1079. {
  1080. APRINTK((((unsigned long) lvcc->tx.buf.ptr) & 15) == 8,
  1081. "vcc_tx_add_aal5_trailer: bad ptr=%p\n", lvcc->tx.buf.ptr);
  1082. lvcc->tx.buf.ptr += 2;
  1083. lvcc->tx.buf.ptr[-2] = cpu_to_be32((uu << 24) | (cpi << 16) | len);
  1084. if (lvcc->tx.buf.ptr >= lvcc->tx.buf.end)
  1085. lvcc->tx.buf.ptr = lvcc->tx.buf.start;
  1086. }
  1087. static inline void vcc_tx_memcpy(struct lanai_vcc *lvcc,
  1088. const unsigned char *src, int n)
  1089. {
  1090. unsigned char *e;
  1091. int m;
  1092. e = ((unsigned char *) lvcc->tx.buf.ptr) + n;
  1093. m = e - (unsigned char *) lvcc->tx.buf.end;
  1094. if (m < 0)
  1095. m = 0;
  1096. memcpy(lvcc->tx.buf.ptr, src, n - m);
  1097. if (m != 0) {
  1098. memcpy(lvcc->tx.buf.start, src + n - m, m);
  1099. e = ((unsigned char *) lvcc->tx.buf.start) + m;
  1100. }
  1101. lvcc->tx.buf.ptr = (u32 *) e;
  1102. }
  1103. static inline void vcc_tx_memzero(struct lanai_vcc *lvcc, int n)
  1104. {
  1105. unsigned char *e;
  1106. int m;
  1107. if (n == 0)
  1108. return;
  1109. e = ((unsigned char *) lvcc->tx.buf.ptr) + n;
  1110. m = e - (unsigned char *) lvcc->tx.buf.end;
  1111. if (m < 0)
  1112. m = 0;
  1113. memset(lvcc->tx.buf.ptr, 0, n - m);
  1114. if (m != 0) {
  1115. memset(lvcc->tx.buf.start, 0, m);
  1116. e = ((unsigned char *) lvcc->tx.buf.start) + m;
  1117. }
  1118. lvcc->tx.buf.ptr = (u32 *) e;
  1119. }
  1120. /* Update "butt" register to specify new WritePtr */
  1121. static inline void lanai_endtx(struct lanai_dev *lanai,
  1122. const struct lanai_vcc *lvcc)
  1123. {
  1124. int i, ptr = ((unsigned char *) lvcc->tx.buf.ptr) -
  1125. (unsigned char *) lvcc->tx.buf.start;
  1126. APRINTK((ptr & ~0x0001FFF0) == 0,
  1127. "lanai_endtx: bad ptr (%d), vci=%d, start,ptr,end=%p,%p,%p\n",
  1128. ptr, lvcc->vci, lvcc->tx.buf.start, lvcc->tx.buf.ptr,
  1129. lvcc->tx.buf.end);
  1130. /*
  1131. * Since the "butt register" is a shared resounce on the card we
  1132. * serialize all accesses to it through this spinlock. This is
  1133. * mostly just paranoia since the register is rarely "busy" anyway
  1134. * but is needed for correctness.
  1135. */
  1136. spin_lock(&lanai->endtxlock);
  1137. /*
  1138. * We need to check if the "butt busy" bit is set before
  1139. * updating the butt register. In theory this should
  1140. * never happen because the ATM card is plenty fast at
  1141. * updating the register. Still, we should make sure
  1142. */
  1143. for (i = 0; reg_read(lanai, Status_Reg) & STATUS_BUTTBUSY; i++) {
  1144. if (unlikely(i > 50)) {
  1145. printk(KERN_ERR DEV_LABEL "(itf %d): butt register "
  1146. "always busy!\n", lanai->number);
  1147. break;
  1148. }
  1149. udelay(5);
  1150. }
  1151. /*
  1152. * Before we tall the card to start work we need to be sure 100% of
  1153. * the info in the service buffer has been written before we tell
  1154. * the card about it
  1155. */
  1156. wmb();
  1157. reg_write(lanai, (ptr << 12) | lvcc->vci, Butt_Reg);
  1158. spin_unlock(&lanai->endtxlock);
  1159. }
  1160. /*
  1161. * Add one AAL5 PDU to lvcc's transmit buffer. Caller garauntees there's
  1162. * space available. "pdusize" is the number of bytes the PDU will take
  1163. */
  1164. static void lanai_send_one_aal5(struct lanai_dev *lanai,
  1165. struct lanai_vcc *lvcc, struct sk_buff *skb, int pdusize)
  1166. {
  1167. int pad;
  1168. APRINTK(pdusize == aal5_size(skb->len),
  1169. "lanai_send_one_aal5: wrong size packet (%d != %d)\n",
  1170. pdusize, aal5_size(skb->len));
  1171. vcc_tx_add_aal5_descriptor(lvcc, 0, pdusize);
  1172. pad = pdusize - skb->len - 8;
  1173. APRINTK(pad >= 0, "pad is negative (%d)\n", pad);
  1174. APRINTK(pad < 48, "pad is too big (%d)\n", pad);
  1175. vcc_tx_memcpy(lvcc, skb->data, skb->len);
  1176. vcc_tx_memzero(lvcc, pad);
  1177. vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
  1178. lanai_endtx(lanai, lvcc);
  1179. lanai_free_skb(lvcc->tx.atmvcc, skb);
  1180. atomic_inc(&lvcc->tx.atmvcc->stats->tx);
  1181. }
  1182. /* Try to fill the buffer - don't call unless there is backlog */
  1183. static void vcc_tx_unqueue_aal5(struct lanai_dev *lanai,
  1184. struct lanai_vcc *lvcc, int endptr)
  1185. {
  1186. int n;
  1187. struct sk_buff *skb;
  1188. int space = vcc_tx_space(lvcc, endptr);
  1189. APRINTK(vcc_is_backlogged(lvcc),
  1190. "vcc_tx_unqueue() called with empty backlog (vci=%d)\n",
  1191. lvcc->vci);
  1192. while (space >= 64) {
  1193. skb = skb_dequeue(&lvcc->tx.backlog);
  1194. if (skb == NULL)
  1195. goto no_backlog;
  1196. n = aal5_size(skb->len);
  1197. if (n + 16 > space) {
  1198. /* No room for this packet - put it back on queue */
  1199. skb_queue_head(&lvcc->tx.backlog, skb);
  1200. return;
  1201. }
  1202. lanai_send_one_aal5(lanai, lvcc, skb, n);
  1203. space -= n + 16;
  1204. }
  1205. if (!vcc_is_backlogged(lvcc)) {
  1206. no_backlog:
  1207. __clear_bit(lvcc->vci, lanai->backlog_vccs);
  1208. }
  1209. }
  1210. /* Given an skb that we want to transmit either send it now or queue */
  1211. static void vcc_tx_aal5(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
  1212. struct sk_buff *skb)
  1213. {
  1214. int space, n;
  1215. if (vcc_is_backlogged(lvcc)) /* Already backlogged */
  1216. goto queue_it;
  1217. space = vcc_tx_space(lvcc,
  1218. TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr)));
  1219. n = aal5_size(skb->len);
  1220. APRINTK(n + 16 >= 64, "vcc_tx_aal5: n too small (%d)\n", n);
  1221. if (space < n + 16) { /* No space for this PDU */
  1222. __set_bit(lvcc->vci, lanai->backlog_vccs);
  1223. queue_it:
  1224. skb_queue_tail(&lvcc->tx.backlog, skb);
  1225. return;
  1226. }
  1227. lanai_send_one_aal5(lanai, lvcc, skb, n);
  1228. }
  1229. static void vcc_tx_unqueue_aal0(struct lanai_dev *lanai,
  1230. struct lanai_vcc *lvcc, int endptr)
  1231. {
  1232. printk(KERN_INFO DEV_LABEL
  1233. ": vcc_tx_unqueue_aal0: not implemented\n");
  1234. }
  1235. static void vcc_tx_aal0(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
  1236. struct sk_buff *skb)
  1237. {
  1238. printk(KERN_INFO DEV_LABEL ": vcc_tx_aal0: not implemented\n");
  1239. /* Remember to increment lvcc->tx.atmvcc->stats->tx */
  1240. lanai_free_skb(lvcc->tx.atmvcc, skb);
  1241. }
  1242. /* -------------------- VCC RX BUFFER UTILITIES: */
  1243. /* unlike the _tx_ cousins, this doesn't update ptr */
  1244. static inline void vcc_rx_memcpy(unsigned char *dest,
  1245. const struct lanai_vcc *lvcc, int n)
  1246. {
  1247. int m = ((const unsigned char *) lvcc->rx.buf.ptr) + n -
  1248. ((const unsigned char *) (lvcc->rx.buf.end));
  1249. if (m < 0)
  1250. m = 0;
  1251. memcpy(dest, lvcc->rx.buf.ptr, n - m);
  1252. memcpy(dest + n - m, lvcc->rx.buf.start, m);
  1253. /* Make sure that these copies don't get reordered */
  1254. barrier();
  1255. }
  1256. /* Receive AAL5 data on a VCC with a particular endptr */
  1257. static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
  1258. {
  1259. int size;
  1260. struct sk_buff *skb;
  1261. const u32 *x;
  1262. u32 *end = &lvcc->rx.buf.start[endptr * 4];
  1263. int n = ((unsigned long) end) - ((unsigned long) lvcc->rx.buf.ptr);
  1264. if (n < 0)
  1265. n += lanai_buf_size(&lvcc->rx.buf);
  1266. APRINTK(n >= 0 && n < lanai_buf_size(&lvcc->rx.buf) && !(n & 15),
  1267. "vcc_rx_aal5: n out of range (%d/%zu)\n",
  1268. n, lanai_buf_size(&lvcc->rx.buf));
  1269. /* Recover the second-to-last word to get true pdu length */
  1270. if ((x = &end[-2]) < lvcc->rx.buf.start)
  1271. x = &lvcc->rx.buf.end[-2];
  1272. /*
  1273. * Before we actually read from the buffer, make sure the memory
  1274. * changes have arrived
  1275. */
  1276. rmb();
  1277. size = be32_to_cpup(x) & 0xffff;
  1278. if (unlikely(n != aal5_size(size))) {
  1279. /* Make sure size matches padding */
  1280. printk(KERN_INFO DEV_LABEL "(itf %d): Got bad AAL5 length "
  1281. "on vci=%d - size=%d n=%d\n",
  1282. lvcc->rx.atmvcc->dev->number, lvcc->vci, size, n);
  1283. lvcc->stats.x.aal5.rx_badlen++;
  1284. goto out;
  1285. }
  1286. skb = atm_alloc_charge(lvcc->rx.atmvcc, size, GFP_ATOMIC);
  1287. if (unlikely(skb == NULL)) {
  1288. lvcc->stats.rx_nomem++;
  1289. goto out;
  1290. }
  1291. skb_put(skb, size);
  1292. vcc_rx_memcpy(skb->data, lvcc, size);
  1293. ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
  1294. __net_timestamp(skb);
  1295. lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
  1296. atomic_inc(&lvcc->rx.atmvcc->stats->rx);
  1297. out:
  1298. lvcc->rx.buf.ptr = end;
  1299. cardvcc_write(lvcc, endptr, vcc_rxreadptr);
  1300. }
  1301. static void vcc_rx_aal0(struct lanai_dev *lanai)
  1302. {
  1303. printk(KERN_INFO DEV_LABEL ": vcc_rx_aal0: not implemented\n");
  1304. /* Remember to get read_lock(&vcc_sklist_lock) while looking up VC */
  1305. /* Remember to increment lvcc->rx.atmvcc->stats->rx */
  1306. }
  1307. /* -------------------- MANAGING HOST-BASED VCC TABLE: */
  1308. /* Decide whether to use vmalloc or get_zeroed_page for VCC table */
  1309. #if (NUM_VCI * BITS_PER_LONG) <= PAGE_SIZE
  1310. #define VCCTABLE_GETFREEPAGE
  1311. #else
  1312. #include <linux/vmalloc.h>
  1313. #endif
  1314. static int vcc_table_allocate(struct lanai_dev *lanai)
  1315. {
  1316. #ifdef VCCTABLE_GETFREEPAGE
  1317. APRINTK((lanai->num_vci) * sizeof(struct lanai_vcc *) <= PAGE_SIZE,
  1318. "vcc table > PAGE_SIZE!");
  1319. lanai->vccs = (struct lanai_vcc **) get_zeroed_page(GFP_KERNEL);
  1320. return (lanai->vccs == NULL) ? -ENOMEM : 0;
  1321. #else
  1322. int bytes = (lanai->num_vci) * sizeof(struct lanai_vcc *);
  1323. lanai->vccs = vzalloc(bytes);
  1324. if (unlikely(lanai->vccs == NULL))
  1325. return -ENOMEM;
  1326. return 0;
  1327. #endif
  1328. }
  1329. static inline void vcc_table_deallocate(const struct lanai_dev *lanai)
  1330. {
  1331. #ifdef VCCTABLE_GETFREEPAGE
  1332. free_page((unsigned long) lanai->vccs);
  1333. #else
  1334. vfree(lanai->vccs);
  1335. #endif
  1336. }
  1337. /* Allocate a fresh lanai_vcc, with the appropriate things cleared */
  1338. static inline struct lanai_vcc *new_lanai_vcc(void)
  1339. {
  1340. struct lanai_vcc *lvcc;
  1341. lvcc = kzalloc(sizeof(*lvcc), GFP_KERNEL);
  1342. if (likely(lvcc != NULL)) {
  1343. skb_queue_head_init(&lvcc->tx.backlog);
  1344. #ifdef DEBUG
  1345. lvcc->vci = -1;
  1346. #endif
  1347. }
  1348. return lvcc;
  1349. }
  1350. static int lanai_get_sized_buffer(struct lanai_dev *lanai,
  1351. struct lanai_buffer *buf, int max_sdu, int multiplier,
  1352. const char *name)
  1353. {
  1354. int size;
  1355. if (unlikely(max_sdu < 1))
  1356. max_sdu = 1;
  1357. max_sdu = aal5_size(max_sdu);
  1358. size = (max_sdu + 16) * multiplier + 16;
  1359. lanai_buf_allocate(buf, size, max_sdu + 32, lanai->pci);
  1360. if (unlikely(buf->start == NULL))
  1361. return -ENOMEM;
  1362. if (unlikely(lanai_buf_size(buf) < size))
  1363. printk(KERN_WARNING DEV_LABEL "(itf %d): wanted %d bytes "
  1364. "for %s buffer, got only %zu\n", lanai->number, size,
  1365. name, lanai_buf_size(buf));
  1366. DPRINTK("Allocated %zu byte %s buffer\n", lanai_buf_size(buf), name);
  1367. return 0;
  1368. }
  1369. /* Setup a RX buffer for a currently unbound AAL5 vci */
  1370. static inline int lanai_setup_rx_vci_aal5(struct lanai_dev *lanai,
  1371. struct lanai_vcc *lvcc, const struct atm_qos *qos)
  1372. {
  1373. return lanai_get_sized_buffer(lanai, &lvcc->rx.buf,
  1374. qos->rxtp.max_sdu, AAL5_RX_MULTIPLIER, "RX");
  1375. }
  1376. /* Setup a TX buffer for a currently unbound AAL5 vci */
  1377. static int lanai_setup_tx_vci(struct lanai_dev *lanai, struct lanai_vcc *lvcc,
  1378. const struct atm_qos *qos)
  1379. {
  1380. int max_sdu, multiplier;
  1381. if (qos->aal == ATM_AAL0) {
  1382. lvcc->tx.unqueue = vcc_tx_unqueue_aal0;
  1383. max_sdu = ATM_CELL_SIZE - 1;
  1384. multiplier = AAL0_TX_MULTIPLIER;
  1385. } else {
  1386. lvcc->tx.unqueue = vcc_tx_unqueue_aal5;
  1387. max_sdu = qos->txtp.max_sdu;
  1388. multiplier = AAL5_TX_MULTIPLIER;
  1389. }
  1390. return lanai_get_sized_buffer(lanai, &lvcc->tx.buf, max_sdu,
  1391. multiplier, "TX");
  1392. }
  1393. static inline void host_vcc_bind(struct lanai_dev *lanai,
  1394. struct lanai_vcc *lvcc, vci_t vci)
  1395. {
  1396. if (lvcc->vbase != NULL)
  1397. return; /* We already were bound in the other direction */
  1398. DPRINTK("Binding vci %d\n", vci);
  1399. #ifdef USE_POWERDOWN
  1400. if (lanai->nbound++ == 0) {
  1401. DPRINTK("Coming out of powerdown\n");
  1402. lanai->conf1 &= ~CONFIG1_POWERDOWN;
  1403. conf1_write(lanai);
  1404. conf2_write(lanai);
  1405. }
  1406. #endif
  1407. lvcc->vbase = cardvcc_addr(lanai, vci);
  1408. lanai->vccs[lvcc->vci = vci] = lvcc;
  1409. }
  1410. static inline void host_vcc_unbind(struct lanai_dev *lanai,
  1411. struct lanai_vcc *lvcc)
  1412. {
  1413. if (lvcc->vbase == NULL)
  1414. return; /* This vcc was never bound */
  1415. DPRINTK("Unbinding vci %d\n", lvcc->vci);
  1416. lvcc->vbase = NULL;
  1417. lanai->vccs[lvcc->vci] = NULL;
  1418. #ifdef USE_POWERDOWN
  1419. if (--lanai->nbound == 0) {
  1420. DPRINTK("Going into powerdown\n");
  1421. lanai->conf1 |= CONFIG1_POWERDOWN;
  1422. conf1_write(lanai);
  1423. }
  1424. #endif
  1425. }
  1426. /* -------------------- RESET CARD: */
  1427. static void lanai_reset(struct lanai_dev *lanai)
  1428. {
  1429. printk(KERN_CRIT DEV_LABEL "(itf %d): *NOT* resetting - not "
  1430. "implemented\n", lanai->number);
  1431. /* TODO */
  1432. /* The following is just a hack until we write the real
  1433. * resetter - at least ack whatever interrupt sent us
  1434. * here
  1435. */
  1436. reg_write(lanai, INT_ALL, IntAck_Reg);
  1437. lanai->stats.card_reset++;
  1438. }
  1439. /* -------------------- SERVICE LIST UTILITIES: */
  1440. /*
  1441. * Allocate service buffer and tell card about it
  1442. */
  1443. static int service_buffer_allocate(struct lanai_dev *lanai)
  1444. {
  1445. lanai_buf_allocate(&lanai->service, SERVICE_ENTRIES * 4, 8,
  1446. lanai->pci);
  1447. if (unlikely(lanai->service.start == NULL))
  1448. return -ENOMEM;
  1449. DPRINTK("allocated service buffer at %p, size %zu(%d)\n",
  1450. lanai->service.start,
  1451. lanai_buf_size(&lanai->service),
  1452. lanai_buf_size_cardorder(&lanai->service));
  1453. /* Clear ServWrite register to be safe */
  1454. reg_write(lanai, 0, ServWrite_Reg);
  1455. /* ServiceStuff register contains size and address of buffer */
  1456. reg_write(lanai,
  1457. SSTUFF_SET_SIZE(lanai_buf_size_cardorder(&lanai->service)) |
  1458. SSTUFF_SET_ADDR(lanai->service.dmaaddr),
  1459. ServiceStuff_Reg);
  1460. return 0;
  1461. }
  1462. static inline void service_buffer_deallocate(struct lanai_dev *lanai)
  1463. {
  1464. lanai_buf_deallocate(&lanai->service, lanai->pci);
  1465. }
  1466. /* Bitfields in service list */
  1467. #define SERVICE_TX (0x80000000) /* Was from transmission */
  1468. #define SERVICE_TRASH (0x40000000) /* RXed PDU was trashed */
  1469. #define SERVICE_CRCERR (0x20000000) /* RXed PDU had CRC error */
  1470. #define SERVICE_CI (0x10000000) /* RXed PDU had CI set */
  1471. #define SERVICE_CLP (0x08000000) /* RXed PDU had CLP set */
  1472. #define SERVICE_STREAM (0x04000000) /* RX Stream mode */
  1473. #define SERVICE_GET_VCI(x) (((x)>>16)&0x3FF)
  1474. #define SERVICE_GET_END(x) ((x)&0x1FFF)
  1475. /* Handle one thing from the service list - returns true if it marked a
  1476. * VCC ready for xmit
  1477. */
  1478. static int handle_service(struct lanai_dev *lanai, u32 s)
  1479. {
  1480. vci_t vci = SERVICE_GET_VCI(s);
  1481. struct lanai_vcc *lvcc;
  1482. read_lock(&vcc_sklist_lock);
  1483. lvcc = lanai->vccs[vci];
  1484. if (unlikely(lvcc == NULL)) {
  1485. read_unlock(&vcc_sklist_lock);
  1486. DPRINTK("(itf %d) got service entry 0x%X for nonexistent "
  1487. "vcc %d\n", lanai->number, (unsigned int) s, vci);
  1488. if (s & SERVICE_TX)
  1489. lanai->stats.service_notx++;
  1490. else
  1491. lanai->stats.service_norx++;
  1492. return 0;
  1493. }
  1494. if (s & SERVICE_TX) { /* segmentation interrupt */
  1495. if (unlikely(lvcc->tx.atmvcc == NULL)) {
  1496. read_unlock(&vcc_sklist_lock);
  1497. DPRINTK("(itf %d) got service entry 0x%X for non-TX "
  1498. "vcc %d\n", lanai->number, (unsigned int) s, vci);
  1499. lanai->stats.service_notx++;
  1500. return 0;
  1501. }
  1502. __set_bit(vci, lanai->transmit_ready);
  1503. lvcc->tx.endptr = SERVICE_GET_END(s);
  1504. read_unlock(&vcc_sklist_lock);
  1505. return 1;
  1506. }
  1507. if (unlikely(lvcc->rx.atmvcc == NULL)) {
  1508. read_unlock(&vcc_sklist_lock);
  1509. DPRINTK("(itf %d) got service entry 0x%X for non-RX "
  1510. "vcc %d\n", lanai->number, (unsigned int) s, vci);
  1511. lanai->stats.service_norx++;
  1512. return 0;
  1513. }
  1514. if (unlikely(lvcc->rx.atmvcc->qos.aal != ATM_AAL5)) {
  1515. read_unlock(&vcc_sklist_lock);
  1516. DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
  1517. "vcc %d\n", lanai->number, (unsigned int) s, vci);
  1518. lanai->stats.service_rxnotaal5++;
  1519. atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
  1520. return 0;
  1521. }
  1522. if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
  1523. vcc_rx_aal5(lvcc, SERVICE_GET_END(s));
  1524. read_unlock(&vcc_sklist_lock);
  1525. return 0;
  1526. }
  1527. if (s & SERVICE_TRASH) {
  1528. int bytes;
  1529. read_unlock(&vcc_sklist_lock);
  1530. DPRINTK("got trashed rx pdu on vci %d\n", vci);
  1531. atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
  1532. lvcc->stats.x.aal5.service_trash++;
  1533. bytes = (SERVICE_GET_END(s) * 16) -
  1534. (((unsigned long) lvcc->rx.buf.ptr) -
  1535. ((unsigned long) lvcc->rx.buf.start)) + 47;
  1536. if (bytes < 0)
  1537. bytes += lanai_buf_size(&lvcc->rx.buf);
  1538. lanai->stats.ovfl_trash += (bytes / 48);
  1539. return 0;
  1540. }
  1541. if (s & SERVICE_STREAM) {
  1542. read_unlock(&vcc_sklist_lock);
  1543. atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
  1544. lvcc->stats.x.aal5.service_stream++;
  1545. printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
  1546. "PDU on VCI %d!\n", lanai->number, vci);
  1547. lanai_reset(lanai);
  1548. return 0;
  1549. }
  1550. DPRINTK("got rx crc error on vci %d\n", vci);
  1551. atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
  1552. lvcc->stats.x.aal5.service_rxcrc++;
  1553. lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
  1554. cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
  1555. read_unlock(&vcc_sklist_lock);
  1556. return 0;
  1557. }
  1558. /* Try transmitting on all VCIs that we marked ready to serve */
  1559. static void iter_transmit(struct lanai_dev *lanai, vci_t vci)
  1560. {
  1561. struct lanai_vcc *lvcc = lanai->vccs[vci];
  1562. if (vcc_is_backlogged(lvcc))
  1563. lvcc->tx.unqueue(lanai, lvcc, lvcc->tx.endptr);
  1564. }
  1565. /* Run service queue -- called from interrupt context or with
  1566. * interrupts otherwise disabled and with the lanai->servicelock
  1567. * lock held
  1568. */
  1569. static void run_service(struct lanai_dev *lanai)
  1570. {
  1571. int ntx = 0;
  1572. u32 wreg = reg_read(lanai, ServWrite_Reg);
  1573. const u32 *end = lanai->service.start + wreg;
  1574. while (lanai->service.ptr != end) {
  1575. ntx += handle_service(lanai,
  1576. le32_to_cpup(lanai->service.ptr++));
  1577. if (lanai->service.ptr >= lanai->service.end)
  1578. lanai->service.ptr = lanai->service.start;
  1579. }
  1580. reg_write(lanai, wreg, ServRead_Reg);
  1581. if (ntx != 0) {
  1582. read_lock(&vcc_sklist_lock);
  1583. vci_bitfield_iterate(lanai, lanai->transmit_ready,
  1584. iter_transmit);
  1585. bitmap_zero(lanai->transmit_ready, NUM_VCI);
  1586. read_unlock(&vcc_sklist_lock);
  1587. }
  1588. }
  1589. /* -------------------- GATHER STATISTICS: */
  1590. static void get_statistics(struct lanai_dev *lanai)
  1591. {
  1592. u32 statreg = reg_read(lanai, Statistics_Reg);
  1593. lanai->stats.atm_ovfl += STATS_GET_FIFO_OVFL(statreg);
  1594. lanai->stats.hec_err += STATS_GET_HEC_ERR(statreg);
  1595. lanai->stats.vci_trash += STATS_GET_BAD_VCI(statreg);
  1596. lanai->stats.ovfl_trash += STATS_GET_BUF_OVFL(statreg);
  1597. }
  1598. /* -------------------- POLLING TIMER: */
  1599. #ifndef DEBUG_RW
  1600. /* Try to undequeue 1 backlogged vcc */
  1601. static void iter_dequeue(struct lanai_dev *lanai, vci_t vci)
  1602. {
  1603. struct lanai_vcc *lvcc = lanai->vccs[vci];
  1604. int endptr;
  1605. if (lvcc == NULL || lvcc->tx.atmvcc == NULL ||
  1606. !vcc_is_backlogged(lvcc)) {
  1607. __clear_bit(vci, lanai->backlog_vccs);
  1608. return;
  1609. }
  1610. endptr = TXREADPTR_GET_PTR(cardvcc_read(lvcc, vcc_txreadptr));
  1611. lvcc->tx.unqueue(lanai, lvcc, endptr);
  1612. }
  1613. #endif /* !DEBUG_RW */
  1614. static void lanai_timed_poll(struct timer_list *t)
  1615. {
  1616. struct lanai_dev *lanai = from_timer(lanai, t, timer);
  1617. #ifndef DEBUG_RW
  1618. unsigned long flags;
  1619. #ifdef USE_POWERDOWN
  1620. if (lanai->conf1 & CONFIG1_POWERDOWN)
  1621. return;
  1622. #endif /* USE_POWERDOWN */
  1623. local_irq_save(flags);
  1624. /* If we can grab the spinlock, check if any services need to be run */
  1625. if (spin_trylock(&lanai->servicelock)) {
  1626. run_service(lanai);
  1627. spin_unlock(&lanai->servicelock);
  1628. }
  1629. /* ...and see if any backlogged VCs can make progress */
  1630. /* unfortunately linux has no read_trylock() currently */
  1631. read_lock(&vcc_sklist_lock);
  1632. vci_bitfield_iterate(lanai, lanai->backlog_vccs, iter_dequeue);
  1633. read_unlock(&vcc_sklist_lock);
  1634. local_irq_restore(flags);
  1635. get_statistics(lanai);
  1636. #endif /* !DEBUG_RW */
  1637. mod_timer(&lanai->timer, jiffies + LANAI_POLL_PERIOD);
  1638. }
  1639. static inline void lanai_timed_poll_start(struct lanai_dev *lanai)
  1640. {
  1641. timer_setup(&lanai->timer, lanai_timed_poll, 0);
  1642. lanai->timer.expires = jiffies + LANAI_POLL_PERIOD;
  1643. add_timer(&lanai->timer);
  1644. }
  1645. static inline void lanai_timed_poll_stop(struct lanai_dev *lanai)
  1646. {
  1647. del_timer_sync(&lanai->timer);
  1648. }
  1649. /* -------------------- INTERRUPT SERVICE: */
  1650. static inline void lanai_int_1(struct lanai_dev *lanai, u32 reason)
  1651. {
  1652. u32 ack = 0;
  1653. if (reason & INT_SERVICE) {
  1654. ack = INT_SERVICE;
  1655. spin_lock(&lanai->servicelock);
  1656. run_service(lanai);
  1657. spin_unlock(&lanai->servicelock);
  1658. }
  1659. if (reason & (INT_AAL0_STR | INT_AAL0)) {
  1660. ack |= reason & (INT_AAL0_STR | INT_AAL0);
  1661. vcc_rx_aal0(lanai);
  1662. }
  1663. /* The rest of the interrupts are pretty rare */
  1664. if (ack == reason)
  1665. goto done;
  1666. if (reason & INT_STATS) {
  1667. reason &= ~INT_STATS; /* No need to ack */
  1668. get_statistics(lanai);
  1669. }
  1670. if (reason & INT_STATUS) {
  1671. ack |= reason & INT_STATUS;
  1672. lanai_check_status(lanai);
  1673. }
  1674. if (unlikely(reason & INT_DMASHUT)) {
  1675. printk(KERN_ERR DEV_LABEL "(itf %d): driver error - DMA "
  1676. "shutdown, reason=0x%08X, address=0x%08X\n",
  1677. lanai->number, (unsigned int) (reason & INT_DMASHUT),
  1678. (unsigned int) reg_read(lanai, DMA_Addr_Reg));
  1679. if (reason & INT_TABORTBM) {
  1680. lanai_reset(lanai);
  1681. return;
  1682. }
  1683. ack |= (reason & INT_DMASHUT);
  1684. printk(KERN_ERR DEV_LABEL "(itf %d): re-enabling DMA\n",
  1685. lanai->number);
  1686. conf1_write(lanai);
  1687. lanai->stats.dma_reenable++;
  1688. pcistatus_check(lanai, 0);
  1689. }
  1690. if (unlikely(reason & INT_TABORTSENT)) {
  1691. ack |= (reason & INT_TABORTSENT);
  1692. printk(KERN_ERR DEV_LABEL "(itf %d): sent PCI target abort\n",
  1693. lanai->number);
  1694. pcistatus_check(lanai, 0);
  1695. }
  1696. if (unlikely(reason & INT_SEGSHUT)) {
  1697. printk(KERN_ERR DEV_LABEL "(itf %d): driver error - "
  1698. "segmentation shutdown, reason=0x%08X\n", lanai->number,
  1699. (unsigned int) (reason & INT_SEGSHUT));
  1700. lanai_reset(lanai);
  1701. return;
  1702. }
  1703. if (unlikely(reason & (INT_PING | INT_WAKE))) {
  1704. printk(KERN_ERR DEV_LABEL "(itf %d): driver error - "
  1705. "unexpected interrupt 0x%08X, resetting\n",
  1706. lanai->number,
  1707. (unsigned int) (reason & (INT_PING | INT_WAKE)));
  1708. lanai_reset(lanai);
  1709. return;
  1710. }
  1711. #ifdef DEBUG
  1712. if (unlikely(ack != reason)) {
  1713. DPRINTK("unacked ints: 0x%08X\n",
  1714. (unsigned int) (reason & ~ack));
  1715. ack = reason;
  1716. }
  1717. #endif
  1718. done:
  1719. if (ack != 0)
  1720. reg_write(lanai, ack, IntAck_Reg);
  1721. }
  1722. static irqreturn_t lanai_int(int irq, void *devid)
  1723. {
  1724. struct lanai_dev *lanai = devid;
  1725. u32 reason;
  1726. #ifdef USE_POWERDOWN
  1727. /*
  1728. * If we're powered down we shouldn't be generating any interrupts -
  1729. * so assume that this is a shared interrupt line and it's for someone
  1730. * else
  1731. */
  1732. if (unlikely(lanai->conf1 & CONFIG1_POWERDOWN))
  1733. return IRQ_NONE;
  1734. #endif
  1735. reason = intr_pending(lanai);
  1736. if (reason == 0)
  1737. return IRQ_NONE; /* Must be for someone else */
  1738. do {
  1739. if (unlikely(reason == 0xFFFFFFFF))
  1740. break; /* Maybe we've been unplugged? */
  1741. lanai_int_1(lanai, reason);
  1742. reason = intr_pending(lanai);
  1743. } while (reason != 0);
  1744. return IRQ_HANDLED;
  1745. }
  1746. /* TODO - it would be nice if we could use the "delayed interrupt" system
  1747. * to some advantage
  1748. */
  1749. /* -------------------- CHECK BOARD ID/REV: */
  1750. /*
  1751. * The board id and revision are stored both in the reset register and
  1752. * in the PCI configuration space - the documentation says to check
  1753. * each of them. If revp!=NULL we store the revision there
  1754. */
  1755. static int check_board_id_and_rev(const char *name, u32 val, int *revp)
  1756. {
  1757. DPRINTK("%s says board_id=%d, board_rev=%d\n", name,
  1758. (int) RESET_GET_BOARD_ID(val),
  1759. (int) RESET_GET_BOARD_REV(val));
  1760. if (RESET_GET_BOARD_ID(val) != BOARD_ID_LANAI256) {
  1761. printk(KERN_ERR DEV_LABEL ": Found %s board-id %d -- not a "
  1762. "Lanai 25.6\n", name, (int) RESET_GET_BOARD_ID(val));
  1763. return -ENODEV;
  1764. }
  1765. if (revp != NULL)
  1766. *revp = RESET_GET_BOARD_REV(val);
  1767. return 0;
  1768. }
  1769. /* -------------------- PCI INITIALIZATION/SHUTDOWN: */
  1770. static int lanai_pci_start(struct lanai_dev *lanai)
  1771. {
  1772. struct pci_dev *pci = lanai->pci;
  1773. int result;
  1774. if (pci_enable_device(pci) != 0) {
  1775. printk(KERN_ERR DEV_LABEL "(itf %d): can't enable "
  1776. "PCI device", lanai->number);
  1777. return -ENXIO;
  1778. }
  1779. pci_set_master(pci);
  1780. if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32)) != 0) {
  1781. printk(KERN_WARNING DEV_LABEL
  1782. "(itf %d): No suitable DMA available.\n", lanai->number);
  1783. return -EBUSY;
  1784. }
  1785. result = check_board_id_and_rev("PCI", pci->subsystem_device, NULL);
  1786. if (result != 0)
  1787. return result;
  1788. /* Set latency timer to zero as per lanai docs */
  1789. result = pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0);
  1790. if (result != PCIBIOS_SUCCESSFUL) {
  1791. printk(KERN_ERR DEV_LABEL "(itf %d): can't write "
  1792. "PCI_LATENCY_TIMER: %d\n", lanai->number, result);
  1793. return -EINVAL;
  1794. }
  1795. pcistatus_check(lanai, 1);
  1796. pcistatus_check(lanai, 0);
  1797. return 0;
  1798. }
  1799. /* -------------------- VPI/VCI ALLOCATION: */
  1800. /*
  1801. * We _can_ use VCI==0 for normal traffic, but only for UBR (or we'll
  1802. * get a CBRZERO interrupt), and we can use it only if no one is receiving
  1803. * AAL0 traffic (since they will use the same queue) - according to the
  1804. * docs we shouldn't even use it for AAL0 traffic
  1805. */
  1806. static inline int vci0_is_ok(struct lanai_dev *lanai,
  1807. const struct atm_qos *qos)
  1808. {
  1809. if (qos->txtp.traffic_class == ATM_CBR || qos->aal == ATM_AAL0)
  1810. return 0;
  1811. if (qos->rxtp.traffic_class != ATM_NONE) {
  1812. if (lanai->naal0 != 0)
  1813. return 0;
  1814. lanai->conf2 |= CONFIG2_VCI0_NORMAL;
  1815. conf2_write_if_powerup(lanai);
  1816. }
  1817. return 1;
  1818. }
  1819. /* return true if vci is currently unused, or if requested qos is
  1820. * compatible
  1821. */
  1822. static int vci_is_ok(struct lanai_dev *lanai, vci_t vci,
  1823. const struct atm_vcc *atmvcc)
  1824. {
  1825. const struct atm_qos *qos = &atmvcc->qos;
  1826. const struct lanai_vcc *lvcc = lanai->vccs[vci];
  1827. if (vci == 0 && !vci0_is_ok(lanai, qos))
  1828. return 0;
  1829. if (unlikely(lvcc != NULL)) {
  1830. if (qos->rxtp.traffic_class != ATM_NONE &&
  1831. lvcc->rx.atmvcc != NULL && lvcc->rx.atmvcc != atmvcc)
  1832. return 0;
  1833. if (qos->txtp.traffic_class != ATM_NONE &&
  1834. lvcc->tx.atmvcc != NULL && lvcc->tx.atmvcc != atmvcc)
  1835. return 0;
  1836. if (qos->txtp.traffic_class == ATM_CBR &&
  1837. lanai->cbrvcc != NULL && lanai->cbrvcc != atmvcc)
  1838. return 0;
  1839. }
  1840. if (qos->aal == ATM_AAL0 && lanai->naal0 == 0 &&
  1841. qos->rxtp.traffic_class != ATM_NONE) {
  1842. const struct lanai_vcc *vci0 = lanai->vccs[0];
  1843. if (vci0 != NULL && vci0->rx.atmvcc != NULL)
  1844. return 0;
  1845. lanai->conf2 &= ~CONFIG2_VCI0_NORMAL;
  1846. conf2_write_if_powerup(lanai);
  1847. }
  1848. return 1;
  1849. }
  1850. static int lanai_normalize_ci(struct lanai_dev *lanai,
  1851. const struct atm_vcc *atmvcc, short *vpip, vci_t *vcip)
  1852. {
  1853. switch (*vpip) {
  1854. case ATM_VPI_ANY:
  1855. *vpip = 0;
  1856. fallthrough;
  1857. case 0:
  1858. break;
  1859. default:
  1860. return -EADDRINUSE;
  1861. }
  1862. switch (*vcip) {
  1863. case ATM_VCI_ANY:
  1864. for (*vcip = ATM_NOT_RSV_VCI; *vcip < lanai->num_vci;
  1865. (*vcip)++)
  1866. if (vci_is_ok(lanai, *vcip, atmvcc))
  1867. return 0;
  1868. return -EADDRINUSE;
  1869. default:
  1870. if (*vcip >= lanai->num_vci || *vcip < 0 ||
  1871. !vci_is_ok(lanai, *vcip, atmvcc))
  1872. return -EADDRINUSE;
  1873. }
  1874. return 0;
  1875. }
  1876. /* -------------------- MANAGE CBR: */
  1877. /*
  1878. * CBR ICG is stored as a fixed-point number with 4 fractional bits.
  1879. * Note that storing a number greater than 2046.0 will result in
  1880. * incorrect shaping
  1881. */
  1882. #define CBRICG_FRAC_BITS (4)
  1883. #define CBRICG_MAX (2046 << CBRICG_FRAC_BITS)
  1884. /*
  1885. * ICG is related to PCR with the formula PCR = MAXPCR / (ICG + 1)
  1886. * where MAXPCR is (according to the docs) 25600000/(54*8),
  1887. * which is equal to (3125<<9)/27.
  1888. *
  1889. * Solving for ICG, we get:
  1890. * ICG = MAXPCR/PCR - 1
  1891. * ICG = (3125<<9)/(27*PCR) - 1
  1892. * ICG = ((3125<<9) - (27*PCR)) / (27*PCR)
  1893. *
  1894. * The end result is supposed to be a fixed-point number with FRAC_BITS
  1895. * bits of a fractional part, so we keep everything in the numerator
  1896. * shifted by that much as we compute
  1897. *
  1898. */
  1899. static int pcr_to_cbricg(const struct atm_qos *qos)
  1900. {
  1901. int rounddown = 0; /* 1 = Round PCR down, i.e. round ICG _up_ */
  1902. int x, icg, pcr = atm_pcr_goal(&qos->txtp);
  1903. if (pcr == 0) /* Use maximum bandwidth */
  1904. return 0;
  1905. if (pcr < 0) {
  1906. rounddown = 1;
  1907. pcr = -pcr;
  1908. }
  1909. x = pcr * 27;
  1910. icg = (3125 << (9 + CBRICG_FRAC_BITS)) - (x << CBRICG_FRAC_BITS);
  1911. if (rounddown)
  1912. icg += x - 1;
  1913. icg /= x;
  1914. if (icg > CBRICG_MAX)
  1915. icg = CBRICG_MAX;
  1916. DPRINTK("pcr_to_cbricg: pcr=%d rounddown=%c icg=%d\n",
  1917. pcr, rounddown ? 'Y' : 'N', icg);
  1918. return icg;
  1919. }
  1920. static inline void lanai_cbr_setup(struct lanai_dev *lanai)
  1921. {
  1922. reg_write(lanai, pcr_to_cbricg(&lanai->cbrvcc->qos), CBR_ICG_Reg);
  1923. reg_write(lanai, lanai->cbrvcc->vci, CBR_PTR_Reg);
  1924. lanai->conf2 |= CONFIG2_CBR_ENABLE;
  1925. conf2_write(lanai);
  1926. }
  1927. static inline void lanai_cbr_shutdown(struct lanai_dev *lanai)
  1928. {
  1929. lanai->conf2 &= ~CONFIG2_CBR_ENABLE;
  1930. conf2_write(lanai);
  1931. }
  1932. /* -------------------- OPERATIONS: */
  1933. /* setup a newly detected device */
  1934. static int lanai_dev_open(struct atm_dev *atmdev)
  1935. {
  1936. struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
  1937. unsigned long raw_base;
  1938. int result;
  1939. DPRINTK("In lanai_dev_open()\n");
  1940. /* Basic device fields */
  1941. lanai->number = atmdev->number;
  1942. lanai->num_vci = NUM_VCI;
  1943. bitmap_zero(lanai->backlog_vccs, NUM_VCI);
  1944. bitmap_zero(lanai->transmit_ready, NUM_VCI);
  1945. lanai->naal0 = 0;
  1946. #ifdef USE_POWERDOWN
  1947. lanai->nbound = 0;
  1948. #endif
  1949. lanai->cbrvcc = NULL;
  1950. memset(&lanai->stats, 0, sizeof lanai->stats);
  1951. spin_lock_init(&lanai->endtxlock);
  1952. spin_lock_init(&lanai->servicelock);
  1953. atmdev->ci_range.vpi_bits = 0;
  1954. atmdev->ci_range.vci_bits = 0;
  1955. while (1 << atmdev->ci_range.vci_bits < lanai->num_vci)
  1956. atmdev->ci_range.vci_bits++;
  1957. atmdev->link_rate = ATM_25_PCR;
  1958. /* 3.2: PCI initialization */
  1959. if ((result = lanai_pci_start(lanai)) != 0)
  1960. goto error;
  1961. raw_base = lanai->pci->resource[0].start;
  1962. lanai->base = (bus_addr_t) ioremap(raw_base, LANAI_MAPPING_SIZE);
  1963. if (lanai->base == NULL) {
  1964. printk(KERN_ERR DEV_LABEL ": couldn't remap I/O space\n");
  1965. result = -ENOMEM;
  1966. goto error_pci;
  1967. }
  1968. /* 3.3: Reset lanai and PHY */
  1969. reset_board(lanai);
  1970. lanai->conf1 = reg_read(lanai, Config1_Reg);
  1971. lanai->conf1 &= ~(CONFIG1_GPOUT1 | CONFIG1_POWERDOWN |
  1972. CONFIG1_MASK_LEDMODE);
  1973. lanai->conf1 |= CONFIG1_SET_LEDMODE(LEDMODE_NOT_SOOL);
  1974. reg_write(lanai, lanai->conf1 | CONFIG1_GPOUT1, Config1_Reg);
  1975. udelay(1000);
  1976. conf1_write(lanai);
  1977. /*
  1978. * 3.4: Turn on endian mode for big-endian hardware
  1979. * We don't actually want to do this - the actual bit fields
  1980. * in the endian register are not documented anywhere.
  1981. * Instead we do the bit-flipping ourselves on big-endian
  1982. * hardware.
  1983. *
  1984. * 3.5: get the board ID/rev by reading the reset register
  1985. */
  1986. result = check_board_id_and_rev("register",
  1987. reg_read(lanai, Reset_Reg), &lanai->board_rev);
  1988. if (result != 0)
  1989. goto error_unmap;
  1990. /* 3.6: read EEPROM */
  1991. if ((result = eeprom_read(lanai)) != 0)
  1992. goto error_unmap;
  1993. if ((result = eeprom_validate(lanai)) != 0)
  1994. goto error_unmap;
  1995. /* 3.7: re-reset PHY, do loopback tests, setup PHY */
  1996. reg_write(lanai, lanai->conf1 | CONFIG1_GPOUT1, Config1_Reg);
  1997. udelay(1000);
  1998. conf1_write(lanai);
  1999. /* TODO - loopback tests */
  2000. lanai->conf1 |= (CONFIG1_GPOUT2 | CONFIG1_GPOUT3 | CONFIG1_DMA_ENABLE);
  2001. conf1_write(lanai);
  2002. /* 3.8/3.9: test and initialize card SRAM */
  2003. if ((result = sram_test_and_clear(lanai)) != 0)
  2004. goto error_unmap;
  2005. /* 3.10: initialize lanai registers */
  2006. lanai->conf1 |= CONFIG1_DMA_ENABLE;
  2007. conf1_write(lanai);
  2008. if ((result = service_buffer_allocate(lanai)) != 0)
  2009. goto error_unmap;
  2010. if ((result = vcc_table_allocate(lanai)) != 0)
  2011. goto error_service;
  2012. lanai->conf2 = (lanai->num_vci >= 512 ? CONFIG2_HOWMANY : 0) |
  2013. CONFIG2_HEC_DROP | /* ??? */ CONFIG2_PTI7_MODE;
  2014. conf2_write(lanai);
  2015. reg_write(lanai, TX_FIFO_DEPTH, TxDepth_Reg);
  2016. reg_write(lanai, 0, CBR_ICG_Reg); /* CBR defaults to no limit */
  2017. if ((result = request_irq(lanai->pci->irq, lanai_int, IRQF_SHARED,
  2018. DEV_LABEL, lanai)) != 0) {
  2019. printk(KERN_ERR DEV_LABEL ": can't allocate interrupt\n");
  2020. goto error_vcctable;
  2021. }
  2022. mb(); /* Make sure that all that made it */
  2023. intr_enable(lanai, INT_ALL & ~(INT_PING | INT_WAKE));
  2024. /* 3.11: initialize loop mode (i.e. turn looping off) */
  2025. lanai->conf1 = (lanai->conf1 & ~CONFIG1_MASK_LOOPMODE) |
  2026. CONFIG1_SET_LOOPMODE(LOOPMODE_NORMAL) |
  2027. CONFIG1_GPOUT2 | CONFIG1_GPOUT3;
  2028. conf1_write(lanai);
  2029. lanai->status = reg_read(lanai, Status_Reg);
  2030. /* We're now done initializing this card */
  2031. #ifdef USE_POWERDOWN
  2032. lanai->conf1 |= CONFIG1_POWERDOWN;
  2033. conf1_write(lanai);
  2034. #endif
  2035. memcpy(atmdev->esi, eeprom_mac(lanai), ESI_LEN);
  2036. lanai_timed_poll_start(lanai);
  2037. printk(KERN_NOTICE DEV_LABEL "(itf %d): rev.%d, base=%p, irq=%u "
  2038. "(%pMF)\n", lanai->number, (int) lanai->pci->revision,
  2039. lanai->base, lanai->pci->irq, atmdev->esi);
  2040. printk(KERN_NOTICE DEV_LABEL "(itf %d): LANAI%s, serialno=%u(0x%X), "
  2041. "board_rev=%d\n", lanai->number,
  2042. lanai->type==lanai2 ? "2" : "HB", (unsigned int) lanai->serialno,
  2043. (unsigned int) lanai->serialno, lanai->board_rev);
  2044. return 0;
  2045. error_vcctable:
  2046. vcc_table_deallocate(lanai);
  2047. error_service:
  2048. service_buffer_deallocate(lanai);
  2049. error_unmap:
  2050. reset_board(lanai);
  2051. #ifdef USE_POWERDOWN
  2052. lanai->conf1 = reg_read(lanai, Config1_Reg) | CONFIG1_POWERDOWN;
  2053. conf1_write(lanai);
  2054. #endif
  2055. iounmap(lanai->base);
  2056. lanai->base = NULL;
  2057. error_pci:
  2058. pci_disable_device(lanai->pci);
  2059. error:
  2060. return result;
  2061. }
  2062. /* called when device is being shutdown, and all vcc's are gone - higher
  2063. * levels will deallocate the atm device for us
  2064. */
  2065. static void lanai_dev_close(struct atm_dev *atmdev)
  2066. {
  2067. struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
  2068. if (lanai->base==NULL)
  2069. return;
  2070. printk(KERN_INFO DEV_LABEL "(itf %d): shutting down interface\n",
  2071. lanai->number);
  2072. lanai_timed_poll_stop(lanai);
  2073. #ifdef USE_POWERDOWN
  2074. lanai->conf1 = reg_read(lanai, Config1_Reg) & ~CONFIG1_POWERDOWN;
  2075. conf1_write(lanai);
  2076. #endif
  2077. intr_disable(lanai, INT_ALL);
  2078. free_irq(lanai->pci->irq, lanai);
  2079. reset_board(lanai);
  2080. #ifdef USE_POWERDOWN
  2081. lanai->conf1 |= CONFIG1_POWERDOWN;
  2082. conf1_write(lanai);
  2083. #endif
  2084. pci_disable_device(lanai->pci);
  2085. vcc_table_deallocate(lanai);
  2086. service_buffer_deallocate(lanai);
  2087. iounmap(lanai->base);
  2088. kfree(lanai);
  2089. }
  2090. /* close a vcc */
  2091. static void lanai_close(struct atm_vcc *atmvcc)
  2092. {
  2093. struct lanai_vcc *lvcc = (struct lanai_vcc *) atmvcc->dev_data;
  2094. struct lanai_dev *lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
  2095. if (lvcc == NULL)
  2096. return;
  2097. clear_bit(ATM_VF_READY, &atmvcc->flags);
  2098. clear_bit(ATM_VF_PARTIAL, &atmvcc->flags);
  2099. if (lvcc->rx.atmvcc == atmvcc) {
  2100. lanai_shutdown_rx_vci(lvcc);
  2101. if (atmvcc->qos.aal == ATM_AAL0) {
  2102. if (--lanai->naal0 <= 0)
  2103. aal0_buffer_free(lanai);
  2104. } else
  2105. lanai_buf_deallocate(&lvcc->rx.buf, lanai->pci);
  2106. lvcc->rx.atmvcc = NULL;
  2107. }
  2108. if (lvcc->tx.atmvcc == atmvcc) {
  2109. if (atmvcc == lanai->cbrvcc) {
  2110. if (lvcc->vbase != NULL)
  2111. lanai_cbr_shutdown(lanai);
  2112. lanai->cbrvcc = NULL;
  2113. }
  2114. lanai_shutdown_tx_vci(lanai, lvcc);
  2115. lanai_buf_deallocate(&lvcc->tx.buf, lanai->pci);
  2116. lvcc->tx.atmvcc = NULL;
  2117. }
  2118. if (--lvcc->nref == 0) {
  2119. host_vcc_unbind(lanai, lvcc);
  2120. kfree(lvcc);
  2121. }
  2122. atmvcc->dev_data = NULL;
  2123. clear_bit(ATM_VF_ADDR, &atmvcc->flags);
  2124. }
  2125. /* open a vcc on the card to vpi/vci */
  2126. static int lanai_open(struct atm_vcc *atmvcc)
  2127. {
  2128. struct lanai_dev *lanai;
  2129. struct lanai_vcc *lvcc;
  2130. int result = 0;
  2131. int vci = atmvcc->vci;
  2132. short vpi = atmvcc->vpi;
  2133. /* we don't support partial open - it's not really useful anyway */
  2134. if ((test_bit(ATM_VF_PARTIAL, &atmvcc->flags)) ||
  2135. (vpi == ATM_VPI_UNSPEC) || (vci == ATM_VCI_UNSPEC))
  2136. return -EINVAL;
  2137. lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
  2138. result = lanai_normalize_ci(lanai, atmvcc, &vpi, &vci);
  2139. if (unlikely(result != 0))
  2140. goto out;
  2141. set_bit(ATM_VF_ADDR, &atmvcc->flags);
  2142. if (atmvcc->qos.aal != ATM_AAL0 && atmvcc->qos.aal != ATM_AAL5)
  2143. return -EINVAL;
  2144. DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n", lanai->number,
  2145. (int) vpi, vci);
  2146. lvcc = lanai->vccs[vci];
  2147. if (lvcc == NULL) {
  2148. lvcc = new_lanai_vcc();
  2149. if (unlikely(lvcc == NULL))
  2150. return -ENOMEM;
  2151. atmvcc->dev_data = lvcc;
  2152. }
  2153. lvcc->nref++;
  2154. if (atmvcc->qos.rxtp.traffic_class != ATM_NONE) {
  2155. APRINTK(lvcc->rx.atmvcc == NULL, "rx.atmvcc!=NULL, vci=%d\n",
  2156. vci);
  2157. if (atmvcc->qos.aal == ATM_AAL0) {
  2158. if (lanai->naal0 == 0)
  2159. result = aal0_buffer_allocate(lanai);
  2160. } else
  2161. result = lanai_setup_rx_vci_aal5(
  2162. lanai, lvcc, &atmvcc->qos);
  2163. if (unlikely(result != 0))
  2164. goto out_free;
  2165. lvcc->rx.atmvcc = atmvcc;
  2166. lvcc->stats.rx_nomem = 0;
  2167. lvcc->stats.x.aal5.rx_badlen = 0;
  2168. lvcc->stats.x.aal5.service_trash = 0;
  2169. lvcc->stats.x.aal5.service_stream = 0;
  2170. lvcc->stats.x.aal5.service_rxcrc = 0;
  2171. if (atmvcc->qos.aal == ATM_AAL0)
  2172. lanai->naal0++;
  2173. }
  2174. if (atmvcc->qos.txtp.traffic_class != ATM_NONE) {
  2175. APRINTK(lvcc->tx.atmvcc == NULL, "tx.atmvcc!=NULL, vci=%d\n",
  2176. vci);
  2177. result = lanai_setup_tx_vci(lanai, lvcc, &atmvcc->qos);
  2178. if (unlikely(result != 0))
  2179. goto out_free;
  2180. lvcc->tx.atmvcc = atmvcc;
  2181. if (atmvcc->qos.txtp.traffic_class == ATM_CBR) {
  2182. APRINTK(lanai->cbrvcc == NULL,
  2183. "cbrvcc!=NULL, vci=%d\n", vci);
  2184. lanai->cbrvcc = atmvcc;
  2185. }
  2186. }
  2187. host_vcc_bind(lanai, lvcc, vci);
  2188. /*
  2189. * Make sure everything made it to RAM before we tell the card about
  2190. * the VCC
  2191. */
  2192. wmb();
  2193. if (atmvcc == lvcc->rx.atmvcc)
  2194. host_vcc_start_rx(lvcc);
  2195. if (atmvcc == lvcc->tx.atmvcc) {
  2196. host_vcc_start_tx(lvcc);
  2197. if (lanai->cbrvcc == atmvcc)
  2198. lanai_cbr_setup(lanai);
  2199. }
  2200. set_bit(ATM_VF_READY, &atmvcc->flags);
  2201. return 0;
  2202. out_free:
  2203. lanai_close(atmvcc);
  2204. out:
  2205. return result;
  2206. }
  2207. static int lanai_send(struct atm_vcc *atmvcc, struct sk_buff *skb)
  2208. {
  2209. struct lanai_vcc *lvcc = (struct lanai_vcc *) atmvcc->dev_data;
  2210. struct lanai_dev *lanai = (struct lanai_dev *) atmvcc->dev->dev_data;
  2211. unsigned long flags;
  2212. if (unlikely(lvcc == NULL || lvcc->vbase == NULL ||
  2213. lvcc->tx.atmvcc != atmvcc))
  2214. goto einval;
  2215. #ifdef DEBUG
  2216. if (unlikely(skb == NULL)) {
  2217. DPRINTK("lanai_send: skb==NULL for vci=%d\n", atmvcc->vci);
  2218. goto einval;
  2219. }
  2220. if (unlikely(lanai == NULL)) {
  2221. DPRINTK("lanai_send: lanai==NULL for vci=%d\n", atmvcc->vci);
  2222. goto einval;
  2223. }
  2224. #endif
  2225. ATM_SKB(skb)->vcc = atmvcc;
  2226. switch (atmvcc->qos.aal) {
  2227. case ATM_AAL5:
  2228. read_lock_irqsave(&vcc_sklist_lock, flags);
  2229. vcc_tx_aal5(lanai, lvcc, skb);
  2230. read_unlock_irqrestore(&vcc_sklist_lock, flags);
  2231. return 0;
  2232. case ATM_AAL0:
  2233. if (unlikely(skb->len != ATM_CELL_SIZE-1))
  2234. goto einval;
  2235. /* NOTE - this next line is technically invalid - we haven't unshared skb */
  2236. cpu_to_be32s((u32 *) skb->data);
  2237. read_lock_irqsave(&vcc_sklist_lock, flags);
  2238. vcc_tx_aal0(lanai, lvcc, skb);
  2239. read_unlock_irqrestore(&vcc_sklist_lock, flags);
  2240. return 0;
  2241. }
  2242. DPRINTK("lanai_send: bad aal=%d on vci=%d\n", (int) atmvcc->qos.aal,
  2243. atmvcc->vci);
  2244. einval:
  2245. lanai_free_skb(atmvcc, skb);
  2246. return -EINVAL;
  2247. }
  2248. static int lanai_change_qos(struct atm_vcc *atmvcc,
  2249. /*const*/ struct atm_qos *qos, int flags)
  2250. {
  2251. return -EBUSY; /* TODO: need to write this */
  2252. }
  2253. #ifndef CONFIG_PROC_FS
  2254. #define lanai_proc_read NULL
  2255. #else
  2256. static int lanai_proc_read(struct atm_dev *atmdev, loff_t *pos, char *page)
  2257. {
  2258. struct lanai_dev *lanai = (struct lanai_dev *) atmdev->dev_data;
  2259. loff_t left = *pos;
  2260. struct lanai_vcc *lvcc;
  2261. if (left-- == 0)
  2262. return sprintf(page, DEV_LABEL "(itf %d): chip=LANAI%s, "
  2263. "serial=%u, magic=0x%08X, num_vci=%d\n",
  2264. atmdev->number, lanai->type==lanai2 ? "2" : "HB",
  2265. (unsigned int) lanai->serialno,
  2266. (unsigned int) lanai->magicno, lanai->num_vci);
  2267. if (left-- == 0)
  2268. return sprintf(page, "revision: board=%d, pci_if=%d\n",
  2269. lanai->board_rev, (int) lanai->pci->revision);
  2270. if (left-- == 0)
  2271. return sprintf(page, "EEPROM ESI: %pM\n",
  2272. &lanai->eeprom[EEPROM_MAC]);
  2273. if (left-- == 0)
  2274. return sprintf(page, "status: SOOL=%d, LOCD=%d, LED=%d, "
  2275. "GPIN=%d\n", (lanai->status & STATUS_SOOL) ? 1 : 0,
  2276. (lanai->status & STATUS_LOCD) ? 1 : 0,
  2277. (lanai->status & STATUS_LED) ? 1 : 0,
  2278. (lanai->status & STATUS_GPIN) ? 1 : 0);
  2279. if (left-- == 0)
  2280. return sprintf(page, "global buffer sizes: service=%zu, "
  2281. "aal0_rx=%zu\n", lanai_buf_size(&lanai->service),
  2282. lanai->naal0 ? lanai_buf_size(&lanai->aal0buf) : 0);
  2283. if (left-- == 0) {
  2284. get_statistics(lanai);
  2285. return sprintf(page, "cells in error: overflow=%u, "
  2286. "closed_vci=%u, bad_HEC=%u, rx_fifo=%u\n",
  2287. lanai->stats.ovfl_trash, lanai->stats.vci_trash,
  2288. lanai->stats.hec_err, lanai->stats.atm_ovfl);
  2289. }
  2290. if (left-- == 0)
  2291. return sprintf(page, "PCI errors: parity_detect=%u, "
  2292. "master_abort=%u, master_target_abort=%u,\n",
  2293. lanai->stats.pcierr_parity_detect,
  2294. lanai->stats.pcierr_serr_set,
  2295. lanai->stats.pcierr_m_target_abort);
  2296. if (left-- == 0)
  2297. return sprintf(page, " slave_target_abort=%u, "
  2298. "master_parity=%u\n", lanai->stats.pcierr_s_target_abort,
  2299. lanai->stats.pcierr_master_parity);
  2300. if (left-- == 0)
  2301. return sprintf(page, " no_tx=%u, "
  2302. "no_rx=%u, bad_rx_aal=%u\n", lanai->stats.service_norx,
  2303. lanai->stats.service_notx,
  2304. lanai->stats.service_rxnotaal5);
  2305. if (left-- == 0)
  2306. return sprintf(page, "resets: dma=%u, card=%u\n",
  2307. lanai->stats.dma_reenable, lanai->stats.card_reset);
  2308. /* At this point, "left" should be the VCI we're looking for */
  2309. read_lock(&vcc_sklist_lock);
  2310. for (; ; left++) {
  2311. if (left >= NUM_VCI) {
  2312. left = 0;
  2313. goto out;
  2314. }
  2315. if ((lvcc = lanai->vccs[left]) != NULL)
  2316. break;
  2317. (*pos)++;
  2318. }
  2319. /* Note that we re-use "left" here since we're done with it */
  2320. left = sprintf(page, "VCI %4d: nref=%d, rx_nomem=%u", (vci_t) left,
  2321. lvcc->nref, lvcc->stats.rx_nomem);
  2322. if (lvcc->rx.atmvcc != NULL) {
  2323. left += sprintf(&page[left], ",\n rx_AAL=%d",
  2324. lvcc->rx.atmvcc->qos.aal == ATM_AAL5 ? 5 : 0);
  2325. if (lvcc->rx.atmvcc->qos.aal == ATM_AAL5)
  2326. left += sprintf(&page[left], ", rx_buf_size=%zu, "
  2327. "rx_bad_len=%u,\n rx_service_trash=%u, "
  2328. "rx_service_stream=%u, rx_bad_crc=%u",
  2329. lanai_buf_size(&lvcc->rx.buf),
  2330. lvcc->stats.x.aal5.rx_badlen,
  2331. lvcc->stats.x.aal5.service_trash,
  2332. lvcc->stats.x.aal5.service_stream,
  2333. lvcc->stats.x.aal5.service_rxcrc);
  2334. }
  2335. if (lvcc->tx.atmvcc != NULL)
  2336. left += sprintf(&page[left], ",\n tx_AAL=%d, "
  2337. "tx_buf_size=%zu, tx_qos=%cBR, tx_backlogged=%c",
  2338. lvcc->tx.atmvcc->qos.aal == ATM_AAL5 ? 5 : 0,
  2339. lanai_buf_size(&lvcc->tx.buf),
  2340. lvcc->tx.atmvcc == lanai->cbrvcc ? 'C' : 'U',
  2341. vcc_is_backlogged(lvcc) ? 'Y' : 'N');
  2342. page[left++] = '\n';
  2343. page[left] = '\0';
  2344. out:
  2345. read_unlock(&vcc_sklist_lock);
  2346. return left;
  2347. }
  2348. #endif /* CONFIG_PROC_FS */
  2349. /* -------------------- HOOKS: */
  2350. static const struct atmdev_ops ops = {
  2351. .dev_close = lanai_dev_close,
  2352. .open = lanai_open,
  2353. .close = lanai_close,
  2354. .send = lanai_send,
  2355. .phy_put = NULL,
  2356. .phy_get = NULL,
  2357. .change_qos = lanai_change_qos,
  2358. .proc_read = lanai_proc_read,
  2359. .owner = THIS_MODULE
  2360. };
  2361. /* initialize one probed card */
  2362. static int lanai_init_one(struct pci_dev *pci,
  2363. const struct pci_device_id *ident)
  2364. {
  2365. struct lanai_dev *lanai;
  2366. struct atm_dev *atmdev;
  2367. int result;
  2368. lanai = kzalloc(sizeof(*lanai), GFP_KERNEL);
  2369. if (lanai == NULL) {
  2370. printk(KERN_ERR DEV_LABEL
  2371. ": couldn't allocate dev_data structure!\n");
  2372. return -ENOMEM;
  2373. }
  2374. atmdev = atm_dev_register(DEV_LABEL, &pci->dev, &ops, -1, NULL);
  2375. if (atmdev == NULL) {
  2376. printk(KERN_ERR DEV_LABEL
  2377. ": couldn't register atm device!\n");
  2378. kfree(lanai);
  2379. return -EBUSY;
  2380. }
  2381. atmdev->dev_data = lanai;
  2382. lanai->pci = pci;
  2383. lanai->type = (enum lanai_type) ident->device;
  2384. result = lanai_dev_open(atmdev);
  2385. if (result != 0) {
  2386. DPRINTK("lanai_start() failed, err=%d\n", -result);
  2387. atm_dev_deregister(atmdev);
  2388. kfree(lanai);
  2389. }
  2390. return result;
  2391. }
  2392. static const struct pci_device_id lanai_pci_tbl[] = {
  2393. { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_LANAI2) },
  2394. { PCI_VDEVICE(EF, PCI_DEVICE_ID_EF_ATM_LANAIHB) },
  2395. { 0, } /* terminal entry */
  2396. };
  2397. MODULE_DEVICE_TABLE(pci, lanai_pci_tbl);
  2398. static struct pci_driver lanai_driver = {
  2399. .name = DEV_LABEL,
  2400. .id_table = lanai_pci_tbl,
  2401. .probe = lanai_init_one,
  2402. };
  2403. module_pci_driver(lanai_driver);
  2404. MODULE_AUTHOR("Mitchell Blank Jr <[email protected]>");
  2405. MODULE_DESCRIPTION("Efficient Networks Speedstream 3010 driver");
  2406. MODULE_LICENSE("GPL");