* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / isdn / sc / packet.c
blobd75cb04d7f7b4fb43d11a57a68b1e50470d4ce7e
1 /*
2 * $Id: packet.c,v 1.4 1998/02/12 23:08:50 keil Exp $
3 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
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.
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.
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.
19 * For more information, please contact gpl-info@spellcast.com or write:
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
29 #define __NO_VERSION__
30 #include "includes.h"
31 #include "hardware.h"
32 #include "message.h"
33 #include "card.h"
35 extern board *adapter[];
36 extern unsigned int cinst;
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 *);
45 int sndpkt(int devId, int channel, struct sk_buff *data)
47 LLData ReqLnkWrite;
48 int status;
49 int card;
50 unsigned long len;
52 card = get_card_from_id(devId);
54 if(!IS_VALID_CARD(card)) {
55 pr_debug("Invalid param: %d is not a valid card id\n", card);
56 return -ENODEV;
59 pr_debug("%s: Send Packet: frst = 0x%x nxt = %d f = %d n = %d\n",
60 adapter[card]->devicename,
61 adapter[card]->channel[channel].first_sendbuf,
62 adapter[card]->channel[channel].next_sendbuf,
63 adapter[card]->channel[channel].free_sendbufs,
64 adapter[card]->channel[channel].num_sendbufs);
66 if(!adapter[card]->channel[channel].free_sendbufs) {
67 pr_debug("%s: Out out TX buffers\n", adapter[card]->devicename);
68 return -EINVAL;
71 if(data->len > BUFFER_SIZE) {
72 pr_debug("%s: Data overflows buffer size (data > buffer)\n", adapter[card]->devicename);
73 return -EINVAL;
76 ReqLnkWrite.buff_offset = adapter[card]->channel[channel].next_sendbuf *
77 BUFFER_SIZE + adapter[card]->channel[channel].first_sendbuf;
78 ReqLnkWrite.msg_len = data->len; /* sk_buff size */
79 pr_debug("%s: Writing %d bytes to buffer offset 0x%x\n", adapter[card]->devicename,
80 ReqLnkWrite.msg_len, ReqLnkWrite.buff_offset);
81 memcpy_toshmem(card, (char *)ReqLnkWrite.buff_offset, data->data, ReqLnkWrite.msg_len);
84 * sendmessage
86 pr_debug("%s: Send Packet size=%d, buf_offset=0x%x buf_indx=%d\n",
87 adapter[card]->devicename,
88 ReqLnkWrite.msg_len, ReqLnkWrite.buff_offset,
89 adapter[card]->channel[channel].next_sendbuf);
91 status = sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkWrite,
92 channel+1, sizeof(LLData), (unsigned int*)&ReqLnkWrite);
93 len = data->len;
94 if(status) {
95 pr_debug("%s: Failed to send packet, status = %d\n", adapter[card]->devicename, status);
96 return -1;
98 else {
99 adapter[card]->channel[channel].free_sendbufs--;
100 adapter[card]->channel[channel].next_sendbuf =
101 ++adapter[card]->channel[channel].next_sendbuf ==
102 adapter[card]->channel[channel].num_sendbufs ? 0 :
103 adapter[card]->channel[channel].next_sendbuf;
104 pr_debug("%s: Packet sent successfully\n", adapter[card]->devicename);
105 dev_kfree_skb(data);
106 indicate_status(card,ISDN_STAT_BSENT,channel, (char *)&len);
108 return len;
111 void rcvpkt(int card, RspMessage *rcvmsg)
113 LLData newll;
114 struct sk_buff *skb;
116 if(!IS_VALID_CARD(card)) {
117 pr_debug("Invalid param: %d is not a valid card id\n", card);
118 return;
121 switch(rcvmsg->rsp_status){
122 case 0x01:
123 case 0x02:
124 case 0x70:
125 pr_debug("%s: Error status code: 0x%x\n", adapter[card]->devicename, rcvmsg->rsp_status);
126 return;
127 case 0x00:
128 if (!(skb = dev_alloc_skb(rcvmsg->msg_data.response.msg_len))) {
129 printk(KERN_WARNING "%s: rcvpkt out of memory, dropping packet\n",
130 adapter[card]->devicename);
131 return;
133 skb_put(skb, rcvmsg->msg_data.response.msg_len);
134 pr_debug("%s: getting data from offset: 0x%x\n",
135 adapter[card]->devicename,rcvmsg->msg_data.response.buff_offset);
136 memcpy_fromshmem(card,
137 skb_put(skb, rcvmsg->msg_data.response.msg_len),
138 (char *)rcvmsg->msg_data.response.buff_offset,
139 rcvmsg->msg_data.response.msg_len);
140 adapter[card]->card->rcvcallb_skb(adapter[card]->driverId,
141 rcvmsg->phy_link_no-1, skb);
143 case 0x03:
145 * Recycle the buffer
147 pr_debug("%s: Buffer size : %d\n", adapter[card]->devicename, BUFFER_SIZE);
148 /* memset_shmem(card, rcvmsg->msg_data.response.buff_offset, 0, BUFFER_SIZE); */
149 newll.buff_offset = rcvmsg->msg_data.response.buff_offset;
150 newll.msg_len = BUFFER_SIZE;
151 pr_debug("%s: recycled buffer at offset 0x%x size %d\n", adapter[card]->devicename,
152 newll.buff_offset, newll.msg_len);
153 sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkRead,
154 rcvmsg->phy_link_no, sizeof(LLData), (unsigned int *)&newll);
159 int setup_buffers(int card, int c)
161 unsigned int nBuffers, i, cBase;
162 unsigned int buffer_size;
163 LLData RcvBuffOffset;
165 if(!IS_VALID_CARD(card)) {
166 pr_debug("Invalid param: %d is not a valid card id\n", card);
167 return -ENODEV;
171 * Calculate the buffer offsets (send/recv/send/recv)
173 pr_debug("%s: Seting up channel buffer space in shared RAM\n", adapter[card]->devicename);
174 buffer_size = BUFFER_SIZE;
175 nBuffers = ((adapter[card]->ramsize - BUFFER_BASE) / buffer_size) / 2;
176 nBuffers = nBuffers > BUFFERS_MAX ? BUFFERS_MAX : nBuffers;
177 pr_debug("%s: Calculating buffer space: %d buffers, %d big\n", adapter[card]->devicename,
178 nBuffers, buffer_size);
179 if(nBuffers < 2) {
180 pr_debug("%s: Not enough buffer space\n", adapter[card]->devicename);
181 return -1;
183 cBase = (nBuffers * buffer_size) * (c - 1);
184 pr_debug("%s: Channel buffer offset from Shared RAM: 0x%x\n", adapter[card]->devicename, cBase);
185 adapter[card]->channel[c-1].first_sendbuf = BUFFER_BASE + cBase;
186 adapter[card]->channel[c-1].num_sendbufs = nBuffers / 2;
187 adapter[card]->channel[c-1].free_sendbufs = nBuffers / 2;
188 adapter[card]->channel[c-1].next_sendbuf = 0;
189 pr_debug("%s: Send buffer setup complete: first=0x%x n=%d f=%d, nxt=%d\n",
190 adapter[card]->devicename,
191 adapter[card]->channel[c-1].first_sendbuf,
192 adapter[card]->channel[c-1].num_sendbufs,
193 adapter[card]->channel[c-1].free_sendbufs,
194 adapter[card]->channel[c-1].next_sendbuf);
197 * Prep the receive buffers
199 pr_debug("%s: Adding %d RecvBuffers:\n", adapter[card]->devicename, nBuffers /2);
200 for (i = 0 ; i < nBuffers / 2; i++) {
201 RcvBuffOffset.buff_offset =
202 ((adapter[card]->channel[c-1].first_sendbuf +
203 (nBuffers / 2) * buffer_size) + (buffer_size * i));
204 RcvBuffOffset.msg_len = buffer_size;
205 pr_debug("%s: Adding RcvBuffer #%d offset=0x%x sz=%d buffsz:%d\n",
206 adapter[card]->devicename,
207 i + 1, RcvBuffOffset.buff_offset,
208 RcvBuffOffset.msg_len,buffer_size);
209 sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkRead,
210 c, sizeof(LLData), (unsigned int *)&RcvBuffOffset);
212 return 0;
215 int print_skb(int card,char *skb_p, int len){
216 int i,data;
217 pr_debug("%s: data at 0x%x len: 0x%x\n",adapter[card]->devicename,
218 skb_p,len);
219 for(i=1;i<=len;i++,skb_p++){
220 data = (int) (0xff & (*skb_p));
221 pr_debug("%s: data = 0x%x",adapter[card]->devicename,data);
222 if(!(i%4))
223 pr_debug(" ");
224 if(!(i%32))
225 pr_debug("\n");
227 pr_debug("\n");
228 return 0;