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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [isdn/] [sc/] [packet.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 *  $Id: packet.c,v 1.1 2005-12-20 10:17:12 jcastillo Exp $
3
 *  Copyright (C) 1996  SpellCaster Telecommunications Inc.
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 *
19
 *  For more information, please contact gpl-info@spellcast.com or write:
20
 *
21
 *     SpellCaster Telecommunications Inc.
22
 *     5621 Finch Avenue East, Unit #3
23
 *     Scarborough, Ontario  Canada
24
 *     M1B 2T9
25
 *     +1 (416) 297-8565
26
 *     +1 (416) 297-6433 Facsimile
27
 */
28
 
29
#define __NO_VERSION__
30
#include "includes.h"
31
#include "hardware.h"
32
#include "message.h"
33
#include "card.h"
34
 
35
extern board *adapter[];
36
extern unsigned int cinst;
37
 
38
extern int get_card_from_id(int);
39
extern int indicate_status(int, int,ulong,char*);
40
extern void *memcpy_toshmem(int, void *, const void *, size_t);
41
extern void *memcpy_fromshmem(int, void *, const void *, size_t);
42
extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
43
                unsigned int, unsigned int, unsigned int, unsigned int *);
44
 
45
int sndpkt(int devId, int channel, struct sk_buff *data)
46
{
47
        LLData  ReqLnkWrite;
48
        int status;
49
        int card;
50
 
51
        card = get_card_from_id(devId);
52
 
53
        if(!IS_VALID_CARD(card)) {
54
                pr_debug("Invalid param: %d is not a valid card id\n", card);
55
                return -ENODEV;
56
        }
57
 
58
        pr_debug("%s: Send Packet: frst = 0x%x nxt = %d  f = %d n = %d\n",
59
                adapter[card]->devicename,
60
                adapter[card]->channel[channel].first_sendbuf,
61
                adapter[card]->channel[channel].next_sendbuf,
62
                adapter[card]->channel[channel].free_sendbufs,
63
                adapter[card]->channel[channel].num_sendbufs);
64
 
65
        if(!adapter[card]->channel[channel].free_sendbufs) {
66
                pr_debug("%s: Out out TX buffers\n", adapter[card]->devicename);
67
                return -EINVAL;
68
        }
69
 
70
        if(data->len > BUFFER_SIZE) {
71
                pr_debug("%s: Data overflows buffer size (data > buffer)\n", adapter[card]->devicename);
72
                return -EINVAL;
73
        }
74
 
75
        ReqLnkWrite.buff_offset = adapter[card]->channel[channel].next_sendbuf *
76
                BUFFER_SIZE + adapter[card]->channel[channel].first_sendbuf;
77
        ReqLnkWrite.msg_len = data->len; /* sk_buff size */
78
        pr_debug("%s: Writing %d bytes to buffer offset 0x%x\n", adapter[card]->devicename,
79
                        ReqLnkWrite.msg_len, ReqLnkWrite.buff_offset);
80
        memcpy_toshmem(card, (char *)ReqLnkWrite.buff_offset, data->data, ReqLnkWrite.msg_len);
81
 
82
        /*
83
         * sendmessage
84
         */
85
        pr_debug("%s: Send Packet size=%d, buf_offset=0x%x buf_indx=%d\n",
86
                adapter[card]->devicename,
87
                ReqLnkWrite.msg_len, ReqLnkWrite.buff_offset,
88
                adapter[card]->channel[channel].next_sendbuf);
89
 
90
        status = sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkWrite,
91
                                channel+1, sizeof(LLData), (unsigned int*)&ReqLnkWrite);
92
        if(status) {
93
                pr_debug("%s: Failed to send packet, status = %d\n", adapter[card]->devicename, status);
94
                return -1;
95
        }
96
        else {
97
                adapter[card]->channel[channel].free_sendbufs--;
98
                adapter[card]->channel[channel].next_sendbuf =
99
                        ++adapter[card]->channel[channel].next_sendbuf ==
100
                        adapter[card]->channel[channel].num_sendbufs ? 0 :
101
                        adapter[card]->channel[channel].next_sendbuf;
102
                        pr_debug("%s: Packet sent successfully\n", adapter[card]->devicename);
103
                dev_kfree_skb(data, FREE_WRITE);
104
                indicate_status(card,ISDN_STAT_BSENT,channel,NULL);
105
        }
106
        return data->len;
107
}
108
 
