1 /* $Id: packet.c,v 1.5.8.1 2001/09/23 22:24:59 kai Exp $
3 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference.
8 * For more information, please contact gpl-info@spellcast.com or write:
10 * SpellCaster Telecommunications Inc.
11 * 5621 Finch Avenue East, Unit #3
12 * Scarborough, Ontario Canada
15 * +1 (416) 297-6433 Facsimile
23 int sndpkt(int devId, int channel, struct sk_buff *data)
30 card = get_card_from_id(devId);
32 if(!IS_VALID_CARD(card)) {
33 pr_debug("invalid param: %d is not a valid card id\n", card);
37 pr_debug("%s: sndpkt: frst = 0x%lx nxt = %d f = %d n = %d\n",
38 sc_adapter[card]->devicename,
39 sc_adapter[card]->channel[channel].first_sendbuf,
40 sc_adapter[card]->channel[channel].next_sendbuf,
41 sc_adapter[card]->channel[channel].free_sendbufs,
42 sc_adapter[card]->channel[channel].num_sendbufs);
44 if(!sc_adapter[card]->channel[channel].free_sendbufs) {
45 pr_debug("%s: out of TX buffers\n",
46 sc_adapter[card]->devicename);
50 if(data->len > BUFFER_SIZE) {
51 pr_debug("%s: data overflows buffer size (data > buffer)\n",
52 sc_adapter[card]->devicename);
56 ReqLnkWrite.buff_offset = sc_adapter[card]->channel[channel].next_sendbuf *
57 BUFFER_SIZE + sc_adapter[card]->channel[channel].first_sendbuf;
58 ReqLnkWrite.msg_len = data->len; /* sk_buff size */
59 pr_debug("%s: writing %d bytes to buffer offset 0x%lx\n",
60 sc_adapter[card]->devicename,
61 ReqLnkWrite.msg_len, ReqLnkWrite.buff_offset);
62 memcpy_toshmem(card, (char *)ReqLnkWrite.buff_offset, data->data, ReqLnkWrite.msg_len);
67 pr_debug("%s: sndpkt size=%d, buf_offset=0x%lx buf_indx=%d\n",
68 sc_adapter[card]->devicename,
69 ReqLnkWrite.msg_len, ReqLnkWrite.buff_offset,
70 sc_adapter[card]->channel[channel].next_sendbuf);
72 status = sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkWrite,
73 channel+1, sizeof(LLData), (unsigned int*)&ReqLnkWrite);
76 pr_debug("%s: failed to send packet, status = %d\n",
77 sc_adapter[card]->devicename, status);
81 sc_adapter[card]->channel[channel].free_sendbufs--;
82 sc_adapter[card]->channel[channel].next_sendbuf =
83 ++sc_adapter[card]->channel[channel].next_sendbuf ==
84 sc_adapter[card]->channel[channel].num_sendbufs ? 0 :
85 sc_adapter[card]->channel[channel].next_sendbuf;
86 pr_debug("%s: packet sent successfully\n", sc_adapter[card]->devicename);
88 indicate_status(card,ISDN_STAT_BSENT,channel, (char *)&len);
93 void rcvpkt(int card, RspMessage *rcvmsg)
98 if(!IS_VALID_CARD(card)) {
99 pr_debug("invalid param: %d is not a valid card id\n", card);
103 switch(rcvmsg->rsp_status){
107 pr_debug("%s: error status code: 0x%x\n",
108 sc_adapter[card]->devicename, rcvmsg->rsp_status);
111 if (!(skb = dev_alloc_skb(rcvmsg->msg_data.response.msg_len))) {
112 printk(KERN_WARNING "%s: rcvpkt out of memory, dropping packet\n",
113 sc_adapter[card]->devicename);
116 skb_put(skb, rcvmsg->msg_data.response.msg_len);
117 pr_debug("%s: getting data from offset: 0x%lx\n",
118 sc_adapter[card]->devicename,
119 rcvmsg->msg_data.response.buff_offset);
120 memcpy_fromshmem(card,
121 skb_put(skb, rcvmsg->msg_data.response.msg_len),
122 (char *)rcvmsg->msg_data.response.buff_offset,
123 rcvmsg->msg_data.response.msg_len);
124 sc_adapter[card]->card->rcvcallb_skb(sc_adapter[card]->driverId,
125 rcvmsg->phy_link_no-1, skb);
131 pr_debug("%s: buffer size : %d\n",
132 sc_adapter[card]->devicename, BUFFER_SIZE);
133 /* memset_shmem(card, rcvmsg->msg_data.response.buff_offset, 0, BUFFER_SIZE); */
134 newll.buff_offset = rcvmsg->msg_data.response.buff_offset;
135 newll.msg_len = BUFFER_SIZE;
136 pr_debug("%s: recycled buffer at offset 0x%lx size %d\n",
137 sc_adapter[card]->devicename,
138 newll.buff_offset, newll.msg_len);
139 sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkRead,
140 rcvmsg->phy_link_no, sizeof(LLData), (unsigned int *)&newll);
145 int setup_buffers(int card, int c)
147 unsigned int nBuffers, i, cBase;
148 unsigned int buffer_size;
149 LLData RcvBuffOffset;
151 if(!IS_VALID_CARD(card)) {
152 pr_debug("invalid param: %d is not a valid card id\n", card);
157 * Calculate the buffer offsets (send/recv/send/recv)
159 pr_debug("%s: setting up channel buffer space in shared RAM\n",
160 sc_adapter[card]->devicename);
161 buffer_size = BUFFER_SIZE;
162 nBuffers = ((sc_adapter[card]->ramsize - BUFFER_BASE) / buffer_size) / 2;
163 nBuffers = nBuffers > BUFFERS_MAX ? BUFFERS_MAX : nBuffers;
164 pr_debug("%s: calculating buffer space: %d buffers, %d big\n",
165 sc_adapter[card]->devicename,
166 nBuffers, buffer_size);
168 pr_debug("%s: not enough buffer space\n",
169 sc_adapter[card]->devicename);
172 cBase = (nBuffers * buffer_size) * (c - 1);
173 pr_debug("%s: channel buffer offset from shared RAM: 0x%x\n",
174 sc_adapter[card]->devicename, cBase);
175 sc_adapter[card]->channel[c-1].first_sendbuf = BUFFER_BASE + cBase;
176 sc_adapter[card]->channel[c-1].num_sendbufs = nBuffers / 2;
177 sc_adapter[card]->channel[c-1].free_sendbufs = nBuffers / 2;
178 sc_adapter[card]->channel[c-1].next_sendbuf = 0;
179 pr_debug("%s: send buffer setup complete: first=0x%lx n=%d f=%d, nxt=%d\n",
180 sc_adapter[card]->devicename,
181 sc_adapter[card]->channel[c-1].first_sendbuf,
182 sc_adapter[card]->channel[c-1].num_sendbufs,
183 sc_adapter[card]->channel[c-1].free_sendbufs,
184 sc_adapter[card]->channel[c-1].next_sendbuf);
187 * Prep the receive buffers
189 pr_debug("%s: adding %d RecvBuffers:\n",
190 sc_adapter[card]->devicename, nBuffers /2);
191 for (i = 0 ; i < nBuffers / 2; i++) {
192 RcvBuffOffset.buff_offset =
193 ((sc_adapter[card]->channel[c-1].first_sendbuf +
194 (nBuffers / 2) * buffer_size) + (buffer_size * i));
195 RcvBuffOffset.msg_len = buffer_size;
196 pr_debug("%s: adding RcvBuffer #%d offset=0x%lx sz=%d bufsz:%d\n",
197 sc_adapter[card]->devicename,
198 i + 1, RcvBuffOffset.buff_offset,
199 RcvBuffOffset.msg_len,buffer_size);
200 sendmessage(card, CEPID, ceReqTypeLnk, ceReqClass1, ceReqLnkRead,
201 c, sizeof(LLData), (unsigned int *)&RcvBuffOffset);