blob: 0bcbd8a3fc840285978d20bb1a7aae7158826ca4 [file] [log] [blame]
Daeseok Youn1dd3cdc2014-05-09 19:10:07 +09001static unsigned int max_intcnt;
2static unsigned int max_bh;
Bob Beers50ee11f2010-03-04 08:40:46 -05003
4/*-----------------------------------------------------------------------------
5 * musycc.c -
6 *
7 * Copyright (C) 2007 One Stop Systems, Inc.
8 * Copyright (C) 2003-2006 SBE, Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * For further information, contact via email: support@onestopsystems.com
21 * One Stop Systems, Inc. Escondido, California U.S.A.
22 *-----------------------------------------------------------------------------
Bob Beers50ee11f2010-03-04 08:40:46 -050023 */
24
Joe Perchese6e4d052010-05-03 11:02:44 -070025#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Bob Beers50ee11f2010-03-04 08:40:46 -050026
27#include <linux/types.h>
28#include "pmcc4_sysdep.h"
29#include <linux/kernel.h>
30#include <linux/errno.h>
31#include <linux/init.h>
32#include "sbecom_inline_linux.h"
33#include "libsbew.h"
34#include "pmcc4_private.h"
35#include "pmcc4.h"
36#include "musycc.h"
37
Bob Beers50ee11f2010-03-04 08:40:46 -050038#define sd_find_chan(ci,ch) c4_find_chan(ch)
39
40
41/*******************************************************************/
42/* global driver variables */
43extern ci_t *c4_list;
44extern int drvr_state;
Bob Beers50ee11f2010-03-04 08:40:46 -050045
Bob Beersc694ed82010-10-16 18:06:36 -040046extern int cxt1e1_max_mru;
47extern int cxt1e1_max_mtu;
Bob Beers50ee11f2010-03-04 08:40:46 -050048extern int max_rxdesc_used;
49extern int max_txdesc_used;
50extern ci_t *CI; /* dummy pointr to board ZEROE's data - DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +020051 * USAGE */
Bob Beers50ee11f2010-03-04 08:40:46 -050052
53
54/*******************************************************************/
55/* forward references */
Johan Meiring77c84b22012-11-20 19:28:48 +020056void c4_fifo_free(mpi_t *, int);
57void c4_wk_chan_restart(mch_t *);
58void musycc_bh_tx_eom(mpi_t *, int);
59int musycc_chan_up(ci_t *, int);
60status_t __init musycc_init(ci_t *);
Johan Meiring77c84b22012-11-20 19:28:48 +020061void musycc_intr_bh_tasklet(ci_t *);
62void musycc_serv_req(mpi_t *, u_int32_t);
63void musycc_update_timeslots(mpi_t *);
Bob Beers50ee11f2010-03-04 08:40:46 -050064
65/*******************************************************************/
66
Shaun Laing37ca35c2013-08-09 07:54:24 -060067static int
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +053068musycc_dump_rxbuffer_ring(mch_t *ch, int lockit)
Bob Beers50ee11f2010-03-04 08:40:46 -050069{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +090070 struct mdesc *m;
71 unsigned long flags = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -050072
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +090073 u_int32_t status;
74 int n;
Bob Beers50ee11f2010-03-04 08:40:46 -050075
Daeseok Youn79cefa52014-05-09 19:08:59 +090076#ifdef RLD_DUMP_BUFDATA
77 u_int32_t *dp;
78 int len = 0;
79#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +090080 if (lockit)
81 spin_lock_irqsave(&ch->ch_rxlock, flags);
82 if (ch->rxd_num == 0)
83 pr_info(" ZERO receive buffers allocated for this channel.");
84 else {
85 FLUSH_MEM_READ();
86 m = &ch->mdr[ch->rxix_irq_srv];
87 for (n = ch->rxd_num; n; n--) {
88 status = le32_to_cpu(m->status);
Daeseok Youn79cefa52014-05-09 19:08:59 +090089 pr_info("%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
90 (m == &ch->mdr[ch->rxix_irq_srv]) ? 'F' : ' ',
91 (unsigned long) m, n,
92 status,
93 m->data ? (status & HOST_RX_OWNED ? 'H' : 'M') : '-',
94 status & POLL_DISABLED ? 'P' : '-',
95 status & EOBIRQ_ENABLE ? 'b' : '-',
96 status & EOMIRQ_ENABLE ? 'm' : '-',
97 status & LENGTH_MASK,
98 le32_to_cpu(m->data), le32_to_cpu(m->next));
Bob Beers50ee11f2010-03-04 08:40:46 -050099#ifdef RLD_DUMP_BUFDATA
Daeseok Youn79cefa52014-05-09 19:08:59 +0900100 len = status & LENGTH_MASK;
Bob Beers50ee11f2010-03-04 08:40:46 -0500101
102#if 1
Daeseok Youn79cefa52014-05-09 19:08:59 +0900103 if (m->data && (status & HOST_RX_OWNED))
Bob Beers50ee11f2010-03-04 08:40:46 -0500104#else
Daeseok Youna38223f2014-05-09 19:09:35 +0900105 /* always dump regardless of valid RX data */
106 if (m->data)
Bob Beers50ee11f2010-03-04 08:40:46 -0500107#endif
Daeseok Youn79cefa52014-05-09 19:08:59 +0900108 {
Daeseok Youna38223f2014-05-09 19:09:35 +0900109 dp = (u_int32_t *)OS_phystov((void *)(le32_to_cpu(m->data)));
Daeseok Youn79cefa52014-05-09 19:08:59 +0900110 if (len >= 0x10)
Daeseok Youna38223f2014-05-09 19:09:35 +0900111 pr_info(" %x[%x]: %08X %08X %08X %08x\n",
112 (u_int32_t)dp, len,
113 *dp, *(dp + 1),
114 *(dp + 2), *(dp + 3));
Daeseok Youn79cefa52014-05-09 19:08:59 +0900115 else if (len >= 0x08)
Daeseok Youna38223f2014-05-09 19:09:35 +0900116 pr_info(" %x[%x]: %08X %08X\n",
117 (u_int32_t)dp, len,
Daeseok Youn79cefa52014-05-09 19:08:59 +0900118 *dp, *(dp + 1));
119 else
Daeseok Youna38223f2014-05-09 19:09:35 +0900120 pr_info(" %x[%x]: %08X\n",
121 (u_int32_t)dp,
122 len, *dp);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900123 }
124#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900125 m = m->snext;
Johan Meiringea9d1e92012-11-20 19:28:46 +0200126 }
Daeseok Youn79cefa52014-05-09 19:08:59 +0900127 }
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900128 pr_info("\n");
Bob Beers50ee11f2010-03-04 08:40:46 -0500129
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900130 if (lockit)
131 spin_unlock_irqrestore(&ch->ch_rxlock, flags);
132 return 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500133}
Bob Beers50ee11f2010-03-04 08:40:46 -0500134
Shaun Laing37ca35c2013-08-09 07:54:24 -0600135static int
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530136musycc_dump_txbuffer_ring(mch_t *ch, int lockit)
Bob Beers50ee11f2010-03-04 08:40:46 -0500137{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900138 struct mdesc *m;
139 unsigned long flags = 0;
140 u_int32_t status;
141 int n;
Daeseok Youn79cefa52014-05-09 19:08:59 +0900142#ifdef RLD_DUMP_BUFDATA
143 u_int32_t *dp;
144 int len = 0;
145#endif
Bob Beers50ee11f2010-03-04 08:40:46 -0500146
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900147 if (lockit)
148 spin_lock_irqsave(&ch->ch_txlock, flags);
149 if (ch->txd_num == 0)
150 pr_info(" ZERO transmit buffers allocated for this channel.");
151 else {
152 FLUSH_MEM_READ();
153 m = ch->txd_irq_srv;
154 for (n = ch->txd_num; n; n--) {
155 status = le32_to_cpu(m->status);
Daeseok Youn79cefa52014-05-09 19:08:59 +0900156 pr_info("%c%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
157 (m == ch->txd_usr_add) ? 'F' : ' ',
158 (m == ch->txd_irq_srv) ? 'L' : ' ',
159 (unsigned long) m, n,
160 status,
161 m->data ? (status & MUSYCC_TX_OWNED ? 'M' : 'H') : '-',
162 status & POLL_DISABLED ? 'P' : '-',
163 status & EOBIRQ_ENABLE ? 'b' : '-',
164 status & EOMIRQ_ENABLE ? 'm' : '-',
165 status & LENGTH_MASK,
166 le32_to_cpu(m->data), le32_to_cpu(m->next));
Bob Beers50ee11f2010-03-04 08:40:46 -0500167#ifdef RLD_DUMP_BUFDATA
Daeseok Youn79cefa52014-05-09 19:08:59 +0900168 len = status & LENGTH_MASK;
Bob Beers50ee11f2010-03-04 08:40:46 -0500169
Daeseok Youn79cefa52014-05-09 19:08:59 +0900170 if (m->data) {
Daeseok Youna38223f2014-05-09 19:09:35 +0900171 dp = (u_int32_t *)OS_phystov((void *)(le32_to_cpu(m->data)));
Daeseok Youn79cefa52014-05-09 19:08:59 +0900172 if (len >= 0x10)
Daeseok Youna38223f2014-05-09 19:09:35 +0900173 pr_info(" %x[%x]: %08X %08X %08X %08x\n",
174 (u_int32_t) dp, len,
175 *dp, *(dp + 1),
176 *(dp + 2), *(dp + 3));
Daeseok Youn79cefa52014-05-09 19:08:59 +0900177 else if (len >= 0x08)
Daeseok Youna38223f2014-05-09 19:09:35 +0900178 pr_info(" %x[%x]: %08X %08X\n",
179 (u_int32_t)dp, len,
Daeseok Youn79cefa52014-05-09 19:08:59 +0900180 *dp, *(dp + 1));
181 else
Daeseok Youna38223f2014-05-09 19:09:35 +0900182 pr_info(" %x[%x]: %08X\n",
183 (u_int32_t)dp, len, *dp);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900184 }
Daeseok Youn79cefa52014-05-09 19:08:59 +0900185#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900186 m = m->snext;
187 }
188 } /* -for- */
189 pr_info("\n");
Bob Beers50ee11f2010-03-04 08:40:46 -0500190
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900191 if (lockit)
192 spin_unlock_irqrestore(&ch->ch_txlock, flags);
193 return 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500194}
Bob Beers50ee11f2010-03-04 08:40:46 -0500195
196/*
197 * The following supports a backdoor debug facility which can be used to
198 * display the state of a board's channel.
199 */
200
201status_t
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530202musycc_dump_ring(ci_t *ci, unsigned int chan)
Bob Beers50ee11f2010-03-04 08:40:46 -0500203{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900204 mch_t *ch;
Daeseok Youn79cefa52014-05-09 19:08:59 +0900205 int bh;
Bob Beers50ee11f2010-03-04 08:40:46 -0500206
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900207 if (chan >= MAX_CHANS_USED)
208 return SBE_DRVR_FAIL; /* E2BIG */
Bob Beers50ee11f2010-03-04 08:40:46 -0500209
Daeseok Youn79cefa52014-05-09 19:08:59 +0900210 bh = atomic_read(&ci->bh_pending);
211 pr_info(">> bh_pend %d [%d] ihead %d itail %d [%d] th_cnt %d bh_cnt %d wdcnt %d note %d\n",
212 bh, max_bh, ci->iqp_headx, ci->iqp_tailx, max_intcnt,
213 ci->intlog.drvr_intr_thcount,
214 ci->intlog.drvr_intr_bhcount,
215 ci->wdcount, ci->wd_notify);
216 max_bh = 0; /* reset counter */
217 max_intcnt = 0; /* reset counter */
Bob Beers50ee11f2010-03-04 08:40:46 -0500218
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900219 ch = sd_find_chan(dummy, chan);
220 if (!ch) {
221 pr_info(">> musycc_dump_ring: channel %d not up.\n", chan);
222 return ENOENT;
223 }
Daeseok Youna38223f2014-05-09 19:09:35 +0900224 pr_info(">> CI %p CHANNEL %3d @ %p: state %x status/p %x/%x\n",
225 ci, chan, ch, ch->state,
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900226 ch->status, ch->p.status);
Daeseok Youna38223f2014-05-09 19:09:35 +0900227 pr_info("--------------------------------\n");
228 pr_info("TX Buffer Ring - Channel %d, txd_num %d. (bd/ch pend %d %d), TXD required %d, txpkt %lu\n",
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900229 chan, ch->txd_num,
Daeseok Youna38223f2014-05-09 19:09:35 +0900230 (u_int32_t)atomic_read(&ci->tx_pending),
231 (u_int32_t)atomic_read(&ch->tx_pending),
232 ch->txd_required, ch->s.tx_packets);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900233 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",
234 ch->user, ch->txd_irq_srv, ch->txd_usr_add,
235 sd_queue_stopped(ch->user),
236 ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
237 musycc_dump_txbuffer_ring(ch, 1);
238 pr_info("RX Buffer Ring - Channel %d, rxd_num %d. IRQ_SRV[%d] 0x%p, start_rx %x rxpkt %lu\n",
239 chan, ch->rxd_num, ch->rxix_irq_srv,
240 &ch->mdr[ch->rxix_irq_srv], ch->ch_start_rx, ch->s.rx_packets);
241 musycc_dump_rxbuffer_ring(ch, 1);
Bob Beers50ee11f2010-03-04 08:40:46 -0500242
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900243 return SBE_DRVR_SUCCESS;
Bob Beers50ee11f2010-03-04 08:40:46 -0500244}
245
246
247status_t
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530248musycc_dump_rings(ci_t *ci, unsigned int start_chan)
Bob Beers50ee11f2010-03-04 08:40:46 -0500249{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900250 unsigned int chan;
Bob Beers50ee11f2010-03-04 08:40:46 -0500251
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900252 for (chan = start_chan; chan < (start_chan + 5); chan++)
253 musycc_dump_ring(ci, chan);
254 return SBE_DRVR_SUCCESS;
Bob Beers50ee11f2010-03-04 08:40:46 -0500255}
256
257
258/*
259 * NOTE on musycc_init_mdt(): These MUSYCC writes are only operational after
260 * a MUSYCC GROUP_INIT command has been issued.
261 */
262
263void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530264musycc_init_mdt(mpi_t *pi)
Bob Beers50ee11f2010-03-04 08:40:46 -0500265{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900266 u_int32_t *addr, cfg;
267 int i;
Bob Beers50ee11f2010-03-04 08:40:46 -0500268
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900269 /*
270 * This Idle Code insertion takes effect prior to channel's first
271 * transmitted message. After that, each message contains its own Idle
272 * Code information which is to be issued after the message is
273 * transmitted (Ref.MUSYCC 5.2.2.3: MCENBL bit in Group Configuration
274 * Descriptor).
275 */
Bob Beers50ee11f2010-03-04 08:40:46 -0500276
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900277 addr = (u_int32_t *) ((u_long) pi->reg + MUSYCC_MDT_BASE03_ADDR);
278 cfg = CFG_CH_FLAG_7E << IDLE_CODE;
Bob Beers50ee11f2010-03-04 08:40:46 -0500279
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900280 for (i = 0; i < 32; addr++, i++)
281 pci_write_32(addr, cfg);
Bob Beers50ee11f2010-03-04 08:40:46 -0500282}
283
284
285/* Set TX thp to the next unprocessed md */
286
287void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530288musycc_update_tx_thp(mch_t *ch)
Bob Beers50ee11f2010-03-04 08:40:46 -0500289{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900290 struct mdesc *md;
291 unsigned long flags;
Bob Beers50ee11f2010-03-04 08:40:46 -0500292
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900293 spin_lock_irqsave(&ch->ch_txlock, flags);
294 while (1) {
295 md = ch->txd_irq_srv;
296 FLUSH_MEM_READ();
297 if (!md->data) {
298 /* No MDs with buffers to process */
299 spin_unlock_irqrestore(&ch->ch_txlock, flags);
300 return;
301 }
302 if ((le32_to_cpu(md->status)) & MUSYCC_TX_OWNED) {
303 /* this is the MD to restart TX with */
304 break;
305 }
306 /*
307 * Otherwise, we have a valid, host-owned message descriptor which
308 * has been successfully transmitted and whose buffer can be freed,
309 * so... process this MD, it's owned by the host. (This might give
310 * as a new, updated txd_irq_srv.)
311 */
312 musycc_bh_tx_eom(ch->up, ch->gchan);
313 }
Johan Meiringea9d1e92012-11-20 19:28:46 +0200314 md = ch->txd_irq_srv;
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900315 ch->up->regram->thp[ch->gchan] = cpu_to_le32(OS_vtophys(md));
316 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500317
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900318 if (ch->tx_full) {
319 ch->tx_full = 0;
320 ch->txd_required = 0;
321 sd_enable_xmit(ch->user); /* re-enable to catch flow controlled
322 * channel */
323 }
324 spin_unlock_irqrestore(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -0500325
326#ifdef RLD_TRANS_DEBUG
Daeseok Youna38223f2014-05-09 19:09:35 +0900327 pr_info("++ musycc_update_tx_thp[%d]: setting thp = %p, sts %x\n",
328 ch->channum, md, md->status);
Bob Beers50ee11f2010-03-04 08:40:46 -0500329#endif
330}
331
332
Bob Beers50ee11f2010-03-04 08:40:46 -0500333/*
334 * This is the workq task executed by the OS when our queue_work() is
335 * scheduled and run. It can fire off either RX or TX ACTIVATION depending
336 * upon the channel's ch_start_tx and ch_start_rx variables. This routine
337 * is implemented as a work queue so that the call to the service request is
338 * able to sleep, awaiting an interrupt acknowledgment response (SACK) from
339 * the hardware.
340 */
341
342void
Johan Meiring77c84b22012-11-20 19:28:48 +0200343musycc_wq_chan_restart(void *arg) /* channel private structure */
Bob Beers50ee11f2010-03-04 08:40:46 -0500344{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900345 mch_t *ch;
346 mpi_t *pi;
347 struct mdesc *md;
Bob Beers50ee11f2010-03-04 08:40:46 -0500348
Daeseok Youn79cefa52014-05-09 19:08:59 +0900349#if defined(RLD_TRANS_DEBUG) || defined(RLD_RXACT_DEBUG)
350 static int hereb4 = 7;
351#endif
352
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900353 ch = container_of(arg, struct c4_chan_info, ch_work);
354 pi = ch->up;
Bob Beers50ee11f2010-03-04 08:40:46 -0500355
356#ifdef RLD_TRANS_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900357 pr_info("wq_chan_restart[%d]: start_RT[%d/%d] status %x\n",
358 ch->channum, ch->ch_start_rx, ch->ch_start_tx, ch->status);
Bob Beers50ee11f2010-03-04 08:40:46 -0500359
360#endif
361
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900362 /**********************************/
363 /** check for RX restart request **/
364 /**********************************/
Bob Beers50ee11f2010-03-04 08:40:46 -0500365
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900366 if ((ch->ch_start_rx) && (ch->status & RX_ENABLED)) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500367
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900368 ch->ch_start_rx = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500369#if defined(RLD_TRANS_DEBUG) || defined(RLD_RXACT_DEBUG)
Daeseok Youn79cefa52014-05-09 19:08:59 +0900370 if (hereb4) { /* RLD DEBUG */
371 hereb4--;
Bob Beers50ee11f2010-03-04 08:40:46 -0500372#ifdef RLD_TRANS_DEBUG
Daeseok Youn79cefa52014-05-09 19:08:59 +0900373 md = &ch->mdr[ch->rxix_irq_srv];
374 pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
Daeseok Youna38223f2014-05-09 19:09:35 +0900375 ch->channum, ch->rxix_irq_srv, md,
376 le32_to_cpu(md->status), ch->s.rx_packets);
Bob Beers50ee11f2010-03-04 08:40:46 -0500377#elif defined(RLD_RXACT_DEBUG)
Daeseok Youn79cefa52014-05-09 19:08:59 +0900378 md = &ch->mdr[ch->rxix_irq_srv];
379 pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
Daeseok Youna38223f2014-05-09 19:09:35 +0900380 ch->channum, ch->rxix_irq_srv,
381 md, le32_to_cpu(md->status),
Daeseok Youn79cefa52014-05-09 19:08:59 +0900382 ch->s.rx_packets);
383 musycc_dump_rxbuffer_ring(ch, 1); /* RLD DEBUG */
Bob Beers50ee11f2010-03-04 08:40:46 -0500384#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900385 }
386#endif
Daeseok Youna38223f2014-05-09 19:09:35 +0900387 musycc_serv_req(pi, SR_CHANNEL_ACTIVATE |
388 SR_RX_DIRECTION | ch->gchan);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200389 }
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900390 /**********************************/
391 /** check for TX restart request **/
392 /**********************************/
Bob Beers50ee11f2010-03-04 08:40:46 -0500393
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900394 if ((ch->ch_start_tx) && (ch->status & TX_ENABLED)) {
395 /* find next unprocessed message, then set TX thp to it */
396 musycc_update_tx_thp(ch);
Bob Beers50ee11f2010-03-04 08:40:46 -0500397
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900398 md = ch->txd_irq_srv;
399 if (!md) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500400#ifdef RLD_TRANS_DEBUG
Daeseok Youna38223f2014-05-09 19:09:35 +0900401 pr_info("-- musycc_wq_chan_restart[%d]: WARNING, starting NULL md\n",
402 ch->channum);
Bob Beers50ee11f2010-03-04 08:40:46 -0500403#endif
Daeseok Youna38223f2014-05-09 19:09:35 +0900404 } else if (md->data && ((le32_to_cpu(md->status)) &
405 MUSYCC_TX_OWNED)) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900406 ch->ch_start_tx = 0;
Daeseok Younb7923d22014-05-09 23:54:08 +0900407
Bob Beers50ee11f2010-03-04 08:40:46 -0500408#ifdef RLD_TRANS_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900409 pr_info("++ musycc_wq_chan_restart() CHAN TX ACTIVATE: chan %d txd_irq_srv %p = sts %x, txpkt %lu\n",
Daeseok Youna38223f2014-05-09 19:09:35 +0900410 ch->channum, ch->txd_irq_srv,
411 ch->txd_irq_srv->status, ch->s.tx_packets);
Bob Beers50ee11f2010-03-04 08:40:46 -0500412#endif
Daeseok Youna38223f2014-05-09 19:09:35 +0900413 musycc_serv_req(pi, SR_CHANNEL_ACTIVATE |
414 SR_TX_DIRECTION | ch->gchan);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900415 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500416#ifdef RLD_RESTART_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900417 else {
418 /* retain request to start until retried and we have data to xmit */
419 pr_info("-- musycc_wq_chan_restart[%d]: DELAYED due to md %p sts %x data %x, start_tx %x\n",
420 ch->channum, md,
421 le32_to_cpu(md->status),
422 le32_to_cpu(md->data), ch->ch_start_tx);
423 musycc_dump_txbuffer_ring(ch, 0);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900424 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500425#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200426 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500427}
Bob Beers50ee11f2010-03-04 08:40:46 -0500428
429
430 /*
431 * Channel restart either fires of a workqueue request (2.6) or lodges a
432 * watchdog activation sequence (2.4).
433 */
434
435void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530436musycc_chan_restart(mch_t *ch)
Bob Beers50ee11f2010-03-04 08:40:46 -0500437{
438#ifdef RLD_RESTART_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900439 pr_info("++ musycc_chan_restart[%d]: txd_irq_srv @ %p = sts %x\n",
440 ch->channum, ch->txd_irq_srv, ch->txd_irq_srv->status);
Bob Beers50ee11f2010-03-04 08:40:46 -0500441#endif
442
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900443 /* 2.6 - find next unprocessed message, then set TX thp to it */
Bob Beers50ee11f2010-03-04 08:40:46 -0500444#ifdef RLD_RESTART_DEBUG
Daeseok Youna38223f2014-05-09 19:09:35 +0900445 pr_info(">> musycc_chan_restart: scheduling Chan %x workQ @ %p\n",
446 ch->channum, &ch->ch_work);
Bob Beers50ee11f2010-03-04 08:40:46 -0500447#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900448 c4_wk_chan_restart(ch); /* work queue mechanism fires off: Ref:
449 * musycc_wq_chan_restart () */
Bob Beers50ee11f2010-03-04 08:40:46 -0500450}
451
452
Bob Beers50ee11f2010-03-04 08:40:46 -0500453void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530454rld_put_led(mpi_t *pi, u_int32_t ledval)
Bob Beers50ee11f2010-03-04 08:40:46 -0500455{
Daeseok Youn1dd3cdc2014-05-09 19:10:07 +0900456 static u_int32_t led;
Bob Beers50ee11f2010-03-04 08:40:46 -0500457
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900458 if (ledval == 0)
459 led = 0;
460 else
461 led |= ledval;
Bob Beers50ee11f2010-03-04 08:40:46 -0500462
Daeseok Youna38223f2014-05-09 19:09:35 +0900463 /* RLD DEBUG TRANHANG */
464 pci_write_32((u_int32_t *) &pi->up->cpldbase->leds, led);
Bob Beers50ee11f2010-03-04 08:40:46 -0500465}
466
467
468#define MUSYCC_SR_RETRY_CNT 9
469
470void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530471musycc_serv_req(mpi_t *pi, u_int32_t req)
Bob Beers50ee11f2010-03-04 08:40:46 -0500472{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900473 volatile u_int32_t r;
474 int rcnt;
Bob Beers50ee11f2010-03-04 08:40:46 -0500475
Johan Meiringea9d1e92012-11-20 19:28:46 +0200476 /*
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900477 * PORT NOTE: Semaphore protect service loop guarantees only a single
478 * operation at a time. Per MUSYCC Manual - "Issuing service requests to
479 * the same channel group without first receiving ACK from each request
480 * may cause the host to lose track of which service request has been
481 * acknowledged."
Johan Meiringea9d1e92012-11-20 19:28:46 +0200482 */
Bob Beers50ee11f2010-03-04 08:40:46 -0500483
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900484 SD_SEM_TAKE(&pi->sr_sem_busy, "serv"); /* only 1 thru here, per
485 * group */
486
487 if (pi->sr_last == req) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500488#ifdef RLD_TRANS_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900489 pr_info(">> same SR, Port %d Req %x\n", pi->portnum, req);
Bob Beers50ee11f2010-03-04 08:40:46 -0500490#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900491
492 /*
493 * The most likely repeated request is the channel activation command
494 * which follows the occurrence of a Transparent mode TX ONR or a
495 * BUFF error. If the previous command was a CHANNEL ACTIVATE,
496 * precede it with a NOOP command in order maintain coherent control
497 * of this current (re)ACTIVATE.
498 */
499
500 r = (pi->sr_last & ~SR_GCHANNEL_MASK);
501 if ((r == (SR_CHANNEL_ACTIVATE | SR_TX_DIRECTION)) ||
502 (r == (SR_CHANNEL_ACTIVATE | SR_RX_DIRECTION))) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500503#ifdef RLD_TRANS_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900504 pr_info(">> same CHAN ACT SR, Port %d Req %x => issue SR_NOOP CMD\n", pi->portnum, req);
Bob Beers50ee11f2010-03-04 08:40:46 -0500505#endif
Daeseok Youna38223f2014-05-09 19:09:35 +0900506 /* allow this next request */
507 SD_SEM_GIVE(&pi->sr_sem_busy);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900508 musycc_serv_req(pi, SR_NOOP);
Daeseok Youna38223f2014-05-09 19:09:35 +0900509 /* relock & continue w/ original req */
510 SD_SEM_TAKE(&pi->sr_sem_busy, "serv");
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900511 } else if (req == SR_NOOP) {
Daeseok Youna38223f2014-05-09 19:09:35 +0900512 /* no need to issue back-to-back
513 * SR_NOOP commands at this time
514 */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900515#ifdef RLD_TRANS_DEBUG
Daeseok Youna38223f2014-05-09 19:09:35 +0900516 pr_info(">> same Port SR_NOOP skipped, Port %d\n",
517 pi->portnum);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900518#endif
Daeseok Youna38223f2014-05-09 19:09:35 +0900519 /* allow this next request */
520 SD_SEM_GIVE(&pi->sr_sem_busy);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900521 return;
522 }
Johan Meiringea9d1e92012-11-20 19:28:46 +0200523 }
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900524 rcnt = 0;
525 pi->sr_last = req;
Bob Beers50ee11f2010-03-04 08:40:46 -0500526rewrite:
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900527 pci_write_32((u_int32_t *) &pi->reg->srd, req);
528 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500529
Johan Meiringea9d1e92012-11-20 19:28:46 +0200530 /*
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900531 * Per MUSYCC Manual, Section 6.1,2 - "When writing an SCR service
532 * request, the host must ensure at least one PCI bus clock cycle has
533 * elapsed before writing another service request. To meet this minimum
534 * elapsed service request write timing interval, it is recommended that
535 * the host follow any SCR write with another operation which reads from
536 * the same address."
Johan Meiringea9d1e92012-11-20 19:28:46 +0200537 */
Daeseok Youna38223f2014-05-09 19:09:35 +0900538
539 /* adhere to write timing imposition */
540 r = pci_read_32((u_int32_t *) &pi->reg->srd);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900541
542
Daeseok Youna38223f2014-05-09 19:09:35 +0900543 if ((r != req) && (req != SR_CHIP_RESET) &&
544 (++rcnt <= MUSYCC_SR_RETRY_CNT)) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900545 if (cxt1e1_log_level >= LOG_MONITOR)
546 pr_info("%s: %d - reissue srv req/last %x/%x (hdw reads %x), Chan %d.\n",
547 pi->up->devname, rcnt, req, pi->sr_last, r,
548 (pi->portnum * MUSYCC_NCHANS) + (req & 0x1f));
Daeseok Youna38223f2014-05-09 19:09:35 +0900549 /* this delay helps reduce reissue counts
550 * (reason not yet researched)
551 */
552 OS_uwait_dummy();
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900553 goto rewrite;
554 }
555 if (rcnt > MUSYCC_SR_RETRY_CNT) {
556 pr_warning("%s: failed service request (#%d)= %x, group %d.\n",
Daeseok Youna38223f2014-05-09 19:09:35 +0900557 pi->up->devname, MUSYCC_SR_RETRY_CNT,
558 req, pi->portnum);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900559 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow any next request */
560 return;
561 }
562 if (req == SR_CHIP_RESET) {
563 /*
564 * PORT NOTE: the CHIP_RESET command is NOT ack'd by the MUSYCC, thus
565 * the upcoming delay is used. Though the MUSYCC documentation
566 * suggests a read-after-write would supply the required delay, it's
567 * unclear what CPU/BUS clock speeds might have been assumed when
568 * suggesting this 'lack of ACK' workaround. Thus the use of uwait.
569 */
570 OS_uwait(100000, "icard"); /* 100ms */
571 } else {
572 FLUSH_MEM_READ();
Daeseok Youna38223f2014-05-09 19:09:35 +0900573 /* sleep until SACK interrupt occurs */
574 SD_SEM_TAKE(&pi->sr_sem_wait, "sakack");
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900575 }
576 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow any next request */
Bob Beers50ee11f2010-03-04 08:40:46 -0500577}
578
579
580#ifdef SBE_PMCC4_ENABLE
581void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530582musycc_update_timeslots(mpi_t *pi)
Bob Beers50ee11f2010-03-04 08:40:46 -0500583{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900584 int i, ch;
585 char e1mode = IS_FRAME_ANY_E1(pi->p.port_mode);
Bob Beers50ee11f2010-03-04 08:40:46 -0500586
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900587 for (i = 0; i < 32; i++) {
588 int usedby = 0, last = 0, ts, j, bits[8];
Bob Beers50ee11f2010-03-04 08:40:46 -0500589
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900590 u_int8_t lastval = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500591
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900592 if (((i == 0) && e1mode) || /* disable if E1 mode */
Daeseok Youna38223f2014-05-09 19:09:35 +0900593 ((i == 16) && ((pi->p.port_mode == CFG_FRAME_E1CRC_CAS) ||
594 (pi->p.port_mode == CFG_FRAME_E1CRC_CAS_AMI))) ||
595 ((i > 23) && (!e1mode))) /* disable if T1 mode */
596 /* make tslot unavailable for this mode */
597 pi->tsm[i] = 0xff;
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900598 else
Daeseok Youna38223f2014-05-09 19:09:35 +0900599 /* make tslot available for assignment */
600 pi->tsm[i] = 0x00;
Johan Meiringea9d1e92012-11-20 19:28:46 +0200601 for (j = 0; j < 8; j++)
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900602 bits[j] = -1;
603 for (ch = 0; ch < MUSYCC_NCHANS; ch++) {
Daeseok Youna38223f2014-05-09 19:09:35 +0900604 if ((pi->chan[ch]->state == UP) &&
605 (pi->chan[ch]->p.bitmask[i])) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900606 usedby++;
607 last = ch;
608 lastval = pi->chan[ch]->p.bitmask[i];
609 for (j = 0; j < 8; j++)
610 if (lastval & (1 << j))
611 bits[j] = ch;
612 pi->tsm[i] |= lastval;
613 }
614 }
615 if (!usedby)
616 ts = 0;
617 else if ((usedby == 1) && (lastval == 0xff))
618 ts = (4 << 5) | last;
619 else if ((usedby == 1) && (lastval == 0x7f))
620 ts = (5 << 5) | last;
621 else {
622 int idx;
Bob Beers50ee11f2010-03-04 08:40:46 -0500623
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900624 if (bits[0] < 0)
625 ts = (6 << 5) | (idx = last);
626 else
627 ts = (7 << 5) | (idx = bits[0]);
628 for (j = 1; j < 8; j++) {
Daeseok Youna38223f2014-05-09 19:09:35 +0900629 pi->regram->rscm[idx * 8 + j] =
630 (bits[j] < 0) ? 0 : (0x80 | bits[j]);
631 pi->regram->tscm[idx * 8 + j] =
632 (bits[j] < 0) ? 0 : (0x80 | bits[j]);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900633 }
634 }
635 pi->regram->rtsm[i] = ts;
636 pi->regram->ttsm[i] = ts;
Johan Meiringea9d1e92012-11-20 19:28:46 +0200637 }
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900638 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500639
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900640 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_RX_DIRECTION);
641 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_TX_DIRECTION);
642 musycc_serv_req(pi, SR_SUBCHANNEL_MAP | SR_RX_DIRECTION);
643 musycc_serv_req(pi, SR_SUBCHANNEL_MAP | SR_TX_DIRECTION);
Bob Beers50ee11f2010-03-04 08:40:46 -0500644}
645#endif
646
647
648#ifdef SBE_WAN256T3_ENABLE
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900649 void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530650musycc_update_timeslots(mpi_t *pi)
Bob Beers50ee11f2010-03-04 08:40:46 -0500651{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900652 mch_t *ch;
Bob Beers50ee11f2010-03-04 08:40:46 -0500653
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900654 u_int8_t ts, hmask, tsen;
655 int gchan;
656 int i;
Bob Beers50ee11f2010-03-04 08:40:46 -0500657
658#ifdef SBE_PMCC4_ENABLE
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900659 hmask = (0x1f << pi->up->p.hypersize) & 0x1f;
Bob Beers50ee11f2010-03-04 08:40:46 -0500660#endif
661#ifdef SBE_WAN256T3_ENABLE
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900662 hmask = (0x1f << hyperdummy) & 0x1f;
Bob Beers50ee11f2010-03-04 08:40:46 -0500663#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900664 for (i = 0; i < 128; i++) {
Daeseok Youna38223f2014-05-09 19:09:35 +0900665 gchan = ((pi->portnum * MUSYCC_NCHANS) +
666 (i & hmask)) % MUSYCC_NCHANS;
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900667 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);
Bob Beers50ee11f2010-03-04 08:40:46 -0500679}
680#endif
681
682
683 /*
684 * This routine converts a generic library channel configuration parameter
685 * into a hardware specific register value (IE. MUSYCC CCD Register).
686 */
687u_int32_t
Johan Meiring77c84b22012-11-20 19:28:48 +0200688musycc_chan_proto(int proto)
Bob Beers50ee11f2010-03-04 08:40:46 -0500689{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900690 int reg;
Bob Beers50ee11f2010-03-04 08:40:46 -0500691
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900692 switch (proto) {
693 case CFG_CH_PROTO_TRANS: /* 0 */
694 reg = MUSYCC_CCD_TRANS;
695 break;
696 case CFG_CH_PROTO_SS7: /* 1 */
697 reg = MUSYCC_CCD_SS7;
698 break;
699 default:
700 case CFG_CH_PROTO_ISLP_MODE: /* 4 */
701 case CFG_CH_PROTO_HDLC_FCS16: /* 2 */
702 reg = MUSYCC_CCD_HDLC_FCS16;
703 break;
704 case CFG_CH_PROTO_HDLC_FCS32: /* 3 */
705 reg = MUSYCC_CCD_HDLC_FCS32;
706 break;
707 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500708
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900709 return reg;
Bob Beers50ee11f2010-03-04 08:40:46 -0500710}
711
712#ifdef SBE_WAN256T3_ENABLE
Shaun Laing37ca35c2013-08-09 07:54:24 -0600713static void __init
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530714musycc_init_port(mpi_t *pi)
Bob Beers50ee11f2010-03-04 08:40:46 -0500715{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900716 pci_write_32((u_int32_t *) &pi->reg->gbp, OS_vtophys(pi->regram));
Bob Beers50ee11f2010-03-04 08:40:46 -0500717
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900718 pi->regram->grcd =
719 __constant_cpu_to_le32(MUSYCC_GRCD_RX_ENABLE |
720 MUSYCC_GRCD_TX_ENABLE |
721 MUSYCC_GRCD_SF_ALIGN |
722 MUSYCC_GRCD_SUBCHAN_DISABLE |
723 MUSYCC_GRCD_OOFMP_DISABLE |
724 MUSYCC_GRCD_COFAIRQ_DISABLE |
725 MUSYCC_GRCD_MC_ENABLE |
726 (MUSYCC_GRCD_POLLTH_32 << MUSYCC_GRCD_POLLTH_SHIFT));
Bob Beers50ee11f2010-03-04 08:40:46 -0500727
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900728 pi->regram->pcd =
729 __constant_cpu_to_le32(MUSYCC_PCD_E1X4_MODE |
730 MUSYCC_PCD_TXDATA_RISING |
731 MUSYCC_PCD_TX_DRIVEN);
Bob Beers50ee11f2010-03-04 08:40:46 -0500732
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900733 /* Message length descriptor */
734 pi->regram->mld = __constant_cpu_to_le32(cxt1e1_max_mru | (cxt1e1_max_mru << 16));
735 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500736
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900737 musycc_serv_req(pi, SR_GROUP_INIT | SR_RX_DIRECTION);
738 musycc_serv_req(pi, SR_GROUP_INIT | SR_TX_DIRECTION);
Bob Beers50ee11f2010-03-04 08:40:46 -0500739
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900740 musycc_init_mdt(pi);
Bob Beers50ee11f2010-03-04 08:40:46 -0500741
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900742 musycc_update_timeslots(pi);
Bob Beers50ee11f2010-03-04 08:40:46 -0500743}
744#endif
745
746
747status_t __init
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530748musycc_init(ci_t *ci)
Bob Beers50ee11f2010-03-04 08:40:46 -0500749{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900750 char *regaddr; /* temp for address boundary calculations */
751 int i, gchan;
Bob Beers50ee11f2010-03-04 08:40:46 -0500752
Daeseok Youna38223f2014-05-09 19:09:35 +0900753 OS_sem_init(&ci->sem_wdbusy, SEM_AVAILABLE); /* watchdog exclusion */
Bob Beers50ee11f2010-03-04 08:40:46 -0500754
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900755 /*
756 * Per MUSYCC manual, Section 6.3.4 - "The host must allocate a dword
757 * aligned memory segment for interrupt queue pointers."
758 */
Bob Beers50ee11f2010-03-04 08:40:46 -0500759
760#define INT_QUEUE_BOUNDARY 4
761
Daeseok Youn693d9632014-04-18 09:31:35 +0900762 regaddr = kzalloc((INT_QUEUE_SIZE + 1) * sizeof(u_int32_t),
763 GFP_KERNEL | GFP_DMA);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900764 if (!regaddr)
765 return -ENOMEM;
766 ci->iqd_p_saved = regaddr; /* save orig value for free's usage */
Daeseok Youna38223f2014-05-09 19:09:35 +0900767 /* this calculates closest boundary */
768 ci->iqd_p = (u_int32_t *) ((unsigned long)(regaddr + INT_QUEUE_BOUNDARY - 1) &
769 (~(INT_QUEUE_BOUNDARY - 1)));
Bob Beers50ee11f2010-03-04 08:40:46 -0500770
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900771 for (i = 0; i < INT_QUEUE_SIZE; i++)
772 ci->iqd_p[i] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
Bob Beers50ee11f2010-03-04 08:40:46 -0500773
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900774 for (i = 0; i < ci->max_port; i++) {
775 mpi_t *pi = &ci->port[i];
Bob Beers50ee11f2010-03-04 08:40:46 -0500776
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900777 /*
778 * Per MUSYCC manual, Section 6.3.2 - "The host must allocate a 2KB
779 * bound memory segment for Channel Group 0."
780 */
Bob Beers50ee11f2010-03-04 08:40:46 -0500781
782#define GROUP_BOUNDARY 0x800
783
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900784 regaddr = kzalloc(sizeof(struct musycc_groupr) + GROUP_BOUNDARY,
785 GFP_KERNEL | GFP_DMA);
786 if (!regaddr) {
787 for (gchan = 0; gchan < i; gchan++) {
788 pi = &ci->port[gchan];
789 kfree(pi->reg);
790 pi->reg = NULL;
791 }
792 return -ENOMEM;
793 }
794 pi->regram_saved = regaddr; /* save orig value for free's usage */
Daeseok Youna38223f2014-05-09 19:09:35 +0900795 /* this calculates closest boundary */
796 pi->regram = (struct musycc_groupr *) ((unsigned long)(regaddr + GROUP_BOUNDARY - 1) &
797 (~(GROUP_BOUNDARY - 1)));
Johan Meiringea9d1e92012-11-20 19:28:46 +0200798 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500799
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900800 /* any board centric MUSYCC commands will use group ZERO as its "home" */
801 ci->regram = ci->port[0].regram;
802 musycc_serv_req(&ci->port[0], SR_CHIP_RESET);
Bob Beers50ee11f2010-03-04 08:40:46 -0500803
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900804 pci_write_32((u_int32_t *) &ci->reg->gbp, OS_vtophys(ci->regram));
805 pci_flush_write(ci);
Bob Beers50ee11f2010-03-04 08:40:46 -0500806#ifdef CONFIG_SBE_PMCC4_NCOMM
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900807 ci->regram->__glcd = __constant_cpu_to_le32(GCD_MAGIC);
Bob Beers50ee11f2010-03-04 08:40:46 -0500808#else
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900809 /* standard driver POLLS for INTB via CPLD register */
Daeseok Youna38223f2014-05-09 19:09:35 +0900810 ci->regram->__glcd = __constant_cpu_to_le32(GCD_MAGIC |
811 MUSYCC_GCD_INTB_DISABLE);
Bob Beers50ee11f2010-03-04 08:40:46 -0500812#endif
813
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900814 ci->regram->__iqp = cpu_to_le32(OS_vtophys(&ci->iqd_p[0]));
815 ci->regram->__iql = __constant_cpu_to_le32(INT_QUEUE_SIZE - 1);
816 pci_write_32((u_int32_t *) &ci->reg->dacbp, 0);
817 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500818
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900819 ci->state = C_RUNNING; /* mark as full interrupt processing
820 * available */
Bob Beers50ee11f2010-03-04 08:40:46 -0500821
Daeseok Youna38223f2014-05-09 19:09:35 +0900822 musycc_serv_req(&ci->port[0], SR_GLOBAL_INIT); /* FIRST INTERRUPT ! */
Bob Beers50ee11f2010-03-04 08:40:46 -0500823
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900824 /* sanity check settable parameters */
Bob Beers50ee11f2010-03-04 08:40:46 -0500825
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900826 if (cxt1e1_max_mru > 0xffe) {
827 pr_warning("Maximum allowed MRU exceeded, resetting %d to %d.\n",
828 cxt1e1_max_mru, 0xffe);
829 cxt1e1_max_mru = 0xffe;
830 }
831 if (cxt1e1_max_mtu > 0xffe) {
832 pr_warning("Maximum allowed MTU exceeded, resetting %d to %d.\n",
833 cxt1e1_max_mtu, 0xffe);
834 cxt1e1_max_mtu = 0xffe;
835 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500836#ifdef SBE_WAN256T3_ENABLE
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900837 for (i = 0; i < MUSYCC_NPORTS; i++)
838 musycc_init_port(&ci->port[i]);
Bob Beers50ee11f2010-03-04 08:40:46 -0500839#endif
840
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900841 return SBE_DRVR_SUCCESS; /* no error */
Bob Beers50ee11f2010-03-04 08:40:46 -0500842}
843
844
845void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +0530846musycc_bh_tx_eom(mpi_t *pi, int gchan)
Bob Beers50ee11f2010-03-04 08:40:46 -0500847{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900848 mch_t *ch;
849 struct mdesc *md;
Bob Beers50ee11f2010-03-04 08:40:46 -0500850
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900851 volatile u_int32_t status;
Bob Beers50ee11f2010-03-04 08:40:46 -0500852
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900853 ch = pi->chan[gchan];
854 if (!ch || ch->state != UP) {
855 if (cxt1e1_log_level >= LOG_ERROR)
856 pr_info("%s: intr: xmit EOM on uninitialized channel %d\n",
857 pi->up->devname, gchan);
858 }
859 if (!ch || !ch->mdt)
860 return; /* note: mdt==0 implies a malloc()
861 * failure w/in chan_up() routine */
Bob Beers50ee11f2010-03-04 08:40:46 -0500862
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900863 do {
Johan Meiring77c84b22012-11-20 19:28:48 +0200864 FLUSH_MEM_READ();
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900865 md = ch->txd_irq_srv;
Johan Meiring77c84b22012-11-20 19:28:48 +0200866 status = le32_to_cpu(md->status);
Bob Beers50ee11f2010-03-04 08:40:46 -0500867
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900868 /*
869 * Note: Per MUSYCC Ref 6.4.9, the host does not poll a host-owned
870 * Transmit Buffer Descriptor during Transparent Mode.
871 */
872 if (status & MUSYCC_TX_OWNED) {
873 int readCount, loopCount;
874
875 /***********************************************************/
876 /* HW Bug Fix */
877 /* ---------- */
878 /* Under certain PCI Bus loading conditions, the data */
879 /* associated with an update of Shared Memory is delayed */
880 /* relative to its PCI Interrupt. This is caught when */
881 /* the host determines it does not yet OWN the descriptor. */
882 /***********************************************************/
883
884 readCount = 0;
885 while (status & MUSYCC_TX_OWNED) {
886 for (loopCount = 0; loopCount < 0x30; loopCount++)
Daeseok Youna38223f2014-05-09 19:09:35 +0900887 /* use call to avoid optimization
888 * removal of dummy delay */
889 OS_uwait_dummy();
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900890 FLUSH_MEM_READ();
891 status = le32_to_cpu(md->status);
892 if (readCount++ > 40)
Daeseok Youna38223f2014-05-09 19:09:35 +0900893 break; /* don't wait any longer */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900894 }
895 if (status & MUSYCC_TX_OWNED) {
896 if (cxt1e1_log_level >= LOG_MONITOR) {
897 pr_info("%s: Port %d Chan %2d - unexpected TX msg ownership intr (md %p sts %x)\n",
Daeseok Youna38223f2014-05-09 19:09:35 +0900898 pi->up->devname, pi->portnum,
899 ch->channum, md, status);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900900 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",
Daeseok Youna38223f2014-05-09 19:09:35 +0900901 ch->user, ch->txd_irq_srv,
902 ch->txd_usr_add,
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900903 sd_queue_stopped(ch->user),
Daeseok Youna38223f2014-05-09 19:09:35 +0900904 ch->ch_start_tx, ch->tx_full,
905 ch->txd_free, ch->p.chan_mode);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900906 musycc_dump_txbuffer_ring(ch, 0);
907 }
908 break; /* Not our mdesc, done */
909 } else {
910 if (cxt1e1_log_level >= LOG_MONITOR)
911 pr_info("%s: Port %d Chan %2d - recovered TX msg ownership [%d] (md %p sts %x)\n",
Daeseok Youna38223f2014-05-09 19:09:35 +0900912 pi->up->devname, pi->portnum,
913 ch->channum, readCount,
914 md, status);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900915 }
916 }
917 ch->txd_irq_srv = md->snext;
918
919 md->data = 0;
Daeseok Youna38223f2014-05-09 19:09:35 +0900920 if (md->mem_token) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900921 /* upcount channel */
Daeseok Youna38223f2014-05-09 19:09:35 +0900922 atomic_sub(OS_mem_token_tlen(md->mem_token),
923 &ch->tx_pending);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900924 /* upcount card */
Daeseok Youna38223f2014-05-09 19:09:35 +0900925 atomic_sub(OS_mem_token_tlen(md->mem_token),
926 &pi->up->tx_pending);
Bob Beers50ee11f2010-03-04 08:40:46 -0500927#ifdef SBE_WAN256T3_ENABLE
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900928 if (!atomic_read(&pi->up->tx_pending))
929 wan256t3_led(pi->up, LED_TX, 0);
Bob Beers50ee11f2010-03-04 08:40:46 -0500930#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900931 OS_mem_token_free_irq(md->mem_token);
932 md->mem_token = NULL;
933 }
934 md->status = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500935#ifdef RLD_TXFULL_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900936 if (cxt1e1_log_level >= LOG_MONITOR2)
937 pr_info("~~ tx_eom: tx_full %x txd_free %d -> %d\n",
938 ch->tx_full, ch->txd_free, ch->txd_free + 1);
Bob Beers50ee11f2010-03-04 08:40:46 -0500939#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900940 ++ch->txd_free;
941 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500942
Daeseok Youna38223f2014-05-09 19:09:35 +0900943 if ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) &&
944 (status & EOBIRQ_ENABLE)) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900945 if (cxt1e1_log_level >= LOG_MONITOR)
946 pr_info("%s: Mode (%x) incorrect EOB status (%x)\n",
Daeseok Youna38223f2014-05-09 19:09:35 +0900947 pi->up->devname, ch->p.chan_mode,
948 status);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900949 if ((status & EOMIRQ_ENABLE) == 0)
950 break;
951 }
Daeseok Youna38223f2014-05-09 19:09:35 +0900952 } while ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) &&
953 ((status & EOMIRQ_ENABLE) == 0));
Johan Meiringea9d1e92012-11-20 19:28:46 +0200954 /*
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900955 * NOTE: (The above 'while' is coupled w/ previous 'do', way above.) Each
956 * Transparent data buffer has the EOB bit, and NOT the EOM bit, set and
957 * will furthermore have a separate IQD associated with each messages
958 * buffer.
Johan Meiringea9d1e92012-11-20 19:28:46 +0200959 */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900960
961 FLUSH_MEM_READ();
962 /*
963 * Smooth flow control hysterisis by maintaining task stoppage until half
964 * the available write buffers are available.
965 */
966 if (ch->tx_full && (ch->txd_free >= (ch->txd_num / 2))) {
967 /*
968 * Then, only releave task stoppage if we actually have enough
969 * buffers to service the last requested packet. It may require MORE
970 * than half the available!
971 */
972 if (ch->txd_free >= ch->txd_required) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500973
974#ifdef RLD_TXFULL_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900975 if (cxt1e1_log_level >= LOG_MONITOR2)
976 pr_info("tx_eom[%d]: enable xmit tx_full no more, txd_free %d txd_num/2 %d\n",
977 ch->channum,
978 ch->txd_free, ch->txd_num / 2);
Bob Beers50ee11f2010-03-04 08:40:46 -0500979#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900980 ch->tx_full = 0;
981 ch->txd_required = 0;
Daeseok Youna38223f2014-05-09 19:09:35 +0900982 /* re-enable to catch flow controlled channel */
983 sd_enable_xmit(ch->user);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900984 }
Johan Meiringea9d1e92012-11-20 19:28:46 +0200985 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500986#ifdef RLD_TXFULL_DEBUG
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900987 else if (ch->tx_full) {
988 if (cxt1e1_log_level >= LOG_MONITOR2)
989 pr_info("tx_eom[%d]: bypass TX enable though room available? (txd_free %d txd_num/2 %d)\n",
990 ch->channum,
991 ch->txd_free, ch->txd_num / 2);
992 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500993#endif
994
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +0900995 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500996}
997
998
Shaun Laing37ca35c2013-08-09 07:54:24 -0600999static void
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +05301000musycc_bh_rx_eom(mpi_t *pi, int gchan)
Bob Beers50ee11f2010-03-04 08:40:46 -05001001{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001002 mch_t *ch;
1003 void *m, *m2;
1004 struct mdesc *md;
1005 volatile u_int32_t status;
1006 u_int32_t error;
Bob Beers50ee11f2010-03-04 08:40:46 -05001007
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001008 ch = pi->chan[gchan];
1009 if (!ch || ch->state != UP) {
1010 if (cxt1e1_log_level > LOG_ERROR)
1011 pr_info("%s: intr: receive EOM on uninitialized channel %d\n",
1012 pi->up->devname, gchan);
1013 return;
1014 }
1015 if (!ch->mdr)
1016 return; /* can this happen ? */
Bob Beers50ee11f2010-03-04 08:40:46 -05001017
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001018 for (;;) {
1019 FLUSH_MEM_READ();
1020 md = &ch->mdr[ch->rxix_irq_srv];
1021 status = le32_to_cpu(md->status);
1022 if (!(status & HOST_RX_OWNED))
1023 break; /* Not our mdesc, done */
1024 m = md->mem_token;
1025 error = (status >> 16) & 0xf;
1026 if (error == 0) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001027 {
1028 m2 = OS_mem_token_alloc(cxt1e1_max_mru);
1029 if (m2) {
1030 /* substitute the mbuf+cluster */
1031 md->mem_token = m2;
1032 md->data = cpu_to_le32(OS_vtophys(
1033 OS_mem_token_data(m2)));
Bob Beers50ee11f2010-03-04 08:40:46 -05001034
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001035 /* pass the received mbuf upward */
Daeseok Youna38223f2014-05-09 19:09:35 +09001036 sd_recv_consume(m, status & LENGTH_MASK,
1037 ch->user);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001038 ch->s.rx_packets++;
1039 ch->s.rx_bytes += status & LENGTH_MASK;
1040 } else
1041 ch->s.rx_dropped++;
1042 }
1043 } else if (error == ERR_FCS)
1044 ch->s.rx_crc_errors++;
1045 else if (error == ERR_ALIGN)
1046 ch->s.rx_missed_errors++;
1047 else if (error == ERR_ABT)
1048 ch->s.rx_missed_errors++;
1049 else if (error == ERR_LNG)
1050 ch->s.rx_length_errors++;
1051 else if (error == ERR_SHT)
1052 ch->s.rx_length_errors++;
1053 FLUSH_MEM_WRITE();
1054 status = cxt1e1_max_mru;
1055 if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
1056 status |= EOBIRQ_ENABLE;
1057 md->status = cpu_to_le32(status);
Bob Beers50ee11f2010-03-04 08:40:46 -05001058
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001059 /* Check next mdesc in the ring */
1060 if (++ch->rxix_irq_srv >= ch->rxd_num)
1061 ch->rxix_irq_srv = 0;
1062 FLUSH_MEM_WRITE();
1063 }
Bob Beers50ee11f2010-03-04 08:40:46 -05001064}
1065
1066
1067irqreturn_t
Johan Meiring77c84b22012-11-20 19:28:48 +02001068musycc_intr_th_handler(void *devp)
Bob Beers50ee11f2010-03-04 08:40:46 -05001069{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001070 ci_t *ci = (ci_t *) devp;
1071 volatile u_int32_t status, currInt = 0;
1072 u_int32_t nextInt, intCnt;
Bob Beers50ee11f2010-03-04 08:40:46 -05001073
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001074 /*
1075 * Hardware not available, potential interrupt hang. But since interrupt
1076 * might be shared, just return.
1077 */
1078 if (ci->state == C_INIT)
1079 return IRQ_NONE;
1080 /*
1081 * Marked as hardware available. Don't service interrupts, just clear the
1082 * event.
1083 */
Bob Beers50ee11f2010-03-04 08:40:46 -05001084
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001085 if (ci->state == C_IDLE) {
1086 status = pci_read_32((u_int32_t *) &ci->reg->isd);
Bob Beers50ee11f2010-03-04 08:40:46 -05001087
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001088 /* clear the interrupt but process nothing else */
1089 pci_write_32((u_int32_t *) &ci->reg->isd, status);
1090 return IRQ_HANDLED;
Johan Meiringea9d1e92012-11-20 19:28:46 +02001091 }
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001092 FLUSH_PCI_READ();
1093 FLUSH_MEM_READ();
1094
1095 status = pci_read_32((u_int32_t *) &ci->reg->isd);
Johan Meiring77c84b22012-11-20 19:28:48 +02001096 nextInt = INTRPTS_NEXTINT(status);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001097 intCnt = INTRPTS_INTCNT(status);
1098 ci->intlog.drvr_intr_thcount++;
Bob Beers50ee11f2010-03-04 08:40:46 -05001099
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001100 /*********************************************************/
1101 /* HW Bug Fix */
1102 /* ---------- */
1103 /* Under certain PCI Bus loading conditions, the */
1104 /* MUSYCC looses the data associated with an update */
1105 /* of its ISD and erroneously returns the immediately */
1106 /* preceding 'nextInt' value. However, the 'intCnt' */
1107 /* value appears to be correct. By not starting service */
1108 /* where the 'missing' 'nextInt' SHOULD point causes */
1109 /* the IQD not to be serviced - the 'not serviced' */
1110 /* entries then remain and continue to increase as more */
1111 /* incorrect ISD's are encountered. */
1112 /*********************************************************/
Bob Beers50ee11f2010-03-04 08:40:46 -05001113
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001114 if (nextInt != INTRPTS_NEXTINT(ci->intlog.this_status_new)) {
1115 if (cxt1e1_log_level >= LOG_MONITOR) {
1116 pr_info("%s: note - updated ISD from %08x to %08x\n",
1117 ci->devname, status,
Daeseok Youna38223f2014-05-09 19:09:35 +09001118 (status & (~INTRPTS_NEXTINT_M)) |
1119 ci->intlog.this_status_new);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001120 }
1121 /*
1122 * Replace bogus status with software corrected value.
1123 *
1124 * It's not known whether, during this problem occurrence, if the
1125 * INTFULL bit is correctly reported or not.
1126 */
Daeseok Youna38223f2014-05-09 19:09:35 +09001127 status = (status & (~INTRPTS_NEXTINT_M)) |
1128 (ci->intlog.this_status_new);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001129 nextInt = INTRPTS_NEXTINT(status);
1130 }
1131 /**********************************************/
1132 /* Cn847x Bug Fix */
1133 /* -------------- */
1134 /* Fix for inability to write back same index */
1135 /* as read for a full interrupt queue. */
1136 /**********************************************/
1137
1138 if (intCnt == INT_QUEUE_SIZE)
1139 currInt = ((intCnt - 1) + nextInt) & (INT_QUEUE_SIZE - 1);
1140 else
1141 /************************************************/
1142 /* Interrupt Write Location Issues */
1143 /* ------------------------------- */
1144 /* When the interrupt status descriptor is */
1145 /* written, the interrupt line is de-asserted */
1146 /* by the Cn847x. In the case of MIPS */
1147 /* microprocessors, this must occur at the */
1148 /* beginning of the interrupt handler so that */
1149 /* the interrupt handle is not re-entered due */
1150 /* to interrupt dis-assertion latency. */
1151 /* In the case of all other processors, this */
1152 /* action should occur at the end of the */
1153 /* interrupt handler to avoid overwriting the */
1154 /* interrupt queue. */
1155 /************************************************/
1156
1157 if (intCnt)
1158 currInt = (intCnt + nextInt) & (INT_QUEUE_SIZE - 1);
1159 else {
1160 /*
1161 * NOTE: Servicing an interrupt whose ISD contains a count of ZERO
1162 * can be indicative of a Shared Interrupt chain. Our driver can be
1163 * called from the system's interrupt handler as a matter of the OS
1164 * walking the chain. As the chain is walked, the interrupt will
1165 * eventually be serviced by the correct driver/handler.
1166 */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001167 return IRQ_NONE;
1168 }
Bob Beers50ee11f2010-03-04 08:40:46 -05001169
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001170 ci->iqp_tailx = currInt;
Bob Beers50ee11f2010-03-04 08:40:46 -05001171
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001172 currInt <<= INTRPTS_NEXTINT_S;
1173 ci->intlog.last_status_new = ci->intlog.this_status_new;
1174 ci->intlog.this_status_new = currInt;
Bob Beers50ee11f2010-03-04 08:40:46 -05001175
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001176 if ((cxt1e1_log_level >= LOG_WARN) && (status & INTRPTS_INTFULL_M))
Daeseok Youna38223f2014-05-09 19:09:35 +09001177 pr_info("%s: Interrupt queue full condition occurred\n",
1178 ci->devname);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001179 if (cxt1e1_log_level >= LOG_DEBUG)
1180 pr_info("%s: interrupts pending, isd @ 0x%p: %x curr %d cnt %d NEXT %d\n",
1181 ci->devname, &ci->reg->isd,
Daeseok Youna38223f2014-05-09 19:09:35 +09001182 status, nextInt, intCnt,
1183 (intCnt + nextInt) & (INT_QUEUE_SIZE - 1));
Bob Beers50ee11f2010-03-04 08:40:46 -05001184
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001185 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -05001186#if defined(SBE_ISR_TASKLET)
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001187 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
1188 atomic_inc(&ci->bh_pending);
1189 tasklet_schedule(&ci->ci_musycc_isr_tasklet);
Bob Beers50ee11f2010-03-04 08:40:46 -05001190#elif defined(SBE_ISR_IMMEDIATE)
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001191 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
1192 atomic_inc(&ci->bh_pending);
1193 queue_task(&ci->ci_musycc_isr_tq, &tq_immediate);
1194 mark_bh(IMMEDIATE_BH);
Bob Beers50ee11f2010-03-04 08:40:46 -05001195#elif defined(SBE_ISR_INLINE)
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001196 (void) musycc_intr_bh_tasklet(ci);
1197 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
Bob Beers50ee11f2010-03-04 08:40:46 -05001198#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001199 return IRQ_HANDLED;
Bob Beers50ee11f2010-03-04 08:40:46 -05001200}
1201
1202
1203#if defined(SBE_ISR_IMMEDIATE)
1204unsigned long
1205#else
1206void
1207#endif
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +05301208musycc_intr_bh_tasklet(ci_t *ci)
Bob Beers50ee11f2010-03-04 08:40:46 -05001209{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001210 mpi_t *pi;
1211 mch_t *ch;
1212 unsigned int intCnt;
1213 volatile u_int32_t currInt = 0;
1214 volatile unsigned int headx, tailx;
1215 int readCount, loopCount;
1216 int group, gchan, event, err, tx;
1217 u_int32_t badInt = INT_EMPTY_ENTRY;
1218 u_int32_t badInt2 = INT_EMPTY_ENTRY2;
Bob Beers50ee11f2010-03-04 08:40:46 -05001219
Johan Meiringea9d1e92012-11-20 19:28:46 +02001220 /*
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001221 * Hardware not available, potential interrupt hang. But since interrupt
1222 * might be shared, just return.
Johan Meiringea9d1e92012-11-20 19:28:46 +02001223 */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001224 if ((drvr_state != SBE_DRVR_AVAILABLE) || (ci->state == C_INIT)) {
Bob Beers50ee11f2010-03-04 08:40:46 -05001225#if defined(SBE_ISR_IMMEDIATE)
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001226 return 0L;
1227#else
1228 return;
Bob Beers50ee11f2010-03-04 08:40:46 -05001229#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001230 }
1231#if defined(SBE_ISR_TASKLET) || defined(SBE_ISR_IMMEDIATE)
1232 if (drvr_state != SBE_DRVR_AVAILABLE) {
1233#if defined(SBE_ISR_TASKLET)
1234 return;
1235#elif defined(SBE_ISR_IMMEDIATE)
1236 return 0L;
1237#endif
1238 }
1239#elif defined(SBE_ISR_INLINE)
1240 /* no semaphore taken, no double checks */
1241#endif
1242
1243 ci->intlog.drvr_intr_bhcount++;
1244 FLUSH_MEM_READ();
1245 {
1246 unsigned int bh = atomic_read(&ci->bh_pending);
1247
1248 max_bh = max(bh, max_bh);
1249 }
1250 atomic_set(&ci->bh_pending, 0);/* if here, no longer pending */
1251 while ((headx = ci->iqp_headx) != (tailx = ci->iqp_tailx)) {
1252 intCnt = (tailx >= headx) ? (tailx - headx) : (tailx - headx + INT_QUEUE_SIZE);
1253 currInt = le32_to_cpu(ci->iqd_p[headx]);
1254
1255 max_intcnt = max(intCnt, max_intcnt); /* RLD DEBUG */
1256
1257 /**************************************************/
1258 /* HW Bug Fix */
1259 /* ---------- */
1260 /* The following code checks for the condition */
1261 /* of interrupt assertion before interrupt */
1262 /* queue update. This is a problem on several */
1263 /* PCI-Local bridge chips found on some products. */
1264 /**************************************************/
1265
1266 readCount = 0;
1267 if ((currInt == badInt) || (currInt == badInt2))
1268 ci->intlog.drvr_int_failure++;
1269
1270 while ((currInt == badInt) || (currInt == badInt2)) {
1271 for (loopCount = 0; loopCount < 0x30; loopCount++)
Daeseok Youna38223f2014-05-09 19:09:35 +09001272 /* use call to avoid optimization
1273 * removal of dummy delay
1274 */
1275 OS_uwait_dummy();
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001276 FLUSH_MEM_READ();
1277 currInt = le32_to_cpu(ci->iqd_p[headx]);
1278 if (readCount++ > 20)
1279 break;
1280 }
1281
Daeseok Youna38223f2014-05-09 19:09:35 +09001282 /* catch failure of Bug Fix checking */
1283 if ((currInt == badInt) || (currInt == badInt2)) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001284 if (cxt1e1_log_level >= LOG_WARN)
1285 pr_info("%s: Illegal Interrupt Detected @ 0x%p, mod %d.)\n",
1286 ci->devname, &ci->iqd_p[headx], headx);
1287
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
1298 if (currInt == badInt)
1299 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY2);
1300 else
1301 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
Daeseok Youna38223f2014-05-09 19:09:35 +09001302 /* insure wrapness */
1303 ci->iqp_headx = (headx + 1) & (INT_QUEUE_SIZE - 1);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001304 FLUSH_MEM_WRITE();
1305 FLUSH_MEM_READ();
1306 continue;
1307 }
1308 group = INTRPT_GRP(currInt);
1309 gchan = INTRPT_CH(currInt);
1310 event = INTRPT_EVENT(currInt);
1311 err = INTRPT_ERROR(currInt);
1312 tx = currInt & INTRPT_DIR_M;
1313
1314 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
1315 FLUSH_MEM_WRITE();
1316
1317 if (cxt1e1_log_level >= LOG_DEBUG) {
1318 if (err != 0)
1319 pr_info(" %08x -> err: %2d,", currInt, err);
1320
1321 pr_info("+ interrupt event: %d, grp: %d, chan: %2d, side: %cX\n",
1322 event, group, gchan, tx ? 'T' : 'R');
1323 }
Daeseok Youna38223f2014-05-09 19:09:35 +09001324 /* notice that here we assume 1-1 group - port mapping */
1325 pi = &ci->port[group];
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001326 ch = pi->chan[gchan];
1327 switch (event) {
1328 case EVE_SACK: /* Service Request Acknowledge */
1329 if (cxt1e1_log_level >= LOG_DEBUG) {
1330 volatile u_int32_t r;
1331
1332 r = pci_read_32((u_int32_t *) &pi->reg->srd);
Daeseok Youna38223f2014-05-09 19:09:35 +09001333 pr_info("- SACK cmd: %08x (hdw= %08x)\n",
1334 pi->sr_last, r);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001335 }
Daeseok Youna38223f2014-05-09 19:09:35 +09001336 /* wake up waiting process */
1337 SD_SEM_GIVE(&pi->sr_sem_wait);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001338 break;
Daeseok Youna38223f2014-05-09 19:09:35 +09001339 case EVE_CHABT: /* Change To Abort Code (0x7e -> 0xff) */
1340 case EVE_CHIC: /* Change To Idle Code (0xff -> 0x7e) */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001341 break;
Daeseok Youna38223f2014-05-09 19:09:35 +09001342 case EVE_EOM: /* End Of Message */
1343 case EVE_EOB: /* End Of Buffer (Transparent mode) */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001344 if (tx)
1345 musycc_bh_tx_eom(pi, gchan);
1346 else
1347 musycc_bh_rx_eom(pi, gchan);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001348 /*
1349 * MUSYCC Interrupt Descriptor section states that EOB and EOM
1350 * can be combined with the NONE error (as well as others). So
1351 * drop thru to catch this...
1352 */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001353 case EVE_NONE:
1354 if (err == ERR_SHT)
1355 ch->s.rx_length_errors++;
1356 break;
1357 default:
1358 if (cxt1e1_log_level >= LOG_WARN)
1359 pr_info("%s: unexpected interrupt event: %d, iqd[%d]: %08x, port: %d\n", ci->devname,
1360 event, headx, currInt, group);
1361 break;
1362 } /* switch on event */
1363
1364
1365 /*
1366 * Per MUSYCC Manual, Section 6.4.8.3 [Transmit Errors], TX errors
1367 * are service-affecting and require action to resume normal
1368 * bit-level processing.
1369 */
1370
1371 switch (err) {
1372 case ERR_ONR:
1373 /*
1374 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors], this
1375 * error requires Transmit channel reactivation.
1376 *
1377 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], this error
1378 * requires Receive channel reactivation.
1379 */
1380 if (tx) {
1381
1382 /*
1383 * TX ONR Error only occurs when channel is configured for
1384 * Transparent Mode. However, this code will catch and
1385 * re-activate on ANY TX ONR error.
1386 */
1387
1388 /*
1389 * Set flag to re-enable on any next transmit attempt.
1390 */
1391 ch->ch_start_tx = CH_START_TX_ONR;
1392
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001393#ifdef RLD_TRANS_DEBUG
Daeseok Youn79cefa52014-05-09 19:08:59 +09001394 if (1 || cxt1e1_log_level >= LOG_MONITOR)
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001395#else
Daeseok Youn79cefa52014-05-09 19:08:59 +09001396 if (cxt1e1_log_level >= LOG_MONITOR)
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001397#endif
Daeseok Youn79cefa52014-05-09 19:08:59 +09001398 {
1399 pr_info("%s: TX buffer underflow [ONR] on channel %d, mode %x QStopped %x free %d\n",
Daeseok Youna38223f2014-05-09 19:09:35 +09001400 ci->devname, ch->channum,
1401 ch->p.chan_mode,
1402 sd_queue_stopped(ch->user),
1403 ch->txd_free);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001404#ifdef RLD_DEBUG
Daeseok Youna38223f2014-05-09 19:09:35 +09001405 /* problem = ONR on HDLC mode */
1406 if (ch->p.chan_mode == 2) {
Daeseok Youn79cefa52014-05-09 19:08:59 +09001407 pr_info("++ Failed Last %x Next %x QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
Daeseok Youna38223f2014-05-09 19:09:35 +09001408 (u_int32_t)ch->txd_irq_srv,
1409 (u_int32_t)ch->txd_usr_add,
Daeseok Youn79cefa52014-05-09 19:08:59 +09001410 sd_queue_stopped(ch->user),
Daeseok Youna38223f2014-05-09 19:09:35 +09001411 ch->ch_start_tx,
1412 ch->tx_full,
1413 ch->txd_free,
1414 ch->p.chan_mode);
Daeseok Youn79cefa52014-05-09 19:08:59 +09001415 musycc_dump_txbuffer_ring(ch, 0);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001416 }
Daeseok Youn79cefa52014-05-09 19:08:59 +09001417#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001418 }
1419 } else { /* RX buffer overrun */
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
1430 if (cxt1e1_log_level >= LOG_WARN) {
1431 pr_info("%s: RX buffer overflow [ONR] on channel %d, mode %x\n",
Daeseok Youna38223f2014-05-09 19:09:35 +09001432 ci->devname, ch->channum,
1433 ch->p.chan_mode);
Daeseok Younb7923d22014-05-09 23:54:08 +09001434#ifdef RLD_DEBUG
1435 musycc_dump_rxbuffer_ring(ch, 0);
1436#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001437 }
1438 }
1439 musycc_chan_restart(ch);
1440 break;
1441 case ERR_BUF:
1442 if (tx) {
1443 ch->s.tx_fifo_errors++;
1444 ch->ch_start_tx = CH_START_TX_BUF;
1445 /*
1446 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors],
1447 * this BUFF error requires Transmit channel reactivation.
1448 */
1449 if (cxt1e1_log_level >= LOG_MONITOR)
1450 pr_info("%s: TX buffer underrun [BUFF] on channel %d, mode %x\n",
Daeseok Youna38223f2014-05-09 19:09:35 +09001451 ci->devname, ch->channum,
1452 ch->p.chan_mode);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001453 } else { /* RX buffer overrun */
1454 ch->s.rx_over_errors++;
1455 /*
1456 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], HDLC
1457 * mode requires NO recovery for this RX BUFF error is
1458 * required. It is suggested to increase the FIFO buffer
1459 * space for this channel. Receive channel reactivation is
1460 * not required, but data has been lost.
1461 */
1462 if (cxt1e1_log_level >= LOG_WARN)
1463 pr_info("%s: RX buffer overrun [BUFF] on channel %d, mode %x\n",
Daeseok Youna38223f2014-05-09 19:09:35 +09001464 ci->devname, ch->channum,
1465 ch->p.chan_mode);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001466 /*
1467 * Per MUSYCC manual, Section 6.4.9.4 [Receive Errors],
1468 * Transparent mode DOES require recovery for the RX BUFF
1469 * error. It is suggested to increase the FIFO buffer space
1470 * for this channel. Receive channel reactivation IS
1471 * required and data has been lost.
1472 */
1473 if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
1474 ch->ch_start_rx = CH_START_RX_BUF;
1475 }
1476
1477 if (tx || (ch->p.chan_mode == CFG_CH_PROTO_TRANS))
1478 musycc_chan_restart(ch);
1479 break;
1480 default:
1481 break;
1482 } /* switch on err */
1483
1484 /* Check for interrupt lost condition */
Daeseok Youna38223f2014-05-09 19:09:35 +09001485 if ((currInt & INTRPT_ILOST_M) &&
1486 (cxt1e1_log_level >= LOG_ERROR))
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001487 pr_info("%s: Interrupt queue overflow - ILOST asserted\n",
1488 ci->devname);
Daeseok Youna38223f2014-05-09 19:09:35 +09001489 /* insure wrapness */
1490 ci->iqp_headx = (headx + 1) & (INT_QUEUE_SIZE - 1);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001491 FLUSH_MEM_WRITE();
1492 FLUSH_MEM_READ();
1493 } /* while */
Daeseok Youna38223f2014-05-09 19:09:35 +09001494 if ((cxt1e1_log_level >= LOG_MONITOR2) &&
1495 (ci->iqp_headx != ci->iqp_tailx)) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001496 int bh;
1497
1498 bh = atomic_read(&CI->bh_pending);
1499 pr_info("_bh_: late arrivals, head %d != tail %d, pending %d\n",
1500 ci->iqp_headx, ci->iqp_tailx, bh);
1501 }
1502#if defined(SBE_ISR_IMMEDIATE)
1503 return 0L;
1504#endif
1505 /* else, nothing returned */
Bob Beers50ee11f2010-03-04 08:40:46 -05001506}
1507
Bob Beers50ee11f2010-03-04 08:40:46 -05001508#ifdef SBE_PMCC4_ENABLE
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001509 status_t
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +05301510musycc_chan_down(ci_t *dummy, int channum)
Bob Beers50ee11f2010-03-04 08:40:46 -05001511{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001512 mpi_t *pi;
1513 mch_t *ch;
1514 int i, gchan;
Bob Beers50ee11f2010-03-04 08:40:46 -05001515
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001516 ch = sd_find_chan(dummy, channum);
1517 if (!ch)
1518 return -EINVAL;
1519 pi = ch->up;
1520 gchan = ch->gchan;
Bob Beers50ee11f2010-03-04 08:40:46 -05001521
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001522 /* Deactivate the channel */
1523 musycc_serv_req(pi, SR_CHANNEL_DEACTIVATE | SR_RX_DIRECTION | gchan);
1524 ch->ch_start_rx = 0;
1525 musycc_serv_req(pi, SR_CHANNEL_DEACTIVATE | SR_TX_DIRECTION | gchan);
1526 ch->ch_start_tx = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -05001527
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001528 if (ch->state == DOWN)
1529 return 0;
1530 ch->state = DOWN;
1531
1532 pi->regram->thp[gchan] = 0;
1533 pi->regram->tmp[gchan] = 0;
1534 pi->regram->rhp[gchan] = 0;
1535 pi->regram->rmp[gchan] = 0;
1536 FLUSH_MEM_WRITE();
1537 for (i = 0; i < ch->txd_num; i++)
1538 if (ch->mdt[i].mem_token)
1539 OS_mem_token_free(ch->mdt[i].mem_token);
1540
1541 for (i = 0; i < ch->rxd_num; i++)
1542 if (ch->mdr[i].mem_token)
1543 OS_mem_token_free(ch->mdr[i].mem_token);
1544
1545 kfree(ch->mdr);
1546 ch->mdr = NULL;
1547 ch->rxd_num = 0;
1548 kfree(ch->mdt);
1549 ch->mdt = NULL;
1550 ch->txd_num = 0;
1551
1552 musycc_update_timeslots(pi);
1553 c4_fifo_free(pi, ch->gchan);
1554
1555 pi->openchans--;
Johan Meiringea9d1e92012-11-20 19:28:46 +02001556 return 0;
Bob Beers50ee11f2010-03-04 08:40:46 -05001557}
1558#endif
1559
Bob Beers50ee11f2010-03-04 08:40:46 -05001560int
Dulshani Gunawardhanaee1803c2013-05-22 23:29:26 +05301561musycc_start_xmit(ci_t *ci, int channum, void *mem_token)
Bob Beers50ee11f2010-03-04 08:40:46 -05001562{
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001563 mch_t *ch;
1564 struct mdesc *md;
1565 void *m2;
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001566 int txd_need_cnt;
1567 u_int32_t len;
Bob Beers50ee11f2010-03-04 08:40:46 -05001568
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001569 ch = sd_find_chan(ci, channum);
1570 if (!ch)
1571 return -ENOENT;
Bob Beers50ee11f2010-03-04 08:40:46 -05001572
Daeseok Youna38223f2014-05-09 19:09:35 +09001573 /* full interrupt processing available */
1574 if (ci->state != C_RUNNING)
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001575 return -EINVAL;
1576 if (ch->state != UP)
1577 return -EINVAL;
Bob Beers50ee11f2010-03-04 08:40:46 -05001578
Daeseok Youna38223f2014-05-09 19:09:35 +09001579 /* how else to flag unwritable state ? */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001580 if (!(ch->status & TX_ENABLED))
Daeseok Youna38223f2014-05-09 19:09:35 +09001581 return -EROFS;
Bob Beers50ee11f2010-03-04 08:40:46 -05001582
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001583#ifdef RLD_TRANS_DEBUG
1584 if (1 || cxt1e1_log_level >= LOG_MONITOR2)
Bob Beers50ee11f2010-03-04 08:40:46 -05001585#else
Johan Meiringea9d1e92012-11-20 19:28:46 +02001586 if (cxt1e1_log_level >= LOG_MONITOR2)
Bob Beers50ee11f2010-03-04 08:40:46 -05001587#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001588 {
1589 pr_info("++ start_xmt[%d]: state %x start %x full %d free %d required %d stopped %x\n",
1590 channum, ch->state, ch->ch_start_tx, ch->tx_full,
Daeseok Youna38223f2014-05-09 19:09:35 +09001591 ch->txd_free, ch->txd_required,
1592 sd_queue_stopped(ch->user));
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001593 }
1594 /***********************************************/
1595 /** Determine total amount of data to be sent **/
1596 /***********************************************/
1597 m2 = mem_token;
1598 txd_need_cnt = 0;
1599 for (len = OS_mem_token_tlen(m2); len > 0;
1600 m2 = (void *) OS_mem_token_next(m2)) {
1601 if (!OS_mem_token_len(m2))
1602 continue;
1603 txd_need_cnt++;
1604 len -= OS_mem_token_len(m2);
1605 }
1606
1607 if (txd_need_cnt == 0) {
1608 if (cxt1e1_log_level >= LOG_MONITOR2)
Daeseok Youna38223f2014-05-09 19:09:35 +09001609 pr_info("%s channel %d: no TX data in User buffer\n",
1610 ci->devname, channum);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001611 OS_mem_token_free(mem_token);
1612 return 0; /* no data to send */
1613 }
1614 /*************************************************/
1615 /** Are there sufficient descriptors available? **/
1616 /*************************************************/
1617 if (txd_need_cnt > ch->txd_num) { /* never enough descriptors for this
1618 * large a buffer */
1619 if (cxt1e1_log_level >= LOG_DEBUG)
1620 pr_info("start_xmit: discarding buffer, insufficient descriptor cnt %d, need %d.\n",
1621 ch->txd_num, txd_need_cnt + 1);
1622 ch->s.tx_dropped++;
1623 OS_mem_token_free(mem_token);
1624 return 0;
1625 }
Daeseok Younb7923d22014-05-09 23:54:08 +09001626
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001627 /************************************************************/
1628 /** flow control the line if not enough descriptors remain **/
1629 /************************************************************/
1630 if (txd_need_cnt > ch->txd_free) {
1631 if (cxt1e1_log_level >= LOG_MONITOR2)
1632 pr_info("start_xmit[%d]: EBUSY - need more descriptors, have %d of %d need %d\n",
Daeseok Youna38223f2014-05-09 19:09:35 +09001633 channum, ch->txd_free,
1634 ch->txd_num, txd_need_cnt);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001635 ch->tx_full = 1;
1636 ch->txd_required = txd_need_cnt;
1637 sd_disable_xmit(ch->user);
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001638 return -EBUSY; /* tell user to try again later */
1639 }
1640 /**************************************************/
1641 /** Put the user data into MUSYCC data buffer(s) **/
1642 /**************************************************/
1643 m2 = mem_token;
1644 md = ch->txd_usr_add; /* get current available descriptor */
Bob Beers50ee11f2010-03-04 08:40:46 -05001645
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001646 for (len = OS_mem_token_tlen(m2); len > 0; m2 = OS_mem_token_next(m2)) {
1647 int u = OS_mem_token_len(m2);
Bob Beers50ee11f2010-03-04 08:40:46 -05001648
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001649 if (!u)
1650 continue;
1651 len -= u;
1652
1653 /*
1654 * Enable following chunks, yet wait to enable the FIRST chunk until
1655 * after ALL subsequent chunks are setup.
1656 */
1657 if (md != ch->txd_usr_add) /* not first chunk */
Daeseok Youna38223f2014-05-09 19:09:35 +09001658 /* transfer ownership from HOST to MUSYCC */
1659 u |= MUSYCC_TX_OWNED;
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001660
1661 if (len) /* not last chunk */
1662 u |= EOBIRQ_ENABLE;
1663 else if (ch->p.chan_mode == CFG_CH_PROTO_TRANS) {
1664 /*
1665 * Per MUSYCC Ref 6.4.9 for Transparent Mode, the host must
1666 * always clear EOMIRQ_ENABLE in every Transmit Buffer Descriptor
1667 * (IE. don't set herein).
1668 */
1669 u |= EOBIRQ_ENABLE;
1670 } else
1671 u |= EOMIRQ_ENABLE; /* EOM, last HDLC chunk */
1672
1673
1674 /* last chunk in hdlc mode */
1675 u |= (ch->p.idlecode << IDLE_CODE);
1676 if (ch->p.pad_fill_count) {
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001677 u |= (PADFILL_ENABLE | (ch->p.pad_fill_count << EXTRA_FLAGS));
1678 }
Daeseok Youna38223f2014-05-09 19:09:35 +09001679 /* Fill in mds on last segment, others set ZERO
1680 * so that entire token is removed ONLY when ALL
1681 * segments have been transmitted.
1682 */
1683 md->mem_token = len ? NULL : mem_token;
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001684
1685 md->data = cpu_to_le32(OS_vtophys(OS_mem_token_data(m2)));
1686 FLUSH_MEM_WRITE();
1687 md->status = cpu_to_le32(u);
1688 --ch->txd_free;
1689 md = md->snext;
1690 }
1691 FLUSH_MEM_WRITE();
1692
Bob Beers50ee11f2010-03-04 08:40:46 -05001693
Johan Meiringea9d1e92012-11-20 19:28:46 +02001694 /*
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001695 * Now transfer ownership of first chunk from HOST to MUSYCC in order to
1696 * fire-off this XMIT.
Johan Meiringea9d1e92012-11-20 19:28:46 +02001697 */
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001698 ch->txd_usr_add->status |= __constant_cpu_to_le32(MUSYCC_TX_OWNED);
Johan Meiring77c84b22012-11-20 19:28:48 +02001699 FLUSH_MEM_WRITE();
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001700 ch->txd_usr_add = md;
Bob Beers50ee11f2010-03-04 08:40:46 -05001701
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001702 len = OS_mem_token_tlen(mem_token);
1703 atomic_add(len, &ch->tx_pending);
1704 atomic_add(len, &ci->tx_pending);
1705 ch->s.tx_packets++;
1706 ch->s.tx_bytes += len;
1707 /*
1708 * If an ONR was seen, then channel requires poking to restart
1709 * transmission.
1710 */
1711 if (ch->ch_start_tx)
1712 musycc_chan_restart(ch);
Bob Beers50ee11f2010-03-04 08:40:46 -05001713#ifdef SBE_WAN256T3_ENABLE
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001714 wan256t3_led(ci, LED_TX, LEDV_G);
Bob Beers50ee11f2010-03-04 08:40:46 -05001715#endif
Daeseok Youn2ab4b6e2014-05-09 19:02:20 +09001716 return 0;
Bob Beers50ee11f2010-03-04 08:40:46 -05001717}
1718
1719
Bob Beers50ee11f2010-03-04 08:40:46 -05001720/*** End-of-File ***/