2 * ESCON CLAW network driver
4 * Linux for zSeries version
5 * Copyright IBM Corp. 2002, 2009
6 * Author(s) Original code written by:
7 * Kazuo Iimura <iimura@jp.ibm.com>
9 * Andy Richter <richtera@us.ibm.com>
10 * Marc Price <mwprice@us.ibm.com>
13 * group x.x.rrrr,x.x.wwww
17 * adapter_name aaaaaaaa
21 * group 0.0.0200 0.0.0201
30 * The device id is decided by the order entries
31 * are added to the group the first is claw0 the second claw1
34 * rrrr - the first of 2 consecutive device addresses used for the
36 * The specified address is always used as the input (Read)
37 * channel and the next address is used as the output channel.
39 * wwww - the second of 2 consecutive device addresses used for
41 * The specified address is always used as the output
42 * channel and the previous address is used as the input channel.
44 * read_buffer - specifies number of input buffers to allocate.
45 * write_buffer - specifies number of output buffers to allocate.
46 * host_name - host name
47 * adaptor_name - adaptor name
48 * api_type - API type TCPIP or API will be sent and expected
51 * Note the following requirements:
52 * 1) host_name must match the configured adapter_name on the remote side
53 * 2) adaptor_name must match the configured host name on the remote side
56 * 1.00 Initial release shipped
57 * 1.10 Changes for Buffer allocation
58 * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
59 * 1.25 Added Packing support
63 #define KMSG_COMPONENT "claw"
65 #include <asm/ccwdev.h>
66 #include <asm/ccwgroup.h>
67 #include <asm/debug.h>
68 #include <asm/idals.h>
70 #include <linux/bitops.h>
71 #include <linux/ctype.h>
72 #include <linux/delay.h>
73 #include <linux/errno.h>
74 #include <linux/if_arp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
78 #include <linux/kernel.h>
79 #include <linux/module.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/proc_fs.h>
83 #include <linux/sched.h>
84 #include <linux/signal.h>
85 #include <linux/skbuff.h>
86 #include <linux/slab.h>
87 #include <linux/string.h>
88 #include <linux/tcp.h>
89 #include <linux/timer.h>
90 #include <linux/types.h>
95 CLAW uses the s390dbf file system see claw_trace and claw_setup
98 static char version[] __initdata = "CLAW driver";
99 static char debug_buffer[255];
101 * Debug Facility Stuff
103 static debug_info_t *claw_dbf_setup;
104 static debug_info_t *claw_dbf_trace;
107 * CLAW Debug Facility functions
110 claw_unregister_debug_facility(void)
112 debug_unregister(claw_dbf_setup);
113 debug_unregister(claw_dbf_trace);
117 claw_register_debug_facility(void)
119 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
120 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
121 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
122 claw_unregister_debug_facility();
125 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
126 debug_set_level(claw_dbf_setup, 2);
127 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
128 debug_set_level(claw_dbf_trace, 2);
133 claw_set_busy(struct net_device *dev)
135 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
139 claw_clear_busy(struct net_device *dev)
141 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
142 netif_wake_queue(dev);
146 claw_check_busy(struct net_device *dev)
148 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
152 claw_setbit_busy(int nr,struct net_device *dev)
154 netif_stop_queue(dev);
155 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
159 claw_clearbit_busy(int nr,struct net_device *dev)
161 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
162 netif_wake_queue(dev);
166 claw_test_and_setbit_busy(int nr,struct net_device *dev)
168 netif_stop_queue(dev);
169 return test_and_set_bit(nr,
170 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
174 /* Functions for the DEV methods */
176 static int claw_probe(struct ccwgroup_device *cgdev);
177 static void claw_remove_device(struct ccwgroup_device *cgdev);
178 static void claw_purge_skb_queue(struct sk_buff_head *q);
179 static int claw_new_device(struct ccwgroup_device *cgdev);
180 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
181 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
182 static int claw_change_mtu( struct net_device *dev, int new_mtu);
183 static int claw_open(struct net_device *dev);
184 static void claw_irq_handler(struct ccw_device *cdev,
185 unsigned long intparm, struct irb *irb);
186 static void claw_irq_tasklet ( unsigned long data );
187 static int claw_release(struct net_device *dev);
188 static void claw_write_retry ( struct chbk * p_ch );
189 static void claw_write_next ( struct chbk * p_ch );
190 static void claw_timer ( struct chbk * p_ch );
193 static int add_claw_reads(struct net_device *dev,
194 struct ccwbk* p_first, struct ccwbk* p_last);
195 static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
196 static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
197 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
198 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
199 static int init_ccw_bk(struct net_device *dev);
200 static void probe_error( struct ccwgroup_device *cgdev);
201 static struct net_device_stats *claw_stats(struct net_device *dev);
202 static int pages_to_order_of_mag(int num_of_pages);
203 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
204 /* sysfs Functions */
205 static ssize_t claw_hname_show(struct device *dev,
206 struct device_attribute *attr, char *buf);
207 static ssize_t claw_hname_write(struct device *dev,
208 struct device_attribute *attr,
209 const char *buf, size_t count);
210 static ssize_t claw_adname_show(struct device *dev,
211 struct device_attribute *attr, char *buf);
212 static ssize_t claw_adname_write(struct device *dev,
213 struct device_attribute *attr,
214 const char *buf, size_t count);
215 static ssize_t claw_apname_show(struct device *dev,
216 struct device_attribute *attr, char *buf);
217 static ssize_t claw_apname_write(struct device *dev,
218 struct device_attribute *attr,
219 const char *buf, size_t count);
220 static ssize_t claw_wbuff_show(struct device *dev,
221 struct device_attribute *attr, char *buf);
222 static ssize_t claw_wbuff_write(struct device *dev,
223 struct device_attribute *attr,
224 const char *buf, size_t count);
225 static ssize_t claw_rbuff_show(struct device *dev,
226 struct device_attribute *attr, char *buf);
227 static ssize_t claw_rbuff_write(struct device *dev,
228 struct device_attribute *attr,
229 const char *buf, size_t count);
231 /* Functions for System Validate */
232 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
233 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
234 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
235 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
236 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
237 static int claw_snd_sys_validate_rsp(struct net_device *dev,
238 struct clawctl * p_ctl, __u32 return_code);
239 static int claw_strt_conn_req(struct net_device *dev );
240 static void claw_strt_read(struct net_device *dev, int lock);
241 static void claw_strt_out_IO(struct net_device *dev);
242 static void claw_free_wrt_buf(struct net_device *dev);
244 /* Functions for unpack reads */
245 static void unpack_read(struct net_device *dev);
247 static int claw_pm_prepare(struct ccwgroup_device *gdev)
252 /* the root device for claw group devices */
253 static struct device *claw_root_dev;
257 static struct ccwgroup_driver claw_group_driver = {
259 .owner = THIS_MODULE,
263 .remove = claw_remove_device,
264 .set_online = claw_new_device,
265 .set_offline = claw_shutdown_device,
266 .prepare = claw_pm_prepare,
269 static struct ccw_device_id claw_ids[] = {
270 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
273 MODULE_DEVICE_TABLE(ccw, claw_ids);
275 static struct ccw_driver claw_ccw_driver = {
277 .owner = THIS_MODULE,
281 .probe = ccwgroup_probe_ccwdev,
282 .remove = ccwgroup_remove_ccwdev,
283 .int_class = IRQIO_CLW,
286 static ssize_t claw_driver_group_store(struct device_driver *ddrv,
287 const char *buf, size_t count)
290 err = ccwgroup_create_dev(claw_root_dev, &claw_group_driver, 2, buf);
291 return err ? err : count;
293 static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
295 static struct attribute *claw_drv_attrs[] = {
296 &driver_attr_group.attr,
299 static struct attribute_group claw_drv_attr_group = {
300 .attrs = claw_drv_attrs,
302 static const struct attribute_group *claw_drv_attr_groups[] = {
303 &claw_drv_attr_group,
311 /*-------------------------------------------------------------------*
313 *-------------------------------------------------------------------*/
316 claw_tx(struct sk_buff *skb, struct net_device *dev)
319 struct claw_privbk *privptr = dev->ml_priv;
320 unsigned long saveflags;
323 CLAW_DBF_TEXT(4, trace, "claw_tx");
324 p_ch = &privptr->channel[WRITE_CHANNEL];
325 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
326 rc=claw_hw_tx( skb, dev, 1 );
327 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
328 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
334 } /* end of claw_tx */
336 /*------------------------------------------------------------------*
337 * pack the collect queue into an skb and return it *
338 * If not packing just return the top skb from the queue *
339 *------------------------------------------------------------------*/
341 static struct sk_buff *
342 claw_pack_skb(struct claw_privbk *privptr)
344 struct sk_buff *new_skb,*held_skb;
345 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
346 struct claw_env *p_env = privptr->p_env;
347 int pkt_cnt,pk_ind,so_far;
349 new_skb = NULL; /* assume no dice */
351 CLAW_DBF_TEXT(4, trace, "PackSKBe");
352 if (!skb_queue_empty(&p_ch->collect_queue)) {
354 held_skb = skb_dequeue(&p_ch->collect_queue);
356 dev_kfree_skb_any(held_skb);
359 if (p_env->packing != DO_PACKED)
361 /* get a new SKB we will pack at least one */
362 new_skb = dev_alloc_skb(p_env->write_size);
363 if (new_skb == NULL) {
364 atomic_inc(&held_skb->users);
365 skb_queue_head(&p_ch->collect_queue,held_skb);
368 /* we have packed packet and a place to put it */
371 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
372 while ((pk_ind) && (held_skb != NULL)) {
373 if (held_skb->len+so_far <= p_env->write_size-8) {
374 memcpy(skb_put(new_skb,held_skb->len),
375 held_skb->data,held_skb->len);
376 privptr->stats.tx_packets++;
377 so_far += held_skb->len;
379 dev_kfree_skb_any(held_skb);
380 held_skb = skb_dequeue(&p_ch->collect_queue);
382 atomic_dec(&held_skb->users);
385 atomic_inc(&held_skb->users);
386 skb_queue_head(&p_ch->collect_queue,held_skb);
390 CLAW_DBF_TEXT(4, trace, "PackSKBx");
394 /*-------------------------------------------------------------------*
397 *-------------------------------------------------------------------*/
400 claw_change_mtu(struct net_device *dev, int new_mtu)
402 struct claw_privbk *privptr = dev->ml_priv;
404 CLAW_DBF_TEXT(4, trace, "setmtu");
405 buff_size = privptr->p_env->write_size;
406 if ((new_mtu < 60) || (new_mtu > buff_size)) {
411 } /* end of claw_change_mtu */
414 /*-------------------------------------------------------------------*
417 *-------------------------------------------------------------------*/
419 claw_open(struct net_device *dev)
424 unsigned long saveflags=0;
426 struct claw_privbk *privptr;
427 DECLARE_WAITQUEUE(wait, current);
428 struct timer_list timer;
431 CLAW_DBF_TEXT(4, trace, "open");
432 privptr = (struct claw_privbk *)dev->ml_priv;
433 /* allocate and initialize CCW blocks */
434 if (privptr->buffs_alloc == 0) {
437 CLAW_DBF_TEXT(2, trace, "openmem");
441 privptr->system_validate_comp=0;
442 privptr->release_pend=0;
443 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
444 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
445 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
446 privptr->p_env->packing=PACKING_ASK;
448 privptr->p_env->packing=0;
449 privptr->p_env->read_size=CLAW_FRAME_SIZE;
450 privptr->p_env->write_size=CLAW_FRAME_SIZE;
453 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
454 (unsigned long) &privptr->channel[READ_CHANNEL]);
455 for ( i = 0; i < 2; i++) {
456 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
457 init_waitqueue_head(&privptr->channel[i].wait);
458 /* skb_queue_head_init(&p_ch->io_queue); */
459 if (i == WRITE_CHANNEL)
461 &privptr->channel[WRITE_CHANNEL].collect_queue);
462 privptr->channel[i].flag_a = 0;
463 privptr->channel[i].IO_active = 0;
464 privptr->channel[i].flag &= ~CLAW_TIMER;
466 timer.function = (void *)claw_timer;
467 timer.data = (unsigned long)(&privptr->channel[i]);
468 timer.expires = jiffies + 15*HZ;
470 spin_lock_irqsave(get_ccwdev_lock(
471 privptr->channel[i].cdev), saveflags);
472 parm = (unsigned long) &privptr->channel[i];
473 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
475 add_wait_queue(&privptr->channel[i].wait, &wait);
476 rc = ccw_device_halt(
477 (struct ccw_device *)privptr->channel[i].cdev,parm);
478 set_current_state(TASK_INTERRUPTIBLE);
479 spin_unlock_irqrestore(
480 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
482 remove_wait_queue(&privptr->channel[i].wait, &wait);
484 ccw_check_return_code(privptr->channel[i].cdev, rc);
485 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
488 if ((((privptr->channel[READ_CHANNEL].last_dstat |
489 privptr->channel[WRITE_CHANNEL].last_dstat) &
490 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
491 (((privptr->channel[READ_CHANNEL].flag |
492 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
493 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
494 "%s: remote side is not ready\n", dev->name);
495 CLAW_DBF_TEXT(2, trace, "notrdy");
497 for ( i = 0; i < 2; i++) {
499 get_ccwdev_lock(privptr->channel[i].cdev),
501 parm = (unsigned long) &privptr->channel[i];
502 privptr->channel[i].claw_state = CLAW_STOP;
503 rc = ccw_device_halt(
504 (struct ccw_device *)&privptr->channel[i].cdev,
506 spin_unlock_irqrestore(
507 get_ccwdev_lock(privptr->channel[i].cdev),
510 ccw_check_return_code(
511 privptr->channel[i].cdev, rc);
514 free_pages((unsigned long)privptr->p_buff_ccw,
515 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
516 if (privptr->p_env->read_size < PAGE_SIZE) {
517 free_pages((unsigned long)privptr->p_buff_read,
518 (int)pages_to_order_of_mag(
519 privptr->p_buff_read_num));
522 p_buf=privptr->p_read_active_first;
523 while (p_buf!=NULL) {
524 free_pages((unsigned long)p_buf->p_buffer,
525 (int)pages_to_order_of_mag(
526 privptr->p_buff_pages_perread ));
530 if (privptr->p_env->write_size < PAGE_SIZE ) {
531 free_pages((unsigned long)privptr->p_buff_write,
532 (int)pages_to_order_of_mag(
533 privptr->p_buff_write_num));
536 p_buf=privptr->p_write_active_first;
537 while (p_buf!=NULL) {
538 free_pages((unsigned long)p_buf->p_buffer,
539 (int)pages_to_order_of_mag(
540 privptr->p_buff_pages_perwrite ));
544 privptr->buffs_alloc = 0;
545 privptr->channel[READ_CHANNEL].flag = 0x00;
546 privptr->channel[WRITE_CHANNEL].flag = 0x00;
547 privptr->p_buff_ccw=NULL;
548 privptr->p_buff_read=NULL;
549 privptr->p_buff_write=NULL;
550 claw_clear_busy(dev);
551 CLAW_DBF_TEXT(2, trace, "open EIO");
555 /* Send SystemValidate command */
557 claw_clear_busy(dev);
558 CLAW_DBF_TEXT(4, trace, "openok");
560 } /* end of claw_open */
562 /*-------------------------------------------------------------------*
566 *--------------------------------------------------------------------*/
568 claw_irq_handler(struct ccw_device *cdev,
569 unsigned long intparm, struct irb *irb)
571 struct chbk *p_ch = NULL;
572 struct claw_privbk *privptr = NULL;
573 struct net_device *dev = NULL;
574 struct claw_env *p_env;
575 struct chbk *p_ch_r=NULL;
577 CLAW_DBF_TEXT(4, trace, "clawirq");
578 /* Bypass all 'unsolicited interrupts' */
579 privptr = dev_get_drvdata(&cdev->dev);
581 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
582 " IRQ, c-%02x d-%02x\n",
583 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
584 CLAW_DBF_TEXT(2, trace, "badirq");
588 /* Try to extract channel from driver data. */
589 if (privptr->channel[READ_CHANNEL].cdev == cdev)
590 p_ch = &privptr->channel[READ_CHANNEL];
591 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
592 p_ch = &privptr->channel[WRITE_CHANNEL];
594 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
595 CLAW_DBF_TEXT(2, trace, "badchan");
598 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
600 dev = (struct net_device *) (p_ch->ndev);
601 p_env=privptr->p_env;
603 /* Copy interruption response block. */
604 memcpy(p_ch->irb, irb, sizeof(struct irb));
606 /* Check for good subchannel return code, otherwise info message */
607 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
609 "%s: subchannel check for device: %04x -"
610 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
611 dev->name, p_ch->devno,
612 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
614 CLAW_DBF_TEXT(2, trace, "chanchk");
618 /* Check the reason-code of a unit check */
619 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
620 ccw_check_unit_check(p_ch, irb->ecw[0]);
622 /* State machine to bring the connection up, down and to restart */
623 p_ch->last_dstat = irb->scsw.cmd.dstat;
625 switch (p_ch->claw_state) {
626 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
627 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
628 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
629 (p_ch->irb->scsw.cmd.stctl ==
630 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
632 wake_up(&p_ch->wait); /* wake up claw_release */
633 CLAW_DBF_TEXT(4, trace, "stop");
635 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
636 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
637 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
638 (p_ch->irb->scsw.cmd.stctl ==
639 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
640 CLAW_DBF_TEXT(4, trace, "haltio");
643 if (p_ch->flag == CLAW_READ) {
644 p_ch->claw_state = CLAW_START_READ;
645 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
646 } else if (p_ch->flag == CLAW_WRITE) {
647 p_ch->claw_state = CLAW_START_WRITE;
648 /* send SYSTEM_VALIDATE */
649 claw_strt_read(dev, LOCK_NO);
650 claw_send_control(dev,
651 SYSTEM_VALIDATE_REQUEST,
654 p_env->adapter_name);
656 dev_warn(&cdev->dev, "The CLAW device received"
657 " an unexpected IRQ, "
660 irb->scsw.cmd.dstat);
663 CLAW_DBF_TEXT(4, trace, "haltio");
665 case CLAW_START_READ:
666 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
667 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
668 clear_bit(0, (void *)&p_ch->IO_active);
669 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
670 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
671 (p_ch->irb->ecw[0]) == 0) {
672 privptr->stats.rx_errors++;
674 "%s: Restart is required after remote "
678 CLAW_DBF_TEXT(4, trace, "notrdy");
681 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
682 (p_ch->irb->scsw.cmd.dstat == 0)) {
683 if (test_and_set_bit(CLAW_BH_ACTIVE,
684 (void *)&p_ch->flag_a) == 0)
685 tasklet_schedule(&p_ch->tasklet);
687 CLAW_DBF_TEXT(4, trace, "PCINoBH");
688 CLAW_DBF_TEXT(4, trace, "PCI_read");
691 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
692 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
693 (p_ch->irb->scsw.cmd.stctl ==
694 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
695 CLAW_DBF_TEXT(4, trace, "SPend_rd");
698 clear_bit(0, (void *)&p_ch->IO_active);
699 claw_clearbit_busy(TB_RETRY, dev);
700 if (test_and_set_bit(CLAW_BH_ACTIVE,
701 (void *)&p_ch->flag_a) == 0)
702 tasklet_schedule(&p_ch->tasklet);
704 CLAW_DBF_TEXT(4, trace, "RdBHAct");
705 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
707 case CLAW_START_WRITE:
708 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
710 "%s: Unit Check Occurred in "
711 "write channel\n", dev->name);
712 clear_bit(0, (void *)&p_ch->IO_active);
713 if (p_ch->irb->ecw[0] & 0x80) {
715 "%s: Resetting Event "
716 "occurred:\n", dev->name);
717 init_timer(&p_ch->timer);
718 p_ch->timer.function =
719 (void *)claw_write_retry;
720 p_ch->timer.data = (unsigned long)p_ch;
721 p_ch->timer.expires = jiffies + 10*HZ;
722 add_timer(&p_ch->timer);
724 "%s: write connection "
725 "restarting\n", dev->name);
727 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
730 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
731 clear_bit(0, (void *)&p_ch->IO_active);
733 "%s: Unit Exception "
734 "occurred in write channel\n",
737 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
738 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
739 (p_ch->irb->scsw.cmd.stctl ==
740 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
741 CLAW_DBF_TEXT(4, trace, "writeUE");
744 clear_bit(0, (void *)&p_ch->IO_active);
745 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
746 claw_write_next(p_ch);
747 claw_clearbit_busy(TB_TX, dev);
748 claw_clear_busy(dev);
750 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
751 if (test_and_set_bit(CLAW_BH_ACTIVE,
752 (void *)&p_ch_r->flag_a) == 0)
753 tasklet_schedule(&p_ch_r->tasklet);
754 CLAW_DBF_TEXT(4, trace, "StWtExit");
758 "The CLAW device for %s received an unexpected IRQ\n",
760 CLAW_DBF_TEXT(2, trace, "badIRQ");
764 } /* end of claw_irq_handler */
767 /*-------------------------------------------------------------------*
770 *--------------------------------------------------------------------*/
772 claw_irq_tasklet ( unsigned long data )
775 struct net_device *dev;
777 p_ch = (struct chbk *) data;
778 dev = (struct net_device *)p_ch->ndev;
779 CLAW_DBF_TEXT(4, trace, "IRQtask");
781 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
782 CLAW_DBF_TEXT(4, trace, "TskletXt");
784 } /* end of claw_irq_bh */
786 /*-------------------------------------------------------------------*
789 *--------------------------------------------------------------------*/
791 claw_release(struct net_device *dev)
795 unsigned long saveflags;
797 struct claw_privbk *privptr;
798 DECLARE_WAITQUEUE(wait, current);
799 struct ccwbk* p_this_ccw;
804 privptr = (struct claw_privbk *)dev->ml_priv;
807 CLAW_DBF_TEXT(4, trace, "release");
808 privptr->release_pend=1;
809 claw_setbit_busy(TB_STOP,dev);
810 for ( i = 1; i >=0 ; i--) {
812 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
813 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
814 privptr->channel[i].claw_state = CLAW_STOP;
815 privptr->channel[i].IO_active = 0;
816 parm = (unsigned long) &privptr->channel[i];
817 if (i == WRITE_CHANNEL)
818 claw_purge_skb_queue(
819 &privptr->channel[WRITE_CHANNEL].collect_queue);
820 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
821 if (privptr->system_validate_comp==0x00) /* never opened? */
822 init_waitqueue_head(&privptr->channel[i].wait);
823 add_wait_queue(&privptr->channel[i].wait, &wait);
824 set_current_state(TASK_INTERRUPTIBLE);
825 spin_unlock_irqrestore(
826 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
828 remove_wait_queue(&privptr->channel[i].wait, &wait);
830 ccw_check_return_code(privptr->channel[i].cdev, rc);
833 if (privptr->pk_skb != NULL) {
834 dev_kfree_skb_any(privptr->pk_skb);
835 privptr->pk_skb = NULL;
837 if(privptr->buffs_alloc != 1) {
838 CLAW_DBF_TEXT(4, trace, "none2fre");
841 CLAW_DBF_TEXT(4, trace, "freebufs");
842 if (privptr->p_buff_ccw != NULL) {
843 free_pages((unsigned long)privptr->p_buff_ccw,
844 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
846 CLAW_DBF_TEXT(4, trace, "freeread");
847 if (privptr->p_env->read_size < PAGE_SIZE) {
848 if (privptr->p_buff_read != NULL) {
849 free_pages((unsigned long)privptr->p_buff_read,
850 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
854 p_buf=privptr->p_read_active_first;
855 while (p_buf!=NULL) {
856 free_pages((unsigned long)p_buf->p_buffer,
857 (int)pages_to_order_of_mag(
858 privptr->p_buff_pages_perread ));
862 CLAW_DBF_TEXT(4, trace, "freewrit");
863 if (privptr->p_env->write_size < PAGE_SIZE ) {
864 free_pages((unsigned long)privptr->p_buff_write,
865 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
868 p_buf=privptr->p_write_active_first;
869 while (p_buf!=NULL) {
870 free_pages((unsigned long)p_buf->p_buffer,
871 (int)pages_to_order_of_mag(
872 privptr->p_buff_pages_perwrite ));
876 CLAW_DBF_TEXT(4, trace, "clearptr");
877 privptr->buffs_alloc = 0;
878 privptr->p_buff_ccw=NULL;
879 privptr->p_buff_read=NULL;
880 privptr->p_buff_write=NULL;
881 privptr->system_validate_comp=0;
882 privptr->release_pend=0;
883 /* Remove any writes that were pending and reset all reads */
884 p_this_ccw=privptr->p_read_active_first;
885 while (p_this_ccw!=NULL) {
886 p_this_ccw->header.length=0xffff;
887 p_this_ccw->header.opcode=0xff;
888 p_this_ccw->header.flag=0x00;
889 p_this_ccw=p_this_ccw->next;
892 while (privptr->p_write_active_first!=NULL) {
893 p_this_ccw=privptr->p_write_active_first;
894 p_this_ccw->header.flag=CLAW_PENDING;
895 privptr->p_write_active_first=p_this_ccw->next;
896 p_this_ccw->next=privptr->p_write_free_chain;
897 privptr->p_write_free_chain=p_this_ccw;
898 ++privptr->write_free_count;
900 privptr->p_write_active_last=NULL;
901 privptr->mtc_logical_link = -1;
902 privptr->mtc_skipping = 1;
903 privptr->mtc_offset=0;
905 if (((privptr->channel[READ_CHANNEL].last_dstat |
906 privptr->channel[WRITE_CHANNEL].last_dstat) &
907 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
908 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
909 "Deactivating %s completed with incorrect"
910 " subchannel status "
911 "(read %02x, write %02x)\n",
913 privptr->channel[READ_CHANNEL].last_dstat,
914 privptr->channel[WRITE_CHANNEL].last_dstat);
915 CLAW_DBF_TEXT(2, trace, "badclose");
917 CLAW_DBF_TEXT(4, trace, "rlsexit");
919 } /* end of claw_release */
921 /*-------------------------------------------------------------------*
924 *--------------------------------------------------------------------*/
927 claw_write_retry ( struct chbk *p_ch )
930 struct net_device *dev=p_ch->ndev;
932 CLAW_DBF_TEXT(4, trace, "w_retry");
933 if (p_ch->claw_state == CLAW_STOP) {
936 claw_strt_out_IO( dev );
937 CLAW_DBF_TEXT(4, trace, "rtry_xit");
939 } /* end of claw_write_retry */
942 /*-------------------------------------------------------------------*
945 *--------------------------------------------------------------------*/
948 claw_write_next ( struct chbk * p_ch )
951 struct net_device *dev;
952 struct claw_privbk *privptr=NULL;
953 struct sk_buff *pk_skb;
955 CLAW_DBF_TEXT(4, trace, "claw_wrt");
956 if (p_ch->claw_state == CLAW_STOP)
958 dev = (struct net_device *) p_ch->ndev;
959 privptr = (struct claw_privbk *) dev->ml_priv;
960 claw_free_wrt_buf( dev );
961 if ((privptr->write_free_count > 0) &&
962 !skb_queue_empty(&p_ch->collect_queue)) {
963 pk_skb = claw_pack_skb(privptr);
964 while (pk_skb != NULL) {
965 claw_hw_tx(pk_skb, dev, 1);
966 if (privptr->write_free_count > 0) {
967 pk_skb = claw_pack_skb(privptr);
972 if (privptr->p_write_active_first!=NULL) {
973 claw_strt_out_IO(dev);
976 } /* end of claw_write_next */
978 /*-------------------------------------------------------------------*
981 *--------------------------------------------------------------------*/
984 claw_timer ( struct chbk * p_ch )
986 CLAW_DBF_TEXT(4, trace, "timer");
987 p_ch->flag |= CLAW_TIMER;
988 wake_up(&p_ch->wait);
990 } /* end of claw_timer */
998 /*-------------------------------------------------------------------*
1000 * pages_to_order_of_mag *
1002 * takes a number of pages from 1 to 512 and returns the *
1003 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1004 * of magnitude get_free_pages() has an upper order of 9 *
1005 *--------------------------------------------------------------------*/
1008 pages_to_order_of_mag(int num_of_pages)
1010 int order_of_mag=1; /* assume 2 pages */
1013 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
1014 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1015 /* 512 pages = 2Meg on 4k page systems */
1016 if (num_of_pages >= 512) {return 9; }
1017 /* we have two or more pages order is at least 1 */
1018 for (nump=2 ;nump <= 512;nump*=2) {
1019 if (num_of_pages <= nump)
1023 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
1024 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
1025 return order_of_mag;
1028 /*-------------------------------------------------------------------*
1032 *--------------------------------------------------------------------*/
1034 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1035 struct ccwbk* p_last)
1037 struct claw_privbk *privptr;
1038 struct ccw1 temp_ccw;
1039 struct endccw * p_end;
1040 CLAW_DBF_TEXT(4, trace, "addreads");
1041 privptr = dev->ml_priv;
1042 p_end = privptr->p_end_ccw;
1044 /* first CCW and last CCW contains a new set of read channel programs
1045 * to apend the running channel programs
1047 if ( p_first==NULL) {
1048 CLAW_DBF_TEXT(4, trace, "addexit");
1052 /* set up ending CCW sequence for this segment */
1054 p_end->read1=0x00; /* second ending CCW is now active */
1055 /* reset ending CCWs and setup TIC CCWs */
1056 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1057 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1058 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1059 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1060 p_end->read2_nop2.cda=0;
1061 p_end->read2_nop2.count=1;
1064 p_end->read1=0x01; /* first ending CCW is now active */
1065 /* reset ending CCWs and setup TIC CCWs */
1066 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1067 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1068 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1069 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1070 p_end->read1_nop2.cda=0;
1071 p_end->read1_nop2.count=1;
1074 if ( privptr-> p_read_active_first ==NULL ) {
1075 privptr->p_read_active_first = p_first; /* set new first */
1076 privptr->p_read_active_last = p_last; /* set new last */
1080 /* set up TIC ccw */
1081 temp_ccw.cda= (__u32)__pa(&p_first->read);
1084 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1089 /* first set of CCW's is chained to the new read */
1090 /* chain, so the second set is chained to the active chain. */
1091 /* Therefore modify the second set to point to the new */
1092 /* read chain set up TIC CCWs */
1093 /* make sure we update the CCW so channel doesn't fetch it */
1094 /* when it's only half done */
1095 memcpy( &p_end->read2_nop2, &temp_ccw ,
1096 sizeof(struct ccw1));
1097 privptr->p_read_active_last->r_TIC_1.cda=
1098 (__u32)__pa(&p_first->read);
1099 privptr->p_read_active_last->r_TIC_2.cda=
1100 (__u32)__pa(&p_first->read);
1103 /* make sure we update the CCW so channel doesn't */
1104 /* fetch it when it is only half done */
1105 memcpy( &p_end->read1_nop2, &temp_ccw ,
1106 sizeof(struct ccw1));
1107 privptr->p_read_active_last->r_TIC_1.cda=
1108 (__u32)__pa(&p_first->read);
1109 privptr->p_read_active_last->r_TIC_2.cda=
1110 (__u32)__pa(&p_first->read);
1112 /* chain in new set of blocks */
1113 privptr->p_read_active_last->next = p_first;
1114 privptr->p_read_active_last=p_last;
1115 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1116 CLAW_DBF_TEXT(4, trace, "addexit");
1118 } /* end of add_claw_reads */
1120 /*-------------------------------------------------------------------*
1121 * ccw_check_return_code *
1123 *-------------------------------------------------------------------*/
1126 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1128 CLAW_DBF_TEXT(4, trace, "ccwret");
1129 if (return_code != 0) {
1130 switch (return_code) {
1131 case -EBUSY: /* BUSY is a transient state no action needed */
1134 dev_err(&cdev->dev, "The remote channel adapter is not"
1139 "The status of the remote channel adapter"
1143 dev_err(&cdev->dev, "The common device layer"
1144 " returned error code %d\n",
1148 CLAW_DBF_TEXT(4, trace, "ccwret");
1149 } /* end of ccw_check_return_code */
1151 /*-------------------------------------------------------------------*
1152 * ccw_check_unit_check *
1153 *--------------------------------------------------------------------*/
1156 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1158 struct net_device *ndev = p_ch->ndev;
1159 struct device *dev = &p_ch->cdev->dev;
1161 CLAW_DBF_TEXT(4, trace, "unitchek");
1162 dev_warn(dev, "The communication peer of %s disconnected\n",
1167 dev_warn(dev, "The remote channel adapter for"
1168 " %s has been reset\n",
1171 } else if (sense & 0x20) {
1173 dev_warn(dev, "A data streaming timeout occurred"
1176 } else if (sense & 0x10) {
1177 dev_warn(dev, "The remote channel adapter for %s"
1181 dev_warn(dev, "A data transfer parity error occurred"
1185 } else if (sense & 0x10) {
1186 dev_warn(dev, "A read data parity error occurred"
1191 } /* end of ccw_check_unit_check */
1193 /*-------------------------------------------------------------------*
1195 *--------------------------------------------------------------------*/
1197 find_link(struct net_device *dev, char *host_name, char *ws_name )
1199 struct claw_privbk *privptr;
1200 struct claw_env *p_env;
1203 CLAW_DBF_TEXT(2, setup, "findlink");
1204 privptr = dev->ml_priv;
1205 p_env=privptr->p_env;
1206 switch (p_env->packing)
1209 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1210 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1215 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1216 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1220 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1221 (memcmp(p_env->api_type , ws_name, 8)!=0))
1227 } /* end of find_link */
1229 /*-------------------------------------------------------------------*
1233 *-------------------------------------------------------------------*/
1236 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1239 struct claw_privbk *privptr;
1240 struct ccwbk *p_this_ccw;
1241 struct ccwbk *p_first_ccw;
1242 struct ccwbk *p_last_ccw;
1244 signed long len_of_data;
1245 unsigned long bytesInThisBuffer;
1246 unsigned char *pDataAddress;
1247 struct endccw *pEnd;
1248 struct ccw1 tempCCW;
1249 struct claw_env *p_env;
1250 struct clawph *pk_head;
1253 CLAW_DBF_TEXT(4, trace, "hw_tx");
1254 privptr = (struct claw_privbk *)(dev->ml_priv);
1255 p_env =privptr->p_env;
1256 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1257 /* scan the write queue to free any completed write packets */
1260 if ((p_env->packing >= PACK_SEND) &&
1261 (skb->cb[1] != 'P')) {
1262 skb_push(skb,sizeof(struct clawph));
1263 pk_head=(struct clawph *)skb->data;
1264 pk_head->len=skb->len-sizeof(struct clawph);
1265 if (pk_head->len%4) {
1266 pk_head->len+= 4-(pk_head->len%4);
1267 skb_pad(skb,4-(pk_head->len%4));
1268 skb_put(skb,4-(pk_head->len%4));
1270 if (p_env->packing == DO_PACKED)
1271 pk_head->link_num = linkid;
1273 pk_head->link_num = 0;
1274 pk_head->flag = 0x00;
1279 if (claw_check_busy(dev)) {
1280 if (privptr->write_free_count!=0) {
1281 claw_clear_busy(dev);
1284 claw_strt_out_IO(dev );
1285 claw_free_wrt_buf( dev );
1286 if (privptr->write_free_count==0) {
1287 ch = &privptr->channel[WRITE_CHANNEL];
1288 atomic_inc(&skb->users);
1289 skb_queue_tail(&ch->collect_queue, skb);
1293 claw_clear_busy(dev);
1298 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1299 ch = &privptr->channel[WRITE_CHANNEL];
1300 atomic_inc(&skb->users);
1301 skb_queue_tail(&ch->collect_queue, skb);
1302 claw_strt_out_IO(dev );
1307 /* See how many write buffers are required to hold this data */
1308 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
1310 /* If that number of buffers isn't available, give up for now */
1311 if (privptr->write_free_count < numBuffers ||
1312 privptr->p_write_free_chain == NULL ) {
1314 claw_setbit_busy(TB_NOBUFFER,dev);
1315 ch = &privptr->channel[WRITE_CHANNEL];
1316 atomic_inc(&skb->users);
1317 skb_queue_tail(&ch->collect_queue, skb);
1318 CLAW_DBF_TEXT(2, trace, "clawbusy");
1321 pDataAddress=skb->data;
1322 len_of_data=skb->len;
1324 while (len_of_data > 0) {
1325 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1326 if (p_this_ccw == NULL) { /* lost the race */
1327 ch = &privptr->channel[WRITE_CHANNEL];
1328 atomic_inc(&skb->users);
1329 skb_queue_tail(&ch->collect_queue, skb);
1332 privptr->p_write_free_chain=p_this_ccw->next;
1333 p_this_ccw->next=NULL;
1334 --privptr->write_free_count; /* -1 */
1335 if (len_of_data >= privptr->p_env->write_size)
1336 bytesInThisBuffer = privptr->p_env->write_size;
1338 bytesInThisBuffer = len_of_data;
1339 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1340 len_of_data-=bytesInThisBuffer;
1341 pDataAddress+=(unsigned long)bytesInThisBuffer;
1342 /* setup write CCW */
1343 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1344 if (len_of_data>0) {
1345 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1347 p_this_ccw->write.count=bytesInThisBuffer;
1348 /* now add to end of this chain */
1349 if (p_first_ccw==NULL) {
1350 p_first_ccw=p_this_ccw;
1352 if (p_last_ccw!=NULL) {
1353 p_last_ccw->next=p_this_ccw;
1354 /* set up TIC ccws */
1355 p_last_ccw->w_TIC_1.cda=
1356 (__u32)__pa(&p_this_ccw->write);
1358 p_last_ccw=p_this_ccw; /* save new last block */
1361 /* FirstCCW and LastCCW now contain a new set of write channel
1362 * programs to append to the running channel program
1365 if (p_first_ccw!=NULL) {
1366 /* setup ending ccw sequence for this segment */
1367 pEnd=privptr->p_end_ccw;
1369 pEnd->write1=0x00; /* second end ccw is now active */
1370 /* set up Tic CCWs */
1371 p_last_ccw->w_TIC_1.cda=
1372 (__u32)__pa(&pEnd->write2_nop1);
1373 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1374 pEnd->write2_nop2.flags =
1375 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1376 pEnd->write2_nop2.cda=0;
1377 pEnd->write2_nop2.count=1;
1379 else { /* end of if (pEnd->write1)*/
1380 pEnd->write1=0x01; /* first end ccw is now active */
1381 /* set up Tic CCWs */
1382 p_last_ccw->w_TIC_1.cda=
1383 (__u32)__pa(&pEnd->write1_nop1);
1384 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1385 pEnd->write1_nop2.flags =
1386 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1387 pEnd->write1_nop2.cda=0;
1388 pEnd->write1_nop2.count=1;
1389 } /* end if if (pEnd->write1) */
1391 if (privptr->p_write_active_first==NULL ) {
1392 privptr->p_write_active_first=p_first_ccw;
1393 privptr->p_write_active_last=p_last_ccw;
1396 /* set up Tic CCWs */
1398 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1401 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1406 * first set of ending CCW's is chained to the new write
1407 * chain, so the second set is chained to the active chain
1408 * Therefore modify the second set to point the new write chain.
1409 * make sure we update the CCW atomically
1410 * so channel does not fetch it when it's only half done
1412 memcpy( &pEnd->write2_nop2, &tempCCW ,
1413 sizeof(struct ccw1));
1414 privptr->p_write_active_last->w_TIC_1.cda=
1415 (__u32)__pa(&p_first_ccw->write);
1419 /*make sure we update the CCW atomically
1420 *so channel does not fetch it when it's only half done
1422 memcpy(&pEnd->write1_nop2, &tempCCW ,
1423 sizeof(struct ccw1));
1424 privptr->p_write_active_last->w_TIC_1.cda=
1425 (__u32)__pa(&p_first_ccw->write);
1427 } /* end if if (pEnd->write1) */
1429 privptr->p_write_active_last->next=p_first_ccw;
1430 privptr->p_write_active_last=p_last_ccw;
1433 } /* endif (p_first_ccw!=NULL) */
1434 dev_kfree_skb_any(skb);
1435 claw_strt_out_IO(dev );
1436 /* if write free count is zero , set NOBUFFER */
1437 if (privptr->write_free_count==0) {
1438 claw_setbit_busy(TB_NOBUFFER,dev);
1441 claw_clearbit_busy(TB_TX,dev);
1444 } /* end of claw_hw_tx */
1446 /*-------------------------------------------------------------------*
1450 *--------------------------------------------------------------------*/
1453 init_ccw_bk(struct net_device *dev)
1456 __u32 ccw_blocks_required;
1457 __u32 ccw_blocks_perpage;
1458 __u32 ccw_pages_required;
1459 __u32 claw_reads_perpage=1;
1460 __u32 claw_read_pages;
1461 __u32 claw_writes_perpage=1;
1462 __u32 claw_write_pages;
1464 struct ccwbk*p_free_chain;
1466 struct ccwbk*p_last_CCWB;
1467 struct ccwbk*p_first_CCWB;
1468 struct endccw *p_endccw=NULL;
1469 addr_t real_address;
1470 struct claw_privbk *privptr = dev->ml_priv;
1471 struct clawh *pClawH=NULL;
1472 addr_t real_TIC_address;
1474 CLAW_DBF_TEXT(4, trace, "init_ccw");
1476 /* initialize statistics field */
1477 privptr->active_link_ID=0;
1478 /* initialize ccwbk pointers */
1479 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1480 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1481 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1482 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1483 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1484 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1485 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1486 privptr->buffs_alloc = 0;
1487 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1488 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1489 /* initialize free write ccwbk counter */
1490 privptr->write_free_count=0; /* number of free bufs on write chain */
1494 * We need 1 CCW block for each read buffer, 1 for each
1495 * write buffer, plus 1 for ClawSignalBlock
1497 ccw_blocks_required =
1498 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
1500 * compute number of CCW blocks that will fit in a page
1502 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1504 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
1507 * read and write sizes are set by 2 constants in claw.h
1508 * 4k and 32k. Unpacked values other than 4k are not going to
1509 * provide good performance. With packing buffers support 32k
1512 if (privptr->p_env->read_size < PAGE_SIZE) {
1513 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1514 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1515 claw_reads_perpage);
1517 else { /* > or equal */
1518 privptr->p_buff_pages_perread =
1519 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1520 claw_read_pages = privptr->p_env->read_buffers *
1521 privptr->p_buff_pages_perread;
1523 if (privptr->p_env->write_size < PAGE_SIZE) {
1524 claw_writes_perpage =
1525 PAGE_SIZE / privptr->p_env->write_size;
1526 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1527 claw_writes_perpage);
1530 else { /* > or equal */
1531 privptr->p_buff_pages_perwrite =
1532 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1533 claw_write_pages = privptr->p_env->write_buffers *
1534 privptr->p_buff_pages_perwrite;
1537 * allocate ccw_pages_required
1539 if (privptr->p_buff_ccw==NULL) {
1540 privptr->p_buff_ccw=
1541 (void *)__get_free_pages(__GFP_DMA,
1542 (int)pages_to_order_of_mag(ccw_pages_required ));
1543 if (privptr->p_buff_ccw==NULL) {
1546 privptr->p_buff_ccw_num=ccw_pages_required;
1548 memset(privptr->p_buff_ccw, 0x00,
1549 privptr->p_buff_ccw_num * PAGE_SIZE);
1552 * obtain ending ccw block address
1555 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1556 real_address = (__u32)__pa(privptr->p_end_ccw);
1557 /* Initialize ending CCW block */
1558 p_endccw=privptr->p_end_ccw;
1559 p_endccw->real=real_address;
1560 p_endccw->write1=0x00;
1561 p_endccw->read1=0x00;
1564 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1565 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1566 p_endccw->write1_nop1.count = 1;
1567 p_endccw->write1_nop1.cda = 0;
1570 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1571 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1572 p_endccw->write1_nop2.count = 1;
1573 p_endccw->write1_nop2.cda = 0;
1576 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1577 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1578 p_endccw->write2_nop1.count = 1;
1579 p_endccw->write2_nop1.cda = 0;
1582 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1583 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1584 p_endccw->write2_nop2.count = 1;
1585 p_endccw->write2_nop2.cda = 0;
1588 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1589 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1590 p_endccw->read1_nop1.count = 1;
1591 p_endccw->read1_nop1.cda = 0;
1594 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1595 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1596 p_endccw->read1_nop2.count = 1;
1597 p_endccw->read1_nop2.cda = 0;
1600 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1601 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1602 p_endccw->read2_nop1.count = 1;
1603 p_endccw->read2_nop1.cda = 0;
1606 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1607 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1608 p_endccw->read2_nop2.count = 1;
1609 p_endccw->read2_nop2.cda = 0;
1612 * Build a chain of CCWs
1615 p_buff=privptr->p_buff_ccw;
1618 for (i=0 ; i < ccw_pages_required; i++ ) {
1619 real_address = (__u32)__pa(p_buff);
1621 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1622 p_buf->next = p_free_chain;
1623 p_free_chain = p_buf;
1624 p_buf->real=(__u32)__pa(p_buf);
1630 * Initialize ClawSignalBlock
1633 if (privptr->p_claw_signal_blk==NULL) {
1634 privptr->p_claw_signal_blk=p_free_chain;
1635 p_free_chain=p_free_chain->next;
1636 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1637 pClawH->length=0xffff;
1638 pClawH->opcode=0xff;
1639 pClawH->flag=CLAW_BUSY;
1643 * allocate write_pages_required and add to free chain
1645 if (privptr->p_buff_write==NULL) {
1646 if (privptr->p_env->write_size < PAGE_SIZE) {
1647 privptr->p_buff_write=
1648 (void *)__get_free_pages(__GFP_DMA,
1649 (int)pages_to_order_of_mag(claw_write_pages ));
1650 if (privptr->p_buff_write==NULL) {
1651 privptr->p_buff_ccw=NULL;
1655 * Build CLAW write free chain
1659 memset(privptr->p_buff_write, 0x00,
1660 ccw_pages_required * PAGE_SIZE);
1661 privptr->p_write_free_chain=NULL;
1663 p_buff=privptr->p_buff_write;
1665 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1666 p_buf = p_free_chain; /* get a CCW */
1667 p_free_chain = p_buf->next;
1668 p_buf->next =privptr->p_write_free_chain;
1669 privptr->p_write_free_chain = p_buf;
1670 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1671 p_buf-> write.cda = (__u32)__pa(p_buff);
1672 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1673 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1674 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1675 p_buf-> w_read_FF.count = 1;
1676 p_buf-> w_read_FF.cda =
1677 (__u32)__pa(&p_buf-> header.flag);
1678 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1679 p_buf-> w_TIC_1.flags = 0;
1680 p_buf-> w_TIC_1.count = 0;
1682 if (((unsigned long)p_buff +
1683 privptr->p_env->write_size) >=
1684 ((unsigned long)(p_buff+2*
1685 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1686 p_buff = p_buff+privptr->p_env->write_size;
1690 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1692 privptr->p_write_free_chain=NULL;
1693 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1694 p_buff=(void *)__get_free_pages(__GFP_DMA,
1695 (int)pages_to_order_of_mag(
1696 privptr->p_buff_pages_perwrite) );
1698 free_pages((unsigned long)privptr->p_buff_ccw,
1699 (int)pages_to_order_of_mag(
1700 privptr->p_buff_ccw_num));
1701 privptr->p_buff_ccw=NULL;
1702 p_buf=privptr->p_buff_write;
1703 while (p_buf!=NULL) {
1704 free_pages((unsigned long)
1706 (int)pages_to_order_of_mag(
1707 privptr->p_buff_pages_perwrite));
1711 } /* Error on get_pages */
1712 memset(p_buff, 0x00, privptr->p_env->write_size );
1713 p_buf = p_free_chain;
1714 p_free_chain = p_buf->next;
1715 p_buf->next = privptr->p_write_free_chain;
1716 privptr->p_write_free_chain = p_buf;
1717 privptr->p_buff_write = p_buf;
1718 p_buf->p_buffer=(struct clawbuf *)p_buff;
1719 p_buf-> write.cda = (__u32)__pa(p_buff);
1720 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1721 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1722 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1723 p_buf-> w_read_FF.count = 1;
1724 p_buf-> w_read_FF.cda =
1725 (__u32)__pa(&p_buf-> header.flag);
1726 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1727 p_buf-> w_TIC_1.flags = 0;
1728 p_buf-> w_TIC_1.count = 0;
1729 } /* for all write_buffers */
1731 } /* else buffers are PAGE_SIZE or bigger */
1734 privptr->p_buff_write_num=claw_write_pages;
1735 privptr->write_free_count=privptr->p_env->write_buffers;
1739 * allocate read_pages_required and chain to free chain
1741 if (privptr->p_buff_read==NULL) {
1742 if (privptr->p_env->read_size < PAGE_SIZE) {
1743 privptr->p_buff_read=
1744 (void *)__get_free_pages(__GFP_DMA,
1745 (int)pages_to_order_of_mag(claw_read_pages) );
1746 if (privptr->p_buff_read==NULL) {
1747 free_pages((unsigned long)privptr->p_buff_ccw,
1748 (int)pages_to_order_of_mag(
1749 privptr->p_buff_ccw_num));
1750 /* free the write pages size is < page size */
1751 free_pages((unsigned long)privptr->p_buff_write,
1752 (int)pages_to_order_of_mag(
1753 privptr->p_buff_write_num));
1754 privptr->p_buff_ccw=NULL;
1755 privptr->p_buff_write=NULL;
1758 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1759 privptr->p_buff_read_num=claw_read_pages;
1761 * Build CLAW read free chain
1764 p_buff=privptr->p_buff_read;
1765 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1766 p_buf = p_free_chain;
1767 p_free_chain = p_buf->next;
1769 if (p_last_CCWB==NULL) {
1775 p_buf->next=p_first_CCWB;
1777 (__u32)__pa(&p_first_CCWB -> read );
1782 p_buf->p_buffer=(struct clawbuf *)p_buff;
1783 /* initialize read command */
1784 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1785 p_buf-> read.cda = (__u32)__pa(p_buff);
1786 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1787 p_buf-> read.count = privptr->p_env->read_size;
1789 /* initialize read_h command */
1790 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1791 p_buf-> read_h.cda =
1792 (__u32)__pa(&(p_buf->header));
1793 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1794 p_buf-> read_h.count = sizeof(struct clawh);
1796 /* initialize Signal command */
1797 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1798 p_buf-> signal.cda =
1799 (__u32)__pa(&(pClawH->flag));
1800 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1801 p_buf-> signal.count = 1;
1803 /* initialize r_TIC_1 command */
1804 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1805 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1806 p_buf-> r_TIC_1.flags = 0;
1807 p_buf-> r_TIC_1.count = 0;
1809 /* initialize r_read_FF command */
1810 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1811 p_buf-> r_read_FF.cda =
1812 (__u32)__pa(&(pClawH->flag));
1813 p_buf-> r_read_FF.flags =
1814 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1815 p_buf-> r_read_FF.count = 1;
1817 /* initialize r_TIC_2 */
1818 memcpy(&p_buf->r_TIC_2,
1819 &p_buf->r_TIC_1, sizeof(struct ccw1));
1821 /* initialize Header */
1822 p_buf->header.length=0xffff;
1823 p_buf->header.opcode=0xff;
1824 p_buf->header.flag=CLAW_PENDING;
1826 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1827 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1830 p_buff= p_buff+privptr->p_env->read_size;
1834 (void *)((unsigned long)
1835 (p_buff+2*(privptr->p_env->read_size)-1)
1838 } /* for read_buffers */
1839 } /* read_size < PAGE_SIZE */
1840 else { /* read Size >= PAGE_SIZE */
1841 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1842 p_buff = (void *)__get_free_pages(__GFP_DMA,
1843 (int)pages_to_order_of_mag(
1844 privptr->p_buff_pages_perread));
1846 free_pages((unsigned long)privptr->p_buff_ccw,
1847 (int)pages_to_order_of_mag(privptr->
1849 /* free the write pages */
1850 p_buf=privptr->p_buff_write;
1851 while (p_buf!=NULL) {
1853 (unsigned long)p_buf->p_buffer,
1854 (int)pages_to_order_of_mag(
1855 privptr->p_buff_pages_perwrite));
1858 /* free any read pages already alloc */
1859 p_buf=privptr->p_buff_read;
1860 while (p_buf!=NULL) {
1862 (unsigned long)p_buf->p_buffer,
1863 (int)pages_to_order_of_mag(
1864 privptr->p_buff_pages_perread));
1867 privptr->p_buff_ccw=NULL;
1868 privptr->p_buff_write=NULL;
1871 memset(p_buff, 0x00, privptr->p_env->read_size);
1872 p_buf = p_free_chain;
1873 privptr->p_buff_read = p_buf;
1874 p_free_chain = p_buf->next;
1876 if (p_last_CCWB==NULL) {
1882 p_buf->next=p_first_CCWB;
1885 &p_first_CCWB -> read );
1889 /* save buff address */
1890 p_buf->p_buffer=(struct clawbuf *)p_buff;
1891 /* initialize read command */
1892 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1893 p_buf-> read.cda = (__u32)__pa(p_buff);
1894 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1895 p_buf-> read.count = privptr->p_env->read_size;
1897 /* initialize read_h command */
1898 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1899 p_buf-> read_h.cda =
1900 (__u32)__pa(&(p_buf->header));
1901 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1902 p_buf-> read_h.count = sizeof(struct clawh);
1904 /* initialize Signal command */
1905 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1906 p_buf-> signal.cda =
1907 (__u32)__pa(&(pClawH->flag));
1908 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1909 p_buf-> signal.count = 1;
1911 /* initialize r_TIC_1 command */
1912 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1913 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1914 p_buf-> r_TIC_1.flags = 0;
1915 p_buf-> r_TIC_1.count = 0;
1917 /* initialize r_read_FF command */
1918 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1919 p_buf-> r_read_FF.cda =
1920 (__u32)__pa(&(pClawH->flag));
1921 p_buf-> r_read_FF.flags =
1922 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1923 p_buf-> r_read_FF.count = 1;
1925 /* initialize r_TIC_2 */
1926 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1927 sizeof(struct ccw1));
1929 /* initialize Header */
1930 p_buf->header.length=0xffff;
1931 p_buf->header.opcode=0xff;
1932 p_buf->header.flag=CLAW_PENDING;
1934 } /* For read_buffers */
1935 } /* read_size >= PAGE_SIZE */
1936 } /* pBuffread = NULL */
1937 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1938 privptr->buffs_alloc = 1;
1941 } /* end of init_ccw_bk */
1943 /*-------------------------------------------------------------------*
1947 *--------------------------------------------------------------------*/
1950 probe_error( struct ccwgroup_device *cgdev)
1952 struct claw_privbk *privptr;
1954 CLAW_DBF_TEXT(4, trace, "proberr");
1955 privptr = dev_get_drvdata(&cgdev->dev);
1956 if (privptr != NULL) {
1957 dev_set_drvdata(&cgdev->dev, NULL);
1958 kfree(privptr->p_env);
1959 kfree(privptr->p_mtc_envelope);
1964 /*-------------------------------------------------------------------*
1965 * claw_process_control *
1968 *--------------------------------------------------------------------*/
1971 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
1974 struct clawbuf *p_buf;
1975 struct clawctl ctlbk;
1976 struct clawctl *p_ctlbk;
1977 char temp_host_name[8];
1978 char temp_ws_name[8];
1979 struct claw_privbk *privptr;
1980 struct claw_env *p_env;
1981 struct sysval *p_sysval;
1982 struct conncmd *p_connect=NULL;
1984 struct chbk *p_ch = NULL;
1985 struct device *tdev;
1986 CLAW_DBF_TEXT(2, setup, "clw_cntl");
1987 udelay(1000); /* Wait a ms for the control packets to
1988 *catch up to each other */
1989 privptr = dev->ml_priv;
1990 p_env=privptr->p_env;
1991 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
1992 memcpy( &temp_host_name, p_env->host_name, 8);
1993 memcpy( &temp_ws_name, p_env->adapter_name , 8);
1994 dev_info(tdev, "%s: CLAW device %.8s: "
1995 "Received Control Packet\n",
1996 dev->name, temp_ws_name);
1997 if (privptr->release_pend==1) {
2000 p_buf=p_ccw->p_buffer;
2002 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2003 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2005 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2007 switch (p_ctlbk->command)
2009 case SYSTEM_VALIDATE_REQUEST:
2010 if (p_ctlbk->version != CLAW_VERSION_ID) {
2011 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2012 CLAW_RC_WRONG_VERSION);
2013 dev_warn(tdev, "The communication peer of %s"
2014 " uses an incorrect API version %d\n",
2015 dev->name, p_ctlbk->version);
2017 p_sysval = (struct sysval *)&(p_ctlbk->data);
2018 dev_info(tdev, "%s: Recv Sys Validate Request: "
2019 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2021 dev->name, p_ctlbk->version,
2023 p_ctlbk->correlator,
2025 p_sysval->host_name);
2026 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2027 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2028 CLAW_RC_NAME_MISMATCH);
2029 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2030 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2031 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
2033 "Host name %s for %s does not match the"
2034 " remote adapter name %s\n",
2035 p_sysval->host_name,
2039 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2040 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2041 CLAW_RC_NAME_MISMATCH);
2042 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2043 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2044 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
2045 dev_warn(tdev, "Adapter name %s for %s does not match"
2046 " the remote host name %s\n",
2051 if ((p_sysval->write_frame_size < p_env->write_size) &&
2052 (p_env->packing == 0)) {
2053 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2054 CLAW_RC_HOST_RCV_TOO_SMALL);
2056 "The local write buffer is smaller than the"
2057 " remote read buffer\n");
2058 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2060 if ((p_sysval->read_frame_size < p_env->read_size) &&
2061 (p_env->packing == 0)) {
2062 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2063 CLAW_RC_HOST_RCV_TOO_SMALL);
2065 "The local read buffer is smaller than the"
2066 " remote write buffer\n");
2067 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2069 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
2071 "CLAW device %.8s: System validate"
2072 " completed.\n", temp_ws_name);
2074 "%s: sys Validate Rsize:%d Wsize:%d\n",
2075 dev->name, p_sysval->read_frame_size,
2076 p_sysval->write_frame_size);
2077 privptr->system_validate_comp = 1;
2078 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2079 p_env->packing = PACKING_ASK;
2080 claw_strt_conn_req(dev);
2082 case SYSTEM_VALIDATE_RESPONSE:
2083 p_sysval = (struct sysval *)&(p_ctlbk->data);
2085 "Settings for %s validated (version=%d, "
2086 "remote device=%d, rc=%d, adapter name=%.8s, "
2087 "host name=%.8s)\n",
2090 p_ctlbk->correlator,
2093 p_sysval->host_name);
2094 switch (p_ctlbk->rc) {
2096 dev_info(tdev, "%s: CLAW device "
2097 "%.8s: System validate completed.\n",
2098 dev->name, temp_ws_name);
2099 if (privptr->system_validate_comp == 0)
2100 claw_strt_conn_req(dev);
2101 privptr->system_validate_comp = 1;
2103 case CLAW_RC_NAME_MISMATCH:
2104 dev_warn(tdev, "Validating %s failed because of"
2105 " a host or adapter name mismatch\n",
2108 case CLAW_RC_WRONG_VERSION:
2109 dev_warn(tdev, "Validating %s failed because of a"
2110 " version conflict\n",
2113 case CLAW_RC_HOST_RCV_TOO_SMALL:
2114 dev_warn(tdev, "Validating %s failed because of a"
2115 " frame size conflict\n",
2119 dev_warn(tdev, "The communication peer of %s rejected"
2120 " the connection\n",
2126 case CONNECTION_REQUEST:
2127 p_connect = (struct conncmd *)&(p_ctlbk->data);
2128 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2129 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2133 p_ctlbk->correlator,
2134 p_connect->host_name,
2135 p_connect->WS_name);
2136 if (privptr->active_link_ID != 0) {
2137 claw_snd_disc(dev, p_ctlbk);
2138 dev_info(tdev, "%s rejected a connection request"
2139 " because it is already active\n",
2142 if (p_ctlbk->linkid != 1) {
2143 claw_snd_disc(dev, p_ctlbk);
2144 dev_info(tdev, "%s rejected a request to open multiple"
2148 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2150 claw_snd_disc(dev, p_ctlbk);
2151 dev_info(tdev, "%s rejected a connection request"
2152 " because of a type mismatch\n",
2155 claw_send_control(dev,
2156 CONNECTION_CONFIRM, p_ctlbk->linkid,
2157 p_ctlbk->correlator,
2158 0, p_connect->host_name,
2159 p_connect->WS_name);
2160 if (p_env->packing == PACKING_ASK) {
2161 p_env->packing = PACK_SEND;
2162 claw_snd_conn_req(dev, 0);
2164 dev_info(tdev, "%s: CLAW device %.8s: Connection "
2165 "completed link_id=%d.\n",
2166 dev->name, temp_ws_name,
2168 privptr->active_link_ID = p_ctlbk->linkid;
2169 p_ch = &privptr->channel[WRITE_CHANNEL];
2170 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2172 case CONNECTION_RESPONSE:
2173 p_connect = (struct conncmd *)&(p_ctlbk->data);
2174 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
2175 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2179 p_ctlbk->correlator,
2181 p_connect->host_name,
2182 p_connect->WS_name);
2184 if (p_ctlbk->rc != 0) {
2185 dev_warn(tdev, "The communication peer of %s rejected"
2186 " a connection request\n",
2191 p_connect->host_name, p_connect->WS_name);
2193 claw_snd_disc(dev, p_ctlbk);
2194 dev_warn(tdev, "The communication peer of %s"
2195 " rejected a connection "
2196 "request because of a type mismatch\n",
2199 /* should be until CONNECTION_CONFIRM */
2200 privptr->active_link_ID = -(p_ctlbk->linkid);
2202 case CONNECTION_CONFIRM:
2203 p_connect = (struct conncmd *)&(p_ctlbk->data);
2205 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2206 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2210 p_ctlbk->correlator,
2211 p_connect->host_name,
2212 p_connect->WS_name);
2213 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2214 privptr->active_link_ID = p_ctlbk->linkid;
2215 if (p_env->packing > PACKING_ASK) {
2217 "%s: Confirmed Now packing\n", dev->name);
2218 p_env->packing = DO_PACKED;
2220 p_ch = &privptr->channel[WRITE_CHANNEL];
2221 wake_up(&p_ch->wait);
2223 dev_warn(tdev, "Activating %s failed because of"
2224 " an incorrect link ID=%d\n",
2225 dev->name, p_ctlbk->linkid);
2226 claw_snd_disc(dev, p_ctlbk);
2230 dev_info(tdev, "%s: Disconnect: "
2231 "Vers=%d,link_id=%d,Corr=%d\n",
2232 dev->name, p_ctlbk->version,
2233 p_ctlbk->linkid, p_ctlbk->correlator);
2234 if ((p_ctlbk->linkid == 2) &&
2235 (p_env->packing == PACK_SEND)) {
2236 privptr->active_link_ID = 1;
2237 p_env->packing = DO_PACKED;
2239 privptr->active_link_ID = 0;
2242 dev_warn(tdev, "The communication peer of %s failed\n",
2246 dev_warn(tdev, "The communication peer of %s sent"
2247 " an unknown command code\n",
2253 } /* end of claw_process_control */
2256 /*-------------------------------------------------------------------*
2257 * claw_send_control *
2259 *--------------------------------------------------------------------*/
2262 claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2263 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2265 struct claw_privbk *privptr;
2266 struct clawctl *p_ctl;
2267 struct sysval *p_sysval;
2268 struct conncmd *p_connect;
2269 struct sk_buff *skb;
2271 CLAW_DBF_TEXT(2, setup, "sndcntl");
2272 privptr = dev->ml_priv;
2273 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2275 p_ctl->command=type;
2276 p_ctl->version=CLAW_VERSION_ID;
2278 p_ctl->correlator=correlator;
2281 p_sysval=(struct sysval *)&p_ctl->data;
2282 p_connect=(struct conncmd *)&p_ctl->data;
2284 switch (p_ctl->command) {
2285 case SYSTEM_VALIDATE_REQUEST:
2286 case SYSTEM_VALIDATE_RESPONSE:
2287 memcpy(&p_sysval->host_name, local_name, 8);
2288 memcpy(&p_sysval->WS_name, remote_name, 8);
2289 if (privptr->p_env->packing > 0) {
2290 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2291 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
2293 /* how big is the biggest group of packets */
2294 p_sysval->read_frame_size =
2295 privptr->p_env->read_size;
2296 p_sysval->write_frame_size =
2297 privptr->p_env->write_size;
2299 memset(&p_sysval->reserved, 0x00, 4);
2301 case CONNECTION_REQUEST:
2302 case CONNECTION_RESPONSE:
2303 case CONNECTION_CONFIRM:
2305 memcpy(&p_sysval->host_name, local_name, 8);
2306 memcpy(&p_sysval->WS_name, remote_name, 8);
2307 if (privptr->p_env->packing > 0) {
2308 /* How big is the biggest packet */
2309 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2310 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2312 memset(&p_connect->reserved1, 0x00, 4);
2313 memset(&p_connect->reserved2, 0x00, 4);
2320 /* write Control Record to the device */
2323 skb = dev_alloc_skb(sizeof(struct clawctl));
2327 memcpy(skb_put(skb, sizeof(struct clawctl)),
2328 p_ctl, sizeof(struct clawctl));
2329 if (privptr->p_env->packing >= PACK_SEND)
2330 claw_hw_tx(skb, dev, 1);
2332 claw_hw_tx(skb, dev, 0);
2334 } /* end of claw_send_control */
2336 /*-------------------------------------------------------------------*
2337 * claw_snd_conn_req *
2339 *--------------------------------------------------------------------*/
2341 claw_snd_conn_req(struct net_device *dev, __u8 link)
2344 struct claw_privbk *privptr = dev->ml_priv;
2345 struct clawctl *p_ctl;
2347 CLAW_DBF_TEXT(2, setup, "snd_conn");
2349 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2350 p_ctl->linkid = link;
2351 if ( privptr->system_validate_comp==0x00 ) {
2354 if (privptr->p_env->packing == PACKING_ASK )
2355 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2356 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2357 if (privptr->p_env->packing == PACK_SEND) {
2358 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2359 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2361 if (privptr->p_env->packing == 0)
2362 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2363 HOST_APPL_NAME, privptr->p_env->api_type);
2366 } /* end of claw_snd_conn_req */
2369 /*-------------------------------------------------------------------*
2372 *--------------------------------------------------------------------*/
2375 claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2378 struct conncmd * p_connect;
2380 CLAW_DBF_TEXT(2, setup, "snd_dsc");
2381 p_connect=(struct conncmd *)&p_ctl->data;
2383 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2384 p_ctl->correlator, 0,
2385 p_connect->host_name, p_connect->WS_name);
2387 } /* end of claw_snd_disc */
2390 /*-------------------------------------------------------------------*
2391 * claw_snd_sys_validate_rsp *
2393 *--------------------------------------------------------------------*/
2396 claw_snd_sys_validate_rsp(struct net_device *dev,
2397 struct clawctl *p_ctl, __u32 return_code)
2399 struct claw_env * p_env;
2400 struct claw_privbk *privptr;
2403 CLAW_DBF_TEXT(2, setup, "chkresp");
2404 privptr = dev->ml_priv;
2405 p_env=privptr->p_env;
2406 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2411 p_env->adapter_name );
2413 } /* end of claw_snd_sys_validate_rsp */
2415 /*-------------------------------------------------------------------*
2416 * claw_strt_conn_req *
2418 *--------------------------------------------------------------------*/
2421 claw_strt_conn_req(struct net_device *dev )
2425 CLAW_DBF_TEXT(2, setup, "conn_req");
2426 rc=claw_snd_conn_req(dev, 1);
2428 } /* end of claw_strt_conn_req */
2432 /*-------------------------------------------------------------------*
2434 *-------------------------------------------------------------------*/
2437 net_device_stats *claw_stats(struct net_device *dev)
2439 struct claw_privbk *privptr;
2441 CLAW_DBF_TEXT(4, trace, "stats");
2442 privptr = dev->ml_priv;
2443 return &privptr->stats;
2444 } /* end of claw_stats */
2447 /*-------------------------------------------------------------------*
2450 *--------------------------------------------------------------------*/
2452 unpack_read(struct net_device *dev )
2454 struct sk_buff *skb;
2455 struct claw_privbk *privptr;
2456 struct claw_env *p_env;
2457 struct ccwbk *p_this_ccw;
2458 struct ccwbk *p_first_ccw;
2459 struct ccwbk *p_last_ccw;
2460 struct clawph *p_packh;
2462 struct clawctl *p_ctlrec=NULL;
2463 struct device *p_dev;
2468 __u8 mtc_this_frm=0;
2473 CLAW_DBF_TEXT(4, trace, "unpkread");
2478 privptr = dev->ml_priv;
2480 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
2481 p_env = privptr->p_env;
2482 p_this_ccw=privptr->p_read_active_first;
2483 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
2486 p_this_ccw->header.flag=CLAW_PENDING;
2487 privptr->p_read_active_first=p_this_ccw->next;
2488 p_this_ccw->next=NULL;
2489 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2490 if ((p_env->packing == PACK_SEND) &&
2491 (p_packh->len == 32) &&
2492 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2493 p_packh++; /* peek past pack header */
2494 p_ctlrec = (struct clawctl *)p_packh;
2495 p_packh--; /* un peek */
2496 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2497 (p_ctlrec->command == CONNECTION_CONFIRM))
2498 p_env->packing = DO_PACKED;
2500 if (p_env->packing == DO_PACKED)
2501 link_num=p_packh->link_num;
2503 link_num=p_this_ccw->header.opcode / 8;
2504 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
2506 if (p_this_ccw->header.length!=
2507 privptr->p_env->read_size ) {
2509 "The communication peer of %s"
2511 " frame of length %02x\n",
2512 dev->name, p_this_ccw->header.length);
2516 if (privptr->mtc_skipping) {
2518 * We're in the mode of skipping past a
2519 * multi-frame message
2520 * that we can't process for some reason or other.
2521 * The first frame without the More-To-Come flag is
2522 * the last frame of the skipped message.
2524 /* in case of More-To-Come not set in this frame */
2525 if (mtc_this_frm==0) {
2526 privptr->mtc_skipping=0; /* Ok, the end */
2527 privptr->mtc_logical_link=-1;
2533 claw_process_control(dev, p_this_ccw);
2534 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
2538 if (p_env->packing == DO_PACKED) {
2539 if (pack_off > p_env->read_size)
2541 p_packd = p_this_ccw->p_buffer+pack_off;
2542 p_packh = (struct clawph *) p_packd;
2543 if ((p_packh->len == 0) || /* done with this frame? */
2544 (p_packh->flag != 0))
2546 bytes_to_mov = p_packh->len;
2547 pack_off += bytes_to_mov+sizeof(struct clawph);
2550 bytes_to_mov=p_this_ccw->header.length;
2552 if (privptr->mtc_logical_link<0) {
2555 * if More-To-Come is set in this frame then we don't know
2556 * length of entire message, and hence have to allocate
2559 /* We are starting a new envelope */
2560 privptr->mtc_offset=0;
2561 privptr->mtc_logical_link=link_num;
2564 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2566 privptr->stats.rx_frame_errors++;
2569 if (p_env->packing == DO_PACKED) {
2570 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2571 p_packd+sizeof(struct clawph), bytes_to_mov);
2574 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2575 p_this_ccw->p_buffer, bytes_to_mov);
2577 if (mtc_this_frm==0) {
2578 len_of_data=privptr->mtc_offset+bytes_to_mov;
2579 skb=dev_alloc_skb(len_of_data);
2581 memcpy(skb_put(skb,len_of_data),
2582 privptr->p_mtc_envelope,
2585 skb_reset_mac_header(skb);
2586 skb->protocol=htons(ETH_P_IP);
2587 skb->ip_summed=CHECKSUM_UNNECESSARY;
2588 privptr->stats.rx_packets++;
2589 privptr->stats.rx_bytes+=len_of_data;
2593 dev_info(p_dev, "Allocating a buffer for"
2594 " incoming data failed\n");
2595 privptr->stats.rx_dropped++;
2597 privptr->mtc_offset=0;
2598 privptr->mtc_logical_link=-1;
2601 privptr->mtc_offset+=bytes_to_mov;
2603 if (p_env->packing == DO_PACKED)
2607 * Remove ThisCCWblock from active read queue, and add it
2608 * to queue of free blocks to be reused.
2611 p_this_ccw->header.length=0xffff;
2612 p_this_ccw->header.opcode=0xff;
2614 * add this one to the free queue for later reuse
2616 if (p_first_ccw==NULL) {
2617 p_first_ccw = p_this_ccw;
2620 p_last_ccw->next = p_this_ccw;
2622 p_last_ccw = p_this_ccw;
2624 * chain to next block on active read queue
2626 p_this_ccw = privptr->p_read_active_first;
2627 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
2628 } /* end of while */
2630 /* check validity */
2632 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
2633 add_claw_reads(dev, p_first_ccw, p_last_ccw);
2634 claw_strt_read(dev, LOCK_YES);
2636 } /* end of unpack_read */
2638 /*-------------------------------------------------------------------*
2641 *--------------------------------------------------------------------*/
2643 claw_strt_read (struct net_device *dev, int lock )
2647 unsigned long saveflags = 0;
2648 struct claw_privbk *privptr = dev->ml_priv;
2649 struct ccwbk*p_ccwbk;
2651 struct clawh *p_clawh;
2652 p_ch = &privptr->channel[READ_CHANNEL];
2654 CLAW_DBF_TEXT(4, trace, "StRdNter");
2655 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2656 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2658 if ((privptr->p_write_active_first!=NULL &&
2659 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2660 (privptr->p_read_active_first!=NULL &&
2661 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2662 p_clawh->flag=CLAW_BUSY; /* 0xff */
2664 if (lock==LOCK_YES) {
2665 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2667 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2668 CLAW_DBF_TEXT(4, trace, "HotRead");
2669 p_ccwbk=privptr->p_read_active_first;
2670 parm = (unsigned long) p_ch;
2671 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2674 ccw_check_return_code(p_ch->cdev, rc);
2678 CLAW_DBF_TEXT(2, trace, "ReadAct");
2681 if (lock==LOCK_YES) {
2682 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2684 CLAW_DBF_TEXT(4, trace, "StRdExit");
2686 } /* end of claw_strt_read */
2688 /*-------------------------------------------------------------------*
2689 * claw_strt_out_IO *
2691 *--------------------------------------------------------------------*/
2694 claw_strt_out_IO( struct net_device *dev )
2698 struct claw_privbk *privptr;
2700 struct ccwbk *p_first_ccw;
2705 privptr = (struct claw_privbk *)dev->ml_priv;
2706 p_ch = &privptr->channel[WRITE_CHANNEL];
2708 CLAW_DBF_TEXT(4, trace, "strt_io");
2709 p_first_ccw=privptr->p_write_active_first;
2711 if (p_ch->claw_state == CLAW_STOP)
2713 if (p_first_ccw == NULL) {
2716 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2717 parm = (unsigned long) p_ch;
2718 CLAW_DBF_TEXT(2, trace, "StWrtIO");
2719 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2722 ccw_check_return_code(p_ch->cdev, rc);
2725 dev->trans_start = jiffies;
2727 } /* end of claw_strt_out_IO */
2729 /*-------------------------------------------------------------------*
2730 * Free write buffers *
2732 *--------------------------------------------------------------------*/
2735 claw_free_wrt_buf( struct net_device *dev )
2738 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
2739 struct ccwbk*p_this_ccw;
2740 struct ccwbk*p_next_ccw;
2742 CLAW_DBF_TEXT(4, trace, "freewrtb");
2743 /* scan the write queue to free any completed write packets */
2744 p_this_ccw=privptr->p_write_active_first;
2745 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2747 p_next_ccw = p_this_ccw->next;
2748 if (((p_next_ccw!=NULL) &&
2749 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2750 ((p_this_ccw == privptr->p_write_active_last) &&
2751 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2752 /* The next CCW is OK or this is */
2753 /* the last CCW...free it @A1A */
2754 privptr->p_write_active_first=p_this_ccw->next;
2755 p_this_ccw->header.flag=CLAW_PENDING;
2756 p_this_ccw->next=privptr->p_write_free_chain;
2757 privptr->p_write_free_chain=p_this_ccw;
2758 ++privptr->write_free_count;
2759 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2760 p_this_ccw=privptr->p_write_active_first;
2761 privptr->stats.tx_packets++;
2767 if (privptr->write_free_count!=0) {
2768 claw_clearbit_busy(TB_NOBUFFER,dev);
2770 /* whole chain removed? */
2771 if (privptr->p_write_active_first==NULL) {
2772 privptr->p_write_active_last=NULL;
2774 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
2778 /*-------------------------------------------------------------------*
2779 * claw free netdevice *
2781 *--------------------------------------------------------------------*/
2783 claw_free_netdevice(struct net_device * dev, int free_dev)
2785 struct claw_privbk *privptr;
2787 CLAW_DBF_TEXT(2, setup, "free_dev");
2790 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2791 privptr = dev->ml_priv;
2792 if (dev->flags & IFF_RUNNING)
2795 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
2797 dev->ml_priv = NULL;
2803 CLAW_DBF_TEXT(2, setup, "free_ok");
2807 * Claw init netdevice
2808 * Initialize everything of the net device except the name and the
2811 static const struct net_device_ops claw_netdev_ops = {
2812 .ndo_open = claw_open,
2813 .ndo_stop = claw_release,
2814 .ndo_get_stats = claw_stats,
2815 .ndo_start_xmit = claw_tx,
2816 .ndo_change_mtu = claw_change_mtu,
2820 claw_init_netdevice(struct net_device * dev)
2822 CLAW_DBF_TEXT(2, setup, "init_dev");
2823 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2824 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
2825 dev->hard_header_len = 0;
2827 dev->type = ARPHRD_SLIP;
2828 dev->tx_queue_len = 1300;
2829 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2830 dev->netdev_ops = &claw_netdev_ops;
2831 CLAW_DBF_TEXT(2, setup, "initok");
2836 * Init a new channel in the privptr->channel[i].
2838 * @param cdev The ccw_device to be added.
2840 * @return 0 on success, !0 on error.
2843 add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2846 struct ccw_dev_id dev_id;
2848 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
2849 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2850 p_ch = &privptr->channel[i];
2852 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
2853 ccw_device_get_id(cdev, &dev_id);
2854 p_ch->devno = dev_id.devno;
2855 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
2864 * Setup an interface.
2866 * @param cgdev Device to be setup.
2868 * @returns 0 on success, !0 on failure.
2871 claw_new_device(struct ccwgroup_device *cgdev)
2873 struct claw_privbk *privptr;
2874 struct claw_env *p_env;
2875 struct net_device *dev;
2877 struct ccw_dev_id dev_id;
2879 dev_info(&cgdev->dev, "add for %s\n",
2880 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
2881 CLAW_DBF_TEXT(2, setup, "new_dev");
2882 privptr = dev_get_drvdata(&cgdev->dev);
2883 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2884 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
2887 p_env = privptr->p_env;
2888 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2889 p_env->devno[READ_CHANNEL] = dev_id.devno;
2890 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2891 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
2892 ret = add_channel(cgdev->cdev[0],0,privptr);
2894 ret = add_channel(cgdev->cdev[1],1,privptr);
2896 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2897 " failed with error code %d\n", ret);
2900 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
2902 dev_warn(&cgdev->dev,
2903 "Setting the read subchannel online"
2904 " failed with error code %d\n", ret);
2907 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
2909 dev_warn(&cgdev->dev,
2910 "Setting the write subchannel online "
2911 "failed with error code %d\n", ret);
2914 dev = alloc_netdev(0, "claw%d", NET_NAME_UNKNOWN, claw_init_netdevice);
2916 dev_warn(&cgdev->dev,
2917 "Activating the CLAW device failed\n");
2920 dev->ml_priv = privptr;
2921 dev_set_drvdata(&cgdev->dev, privptr);
2922 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2923 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
2925 SET_NETDEV_DEV(dev, &cgdev->dev);
2926 if (register_netdev(dev) != 0) {
2927 claw_free_netdevice(dev, 1);
2928 CLAW_DBF_TEXT(2, trace, "regfail");
2931 dev->flags &=~IFF_RUNNING;
2932 if (privptr->buffs_alloc == 0) {
2933 ret=init_ccw_bk(dev);
2935 unregister_netdev(dev);
2936 claw_free_netdevice(dev,1);
2937 CLAW_DBF_TEXT(2, trace, "ccwmem");
2941 privptr->channel[READ_CHANNEL].ndev = dev;
2942 privptr->channel[WRITE_CHANNEL].ndev = dev;
2943 privptr->p_env->ndev = dev;
2945 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
2946 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2947 dev->name, p_env->read_size,
2948 p_env->write_size, p_env->read_buffers,
2949 p_env->write_buffers, p_env->devno[READ_CHANNEL],
2950 p_env->devno[WRITE_CHANNEL]);
2951 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
2952 ":%.8s api_type: %.8s\n",
2953 dev->name, p_env->host_name,
2954 p_env->adapter_name , p_env->api_type);
2957 ccw_device_set_offline(cgdev->cdev[1]);
2958 ccw_device_set_offline(cgdev->cdev[0]);
2963 claw_purge_skb_queue(struct sk_buff_head *q)
2965 struct sk_buff *skb;
2967 CLAW_DBF_TEXT(4, trace, "purgque");
2968 while ((skb = skb_dequeue(q))) {
2969 atomic_dec(&skb->users);
2970 dev_kfree_skb_any(skb);
2975 * Shutdown an interface.
2977 * @param cgdev Device to be shut down.
2979 * @returns 0 on success, !0 on failure.
2982 claw_shutdown_device(struct ccwgroup_device *cgdev)
2984 struct claw_privbk *priv;
2985 struct net_device *ndev;
2988 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
2989 priv = dev_get_drvdata(&cgdev->dev);
2992 ndev = priv->channel[READ_CHANNEL].ndev;
2994 /* Close the device */
2995 dev_info(&cgdev->dev, "%s: shutting down\n",
2997 if (ndev->flags & IFF_RUNNING)
2998 ret = claw_release(ndev);
2999 ndev->flags &=~IFF_RUNNING;
3000 unregister_netdev(ndev);
3001 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
3002 claw_free_netdevice(ndev, 1);
3003 priv->channel[READ_CHANNEL].ndev = NULL;
3004 priv->channel[WRITE_CHANNEL].ndev = NULL;
3005 priv->p_env->ndev = NULL;
3007 ccw_device_set_offline(cgdev->cdev[1]);
3008 ccw_device_set_offline(cgdev->cdev[0]);
3013 claw_remove_device(struct ccwgroup_device *cgdev)
3015 struct claw_privbk *priv;
3017 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
3018 priv = dev_get_drvdata(&cgdev->dev);
3019 dev_info(&cgdev->dev, " will be removed.\n");
3020 if (cgdev->state == CCWGROUP_ONLINE)
3021 claw_shutdown_device(cgdev);
3022 kfree(priv->p_mtc_envelope);
3023 priv->p_mtc_envelope=NULL;
3026 kfree(priv->channel[0].irb);
3027 priv->channel[0].irb=NULL;
3028 kfree(priv->channel[1].irb);
3029 priv->channel[1].irb=NULL;
3031 dev_set_drvdata(&cgdev->dev, NULL);
3032 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3033 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
3034 put_device(&cgdev->dev);
3044 claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
3046 struct claw_privbk *priv;
3047 struct claw_env * p_env;
3049 priv = dev_get_drvdata(dev);
3052 p_env = priv->p_env;
3053 return sprintf(buf, "%s\n",p_env->host_name);
3057 claw_hname_write(struct device *dev, struct device_attribute *attr,
3058 const char *buf, size_t count)
3060 struct claw_privbk *priv;
3061 struct claw_env * p_env;
3063 priv = dev_get_drvdata(dev);
3066 p_env = priv->p_env;
3067 if (count > MAX_NAME_LEN+1)
3069 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3070 strncpy(p_env->host_name,buf, count);
3071 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3072 p_env->host_name[MAX_NAME_LEN] = 0x00;
3073 CLAW_DBF_TEXT(2, setup, "HstnSet");
3074 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
3079 static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3082 claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
3084 struct claw_privbk *priv;
3085 struct claw_env * p_env;
3087 priv = dev_get_drvdata(dev);
3090 p_env = priv->p_env;
3091 return sprintf(buf, "%s\n", p_env->adapter_name);
3095 claw_adname_write(struct device *dev, struct device_attribute *attr,
3096 const char *buf, size_t count)
3098 struct claw_privbk *priv;
3099 struct claw_env * p_env;
3101 priv = dev_get_drvdata(dev);
3104 p_env = priv->p_env;
3105 if (count > MAX_NAME_LEN+1)
3107 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3108 strncpy(p_env->adapter_name,buf, count);
3109 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3110 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
3111 CLAW_DBF_TEXT(2, setup, "AdnSet");
3112 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
3117 static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3120 claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
3122 struct claw_privbk *priv;
3123 struct claw_env * p_env;
3125 priv = dev_get_drvdata(dev);
3128 p_env = priv->p_env;
3129 return sprintf(buf, "%s\n",
3134 claw_apname_write(struct device *dev, struct device_attribute *attr,
3135 const char *buf, size_t count)
3137 struct claw_privbk *priv;
3138 struct claw_env * p_env;
3140 priv = dev_get_drvdata(dev);
3143 p_env = priv->p_env;
3144 if (count > MAX_NAME_LEN+1)
3146 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3147 strncpy(p_env->api_type,buf, count);
3148 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3149 p_env->api_type[MAX_NAME_LEN] = 0x00;
3150 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3151 p_env->read_size=DEF_PACK_BUFSIZE;
3152 p_env->write_size=DEF_PACK_BUFSIZE;
3153 p_env->packing=PACKING_ASK;
3154 CLAW_DBF_TEXT(2, setup, "PACKING");
3158 p_env->read_size=CLAW_FRAME_SIZE;
3159 p_env->write_size=CLAW_FRAME_SIZE;
3160 CLAW_DBF_TEXT(2, setup, "ApiSet");
3162 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
3166 static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3169 claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3171 struct claw_privbk *priv;
3172 struct claw_env * p_env;
3174 priv = dev_get_drvdata(dev);
3177 p_env = priv->p_env;
3178 return sprintf(buf, "%d\n", p_env->write_buffers);
3182 claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3183 const char *buf, size_t count)
3185 struct claw_privbk *priv;
3186 struct claw_env * p_env;
3189 priv = dev_get_drvdata(dev);
3192 p_env = priv->p_env;
3193 sscanf(buf, "%i", &nnn);
3194 if (p_env->packing) {
3200 if ((nnn > max ) || (nnn < 2))
3202 p_env->write_buffers = nnn;
3203 CLAW_DBF_TEXT(2, setup, "Wbufset");
3204 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
3208 static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3211 claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3213 struct claw_privbk *priv;
3214 struct claw_env * p_env;
3216 priv = dev_get_drvdata(dev);
3219 p_env = priv->p_env;
3220 return sprintf(buf, "%d\n", p_env->read_buffers);
3224 claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3225 const char *buf, size_t count)
3227 struct claw_privbk *priv;
3228 struct claw_env *p_env;
3231 priv = dev_get_drvdata(dev);
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);
3249 static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3251 static struct attribute *claw_attr[] = {
3252 &dev_attr_read_buffer.attr,
3253 &dev_attr_write_buffer.attr,
3254 &dev_attr_adapter_name.attr,
3255 &dev_attr_api_type.attr,
3256 &dev_attr_host_name.attr,
3259 static struct attribute_group claw_attr_group = {
3262 static const struct attribute_group *claw_attr_groups[] = {
3266 static const struct device_type claw_devtype = {
3268 .groups = claw_attr_groups,
3271 /*----------------------------------------------------------------*
3273 * this function is called for each CLAW device. *
3274 *----------------------------------------------------------------*/
3275 static int claw_probe(struct ccwgroup_device *cgdev)
3277 struct claw_privbk *privptr = NULL;
3279 CLAW_DBF_TEXT(2, setup, "probe");
3280 if (!get_device(&cgdev->dev))
3282 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
3283 dev_set_drvdata(&cgdev->dev, privptr);
3284 if (privptr == NULL) {
3286 put_device(&cgdev->dev);
3287 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3290 privptr->p_mtc_envelope = kzalloc(MAX_ENVELOPE_SIZE, GFP_KERNEL);
3291 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
3292 if ((privptr->p_mtc_envelope == NULL) || (privptr->p_env == NULL)) {
3294 put_device(&cgdev->dev);
3295 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3298 memcpy(privptr->p_env->adapter_name, WS_NAME_NOT_DEF, 8);
3299 memcpy(privptr->p_env->host_name, WS_NAME_NOT_DEF, 8);
3300 memcpy(privptr->p_env->api_type, WS_NAME_NOT_DEF, 8);
3301 privptr->p_env->packing = 0;
3302 privptr->p_env->write_buffers = 5;
3303 privptr->p_env->read_buffers = 5;
3304 privptr->p_env->read_size = CLAW_FRAME_SIZE;
3305 privptr->p_env->write_size = CLAW_FRAME_SIZE;
3306 privptr->p_env->p_priv = privptr;
3307 cgdev->cdev[0]->handler = claw_irq_handler;
3308 cgdev->cdev[1]->handler = claw_irq_handler;
3309 cgdev->dev.type = &claw_devtype;
3310 CLAW_DBF_TEXT(2, setup, "prbext 0");
3313 } /* end of claw_probe */
3315 /*--------------------------------------------------------------------*
3316 * claw_init and cleanup *
3317 *---------------------------------------------------------------------*/
3319 static void __exit claw_cleanup(void)
3321 ccwgroup_driver_unregister(&claw_group_driver);
3322 ccw_driver_unregister(&claw_ccw_driver);
3323 root_device_unregister(claw_root_dev);
3324 claw_unregister_debug_facility();
3325 pr_info("Driver unloaded\n");
3329 * Initialize module.
3330 * This is called just after the module is loaded.
3332 * @return 0 on success, !0 on error.
3334 static int __init claw_init(void)
3338 pr_info("Loading %s\n", version);
3339 ret = claw_register_debug_facility();
3341 pr_err("Registering with the S/390 debug feature"
3342 " failed with error code %d\n", ret);
3345 CLAW_DBF_TEXT(2, setup, "init_mod");
3346 claw_root_dev = root_device_register("claw");
3347 ret = PTR_ERR_OR_ZERO(claw_root_dev);
3350 ret = ccw_driver_register(&claw_ccw_driver);
3353 claw_group_driver.driver.groups = claw_drv_attr_groups;
3354 ret = ccwgroup_driver_register(&claw_group_driver);
3360 ccw_driver_unregister(&claw_ccw_driver);
3362 root_device_unregister(claw_root_dev);
3364 CLAW_DBF_TEXT(2, setup, "init_bad");
3365 claw_unregister_debug_facility();
3367 pr_err("Initializing the claw device driver failed\n");
3371 module_init(claw_init);
3372 module_exit(claw_cleanup);
3374 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3375 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3376 "Copyright IBM Corp. 2000, 2008\n");
3377 MODULE_LICENSE("GPL");