s390: scatter-gather for inbound traffic in qeth driver
[linux-2.6/openmoko-kernel/knife-kernel.git] / drivers / s390 / net / claw.c
blob348bb7b82771a231cb5aae013d6d64158095275a
1 /*
2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
5 * Linux for zSeries version
6 * Copyright (C) 2002,2005 IBM Corporation
7 * Author(s) Original code written by:
8 * Kazuo Iimura (iimura@jp.ibm.com)
9 * Rewritten by
10 * Andy Richter (richtera@us.ibm.com)
11 * Marc Price (mwprice@us.ibm.com)
13 * sysfs parms:
14 * group x.x.rrrr,x.x.wwww
15 * read_buffer nnnnnnn
16 * write_buffer nnnnnn
17 * host_name aaaaaaaa
18 * adapter_name aaaaaaaa
19 * api_type aaaaaaaa
21 * eg.
22 * group 0.0.0200 0.0.0201
23 * read_buffer 25
24 * write_buffer 20
25 * host_name LINUX390
26 * adapter_name RS6K
27 * api_type TCPIP
29 * where
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
33 * up to CLAW_MAX_DEV
35 * rrrr - the first of 2 consecutive device addresses used for the
36 * CLAW protocol.
37 * The specified address is always used as the input (Read)
38 * channel and the next address is used as the output channel.
40 * wwww - the second of 2 consecutive device addresses used for
41 * the CLAW protocol.
42 * The specified address is always used as the output
43 * channel and the previous address is used as the input channel.
45 * read_buffer - specifies number of input buffers to allocate.
46 * write_buffer - specifies number of output buffers to allocate.
47 * host_name - host name
48 * adaptor_name - adaptor name
49 * api_type - API type TCPIP or API will be sent and expected
50 * as ws_name
52 * Note the following requirements:
53 * 1) host_name must match the configured adapter_name on the remote side
54 * 2) adaptor_name must match the configured host name on the remote side
56 * Change History
57 * 1.00 Initial release shipped
58 * 1.10 Changes for Buffer allocation
59 * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
60 * 1.25 Added Packing support
62 #include <asm/bitops.h>
63 #include <asm/ccwdev.h>
64 #include <asm/ccwgroup.h>
65 #include <asm/debug.h>
66 #include <asm/idals.h>
67 #include <asm/io.h>
69 #include <linux/ctype.h>
70 #include <linux/delay.h>
71 #include <linux/errno.h>
72 #include <linux/if_arp.h>
73 #include <linux/init.h>
74 #include <linux/interrupt.h>
75 #include <linux/ip.h>
76 #include <linux/kernel.h>
77 #include <linux/module.h>
78 #include <linux/netdevice.h>
79 #include <linux/etherdevice.h>
80 #include <linux/proc_fs.h>
81 #include <linux/sched.h>
82 #include <linux/signal.h>
83 #include <linux/skbuff.h>
84 #include <linux/slab.h>
85 #include <linux/string.h>
86 #include <linux/tcp.h>
87 #include <linux/timer.h>
88 #include <linux/types.h>
90 #include "cu3088.h"
91 #include "claw.h"
93 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
94 MODULE_DESCRIPTION("Linux for zSeries CLAW Driver\n" \
95 "Copyright 2000,2005 IBM Corporation\n");
96 MODULE_LICENSE("GPL");
98 /* Debugging is based on DEBUGMSG, IOTRACE, or FUNCTRACE options:
99 DEBUGMSG - Enables output of various debug messages in the code
100 IOTRACE - Enables output of CCW and other IO related traces
101 FUNCTRACE - Enables output of function entry/exit trace
102 Define any combination of above options to enable tracing
104 CLAW also uses the s390dbf file system see claw_trace and claw_setup
107 /* following enables tracing */
108 //#define DEBUGMSG
109 //#define IOTRACE
110 //#define FUNCTRACE
112 #ifdef DEBUGMSG
113 #define DEBUG
114 #endif
116 #ifdef IOTRACE
117 #define DEBUG
118 #endif
120 #ifdef FUNCTRACE
121 #define DEBUG
122 #endif
124 static char debug_buffer[255];
126 * Debug Facility Stuff
128 static debug_info_t *claw_dbf_setup;
129 static debug_info_t *claw_dbf_trace;
132 * CLAW Debug Facility functions
134 static void
135 claw_unregister_debug_facility(void)
137 if (claw_dbf_setup)
138 debug_unregister(claw_dbf_setup);
139 if (claw_dbf_trace)
140 debug_unregister(claw_dbf_trace);
143 static int
144 claw_register_debug_facility(void)
146 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
147 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
148 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
149 printk(KERN_WARNING "Not enough memory for debug facility.\n");
150 claw_unregister_debug_facility();
151 return -ENOMEM;
153 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
154 debug_set_level(claw_dbf_setup, 2);
155 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
156 debug_set_level(claw_dbf_trace, 2);
157 return 0;
160 static inline void
161 claw_set_busy(struct net_device *dev)
163 ((struct claw_privbk *) dev->priv)->tbusy=1;
164 eieio();
167 static inline void
168 claw_clear_busy(struct net_device *dev)
170 clear_bit(0, &(((struct claw_privbk *) dev->priv)->tbusy));
171 netif_wake_queue(dev);
172 eieio();
175 static inline int
176 claw_check_busy(struct net_device *dev)
178 eieio();
179 return ((struct claw_privbk *) dev->priv)->tbusy;
182 static inline void
183 claw_setbit_busy(int nr,struct net_device *dev)
185 netif_stop_queue(dev);
186 set_bit(nr, (void *)&(((struct claw_privbk *)dev->priv)->tbusy));
189 static inline void
190 claw_clearbit_busy(int nr,struct net_device *dev)
192 clear_bit(nr,(void *)&(((struct claw_privbk *)dev->priv)->tbusy));
193 netif_wake_queue(dev);
196 static inline int
197 claw_test_and_setbit_busy(int nr,struct net_device *dev)
199 netif_stop_queue(dev);
200 return test_and_set_bit(nr,
201 (void *)&(((struct claw_privbk *) dev->priv)->tbusy));
205 /* Functions for the DEV methods */
207 static int claw_probe(struct ccwgroup_device *cgdev);
208 static void claw_remove_device(struct ccwgroup_device *cgdev);
209 static void claw_purge_skb_queue(struct sk_buff_head *q);
210 static int claw_new_device(struct ccwgroup_device *cgdev);
211 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
212 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
213 static int claw_change_mtu( struct net_device *dev, int new_mtu);
214 static int claw_open(struct net_device *dev);
215 static void claw_irq_handler(struct ccw_device *cdev,
216 unsigned long intparm, struct irb *irb);
217 static void claw_irq_tasklet ( unsigned long data );
218 static int claw_release(struct net_device *dev);
219 static void claw_write_retry ( struct chbk * p_ch );
220 static void claw_write_next ( struct chbk * p_ch );
221 static void claw_timer ( struct chbk * p_ch );
223 /* Functions */
224 static int add_claw_reads(struct net_device *dev,
225 struct ccwbk* p_first, struct ccwbk* p_last);
226 static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
227 static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
228 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
229 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
230 static int init_ccw_bk(struct net_device *dev);
231 static void probe_error( struct ccwgroup_device *cgdev);
232 static struct net_device_stats *claw_stats(struct net_device *dev);
233 static int pages_to_order_of_mag(int num_of_pages);
234 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
235 #ifdef DEBUG
236 static void dumpit (char *buf, int len);
237 #endif
238 /* sysfs Functions */
239 static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
240 static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
241 const char *buf, size_t count);
242 static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
243 static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
244 const char *buf, size_t count);
245 static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
246 static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
247 const char *buf, size_t count);
248 static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
249 static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
250 const char *buf, size_t count);
251 static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
252 static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
253 const char *buf, size_t count);
254 static int claw_add_files(struct device *dev);
255 static void claw_remove_files(struct device *dev);
257 /* Functions for System Validate */
258 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
259 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
260 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
261 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
262 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
263 static int claw_snd_sys_validate_rsp(struct net_device *dev,
264 struct clawctl * p_ctl, __u32 return_code);
265 static int claw_strt_conn_req(struct net_device *dev );
266 static void claw_strt_read ( struct net_device *dev, int lock );
267 static void claw_strt_out_IO( struct net_device *dev );
268 static void claw_free_wrt_buf( struct net_device *dev );
270 /* Functions for unpack reads */
271 static void unpack_read (struct net_device *dev );
273 /* ccwgroup table */
275 static struct ccwgroup_driver claw_group_driver = {
276 .owner = THIS_MODULE,
277 .name = "claw",
278 .max_slaves = 2,
279 .driver_id = 0xC3D3C1E6,
280 .probe = claw_probe,
281 .remove = claw_remove_device,
282 .set_online = claw_new_device,
283 .set_offline = claw_shutdown_device,
288 * Key functions
291 /*----------------------------------------------------------------*
292 * claw_probe *
293 * this function is called for each CLAW device. *
294 *----------------------------------------------------------------*/
295 static int
296 claw_probe(struct ccwgroup_device *cgdev)
298 int rc;
299 struct claw_privbk *privptr=NULL;
301 #ifdef FUNCTRACE
302 printk(KERN_INFO "%s Enter\n",__FUNCTION__);
303 #endif
304 CLAW_DBF_TEXT(2,setup,"probe");
305 if (!get_device(&cgdev->dev))
306 return -ENODEV;
307 #ifdef DEBUGMSG
308 printk(KERN_INFO "claw: variable cgdev =\n");
309 dumpit((char *)cgdev, sizeof(struct ccwgroup_device));
310 #endif
311 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
312 if (privptr == NULL) {
313 probe_error(cgdev);
314 put_device(&cgdev->dev);
315 printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
316 cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
317 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
318 return -ENOMEM;
320 privptr->p_mtc_envelope= kmalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
321 privptr->p_env = kmalloc(sizeof(struct claw_env), GFP_KERNEL);
322 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
323 probe_error(cgdev);
324 put_device(&cgdev->dev);
325 printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
326 cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
327 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
328 return -ENOMEM;
330 memset(privptr->p_mtc_envelope, 0x00, MAX_ENVELOPE_SIZE);
331 memset(privptr->p_env, 0x00, sizeof(struct claw_env));
332 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
333 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
334 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
335 privptr->p_env->packing = 0;
336 privptr->p_env->write_buffers = 5;
337 privptr->p_env->read_buffers = 5;
338 privptr->p_env->read_size = CLAW_FRAME_SIZE;
339 privptr->p_env->write_size = CLAW_FRAME_SIZE;
340 rc = claw_add_files(&cgdev->dev);
341 if (rc) {
342 probe_error(cgdev);
343 put_device(&cgdev->dev);
344 printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
345 cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
346 CLAW_DBF_TEXT_(2,setup,"probex%d",rc);
347 return rc;
349 printk(KERN_INFO "claw: sysfs files added for %s\n",cgdev->cdev[0]->dev.bus_id);
350 privptr->p_env->p_priv = privptr;
351 cgdev->cdev[0]->handler = claw_irq_handler;
352 cgdev->cdev[1]->handler = claw_irq_handler;
353 cgdev->dev.driver_data = privptr;
354 #ifdef FUNCTRACE
355 printk(KERN_INFO "claw:%s exit on line %d, "
356 "rc = 0\n",__FUNCTION__,__LINE__);
357 #endif
358 CLAW_DBF_TEXT(2,setup,"prbext 0");
360 return 0;
361 } /* end of claw_probe */
363 /*-------------------------------------------------------------------*
364 * claw_tx *
365 *-------------------------------------------------------------------*/
367 static int
368 claw_tx(struct sk_buff *skb, struct net_device *dev)
370 int rc;
371 struct claw_privbk *privptr=dev->priv;
372 unsigned long saveflags;
373 struct chbk *p_ch;
375 #ifdef FUNCTRACE
376 printk(KERN_INFO "%s:%s enter\n",dev->name,__FUNCTION__);
377 #endif
378 CLAW_DBF_TEXT(4,trace,"claw_tx");
379 p_ch=&privptr->channel[WRITE];
380 if (skb == NULL) {
381 printk(KERN_WARNING "%s: null pointer passed as sk_buffer\n",
382 dev->name);
383 privptr->stats.tx_dropped++;
384 #ifdef FUNCTRACE
385 printk(KERN_INFO "%s: %s() exit on line %d, rc = EIO\n",
386 dev->name,__FUNCTION__, __LINE__);
387 #endif
388 CLAW_DBF_TEXT_(2,trace,"clawtx%d",-EIO);
389 return -EIO;
392 #ifdef IOTRACE
393 printk(KERN_INFO "%s: variable sk_buff=\n",dev->name);
394 dumpit((char *) skb, sizeof(struct sk_buff));
395 printk(KERN_INFO "%s: variable dev=\n",dev->name);
396 dumpit((char *) dev, sizeof(struct net_device));
397 #endif
398 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
399 rc=claw_hw_tx( skb, dev, 1 );
400 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
401 #ifdef FUNCTRACE
402 printk(KERN_INFO "%s:%s exit on line %d, rc = %d\n",
403 dev->name, __FUNCTION__, __LINE__, rc);
404 #endif
405 CLAW_DBF_TEXT_(4,trace,"clawtx%d",rc);
406 return rc;
407 } /* end of claw_tx */
409 /*------------------------------------------------------------------*
410 * pack the collect queue into an skb and return it *
411 * If not packing just return the top skb from the queue *
412 *------------------------------------------------------------------*/
414 static struct sk_buff *
415 claw_pack_skb(struct claw_privbk *privptr)
417 struct sk_buff *new_skb,*held_skb;
418 struct chbk *p_ch = &privptr->channel[WRITE];
419 struct claw_env *p_env = privptr->p_env;
420 int pkt_cnt,pk_ind,so_far;
422 new_skb = NULL; /* assume no dice */
423 pkt_cnt = 0;
424 CLAW_DBF_TEXT(4,trace,"PackSKBe");
425 if (!skb_queue_empty(&p_ch->collect_queue)) {
426 /* some data */
427 held_skb = skb_dequeue(&p_ch->collect_queue);
428 if (held_skb)
429 dev_kfree_skb_any(held_skb);
430 else
431 return NULL;
432 if (p_env->packing != DO_PACKED)
433 return held_skb;
434 /* get a new SKB we will pack at least one */
435 new_skb = dev_alloc_skb(p_env->write_size);
436 if (new_skb == NULL) {
437 atomic_inc(&held_skb->users);
438 skb_queue_head(&p_ch->collect_queue,held_skb);
439 return NULL;
441 /* we have packed packet and a place to put it */
442 pk_ind = 1;
443 so_far = 0;
444 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
445 while ((pk_ind) && (held_skb != NULL)) {
446 if (held_skb->len+so_far <= p_env->write_size-8) {
447 memcpy(skb_put(new_skb,held_skb->len),
448 held_skb->data,held_skb->len);
449 privptr->stats.tx_packets++;
450 so_far += held_skb->len;
451 pkt_cnt++;
452 dev_kfree_skb_any(held_skb);
453 held_skb = skb_dequeue(&p_ch->collect_queue);
454 if (held_skb)
455 atomic_dec(&held_skb->users);
456 } else {
457 pk_ind = 0;
458 atomic_inc(&held_skb->users);
459 skb_queue_head(&p_ch->collect_queue,held_skb);
462 #ifdef IOTRACE
463 printk(KERN_INFO "%s: %s() Packed %d len %d\n",
464 p_env->ndev->name,
465 __FUNCTION__,pkt_cnt,new_skb->len);
466 #endif
468 CLAW_DBF_TEXT(4,trace,"PackSKBx");
469 return new_skb;
472 /*-------------------------------------------------------------------*
473 * claw_change_mtu *
475 *-------------------------------------------------------------------*/
477 static int
478 claw_change_mtu(struct net_device *dev, int new_mtu)
480 struct claw_privbk *privptr=dev->priv;
481 int buff_size;
482 #ifdef FUNCTRACE
483 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
484 #endif
485 #ifdef DEBUGMSG
486 printk(KERN_INFO "variable dev =\n");
487 dumpit((char *) dev, sizeof(struct net_device));
488 printk(KERN_INFO "variable new_mtu = %d\n", new_mtu);
489 #endif
490 CLAW_DBF_TEXT(4,trace,"setmtu");
491 buff_size = privptr->p_env->write_size;
492 if ((new_mtu < 60) || (new_mtu > buff_size)) {
493 #ifdef FUNCTRACE
494 printk(KERN_INFO "%s:%s Exit on line %d, rc=EINVAL\n",
495 dev->name,
496 __FUNCTION__, __LINE__);
497 #endif
498 return -EINVAL;
500 dev->mtu = new_mtu;
501 #ifdef FUNCTRACE
502 printk(KERN_INFO "%s:%s Exit on line %d\n",dev->name,
503 __FUNCTION__, __LINE__);
504 #endif
505 return 0;
506 } /* end of claw_change_mtu */
509 /*-------------------------------------------------------------------*
510 * claw_open *
512 *-------------------------------------------------------------------*/
513 static int
514 claw_open(struct net_device *dev)
517 int rc;
518 int i;
519 unsigned long saveflags=0;
520 unsigned long parm;
521 struct claw_privbk *privptr;
522 DECLARE_WAITQUEUE(wait, current);
523 struct timer_list timer;
524 struct ccwbk *p_buf;
526 #ifdef FUNCTRACE
527 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
528 #endif
529 CLAW_DBF_TEXT(4,trace,"open");
530 if (!dev || (dev->name[0] == 0x00)) {
531 CLAW_DBF_TEXT(2,trace,"BadDev");
532 printk(KERN_WARNING "claw: Bad device at open failing \n");
533 return -ENODEV;
535 privptr = (struct claw_privbk *)dev->priv;
536 /* allocate and initialize CCW blocks */
537 if (privptr->buffs_alloc == 0) {
538 rc=init_ccw_bk(dev);
539 if (rc) {
540 printk(KERN_INFO "%s:%s Exit on line %d, rc=ENOMEM\n",
541 dev->name,
542 __FUNCTION__, __LINE__);
543 CLAW_DBF_TEXT(2,trace,"openmem");
544 return -ENOMEM;
547 privptr->system_validate_comp=0;
548 privptr->release_pend=0;
549 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
550 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
551 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
552 privptr->p_env->packing=PACKING_ASK;
553 } else {
554 privptr->p_env->packing=0;
555 privptr->p_env->read_size=CLAW_FRAME_SIZE;
556 privptr->p_env->write_size=CLAW_FRAME_SIZE;
558 claw_set_busy(dev);
559 tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
560 (unsigned long) &privptr->channel[READ]);
561 for ( i = 0; i < 2; i++) {
562 CLAW_DBF_TEXT_(2,trace,"opn_ch%d",i);
563 init_waitqueue_head(&privptr->channel[i].wait);
564 /* skb_queue_head_init(&p_ch->io_queue); */
565 if (i == WRITE)
566 skb_queue_head_init(
567 &privptr->channel[WRITE].collect_queue);
568 privptr->channel[i].flag_a = 0;
569 privptr->channel[i].IO_active = 0;
570 privptr->channel[i].flag &= ~CLAW_TIMER;
571 init_timer(&timer);
572 timer.function = (void *)claw_timer;
573 timer.data = (unsigned long)(&privptr->channel[i]);
574 timer.expires = jiffies + 15*HZ;
575 add_timer(&timer);
576 spin_lock_irqsave(get_ccwdev_lock(
577 privptr->channel[i].cdev), saveflags);
578 parm = (unsigned long) &privptr->channel[i];
579 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
580 rc = 0;
581 add_wait_queue(&privptr->channel[i].wait, &wait);
582 rc = ccw_device_halt(
583 (struct ccw_device *)privptr->channel[i].cdev,parm);
584 set_current_state(TASK_INTERRUPTIBLE);
585 spin_unlock_irqrestore(
586 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
587 schedule();
588 set_current_state(TASK_RUNNING);
589 remove_wait_queue(&privptr->channel[i].wait, &wait);
590 if(rc != 0)
591 ccw_check_return_code(privptr->channel[i].cdev, rc);
592 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
593 del_timer(&timer);
595 if ((((privptr->channel[READ].last_dstat |
596 privptr->channel[WRITE].last_dstat) &
597 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
598 (((privptr->channel[READ].flag |
599 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
600 #ifdef DEBUGMSG
601 printk(KERN_INFO "%s: channel problems during open - read:"
602 " %02x - write: %02x\n",
603 dev->name,
604 privptr->channel[READ].last_dstat,
605 privptr->channel[WRITE].last_dstat);
606 #endif
607 printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
608 CLAW_DBF_TEXT(2,trace,"notrdy");
610 for ( i = 0; i < 2; i++) {
611 spin_lock_irqsave(
612 get_ccwdev_lock(privptr->channel[i].cdev),
613 saveflags);
614 parm = (unsigned long) &privptr->channel[i];
615 privptr->channel[i].claw_state = CLAW_STOP;
616 rc = ccw_device_halt(
617 (struct ccw_device *)&privptr->channel[i].cdev,
618 parm);
619 spin_unlock_irqrestore(
620 get_ccwdev_lock(privptr->channel[i].cdev),
621 saveflags);
622 if (rc != 0) {
623 ccw_check_return_code(
624 privptr->channel[i].cdev, rc);
627 free_pages((unsigned long)privptr->p_buff_ccw,
628 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
629 if (privptr->p_env->read_size < PAGE_SIZE) {
630 free_pages((unsigned long)privptr->p_buff_read,
631 (int)pages_to_order_of_mag(
632 privptr->p_buff_read_num));
634 else {
635 p_buf=privptr->p_read_active_first;
636 while (p_buf!=NULL) {
637 free_pages((unsigned long)p_buf->p_buffer,
638 (int)pages_to_order_of_mag(
639 privptr->p_buff_pages_perread ));
640 p_buf=p_buf->next;
643 if (privptr->p_env->write_size < PAGE_SIZE ) {
644 free_pages((unsigned long)privptr->p_buff_write,
645 (int)pages_to_order_of_mag(
646 privptr->p_buff_write_num));
648 else {
649 p_buf=privptr->p_write_active_first;
650 while (p_buf!=NULL) {
651 free_pages((unsigned long)p_buf->p_buffer,
652 (int)pages_to_order_of_mag(
653 privptr->p_buff_pages_perwrite ));
654 p_buf=p_buf->next;
657 privptr->buffs_alloc = 0;
658 privptr->channel[READ].flag= 0x00;
659 privptr->channel[WRITE].flag = 0x00;
660 privptr->p_buff_ccw=NULL;
661 privptr->p_buff_read=NULL;
662 privptr->p_buff_write=NULL;
663 claw_clear_busy(dev);
664 #ifdef FUNCTRACE
665 printk(KERN_INFO "%s:%s Exit on line %d, rc=EIO\n",
666 dev->name,__FUNCTION__,__LINE__);
667 #endif
668 CLAW_DBF_TEXT(2,trace,"open EIO");
669 return -EIO;
672 /* Send SystemValidate command */
674 claw_clear_busy(dev);
676 #ifdef FUNCTRACE
677 printk(KERN_INFO "%s:%s Exit on line %d, rc=0\n",
678 dev->name,__FUNCTION__,__LINE__);
679 #endif
680 CLAW_DBF_TEXT(4,trace,"openok");
681 return 0;
682 } /* end of claw_open */
684 /*-------------------------------------------------------------------*
686 * claw_irq_handler *
688 *--------------------------------------------------------------------*/
689 static void
690 claw_irq_handler(struct ccw_device *cdev,
691 unsigned long intparm, struct irb *irb)
693 struct chbk *p_ch = NULL;
694 struct claw_privbk *privptr = NULL;
695 struct net_device *dev = NULL;
696 struct claw_env *p_env;
697 struct chbk *p_ch_r=NULL;
700 #ifdef FUNCTRACE
701 printk(KERN_INFO "%s enter \n",__FUNCTION__);
702 #endif
703 CLAW_DBF_TEXT(4,trace,"clawirq");
704 /* Bypass all 'unsolicited interrupts' */
705 if (!cdev->dev.driver_data) {
706 printk(KERN_WARNING "claw: unsolicited interrupt for device:"
707 "%s received c-%02x d-%02x\n",
708 cdev->dev.bus_id,irb->scsw.cstat, irb->scsw.dstat);
709 #ifdef FUNCTRACE
710 printk(KERN_INFO "claw: %s() "
711 "exit on line %d\n",__FUNCTION__,__LINE__);
712 #endif
713 CLAW_DBF_TEXT(2,trace,"badirq");
714 return;
716 privptr = (struct claw_privbk *)cdev->dev.driver_data;
718 /* Try to extract channel from driver data. */
719 if (privptr->channel[READ].cdev == cdev)
720 p_ch = &privptr->channel[READ];
721 else if (privptr->channel[WRITE].cdev == cdev)
722 p_ch = &privptr->channel[WRITE];
723 else {
724 printk(KERN_WARNING "claw: Can't determine channel for "
725 "interrupt, device %s\n", cdev->dev.bus_id);
726 CLAW_DBF_TEXT(2,trace,"badchan");
727 return;
729 CLAW_DBF_TEXT_(4,trace,"IRQCH=%d",p_ch->flag);
731 dev = (struct net_device *) (p_ch->ndev);
732 p_env=privptr->p_env;
734 #ifdef IOTRACE
735 printk(KERN_INFO "%s: interrupt for device: %04x "
736 "received c-%02x d-%02x state-%02x\n",
737 dev->name, p_ch->devno, irb->scsw.cstat,
738 irb->scsw.dstat, p_ch->claw_state);
739 #endif
741 /* Copy interruption response block. */
742 memcpy(p_ch->irb, irb, sizeof(struct irb));
744 /* Check for good subchannel return code, otherwise error message */
745 if (irb->scsw.cstat && !(irb->scsw.cstat & SCHN_STAT_PCI)) {
746 printk(KERN_INFO "%s: subchannel check for device: %04x -"
747 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
748 dev->name, p_ch->devno,
749 irb->scsw.cstat, irb->scsw.dstat,irb->scsw.cpa);
750 #ifdef IOTRACE
751 dumpit((char *)irb,sizeof(struct irb));
752 dumpit((char *)(unsigned long)irb->scsw.cpa,
753 sizeof(struct ccw1));
754 #endif
755 #ifdef FUNCTRACE
756 printk(KERN_INFO "%s:%s Exit on line %d\n",
757 dev->name,__FUNCTION__,__LINE__);
758 #endif
759 CLAW_DBF_TEXT(2,trace,"chanchk");
760 /* return; */
763 /* Check the reason-code of a unit check */
764 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
765 ccw_check_unit_check(p_ch, irb->ecw[0]);
768 /* State machine to bring the connection up, down and to restart */
769 p_ch->last_dstat = irb->scsw.dstat;
771 switch (p_ch->claw_state) {
772 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
773 #ifdef DEBUGMSG
774 printk(KERN_INFO "%s: CLAW_STOP enter\n", dev->name);
775 #endif
776 if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
777 (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
778 (p_ch->irb->scsw.stctl ==
779 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
780 #ifdef FUNCTRACE
781 printk(KERN_INFO "%s:%s Exit on line %d\n",
782 dev->name,__FUNCTION__,__LINE__);
783 #endif
784 return;
786 wake_up(&p_ch->wait); /* wake up claw_release */
788 #ifdef DEBUGMSG
789 printk(KERN_INFO "%s: CLAW_STOP exit\n", dev->name);
790 #endif
791 #ifdef FUNCTRACE
792 printk(KERN_INFO "%s:%s Exit on line %d\n",
793 dev->name,__FUNCTION__,__LINE__);
794 #endif
795 CLAW_DBF_TEXT(4,trace,"stop");
796 return;
798 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
799 #ifdef DEBUGMSG
800 printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO\n",
801 dev->name);
802 #endif
803 if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
804 (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
805 (p_ch->irb->scsw.stctl ==
806 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
807 #ifdef FUNCTRACE
808 printk(KERN_INFO "%s:%s Exit on line %d\n",
809 dev->name,__FUNCTION__,__LINE__);
810 #endif
811 CLAW_DBF_TEXT(4,trace,"haltio");
812 return;
814 if (p_ch->flag == CLAW_READ) {
815 p_ch->claw_state = CLAW_START_READ;
816 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
818 else
819 if (p_ch->flag == CLAW_WRITE) {
820 p_ch->claw_state = CLAW_START_WRITE;
821 /* send SYSTEM_VALIDATE */
822 claw_strt_read(dev, LOCK_NO);
823 claw_send_control(dev,
824 SYSTEM_VALIDATE_REQUEST,
825 0, 0, 0,
826 p_env->host_name,
827 p_env->adapter_name );
828 } else {
829 printk(KERN_WARNING "claw: unsolicited "
830 "interrupt for device:"
831 "%s received c-%02x d-%02x\n",
832 cdev->dev.bus_id,
833 irb->scsw.cstat,
834 irb->scsw.dstat);
835 return;
837 #ifdef DEBUGMSG
838 printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO exit\n",
839 dev->name);
840 #endif
841 #ifdef FUNCTRACE
842 printk(KERN_INFO "%s:%s Exit on line %d\n",
843 dev->name,__FUNCTION__,__LINE__);
844 #endif
845 CLAW_DBF_TEXT(4,trace,"haltio");
846 return;
847 case CLAW_START_READ:
848 CLAW_DBF_TEXT(4,trace,"ReadIRQ");
849 if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
850 clear_bit(0, (void *)&p_ch->IO_active);
851 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
852 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
853 (p_ch->irb->ecw[0]) == 0)
855 privptr->stats.rx_errors++;
856 printk(KERN_INFO "%s: Restart is "
857 "required after remote "
858 "side recovers \n",
859 dev->name);
861 #ifdef FUNCTRACE
862 printk(KERN_INFO "%s:%s Exit on line %d\n",
863 dev->name,__FUNCTION__,__LINE__);
864 #endif
865 CLAW_DBF_TEXT(4,trace,"notrdy");
866 return;
868 if ((p_ch->irb->scsw.cstat & SCHN_STAT_PCI) &&
869 (p_ch->irb->scsw.dstat==0)) {
870 if (test_and_set_bit(CLAW_BH_ACTIVE,
871 (void *)&p_ch->flag_a) == 0) {
872 tasklet_schedule(&p_ch->tasklet);
874 else {
875 CLAW_DBF_TEXT(4,trace,"PCINoBH");
877 #ifdef FUNCTRACE
878 printk(KERN_INFO "%s:%s Exit on line %d\n",
879 dev->name,__FUNCTION__,__LINE__);
880 #endif
881 CLAW_DBF_TEXT(4,trace,"PCI_read");
882 return;
884 if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
885 (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
886 (p_ch->irb->scsw.stctl ==
887 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
888 #ifdef FUNCTRACE
889 printk(KERN_INFO "%s:%s Exit on line %d\n",
890 dev->name,__FUNCTION__,__LINE__);
891 #endif
892 CLAW_DBF_TEXT(4,trace,"SPend_rd");
893 return;
895 clear_bit(0, (void *)&p_ch->IO_active);
896 claw_clearbit_busy(TB_RETRY,dev);
897 if (test_and_set_bit(CLAW_BH_ACTIVE,
898 (void *)&p_ch->flag_a) == 0) {
899 tasklet_schedule(&p_ch->tasklet);
901 else {
902 CLAW_DBF_TEXT(4,trace,"RdBHAct");
905 #ifdef DEBUGMSG
906 printk(KERN_INFO "%s: process CLAW_START_READ exit\n",
907 dev->name);
908 #endif
909 #ifdef FUNCTRACE
910 printk(KERN_INFO "%s:%s Exit on line %d\n",
911 dev->name,__FUNCTION__,__LINE__);
912 #endif
913 CLAW_DBF_TEXT(4,trace,"RdIRQXit");
914 return;
915 case CLAW_START_WRITE:
916 if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
917 printk(KERN_INFO "%s: Unit Check Occured in "
918 "write channel\n",dev->name);
919 clear_bit(0, (void *)&p_ch->IO_active);
920 if (p_ch->irb->ecw[0] & 0x80 ) {
921 printk(KERN_INFO "%s: Resetting Event "
922 "occurred:\n",dev->name);
923 init_timer(&p_ch->timer);
924 p_ch->timer.function =
925 (void *)claw_write_retry;
926 p_ch->timer.data = (unsigned long)p_ch;
927 p_ch->timer.expires = jiffies + 10*HZ;
928 add_timer(&p_ch->timer);
929 printk(KERN_INFO "%s: write connection "
930 "restarting\n",dev->name);
932 #ifdef FUNCTRACE
933 printk(KERN_INFO "%s:%s Exit on line %d\n",
934 dev->name,__FUNCTION__,__LINE__);
935 #endif
936 CLAW_DBF_TEXT(4,trace,"rstrtwrt");
937 return;
939 if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
940 clear_bit(0, (void *)&p_ch->IO_active);
941 printk(KERN_INFO "%s: Unit Exception "
942 "Occured in write channel\n",
943 dev->name);
945 if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
946 (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
947 (p_ch->irb->scsw.stctl ==
948 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
949 #ifdef FUNCTRACE
950 printk(KERN_INFO "%s:%s Exit on line %d\n",
951 dev->name,__FUNCTION__,__LINE__);
952 #endif
953 CLAW_DBF_TEXT(4,trace,"writeUE");
954 return;
956 clear_bit(0, (void *)&p_ch->IO_active);
957 if (claw_test_and_setbit_busy(TB_TX,dev)==0) {
958 claw_write_next(p_ch);
959 claw_clearbit_busy(TB_TX,dev);
960 claw_clear_busy(dev);
962 p_ch_r=(struct chbk *)&privptr->channel[READ];
963 if (test_and_set_bit(CLAW_BH_ACTIVE,
964 (void *)&p_ch_r->flag_a) == 0) {
965 tasklet_schedule(&p_ch_r->tasklet);
968 #ifdef DEBUGMSG
969 printk(KERN_INFO "%s: process CLAW_START_WRITE exit\n",
970 dev->name);
971 #endif
972 #ifdef FUNCTRACE
973 printk(KERN_INFO "%s:%s Exit on line %d\n",
974 dev->name,__FUNCTION__,__LINE__);
975 #endif
976 CLAW_DBF_TEXT(4,trace,"StWtExit");
977 return;
978 default:
979 printk(KERN_WARNING "%s: wrong selection code - irq "
980 "state=%d\n",dev->name,p_ch->claw_state);
981 #ifdef FUNCTRACE
982 printk(KERN_INFO "%s:%s Exit on line %d\n",
983 dev->name,__FUNCTION__,__LINE__);
984 #endif
985 CLAW_DBF_TEXT(2,trace,"badIRQ");
986 return;
989 } /* end of claw_irq_handler */
992 /*-------------------------------------------------------------------*
993 * claw_irq_tasklet *
995 *--------------------------------------------------------------------*/
996 static void
997 claw_irq_tasklet ( unsigned long data )
999 struct chbk * p_ch;
1000 struct net_device *dev;
1001 struct claw_privbk * privptr;
1003 p_ch = (struct chbk *) data;
1004 dev = (struct net_device *)p_ch->ndev;
1005 #ifdef FUNCTRACE
1006 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
1007 #endif
1008 #ifdef DEBUGMSG
1009 printk(KERN_INFO "%s: variable p_ch =\n",dev->name);
1010 dumpit((char *) p_ch, sizeof(struct chbk));
1011 #endif
1012 CLAW_DBF_TEXT(4,trace,"IRQtask");
1014 privptr = (struct claw_privbk *) dev->priv;
1016 #ifdef DEBUGMSG
1017 printk(KERN_INFO "%s: bh routine - state-%02x\n" ,
1018 dev->name, p_ch->claw_state);
1019 #endif
1021 unpack_read(dev);
1022 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
1023 CLAW_DBF_TEXT(4,trace,"TskletXt");
1024 #ifdef FUNCTRACE
1025 printk(KERN_INFO "%s:%s Exit on line %d\n",
1026 dev->name,__FUNCTION__,__LINE__);
1027 #endif
1028 return;
1029 } /* end of claw_irq_bh */
1031 /*-------------------------------------------------------------------*
1032 * claw_release *
1034 *--------------------------------------------------------------------*/
1035 static int
1036 claw_release(struct net_device *dev)
1038 int rc;
1039 int i;
1040 unsigned long saveflags;
1041 unsigned long parm;
1042 struct claw_privbk *privptr;
1043 DECLARE_WAITQUEUE(wait, current);
1044 struct ccwbk* p_this_ccw;
1045 struct ccwbk* p_buf;
1047 if (!dev)
1048 return 0;
1049 privptr = (struct claw_privbk *) dev->priv;
1050 if (!privptr)
1051 return 0;
1052 #ifdef FUNCTRACE
1053 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
1054 #endif
1055 CLAW_DBF_TEXT(4,trace,"release");
1056 #ifdef DEBUGMSG
1057 printk(KERN_INFO "%s: variable dev =\n",dev->name);
1058 dumpit((char *) dev, sizeof(struct net_device));
1059 printk(KERN_INFO "Priv Buffalloc %d\n",privptr->buffs_alloc);
1060 printk(KERN_INFO "Priv p_buff_ccw = %p\n",&privptr->p_buff_ccw);
1061 #endif
1062 privptr->release_pend=1;
1063 claw_setbit_busy(TB_STOP,dev);
1064 for ( i = 1; i >=0 ; i--) {
1065 spin_lock_irqsave(
1066 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
1067 /* del_timer(&privptr->channel[READ].timer); */
1068 privptr->channel[i].claw_state = CLAW_STOP;
1069 privptr->channel[i].IO_active = 0;
1070 parm = (unsigned long) &privptr->channel[i];
1071 if (i == WRITE)
1072 claw_purge_skb_queue(
1073 &privptr->channel[WRITE].collect_queue);
1074 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
1075 if (privptr->system_validate_comp==0x00) /* never opened? */
1076 init_waitqueue_head(&privptr->channel[i].wait);
1077 add_wait_queue(&privptr->channel[i].wait, &wait);
1078 set_current_state(TASK_INTERRUPTIBLE);
1079 spin_unlock_irqrestore(
1080 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
1081 schedule();
1082 set_current_state(TASK_RUNNING);
1083 remove_wait_queue(&privptr->channel[i].wait, &wait);
1084 if (rc != 0) {
1085 ccw_check_return_code(privptr->channel[i].cdev, rc);
1088 if (privptr->pk_skb != NULL) {
1089 dev_kfree_skb_any(privptr->pk_skb);
1090 privptr->pk_skb = NULL;
1092 if(privptr->buffs_alloc != 1) {
1093 #ifdef FUNCTRACE
1094 printk(KERN_INFO "%s:%s Exit on line %d\n",
1095 dev->name,__FUNCTION__,__LINE__);
1096 #endif
1097 CLAW_DBF_TEXT(4,trace,"none2fre");
1098 return 0;
1100 CLAW_DBF_TEXT(4,trace,"freebufs");
1101 if (privptr->p_buff_ccw != NULL) {
1102 free_pages((unsigned long)privptr->p_buff_ccw,
1103 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
1105 CLAW_DBF_TEXT(4,trace,"freeread");
1106 if (privptr->p_env->read_size < PAGE_SIZE) {
1107 if (privptr->p_buff_read != NULL) {
1108 free_pages((unsigned long)privptr->p_buff_read,
1109 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
1112 else {
1113 p_buf=privptr->p_read_active_first;
1114 while (p_buf!=NULL) {
1115 free_pages((unsigned long)p_buf->p_buffer,
1116 (int)pages_to_order_of_mag(
1117 privptr->p_buff_pages_perread ));
1118 p_buf=p_buf->next;
1121 CLAW_DBF_TEXT(4,trace,"freewrit");
1122 if (privptr->p_env->write_size < PAGE_SIZE ) {
1123 free_pages((unsigned long)privptr->p_buff_write,
1124 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
1126 else {
1127 p_buf=privptr->p_write_active_first;
1128 while (p_buf!=NULL) {
1129 free_pages((unsigned long)p_buf->p_buffer,
1130 (int)pages_to_order_of_mag(
1131 privptr->p_buff_pages_perwrite ));
1132 p_buf=p_buf->next;
1135 CLAW_DBF_TEXT(4,trace,"clearptr");
1136 privptr->buffs_alloc = 0;
1137 privptr->p_buff_ccw=NULL;
1138 privptr->p_buff_read=NULL;
1139 privptr->p_buff_write=NULL;
1140 privptr->system_validate_comp=0;
1141 privptr->release_pend=0;
1142 /* Remove any writes that were pending and reset all reads */
1143 p_this_ccw=privptr->p_read_active_first;
1144 while (p_this_ccw!=NULL) {
1145 p_this_ccw->header.length=0xffff;
1146 p_this_ccw->header.opcode=0xff;
1147 p_this_ccw->header.flag=0x00;
1148 p_this_ccw=p_this_ccw->next;
1151 while (privptr->p_write_active_first!=NULL) {
1152 p_this_ccw=privptr->p_write_active_first;
1153 p_this_ccw->header.flag=CLAW_PENDING;
1154 privptr->p_write_active_first=p_this_ccw->next;
1155 p_this_ccw->next=privptr->p_write_free_chain;
1156 privptr->p_write_free_chain=p_this_ccw;
1157 ++privptr->write_free_count;
1159 privptr->p_write_active_last=NULL;
1160 privptr->mtc_logical_link = -1;
1161 privptr->mtc_skipping = 1;
1162 privptr->mtc_offset=0;
1164 if (((privptr->channel[READ].last_dstat |
1165 privptr->channel[WRITE].last_dstat) &
1166 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
1167 printk(KERN_WARNING "%s: channel problems during close - "
1168 "read: %02x - write: %02x\n",
1169 dev->name,
1170 privptr->channel[READ].last_dstat,
1171 privptr->channel[WRITE].last_dstat);
1172 CLAW_DBF_TEXT(2,trace,"badclose");
1174 #ifdef FUNCTRACE
1175 printk(KERN_INFO "%s:%s Exit on line %d\n",
1176 dev->name,__FUNCTION__,__LINE__);
1177 #endif
1178 CLAW_DBF_TEXT(4,trace,"rlsexit");
1179 return 0;
1180 } /* end of claw_release */
1184 /*-------------------------------------------------------------------*
1185 * claw_write_retry *
1187 *--------------------------------------------------------------------*/
1189 static void
1190 claw_write_retry ( struct chbk *p_ch )
1193 struct net_device *dev=p_ch->ndev;
1196 #ifdef FUNCTRACE
1197 printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
1198 printk(KERN_INFO "claw: variable p_ch =\n");
1199 dumpit((char *) p_ch, sizeof(struct chbk));
1200 #endif
1201 CLAW_DBF_TEXT(4,trace,"w_retry");
1202 if (p_ch->claw_state == CLAW_STOP) {
1203 #ifdef FUNCTRACE
1204 printk(KERN_INFO "%s:%s Exit on line %d\n",
1205 dev->name,__FUNCTION__,__LINE__);
1206 #endif
1207 return;
1209 #ifdef DEBUGMSG
1210 printk( KERN_INFO "%s:%s state-%02x\n" ,
1211 dev->name,
1212 __FUNCTION__,
1213 p_ch->claw_state);
1214 #endif
1215 claw_strt_out_IO( dev );
1216 #ifdef FUNCTRACE
1217 printk(KERN_INFO "%s:%s Exit on line %d\n",
1218 dev->name,__FUNCTION__,__LINE__);
1219 #endif
1220 CLAW_DBF_TEXT(4,trace,"rtry_xit");
1221 return;
1222 } /* end of claw_write_retry */
1225 /*-------------------------------------------------------------------*
1226 * claw_write_next *
1228 *--------------------------------------------------------------------*/
1230 static void
1231 claw_write_next ( struct chbk * p_ch )
1234 struct net_device *dev;
1235 struct claw_privbk *privptr=NULL;
1236 struct sk_buff *pk_skb;
1237 int rc;
1239 #ifdef FUNCTRACE
1240 printk(KERN_INFO "%s:%s Enter \n",p_ch->ndev->name,__FUNCTION__);
1241 printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
1242 dumpit((char *) p_ch, sizeof(struct chbk));
1243 #endif
1244 CLAW_DBF_TEXT(4,trace,"claw_wrt");
1245 if (p_ch->claw_state == CLAW_STOP)
1246 return;
1247 dev = (struct net_device *) p_ch->ndev;
1248 privptr = (struct claw_privbk *) dev->priv;
1249 claw_free_wrt_buf( dev );
1250 if ((privptr->write_free_count > 0) &&
1251 !skb_queue_empty(&p_ch->collect_queue)) {
1252 pk_skb = claw_pack_skb(privptr);
1253 while (pk_skb != NULL) {
1254 rc = claw_hw_tx( pk_skb, dev,1);
1255 if (privptr->write_free_count > 0) {
1256 pk_skb = claw_pack_skb(privptr);
1257 } else
1258 pk_skb = NULL;
1261 if (privptr->p_write_active_first!=NULL) {
1262 claw_strt_out_IO(dev);
1265 #ifdef FUNCTRACE
1266 printk(KERN_INFO "%s:%s Exit on line %d\n",
1267 dev->name,__FUNCTION__,__LINE__);
1268 #endif
1269 return;
1270 } /* end of claw_write_next */
1272 /*-------------------------------------------------------------------*
1274 * claw_timer *
1275 *--------------------------------------------------------------------*/
1277 static void
1278 claw_timer ( struct chbk * p_ch )
1280 #ifdef FUNCTRACE
1281 printk(KERN_INFO "%s:%s Entry\n",p_ch->ndev->name,__FUNCTION__);
1282 printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
1283 dumpit((char *) p_ch, sizeof(struct chbk));
1284 #endif
1285 CLAW_DBF_TEXT(4,trace,"timer");
1286 p_ch->flag |= CLAW_TIMER;
1287 wake_up(&p_ch->wait);
1288 #ifdef FUNCTRACE
1289 printk(KERN_INFO "%s:%s Exit on line %d\n",
1290 p_ch->ndev->name,__FUNCTION__,__LINE__);
1291 #endif
1292 return;
1293 } /* end of claw_timer */
1298 * functions
1302 /*-------------------------------------------------------------------*
1304 * pages_to_order_of_mag *
1306 * takes a number of pages from 1 to 512 and returns the *
1307 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1308 * of magnitude get_free_pages() has an upper order of 9 *
1309 *--------------------------------------------------------------------*/
1311 static int
1312 pages_to_order_of_mag(int num_of_pages)
1314 int order_of_mag=1; /* assume 2 pages */
1315 int nump=2;
1316 #ifdef FUNCTRACE
1317 printk(KERN_INFO "%s Enter pages = %d \n",__FUNCTION__,num_of_pages);
1318 #endif
1319 CLAW_DBF_TEXT_(5,trace,"pages%d",num_of_pages);
1320 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1321 /* 512 pages = 2Meg on 4k page systems */
1322 if (num_of_pages >= 512) {return 9; }
1323 /* we have two or more pages order is at least 1 */
1324 for (nump=2 ;nump <= 512;nump*=2) {
1325 if (num_of_pages <= nump)
1326 break;
1327 order_of_mag +=1;
1329 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
1330 #ifdef FUNCTRACE
1331 printk(KERN_INFO "%s Exit on line %d, order = %d\n",
1332 __FUNCTION__,__LINE__, order_of_mag);
1333 #endif
1334 CLAW_DBF_TEXT_(5,trace,"mag%d",order_of_mag);
1335 return order_of_mag;
1338 /*-------------------------------------------------------------------*
1340 * add_claw_reads *
1342 *--------------------------------------------------------------------*/
1343 static int
1344 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1345 struct ccwbk* p_last)
1347 struct claw_privbk *privptr;
1348 struct ccw1 temp_ccw;
1349 struct endccw * p_end;
1350 #ifdef IOTRACE
1351 struct ccwbk* p_buf;
1352 #endif
1353 #ifdef FUNCTRACE
1354 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
1355 #endif
1356 #ifdef DEBUGMSG
1357 printk(KERN_INFO "dev\n");
1358 dumpit((char *) dev, sizeof(struct net_device));
1359 printk(KERN_INFO "p_first\n");
1360 dumpit((char *) p_first, sizeof(struct ccwbk));
1361 printk(KERN_INFO "p_last\n");
1362 dumpit((char *) p_last, sizeof(struct ccwbk));
1363 #endif
1364 CLAW_DBF_TEXT(4,trace,"addreads");
1365 privptr = dev->priv;
1366 p_end = privptr->p_end_ccw;
1368 /* first CCW and last CCW contains a new set of read channel programs
1369 * to apend the running channel programs
1371 if ( p_first==NULL) {
1372 #ifdef FUNCTRACE
1373 printk(KERN_INFO "%s:%s Exit on line %d\n",
1374 dev->name,__FUNCTION__,__LINE__);
1375 #endif
1376 CLAW_DBF_TEXT(4,trace,"addexit");
1377 return 0;
1380 /* set up ending CCW sequence for this segment */
1381 if (p_end->read1) {
1382 p_end->read1=0x00; /* second ending CCW is now active */
1383 /* reset ending CCWs and setup TIC CCWs */
1384 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1385 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1386 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1387 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1388 p_end->read2_nop2.cda=0;
1389 p_end->read2_nop2.count=1;
1391 else {
1392 p_end->read1=0x01; /* first ending CCW is now active */
1393 /* reset ending CCWs and setup TIC CCWs */
1394 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1395 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1396 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1397 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1398 p_end->read1_nop2.cda=0;
1399 p_end->read1_nop2.count=1;
1402 if ( privptr-> p_read_active_first ==NULL ) {
1403 #ifdef DEBUGMSG
1404 printk(KERN_INFO "%s:%s p_read_active_first == NULL \n",
1405 dev->name,__FUNCTION__);
1406 printk(KERN_INFO "%s:%s Read active first/last changed \n",
1407 dev->name,__FUNCTION__);
1408 #endif
1409 privptr-> p_read_active_first= p_first; /* set new first */
1410 privptr-> p_read_active_last = p_last; /* set new last */
1412 else {
1414 #ifdef DEBUGMSG
1415 printk(KERN_INFO "%s:%s Read in progress \n",
1416 dev->name,__FUNCTION__);
1417 #endif
1418 /* set up TIC ccw */
1419 temp_ccw.cda= (__u32)__pa(&p_first->read);
1420 temp_ccw.count=0;
1421 temp_ccw.flags=0;
1422 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1425 if (p_end->read1) {
1427 /* first set of CCW's is chained to the new read */
1428 /* chain, so the second set is chained to the active chain. */
1429 /* Therefore modify the second set to point to the new */
1430 /* read chain set up TIC CCWs */
1431 /* make sure we update the CCW so channel doesn't fetch it */
1432 /* when it's only half done */
1433 memcpy( &p_end->read2_nop2, &temp_ccw ,
1434 sizeof(struct ccw1));
1435 privptr->p_read_active_last->r_TIC_1.cda=
1436 (__u32)__pa(&p_first->read);
1437 privptr->p_read_active_last->r_TIC_2.cda=
1438 (__u32)__pa(&p_first->read);
1440 else {
1441 /* make sure we update the CCW so channel doesn't */
1442 /* fetch it when it is only half done */
1443 memcpy( &p_end->read1_nop2, &temp_ccw ,
1444 sizeof(struct ccw1));
1445 privptr->p_read_active_last->r_TIC_1.cda=
1446 (__u32)__pa(&p_first->read);
1447 privptr->p_read_active_last->r_TIC_2.cda=
1448 (__u32)__pa(&p_first->read);
1450 /* chain in new set of blocks */
1451 privptr->p_read_active_last->next = p_first;
1452 privptr->p_read_active_last=p_last;
1453 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1454 #ifdef IOTRACE
1455 printk(KERN_INFO "%s:%s dump p_last CCW BK \n",dev->name,__FUNCTION__);
1456 dumpit((char *)p_last, sizeof(struct ccwbk));
1457 printk(KERN_INFO "%s:%s dump p_end CCW BK \n",dev->name,__FUNCTION__);
1458 dumpit((char *)p_end, sizeof(struct endccw));
1460 printk(KERN_INFO "%s:%s dump p_first CCW BK \n",dev->name,__FUNCTION__);
1461 dumpit((char *)p_first, sizeof(struct ccwbk));
1462 printk(KERN_INFO "%s:%s Dump Active CCW chain \n",
1463 dev->name,__FUNCTION__);
1464 p_buf=privptr->p_read_active_first;
1465 while (p_buf!=NULL) {
1466 dumpit((char *)p_buf, sizeof(struct ccwbk));
1467 p_buf=p_buf->next;
1469 #endif
1470 #ifdef FUNCTRACE
1471 printk(KERN_INFO "%s:%s Exit on line %d\n",
1472 dev->name,__FUNCTION__,__LINE__);
1473 #endif
1474 CLAW_DBF_TEXT(4,trace,"addexit");
1475 return 0;
1476 } /* end of add_claw_reads */
1478 /*-------------------------------------------------------------------*
1479 * ccw_check_return_code *
1481 *-------------------------------------------------------------------*/
1483 static void
1484 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1486 #ifdef FUNCTRACE
1487 printk(KERN_INFO "%s: %s() > enter \n",
1488 cdev->dev.bus_id,__FUNCTION__);
1489 #endif
1490 CLAW_DBF_TEXT(4,trace,"ccwret");
1491 #ifdef DEBUGMSG
1492 printk(KERN_INFO "variable cdev =\n");
1493 dumpit((char *) cdev, sizeof(struct ccw_device));
1494 printk(KERN_INFO "variable return_code = %d\n",return_code);
1495 #endif
1496 if (return_code != 0) {
1497 switch (return_code) {
1498 case -EBUSY:
1499 printk(KERN_INFO "%s: Busy !\n",
1500 cdev->dev.bus_id);
1501 break;
1502 case -ENODEV:
1503 printk(KERN_EMERG "%s: Missing device called "
1504 "for IO ENODEV\n", cdev->dev.bus_id);
1505 break;
1506 case -EIO:
1507 printk(KERN_EMERG "%s: Status pending... EIO \n",
1508 cdev->dev.bus_id);
1509 break;
1510 case -EINVAL:
1511 printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
1512 cdev->dev.bus_id);
1513 break;
1514 default:
1515 printk(KERN_EMERG "%s: Unknown error in "
1516 "Do_IO %d\n",cdev->dev.bus_id, return_code);
1519 #ifdef FUNCTRACE
1520 printk(KERN_INFO "%s: %s() > exit on line %d\n",
1521 cdev->dev.bus_id,__FUNCTION__,__LINE__);
1522 #endif
1523 CLAW_DBF_TEXT(4,trace,"ccwret");
1524 } /* end of ccw_check_return_code */
1526 /*-------------------------------------------------------------------*
1527 * ccw_check_unit_check *
1528 *--------------------------------------------------------------------*/
1530 static void
1531 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1533 struct net_device *dev = p_ch->ndev;
1535 #ifdef FUNCTRACE
1536 printk(KERN_INFO "%s: %s() > enter\n",dev->name,__FUNCTION__);
1537 #endif
1538 #ifdef DEBUGMSG
1539 printk(KERN_INFO "%s: variable dev =\n",dev->name);
1540 dumpit((char *)dev, sizeof(struct net_device));
1541 printk(KERN_INFO "%s: variable sense =\n",dev->name);
1542 dumpit((char *)&sense, 2);
1543 #endif
1544 CLAW_DBF_TEXT(4,trace,"unitchek");
1546 printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
1547 dev->name, sense);
1549 if (sense & 0x40) {
1550 if (sense & 0x01) {
1551 printk(KERN_WARNING "%s: Interface disconnect or "
1552 "Selective reset "
1553 "occurred (remote side)\n", dev->name);
1555 else {
1556 printk(KERN_WARNING "%s: System reset occured"
1557 " (remote side)\n", dev->name);
1560 else if (sense & 0x20) {
1561 if (sense & 0x04) {
1562 printk(KERN_WARNING "%s: Data-streaming "
1563 "timeout)\n", dev->name);
1565 else {
1566 printk(KERN_WARNING "%s: Data-transfer parity"
1567 " error\n", dev->name);
1570 else if (sense & 0x10) {
1571 if (sense & 0x20) {
1572 printk(KERN_WARNING "%s: Hardware malfunction "
1573 "(remote side)\n", dev->name);
1575 else {
1576 printk(KERN_WARNING "%s: read-data parity error "
1577 "(remote side)\n", dev->name);
1581 #ifdef FUNCTRACE
1582 printk(KERN_INFO "%s: %s() exit on line %d\n",
1583 dev->name,__FUNCTION__,__LINE__);
1584 #endif
1585 } /* end of ccw_check_unit_check */
1589 /*-------------------------------------------------------------------*
1590 * Dump buffer format *
1592 *--------------------------------------------------------------------*/
1593 #ifdef DEBUG
1594 static void
1595 dumpit(char* buf, int len)
1598 __u32 ct, sw, rm, dup;
1599 char *ptr, *rptr;
1600 char tbuf[82], tdup[82];
1601 #if (CONFIG_64BIT)
1602 char addr[22];
1603 #else
1604 char addr[12];
1605 #endif
1606 char boff[12];
1607 char bhex[82], duphex[82];
1608 char basc[40];
1610 sw = 0;
1611 rptr =ptr=buf;
1612 rm = 16;
1613 duphex[0] = 0x00;
1614 dup = 0;
1615 for ( ct=0; ct < len; ct++, ptr++, rptr++ ) {
1616 if (sw == 0) {
1617 #if (CONFIG_64BIT)
1618 sprintf(addr, "%16.16lX",(unsigned long)rptr);
1619 #else
1620 sprintf(addr, "%8.8X",(__u32)rptr);
1621 #endif
1622 sprintf(boff, "%4.4X", (__u32)ct);
1623 bhex[0] = '\0';
1624 basc[0] = '\0';
1626 if ((sw == 4) || (sw == 12)) {
1627 strcat(bhex, " ");
1629 if (sw == 8) {
1630 strcat(bhex, " ");
1632 #if (CONFIG_64BIT)
1633 sprintf(tbuf,"%2.2lX", (unsigned long)*ptr);
1634 #else
1635 sprintf(tbuf,"%2.2X", (__u32)*ptr);
1636 #endif
1637 tbuf[2] = '\0';
1638 strcat(bhex, tbuf);
1639 if ((0!=isprint(*ptr)) && (*ptr >= 0x20)) {
1640 basc[sw] = *ptr;
1642 else {
1643 basc[sw] = '.';
1645 basc[sw+1] = '\0';
1646 sw++;
1647 rm--;
1648 if (sw==16) {
1649 if ((strcmp(duphex, bhex)) !=0) {
1650 if (dup !=0) {
1651 sprintf(tdup,"Duplicate as above to"
1652 " %s", addr);
1653 printk( KERN_INFO " "
1654 " --- %s ---\n",tdup);
1656 printk( KERN_INFO " %s (+%s) : %s [%s]\n",
1657 addr, boff, bhex, basc);
1658 dup = 0;
1659 strcpy(duphex, bhex);
1661 else {
1662 dup++;
1664 sw = 0;
1665 rm = 16;
1667 } /* endfor */
1669 if (sw != 0) {
1670 for ( ; rm > 0; rm--, sw++ ) {
1671 if ((sw==4) || (sw==12)) strcat(bhex, " ");
1672 if (sw==8) strcat(bhex, " ");
1673 strcat(bhex, " ");
1674 strcat(basc, " ");
1676 if (dup !=0) {
1677 sprintf(tdup,"Duplicate as above to %s", addr);
1678 printk( KERN_INFO " --- %s ---\n",
1679 tdup);
1681 printk( KERN_INFO " %s (+%s) : %s [%s]\n",
1682 addr, boff, bhex, basc);
1684 else {
1685 if (dup >=1) {
1686 sprintf(tdup,"Duplicate as above to %s", addr);
1687 printk( KERN_INFO " --- %s ---\n",
1688 tdup);
1690 if (dup !=0) {
1691 printk( KERN_INFO " %s (+%s) : %s [%s]\n",
1692 addr, boff, bhex, basc);
1695 return;
1697 } /* end of dumpit */
1698 #endif
1700 /*-------------------------------------------------------------------*
1701 * find_link *
1702 *--------------------------------------------------------------------*/
1703 static int
1704 find_link(struct net_device *dev, char *host_name, char *ws_name )
1706 struct claw_privbk *privptr;
1707 struct claw_env *p_env;
1708 int rc=0;
1710 #ifdef FUNCTRACE
1711 printk(KERN_INFO "%s:%s > enter \n",dev->name,__FUNCTION__);
1712 #endif
1713 CLAW_DBF_TEXT(2,setup,"findlink");
1714 #ifdef DEBUGMSG
1715 printk(KERN_INFO "%s: variable dev = \n",dev->name);
1716 dumpit((char *) dev, sizeof(struct net_device));
1717 printk(KERN_INFO "%s: variable host_name = %s\n",dev->name, host_name);
1718 printk(KERN_INFO "%s: variable ws_name = %s\n",dev->name, ws_name);
1719 #endif
1720 privptr=dev->priv;
1721 p_env=privptr->p_env;
1722 switch (p_env->packing)
1724 case PACKING_ASK:
1725 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1726 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1727 rc = EINVAL;
1728 break;
1729 case DO_PACKED:
1730 case PACK_SEND:
1731 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1732 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1733 rc = EINVAL;
1734 break;
1735 default:
1736 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1737 (memcmp(p_env->api_type , ws_name, 8)!=0))
1738 rc = EINVAL;
1739 break;
1742 #ifdef FUNCTRACE
1743 printk(KERN_INFO "%s:%s Exit on line %d\n",
1744 dev->name,__FUNCTION__,__LINE__);
1745 #endif
1746 return 0;
1747 } /* end of find_link */
1749 /*-------------------------------------------------------------------*
1750 * claw_hw_tx *
1753 *-------------------------------------------------------------------*/
1755 static int
1756 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1758 int rc=0;
1759 struct claw_privbk *privptr;
1760 struct ccwbk *p_this_ccw;
1761 struct ccwbk *p_first_ccw;
1762 struct ccwbk *p_last_ccw;
1763 __u32 numBuffers;
1764 signed long len_of_data;
1765 unsigned long bytesInThisBuffer;
1766 unsigned char *pDataAddress;
1767 struct endccw *pEnd;
1768 struct ccw1 tempCCW;
1769 struct chbk *p_ch;
1770 struct claw_env *p_env;
1771 int lock;
1772 struct clawph *pk_head;
1773 struct chbk *ch;
1774 #ifdef IOTRACE
1775 struct ccwbk *p_buf;
1776 #endif
1777 #ifdef FUNCTRACE
1778 printk(KERN_INFO "%s: %s() > enter\n",dev->name,__FUNCTION__);
1779 #endif
1780 CLAW_DBF_TEXT(4,trace,"hw_tx");
1781 #ifdef DEBUGMSG
1782 printk(KERN_INFO "%s: variable dev skb =\n",dev->name);
1783 dumpit((char *) skb, sizeof(struct sk_buff));
1784 printk(KERN_INFO "%s: variable dev =\n",dev->name);
1785 dumpit((char *) dev, sizeof(struct net_device));
1786 printk(KERN_INFO "%s: variable linkid = %ld\n",dev->name,linkid);
1787 #endif
1788 privptr = (struct claw_privbk *) (dev->priv);
1789 p_ch=(struct chbk *)&privptr->channel[WRITE];
1790 p_env =privptr->p_env;
1791 #ifdef IOTRACE
1792 printk(KERN_INFO "%s: %s() dump sk_buff \n",dev->name,__FUNCTION__);
1793 dumpit((char *)skb ,sizeof(struct sk_buff));
1794 #endif
1795 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1796 /* scan the write queue to free any completed write packets */
1797 p_first_ccw=NULL;
1798 p_last_ccw=NULL;
1799 if ((p_env->packing >= PACK_SEND) &&
1800 (skb->cb[1] != 'P')) {
1801 skb_push(skb,sizeof(struct clawph));
1802 pk_head=(struct clawph *)skb->data;
1803 pk_head->len=skb->len-sizeof(struct clawph);
1804 if (pk_head->len%4) {
1805 pk_head->len+= 4-(pk_head->len%4);
1806 skb_pad(skb,4-(pk_head->len%4));
1807 skb_put(skb,4-(pk_head->len%4));
1809 if (p_env->packing == DO_PACKED)
1810 pk_head->link_num = linkid;
1811 else
1812 pk_head->link_num = 0;
1813 pk_head->flag = 0x00;
1814 skb_pad(skb,4);
1815 skb->cb[1] = 'P';
1817 if (linkid == 0) {
1818 if (claw_check_busy(dev)) {
1819 if (privptr->write_free_count!=0) {
1820 claw_clear_busy(dev);
1822 else {
1823 claw_strt_out_IO(dev );
1824 claw_free_wrt_buf( dev );
1825 if (privptr->write_free_count==0) {
1826 #ifdef IOTRACE
1827 printk(KERN_INFO "%s: "
1828 "(claw_check_busy) no free write "
1829 "buffers\n", dev->name);
1830 #endif
1831 ch = &privptr->channel[WRITE];
1832 atomic_inc(&skb->users);
1833 skb_queue_tail(&ch->collect_queue, skb);
1834 goto Done;
1836 else {
1837 claw_clear_busy(dev);
1841 /* tx lock */
1842 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1843 #ifdef DEBUGMSG
1844 printk(KERN_INFO "%s: busy (claw_test_and_setbit_"
1845 "busy)\n", dev->name);
1846 #endif
1847 ch = &privptr->channel[WRITE];
1848 atomic_inc(&skb->users);
1849 skb_queue_tail(&ch->collect_queue, skb);
1850 claw_strt_out_IO(dev );
1851 rc=-EBUSY;
1852 goto Done2;
1855 /* See how many write buffers are required to hold this data */
1856 numBuffers= ( skb->len + privptr->p_env->write_size - 1) /
1857 ( privptr->p_env->write_size);
1859 /* If that number of buffers isn't available, give up for now */
1860 if (privptr->write_free_count < numBuffers ||
1861 privptr->p_write_free_chain == NULL ) {
1863 claw_setbit_busy(TB_NOBUFFER,dev);
1865 #ifdef DEBUGMSG
1866 printk(KERN_INFO "%s: busy (claw_setbit_busy"
1867 "(TB_NOBUFFER))\n", dev->name);
1868 printk(KERN_INFO " free_count: %d, numBuffers : %d\n",
1869 (int)privptr->write_free_count,(int) numBuffers );
1870 #endif
1871 ch = &privptr->channel[WRITE];
1872 atomic_inc(&skb->users);
1873 skb_queue_tail(&ch->collect_queue, skb);
1874 CLAW_DBF_TEXT(2,trace,"clawbusy");
1875 goto Done2;
1877 pDataAddress=skb->data;
1878 len_of_data=skb->len;
1880 while (len_of_data > 0) {
1881 #ifdef DEBUGMSG
1882 printk(KERN_INFO "%s: %s() length-of-data is %ld \n",
1883 dev->name ,__FUNCTION__,len_of_data);
1884 dumpit((char *)pDataAddress ,64);
1885 #endif
1886 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1887 if (p_this_ccw == NULL) { /* lost the race */
1888 ch = &privptr->channel[WRITE];
1889 atomic_inc(&skb->users);
1890 skb_queue_tail(&ch->collect_queue, skb);
1891 goto Done2;
1893 privptr->p_write_free_chain=p_this_ccw->next;
1894 p_this_ccw->next=NULL;
1895 --privptr->write_free_count; /* -1 */
1896 bytesInThisBuffer=len_of_data;
1897 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1898 len_of_data-=bytesInThisBuffer;
1899 pDataAddress+=(unsigned long)bytesInThisBuffer;
1900 /* setup write CCW */
1901 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1902 if (len_of_data>0) {
1903 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1905 p_this_ccw->write.count=bytesInThisBuffer;
1906 /* now add to end of this chain */
1907 if (p_first_ccw==NULL) {
1908 p_first_ccw=p_this_ccw;
1910 if (p_last_ccw!=NULL) {
1911 p_last_ccw->next=p_this_ccw;
1912 /* set up TIC ccws */
1913 p_last_ccw->w_TIC_1.cda=
1914 (__u32)__pa(&p_this_ccw->write);
1916 p_last_ccw=p_this_ccw; /* save new last block */
1917 #ifdef IOTRACE
1918 printk(KERN_INFO "%s: %s() > CCW and Buffer %ld bytes long \n",
1919 dev->name,__FUNCTION__,bytesInThisBuffer);
1920 dumpit((char *)p_this_ccw, sizeof(struct ccwbk));
1921 dumpit((char *)p_this_ccw->p_buffer, 64);
1922 #endif
1925 /* FirstCCW and LastCCW now contain a new set of write channel
1926 * programs to append to the running channel program
1929 if (p_first_ccw!=NULL) {
1930 /* setup ending ccw sequence for this segment */
1931 pEnd=privptr->p_end_ccw;
1932 if (pEnd->write1) {
1933 pEnd->write1=0x00; /* second end ccw is now active */
1934 /* set up Tic CCWs */
1935 p_last_ccw->w_TIC_1.cda=
1936 (__u32)__pa(&pEnd->write2_nop1);
1937 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1938 pEnd->write2_nop2.flags =
1939 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1940 pEnd->write2_nop2.cda=0;
1941 pEnd->write2_nop2.count=1;
1943 else { /* end of if (pEnd->write1)*/
1944 pEnd->write1=0x01; /* first end ccw is now active */
1945 /* set up Tic CCWs */
1946 p_last_ccw->w_TIC_1.cda=
1947 (__u32)__pa(&pEnd->write1_nop1);
1948 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1949 pEnd->write1_nop2.flags =
1950 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1951 pEnd->write1_nop2.cda=0;
1952 pEnd->write1_nop2.count=1;
1953 } /* end if if (pEnd->write1) */
1956 if (privptr->p_write_active_first==NULL ) {
1957 privptr->p_write_active_first=p_first_ccw;
1958 privptr->p_write_active_last=p_last_ccw;
1960 else {
1962 /* set up Tic CCWs */
1964 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1965 tempCCW.count=0;
1966 tempCCW.flags=0;
1967 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1969 if (pEnd->write1) {
1972 * first set of ending CCW's is chained to the new write
1973 * chain, so the second set is chained to the active chain
1974 * Therefore modify the second set to point the new write chain.
1975 * make sure we update the CCW atomically
1976 * so channel does not fetch it when it's only half done
1978 memcpy( &pEnd->write2_nop2, &tempCCW ,
1979 sizeof(struct ccw1));
1980 privptr->p_write_active_last->w_TIC_1.cda=
1981 (__u32)__pa(&p_first_ccw->write);
1983 else {
1985 /*make sure we update the CCW atomically
1986 *so channel does not fetch it when it's only half done
1988 memcpy(&pEnd->write1_nop2, &tempCCW ,
1989 sizeof(struct ccw1));
1990 privptr->p_write_active_last->w_TIC_1.cda=
1991 (__u32)__pa(&p_first_ccw->write);
1993 } /* end if if (pEnd->write1) */
1995 privptr->p_write_active_last->next=p_first_ccw;
1996 privptr->p_write_active_last=p_last_ccw;
1999 } /* endif (p_first_ccw!=NULL) */
2002 #ifdef IOTRACE
2003 printk(KERN_INFO "%s: %s() > Dump Active CCW chain \n",
2004 dev->name,__FUNCTION__);
2005 p_buf=privptr->p_write_active_first;
2006 while (p_buf!=NULL) {
2007 dumpit((char *)p_buf, sizeof(struct ccwbk));
2008 p_buf=p_buf->next;
2010 p_buf=(struct ccwbk*)privptr->p_end_ccw;
2011 dumpit((char *)p_buf, sizeof(struct endccw));
2012 #endif
2013 dev_kfree_skb_any(skb);
2014 if (linkid==0) {
2015 lock=LOCK_NO;
2017 else {
2018 lock=LOCK_YES;
2020 claw_strt_out_IO(dev );
2021 /* if write free count is zero , set NOBUFFER */
2022 #ifdef DEBUGMSG
2023 printk(KERN_INFO "%s: %s() > free_count is %d\n",
2024 dev->name,__FUNCTION__,
2025 (int) privptr->write_free_count );
2026 #endif
2027 if (privptr->write_free_count==0) {
2028 claw_setbit_busy(TB_NOBUFFER,dev);
2030 Done2:
2031 claw_clearbit_busy(TB_TX,dev);
2032 Done:
2033 #ifdef FUNCTRACE
2034 printk(KERN_INFO "%s: %s() > exit on line %d, rc = %d \n",
2035 dev->name,__FUNCTION__,__LINE__, rc);
2036 #endif
2037 return(rc);
2038 } /* end of claw_hw_tx */
2040 /*-------------------------------------------------------------------*
2042 * init_ccw_bk *
2044 *--------------------------------------------------------------------*/
2046 static int
2047 init_ccw_bk(struct net_device *dev)
2050 __u32 ccw_blocks_required;
2051 __u32 ccw_blocks_perpage;
2052 __u32 ccw_pages_required;
2053 __u32 claw_reads_perpage=1;
2054 __u32 claw_read_pages;
2055 __u32 claw_writes_perpage=1;
2056 __u32 claw_write_pages;
2057 void *p_buff=NULL;
2058 struct ccwbk*p_free_chain;
2059 struct ccwbk*p_buf;
2060 struct ccwbk*p_last_CCWB;
2061 struct ccwbk*p_first_CCWB;
2062 struct endccw *p_endccw=NULL;
2063 addr_t real_address;
2064 struct claw_privbk *privptr=dev->priv;
2065 struct clawh *pClawH=NULL;
2066 addr_t real_TIC_address;
2067 int i,j;
2068 #ifdef FUNCTRACE
2069 printk(KERN_INFO "%s: %s() enter \n",dev->name,__FUNCTION__);
2070 #endif
2071 CLAW_DBF_TEXT(4,trace,"init_ccw");
2072 #ifdef DEBUGMSG
2073 printk(KERN_INFO "%s: variable dev =\n",dev->name);
2074 dumpit((char *) dev, sizeof(struct net_device));
2075 #endif
2077 /* initialize statistics field */
2078 privptr->active_link_ID=0;
2079 /* initialize ccwbk pointers */
2080 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
2081 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
2082 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
2083 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
2084 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
2085 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
2086 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
2087 privptr->buffs_alloc = 0;
2088 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
2089 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
2090 /* initialize free write ccwbk counter */
2091 privptr->write_free_count=0; /* number of free bufs on write chain */
2092 p_last_CCWB = NULL;
2093 p_first_CCWB= NULL;
2095 * We need 1 CCW block for each read buffer, 1 for each
2096 * write buffer, plus 1 for ClawSignalBlock
2098 ccw_blocks_required =
2099 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
2100 #ifdef DEBUGMSG
2101 printk(KERN_INFO "%s: %s() "
2102 "ccw_blocks_required=%d\n",
2103 dev->name,__FUNCTION__,
2104 ccw_blocks_required);
2105 printk(KERN_INFO "%s: %s() "
2106 "PAGE_SIZE=0x%x\n",
2107 dev->name,__FUNCTION__,
2108 (unsigned int)PAGE_SIZE);
2109 printk(KERN_INFO "%s: %s() > "
2110 "PAGE_MASK=0x%x\n",
2111 dev->name,__FUNCTION__,
2112 (unsigned int)PAGE_MASK);
2113 #endif
2115 * compute number of CCW blocks that will fit in a page
2117 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
2118 ccw_pages_required=
2119 (ccw_blocks_required+ccw_blocks_perpage -1) /
2120 ccw_blocks_perpage;
2122 #ifdef DEBUGMSG
2123 printk(KERN_INFO "%s: %s() > ccw_blocks_perpage=%d\n",
2124 dev->name,__FUNCTION__,
2125 ccw_blocks_perpage);
2126 printk(KERN_INFO "%s: %s() > ccw_pages_required=%d\n",
2127 dev->name,__FUNCTION__,
2128 ccw_pages_required);
2129 #endif
2131 * read and write sizes are set by 2 constants in claw.h
2132 * 4k and 32k. Unpacked values other than 4k are not going to
2133 * provide good performance. With packing buffers support 32k
2134 * buffers are used.
2136 if (privptr->p_env->read_size < PAGE_SIZE) {
2137 claw_reads_perpage= PAGE_SIZE / privptr->p_env->read_size;
2138 claw_read_pages= (privptr->p_env->read_buffers +
2139 claw_reads_perpage -1) / claw_reads_perpage;
2141 else { /* > or equal */
2142 privptr->p_buff_pages_perread=
2143 (privptr->p_env->read_size + PAGE_SIZE - 1) / PAGE_SIZE;
2144 claw_read_pages=
2145 privptr->p_env->read_buffers * privptr->p_buff_pages_perread;
2147 if (privptr->p_env->write_size < PAGE_SIZE) {
2148 claw_writes_perpage=
2149 PAGE_SIZE / privptr->p_env->write_size;
2150 claw_write_pages=
2151 (privptr->p_env->write_buffers + claw_writes_perpage -1) /
2152 claw_writes_perpage;
2155 else { /* > or equal */
2156 privptr->p_buff_pages_perwrite=
2157 (privptr->p_env->read_size + PAGE_SIZE - 1) / PAGE_SIZE;
2158 claw_write_pages=
2159 privptr->p_env->write_buffers * privptr->p_buff_pages_perwrite;
2161 #ifdef DEBUGMSG
2162 if (privptr->p_env->read_size < PAGE_SIZE) {
2163 printk(KERN_INFO "%s: %s() reads_perpage=%d\n",
2164 dev->name,__FUNCTION__,
2165 claw_reads_perpage);
2167 else {
2168 printk(KERN_INFO "%s: %s() pages_perread=%d\n",
2169 dev->name,__FUNCTION__,
2170 privptr->p_buff_pages_perread);
2172 printk(KERN_INFO "%s: %s() read_pages=%d\n",
2173 dev->name,__FUNCTION__,
2174 claw_read_pages);
2175 if (privptr->p_env->write_size < PAGE_SIZE) {
2176 printk(KERN_INFO "%s: %s() writes_perpage=%d\n",
2177 dev->name,__FUNCTION__,
2178 claw_writes_perpage);
2180 else {
2181 printk(KERN_INFO "%s: %s() pages_perwrite=%d\n",
2182 dev->name,__FUNCTION__,
2183 privptr->p_buff_pages_perwrite);
2185 printk(KERN_INFO "%s: %s() write_pages=%d\n",
2186 dev->name,__FUNCTION__,
2187 claw_write_pages);
2188 #endif
2192 * allocate ccw_pages_required
2194 if (privptr->p_buff_ccw==NULL) {
2195 privptr->p_buff_ccw=
2196 (void *)__get_free_pages(__GFP_DMA,
2197 (int)pages_to_order_of_mag(ccw_pages_required ));
2198 if (privptr->p_buff_ccw==NULL) {
2199 printk(KERN_INFO "%s: %s() "
2200 "__get_free_pages for CCWs failed : "
2201 "pages is %d\n",
2202 dev->name,__FUNCTION__,
2203 ccw_pages_required );
2204 #ifdef FUNCTRACE
2205 printk(KERN_INFO "%s: %s() > "
2206 "exit on line %d, rc = ENOMEM\n",
2207 dev->name,__FUNCTION__,
2208 __LINE__);
2209 #endif
2210 return -ENOMEM;
2212 privptr->p_buff_ccw_num=ccw_pages_required;
2214 memset(privptr->p_buff_ccw, 0x00,
2215 privptr->p_buff_ccw_num * PAGE_SIZE);
2218 * obtain ending ccw block address
2221 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
2222 real_address = (__u32)__pa(privptr->p_end_ccw);
2223 /* Initialize ending CCW block */
2224 #ifdef DEBUGMSG
2225 printk(KERN_INFO "%s: %s() begin initialize ending CCW blocks\n",
2226 dev->name,__FUNCTION__);
2227 #endif
2229 p_endccw=privptr->p_end_ccw;
2230 p_endccw->real=real_address;
2231 p_endccw->write1=0x00;
2232 p_endccw->read1=0x00;
2234 /* write1_nop1 */
2235 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2236 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2237 p_endccw->write1_nop1.count = 1;
2238 p_endccw->write1_nop1.cda = 0;
2240 /* write1_nop2 */
2241 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2242 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2243 p_endccw->write1_nop2.count = 1;
2244 p_endccw->write1_nop2.cda = 0;
2246 /* write2_nop1 */
2247 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2248 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2249 p_endccw->write2_nop1.count = 1;
2250 p_endccw->write2_nop1.cda = 0;
2252 /* write2_nop2 */
2253 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2254 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2255 p_endccw->write2_nop2.count = 1;
2256 p_endccw->write2_nop2.cda = 0;
2258 /* read1_nop1 */
2259 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2260 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2261 p_endccw->read1_nop1.count = 1;
2262 p_endccw->read1_nop1.cda = 0;
2264 /* read1_nop2 */
2265 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2266 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2267 p_endccw->read1_nop2.count = 1;
2268 p_endccw->read1_nop2.cda = 0;
2270 /* read2_nop1 */
2271 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2272 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2273 p_endccw->read2_nop1.count = 1;
2274 p_endccw->read2_nop1.cda = 0;
2276 /* read2_nop2 */
2277 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2278 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2279 p_endccw->read2_nop2.count = 1;
2280 p_endccw->read2_nop2.cda = 0;
2282 #ifdef IOTRACE
2283 printk(KERN_INFO "%s: %s() dump claw ending CCW BK \n",
2284 dev->name,__FUNCTION__);
2285 dumpit((char *)p_endccw, sizeof(struct endccw));
2286 #endif
2289 * Build a chain of CCWs
2293 #ifdef DEBUGMSG
2294 printk(KERN_INFO "%s: %s() Begin build a chain of CCW buffer \n",
2295 dev->name,__FUNCTION__);
2296 #endif
2297 p_buff=privptr->p_buff_ccw;
2299 p_free_chain=NULL;
2300 for (i=0 ; i < ccw_pages_required; i++ ) {
2301 real_address = (__u32)__pa(p_buff);
2302 p_buf=p_buff;
2303 for (j=0 ; j < ccw_blocks_perpage ; j++) {
2304 p_buf->next = p_free_chain;
2305 p_free_chain = p_buf;
2306 p_buf->real=(__u32)__pa(p_buf);
2307 ++p_buf;
2309 p_buff+=PAGE_SIZE;
2311 #ifdef DEBUGMSG
2312 printk(KERN_INFO "%s: %s() "
2313 "End build a chain of CCW buffer \n",
2314 dev->name,__FUNCTION__);
2315 p_buf=p_free_chain;
2316 while (p_buf!=NULL) {
2317 dumpit((char *)p_buf, sizeof(struct ccwbk));
2318 p_buf=p_buf->next;
2320 #endif
2323 * Initialize ClawSignalBlock
2326 #ifdef DEBUGMSG
2327 printk(KERN_INFO "%s: %s() "
2328 "Begin initialize ClawSignalBlock \n",
2329 dev->name,__FUNCTION__);
2330 #endif
2331 if (privptr->p_claw_signal_blk==NULL) {
2332 privptr->p_claw_signal_blk=p_free_chain;
2333 p_free_chain=p_free_chain->next;
2334 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
2335 pClawH->length=0xffff;
2336 pClawH->opcode=0xff;
2337 pClawH->flag=CLAW_BUSY;
2339 #ifdef DEBUGMSG
2340 printk(KERN_INFO "%s: %s() > End initialize "
2341 "ClawSignalBlock\n",
2342 dev->name,__FUNCTION__);
2343 dumpit((char *)privptr->p_claw_signal_blk, sizeof(struct ccwbk));
2344 #endif
2347 * allocate write_pages_required and add to free chain
2349 if (privptr->p_buff_write==NULL) {
2350 if (privptr->p_env->write_size < PAGE_SIZE) {
2351 privptr->p_buff_write=
2352 (void *)__get_free_pages(__GFP_DMA,
2353 (int)pages_to_order_of_mag(claw_write_pages ));
2354 if (privptr->p_buff_write==NULL) {
2355 printk(KERN_INFO "%s: %s() __get_free_pages for write"
2356 " bufs failed : get is for %d pages\n",
2357 dev->name,__FUNCTION__,claw_write_pages );
2358 free_pages((unsigned long)privptr->p_buff_ccw,
2359 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
2360 privptr->p_buff_ccw=NULL;
2361 #ifdef FUNCTRACE
2362 printk(KERN_INFO "%s: %s() > exit on line %d,"
2363 "rc = ENOMEM\n",
2364 dev->name,__FUNCTION__,__LINE__);
2365 #endif
2366 return -ENOMEM;
2369 * Build CLAW write free chain
2373 memset(privptr->p_buff_write, 0x00,
2374 ccw_pages_required * PAGE_SIZE);
2375 #ifdef DEBUGMSG
2376 printk(KERN_INFO "%s: %s() Begin build claw write free "
2377 "chain \n",dev->name,__FUNCTION__);
2378 #endif
2379 privptr->p_write_free_chain=NULL;
2381 p_buff=privptr->p_buff_write;
2383 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
2384 p_buf = p_free_chain; /* get a CCW */
2385 p_free_chain = p_buf->next;
2386 p_buf->next =privptr->p_write_free_chain;
2387 privptr->p_write_free_chain = p_buf;
2388 p_buf-> p_buffer = (struct clawbuf *)p_buff;
2389 p_buf-> write.cda = (__u32)__pa(p_buff);
2390 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2391 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2392 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2393 p_buf-> w_read_FF.count = 1;
2394 p_buf-> w_read_FF.cda =
2395 (__u32)__pa(&p_buf-> header.flag);
2396 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2397 p_buf-> w_TIC_1.flags = 0;
2398 p_buf-> w_TIC_1.count = 0;
2400 if (((unsigned long)p_buff+privptr->p_env->write_size) >=
2401 ((unsigned long)(p_buff+2*
2402 (privptr->p_env->write_size) -1) & PAGE_MASK)) {
2403 p_buff= p_buff+privptr->p_env->write_size;
2407 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
2409 privptr->p_write_free_chain=NULL;
2410 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
2411 p_buff=(void *)__get_free_pages(__GFP_DMA,
2412 (int)pages_to_order_of_mag(
2413 privptr->p_buff_pages_perwrite) );
2414 #ifdef IOTRACE
2415 printk(KERN_INFO "%s:%s __get_free_pages "
2416 "for writes buf: get for %d pages\n",
2417 dev->name,__FUNCTION__,
2418 privptr->p_buff_pages_perwrite);
2419 #endif
2420 if (p_buff==NULL) {
2421 printk(KERN_INFO "%s:%s __get_free_pages"
2422 "for writes buf failed : get is for %d pages\n",
2423 dev->name,
2424 __FUNCTION__,
2425 privptr->p_buff_pages_perwrite );
2426 free_pages((unsigned long)privptr->p_buff_ccw,
2427 (int)pages_to_order_of_mag(
2428 privptr->p_buff_ccw_num));
2429 privptr->p_buff_ccw=NULL;
2430 p_buf=privptr->p_buff_write;
2431 while (p_buf!=NULL) {
2432 free_pages((unsigned long)
2433 p_buf->p_buffer,
2434 (int)pages_to_order_of_mag(
2435 privptr->p_buff_pages_perwrite));
2436 p_buf=p_buf->next;
2438 #ifdef FUNCTRACE
2439 printk(KERN_INFO "%s: %s exit on line %d, rc = ENOMEM\n",
2440 dev->name,
2441 __FUNCTION__,
2442 __LINE__);
2443 #endif
2444 return -ENOMEM;
2445 } /* Error on get_pages */
2446 memset(p_buff, 0x00, privptr->p_env->write_size );
2447 p_buf = p_free_chain;
2448 p_free_chain = p_buf->next;
2449 p_buf->next = privptr->p_write_free_chain;
2450 privptr->p_write_free_chain = p_buf;
2451 privptr->p_buff_write = p_buf;
2452 p_buf->p_buffer=(struct clawbuf *)p_buff;
2453 p_buf-> write.cda = (__u32)__pa(p_buff);
2454 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2455 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2456 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2457 p_buf-> w_read_FF.count = 1;
2458 p_buf-> w_read_FF.cda =
2459 (__u32)__pa(&p_buf-> header.flag);
2460 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2461 p_buf-> w_TIC_1.flags = 0;
2462 p_buf-> w_TIC_1.count = 0;
2463 } /* for all write_buffers */
2465 } /* else buffers are PAGE_SIZE or bigger */
2468 privptr->p_buff_write_num=claw_write_pages;
2469 privptr->write_free_count=privptr->p_env->write_buffers;
2472 #ifdef DEBUGMSG
2473 printk(KERN_INFO "%s:%s End build claw write free chain \n",
2474 dev->name,__FUNCTION__);
2475 p_buf=privptr->p_write_free_chain;
2476 while (p_buf!=NULL) {
2477 dumpit((char *)p_buf, sizeof(struct ccwbk));
2478 p_buf=p_buf->next;
2480 #endif
2482 * allocate read_pages_required and chain to free chain
2484 if (privptr->p_buff_read==NULL) {
2485 if (privptr->p_env->read_size < PAGE_SIZE) {
2486 privptr->p_buff_read=
2487 (void *)__get_free_pages(__GFP_DMA,
2488 (int)pages_to_order_of_mag(claw_read_pages) );
2489 if (privptr->p_buff_read==NULL) {
2490 printk(KERN_INFO "%s: %s() "
2491 "__get_free_pages for read buf failed : "
2492 "get is for %d pages\n",
2493 dev->name,__FUNCTION__,claw_read_pages );
2494 free_pages((unsigned long)privptr->p_buff_ccw,
2495 (int)pages_to_order_of_mag(
2496 privptr->p_buff_ccw_num));
2497 /* free the write pages size is < page size */
2498 free_pages((unsigned long)privptr->p_buff_write,
2499 (int)pages_to_order_of_mag(
2500 privptr->p_buff_write_num));
2501 privptr->p_buff_ccw=NULL;
2502 privptr->p_buff_write=NULL;
2503 #ifdef FUNCTRACE
2504 printk(KERN_INFO "%s: %s() > exit on line %d, rc ="
2505 " ENOMEM\n",dev->name,__FUNCTION__,__LINE__);
2506 #endif
2507 return -ENOMEM;
2509 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
2510 privptr->p_buff_read_num=claw_read_pages;
2512 * Build CLAW read free chain
2515 #ifdef DEBUGMSG
2516 printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
2517 dev->name,__FUNCTION__);
2518 #endif
2519 p_buff=privptr->p_buff_read;
2520 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
2521 p_buf = p_free_chain;
2522 p_free_chain = p_buf->next;
2524 if (p_last_CCWB==NULL) {
2525 p_buf->next=NULL;
2526 real_TIC_address=0;
2527 p_last_CCWB=p_buf;
2529 else {
2530 p_buf->next=p_first_CCWB;
2531 real_TIC_address=
2532 (__u32)__pa(&p_first_CCWB -> read );
2535 p_first_CCWB=p_buf;
2537 p_buf->p_buffer=(struct clawbuf *)p_buff;
2538 /* initialize read command */
2539 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
2540 p_buf-> read.cda = (__u32)__pa(p_buff);
2541 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2542 p_buf-> read.count = privptr->p_env->read_size;
2544 /* initialize read_h command */
2545 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
2546 p_buf-> read_h.cda =
2547 (__u32)__pa(&(p_buf->header));
2548 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2549 p_buf-> read_h.count = sizeof(struct clawh);
2551 /* initialize Signal command */
2552 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
2553 p_buf-> signal.cda =
2554 (__u32)__pa(&(pClawH->flag));
2555 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2556 p_buf-> signal.count = 1;
2558 /* initialize r_TIC_1 command */
2559 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2560 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
2561 p_buf-> r_TIC_1.flags = 0;
2562 p_buf-> r_TIC_1.count = 0;
2564 /* initialize r_read_FF command */
2565 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2566 p_buf-> r_read_FF.cda =
2567 (__u32)__pa(&(pClawH->flag));
2568 p_buf-> r_read_FF.flags =
2569 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2570 p_buf-> r_read_FF.count = 1;
2572 /* initialize r_TIC_2 */
2573 memcpy(&p_buf->r_TIC_2,
2574 &p_buf->r_TIC_1, sizeof(struct ccw1));
2576 /* initialize Header */
2577 p_buf->header.length=0xffff;
2578 p_buf->header.opcode=0xff;
2579 p_buf->header.flag=CLAW_PENDING;
2581 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
2582 ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
2583 & PAGE_MASK) ) {
2584 p_buff= p_buff+privptr->p_env->read_size;
2586 else {
2587 p_buff=
2588 (void *)((unsigned long)
2589 (p_buff+2*(privptr->p_env->read_size) -1)
2590 & PAGE_MASK) ;
2592 } /* for read_buffers */
2593 } /* read_size < PAGE_SIZE */
2594 else { /* read Size >= PAGE_SIZE */
2596 #ifdef DEBUGMSG
2597 printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
2598 dev->name,__FUNCTION__);
2599 #endif
2600 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
2601 p_buff = (void *)__get_free_pages(__GFP_DMA,
2602 (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
2603 if (p_buff==NULL) {
2604 printk(KERN_INFO "%s: %s() __get_free_pages for read "
2605 "buf failed : get is for %d pages\n",
2606 dev->name,__FUNCTION__,
2607 privptr->p_buff_pages_perread );
2608 free_pages((unsigned long)privptr->p_buff_ccw,
2609 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
2610 /* free the write pages */
2611 p_buf=privptr->p_buff_write;
2612 while (p_buf!=NULL) {
2613 free_pages((unsigned long)p_buf->p_buffer,
2614 (int)pages_to_order_of_mag(
2615 privptr->p_buff_pages_perwrite ));
2616 p_buf=p_buf->next;
2618 /* free any read pages already alloc */
2619 p_buf=privptr->p_buff_read;
2620 while (p_buf!=NULL) {
2621 free_pages((unsigned long)p_buf->p_buffer,
2622 (int)pages_to_order_of_mag(
2623 privptr->p_buff_pages_perread ));
2624 p_buf=p_buf->next;
2626 privptr->p_buff_ccw=NULL;
2627 privptr->p_buff_write=NULL;
2628 #ifdef FUNCTRACE
2629 printk(KERN_INFO "%s: %s() exit on line %d, rc = ENOMEM\n",
2630 dev->name,__FUNCTION__,
2631 __LINE__);
2632 #endif
2633 return -ENOMEM;
2635 memset(p_buff, 0x00, privptr->p_env->read_size);
2636 p_buf = p_free_chain;
2637 privptr->p_buff_read = p_buf;
2638 p_free_chain = p_buf->next;
2640 if (p_last_CCWB==NULL) {
2641 p_buf->next=NULL;
2642 real_TIC_address=0;
2643 p_last_CCWB=p_buf;
2645 else {
2646 p_buf->next=p_first_CCWB;
2647 real_TIC_address=
2648 (addr_t)__pa(
2649 &p_first_CCWB -> read );
2652 p_first_CCWB=p_buf;
2653 /* save buff address */
2654 p_buf->p_buffer=(struct clawbuf *)p_buff;
2655 /* initialize read command */
2656 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
2657 p_buf-> read.cda = (__u32)__pa(p_buff);
2658 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2659 p_buf-> read.count = privptr->p_env->read_size;
2661 /* initialize read_h command */
2662 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
2663 p_buf-> read_h.cda =
2664 (__u32)__pa(&(p_buf->header));
2665 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2666 p_buf-> read_h.count = sizeof(struct clawh);
2668 /* initialize Signal command */
2669 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
2670 p_buf-> signal.cda =
2671 (__u32)__pa(&(pClawH->flag));
2672 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2673 p_buf-> signal.count = 1;
2675 /* initialize r_TIC_1 command */
2676 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2677 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
2678 p_buf-> r_TIC_1.flags = 0;
2679 p_buf-> r_TIC_1.count = 0;
2681 /* initialize r_read_FF command */
2682 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2683 p_buf-> r_read_FF.cda =
2684 (__u32)__pa(&(pClawH->flag));
2685 p_buf-> r_read_FF.flags =
2686 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2687 p_buf-> r_read_FF.count = 1;
2689 /* initialize r_TIC_2 */
2690 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
2691 sizeof(struct ccw1));
2693 /* initialize Header */
2694 p_buf->header.length=0xffff;
2695 p_buf->header.opcode=0xff;
2696 p_buf->header.flag=CLAW_PENDING;
2698 } /* For read_buffers */
2699 } /* read_size >= PAGE_SIZE */
2700 } /* pBuffread = NULL */
2701 #ifdef DEBUGMSG
2702 printk(KERN_INFO "%s: %s() > End build claw read free chain \n",
2703 dev->name,__FUNCTION__);
2704 p_buf=p_first_CCWB;
2705 while (p_buf!=NULL) {
2706 dumpit((char *)p_buf, sizeof(struct ccwbk));
2707 p_buf=p_buf->next;
2710 #endif
2711 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
2712 privptr->buffs_alloc = 1;
2713 #ifdef FUNCTRACE
2714 printk(KERN_INFO "%s: %s() exit on line %d\n",
2715 dev->name,__FUNCTION__,__LINE__);
2716 #endif
2717 return 0;
2718 } /* end of init_ccw_bk */
2720 /*-------------------------------------------------------------------*
2722 * probe_error *
2724 *--------------------------------------------------------------------*/
2726 static void
2727 probe_error( struct ccwgroup_device *cgdev)
2729 struct claw_privbk *privptr;
2730 #ifdef FUNCTRACE
2731 printk(KERN_INFO "%s enter \n",__FUNCTION__);
2732 #endif
2733 CLAW_DBF_TEXT(4,trace,"proberr");
2734 #ifdef DEBUGMSG
2735 printk(KERN_INFO "%s variable cgdev =\n",__FUNCTION__);
2736 dumpit((char *) cgdev, sizeof(struct ccwgroup_device));
2737 #endif
2738 privptr=(struct claw_privbk *)cgdev->dev.driver_data;
2739 if (privptr!=NULL) {
2740 kfree(privptr->p_env);
2741 privptr->p_env=NULL;
2742 kfree(privptr->p_mtc_envelope);
2743 privptr->p_mtc_envelope=NULL;
2744 kfree(privptr);
2745 privptr=NULL;
2747 #ifdef FUNCTRACE
2748 printk(KERN_INFO "%s > exit on line %d\n",
2749 __FUNCTION__,__LINE__);
2750 #endif
2752 return;
2753 } /* probe_error */
2757 /*-------------------------------------------------------------------*
2758 * claw_process_control *
2761 *--------------------------------------------------------------------*/
2763 static int
2764 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2767 struct clawbuf *p_buf;
2768 struct clawctl ctlbk;
2769 struct clawctl *p_ctlbk;
2770 char temp_host_name[8];
2771 char temp_ws_name[8];
2772 struct claw_privbk *privptr;
2773 struct claw_env *p_env;
2774 struct sysval *p_sysval;
2775 struct conncmd *p_connect=NULL;
2776 int rc;
2777 struct chbk *p_ch = NULL;
2778 #ifdef FUNCTRACE
2779 printk(KERN_INFO "%s: %s() > enter \n",
2780 dev->name,__FUNCTION__);
2781 #endif
2782 CLAW_DBF_TEXT(2,setup,"clw_cntl");
2783 #ifdef DEBUGMSG
2784 printk(KERN_INFO "%s: variable dev =\n",dev->name);
2785 dumpit((char *) dev, sizeof(struct net_device));
2786 printk(KERN_INFO "%s: variable p_ccw =\n",dev->name);
2787 dumpit((char *) p_ccw, sizeof(struct ccwbk *));
2788 #endif
2789 udelay(1000); /* Wait a ms for the control packets to
2790 *catch up to each other */
2791 privptr=dev->priv;
2792 p_env=privptr->p_env;
2793 memcpy( &temp_host_name, p_env->host_name, 8);
2794 memcpy( &temp_ws_name, p_env->adapter_name , 8);
2795 printk(KERN_INFO "%s: CLAW device %.8s: "
2796 "Received Control Packet\n",
2797 dev->name, temp_ws_name);
2798 if (privptr->release_pend==1) {
2799 #ifdef FUNCTRACE
2800 printk(KERN_INFO "%s: %s() > "
2801 "exit on line %d, rc=0\n",
2802 dev->name,__FUNCTION__,__LINE__);
2803 #endif
2804 return 0;
2806 p_buf=p_ccw->p_buffer;
2807 p_ctlbk=&ctlbk;
2808 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2809 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2810 } else {
2811 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2813 #ifdef IOTRACE
2814 printk(KERN_INFO "%s: dump claw control data inbound\n",dev->name);
2815 dumpit((char *)p_ctlbk, sizeof(struct clawctl));
2816 #endif
2817 switch (p_ctlbk->command)
2819 case SYSTEM_VALIDATE_REQUEST:
2820 if (p_ctlbk->version!=CLAW_VERSION_ID) {
2821 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2822 CLAW_RC_WRONG_VERSION );
2823 printk("%s: %d is wrong version id. "
2824 "Expected %d\n",
2825 dev->name, p_ctlbk->version,
2826 CLAW_VERSION_ID);
2828 p_sysval=(struct sysval *)&(p_ctlbk->data);
2829 printk( "%s: Recv Sys Validate Request: "
2830 "Vers=%d,link_id=%d,Corr=%d,WS name=%."
2831 "8s,Host name=%.8s\n",
2832 dev->name, p_ctlbk->version,
2833 p_ctlbk->linkid,
2834 p_ctlbk->correlator,
2835 p_sysval->WS_name,
2836 p_sysval->host_name);
2837 if (0!=memcmp(temp_host_name,p_sysval->host_name,8)) {
2838 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2839 CLAW_RC_NAME_MISMATCH );
2840 CLAW_DBF_TEXT(2,setup,"HSTBAD");
2841 CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->host_name);
2842 CLAW_DBF_TEXT_(2,setup,"%s",temp_host_name);
2843 printk(KERN_INFO "%s: Host name mismatch\n",
2844 dev->name);
2845 printk(KERN_INFO "%s: Received :%s: "
2846 "expected :%s: \n",
2847 dev->name,
2848 p_sysval->host_name,
2849 temp_host_name);
2851 if (0!=memcmp(temp_ws_name,p_sysval->WS_name,8)) {
2852 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2853 CLAW_RC_NAME_MISMATCH );
2854 CLAW_DBF_TEXT(2,setup,"WSNBAD");
2855 CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->WS_name);
2856 CLAW_DBF_TEXT_(2,setup,"%s",temp_ws_name);
2857 printk(KERN_INFO "%s: WS name mismatch\n",
2858 dev->name);
2859 printk(KERN_INFO "%s: Received :%s: "
2860 "expected :%s: \n",
2861 dev->name,
2862 p_sysval->WS_name,
2863 temp_ws_name);
2865 if (( p_sysval->write_frame_size < p_env->write_size) &&
2866 ( p_env->packing == 0)) {
2867 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2868 CLAW_RC_HOST_RCV_TOO_SMALL );
2869 printk(KERN_INFO "%s: host write size is too "
2870 "small\n", dev->name);
2871 CLAW_DBF_TEXT(2,setup,"wrtszbad");
2873 if (( p_sysval->read_frame_size < p_env->read_size) &&
2874 ( p_env->packing == 0)) {
2875 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2876 CLAW_RC_HOST_RCV_TOO_SMALL );
2877 printk(KERN_INFO "%s: host read size is too "
2878 "small\n", dev->name);
2879 CLAW_DBF_TEXT(2,setup,"rdsizbad");
2881 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0 );
2882 printk("%s: CLAW device %.8s: System validate"
2883 " completed.\n",dev->name, temp_ws_name);
2884 printk("%s: sys Validate Rsize:%d Wsize:%d\n",dev->name,
2885 p_sysval->read_frame_size,p_sysval->write_frame_size);
2886 privptr->system_validate_comp=1;
2887 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
2888 p_env->packing = PACKING_ASK;
2890 claw_strt_conn_req(dev);
2891 break;
2893 case SYSTEM_VALIDATE_RESPONSE:
2894 p_sysval=(struct sysval *)&(p_ctlbk->data);
2895 printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
2896 "WS name=%.8s,Host name=%.8s\n",
2897 dev->name,
2898 p_ctlbk->version,
2899 p_ctlbk->correlator,
2900 p_ctlbk->rc,
2901 p_sysval->WS_name,
2902 p_sysval->host_name);
2903 switch (p_ctlbk->rc)
2905 case 0:
2906 printk(KERN_INFO "%s: CLAW device "
2907 "%.8s: System validate "
2908 "completed.\n",
2909 dev->name, temp_ws_name);
2910 if (privptr->system_validate_comp == 0)
2911 claw_strt_conn_req(dev);
2912 privptr->system_validate_comp=1;
2913 break;
2914 case CLAW_RC_NAME_MISMATCH:
2915 printk(KERN_INFO "%s: Sys Validate "
2916 "Resp : Host, WS name is "
2917 "mismatch\n",
2918 dev->name);
2919 break;
2920 case CLAW_RC_WRONG_VERSION:
2921 printk(KERN_INFO "%s: Sys Validate "
2922 "Resp : Wrong version\n",
2923 dev->name);
2924 break;
2925 case CLAW_RC_HOST_RCV_TOO_SMALL:
2926 printk(KERN_INFO "%s: Sys Validate "
2927 "Resp : bad frame size\n",
2928 dev->name);
2929 break;
2930 default:
2931 printk(KERN_INFO "%s: Sys Validate "
2932 "error code=%d \n",
2933 dev->name, p_ctlbk->rc );
2934 break;
2936 break;
2938 case CONNECTION_REQUEST:
2939 p_connect=(struct conncmd *)&(p_ctlbk->data);
2940 printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2941 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2942 dev->name,
2943 p_ctlbk->version,
2944 p_ctlbk->linkid,
2945 p_ctlbk->correlator,
2946 p_connect->host_name,
2947 p_connect->WS_name);
2948 if (privptr->active_link_ID!=0 ) {
2949 claw_snd_disc(dev, p_ctlbk);
2950 printk(KERN_INFO "%s: Conn Req error : "
2951 "already logical link is active \n",
2952 dev->name);
2954 if (p_ctlbk->linkid!=1 ) {
2955 claw_snd_disc(dev, p_ctlbk);
2956 printk(KERN_INFO "%s: Conn Req error : "
2957 "req logical link id is not 1\n",
2958 dev->name);
2960 rc=find_link(dev,
2961 p_connect->host_name, p_connect->WS_name);
2962 if (rc!=0) {
2963 claw_snd_disc(dev, p_ctlbk);
2964 printk(KERN_INFO "%s: Conn Req error : "
2965 "req appl name does not match\n",
2966 dev->name);
2968 claw_send_control(dev,
2969 CONNECTION_CONFIRM, p_ctlbk->linkid,
2970 p_ctlbk->correlator,
2971 0, p_connect->host_name,
2972 p_connect->WS_name);
2973 if (p_env->packing == PACKING_ASK) {
2974 printk("%s: Now Pack ask\n",dev->name);
2975 p_env->packing = PACK_SEND;
2976 claw_snd_conn_req(dev,0);
2978 printk(KERN_INFO "%s: CLAW device %.8s: Connection "
2979 "completed link_id=%d.\n",
2980 dev->name, temp_ws_name,
2981 p_ctlbk->linkid);
2982 privptr->active_link_ID=p_ctlbk->linkid;
2983 p_ch=&privptr->channel[WRITE];
2984 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2985 break;
2986 case CONNECTION_RESPONSE:
2987 p_connect=(struct conncmd *)&(p_ctlbk->data);
2988 printk(KERN_INFO "%s: Revc Conn Resp: Vers=%d,link_id=%d,"
2989 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2990 dev->name,
2991 p_ctlbk->version,
2992 p_ctlbk->linkid,
2993 p_ctlbk->correlator,
2994 p_ctlbk->rc,
2995 p_connect->host_name,
2996 p_connect->WS_name);
2998 if (p_ctlbk->rc !=0 ) {
2999 printk(KERN_INFO "%s: Conn Resp error: rc=%d \n",
3000 dev->name, p_ctlbk->rc);
3001 return 1;
3003 rc=find_link(dev,
3004 p_connect->host_name, p_connect->WS_name);
3005 if (rc!=0) {
3006 claw_snd_disc(dev, p_ctlbk);
3007 printk(KERN_INFO "%s: Conn Resp error: "
3008 "req appl name does not match\n",
3009 dev->name);
3011 /* should be until CONNECTION_CONFIRM */
3012 privptr->active_link_ID = - (p_ctlbk->linkid);
3013 break;
3014 case CONNECTION_CONFIRM:
3015 p_connect=(struct conncmd *)&(p_ctlbk->data);
3016 printk(KERN_INFO "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
3017 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
3018 dev->name,
3019 p_ctlbk->version,
3020 p_ctlbk->linkid,
3021 p_ctlbk->correlator,
3022 p_connect->host_name,
3023 p_connect->WS_name);
3024 if (p_ctlbk->linkid== -(privptr->active_link_ID)) {
3025 privptr->active_link_ID=p_ctlbk->linkid;
3026 if (p_env->packing > PACKING_ASK) {
3027 printk(KERN_INFO "%s: Confirmed Now packing\n",dev->name);
3028 p_env->packing = DO_PACKED;
3030 p_ch=&privptr->channel[WRITE];
3031 wake_up(&p_ch->wait);
3033 else {
3034 printk(KERN_INFO "%s: Conn confirm: "
3035 "unexpected linkid=%d \n",
3036 dev->name, p_ctlbk->linkid);
3037 claw_snd_disc(dev, p_ctlbk);
3039 break;
3040 case DISCONNECT:
3041 printk(KERN_INFO "%s: Disconnect: "
3042 "Vers=%d,link_id=%d,Corr=%d\n",
3043 dev->name, p_ctlbk->version,
3044 p_ctlbk->linkid, p_ctlbk->correlator);
3045 if ((p_ctlbk->linkid == 2) &&
3046 (p_env->packing == PACK_SEND)) {
3047 privptr->active_link_ID = 1;
3048 p_env->packing = DO_PACKED;
3050 else
3051 privptr->active_link_ID=0;
3052 break;
3053 case CLAW_ERROR:
3054 printk(KERN_INFO "%s: CLAW ERROR detected\n",
3055 dev->name);
3056 break;
3057 default:
3058 printk(KERN_INFO "%s: Unexpected command code=%d \n",
3059 dev->name, p_ctlbk->command);
3060 break;
3063 #ifdef FUNCTRACE
3064 printk(KERN_INFO "%s: %s() exit on line %d, rc = 0\n",
3065 dev->name,__FUNCTION__,__LINE__);
3066 #endif
3068 return 0;
3069 } /* end of claw_process_control */
3072 /*-------------------------------------------------------------------*
3073 * claw_send_control *
3075 *--------------------------------------------------------------------*/
3077 static int
3078 claw_send_control(struct net_device *dev, __u8 type, __u8 link,
3079 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
3081 struct claw_privbk *privptr;
3082 struct clawctl *p_ctl;
3083 struct sysval *p_sysval;
3084 struct conncmd *p_connect;
3085 struct sk_buff *skb;
3087 #ifdef FUNCTRACE
3088 printk(KERN_INFO "%s:%s > enter \n",dev->name,__FUNCTION__);
3089 #endif
3090 CLAW_DBF_TEXT(2,setup,"sndcntl");
3091 #ifdef DEBUGMSG
3092 printk(KERN_INFO "%s: Sending Control Packet \n",dev->name);
3093 printk(KERN_INFO "%s: variable type = 0x%X, link = "
3094 "%d, correlator = %d, rc = %d\n",
3095 dev->name,type, link, correlator, rc);
3096 printk(KERN_INFO "%s: variable local_name = %s, "
3097 "remote_name = %s\n",dev->name, local_name, remote_name);
3098 #endif
3099 privptr=dev->priv;
3100 p_ctl=(struct clawctl *)&privptr->ctl_bk;
3102 p_ctl->command=type;
3103 p_ctl->version=CLAW_VERSION_ID;
3104 p_ctl->linkid=link;
3105 p_ctl->correlator=correlator;
3106 p_ctl->rc=rc;
3108 p_sysval=(struct sysval *)&p_ctl->data;
3109 p_connect=(struct conncmd *)&p_ctl->data;
3111 switch (p_ctl->command) {
3112 case SYSTEM_VALIDATE_REQUEST:
3113 case SYSTEM_VALIDATE_RESPONSE:
3114 memcpy(&p_sysval->host_name, local_name, 8);
3115 memcpy(&p_sysval->WS_name, remote_name, 8);
3116 if (privptr->p_env->packing > 0) {
3117 p_sysval->read_frame_size=DEF_PACK_BUFSIZE;
3118 p_sysval->write_frame_size=DEF_PACK_BUFSIZE;
3119 } else {
3120 /* how big is the piggest group of packets */
3121 p_sysval->read_frame_size=privptr->p_env->read_size;
3122 p_sysval->write_frame_size=privptr->p_env->write_size;
3124 memset(&p_sysval->reserved, 0x00, 4);
3125 break;
3126 case CONNECTION_REQUEST:
3127 case CONNECTION_RESPONSE:
3128 case CONNECTION_CONFIRM:
3129 case DISCONNECT:
3130 memcpy(&p_sysval->host_name, local_name, 8);
3131 memcpy(&p_sysval->WS_name, remote_name, 8);
3132 if (privptr->p_env->packing > 0) {
3133 /* How big is the biggest packet */
3134 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
3135 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
3136 } else {
3137 memset(&p_connect->reserved1, 0x00, 4);
3138 memset(&p_connect->reserved2, 0x00, 4);
3140 break;
3141 default:
3142 break;
3145 /* write Control Record to the device */
3148 skb = dev_alloc_skb(sizeof(struct clawctl));
3149 if (!skb) {
3150 printk( "%s:%s low on mem, returning...\n",
3151 dev->name,__FUNCTION__);
3152 #ifdef DEBUG
3153 printk(KERN_INFO "%s:%s Exit, rc = ENOMEM\n",
3154 dev->name,__FUNCTION__);
3155 #endif
3156 return -ENOMEM;
3158 memcpy(skb_put(skb, sizeof(struct clawctl)),
3159 p_ctl, sizeof(struct clawctl));
3160 #ifdef IOTRACE
3161 printk(KERN_INFO "%s: outbnd claw cntl data \n",dev->name);
3162 dumpit((char *)p_ctl,sizeof(struct clawctl));
3163 #endif
3164 if (privptr->p_env->packing >= PACK_SEND)
3165 claw_hw_tx(skb, dev, 1);
3166 else
3167 claw_hw_tx(skb, dev, 0);
3168 #ifdef FUNCTRACE
3169 printk(KERN_INFO "%s:%s Exit on line %d\n",
3170 dev->name,__FUNCTION__,__LINE__);
3171 #endif
3173 return 0;
3174 } /* end of claw_send_control */
3176 /*-------------------------------------------------------------------*
3177 * claw_snd_conn_req *
3179 *--------------------------------------------------------------------*/
3180 static int
3181 claw_snd_conn_req(struct net_device *dev, __u8 link)
3183 int rc;
3184 struct claw_privbk *privptr=dev->priv;
3185 struct clawctl *p_ctl;
3187 #ifdef FUNCTRACE
3188 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
3189 #endif
3190 CLAW_DBF_TEXT(2,setup,"snd_conn");
3191 #ifdef DEBUGMSG
3192 printk(KERN_INFO "%s: variable link = %X, dev =\n",dev->name, link);
3193 dumpit((char *) dev, sizeof(struct net_device));
3194 #endif
3195 rc = 1;
3196 p_ctl=(struct clawctl *)&privptr->ctl_bk;
3197 p_ctl->linkid = link;
3198 if ( privptr->system_validate_comp==0x00 ) {
3199 #ifdef FUNCTRACE
3200 printk(KERN_INFO "%s:%s Exit on line %d, rc = 1\n",
3201 dev->name,__FUNCTION__,__LINE__);
3202 #endif
3203 return rc;
3205 if (privptr->p_env->packing == PACKING_ASK )
3206 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3207 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
3208 if (privptr->p_env->packing == PACK_SEND) {
3209 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3210 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
3212 if (privptr->p_env->packing == 0)
3213 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3214 HOST_APPL_NAME, privptr->p_env->api_type);
3215 #ifdef FUNCTRACE
3216 printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3217 dev->name,__FUNCTION__,__LINE__, rc);
3218 #endif
3219 return rc;
3221 } /* end of claw_snd_conn_req */
3224 /*-------------------------------------------------------------------*
3225 * claw_snd_disc *
3227 *--------------------------------------------------------------------*/
3229 static int
3230 claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
3232 int rc;
3233 struct conncmd * p_connect;
3235 #ifdef FUNCTRACE
3236 printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3237 #endif
3238 CLAW_DBF_TEXT(2,setup,"snd_dsc");
3239 #ifdef DEBUGMSG
3240 printk(KERN_INFO "%s: variable dev =\n",dev->name);
3241 dumpit((char *) dev, sizeof(struct net_device));
3242 printk(KERN_INFO "%s: variable p_ctl",dev->name);
3243 dumpit((char *) p_ctl, sizeof(struct clawctl));
3244 #endif
3245 p_connect=(struct conncmd *)&p_ctl->data;
3247 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
3248 p_ctl->correlator, 0,
3249 p_connect->host_name, p_connect->WS_name);
3250 #ifdef FUNCTRACE
3251 printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3252 dev->name,__FUNCTION__, __LINE__, rc);
3253 #endif
3254 return rc;
3255 } /* end of claw_snd_disc */
3258 /*-------------------------------------------------------------------*
3259 * claw_snd_sys_validate_rsp *
3261 *--------------------------------------------------------------------*/
3263 static int
3264 claw_snd_sys_validate_rsp(struct net_device *dev,
3265 struct clawctl *p_ctl, __u32 return_code)
3267 struct claw_env * p_env;
3268 struct claw_privbk *privptr;
3269 int rc;
3271 #ifdef FUNCTRACE
3272 printk(KERN_INFO "%s:%s Enter\n",
3273 dev->name,__FUNCTION__);
3274 #endif
3275 CLAW_DBF_TEXT(2,setup,"chkresp");
3276 #ifdef DEBUGMSG
3277 printk(KERN_INFO "%s: variable return_code = %d, dev =\n",
3278 dev->name, return_code);
3279 dumpit((char *) dev, sizeof(struct net_device));
3280 printk(KERN_INFO "%s: variable p_ctl =\n",dev->name);
3281 dumpit((char *) p_ctl, sizeof(struct clawctl));
3282 #endif
3283 privptr = dev->priv;
3284 p_env=privptr->p_env;
3285 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
3286 p_ctl->linkid,
3287 p_ctl->correlator,
3288 return_code,
3289 p_env->host_name,
3290 p_env->adapter_name );
3291 #ifdef FUNCTRACE
3292 printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3293 dev->name,__FUNCTION__,__LINE__, rc);
3294 #endif
3295 return rc;
3296 } /* end of claw_snd_sys_validate_rsp */
3298 /*-------------------------------------------------------------------*
3299 * claw_strt_conn_req *
3301 *--------------------------------------------------------------------*/
3303 static int
3304 claw_strt_conn_req(struct net_device *dev )
3306 int rc;
3308 #ifdef FUNCTRACE
3309 printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3310 #endif
3311 CLAW_DBF_TEXT(2,setup,"conn_req");
3312 #ifdef DEBUGMSG
3313 printk(KERN_INFO "%s: variable dev =\n",dev->name);
3314 dumpit((char *) dev, sizeof(struct net_device));
3315 #endif
3316 rc=claw_snd_conn_req(dev, 1);
3317 #ifdef FUNCTRACE
3318 printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3319 dev->name,__FUNCTION__,__LINE__, rc);
3320 #endif
3321 return rc;
3322 } /* end of claw_strt_conn_req */
3326 /*-------------------------------------------------------------------*
3327 * claw_stats *
3328 *-------------------------------------------------------------------*/
3330 static struct
3331 net_device_stats *claw_stats(struct net_device *dev)
3333 struct claw_privbk *privptr;
3334 #ifdef FUNCTRACE
3335 printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3336 #endif
3337 CLAW_DBF_TEXT(4,trace,"stats");
3338 privptr = dev->priv;
3339 #ifdef FUNCTRACE
3340 printk(KERN_INFO "%s:%s Exit on line %d\n",
3341 dev->name,__FUNCTION__,__LINE__);
3342 #endif
3343 return &privptr->stats;
3344 } /* end of claw_stats */
3347 /*-------------------------------------------------------------------*
3348 * unpack_read *
3350 *--------------------------------------------------------------------*/
3351 static void
3352 unpack_read(struct net_device *dev )
3354 struct sk_buff *skb;
3355 struct claw_privbk *privptr;
3356 struct claw_env *p_env;
3357 struct ccwbk *p_this_ccw;
3358 struct ccwbk *p_first_ccw;
3359 struct ccwbk *p_last_ccw;
3360 struct clawph *p_packh;
3361 void *p_packd;
3362 struct clawctl *p_ctlrec=NULL;
3364 __u32 len_of_data;
3365 __u32 pack_off;
3366 __u8 link_num;
3367 __u8 mtc_this_frm=0;
3368 __u32 bytes_to_mov;
3369 struct chbk *p_ch = NULL;
3370 int i=0;
3371 int p=0;
3373 #ifdef FUNCTRACE
3374 printk(KERN_INFO "%s:%s enter \n",dev->name,__FUNCTION__);
3375 #endif
3376 CLAW_DBF_TEXT(4,trace,"unpkread");
3377 p_first_ccw=NULL;
3378 p_last_ccw=NULL;
3379 p_packh=NULL;
3380 p_packd=NULL;
3381 privptr=dev->priv;
3382 p_env = privptr->p_env;
3383 p_this_ccw=privptr->p_read_active_first;
3384 i=0;
3385 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
3386 #ifdef IOTRACE
3387 printk(KERN_INFO "%s p_this_ccw \n",dev->name);
3388 dumpit((char*)p_this_ccw, sizeof(struct ccwbk));
3389 printk(KERN_INFO "%s Inbound p_this_ccw->p_buffer(64)"
3390 " pk=%d \n",dev->name,p_env->packing);
3391 dumpit((char *)p_this_ccw->p_buffer, 64 );
3392 #endif
3393 pack_off = 0;
3394 p = 0;
3395 p_this_ccw->header.flag=CLAW_PENDING;
3396 privptr->p_read_active_first=p_this_ccw->next;
3397 p_this_ccw->next=NULL;
3398 p_packh = (struct clawph *)p_this_ccw->p_buffer;
3399 if ((p_env->packing == PACK_SEND) &&
3400 (p_packh->len == 32) &&
3401 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
3402 p_packh++; /* peek past pack header */
3403 p_ctlrec = (struct clawctl *)p_packh;
3404 p_packh--; /* un peek */
3405 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
3406 (p_ctlrec->command == CONNECTION_CONFIRM))
3407 p_env->packing = DO_PACKED;
3409 if (p_env->packing == DO_PACKED)
3410 link_num=p_packh->link_num;
3411 else
3412 link_num=p_this_ccw->header.opcode / 8;
3413 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
3414 #ifdef DEBUGMSG
3415 printk(KERN_INFO "%s: %s > More_to_come is ON\n",
3416 dev->name,__FUNCTION__);
3417 #endif
3418 mtc_this_frm=1;
3419 if (p_this_ccw->header.length!=
3420 privptr->p_env->read_size ) {
3421 printk(KERN_INFO " %s: Invalid frame detected "
3422 "length is %02x\n" ,
3423 dev->name, p_this_ccw->header.length);
3427 if (privptr->mtc_skipping) {
3429 * We're in the mode of skipping past a
3430 * multi-frame message
3431 * that we can't process for some reason or other.
3432 * The first frame without the More-To-Come flag is
3433 * the last frame of the skipped message.
3435 /* in case of More-To-Come not set in this frame */
3436 if (mtc_this_frm==0) {
3437 privptr->mtc_skipping=0; /* Ok, the end */
3438 privptr->mtc_logical_link=-1;
3440 #ifdef DEBUGMSG
3441 printk(KERN_INFO "%s:%s goto next "
3442 "frame from MoretoComeSkip \n",
3443 dev->name,__FUNCTION__);
3444 #endif
3445 goto NextFrame;
3448 if (link_num==0) {
3449 claw_process_control(dev, p_this_ccw);
3450 #ifdef DEBUGMSG
3451 printk(KERN_INFO "%s:%s goto next "
3452 "frame from claw_process_control \n",
3453 dev->name,__FUNCTION__);
3454 #endif
3455 CLAW_DBF_TEXT(4,trace,"UnpkCntl");
3456 goto NextFrame;
3458 unpack_next:
3459 if (p_env->packing == DO_PACKED) {
3460 if (pack_off > p_env->read_size)
3461 goto NextFrame;
3462 p_packd = p_this_ccw->p_buffer+pack_off;
3463 p_packh = (struct clawph *) p_packd;
3464 if ((p_packh->len == 0) || /* all done with this frame? */
3465 (p_packh->flag != 0))
3466 goto NextFrame;
3467 bytes_to_mov = p_packh->len;
3468 pack_off += bytes_to_mov+sizeof(struct clawph);
3469 p++;
3470 } else {
3471 bytes_to_mov=p_this_ccw->header.length;
3473 if (privptr->mtc_logical_link<0) {
3474 #ifdef DEBUGMSG
3475 printk(KERN_INFO "%s: %s mtc_logical_link < 0 \n",
3476 dev->name,__FUNCTION__);
3477 #endif
3480 * if More-To-Come is set in this frame then we don't know
3481 * length of entire message, and hence have to allocate
3482 * large buffer */
3484 /* We are starting a new envelope */
3485 privptr->mtc_offset=0;
3486 privptr->mtc_logical_link=link_num;
3489 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
3490 /* error */
3491 #ifdef DEBUGMSG
3492 printk(KERN_INFO "%s: %s > goto next "
3493 "frame from MoretoComeSkip \n",
3494 dev->name,
3495 __FUNCTION__);
3496 printk(KERN_INFO " bytes_to_mov %d > (MAX_ENVELOPE_"
3497 "SIZE-privptr->mtc_offset %d)\n",
3498 bytes_to_mov,(MAX_ENVELOPE_SIZE- privptr->mtc_offset));
3499 #endif
3500 privptr->stats.rx_frame_errors++;
3501 goto NextFrame;
3503 if (p_env->packing == DO_PACKED) {
3504 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
3505 p_packd+sizeof(struct clawph), bytes_to_mov);
3507 } else {
3508 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
3509 p_this_ccw->p_buffer, bytes_to_mov);
3511 #ifdef DEBUGMSG
3512 printk(KERN_INFO "%s: %s() received data \n",
3513 dev->name,__FUNCTION__);
3514 if (p_env->packing == DO_PACKED)
3515 dumpit((char *)p_packd+sizeof(struct clawph),32);
3516 else
3517 dumpit((char *)p_this_ccw->p_buffer, 32);
3518 printk(KERN_INFO "%s: %s() bytelength %d \n",
3519 dev->name,__FUNCTION__,bytes_to_mov);
3520 #endif
3521 if (mtc_this_frm==0) {
3522 len_of_data=privptr->mtc_offset+bytes_to_mov;
3523 skb=dev_alloc_skb(len_of_data);
3524 if (skb) {
3525 memcpy(skb_put(skb,len_of_data),
3526 privptr->p_mtc_envelope,
3527 len_of_data);
3528 skb->dev=dev;
3529 skb_reset_mac_header(skb);
3530 skb->protocol=htons(ETH_P_IP);
3531 skb->ip_summed=CHECKSUM_UNNECESSARY;
3532 privptr->stats.rx_packets++;
3533 privptr->stats.rx_bytes+=len_of_data;
3534 netif_rx(skb);
3535 #ifdef DEBUGMSG
3536 printk(KERN_INFO "%s: %s() netif_"
3537 "rx(skb) completed \n",
3538 dev->name,__FUNCTION__);
3539 #endif
3541 else {
3542 privptr->stats.rx_dropped++;
3543 printk(KERN_WARNING "%s: %s() low on memory\n",
3544 dev->name,__FUNCTION__);
3546 privptr->mtc_offset=0;
3547 privptr->mtc_logical_link=-1;
3549 else {
3550 privptr->mtc_offset+=bytes_to_mov;
3552 if (p_env->packing == DO_PACKED)
3553 goto unpack_next;
3554 NextFrame:
3556 * Remove ThisCCWblock from active read queue, and add it
3557 * to queue of free blocks to be reused.
3559 i++;
3560 p_this_ccw->header.length=0xffff;
3561 p_this_ccw->header.opcode=0xff;
3563 * add this one to the free queue for later reuse
3565 if (p_first_ccw==NULL) {
3566 p_first_ccw = p_this_ccw;
3568 else {
3569 p_last_ccw->next = p_this_ccw;
3571 p_last_ccw = p_this_ccw;
3573 * chain to next block on active read queue
3575 p_this_ccw = privptr->p_read_active_first;
3576 CLAW_DBF_TEXT_(4,trace,"rxpkt %d",p);
3577 } /* end of while */
3579 /* check validity */
3581 #ifdef IOTRACE
3582 printk(KERN_INFO "%s:%s processed frame is %d \n",
3583 dev->name,__FUNCTION__,i);
3584 printk(KERN_INFO "%s:%s F:%lx L:%lx\n",
3585 dev->name,
3586 __FUNCTION__,
3587 (unsigned long)p_first_ccw,
3588 (unsigned long)p_last_ccw);
3589 #endif
3590 CLAW_DBF_TEXT_(4,trace,"rxfrm %d",i);
3591 add_claw_reads(dev, p_first_ccw, p_last_ccw);
3592 p_ch=&privptr->channel[READ];
3593 claw_strt_read(dev, LOCK_YES);
3594 #ifdef FUNCTRACE
3595 printk(KERN_INFO "%s: %s exit on line %d\n",
3596 dev->name, __FUNCTION__, __LINE__);
3597 #endif
3598 return;
3599 } /* end of unpack_read */
3601 /*-------------------------------------------------------------------*
3602 * claw_strt_read *
3604 *--------------------------------------------------------------------*/
3605 static void
3606 claw_strt_read (struct net_device *dev, int lock )
3608 int rc = 0;
3609 __u32 parm;
3610 unsigned long saveflags = 0;
3611 struct claw_privbk *privptr=dev->priv;
3612 struct ccwbk*p_ccwbk;
3613 struct chbk *p_ch;
3614 struct clawh *p_clawh;
3615 p_ch=&privptr->channel[READ];
3617 #ifdef FUNCTRACE
3618 printk(KERN_INFO "%s:%s Enter \n",dev->name,__FUNCTION__);
3619 printk(KERN_INFO "%s: variable lock = %d, dev =\n",dev->name, lock);
3620 dumpit((char *) dev, sizeof(struct net_device));
3621 #endif
3622 CLAW_DBF_TEXT(4,trace,"StRdNter");
3623 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
3624 p_clawh->flag=CLAW_IDLE; /* 0x00 */
3626 if ((privptr->p_write_active_first!=NULL &&
3627 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
3628 (privptr->p_read_active_first!=NULL &&
3629 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
3630 p_clawh->flag=CLAW_BUSY; /* 0xff */
3632 #ifdef DEBUGMSG
3633 printk(KERN_INFO "%s:%s state-%02x\n" ,
3634 dev->name,__FUNCTION__, p_ch->claw_state);
3635 #endif
3636 if (lock==LOCK_YES) {
3637 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
3639 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
3640 #ifdef DEBUGMSG
3641 printk(KERN_INFO "%s: HOT READ started in %s\n" ,
3642 dev->name,__FUNCTION__);
3643 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
3644 dumpit((char *)&p_clawh->flag , 1);
3645 #endif
3646 CLAW_DBF_TEXT(4,trace,"HotRead");
3647 p_ccwbk=privptr->p_read_active_first;
3648 parm = (unsigned long) p_ch;
3649 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
3650 0xff, 0);
3651 if (rc != 0) {
3652 ccw_check_return_code(p_ch->cdev, rc);
3655 else {
3656 #ifdef DEBUGMSG
3657 printk(KERN_INFO "%s: No READ started by %s() In progress\n" ,
3658 dev->name,__FUNCTION__);
3659 #endif
3660 CLAW_DBF_TEXT(2,trace,"ReadAct");
3663 if (lock==LOCK_YES) {
3664 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
3666 #ifdef FUNCTRACE
3667 printk(KERN_INFO "%s:%s Exit on line %d\n",
3668 dev->name,__FUNCTION__,__LINE__);
3669 #endif
3670 CLAW_DBF_TEXT(4,trace,"StRdExit");
3671 return;
3672 } /* end of claw_strt_read */
3674 /*-------------------------------------------------------------------*
3675 * claw_strt_out_IO *
3677 *--------------------------------------------------------------------*/
3679 static void
3680 claw_strt_out_IO( struct net_device *dev )
3682 int rc = 0;
3683 unsigned long parm;
3684 struct claw_privbk *privptr;
3685 struct chbk *p_ch;
3686 struct ccwbk *p_first_ccw;
3688 #ifdef FUNCTRACE
3689 printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3690 #endif
3691 if (!dev) {
3692 return;
3694 privptr=(struct claw_privbk *)dev->priv;
3695 p_ch=&privptr->channel[WRITE];
3697 #ifdef DEBUGMSG
3698 printk(KERN_INFO "%s:%s state-%02x\n" ,
3699 dev->name,__FUNCTION__,p_ch->claw_state);
3700 #endif
3701 CLAW_DBF_TEXT(4,trace,"strt_io");
3702 p_first_ccw=privptr->p_write_active_first;
3704 if (p_ch->claw_state == CLAW_STOP)
3705 return;
3706 if (p_first_ccw == NULL) {
3707 #ifdef FUNCTRACE
3708 printk(KERN_INFO "%s:%s Exit on line %d\n",
3709 dev->name,__FUNCTION__,__LINE__);
3710 #endif
3711 return;
3713 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
3714 parm = (unsigned long) p_ch;
3715 #ifdef DEBUGMSG
3716 printk(KERN_INFO "%s:%s do_io \n" ,dev->name,__FUNCTION__);
3717 dumpit((char *)p_first_ccw, sizeof(struct ccwbk));
3718 #endif
3719 CLAW_DBF_TEXT(2,trace,"StWrtIO");
3720 rc = ccw_device_start (p_ch->cdev,&p_first_ccw->write, parm,
3721 0xff, 0);
3722 if (rc != 0) {
3723 ccw_check_return_code(p_ch->cdev, rc);
3726 dev->trans_start = jiffies;
3727 #ifdef FUNCTRACE
3728 printk(KERN_INFO "%s:%s Exit on line %d\n",
3729 dev->name,__FUNCTION__,__LINE__);
3730 #endif
3732 return;
3733 } /* end of claw_strt_out_IO */
3735 /*-------------------------------------------------------------------*
3736 * Free write buffers *
3738 *--------------------------------------------------------------------*/
3740 static void
3741 claw_free_wrt_buf( struct net_device *dev )
3744 struct claw_privbk *privptr=(struct claw_privbk *)dev->priv;
3745 struct ccwbk*p_first_ccw;
3746 struct ccwbk*p_last_ccw;
3747 struct ccwbk*p_this_ccw;
3748 struct ccwbk*p_next_ccw;
3749 #ifdef IOTRACE
3750 struct ccwbk*p_buf;
3751 #endif
3752 #ifdef FUNCTRACE
3753 printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3754 printk(KERN_INFO "%s: free count = %d variable dev =\n",
3755 dev->name,privptr->write_free_count);
3756 #endif
3757 CLAW_DBF_TEXT(4,trace,"freewrtb");
3758 /* scan the write queue to free any completed write packets */
3759 p_first_ccw=NULL;
3760 p_last_ccw=NULL;
3761 #ifdef IOTRACE
3762 printk(KERN_INFO "%s: Dump current CCW chain \n",dev->name );
3763 p_buf=privptr->p_write_active_first;
3764 while (p_buf!=NULL) {
3765 dumpit((char *)p_buf, sizeof(struct ccwbk));
3766 p_buf=p_buf->next;
3768 if (p_buf==NULL) {
3769 printk(KERN_INFO "%s: privptr->p_write_"
3770 "active_first==NULL\n",dev->name );
3772 p_buf=(struct ccwbk*)privptr->p_end_ccw;
3773 dumpit((char *)p_buf, sizeof(struct endccw));
3774 #endif
3775 p_this_ccw=privptr->p_write_active_first;
3776 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
3778 p_next_ccw = p_this_ccw->next;
3779 if (((p_next_ccw!=NULL) &&
3780 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
3781 ((p_this_ccw == privptr->p_write_active_last) &&
3782 (p_this_ccw->header.flag!=CLAW_PENDING))) {
3783 /* The next CCW is OK or this is */
3784 /* the last CCW...free it @A1A */
3785 privptr->p_write_active_first=p_this_ccw->next;
3786 p_this_ccw->header.flag=CLAW_PENDING;
3787 p_this_ccw->next=privptr->p_write_free_chain;
3788 privptr->p_write_free_chain=p_this_ccw;
3789 ++privptr->write_free_count;
3790 privptr->stats.tx_bytes+= p_this_ccw->write.count;
3791 p_this_ccw=privptr->p_write_active_first;
3792 privptr->stats.tx_packets++;
3794 else {
3795 break;
3798 if (privptr->write_free_count!=0) {
3799 claw_clearbit_busy(TB_NOBUFFER,dev);
3801 /* whole chain removed? */
3802 if (privptr->p_write_active_first==NULL) {
3803 privptr->p_write_active_last=NULL;
3804 #ifdef DEBUGMSG
3805 printk(KERN_INFO "%s:%s p_write_"
3806 "active_first==NULL\n",dev->name,__FUNCTION__);
3807 #endif
3809 #ifdef IOTRACE
3810 printk(KERN_INFO "%s: Dump arranged CCW chain \n",dev->name );
3811 p_buf=privptr->p_write_active_first;
3812 while (p_buf!=NULL) {
3813 dumpit((char *)p_buf, sizeof(struct ccwbk));
3814 p_buf=p_buf->next;
3816 if (p_buf==NULL) {
3817 printk(KERN_INFO "%s: privptr->p_write_active_"
3818 "first==NULL\n",dev->name );
3820 p_buf=(struct ccwbk*)privptr->p_end_ccw;
3821 dumpit((char *)p_buf, sizeof(struct endccw));
3822 #endif
3824 CLAW_DBF_TEXT_(4,trace,"FWC=%d",privptr->write_free_count);
3825 #ifdef FUNCTRACE
3826 printk(KERN_INFO "%s:%s Exit on line %d free_count =%d\n",
3827 dev->name,__FUNCTION__, __LINE__,privptr->write_free_count);
3828 #endif
3829 return;
3832 /*-------------------------------------------------------------------*
3833 * claw free netdevice *
3835 *--------------------------------------------------------------------*/
3836 static void
3837 claw_free_netdevice(struct net_device * dev, int free_dev)
3839 struct claw_privbk *privptr;
3840 #ifdef FUNCTRACE
3841 printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3842 #endif
3843 CLAW_DBF_TEXT(2,setup,"free_dev");
3845 if (!dev)
3846 return;
3847 CLAW_DBF_TEXT_(2,setup,"%s",dev->name);
3848 privptr = dev->priv;
3849 if (dev->flags & IFF_RUNNING)
3850 claw_release(dev);
3851 if (privptr) {
3852 privptr->channel[READ].ndev = NULL; /* say it's free */
3854 dev->priv=NULL;
3855 #ifdef MODULE
3856 if (free_dev) {
3857 free_netdev(dev);
3859 #endif
3860 CLAW_DBF_TEXT(2,setup,"feee_ok");
3861 #ifdef FUNCTRACE
3862 printk(KERN_INFO "%s:%s Exit\n",dev->name,__FUNCTION__);
3863 #endif
3867 * Claw init netdevice
3868 * Initialize everything of the net device except the name and the
3869 * channel structs.
3871 static void
3872 claw_init_netdevice(struct net_device * dev)
3874 #ifdef FUNCTRACE
3875 printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3876 #endif
3877 CLAW_DBF_TEXT(2,setup,"init_dev");
3878 CLAW_DBF_TEXT_(2,setup,"%s",dev->name);
3879 if (!dev) {
3880 printk(KERN_WARNING "claw:%s BAD Device exit line %d\n",
3881 __FUNCTION__,__LINE__);
3882 CLAW_DBF_TEXT(2,setup,"baddev");
3883 return;
3885 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
3886 dev->hard_start_xmit = claw_tx;
3887 dev->open = claw_open;
3888 dev->stop = claw_release;
3889 dev->get_stats = claw_stats;
3890 dev->change_mtu = claw_change_mtu;
3891 dev->hard_header_len = 0;
3892 dev->addr_len = 0;
3893 dev->type = ARPHRD_SLIP;
3894 dev->tx_queue_len = 1300;
3895 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
3896 SET_MODULE_OWNER(dev);
3897 #ifdef FUNCTRACE
3898 printk(KERN_INFO "%s:%s Exit\n",dev->name,__FUNCTION__);
3899 #endif
3900 CLAW_DBF_TEXT(2,setup,"initok");
3901 return;
3905 * Init a new channel in the privptr->channel[i].
3907 * @param cdev The ccw_device to be added.
3909 * @return 0 on success, !0 on error.
3911 static int
3912 add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
3914 struct chbk *p_ch;
3915 struct ccw_dev_id dev_id;
3917 #ifdef FUNCTRACE
3918 printk(KERN_INFO "%s:%s Enter\n",cdev->dev.bus_id,__FUNCTION__);
3919 #endif
3920 CLAW_DBF_TEXT_(2,setup,"%s",cdev->dev.bus_id);
3921 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
3922 p_ch = &privptr->channel[i];
3923 p_ch->cdev = cdev;
3924 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", cdev->dev.bus_id);
3925 ccw_device_get_id(cdev, &dev_id);
3926 p_ch->devno = dev_id.devno;
3927 if ((p_ch->irb = kmalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
3928 printk(KERN_WARNING "%s Out of memory in %s for irb\n",
3929 p_ch->id,__FUNCTION__);
3930 #ifdef FUNCTRACE
3931 printk(KERN_INFO "%s:%s Exit on line %d\n",
3932 p_ch->id,__FUNCTION__,__LINE__);
3933 #endif
3934 return -ENOMEM;
3936 memset(p_ch->irb, 0, sizeof (struct irb));
3937 #ifdef FUNCTRACE
3938 printk(KERN_INFO "%s:%s Exit on line %d\n",
3939 cdev->dev.bus_id,__FUNCTION__,__LINE__);
3940 #endif
3941 return 0;
3947 * Setup an interface.
3949 * @param cgdev Device to be setup.
3951 * @returns 0 on success, !0 on failure.
3953 static int
3954 claw_new_device(struct ccwgroup_device *cgdev)
3956 struct claw_privbk *privptr;
3957 struct claw_env *p_env;
3958 struct net_device *dev;
3959 int ret;
3960 struct ccw_dev_id dev_id;
3962 pr_debug("%s() called\n", __FUNCTION__);
3963 printk(KERN_INFO "claw: add for %s\n",cgdev->cdev[READ]->dev.bus_id);
3964 CLAW_DBF_TEXT(2,setup,"new_dev");
3965 privptr = cgdev->dev.driver_data;
3966 cgdev->cdev[READ]->dev.driver_data = privptr;
3967 cgdev->cdev[WRITE]->dev.driver_data = privptr;
3968 if (!privptr)
3969 return -ENODEV;
3970 p_env = privptr->p_env;
3971 ccw_device_get_id(cgdev->cdev[READ], &dev_id);
3972 p_env->devno[READ] = dev_id.devno;
3973 ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
3974 p_env->devno[WRITE] = dev_id.devno;
3975 ret = add_channel(cgdev->cdev[0],0,privptr);
3976 if (ret == 0)
3977 ret = add_channel(cgdev->cdev[1],1,privptr);
3978 if (ret != 0) {
3979 printk(KERN_WARNING
3980 "add channel failed "
3981 "with ret = %d\n", ret);
3982 goto out;
3984 ret = ccw_device_set_online(cgdev->cdev[READ]);
3985 if (ret != 0) {
3986 printk(KERN_WARNING
3987 "claw: ccw_device_set_online %s READ failed "
3988 "with ret = %d\n",cgdev->cdev[READ]->dev.bus_id,ret);
3989 goto out;
3991 ret = ccw_device_set_online(cgdev->cdev[WRITE]);
3992 if (ret != 0) {
3993 printk(KERN_WARNING
3994 "claw: ccw_device_set_online %s WRITE failed "
3995 "with ret = %d\n",cgdev->cdev[WRITE]->dev.bus_id, ret);
3996 goto out;
3998 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
3999 if (!dev) {
4000 printk(KERN_WARNING "%s:alloc_netdev failed\n",__FUNCTION__);
4001 goto out;
4003 dev->priv = privptr;
4004 cgdev->dev.driver_data = privptr;
4005 cgdev->cdev[READ]->dev.driver_data = privptr;
4006 cgdev->cdev[WRITE]->dev.driver_data = privptr;
4007 /* sysfs magic */
4008 SET_NETDEV_DEV(dev, &cgdev->dev);
4009 if (register_netdev(dev) != 0) {
4010 claw_free_netdevice(dev, 1);
4011 CLAW_DBF_TEXT(2,trace,"regfail");
4012 goto out;
4014 dev->flags &=~IFF_RUNNING;
4015 if (privptr->buffs_alloc == 0) {
4016 ret=init_ccw_bk(dev);
4017 if (ret !=0) {
4018 printk(KERN_WARNING
4019 "claw: init_ccw_bk failed with ret=%d\n", ret);
4020 unregister_netdev(dev);
4021 claw_free_netdevice(dev,1);
4022 CLAW_DBF_TEXT(2,trace,"ccwmem");
4023 goto out;
4026 privptr->channel[READ].ndev = dev;
4027 privptr->channel[WRITE].ndev = dev;
4028 privptr->p_env->ndev = dev;
4030 printk(KERN_INFO "%s:readsize=%d writesize=%d "
4031 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
4032 dev->name, p_env->read_size,
4033 p_env->write_size, p_env->read_buffers,
4034 p_env->write_buffers, p_env->devno[READ],
4035 p_env->devno[WRITE]);
4036 printk(KERN_INFO "%s:host_name:%.8s, adapter_name "
4037 ":%.8s api_type: %.8s\n",
4038 dev->name, p_env->host_name,
4039 p_env->adapter_name , p_env->api_type);
4040 return 0;
4041 out:
4042 ccw_device_set_offline(cgdev->cdev[1]);
4043 ccw_device_set_offline(cgdev->cdev[0]);
4045 return -ENODEV;
4048 static void
4049 claw_purge_skb_queue(struct sk_buff_head *q)
4051 struct sk_buff *skb;
4053 CLAW_DBF_TEXT(4,trace,"purgque");
4055 while ((skb = skb_dequeue(q))) {
4056 atomic_dec(&skb->users);
4057 dev_kfree_skb_any(skb);
4062 * Shutdown an interface.
4064 * @param cgdev Device to be shut down.
4066 * @returns 0 on success, !0 on failure.
4068 static int
4069 claw_shutdown_device(struct ccwgroup_device *cgdev)
4071 struct claw_privbk *priv;
4072 struct net_device *ndev;
4073 int ret;
4075 pr_debug("%s() called\n", __FUNCTION__);
4076 CLAW_DBF_TEXT_(2,setup,"%s",cgdev->dev.bus_id);
4077 priv = cgdev->dev.driver_data;
4078 if (!priv)
4079 return -ENODEV;
4080 ndev = priv->channel[READ].ndev;
4081 if (ndev) {
4082 /* Close the device */
4083 printk(KERN_INFO
4084 "%s: shuting down \n",ndev->name);
4085 if (ndev->flags & IFF_RUNNING)
4086 ret = claw_release(ndev);
4087 ndev->flags &=~IFF_RUNNING;
4088 unregister_netdev(ndev);
4089 ndev->priv = NULL; /* cgdev data, not ndev's to free */
4090 claw_free_netdevice(ndev, 1);
4091 priv->channel[READ].ndev = NULL;
4092 priv->channel[WRITE].ndev = NULL;
4093 priv->p_env->ndev = NULL;
4095 ccw_device_set_offline(cgdev->cdev[1]);
4096 ccw_device_set_offline(cgdev->cdev[0]);
4097 return 0;
4100 static void
4101 claw_remove_device(struct ccwgroup_device *cgdev)
4103 struct claw_privbk *priv;
4105 pr_debug("%s() called\n", __FUNCTION__);
4106 CLAW_DBF_TEXT_(2,setup,"%s",cgdev->dev.bus_id);
4107 priv = cgdev->dev.driver_data;
4108 if (!priv) {
4109 printk(KERN_WARNING "claw: %s() no Priv exiting\n",__FUNCTION__);
4110 return;
4112 printk(KERN_INFO "claw: %s() called %s will be removed.\n",
4113 __FUNCTION__,cgdev->cdev[0]->dev.bus_id);
4114 if (cgdev->state == CCWGROUP_ONLINE)
4115 claw_shutdown_device(cgdev);
4116 claw_remove_files(&cgdev->dev);
4117 kfree(priv->p_mtc_envelope);
4118 priv->p_mtc_envelope=NULL;
4119 kfree(priv->p_env);
4120 priv->p_env=NULL;
4121 kfree(priv->channel[0].irb);
4122 priv->channel[0].irb=NULL;
4123 kfree(priv->channel[1].irb);
4124 priv->channel[1].irb=NULL;
4125 kfree(priv);
4126 cgdev->dev.driver_data=NULL;
4127 cgdev->cdev[READ]->dev.driver_data = NULL;
4128 cgdev->cdev[WRITE]->dev.driver_data = NULL;
4129 put_device(&cgdev->dev);
4134 * sysfs attributes
4136 static ssize_t
4137 claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
4139 struct claw_privbk *priv;
4140 struct claw_env * p_env;
4142 priv = dev->driver_data;
4143 if (!priv)
4144 return -ENODEV;
4145 p_env = priv->p_env;
4146 return sprintf(buf, "%s\n",p_env->host_name);
4149 static ssize_t
4150 claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4152 struct claw_privbk *priv;
4153 struct claw_env * p_env;
4155 priv = dev->driver_data;
4156 if (!priv)
4157 return -ENODEV;
4158 p_env = priv->p_env;
4159 if (count > MAX_NAME_LEN+1)
4160 return -EINVAL;
4161 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
4162 strncpy(p_env->host_name,buf, count);
4163 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
4164 p_env->host_name[MAX_NAME_LEN] = 0x00;
4165 CLAW_DBF_TEXT(2,setup,"HstnSet");
4166 CLAW_DBF_TEXT_(2,setup,"%s",p_env->host_name);
4168 return count;
4171 static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
4173 static ssize_t
4174 claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
4176 struct claw_privbk *priv;
4177 struct claw_env * p_env;
4179 priv = dev->driver_data;
4180 if (!priv)
4181 return -ENODEV;
4182 p_env = priv->p_env;
4183 return sprintf(buf, "%s\n",p_env->adapter_name);
4186 static ssize_t
4187 claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4189 struct claw_privbk *priv;
4190 struct claw_env * p_env;
4192 priv = dev->driver_data;
4193 if (!priv)
4194 return -ENODEV;
4195 p_env = priv->p_env;
4196 if (count > MAX_NAME_LEN+1)
4197 return -EINVAL;
4198 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
4199 strncpy(p_env->adapter_name,buf, count);
4200 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
4201 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
4202 CLAW_DBF_TEXT(2,setup,"AdnSet");
4203 CLAW_DBF_TEXT_(2,setup,"%s",p_env->adapter_name);
4205 return count;
4208 static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
4210 static ssize_t
4211 claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
4213 struct claw_privbk *priv;
4214 struct claw_env * p_env;
4216 priv = dev->driver_data;
4217 if (!priv)
4218 return -ENODEV;
4219 p_env = priv->p_env;
4220 return sprintf(buf, "%s\n",
4221 p_env->api_type);
4224 static ssize_t
4225 claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4227 struct claw_privbk *priv;
4228 struct claw_env * p_env;
4230 priv = dev->driver_data;
4231 if (!priv)
4232 return -ENODEV;
4233 p_env = priv->p_env;
4234 if (count > MAX_NAME_LEN+1)
4235 return -EINVAL;
4236 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
4237 strncpy(p_env->api_type,buf, count);
4238 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
4239 p_env->api_type[MAX_NAME_LEN] = 0x00;
4240 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
4241 p_env->read_size=DEF_PACK_BUFSIZE;
4242 p_env->write_size=DEF_PACK_BUFSIZE;
4243 p_env->packing=PACKING_ASK;
4244 CLAW_DBF_TEXT(2,setup,"PACKING");
4246 else {
4247 p_env->packing=0;
4248 p_env->read_size=CLAW_FRAME_SIZE;
4249 p_env->write_size=CLAW_FRAME_SIZE;
4250 CLAW_DBF_TEXT(2,setup,"ApiSet");
4252 CLAW_DBF_TEXT_(2,setup,"%s",p_env->api_type);
4253 return count;
4256 static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
4258 static ssize_t
4259 claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
4261 struct claw_privbk *priv;
4262 struct claw_env * p_env;
4264 priv = dev->driver_data;
4265 if (!priv)
4266 return -ENODEV;
4267 p_env = priv->p_env;
4268 return sprintf(buf, "%d\n", p_env->write_buffers);
4271 static ssize_t
4272 claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4274 struct claw_privbk *priv;
4275 struct claw_env * p_env;
4276 int nnn,max;
4278 priv = dev->driver_data;
4279 if (!priv)
4280 return -ENODEV;
4281 p_env = priv->p_env;
4282 sscanf(buf, "%i", &nnn);
4283 if (p_env->packing) {
4284 max = 64;
4286 else {
4287 max = 512;
4289 if ((nnn > max ) || (nnn < 2))
4290 return -EINVAL;
4291 p_env->write_buffers = nnn;
4292 CLAW_DBF_TEXT(2,setup,"Wbufset");
4293 CLAW_DBF_TEXT_(2,setup,"WB=%d",p_env->write_buffers);
4294 return count;
4297 static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
4299 static ssize_t
4300 claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
4302 struct claw_privbk *priv;
4303 struct claw_env * p_env;
4305 priv = dev->driver_data;
4306 if (!priv)
4307 return -ENODEV;
4308 p_env = priv->p_env;
4309 return sprintf(buf, "%d\n", p_env->read_buffers);
4312 static ssize_t
4313 claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4315 struct claw_privbk *priv;
4316 struct claw_env *p_env;
4317 int nnn,max;
4319 priv = dev->driver_data;
4320 if (!priv)
4321 return -ENODEV;
4322 p_env = priv->p_env;
4323 sscanf(buf, "%i", &nnn);
4324 if (p_env->packing) {
4325 max = 64;
4327 else {
4328 max = 512;
4330 if ((nnn > max ) || (nnn < 2))
4331 return -EINVAL;
4332 p_env->read_buffers = nnn;
4333 CLAW_DBF_TEXT(2,setup,"Rbufset");
4334 CLAW_DBF_TEXT_(2,setup,"RB=%d",p_env->read_buffers);
4335 return count;
4338 static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
4340 static struct attribute *claw_attr[] = {
4341 &dev_attr_read_buffer.attr,
4342 &dev_attr_write_buffer.attr,
4343 &dev_attr_adapter_name.attr,
4344 &dev_attr_api_type.attr,
4345 &dev_attr_host_name.attr,
4346 NULL,
4349 static struct attribute_group claw_attr_group = {
4350 .attrs = claw_attr,
4353 static int
4354 claw_add_files(struct device *dev)
4356 pr_debug("%s() called\n", __FUNCTION__);
4357 CLAW_DBF_TEXT(2,setup,"add_file");
4358 return sysfs_create_group(&dev->kobj, &claw_attr_group);
4361 static void
4362 claw_remove_files(struct device *dev)
4364 pr_debug("%s() called\n", __FUNCTION__);
4365 CLAW_DBF_TEXT(2,setup,"rem_file");
4366 sysfs_remove_group(&dev->kobj, &claw_attr_group);
4369 /*--------------------------------------------------------------------*
4370 * claw_init and cleanup *
4371 *---------------------------------------------------------------------*/
4373 static void __exit
4374 claw_cleanup(void)
4376 unregister_cu3088_discipline(&claw_group_driver);
4377 claw_unregister_debug_facility();
4378 printk(KERN_INFO "claw: Driver unloaded\n");
4383 * Initialize module.
4384 * This is called just after the module is loaded.
4386 * @return 0 on success, !0 on error.
4388 static int __init
4389 claw_init(void)
4391 int ret = 0;
4392 printk(KERN_INFO "claw: starting driver\n");
4394 #ifdef FUNCTRACE
4395 printk(KERN_INFO "claw: %s() enter \n",__FUNCTION__);
4396 #endif
4397 ret = claw_register_debug_facility();
4398 if (ret) {
4399 printk(KERN_WARNING "claw: %s() debug_register failed %d\n",
4400 __FUNCTION__,ret);
4401 return ret;
4403 CLAW_DBF_TEXT(2,setup,"init_mod");
4404 ret = register_cu3088_discipline(&claw_group_driver);
4405 if (ret) {
4406 claw_unregister_debug_facility();
4407 printk(KERN_WARNING "claw; %s() cu3088 register failed %d\n",
4408 __FUNCTION__,ret);
4410 #ifdef FUNCTRACE
4411 printk(KERN_INFO "claw: %s() exit \n",__FUNCTION__);
4412 #endif
4413 return ret;
4416 module_init(claw_init);
4417 module_exit(claw_cleanup);
4421 /*--------------------------------------------------------------------*
4422 * End of File *
4423 *---------------------------------------------------------------------*/