blob: b2cc68a1fe879ab155106b271e2671fb564cab09 [file] [log] [blame]
Bob Beers50ee11f2010-03-04 08:40:46 -05001unsigned int max_intcnt = 0;
2unsigned int max_bh = 0;
3
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
38#ifdef SBE_INCLUDE_SYMBOLS
39#define STATIC
40#else
41#define STATIC static
42#endif
43
44#define sd_find_chan(ci,ch) c4_find_chan(ch)
45
46
47/*******************************************************************/
48/* global driver variables */
49extern ci_t *c4_list;
50extern int drvr_state;
Greg Kroah-Hartmanb8b73992010-12-10 10:46:30 -080051extern int cxt1e1_log_level;
Bob Beers50ee11f2010-03-04 08:40:46 -050052
Bob Beersc694ed82010-10-16 18:06:36 -040053extern int cxt1e1_max_mru;
54extern int cxt1e1_max_mtu;
Bob Beers50ee11f2010-03-04 08:40:46 -050055extern int max_rxdesc_used;
56extern int max_txdesc_used;
57extern ci_t *CI; /* dummy pointr to board ZEROE's data - DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +020058 * USAGE */
Bob Beers50ee11f2010-03-04 08:40:46 -050059
60
61/*******************************************************************/
62/* forward references */
Johan Meiring77c84b22012-11-20 19:28:48 +020063void c4_fifo_free(mpi_t *, int);
64void c4_wk_chan_restart(mch_t *);
65void musycc_bh_tx_eom(mpi_t *, int);
66int musycc_chan_up(ci_t *, int);
67status_t __init musycc_init(ci_t *);
68STATIC void __init musycc_init_port(mpi_t *);
69void musycc_intr_bh_tasklet(ci_t *);
70void musycc_serv_req(mpi_t *, u_int32_t);
71void musycc_update_timeslots(mpi_t *);
Bob Beers50ee11f2010-03-04 08:40:46 -050072
73/*******************************************************************/
74
75#if 1
76STATIC int
Johan Meiring77c84b22012-11-20 19:28:48 +020077musycc_dump_rxbuffer_ring(mch_t * ch, int lockit)
Bob Beers50ee11f2010-03-04 08:40:46 -050078{
79 struct mdesc *m;
80 unsigned long flags = 0;
81
82 u_int32_t status;
83 int n;
84
85 if (lockit)
Johan Meiring77c84b22012-11-20 19:28:48 +020086 spin_lock_irqsave(&ch->ch_rxlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -050087 if (ch->rxd_num == 0)
Johan Meiringea9d1e92012-11-20 19:28:46 +020088 pr_info(" ZERO receive buffers allocated for this channel.");
Johan Meiringfead55a2012-11-20 19:28:47 +020089 else {
Johan Meiring77c84b22012-11-20 19:28:48 +020090 FLUSH_MEM_READ();
Johan Meiringea9d1e92012-11-20 19:28:46 +020091 m = &ch->mdr[ch->rxix_irq_srv];
Johan Meiringfead55a2012-11-20 19:28:47 +020092 for (n = ch->rxd_num; n; n--) {
Johan Meiring77c84b22012-11-20 19:28:48 +020093 status = le32_to_cpu(m->status);
Johan Meiringea9d1e92012-11-20 19:28:46 +020094 {
95 pr_info("%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
96 (m == &ch->mdr[ch->rxix_irq_srv]) ? 'F' : ' ',
97 (unsigned long) m, n,
98 status,
99 m->data ? (status & HOST_RX_OWNED ? 'H' : 'M') : '-',
100 status & POLL_DISABLED ? 'P' : '-',
101 status & EOBIRQ_ENABLE ? 'b' : '-',
102 status & EOMIRQ_ENABLE ? 'm' : '-',
103 status & LENGTH_MASK,
Johan Meiring77c84b22012-11-20 19:28:48 +0200104 le32_to_cpu(m->data), le32_to_cpu(m->next));
Bob Beers50ee11f2010-03-04 08:40:46 -0500105#ifdef RLD_DUMP_BUFDATA
Johan Meiringea9d1e92012-11-20 19:28:46 +0200106 {
107 u_int32_t *dp;
108 int len = status & LENGTH_MASK;
Bob Beers50ee11f2010-03-04 08:40:46 -0500109
110#if 1
Johan Meiringea9d1e92012-11-20 19:28:46 +0200111 if (m->data && (status & HOST_RX_OWNED))
Bob Beers50ee11f2010-03-04 08:40:46 -0500112#else
Johan Meiringea9d1e92012-11-20 19:28:46 +0200113 if (m->data) /* always dump regardless of valid RX
114 * data */
Bob Beers50ee11f2010-03-04 08:40:46 -0500115#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200116 {
Johan Meiring77c84b22012-11-20 19:28:48 +0200117 dp = (u_int32_t *) OS_phystov((void *) (le32_to_cpu(m->data)));
Johan Meiringea9d1e92012-11-20 19:28:46 +0200118 if (len >= 0x10)
119 pr_info(" %x[%x]: %08X %08X %08X %08x\n", (u_int32_t) dp, len,
120 *dp, *(dp + 1), *(dp + 2), *(dp + 3));
121 else if (len >= 0x08)
122 pr_info(" %x[%x]: %08X %08X\n", (u_int32_t) dp, len,
123 *dp, *(dp + 1));
124 else
125 pr_info(" %x[%x]: %08X\n", (u_int32_t) dp, len, *dp);
126 }
127 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500128#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200129 }
130 m = m->snext;
131 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500132 } /* -for- */
Joe Perches694a9802010-05-03 12:33:16 -0700133 pr_info("\n");
Bob Beers50ee11f2010-03-04 08:40:46 -0500134
135 if (lockit)
Johan Meiring77c84b22012-11-20 19:28:48 +0200136 spin_unlock_irqrestore(&ch->ch_rxlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -0500137 return 0;
138}
139#endif
140
141#if 1
142STATIC int
Johan Meiring77c84b22012-11-20 19:28:48 +0200143musycc_dump_txbuffer_ring(mch_t * ch, int lockit)
Bob Beers50ee11f2010-03-04 08:40:46 -0500144{
145 struct mdesc *m;
146 unsigned long flags = 0;
147 u_int32_t status;
148 int n;
149
150 if (lockit)
Johan Meiring77c84b22012-11-20 19:28:48 +0200151 spin_lock_irqsave(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -0500152 if (ch->txd_num == 0)
Johan Meiringea9d1e92012-11-20 19:28:46 +0200153 pr_info(" ZERO transmit buffers allocated for this channel.");
Johan Meiringfead55a2012-11-20 19:28:47 +0200154 else {
Johan Meiring77c84b22012-11-20 19:28:48 +0200155 FLUSH_MEM_READ();
Johan Meiringea9d1e92012-11-20 19:28:46 +0200156 m = ch->txd_irq_srv;
Johan Meiringfead55a2012-11-20 19:28:47 +0200157 for (n = ch->txd_num; n; n--) {
Johan Meiring77c84b22012-11-20 19:28:48 +0200158 status = le32_to_cpu(m->status);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200159 {
160 pr_info("%c%c %08lx[%2d]: sts %08x (%c%c%c%c:%d.) Data [%08x] Next [%08x]\n",
161 (m == ch->txd_usr_add) ? 'F' : ' ',
162 (m == ch->txd_irq_srv) ? 'L' : ' ',
163 (unsigned long) m, n,
164 status,
165 m->data ? (status & MUSYCC_TX_OWNED ? 'M' : 'H') : '-',
166 status & POLL_DISABLED ? 'P' : '-',
167 status & EOBIRQ_ENABLE ? 'b' : '-',
168 status & EOMIRQ_ENABLE ? 'm' : '-',
169 status & LENGTH_MASK,
Johan Meiring77c84b22012-11-20 19:28:48 +0200170 le32_to_cpu(m->data), le32_to_cpu(m->next));
Bob Beers50ee11f2010-03-04 08:40:46 -0500171#ifdef RLD_DUMP_BUFDATA
Johan Meiringea9d1e92012-11-20 19:28:46 +0200172 {
173 u_int32_t *dp;
174 int len = status & LENGTH_MASK;
Bob Beers50ee11f2010-03-04 08:40:46 -0500175
Johan Meiringfead55a2012-11-20 19:28:47 +0200176 if (m->data) {
Johan Meiring77c84b22012-11-20 19:28:48 +0200177 dp = (u_int32_t *) OS_phystov((void *) (le32_to_cpu(m->data)));
Johan Meiringea9d1e92012-11-20 19:28:46 +0200178 if (len >= 0x10)
179 pr_info(" %x[%x]: %08X %08X %08X %08x\n", (u_int32_t) dp, len,
180 *dp, *(dp + 1), *(dp + 2), *(dp + 3));
181 else if (len >= 0x08)
182 pr_info(" %x[%x]: %08X %08X\n", (u_int32_t) dp, len,
183 *dp, *(dp + 1));
184 else
185 pr_info(" %x[%x]: %08X\n", (u_int32_t) dp, len, *dp);
186 }
187 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500188#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200189 }
190 m = m->snext;
191 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500192 } /* -for- */
Joe Perches694a9802010-05-03 12:33:16 -0700193 pr_info("\n");
Bob Beers50ee11f2010-03-04 08:40:46 -0500194
195 if (lockit)
Johan Meiring77c84b22012-11-20 19:28:48 +0200196 spin_unlock_irqrestore(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -0500197 return 0;
198}
199#endif
200
201
202/*
203 * The following supports a backdoor debug facility which can be used to
204 * display the state of a board's channel.
205 */
206
207status_t
Johan Meiring77c84b22012-11-20 19:28:48 +0200208musycc_dump_ring(ci_t * ci, unsigned int chan)
Bob Beers50ee11f2010-03-04 08:40:46 -0500209{
210 mch_t *ch;
211
212 if (chan >= MAX_CHANS_USED)
Johan Meiringea9d1e92012-11-20 19:28:46 +0200213 return SBE_DRVR_FAIL; /* E2BIG */
Bob Beers50ee11f2010-03-04 08:40:46 -0500214 {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200215 int bh;
Bob Beers50ee11f2010-03-04 08:40:46 -0500216
Johan Meiring77c84b22012-11-20 19:28:48 +0200217 bh = atomic_read(&ci->bh_pending);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200218 pr_info(">> bh_pend %d [%d] ihead %d itail %d [%d] th_cnt %d bh_cnt %d wdcnt %d note %d\n",
219 bh, max_bh, ci->iqp_headx, ci->iqp_tailx, max_intcnt,
220 ci->intlog.drvr_intr_thcount,
221 ci->intlog.drvr_intr_bhcount,
222 ci->wdcount, ci->wd_notify);
223 max_bh = 0; /* reset counter */
224 max_intcnt = 0; /* reset counter */
Bob Beers50ee11f2010-03-04 08:40:46 -0500225 }
226
Johan Meiring77c84b22012-11-20 19:28:48 +0200227 if (!(ch = sd_find_chan(dummy, chan))) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200228 pr_info(">> musycc_dump_ring: channel %d not up.\n", chan);
229 return ENOENT;
Bob Beers50ee11f2010-03-04 08:40:46 -0500230 }
Joe Perches694a9802010-05-03 12:33:16 -0700231 pr_info(">> CI %p CHANNEL %3d @ %p: state %x status/p %x/%x\n", ci, chan, ch, ch->state,
Johan Meiringea9d1e92012-11-20 19:28:46 +0200232 ch->status, ch->p.status);
Joe Perches694a9802010-05-03 12:33:16 -0700233 pr_info("--------------------------------\nTX Buffer Ring - Channel %d, txd_num %d. (bd/ch pend %d %d), TXD required %d, txpkt %lu\n",
Johan Meiringea9d1e92012-11-20 19:28:46 +0200234 chan, ch->txd_num,
Johan Meiring77c84b22012-11-20 19:28:48 +0200235 (u_int32_t) atomic_read(&ci->tx_pending), (u_int32_t) atomic_read(&ch->tx_pending), ch->txd_required, ch->s.tx_packets);
Joe Perches694a9802010-05-03 12:33:16 -0700236 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",
Johan Meiringea9d1e92012-11-20 19:28:46 +0200237 ch->user, ch->txd_irq_srv, ch->txd_usr_add,
Johan Meiring77c84b22012-11-20 19:28:48 +0200238 sd_queue_stopped(ch->user),
Johan Meiringea9d1e92012-11-20 19:28:46 +0200239 ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
Johan Meiring77c84b22012-11-20 19:28:48 +0200240 musycc_dump_txbuffer_ring(ch, 1);
Joe Perches694a9802010-05-03 12:33:16 -0700241 pr_info("RX Buffer Ring - Channel %d, rxd_num %d. IRQ_SRV[%d] 0x%p, start_rx %x rxpkt %lu\n",
Johan Meiringea9d1e92012-11-20 19:28:46 +0200242 chan, ch->rxd_num, ch->rxix_irq_srv,
243 &ch->mdr[ch->rxix_irq_srv], ch->ch_start_rx, ch->s.rx_packets);
Johan Meiring77c84b22012-11-20 19:28:48 +0200244 musycc_dump_rxbuffer_ring(ch, 1);
Bob Beers50ee11f2010-03-04 08:40:46 -0500245
246 return SBE_DRVR_SUCCESS;
247}
248
249
250status_t
Johan Meiring77c84b22012-11-20 19:28:48 +0200251musycc_dump_rings(ci_t * ci, unsigned int start_chan)
Bob Beers50ee11f2010-03-04 08:40:46 -0500252{
253 unsigned int chan;
254
255 for (chan = start_chan; chan < (start_chan + 5); chan++)
Johan Meiring77c84b22012-11-20 19:28:48 +0200256 musycc_dump_ring(ci, chan);
Bob Beers50ee11f2010-03-04 08:40:46 -0500257 return SBE_DRVR_SUCCESS;
258}
259
260
261/*
262 * NOTE on musycc_init_mdt(): These MUSYCC writes are only operational after
263 * a MUSYCC GROUP_INIT command has been issued.
264 */
265
266void
Johan Meiring77c84b22012-11-20 19:28:48 +0200267musycc_init_mdt(mpi_t * pi)
Bob Beers50ee11f2010-03-04 08:40:46 -0500268{
269 u_int32_t *addr, cfg;
270 int i;
271
272 /*
273 * This Idle Code insertion takes effect prior to channel's first
274 * transmitted message. After that, each message contains its own Idle
275 * Code information which is to be issued after the message is
276 * transmitted (Ref.MUSYCC 5.2.2.3: MCENBL bit in Group Configuration
277 * Descriptor).
278 */
279
280 addr = (u_int32_t *) ((u_long) pi->reg + MUSYCC_MDT_BASE03_ADDR);
281 cfg = CFG_CH_FLAG_7E << IDLE_CODE;
282
283 for (i = 0; i < 32; addr++, i++)
Johan Meiring77c84b22012-11-20 19:28:48 +0200284 pci_write_32(addr, cfg);
Bob Beers50ee11f2010-03-04 08:40:46 -0500285}
286
287
288/* Set TX thp to the next unprocessed md */
289
290void
Johan Meiring77c84b22012-11-20 19:28:48 +0200291musycc_update_tx_thp(mch_t * ch)
Bob Beers50ee11f2010-03-04 08:40:46 -0500292{
293 struct mdesc *md;
294 unsigned long flags;
295
Johan Meiring77c84b22012-11-20 19:28:48 +0200296 spin_lock_irqsave(&ch->ch_txlock, flags);
Johan Meiringfead55a2012-11-20 19:28:47 +0200297 while (1) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200298 md = ch->txd_irq_srv;
Johan Meiring77c84b22012-11-20 19:28:48 +0200299 FLUSH_MEM_READ();
Johan Meiringfead55a2012-11-20 19:28:47 +0200300 if (!md->data) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200301 /* No MDs with buffers to process */
Johan Meiring77c84b22012-11-20 19:28:48 +0200302 spin_unlock_irqrestore(&ch->ch_txlock, flags);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200303 return;
304 }
Johan Meiring77c84b22012-11-20 19:28:48 +0200305 if ((le32_to_cpu(md->status)) & MUSYCC_TX_OWNED) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200306 /* this is the MD to restart TX with */
307 break;
308 }
309 /*
310 * Otherwise, we have a valid, host-owned message descriptor which
311 * has been successfully transmitted and whose buffer can be freed,
312 * so... process this MD, it's owned by the host. (This might give
313 * as a new, updated txd_irq_srv.)
314 */
Johan Meiring77c84b22012-11-20 19:28:48 +0200315 musycc_bh_tx_eom(ch->up, ch->gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -0500316 }
317 md = ch->txd_irq_srv;
Johan Meiring77c84b22012-11-20 19:28:48 +0200318 ch->up->regram->thp[ch->gchan] = cpu_to_le32(OS_vtophys(md));
319 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500320
Johan Meiringfead55a2012-11-20 19:28:47 +0200321 if (ch->tx_full) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200322 ch->tx_full = 0;
323 ch->txd_required = 0;
Johan Meiring77c84b22012-11-20 19:28:48 +0200324 sd_enable_xmit(ch->user); /* re-enable to catch flow controlled
Johan Meiringea9d1e92012-11-20 19:28:46 +0200325 * channel */
Bob Beers50ee11f2010-03-04 08:40:46 -0500326 }
Johan Meiring77c84b22012-11-20 19:28:48 +0200327 spin_unlock_irqrestore(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -0500328
329#ifdef RLD_TRANS_DEBUG
Joe Perches694a9802010-05-03 12:33:16 -0700330 pr_info("++ musycc_update_tx_thp[%d]: setting thp = %p, sts %x\n", ch->channum, md, md->status);
Bob Beers50ee11f2010-03-04 08:40:46 -0500331#endif
332}
333
334
Bob Beers50ee11f2010-03-04 08:40:46 -0500335/*
336 * This is the workq task executed by the OS when our queue_work() is
337 * scheduled and run. It can fire off either RX or TX ACTIVATION depending
338 * upon the channel's ch_start_tx and ch_start_rx variables. This routine
339 * is implemented as a work queue so that the call to the service request is
340 * able to sleep, awaiting an interrupt acknowledgment response (SACK) from
341 * the hardware.
342 */
343
344void
Johan Meiring77c84b22012-11-20 19:28:48 +0200345musycc_wq_chan_restart(void *arg) /* channel private structure */
Bob Beers50ee11f2010-03-04 08:40:46 -0500346{
347 mch_t *ch;
348 mpi_t *pi;
349 struct mdesc *md;
350#if 0
351 unsigned long flags;
352#endif
353
354 ch = container_of(arg, struct c4_chan_info, ch_work);
355 pi = ch->up;
356
357#ifdef RLD_TRANS_DEBUG
Joe Perches694a9802010-05-03 12:33:16 -0700358 pr_info("wq_chan_restart[%d]: start_RT[%d/%d] status %x\n",
Johan Meiringea9d1e92012-11-20 19:28:46 +0200359 ch->channum, ch->ch_start_rx, ch->ch_start_tx, ch->status);
Bob Beers50ee11f2010-03-04 08:40:46 -0500360
361#endif
362
363 /**********************************/
364 /** check for RX restart request **/
365 /**********************************/
366
Johan Meiringfead55a2012-11-20 19:28:47 +0200367 if ((ch->ch_start_rx) && (ch->status & RX_ENABLED)) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500368
Johan Meiringea9d1e92012-11-20 19:28:46 +0200369 ch->ch_start_rx = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500370#if defined(RLD_TRANS_DEBUG) || defined(RLD_RXACT_DEBUG)
Johan Meiringea9d1e92012-11-20 19:28:46 +0200371 {
372 static int hereb4 = 7;
Bob Beers50ee11f2010-03-04 08:40:46 -0500373
Johan Meiringfead55a2012-11-20 19:28:47 +0200374 if (hereb4) { /* RLD DEBUG */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200375 hereb4--;
Bob Beers50ee11f2010-03-04 08:40:46 -0500376#ifdef RLD_TRANS_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +0200377 md = &ch->mdr[ch->rxix_irq_srv];
378 pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
Johan Meiring77c84b22012-11-20 19:28:48 +0200379 ch->channum, ch->rxix_irq_srv, md, le32_to_cpu(md->status),
Johan Meiringea9d1e92012-11-20 19:28:46 +0200380 ch->s.rx_packets);
Bob Beers50ee11f2010-03-04 08:40:46 -0500381#elif defined(RLD_RXACT_DEBUG)
Johan Meiringea9d1e92012-11-20 19:28:46 +0200382 md = &ch->mdr[ch->rxix_irq_srv];
383 pr_info("++ musycc_wq_chan_restart[%d] CHAN RX ACTIVATE: rxix_irq_srv %d, md %p sts %x, rxpkt %lu\n",
Johan Meiring77c84b22012-11-20 19:28:48 +0200384 ch->channum, ch->rxix_irq_srv, md, le32_to_cpu(md->status),
Johan Meiringea9d1e92012-11-20 19:28:46 +0200385 ch->s.rx_packets);
Johan Meiring77c84b22012-11-20 19:28:48 +0200386 musycc_dump_rxbuffer_ring(ch, 1); /* RLD DEBUG */
Bob Beers50ee11f2010-03-04 08:40:46 -0500387#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200388 }
389 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500390#endif
Johan Meiring77c84b22012-11-20 19:28:48 +0200391 musycc_serv_req(pi, SR_CHANNEL_ACTIVATE | SR_RX_DIRECTION | ch->gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -0500392 }
393 /**********************************/
394 /** check for TX restart request **/
395 /**********************************/
396
Johan Meiringfead55a2012-11-20 19:28:47 +0200397 if ((ch->ch_start_tx) && (ch->status & TX_ENABLED)) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200398 /* find next unprocessed message, then set TX thp to it */
Johan Meiring77c84b22012-11-20 19:28:48 +0200399 musycc_update_tx_thp(ch);
Bob Beers50ee11f2010-03-04 08:40:46 -0500400
401#if 0
Johan Meiring77c84b22012-11-20 19:28:48 +0200402 spin_lock_irqsave(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -0500403#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200404 md = ch->txd_irq_srv;
Johan Meiringfead55a2012-11-20 19:28:47 +0200405 if (!md) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500406#ifdef RLD_TRANS_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +0200407 pr_info("-- musycc_wq_chan_restart[%d]: WARNING, starting NULL md\n", ch->channum);
Bob Beers50ee11f2010-03-04 08:40:46 -0500408#endif
409#if 0
Johan Meiring77c84b22012-11-20 19:28:48 +0200410 spin_unlock_irqrestore(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -0500411#endif
Johan Meiring77c84b22012-11-20 19:28:48 +0200412 } else if (md->data && ((le32_to_cpu(md->status)) & MUSYCC_TX_OWNED)) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200413 ch->ch_start_tx = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500414#if 0
Johan Meiring77c84b22012-11-20 19:28:48 +0200415 spin_unlock_irqrestore(&ch->ch_txlock, flags); /* allow interrupts for service request */
Bob Beers50ee11f2010-03-04 08:40:46 -0500416#endif
417#ifdef RLD_TRANS_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +0200418 pr_info("++ musycc_wq_chan_restart() CHAN TX ACTIVATE: chan %d txd_irq_srv %p = sts %x, txpkt %lu\n",
419 ch->channum, ch->txd_irq_srv, ch->txd_irq_srv->status, ch->s.tx_packets);
Bob Beers50ee11f2010-03-04 08:40:46 -0500420#endif
Johan Meiring77c84b22012-11-20 19:28:48 +0200421 musycc_serv_req(pi, SR_CHANNEL_ACTIVATE | SR_TX_DIRECTION | ch->gchan);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200422 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500423#ifdef RLD_RESTART_DEBUG
Johan Meiringfead55a2012-11-20 19:28:47 +0200424 else {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200425 /* retain request to start until retried and we have data to xmit */
426 pr_info("-- musycc_wq_chan_restart[%d]: DELAYED due to md %p sts %x data %x, start_tx %x\n",
427 ch->channum, md,
Johan Meiring77c84b22012-11-20 19:28:48 +0200428 le32_to_cpu(md->status),
429 le32_to_cpu(md->data), ch->ch_start_tx);
430 musycc_dump_txbuffer_ring(ch, 0);
Bob Beers50ee11f2010-03-04 08:40:46 -0500431#if 0
Johan Meiring77c84b22012-11-20 19:28:48 +0200432 spin_unlock_irqrestore(&ch->ch_txlock, flags); /* allow interrupts for service request */
Bob Beers50ee11f2010-03-04 08:40:46 -0500433#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200434 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500435#endif
436 }
437}
Bob Beers50ee11f2010-03-04 08:40:46 -0500438
439
440 /*
441 * Channel restart either fires of a workqueue request (2.6) or lodges a
442 * watchdog activation sequence (2.4).
443 */
444
445void
Johan Meiring77c84b22012-11-20 19:28:48 +0200446musycc_chan_restart(mch_t * ch)
Bob Beers50ee11f2010-03-04 08:40:46 -0500447{
448#ifdef RLD_RESTART_DEBUG
Joe Perches694a9802010-05-03 12:33:16 -0700449 pr_info("++ musycc_chan_restart[%d]: txd_irq_srv @ %p = sts %x\n",
Johan Meiringea9d1e92012-11-20 19:28:46 +0200450 ch->channum, ch->txd_irq_srv, ch->txd_irq_srv->status);
Bob Beers50ee11f2010-03-04 08:40:46 -0500451#endif
452
Bob Beers50ee11f2010-03-04 08:40:46 -0500453 /* 2.6 - find next unprocessed message, then set TX thp to it */
454#ifdef RLD_RESTART_DEBUG
Joe Perches694a9802010-05-03 12:33:16 -0700455 pr_info(">> musycc_chan_restart: scheduling Chan %x workQ @ %p\n", ch->channum, &ch->ch_work);
Bob Beers50ee11f2010-03-04 08:40:46 -0500456#endif
Johan Meiring77c84b22012-11-20 19:28:48 +0200457 c4_wk_chan_restart(ch); /* work queue mechanism fires off: Ref:
Johan Meiringea9d1e92012-11-20 19:28:46 +0200458 * musycc_wq_chan_restart () */
Bob Beers50ee11f2010-03-04 08:40:46 -0500459
Bob Beers50ee11f2010-03-04 08:40:46 -0500460}
461
462
Bob Beers50ee11f2010-03-04 08:40:46 -0500463void
Johan Meiring77c84b22012-11-20 19:28:48 +0200464rld_put_led(mpi_t * pi, u_int32_t ledval)
Bob Beers50ee11f2010-03-04 08:40:46 -0500465{
466 static u_int32_t led = 0;
467
468 if (ledval == 0)
Johan Meiringea9d1e92012-11-20 19:28:46 +0200469 led = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500470 else
Johan Meiringea9d1e92012-11-20 19:28:46 +0200471 led |= ledval;
Bob Beers50ee11f2010-03-04 08:40:46 -0500472
Johan Meiring77c84b22012-11-20 19:28:48 +0200473 pci_write_32((u_int32_t *) &pi->up->cpldbase->leds, led); /* RLD DEBUG TRANHANG */
Bob Beers50ee11f2010-03-04 08:40:46 -0500474}
475
476
477#define MUSYCC_SR_RETRY_CNT 9
478
479void
Johan Meiring77c84b22012-11-20 19:28:48 +0200480musycc_serv_req(mpi_t * pi, u_int32_t req)
Bob Beers50ee11f2010-03-04 08:40:46 -0500481{
482 volatile u_int32_t r;
483 int rcnt;
484
485 /*
486 * PORT NOTE: Semaphore protect service loop guarantees only a single
487 * operation at a time. Per MUSYCC Manual - "Issuing service requests to
488 * the same channel group without first receiving ACK from each request
489 * may cause the host to lose track of which service request has been
490 * acknowledged."
491 */
492
Johan Meiring77c84b22012-11-20 19:28:48 +0200493 SD_SEM_TAKE(&pi->sr_sem_busy, "serv"); /* only 1 thru here, per
Johan Meiringea9d1e92012-11-20 19:28:46 +0200494 * group */
Bob Beers50ee11f2010-03-04 08:40:46 -0500495
Johan Meiringfead55a2012-11-20 19:28:47 +0200496 if (pi->sr_last == req) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500497#ifdef RLD_TRANS_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +0200498 pr_info(">> same SR, Port %d Req %x\n", pi->portnum, req);
Bob Beers50ee11f2010-03-04 08:40:46 -0500499#endif
500
Johan Meiringea9d1e92012-11-20 19:28:46 +0200501 /*
502 * The most likely repeated request is the channel activation command
503 * which follows the occurrence of a Transparent mode TX ONR or a
504 * BUFF error. If the previous command was a CHANNEL ACTIVATE,
505 * precede it with a NOOP command in order maintain coherent control
506 * of this current (re)ACTIVATE.
507 */
Bob Beers50ee11f2010-03-04 08:40:46 -0500508
Johan Meiringea9d1e92012-11-20 19:28:46 +0200509 r = (pi->sr_last & ~SR_GCHANNEL_MASK);
510 if ((r == (SR_CHANNEL_ACTIVATE | SR_TX_DIRECTION)) ||
Johan Meiringfead55a2012-11-20 19:28:47 +0200511 (r == (SR_CHANNEL_ACTIVATE | SR_RX_DIRECTION))) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500512#ifdef RLD_TRANS_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +0200513 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 -0500514#endif
Johan Meiring77c84b22012-11-20 19:28:48 +0200515 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow this next request */
516 musycc_serv_req(pi, SR_NOOP);
517 SD_SEM_TAKE(&pi->sr_sem_busy, "serv"); /* relock & continue w/
Johan Meiringea9d1e92012-11-20 19:28:46 +0200518 * original req */
Johan Meiringfead55a2012-11-20 19:28:47 +0200519 } else if (req == SR_NOOP) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200520 /* no need to issue back-to-back SR_NOOP commands at this time */
Bob Beers50ee11f2010-03-04 08:40:46 -0500521#ifdef RLD_TRANS_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +0200522 pr_info(">> same Port SR_NOOP skipped, Port %d\n", pi->portnum);
Bob Beers50ee11f2010-03-04 08:40:46 -0500523#endif
Johan Meiring77c84b22012-11-20 19:28:48 +0200524 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow this next request */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200525 return;
526 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500527 }
528 rcnt = 0;
529 pi->sr_last = req;
530rewrite:
Johan Meiring77c84b22012-11-20 19:28:48 +0200531 pci_write_32((u_int32_t *) &pi->reg->srd, req);
532 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500533
534 /*
535 * Per MUSYCC Manual, Section 6.1,2 - "When writing an SCR service
536 * request, the host must ensure at least one PCI bus clock cycle has
537 * elapsed before writing another service request. To meet this minimum
538 * elapsed service request write timing interval, it is recommended that
539 * the host follow any SCR write with another operation which reads from
540 * the same address."
541 */
Johan Meiring77c84b22012-11-20 19:28:48 +0200542 r = pci_read_32((u_int32_t *) &pi->reg->srd); /* adhere to write
Johan Meiringea9d1e92012-11-20 19:28:46 +0200543 * timing imposition */
Bob Beers50ee11f2010-03-04 08:40:46 -0500544
545
Johan Meiringfead55a2012-11-20 19:28:47 +0200546 if ((r != req) && (req != SR_CHIP_RESET) && (++rcnt <= MUSYCC_SR_RETRY_CNT)) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200547 if (cxt1e1_log_level >= LOG_MONITOR)
548 pr_info("%s: %d - reissue srv req/last %x/%x (hdw reads %x), Chan %d.\n",
549 pi->up->devname, rcnt, req, pi->sr_last, r,
550 (pi->portnum * MUSYCC_NCHANS) + (req & 0x1f));
Johan Meiring77c84b22012-11-20 19:28:48 +0200551 OS_uwait_dummy(); /* this delay helps reduce reissue counts
Johan Meiringea9d1e92012-11-20 19:28:46 +0200552 * (reason not yet researched) */
553 goto rewrite;
Bob Beers50ee11f2010-03-04 08:40:46 -0500554 }
Johan Meiringfead55a2012-11-20 19:28:47 +0200555 if (rcnt > MUSYCC_SR_RETRY_CNT) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200556 pr_warning("%s: failed service request (#%d)= %x, group %d.\n",
557 pi->up->devname, MUSYCC_SR_RETRY_CNT, req, pi->portnum);
Johan Meiring77c84b22012-11-20 19:28:48 +0200558 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow any next request */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200559 return;
Bob Beers50ee11f2010-03-04 08:40:46 -0500560 }
Johan Meiringfead55a2012-11-20 19:28:47 +0200561 if (req == SR_CHIP_RESET) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200562 /*
563 * PORT NOTE: the CHIP_RESET command is NOT ack'd by the MUSYCC, thus
564 * the upcoming delay is used. Though the MUSYCC documentation
565 * suggests a read-after-write would supply the required delay, it's
566 * unclear what CPU/BUS clock speeds might have been assumed when
567 * suggesting this 'lack of ACK' workaround. Thus the use of uwait.
568 */
Johan Meiring77c84b22012-11-20 19:28:48 +0200569 OS_uwait(100000, "icard"); /* 100ms */
Johan Meiringfead55a2012-11-20 19:28:47 +0200570 } else {
Johan Meiring77c84b22012-11-20 19:28:48 +0200571 FLUSH_MEM_READ();
572 SD_SEM_TAKE(&pi->sr_sem_wait, "sakack"); /* sleep until SACK
Johan Meiringea9d1e92012-11-20 19:28:46 +0200573 * interrupt occurs */
Bob Beers50ee11f2010-03-04 08:40:46 -0500574 }
Johan Meiring77c84b22012-11-20 19:28:48 +0200575 SD_SEM_GIVE(&pi->sr_sem_busy); /* allow any next request */
Bob Beers50ee11f2010-03-04 08:40:46 -0500576}
577
578
579#ifdef SBE_PMCC4_ENABLE
580void
Johan Meiring77c84b22012-11-20 19:28:48 +0200581musycc_update_timeslots(mpi_t * pi)
Bob Beers50ee11f2010-03-04 08:40:46 -0500582{
583 int i, ch;
Johan Meiring77c84b22012-11-20 19:28:48 +0200584 char e1mode = IS_FRAME_ANY_E1(pi->p.port_mode);
Bob Beers50ee11f2010-03-04 08:40:46 -0500585
Johan Meiringfead55a2012-11-20 19:28:47 +0200586 for (i = 0; i < 32; i++) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200587 int usedby = 0, last = 0, ts, j, bits[8];
Bob Beers50ee11f2010-03-04 08:40:46 -0500588
Johan Meiringea9d1e92012-11-20 19:28:46 +0200589 u_int8_t lastval = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500590
Johan Meiringea9d1e92012-11-20 19:28:46 +0200591 if (((i == 0) && e1mode) || /* disable if E1 mode */
592 ((i == 16) && ((pi->p.port_mode == CFG_FRAME_E1CRC_CAS) || (pi->p.port_mode == CFG_FRAME_E1CRC_CAS_AMI)))
593 || ((i > 23) && (!e1mode))) /* disable if T1 mode */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200594 pi->tsm[i] = 0xff; /* make tslot unavailable for this mode */
Johan Meiringfead55a2012-11-20 19:28:47 +0200595 else
Johan Meiringea9d1e92012-11-20 19:28:46 +0200596 pi->tsm[i] = 0x00; /* make tslot available for assignment */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200597 for (j = 0; j < 8; j++)
598 bits[j] = -1;
Johan Meiringfead55a2012-11-20 19:28:47 +0200599 for (ch = 0; ch < MUSYCC_NCHANS; ch++) {
600 if ((pi->chan[ch]->state == UP) && (pi->chan[ch]->p.bitmask[i])) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200601 usedby++;
602 last = ch;
603 lastval = pi->chan[ch]->p.bitmask[i];
604 for (j = 0; j < 8; j++)
605 if (lastval & (1 << j))
606 bits[j] = ch;
607 pi->tsm[i] |= lastval;
608 }
609 }
610 if (!usedby)
611 ts = 0;
612 else if ((usedby == 1) && (lastval == 0xff))
613 ts = (4 << 5) | last;
614 else if ((usedby == 1) && (lastval == 0x7f))
615 ts = (5 << 5) | last;
Johan Meiringfead55a2012-11-20 19:28:47 +0200616 else {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200617 int idx;
Bob Beers50ee11f2010-03-04 08:40:46 -0500618
Johan Meiringea9d1e92012-11-20 19:28:46 +0200619 if (bits[0] < 0)
620 ts = (6 << 5) | (idx = last);
621 else
622 ts = (7 << 5) | (idx = bits[0]);
Johan Meiringfead55a2012-11-20 19:28:47 +0200623 for (j = 1; j < 8; j++) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200624 pi->regram->rscm[idx * 8 + j] = (bits[j] < 0) ? 0 : (0x80 | bits[j]);
625 pi->regram->tscm[idx * 8 + j] = (bits[j] < 0) ? 0 : (0x80 | bits[j]);
626 }
627 }
628 pi->regram->rtsm[i] = ts;
629 pi->regram->ttsm[i] = ts;
Bob Beers50ee11f2010-03-04 08:40:46 -0500630 }
Johan Meiring77c84b22012-11-20 19:28:48 +0200631 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500632
Johan Meiring77c84b22012-11-20 19:28:48 +0200633 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_RX_DIRECTION);
634 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_TX_DIRECTION);
635 musycc_serv_req(pi, SR_SUBCHANNEL_MAP | SR_RX_DIRECTION);
636 musycc_serv_req(pi, SR_SUBCHANNEL_MAP | SR_TX_DIRECTION);
Bob Beers50ee11f2010-03-04 08:40:46 -0500637}
638#endif
639
640
641#ifdef SBE_WAN256T3_ENABLE
642void
Johan Meiring77c84b22012-11-20 19:28:48 +0200643musycc_update_timeslots(mpi_t * pi)
Bob Beers50ee11f2010-03-04 08:40:46 -0500644{
645 mch_t *ch;
646
647 u_int8_t ts, hmask, tsen;
648 int gchan;
649 int i;
650
651#ifdef SBE_PMCC4_ENABLE
652 hmask = (0x1f << pi->up->p.hypersize) & 0x1f;
653#endif
654#ifdef SBE_WAN256T3_ENABLE
655 hmask = (0x1f << hyperdummy) & 0x1f;
656#endif
Johan Meiringfead55a2012-11-20 19:28:47 +0200657 for (i = 0; i < 128; i++) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200658 gchan = ((pi->portnum * MUSYCC_NCHANS) + (i & hmask)) % MUSYCC_NCHANS;
659 ch = pi->chan[gchan];
660 if (ch->p.mode_56k)
661 tsen = MODE_56KBPS;
662 else
663 tsen = MODE_64KBPS; /* also the default */
664 ts = ((pi->portnum % 4) == (i / 32)) ? (tsen << 5) | (i & hmask) : 0;
665 pi->regram->rtsm[i] = ts;
666 pi->regram->ttsm[i] = ts;
Bob Beers50ee11f2010-03-04 08:40:46 -0500667 }
Johan Meiring77c84b22012-11-20 19:28:48 +0200668 FLUSH_MEM_WRITE();
669 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_RX_DIRECTION);
670 musycc_serv_req(pi, SR_TIMESLOT_MAP | SR_TX_DIRECTION);
Bob Beers50ee11f2010-03-04 08:40:46 -0500671}
672#endif
673
674
675 /*
676 * This routine converts a generic library channel configuration parameter
677 * into a hardware specific register value (IE. MUSYCC CCD Register).
678 */
679u_int32_t
Johan Meiring77c84b22012-11-20 19:28:48 +0200680musycc_chan_proto(int proto)
Bob Beers50ee11f2010-03-04 08:40:46 -0500681{
682 int reg;
683
Johan Meiringfead55a2012-11-20 19:28:47 +0200684 switch (proto) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500685 case CFG_CH_PROTO_TRANS: /* 0 */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200686 reg = MUSYCC_CCD_TRANS;
687 break;
Bob Beers50ee11f2010-03-04 08:40:46 -0500688 case CFG_CH_PROTO_SS7: /* 1 */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200689 reg = MUSYCC_CCD_SS7;
690 break;
Bob Beers50ee11f2010-03-04 08:40:46 -0500691 default:
692 case CFG_CH_PROTO_ISLP_MODE: /* 4 */
693 case CFG_CH_PROTO_HDLC_FCS16: /* 2 */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200694 reg = MUSYCC_CCD_HDLC_FCS16;
695 break;
Bob Beers50ee11f2010-03-04 08:40:46 -0500696 case CFG_CH_PROTO_HDLC_FCS32: /* 3 */
Johan Meiringea9d1e92012-11-20 19:28:46 +0200697 reg = MUSYCC_CCD_HDLC_FCS32;
698 break;
Bob Beers50ee11f2010-03-04 08:40:46 -0500699 }
700
701 return reg;
702}
703
704#ifdef SBE_WAN256T3_ENABLE
705STATIC void __init
Johan Meiring77c84b22012-11-20 19:28:48 +0200706musycc_init_port(mpi_t * pi)
Bob Beers50ee11f2010-03-04 08:40:46 -0500707{
Johan Meiring77c84b22012-11-20 19:28:48 +0200708 pci_write_32((u_int32_t *) &pi->reg->gbp, OS_vtophys(pi->regram));
Bob Beers50ee11f2010-03-04 08:40:46 -0500709
710 pi->regram->grcd =
Johan Meiring77c84b22012-11-20 19:28:48 +0200711 __constant_cpu_to_le32(MUSYCC_GRCD_RX_ENABLE |
Johan Meiringea9d1e92012-11-20 19:28:46 +0200712 MUSYCC_GRCD_TX_ENABLE |
713 MUSYCC_GRCD_SF_ALIGN |
714 MUSYCC_GRCD_SUBCHAN_DISABLE |
715 MUSYCC_GRCD_OOFMP_DISABLE |
716 MUSYCC_GRCD_COFAIRQ_DISABLE |
717 MUSYCC_GRCD_MC_ENABLE |
718 (MUSYCC_GRCD_POLLTH_32 << MUSYCC_GRCD_POLLTH_SHIFT));
Bob Beers50ee11f2010-03-04 08:40:46 -0500719
720 pi->regram->pcd =
Johan Meiring77c84b22012-11-20 19:28:48 +0200721 __constant_cpu_to_le32(MUSYCC_PCD_E1X4_MODE |
Johan Meiringea9d1e92012-11-20 19:28:46 +0200722 MUSYCC_PCD_TXDATA_RISING |
723 MUSYCC_PCD_TX_DRIVEN);
Bob Beers50ee11f2010-03-04 08:40:46 -0500724
725 /* Message length descriptor */
Johan Meiring77c84b22012-11-20 19:28:48 +0200726 pi->regram->mld = __constant_cpu_to_le32(cxt1e1_max_mru | (cxt1e1_max_mru << 16));
727 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500728
Johan Meiring77c84b22012-11-20 19:28:48 +0200729 musycc_serv_req(pi, SR_GROUP_INIT | SR_RX_DIRECTION);
730 musycc_serv_req(pi, SR_GROUP_INIT | SR_TX_DIRECTION);
Bob Beers50ee11f2010-03-04 08:40:46 -0500731
Johan Meiring77c84b22012-11-20 19:28:48 +0200732 musycc_init_mdt(pi);
Bob Beers50ee11f2010-03-04 08:40:46 -0500733
Johan Meiring77c84b22012-11-20 19:28:48 +0200734 musycc_update_timeslots(pi);
Bob Beers50ee11f2010-03-04 08:40:46 -0500735}
736#endif
737
738
739status_t __init
Johan Meiring77c84b22012-11-20 19:28:48 +0200740musycc_init(ci_t * ci)
Bob Beers50ee11f2010-03-04 08:40:46 -0500741{
742 char *regaddr; /* temp for address boundary calculations */
743 int i, gchan;
744
Johan Meiring77c84b22012-11-20 19:28:48 +0200745 OS_sem_init(&ci->sem_wdbusy, SEM_AVAILABLE); /* watchdog exclusion */
Bob Beers50ee11f2010-03-04 08:40:46 -0500746
747 /*
748 * Per MUSYCC manual, Section 6.3.4 - "The host must allocate a dword
749 * aligned memory segment for interrupt queue pointers."
750 */
751
752#define INT_QUEUE_BOUNDARY 4
753
Johan Meiring77c84b22012-11-20 19:28:48 +0200754 regaddr = OS_kmalloc((INT_QUEUE_SIZE + 1) * sizeof(u_int32_t));
Bob Beers50ee11f2010-03-04 08:40:46 -0500755 if (regaddr == 0)
Johan Meiringea9d1e92012-11-20 19:28:46 +0200756 return ENOMEM;
Bob Beers50ee11f2010-03-04 08:40:46 -0500757 ci->iqd_p_saved = regaddr; /* save orig value for free's usage */
758 ci->iqd_p = (u_int32_t *) ((unsigned long) (regaddr + INT_QUEUE_BOUNDARY - 1) &
Johan Meiringea9d1e92012-11-20 19:28:46 +0200759 (~(INT_QUEUE_BOUNDARY - 1))); /* this calculates
760 * closest boundary */
Bob Beers50ee11f2010-03-04 08:40:46 -0500761
762 for (i = 0; i < INT_QUEUE_SIZE; i++)
Johan Meiring77c84b22012-11-20 19:28:48 +0200763 ci->iqd_p[i] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
Bob Beers50ee11f2010-03-04 08:40:46 -0500764
Johan Meiringfead55a2012-11-20 19:28:47 +0200765 for (i = 0; i < ci->max_port; i++) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200766 mpi_t *pi = &ci->port[i];
Bob Beers50ee11f2010-03-04 08:40:46 -0500767
Johan Meiringea9d1e92012-11-20 19:28:46 +0200768 /*
769 * Per MUSYCC manual, Section 6.3.2 - "The host must allocate a 2KB
770 * bound memory segment for Channel Group 0."
771 */
Bob Beers50ee11f2010-03-04 08:40:46 -0500772
773#define GROUP_BOUNDARY 0x800
774
Johan Meiring77c84b22012-11-20 19:28:48 +0200775 regaddr = OS_kmalloc(sizeof(struct musycc_groupr) + GROUP_BOUNDARY);
Johan Meiringfead55a2012-11-20 19:28:47 +0200776 if (regaddr == 0) {
777 for (gchan = 0; gchan < i; gchan++) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200778 pi = &ci->port[gchan];
Johan Meiring77c84b22012-11-20 19:28:48 +0200779 OS_kfree(pi->reg);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200780 pi->reg = 0;
781 }
782 return ENOMEM;
783 }
784 pi->regram_saved = regaddr; /* save orig value for free's usage */
785 pi->regram = (struct musycc_groupr *) ((unsigned long) (regaddr + GROUP_BOUNDARY - 1) &
786 (~(GROUP_BOUNDARY - 1))); /* this calculates
787 * closest boundary */
Bob Beers50ee11f2010-03-04 08:40:46 -0500788 }
789
790 /* any board centric MUSYCC commands will use group ZERO as its "home" */
791 ci->regram = ci->port[0].regram;
Johan Meiring77c84b22012-11-20 19:28:48 +0200792 musycc_serv_req(&ci->port[0], SR_CHIP_RESET);
Bob Beers50ee11f2010-03-04 08:40:46 -0500793
Johan Meiring77c84b22012-11-20 19:28:48 +0200794 pci_write_32((u_int32_t *) &ci->reg->gbp, OS_vtophys(ci->regram));
795 pci_flush_write(ci);
Bob Beers50ee11f2010-03-04 08:40:46 -0500796#ifdef CONFIG_SBE_PMCC4_NCOMM
Johan Meiring77c84b22012-11-20 19:28:48 +0200797 ci->regram->__glcd = __constant_cpu_to_le32(GCD_MAGIC);
Bob Beers50ee11f2010-03-04 08:40:46 -0500798#else
799 /* standard driver POLLS for INTB via CPLD register */
Johan Meiring77c84b22012-11-20 19:28:48 +0200800 ci->regram->__glcd = __constant_cpu_to_le32(GCD_MAGIC | MUSYCC_GCD_INTB_DISABLE);
Bob Beers50ee11f2010-03-04 08:40:46 -0500801#endif
802
Johan Meiring77c84b22012-11-20 19:28:48 +0200803 ci->regram->__iqp = cpu_to_le32(OS_vtophys(&ci->iqd_p[0]));
804 ci->regram->__iql = __constant_cpu_to_le32(INT_QUEUE_SIZE - 1);
805 pci_write_32((u_int32_t *) &ci->reg->dacbp, 0);
806 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500807
808 ci->state = C_RUNNING; /* mark as full interrupt processing
Johan Meiringea9d1e92012-11-20 19:28:46 +0200809 * available */
Bob Beers50ee11f2010-03-04 08:40:46 -0500810
Johan Meiring77c84b22012-11-20 19:28:48 +0200811 musycc_serv_req(&ci->port[0], SR_GLOBAL_INIT); /* FIRST INTERRUPT ! */
Bob Beers50ee11f2010-03-04 08:40:46 -0500812
813 /* sanity check settable parameters */
814
Johan Meiringfead55a2012-11-20 19:28:47 +0200815 if (cxt1e1_max_mru > 0xffe) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200816 pr_warning("Maximum allowed MRU exceeded, resetting %d to %d.\n",
817 cxt1e1_max_mru, 0xffe);
818 cxt1e1_max_mru = 0xffe;
Bob Beers50ee11f2010-03-04 08:40:46 -0500819 }
Johan Meiringfead55a2012-11-20 19:28:47 +0200820 if (cxt1e1_max_mtu > 0xffe) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200821 pr_warning("Maximum allowed MTU exceeded, resetting %d to %d.\n",
822 cxt1e1_max_mtu, 0xffe);
823 cxt1e1_max_mtu = 0xffe;
Bob Beers50ee11f2010-03-04 08:40:46 -0500824 }
825#ifdef SBE_WAN256T3_ENABLE
826 for (i = 0; i < MUSYCC_NPORTS; i++)
Johan Meiring77c84b22012-11-20 19:28:48 +0200827 musycc_init_port(&ci->port[i]);
Bob Beers50ee11f2010-03-04 08:40:46 -0500828#endif
829
830 return SBE_DRVR_SUCCESS; /* no error */
831}
832
833
834void
Johan Meiring77c84b22012-11-20 19:28:48 +0200835musycc_bh_tx_eom(mpi_t * pi, int gchan)
Bob Beers50ee11f2010-03-04 08:40:46 -0500836{
837 mch_t *ch;
838 struct mdesc *md;
839
840#if 0
841#ifndef SBE_ISR_INLINE
842 unsigned long flags;
843
844#endif
845#endif
846 volatile u_int32_t status;
847
848 ch = pi->chan[gchan];
Johan Meiringfead55a2012-11-20 19:28:47 +0200849 if (ch == 0 || ch->state != UP) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200850 if (cxt1e1_log_level >= LOG_ERROR)
851 pr_info("%s: intr: xmit EOM on uninitialized channel %d\n",
852 pi->up->devname, gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -0500853 }
854 if (ch == 0 || ch->mdt == 0)
Johan Meiringea9d1e92012-11-20 19:28:46 +0200855 return; /* note: mdt==0 implies a malloc()
856 * failure w/in chan_up() routine */
Bob Beers50ee11f2010-03-04 08:40:46 -0500857
858#if 0
859#ifdef SBE_ISR_INLINE
Johan Meiring77c84b22012-11-20 19:28:48 +0200860 spin_lock_irq(&ch->ch_txlock);
Bob Beers50ee11f2010-03-04 08:40:46 -0500861#else
Johan Meiring77c84b22012-11-20 19:28:48 +0200862 spin_lock_irqsave(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -0500863#endif
864#endif
Johan Meiringfead55a2012-11-20 19:28:47 +0200865 do {
Johan Meiring77c84b22012-11-20 19:28:48 +0200866 FLUSH_MEM_READ();
Johan Meiringea9d1e92012-11-20 19:28:46 +0200867 md = ch->txd_irq_srv;
Johan Meiring77c84b22012-11-20 19:28:48 +0200868 status = le32_to_cpu(md->status);
Bob Beers50ee11f2010-03-04 08:40:46 -0500869
Johan Meiringea9d1e92012-11-20 19:28:46 +0200870 /*
871 * Note: Per MUSYCC Ref 6.4.9, the host does not poll a host-owned
872 * Transmit Buffer Descriptor during Transparent Mode.
873 */
Johan Meiringfead55a2012-11-20 19:28:47 +0200874 if (status & MUSYCC_TX_OWNED) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200875 int readCount, loopCount;
Bob Beers50ee11f2010-03-04 08:40:46 -0500876
Johan Meiringea9d1e92012-11-20 19:28:46 +0200877 /***********************************************************/
878 /* HW Bug Fix */
879 /* ---------- */
880 /* Under certain PCI Bus loading conditions, the data */
881 /* associated with an update of Shared Memory is delayed */
882 /* relative to its PCI Interrupt. This is caught when */
883 /* the host determines it does not yet OWN the descriptor. */
884 /***********************************************************/
Bob Beers50ee11f2010-03-04 08:40:46 -0500885
Johan Meiringea9d1e92012-11-20 19:28:46 +0200886 readCount = 0;
Johan Meiringfead55a2012-11-20 19:28:47 +0200887 while (status & MUSYCC_TX_OWNED) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200888 for (loopCount = 0; loopCount < 0x30; loopCount++)
Johan Meiring77c84b22012-11-20 19:28:48 +0200889 OS_uwait_dummy(); /* use call to avoid optimization
Johan Meiringea9d1e92012-11-20 19:28:46 +0200890 * removal of dummy delay */
Johan Meiring77c84b22012-11-20 19:28:48 +0200891 FLUSH_MEM_READ();
892 status = le32_to_cpu(md->status);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200893 if (readCount++ > 40)
894 break; /* don't wait any longer */
895 }
Johan Meiringfead55a2012-11-20 19:28:47 +0200896 if (status & MUSYCC_TX_OWNED) {
897 if (cxt1e1_log_level >= LOG_MONITOR) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200898 pr_info("%s: Port %d Chan %2d - unexpected TX msg ownership intr (md %p sts %x)\n",
899 pi->up->devname, pi->portnum, ch->channum,
900 md, status);
901 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",
902 ch->user, ch->txd_irq_srv, ch->txd_usr_add,
Johan Meiring77c84b22012-11-20 19:28:48 +0200903 sd_queue_stopped(ch->user),
Johan Meiringea9d1e92012-11-20 19:28:46 +0200904 ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
Johan Meiring77c84b22012-11-20 19:28:48 +0200905 musycc_dump_txbuffer_ring(ch, 0);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200906 }
907 break; /* Not our mdesc, done */
Johan Meiringfead55a2012-11-20 19:28:47 +0200908 } else {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200909 if (cxt1e1_log_level >= LOG_MONITOR)
910 pr_info("%s: Port %d Chan %2d - recovered TX msg ownership [%d] (md %p sts %x)\n",
911 pi->up->devname, pi->portnum, ch->channum, readCount, md, status);
912 }
913 }
914 ch->txd_irq_srv = md->snext;
Bob Beers50ee11f2010-03-04 08:40:46 -0500915
Johan Meiringea9d1e92012-11-20 19:28:46 +0200916 md->data = 0;
Johan Meiringfead55a2012-11-20 19:28:47 +0200917 if (md->mem_token != 0) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200918 /* upcount channel */
Johan Meiring77c84b22012-11-20 19:28:48 +0200919 atomic_sub(OS_mem_token_tlen(md->mem_token), &ch->tx_pending);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200920 /* upcount card */
Johan Meiring77c84b22012-11-20 19:28:48 +0200921 atomic_sub(OS_mem_token_tlen(md->mem_token), &pi->up->tx_pending);
Bob Beers50ee11f2010-03-04 08:40:46 -0500922#ifdef SBE_WAN256T3_ENABLE
Johan Meiring77c84b22012-11-20 19:28:48 +0200923 if (!atomic_read(&pi->up->tx_pending))
924 wan256t3_led(pi->up, LED_TX, 0);
Bob Beers50ee11f2010-03-04 08:40:46 -0500925#endif
926
927#ifdef CONFIG_SBE_WAN256T3_NCOMM
Johan Meiringea9d1e92012-11-20 19:28:46 +0200928 /* callback that our packet was sent */
929 {
930 int hdlcnum = (pi->portnum * 32 + gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -0500931
Johan Meiringfead55a2012-11-20 19:28:47 +0200932 if (hdlcnum >= 228) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200933 if (nciProcess_TX_complete)
934 (*nciProcess_TX_complete) (hdlcnum,
Johan Meiring77c84b22012-11-20 19:28:48 +0200935 getuserbychan(gchan));
Johan Meiringea9d1e92012-11-20 19:28:46 +0200936 }
937 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500938#endif /*** CONFIG_SBE_WAN256T3_NCOMM ***/
939
Johan Meiring77c84b22012-11-20 19:28:48 +0200940 OS_mem_token_free_irq(md->mem_token);
Johan Meiringea9d1e92012-11-20 19:28:46 +0200941 md->mem_token = 0;
942 }
943 md->status = 0;
Bob Beers50ee11f2010-03-04 08:40:46 -0500944#ifdef RLD_TXFULL_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +0200945 if (cxt1e1_log_level >= LOG_MONITOR2)
946 pr_info("~~ tx_eom: tx_full %x txd_free %d -> %d\n",
947 ch->tx_full, ch->txd_free, ch->txd_free + 1);
Bob Beers50ee11f2010-03-04 08:40:46 -0500948#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200949 ++ch->txd_free;
Johan Meiring77c84b22012-11-20 19:28:48 +0200950 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -0500951
Johan Meiringfead55a2012-11-20 19:28:47 +0200952 if ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) && (status & EOBIRQ_ENABLE)) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200953 if (cxt1e1_log_level >= LOG_MONITOR)
954 pr_info("%s: Mode (%x) incorrect EOB status (%x)\n",
955 pi->up->devname, ch->p.chan_mode, status);
956 if ((status & EOMIRQ_ENABLE) == 0)
957 break;
958 }
Johan Meiringfead55a2012-11-20 19:28:47 +0200959 } while ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) && ((status & EOMIRQ_ENABLE) == 0));
Bob Beers50ee11f2010-03-04 08:40:46 -0500960 /*
961 * NOTE: (The above 'while' is coupled w/ previous 'do', way above.) Each
962 * Transparent data buffer has the EOB bit, and NOT the EOM bit, set and
963 * will furthermore have a separate IQD associated with each messages
964 * buffer.
965 */
966
Johan Meiring77c84b22012-11-20 19:28:48 +0200967 FLUSH_MEM_READ();
Bob Beers50ee11f2010-03-04 08:40:46 -0500968 /*
969 * Smooth flow control hysterisis by maintaining task stoppage until half
970 * the available write buffers are available.
971 */
Johan Meiringfead55a2012-11-20 19:28:47 +0200972 if (ch->tx_full && (ch->txd_free >= (ch->txd_num / 2))) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200973 /*
974 * Then, only releave task stoppage if we actually have enough
975 * buffers to service the last requested packet. It may require MORE
976 * than half the available!
977 */
Johan Meiringfead55a2012-11-20 19:28:47 +0200978 if (ch->txd_free >= ch->txd_required) {
Bob Beers50ee11f2010-03-04 08:40:46 -0500979
980#ifdef RLD_TXFULL_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +0200981 if (cxt1e1_log_level >= LOG_MONITOR2)
982 pr_info("tx_eom[%d]: enable xmit tx_full no more, txd_free %d txd_num/2 %d\n",
983 ch->channum,
984 ch->txd_free, ch->txd_num / 2);
Bob Beers50ee11f2010-03-04 08:40:46 -0500985#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +0200986 ch->tx_full = 0;
987 ch->txd_required = 0;
Johan Meiring77c84b22012-11-20 19:28:48 +0200988 sd_enable_xmit(ch->user); /* re-enable to catch flow controlled
Johan Meiringea9d1e92012-11-20 19:28:46 +0200989 * channel */
990 }
Bob Beers50ee11f2010-03-04 08:40:46 -0500991 }
992#ifdef RLD_TXFULL_DEBUG
Johan Meiringfead55a2012-11-20 19:28:47 +0200993 else if (ch->tx_full) {
Johan Meiringea9d1e92012-11-20 19:28:46 +0200994 if (cxt1e1_log_level >= LOG_MONITOR2)
995 pr_info("tx_eom[%d]: bypass TX enable though room available? (txd_free %d txd_num/2 %d)\n",
996 ch->channum,
997 ch->txd_free, ch->txd_num / 2);
Bob Beers50ee11f2010-03-04 08:40:46 -0500998 }
999#endif
1000
Johan Meiring77c84b22012-11-20 19:28:48 +02001001 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -05001002#if 0
1003#ifdef SBE_ISR_INLINE
Johan Meiring77c84b22012-11-20 19:28:48 +02001004 spin_unlock_irq(&ch->ch_txlock);
Bob Beers50ee11f2010-03-04 08:40:46 -05001005#else
Johan Meiring77c84b22012-11-20 19:28:48 +02001006 spin_unlock_irqrestore(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -05001007#endif
1008#endif
1009}
1010
1011
1012STATIC void
Johan Meiring77c84b22012-11-20 19:28:48 +02001013musycc_bh_rx_eom(mpi_t * pi, int gchan)
Bob Beers50ee11f2010-03-04 08:40:46 -05001014{
1015 mch_t *ch;
1016 void *m, *m2;
1017 struct mdesc *md;
1018 volatile u_int32_t status;
1019 u_int32_t error;
1020
1021 ch = pi->chan[gchan];
Johan Meiringfead55a2012-11-20 19:28:47 +02001022 if (ch == 0 || ch->state != UP) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001023 if (cxt1e1_log_level > LOG_ERROR)
1024 pr_info("%s: intr: receive EOM on uninitialized channel %d\n",
1025 pi->up->devname, gchan);
1026 return;
Bob Beers50ee11f2010-03-04 08:40:46 -05001027 }
1028 if (ch->mdr == 0)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001029 return; /* can this happen ? */
Bob Beers50ee11f2010-03-04 08:40:46 -05001030
Johan Meiringfead55a2012-11-20 19:28:47 +02001031 for (;;) {
Johan Meiring77c84b22012-11-20 19:28:48 +02001032 FLUSH_MEM_READ();
Johan Meiringea9d1e92012-11-20 19:28:46 +02001033 md = &ch->mdr[ch->rxix_irq_srv];
Johan Meiring77c84b22012-11-20 19:28:48 +02001034 status = le32_to_cpu(md->status);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001035 if (!(status & HOST_RX_OWNED))
1036 break; /* Not our mdesc, done */
1037 m = md->mem_token;
1038 error = (status >> 16) & 0xf;
Johan Meiringfead55a2012-11-20 19:28:47 +02001039 if (error == 0) {
Bob Beers50ee11f2010-03-04 08:40:46 -05001040#ifdef CONFIG_SBE_WAN256T3_NCOMM
Johan Meiringea9d1e92012-11-20 19:28:46 +02001041 int hdlcnum = (pi->portnum * 32 + gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -05001042
Johan Meiringea9d1e92012-11-20 19:28:46 +02001043 /*
1044 * if the packet number belongs to NCOMM, then send it to the TMS
1045 * driver
1046 */
Johan Meiringfead55a2012-11-20 19:28:47 +02001047 if (hdlcnum >= 228) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001048 if (nciProcess_RX_packet)
1049 (*nciProcess_RX_packet) (hdlcnum, status & 0x3fff, m, ch->user);
1050 } else
Bob Beers50ee11f2010-03-04 08:40:46 -05001051#endif /*** CONFIG_SBE_WAN256T3_NCOMM ***/
1052
Johan Meiringea9d1e92012-11-20 19:28:46 +02001053 {
Johan Meiring77c84b22012-11-20 19:28:48 +02001054 if ((m2 = OS_mem_token_alloc(cxt1e1_max_mru))) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001055 /* substitute the mbuf+cluster */
1056 md->mem_token = m2;
Johan Meiring77c84b22012-11-20 19:28:48 +02001057 md->data = cpu_to_le32(OS_vtophys(OS_mem_token_data(m2)));
Bob Beers50ee11f2010-03-04 08:40:46 -05001058
Johan Meiringea9d1e92012-11-20 19:28:46 +02001059 /* pass the received mbuf upward */
Johan Meiring77c84b22012-11-20 19:28:48 +02001060 sd_recv_consume(m, status & LENGTH_MASK, ch->user);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001061 ch->s.rx_packets++;
1062 ch->s.rx_bytes += status & LENGTH_MASK;
1063 } else
Johan Meiringea9d1e92012-11-20 19:28:46 +02001064 ch->s.rx_dropped++;
Johan Meiringea9d1e92012-11-20 19:28:46 +02001065 }
1066 } else if (error == ERR_FCS)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001067 ch->s.rx_crc_errors++;
Johan Meiringfead55a2012-11-20 19:28:47 +02001068 else if (error == ERR_ALIGN)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001069 ch->s.rx_missed_errors++;
Johan Meiringfead55a2012-11-20 19:28:47 +02001070 else if (error == ERR_ABT)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001071 ch->s.rx_missed_errors++;
Johan Meiringfead55a2012-11-20 19:28:47 +02001072 else if (error == ERR_LNG)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001073 ch->s.rx_length_errors++;
Johan Meiringfead55a2012-11-20 19:28:47 +02001074 else if (error == ERR_SHT)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001075 ch->s.rx_length_errors++;
Johan Meiring77c84b22012-11-20 19:28:48 +02001076 FLUSH_MEM_WRITE();
Johan Meiringea9d1e92012-11-20 19:28:46 +02001077 status = cxt1e1_max_mru;
1078 if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
1079 status |= EOBIRQ_ENABLE;
Johan Meiring77c84b22012-11-20 19:28:48 +02001080 md->status = cpu_to_le32(status);
Bob Beers50ee11f2010-03-04 08:40:46 -05001081
Johan Meiringea9d1e92012-11-20 19:28:46 +02001082 /* Check next mdesc in the ring */
1083 if (++ch->rxix_irq_srv >= ch->rxd_num)
1084 ch->rxix_irq_srv = 0;
Johan Meiring77c84b22012-11-20 19:28:48 +02001085 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -05001086 }
1087}
1088
1089
1090irqreturn_t
Johan Meiring77c84b22012-11-20 19:28:48 +02001091musycc_intr_th_handler(void *devp)
Bob Beers50ee11f2010-03-04 08:40:46 -05001092{
1093 ci_t *ci = (ci_t *) devp;
1094 volatile u_int32_t status, currInt = 0;
1095 u_int32_t nextInt, intCnt;
1096
1097 /*
1098 * Hardware not available, potential interrupt hang. But since interrupt
1099 * might be shared, just return.
1100 */
1101 if (ci->state == C_INIT)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001102 return IRQ_NONE;
Bob Beers50ee11f2010-03-04 08:40:46 -05001103 /*
1104 * Marked as hardware available. Don't service interrupts, just clear the
1105 * event.
1106 */
1107
Johan Meiringfead55a2012-11-20 19:28:47 +02001108 if (ci->state == C_IDLE) {
Johan Meiring77c84b22012-11-20 19:28:48 +02001109 status = pci_read_32((u_int32_t *) &ci->reg->isd);
Bob Beers50ee11f2010-03-04 08:40:46 -05001110
Johan Meiringea9d1e92012-11-20 19:28:46 +02001111 /* clear the interrupt but process nothing else */
Johan Meiring77c84b22012-11-20 19:28:48 +02001112 pci_write_32((u_int32_t *) &ci->reg->isd, status);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001113 return IRQ_HANDLED;
Bob Beers50ee11f2010-03-04 08:40:46 -05001114 }
Johan Meiring77c84b22012-11-20 19:28:48 +02001115 FLUSH_PCI_READ();
1116 FLUSH_MEM_READ();
Bob Beers50ee11f2010-03-04 08:40:46 -05001117
Johan Meiring77c84b22012-11-20 19:28:48 +02001118 status = pci_read_32((u_int32_t *) &ci->reg->isd);
1119 nextInt = INTRPTS_NEXTINT(status);
1120 intCnt = INTRPTS_INTCNT(status);
Bob Beers50ee11f2010-03-04 08:40:46 -05001121 ci->intlog.drvr_intr_thcount++;
1122
1123 /*********************************************************/
1124 /* HW Bug Fix */
1125 /* ---------- */
1126 /* Under certain PCI Bus loading conditions, the */
1127 /* MUSYCC looses the data associated with an update */
1128 /* of its ISD and erroneously returns the immediately */
1129 /* preceding 'nextInt' value. However, the 'intCnt' */
1130 /* value appears to be correct. By not starting service */
1131 /* where the 'missing' 'nextInt' SHOULD point causes */
1132 /* the IQD not to be serviced - the 'not serviced' */
1133 /* entries then remain and continue to increase as more */
1134 /* incorrect ISD's are encountered. */
1135 /*********************************************************/
1136
Johan Meiring77c84b22012-11-20 19:28:48 +02001137 if (nextInt != INTRPTS_NEXTINT(ci->intlog.this_status_new)) {
Johan Meiringfead55a2012-11-20 19:28:47 +02001138 if (cxt1e1_log_level >= LOG_MONITOR) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001139 pr_info("%s: note - updated ISD from %08x to %08x\n",
1140 ci->devname, status,
1141 (status & (~INTRPTS_NEXTINT_M)) | ci->intlog.this_status_new);
1142 }
1143 /*
1144 * Replace bogus status with software corrected value.
1145 *
1146 * It's not known whether, during this problem occurrence, if the
1147 * INTFULL bit is correctly reported or not.
1148 */
1149 status = (status & (~INTRPTS_NEXTINT_M)) | (ci->intlog.this_status_new);
Johan Meiring77c84b22012-11-20 19:28:48 +02001150 nextInt = INTRPTS_NEXTINT(status);
Bob Beers50ee11f2010-03-04 08:40:46 -05001151 }
1152 /**********************************************/
1153 /* Cn847x Bug Fix */
1154 /* -------------- */
1155 /* Fix for inability to write back same index */
1156 /* as read for a full interrupt queue. */
1157 /**********************************************/
1158
1159 if (intCnt == INT_QUEUE_SIZE)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001160 currInt = ((intCnt - 1) + nextInt) & (INT_QUEUE_SIZE - 1);
Johan Meiringfead55a2012-11-20 19:28:47 +02001161 else
Johan Meiringea9d1e92012-11-20 19:28:46 +02001162 /************************************************/
1163 /* Interrupt Write Location Issues */
1164 /* ------------------------------- */
1165 /* When the interrupt status descriptor is */
1166 /* written, the interrupt line is de-asserted */
1167 /* by the Cn847x. In the case of MIPS */
1168 /* microprocessors, this must occur at the */
1169 /* beginning of the interrupt handler so that */
1170 /* the interrupt handle is not re-entered due */
1171 /* to interrupt dis-assertion latency. */
1172 /* In the case of all other processors, this */
1173 /* action should occur at the end of the */
1174 /* interrupt handler to avoid overwriting the */
1175 /* interrupt queue. */
1176 /************************************************/
Bob Beers50ee11f2010-03-04 08:40:46 -05001177
1178 if (intCnt)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001179 currInt = (intCnt + nextInt) & (INT_QUEUE_SIZE - 1);
Johan Meiringfead55a2012-11-20 19:28:47 +02001180 else {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001181 /*
1182 * NOTE: Servicing an interrupt whose ISD contains a count of ZERO
1183 * can be indicative of a Shared Interrupt chain. Our driver can be
1184 * called from the system's interrupt handler as a matter of the OS
1185 * walking the chain. As the chain is walked, the interrupt will
1186 * eventually be serviced by the correct driver/handler.
1187 */
Bob Beers50ee11f2010-03-04 08:40:46 -05001188#if 0
Johan Meiringea9d1e92012-11-20 19:28:46 +02001189 /* chained interrupt = not ours */
1190 pr_info(">> %s: intCnt NULL, sts %x, possibly a chained interrupt!\n",
1191 ci->devname, status);
Bob Beers50ee11f2010-03-04 08:40:46 -05001192#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +02001193 return IRQ_NONE;
Bob Beers50ee11f2010-03-04 08:40:46 -05001194 }
1195
1196 ci->iqp_tailx = currInt;
1197
1198 currInt <<= INTRPTS_NEXTINT_S;
1199 ci->intlog.last_status_new = ci->intlog.this_status_new;
1200 ci->intlog.this_status_new = currInt;
1201
Greg Kroah-Hartmanb8b73992010-12-10 10:46:30 -08001202 if ((cxt1e1_log_level >= LOG_WARN) && (status & INTRPTS_INTFULL_M))
Johan Meiringea9d1e92012-11-20 19:28:46 +02001203 pr_info("%s: Interrupt queue full condition occurred\n", ci->devname);
Greg Kroah-Hartmanb8b73992010-12-10 10:46:30 -08001204 if (cxt1e1_log_level >= LOG_DEBUG)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001205 pr_info("%s: interrupts pending, isd @ 0x%p: %x curr %d cnt %d NEXT %d\n",
1206 ci->devname, &ci->reg->isd,
1207 status, nextInt, intCnt, (intCnt + nextInt) & (INT_QUEUE_SIZE - 1));
Bob Beers50ee11f2010-03-04 08:40:46 -05001208
Johan Meiring77c84b22012-11-20 19:28:48 +02001209 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -05001210#if defined(SBE_ISR_TASKLET)
Johan Meiring77c84b22012-11-20 19:28:48 +02001211 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
1212 atomic_inc(&ci->bh_pending);
1213 tasklet_schedule(&ci->ci_musycc_isr_tasklet);
Bob Beers50ee11f2010-03-04 08:40:46 -05001214#elif defined(SBE_ISR_IMMEDIATE)
Johan Meiring77c84b22012-11-20 19:28:48 +02001215 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
1216 atomic_inc(&ci->bh_pending);
1217 queue_task(&ci->ci_musycc_isr_tq, &tq_immediate);
1218 mark_bh(IMMEDIATE_BH);
Bob Beers50ee11f2010-03-04 08:40:46 -05001219#elif defined(SBE_ISR_INLINE)
Johan Meiring77c84b22012-11-20 19:28:48 +02001220 (void) musycc_intr_bh_tasklet(ci);
1221 pci_write_32((u_int32_t *) &ci->reg->isd, currInt);
Bob Beers50ee11f2010-03-04 08:40:46 -05001222#endif
1223 return IRQ_HANDLED;
1224}
1225
1226
1227#if defined(SBE_ISR_IMMEDIATE)
1228unsigned long
1229#else
1230void
1231#endif
Johan Meiring77c84b22012-11-20 19:28:48 +02001232musycc_intr_bh_tasklet(ci_t * ci)
Bob Beers50ee11f2010-03-04 08:40:46 -05001233{
1234 mpi_t *pi;
1235 mch_t *ch;
1236 unsigned int intCnt;
1237 volatile u_int32_t currInt = 0;
1238 volatile unsigned int headx, tailx;
1239 int readCount, loopCount;
1240 int group, gchan, event, err, tx;
1241 u_int32_t badInt = INT_EMPTY_ENTRY;
1242 u_int32_t badInt2 = INT_EMPTY_ENTRY2;
1243
1244 /*
1245 * Hardware not available, potential interrupt hang. But since interrupt
1246 * might be shared, just return.
1247 */
Johan Meiringfead55a2012-11-20 19:28:47 +02001248 if ((drvr_state != SBE_DRVR_AVAILABLE) || (ci->state == C_INIT)) {
Bob Beers50ee11f2010-03-04 08:40:46 -05001249#if defined(SBE_ISR_IMMEDIATE)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001250 return 0L;
Bob Beers50ee11f2010-03-04 08:40:46 -05001251#else
Johan Meiringea9d1e92012-11-20 19:28:46 +02001252 return;
Bob Beers50ee11f2010-03-04 08:40:46 -05001253#endif
1254 }
1255#if defined(SBE_ISR_TASKLET) || defined(SBE_ISR_IMMEDIATE)
Johan Meiringfead55a2012-11-20 19:28:47 +02001256 if (drvr_state != SBE_DRVR_AVAILABLE) {
Bob Beers50ee11f2010-03-04 08:40:46 -05001257#if defined(SBE_ISR_TASKLET)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001258 return;
Bob Beers50ee11f2010-03-04 08:40:46 -05001259#elif defined(SBE_ISR_IMMEDIATE)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001260 return 0L;
Bob Beers50ee11f2010-03-04 08:40:46 -05001261#endif
1262 }
1263#elif defined(SBE_ISR_INLINE)
1264 /* no semaphore taken, no double checks */
1265#endif
1266
1267 ci->intlog.drvr_intr_bhcount++;
Johan Meiring77c84b22012-11-20 19:28:48 +02001268 FLUSH_MEM_READ();
Bob Beers50ee11f2010-03-04 08:40:46 -05001269 {
Johan Meiring77c84b22012-11-20 19:28:48 +02001270 unsigned int bh = atomic_read(&ci->bh_pending);
Bob Beers50ee11f2010-03-04 08:40:46 -05001271
Johan Meiring77c84b22012-11-20 19:28:48 +02001272 max_bh = max(bh, max_bh);
Bob Beers50ee11f2010-03-04 08:40:46 -05001273 }
Johan Meiring77c84b22012-11-20 19:28:48 +02001274 atomic_set(&ci->bh_pending, 0);/* if here, no longer pending */
Johan Meiringfead55a2012-11-20 19:28:47 +02001275 while ((headx = ci->iqp_headx) != (tailx = ci->iqp_tailx)) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001276 intCnt = (tailx >= headx) ? (tailx - headx) : (tailx - headx + INT_QUEUE_SIZE);
Johan Meiring77c84b22012-11-20 19:28:48 +02001277 currInt = le32_to_cpu(ci->iqd_p[headx]);
Bob Beers50ee11f2010-03-04 08:40:46 -05001278
Johan Meiring77c84b22012-11-20 19:28:48 +02001279 max_intcnt = max(intCnt, max_intcnt); /* RLD DEBUG */
Bob Beers50ee11f2010-03-04 08:40:46 -05001280
Johan Meiringea9d1e92012-11-20 19:28:46 +02001281 /**************************************************/
1282 /* HW Bug Fix */
1283 /* ---------- */
1284 /* The following code checks for the condition */
1285 /* of interrupt assertion before interrupt */
1286 /* queue update. This is a problem on several */
1287 /* PCI-Local bridge chips found on some products. */
1288 /**************************************************/
Bob Beers50ee11f2010-03-04 08:40:46 -05001289
Johan Meiringea9d1e92012-11-20 19:28:46 +02001290 readCount = 0;
1291 if ((currInt == badInt) || (currInt == badInt2))
1292 ci->intlog.drvr_int_failure++;
Bob Beers50ee11f2010-03-04 08:40:46 -05001293
Johan Meiringfead55a2012-11-20 19:28:47 +02001294 while ((currInt == badInt) || (currInt == badInt2)) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001295 for (loopCount = 0; loopCount < 0x30; loopCount++)
Johan Meiring77c84b22012-11-20 19:28:48 +02001296 OS_uwait_dummy(); /* use call to avoid optimization removal
Johan Meiringea9d1e92012-11-20 19:28:46 +02001297 * of dummy delay */
Johan Meiring77c84b22012-11-20 19:28:48 +02001298 FLUSH_MEM_READ();
1299 currInt = le32_to_cpu(ci->iqd_p[headx]);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001300 if (readCount++ > 20)
1301 break;
1302 }
Bob Beers50ee11f2010-03-04 08:40:46 -05001303
Johan Meiringfead55a2012-11-20 19:28:47 +02001304 if ((currInt == badInt) || (currInt == badInt2)) { /* catch failure of Bug
Johan Meiringea9d1e92012-11-20 19:28:46 +02001305 * Fix checking */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001306 if (cxt1e1_log_level >= LOG_WARN)
1307 pr_info("%s: Illegal Interrupt Detected @ 0x%p, mod %d.)\n",
1308 ci->devname, &ci->iqd_p[headx], headx);
Bob Beers50ee11f2010-03-04 08:40:46 -05001309
Johan Meiringea9d1e92012-11-20 19:28:46 +02001310 /*
1311 * If the descriptor has not recovered, then leaving the EMPTY
1312 * entry set will not signal to the MUSYCC that this descriptor
1313 * has been serviced. The Interrupt Queue can then start losing
1314 * available descriptors and MUSYCC eventually encounters and
1315 * reports the INTFULL condition. Per manual, changing any bit
1316 * marks descriptor as available, thus the use of different
1317 * EMPTY_ENTRY values.
1318 */
Bob Beers50ee11f2010-03-04 08:40:46 -05001319
Johan Meiringea9d1e92012-11-20 19:28:46 +02001320 if (currInt == badInt)
Johan Meiring77c84b22012-11-20 19:28:48 +02001321 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY2);
Johan Meiringfead55a2012-11-20 19:28:47 +02001322 else
Johan Meiring77c84b22012-11-20 19:28:48 +02001323 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001324 ci->iqp_headx = (headx + 1) & (INT_QUEUE_SIZE - 1); /* insure wrapness */
Johan Meiring77c84b22012-11-20 19:28:48 +02001325 FLUSH_MEM_WRITE();
1326 FLUSH_MEM_READ();
Johan Meiringea9d1e92012-11-20 19:28:46 +02001327 continue;
1328 }
Johan Meiring77c84b22012-11-20 19:28:48 +02001329 group = INTRPT_GRP(currInt);
1330 gchan = INTRPT_CH(currInt);
1331 event = INTRPT_EVENT(currInt);
1332 err = INTRPT_ERROR(currInt);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001333 tx = currInt & INTRPT_DIR_M;
Bob Beers50ee11f2010-03-04 08:40:46 -05001334
Johan Meiring77c84b22012-11-20 19:28:48 +02001335 ci->iqd_p[headx] = __constant_cpu_to_le32(INT_EMPTY_ENTRY);
1336 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -05001337
Johan Meiringfead55a2012-11-20 19:28:47 +02001338 if (cxt1e1_log_level >= LOG_DEBUG) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001339 if (err != 0)
1340 pr_info(" %08x -> err: %2d,", currInt, err);
Bob Beers50ee11f2010-03-04 08:40:46 -05001341
Johan Meiringea9d1e92012-11-20 19:28:46 +02001342 pr_info("+ interrupt event: %d, grp: %d, chan: %2d, side: %cX\n",
1343 event, group, gchan, tx ? 'T' : 'R');
1344 }
1345 pi = &ci->port[group]; /* notice that here we assume 1-1 group -
1346 * port mapping */
1347 ch = pi->chan[gchan];
Johan Meiringfead55a2012-11-20 19:28:47 +02001348 switch (event) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001349 case EVE_SACK: /* Service Request Acknowledge */
Johan Meiringfead55a2012-11-20 19:28:47 +02001350 if (cxt1e1_log_level >= LOG_DEBUG) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001351 volatile u_int32_t r;
Bob Beers50ee11f2010-03-04 08:40:46 -05001352
Johan Meiring77c84b22012-11-20 19:28:48 +02001353 r = pci_read_32((u_int32_t *) &pi->reg->srd);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001354 pr_info("- SACK cmd: %08x (hdw= %08x)\n", pi->sr_last, r);
1355 }
Johan Meiring77c84b22012-11-20 19:28:48 +02001356 SD_SEM_GIVE(&pi->sr_sem_wait); /* wake up waiting process */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001357 break;
1358 case EVE_CHABT: /* Change To Abort Code (0x7e -> 0xff) */
1359 case EVE_CHIC: /* Change To Idle Code (0xff -> 0x7e) */
1360 break;
1361 case EVE_EOM: /* End Of Message */
1362 case EVE_EOB: /* End Of Buffer (Transparent mode) */
1363 if (tx)
Johan Meiring77c84b22012-11-20 19:28:48 +02001364 musycc_bh_tx_eom(pi, gchan);
Johan Meiringfead55a2012-11-20 19:28:47 +02001365 else
Johan Meiring77c84b22012-11-20 19:28:48 +02001366 musycc_bh_rx_eom(pi, gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -05001367#if 0
Johan Meiringea9d1e92012-11-20 19:28:46 +02001368 break;
Bob Beers50ee11f2010-03-04 08:40:46 -05001369#else
Johan Meiringea9d1e92012-11-20 19:28:46 +02001370 /*
1371 * MUSYCC Interrupt Descriptor section states that EOB and EOM
1372 * can be combined with the NONE error (as well as others). So
1373 * drop thru to catch this...
1374 */
Bob Beers50ee11f2010-03-04 08:40:46 -05001375#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +02001376 case EVE_NONE:
1377 if (err == ERR_SHT)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001378 ch->s.rx_length_errors++;
Johan Meiringea9d1e92012-11-20 19:28:46 +02001379 break;
1380 default:
1381 if (cxt1e1_log_level >= LOG_WARN)
1382 pr_info("%s: unexpected interrupt event: %d, iqd[%d]: %08x, port: %d\n", ci->devname,
1383 event, headx, currInt, group);
1384 break;
1385 } /* switch on event */
Bob Beers50ee11f2010-03-04 08:40:46 -05001386
1387
Johan Meiringea9d1e92012-11-20 19:28:46 +02001388 /*
1389 * Per MUSYCC Manual, Section 6.4.8.3 [Transmit Errors], TX errors
1390 * are service-affecting and require action to resume normal
1391 * bit-level processing.
1392 */
Bob Beers50ee11f2010-03-04 08:40:46 -05001393
Johan Meiringfead55a2012-11-20 19:28:47 +02001394 switch (err) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001395 case ERR_ONR:
1396 /*
1397 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors], this
1398 * error requires Transmit channel reactivation.
1399 *
1400 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], this error
1401 * requires Receive channel reactivation.
1402 */
Johan Meiringfead55a2012-11-20 19:28:47 +02001403 if (tx) {
Bob Beers50ee11f2010-03-04 08:40:46 -05001404
Johan Meiringea9d1e92012-11-20 19:28:46 +02001405 /*
1406 * TX ONR Error only occurs when channel is configured for
1407 * Transparent Mode. However, this code will catch and
1408 * re-activate on ANY TX ONR error.
1409 */
Bob Beers50ee11f2010-03-04 08:40:46 -05001410
Johan Meiringea9d1e92012-11-20 19:28:46 +02001411 /*
1412 * Set flag to re-enable on any next transmit attempt.
1413 */
1414 ch->ch_start_tx = CH_START_TX_ONR;
Bob Beers50ee11f2010-03-04 08:40:46 -05001415
Johan Meiringea9d1e92012-11-20 19:28:46 +02001416 {
Bob Beers50ee11f2010-03-04 08:40:46 -05001417#ifdef RLD_TRANS_DEBUG
Johan Meiringea9d1e92012-11-20 19:28:46 +02001418 if (1 || cxt1e1_log_level >= LOG_MONITOR)
Bob Beers50ee11f2010-03-04 08:40:46 -05001419#else
Johan Meiringea9d1e92012-11-20 19:28:46 +02001420 if (cxt1e1_log_level >= LOG_MONITOR)
Bob Beers50ee11f2010-03-04 08:40:46 -05001421#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +02001422 {
1423 pr_info("%s: TX buffer underflow [ONR] on channel %d, mode %x QStopped %x free %d\n",
Johan Meiring77c84b22012-11-20 19:28:48 +02001424 ci->devname, ch->channum, ch->p.chan_mode, sd_queue_stopped(ch->user), ch->txd_free);
Bob Beers50ee11f2010-03-04 08:40:46 -05001425#ifdef RLD_DEBUG
Johan Meiringfead55a2012-11-20 19:28:47 +02001426 if (ch->p.chan_mode == 2) { /* problem = ONR on HDLC
Johan Meiringea9d1e92012-11-20 19:28:46 +02001427 * mode */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001428 pr_info("++ Failed Last %x Next %x QStopped %x, start_tx %x tx_full %d txd_free %d mode %x\n",
1429 (u_int32_t) ch->txd_irq_srv, (u_int32_t) ch->txd_usr_add,
Johan Meiring77c84b22012-11-20 19:28:48 +02001430 sd_queue_stopped(ch->user),
Johan Meiringea9d1e92012-11-20 19:28:46 +02001431 ch->ch_start_tx, ch->tx_full, ch->txd_free, ch->p.chan_mode);
Johan Meiring77c84b22012-11-20 19:28:48 +02001432 musycc_dump_txbuffer_ring(ch, 0);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001433 }
Bob Beers50ee11f2010-03-04 08:40:46 -05001434#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +02001435 }
1436 }
Johan Meiringfead55a2012-11-20 19:28:47 +02001437 } else { /* RX buffer overrun */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001438 /*
1439 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors],
1440 * channel recovery for this RX ONR error IS required. It is
1441 * also suggested to increase the number of receive buffers
1442 * for this channel. Receive channel reactivation IS
1443 * required, and data has been lost.
1444 */
1445 ch->s.rx_over_errors++;
1446 ch->ch_start_rx = CH_START_RX_ONR;
Bob Beers50ee11f2010-03-04 08:40:46 -05001447
Johan Meiringfead55a2012-11-20 19:28:47 +02001448 if (cxt1e1_log_level >= LOG_WARN) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001449 pr_info("%s: RX buffer overflow [ONR] on channel %d, mode %x\n",
1450 ci->devname, ch->channum, ch->p.chan_mode);
1451 //musycc_dump_rxbuffer_ring (ch, 0); /* RLD DEBUG */
1452 }
1453 }
Johan Meiring77c84b22012-11-20 19:28:48 +02001454 musycc_chan_restart(ch);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001455 break;
1456 case ERR_BUF:
Johan Meiringfead55a2012-11-20 19:28:47 +02001457 if (tx) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001458 ch->s.tx_fifo_errors++;
1459 ch->ch_start_tx = CH_START_TX_BUF;
1460 /*
1461 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors],
1462 * this BUFF error requires Transmit channel reactivation.
1463 */
1464 if (cxt1e1_log_level >= LOG_MONITOR)
1465 pr_info("%s: TX buffer underrun [BUFF] on channel %d, mode %x\n",
1466 ci->devname, ch->channum, ch->p.chan_mode);
Johan Meiringfead55a2012-11-20 19:28:47 +02001467 } else { /* RX buffer overrun */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001468 ch->s.rx_over_errors++;
1469 /*
1470 * Per MUSYCC manual, Section 6.4.8.4 [Receive Errors], HDLC
1471 * mode requires NO recovery for this RX BUFF error is
1472 * required. It is suggested to increase the FIFO buffer
1473 * space for this channel. Receive channel reactivation is
1474 * not required, but data has been lost.
1475 */
1476 if (cxt1e1_log_level >= LOG_WARN)
1477 pr_info("%s: RX buffer overrun [BUFF] on channel %d, mode %x\n",
1478 ci->devname, ch->channum, ch->p.chan_mode);
1479 /*
1480 * Per MUSYCC manual, Section 6.4.9.4 [Receive Errors],
1481 * Transparent mode DOES require recovery for the RX BUFF
1482 * error. It is suggested to increase the FIFO buffer space
1483 * for this channel. Receive channel reactivation IS
1484 * required and data has been lost.
1485 */
1486 if (ch->p.chan_mode == CFG_CH_PROTO_TRANS)
1487 ch->ch_start_rx = CH_START_RX_BUF;
1488 }
Bob Beers50ee11f2010-03-04 08:40:46 -05001489
Johan Meiringea9d1e92012-11-20 19:28:46 +02001490 if (tx || (ch->p.chan_mode == CFG_CH_PROTO_TRANS))
Johan Meiring77c84b22012-11-20 19:28:48 +02001491 musycc_chan_restart(ch);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001492 break;
1493 default:
1494 break;
1495 } /* switch on err */
Bob Beers50ee11f2010-03-04 08:40:46 -05001496
Johan Meiringea9d1e92012-11-20 19:28:46 +02001497 /* Check for interrupt lost condition */
1498 if ((currInt & INTRPT_ILOST_M) && (cxt1e1_log_level >= LOG_ERROR))
Johan Meiringea9d1e92012-11-20 19:28:46 +02001499 pr_info("%s: Interrupt queue overflow - ILOST asserted\n",
1500 ci->devname);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001501 ci->iqp_headx = (headx + 1) & (INT_QUEUE_SIZE - 1); /* insure wrapness */
Johan Meiring77c84b22012-11-20 19:28:48 +02001502 FLUSH_MEM_WRITE();
1503 FLUSH_MEM_READ();
Bob Beers50ee11f2010-03-04 08:40:46 -05001504 } /* while */
Johan Meiringfead55a2012-11-20 19:28:47 +02001505 if ((cxt1e1_log_level >= LOG_MONITOR2) && (ci->iqp_headx != ci->iqp_tailx)) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001506 int bh;
Bob Beers50ee11f2010-03-04 08:40:46 -05001507
Johan Meiring77c84b22012-11-20 19:28:48 +02001508 bh = atomic_read(&CI->bh_pending);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001509 pr_info("_bh_: late arrivals, head %d != tail %d, pending %d\n",
1510 ci->iqp_headx, ci->iqp_tailx, bh);
Bob Beers50ee11f2010-03-04 08:40:46 -05001511 }
1512#if defined(SBE_ISR_IMMEDIATE)
1513 return 0L;
1514#endif
1515 /* else, nothing returned */
1516}
1517
1518#if 0
1519int __init
Johan Meiring77c84b22012-11-20 19:28:48 +02001520musycc_new_chan(ci_t * ci, int channum, void *user)
Bob Beers50ee11f2010-03-04 08:40:46 -05001521{
1522 mch_t *ch;
1523
1524 ch = ci->port[channum / MUSYCC_NCHANS].chan[channum % MUSYCC_NCHANS];
1525
1526 if (ch->state != UNASSIGNED)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001527 return EEXIST;
Bob Beers50ee11f2010-03-04 08:40:46 -05001528 /* NOTE: mch_t already cleared during OS_kmalloc() */
1529 ch->state = DOWN;
1530 ch->user = user;
1531#if 0
1532 ch->status = 0;
1533 ch->p.status = 0;
1534 ch->p.intr_mask = 0;
1535#endif
1536 ch->p.chan_mode = CFG_CH_PROTO_HDLC_FCS16;
1537 ch->p.idlecode = CFG_CH_FLAG_7E;
1538 ch->p.pad_fill_count = 2;
Johan Meiring77c84b22012-11-20 19:28:48 +02001539 spin_lock_init(&ch->ch_rxlock);
1540 spin_lock_init(&ch->ch_txlock);
Bob Beers50ee11f2010-03-04 08:40:46 -05001541
1542 return 0;
1543}
1544#endif
1545
1546
1547#ifdef SBE_PMCC4_ENABLE
1548status_t
Johan Meiring77c84b22012-11-20 19:28:48 +02001549musycc_chan_down(ci_t * dummy, int channum)
Bob Beers50ee11f2010-03-04 08:40:46 -05001550{
1551 mpi_t *pi;
1552 mch_t *ch;
1553 int i, gchan;
1554
Johan Meiring77c84b22012-11-20 19:28:48 +02001555 if (!(ch = sd_find_chan(dummy, channum)))
Johan Meiringea9d1e92012-11-20 19:28:46 +02001556 return EINVAL;
Bob Beers50ee11f2010-03-04 08:40:46 -05001557 pi = ch->up;
1558 gchan = ch->gchan;
1559
1560 /* Deactivate the channel */
Johan Meiring77c84b22012-11-20 19:28:48 +02001561 musycc_serv_req(pi, SR_CHANNEL_DEACTIVATE | SR_RX_DIRECTION | gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -05001562 ch->ch_start_rx = 0;
Johan Meiring77c84b22012-11-20 19:28:48 +02001563 musycc_serv_req(pi, SR_CHANNEL_DEACTIVATE | SR_TX_DIRECTION | gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -05001564 ch->ch_start_tx = 0;
1565
1566 if (ch->state == DOWN)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001567 return 0;
Bob Beers50ee11f2010-03-04 08:40:46 -05001568 ch->state = DOWN;
1569
1570 pi->regram->thp[gchan] = 0;
1571 pi->regram->tmp[gchan] = 0;
1572 pi->regram->rhp[gchan] = 0;
1573 pi->regram->rmp[gchan] = 0;
Johan Meiring77c84b22012-11-20 19:28:48 +02001574 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -05001575 for (i = 0; i < ch->txd_num; i++)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001576 if (ch->mdt[i].mem_token != 0)
Johan Meiring77c84b22012-11-20 19:28:48 +02001577 OS_mem_token_free(ch->mdt[i].mem_token);
Bob Beers50ee11f2010-03-04 08:40:46 -05001578
1579 for (i = 0; i < ch->rxd_num; i++)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001580 if (ch->mdr[i].mem_token != 0)
Johan Meiring77c84b22012-11-20 19:28:48 +02001581 OS_mem_token_free(ch->mdr[i].mem_token);
Bob Beers50ee11f2010-03-04 08:40:46 -05001582
Johan Meiring77c84b22012-11-20 19:28:48 +02001583 OS_kfree(ch->mdr);
Bob Beers50ee11f2010-03-04 08:40:46 -05001584 ch->mdr = 0;
1585 ch->rxd_num = 0;
Johan Meiring77c84b22012-11-20 19:28:48 +02001586 OS_kfree(ch->mdt);
Bob Beers50ee11f2010-03-04 08:40:46 -05001587 ch->mdt = 0;
1588 ch->txd_num = 0;
1589
Johan Meiring77c84b22012-11-20 19:28:48 +02001590 musycc_update_timeslots(pi);
1591 c4_fifo_free(pi, ch->gchan);
Bob Beers50ee11f2010-03-04 08:40:46 -05001592
1593 pi->openchans--;
1594 return 0;
1595}
1596#endif
1597
1598
1599int
Johan Meiring77c84b22012-11-20 19:28:48 +02001600musycc_del_chan(ci_t * ci, int channum)
Bob Beers50ee11f2010-03-04 08:40:46 -05001601{
1602 mch_t *ch;
1603
1604 if ((channum < 0) || (channum >= (MUSYCC_NPORTS * MUSYCC_NCHANS))) /* sanity chk param */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001605 return ECHRNG;
Johan Meiring77c84b22012-11-20 19:28:48 +02001606 if (!(ch = sd_find_chan(ci, channum)))
Johan Meiringea9d1e92012-11-20 19:28:46 +02001607 return ENOENT;
Bob Beers50ee11f2010-03-04 08:40:46 -05001608 if (ch->state == UP)
Johan Meiring77c84b22012-11-20 19:28:48 +02001609 musycc_chan_down(ci, channum);
Bob Beers50ee11f2010-03-04 08:40:46 -05001610 ch->state = UNASSIGNED;
1611 return 0;
1612}
1613
1614
1615int
Johan Meiring77c84b22012-11-20 19:28:48 +02001616musycc_del_chan_stats(ci_t * ci, int channum)
Bob Beers50ee11f2010-03-04 08:40:46 -05001617{
1618 mch_t *ch;
1619
1620 if (channum < 0 || channum >= (MUSYCC_NPORTS * MUSYCC_NCHANS)) /* sanity chk param */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001621 return ECHRNG;
Johan Meiring77c84b22012-11-20 19:28:48 +02001622 if (!(ch = sd_find_chan(ci, channum)))
Johan Meiringea9d1e92012-11-20 19:28:46 +02001623 return ENOENT;
Bob Beers50ee11f2010-03-04 08:40:46 -05001624
Johan Meiring77c84b22012-11-20 19:28:48 +02001625 memset(&ch->s, 0, sizeof(struct sbecom_chan_stats));
Bob Beers50ee11f2010-03-04 08:40:46 -05001626 return 0;
1627}
1628
1629
1630int
Johan Meiring77c84b22012-11-20 19:28:48 +02001631musycc_start_xmit(ci_t * ci, int channum, void *mem_token)
Bob Beers50ee11f2010-03-04 08:40:46 -05001632{
1633 mch_t *ch;
1634 struct mdesc *md;
1635 void *m2;
1636#if 0
1637 unsigned long flags;
1638#endif
1639 int txd_need_cnt;
1640 u_int32_t len;
1641
Johan Meiring77c84b22012-11-20 19:28:48 +02001642 if (!(ch = sd_find_chan(ci, channum)))
Johan Meiringea9d1e92012-11-20 19:28:46 +02001643 return -ENOENT;
Bob Beers50ee11f2010-03-04 08:40:46 -05001644
1645 if (ci->state != C_RUNNING) /* full interrupt processing available */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001646 return -EINVAL;
Bob Beers50ee11f2010-03-04 08:40:46 -05001647 if (ch->state != UP)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001648 return -EINVAL;
Bob Beers50ee11f2010-03-04 08:40:46 -05001649
1650 if (!(ch->status & TX_ENABLED))
Johan Meiringea9d1e92012-11-20 19:28:46 +02001651 return -EROFS; /* how else to flag unwritable state ? */
Bob Beers50ee11f2010-03-04 08:40:46 -05001652
1653#ifdef RLD_TRANS_DEBUGx
Greg Kroah-Hartmanb8b73992010-12-10 10:46:30 -08001654 if (1 || cxt1e1_log_level >= LOG_MONITOR2)
Bob Beers50ee11f2010-03-04 08:40:46 -05001655#else
Greg Kroah-Hartmanb8b73992010-12-10 10:46:30 -08001656 if (cxt1e1_log_level >= LOG_MONITOR2)
Bob Beers50ee11f2010-03-04 08:40:46 -05001657#endif
1658 {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001659 pr_info("++ start_xmt[%d]: state %x start %x full %d free %d required %d stopped %x\n",
1660 channum, ch->state, ch->ch_start_tx, ch->tx_full,
Johan Meiring77c84b22012-11-20 19:28:48 +02001661 ch->txd_free, ch->txd_required, sd_queue_stopped(ch->user));
Bob Beers50ee11f2010-03-04 08:40:46 -05001662 }
1663 /***********************************************/
1664 /** Determine total amount of data to be sent **/
1665 /***********************************************/
1666 m2 = mem_token;
1667 txd_need_cnt = 0;
Johan Meiring77c84b22012-11-20 19:28:48 +02001668 for (len = OS_mem_token_tlen(m2); len > 0;
1669 m2 = (void *) OS_mem_token_next(m2)) {
1670 if (!OS_mem_token_len(m2))
Johan Meiringea9d1e92012-11-20 19:28:46 +02001671 continue;
1672 txd_need_cnt++;
Johan Meiring77c84b22012-11-20 19:28:48 +02001673 len -= OS_mem_token_len(m2);
Bob Beers50ee11f2010-03-04 08:40:46 -05001674 }
1675
Johan Meiringfead55a2012-11-20 19:28:47 +02001676 if (txd_need_cnt == 0) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001677 if (cxt1e1_log_level >= LOG_MONITOR2)
1678 pr_info("%s channel %d: no TX data in User buffer\n", ci->devname, channum);
Johan Meiring77c84b22012-11-20 19:28:48 +02001679 OS_mem_token_free(mem_token);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001680 return 0; /* no data to send */
Bob Beers50ee11f2010-03-04 08:40:46 -05001681 }
1682 /*************************************************/
1683 /** Are there sufficient descriptors available? **/
1684 /*************************************************/
Johan Meiringfead55a2012-11-20 19:28:47 +02001685 if (txd_need_cnt > ch->txd_num) { /* never enough descriptors for this
1686 * large a buffer */
Johan Meiringea9d1e92012-11-20 19:28:46 +02001687 if (cxt1e1_log_level >= LOG_DEBUG)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001688 pr_info("start_xmit: discarding buffer, insufficient descriptor cnt %d, need %d.\n",
1689 ch->txd_num, txd_need_cnt + 1);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001690 ch->s.tx_dropped++;
Johan Meiring77c84b22012-11-20 19:28:48 +02001691 OS_mem_token_free(mem_token);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001692 return 0;
Bob Beers50ee11f2010-03-04 08:40:46 -05001693 }
1694#if 0
Johan Meiring77c84b22012-11-20 19:28:48 +02001695 spin_lock_irqsave(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -05001696#endif
1697 /************************************************************/
1698 /** flow control the line if not enough descriptors remain **/
1699 /************************************************************/
Johan Meiringfead55a2012-11-20 19:28:47 +02001700 if (txd_need_cnt > ch->txd_free) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001701 if (cxt1e1_log_level >= LOG_MONITOR2)
Johan Meiringea9d1e92012-11-20 19:28:46 +02001702 pr_info("start_xmit[%d]: EBUSY - need more descriptors, have %d of %d need %d\n",
1703 channum, ch->txd_free, ch->txd_num, txd_need_cnt);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001704 ch->tx_full = 1;
1705 ch->txd_required = txd_need_cnt;
Johan Meiring77c84b22012-11-20 19:28:48 +02001706 sd_disable_xmit(ch->user);
Bob Beers50ee11f2010-03-04 08:40:46 -05001707#if 0
Johan Meiring77c84b22012-11-20 19:28:48 +02001708 spin_unlock_irqrestore(&ch->ch_txlock, flags);
Bob Beers50ee11f2010-03-04 08:40:46 -05001709#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +02001710 return -EBUSY; /* tell user to try again later */
Bob Beers50ee11f2010-03-04 08:40:46 -05001711 }
1712 /**************************************************/
1713 /** Put the user data into MUSYCC data buffer(s) **/
1714 /**************************************************/
1715 m2 = mem_token;
1716 md = ch->txd_usr_add; /* get current available descriptor */
1717
Johan Meiring77c84b22012-11-20 19:28:48 +02001718 for (len = OS_mem_token_tlen(m2); len > 0; m2 = OS_mem_token_next(m2)) {
1719 int u = OS_mem_token_len(m2);
Bob Beers50ee11f2010-03-04 08:40:46 -05001720
Johan Meiringea9d1e92012-11-20 19:28:46 +02001721 if (!u)
1722 continue;
1723 len -= u;
Bob Beers50ee11f2010-03-04 08:40:46 -05001724
Johan Meiringea9d1e92012-11-20 19:28:46 +02001725 /*
1726 * Enable following chunks, yet wait to enable the FIRST chunk until
1727 * after ALL subsequent chunks are setup.
1728 */
1729 if (md != ch->txd_usr_add) /* not first chunk */
1730 u |= MUSYCC_TX_OWNED; /* transfer ownership from HOST to MUSYCC */
Bob Beers50ee11f2010-03-04 08:40:46 -05001731
Johan Meiringea9d1e92012-11-20 19:28:46 +02001732 if (len) /* not last chunk */
1733 u |= EOBIRQ_ENABLE;
Johan Meiringfead55a2012-11-20 19:28:47 +02001734 else if (ch->p.chan_mode == CFG_CH_PROTO_TRANS) {
Johan Meiringea9d1e92012-11-20 19:28:46 +02001735 /*
1736 * Per MUSYCC Ref 6.4.9 for Transparent Mode, the host must
1737 * always clear EOMIRQ_ENABLE in every Transmit Buffer Descriptor
1738 * (IE. don't set herein).
1739 */
1740 u |= EOBIRQ_ENABLE;
1741 } else
1742 u |= EOMIRQ_ENABLE; /* EOM, last HDLC chunk */
Bob Beers50ee11f2010-03-04 08:40:46 -05001743
1744
Johan Meiringea9d1e92012-11-20 19:28:46 +02001745 /* last chunk in hdlc mode */
1746 u |= (ch->p.idlecode << IDLE_CODE);
Johan Meiringfead55a2012-11-20 19:28:47 +02001747 if (ch->p.pad_fill_count) {
Bob Beers50ee11f2010-03-04 08:40:46 -05001748#if 0
Johan Meiringea9d1e92012-11-20 19:28:46 +02001749 /* NOOP NOTE: u_int8_t cannot be > 0xFF */
1750 /* sanitize pad_fill_count for maximums allowed by hardware */
1751 if (ch->p.pad_fill_count > EXTRA_FLAGS_MASK)
1752 ch->p.pad_fill_count = EXTRA_FLAGS_MASK;
Bob Beers50ee11f2010-03-04 08:40:46 -05001753#endif
Johan Meiringea9d1e92012-11-20 19:28:46 +02001754 u |= (PADFILL_ENABLE | (ch->p.pad_fill_count << EXTRA_FLAGS));
1755 }
1756 md->mem_token = len ? 0 : mem_token; /* Fill in mds on last
1757 * segment, others set ZERO
1758 * so that entire token is
1759 * removed ONLY when ALL
1760 * segments have been
1761 * transmitted. */
Bob Beers50ee11f2010-03-04 08:40:46 -05001762
Johan Meiring77c84b22012-11-20 19:28:48 +02001763 md->data = cpu_to_le32(OS_vtophys(OS_mem_token_data(m2)));
1764 FLUSH_MEM_WRITE();
1765 md->status = cpu_to_le32(u);
Johan Meiringea9d1e92012-11-20 19:28:46 +02001766 --ch->txd_free;
1767 md = md->snext;
Bob Beers50ee11f2010-03-04 08:40:46 -05001768 }
Johan Meiring77c84b22012-11-20 19:28:48 +02001769 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -05001770
1771
1772 /*
1773 * Now transfer ownership of first chunk from HOST to MUSYCC in order to
1774 * fire-off this XMIT.
1775 */
Johan Meiring77c84b22012-11-20 19:28:48 +02001776 ch->txd_usr_add->status |= __constant_cpu_to_le32(MUSYCC_TX_OWNED);
1777 FLUSH_MEM_WRITE();
Bob Beers50ee11f2010-03-04 08:40:46 -05001778 ch->txd_usr_add = md;
1779
Johan Meiring77c84b22012-11-20 19:28:48 +02001780 len = OS_mem_token_tlen(mem_token);
1781 atomic_add(len, &ch->tx_pending);
1782 atomic_add(len, &ci->tx_pending);
Bob Beers50ee11f2010-03-04 08:40:46 -05001783 ch->s.tx_packets++;
1784 ch->s.tx_bytes += len;
Bob Beers50ee11f2010-03-04 08:40:46 -05001785 /*
1786 * If an ONR was seen, then channel requires poking to restart
1787 * transmission.
1788 */
1789 if (ch->ch_start_tx)
Johan Meiring77c84b22012-11-20 19:28:48 +02001790 musycc_chan_restart(ch);
Bob Beers50ee11f2010-03-04 08:40:46 -05001791#ifdef SBE_WAN256T3_ENABLE
Johan Meiring77c84b22012-11-20 19:28:48 +02001792 wan256t3_led(ci, LED_TX, LEDV_G);
Bob Beers50ee11f2010-03-04 08:40:46 -05001793#endif
1794 return 0;
1795}
1796
1797
Bob Beers50ee11f2010-03-04 08:40:46 -05001798/*** End-of-File ***/