109
void rcvpkt(int card, RspMessage *rcvmsg)
110
{
111
        LLData newll;
112
        struct sk_buff *skb;
113
 
114
        if(!IS_VALID_CARD(card)) {
115
                pr_debug("Invalid param: %d is not a valid card id\n", card);
116
                return;
117
        }
118
 
119
        switch(rcvmsg->rsp_status){
120
        case 0x01:
121
        case 0x02:
122
        case 0x70:
123
                pr_debug("%s: Error status code: 0x%x\n", adapter[card]->devicename, rcvmsg->rsp_status);
124
                return;
125
        case 0x00:
126
            if (!(skb = dev_alloc_skb(rcvmsg->msg_data.response.msg_len))) {
127
                        printk(KERN_WARNING "%s: rcvpkt out of memory, dropping packet\n",
128
                                adapter[card]->devicename);
129
                        return;
130
                }
131
                skb_put(skb, rcvmsg->msg_data.response.msg_len);
132
                pr_debug("%s: getting data from offset: 0x%x\n",
133
                        adapter[card]->devicename,rcvmsg->msg_data.response.buff_offset);
134
                memcpy_fromshmem(card,
135
                        skb_put(skb, rcvmsg->msg_data.response.msg_len),
136
                        (char *)rcvmsg->msg_data.response.buff_offset,
137
                        rcvmsg->msg_data.response.msg_len);
138
                adapter[card]->card->rcvcallb_skb(adapter[card]->driverId,
139
                        rcvmsg->phy_link_no-1, skb);
140
 
141
        case 0x03:
142
                /*
143
                 * Recycle the buffer
144
                 */
145
                pr_debug("%s: Buffer size : %d\n", adapter[card]->devicename, BUFFER_SIZE);
146
/*              memset_shmem(card, rcvmsg->msg_data.response.buff_offset, 0, BUFFER_SIZE); */
147
                newll.buff_offset = rcvmsg->msg_data.response.buff_offset;
148
                newll.msg_len = BUFFER_SIZE;
149
                pr_debug("%s: recycled buffer at offset 0x%x size %d\n", adapter[card]->devicename,
150
                        newll.buff_offset, newll.msg_len);
151
                sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkRead,
152
                        rcvmsg->phy_link_no, sizeof(LLData), (unsigned int *)&newll);
153
        }
154
 
155
}
156
 
157
int setup_buffers(int card, int c)
158
{
159
        unsigned int nBuffers, i, cBase;
160
        unsigned int buffer_size;
161
        LLData  RcvBuffOffset;
162
 
163
        if(!IS_VALID_CARD(card)) {
164
                pr_debug("Invalid param: %d is not a valid card id\n", card);
165
                return -ENODEV;
166
        }
167
 
168
        /*
169
         * Calculate the buffer offsets (send/recv/send/recv)
170
         */
171
        pr_debug("%s: Seting up channel buffer space in shared RAM\n", adapter[card]->devicename);
172
        buffer_size = BUFFER_SIZE;
173
        nBuffers = ((adapter[card]->ramsize - BUFFER_BASE) / buffer_size) / 2;
174
        nBuffers = nBuffers > BUFFERS_MAX ? BUFFERS_MAX : nBuffers;
175
        pr_debug("%s: Calculating buffer space: %d buffers, %d big\n", adapter[card]->devicename,
176
                nBuffers, buffer_size);
177
        if(nBuffers < 2) {
178
                pr_debug("%s: Not enough buffer space\n", adapter[card]->devicename);
179
                return -1;
180
        }
181
        cBase = (nBuffers * buffer_size) * (c - 1);
182
        pr_debug("%s: Channel buffer offset from Shared RAM: 0x%x\n", adapter[card]->devicename, cBase);
183
        adapter[card]->channel[c-1].first_sendbuf = BUFFER_BASE + cBase;
184
        adapter[card]->channel[c-1].num_sendbufs = nBuffers / 2;
185
        adapter[card]->channel[c-1].free_sendbufs = nBuffers / 2;
186
        adapter[card]->channel[c-1].next_sendbuf = 0;
187
        pr_debug("%s: Send buffer setup complete: first=0x%x n=%d f=%d, nxt=%d\n",
188
                                adapter[card]->devicename,
189
                                adapter[card]->channel[c-1].first_sendbuf,
190
                                adapter[card]->channel[c-1].num_sendbufs,
191
                                adapter[card]->channel[c-1].free_sendbufs,
192
                                adapter[card]->channel[c-1].next_sendbuf);
193
 
194
        /*
195
         * Prep the receive buffers
196
         */
197
        pr_debug("%s: Adding %d RecvBuffers:\n", adapter[card]->devicename, nBuffers /2);
198
        for (i = 0 ; i < nBuffers / 2; i++) {
199
                RcvBuffOffset.buff_offset =
200
                        ((adapter[card]->channel[c-1].first_sendbuf +
201
                        (nBuffers / 2) * buffer_size) + (buffer_size * i));
202
                RcvBuffOffset.msg_len = buffer_size;
203
                pr_debug("%s: Adding RcvBuffer #%d offset=0x%x sz=%d buffsz:%d\n",
204
                                adapter[card]->devicename,
205
                                i + 1, RcvBuffOffset.buff_offset,
206
                                RcvBuffOffset.msg_len,buffer_size);
207
                sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkRead,
208
                                c, sizeof(LLData), (unsigned int *)&RcvBuffOffset);
209
        }
210
        return 0;
211
}
212
 
213
int print_skb(int card,char *skb_p, int len){
214
        int i,data;
215
        pr_debug("%s: data at 0x%x len: 0x%x\n",adapter[card]->devicename,
216
                        skb_p,len);
217
        for(i=1;i<=len;i++,skb_p++){
218
                data = (int) (0xff & (*skb_p));
219
                pr_debug("%s: data =  0x%x",adapter[card]->devicename,data);
220
                if(!(i%4))
221
                        pr_debug(" ");
222
                if(!(i%32))
223
                        pr_debug("\n");
224
        }
225
        pr_debug("\n");
226
        return 0;
227
}
228
 

powered by: WebSVN 2.1.0

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