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)
113 debug_unregister(claw_dbf_setup);
115 debug_unregister(claw_dbf_trace);
119 claw_register_debug_facility(void)
121 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
122 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
123 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
124 claw_unregister_debug_facility();
127 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
128 debug_set_level(claw_dbf_setup, 2);
129 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
130 debug_set_level(claw_dbf_trace, 2);
135 claw_set_busy(struct net_device *dev)
137 ((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);
148 claw_check_busy(struct net_device *dev)
150 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
154 claw_setbit_busy(int nr,struct net_device *dev)
156 netif_stop_queue(dev);
157 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
161 claw_clearbit_busy(int nr,struct net_device *dev)
163 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
164 netif_wake_queue(dev);
168 claw_test_and_setbit_busy(int nr,struct net_device *dev)
170 netif_stop_queue(dev);
171 return test_and_set_bit(nr,
172 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
176 /* Functions for the DEV methods */
178 static int claw_probe(struct ccwgroup_device *cgdev);
179 static void claw_remove_device(struct ccwgroup_device *cgdev);
180 static void claw_purge_skb_queue(struct sk_buff_head *q);
181 static int claw_new_device(struct ccwgroup_device *cgdev);
182 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
183 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
184 static int claw_change_mtu( struct net_device *dev, int new_mtu);
185 static int claw_open(struct net_device *dev);
186 static void claw_irq_handler(struct ccw_device *cdev,
187 unsigned long intparm, struct irb *irb);
188 static void claw_irq_tasklet ( unsigned long data );
189 static int claw_release(struct net_device *dev);
190 static void claw_write_retry ( struct chbk * p_ch );
191 static void claw_write_next ( struct chbk * p_ch );
192 static void claw_timer ( struct chbk * p_ch );
195 static int add_claw_reads(struct net_device *dev,
196 struct ccwbk* p_first, struct ccwbk* p_last);
197 static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
198 static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
199 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
200 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
201 static int init_ccw_bk(struct net_device *dev);
202 static void probe_error( struct ccwgroup_device *cgdev);
203 static struct net_device_stats *claw_stats(struct net_device *dev);
204 static int pages_to_order_of_mag(int num_of_pages);
205 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
206 /* sysfs Functions */
207 static ssize_t claw_hname_show(struct device *dev,
208 struct device_attribute *attr, char *buf);
209 static ssize_t claw_hname_write(struct device *dev,
210 struct device_attribute *attr,
211 const char *buf, size_t count);
212 static ssize_t claw_adname_show(struct device *dev,
213 struct device_attribute *attr, char *buf);
214 static ssize_t claw_adname_write(struct device *dev,
215 struct device_attribute *attr,
216 const char *buf, size_t count);
217 static ssize_t claw_apname_show(struct device *dev,
218 struct device_attribute *attr, char *buf);
219 static ssize_t claw_apname_write(struct device *dev,
220 struct device_attribute *attr,
221 const char *buf, size_t count);
222 static ssize_t claw_wbuff_show(struct device *dev,
223 struct device_attribute *attr, char *buf);
224 static ssize_t claw_wbuff_write(struct device *dev,
225 struct device_attribute *attr,
226 const char *buf, size_t count);
227 static ssize_t claw_rbuff_show(struct device *dev,
228 struct device_attribute *attr, char *buf);
229 static ssize_t claw_rbuff_write(struct device *dev,
230 struct device_attribute *attr,
231 const char *buf, size_t count);
233 /* Functions for System Validate */
234 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
235 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
236 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
237 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
238 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
239 static int claw_snd_sys_validate_rsp(struct net_device *dev,
240 struct clawctl * p_ctl, __u32 return_code);
241 static int claw_strt_conn_req(struct net_device *dev );
242 static void claw_strt_read(struct net_device *dev, int lock);
243 static void claw_strt_out_IO(struct net_device *dev);
244 static void claw_free_wrt_buf(struct net_device *dev);
246 /* Functions for unpack reads */
247 static void unpack_read(struct net_device *dev);
249 static int claw_pm_prepare(struct ccwgroup_device *gdev)
254 /* the root device for claw group devices */
255 static struct device *claw_root_dev;
259 static struct ccwgroup_driver claw_group_driver = {
261 .owner = THIS_MODULE,
265 .remove = claw_remove_device,
266 .set_online = claw_new_device,
267 .set_offline = claw_shutdown_device,
268 .prepare = claw_pm_prepare,
271 static struct ccw_device_id claw_ids[] = {
272 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
275 MODULE_DEVICE_TABLE(ccw, claw_ids);
277 static struct ccw_driver claw_ccw_driver = {
279 .owner = THIS_MODULE,
283 .probe = ccwgroup_probe_ccwdev,
284 .remove = ccwgroup_remove_ccwdev,
285 .int_class = IRQIO_CLW,
288 static ssize_t claw_driver_group_store(struct device_driver *ddrv,
289 const char *buf, size_t count)
292 err = ccwgroup_create_dev(claw_root_dev, &claw_group_driver, 2, buf);
293 return err ? err : count;
295 static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
297 static struct attribute *claw_drv_attrs[] = {
298 &driver_attr_group.attr,
301 static struct attribute_group claw_drv_attr_group = {
302 .attrs = claw_drv_attrs,
304 static const struct attribute_group *claw_drv_attr_groups[] = {
305 &claw_drv_attr_group,
313 /*-------------------------------------------------------------------*
315 *-------------------------------------------------------------------*/
318 claw_tx(struct sk_buff *skb, struct net_device *dev)
321 struct claw_privbk *privptr = dev->ml_priv;
322 unsigned long saveflags;
325 CLAW_DBF_TEXT(4, trace, "claw_tx");
326 p_ch = &privptr->channel[WRITE_CHANNEL];
327 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
328 rc=claw_hw_tx( skb, dev, 1 );
329 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
330 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
336 } /* end of claw_tx */
338 /*------------------------------------------------------------------*
339 * pack the collect queue into an skb and return it *
340 * If not packing just return the top skb from the queue *
341 *------------------------------------------------------------------*/
343 static struct sk_buff *
344 claw_pack_skb(struct claw_privbk *privptr)
346 struct sk_buff *new_skb,*held_skb;
347 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
348 struct claw_env *p_env = privptr->p_env;
349 int pkt_cnt,pk_ind,so_far;
351 new_skb = NULL; /* assume no dice */
353 CLAW_DBF_TEXT(4, trace, "PackSKBe");
354 if (!skb_queue_empty(&p_ch->collect_queue)) {
356 held_skb = skb_dequeue(&p_ch->collect_queue);
358 dev_kfree_skb_any(held_skb);
361 if (p_env->packing != DO_PACKED)
363 /* get a new SKB we will pack at least one */
364 new_skb = dev_alloc_skb(p_env->write_size);
365 if (new_skb == NULL) {
366 atomic_inc(&held_skb->users);
367 skb_queue_head(&p_ch->collect_queue,held_skb);
370 /* we have packed packet and a place to put it */
373 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
374 while ((pk_ind) && (held_skb != NULL)) {
375 if (held_skb->len+so_far <= p_env->write_size-8) {
376 memcpy(skb_put(new_skb,held_skb->len),
377 held_skb->data,held_skb->len);
378 privptr->stats.tx_packets++;
379 so_far += held_skb->len;
381 dev_kfree_skb_any(held_skb);
382 held_skb = skb_dequeue(&p_ch->collect_queue);
384 atomic_dec(&held_skb->users);
387 atomic_inc(&held_skb->users);
388 skb_queue_head(&p_ch->collect_queue,held_skb);
392 CLAW_DBF_TEXT(4, trace, "PackSKBx");
396 /*-------------------------------------------------------------------*
399 *-------------------------------------------------------------------*/
402 claw_change_mtu(struct net_device *dev, int new_mtu)
404 struct claw_privbk *privptr = dev->ml_priv;
406 CLAW_DBF_TEXT(4, trace, "setmtu");
407 buff_size = privptr->p_env->write_size;
408 if ((new_mtu < 60) || (new_mtu > buff_size)) {
413 } /* end of claw_change_mtu */
416 /*-------------------------------------------------------------------*
419 *-------------------------------------------------------------------*/
421 claw_open(struct net_device *dev)
426 unsigned long saveflags=0;
428 struct claw_privbk *privptr;
429 DECLARE_WAITQUEUE(wait, current);
430 struct timer_list timer;
433 CLAW_DBF_TEXT(4, trace, "open");
434 privptr = (struct claw_privbk *)dev->ml_priv;
435 /* allocate and initialize CCW blocks */
436 if (privptr->buffs_alloc == 0) {
439 CLAW_DBF_TEXT(2, trace, "openmem");
443 privptr->system_validate_comp=0;
444 privptr->release_pend=0;
445 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
446 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
447 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
448 privptr->p_env->packing=PACKING_ASK;
450 privptr->p_env->packing=0;
451 privptr->p_env->read_size=CLAW_FRAME_SIZE;
452 privptr->p_env->write_size=CLAW_FRAME_SIZE;
455 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
456 (unsigned long) &privptr->channel[READ_CHANNEL]);
457 for ( i = 0; i < 2; i++) {
458 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
459 init_waitqueue_head(&privptr->channel[i].wait);
460 /* skb_queue_head_init(&p_ch->io_queue); */
461 if (i == WRITE_CHANNEL)
463 &privptr->channel[WRITE_CHANNEL].collect_queue);
464 privptr->channel[i].flag_a = 0;
465 privptr->channel[i].IO_active = 0;
466 privptr->channel[i].flag &= ~CLAW_TIMER;
468 timer.function = (void *)claw_timer;
469 timer.data = (unsigned long)(&privptr->channel[i]);
470 timer.expires = jiffies + 15*HZ;
472 spin_lock_irqsave(get_ccwdev_lock(
473 privptr->channel[i].cdev), saveflags);
474 parm = (unsigned long) &privptr->channel[i];
475 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
477 add_wait_queue(&privptr->channel[i].wait, &wait);
478 rc = ccw_device_halt(
479 (struct ccw_device *)privptr->channel[i].cdev,parm);
480 set_current_state(TASK_INTERRUPTIBLE);
481 spin_unlock_irqrestore(
482 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
484 remove_wait_queue(&privptr->channel[i].wait, &wait);
486 ccw_check_return_code(privptr->channel[i].cdev, rc);
487 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
490 if ((((privptr->channel[READ_CHANNEL].last_dstat |
491 privptr->channel[WRITE_CHANNEL].last_dstat) &
492 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
493 (((privptr->channel[READ_CHANNEL].flag |
494 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
495 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
496 "%s: remote side is not ready\n", dev->name);
497 CLAW_DBF_TEXT(2, trace, "notrdy");
499 for ( i = 0; i < 2; i++) {
501 get_ccwdev_lock(privptr->channel[i].cdev),
503 parm = (unsigned long) &privptr->channel[i];
504 privptr->channel[i].claw_state = CLAW_STOP;
505 rc = ccw_device_halt(
506 (struct ccw_device *)&privptr->channel[i].cdev,
508 spin_unlock_irqrestore(
509 get_ccwdev_lock(privptr->channel[i].cdev),
512 ccw_check_return_code(
513 privptr->channel[i].cdev, rc);
516 free_pages((unsigned long)privptr->p_buff_ccw,
517 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
518 if (privptr->p_env->read_size < PAGE_SIZE) {
519 free_pages((unsigned long)privptr->p_buff_read,
520 (int)pages_to_order_of_mag(
521 privptr->p_buff_read_num));
524 p_buf=privptr->p_read_active_first;
525 while (p_buf!=NULL) {
526 free_pages((unsigned long)p_buf->p_buffer,
527 (int)pages_to_order_of_mag(
528 privptr->p_buff_pages_perread ));
532 if (privptr->p_env->write_size < PAGE_SIZE ) {
533 free_pages((unsigned long)privptr->p_buff_write,
534 (int)pages_to_order_of_mag(
535 privptr->p_buff_write_num));
538 p_buf=privptr->p_write_active_first;
539 while (p_buf!=NULL) {
540 free_pages((unsigned long)p_buf->p_buffer,
541 (int)pages_to_order_of_mag(
542 privptr->p_buff_pages_perwrite ));
546 privptr->buffs_alloc = 0;
547 privptr->channel[READ_CHANNEL].flag = 0x00;
548 privptr->channel[WRITE_CHANNEL].flag = 0x00;
549 privptr->p_buff_ccw=NULL;
550 privptr->p_buff_read=NULL;
551 privptr->p_buff_write=NULL;
552 claw_clear_busy(dev);
553 CLAW_DBF_TEXT(2, trace, "open EIO");
557 /* Send SystemValidate command */
559 claw_clear_busy(dev);
560 CLAW_DBF_TEXT(4, trace, "openok");
562 } /* end of claw_open */
564 /*-------------------------------------------------------------------*
568 *--------------------------------------------------------------------*/
570 claw_irq_handler(struct ccw_device *cdev,
571 unsigned long intparm, struct irb *irb)
573 struct chbk *p_ch = NULL;
574 struct claw_privbk *privptr = NULL;
575 struct net_device *dev = NULL;
576 struct claw_env *p_env;
577 struct chbk *p_ch_r=NULL;
579 CLAW_DBF_TEXT(4, trace, "clawirq");
580 /* Bypass all 'unsolicited interrupts' */
581 privptr = dev_get_drvdata(&cdev->dev);
583 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
584 " IRQ, c-%02x d-%02x\n",
585 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
586 CLAW_DBF_TEXT(2, trace, "badirq");
590 /* Try to extract channel from driver data. */
591 if (privptr->channel[READ_CHANNEL].cdev == cdev)
592 p_ch = &privptr->channel[READ_CHANNEL];
593 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
594 p_ch = &privptr->channel[WRITE_CHANNEL];
596 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
597 CLAW_DBF_TEXT(2, trace, "badchan");
600 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
602 dev = (struct net_device *) (p_ch->ndev);
603 p_env=privptr->p_env;
605 /* Copy interruption response block. */
606 memcpy(p_ch->irb, irb, sizeof(struct irb));
608 /* Check for good subchannel return code, otherwise info message */
609 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
611 "%s: subchannel check for device: %04x -"
612 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
613 dev->name, p_ch->devno,
614 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
616 CLAW_DBF_TEXT(2, trace, "chanchk");
620 /* Check the reason-code of a unit check */
621 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
622 ccw_check_unit_check(p_ch, irb->ecw[0]);
624 /* State machine to bring the connection up, down and to restart */
625 p_ch->last_dstat = irb->scsw.cmd.dstat;
627 switch (p_ch->claw_state) {
628 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
629 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
630 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
631 (p_ch->irb->scsw.cmd.stctl ==
632 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
634 wake_up(&p_ch->wait); /* wake up claw_release */
635 CLAW_DBF_TEXT(4, trace, "stop");
637 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
638 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
639 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
640 (p_ch->irb->scsw.cmd.stctl ==
641 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
642 CLAW_DBF_TEXT(4, trace, "haltio");
645 if (p_ch->flag == CLAW_READ) {
646 p_ch->claw_state = CLAW_START_READ;
647 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
648 } else if (p_ch->flag == CLAW_WRITE) {
649 p_ch->claw_state = CLAW_START_WRITE;
650 /* send SYSTEM_VALIDATE */
651 claw_strt_read(dev, LOCK_NO);
652 claw_send_control(dev,
653 SYSTEM_VALIDATE_REQUEST,
656 p_env->adapter_name);
658 dev_warn(&cdev->dev, "The CLAW device received"
659 " an unexpected IRQ, "
662 irb->scsw.cmd.dstat);
665 CLAW_DBF_TEXT(4, trace, "haltio");
667 case CLAW_START_READ:
668 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
669 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
670 clear_bit(0, (void *)&p_ch->IO_active);
671 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
672 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
673 (p_ch->irb->ecw[0]) == 0) {
674 privptr->stats.rx_errors++;
676 "%s: Restart is required after remote "
680 CLAW_DBF_TEXT(4, trace, "notrdy");
683 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
684 (p_ch->irb->scsw.cmd.dstat == 0)) {
685 if (test_and_set_bit(CLAW_BH_ACTIVE,
686 (void *)&p_ch->flag_a) == 0)
687 tasklet_schedule(&p_ch->tasklet);
689 CLAW_DBF_TEXT(4, trace, "PCINoBH");
690 CLAW_DBF_TEXT(4, trace, "PCI_read");
693 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
694 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
695 (p_ch->irb->scsw.cmd.stctl ==
696 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
697 CLAW_DBF_TEXT(4, trace, "SPend_rd");
700 clear_bit(0, (void *)&p_ch->IO_active);
701 claw_clearbit_busy(TB_RETRY, dev);
702 if (test_and_set_bit(CLAW_BH_ACTIVE,
703 (void *)&p_ch->flag_a) == 0)
704 tasklet_schedule(&p_ch->tasklet);
706 CLAW_DBF_TEXT(4, trace, "RdBHAct");
707 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
709 case CLAW_START_WRITE:
710 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
712 "%s: Unit Check Occurred in "
713 "write channel\n", dev->name);
714 clear_bit(0, (void *)&p_ch->IO_active);
715 if (p_ch->irb->ecw[0] & 0x80) {
717 "%s: Resetting Event "
718 "occurred:\n", dev->name);
719 init_timer(&p_ch->timer);
720 p_ch->timer.function =
721 (void *)claw_write_retry;
722 p_ch->timer.data = (unsigned long)p_ch;
723 p_ch->timer.expires = jiffies + 10*HZ;
724 add_timer(&p_ch->timer);
726 "%s: write connection "
727 "restarting\n", dev->name);
729 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
732 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
733 clear_bit(0, (void *)&p_ch->IO_active);
735 "%s: Unit Exception "
736 "occurred in write channel\n",
739 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
740 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
741 (p_ch->irb->scsw.cmd.stctl ==
742 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
743 CLAW_DBF_TEXT(4, trace, "writeUE");
746 clear_bit(0, (void *)&p_ch->IO_active);
747 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
748 claw_write_next(p_ch);
749 claw_clearbit_busy(TB_TX, dev);
750 claw_clear_busy(dev);
752 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
753 if (test_and_set_bit(CLAW_BH_ACTIVE,
754 (void *)&p_ch_r->flag_a) == 0)
755 tasklet_schedule(&p_ch_r->tasklet);
756 CLAW_DBF_TEXT(4, trace, "StWtExit");
760 "The CLAW device for %s received an unexpected IRQ\n",
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;
779 p_ch = (struct chbk *) data;
780 dev = (struct net_device *)p_ch->ndev;
781 CLAW_DBF_TEXT(4, trace, "IRQtask");
783 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
784 CLAW_DBF_TEXT(4, trace, "TskletXt");
786 } /* end of claw_irq_bh */
788 /*-------------------------------------------------------------------*
791 *--------------------------------------------------------------------*/
793 claw_release(struct net_device *dev)
797 unsigned long saveflags;
799 struct claw_privbk *privptr;
800 DECLARE_WAITQUEUE(wait, current);
801 struct ccwbk* p_this_ccw;
806 privptr = (struct claw_privbk *)dev->ml_priv;
809 CLAW_DBF_TEXT(4, trace, "release");
810 privptr->release_pend=1;
811 claw_setbit_busy(TB_STOP,dev);
812 for ( i = 1; i >=0 ; i--) {
814 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
815 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
816 privptr->channel[i].claw_state = CLAW_STOP;
817 privptr->channel[i].IO_active = 0;
818 parm = (unsigned long) &privptr->channel[i];
819 if (i == WRITE_CHANNEL)
820 claw_purge_skb_queue(
821 &privptr->channel[WRITE_CHANNEL].collect_queue);
822 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
823 if (privptr->system_validate_comp==0x00) /* never opened? */
824 init_waitqueue_head(&privptr->channel[i].wait);
825 add_wait_queue(&privptr->channel[i].wait, &wait);
826 set_current_state(TASK_INTERRUPTIBLE);
827 spin_unlock_irqrestore(
828 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
830 remove_wait_queue(&privptr->channel[i].wait, &wait);
832 ccw_check_return_code(privptr->channel[i].cdev, rc);
835 if (privptr->pk_skb != NULL) {
836 dev_kfree_skb_any(privptr->pk_skb);
837 privptr->pk_skb = NULL;
839 if(privptr->buffs_alloc != 1) {
840 CLAW_DBF_TEXT(4, trace, "none2fre");
843 CLAW_DBF_TEXT(4, trace, "freebufs");
844 if (privptr->p_buff_ccw != NULL) {
845 free_pages((unsigned long)privptr->p_buff_ccw,
846 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
848 CLAW_DBF_TEXT(4, trace, "freeread");
849 if (privptr->p_env->read_size < PAGE_SIZE) {
850 if (privptr->p_buff_read != NULL) {
851 free_pages((unsigned long)privptr->p_buff_read,
852 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
856 p_buf=privptr->p_read_active_first;
857 while (p_buf!=NULL) {
858 free_pages((unsigned long)p_buf->p_buffer,
859 (int)pages_to_order_of_mag(
860 privptr->p_buff_pages_perread ));
864 CLAW_DBF_TEXT(4, trace, "freewrit");
865 if (privptr->p_env->write_size < PAGE_SIZE ) {
866 free_pages((unsigned long)privptr->p_buff_write,
867 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
870 p_buf=privptr->p_write_active_first;
871 while (p_buf!=NULL) {
872 free_pages((unsigned long)p_buf->p_buffer,
873 (int)pages_to_order_of_mag(
874 privptr->p_buff_pages_perwrite ));
878 CLAW_DBF_TEXT(4, trace, "clearptr");
879 privptr->buffs_alloc = 0;
880 privptr->p_buff_ccw=NULL;
881 privptr->p_buff_read=NULL;
882 privptr->p_buff_write=NULL;
883 privptr->system_validate_comp=0;
884 privptr->release_pend=0;
885 /* Remove any writes that were pending and reset all reads */
886 p_this_ccw=privptr->p_read_active_first;
887 while (p_this_ccw!=NULL) {
888 p_this_ccw->header.length=0xffff;
889 p_this_ccw->header.opcode=0xff;
890 p_this_ccw->header.flag=0x00;
891 p_this_ccw=p_this_ccw->next;
894 while (privptr->p_write_active_first!=NULL) {
895 p_this_ccw=privptr->p_write_active_first;
896 p_this_ccw->header.flag=CLAW_PENDING;
897 privptr->p_write_active_first=p_this_ccw->next;
898 p_this_ccw->next=privptr->p_write_free_chain;
899 privptr->p_write_free_chain=p_this_ccw;
900 ++privptr->write_free_count;
902 privptr->p_write_active_last=NULL;
903 privptr->mtc_logical_link = -1;
904 privptr->mtc_skipping = 1;
905 privptr->mtc_offset=0;
907 if (((privptr->channel[READ_CHANNEL].last_dstat |
908 privptr->channel[WRITE_CHANNEL].last_dstat) &
909 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
910 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
911 "Deactivating %s completed with incorrect"
912 " subchannel status "
913 "(read %02x, write %02x)\n",
915 privptr->channel[READ_CHANNEL].last_dstat,
916 privptr->channel[WRITE_CHANNEL].last_dstat);
917 CLAW_DBF_TEXT(2, trace, "badclose");
919 CLAW_DBF_TEXT(4, trace, "rlsexit");
921 } /* end of claw_release */
923 /*-------------------------------------------------------------------*
926 *--------------------------------------------------------------------*/
929 claw_write_retry ( struct chbk *p_ch )
932 struct net_device *dev=p_ch->ndev;
934 CLAW_DBF_TEXT(4, trace, "w_retry");
935 if (p_ch->claw_state == CLAW_STOP) {
938 claw_strt_out_IO( dev );
939 CLAW_DBF_TEXT(4, trace, "rtry_xit");
941 } /* end of claw_write_retry */
944 /*-------------------------------------------------------------------*
947 *--------------------------------------------------------------------*/
950 claw_write_next ( struct chbk * p_ch )
953 struct net_device *dev;
954 struct claw_privbk *privptr=NULL;
955 struct sk_buff *pk_skb;
957 CLAW_DBF_TEXT(4, trace, "claw_wrt");
958 if (p_ch->claw_state == CLAW_STOP)
960 dev = (struct net_device *) p_ch->ndev;
961 privptr = (struct claw_privbk *) dev->ml_priv;
962 claw_free_wrt_buf( dev );
963 if ((privptr->write_free_count > 0) &&
964 !skb_queue_empty(&p_ch->collect_queue)) {
965 pk_skb = claw_pack_skb(privptr);
966 while (pk_skb != NULL) {
967 claw_hw_tx(pk_skb, dev, 1);
968 if (privptr->write_free_count > 0) {
969 pk_skb = claw_pack_skb(privptr);
974 if (privptr->p_write_active_first!=NULL) {
975 claw_strt_out_IO(dev);
978 } /* end of claw_write_next */
980 /*-------------------------------------------------------------------*
983 *--------------------------------------------------------------------*/
986 claw_timer ( struct chbk * p_ch )
988 CLAW_DBF_TEXT(4, trace, "timer");
989 p_ch->flag |= CLAW_TIMER;
990 wake_up(&p_ch->wait);
992 } /* end of claw_timer */
1000 /*-------------------------------------------------------------------*
1002 * pages_to_order_of_mag *
1004 * takes a number of pages from 1 to 512 and returns the *
1005 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1006 * of magnitude get_free_pages() has an upper order of 9 *
1007 *--------------------------------------------------------------------*/
1010 pages_to_order_of_mag(int num_of_pages)
1012 int order_of_mag=1; /* assume 2 pages */
1015 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
1016 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1017 /* 512 pages = 2Meg on 4k page systems */
1018 if (num_of_pages >= 512) {return 9; }
1019 /* we have two or more pages order is at least 1 */
1020 for (nump=2 ;nump <= 512;nump*=2) {
1021 if (num_of_pages <= nump)
1025 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
1026 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
1027 return order_of_mag;
1030 /*-------------------------------------------------------------------*
1034 *--------------------------------------------------------------------*/
1036 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1037 struct ccwbk* p_last)
1039 struct claw_privbk *privptr;
1040 struct ccw1 temp_ccw;
1041 struct endccw * p_end;
1042 CLAW_DBF_TEXT(4, trace, "addreads");
1043 privptr = dev->ml_priv;
1044 p_end = privptr->p_end_ccw;
1046 /* first CCW and last CCW contains a new set of read channel programs
1047 * to apend the running channel programs
1049 if ( p_first==NULL) {
1050 CLAW_DBF_TEXT(4, trace, "addexit");
1054 /* set up ending CCW sequence for this segment */
1056 p_end->read1=0x00; /* second ending CCW is now active */
1057 /* reset ending CCWs and setup TIC CCWs */
1058 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1059 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1060 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1061 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1062 p_end->read2_nop2.cda=0;
1063 p_end->read2_nop2.count=1;
1066 p_end->read1=0x01; /* first ending CCW is now active */
1067 /* reset ending CCWs and setup TIC CCWs */
1068 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1069 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1070 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1071 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1072 p_end->read1_nop2.cda=0;
1073 p_end->read1_nop2.count=1;
1076 if ( privptr-> p_read_active_first ==NULL ) {
1077 privptr->p_read_active_first = p_first; /* set new first */
1078 privptr->p_read_active_last = p_last; /* set new last */
1082 /* set up TIC ccw */
1083 temp_ccw.cda= (__u32)__pa(&p_first->read);
1086 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1091 /* first set of CCW's is chained to the new read */
1092 /* chain, so the second set is chained to the active chain. */
1093 /* Therefore modify the second set to point to the new */
1094 /* read chain set up TIC CCWs */
1095 /* make sure we update the CCW so channel doesn't fetch it */
1096 /* when it's only half done */
1097 memcpy( &p_end->read2_nop2, &temp_ccw ,
1098 sizeof(struct ccw1));
1099 privptr->p_read_active_last->r_TIC_1.cda=
1100 (__u32)__pa(&p_first->read);
1101 privptr->p_read_active_last->r_TIC_2.cda=
1102 (__u32)__pa(&p_first->read);
1105 /* make sure we update the CCW so channel doesn't */
1106 /* fetch it when it is only half done */
1107 memcpy( &p_end->read1_nop2, &temp_ccw ,
1108 sizeof(struct ccw1));
1109 privptr->p_read_active_last->r_TIC_1.cda=
1110 (__u32)__pa(&p_first->read);
1111 privptr->p_read_active_last->r_TIC_2.cda=
1112 (__u32)__pa(&p_first->read);
1114 /* chain in new set of blocks */
1115 privptr->p_read_active_last->next = p_first;
1116 privptr->p_read_active_last=p_last;
1117 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1118 CLAW_DBF_TEXT(4, trace, "addexit");
1120 } /* end of add_claw_reads */
1122 /*-------------------------------------------------------------------*
1123 * ccw_check_return_code *
1125 *-------------------------------------------------------------------*/
1128 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1130 CLAW_DBF_TEXT(4, trace, "ccwret");
1131 if (return_code != 0) {
1132 switch (return_code) {
1133 case -EBUSY: /* BUSY is a transient state no action needed */
1136 dev_err(&cdev->dev, "The remote channel adapter is not"
1141 "The status of the remote channel adapter"
1145 dev_err(&cdev->dev, "The common device layer"
1146 " returned error code %d\n",
1150 CLAW_DBF_TEXT(4, trace, "ccwret");
1151 } /* end of ccw_check_return_code */
1153 /*-------------------------------------------------------------------*
1154 * ccw_check_unit_check *
1155 *--------------------------------------------------------------------*/
1158 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1160 struct net_device *ndev = p_ch->ndev;
1161 struct device *dev = &p_ch->cdev->dev;
1163 CLAW_DBF_TEXT(4, trace, "unitchek");
1164 dev_warn(dev, "The communication peer of %s disconnected\n",
1169 dev_warn(dev, "The remote channel adapter for"
1170 " %s has been reset\n",
1173 } else if (sense & 0x20) {
1175 dev_warn(dev, "A data streaming timeout occurred"
1178 } else if (sense & 0x10) {
1179 dev_warn(dev, "The remote channel adapter for %s"
1183 dev_warn(dev, "A data transfer parity error occurred"
1187 } else if (sense & 0x10) {
1188 dev_warn(dev, "A read data parity error occurred"
1193 } /* end of ccw_check_unit_check */
1195 /*-------------------------------------------------------------------*
1197 *--------------------------------------------------------------------*/
1199 find_link(struct net_device *dev, char *host_name, char *ws_name )
1201 struct claw_privbk *privptr;
1202 struct claw_env *p_env;
1205 CLAW_DBF_TEXT(2, setup, "findlink");
1206 privptr = dev->ml_priv;
1207 p_env=privptr->p_env;
1208 switch (p_env->packing)
1211 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1212 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1217 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1218 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1222 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1223 (memcmp(p_env->api_type , ws_name, 8)!=0))
1229 } /* end of find_link */
1231 /*-------------------------------------------------------------------*
1235 *-------------------------------------------------------------------*/
1238 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1241 struct claw_privbk *privptr;
1242 struct ccwbk *p_this_ccw;
1243 struct ccwbk *p_first_ccw;
1244 struct ccwbk *p_last_ccw;
1246 signed long len_of_data;
1247 unsigned long bytesInThisBuffer;
1248 unsigned char *pDataAddress;
1249 struct endccw *pEnd;
1250 struct ccw1 tempCCW;
1251 struct claw_env *p_env;
1252 struct clawph *pk_head;
1255 CLAW_DBF_TEXT(4, trace, "hw_tx");
1256 privptr = (struct claw_privbk *)(dev->ml_priv);
1257 p_env =privptr->p_env;
1258 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1259 /* scan the write queue to free any completed write packets */
1262 if ((p_env->packing >= PACK_SEND) &&
1263 (skb->cb[1] != 'P')) {
1264 skb_push(skb,sizeof(struct clawph));
1265 pk_head=(struct clawph *)skb->data;
1266 pk_head->len=skb->len-sizeof(struct clawph);
1267 if (pk_head->len%4) {
1268 pk_head->len+= 4-(pk_head->len%4);
1269 skb_pad(skb,4-(pk_head->len%4));
1270 skb_put(skb,4-(pk_head->len%4));
1272 if (p_env->packing == DO_PACKED)
1273 pk_head->link_num = linkid;
1275 pk_head->link_num = 0;
1276 pk_head->flag = 0x00;
1281 if (claw_check_busy(dev)) {
1282 if (privptr->write_free_count!=0) {
1283 claw_clear_busy(dev);
1286 claw_strt_out_IO(dev );
1287 claw_free_wrt_buf( dev );
1288 if (privptr->write_free_count==0) {
1289 ch = &privptr->channel[WRITE_CHANNEL];
1290 atomic_inc(&skb->users);
1291 skb_queue_tail(&ch->collect_queue, skb);
1295 claw_clear_busy(dev);
1300 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1301 ch = &privptr->channel[WRITE_CHANNEL];
1302 atomic_inc(&skb->users);
1303 skb_queue_tail(&ch->collect_queue, skb);
1304 claw_strt_out_IO(dev );
1309 /* See how many write buffers are required to hold this data */
1310 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
1312 /* If that number of buffers isn't available, give up for now */
1313 if (privptr->write_free_count < numBuffers ||
1314 privptr->p_write_free_chain == NULL ) {
1316 claw_setbit_busy(TB_NOBUFFER,dev);
1317 ch = &privptr->channel[WRITE_CHANNEL];
1318 atomic_inc(&skb->users);
1319 skb_queue_tail(&ch->collect_queue, skb);
1320 CLAW_DBF_TEXT(2, trace, "clawbusy");
1323 pDataAddress=skb->data;
1324 len_of_data=skb->len;
1326 while (len_of_data > 0) {
1327 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1328 if (p_this_ccw == NULL) { /* lost the race */
1329 ch = &privptr->channel[WRITE_CHANNEL];
1330 atomic_inc(&skb->users);
1331 skb_queue_tail(&ch->collect_queue, skb);
1334 privptr->p_write_free_chain=p_this_ccw->next;
1335 p_this_ccw->next=NULL;
1336 --privptr->write_free_count; /* -1 */
1337 if (len_of_data >= privptr->p_env->write_size)
1338 bytesInThisBuffer = privptr->p_env->write_size;
1340 bytesInThisBuffer = len_of_data;
1341 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1342 len_of_data-=bytesInThisBuffer;
1343 pDataAddress+=(unsigned long)bytesInThisBuffer;
1344 /* setup write CCW */
1345 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1346 if (len_of_data>0) {
1347 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1349 p_this_ccw->write.count=bytesInThisBuffer;
1350 /* now add to end of this chain */
1351 if (p_first_ccw==NULL) {
1352 p_first_ccw=p_this_ccw;
1354 if (p_last_ccw!=NULL) {
1355 p_last_ccw->next=p_this_ccw;
1356 /* set up TIC ccws */
1357 p_last_ccw->w_TIC_1.cda=
1358 (__u32)__pa(&p_this_ccw->write);
1360 p_last_ccw=p_this_ccw; /* save new last block */
1363 /* FirstCCW and LastCCW now contain a new set of write channel
1364 * programs to append to the running channel program
1367 if (p_first_ccw!=NULL) {
1368 /* setup ending ccw sequence for this segment */
1369 pEnd=privptr->p_end_ccw;
1371 pEnd->write1=0x00; /* second end ccw is now active */
1372 /* set up Tic CCWs */
1373 p_last_ccw->w_TIC_1.cda=
1374 (__u32)__pa(&pEnd->write2_nop1);
1375 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1376 pEnd->write2_nop2.flags =
1377 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1378 pEnd->write2_nop2.cda=0;
1379 pEnd->write2_nop2.count=1;
1381 else { /* end of if (pEnd->write1)*/
1382 pEnd->write1=0x01; /* first end ccw is now active */
1383 /* set up Tic CCWs */
1384 p_last_ccw->w_TIC_1.cda=
1385 (__u32)__pa(&pEnd->write1_nop1);
1386 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1387 pEnd->write1_nop2.flags =
1388 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1389 pEnd->write1_nop2.cda=0;
1390 pEnd->write1_nop2.count=1;
1391 } /* end if if (pEnd->write1) */
1393 if (privptr->p_write_active_first==NULL ) {
1394 privptr->p_write_active_first=p_first_ccw;
1395 privptr->p_write_active_last=p_last_ccw;
1398 /* set up Tic CCWs */
1400 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1403 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1408 * first set of ending CCW's is chained to the new write
1409 * chain, so the second set is chained to the active chain
1410 * Therefore modify the second set to point the new write chain.
1411 * make sure we update the CCW atomically
1412 * so channel does not fetch it when it's only half done
1414 memcpy( &pEnd->write2_nop2, &tempCCW ,
1415 sizeof(struct ccw1));
1416 privptr->p_write_active_last->w_TIC_1.cda=
1417 (__u32)__pa(&p_first_ccw->write);
1421 /*make sure we update the CCW atomically
1422 *so channel does not fetch it when it's only half done
1424 memcpy(&pEnd->write1_nop2, &tempCCW ,
1425 sizeof(struct ccw1));
1426 privptr->p_write_active_last->w_TIC_1.cda=
1427 (__u32)__pa(&p_first_ccw->write);
1429 } /* end if if (pEnd->write1) */
1431 privptr->p_write_active_last->next=p_first_ccw;
1432 privptr->p_write_active_last=p_last_ccw;
1435 } /* endif (p_first_ccw!=NULL) */
1436 dev_kfree_skb_any(skb);
1437 claw_strt_out_IO(dev );
1438 /* if write free count is zero , set NOBUFFER */
1439 if (privptr->write_free_count==0) {
1440 claw_setbit_busy(TB_NOBUFFER,dev);
1443 claw_clearbit_busy(TB_TX,dev);
1446 } /* end of claw_hw_tx */
1448 /*-------------------------------------------------------------------*
1452 *--------------------------------------------------------------------*/
1455 init_ccw_bk(struct net_device *dev)
1458 __u32 ccw_blocks_required;
1459 __u32 ccw_blocks_perpage;
1460 __u32 ccw_pages_required;
1461 __u32 claw_reads_perpage=1;
1462 __u32 claw_read_pages;
1463 __u32 claw_writes_perpage=1;
1464 __u32 claw_write_pages;
1466 struct ccwbk*p_free_chain;
1468 struct ccwbk*p_last_CCWB;
1469 struct ccwbk*p_first_CCWB;
1470 struct endccw *p_endccw=NULL;
1471 addr_t real_address;
1472 struct claw_privbk *privptr = dev->ml_priv;
1473 struct clawh *pClawH=NULL;
1474 addr_t real_TIC_address;
1476 CLAW_DBF_TEXT(4, trace, "init_ccw");
1478 /* initialize statistics field */
1479 privptr->active_link_ID=0;
1480 /* initialize ccwbk pointers */
1481 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1482 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1483 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1484 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1485 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1486 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1487 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1488 privptr->buffs_alloc = 0;
1489 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1490 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1491 /* initialize free write ccwbk counter */
1492 privptr->write_free_count=0; /* number of free bufs on write chain */
1496 * We need 1 CCW block for each read buffer, 1 for each
1497 * write buffer, plus 1 for ClawSignalBlock
1499 ccw_blocks_required =
1500 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
1502 * compute number of CCW blocks that will fit in a page
1504 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1506 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
1509 * read and write sizes are set by 2 constants in claw.h
1510 * 4k and 32k. Unpacked values other than 4k are not going to
1511 * provide good performance. With packing buffers support 32k
1514 if (privptr->p_env->read_size < PAGE_SIZE) {
1515 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1516 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1517 claw_reads_perpage);
1519 else { /* > or equal */
1520 privptr->p_buff_pages_perread =
1521 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1522 claw_read_pages = privptr->p_env->read_buffers *
1523 privptr->p_buff_pages_perread;
1525 if (privptr->p_env->write_size < PAGE_SIZE) {
1526 claw_writes_perpage =
1527 PAGE_SIZE / privptr->p_env->write_size;
1528 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1529 claw_writes_perpage);
1532 else { /* > or equal */
1533 privptr->p_buff_pages_perwrite =
1534 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1535 claw_write_pages = privptr->p_env->write_buffers *
1536 privptr->p_buff_pages_perwrite;
1539 * allocate ccw_pages_required
1541 if (privptr->p_buff_ccw==NULL) {
1542 privptr->p_buff_ccw=
1543 (void *)__get_free_pages(__GFP_DMA,
1544 (int)pages_to_order_of_mag(ccw_pages_required ));
1545 if (privptr->p_buff_ccw==NULL) {
1548 privptr->p_buff_ccw_num=ccw_pages_required;
1550 memset(privptr->p_buff_ccw, 0x00,
1551 privptr->p_buff_ccw_num * PAGE_SIZE);
1554 * obtain ending ccw block address
1557 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1558 real_address = (__u32)__pa(privptr->p_end_ccw);
1559 /* Initialize ending CCW block */
1560 p_endccw=privptr->p_end_ccw;
1561 p_endccw->real=real_address;
1562 p_endccw->write1=0x00;
1563 p_endccw->read1=0x00;
1566 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1567 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1568 p_endccw->write1_nop1.count = 1;
1569 p_endccw->write1_nop1.cda = 0;
1572 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1573 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1574 p_endccw->write1_nop2.count = 1;
1575 p_endccw->write1_nop2.cda = 0;
1578 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1579 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1580 p_endccw->write2_nop1.count = 1;
1581 p_endccw->write2_nop1.cda = 0;
1584 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1585 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1586 p_endccw->write2_nop2.count = 1;
1587 p_endccw->write2_nop2.cda = 0;
1590 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1591 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1592 p_endccw->read1_nop1.count = 1;
1593 p_endccw->read1_nop1.cda = 0;
1596 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1597 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1598 p_endccw->read1_nop2.count = 1;
1599 p_endccw->read1_nop2.cda = 0;
1602 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1603 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1604 p_endccw->read2_nop1.count = 1;
1605 p_endccw->read2_nop1.cda = 0;
1608 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1609 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1610 p_endccw->read2_nop2.count = 1;
1611 p_endccw->read2_nop2.cda = 0;
1614 * Build a chain of CCWs
1617 p_buff=privptr->p_buff_ccw;
1620 for (i=0 ; i < ccw_pages_required; i++ ) {
1621 real_address = (__u32)__pa(p_buff);
1623 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1624 p_buf->next = p_free_chain;
1625 p_free_chain = p_buf;
1626 p_buf->real=(__u32)__pa(p_buf);
1632 * Initialize ClawSignalBlock
1635 if (privptr->p_claw_signal_blk==NULL) {
1636 privptr->p_claw_signal_blk=p_free_chain;
1637 p_free_chain=p_free_chain->next;
1638 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1639 pClawH->length=0xffff;
1640 pClawH->opcode=0xff;
1641 pClawH->flag=CLAW_BUSY;
1645 * allocate write_pages_required and add to free chain
1647 if (privptr->p_buff_write==NULL) {
1648 if (privptr->p_env->write_size < PAGE_SIZE) {
1649 privptr->p_buff_write=
1650 (void *)__get_free_pages(__GFP_DMA,
1651 (int)pages_to_order_of_mag(claw_write_pages ));
1652 if (privptr->p_buff_write==NULL) {
1653 privptr->p_buff_ccw=NULL;
1657 * Build CLAW write free chain
1661 memset(privptr->p_buff_write, 0x00,
1662 ccw_pages_required * PAGE_SIZE);
1663 privptr->p_write_free_chain=NULL;
1665 p_buff=privptr->p_buff_write;
1667 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1668 p_buf = p_free_chain; /* get a CCW */
1669 p_free_chain = p_buf->next;
1670 p_buf->next =privptr->p_write_free_chain;
1671 privptr->p_write_free_chain = p_buf;
1672 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1673 p_buf-> write.cda = (__u32)__pa(p_buff);
1674 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1675 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1676 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1677 p_buf-> w_read_FF.count = 1;
1678 p_buf-> w_read_FF.cda =
1679 (__u32)__pa(&p_buf-> header.flag);
1680 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1681 p_buf-> w_TIC_1.flags = 0;
1682 p_buf-> w_TIC_1.count = 0;
1684 if (((unsigned long)p_buff +
1685 privptr->p_env->write_size) >=
1686 ((unsigned long)(p_buff+2*
1687 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1688 p_buff = p_buff+privptr->p_env->write_size;
1692 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1694 privptr->p_write_free_chain=NULL;
1695 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1696 p_buff=(void *)__get_free_pages(__GFP_DMA,
1697 (int)pages_to_order_of_mag(
1698 privptr->p_buff_pages_perwrite) );
1700 free_pages((unsigned long)privptr->p_buff_ccw,
1701 (int)pages_to_order_of_mag(
1702 privptr->p_buff_ccw_num));
1703 privptr->p_buff_ccw=NULL;
1704 p_buf=privptr->p_buff_write;
1705 while (p_buf!=NULL) {
1706 free_pages((unsigned long)
1708 (int)pages_to_order_of_mag(
1709 privptr->p_buff_pages_perwrite));
1713 } /* Error on get_pages */
1714 memset(p_buff, 0x00, privptr->p_env->write_size );
1715 p_buf = p_free_chain;
1716 p_free_chain = p_buf->next;
1717 p_buf->next = privptr->p_write_free_chain;
1718 privptr->p_write_free_chain = p_buf;
1719 privptr->p_buff_write = p_buf;
1720 p_buf->p_buffer=(struct clawbuf *)p_buff;
1721 p_buf-> write.cda = (__u32)__pa(p_buff);
1722 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1723 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1724 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1725 p_buf-> w_read_FF.count = 1;
1726 p_buf-> w_read_FF.cda =
1727 (__u32)__pa(&p_buf-> header.flag);
1728 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1729 p_buf-> w_TIC_1.flags = 0;
1730 p_buf-> w_TIC_1.count = 0;
1731 } /* for all write_buffers */
1733 } /* else buffers are PAGE_SIZE or bigger */
1736 privptr->p_buff_write_num=claw_write_pages;
1737 privptr->write_free_count=privptr->p_env->write_buffers;
1741 * allocate read_pages_required and chain to free chain
1743 if (privptr->p_buff_read==NULL) {
1744 if (privptr->p_env->read_size < PAGE_SIZE) {
1745 privptr->p_buff_read=
1746 (void *)__get_free_pages(__GFP_DMA,
1747 (int)pages_to_order_of_mag(claw_read_pages) );
1748 if (privptr->p_buff_read==NULL) {
1749 free_pages((unsigned long)privptr->p_buff_ccw,
1750 (int)pages_to_order_of_mag(
1751 privptr->p_buff_ccw_num));
1752 /* free the write pages size is < page size */
1753 free_pages((unsigned long)privptr->p_buff_write,
1754 (int)pages_to_order_of_mag(
1755 privptr->p_buff_write_num));
1756 privptr->p_buff_ccw=NULL;
1757 privptr->p_buff_write=NULL;
1760 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1761 privptr->p_buff_read_num=claw_read_pages;
1763 * Build CLAW read free chain
1766 p_buff=privptr->p_buff_read;
1767 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1768 p_buf = p_free_chain;
1769 p_free_chain = p_buf->next;
1771 if (p_last_CCWB==NULL) {
1777 p_buf->next=p_first_CCWB;
1779 (__u32)__pa(&p_first_CCWB -> read );
1784 p_buf->p_buffer=(struct clawbuf *)p_buff;
1785 /* initialize read command */
1786 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1787 p_buf-> read.cda = (__u32)__pa(p_buff);
1788 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1789 p_buf-> read.count = privptr->p_env->read_size;
1791 /* initialize read_h command */
1792 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1793 p_buf-> read_h.cda =
1794 (__u32)__pa(&(p_buf->header));
1795 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1796 p_buf-> read_h.count = sizeof(struct clawh);
1798 /* initialize Signal command */
1799 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1800 p_buf-> signal.cda =
1801 (__u32)__pa(&(pClawH->flag));
1802 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1803 p_buf-> signal.count = 1;
1805 /* initialize r_TIC_1 command */
1806 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1807 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1808 p_buf-> r_TIC_1.flags = 0;
1809 p_buf-> r_TIC_1.count = 0;
1811 /* initialize r_read_FF command */
1812 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1813 p_buf-> r_read_FF.cda =
1814 (__u32)__pa(&(pClawH->flag));
1815 p_buf-> r_read_FF.flags =
1816 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1817 p_buf-> r_read_FF.count = 1;
1819 /* initialize r_TIC_2 */
1820 memcpy(&p_buf->r_TIC_2,
1821 &p_buf->r_TIC_1, sizeof(struct ccw1));
1823 /* initialize Header */
1824 p_buf->header.length=0xffff;
1825 p_buf->header.opcode=0xff;
1826 p_buf->header.flag=CLAW_PENDING;
1828 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1829 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1832 p_buff= p_buff+privptr->p_env->read_size;
1836 (void *)((unsigned long)
1837 (p_buff+2*(privptr->p_env->read_size)-1)
1840 } /* for read_buffers */
1841 } /* read_size < PAGE_SIZE */
1842 else { /* read Size >= PAGE_SIZE */
1843 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1844 p_buff = (void *)__get_free_pages(__GFP_DMA,
1845 (int)pages_to_order_of_mag(
1846 privptr->p_buff_pages_perread));
1848 free_pages((unsigned long)privptr->p_buff_ccw,
1849 (int)pages_to_order_of_mag(privptr->
1851 /* free the write pages */
1852 p_buf=privptr->p_buff_write;
1853 while (p_buf!=NULL) {
1855 (unsigned long)p_buf->p_buffer,
1856 (int)pages_to_order_of_mag(
1857 privptr->p_buff_pages_perwrite));
1860 /* free any read pages already alloc */
1861 p_buf=privptr->p_buff_read;
1862 while (p_buf!=NULL) {
1864 (unsigned long)p_buf->p_buffer,
1865 (int)pages_to_order_of_mag(
1866 privptr->p_buff_pages_perread));
1869 privptr->p_buff_ccw=NULL;
1870 privptr->p_buff_write=NULL;
1873 memset(p_buff, 0x00, privptr->p_env->read_size);
1874 p_buf = p_free_chain;
1875 privptr->p_buff_read = p_buf;
1876 p_free_chain = p_buf->next;
1878 if (p_last_CCWB==NULL) {
1884 p_buf->next=p_first_CCWB;
1887 &p_first_CCWB -> read );
1891 /* save buff address */
1892 p_buf->p_buffer=(struct clawbuf *)p_buff;
1893 /* initialize read command */
1894 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1895 p_buf-> read.cda = (__u32)__pa(p_buff);
1896 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1897 p_buf-> read.count = privptr->p_env->read_size;
1899 /* initialize read_h command */
1900 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1901 p_buf-> read_h.cda =
1902 (__u32)__pa(&(p_buf->header));
1903 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1904 p_buf-> read_h.count = sizeof(struct clawh);
1906 /* initialize Signal command */
1907 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1908 p_buf-> signal.cda =
1909 (__u32)__pa(&(pClawH->flag));
1910 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1911 p_buf-> signal.count = 1;
1913 /* initialize r_TIC_1 command */
1914 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1915 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1916 p_buf-> r_TIC_1.flags = 0;
1917 p_buf-> r_TIC_1.count = 0;
1919 /* initialize r_read_FF command */
1920 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1921 p_buf-> r_read_FF.cda =
1922 (__u32)__pa(&(pClawH->flag));
1923 p_buf-> r_read_FF.flags =
1924 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1925 p_buf-> r_read_FF.count = 1;
1927 /* initialize r_TIC_2 */
1928 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1929 sizeof(struct ccw1));
1931 /* initialize Header */
1932 p_buf->header.length=0xffff;
1933 p_buf->header.opcode=0xff;
1934 p_buf->header.flag=CLAW_PENDING;
1936 } /* For read_buffers */
1937 } /* read_size >= PAGE_SIZE */
1938 } /* pBuffread = NULL */
1939 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1940 privptr->buffs_alloc = 1;
1943 } /* end of init_ccw_bk */
1945 /*-------------------------------------------------------------------*
1949 *--------------------------------------------------------------------*/
1952 probe_error( struct ccwgroup_device *cgdev)
1954 struct claw_privbk *privptr;
1956 CLAW_DBF_TEXT(4, trace, "proberr");
1957 privptr = dev_get_drvdata(&cgdev->dev);
1958 if (privptr != NULL) {
1959 dev_set_drvdata(&cgdev->dev, NULL);
1960 kfree(privptr->p_env);
1961 kfree(privptr->p_mtc_envelope);
1966 /*-------------------------------------------------------------------*
1967 * claw_process_control *
1970 *--------------------------------------------------------------------*/
1973 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
1976 struct clawbuf *p_buf;
1977 struct clawctl ctlbk;
1978 struct clawctl *p_ctlbk;
1979 char temp_host_name[8];
1980 char temp_ws_name[8];
1981 struct claw_privbk *privptr;
1982 struct claw_env *p_env;
1983 struct sysval *p_sysval;
1984 struct conncmd *p_connect=NULL;
1986 struct chbk *p_ch = NULL;
1987 struct device *tdev;
1988 CLAW_DBF_TEXT(2, setup, "clw_cntl");
1989 udelay(1000); /* Wait a ms for the control packets to
1990 *catch up to each other */
1991 privptr = dev->ml_priv;
1992 p_env=privptr->p_env;
1993 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
1994 memcpy( &temp_host_name, p_env->host_name, 8);
1995 memcpy( &temp_ws_name, p_env->adapter_name , 8);
1996 dev_info(tdev, "%s: CLAW device %.8s: "
1997 "Received Control Packet\n",
1998 dev->name, temp_ws_name);
1999 if (privptr->release_pend==1) {
2002 p_buf=p_ccw->p_buffer;
2004 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2005 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2007 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2009 switch (p_ctlbk->command)
2011 case SYSTEM_VALIDATE_REQUEST:
2012 if (p_ctlbk->version != CLAW_VERSION_ID) {
2013 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2014 CLAW_RC_WRONG_VERSION);
2015 dev_warn(tdev, "The communication peer of %s"
2016 " uses an incorrect API version %d\n",
2017 dev->name, p_ctlbk->version);
2019 p_sysval = (struct sysval *)&(p_ctlbk->data);
2020 dev_info(tdev, "%s: Recv Sys Validate Request: "
2021 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2023 dev->name, p_ctlbk->version,
2025 p_ctlbk->correlator,
2027 p_sysval->host_name);
2028 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2029 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2030 CLAW_RC_NAME_MISMATCH);
2031 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2032 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2033 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
2035 "Host name %s for %s does not match the"
2036 " remote adapter name %s\n",
2037 p_sysval->host_name,
2041 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2042 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2043 CLAW_RC_NAME_MISMATCH);
2044 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2045 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2046 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
2047 dev_warn(tdev, "Adapter name %s for %s does not match"
2048 " the remote host name %s\n",
2053 if ((p_sysval->write_frame_size < p_env->write_size) &&
2054 (p_env->packing == 0)) {
2055 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2056 CLAW_RC_HOST_RCV_TOO_SMALL);
2058 "The local write buffer is smaller than the"
2059 " remote read buffer\n");
2060 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2062 if ((p_sysval->read_frame_size < p_env->read_size) &&
2063 (p_env->packing == 0)) {
2064 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2065 CLAW_RC_HOST_RCV_TOO_SMALL);
2067 "The local read buffer is smaller than the"
2068 " remote write buffer\n");
2069 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2071 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
2073 "CLAW device %.8s: System validate"
2074 " completed.\n", temp_ws_name);
2076 "%s: sys Validate Rsize:%d Wsize:%d\n",
2077 dev->name, p_sysval->read_frame_size,
2078 p_sysval->write_frame_size);
2079 privptr->system_validate_comp = 1;
2080 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2081 p_env->packing = PACKING_ASK;
2082 claw_strt_conn_req(dev);
2084 case SYSTEM_VALIDATE_RESPONSE:
2085 p_sysval = (struct sysval *)&(p_ctlbk->data);
2087 "Settings for %s validated (version=%d, "
2088 "remote device=%d, rc=%d, adapter name=%.8s, "
2089 "host name=%.8s)\n",
2092 p_ctlbk->correlator,
2095 p_sysval->host_name);
2096 switch (p_ctlbk->rc) {
2098 dev_info(tdev, "%s: CLAW device "
2099 "%.8s: System validate completed.\n",
2100 dev->name, temp_ws_name);
2101 if (privptr->system_validate_comp == 0)
2102 claw_strt_conn_req(dev);
2103 privptr->system_validate_comp = 1;
2105 case CLAW_RC_NAME_MISMATCH:
2106 dev_warn(tdev, "Validating %s failed because of"
2107 " a host or adapter name mismatch\n",
2110 case CLAW_RC_WRONG_VERSION:
2111 dev_warn(tdev, "Validating %s failed because of a"
2112 " version conflict\n",
2115 case CLAW_RC_HOST_RCV_TOO_SMALL:
2116 dev_warn(tdev, "Validating %s failed because of a"
2117 " frame size conflict\n",
2121 dev_warn(tdev, "The communication peer of %s rejected"
2122 " the connection\n",
2128 case CONNECTION_REQUEST:
2129 p_connect = (struct conncmd *)&(p_ctlbk->data);
2130 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2131 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2135 p_ctlbk->correlator,
2136 p_connect->host_name,
2137 p_connect->WS_name);
2138 if (privptr->active_link_ID != 0) {
2139 claw_snd_disc(dev, p_ctlbk);
2140 dev_info(tdev, "%s rejected a connection request"
2141 " because it is already active\n",
2144 if (p_ctlbk->linkid != 1) {
2145 claw_snd_disc(dev, p_ctlbk);
2146 dev_info(tdev, "%s rejected a request to open multiple"
2150 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2152 claw_snd_disc(dev, p_ctlbk);
2153 dev_info(tdev, "%s rejected a connection request"
2154 " because of a type mismatch\n",
2157 claw_send_control(dev,
2158 CONNECTION_CONFIRM, p_ctlbk->linkid,
2159 p_ctlbk->correlator,
2160 0, p_connect->host_name,
2161 p_connect->WS_name);
2162 if (p_env->packing == PACKING_ASK) {
2163 p_env->packing = PACK_SEND;
2164 claw_snd_conn_req(dev, 0);
2166 dev_info(tdev, "%s: CLAW device %.8s: Connection "
2167 "completed link_id=%d.\n",
2168 dev->name, temp_ws_name,
2170 privptr->active_link_ID = p_ctlbk->linkid;
2171 p_ch = &privptr->channel[WRITE_CHANNEL];
2172 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2174 case CONNECTION_RESPONSE:
2175 p_connect = (struct conncmd *)&(p_ctlbk->data);
2176 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
2177 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2181 p_ctlbk->correlator,
2183 p_connect->host_name,
2184 p_connect->WS_name);
2186 if (p_ctlbk->rc != 0) {
2187 dev_warn(tdev, "The communication peer of %s rejected"
2188 " a connection request\n",
2193 p_connect->host_name, p_connect->WS_name);
2195 claw_snd_disc(dev, p_ctlbk);
2196 dev_warn(tdev, "The communication peer of %s"
2197 " rejected a connection "
2198 "request because of a type mismatch\n",
2201 /* should be until CONNECTION_CONFIRM */
2202 privptr->active_link_ID = -(p_ctlbk->linkid);
2204 case CONNECTION_CONFIRM:
2205 p_connect = (struct conncmd *)&(p_ctlbk->data);
2207 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2208 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2212 p_ctlbk->correlator,
2213 p_connect->host_name,
2214 p_connect->WS_name);
2215 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2216 privptr->active_link_ID = p_ctlbk->linkid;
2217 if (p_env->packing > PACKING_ASK) {
2219 "%s: Confirmed Now packing\n", dev->name);
2220 p_env->packing = DO_PACKED;
2222 p_ch = &privptr->channel[WRITE_CHANNEL];
2223 wake_up(&p_ch->wait);
2225 dev_warn(tdev, "Activating %s failed because of"
2226 " an incorrect link ID=%d\n",
2227 dev->name, p_ctlbk->linkid);
2228 claw_snd_disc(dev, p_ctlbk);
2232 dev_info(tdev, "%s: Disconnect: "
2233 "Vers=%d,link_id=%d,Corr=%d\n",
2234 dev->name, p_ctlbk->version,
2235 p_ctlbk->linkid, p_ctlbk->correlator);
2236 if ((p_ctlbk->linkid == 2) &&
2237 (p_env->packing == PACK_SEND)) {
2238 privptr->active_link_ID = 1;
2239 p_env->packing = DO_PACKED;
2241 privptr->active_link_ID = 0;
2244 dev_warn(tdev, "The communication peer of %s failed\n",
2248 dev_warn(tdev, "The communication peer of %s sent"
2249 " an unknown command code\n",
2255 } /* end of claw_process_control */
2258 /*-------------------------------------------------------------------*
2259 * claw_send_control *
2261 *--------------------------------------------------------------------*/
2264 claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2265 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2267 struct claw_privbk *privptr;
2268 struct clawctl *p_ctl;
2269 struct sysval *p_sysval;
2270 struct conncmd *p_connect;
2271 struct sk_buff *skb;
2273 CLAW_DBF_TEXT(2, setup, "sndcntl");
2274 privptr = dev->ml_priv;
2275 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2277 p_ctl->command=type;
2278 p_ctl->version=CLAW_VERSION_ID;
2280 p_ctl->correlator=correlator;
2283 p_sysval=(struct sysval *)&p_ctl->data;
2284 p_connect=(struct conncmd *)&p_ctl->data;
2286 switch (p_ctl->command) {
2287 case SYSTEM_VALIDATE_REQUEST:
2288 case SYSTEM_VALIDATE_RESPONSE:
2289 memcpy(&p_sysval->host_name, local_name, 8);
2290 memcpy(&p_sysval->WS_name, remote_name, 8);
2291 if (privptr->p_env->packing > 0) {
2292 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2293 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
2295 /* how big is the biggest group of packets */
2296 p_sysval->read_frame_size =
2297 privptr->p_env->read_size;
2298 p_sysval->write_frame_size =
2299 privptr->p_env->write_size;
2301 memset(&p_sysval->reserved, 0x00, 4);
2303 case CONNECTION_REQUEST:
2304 case CONNECTION_RESPONSE:
2305 case CONNECTION_CONFIRM:
2307 memcpy(&p_sysval->host_name, local_name, 8);
2308 memcpy(&p_sysval->WS_name, remote_name, 8);
2309 if (privptr->p_env->packing > 0) {
2310 /* How big is the biggest packet */
2311 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2312 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2314 memset(&p_connect->reserved1, 0x00, 4);
2315 memset(&p_connect->reserved2, 0x00, 4);
2322 /* write Control Record to the device */
2325 skb = dev_alloc_skb(sizeof(struct clawctl));
2329 memcpy(skb_put(skb, sizeof(struct clawctl)),
2330 p_ctl, sizeof(struct clawctl));
2331 if (privptr->p_env->packing >= PACK_SEND)
2332 claw_hw_tx(skb, dev, 1);
2334 claw_hw_tx(skb, dev, 0);
2336 } /* end of claw_send_control */
2338 /*-------------------------------------------------------------------*
2339 * claw_snd_conn_req *
2341 *--------------------------------------------------------------------*/
2343 claw_snd_conn_req(struct net_device *dev, __u8 link)
2346 struct claw_privbk *privptr = dev->ml_priv;
2347 struct clawctl *p_ctl;
2349 CLAW_DBF_TEXT(2, setup, "snd_conn");
2351 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2352 p_ctl->linkid = link;
2353 if ( privptr->system_validate_comp==0x00 ) {
2356 if (privptr->p_env->packing == PACKING_ASK )
2357 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2358 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2359 if (privptr->p_env->packing == PACK_SEND) {
2360 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2361 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2363 if (privptr->p_env->packing == 0)
2364 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2365 HOST_APPL_NAME, privptr->p_env->api_type);
2368 } /* end of claw_snd_conn_req */
2371 /*-------------------------------------------------------------------*
2374 *--------------------------------------------------------------------*/
2377 claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2380 struct conncmd * p_connect;
2382 CLAW_DBF_TEXT(2, setup, "snd_dsc");
2383 p_connect=(struct conncmd *)&p_ctl->data;
2385 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2386 p_ctl->correlator, 0,
2387 p_connect->host_name, p_connect->WS_name);
2389 } /* end of claw_snd_disc */
2392 /*-------------------------------------------------------------------*
2393 * claw_snd_sys_validate_rsp *
2395 *--------------------------------------------------------------------*/
2398 claw_snd_sys_validate_rsp(struct net_device *dev,
2399 struct clawctl *p_ctl, __u32 return_code)
2401 struct claw_env * p_env;
2402 struct claw_privbk *privptr;
2405 CLAW_DBF_TEXT(2, setup, "chkresp");
2406 privptr = dev->ml_priv;
2407 p_env=privptr->p_env;
2408 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2413 p_env->adapter_name );
2415 } /* end of claw_snd_sys_validate_rsp */
2417 /*-------------------------------------------------------------------*
2418 * claw_strt_conn_req *
2420 *--------------------------------------------------------------------*/
2423 claw_strt_conn_req(struct net_device *dev )
2427 CLAW_DBF_TEXT(2, setup, "conn_req");
2428 rc=claw_snd_conn_req(dev, 1);
2430 } /* end of claw_strt_conn_req */
2434 /*-------------------------------------------------------------------*
2436 *-------------------------------------------------------------------*/
2439 net_device_stats *claw_stats(struct net_device *dev)
2441 struct claw_privbk *privptr;
2443 CLAW_DBF_TEXT(4, trace, "stats");
2444 privptr = dev->ml_priv;
2445 return &privptr->stats;
2446 } /* end of claw_stats */
2449 /*-------------------------------------------------------------------*
2452 *--------------------------------------------------------------------*/
2454 unpack_read(struct net_device *dev )
2456 struct sk_buff *skb;
2457 struct claw_privbk *privptr;
2458 struct claw_env *p_env;
2459 struct ccwbk *p_this_ccw;
2460 struct ccwbk *p_first_ccw;
2461 struct ccwbk *p_last_ccw;
2462 struct clawph *p_packh;
2464 struct clawctl *p_ctlrec=NULL;
2465 struct device *p_dev;
2470 __u8 mtc_this_frm=0;
2475 CLAW_DBF_TEXT(4, trace, "unpkread");
2480 privptr = dev->ml_priv;
2482 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
2483 p_env = privptr->p_env;
2484 p_this_ccw=privptr->p_read_active_first;
2485 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
2488 p_this_ccw->header.flag=CLAW_PENDING;
2489 privptr->p_read_active_first=p_this_ccw->next;
2490 p_this_ccw->next=NULL;
2491 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2492 if ((p_env->packing == PACK_SEND) &&
2493 (p_packh->len == 32) &&
2494 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2495 p_packh++; /* peek past pack header */
2496 p_ctlrec = (struct clawctl *)p_packh;
2497 p_packh--; /* un peek */
2498 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2499 (p_ctlrec->command == CONNECTION_CONFIRM))
2500 p_env->packing = DO_PACKED;
2502 if (p_env->packing == DO_PACKED)
2503 link_num=p_packh->link_num;
2505 link_num=p_this_ccw->header.opcode / 8;
2506 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
2508 if (p_this_ccw->header.length!=
2509 privptr->p_env->read_size ) {
2511 "The communication peer of %s"
2513 " frame of length %02x\n",
2514 dev->name, p_this_ccw->header.length);
2518 if (privptr->mtc_skipping) {
2520 * We're in the mode of skipping past a
2521 * multi-frame message
2522 * that we can't process for some reason or other.
2523 * The first frame without the More-To-Come flag is
2524 * the last frame of the skipped message.
2526 /* in case of More-To-Come not set in this frame */
2527 if (mtc_this_frm==0) {
2528 privptr->mtc_skipping=0; /* Ok, the end */
2529 privptr->mtc_logical_link=-1;
2535 claw_process_control(dev, p_this_ccw);
2536 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
2540 if (p_env->packing == DO_PACKED) {
2541 if (pack_off > p_env->read_size)
2543 p_packd = p_this_ccw->p_buffer+pack_off;
2544 p_packh = (struct clawph *) p_packd;
2545 if ((p_packh->len == 0) || /* done with this frame? */
2546 (p_packh->flag != 0))
2548 bytes_to_mov = p_packh->len;
2549 pack_off += bytes_to_mov+sizeof(struct clawph);
2552 bytes_to_mov=p_this_ccw->header.length;
2554 if (privptr->mtc_logical_link<0) {
2557 * if More-To-Come is set in this frame then we don't know
2558 * length of entire message, and hence have to allocate
2561 /* We are starting a new envelope */
2562 privptr->mtc_offset=0;
2563 privptr->mtc_logical_link=link_num;
2566 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2568 privptr->stats.rx_frame_errors++;
2571 if (p_env->packing == DO_PACKED) {
2572 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2573 p_packd+sizeof(struct clawph), bytes_to_mov);
2576 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2577 p_this_ccw->p_buffer, bytes_to_mov);
2579 if (mtc_this_frm==0) {
2580 len_of_data=privptr->mtc_offset+bytes_to_mov;
2581 skb=dev_alloc_skb(len_of_data);
2583 memcpy(skb_put(skb,len_of_data),
2584 privptr->p_mtc_envelope,
2587 skb_reset_mac_header(skb);
2588 skb->protocol=htons(ETH_P_IP);
2589 skb->ip_summed=CHECKSUM_UNNECESSARY;
2590 privptr->stats.rx_packets++;
2591 privptr->stats.rx_bytes+=len_of_data;
2595 dev_info(p_dev, "Allocating a buffer for"
2596 " incoming data failed\n");
2597 privptr->stats.rx_dropped++;
2599 privptr->mtc_offset=0;
2600 privptr->mtc_logical_link=-1;
2603 privptr->mtc_offset+=bytes_to_mov;
2605 if (p_env->packing == DO_PACKED)
2609 * Remove ThisCCWblock from active read queue, and add it
2610 * to queue of free blocks to be reused.
2613 p_this_ccw->header.length=0xffff;
2614 p_this_ccw->header.opcode=0xff;
2616 * add this one to the free queue for later reuse
2618 if (p_first_ccw==NULL) {
2619 p_first_ccw = p_this_ccw;
2622 p_last_ccw->next = p_this_ccw;
2624 p_last_ccw = p_this_ccw;
2626 * chain to next block on active read queue
2628 p_this_ccw = privptr->p_read_active_first;
2629 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
2630 } /* end of while */
2632 /* check validity */
2634 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
2635 add_claw_reads(dev, p_first_ccw, p_last_ccw);
2636 claw_strt_read(dev, LOCK_YES);
2638 } /* end of unpack_read */
2640 /*-------------------------------------------------------------------*
2643 *--------------------------------------------------------------------*/
2645 claw_strt_read (struct net_device *dev, int lock )
2649 unsigned long saveflags = 0;
2650 struct claw_privbk *privptr = dev->ml_priv;
2651 struct ccwbk*p_ccwbk;
2653 struct clawh *p_clawh;
2654 p_ch = &privptr->channel[READ_CHANNEL];
2656 CLAW_DBF_TEXT(4, trace, "StRdNter");
2657 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2658 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2660 if ((privptr->p_write_active_first!=NULL &&
2661 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2662 (privptr->p_read_active_first!=NULL &&
2663 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2664 p_clawh->flag=CLAW_BUSY; /* 0xff */
2666 if (lock==LOCK_YES) {
2667 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2669 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2670 CLAW_DBF_TEXT(4, trace, "HotRead");
2671 p_ccwbk=privptr->p_read_active_first;
2672 parm = (unsigned long) p_ch;
2673 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2676 ccw_check_return_code(p_ch->cdev, rc);
2680 CLAW_DBF_TEXT(2, trace, "ReadAct");
2683 if (lock==LOCK_YES) {
2684 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2686 CLAW_DBF_TEXT(4, trace, "StRdExit");
2688 } /* end of claw_strt_read */
2690 /*-------------------------------------------------------------------*
2691 * claw_strt_out_IO *
2693 *--------------------------------------------------------------------*/
2696 claw_strt_out_IO( struct net_device *dev )
2700 struct claw_privbk *privptr;
2702 struct ccwbk *p_first_ccw;
2707 privptr = (struct claw_privbk *)dev->ml_priv;
2708 p_ch = &privptr->channel[WRITE_CHANNEL];
2710 CLAW_DBF_TEXT(4, trace, "strt_io");
2711 p_first_ccw=privptr->p_write_active_first;
2713 if (p_ch->claw_state == CLAW_STOP)
2715 if (p_first_ccw == NULL) {
2718 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2719 parm = (unsigned long) p_ch;
2720 CLAW_DBF_TEXT(2, trace, "StWrtIO");
2721 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2724 ccw_check_return_code(p_ch->cdev, rc);
2727 dev->trans_start = jiffies;
2729 } /* end of claw_strt_out_IO */
2731 /*-------------------------------------------------------------------*
2732 * Free write buffers *
2734 *--------------------------------------------------------------------*/
2737 claw_free_wrt_buf( struct net_device *dev )
2740 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
2741 struct ccwbk*p_this_ccw;
2742 struct ccwbk*p_next_ccw;
2744 CLAW_DBF_TEXT(4, trace, "freewrtb");
2745 /* scan the write queue to free any completed write packets */
2746 p_this_ccw=privptr->p_write_active_first;
2747 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2749 p_next_ccw = p_this_ccw->next;
2750 if (((p_next_ccw!=NULL) &&
2751 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2752 ((p_this_ccw == privptr->p_write_active_last) &&
2753 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2754 /* The next CCW is OK or this is */
2755 /* the last CCW...free it @A1A */
2756 privptr->p_write_active_first=p_this_ccw->next;
2757 p_this_ccw->header.flag=CLAW_PENDING;
2758 p_this_ccw->next=privptr->p_write_free_chain;
2759 privptr->p_write_free_chain=p_this_ccw;
2760 ++privptr->write_free_count;
2761 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2762 p_this_ccw=privptr->p_write_active_first;
2763 privptr->stats.tx_packets++;
2769 if (privptr->write_free_count!=0) {
2770 claw_clearbit_busy(TB_NOBUFFER,dev);
2772 /* whole chain removed? */
2773 if (privptr->p_write_active_first==NULL) {
2774 privptr->p_write_active_last=NULL;
2776 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
2780 /*-------------------------------------------------------------------*
2781 * claw free netdevice *
2783 *--------------------------------------------------------------------*/
2785 claw_free_netdevice(struct net_device * dev, int free_dev)
2787 struct claw_privbk *privptr;
2789 CLAW_DBF_TEXT(2, setup, "free_dev");
2792 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2793 privptr = dev->ml_priv;
2794 if (dev->flags & IFF_RUNNING)
2797 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
2799 dev->ml_priv = NULL;
2805 CLAW_DBF_TEXT(2, setup, "free_ok");
2809 * Claw init netdevice
2810 * Initialize everything of the net device except the name and the
2813 static const struct net_device_ops claw_netdev_ops = {
2814 .ndo_open = claw_open,
2815 .ndo_stop = claw_release,
2816 .ndo_get_stats = claw_stats,
2817 .ndo_start_xmit = claw_tx,
2818 .ndo_change_mtu = claw_change_mtu,
2822 claw_init_netdevice(struct net_device * dev)
2824 CLAW_DBF_TEXT(2, setup, "init_dev");
2825 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2826 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
2827 dev->hard_header_len = 0;
2829 dev->type = ARPHRD_SLIP;
2830 dev->tx_queue_len = 1300;
2831 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2832 dev->netdev_ops = &claw_netdev_ops;
2833 CLAW_DBF_TEXT(2, setup, "initok");
2838 * Init a new channel in the privptr->channel[i].
2840 * @param cdev The ccw_device to be added.
2842 * @return 0 on success, !0 on error.
2845 add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2848 struct ccw_dev_id dev_id;
2850 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
2851 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2852 p_ch = &privptr->channel[i];
2854 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
2855 ccw_device_get_id(cdev, &dev_id);
2856 p_ch->devno = dev_id.devno;
2857 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
2866 * Setup an interface.
2868 * @param cgdev Device to be setup.
2870 * @returns 0 on success, !0 on failure.
2873 claw_new_device(struct ccwgroup_device *cgdev)
2875 struct claw_privbk *privptr;
2876 struct claw_env *p_env;
2877 struct net_device *dev;
2879 struct ccw_dev_id dev_id;
2881 dev_info(&cgdev->dev, "add for %s\n",
2882 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
2883 CLAW_DBF_TEXT(2, setup, "new_dev");
2884 privptr = dev_get_drvdata(&cgdev->dev);
2885 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2886 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
2889 p_env = privptr->p_env;
2890 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2891 p_env->devno[READ_CHANNEL] = dev_id.devno;
2892 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2893 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
2894 ret = add_channel(cgdev->cdev[0],0,privptr);
2896 ret = add_channel(cgdev->cdev[1],1,privptr);
2898 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2899 " failed with error code %d\n", ret);
2902 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
2904 dev_warn(&cgdev->dev,
2905 "Setting the read subchannel online"
2906 " failed with error code %d\n", ret);
2909 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
2911 dev_warn(&cgdev->dev,
2912 "Setting the write subchannel online "
2913 "failed with error code %d\n", ret);
2916 dev = alloc_netdev(0, "claw%d", NET_NAME_UNKNOWN, claw_init_netdevice);
2918 dev_warn(&cgdev->dev,
2919 "Activating the CLAW device failed\n");
2922 dev->ml_priv = privptr;
2923 dev_set_drvdata(&cgdev->dev, privptr);
2924 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2925 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
2927 SET_NETDEV_DEV(dev, &cgdev->dev);
2928 if (register_netdev(dev) != 0) {
2929 claw_free_netdevice(dev, 1);
2930 CLAW_DBF_TEXT(2, trace, "regfail");
2933 dev->flags &=~IFF_RUNNING;
2934 if (privptr->buffs_alloc == 0) {
2935 ret=init_ccw_bk(dev);
2937 unregister_netdev(dev);
2938 claw_free_netdevice(dev,1);
2939 CLAW_DBF_TEXT(2, trace, "ccwmem");
2943 privptr->channel[READ_CHANNEL].ndev = dev;
2944 privptr->channel[WRITE_CHANNEL].ndev = dev;
2945 privptr->p_env->ndev = dev;
2947 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
2948 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2949 dev->name, p_env->read_size,
2950 p_env->write_size, p_env->read_buffers,
2951 p_env->write_buffers, p_env->devno[READ_CHANNEL],
2952 p_env->devno[WRITE_CHANNEL]);
2953 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
2954 ":%.8s api_type: %.8s\n",
2955 dev->name, p_env->host_name,
2956 p_env->adapter_name , p_env->api_type);
2959 ccw_device_set_offline(cgdev->cdev[1]);
2960 ccw_device_set_offline(cgdev->cdev[0]);
2965 claw_purge_skb_queue(struct sk_buff_head *q)
2967 struct sk_buff *skb;
2969 CLAW_DBF_TEXT(4, trace, "purgque");
2970 while ((skb = skb_dequeue(q))) {
2971 atomic_dec(&skb->users);
2972 dev_kfree_skb_any(skb);
2977 * Shutdown an interface.
2979 * @param cgdev Device to be shut down.
2981 * @returns 0 on success, !0 on failure.
2984 claw_shutdown_device(struct ccwgroup_device *cgdev)
2986 struct claw_privbk *priv;
2987 struct net_device *ndev;
2990 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
2991 priv = dev_get_drvdata(&cgdev->dev);
2994 ndev = priv->channel[READ_CHANNEL].ndev;
2996 /* Close the device */
2997 dev_info(&cgdev->dev, "%s: shutting down\n",
2999 if (ndev->flags & IFF_RUNNING)
3000 ret = claw_release(ndev);
3001 ndev->flags &=~IFF_RUNNING;
3002 unregister_netdev(ndev);
3003 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
3004 claw_free_netdevice(ndev, 1);
3005 priv->channel[READ_CHANNEL].ndev = NULL;
3006 priv->channel[WRITE_CHANNEL].ndev = NULL;
3007 priv->p_env->ndev = NULL;
3009 ccw_device_set_offline(cgdev->cdev[1]);
3010 ccw_device_set_offline(cgdev->cdev[0]);
3015 claw_remove_device(struct ccwgroup_device *cgdev)
3017 struct claw_privbk *priv;
3019 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
3020 priv = dev_get_drvdata(&cgdev->dev);
3021 dev_info(&cgdev->dev, " will be removed.\n");
3022 if (cgdev->state == CCWGROUP_ONLINE)
3023 claw_shutdown_device(cgdev);
3024 kfree(priv->p_mtc_envelope);
3025 priv->p_mtc_envelope=NULL;
3028 kfree(priv->channel[0].irb);
3029 priv->channel[0].irb=NULL;
3030 kfree(priv->channel[1].irb);
3031 priv->channel[1].irb=NULL;
3033 dev_set_drvdata(&cgdev->dev, NULL);
3034 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3035 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
3036 put_device(&cgdev->dev);
3046 claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
3048 struct claw_privbk *priv;
3049 struct claw_env * p_env;
3051 priv = dev_get_drvdata(dev);
3054 p_env = priv->p_env;
3055 return sprintf(buf, "%s\n",p_env->host_name);
3059 claw_hname_write(struct device *dev, struct device_attribute *attr,
3060 const char *buf, size_t count)
3062 struct claw_privbk *priv;
3063 struct claw_env * p_env;
3065 priv = dev_get_drvdata(dev);
3068 p_env = priv->p_env;
3069 if (count > MAX_NAME_LEN+1)
3071 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3072 strncpy(p_env->host_name,buf, count);
3073 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3074 p_env->host_name[MAX_NAME_LEN] = 0x00;
3075 CLAW_DBF_TEXT(2, setup, "HstnSet");
3076 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
3081 static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3084 claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
3086 struct claw_privbk *priv;
3087 struct claw_env * p_env;
3089 priv = dev_get_drvdata(dev);
3092 p_env = priv->p_env;
3093 return sprintf(buf, "%s\n", p_env->adapter_name);
3097 claw_adname_write(struct device *dev, struct device_attribute *attr,
3098 const char *buf, size_t count)
3100 struct claw_privbk *priv;
3101 struct claw_env * p_env;
3103 priv = dev_get_drvdata(dev);
3106 p_env = priv->p_env;
3107 if (count > MAX_NAME_LEN+1)
3109 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3110 strncpy(p_env->adapter_name,buf, count);
3111 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3112 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
3113 CLAW_DBF_TEXT(2, setup, "AdnSet");
3114 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
3119 static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3122 claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
3124 struct claw_privbk *priv;
3125 struct claw_env * p_env;
3127 priv = dev_get_drvdata(dev);
3130 p_env = priv->p_env;
3131 return sprintf(buf, "%s\n",
3136 claw_apname_write(struct device *dev, struct device_attribute *attr,
3137 const char *buf, size_t count)
3139 struct claw_privbk *priv;
3140 struct claw_env * p_env;
3142 priv = dev_get_drvdata(dev);
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_get_drvdata(dev);
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,
3185 const char *buf, size_t count)
3187 struct claw_privbk *priv;
3188 struct claw_env * p_env;
3191 priv = dev_get_drvdata(dev);
3194 p_env = priv->p_env;
3195 sscanf(buf, "%i", &nnn);
3196 if (p_env->packing) {
3202 if ((nnn > max ) || (nnn < 2))
3204 p_env->write_buffers = nnn;
3205 CLAW_DBF_TEXT(2, setup, "Wbufset");
3206 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
3210 static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3213 claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3215 struct claw_privbk *priv;
3216 struct claw_env * p_env;
3218 priv = dev_get_drvdata(dev);
3221 p_env = priv->p_env;
3222 return sprintf(buf, "%d\n", p_env->read_buffers);
3226 claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3227 const char *buf, size_t count)
3229 struct claw_privbk *priv;
3230 struct claw_env *p_env;
3233 priv = dev_get_drvdata(dev);
3236 p_env = priv->p_env;
3237 sscanf(buf, "%i", &nnn);
3238 if (p_env->packing) {
3244 if ((nnn > max ) || (nnn < 2))
3246 p_env->read_buffers = nnn;
3247 CLAW_DBF_TEXT(2, setup, "Rbufset");
3248 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
3251 static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3253 static struct attribute *claw_attr[] = {
3254 &dev_attr_read_buffer.attr,
3255 &dev_attr_write_buffer.attr,
3256 &dev_attr_adapter_name.attr,
3257 &dev_attr_api_type.attr,
3258 &dev_attr_host_name.attr,
3261 static struct attribute_group claw_attr_group = {
3264 static const struct attribute_group *claw_attr_groups[] = {
3268 static const struct device_type claw_devtype = {
3270 .groups = claw_attr_groups,
3273 /*----------------------------------------------------------------*
3275 * this function is called for each CLAW device. *
3276 *----------------------------------------------------------------*/
3277 static int claw_probe(struct ccwgroup_device *cgdev)
3279 struct claw_privbk *privptr = NULL;
3281 CLAW_DBF_TEXT(2, setup, "probe");
3282 if (!get_device(&cgdev->dev))
3284 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
3285 dev_set_drvdata(&cgdev->dev, privptr);
3286 if (privptr == NULL) {
3288 put_device(&cgdev->dev);
3289 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3292 privptr->p_mtc_envelope = kzalloc(MAX_ENVELOPE_SIZE, GFP_KERNEL);
3293 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
3294 if ((privptr->p_mtc_envelope == NULL) || (privptr->p_env == NULL)) {
3296 put_device(&cgdev->dev);
3297 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3300 memcpy(privptr->p_env->adapter_name, WS_NAME_NOT_DEF, 8);
3301 memcpy(privptr->p_env->host_name, WS_NAME_NOT_DEF, 8);
3302 memcpy(privptr->p_env->api_type, WS_NAME_NOT_DEF, 8);
3303 privptr->p_env->packing = 0;
3304 privptr->p_env->write_buffers = 5;
3305 privptr->p_env->read_buffers = 5;
3306 privptr->p_env->read_size = CLAW_FRAME_SIZE;
3307 privptr->p_env->write_size = CLAW_FRAME_SIZE;
3308 privptr->p_env->p_priv = privptr;
3309 cgdev->cdev[0]->handler = claw_irq_handler;
3310 cgdev->cdev[1]->handler = claw_irq_handler;
3311 cgdev->dev.type = &claw_devtype;
3312 CLAW_DBF_TEXT(2, setup, "prbext 0");
3315 } /* end of claw_probe */
3317 /*--------------------------------------------------------------------*
3318 * claw_init and cleanup *
3319 *---------------------------------------------------------------------*/
3321 static void __exit claw_cleanup(void)
3323 ccwgroup_driver_unregister(&claw_group_driver);
3324 ccw_driver_unregister(&claw_ccw_driver);
3325 root_device_unregister(claw_root_dev);
3326 claw_unregister_debug_facility();
3327 pr_info("Driver unloaded\n");
3331 * Initialize module.
3332 * This is called just after the module is loaded.
3334 * @return 0 on success, !0 on error.
3336 static int __init claw_init(void)
3340 pr_info("Loading %s\n", version);
3341 ret = claw_register_debug_facility();
3343 pr_err("Registering with the S/390 debug feature"
3344 " failed with error code %d\n", ret);
3347 CLAW_DBF_TEXT(2, setup, "init_mod");
3348 claw_root_dev = root_device_register("claw");
3349 ret = PTR_ERR_OR_ZERO(claw_root_dev);
3352 ret = ccw_driver_register(&claw_ccw_driver);
3355 claw_group_driver.driver.groups = claw_drv_attr_groups;
3356 ret = ccwgroup_driver_register(&claw_group_driver);
3362 ccw_driver_unregister(&claw_ccw_driver);
3364 root_device_unregister(claw_root_dev);
3366 CLAW_DBF_TEXT(2, setup, "init_bad");
3367 claw_unregister_debug_facility();
3369 pr_err("Initializing the claw device driver failed\n");
3373 module_init(claw_init);
3374 module_exit(claw_cleanup);
3376 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3377 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3378 "Copyright IBM Corp. 2000, 2008\n");
3379 MODULE_LICENSE("GPL");