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)
10 * Andy Richter (richtera@us.ibm.com)
11 * Marc Price (mwprice@us.ibm.com)
14 * group x.x.rrrr,x.x.wwww
18 * adapter_name aaaaaaaa
22 * group 0.0.0200 0.0.0201
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
35 * rrrr - the first of 2 consecutive device addresses used for the
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
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
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
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
63 #include <asm/ccwdev.h>
64 #include <asm/ccwgroup.h>
65 #include <asm/debug.h>
66 #include <asm/idals.h>
68 #include <linux/bitops.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>
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>
94 CLAW uses the s390dbf file system see claw_trace and claw_setup
98 static char debug_buffer[255];
100 * Debug Facility Stuff
102 static debug_info_t *claw_dbf_setup;
103 static debug_info_t *claw_dbf_trace;
106 * CLAW Debug Facility functions
109 claw_unregister_debug_facility(void)
112 debug_unregister(claw_dbf_setup);
114 debug_unregister(claw_dbf_trace);
118 claw_register_debug_facility(void)
120 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
121 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
122 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
123 claw_unregister_debug_facility();
126 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
127 debug_set_level(claw_dbf_setup, 2);
128 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
129 debug_set_level(claw_dbf_trace, 2);
134 claw_set_busy(struct net_device *dev)
136 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
141 claw_clear_busy(struct net_device *dev)
143 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
144 netif_wake_queue(dev);
149 claw_check_busy(struct net_device *dev)
152 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
156 claw_setbit_busy(int nr,struct net_device *dev)
158 netif_stop_queue(dev);
159 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
163 claw_clearbit_busy(int nr,struct net_device *dev)
165 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
166 netif_wake_queue(dev);
170 claw_test_and_setbit_busy(int nr,struct net_device *dev)
172 netif_stop_queue(dev);
173 return test_and_set_bit(nr,
174 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
178 /* Functions for the DEV methods */
180 static int claw_probe(struct ccwgroup_device *cgdev);
181 static void claw_remove_device(struct ccwgroup_device *cgdev);
182 static void claw_purge_skb_queue(struct sk_buff_head *q);
183 static int claw_new_device(struct ccwgroup_device *cgdev);
184 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
185 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
186 static int claw_change_mtu( struct net_device *dev, int new_mtu);
187 static int claw_open(struct net_device *dev);
188 static void claw_irq_handler(struct ccw_device *cdev,
189 unsigned long intparm, struct irb *irb);
190 static void claw_irq_tasklet ( unsigned long data );
191 static int claw_release(struct net_device *dev);
192 static void claw_write_retry ( struct chbk * p_ch );
193 static void claw_write_next ( struct chbk * p_ch );
194 static void claw_timer ( struct chbk * p_ch );
197 static int add_claw_reads(struct net_device *dev,
198 struct ccwbk* p_first, struct ccwbk* p_last);
199 static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
200 static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
201 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
202 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
203 static int init_ccw_bk(struct net_device *dev);
204 static void probe_error( struct ccwgroup_device *cgdev);
205 static struct net_device_stats *claw_stats(struct net_device *dev);
206 static int pages_to_order_of_mag(int num_of_pages);
207 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
208 /* sysfs Functions */
209 static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
210 static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
211 const char *buf, size_t count);
212 static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
213 static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
214 const char *buf, size_t count);
215 static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
216 static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
217 const char *buf, size_t count);
218 static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
219 static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
220 const char *buf, size_t count);
221 static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
222 static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
223 const char *buf, size_t count);
224 static int claw_add_files(struct device *dev);
225 static void claw_remove_files(struct device *dev);
227 /* Functions for System Validate */
228 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
229 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
230 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
231 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
232 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
233 static int claw_snd_sys_validate_rsp(struct net_device *dev,
234 struct clawctl * p_ctl, __u32 return_code);
235 static int claw_strt_conn_req(struct net_device *dev );
236 static void claw_strt_read(struct net_device *dev, int lock);
237 static void claw_strt_out_IO(struct net_device *dev);
238 static void claw_free_wrt_buf(struct net_device *dev);
240 /* Functions for unpack reads */
241 static void unpack_read(struct net_device *dev);
245 static struct ccwgroup_driver claw_group_driver = {
246 .owner = THIS_MODULE,
249 .driver_id = 0xC3D3C1E6,
251 .remove = claw_remove_device,
252 .set_online = claw_new_device,
253 .set_offline = claw_shutdown_device,
260 /*----------------------------------------------------------------*
262 * this function is called for each CLAW device. *
263 *----------------------------------------------------------------*/
265 claw_probe(struct ccwgroup_device *cgdev)
268 struct claw_privbk *privptr=NULL;
270 CLAW_DBF_TEXT(2, setup, "probe");
271 if (!get_device(&cgdev->dev))
273 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
274 cgdev->dev.driver_data = privptr;
275 if (privptr == NULL) {
277 put_device(&cgdev->dev);
278 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
281 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
282 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
283 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
285 put_device(&cgdev->dev);
286 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
289 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
290 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
291 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
292 privptr->p_env->packing = 0;
293 privptr->p_env->write_buffers = 5;
294 privptr->p_env->read_buffers = 5;
295 privptr->p_env->read_size = CLAW_FRAME_SIZE;
296 privptr->p_env->write_size = CLAW_FRAME_SIZE;
297 rc = claw_add_files(&cgdev->dev);
300 put_device(&cgdev->dev);
301 printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
302 cgdev->cdev[0]->dev.bus_id,__func__,__LINE__);
303 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
306 privptr->p_env->p_priv = privptr;
307 cgdev->cdev[0]->handler = claw_irq_handler;
308 cgdev->cdev[1]->handler = claw_irq_handler;
309 CLAW_DBF_TEXT(2, setup, "prbext 0");
312 } /* end of claw_probe */
314 /*-------------------------------------------------------------------*
316 *-------------------------------------------------------------------*/
319 claw_tx(struct sk_buff *skb, struct net_device *dev)
322 struct claw_privbk *privptr = dev->ml_priv;
323 unsigned long saveflags;
326 CLAW_DBF_TEXT(4, trace, "claw_tx");
327 p_ch=&privptr->channel[WRITE];
329 privptr->stats.tx_dropped++;
330 privptr->stats.tx_errors++;
331 CLAW_DBF_TEXT_(2, trace, "clawtx%d", -EIO);
334 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
335 rc=claw_hw_tx( skb, dev, 1 );
336 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
337 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
339 } /* end of claw_tx */
341 /*------------------------------------------------------------------*
342 * pack the collect queue into an skb and return it *
343 * If not packing just return the top skb from the queue *
344 *------------------------------------------------------------------*/
346 static struct sk_buff *
347 claw_pack_skb(struct claw_privbk *privptr)
349 struct sk_buff *new_skb,*held_skb;
350 struct chbk *p_ch = &privptr->channel[WRITE];
351 struct claw_env *p_env = privptr->p_env;
352 int pkt_cnt,pk_ind,so_far;
354 new_skb = NULL; /* assume no dice */
356 CLAW_DBF_TEXT(4, trace, "PackSKBe");
357 if (!skb_queue_empty(&p_ch->collect_queue)) {
359 held_skb = skb_dequeue(&p_ch->collect_queue);
361 dev_kfree_skb_any(held_skb);
364 if (p_env->packing != DO_PACKED)
366 /* get a new SKB we will pack at least one */
367 new_skb = dev_alloc_skb(p_env->write_size);
368 if (new_skb == NULL) {
369 atomic_inc(&held_skb->users);
370 skb_queue_head(&p_ch->collect_queue,held_skb);
373 /* we have packed packet and a place to put it */
376 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
377 while ((pk_ind) && (held_skb != NULL)) {
378 if (held_skb->len+so_far <= p_env->write_size-8) {
379 memcpy(skb_put(new_skb,held_skb->len),
380 held_skb->data,held_skb->len);
381 privptr->stats.tx_packets++;
382 so_far += held_skb->len;
384 dev_kfree_skb_any(held_skb);
385 held_skb = skb_dequeue(&p_ch->collect_queue);
387 atomic_dec(&held_skb->users);
390 atomic_inc(&held_skb->users);
391 skb_queue_head(&p_ch->collect_queue,held_skb);
395 CLAW_DBF_TEXT(4, trace, "PackSKBx");
399 /*-------------------------------------------------------------------*
402 *-------------------------------------------------------------------*/
405 claw_change_mtu(struct net_device *dev, int new_mtu)
407 struct claw_privbk *privptr = dev->ml_priv;
409 CLAW_DBF_TEXT(4, trace, "setmtu");
410 buff_size = privptr->p_env->write_size;
411 if ((new_mtu < 60) || (new_mtu > buff_size)) {
416 } /* end of claw_change_mtu */
419 /*-------------------------------------------------------------------*
422 *-------------------------------------------------------------------*/
424 claw_open(struct net_device *dev)
429 unsigned long saveflags=0;
431 struct claw_privbk *privptr;
432 DECLARE_WAITQUEUE(wait, current);
433 struct timer_list timer;
436 CLAW_DBF_TEXT(4, trace, "open");
437 privptr = (struct claw_privbk *)dev->ml_priv;
438 /* allocate and initialize CCW blocks */
439 if (privptr->buffs_alloc == 0) {
442 CLAW_DBF_TEXT(2, trace, "openmem");
446 privptr->system_validate_comp=0;
447 privptr->release_pend=0;
448 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
449 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
450 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
451 privptr->p_env->packing=PACKING_ASK;
453 privptr->p_env->packing=0;
454 privptr->p_env->read_size=CLAW_FRAME_SIZE;
455 privptr->p_env->write_size=CLAW_FRAME_SIZE;
458 tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
459 (unsigned long) &privptr->channel[READ]);
460 for ( i = 0; i < 2; i++) {
461 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
462 init_waitqueue_head(&privptr->channel[i].wait);
463 /* skb_queue_head_init(&p_ch->io_queue); */
466 &privptr->channel[WRITE].collect_queue);
467 privptr->channel[i].flag_a = 0;
468 privptr->channel[i].IO_active = 0;
469 privptr->channel[i].flag &= ~CLAW_TIMER;
471 timer.function = (void *)claw_timer;
472 timer.data = (unsigned long)(&privptr->channel[i]);
473 timer.expires = jiffies + 15*HZ;
475 spin_lock_irqsave(get_ccwdev_lock(
476 privptr->channel[i].cdev), saveflags);
477 parm = (unsigned long) &privptr->channel[i];
478 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
480 add_wait_queue(&privptr->channel[i].wait, &wait);
481 rc = ccw_device_halt(
482 (struct ccw_device *)privptr->channel[i].cdev,parm);
483 set_current_state(TASK_INTERRUPTIBLE);
484 spin_unlock_irqrestore(
485 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
487 set_current_state(TASK_RUNNING);
488 remove_wait_queue(&privptr->channel[i].wait, &wait);
490 ccw_check_return_code(privptr->channel[i].cdev, rc);
491 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
494 if ((((privptr->channel[READ].last_dstat |
495 privptr->channel[WRITE].last_dstat) &
496 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
497 (((privptr->channel[READ].flag |
498 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
499 printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
500 CLAW_DBF_TEXT(2, trace, "notrdy");
502 for ( i = 0; i < 2; i++) {
504 get_ccwdev_lock(privptr->channel[i].cdev),
506 parm = (unsigned long) &privptr->channel[i];
507 privptr->channel[i].claw_state = CLAW_STOP;
508 rc = ccw_device_halt(
509 (struct ccw_device *)&privptr->channel[i].cdev,
511 spin_unlock_irqrestore(
512 get_ccwdev_lock(privptr->channel[i].cdev),
515 ccw_check_return_code(
516 privptr->channel[i].cdev, rc);
519 free_pages((unsigned long)privptr->p_buff_ccw,
520 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
521 if (privptr->p_env->read_size < PAGE_SIZE) {
522 free_pages((unsigned long)privptr->p_buff_read,
523 (int)pages_to_order_of_mag(
524 privptr->p_buff_read_num));
527 p_buf=privptr->p_read_active_first;
528 while (p_buf!=NULL) {
529 free_pages((unsigned long)p_buf->p_buffer,
530 (int)pages_to_order_of_mag(
531 privptr->p_buff_pages_perread ));
535 if (privptr->p_env->write_size < PAGE_SIZE ) {
536 free_pages((unsigned long)privptr->p_buff_write,
537 (int)pages_to_order_of_mag(
538 privptr->p_buff_write_num));
541 p_buf=privptr->p_write_active_first;
542 while (p_buf!=NULL) {
543 free_pages((unsigned long)p_buf->p_buffer,
544 (int)pages_to_order_of_mag(
545 privptr->p_buff_pages_perwrite ));
549 privptr->buffs_alloc = 0;
550 privptr->channel[READ].flag= 0x00;
551 privptr->channel[WRITE].flag = 0x00;
552 privptr->p_buff_ccw=NULL;
553 privptr->p_buff_read=NULL;
554 privptr->p_buff_write=NULL;
555 claw_clear_busy(dev);
556 CLAW_DBF_TEXT(2, trace, "open EIO");
560 /* Send SystemValidate command */
562 claw_clear_busy(dev);
563 CLAW_DBF_TEXT(4, trace, "openok");
565 } /* end of claw_open */
567 /*-------------------------------------------------------------------*
571 *--------------------------------------------------------------------*/
573 claw_irq_handler(struct ccw_device *cdev,
574 unsigned long intparm, struct irb *irb)
576 struct chbk *p_ch = NULL;
577 struct claw_privbk *privptr = NULL;
578 struct net_device *dev = NULL;
579 struct claw_env *p_env;
580 struct chbk *p_ch_r=NULL;
582 CLAW_DBF_TEXT(4, trace, "clawirq");
583 /* Bypass all 'unsolicited interrupts' */
584 if (!cdev->dev.driver_data) {
585 printk(KERN_WARNING "claw: unsolicited interrupt for device:"
586 "%s received c-%02x d-%02x\n",
587 cdev->dev.bus_id, irb->scsw.cmd.cstat,
588 irb->scsw.cmd.dstat);
589 CLAW_DBF_TEXT(2, trace, "badirq");
592 privptr = (struct claw_privbk *)cdev->dev.driver_data;
594 /* Try to extract channel from driver data. */
595 if (privptr->channel[READ].cdev == cdev)
596 p_ch = &privptr->channel[READ];
597 else if (privptr->channel[WRITE].cdev == cdev)
598 p_ch = &privptr->channel[WRITE];
600 printk(KERN_WARNING "claw: Can't determine channel for "
601 "interrupt, device %s\n", cdev->dev.bus_id);
602 CLAW_DBF_TEXT(2, trace, "badchan");
605 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
607 dev = (struct net_device *) (p_ch->ndev);
608 p_env=privptr->p_env;
610 /* Copy interruption response block. */
611 memcpy(p_ch->irb, irb, sizeof(struct irb));
613 /* Check for good subchannel return code, otherwise info message */
614 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
615 printk(KERN_INFO "%s: subchannel check for device: %04x -"
616 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
617 dev->name, p_ch->devno,
618 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
620 CLAW_DBF_TEXT(2, trace, "chanchk");
624 /* Check the reason-code of a unit check */
625 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
626 ccw_check_unit_check(p_ch, irb->ecw[0]);
628 /* State machine to bring the connection up, down and to restart */
629 p_ch->last_dstat = irb->scsw.cmd.dstat;
631 switch (p_ch->claw_state) {
632 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
633 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
634 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
635 (p_ch->irb->scsw.cmd.stctl ==
636 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
638 wake_up(&p_ch->wait); /* wake up claw_release */
639 CLAW_DBF_TEXT(4, trace, "stop");
641 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
642 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
643 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
644 (p_ch->irb->scsw.cmd.stctl ==
645 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
646 CLAW_DBF_TEXT(4, trace, "haltio");
649 if (p_ch->flag == CLAW_READ) {
650 p_ch->claw_state = CLAW_START_READ;
651 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
652 } else if (p_ch->flag == CLAW_WRITE) {
653 p_ch->claw_state = CLAW_START_WRITE;
654 /* send SYSTEM_VALIDATE */
655 claw_strt_read(dev, LOCK_NO);
656 claw_send_control(dev,
657 SYSTEM_VALIDATE_REQUEST,
660 p_env->adapter_name);
662 printk(KERN_WARNING "claw: unsolicited "
663 "interrupt for device:"
664 "%s received c-%02x d-%02x\n",
667 irb->scsw.cmd.dstat);
670 CLAW_DBF_TEXT(4, trace, "haltio");
672 case CLAW_START_READ:
673 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
674 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
675 clear_bit(0, (void *)&p_ch->IO_active);
676 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
677 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
678 (p_ch->irb->ecw[0]) == 0) {
679 privptr->stats.rx_errors++;
680 printk(KERN_INFO "%s: Restart is "
681 "required after remote "
685 CLAW_DBF_TEXT(4, trace, "notrdy");
688 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
689 (p_ch->irb->scsw.cmd.dstat == 0)) {
690 if (test_and_set_bit(CLAW_BH_ACTIVE,
691 (void *)&p_ch->flag_a) == 0)
692 tasklet_schedule(&p_ch->tasklet);
694 CLAW_DBF_TEXT(4, trace, "PCINoBH");
695 CLAW_DBF_TEXT(4, trace, "PCI_read");
698 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
699 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
700 (p_ch->irb->scsw.cmd.stctl ==
701 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
702 CLAW_DBF_TEXT(4, trace, "SPend_rd");
705 clear_bit(0, (void *)&p_ch->IO_active);
706 claw_clearbit_busy(TB_RETRY, dev);
707 if (test_and_set_bit(CLAW_BH_ACTIVE,
708 (void *)&p_ch->flag_a) == 0)
709 tasklet_schedule(&p_ch->tasklet);
711 CLAW_DBF_TEXT(4, trace, "RdBHAct");
712 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
714 case CLAW_START_WRITE:
715 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
716 printk(KERN_INFO "%s: Unit Check Occured in "
717 "write channel\n", dev->name);
718 clear_bit(0, (void *)&p_ch->IO_active);
719 if (p_ch->irb->ecw[0] & 0x80) {
720 printk(KERN_INFO "%s: Resetting Event "
721 "occurred:\n", dev->name);
722 init_timer(&p_ch->timer);
723 p_ch->timer.function =
724 (void *)claw_write_retry;
725 p_ch->timer.data = (unsigned long)p_ch;
726 p_ch->timer.expires = jiffies + 10*HZ;
727 add_timer(&p_ch->timer);
728 printk(KERN_INFO "%s: write connection "
729 "restarting\n", dev->name);
731 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
734 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
735 clear_bit(0, (void *)&p_ch->IO_active);
736 printk(KERN_INFO "%s: Unit Exception "
737 "Occured in write channel\n",
740 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
741 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
742 (p_ch->irb->scsw.cmd.stctl ==
743 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
744 CLAW_DBF_TEXT(4, trace, "writeUE");
747 clear_bit(0, (void *)&p_ch->IO_active);
748 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
749 claw_write_next(p_ch);
750 claw_clearbit_busy(TB_TX, dev);
751 claw_clear_busy(dev);
753 p_ch_r = (struct chbk *)&privptr->channel[READ];
754 if (test_and_set_bit(CLAW_BH_ACTIVE,
755 (void *)&p_ch_r->flag_a) == 0)
756 tasklet_schedule(&p_ch_r->tasklet);
757 CLAW_DBF_TEXT(4, trace, "StWtExit");
760 printk(KERN_WARNING "%s: wrong selection code - irq "
761 "state=%d\n", dev->name, p_ch->claw_state);
762 CLAW_DBF_TEXT(2, trace, "badIRQ");
766 } /* end of claw_irq_handler */
769 /*-------------------------------------------------------------------*
772 *--------------------------------------------------------------------*/
774 claw_irq_tasklet ( unsigned long data )
777 struct net_device *dev;
778 struct claw_privbk * privptr;
780 p_ch = (struct chbk *) data;
781 dev = (struct net_device *)p_ch->ndev;
782 CLAW_DBF_TEXT(4, trace, "IRQtask");
783 privptr = (struct claw_privbk *)dev->ml_priv;
785 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
786 CLAW_DBF_TEXT(4, trace, "TskletXt");
788 } /* end of claw_irq_bh */
790 /*-------------------------------------------------------------------*
793 *--------------------------------------------------------------------*/
795 claw_release(struct net_device *dev)
799 unsigned long saveflags;
801 struct claw_privbk *privptr;
802 DECLARE_WAITQUEUE(wait, current);
803 struct ccwbk* p_this_ccw;
808 privptr = (struct claw_privbk *)dev->ml_priv;
811 CLAW_DBF_TEXT(4, trace, "release");
812 privptr->release_pend=1;
813 claw_setbit_busy(TB_STOP,dev);
814 for ( i = 1; i >=0 ; i--) {
816 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
817 /* del_timer(&privptr->channel[READ].timer); */
818 privptr->channel[i].claw_state = CLAW_STOP;
819 privptr->channel[i].IO_active = 0;
820 parm = (unsigned long) &privptr->channel[i];
822 claw_purge_skb_queue(
823 &privptr->channel[WRITE].collect_queue);
824 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
825 if (privptr->system_validate_comp==0x00) /* never opened? */
826 init_waitqueue_head(&privptr->channel[i].wait);
827 add_wait_queue(&privptr->channel[i].wait, &wait);
828 set_current_state(TASK_INTERRUPTIBLE);
829 spin_unlock_irqrestore(
830 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
832 set_current_state(TASK_RUNNING);
833 remove_wait_queue(&privptr->channel[i].wait, &wait);
835 ccw_check_return_code(privptr->channel[i].cdev, rc);
838 if (privptr->pk_skb != NULL) {
839 dev_kfree_skb_any(privptr->pk_skb);
840 privptr->pk_skb = NULL;
842 if(privptr->buffs_alloc != 1) {
843 CLAW_DBF_TEXT(4, trace, "none2fre");
846 CLAW_DBF_TEXT(4, trace, "freebufs");
847 if (privptr->p_buff_ccw != NULL) {
848 free_pages((unsigned long)privptr->p_buff_ccw,
849 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
851 CLAW_DBF_TEXT(4, trace, "freeread");
852 if (privptr->p_env->read_size < PAGE_SIZE) {
853 if (privptr->p_buff_read != NULL) {
854 free_pages((unsigned long)privptr->p_buff_read,
855 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
859 p_buf=privptr->p_read_active_first;
860 while (p_buf!=NULL) {
861 free_pages((unsigned long)p_buf->p_buffer,
862 (int)pages_to_order_of_mag(
863 privptr->p_buff_pages_perread ));
867 CLAW_DBF_TEXT(4, trace, "freewrit");
868 if (privptr->p_env->write_size < PAGE_SIZE ) {
869 free_pages((unsigned long)privptr->p_buff_write,
870 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
873 p_buf=privptr->p_write_active_first;
874 while (p_buf!=NULL) {
875 free_pages((unsigned long)p_buf->p_buffer,
876 (int)pages_to_order_of_mag(
877 privptr->p_buff_pages_perwrite ));
881 CLAW_DBF_TEXT(4, trace, "clearptr");
882 privptr->buffs_alloc = 0;
883 privptr->p_buff_ccw=NULL;
884 privptr->p_buff_read=NULL;
885 privptr->p_buff_write=NULL;
886 privptr->system_validate_comp=0;
887 privptr->release_pend=0;
888 /* Remove any writes that were pending and reset all reads */
889 p_this_ccw=privptr->p_read_active_first;
890 while (p_this_ccw!=NULL) {
891 p_this_ccw->header.length=0xffff;
892 p_this_ccw->header.opcode=0xff;
893 p_this_ccw->header.flag=0x00;
894 p_this_ccw=p_this_ccw->next;
897 while (privptr->p_write_active_first!=NULL) {
898 p_this_ccw=privptr->p_write_active_first;
899 p_this_ccw->header.flag=CLAW_PENDING;
900 privptr->p_write_active_first=p_this_ccw->next;
901 p_this_ccw->next=privptr->p_write_free_chain;
902 privptr->p_write_free_chain=p_this_ccw;
903 ++privptr->write_free_count;
905 privptr->p_write_active_last=NULL;
906 privptr->mtc_logical_link = -1;
907 privptr->mtc_skipping = 1;
908 privptr->mtc_offset=0;
910 if (((privptr->channel[READ].last_dstat |
911 privptr->channel[WRITE].last_dstat) &
912 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
913 printk(KERN_WARNING "%s: channel problems during close - "
914 "read: %02x - write: %02x\n",
916 privptr->channel[READ].last_dstat,
917 privptr->channel[WRITE].last_dstat);
918 CLAW_DBF_TEXT(2, trace, "badclose");
920 CLAW_DBF_TEXT(4, trace, "rlsexit");
922 } /* end of claw_release */
924 /*-------------------------------------------------------------------*
927 *--------------------------------------------------------------------*/
930 claw_write_retry ( struct chbk *p_ch )
933 struct net_device *dev=p_ch->ndev;
935 CLAW_DBF_TEXT(4, trace, "w_retry");
936 if (p_ch->claw_state == CLAW_STOP) {
939 claw_strt_out_IO( dev );
940 CLAW_DBF_TEXT(4, trace, "rtry_xit");
942 } /* end of claw_write_retry */
945 /*-------------------------------------------------------------------*
948 *--------------------------------------------------------------------*/
951 claw_write_next ( struct chbk * p_ch )
954 struct net_device *dev;
955 struct claw_privbk *privptr=NULL;
956 struct sk_buff *pk_skb;
959 CLAW_DBF_TEXT(4, trace, "claw_wrt");
960 if (p_ch->claw_state == CLAW_STOP)
962 dev = (struct net_device *) p_ch->ndev;
963 privptr = (struct claw_privbk *) dev->ml_priv;
964 claw_free_wrt_buf( dev );
965 if ((privptr->write_free_count > 0) &&
966 !skb_queue_empty(&p_ch->collect_queue)) {
967 pk_skb = claw_pack_skb(privptr);
968 while (pk_skb != NULL) {
969 rc = claw_hw_tx( pk_skb, dev,1);
970 if (privptr->write_free_count > 0) {
971 pk_skb = claw_pack_skb(privptr);
976 if (privptr->p_write_active_first!=NULL) {
977 claw_strt_out_IO(dev);
980 } /* end of claw_write_next */
982 /*-------------------------------------------------------------------*
985 *--------------------------------------------------------------------*/
988 claw_timer ( struct chbk * p_ch )
990 CLAW_DBF_TEXT(4, trace, "timer");
991 p_ch->flag |= CLAW_TIMER;
992 wake_up(&p_ch->wait);
994 } /* end of claw_timer */
1002 /*-------------------------------------------------------------------*
1004 * pages_to_order_of_mag *
1006 * takes a number of pages from 1 to 512 and returns the *
1007 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1008 * of magnitude get_free_pages() has an upper order of 9 *
1009 *--------------------------------------------------------------------*/
1012 pages_to_order_of_mag(int num_of_pages)
1014 int order_of_mag=1; /* assume 2 pages */
1017 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
1018 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1019 /* 512 pages = 2Meg on 4k page systems */
1020 if (num_of_pages >= 512) {return 9; }
1021 /* we have two or more pages order is at least 1 */
1022 for (nump=2 ;nump <= 512;nump*=2) {
1023 if (num_of_pages <= nump)
1027 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
1028 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
1029 return order_of_mag;
1032 /*-------------------------------------------------------------------*
1036 *--------------------------------------------------------------------*/
1038 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1039 struct ccwbk* p_last)
1041 struct claw_privbk *privptr;
1042 struct ccw1 temp_ccw;
1043 struct endccw * p_end;
1044 CLAW_DBF_TEXT(4, trace, "addreads");
1045 privptr = dev->ml_priv;
1046 p_end = privptr->p_end_ccw;
1048 /* first CCW and last CCW contains a new set of read channel programs
1049 * to apend the running channel programs
1051 if ( p_first==NULL) {
1052 CLAW_DBF_TEXT(4, trace, "addexit");
1056 /* set up ending CCW sequence for this segment */
1058 p_end->read1=0x00; /* second ending CCW is now active */
1059 /* reset ending CCWs and setup TIC CCWs */
1060 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1061 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1062 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1063 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1064 p_end->read2_nop2.cda=0;
1065 p_end->read2_nop2.count=1;
1068 p_end->read1=0x01; /* first ending CCW is now active */
1069 /* reset ending CCWs and setup TIC CCWs */
1070 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1071 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1072 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1073 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1074 p_end->read1_nop2.cda=0;
1075 p_end->read1_nop2.count=1;
1078 if ( privptr-> p_read_active_first ==NULL ) {
1079 privptr-> p_read_active_first= p_first; /* set new first */
1080 privptr-> p_read_active_last = p_last; /* set new last */
1084 /* set up TIC ccw */
1085 temp_ccw.cda= (__u32)__pa(&p_first->read);
1088 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1093 /* first set of CCW's is chained to the new read */
1094 /* chain, so the second set is chained to the active chain. */
1095 /* Therefore modify the second set to point to the new */
1096 /* read chain set up TIC CCWs */
1097 /* make sure we update the CCW so channel doesn't fetch it */
1098 /* when it's only half done */
1099 memcpy( &p_end->read2_nop2, &temp_ccw ,
1100 sizeof(struct ccw1));
1101 privptr->p_read_active_last->r_TIC_1.cda=
1102 (__u32)__pa(&p_first->read);
1103 privptr->p_read_active_last->r_TIC_2.cda=
1104 (__u32)__pa(&p_first->read);
1107 /* make sure we update the CCW so channel doesn't */
1108 /* fetch it when it is only half done */
1109 memcpy( &p_end->read1_nop2, &temp_ccw ,
1110 sizeof(struct ccw1));
1111 privptr->p_read_active_last->r_TIC_1.cda=
1112 (__u32)__pa(&p_first->read);
1113 privptr->p_read_active_last->r_TIC_2.cda=
1114 (__u32)__pa(&p_first->read);
1116 /* chain in new set of blocks */
1117 privptr->p_read_active_last->next = p_first;
1118 privptr->p_read_active_last=p_last;
1119 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1120 CLAW_DBF_TEXT(4, trace, "addexit");
1122 } /* end of add_claw_reads */
1124 /*-------------------------------------------------------------------*
1125 * ccw_check_return_code *
1127 *-------------------------------------------------------------------*/
1130 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1132 CLAW_DBF_TEXT(4, trace, "ccwret");
1133 if (return_code != 0) {
1134 switch (return_code) {
1135 case -EBUSY: /* BUSY is a transient state no action needed */
1138 printk(KERN_EMERG "%s: Missing device called "
1139 "for IO ENODEV\n", cdev->dev.bus_id);
1142 printk(KERN_EMERG "%s: Status pending... EIO \n",
1146 printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
1150 printk(KERN_EMERG "%s: Unknown error in "
1151 "Do_IO %d\n",cdev->dev.bus_id, return_code);
1154 CLAW_DBF_TEXT(4, trace, "ccwret");
1155 } /* end of ccw_check_return_code */
1157 /*-------------------------------------------------------------------*
1158 * ccw_check_unit_check *
1159 *--------------------------------------------------------------------*/
1162 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1164 struct net_device *ndev = p_ch->ndev;
1166 CLAW_DBF_TEXT(4, trace, "unitchek");
1167 printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
1172 printk(KERN_WARNING "%s: Interface disconnect or "
1174 "occurred (remote side)\n", ndev->name);
1177 printk(KERN_WARNING "%s: System reset occured"
1178 " (remote side)\n", ndev->name);
1181 else if (sense & 0x20) {
1183 printk(KERN_WARNING "%s: Data-streaming "
1184 "timeout)\n", ndev->name);
1187 printk(KERN_WARNING "%s: Data-transfer parity"
1188 " error\n", ndev->name);
1191 else if (sense & 0x10) {
1193 printk(KERN_WARNING "%s: Hardware malfunction "
1194 "(remote side)\n", ndev->name);
1197 printk(KERN_WARNING "%s: read-data parity error "
1198 "(remote side)\n", ndev->name);
1202 } /* end of ccw_check_unit_check */
1204 /*-------------------------------------------------------------------*
1206 *--------------------------------------------------------------------*/
1208 find_link(struct net_device *dev, char *host_name, char *ws_name )
1210 struct claw_privbk *privptr;
1211 struct claw_env *p_env;
1214 CLAW_DBF_TEXT(2, setup, "findlink");
1215 privptr = dev->ml_priv;
1216 p_env=privptr->p_env;
1217 switch (p_env->packing)
1220 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1221 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1226 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1227 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1231 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1232 (memcmp(p_env->api_type , ws_name, 8)!=0))
1238 } /* end of find_link */
1240 /*-------------------------------------------------------------------*
1244 *-------------------------------------------------------------------*/
1247 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1250 struct claw_privbk *privptr;
1251 struct ccwbk *p_this_ccw;
1252 struct ccwbk *p_first_ccw;
1253 struct ccwbk *p_last_ccw;
1255 signed long len_of_data;
1256 unsigned long bytesInThisBuffer;
1257 unsigned char *pDataAddress;
1258 struct endccw *pEnd;
1259 struct ccw1 tempCCW;
1261 struct claw_env *p_env;
1263 struct clawph *pk_head;
1266 CLAW_DBF_TEXT(4, trace, "hw_tx");
1267 privptr = (struct claw_privbk *)(dev->ml_priv);
1268 p_ch=(struct chbk *)&privptr->channel[WRITE];
1269 p_env =privptr->p_env;
1270 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1271 /* scan the write queue to free any completed write packets */
1274 if ((p_env->packing >= PACK_SEND) &&
1275 (skb->cb[1] != 'P')) {
1276 skb_push(skb,sizeof(struct clawph));
1277 pk_head=(struct clawph *)skb->data;
1278 pk_head->len=skb->len-sizeof(struct clawph);
1279 if (pk_head->len%4) {
1280 pk_head->len+= 4-(pk_head->len%4);
1281 skb_pad(skb,4-(pk_head->len%4));
1282 skb_put(skb,4-(pk_head->len%4));
1284 if (p_env->packing == DO_PACKED)
1285 pk_head->link_num = linkid;
1287 pk_head->link_num = 0;
1288 pk_head->flag = 0x00;
1293 if (claw_check_busy(dev)) {
1294 if (privptr->write_free_count!=0) {
1295 claw_clear_busy(dev);
1298 claw_strt_out_IO(dev );
1299 claw_free_wrt_buf( dev );
1300 if (privptr->write_free_count==0) {
1301 ch = &privptr->channel[WRITE];
1302 atomic_inc(&skb->users);
1303 skb_queue_tail(&ch->collect_queue, skb);
1307 claw_clear_busy(dev);
1312 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1313 ch = &privptr->channel[WRITE];
1314 atomic_inc(&skb->users);
1315 skb_queue_tail(&ch->collect_queue, skb);
1316 claw_strt_out_IO(dev );
1321 /* See how many write buffers are required to hold this data */
1322 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
1324 /* If that number of buffers isn't available, give up for now */
1325 if (privptr->write_free_count < numBuffers ||
1326 privptr->p_write_free_chain == NULL ) {
1328 claw_setbit_busy(TB_NOBUFFER,dev);
1329 ch = &privptr->channel[WRITE];
1330 atomic_inc(&skb->users);
1331 skb_queue_tail(&ch->collect_queue, skb);
1332 CLAW_DBF_TEXT(2, trace, "clawbusy");
1335 pDataAddress=skb->data;
1336 len_of_data=skb->len;
1338 while (len_of_data > 0) {
1339 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1340 if (p_this_ccw == NULL) { /* lost the race */
1341 ch = &privptr->channel[WRITE];
1342 atomic_inc(&skb->users);
1343 skb_queue_tail(&ch->collect_queue, skb);
1346 privptr->p_write_free_chain=p_this_ccw->next;
1347 p_this_ccw->next=NULL;
1348 --privptr->write_free_count; /* -1 */
1349 bytesInThisBuffer=len_of_data;
1350 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1351 len_of_data-=bytesInThisBuffer;
1352 pDataAddress+=(unsigned long)bytesInThisBuffer;
1353 /* setup write CCW */
1354 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1355 if (len_of_data>0) {
1356 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1358 p_this_ccw->write.count=bytesInThisBuffer;
1359 /* now add to end of this chain */
1360 if (p_first_ccw==NULL) {
1361 p_first_ccw=p_this_ccw;
1363 if (p_last_ccw!=NULL) {
1364 p_last_ccw->next=p_this_ccw;
1365 /* set up TIC ccws */
1366 p_last_ccw->w_TIC_1.cda=
1367 (__u32)__pa(&p_this_ccw->write);
1369 p_last_ccw=p_this_ccw; /* save new last block */
1372 /* FirstCCW and LastCCW now contain a new set of write channel
1373 * programs to append to the running channel program
1376 if (p_first_ccw!=NULL) {
1377 /* setup ending ccw sequence for this segment */
1378 pEnd=privptr->p_end_ccw;
1380 pEnd->write1=0x00; /* second end ccw is now active */
1381 /* set up Tic CCWs */
1382 p_last_ccw->w_TIC_1.cda=
1383 (__u32)__pa(&pEnd->write2_nop1);
1384 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1385 pEnd->write2_nop2.flags =
1386 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1387 pEnd->write2_nop2.cda=0;
1388 pEnd->write2_nop2.count=1;
1390 else { /* end of if (pEnd->write1)*/
1391 pEnd->write1=0x01; /* first end ccw is now active */
1392 /* set up Tic CCWs */
1393 p_last_ccw->w_TIC_1.cda=
1394 (__u32)__pa(&pEnd->write1_nop1);
1395 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1396 pEnd->write1_nop2.flags =
1397 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1398 pEnd->write1_nop2.cda=0;
1399 pEnd->write1_nop2.count=1;
1400 } /* end if if (pEnd->write1) */
1402 if (privptr->p_write_active_first==NULL ) {
1403 privptr->p_write_active_first=p_first_ccw;
1404 privptr->p_write_active_last=p_last_ccw;
1407 /* set up Tic CCWs */
1409 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1412 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1417 * first set of ending CCW's is chained to the new write
1418 * chain, so the second set is chained to the active chain
1419 * Therefore modify the second set to point the new write chain.
1420 * make sure we update the CCW atomically
1421 * so channel does not fetch it when it's only half done
1423 memcpy( &pEnd->write2_nop2, &tempCCW ,
1424 sizeof(struct ccw1));
1425 privptr->p_write_active_last->w_TIC_1.cda=
1426 (__u32)__pa(&p_first_ccw->write);
1430 /*make sure we update the CCW atomically
1431 *so channel does not fetch it when it's only half done
1433 memcpy(&pEnd->write1_nop2, &tempCCW ,
1434 sizeof(struct ccw1));
1435 privptr->p_write_active_last->w_TIC_1.cda=
1436 (__u32)__pa(&p_first_ccw->write);
1438 } /* end if if (pEnd->write1) */
1440 privptr->p_write_active_last->next=p_first_ccw;
1441 privptr->p_write_active_last=p_last_ccw;
1444 } /* endif (p_first_ccw!=NULL) */
1445 dev_kfree_skb_any(skb);
1452 claw_strt_out_IO(dev );
1453 /* if write free count is zero , set NOBUFFER */
1454 if (privptr->write_free_count==0) {
1455 claw_setbit_busy(TB_NOBUFFER,dev);
1458 claw_clearbit_busy(TB_TX,dev);
1461 } /* end of claw_hw_tx */
1463 /*-------------------------------------------------------------------*
1467 *--------------------------------------------------------------------*/
1470 init_ccw_bk(struct net_device *dev)
1473 __u32 ccw_blocks_required;
1474 __u32 ccw_blocks_perpage;
1475 __u32 ccw_pages_required;
1476 __u32 claw_reads_perpage=1;
1477 __u32 claw_read_pages;
1478 __u32 claw_writes_perpage=1;
1479 __u32 claw_write_pages;
1481 struct ccwbk*p_free_chain;
1483 struct ccwbk*p_last_CCWB;
1484 struct ccwbk*p_first_CCWB;
1485 struct endccw *p_endccw=NULL;
1486 addr_t real_address;
1487 struct claw_privbk *privptr = dev->ml_priv;
1488 struct clawh *pClawH=NULL;
1489 addr_t real_TIC_address;
1491 CLAW_DBF_TEXT(4, trace, "init_ccw");
1493 /* initialize statistics field */
1494 privptr->active_link_ID=0;
1495 /* initialize ccwbk pointers */
1496 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1497 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1498 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1499 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1500 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1501 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1502 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1503 privptr->buffs_alloc = 0;
1504 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1505 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1506 /* initialize free write ccwbk counter */
1507 privptr->write_free_count=0; /* number of free bufs on write chain */
1511 * We need 1 CCW block for each read buffer, 1 for each
1512 * write buffer, plus 1 for ClawSignalBlock
1514 ccw_blocks_required =
1515 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
1517 * compute number of CCW blocks that will fit in a page
1519 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1521 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
1524 * read and write sizes are set by 2 constants in claw.h
1525 * 4k and 32k. Unpacked values other than 4k are not going to
1526 * provide good performance. With packing buffers support 32k
1529 if (privptr->p_env->read_size < PAGE_SIZE) {
1530 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1531 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1532 claw_reads_perpage);
1534 else { /* > or equal */
1535 privptr->p_buff_pages_perread =
1536 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1537 claw_read_pages = privptr->p_env->read_buffers *
1538 privptr->p_buff_pages_perread;
1540 if (privptr->p_env->write_size < PAGE_SIZE) {
1541 claw_writes_perpage =
1542 PAGE_SIZE / privptr->p_env->write_size;
1543 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1544 claw_writes_perpage);
1547 else { /* > or equal */
1548 privptr->p_buff_pages_perwrite =
1549 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1550 claw_write_pages = privptr->p_env->write_buffers *
1551 privptr->p_buff_pages_perwrite;
1554 * allocate ccw_pages_required
1556 if (privptr->p_buff_ccw==NULL) {
1557 privptr->p_buff_ccw=
1558 (void *)__get_free_pages(__GFP_DMA,
1559 (int)pages_to_order_of_mag(ccw_pages_required ));
1560 if (privptr->p_buff_ccw==NULL) {
1563 privptr->p_buff_ccw_num=ccw_pages_required;
1565 memset(privptr->p_buff_ccw, 0x00,
1566 privptr->p_buff_ccw_num * PAGE_SIZE);
1569 * obtain ending ccw block address
1572 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1573 real_address = (__u32)__pa(privptr->p_end_ccw);
1574 /* Initialize ending CCW block */
1575 p_endccw=privptr->p_end_ccw;
1576 p_endccw->real=real_address;
1577 p_endccw->write1=0x00;
1578 p_endccw->read1=0x00;
1581 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1582 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1583 p_endccw->write1_nop1.count = 1;
1584 p_endccw->write1_nop1.cda = 0;
1587 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1588 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1589 p_endccw->write1_nop2.count = 1;
1590 p_endccw->write1_nop2.cda = 0;
1593 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1594 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1595 p_endccw->write2_nop1.count = 1;
1596 p_endccw->write2_nop1.cda = 0;
1599 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1600 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1601 p_endccw->write2_nop2.count = 1;
1602 p_endccw->write2_nop2.cda = 0;
1605 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1606 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1607 p_endccw->read1_nop1.count = 1;
1608 p_endccw->read1_nop1.cda = 0;
1611 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1612 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1613 p_endccw->read1_nop2.count = 1;
1614 p_endccw->read1_nop2.cda = 0;
1617 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1618 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1619 p_endccw->read2_nop1.count = 1;
1620 p_endccw->read2_nop1.cda = 0;
1623 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1624 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1625 p_endccw->read2_nop2.count = 1;
1626 p_endccw->read2_nop2.cda = 0;
1629 * Build a chain of CCWs
1632 p_buff=privptr->p_buff_ccw;
1635 for (i=0 ; i < ccw_pages_required; i++ ) {
1636 real_address = (__u32)__pa(p_buff);
1638 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1639 p_buf->next = p_free_chain;
1640 p_free_chain = p_buf;
1641 p_buf->real=(__u32)__pa(p_buf);
1647 * Initialize ClawSignalBlock
1650 if (privptr->p_claw_signal_blk==NULL) {
1651 privptr->p_claw_signal_blk=p_free_chain;
1652 p_free_chain=p_free_chain->next;
1653 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1654 pClawH->length=0xffff;
1655 pClawH->opcode=0xff;
1656 pClawH->flag=CLAW_BUSY;
1660 * allocate write_pages_required and add to free chain
1662 if (privptr->p_buff_write==NULL) {
1663 if (privptr->p_env->write_size < PAGE_SIZE) {
1664 privptr->p_buff_write=
1665 (void *)__get_free_pages(__GFP_DMA,
1666 (int)pages_to_order_of_mag(claw_write_pages ));
1667 if (privptr->p_buff_write==NULL) {
1668 privptr->p_buff_ccw=NULL;
1672 * Build CLAW write free chain
1676 memset(privptr->p_buff_write, 0x00,
1677 ccw_pages_required * PAGE_SIZE);
1678 privptr->p_write_free_chain=NULL;
1680 p_buff=privptr->p_buff_write;
1682 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1683 p_buf = p_free_chain; /* get a CCW */
1684 p_free_chain = p_buf->next;
1685 p_buf->next =privptr->p_write_free_chain;
1686 privptr->p_write_free_chain = p_buf;
1687 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1688 p_buf-> write.cda = (__u32)__pa(p_buff);
1689 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1690 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1691 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1692 p_buf-> w_read_FF.count = 1;
1693 p_buf-> w_read_FF.cda =
1694 (__u32)__pa(&p_buf-> header.flag);
1695 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1696 p_buf-> w_TIC_1.flags = 0;
1697 p_buf-> w_TIC_1.count = 0;
1699 if (((unsigned long)p_buff+privptr->p_env->write_size) >=
1700 ((unsigned long)(p_buff+2*
1701 (privptr->p_env->write_size) -1) & PAGE_MASK)) {
1702 p_buff= p_buff+privptr->p_env->write_size;
1706 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1708 privptr->p_write_free_chain=NULL;
1709 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1710 p_buff=(void *)__get_free_pages(__GFP_DMA,
1711 (int)pages_to_order_of_mag(
1712 privptr->p_buff_pages_perwrite) );
1714 free_pages((unsigned long)privptr->p_buff_ccw,
1715 (int)pages_to_order_of_mag(
1716 privptr->p_buff_ccw_num));
1717 privptr->p_buff_ccw=NULL;
1718 p_buf=privptr->p_buff_write;
1719 while (p_buf!=NULL) {
1720 free_pages((unsigned long)
1722 (int)pages_to_order_of_mag(
1723 privptr->p_buff_pages_perwrite));
1727 } /* Error on get_pages */
1728 memset(p_buff, 0x00, privptr->p_env->write_size );
1729 p_buf = p_free_chain;
1730 p_free_chain = p_buf->next;
1731 p_buf->next = privptr->p_write_free_chain;
1732 privptr->p_write_free_chain = p_buf;
1733 privptr->p_buff_write = p_buf;
1734 p_buf->p_buffer=(struct clawbuf *)p_buff;
1735 p_buf-> write.cda = (__u32)__pa(p_buff);
1736 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1737 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1738 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1739 p_buf-> w_read_FF.count = 1;
1740 p_buf-> w_read_FF.cda =
1741 (__u32)__pa(&p_buf-> header.flag);
1742 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1743 p_buf-> w_TIC_1.flags = 0;
1744 p_buf-> w_TIC_1.count = 0;
1745 } /* for all write_buffers */
1747 } /* else buffers are PAGE_SIZE or bigger */
1750 privptr->p_buff_write_num=claw_write_pages;
1751 privptr->write_free_count=privptr->p_env->write_buffers;
1755 * allocate read_pages_required and chain to free chain
1757 if (privptr->p_buff_read==NULL) {
1758 if (privptr->p_env->read_size < PAGE_SIZE) {
1759 privptr->p_buff_read=
1760 (void *)__get_free_pages(__GFP_DMA,
1761 (int)pages_to_order_of_mag(claw_read_pages) );
1762 if (privptr->p_buff_read==NULL) {
1763 free_pages((unsigned long)privptr->p_buff_ccw,
1764 (int)pages_to_order_of_mag(
1765 privptr->p_buff_ccw_num));
1766 /* free the write pages size is < page size */
1767 free_pages((unsigned long)privptr->p_buff_write,
1768 (int)pages_to_order_of_mag(
1769 privptr->p_buff_write_num));
1770 privptr->p_buff_ccw=NULL;
1771 privptr->p_buff_write=NULL;
1774 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1775 privptr->p_buff_read_num=claw_read_pages;
1777 * Build CLAW read free chain
1780 p_buff=privptr->p_buff_read;
1781 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1782 p_buf = p_free_chain;
1783 p_free_chain = p_buf->next;
1785 if (p_last_CCWB==NULL) {
1791 p_buf->next=p_first_CCWB;
1793 (__u32)__pa(&p_first_CCWB -> read );
1798 p_buf->p_buffer=(struct clawbuf *)p_buff;
1799 /* initialize read command */
1800 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1801 p_buf-> read.cda = (__u32)__pa(p_buff);
1802 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1803 p_buf-> read.count = privptr->p_env->read_size;
1805 /* initialize read_h command */
1806 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1807 p_buf-> read_h.cda =
1808 (__u32)__pa(&(p_buf->header));
1809 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1810 p_buf-> read_h.count = sizeof(struct clawh);
1812 /* initialize Signal command */
1813 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1814 p_buf-> signal.cda =
1815 (__u32)__pa(&(pClawH->flag));
1816 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1817 p_buf-> signal.count = 1;
1819 /* initialize r_TIC_1 command */
1820 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1821 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1822 p_buf-> r_TIC_1.flags = 0;
1823 p_buf-> r_TIC_1.count = 0;
1825 /* initialize r_read_FF command */
1826 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1827 p_buf-> r_read_FF.cda =
1828 (__u32)__pa(&(pClawH->flag));
1829 p_buf-> r_read_FF.flags =
1830 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1831 p_buf-> r_read_FF.count = 1;
1833 /* initialize r_TIC_2 */
1834 memcpy(&p_buf->r_TIC_2,
1835 &p_buf->r_TIC_1, sizeof(struct ccw1));
1837 /* initialize Header */
1838 p_buf->header.length=0xffff;
1839 p_buf->header.opcode=0xff;
1840 p_buf->header.flag=CLAW_PENDING;
1842 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1843 ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
1845 p_buff= p_buff+privptr->p_env->read_size;
1849 (void *)((unsigned long)
1850 (p_buff+2*(privptr->p_env->read_size) -1)
1853 } /* for read_buffers */
1854 } /* read_size < PAGE_SIZE */
1855 else { /* read Size >= PAGE_SIZE */
1856 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1857 p_buff = (void *)__get_free_pages(__GFP_DMA,
1858 (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
1860 free_pages((unsigned long)privptr->p_buff_ccw,
1861 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
1862 /* free the write pages */
1863 p_buf=privptr->p_buff_write;
1864 while (p_buf!=NULL) {
1865 free_pages((unsigned long)p_buf->p_buffer,
1866 (int)pages_to_order_of_mag(
1867 privptr->p_buff_pages_perwrite ));
1870 /* free any read pages already alloc */
1871 p_buf=privptr->p_buff_read;
1872 while (p_buf!=NULL) {
1873 free_pages((unsigned long)p_buf->p_buffer,
1874 (int)pages_to_order_of_mag(
1875 privptr->p_buff_pages_perread ));
1878 privptr->p_buff_ccw=NULL;
1879 privptr->p_buff_write=NULL;
1882 memset(p_buff, 0x00, privptr->p_env->read_size);
1883 p_buf = p_free_chain;
1884 privptr->p_buff_read = p_buf;
1885 p_free_chain = p_buf->next;
1887 if (p_last_CCWB==NULL) {
1893 p_buf->next=p_first_CCWB;
1896 &p_first_CCWB -> read );
1900 /* save buff address */
1901 p_buf->p_buffer=(struct clawbuf *)p_buff;
1902 /* initialize read command */
1903 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1904 p_buf-> read.cda = (__u32)__pa(p_buff);
1905 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1906 p_buf-> read.count = privptr->p_env->read_size;
1908 /* initialize read_h command */
1909 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1910 p_buf-> read_h.cda =
1911 (__u32)__pa(&(p_buf->header));
1912 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1913 p_buf-> read_h.count = sizeof(struct clawh);
1915 /* initialize Signal command */
1916 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1917 p_buf-> signal.cda =
1918 (__u32)__pa(&(pClawH->flag));
1919 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1920 p_buf-> signal.count = 1;
1922 /* initialize r_TIC_1 command */
1923 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1924 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1925 p_buf-> r_TIC_1.flags = 0;
1926 p_buf-> r_TIC_1.count = 0;
1928 /* initialize r_read_FF command */
1929 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1930 p_buf-> r_read_FF.cda =
1931 (__u32)__pa(&(pClawH->flag));
1932 p_buf-> r_read_FF.flags =
1933 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1934 p_buf-> r_read_FF.count = 1;
1936 /* initialize r_TIC_2 */
1937 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1938 sizeof(struct ccw1));
1940 /* initialize Header */
1941 p_buf->header.length=0xffff;
1942 p_buf->header.opcode=0xff;
1943 p_buf->header.flag=CLAW_PENDING;
1945 } /* For read_buffers */
1946 } /* read_size >= PAGE_SIZE */
1947 } /* pBuffread = NULL */
1948 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1949 privptr->buffs_alloc = 1;
1952 } /* end of init_ccw_bk */
1954 /*-------------------------------------------------------------------*
1958 *--------------------------------------------------------------------*/
1961 probe_error( struct ccwgroup_device *cgdev)
1963 struct claw_privbk *privptr;
1965 CLAW_DBF_TEXT(4, trace, "proberr");
1966 privptr = (struct claw_privbk *) cgdev->dev.driver_data;
1967 if (privptr != NULL) {
1968 cgdev->dev.driver_data = NULL;
1969 kfree(privptr->p_env);
1970 kfree(privptr->p_mtc_envelope);
1975 /*-------------------------------------------------------------------*
1976 * claw_process_control *
1979 *--------------------------------------------------------------------*/
1982 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
1985 struct clawbuf *p_buf;
1986 struct clawctl ctlbk;
1987 struct clawctl *p_ctlbk;
1988 char temp_host_name[8];
1989 char temp_ws_name[8];
1990 struct claw_privbk *privptr;
1991 struct claw_env *p_env;
1992 struct sysval *p_sysval;
1993 struct conncmd *p_connect=NULL;
1995 struct chbk *p_ch = NULL;
1996 struct device *tdev;
1997 CLAW_DBF_TEXT(2, setup, "clw_cntl");
1998 udelay(1000); /* Wait a ms for the control packets to
1999 *catch up to each other */
2000 privptr = dev->ml_priv;
2001 p_env=privptr->p_env;
2002 tdev = &privptr->channel[READ].cdev->dev;
2003 memcpy( &temp_host_name, p_env->host_name, 8);
2004 memcpy( &temp_ws_name, p_env->adapter_name , 8);
2005 printk(KERN_INFO "%s: CLAW device %.8s: "
2006 "Received Control Packet\n",
2007 dev->name, temp_ws_name);
2008 if (privptr->release_pend==1) {
2011 p_buf=p_ccw->p_buffer;
2013 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2014 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2016 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2018 switch (p_ctlbk->command)
2020 case SYSTEM_VALIDATE_REQUEST:
2021 if (p_ctlbk->version != CLAW_VERSION_ID) {
2022 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2023 CLAW_RC_WRONG_VERSION);
2024 printk("%s: %d is wrong version id. "
2026 dev->name, p_ctlbk->version,
2029 p_sysval = (struct sysval *)&(p_ctlbk->data);
2030 printk("%s: Recv Sys Validate Request: "
2031 "Vers=%d,link_id=%d,Corr=%d,WS name=%."
2032 "8s,Host name=%.8s\n",
2033 dev->name, p_ctlbk->version,
2035 p_ctlbk->correlator,
2037 p_sysval->host_name);
2038 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2039 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2040 CLAW_RC_NAME_MISMATCH);
2041 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2042 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2043 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
2044 printk(KERN_INFO "%s: Host name mismatch\n",
2046 printk(KERN_INFO "%s: Received :%s: "
2049 p_sysval->host_name,
2052 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2053 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2054 CLAW_RC_NAME_MISMATCH);
2055 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2056 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2057 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
2058 printk(KERN_INFO "%s: WS name mismatch\n",
2060 printk(KERN_INFO "%s: Received :%s: "
2066 if ((p_sysval->write_frame_size < p_env->write_size) &&
2067 (p_env->packing == 0)) {
2068 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2069 CLAW_RC_HOST_RCV_TOO_SMALL);
2070 printk(KERN_INFO "%s: host write size is too "
2071 "small\n", dev->name);
2072 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2074 if ((p_sysval->read_frame_size < p_env->read_size) &&
2075 (p_env->packing == 0)) {
2076 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2077 CLAW_RC_HOST_RCV_TOO_SMALL);
2078 printk(KERN_INFO "%s: host read size is too "
2079 "small\n", dev->name);
2080 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2082 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
2083 printk(KERN_INFO "%s: CLAW device %.8s: System validate "
2084 "completed.\n", dev->name, temp_ws_name);
2085 printk("%s: sys Validate Rsize:%d Wsize:%d\n", dev->name,
2086 p_sysval->read_frame_size, p_sysval->write_frame_size);
2087 privptr->system_validate_comp = 1;
2088 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2089 p_env->packing = PACKING_ASK;
2090 claw_strt_conn_req(dev);
2092 case SYSTEM_VALIDATE_RESPONSE:
2093 p_sysval = (struct sysval *)&(p_ctlbk->data);
2094 printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
2095 "WS name=%.8s,Host name=%.8s\n",
2098 p_ctlbk->correlator,
2101 p_sysval->host_name);
2102 switch (p_ctlbk->rc) {
2104 printk(KERN_INFO "%s: CLAW device "
2105 "%.8s: System validate "
2107 dev->name, temp_ws_name);
2108 if (privptr->system_validate_comp == 0)
2109 claw_strt_conn_req(dev);
2110 privptr->system_validate_comp = 1;
2112 case CLAW_RC_NAME_MISMATCH:
2113 printk(KERN_INFO "%s: Sys Validate "
2114 "Resp : Host, WS name is "
2118 case CLAW_RC_WRONG_VERSION:
2119 printk(KERN_INFO "%s: Sys Validate "
2120 "Resp : Wrong version\n",
2123 case CLAW_RC_HOST_RCV_TOO_SMALL:
2124 printk(KERN_INFO "%s: Sys Validate "
2125 "Resp : bad frame size\n",
2129 printk(KERN_INFO "%s: Sys Validate "
2131 dev->name, p_ctlbk->rc);
2136 case CONNECTION_REQUEST:
2137 p_connect = (struct conncmd *)&(p_ctlbk->data);
2138 printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2139 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2143 p_ctlbk->correlator,
2144 p_connect->host_name,
2145 p_connect->WS_name);
2146 if (privptr->active_link_ID != 0) {
2147 claw_snd_disc(dev, p_ctlbk);
2148 printk(KERN_INFO "%s: Conn Req error : "
2149 "already logical link is active \n",
2152 if (p_ctlbk->linkid != 1) {
2153 claw_snd_disc(dev, p_ctlbk);
2154 printk(KERN_INFO "%s: Conn Req error : "
2155 "req logical link id is not 1\n",
2158 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2160 claw_snd_disc(dev, p_ctlbk);
2161 printk(KERN_INFO "%s: Conn Resp error: "
2162 "req appl name does not match\n",
2165 claw_send_control(dev,
2166 CONNECTION_CONFIRM, p_ctlbk->linkid,
2167 p_ctlbk->correlator,
2168 0, p_connect->host_name,
2169 p_connect->WS_name);
2170 if (p_env->packing == PACKING_ASK) {
2171 p_env->packing = PACK_SEND;
2172 claw_snd_conn_req(dev, 0);
2174 printk(KERN_INFO "%s: CLAW device %.8s: Connection "
2175 "completed link_id=%d.\n",
2176 dev->name, temp_ws_name,
2178 privptr->active_link_ID = p_ctlbk->linkid;
2179 p_ch = &privptr->channel[WRITE];
2180 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2182 case CONNECTION_RESPONSE:
2183 p_connect = (struct conncmd *)&(p_ctlbk->data);
2184 printk(KERN_INFO "%s: Revc Conn Resp: Vers=%d,link_id=%d,"
2185 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2189 p_ctlbk->correlator,
2191 p_connect->host_name,
2192 p_connect->WS_name);
2194 if (p_ctlbk->rc != 0) {
2195 printk(KERN_INFO "%s: Conn Resp error: rc=%d \n",
2196 dev->name, p_ctlbk->rc);
2200 p_connect->host_name, p_connect->WS_name);
2202 claw_snd_disc(dev, p_ctlbk);
2203 printk(KERN_INFO "%s: Conn Resp error: "
2204 "req appl name does not match\n",
2207 /* should be until CONNECTION_CONFIRM */
2208 privptr->active_link_ID = -(p_ctlbk->linkid);
2210 case CONNECTION_CONFIRM:
2211 p_connect = (struct conncmd *)&(p_ctlbk->data);
2212 printk(KERN_INFO "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2213 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2217 p_ctlbk->correlator,
2218 p_connect->host_name,
2219 p_connect->WS_name);
2220 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2221 privptr->active_link_ID = p_ctlbk->linkid;
2222 if (p_env->packing > PACKING_ASK) {
2223 printk(KERN_INFO "%s: Confirmed Now packing\n",
2225 p_env->packing = DO_PACKED;
2227 p_ch = &privptr->channel[WRITE];
2228 wake_up(&p_ch->wait);
2230 printk(KERN_INFO "%s: Conn confirm: "
2231 "unexpected linkid=%d \n",
2232 dev->name, p_ctlbk->linkid);
2233 claw_snd_disc(dev, p_ctlbk);
2237 printk(KERN_INFO "%s: Disconnect: "
2238 "Vers=%d,link_id=%d,Corr=%d\n",
2239 dev->name, p_ctlbk->version,
2240 p_ctlbk->linkid, p_ctlbk->correlator);
2241 if ((p_ctlbk->linkid == 2) &&
2242 (p_env->packing == PACK_SEND)) {
2243 privptr->active_link_ID = 1;
2244 p_env->packing = DO_PACKED;
2246 privptr->active_link_ID = 0;
2249 printk(KERN_INFO "%s: CLAW ERROR detected\n",
2253 printk(KERN_INFO "%s: Unexpected command code=%d \n",
2254 dev->name, p_ctlbk->command);
2259 } /* end of claw_process_control */
2262 /*-------------------------------------------------------------------*
2263 * claw_send_control *
2265 *--------------------------------------------------------------------*/
2268 claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2269 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2271 struct claw_privbk *privptr;
2272 struct clawctl *p_ctl;
2273 struct sysval *p_sysval;
2274 struct conncmd *p_connect;
2275 struct sk_buff *skb;
2277 CLAW_DBF_TEXT(2, setup, "sndcntl");
2278 privptr = dev->ml_priv;
2279 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2281 p_ctl->command=type;
2282 p_ctl->version=CLAW_VERSION_ID;
2284 p_ctl->correlator=correlator;
2287 p_sysval=(struct sysval *)&p_ctl->data;
2288 p_connect=(struct conncmd *)&p_ctl->data;
2290 switch (p_ctl->command) {
2291 case SYSTEM_VALIDATE_REQUEST:
2292 case SYSTEM_VALIDATE_RESPONSE:
2293 memcpy(&p_sysval->host_name, local_name, 8);
2294 memcpy(&p_sysval->WS_name, remote_name, 8);
2295 if (privptr->p_env->packing > 0) {
2296 p_sysval->read_frame_size=DEF_PACK_BUFSIZE;
2297 p_sysval->write_frame_size=DEF_PACK_BUFSIZE;
2299 /* how big is the biggest group of packets */
2300 p_sysval->read_frame_size=privptr->p_env->read_size;
2301 p_sysval->write_frame_size=privptr->p_env->write_size;
2303 memset(&p_sysval->reserved, 0x00, 4);
2305 case CONNECTION_REQUEST:
2306 case CONNECTION_RESPONSE:
2307 case CONNECTION_CONFIRM:
2309 memcpy(&p_sysval->host_name, local_name, 8);
2310 memcpy(&p_sysval->WS_name, remote_name, 8);
2311 if (privptr->p_env->packing > 0) {
2312 /* How big is the biggest packet */
2313 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2314 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2316 memset(&p_connect->reserved1, 0x00, 4);
2317 memset(&p_connect->reserved2, 0x00, 4);
2324 /* write Control Record to the device */
2327 skb = dev_alloc_skb(sizeof(struct clawctl));
2331 memcpy(skb_put(skb, sizeof(struct clawctl)),
2332 p_ctl, sizeof(struct clawctl));
2333 if (privptr->p_env->packing >= PACK_SEND)
2334 claw_hw_tx(skb, dev, 1);
2336 claw_hw_tx(skb, dev, 0);
2338 } /* end of claw_send_control */
2340 /*-------------------------------------------------------------------*
2341 * claw_snd_conn_req *
2343 *--------------------------------------------------------------------*/
2345 claw_snd_conn_req(struct net_device *dev, __u8 link)
2348 struct claw_privbk *privptr = dev->ml_priv;
2349 struct clawctl *p_ctl;
2351 CLAW_DBF_TEXT(2, setup, "snd_conn");
2353 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2354 p_ctl->linkid = link;
2355 if ( privptr->system_validate_comp==0x00 ) {
2358 if (privptr->p_env->packing == PACKING_ASK )
2359 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2360 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2361 if (privptr->p_env->packing == PACK_SEND) {
2362 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2363 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2365 if (privptr->p_env->packing == 0)
2366 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2367 HOST_APPL_NAME, privptr->p_env->api_type);
2370 } /* end of claw_snd_conn_req */
2373 /*-------------------------------------------------------------------*
2376 *--------------------------------------------------------------------*/
2379 claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2382 struct conncmd * p_connect;
2384 CLAW_DBF_TEXT(2, setup, "snd_dsc");
2385 p_connect=(struct conncmd *)&p_ctl->data;
2387 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2388 p_ctl->correlator, 0,
2389 p_connect->host_name, p_connect->WS_name);
2391 } /* end of claw_snd_disc */
2394 /*-------------------------------------------------------------------*
2395 * claw_snd_sys_validate_rsp *
2397 *--------------------------------------------------------------------*/
2400 claw_snd_sys_validate_rsp(struct net_device *dev,
2401 struct clawctl *p_ctl, __u32 return_code)
2403 struct claw_env * p_env;
2404 struct claw_privbk *privptr;
2407 CLAW_DBF_TEXT(2, setup, "chkresp");
2408 privptr = dev->ml_priv;
2409 p_env=privptr->p_env;
2410 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2415 p_env->adapter_name );
2417 } /* end of claw_snd_sys_validate_rsp */
2419 /*-------------------------------------------------------------------*
2420 * claw_strt_conn_req *
2422 *--------------------------------------------------------------------*/
2425 claw_strt_conn_req(struct net_device *dev )
2429 CLAW_DBF_TEXT(2, setup, "conn_req");
2430 rc=claw_snd_conn_req(dev, 1);
2432 } /* end of claw_strt_conn_req */
2436 /*-------------------------------------------------------------------*
2438 *-------------------------------------------------------------------*/
2441 net_device_stats *claw_stats(struct net_device *dev)
2443 struct claw_privbk *privptr;
2445 CLAW_DBF_TEXT(4, trace, "stats");
2446 privptr = dev->ml_priv;
2447 return &privptr->stats;
2448 } /* end of claw_stats */
2451 /*-------------------------------------------------------------------*
2454 *--------------------------------------------------------------------*/
2456 unpack_read(struct net_device *dev )
2458 struct sk_buff *skb;
2459 struct claw_privbk *privptr;
2460 struct claw_env *p_env;
2461 struct ccwbk *p_this_ccw;
2462 struct ccwbk *p_first_ccw;
2463 struct ccwbk *p_last_ccw;
2464 struct clawph *p_packh;
2466 struct clawctl *p_ctlrec=NULL;
2467 struct device *p_dev;
2472 __u8 mtc_this_frm=0;
2477 CLAW_DBF_TEXT(4, trace, "unpkread");
2482 privptr = dev->ml_priv;
2484 p_dev = &privptr->channel[READ].cdev->dev;
2485 p_env = privptr->p_env;
2486 p_this_ccw=privptr->p_read_active_first;
2488 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
2491 p_this_ccw->header.flag=CLAW_PENDING;
2492 privptr->p_read_active_first=p_this_ccw->next;
2493 p_this_ccw->next=NULL;
2494 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2495 if ((p_env->packing == PACK_SEND) &&
2496 (p_packh->len == 32) &&
2497 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2498 p_packh++; /* peek past pack header */
2499 p_ctlrec = (struct clawctl *)p_packh;
2500 p_packh--; /* un peek */
2501 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2502 (p_ctlrec->command == CONNECTION_CONFIRM))
2503 p_env->packing = DO_PACKED;
2505 if (p_env->packing == DO_PACKED)
2506 link_num=p_packh->link_num;
2508 link_num=p_this_ccw->header.opcode / 8;
2509 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
2511 if (p_this_ccw->header.length!=
2512 privptr->p_env->read_size ) {
2513 printk(KERN_INFO " %s: Invalid frame detected "
2514 "length is %02x\n" ,
2515 dev->name, p_this_ccw->header.length);
2519 if (privptr->mtc_skipping) {
2521 * We're in the mode of skipping past a
2522 * multi-frame message
2523 * that we can't process for some reason or other.
2524 * The first frame without the More-To-Come flag is
2525 * the last frame of the skipped message.
2527 /* in case of More-To-Come not set in this frame */
2528 if (mtc_this_frm==0) {
2529 privptr->mtc_skipping=0; /* Ok, the end */
2530 privptr->mtc_logical_link=-1;
2536 claw_process_control(dev, p_this_ccw);
2537 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
2541 if (p_env->packing == DO_PACKED) {
2542 if (pack_off > p_env->read_size)
2544 p_packd = p_this_ccw->p_buffer+pack_off;
2545 p_packh = (struct clawph *) p_packd;
2546 if ((p_packh->len == 0) || /* all done with this frame? */
2547 (p_packh->flag != 0))
2549 bytes_to_mov = p_packh->len;
2550 pack_off += bytes_to_mov+sizeof(struct clawph);
2553 bytes_to_mov=p_this_ccw->header.length;
2555 if (privptr->mtc_logical_link<0) {
2558 * if More-To-Come is set in this frame then we don't know
2559 * length of entire message, and hence have to allocate
2562 /* We are starting a new envelope */
2563 privptr->mtc_offset=0;
2564 privptr->mtc_logical_link=link_num;
2567 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2569 privptr->stats.rx_frame_errors++;
2572 if (p_env->packing == DO_PACKED) {
2573 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2574 p_packd+sizeof(struct clawph), bytes_to_mov);
2577 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2578 p_this_ccw->p_buffer, bytes_to_mov);
2580 if (mtc_this_frm==0) {
2581 len_of_data=privptr->mtc_offset+bytes_to_mov;
2582 skb=dev_alloc_skb(len_of_data);
2584 memcpy(skb_put(skb,len_of_data),
2585 privptr->p_mtc_envelope,
2588 skb_reset_mac_header(skb);
2589 skb->protocol=htons(ETH_P_IP);
2590 skb->ip_summed=CHECKSUM_UNNECESSARY;
2591 privptr->stats.rx_packets++;
2592 privptr->stats.rx_bytes+=len_of_data;
2596 privptr->stats.rx_dropped++;
2597 printk(KERN_WARNING "%s: %s() low on memory\n",
2598 dev->name,__func__);
2600 privptr->mtc_offset=0;
2601 privptr->mtc_logical_link=-1;
2604 privptr->mtc_offset+=bytes_to_mov;
2606 if (p_env->packing == DO_PACKED)
2610 * Remove ThisCCWblock from active read queue, and add it
2611 * to queue of free blocks to be reused.
2614 p_this_ccw->header.length=0xffff;
2615 p_this_ccw->header.opcode=0xff;
2617 * add this one to the free queue for later reuse
2619 if (p_first_ccw==NULL) {
2620 p_first_ccw = p_this_ccw;
2623 p_last_ccw->next = p_this_ccw;
2625 p_last_ccw = p_this_ccw;
2627 * chain to next block on active read queue
2629 p_this_ccw = privptr->p_read_active_first;
2630 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
2631 } /* end of while */
2633 /* check validity */
2635 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
2636 add_claw_reads(dev, p_first_ccw, p_last_ccw);
2637 claw_strt_read(dev, LOCK_YES);
2639 } /* end of unpack_read */
2641 /*-------------------------------------------------------------------*
2644 *--------------------------------------------------------------------*/
2646 claw_strt_read (struct net_device *dev, int lock )
2650 unsigned long saveflags = 0;
2651 struct claw_privbk *privptr = dev->ml_priv;
2652 struct ccwbk*p_ccwbk;
2654 struct clawh *p_clawh;
2655 p_ch=&privptr->channel[READ];
2657 CLAW_DBF_TEXT(4, trace, "StRdNter");
2658 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2659 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2661 if ((privptr->p_write_active_first!=NULL &&
2662 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2663 (privptr->p_read_active_first!=NULL &&
2664 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2665 p_clawh->flag=CLAW_BUSY; /* 0xff */
2667 if (lock==LOCK_YES) {
2668 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2670 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2671 CLAW_DBF_TEXT(4, trace, "HotRead");
2672 p_ccwbk=privptr->p_read_active_first;
2673 parm = (unsigned long) p_ch;
2674 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2677 ccw_check_return_code(p_ch->cdev, rc);
2681 CLAW_DBF_TEXT(2, trace, "ReadAct");
2684 if (lock==LOCK_YES) {
2685 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2687 CLAW_DBF_TEXT(4, trace, "StRdExit");
2689 } /* end of claw_strt_read */
2691 /*-------------------------------------------------------------------*
2692 * claw_strt_out_IO *
2694 *--------------------------------------------------------------------*/
2697 claw_strt_out_IO( struct net_device *dev )
2701 struct claw_privbk *privptr;
2703 struct ccwbk *p_first_ccw;
2708 privptr = (struct claw_privbk *)dev->ml_priv;
2709 p_ch=&privptr->channel[WRITE];
2711 CLAW_DBF_TEXT(4, trace, "strt_io");
2712 p_first_ccw=privptr->p_write_active_first;
2714 if (p_ch->claw_state == CLAW_STOP)
2716 if (p_first_ccw == NULL) {
2719 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2720 parm = (unsigned long) p_ch;
2721 CLAW_DBF_TEXT(2, trace, "StWrtIO");
2722 rc = ccw_device_start (p_ch->cdev,&p_first_ccw->write, parm,
2725 ccw_check_return_code(p_ch->cdev, rc);
2728 dev->trans_start = jiffies;
2730 } /* end of claw_strt_out_IO */
2732 /*-------------------------------------------------------------------*
2733 * Free write buffers *
2735 *--------------------------------------------------------------------*/
2738 claw_free_wrt_buf( struct net_device *dev )
2741 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
2742 struct ccwbk*p_first_ccw;
2743 struct ccwbk*p_last_ccw;
2744 struct ccwbk*p_this_ccw;
2745 struct ccwbk*p_next_ccw;
2747 CLAW_DBF_TEXT(4, trace, "freewrtb");
2748 /* scan the write queue to free any completed write packets */
2751 p_this_ccw=privptr->p_write_active_first;
2752 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2754 p_next_ccw = p_this_ccw->next;
2755 if (((p_next_ccw!=NULL) &&
2756 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2757 ((p_this_ccw == privptr->p_write_active_last) &&
2758 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2759 /* The next CCW is OK or this is */
2760 /* the last CCW...free it @A1A */
2761 privptr->p_write_active_first=p_this_ccw->next;
2762 p_this_ccw->header.flag=CLAW_PENDING;
2763 p_this_ccw->next=privptr->p_write_free_chain;
2764 privptr->p_write_free_chain=p_this_ccw;
2765 ++privptr->write_free_count;
2766 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2767 p_this_ccw=privptr->p_write_active_first;
2768 privptr->stats.tx_packets++;
2774 if (privptr->write_free_count!=0) {
2775 claw_clearbit_busy(TB_NOBUFFER,dev);
2777 /* whole chain removed? */
2778 if (privptr->p_write_active_first==NULL) {
2779 privptr->p_write_active_last=NULL;
2781 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
2785 /*-------------------------------------------------------------------*
2786 * claw free netdevice *
2788 *--------------------------------------------------------------------*/
2790 claw_free_netdevice(struct net_device * dev, int free_dev)
2792 struct claw_privbk *privptr;
2794 CLAW_DBF_TEXT(2, setup, "free_dev");
2797 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2798 privptr = dev->ml_priv;
2799 if (dev->flags & IFF_RUNNING)
2802 privptr->channel[READ].ndev = NULL; /* say it's free */
2804 dev->ml_priv = NULL;
2810 CLAW_DBF_TEXT(2, setup, "free_ok");
2814 * Claw init netdevice
2815 * Initialize everything of the net device except the name and the
2819 claw_init_netdevice(struct net_device * dev)
2821 CLAW_DBF_TEXT(2, setup, "init_dev");
2822 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2823 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
2824 dev->hard_start_xmit = claw_tx;
2825 dev->open = claw_open;
2826 dev->stop = claw_release;
2827 dev->get_stats = claw_stats;
2828 dev->change_mtu = claw_change_mtu;
2829 dev->hard_header_len = 0;
2831 dev->type = ARPHRD_SLIP;
2832 dev->tx_queue_len = 1300;
2833 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2834 CLAW_DBF_TEXT(2, setup, "initok");
2839 * Init a new channel in the privptr->channel[i].
2841 * @param cdev The ccw_device to be added.
2843 * @return 0 on success, !0 on error.
2846 add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2849 struct ccw_dev_id dev_id;
2851 CLAW_DBF_TEXT_(2, setup, "%s", cdev->dev.bus_id);
2852 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2853 p_ch = &privptr->channel[i];
2855 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", cdev->dev.bus_id);
2856 ccw_device_get_id(cdev, &dev_id);
2857 p_ch->devno = dev_id.devno;
2858 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
2867 * Setup an interface.
2869 * @param cgdev Device to be setup.
2871 * @returns 0 on success, !0 on failure.
2874 claw_new_device(struct ccwgroup_device *cgdev)
2876 struct claw_privbk *privptr;
2877 struct claw_env *p_env;
2878 struct net_device *dev;
2880 struct ccw_dev_id dev_id;
2882 printk(KERN_INFO "claw: add for %s\n",cgdev->cdev[READ]->dev.bus_id);
2883 CLAW_DBF_TEXT(2, setup, "new_dev");
2884 privptr = cgdev->dev.driver_data;
2885 cgdev->cdev[READ]->dev.driver_data = privptr;
2886 cgdev->cdev[WRITE]->dev.driver_data = privptr;
2889 p_env = privptr->p_env;
2890 ccw_device_get_id(cgdev->cdev[READ], &dev_id);
2891 p_env->devno[READ] = dev_id.devno;
2892 ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
2893 p_env->devno[WRITE] = dev_id.devno;
2894 ret = add_channel(cgdev->cdev[0],0,privptr);
2896 ret = add_channel(cgdev->cdev[1],1,privptr);
2899 "add channel failed with ret = %d\n", ret);
2902 ret = ccw_device_set_online(cgdev->cdev[READ]);
2905 "claw: ccw_device_set_online %s READ failed "
2906 "with ret = %d\n",cgdev->cdev[READ]->dev.bus_id,ret);
2909 ret = ccw_device_set_online(cgdev->cdev[WRITE]);
2912 "claw: ccw_device_set_online %s WRITE failed "
2913 "with ret = %d\n",cgdev->cdev[WRITE]->dev.bus_id, ret);
2916 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2918 printk(KERN_WARNING "%s:alloc_netdev failed\n",__func__);
2921 dev->ml_priv = privptr;
2922 cgdev->dev.driver_data = privptr;
2923 cgdev->cdev[READ]->dev.driver_data = privptr;
2924 cgdev->cdev[WRITE]->dev.driver_data = privptr;
2926 SET_NETDEV_DEV(dev, &cgdev->dev);
2927 if (register_netdev(dev) != 0) {
2928 claw_free_netdevice(dev, 1);
2929 CLAW_DBF_TEXT(2, trace, "regfail");
2932 dev->flags &=~IFF_RUNNING;
2933 if (privptr->buffs_alloc == 0) {
2934 ret=init_ccw_bk(dev);
2936 unregister_netdev(dev);
2937 claw_free_netdevice(dev,1);
2938 CLAW_DBF_TEXT(2, trace, "ccwmem");
2942 privptr->channel[READ].ndev = dev;
2943 privptr->channel[WRITE].ndev = dev;
2944 privptr->p_env->ndev = dev;
2946 printk(KERN_INFO "%s:readsize=%d writesize=%d "
2947 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2948 dev->name, p_env->read_size,
2949 p_env->write_size, p_env->read_buffers,
2950 p_env->write_buffers, p_env->devno[READ],
2951 p_env->devno[WRITE]);
2952 printk(KERN_INFO "%s:host_name:%.8s, adapter_name "
2953 ":%.8s api_type: %.8s\n",
2954 dev->name, p_env->host_name,
2955 p_env->adapter_name , p_env->api_type);
2958 ccw_device_set_offline(cgdev->cdev[1]);
2959 ccw_device_set_offline(cgdev->cdev[0]);
2964 claw_purge_skb_queue(struct sk_buff_head *q)
2966 struct sk_buff *skb;
2968 CLAW_DBF_TEXT(4, trace, "purgque");
2969 while ((skb = skb_dequeue(q))) {
2970 atomic_dec(&skb->users);
2971 dev_kfree_skb_any(skb);
2976 * Shutdown an interface.
2978 * @param cgdev Device to be shut down.
2980 * @returns 0 on success, !0 on failure.
2983 claw_shutdown_device(struct ccwgroup_device *cgdev)
2985 struct claw_privbk *priv;
2986 struct net_device *ndev;
2989 CLAW_DBF_TEXT_(2, setup, "%s", cgdev->dev.bus_id);
2990 priv = cgdev->dev.driver_data;
2993 ndev = priv->channel[READ].ndev;
2995 /* Close the device */
2997 "%s: shuting down \n",ndev->name);
2998 if (ndev->flags & IFF_RUNNING)
2999 ret = claw_release(ndev);
3000 ndev->flags &=~IFF_RUNNING;
3001 unregister_netdev(ndev);
3002 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
3003 claw_free_netdevice(ndev, 1);
3004 priv->channel[READ].ndev = NULL;
3005 priv->channel[WRITE].ndev = NULL;
3006 priv->p_env->ndev = NULL;
3008 ccw_device_set_offline(cgdev->cdev[1]);
3009 ccw_device_set_offline(cgdev->cdev[0]);
3014 claw_remove_device(struct ccwgroup_device *cgdev)
3016 struct claw_privbk *priv;
3019 CLAW_DBF_TEXT_(2, setup, "%s", cgdev->dev.bus_id);
3020 priv = cgdev->dev.driver_data;
3022 printk(KERN_INFO "claw: %s() called %s will be removed.\n",
3023 __func__,cgdev->cdev[0]->dev.bus_id);
3024 if (cgdev->state == CCWGROUP_ONLINE)
3025 claw_shutdown_device(cgdev);
3026 claw_remove_files(&cgdev->dev);
3027 kfree(priv->p_mtc_envelope);
3028 priv->p_mtc_envelope=NULL;
3031 kfree(priv->channel[0].irb);
3032 priv->channel[0].irb=NULL;
3033 kfree(priv->channel[1].irb);
3034 priv->channel[1].irb=NULL;
3036 cgdev->dev.driver_data=NULL;
3037 cgdev->cdev[READ]->dev.driver_data = NULL;
3038 cgdev->cdev[WRITE]->dev.driver_data = NULL;
3039 put_device(&cgdev->dev);
3049 claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
3051 struct claw_privbk *priv;
3052 struct claw_env * p_env;
3054 priv = dev->driver_data;
3057 p_env = priv->p_env;
3058 return sprintf(buf, "%s\n",p_env->host_name);
3062 claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
3064 struct claw_privbk *priv;
3065 struct claw_env * p_env;
3067 priv = dev->driver_data;
3070 p_env = priv->p_env;
3071 if (count > MAX_NAME_LEN+1)
3073 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3074 strncpy(p_env->host_name,buf, count);
3075 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3076 p_env->host_name[MAX_NAME_LEN] = 0x00;
3077 CLAW_DBF_TEXT(2, setup, "HstnSet");
3078 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
3083 static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3086 claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
3088 struct claw_privbk *priv;
3089 struct claw_env * p_env;
3091 priv = dev->driver_data;
3094 p_env = priv->p_env;
3095 return sprintf(buf, "%s\n", p_env->adapter_name);
3099 claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
3101 struct claw_privbk *priv;
3102 struct claw_env * p_env;
3104 priv = dev->driver_data;
3107 p_env = priv->p_env;
3108 if (count > MAX_NAME_LEN+1)
3110 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3111 strncpy(p_env->adapter_name,buf, count);
3112 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3113 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
3114 CLAW_DBF_TEXT(2, setup, "AdnSet");
3115 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
3120 static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3123 claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
3125 struct claw_privbk *priv;
3126 struct claw_env * p_env;
3128 priv = dev->driver_data;
3131 p_env = priv->p_env;
3132 return sprintf(buf, "%s\n",
3137 claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
3139 struct claw_privbk *priv;
3140 struct claw_env * p_env;
3142 priv = dev->driver_data;
3145 p_env = priv->p_env;
3146 if (count > MAX_NAME_LEN+1)
3148 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3149 strncpy(p_env->api_type,buf, count);
3150 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3151 p_env->api_type[MAX_NAME_LEN] = 0x00;
3152 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3153 p_env->read_size=DEF_PACK_BUFSIZE;
3154 p_env->write_size=DEF_PACK_BUFSIZE;
3155 p_env->packing=PACKING_ASK;
3156 CLAW_DBF_TEXT(2, setup, "PACKING");
3160 p_env->read_size=CLAW_FRAME_SIZE;
3161 p_env->write_size=CLAW_FRAME_SIZE;
3162 CLAW_DBF_TEXT(2, setup, "ApiSet");
3164 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
3168 static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3171 claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3173 struct claw_privbk *priv;
3174 struct claw_env * p_env;
3176 priv = dev->driver_data;
3179 p_env = priv->p_env;
3180 return sprintf(buf, "%d\n", p_env->write_buffers);
3184 claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
3186 struct claw_privbk *priv;
3187 struct claw_env * p_env;
3190 priv = dev->driver_data;
3193 p_env = priv->p_env;
3194 sscanf(buf, "%i", &nnn);
3195 if (p_env->packing) {
3201 if ((nnn > max ) || (nnn < 2))
3203 p_env->write_buffers = nnn;
3204 CLAW_DBF_TEXT(2, setup, "Wbufset");
3205 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
3209 static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3212 claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3214 struct claw_privbk *priv;
3215 struct claw_env * p_env;
3217 priv = dev->driver_data;
3220 p_env = priv->p_env;
3221 return sprintf(buf, "%d\n", p_env->read_buffers);
3225 claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
3227 struct claw_privbk *priv;
3228 struct claw_env *p_env;
3231 priv = dev->driver_data;
3234 p_env = priv->p_env;
3235 sscanf(buf, "%i", &nnn);
3236 if (p_env->packing) {
3242 if ((nnn > max ) || (nnn < 2))
3244 p_env->read_buffers = nnn;
3245 CLAW_DBF_TEXT(2, setup, "Rbufset");
3246 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
3250 static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3252 static struct attribute *claw_attr[] = {
3253 &dev_attr_read_buffer.attr,
3254 &dev_attr_write_buffer.attr,
3255 &dev_attr_adapter_name.attr,
3256 &dev_attr_api_type.attr,
3257 &dev_attr_host_name.attr,
3261 static struct attribute_group claw_attr_group = {
3266 claw_add_files(struct device *dev)
3268 CLAW_DBF_TEXT(2, setup, "add_file");
3269 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3273 claw_remove_files(struct device *dev)
3275 CLAW_DBF_TEXT(2, setup, "rem_file");
3276 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3279 /*--------------------------------------------------------------------*
3280 * claw_init and cleanup *
3281 *---------------------------------------------------------------------*/
3286 unregister_cu3088_discipline(&claw_group_driver);
3287 claw_unregister_debug_facility();
3288 printk(KERN_INFO "claw: Driver unloaded\n");
3293 * Initialize module.
3294 * This is called just after the module is loaded.
3296 * @return 0 on success, !0 on error.
3302 printk(KERN_INFO "claw: starting driver\n");
3304 ret = claw_register_debug_facility();
3306 printk(KERN_WARNING "claw: %s() debug_register failed %d\n",
3310 CLAW_DBF_TEXT(2, setup, "init_mod");
3311 ret = register_cu3088_discipline(&claw_group_driver);
3313 CLAW_DBF_TEXT(2, setup, "init_bad");
3314 claw_unregister_debug_facility();
3315 printk(KERN_WARNING "claw; %s() cu3088 register failed %d\n",
3321 module_init(claw_init);
3322 module_exit(claw_cleanup);
3324 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3325 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3326 "Copyright 2000,2008 IBM Corporation\n");
3327 MODULE_LICENSE("GPL");