musycc.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982
  1. /*
  2. * $Id: musycc.c,v 2.1 2007/08/15 23:32:17 rickd PMCC4_3_1B $
  3. */
  4. unsigned int max_intcnt = 0;
  5. unsigned int max_bh = 0;
  6. /*-----------------------------------------------------------------------------
  7. * musycc.c -
  8. *
  9. * Copyright (C) 2007 One Stop Systems, Inc.
  10. * Copyright (C) 2003-2006 SBE, Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * For further information, contact via email: support@onestopsystems.com
  23. * One Stop Systems, Inc. Escondido, California U.S.A.
  24. *-----------------------------------------------------------------------------
  25. * RCS info:
  26. * RCS revision: $Revision: 2.1 $
  27. * Last changed on $Date: 2007/08/15 23:32:17 $
  28. * Changed by $Author: rickd $
  29. *-----------------------------------------------------------------------------
  30. * $Log: musycc.c,v $
  31. * Revision 2.1 2007/08/15 23:32:17 rickd
  32. * Use 'if 0' instead of GNU comment delimeter to avoid line wrap induced compiler errors.
  33. *
  34. * Revision 2.0 2007/08/15 22:13:20 rickd
  35. * Update to printf pointer %p usage and correct some UINT to ULONG for
  36. * 64bit comptibility.
  37. *
  38. * Revision 1.7 2006/04/21 00:56:40 rickd
  39. * workqueue files now prefixed with <sbecom> prefix.
  40. *
  41. * Revision 1.6 2005/10/27 18:54:19 rickd
  42. * Clean out old code. Default to HDLC_FCS16, not TRANS.
  43. *
  44. * Revision 1.5 2005/10/17 23:55:28 rickd
  45. * Initial port of NCOMM support patches from original work found
  46. * in pmc_c4t1e1 as updated by NCOMM. Ref: CONFIG_SBE_PMCC4_NCOMM.
  47. *
  48. * Revision 1.4 2005/10/13 20:35:25 rickd
  49. * Cleanup warning for unused <flags> variable.
  50. *
  51. * Revision 1.3 2005/10/13 19:19:22 rickd
  52. * Disable redundant driver removal cleanup code.
  53. *
  54. * Revision 1.2 2005/10/11 18:36:16 rickd
  55. * Clean up warning messages caused by de-implemented some <flags> associated
  56. * with spin_lock() removals.
  57. *
  58. * Revision 1.1 2005/10/05 00:45:28 rickd
  59. * Re-enable xmit on flow-controlled and full channel to fix restart hang.
  60. * Add some temp spin-lock debug code (rld_spin_owner).
  61. *
  62. * Revision 1.0 2005/09/28 00:10:06 rickd
  63. * Initial release for C4T1E1 support. Lots of transparent
  64. * mode updates.
  65. *
  66. *-----------------------------------------------------------------------------
  67. */
  68. char SBEid_pmcc4_musyccc[] =
  69. "@(#)musycc.c - $Revision: 2.1 $ (c) Copyright 2004-2006 SBE, Inc.";
  70. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  71. #include <linux/types.h>
  72. #include "pmcc4_sysdep.h"
  73. #include <linux/kernel.h>
  74. #include <linux/errno.h>
  75. #include <linux/init.h>
  76. #include "sbecom_inline_linux.h"
  77. #include "libsbew.h"
  78. #include "pmcc4_private.h"
  79. #include "pmcc4.h"
  80. #include "musycc.h"
  81. #ifdef SBE_INCLUDE_SYMBOLS
  82. #define STATIC
  83. #else
  84. #define STATIC static
  85. #endif
  86. #define sd_find_chan(ci,ch) c4_find_chan(ch)
  87. /*******************************************************************/
  88. /* global driver variables */
  89. extern ci_t *c4_list;
  90. extern int drvr_state;
  91. extern int cxt1e1_log_level;
  92. extern int cxt1e1_max_mru;
  93. extern int cxt1e1_max_mtu;
  94. extern int max_rxdesc_used;
  95. extern int max_txdesc_used;
  96. extern ci_t *CI; /* dummy pointr to board ZEROE's data - DEBUG
  97. * USAGE */
  98. /*******************************************************************/
  99. /* forward references */
  100. void c4_fifo_free (mpi_t *, int);
  101. void c4_wk_chan_restart (mch_t *);
  102. void musycc_bh_tx_eom (mpi_t *, int);
  103. int musycc_chan_up (ci_t *, int);
  104. status_t __init musycc_init (ci_t *);
  105. STATIC void __init musycc_init_port (mpi_t *);
  106. void musycc_intr_bh_tasklet (ci_t *);
  107. void musycc_serv_req (mpi_t *, u_int32_t);
  108. void musycc_update_timeslots (mpi_t *);
  109. /*******************************************************************/
  110. #if 1
  111. STATIC int
  112. musycc_dump_rxbuffer_ring (mch_t * ch, int lockit)
  113. {
  114. struct mdesc *m;
  115. unsigned long flags = 0;
  116. u_int32_t status;
  117. int n;
  118. if (lockit)
  119. {
  120. spin_lock_irqsave (&ch->ch_rxlock, flags);
  121. }
  122. if (ch->rxd_num == 0)
  123. {
  124. pr_info(" ZERO receive buffers allocated for this channel.");
  125. } else
  126. {
  127. FLUSH_MEM_READ ();
  128. m = &ch->mdr[ch->rxix_irq_srv];
  129. for (n = ch->rxd_num; n; n--)
  130. {
  131. status = le32_to_cpu (m->status);
  132. {
  133. pr_info("%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
  134. (m == &ch->mdr[ch->rxix_irq_srv]) ? 'F' : ' ',
  135. (unsigned long) m, n,
  136. status,
  137. m->data ? (status & HOST_RX_OWNED ? 'H' : 'M') : '-',
  138. status & POLL_DISABLED ? 'P' : '-',
  139. status & EOBIRQ_ENABLE ? 'b' : '-',
  140. status & EOMIRQ_ENABLE ? 'm' : '-',
  141. status & LENGTH_MASK,
  142. le32_to_cpu (m->data), le32_to_cpu (m->next));
  143. #ifdef RLD_DUMP_BUFDATA
  144. {
  145. u_int32_t *dp;
  146. int len = status & LENGTH_MASK;
  147. #if 1
  148. if (m->data && (status & HOST_RX_OWNED))
  149. #else
  150. if (m->data) /* always dump regardless of valid RX
  151. * data */
  152. #endif
  153. {
  154. dp = (u_int32_t *) OS_phystov ((void *) (le32_to_cpu (m->data)));
  155. if (len >= 0x10)
  156. pr_info(" %x[%x]: %08X %08X %08X %08x\n", (u_int32_t) dp, len,
  157. *dp, *(dp + 1), *(dp + 2), *(dp + 3));
  158. else if (len >= 0x08)
  159. pr_info(" %x[%x]: %08X %08X\n", (u_int32_t) dp, len,
  160. *dp, *(dp + 1));
  161. else
  162. pr_info(" %x[%x]: %08X\n", (u_int32_t) dp, len, *dp);
  163. }
  164. }
  165. #endif
  166. }
  167. m = m->snext;
  168. }
  169. } /* -for- */
  170. pr_info("\n");
  171. if (lockit)
  172. {
  173. spin_unlock_irqrestore (&ch->ch_rxlock, flags);
  174. }
  175. return 0;
  176. }
  177. #endif
  178. #if 1
  179. STATIC int
  180. musycc_dump_txbuffer_ring (mch_t * ch, int lockit)
  181. {
  182. struct mdesc *m;
  183. unsigned long flags = 0;
  184. u_int32_t status;
  185. int n;
  186. if (lockit)
  187. {
  188. spin_lock_irqsave (&ch->ch_txlock, flags);
  189. }
  190. if (ch->txd_num == 0)
  191. {
  192. pr_info(" ZERO transmit buffers allocated for this channel.");
  193. } else
  194. {
  195. FLUSH_MEM_READ ();
  196. m = ch->txd_irq_srv;
  197. for (n = ch->txd_num; n; n--)
  198. {
  199. status = le32_to_cpu (m->status);
  200. {
  201. pr_info("%c%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
  202. (m == ch->txd_usr_add) ? 'F' : ' ',
  203. (m == ch->txd_irq_srv) ? 'L' : ' ',
  204. (unsigned long) m, n,
  205. status,
  206. m->data ? (status & MUSYCC_TX_OWNED ? 'M' : 'H') : '-',
  207. status & POLL_DISABLED ? 'P' : '-',
  208. status & EOBIRQ_ENABLE ? 'b' : '-',
  209. status & EOMIRQ_ENABLE ? 'm' : '-',
  210. status & LENGTH_MASK,
  211. le32_to_cpu (m->data), le32_to_cpu (m->next));
  212. #ifdef RLD_DUMP_BUFDATA
  213. {
  214. u_int32_t *dp;
  215. int len = status & LENGTH_MASK;
  216. if (m->data)
  217. {
  218. dp = (u_int32_t *) OS_phystov ((void *) (le32_to_cpu (m->data)));
  219. if (len >= 0x10)
  220. pr_info(" %x[%x]: %08X %08X %08X %08x\n", (u_int32_t) dp, len,
  221. *dp, *(dp + 1), *(dp + 2), *(dp + 3));
  222. else if (len >= 0x08)
  223. pr_info(" %x[%x]: %08X %08X\n", (u_int32_t) dp, len,
  224. *dp, *(dp + 1));
  225. else
  226. pr_info(" %x[%x]: %08X\n", (u_int32_t) dp, len, *dp);
  227. }
  228. }
  229. #endif
  230. }
  231. m = m->snext;
  232. }
  233. } /* -for- */
  234. pr_info("\n");
  235. if (lockit)
  236. {
  237. spin_unlock_irqrestore (&ch->ch_txlock, flags);
  238. }
  239. return 0;
  240. }
  241. #endif
  242. /*
  243. * The following supports a backdoor debug facility which can be used to
  244. * display the state of a board's channel.
  245. */
  246. status_t
  247. musycc_dump_ring (ci_t * ci, unsigned int chan)
  248. {
  249. mch_t *ch;
  250. if (chan >= MAX_CHANS_USED)
  251. {
  252. return SBE_DRVR_FAIL; /* E2BIG */
  253. }
  254. {
  255. int bh;
  256. bh = atomic_read (&ci->bh_pending);
  257. pr_info(">> bh_pend %d [%d] ihead %d itail %d [%d] th_cnt %d bh_cnt %d wdcnt %d note %d\n",
  258. bh, max_bh, ci->iqp_headx, ci->iqp_tailx, max_intcnt,
  259. ci->intlog.drvr_intr_thcount,
  260. ci->intlog.drvr_intr_bhcount,
  261. ci->wdcount, ci->wd_notify);
  262. max_bh = 0; /* reset counter */
  263. max_intcnt = 0; /* reset counter */
  264. }
  265. if (!(ch = sd_find_chan (dummy, chan)))
  266. {
  267. pr_info(">> musycc_dump_ring: channel %d not up.\n", chan);
  268. return ENOENT;
  269. }
  270. pr_info(">> CI %p CHANNEL %3d @ %p: state %x status/p %x/%x\n", ci, chan, ch, ch->state,
  271. ch->status, ch->p.status);
  272. pr_info("--------------------------------\nTX Buffer Ring - Channel %d, txd_num %d. (bd/ch pend %d %d), TXD required %d, txpkt %lu\n",
  273. chan, ch->txd_num,
  274. (u_int32_t) atomic_read (&ci->tx_pending), (u_int32_t) atomic_read (&ch->tx_pending), ch->txd_required, ch->s.tx_packets);
  275. pr_info("++ User 0x%p IRQ_SRV 0x%p USR_ADD 0x%p QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
  276. ch->user, ch->txd_irq_srv, ch->txd_usr_add,
  277. sd_queue_stopped (ch->user),
  278. ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
  279. musycc_dump_txbuffer_ring (ch, 1);
  280. pr_info("RX Buffer Ring - Channel %d, rxd_num %d. IRQ_SRV[%d] 0x%p, start_rx %x rxpkt %lu\n",
  281. chan, ch->rxd_num, ch->rxix_irq_srv,
  282. &ch->mdr[ch->rxix_irq_srv], ch->ch_start_rx, ch->s.rx_packets);
  283. musycc_dump_rxbuffer_ring (ch, 1);
  284. return SBE_DRVR_SUCCESS;
  285. }
  286. status_t
  287. musycc_dump_rings (ci_t * ci, unsigned int start_chan)
  288. {
  289. unsigned int chan;
  290. for (chan = start_chan; chan < (start_chan + 5); chan++)
  291. musycc_dump_ring (ci, chan);
  292. return SBE_DRVR_SUCCESS;
  293. }
  294. /*
  295. * NOTE on musycc_init_mdt(): These MUSYCC writes are only operational after
  296. * a MUSYCC GROUP_INIT command has been issued.
  297. */
  298. void
  299. musycc_init_mdt (mpi_t * pi)
  300. {
  301. u_int32_t *addr, cfg;
  302. int i;
  303. /*
  304. * This Idle Code insertion takes effect prior to channel's first
  305. * transmitted message. After that, each message contains its own Idle
  306. * Code information which is to be issued after the message is
  307. * transmitted (Ref.MUSYCC 5.2.2.3: MCENBL bit in Group Configuration
  308. * Descriptor).
  309. */
  310. addr = (u_int32_t *) ((u_long) pi->reg + MUSYCC_MDT_BASE03_ADDR);
  311. cfg = CFG_CH_FLAG_7E << IDLE_CODE;
  312. for (i = 0; i < 32; addr++, i++)
  313. {
  314. pci_write_32 (addr, cfg);
  315. }
  316. }
  317. /* Set TX thp to the next unprocessed md */
  318. void
  319. musycc_update_tx_thp (mch_t * ch)
  320. {
  321. struct mdesc *md;
  322. unsigned long flags;
  323. spin_lock_irqsave (&ch->ch_txlock, flags);
  324. while (1)
  325. {
  326. md = ch->txd_irq_srv;
  327. FLUSH_MEM_READ ();
  328. if (!md->data)
  329. {
  330. /* No MDs with buffers to process */
  331. spin_unlock_irqrestore (&ch->ch_txlock, flags);
  332. return;
  333. }
  334. if ((le32_to_cpu (md->status)) & MUSYCC_TX_OWNED)
  335. {
  336. /* this is the MD to restart TX with */
  337. break;
  338. }
  339. /*
  340. * Otherwise, we have a valid, host-owned message descriptor which
  341. * has been successfully transmitted and whose buffer can be freed,
  342. * so... process this MD, it's owned by the host. (This might give
  343. * as a new, updated txd_irq_srv.)
  344. */
  345. musycc_bh_tx_eom (ch->up, ch->gchan);
  346. }
  347. md = ch->txd_irq_srv;
  348. ch->up->regram->thp[ch->gchan] = cpu_to_le32 (OS_vtophys (md));
  349. FLUSH_MEM_WRITE ();
  350. if (ch->tx_full)
  351. {
  352. ch->tx_full = 0;
  353. ch->txd_required = 0;
  354. sd_enable_xmit (ch->user); /* re-enable to catch flow controlled
  355. * channel */
  356. }
  357. spin_unlock_irqrestore (&ch->ch_txlock, flags);
  358. #ifdef RLD_TRANS_DEBUG
  359. pr_info("++ musycc_update_tx_thp[%d]: setting thp = %p, sts %x\n", ch->channum, md, md->status);
  360. #endif
  361. }
  362. /*
  363. * This is the workq task executed by the OS when our queue_work() is
  364. * scheduled and run. It can fire off either RX or TX ACTIVATION depending
  365. * upon the channel's ch_start_tx and ch_start_rx variables. This routine
  366. * is implemented as a work queue so that the call to the service request is
  367. * able to sleep, awaiting an interrupt acknowledgment response (SACK) from
  368. * the hardware.
  369. */
  370. void
  371. musycc_wq_chan_restart (void *arg) /* channel private structure */
  372. {
  373. mch_t *ch;
  374. mpi_t *pi;
  375. struct mdesc *md;
  376. #if 0
  377. unsigned long flags;
  378. #endif
  379. ch = container_of(arg, struct c4_chan_info, ch_work);
  380. pi = ch->up;
  381. #ifdef RLD_TRANS_DEBUG
  382. pr_info("wq_chan_restart[%d]: start_RT[%d/%d] status %x\n",
  383. ch->channum, ch->ch_start_rx, ch->ch_start_tx, ch->status);
  384. #endif
  385. /**********************************/
  386. /** check for RX restart request **/
  387. /**********************************/
  388. if ((ch->ch_start_rx) && (ch->status & RX_ENABLED))
  389. {
  390. ch->ch_start_rx = 0;
  391. #if defined(RLD_TRANS_DEBUG) || defined(RLD_RXACT_DEBUG)
  392. {
  393. static int hereb4 = 7;
  394. if (hereb4) /* RLD DEBUG */
  395. {
  396. hereb4--;
  397. #ifdef RLD_TRANS_DEBUG
  398. md = &ch->mdr[ch->rxix_irq_srv];
  399. pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
  400. ch->channum, ch->rxix_irq_srv, md, le32_to_cpu (md->status),
  401. ch->s.rx_packets);
  402. #elif defined(RLD_RXACT_DEBUG)
  403. md = &ch->mdr[ch->rxix_irq_srv];
  404. pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
  405. ch->channum, ch->rxix_irq_srv, md, le32_to_cpu (md->status),
  406. ch->s.rx_packets);
  407. musycc_dump_rxbuffer_ring (ch, 1); /* RLD DEBUG */
  408. #endif
  409. }
  410. }
  411. #endif
  412. musycc_serv_req (pi, SR_CHANNEL_ACTIVATE | SR_RX_DIRECTION | ch->gchan);
  413. }
  414. /**********************************/
  415. /** check for TX restart request **/
  416. /**********************************/
  417. if ((ch->ch_start_tx) && (ch->status & TX_ENABLED))
  418. {
  419. /* find next unprocessed message, then set TX thp to it */
  420. musycc_update_tx_thp (ch);
  421. #if 0
  422. spin_lock_irqsave (&ch->ch_txlock, flags);
  423. #endif
  424. md = ch->txd_irq_srv;
  425. if (!md)
  426. {
  427. #ifdef RLD_TRANS_DEBUG
  428. pr_info("-- musycc_wq_chan_restart[%d]: WARNING, starting NULL md\n", ch->channum);
  429. #endif
  430. #if 0
  431. spin_unlock_irqrestore (&ch->ch_txlock, flags);
  432. #endif
  433. } else if (md->data && ((le32_to_cpu (md->status)) & MUSYCC_TX_OWNED))
  434. {
  435. ch->ch_start_tx = 0;
  436. #if 0
  437. spin_unlock_irqrestore (&ch->ch_txlock, flags); /* allow interrupts for service request */
  438. #endif
  439. #ifdef RLD_TRANS_DEBUG
  440. pr_info("++ musycc_wq_chan_restart() CHAN TX ACTIVATE: chan %d txd_irq_srv %p = sts %x, txpkt %lu\n",
  441. ch->channum, ch->txd_irq_srv, ch->txd_irq_srv->status, ch->s.tx_packets);
  442. #endif
  443. musycc_serv_req (pi, SR_CHANNEL_ACTIVATE | SR_TX_DIRECTION | ch->gchan);
  444. }
  445. #ifdef RLD_RESTART_DEBUG
  446. else
  447. {
  448. /* retain request to start until retried and we have data to xmit */
  449. pr_info("-- musycc_wq_chan_restart[%d]: DELAYED due to md %p sts %x data %x, start_tx %x\n",
  450. ch->channum, md,
  451. le32_to_cpu (md->status),
  452. le32_to_cpu (md->data), ch->ch_start_tx);
  453. musycc_dump_txbuffer_ring (ch, 0);
  454. #if 0
  455. spin_unlock_irqrestore (&ch->ch_txlock, flags); /* allow interrupts for service request */
  456. #endif
  457. }
  458. #endif
  459. }
  460. }
  461. /*
  462. * Channel restart either fires of a workqueue request (2.6) or lodges a
  463. * watchdog activation sequence (2.4).
  464. */
  465. void
  466. musycc_chan_restart (mch_t * ch)
  467. {
  468. #ifdef RLD_RESTART_DEBUG
  469. pr_info("++ musycc_chan_restart[%d]: txd_irq_srv @ %p = sts %x\n",
  470. ch->channum, ch->txd_irq_srv, ch->txd_irq_srv->status);
  471. #endif
  472. /* 2.6 - find next unprocessed message, then set TX thp to it */
  473. #ifdef RLD_RESTART_DEBUG
  474. pr_info(">> musycc_chan_restart: scheduling Chan %x workQ @ %p\n", ch->channum, &ch->ch_work);
  475. #endif
  476. c4_wk_chan_restart (ch); /* work queue mechanism fires off: Ref:
  477. * musycc_wq_chan_restart () */
  478. }
  479. void
  480. rld_put_led (mpi_t * pi, u_int32_t ledval)
  481. {
  482. static u_int32_t led = 0;
  483. if (ledval == 0)
  484. led = 0;
  485. else
  486. led |= ledval;
  487. pci_write_32 ((u_int32_t *) &pi->up->cpldbase->leds, led); /* RLD DEBUG TRANHANG */
  488. }
  489. #define MUSYCC_SR_RETRY_CNT 9
  490. void
  491. musycc_serv_req (mpi_t * pi, u_int32_t req)
  492. {
  493. volatile u_int32_t r;
  494. int rcnt;
  495. /*
  496. * PORT NOTE: Semaphore protect service loop guarantees only a single
  497. * operation at a time. Per MUSYCC Manual - "Issuing service requests to
  498. * the same channel group without first receiving ACK from each request
  499. * may cause the host to lose track of which service request has been
  500. * acknowledged."
  501. */
  502. SD_SEM_TAKE (&pi->sr_sem_busy, "serv"); /* only 1 thru here, per
  503. * group */
  504. if (pi->sr_last == req)
  505. {
  506. #ifdef RLD_TRANS_DEBUG
  507. pr_info(">> same SR, Port %d Req %x\n", pi->portnum, req);
  508. #endif
  509. /*
  510. * The most likely repeated request is the channel activation command
  511. * which follows the occurrence of a Transparent mode TX ONR or a
  512. * BUFF error. If the previous command was a CHANNEL ACTIVATE,
  513. * precede it with a NOOP command in order maintain coherent control
  514. * of this current (re)ACTIVATE.
  515. */
  516. r = (pi->sr_last & ~SR_GCHANNEL_MASK);
  517. if ((r == (SR_CHANNEL_ACTIVATE | SR_TX_DIRECTION)) ||
  518. (r == (SR_CHANNEL_ACTIVATE | SR_RX_DIRECTION)))
  519. {
  520. #ifdef RLD_TRANS_DEBUG
  521. pr_info(">> same CHAN ACT SR, Port %d Req %x => issue SR_NOOP CMD\n", pi->portnum, req);
  522. #endif
  523. SD_SEM_GIVE (&pi->sr_sem_busy); /* allow this next request */
  524. musycc_serv_req (pi, SR_NOOP);
  525. SD_SEM_TAKE (&pi->sr_sem_busy, "serv"); /* relock & continue w/
  526. * original req */
  527. } else if (req == SR_NOOP)
  528. {
  529. /* no need to issue back-to-back SR_NOOP commands at this time */
  530. #ifdef RLD_TRANS_DEBUG
  531. pr_info(">> same Port SR_NOOP skipped, Port %d\n", pi->portnum);
  532. #endif
  533. SD_SEM_GIVE (&pi->sr_sem_busy); /* allow this next request */
  534. return;
  535. }
  536. }
  537. rcnt = 0;
  538. pi->sr_last = req;
  539. rewrite:
  540. pci_write_32 ((u_int32_t *) &pi->reg->srd, req);
  541. FLUSH_MEM_WRITE ();
  542. /*
  543. * Per MUSYCC Manual, Section 6.1,2 - "When writing an SCR service
  544. * request, the host must ensure at least one PCI bus clock cycle has
  545. * elapsed before writing another service request. To meet this minimum
  546. * elapsed service request write timing interval, it is recommended that
  547. * the host follow any SCR write with another operation which reads from
  548. * the same address."
  549. */
  550. r = pci_read_32 ((u_int32_t *) &pi->reg->srd); /* adhere to write
  551. * timing imposition */
  552. if ((r != req) && (req != SR_CHIP_RESET) && (++rcnt <= MUSYCC_SR_RETRY_CNT))
  553. {
  554. if (cxt1e1_log_level >= LOG_MONITOR)
  555. pr_info("%s: %d - reissue srv req/last %x/%x (hdw reads %x), Chan %d.\n",
  556. pi->up->devname, rcnt, req, pi->sr_last, r,
  557. (pi->portnum * MUSYCC_NCHANS) + (req & 0x1f));
  558. OS_uwait_dummy (); /* this delay helps reduce reissue counts
  559. * (reason not yet researched) */
  560. goto rewrite;
  561. }
  562. if (rcnt > MUSYCC_SR_RETRY_CNT)
  563. {
  564. pr_warning("%s: failed service request (#%d)= %x, group %d.\n",
  565. pi->up->devname, MUSYCC_SR_RETRY_CNT, req, pi->portnum);
  566. SD_SEM_GIVE (&pi->sr_sem_busy); /* allow any next request */
  567. return;
  568. }
  569. if (req == SR_CHIP_RESET)
  570. {
  571. /*
  572. * PORT NOTE: the CHIP_RESET command is NOT ack'd by the MUSYCC, thus
  573. * the upcoming delay is used. Though the MUSYCC documentation
  574. * suggests a read-after-write would supply the required delay, it's
  575. * unclear what CPU/BUS clock speeds might have been assumed when
  576. * suggesting this 'lack of ACK' workaround. Thus the use of uwait.
  577. */
  578. OS_uwait (100000, "icard"); /* 100ms */
  579. } else
  580. {
  581. FLUSH_MEM_READ ();
  582. SD_SEM_TAKE (&pi->sr_sem_wait, "sakack"); /* sleep until SACK
  583. * interrupt occurs */
  584. }
  585. SD_SEM_GIVE (&pi->sr_sem_busy); /* allow any next request */
  586. }
  587. #ifdef SBE_PMCC4_ENABLE
  588. void
  589. musycc_update_timeslots (mpi_t * pi)
  590. {
  591. int i, ch;
  592. char e1mode = IS_FRAME_ANY_E1 (pi->p.port_mode);
  593. for (i = 0; i < 32; i++)
  594. {
  595. int usedby = 0, last = 0, ts, j, bits[8];
  596. u_int8_t lastval = 0;
  597. if (((i == 0) && e1mode) || /* disable if E1 mode */
  598. ((i == 16) && ((pi->p.port_mode == CFG_FRAME_E1CRC_CAS) || (pi->p.port_mode == CFG_FRAME_E1CRC_CAS_AMI)))
  599. || ((i > 23) && (!e1mode))) /* disable if T1 mode */
  600. {
  601. pi->tsm[i] = 0xff; /* make tslot unavailable for this mode */
  602. } else
  603. {
  604. pi->tsm[i] = 0x00; /* make tslot available for assignment */
  605. }
  606. for (j = 0; j < 8; j++)
  607. bits[j] = -1;
  608. for (ch = 0; ch < MUSYCC_NCHANS; ch++)
  609. {
  610. if ((pi->chan[ch]->state == UP) && (pi->chan[ch]->p.bitmask[i]))
  611. {
  612. usedby++;
  613. last = ch;
  614. lastval = pi->chan[ch]->p.bitmask[i];
  615. for (j = 0; j < 8; j++)
  616. if (lastval & (1 << j))
  617. bits[j] = ch;
  618. pi->tsm[i] |= lastval;
  619. }
  620. }
  621. if (!usedby)
  622. ts = 0;
  623. else if ((usedby == 1) && (lastval == 0xff))
  624. ts = (4 << 5) | last;
  625. else if ((usedby == 1) && (lastval == 0x7f))
  626. ts = (5 << 5) | last;
  627. else
  628. {
  629. int idx;
  630. if (bits[0] < 0)
  631. ts = (6 << 5) | (idx = last);
  632. else
  633. ts = (7 << 5) | (idx = bits[0]);
  634. for (j = 1; j < 8; j++)
  635. {
  636. pi->regram->rscm[idx * 8 + j] = (bits[j] < 0) ? 0 : (0x80 | bits[j]);
  637. pi->regram->tscm[idx * 8 + j] = (bits[j] < 0) ? 0 : (0x80 | bits[j]);
  638. }
  639. }
  640. pi->regram->rtsm[i] = ts;
  641. pi->regram->ttsm[i] = ts;
  642. }
  643. FLUSH_MEM_WRITE ();
  644. musycc_serv_req (pi, SR_TIMESLOT_MAP | SR_RX_DIRECTION);
  645. musycc_serv_req (pi, SR_TIMESLOT_MAP | SR_TX_DIRECTION);
  646. musycc_serv_req (pi, SR_SUBCHANNEL_MAP | SR_RX_DIRECTION);
  647. musycc_serv_req (pi, SR_SUBCHANNEL_MAP | SR_TX_DIRECTION);
  648. }
  649. #endif
  650. #ifdef SBE_WAN256T3_ENABLE
  651. void
  652. musycc_update_timeslots (mpi_t * pi)
  653. {
  654. mch_t *ch;
  655. u_int8_t ts, hmask, tsen;
  656. int gchan;
  657. int i;
  658. #ifdef SBE_PMCC4_ENABLE
  659. hmask = (0x1f << pi->up->p.hypersize) & 0x1f;
  660. #endif
  661. #ifdef SBE_WAN256T3_ENABLE
  662. hmask = (0x1f << hyperdummy) & 0x1f;
  663. #endif
  664. for (i = 0; i < 128; i++)
  665. {
  666. gchan = ((pi->portnum * MUSYCC_NCHANS) + (i & hmask)) % MUSYCC_NCHANS;
  667. ch = pi->chan[gchan];
  668. if (ch->p.mode_56k)
  669. tsen = MODE_56KBPS;
  670. else
  671. tsen = MODE_64KBPS; /* also the default */
  672. ts = ((pi->portnum % 4) == (i / 32)) ? (tsen << 5) | (i & hmask) : 0;
  673. pi->regram->rtsm[i] = ts;
  674. pi->regram->ttsm[i] = ts;
  675. }
  676. FLUSH_MEM_WRITE ();
  677. musycc_serv_req (pi, SR_TIMESLOT_MAP | SR_RX_DIRECTION);
  678. musycc_serv_req (pi, SR_TIMESLOT_MAP | SR_TX_DIRECTION);
  679. }
  680. #endif
  681. /*
  682. * This routine converts a generic library channel configuration parameter
  683. * into a hardware specific register value (IE. MUSYCC CCD Register).
  684. */
  685. u_int32_t
  686. musycc_chan_proto (int proto)
  687. {
  688. int reg;
  689. switch (proto)
  690. {
  691. case CFG_CH_PROTO_TRANS: /* 0 */
  692. reg = MUSYCC_CCD_TRANS;
  693. break;
  694. case CFG_CH_PROTO_SS7: /* 1 */
  695. reg = MUSYCC_CCD_SS7;
  696. break;
  697. default:
  698. case CFG_CH_PROTO_ISLP_MODE: /* 4 */
  699. case CFG_CH_PROTO_HDLC_FCS16: /* 2 */
  700. reg = MUSYCC_CCD_HDLC_FCS16;
  701. break;
  702. case CFG_CH_PROTO_HDLC_FCS32: /* 3 */
  703. reg = MUSYCC_CCD_HDLC_FCS32;
  704. break;
  705. }
  706. return reg;
  707. }
  708. #ifdef SBE_WAN256T3_ENABLE
  709. STATIC void __init
  710. musycc_init_port (mpi_t * pi)
  711. {
  712. pci_write_32 ((u_int32_t *) &pi->reg->gbp, OS_vtophys (pi->regram));
  713. pi->regram->grcd =
  714. __constant_cpu_to_le32 (MUSYCC_GRCD_RX_ENABLE |
  715. MUSYCC_GRCD_TX_ENABLE |
  716. MUSYCC_GRCD_SF_ALIGN |
  717. MUSYCC_GRCD_SUBCHAN_DISABLE |
  718. MUSYCC_GRCD_OOFMP_DISABLE |
  719. MUSYCC_GRCD_COFAIRQ_DISABLE |
  720. MUSYCC_GRCD_MC_ENABLE |
  721. (MUSYCC_GRCD_POLLTH_32 << MUSYCC_GRCD_POLLTH_SHIFT));
  722. pi->regram->pcd =
  723. __constant_cpu_to_le32 (MUSYCC_PCD_E1X4_MODE |
  724. MUSYCC_PCD_TXDATA_RISING |
  725. MUSYCC_PCD_TX_DRIVEN);
  726. /* Message length descriptor */
  727. pi->regram->mld = __constant_cpu_to_le32 (cxt1e1_max_mru | (cxt1e1_max_mru << 16));
  728. FLUSH_MEM_WRITE ();
  729. musycc_serv_req (pi, SR_GROUP_INIT | SR_RX_DIRECTION);
  730. musycc_serv_req (pi, SR_GROUP_INIT | SR_TX_DIRECTION);
  731. musycc_init_mdt (pi);
  732. musycc_update_timeslots (pi);
  733. }
  734. #endif
  735. status_t __init
  736. musycc_init (ci_t * ci)
  737. {
  738. char *regaddr; /* temp for address boundary calculations */
  739. int i, gchan;
  740. OS_sem_init (&ci->sem_wdbusy, SEM_AVAILABLE); /* watchdog exclusion */
  741. /*
  742. * Per MUSYCC manual, Section 6.3.4 - "The host must allocate a dword
  743. * aligned memory segment for interrupt queue pointers."
  744. */
  745. #define INT_QUEUE_BOUNDARY 4
  746. regaddr = OS_kmalloc ((INT_QUEUE_SIZE + 1) * sizeof (u_int32_t));
  747. if (regaddr == 0)
  748. return ENOMEM;
  749. ci->iqd_p_saved = regaddr; /* save orig value for free's usage */
  750. ci->iqd_p = (u_int32_t *) ((unsigned long) (regaddr + INT_QUEUE_BOUNDARY - 1) &
  751. (~(INT_QUEUE_BOUNDARY - 1))); /* this calculates
  752. * closest boundary */
  753. for (i = 0; i < INT_QUEUE_SIZE; i++)
  754. {
  755. ci->iqd_p[i] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY);
  756. }
  757. for (i = 0; i < ci->max_port; i++)
  758. {
  759. mpi_t *pi = &ci->port[i];
  760. /*
  761. * Per MUSYCC manual, Section 6.3.2 - "The host must allocate a 2KB
  762. * bound memory segment for Channel Group 0."
  763. */
  764. #define GROUP_BOUNDARY 0x800
  765. regaddr = OS_kmalloc (sizeof (struct musycc_groupr) + GROUP_BOUNDARY);
  766. if (regaddr == 0)
  767. {
  768. for (gchan = 0; gchan < i; gchan++)
  769. {
  770. pi = &ci->port[gchan];
  771. OS_kfree (pi->reg);
  772. pi->reg = 0;
  773. }
  774. return ENOMEM;
  775. }
  776. pi->regram_saved = regaddr; /* save orig value for free's usage */
  777. pi->regram = (struct musycc_groupr *) ((unsigned long) (regaddr + GROUP_BOUNDARY - 1) &
  778. (~(GROUP_BOUNDARY - 1))); /* this calculates
  779. * closest boundary */
  780. }
  781. /* any board centric MUSYCC commands will use group ZERO as its "home" */
  782. ci->regram = ci->port[0].regram;
  783. musycc_serv_req (&ci->port[0], SR_CHIP_RESET);
  784. pci_write_32 ((u_int32_t *) &ci->reg->gbp, OS_vtophys (ci->regram));
  785. pci_flush_write (ci);
  786. #ifdef CONFIG_SBE_PMCC4_NCOMM
  787. ci->regram->__glcd = __constant_cpu_to_le32 (GCD_MAGIC);
  788. #else
  789. /* standard driver POLLS for INTB via CPLD register */
  790. ci->regram->__glcd = __constant_cpu_to_le32 (GCD_MAGIC | MUSYCC_GCD_INTB_DISABLE);
  791. #endif
  792. ci->regram->__iqp = cpu_to_le32 (OS_vtophys (&ci->iqd_p[0]));
  793. ci->regram->__iql = __constant_cpu_to_le32 (INT_QUEUE_SIZE - 1);
  794. pci_write_32 ((u_int32_t *) &ci->reg->dacbp, 0);
  795. FLUSH_MEM_WRITE ();
  796. ci->state = C_RUNNING; /* mark as full interrupt processing
  797. * available */
  798. musycc_serv_req (&ci->port[0], SR_GLOBAL_INIT); /* FIRST INTERRUPT ! */
  799. /* sanity check settable parameters */
  800. if (cxt1e1_max_mru > 0xffe)
  801. {
  802. pr_warning("Maximum allowed MRU exceeded, resetting %d to %d.\n",
  803. cxt1e1_max_mru, 0xffe);
  804. cxt1e1_max_mru = 0xffe;
  805. }
  806. if (cxt1e1_max_mtu > 0xffe)
  807. {
  808. pr_warning("Maximum allowed MTU exceeded, resetting %d to %d.\n",
  809. cxt1e1_max_mtu, 0xffe);
  810. cxt1e1_max_mtu = 0xffe;
  811. }
  812. #ifdef SBE_WAN256T3_ENABLE
  813. for (i = 0; i < MUSYCC_NPORTS; i++)
  814. musycc_init_port (&ci->port[i]);
  815. #endif
  816. return SBE_DRVR_SUCCESS; /* no error */
  817. }
  818. void
  819. musycc_bh_tx_eom (mpi_t * pi, int gchan)
  820. {
  821. mch_t *ch;
  822. struct mdesc *md;
  823. #if 0
  824. #ifndef SBE_ISR_INLINE
  825. unsigned long flags;
  826. #endif
  827. #endif
  828. volatile u_int32_t status;
  829. ch = pi->chan[gchan];
  830. if (ch == 0 || ch->state != UP)
  831. {
  832. if (cxt1e1_log_level >= LOG_ERROR)
  833. pr_info("%s: intr: xmit EOM on uninitialized channel %d\n",
  834. pi->up->devname, gchan);
  835. }
  836. if (ch == 0 || ch->mdt == 0)
  837. return; /* note: mdt==0 implies a malloc()
  838. * failure w/in chan_up() routine */
  839. #if 0
  840. #ifdef SBE_ISR_INLINE
  841. spin_lock_irq (&ch->ch_txlock);
  842. #else
  843. spin_lock_irqsave (&ch->ch_txlock, flags);
  844. #endif
  845. #endif
  846. do
  847. {
  848. FLUSH_MEM_READ ();
  849. md = ch->txd_irq_srv;
  850. status = le32_to_cpu (md->status);
  851. /*
  852. * Note: Per MUSYCC Ref 6.4.9, the host does not poll a host-owned
  853. * Transmit Buffer Descriptor during Transparent Mode.
  854. */
  855. if (status & MUSYCC_TX_OWNED)
  856. {
  857. int readCount, loopCount;
  858. /***********************************************************/
  859. /* HW Bug Fix */
  860. /* ---------- */
  861. /* Under certain PCI Bus loading conditions, the data */
  862. /* associated with an update of Shared Memory is delayed */
  863. /* relative to its PCI Interrupt. This is caught when */
  864. /* the host determines it does not yet OWN the descriptor. */
  865. /***********************************************************/
  866. readCount = 0;
  867. while (status & MUSYCC_TX_OWNED)
  868. {
  869. for (loopCount = 0; loopCount < 0x30; loopCount++)
  870. OS_uwait_dummy (); /* use call to avoid optimization
  871. * removal of dummy delay */
  872. FLUSH_MEM_READ ();
  873. status = le32_to_cpu (md->status);
  874. if (readCount++ > 40)
  875. break; /* don't wait any longer */
  876. }
  877. if (status & MUSYCC_TX_OWNED)
  878. {
  879. if (cxt1e1_log_level >= LOG_MONITOR)
  880. {
  881. pr_info("%s: Port %d Chan %2d - unexpected TX msg ownership intr (md %p sts %x)\n",
  882. pi->up->devname, pi->portnum, ch->channum,
  883. md, status);
  884. pr_info("++ User 0x%p IRQ_SRV 0x%p USR_ADD 0x%p QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
  885. ch->user, ch->txd_irq_srv, ch->txd_usr_add,
  886. sd_queue_stopped (ch->user),
  887. ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
  888. musycc_dump_txbuffer_ring (ch, 0);
  889. }
  890. break; /* Not our mdesc, done */
  891. } else
  892. {
  893. if (cxt1e1_log_level >= LOG_MONITOR)
  894. pr_info("%s: Port %d Chan %2d - recovered TX msg ownership [%d] (md %p sts %x)\n",
  895. pi->up->devname, pi->portnum, ch->channum, readCount, md, status);
  896. }
  897. }
  898. ch->txd_irq_srv = md->snext;
  899. md->data = 0;
  900. if (md->mem_token != 0)
  901. {
  902. /* upcount channel */
  903. atomic_sub (OS_mem_token_tlen (md->mem_token), &ch->tx_pending);
  904. /* upcount card */
  905. atomic_sub (OS_mem_token_tlen (md->mem_token), &pi->up->tx_pending);
  906. #ifdef SBE_WAN256T3_ENABLE
  907. if (!atomic_read (&pi->up->tx_pending))
  908. wan256t3_led (pi->up, LED_TX, 0);
  909. #endif
  910. #ifdef CONFIG_SBE_WAN256T3_NCOMM
  911. /* callback that our packet was sent */
  912. {
  913. int hdlcnum = (pi->portnum * 32 + gchan);
  914. if (hdlcnum >= 228)
  915. {
  916. if (nciProcess_TX_complete)
  917. (*nciProcess_TX_complete) (hdlcnum,
  918. getuserbychan (gchan));
  919. }
  920. }
  921. #endif /*** CONFIG_SBE_WAN256T3_NCOMM ***/
  922. OS_mem_token_free_irq (md->mem_token);
  923. md->mem_token = 0;
  924. }
  925. md->status = 0;
  926. #ifdef RLD_TXFULL_DEBUG
  927. if (cxt1e1_log_level >= LOG_MONITOR2)
  928. pr_info("~~ tx_eom: tx_full %x txd_free %d -> %d\n",
  929. ch->tx_full, ch->txd_free, ch->txd_free + 1);
  930. #endif
  931. ++ch->txd_free;
  932. FLUSH_MEM_WRITE ();
  933. if ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) && (status & EOBIRQ_ENABLE))
  934. {
  935. if (cxt1e1_log_level >= LOG_MONITOR)
  936. pr_info("%s: Mode (%x) incorrect EOB status (%x)\n",
  937. pi->up->devname, ch->p.chan_mode, status);
  938. if ((status & EOMIRQ_ENABLE) == 0)
  939. break;
  940. }
  941. }
  942. while ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) && ((status & EOMIRQ_ENABLE) == 0));
  943. /*
  944. * NOTE: (The above 'while' is coupled w/ previous 'do', way above.) Each
  945. * Transparent data buffer has the EOB bit, and NOT the EOM bit, set and
  946. * will furthermore have a separate IQD associated with each messages
  947. * buffer.
  948. */
  949. FLUSH_MEM_READ ();
  950. /*
  951. * Smooth flow control hysterisis by maintaining task stoppage until half
  952. * the available write buffers are available.
  953. */
  954. if (ch->tx_full && (ch->txd_free >= (ch->txd_num / 2)))
  955. {
  956. /*
  957. * Then, only releave task stoppage if we actually have enough
  958. * buffers to service the last requested packet. It may require MORE
  959. * than half the available!
  960. */
  961. if (ch->txd_free >= ch->txd_required)
  962. {
  963. #ifdef RLD_TXFULL_DEBUG
  964. if (cxt1e1_log_level >= LOG_MONITOR2)
  965. pr_info("tx_eom[%d]: enable xmit tx_full no more, txd_free %d txd_num/2 %d\n",
  966. ch->channum,
  967. ch->txd_free, ch->txd_num / 2);
  968. #endif
  969. ch->tx_full = 0;
  970. ch->txd_required = 0;
  971. sd_enable_xmit (ch->user); /* re-enable to catch flow controlled
  972. * channel */
  973. }
  974. }
  975. #ifdef RLD_TXFULL_DEBUG
  976. else if (ch->tx_full)
  977. {
  978. if (cxt1e1_log_level >= LOG_MONITOR2)
  979. pr_info("tx_eom[%d]: bypass TX enable though room available? (txd_free %d txd_num/2 %d)\n",
  980. ch->channum,
  981. ch->txd_free, ch->txd_num / 2);
  982. }
  983. #endif
  984. FLUSH_MEM_WRITE ();
  985. #if 0
  986. #ifdef SBE_ISR_INLINE
  987. spin_unlock_irq (&ch->ch_txlock);
  988. #else
  989. spin_unlock_irqrestore (&ch->ch_txlock, flags);
  990. #endif
  991. #endif
  992. }
  993. STATIC void
  994. musycc_bh_rx_eom (mpi_t * pi, int gchan)
  995. {
  996. mch_t *ch;
  997. void *m, *m2;
  998. struct mdesc *md;
  999. volatile u_int32_t status;
  1000. u_int32_t error;
  1001. ch = pi->chan[gchan];
  1002. if (ch == 0 || ch->state != UP)
  1003. {
  1004. if (cxt1e1_log_level > LOG_ERROR)
  1005. pr_info("%s: intr: receive EOM on uninitialized channel %d\n",
  1006. pi->up->devname, gchan);
  1007. return;
  1008. }
  1009. if (ch->mdr == 0)
  1010. return; /* can this happen ? */
  1011. for (;;)
  1012. {
  1013. FLUSH_MEM_READ ();
  1014. md = &ch->mdr[ch->rxix_irq_srv];
  1015. status = le32_to_cpu (md->status);
  1016. if (!(status & HOST_RX_OWNED))
  1017. break; /* Not our mdesc, done */
  1018. m = md->mem_token;
  1019. error = (status >> 16) & 0xf;
  1020. if (error == 0)
  1021. {
  1022. #ifdef CONFIG_SBE_WAN256T3_NCOMM
  1023. int hdlcnum = (pi->portnum * 32 + gchan);
  1024. /*
  1025. * if the packet number belongs to NCOMM, then send it to the TMS
  1026. * driver
  1027. */
  1028. if (hdlcnum >= 228)
  1029. {
  1030. if (nciProcess_RX_packet)
  1031. (*nciProcess_RX_packet) (hdlcnum, status & 0x3fff, m, ch->user);
  1032. } else
  1033. #endif /*** CONFIG_SBE_WAN256T3_NCOMM ***/
  1034. {
  1035. if ((m2 = OS_mem_token_alloc (cxt1e1_max_mru)))
  1036. {
  1037. /* substitute the mbuf+cluster */
  1038. md->mem_token = m2;
  1039. md->data = cpu_to_le32 (OS_vtophys (OS_mem_token_data (m2)));
  1040. /* pass the received mbuf upward */
  1041. sd_recv_consume (m, status & LENGTH_MASK, ch->user);
  1042. ch->s.rx_packets++;
  1043. ch->s.rx_bytes += status & LENGTH_MASK;
  1044. } else
  1045. {
  1046. ch->s.rx_dropped++;
  1047. }
  1048. }
  1049. } else if (error == ERR_FCS)
  1050. {
  1051. ch->s.rx_crc_errors++;
  1052. } else if (error == ERR_ALIGN)
  1053. {
  1054. ch->s.rx_missed_errors++;
  1055. } else if (error == ERR_ABT)
  1056. {
  1057. ch->s.rx_missed_errors++;
  1058. } else if (error == ERR_LNG)
  1059. {
  1060. ch->s.rx_length_errors++;
  1061. } else if (error == ERR_SHT)
  1062. {
  1063. ch->s.rx_length_errors++;
  1064. }
  1065. FLUSH_MEM_WRITE ();
  1066. status = cxt1e1_max_mru;
  1067. if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
  1068. status |= EOBIRQ_ENABLE;
  1069. md->status = cpu_to_le32 (status);
  1070. /* Check next mdesc in the ring */
  1071. if (++ch->rxix_irq_srv >= ch->rxd_num)
  1072. ch->rxix_irq_srv = 0;
  1073. FLUSH_MEM_WRITE ();
  1074. }
  1075. }
  1076. irqreturn_t
  1077. musycc_intr_th_handler (void *devp)
  1078. {
  1079. ci_t *ci = (ci_t *) devp;
  1080. volatile u_int32_t status, currInt = 0;
  1081. u_int32_t nextInt, intCnt;
  1082. /*
  1083. * Hardware not available, potential interrupt hang. But since interrupt
  1084. * might be shared, just return.
  1085. */
  1086. if (ci->state == C_INIT)
  1087. {
  1088. return IRQ_NONE;
  1089. }
  1090. /*
  1091. * Marked as hardware available. Don't service interrupts, just clear the
  1092. * event.
  1093. */
  1094. if (ci->state == C_IDLE)
  1095. {
  1096. status = pci_read_32 ((u_int32_t *) &ci->reg->isd);
  1097. /* clear the interrupt but process nothing else */
  1098. pci_write_32 ((u_int32_t *) &ci->reg->isd, status);
  1099. return IRQ_HANDLED;
  1100. }
  1101. FLUSH_PCI_READ ();
  1102. FLUSH_MEM_READ ();
  1103. status = pci_read_32 ((u_int32_t *) &ci->reg->isd);
  1104. nextInt = INTRPTS_NEXTINT (status);
  1105. intCnt = INTRPTS_INTCNT (status);
  1106. ci->intlog.drvr_intr_thcount++;
  1107. /*********************************************************/
  1108. /* HW Bug Fix */
  1109. /* ---------- */
  1110. /* Under certain PCI Bus loading conditions, the */
  1111. /* MUSYCC looses the data associated with an update */
  1112. /* of its ISD and erroneously returns the immediately */
  1113. /* preceding 'nextInt' value. However, the 'intCnt' */
  1114. /* value appears to be correct. By not starting service */
  1115. /* where the 'missing' 'nextInt' SHOULD point causes */
  1116. /* the IQD not to be serviced - the 'not serviced' */
  1117. /* entries then remain and continue to increase as more */
  1118. /* incorrect ISD's are encountered. */
  1119. /*********************************************************/
  1120. if (nextInt != INTRPTS_NEXTINT (ci->intlog.this_status_new))
  1121. {
  1122. if (cxt1e1_log_level >= LOG_MONITOR)
  1123. {
  1124. pr_info("%s: note - updated ISD from %08x to %08x\n",
  1125. ci->devname, status,
  1126. (status & (~INTRPTS_NEXTINT_M)) | ci->intlog.this_status_new);
  1127. }
  1128. /*
  1129. * Replace bogus status with software corrected value.
  1130. *
  1131. * It's not known whether, during this problem occurrence, if the
  1132. * INTFULL bit is correctly reported or not.
  1133. */
  1134. status = (status & (~INTRPTS_NEXTINT_M)) | (ci->intlog.this_status_new);
  1135. nextInt = INTRPTS_NEXTINT (status);
  1136. }
  1137. /**********************************************/
  1138. /* Cn847x Bug Fix */
  1139. /* -------------- */
  1140. /* Fix for inability to write back same index */
  1141. /* as read for a full interrupt queue. */
  1142. /**********************************************/
  1143. if (intCnt == INT_QUEUE_SIZE)
  1144. {
  1145. currInt = ((intCnt - 1) + nextInt) & (INT_QUEUE_SIZE - 1);
  1146. } else
  1147. /************************************************/
  1148. /* Interrupt Write Location Issues */
  1149. /* ------------------------------- */
  1150. /* When the interrupt status descriptor is */
  1151. /* written, the interrupt line is de-asserted */
  1152. /* by the Cn847x. In the case of MIPS */
  1153. /* microprocessors, this must occur at the */
  1154. /* beginning of the interrupt handler so that */
  1155. /* the interrupt handle is not re-entered due */
  1156. /* to interrupt dis-assertion latency. */
  1157. /* In the case of all other processors, this */
  1158. /* action should occur at the end of the */
  1159. /* interrupt handler to avoid overwriting the */
  1160. /* interrupt queue. */
  1161. /************************************************/
  1162. if (intCnt)
  1163. {
  1164. currInt = (intCnt + nextInt) & (INT_QUEUE_SIZE - 1);
  1165. } else
  1166. {
  1167. /*
  1168. * NOTE: Servicing an interrupt whose ISD contains a count of ZERO
  1169. * can be indicative of a Shared Interrupt chain. Our driver can be
  1170. * called from the system's interrupt handler as a matter of the OS
  1171. * walking the chain. As the chain is walked, the interrupt will
  1172. * eventually be serviced by the correct driver/handler.
  1173. */
  1174. #if 0
  1175. /* chained interrupt = not ours */
  1176. pr_info(">> %s: intCnt NULL, sts %x, possibly a chained interrupt!\n",
  1177. ci->devname, status);
  1178. #endif
  1179. return IRQ_NONE;
  1180. }
  1181. ci->iqp_tailx = currInt;
  1182. currInt <<= INTRPTS_NEXTINT_S;
  1183. ci->intlog.last_status_new = ci->intlog.this_status_new;
  1184. ci->intlog.this_status_new = currInt;
  1185. if ((cxt1e1_log_level >= LOG_WARN) && (status & INTRPTS_INTFULL_M))
  1186. {
  1187. pr_info("%s: Interrupt queue full condition occurred\n", ci->devname);
  1188. }
  1189. if (cxt1e1_log_level >= LOG_DEBUG)
  1190. pr_info("%s: interrupts pending, isd @ 0x%p: %x curr %d cnt %d NEXT %d\n",
  1191. ci->devname, &ci->reg->isd,
  1192. status, nextInt, intCnt, (intCnt + nextInt) & (INT_QUEUE_SIZE - 1));
  1193. FLUSH_MEM_WRITE ();
  1194. #if defined(SBE_ISR_TASKLET)
  1195. pci_write_32 ((u_int32_t *) &ci->reg->isd, currInt);
  1196. atomic_inc (&ci->bh_pending);
  1197. tasklet_schedule (&ci->ci_musycc_isr_tasklet);
  1198. #elif defined(SBE_ISR_IMMEDIATE)
  1199. pci_write_32 ((u_int32_t *) &ci->reg->isd, currInt);
  1200. atomic_inc (&ci->bh_pending);
  1201. queue_task (&ci->ci_musycc_isr_tq, &tq_immediate);
  1202. mark_bh (IMMEDIATE_BH);
  1203. #elif defined(SBE_ISR_INLINE)
  1204. (void) musycc_intr_bh_tasklet (ci);
  1205. pci_write_32 ((u_int32_t *) &ci->reg->isd, currInt);
  1206. #endif
  1207. return IRQ_HANDLED;
  1208. }
  1209. #if defined(SBE_ISR_IMMEDIATE)
  1210. unsigned long
  1211. #else
  1212. void
  1213. #endif
  1214. musycc_intr_bh_tasklet (ci_t * ci)
  1215. {
  1216. mpi_t *pi;
  1217. mch_t *ch;
  1218. unsigned int intCnt;
  1219. volatile u_int32_t currInt = 0;
  1220. volatile unsigned int headx, tailx;
  1221. int readCount, loopCount;
  1222. int group, gchan, event, err, tx;
  1223. u_int32_t badInt = INT_EMPTY_ENTRY;
  1224. u_int32_t badInt2 = INT_EMPTY_ENTRY2;
  1225. /*
  1226. * Hardware not available, potential interrupt hang. But since interrupt
  1227. * might be shared, just return.
  1228. */
  1229. if ((drvr_state != SBE_DRVR_AVAILABLE) || (ci->state == C_INIT))
  1230. {
  1231. #if defined(SBE_ISR_IMMEDIATE)
  1232. return 0L;
  1233. #else
  1234. return;
  1235. #endif
  1236. }
  1237. #if defined(SBE_ISR_TASKLET) || defined(SBE_ISR_IMMEDIATE)
  1238. if (drvr_state != SBE_DRVR_AVAILABLE)
  1239. {
  1240. #if defined(SBE_ISR_TASKLET)
  1241. return;
  1242. #elif defined(SBE_ISR_IMMEDIATE)
  1243. return 0L;
  1244. #endif
  1245. }
  1246. #elif defined(SBE_ISR_INLINE)
  1247. /* no semaphore taken, no double checks */
  1248. #endif
  1249. ci->intlog.drvr_intr_bhcount++;
  1250. FLUSH_MEM_READ ();
  1251. {
  1252. unsigned int bh = atomic_read (&ci->bh_pending);
  1253. max_bh = max (bh, max_bh);
  1254. }
  1255. atomic_set (&ci->bh_pending, 0);/* if here, no longer pending */
  1256. while ((headx = ci->iqp_headx) != (tailx = ci->iqp_tailx))
  1257. {
  1258. intCnt = (tailx >= headx) ? (tailx - headx) : (tailx - headx + INT_QUEUE_SIZE);
  1259. currInt = le32_to_cpu (ci->iqd_p[headx]);
  1260. max_intcnt = max (intCnt, max_intcnt); /* RLD DEBUG */
  1261. /**************************************************/
  1262. /* HW Bug Fix */
  1263. /* ---------- */
  1264. /* The following code checks for the condition */
  1265. /* of interrupt assertion before interrupt */
  1266. /* queue update. This is a problem on several */
  1267. /* PCI-Local bridge chips found on some products. */
  1268. /**************************************************/
  1269. readCount = 0;
  1270. if ((currInt == badInt) || (currInt == badInt2))
  1271. ci->intlog.drvr_int_failure++;
  1272. while ((currInt == badInt) || (currInt == badInt2))
  1273. {
  1274. for (loopCount = 0; loopCount < 0x30; loopCount++)
  1275. OS_uwait_dummy (); /* use call to avoid optimization removal
  1276. * of dummy delay */
  1277. FLUSH_MEM_READ ();
  1278. currInt = le32_to_cpu (ci->iqd_p[headx]);
  1279. if (readCount++ > 20)
  1280. break;
  1281. }
  1282. if ((currInt == badInt) || (currInt == badInt2)) /* catch failure of Bug
  1283. * Fix checking */
  1284. {
  1285. if (cxt1e1_log_level >= LOG_WARN)
  1286. pr_info("%s: Illegal Interrupt Detected @ 0x%p, mod %d.)\n",
  1287. ci->devname, &ci->iqd_p[headx], headx);
  1288. /*
  1289. * If the descriptor has not recovered, then leaving the EMPTY
  1290. * entry set will not signal to the MUSYCC that this descriptor
  1291. * has been serviced. The Interrupt Queue can then start losing
  1292. * available descriptors and MUSYCC eventually encounters and
  1293. * reports the INTFULL condition. Per manual, changing any bit
  1294. * marks descriptor as available, thus the use of different
  1295. * EMPTY_ENTRY values.
  1296. */
  1297. if (currInt == badInt)
  1298. {
  1299. ci->iqd_p[headx] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY2);
  1300. } else
  1301. {
  1302. ci->iqd_p[headx] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY);
  1303. }
  1304. ci->iqp_headx = (headx + 1) & (INT_QUEUE_SIZE - 1); /* insure wrapness */
  1305. FLUSH_MEM_WRITE ();
  1306. FLUSH_MEM_READ ();
  1307. continue;
  1308. }
  1309. group = INTRPT_GRP (currInt);
  1310. gchan = INTRPT_CH (currInt);
  1311. event = INTRPT_EVENT (currInt);
  1312. err = INTRPT_ERROR (currInt);
  1313. tx = currInt & INTRPT_DIR_M;
  1314. ci->iqd_p[headx] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY);
  1315. FLUSH_MEM_WRITE ();
  1316. if (cxt1e1_log_level >= LOG_DEBUG)
  1317. {
  1318. if (err != 0)
  1319. pr_info(" %08x -> err: %2d,", currInt, err);
  1320. pr_info("+ interrupt event: %d, grp: %d, chan: %2d, side: %cX\n",
  1321. event, group, gchan, tx ? 'T' : 'R');
  1322. }
  1323. pi = &ci->port[group]; /* notice that here we assume 1-1 group -
  1324. * port mapping */
  1325. ch = pi->chan[gchan];
  1326. switch (event)
  1327. {
  1328. case EVE_SACK: /* Service Request Acknowledge */
  1329. if (cxt1e1_log_level >= LOG_DEBUG)
  1330. {
  1331. volatile u_int32_t r;
  1332. r = pci_read_32 ((u_int32_t *) &pi->reg->srd);
  1333. pr_info("- SACK cmd: %08x (hdw= %08x)\n", pi->sr_last, r);
  1334. }
  1335. SD_SEM_GIVE (&pi->sr_sem_wait); /* wake up waiting process */
  1336. break;
  1337. case EVE_CHABT: /* Change To Abort Code (0x7e -> 0xff) */
  1338. case EVE_CHIC: /* Change To Idle Code (0xff -> 0x7e) */
  1339. break;
  1340. case EVE_EOM: /* End Of Message */
  1341. case EVE_EOB: /* End Of Buffer (Transparent mode) */
  1342. if (tx)
  1343. {
  1344. musycc_bh_tx_eom (pi, gchan);
  1345. } else
  1346. {
  1347. musycc_bh_rx_eom (pi, gchan);
  1348. }
  1349. #if 0
  1350. break;
  1351. #else
  1352. /*
  1353. * MUSYCC Interrupt Descriptor section states that EOB and EOM
  1354. * can be combined with the NONE error (as well as others). So
  1355. * drop thru to catch this...
  1356. */
  1357. #endif
  1358. case EVE_NONE:
  1359. if (err == ERR_SHT)
  1360. {
  1361. ch->s.rx_length_errors++;
  1362. }
  1363. break;
  1364. default:
  1365. if (cxt1e1_log_level >= LOG_WARN)
  1366. pr_info("%s: unexpected interrupt event: %d, iqd[%d]: %08x, port: %d\n", ci->devname,
  1367. event, headx, currInt, group);
  1368. break;
  1369. } /* switch on event */
  1370. /*
  1371. * Per MUSYCC Manual, Section 6.4.8.3 [Transmit Errors], TX errors
  1372. * are service-affecting and require action to resume normal
  1373. * bit-level processing.
  1374. */
  1375. switch (err)
  1376. {
  1377. case ERR_ONR:
  1378. /*
  1379. * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors], this
  1380. * error requires Transmit channel reactivation.
  1381. *
  1382. * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], this error
  1383. * requires Receive channel reactivation.
  1384. */
  1385. if (tx)
  1386. {
  1387. /*
  1388. * TX ONR Error only occurs when channel is configured for
  1389. * Transparent Mode. However, this code will catch and
  1390. * re-activate on ANY TX ONR error.
  1391. */
  1392. /*
  1393. * Set flag to re-enable on any next transmit attempt.
  1394. */
  1395. ch->ch_start_tx = CH_START_TX_ONR;
  1396. {
  1397. #ifdef RLD_TRANS_DEBUG
  1398. if (1 || cxt1e1_log_level >= LOG_MONITOR)
  1399. #else
  1400. if (cxt1e1_log_level >= LOG_MONITOR)
  1401. #endif
  1402. {
  1403. pr_info("%s: TX buffer underflow [ONR] on channel %d, mode %x QStopped %x free %d\n",
  1404. ci->devname, ch->channum, ch->p.chan_mode, sd_queue_stopped (ch->user), ch->txd_free);
  1405. #ifdef RLD_DEBUG
  1406. if (ch->p.chan_mode == 2) /* problem = ONR on HDLC
  1407. * mode */
  1408. {
  1409. pr_info("++ Failed Last %x Next %x QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
  1410. (u_int32_t) ch->txd_irq_srv, (u_int32_t) ch->txd_usr_add,
  1411. sd_queue_stopped (ch->user),
  1412. ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
  1413. musycc_dump_txbuffer_ring (ch, 0);
  1414. }
  1415. #endif
  1416. }
  1417. }
  1418. } else /* RX buffer overrun */
  1419. {
  1420. /*
  1421. * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors],
  1422. * channel recovery for this RX ONR error IS required. It is
  1423. * also suggested to increase the number of receive buffers
  1424. * for this channel. Receive channel reactivation IS
  1425. * required, and data has been lost.
  1426. */
  1427. ch->s.rx_over_errors++;
  1428. ch->ch_start_rx = CH_START_RX_ONR;
  1429. if (cxt1e1_log_level >= LOG_WARN)
  1430. {
  1431. pr_info("%s: RX buffer overflow [ONR] on channel %d, mode %x\n",
  1432. ci->devname, ch->channum, ch->p.chan_mode);
  1433. //musycc_dump_rxbuffer_ring (ch, 0); /* RLD DEBUG */
  1434. }
  1435. }
  1436. musycc_chan_restart (ch);
  1437. break;
  1438. case ERR_BUF:
  1439. if (tx)
  1440. {
  1441. ch->s.tx_fifo_errors++;
  1442. ch->ch_start_tx = CH_START_TX_BUF;
  1443. /*
  1444. * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors],
  1445. * this BUFF error requires Transmit channel reactivation.
  1446. */
  1447. if (cxt1e1_log_level >= LOG_MONITOR)
  1448. pr_info("%s: TX buffer underrun [BUFF] on channel %d, mode %x\n",
  1449. ci->devname, ch->channum, ch->p.chan_mode);
  1450. } else /* RX buffer overrun */
  1451. {
  1452. ch->s.rx_over_errors++;
  1453. /*
  1454. * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], HDLC
  1455. * mode requires NO recovery for this RX BUFF error is
  1456. * required. It is suggested to increase the FIFO buffer
  1457. * space for this channel. Receive channel reactivation is
  1458. * not required, but data has been lost.
  1459. */
  1460. if (cxt1e1_log_level >= LOG_WARN)
  1461. pr_info("%s: RX buffer overrun [BUFF] on channel %d, mode %x\n",
  1462. ci->devname, ch->channum, ch->p.chan_mode);
  1463. /*
  1464. * Per MUSYCC manual, Section 6.4.9.4 [Receive Errors],
  1465. * Transparent mode DOES require recovery for the RX BUFF
  1466. * error. It is suggested to increase the FIFO buffer space
  1467. * for this channel. Receive channel reactivation IS
  1468. * required and data has been lost.
  1469. */
  1470. if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
  1471. ch->ch_start_rx = CH_START_RX_BUF;
  1472. }
  1473. if (tx || (ch->p.chan_mode == CFG_CH_PROTO_TRANS))
  1474. musycc_chan_restart (ch);
  1475. break;
  1476. default:
  1477. break;
  1478. } /* switch on err */
  1479. /* Check for interrupt lost condition */
  1480. if ((currInt & INTRPT_ILOST_M) && (cxt1e1_log_level >= LOG_ERROR))
  1481. {
  1482. pr_info("%s: Interrupt queue overflow - ILOST asserted\n",
  1483. ci->devname);
  1484. }
  1485. ci->iqp_headx = (headx + 1) & (INT_QUEUE_SIZE - 1); /* insure wrapness */
  1486. FLUSH_MEM_WRITE ();
  1487. FLUSH_MEM_READ ();
  1488. } /* while */
  1489. if ((cxt1e1_log_level >= LOG_MONITOR2) && (ci->iqp_headx != ci->iqp_tailx))
  1490. {
  1491. int bh;
  1492. bh = atomic_read (&CI->bh_pending);
  1493. pr_info("_bh_: late arrivals, head %d != tail %d, pending %d\n",
  1494. ci->iqp_headx, ci->iqp_tailx, bh);
  1495. }
  1496. #if defined(SBE_ISR_IMMEDIATE)
  1497. return 0L;
  1498. #endif
  1499. /* else, nothing returned */
  1500. }
  1501. #if 0
  1502. int __init
  1503. musycc_new_chan (ci_t * ci, int channum, void *user)
  1504. {
  1505. mch_t *ch;
  1506. ch = ci->port[channum / MUSYCC_NCHANS].chan[channum % MUSYCC_NCHANS];
  1507. if (ch->state != UNASSIGNED)
  1508. return EEXIST;
  1509. /* NOTE: mch_t already cleared during OS_kmalloc() */
  1510. ch->state = DOWN;
  1511. ch->user = user;
  1512. #if 0
  1513. ch->status = 0;
  1514. ch->p.status = 0;
  1515. ch->p.intr_mask = 0;
  1516. #endif
  1517. ch->p.chan_mode = CFG_CH_PROTO_HDLC_FCS16;
  1518. ch->p.idlecode = CFG_CH_FLAG_7E;
  1519. ch->p.pad_fill_count = 2;
  1520. spin_lock_init (&ch->ch_rxlock);
  1521. spin_lock_init (&ch->ch_txlock);
  1522. return 0;
  1523. }
  1524. #endif
  1525. #ifdef SBE_PMCC4_ENABLE
  1526. status_t
  1527. musycc_chan_down (ci_t * dummy, int channum)
  1528. {
  1529. mpi_t *pi;
  1530. mch_t *ch;
  1531. int i, gchan;
  1532. if (!(ch = sd_find_chan (dummy, channum)))
  1533. return EINVAL;
  1534. pi = ch->up;
  1535. gchan = ch->gchan;
  1536. /* Deactivate the channel */
  1537. musycc_serv_req (pi, SR_CHANNEL_DEACTIVATE | SR_RX_DIRECTION | gchan);
  1538. ch->ch_start_rx = 0;
  1539. musycc_serv_req (pi, SR_CHANNEL_DEACTIVATE | SR_TX_DIRECTION | gchan);
  1540. ch->ch_start_tx = 0;
  1541. if (ch->state == DOWN)
  1542. return 0;
  1543. ch->state = DOWN;
  1544. pi->regram->thp[gchan] = 0;
  1545. pi->regram->tmp[gchan] = 0;
  1546. pi->regram->rhp[gchan] = 0;
  1547. pi->regram->rmp[gchan] = 0;
  1548. FLUSH_MEM_WRITE ();
  1549. for (i = 0; i < ch->txd_num; i++)
  1550. {
  1551. if (ch->mdt[i].mem_token != 0)
  1552. OS_mem_token_free (ch->mdt[i].mem_token);
  1553. }
  1554. for (i = 0; i < ch->rxd_num; i++)
  1555. {
  1556. if (ch->mdr[i].mem_token != 0)
  1557. OS_mem_token_free (ch->mdr[i].mem_token);
  1558. }
  1559. OS_kfree (ch->mdr);
  1560. ch->mdr = 0;
  1561. ch->rxd_num = 0;
  1562. OS_kfree (ch->mdt);
  1563. ch->mdt = 0;
  1564. ch->txd_num = 0;
  1565. musycc_update_timeslots (pi);
  1566. c4_fifo_free (pi, ch->gchan);
  1567. pi->openchans--;
  1568. return 0;
  1569. }
  1570. #endif
  1571. int
  1572. musycc_del_chan (ci_t * ci, int channum)
  1573. {
  1574. mch_t *ch;
  1575. if ((channum < 0) || (channum >= (MUSYCC_NPORTS * MUSYCC_NCHANS))) /* sanity chk param */
  1576. return ECHRNG;
  1577. if (!(ch = sd_find_chan (ci, channum)))
  1578. return ENOENT;
  1579. if (ch->state == UP)
  1580. musycc_chan_down (ci, channum);
  1581. ch->state = UNASSIGNED;
  1582. return 0;
  1583. }
  1584. int
  1585. musycc_del_chan_stats (ci_t * ci, int channum)
  1586. {
  1587. mch_t *ch;
  1588. if (channum < 0 || channum >= (MUSYCC_NPORTS * MUSYCC_NCHANS)) /* sanity chk param */
  1589. return ECHRNG;
  1590. if (!(ch = sd_find_chan (ci, channum)))
  1591. return ENOENT;
  1592. memset (&ch->s, 0, sizeof (struct sbecom_chan_stats));
  1593. return 0;
  1594. }
  1595. int
  1596. musycc_start_xmit (ci_t * ci, int channum, void *mem_token)
  1597. {
  1598. mch_t *ch;
  1599. struct mdesc *md;
  1600. void *m2;
  1601. #if 0
  1602. unsigned long flags;
  1603. #endif
  1604. int txd_need_cnt;
  1605. u_int32_t len;
  1606. if (!(ch = sd_find_chan (ci, channum)))
  1607. return ENOENT;
  1608. if (ci->state != C_RUNNING) /* full interrupt processing available */
  1609. return EINVAL;
  1610. if (ch->state != UP)
  1611. return EINVAL;
  1612. if (!(ch->status & TX_ENABLED))
  1613. return EROFS; /* how else to flag unwritable state ? */
  1614. #ifdef RLD_TRANS_DEBUGx
  1615. if (1 || cxt1e1_log_level >= LOG_MONITOR2)
  1616. #else
  1617. if (cxt1e1_log_level >= LOG_MONITOR2)
  1618. #endif
  1619. {
  1620. pr_info("++ start_xmt[%d]: state %x start %x full %d free %d required %d stopped %x\n",
  1621. channum, ch->state, ch->ch_start_tx, ch->tx_full,
  1622. ch->txd_free, ch->txd_required, sd_queue_stopped (ch->user));
  1623. }
  1624. /***********************************************/
  1625. /** Determine total amount of data to be sent **/
  1626. /***********************************************/
  1627. m2 = mem_token;
  1628. txd_need_cnt = 0;
  1629. for (len = OS_mem_token_tlen (m2); len > 0;
  1630. m2 = (void *) OS_mem_token_next (m2))
  1631. {
  1632. if (!OS_mem_token_len (m2))
  1633. continue;
  1634. txd_need_cnt++;
  1635. len -= OS_mem_token_len (m2);
  1636. }
  1637. if (txd_need_cnt == 0)
  1638. {
  1639. if (cxt1e1_log_level >= LOG_MONITOR2)
  1640. pr_info("%s channel %d: no TX data in User buffer\n", ci->devname, channum);
  1641. OS_mem_token_free (mem_token);
  1642. return 0; /* no data to send */
  1643. }
  1644. /*************************************************/
  1645. /** Are there sufficient descriptors available? **/
  1646. /*************************************************/
  1647. if (txd_need_cnt > ch->txd_num) /* never enough descriptors for this
  1648. * large a buffer */
  1649. {
  1650. if (cxt1e1_log_level >= LOG_DEBUG)
  1651. {
  1652. pr_info("start_xmit: discarding buffer, insufficient descriptor cnt %d, need %d.\n",
  1653. ch->txd_num, txd_need_cnt + 1);
  1654. }
  1655. ch->s.tx_dropped++;
  1656. OS_mem_token_free (mem_token);
  1657. return 0;
  1658. }
  1659. #if 0
  1660. spin_lock_irqsave (&ch->ch_txlock, flags);
  1661. #endif
  1662. /************************************************************/
  1663. /** flow control the line if not enough descriptors remain **/
  1664. /************************************************************/
  1665. if (txd_need_cnt > ch->txd_free)
  1666. {
  1667. if (cxt1e1_log_level >= LOG_MONITOR2)
  1668. {
  1669. pr_info("start_xmit[%d]: EBUSY - need more descriptors, have %d of %d need %d\n",
  1670. channum, ch->txd_free, ch->txd_num, txd_need_cnt);
  1671. }
  1672. ch->tx_full = 1;
  1673. ch->txd_required = txd_need_cnt;
  1674. sd_disable_xmit (ch->user);
  1675. #if 0
  1676. spin_unlock_irqrestore (&ch->ch_txlock, flags);
  1677. #endif
  1678. return EBUSY; /* tell user to try again later */
  1679. }
  1680. /**************************************************/
  1681. /** Put the user data into MUSYCC data buffer(s) **/
  1682. /**************************************************/
  1683. m2 = mem_token;
  1684. md = ch->txd_usr_add; /* get current available descriptor */
  1685. for (len = OS_mem_token_tlen (m2); len > 0; m2 = OS_mem_token_next (m2))
  1686. {
  1687. int u = OS_mem_token_len (m2);
  1688. if (!u)
  1689. continue;
  1690. len -= u;
  1691. /*
  1692. * Enable following chunks, yet wait to enable the FIRST chunk until
  1693. * after ALL subsequent chunks are setup.
  1694. */
  1695. if (md != ch->txd_usr_add) /* not first chunk */
  1696. u |= MUSYCC_TX_OWNED; /* transfer ownership from HOST to MUSYCC */
  1697. if (len) /* not last chunk */
  1698. u |= EOBIRQ_ENABLE;
  1699. else if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
  1700. {
  1701. /*
  1702. * Per MUSYCC Ref 6.4.9 for Transparent Mode, the host must
  1703. * always clear EOMIRQ_ENABLE in every Transmit Buffer Descriptor
  1704. * (IE. don't set herein).
  1705. */
  1706. u |= EOBIRQ_ENABLE;
  1707. } else
  1708. u |= EOMIRQ_ENABLE; /* EOM, last HDLC chunk */
  1709. /* last chunk in hdlc mode */
  1710. u |= (ch->p.idlecode << IDLE_CODE);
  1711. if (ch->p.pad_fill_count)
  1712. {
  1713. #if 0
  1714. /* NOOP NOTE: u_int8_t cannot be > 0xFF */
  1715. /* sanitize pad_fill_count for maximums allowed by hardware */
  1716. if (ch->p.pad_fill_count > EXTRA_FLAGS_MASK)
  1717. ch->p.pad_fill_count = EXTRA_FLAGS_MASK;
  1718. #endif
  1719. u |= (PADFILL_ENABLE | (ch->p.pad_fill_count << EXTRA_FLAGS));
  1720. }
  1721. md->mem_token = len ? 0 : mem_token; /* Fill in mds on last
  1722. * segment, others set ZERO
  1723. * so that entire token is
  1724. * removed ONLY when ALL
  1725. * segments have been
  1726. * transmitted. */
  1727. md->data = cpu_to_le32 (OS_vtophys (OS_mem_token_data (m2)));
  1728. FLUSH_MEM_WRITE ();
  1729. md->status = cpu_to_le32 (u);
  1730. --ch->txd_free;
  1731. md = md->snext;
  1732. }
  1733. FLUSH_MEM_WRITE ();
  1734. /*
  1735. * Now transfer ownership of first chunk from HOST to MUSYCC in order to
  1736. * fire-off this XMIT.
  1737. */
  1738. ch->txd_usr_add->status |= __constant_cpu_to_le32 (MUSYCC_TX_OWNED);
  1739. FLUSH_MEM_WRITE ();
  1740. ch->txd_usr_add = md;
  1741. len = OS_mem_token_tlen (mem_token);
  1742. atomic_add (len, &ch->tx_pending);
  1743. atomic_add (len, &ci->tx_pending);
  1744. ch->s.tx_packets++;
  1745. ch->s.tx_bytes += len;
  1746. /*
  1747. * If an ONR was seen, then channel requires poking to restart
  1748. * transmission.
  1749. */
  1750. if (ch->ch_start_tx)
  1751. {
  1752. musycc_chan_restart (ch);
  1753. }
  1754. #ifdef SBE_WAN256T3_ENABLE
  1755. wan256t3_led (ci, LED_TX, LEDV_G);
  1756. #endif
  1757. return 0;
  1758. }
  1759. /*** End-of-File ***/