OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [isdn/] [sc/] [message.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *  $Id: message.c,v 1.1.1.1 2001-09-10 07:44:19 simons Exp $
3
 *  Copyright (C) 1996  SpellCaster Telecommunications Inc.
4
 *
5
 *  message.c - functions for sending and receiving control messages
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
 *
21
 *  For more information, please contact gpl-info@spellcast.com or write:
22
 *
23
 *     SpellCaster Telecommunications Inc.
24
 *     5621 Finch Avenue East, Unit #3
25
 *     Scarborough, Ontario  Canada
26
 *     M1B 2T9
27
 *     +1 (416) 297-8565
28
 *     +1 (416) 297-6433 Facsimile
29
 */
30
 
31
#define __NO_VERSION__
32
#include "includes.h"
33
#include "hardware.h"
34
#include "message.h"
35
#include "card.h"
36
 
37
extern board *adapter[];
38
extern unsigned int cinst;
39
 
40
/*
41
 * Obligitory function prototypes
42
 */
43
extern int indicate_status(int,ulong,char*);
44
extern int scm_command(isdn_ctrl *);
45
extern void *memcpy_fromshmem(int, void *, const void *, size_t);
46
 
47
/*
48
 * Dump message queue in shared memory to screen
49
 */
50
void dump_messages(int card)
51
{
52
        DualPortMemory dpm;
53
        unsigned long flags;
54
 
55
        int i =0;
56
 
57
        if (!IS_VALID_CARD(card)) {
58
                pr_debug("Invalid param: %d is not a valid card id\n", card);
59
        }
60
 
61
        save_flags(flags);
62
        cli();
63
        outb(adapter[card]->ioport[adapter[card]->shmem_pgport],
64
                (adapter[card]->shmem_magic >> 14) | 0x80);
65
        memcpy_fromshmem(card, &dpm, 0, sizeof(dpm));
66
        restore_flags(flags);
67
 
68
        pr_debug("%s: Dumping Request Queue\n", adapter[card]->devicename);
69
        for (i = 0; i < dpm.req_head; i++) {
70
                pr_debug("%s: Message #%d: (%d,%d,%d), link: %d\n",
71
                                adapter[card]->devicename, i,
72
                                dpm.req_queue[i].type,
73
                                dpm.req_queue[i].class,
74
                                dpm.req_queue[i].code,
75
                                dpm.req_queue[i].phy_link_no);
76
        }
77
 
78
        pr_debug("%s: Dumping Response Queue\n", adapter[card]->devicename);
79
        for (i = 0; i < dpm.rsp_head; i++) {
80
                pr_debug("%s: Message #%d: (%d,%d,%d), link: %d, status: %d\n",
81
                                adapter[card]->devicename, i,
82
                                dpm.rsp_queue[i].type,
83
                                dpm.rsp_queue[i].class,
84
                                dpm.rsp_queue[i].code,
85
                                dpm.rsp_queue[i].phy_link_no,
86
                                dpm.rsp_queue[i].rsp_status);
87
        }
88
 
89
}
90
 
91
/*
92
 * receive a message from the board
93
 */
94
int receivemessage(int card, RspMessage *rspmsg)
95
{
96
        DualPortMemory *dpm;
97
        unsigned long flags;
98
 
99
        if (!IS_VALID_CARD(card)) {
100
                pr_debug("Invalid param: %d is not a valid card id\n", card);
101
                return -EINVAL;
102
        }
103
 
104
        pr_debug("%s: Entered receivemessage\n",adapter[card]->devicename);
105
 
106
        /*
107
         * See if there are messages waiting
108
         */
109
        if (inb(adapter[card]->ioport[FIFO_STATUS]) & RF_HAS_DATA) {
110
                /*
111
                 * Map in the DPM to the base page and copy the message
112
                 */
113
                save_flags(flags);
114
                cli();
115
                outb((adapter[card]->shmem_magic >> 14) | 0x80,
116
                        adapter[card]->ioport[adapter[card]->shmem_pgport]);
117
                dpm = (DualPortMemory *) adapter[card]->rambase;
118
                memcpy_fromio(rspmsg, &(dpm->rsp_queue[dpm->rsp_tail]),
119
                        MSG_LEN);
120
                dpm->rsp_tail = (dpm->rsp_tail+1) % MAX_MESSAGES;
121
                inb(adapter[card]->ioport[FIFO_READ]);
122
                restore_flags(flags);
123
 
124
                /*
125
                 * Tell the board that the message is received
126
                 */
127
                pr_debug("%s: Received Message seq:%d pid:%d time:%d cmd:%d "
128
                                "cnt:%d (type,class,code):(%d,%d,%d) "
129
                                "link:%d stat:0x%x\n",
130
                                        adapter[card]->devicename,
131
                                        rspmsg->sequence_no,
132
                                        rspmsg->process_id,
133
                                        rspmsg->time_stamp,
134
                                        rspmsg->cmd_sequence_no,
135
                                        rspmsg->msg_byte_cnt,
136
                                        rspmsg->type,
137
                                        rspmsg->class,
138
                                        rspmsg->code,
139
                                        rspmsg->phy_link_no,
140
                                        rspmsg->rsp_status);
141
 
142
                return 0;
143
        }
144
        return -ENOMSG;
145
}
146
 
147
/*
148
 * send a message to the board
149
 */
150
int sendmessage(int card,
151
                unsigned int procid,
152
                unsigned int type,
153
                unsigned int class,
154
                unsigned int code,
155
                unsigned int link,
156
                unsigned int data_len,
157
                unsigned int *data)
158
{
159
        DualPortMemory *dpm;
160
        ReqMessage sndmsg;
161
        unsigned long flags;
162
 
163
        if (!IS_VALID_CARD(card)) {
164
                pr_debug("Invalid param: %d is not a valid card id\n", card);
165
                return -EINVAL;
166
        }
167
 
168
        /*
169
         * Make sure we only send CEPID messages when the engine is up
170
         * and CMPID messages when it is down
171
         */
172
        if(adapter[card]->EngineUp && procid == CMPID) {
173
                pr_debug("%s: Attempt to send CM message with engine up\n",
174
                        adapter[card]->devicename);
175
                return -ESRCH;
176
        }
177
 
178
        if(!adapter[card]->EngineUp && procid == CEPID) {
179
                pr_debug("%s: Attempt to send CE message with engine down\n",
180
                        adapter[card]->devicename);
181
                return -ESRCH;
182
        }
183
 
184
        memset(&sndmsg, 0, MSG_LEN);
185
        sndmsg.msg_byte_cnt = 4;
186
        sndmsg.type = type;
187
        sndmsg.class = class;
188
        sndmsg.code = code;
189
        sndmsg.phy_link_no = link;
190
 
191
        if (data_len > 0) {
192
                if (data_len > MSG_DATA_LEN)
193
                        data_len = MSG_DATA_LEN;
194
                memcpy(&(sndmsg.msg_data), data, data_len);
195
                sndmsg.msg_byte_cnt = data_len + 8;
196
        }
197
 
198
        sndmsg.process_id = procid;
199
        sndmsg.sequence_no = adapter[card]->seq_no++ % 256;
200
 
201
        /*
202
         * wait for an empty slot in the queue
203
         */
204
        while (!(inb(adapter[card]->ioport[FIFO_STATUS]) & WF_NOT_FULL))
205
                SLOW_DOWN_IO;
206
 
207
        /*
208
         * Disable interrupts and map in shared memory
209
         */
210
        save_flags(flags);
211
        cli();
212
        outb((adapter[card]->shmem_magic >> 14) | 0x80,
213
                adapter[card]->ioport[adapter[card]->shmem_pgport]);
214
        dpm = (DualPortMemory *) adapter[card]->rambase;        /* Fix me */
215
        memcpy_toio(&(dpm->req_queue[dpm->req_head]),&sndmsg,MSG_LEN);
216
        dpm->req_head = (dpm->req_head+1) % MAX_MESSAGES;
217
        outb(sndmsg.sequence_no, adapter[card]->ioport[FIFO_WRITE]);
218
        restore_flags(flags);
219
 
220
        pr_debug("%s: Sent Message seq:%d pid:%d time:%d "
221
                        "cnt:%d (type,class,code):(%d,%d,%d) "
222
                        "link:%d\n ",
223
                                adapter[card]->devicename,
224
                                sndmsg.sequence_no,
225
                                sndmsg.process_id,
226
                                sndmsg.time_stamp,
227
                                sndmsg.msg_byte_cnt,
228
                                sndmsg.type,
229
                                sndmsg.class,
230
                                sndmsg.code,
231
                                sndmsg.phy_link_no);
232
 
233
        return 0;
234
}
235
 
236
int send_and_receive(int card,
237
                unsigned int procid,
238
                unsigned char type,
239
                unsigned char class,
240
                unsigned char code,
241
                unsigned char link,
242
                unsigned char data_len,
243
                unsigned char *data,
244
                RspMessage *mesgdata,
245
                int timeout)
246
{
247
        int retval;
248
        int tries;
249
 
250
        if (!IS_VALID_CARD(card)) {
251
                pr_debug("Invalid param: %d is not a valid card id\n", card);
252
                return -EINVAL;
253
        }
254
 
255
        adapter[card]->want_async_messages = 1;
256
        retval = sendmessage(card, procid, type, class, code, link,
257
                        data_len, (unsigned int *) data);
258
 
259
        if (retval) {
260
                pr_debug("%s: SendMessage failed in SAR\n",
261
                        adapter[card]->devicename);
262
                adapter[card]->want_async_messages = 0;
263
                return -EIO;
264
        }
265
 
266
        tries = 0;
267
        /* wait for the response */
268
        while (tries < timeout) {
269
                current->state = TASK_INTERRUPTIBLE;
270
                current->timeout = jiffies + 1;
271
                schedule();
272
 
273
                pr_debug("SAR waiting..\n");
274
 
275
                /*
276
                 * See if we got our message back
277
                 */
278
                if ((adapter[card]->async_msg.type == type) &&
279
                    (adapter[card]->async_msg.class == class) &&
280
                    (adapter[card]->async_msg.code == code) &&
281
                    (adapter[card]->async_msg.phy_link_no == link)) {
282
 
283
                        /*
284
                         * Got it!
285
                         */
286
                        pr_debug("%s: Got ASYNC message\n",
287
                                adapter[card]->devicename);
288
                        memcpy(mesgdata, &(adapter[card]->async_msg),
289
                                sizeof(RspMessage));
290
                        adapter[card]->want_async_messages = 0;
291
                        return 0;
292
                }
293
 
294
                tries++;
295
        }
296
 
297
        pr_debug("%s: SAR message timeout\n", adapter[card]->devicename);
298
        adapter[card]->want_async_messages = 0;
299
        return -ETIME;
300
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.