2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
5 * Linux for zSeries version
6 * Copyright IBM Corp. 2002, 2009
7 * Author(s) Original code written by:
8 * Kazuo Iimura <iimura@jp.ibm.com>
10 * Andy Richter <richtera@us.ibm.com>
11 * Marc Price <mwprice@us.ibm.com>
14 * group x.x.rrrr,x.x.wwww
18 * adapter_name aaaaaaaa
22 * group 0.0.0200 0.0.0201
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
35 * rrrr - the first of 2 consecutive device addresses used for the
37 * The specified address is always used as the input (Read)
38 * channel and the next address is used as the output channel.
40 * wwww - the second of 2 consecutive device addresses used for
42 * The specified address is always used as the output
43 * channel and the previous address is used as the input channel.
45 * read_buffer - specifies number of input buffers to allocate.
46 * write_buffer - specifies number of output buffers to allocate.
47 * host_name - host name
48 * adaptor_name - adaptor name
49 * api_type - API type TCPIP or API will be sent and expected
52 * Note the following requirements:
53 * 1) host_name must match the configured adapter_name on the remote side
54 * 2) adaptor_name must match the configured host name on the remote side
57 * 1.00 Initial release shipped
58 * 1.10 Changes for Buffer allocation
59 * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
60 * 1.25 Added Packing support
64 #define KMSG_COMPONENT "claw"
66 #include <linux/kernel_stat.h>
67 #include <asm/ccwdev.h>
68 #include <asm/ccwgroup.h>
69 #include <asm/debug.h>
70 #include <asm/idals.h>
72 #include <linux/bitops.h>
73 #include <linux/ctype.h>
74 #include <linux/delay.h>
75 #include <linux/errno.h>
76 #include <linux/if_arp.h>
77 #include <linux/init.h>
78 #include <linux/interrupt.h>
80 #include <linux/kernel.h>
81 #include <linux/module.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/proc_fs.h>
85 #include <linux/sched.h>
86 #include <linux/signal.h>
87 #include <linux/skbuff.h>
88 #include <linux/slab.h>
89 #include <linux/string.h>
90 #include <linux/tcp.h>
91 #include <linux/timer.h>
92 #include <linux/types.h>
97 CLAW uses the s390dbf file system see claw_trace and claw_setup
100 static char version
[] __initdata
= "CLAW driver";
101 static char debug_buffer
[255];
103 * Debug Facility Stuff
105 static debug_info_t
*claw_dbf_setup
;
106 static debug_info_t
*claw_dbf_trace
;
109 * CLAW Debug Facility functions
112 claw_unregister_debug_facility(void)
115 debug_unregister(claw_dbf_setup
);
117 debug_unregister(claw_dbf_trace
);
121 claw_register_debug_facility(void)
123 claw_dbf_setup
= debug_register("claw_setup", 2, 1, 8);
124 claw_dbf_trace
= debug_register("claw_trace", 2, 2, 8);
125 if (claw_dbf_setup
== NULL
|| claw_dbf_trace
== NULL
) {
126 claw_unregister_debug_facility();
129 debug_register_view(claw_dbf_setup
, &debug_hex_ascii_view
);
130 debug_set_level(claw_dbf_setup
, 2);
131 debug_register_view(claw_dbf_trace
, &debug_hex_ascii_view
);
132 debug_set_level(claw_dbf_trace
, 2);
137 claw_set_busy(struct net_device
*dev
)
139 ((struct claw_privbk
*)dev
->ml_priv
)->tbusy
= 1;
144 claw_clear_busy(struct net_device
*dev
)
146 clear_bit(0, &(((struct claw_privbk
*) dev
->ml_priv
)->tbusy
));
147 netif_wake_queue(dev
);
152 claw_check_busy(struct net_device
*dev
)
155 return ((struct claw_privbk
*) dev
->ml_priv
)->tbusy
;
159 claw_setbit_busy(int nr
,struct net_device
*dev
)
161 netif_stop_queue(dev
);
162 set_bit(nr
, (void *)&(((struct claw_privbk
*)dev
->ml_priv
)->tbusy
));
166 claw_clearbit_busy(int nr
,struct net_device
*dev
)
168 clear_bit(nr
, (void *)&(((struct claw_privbk
*)dev
->ml_priv
)->tbusy
));
169 netif_wake_queue(dev
);
173 claw_test_and_setbit_busy(int nr
,struct net_device
*dev
)
175 netif_stop_queue(dev
);
176 return test_and_set_bit(nr
,
177 (void *)&(((struct claw_privbk
*) dev
->ml_priv
)->tbusy
));
181 /* Functions for the DEV methods */
183 static int claw_probe(struct ccwgroup_device
*cgdev
);
184 static void claw_remove_device(struct ccwgroup_device
*cgdev
);
185 static void claw_purge_skb_queue(struct sk_buff_head
*q
);
186 static int claw_new_device(struct ccwgroup_device
*cgdev
);
187 static int claw_shutdown_device(struct ccwgroup_device
*cgdev
);
188 static int claw_tx(struct sk_buff
*skb
, struct net_device
*dev
);
189 static int claw_change_mtu( struct net_device
*dev
, int new_mtu
);
190 static int claw_open(struct net_device
*dev
);
191 static void claw_irq_handler(struct ccw_device
*cdev
,
192 unsigned long intparm
, struct irb
*irb
);
193 static void claw_irq_tasklet ( unsigned long data
);
194 static int claw_release(struct net_device
*dev
);
195 static void claw_write_retry ( struct chbk
* p_ch
);
196 static void claw_write_next ( struct chbk
* p_ch
);
197 static void claw_timer ( struct chbk
* p_ch
);
200 static int add_claw_reads(struct net_device
*dev
,
201 struct ccwbk
* p_first
, struct ccwbk
* p_last
);
202 static void ccw_check_return_code (struct ccw_device
*cdev
, int return_code
);
203 static void ccw_check_unit_check (struct chbk
* p_ch
, unsigned char sense
);
204 static int find_link(struct net_device
*dev
, char *host_name
, char *ws_name
);
205 static int claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
);
206 static int init_ccw_bk(struct net_device
*dev
);
207 static void probe_error( struct ccwgroup_device
*cgdev
);
208 static struct net_device_stats
*claw_stats(struct net_device
*dev
);
209 static int pages_to_order_of_mag(int num_of_pages
);
210 static struct sk_buff
*claw_pack_skb(struct claw_privbk
*privptr
);
211 /* sysfs Functions */
212 static ssize_t
claw_hname_show(struct device
*dev
,
213 struct device_attribute
*attr
, char *buf
);
214 static ssize_t
claw_hname_write(struct device
*dev
,
215 struct device_attribute
*attr
,
216 const char *buf
, size_t count
);
217 static ssize_t
claw_adname_show(struct device
*dev
,
218 struct device_attribute
*attr
, char *buf
);
219 static ssize_t
claw_adname_write(struct device
*dev
,
220 struct device_attribute
*attr
,
221 const char *buf
, size_t count
);
222 static ssize_t
claw_apname_show(struct device
*dev
,
223 struct device_attribute
*attr
, char *buf
);
224 static ssize_t
claw_apname_write(struct device
*dev
,
225 struct device_attribute
*attr
,
226 const char *buf
, size_t count
);
227 static ssize_t
claw_wbuff_show(struct device
*dev
,
228 struct device_attribute
*attr
, char *buf
);
229 static ssize_t
claw_wbuff_write(struct device
*dev
,
230 struct device_attribute
*attr
,
231 const char *buf
, size_t count
);
232 static ssize_t
claw_rbuff_show(struct device
*dev
,
233 struct device_attribute
*attr
, char *buf
);
234 static ssize_t
claw_rbuff_write(struct device
*dev
,
235 struct device_attribute
*attr
,
236 const char *buf
, size_t count
);
237 static int claw_add_files(struct device
*dev
);
238 static void claw_remove_files(struct device
*dev
);
240 /* Functions for System Validate */
241 static int claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
);
242 static int claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
243 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
);
244 static int claw_snd_conn_req(struct net_device
*dev
, __u8 link
);
245 static int claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
);
246 static int claw_snd_sys_validate_rsp(struct net_device
*dev
,
247 struct clawctl
* p_ctl
, __u32 return_code
);
248 static int claw_strt_conn_req(struct net_device
*dev
);
249 static void claw_strt_read(struct net_device
*dev
, int lock
);
250 static void claw_strt_out_IO(struct net_device
*dev
);
251 static void claw_free_wrt_buf(struct net_device
*dev
);
253 /* Functions for unpack reads */
254 static void unpack_read(struct net_device
*dev
);
256 static int claw_pm_prepare(struct ccwgroup_device
*gdev
)
261 /* the root device for claw group devices */
262 static struct device
*claw_root_dev
;
266 static struct ccwgroup_driver claw_group_driver
= {
268 .owner
= THIS_MODULE
,
272 .driver_id
= 0xC3D3C1E6,
274 .remove
= claw_remove_device
,
275 .set_online
= claw_new_device
,
276 .set_offline
= claw_shutdown_device
,
277 .prepare
= claw_pm_prepare
,
280 static struct ccw_device_id claw_ids
[] = {
281 {CCW_DEVICE(0x3088, 0x61), .driver_info
= claw_channel_type_claw
},
284 MODULE_DEVICE_TABLE(ccw
, claw_ids
);
286 static struct ccw_driver claw_ccw_driver
= {
288 .owner
= THIS_MODULE
,
292 .probe
= ccwgroup_probe_ccwdev
,
293 .remove
= ccwgroup_remove_ccwdev
,
297 claw_driver_group_store(struct device_driver
*ddrv
, const char *buf
,
301 err
= ccwgroup_create_from_string(claw_root_dev
,
302 claw_group_driver
.driver_id
,
303 &claw_ccw_driver
, 2, buf
);
304 return err
? err
: count
;
307 static DRIVER_ATTR(group
, 0200, NULL
, claw_driver_group_store
);
309 static struct attribute
*claw_group_attrs
[] = {
310 &driver_attr_group
.attr
,
314 static struct attribute_group claw_group_attr_group
= {
315 .attrs
= claw_group_attrs
,
318 static const struct attribute_group
*claw_group_attr_groups
[] = {
319 &claw_group_attr_group
,
327 /*----------------------------------------------------------------*
329 * this function is called for each CLAW device. *
330 *----------------------------------------------------------------*/
332 claw_probe(struct ccwgroup_device
*cgdev
)
335 struct claw_privbk
*privptr
=NULL
;
337 CLAW_DBF_TEXT(2, setup
, "probe");
338 if (!get_device(&cgdev
->dev
))
340 privptr
= kzalloc(sizeof(struct claw_privbk
), GFP_KERNEL
);
341 dev_set_drvdata(&cgdev
->dev
, privptr
);
342 if (privptr
== NULL
) {
344 put_device(&cgdev
->dev
);
345 CLAW_DBF_TEXT_(2, setup
, "probex%d", -ENOMEM
);
348 privptr
->p_mtc_envelope
= kzalloc( MAX_ENVELOPE_SIZE
, GFP_KERNEL
);
349 privptr
->p_env
= kzalloc(sizeof(struct claw_env
), GFP_KERNEL
);
350 if ((privptr
->p_mtc_envelope
==NULL
) || (privptr
->p_env
==NULL
)) {
352 put_device(&cgdev
->dev
);
353 CLAW_DBF_TEXT_(2, setup
, "probex%d", -ENOMEM
);
356 memcpy(privptr
->p_env
->adapter_name
,WS_NAME_NOT_DEF
,8);
357 memcpy(privptr
->p_env
->host_name
,WS_NAME_NOT_DEF
,8);
358 memcpy(privptr
->p_env
->api_type
,WS_NAME_NOT_DEF
,8);
359 privptr
->p_env
->packing
= 0;
360 privptr
->p_env
->write_buffers
= 5;
361 privptr
->p_env
->read_buffers
= 5;
362 privptr
->p_env
->read_size
= CLAW_FRAME_SIZE
;
363 privptr
->p_env
->write_size
= CLAW_FRAME_SIZE
;
364 rc
= claw_add_files(&cgdev
->dev
);
367 put_device(&cgdev
->dev
);
368 dev_err(&cgdev
->dev
, "Creating the /proc files for a new"
369 " CLAW device failed\n");
370 CLAW_DBF_TEXT_(2, setup
, "probex%d", rc
);
373 privptr
->p_env
->p_priv
= privptr
;
374 cgdev
->cdev
[0]->handler
= claw_irq_handler
;
375 cgdev
->cdev
[1]->handler
= claw_irq_handler
;
376 CLAW_DBF_TEXT(2, setup
, "prbext 0");
379 } /* end of claw_probe */
381 /*-------------------------------------------------------------------*
383 *-------------------------------------------------------------------*/
386 claw_tx(struct sk_buff
*skb
, struct net_device
*dev
)
389 struct claw_privbk
*privptr
= dev
->ml_priv
;
390 unsigned long saveflags
;
393 CLAW_DBF_TEXT(4, trace
, "claw_tx");
394 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
395 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
396 rc
=claw_hw_tx( skb
, dev
, 1 );
397 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
398 CLAW_DBF_TEXT_(4, trace
, "clawtx%d", rc
);
404 } /* end of claw_tx */
406 /*------------------------------------------------------------------*
407 * pack the collect queue into an skb and return it *
408 * If not packing just return the top skb from the queue *
409 *------------------------------------------------------------------*/
411 static struct sk_buff
*
412 claw_pack_skb(struct claw_privbk
*privptr
)
414 struct sk_buff
*new_skb
,*held_skb
;
415 struct chbk
*p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
416 struct claw_env
*p_env
= privptr
->p_env
;
417 int pkt_cnt
,pk_ind
,so_far
;
419 new_skb
= NULL
; /* assume no dice */
421 CLAW_DBF_TEXT(4, trace
, "PackSKBe");
422 if (!skb_queue_empty(&p_ch
->collect_queue
)) {
424 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
426 dev_kfree_skb_any(held_skb
);
429 if (p_env
->packing
!= DO_PACKED
)
431 /* get a new SKB we will pack at least one */
432 new_skb
= dev_alloc_skb(p_env
->write_size
);
433 if (new_skb
== NULL
) {
434 atomic_inc(&held_skb
->users
);
435 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
438 /* we have packed packet and a place to put it */
441 new_skb
->cb
[1] = 'P'; /* every skb on queue has pack header */
442 while ((pk_ind
) && (held_skb
!= NULL
)) {
443 if (held_skb
->len
+so_far
<= p_env
->write_size
-8) {
444 memcpy(skb_put(new_skb
,held_skb
->len
),
445 held_skb
->data
,held_skb
->len
);
446 privptr
->stats
.tx_packets
++;
447 so_far
+= held_skb
->len
;
449 dev_kfree_skb_any(held_skb
);
450 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
452 atomic_dec(&held_skb
->users
);
455 atomic_inc(&held_skb
->users
);
456 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
460 CLAW_DBF_TEXT(4, trace
, "PackSKBx");
464 /*-------------------------------------------------------------------*
467 *-------------------------------------------------------------------*/
470 claw_change_mtu(struct net_device
*dev
, int new_mtu
)
472 struct claw_privbk
*privptr
= dev
->ml_priv
;
474 CLAW_DBF_TEXT(4, trace
, "setmtu");
475 buff_size
= privptr
->p_env
->write_size
;
476 if ((new_mtu
< 60) || (new_mtu
> buff_size
)) {
481 } /* end of claw_change_mtu */
484 /*-------------------------------------------------------------------*
487 *-------------------------------------------------------------------*/
489 claw_open(struct net_device
*dev
)
494 unsigned long saveflags
=0;
496 struct claw_privbk
*privptr
;
497 DECLARE_WAITQUEUE(wait
, current
);
498 struct timer_list timer
;
501 CLAW_DBF_TEXT(4, trace
, "open");
502 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
503 /* allocate and initialize CCW blocks */
504 if (privptr
->buffs_alloc
== 0) {
507 CLAW_DBF_TEXT(2, trace
, "openmem");
511 privptr
->system_validate_comp
=0;
512 privptr
->release_pend
=0;
513 if(strncmp(privptr
->p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
514 privptr
->p_env
->read_size
=DEF_PACK_BUFSIZE
;
515 privptr
->p_env
->write_size
=DEF_PACK_BUFSIZE
;
516 privptr
->p_env
->packing
=PACKING_ASK
;
518 privptr
->p_env
->packing
=0;
519 privptr
->p_env
->read_size
=CLAW_FRAME_SIZE
;
520 privptr
->p_env
->write_size
=CLAW_FRAME_SIZE
;
523 tasklet_init(&privptr
->channel
[READ_CHANNEL
].tasklet
, claw_irq_tasklet
,
524 (unsigned long) &privptr
->channel
[READ_CHANNEL
]);
525 for ( i
= 0; i
< 2; i
++) {
526 CLAW_DBF_TEXT_(2, trace
, "opn_ch%d", i
);
527 init_waitqueue_head(&privptr
->channel
[i
].wait
);
528 /* skb_queue_head_init(&p_ch->io_queue); */
529 if (i
== WRITE_CHANNEL
)
531 &privptr
->channel
[WRITE_CHANNEL
].collect_queue
);
532 privptr
->channel
[i
].flag_a
= 0;
533 privptr
->channel
[i
].IO_active
= 0;
534 privptr
->channel
[i
].flag
&= ~CLAW_TIMER
;
536 timer
.function
= (void *)claw_timer
;
537 timer
.data
= (unsigned long)(&privptr
->channel
[i
]);
538 timer
.expires
= jiffies
+ 15*HZ
;
540 spin_lock_irqsave(get_ccwdev_lock(
541 privptr
->channel
[i
].cdev
), saveflags
);
542 parm
= (unsigned long) &privptr
->channel
[i
];
543 privptr
->channel
[i
].claw_state
= CLAW_START_HALT_IO
;
545 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
546 rc
= ccw_device_halt(
547 (struct ccw_device
*)privptr
->channel
[i
].cdev
,parm
);
548 set_current_state(TASK_INTERRUPTIBLE
);
549 spin_unlock_irqrestore(
550 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
552 set_current_state(TASK_RUNNING
);
553 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
555 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
556 if((privptr
->channel
[i
].flag
& CLAW_TIMER
) == 0x00)
559 if ((((privptr
->channel
[READ_CHANNEL
].last_dstat
|
560 privptr
->channel
[WRITE_CHANNEL
].last_dstat
) &
561 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) ||
562 (((privptr
->channel
[READ_CHANNEL
].flag
|
563 privptr
->channel
[WRITE_CHANNEL
].flag
) & CLAW_TIMER
) != 0x00)) {
564 dev_info(&privptr
->channel
[READ_CHANNEL
].cdev
->dev
,
565 "%s: remote side is not ready\n", dev
->name
);
566 CLAW_DBF_TEXT(2, trace
, "notrdy");
568 for ( i
= 0; i
< 2; i
++) {
570 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
572 parm
= (unsigned long) &privptr
->channel
[i
];
573 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
574 rc
= ccw_device_halt(
575 (struct ccw_device
*)&privptr
->channel
[i
].cdev
,
577 spin_unlock_irqrestore(
578 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
581 ccw_check_return_code(
582 privptr
->channel
[i
].cdev
, rc
);
585 free_pages((unsigned long)privptr
->p_buff_ccw
,
586 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
587 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
588 free_pages((unsigned long)privptr
->p_buff_read
,
589 (int)pages_to_order_of_mag(
590 privptr
->p_buff_read_num
));
593 p_buf
=privptr
->p_read_active_first
;
594 while (p_buf
!=NULL
) {
595 free_pages((unsigned long)p_buf
->p_buffer
,
596 (int)pages_to_order_of_mag(
597 privptr
->p_buff_pages_perread
));
601 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
602 free_pages((unsigned long)privptr
->p_buff_write
,
603 (int)pages_to_order_of_mag(
604 privptr
->p_buff_write_num
));
607 p_buf
=privptr
->p_write_active_first
;
608 while (p_buf
!=NULL
) {
609 free_pages((unsigned long)p_buf
->p_buffer
,
610 (int)pages_to_order_of_mag(
611 privptr
->p_buff_pages_perwrite
));
615 privptr
->buffs_alloc
= 0;
616 privptr
->channel
[READ_CHANNEL
].flag
= 0x00;
617 privptr
->channel
[WRITE_CHANNEL
].flag
= 0x00;
618 privptr
->p_buff_ccw
=NULL
;
619 privptr
->p_buff_read
=NULL
;
620 privptr
->p_buff_write
=NULL
;
621 claw_clear_busy(dev
);
622 CLAW_DBF_TEXT(2, trace
, "open EIO");
626 /* Send SystemValidate command */
628 claw_clear_busy(dev
);
629 CLAW_DBF_TEXT(4, trace
, "openok");
631 } /* end of claw_open */
633 /*-------------------------------------------------------------------*
637 *--------------------------------------------------------------------*/
639 claw_irq_handler(struct ccw_device
*cdev
,
640 unsigned long intparm
, struct irb
*irb
)
642 struct chbk
*p_ch
= NULL
;
643 struct claw_privbk
*privptr
= NULL
;
644 struct net_device
*dev
= NULL
;
645 struct claw_env
*p_env
;
646 struct chbk
*p_ch_r
=NULL
;
648 kstat_cpu(smp_processor_id()).irqs
[IOINT_CLW
]++;
649 CLAW_DBF_TEXT(4, trace
, "clawirq");
650 /* Bypass all 'unsolicited interrupts' */
651 privptr
= dev_get_drvdata(&cdev
->dev
);
653 dev_warn(&cdev
->dev
, "An uninitialized CLAW device received an"
654 " IRQ, c-%02x d-%02x\n",
655 irb
->scsw
.cmd
.cstat
, irb
->scsw
.cmd
.dstat
);
656 CLAW_DBF_TEXT(2, trace
, "badirq");
660 /* Try to extract channel from driver data. */
661 if (privptr
->channel
[READ_CHANNEL
].cdev
== cdev
)
662 p_ch
= &privptr
->channel
[READ_CHANNEL
];
663 else if (privptr
->channel
[WRITE_CHANNEL
].cdev
== cdev
)
664 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
666 dev_warn(&cdev
->dev
, "The device is not a CLAW device\n");
667 CLAW_DBF_TEXT(2, trace
, "badchan");
670 CLAW_DBF_TEXT_(4, trace
, "IRQCH=%d", p_ch
->flag
);
672 dev
= (struct net_device
*) (p_ch
->ndev
);
673 p_env
=privptr
->p_env
;
675 /* Copy interruption response block. */
676 memcpy(p_ch
->irb
, irb
, sizeof(struct irb
));
678 /* Check for good subchannel return code, otherwise info message */
679 if (irb
->scsw
.cmd
.cstat
&& !(irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
)) {
681 "%s: subchannel check for device: %04x -"
682 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
683 dev
->name
, p_ch
->devno
,
684 irb
->scsw
.cmd
.cstat
, irb
->scsw
.cmd
.dstat
,
686 CLAW_DBF_TEXT(2, trace
, "chanchk");
690 /* Check the reason-code of a unit check */
691 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
692 ccw_check_unit_check(p_ch
, irb
->ecw
[0]);
694 /* State machine to bring the connection up, down and to restart */
695 p_ch
->last_dstat
= irb
->scsw
.cmd
.dstat
;
697 switch (p_ch
->claw_state
) {
698 case CLAW_STOP
:/* HALT_IO by claw_release (halt sequence) */
699 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
700 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
701 (p_ch
->irb
->scsw
.cmd
.stctl
==
702 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
))))
704 wake_up(&p_ch
->wait
); /* wake up claw_release */
705 CLAW_DBF_TEXT(4, trace
, "stop");
707 case CLAW_START_HALT_IO
: /* HALT_IO issued by claw_open */
708 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
709 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
710 (p_ch
->irb
->scsw
.cmd
.stctl
==
711 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
712 CLAW_DBF_TEXT(4, trace
, "haltio");
715 if (p_ch
->flag
== CLAW_READ
) {
716 p_ch
->claw_state
= CLAW_START_READ
;
717 wake_up(&p_ch
->wait
); /* wake claw_open (READ)*/
718 } else if (p_ch
->flag
== CLAW_WRITE
) {
719 p_ch
->claw_state
= CLAW_START_WRITE
;
720 /* send SYSTEM_VALIDATE */
721 claw_strt_read(dev
, LOCK_NO
);
722 claw_send_control(dev
,
723 SYSTEM_VALIDATE_REQUEST
,
726 p_env
->adapter_name
);
728 dev_warn(&cdev
->dev
, "The CLAW device received"
729 " an unexpected IRQ, "
732 irb
->scsw
.cmd
.dstat
);
735 CLAW_DBF_TEXT(4, trace
, "haltio");
737 case CLAW_START_READ
:
738 CLAW_DBF_TEXT(4, trace
, "ReadIRQ");
739 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) {
740 clear_bit(0, (void *)&p_ch
->IO_active
);
741 if ((p_ch
->irb
->ecw
[0] & 0x41) == 0x41 ||
742 (p_ch
->irb
->ecw
[0] & 0x40) == 0x40 ||
743 (p_ch
->irb
->ecw
[0]) == 0) {
744 privptr
->stats
.rx_errors
++;
746 "%s: Restart is required after remote "
750 CLAW_DBF_TEXT(4, trace
, "notrdy");
753 if ((p_ch
->irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
) &&
754 (p_ch
->irb
->scsw
.cmd
.dstat
== 0)) {
755 if (test_and_set_bit(CLAW_BH_ACTIVE
,
756 (void *)&p_ch
->flag_a
) == 0)
757 tasklet_schedule(&p_ch
->tasklet
);
759 CLAW_DBF_TEXT(4, trace
, "PCINoBH");
760 CLAW_DBF_TEXT(4, trace
, "PCI_read");
763 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
764 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
765 (p_ch
->irb
->scsw
.cmd
.stctl
==
766 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
767 CLAW_DBF_TEXT(4, trace
, "SPend_rd");
770 clear_bit(0, (void *)&p_ch
->IO_active
);
771 claw_clearbit_busy(TB_RETRY
, dev
);
772 if (test_and_set_bit(CLAW_BH_ACTIVE
,
773 (void *)&p_ch
->flag_a
) == 0)
774 tasklet_schedule(&p_ch
->tasklet
);
776 CLAW_DBF_TEXT(4, trace
, "RdBHAct");
777 CLAW_DBF_TEXT(4, trace
, "RdIRQXit");
779 case CLAW_START_WRITE
:
780 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) {
782 "%s: Unit Check Occurred in "
783 "write channel\n", dev
->name
);
784 clear_bit(0, (void *)&p_ch
->IO_active
);
785 if (p_ch
->irb
->ecw
[0] & 0x80) {
787 "%s: Resetting Event "
788 "occurred:\n", dev
->name
);
789 init_timer(&p_ch
->timer
);
790 p_ch
->timer
.function
=
791 (void *)claw_write_retry
;
792 p_ch
->timer
.data
= (unsigned long)p_ch
;
793 p_ch
->timer
.expires
= jiffies
+ 10*HZ
;
794 add_timer(&p_ch
->timer
);
796 "%s: write connection "
797 "restarting\n", dev
->name
);
799 CLAW_DBF_TEXT(4, trace
, "rstrtwrt");
802 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) {
803 clear_bit(0, (void *)&p_ch
->IO_active
);
805 "%s: Unit Exception "
806 "occurred in write channel\n",
809 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
810 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
811 (p_ch
->irb
->scsw
.cmd
.stctl
==
812 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
813 CLAW_DBF_TEXT(4, trace
, "writeUE");
816 clear_bit(0, (void *)&p_ch
->IO_active
);
817 if (claw_test_and_setbit_busy(TB_TX
, dev
) == 0) {
818 claw_write_next(p_ch
);
819 claw_clearbit_busy(TB_TX
, dev
);
820 claw_clear_busy(dev
);
822 p_ch_r
= (struct chbk
*)&privptr
->channel
[READ_CHANNEL
];
823 if (test_and_set_bit(CLAW_BH_ACTIVE
,
824 (void *)&p_ch_r
->flag_a
) == 0)
825 tasklet_schedule(&p_ch_r
->tasklet
);
826 CLAW_DBF_TEXT(4, trace
, "StWtExit");
830 "The CLAW device for %s received an unexpected IRQ\n",
832 CLAW_DBF_TEXT(2, trace
, "badIRQ");
836 } /* end of claw_irq_handler */
839 /*-------------------------------------------------------------------*
842 *--------------------------------------------------------------------*/
844 claw_irq_tasklet ( unsigned long data
)
847 struct net_device
*dev
;
848 struct claw_privbk
* privptr
;
850 p_ch
= (struct chbk
*) data
;
851 dev
= (struct net_device
*)p_ch
->ndev
;
852 CLAW_DBF_TEXT(4, trace
, "IRQtask");
853 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
855 clear_bit(CLAW_BH_ACTIVE
, (void *)&p_ch
->flag_a
);
856 CLAW_DBF_TEXT(4, trace
, "TskletXt");
858 } /* end of claw_irq_bh */
860 /*-------------------------------------------------------------------*
863 *--------------------------------------------------------------------*/
865 claw_release(struct net_device
*dev
)
869 unsigned long saveflags
;
871 struct claw_privbk
*privptr
;
872 DECLARE_WAITQUEUE(wait
, current
);
873 struct ccwbk
* p_this_ccw
;
878 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
881 CLAW_DBF_TEXT(4, trace
, "release");
882 privptr
->release_pend
=1;
883 claw_setbit_busy(TB_STOP
,dev
);
884 for ( i
= 1; i
>=0 ; i
--) {
886 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
887 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
888 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
889 privptr
->channel
[i
].IO_active
= 0;
890 parm
= (unsigned long) &privptr
->channel
[i
];
891 if (i
== WRITE_CHANNEL
)
892 claw_purge_skb_queue(
893 &privptr
->channel
[WRITE_CHANNEL
].collect_queue
);
894 rc
= ccw_device_halt (privptr
->channel
[i
].cdev
, parm
);
895 if (privptr
->system_validate_comp
==0x00) /* never opened? */
896 init_waitqueue_head(&privptr
->channel
[i
].wait
);
897 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
898 set_current_state(TASK_INTERRUPTIBLE
);
899 spin_unlock_irqrestore(
900 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
902 set_current_state(TASK_RUNNING
);
903 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
905 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
908 if (privptr
->pk_skb
!= NULL
) {
909 dev_kfree_skb_any(privptr
->pk_skb
);
910 privptr
->pk_skb
= NULL
;
912 if(privptr
->buffs_alloc
!= 1) {
913 CLAW_DBF_TEXT(4, trace
, "none2fre");
916 CLAW_DBF_TEXT(4, trace
, "freebufs");
917 if (privptr
->p_buff_ccw
!= NULL
) {
918 free_pages((unsigned long)privptr
->p_buff_ccw
,
919 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
921 CLAW_DBF_TEXT(4, trace
, "freeread");
922 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
923 if (privptr
->p_buff_read
!= NULL
) {
924 free_pages((unsigned long)privptr
->p_buff_read
,
925 (int)pages_to_order_of_mag(privptr
->p_buff_read_num
));
929 p_buf
=privptr
->p_read_active_first
;
930 while (p_buf
!=NULL
) {
931 free_pages((unsigned long)p_buf
->p_buffer
,
932 (int)pages_to_order_of_mag(
933 privptr
->p_buff_pages_perread
));
937 CLAW_DBF_TEXT(4, trace
, "freewrit");
938 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
939 free_pages((unsigned long)privptr
->p_buff_write
,
940 (int)pages_to_order_of_mag(privptr
->p_buff_write_num
));
943 p_buf
=privptr
->p_write_active_first
;
944 while (p_buf
!=NULL
) {
945 free_pages((unsigned long)p_buf
->p_buffer
,
946 (int)pages_to_order_of_mag(
947 privptr
->p_buff_pages_perwrite
));
951 CLAW_DBF_TEXT(4, trace
, "clearptr");
952 privptr
->buffs_alloc
= 0;
953 privptr
->p_buff_ccw
=NULL
;
954 privptr
->p_buff_read
=NULL
;
955 privptr
->p_buff_write
=NULL
;
956 privptr
->system_validate_comp
=0;
957 privptr
->release_pend
=0;
958 /* Remove any writes that were pending and reset all reads */
959 p_this_ccw
=privptr
->p_read_active_first
;
960 while (p_this_ccw
!=NULL
) {
961 p_this_ccw
->header
.length
=0xffff;
962 p_this_ccw
->header
.opcode
=0xff;
963 p_this_ccw
->header
.flag
=0x00;
964 p_this_ccw
=p_this_ccw
->next
;
967 while (privptr
->p_write_active_first
!=NULL
) {
968 p_this_ccw
=privptr
->p_write_active_first
;
969 p_this_ccw
->header
.flag
=CLAW_PENDING
;
970 privptr
->p_write_active_first
=p_this_ccw
->next
;
971 p_this_ccw
->next
=privptr
->p_write_free_chain
;
972 privptr
->p_write_free_chain
=p_this_ccw
;
973 ++privptr
->write_free_count
;
975 privptr
->p_write_active_last
=NULL
;
976 privptr
->mtc_logical_link
= -1;
977 privptr
->mtc_skipping
= 1;
978 privptr
->mtc_offset
=0;
980 if (((privptr
->channel
[READ_CHANNEL
].last_dstat
|
981 privptr
->channel
[WRITE_CHANNEL
].last_dstat
) &
982 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) {
983 dev_warn(&privptr
->channel
[READ_CHANNEL
].cdev
->dev
,
984 "Deactivating %s completed with incorrect"
985 " subchannel status "
986 "(read %02x, write %02x)\n",
988 privptr
->channel
[READ_CHANNEL
].last_dstat
,
989 privptr
->channel
[WRITE_CHANNEL
].last_dstat
);
990 CLAW_DBF_TEXT(2, trace
, "badclose");
992 CLAW_DBF_TEXT(4, trace
, "rlsexit");
994 } /* end of claw_release */
996 /*-------------------------------------------------------------------*
999 *--------------------------------------------------------------------*/
1002 claw_write_retry ( struct chbk
*p_ch
)
1005 struct net_device
*dev
=p_ch
->ndev
;
1007 CLAW_DBF_TEXT(4, trace
, "w_retry");
1008 if (p_ch
->claw_state
== CLAW_STOP
) {
1011 claw_strt_out_IO( dev
);
1012 CLAW_DBF_TEXT(4, trace
, "rtry_xit");
1014 } /* end of claw_write_retry */
1017 /*-------------------------------------------------------------------*
1020 *--------------------------------------------------------------------*/
1023 claw_write_next ( struct chbk
* p_ch
)
1026 struct net_device
*dev
;
1027 struct claw_privbk
*privptr
=NULL
;
1028 struct sk_buff
*pk_skb
;
1031 CLAW_DBF_TEXT(4, trace
, "claw_wrt");
1032 if (p_ch
->claw_state
== CLAW_STOP
)
1034 dev
= (struct net_device
*) p_ch
->ndev
;
1035 privptr
= (struct claw_privbk
*) dev
->ml_priv
;
1036 claw_free_wrt_buf( dev
);
1037 if ((privptr
->write_free_count
> 0) &&
1038 !skb_queue_empty(&p_ch
->collect_queue
)) {
1039 pk_skb
= claw_pack_skb(privptr
);
1040 while (pk_skb
!= NULL
) {
1041 rc
= claw_hw_tx( pk_skb
, dev
,1);
1042 if (privptr
->write_free_count
> 0) {
1043 pk_skb
= claw_pack_skb(privptr
);
1048 if (privptr
->p_write_active_first
!=NULL
) {
1049 claw_strt_out_IO(dev
);
1052 } /* end of claw_write_next */
1054 /*-------------------------------------------------------------------*
1057 *--------------------------------------------------------------------*/
1060 claw_timer ( struct chbk
* p_ch
)
1062 CLAW_DBF_TEXT(4, trace
, "timer");
1063 p_ch
->flag
|= CLAW_TIMER
;
1064 wake_up(&p_ch
->wait
);
1066 } /* end of claw_timer */
1074 /*-------------------------------------------------------------------*
1076 * pages_to_order_of_mag *
1078 * takes a number of pages from 1 to 512 and returns the *
1079 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1080 * of magnitude get_free_pages() has an upper order of 9 *
1081 *--------------------------------------------------------------------*/
1084 pages_to_order_of_mag(int num_of_pages
)
1086 int order_of_mag
=1; /* assume 2 pages */
1089 CLAW_DBF_TEXT_(5, trace
, "pages%d", num_of_pages
);
1090 if (num_of_pages
== 1) {return 0; } /* magnitude of 0 = 1 page */
1091 /* 512 pages = 2Meg on 4k page systems */
1092 if (num_of_pages
>= 512) {return 9; }
1093 /* we have two or more pages order is at least 1 */
1094 for (nump
=2 ;nump
<= 512;nump
*=2) {
1095 if (num_of_pages
<= nump
)
1099 if (order_of_mag
> 9) { order_of_mag
= 9; } /* I know it's paranoid */
1100 CLAW_DBF_TEXT_(5, trace
, "mag%d", order_of_mag
);
1101 return order_of_mag
;
1104 /*-------------------------------------------------------------------*
1108 *--------------------------------------------------------------------*/
1110 add_claw_reads(struct net_device
*dev
, struct ccwbk
* p_first
,
1111 struct ccwbk
* p_last
)
1113 struct claw_privbk
*privptr
;
1114 struct ccw1 temp_ccw
;
1115 struct endccw
* p_end
;
1116 CLAW_DBF_TEXT(4, trace
, "addreads");
1117 privptr
= dev
->ml_priv
;
1118 p_end
= privptr
->p_end_ccw
;
1120 /* first CCW and last CCW contains a new set of read channel programs
1121 * to apend the running channel programs
1123 if ( p_first
==NULL
) {
1124 CLAW_DBF_TEXT(4, trace
, "addexit");
1128 /* set up ending CCW sequence for this segment */
1130 p_end
->read1
=0x00; /* second ending CCW is now active */
1131 /* reset ending CCWs and setup TIC CCWs */
1132 p_end
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1133 p_end
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1134 p_last
->r_TIC_1
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1135 p_last
->r_TIC_2
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1136 p_end
->read2_nop2
.cda
=0;
1137 p_end
->read2_nop2
.count
=1;
1140 p_end
->read1
=0x01; /* first ending CCW is now active */
1141 /* reset ending CCWs and setup TIC CCWs */
1142 p_end
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1143 p_end
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1144 p_last
->r_TIC_1
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1145 p_last
->r_TIC_2
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1146 p_end
->read1_nop2
.cda
=0;
1147 p_end
->read1_nop2
.count
=1;
1150 if ( privptr
-> p_read_active_first
==NULL
) {
1151 privptr
->p_read_active_first
= p_first
; /* set new first */
1152 privptr
->p_read_active_last
= p_last
; /* set new last */
1156 /* set up TIC ccw */
1157 temp_ccw
.cda
= (__u32
)__pa(&p_first
->read
);
1160 temp_ccw
.cmd_code
= CCW_CLAW_CMD_TIC
;
1165 /* first set of CCW's is chained to the new read */
1166 /* chain, so the second set is chained to the active chain. */
1167 /* Therefore modify the second set to point to the new */
1168 /* read chain set up TIC CCWs */
1169 /* make sure we update the CCW so channel doesn't fetch it */
1170 /* when it's only half done */
1171 memcpy( &p_end
->read2_nop2
, &temp_ccw
,
1172 sizeof(struct ccw1
));
1173 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1174 (__u32
)__pa(&p_first
->read
);
1175 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1176 (__u32
)__pa(&p_first
->read
);
1179 /* make sure we update the CCW so channel doesn't */
1180 /* fetch it when it is only half done */
1181 memcpy( &p_end
->read1_nop2
, &temp_ccw
,
1182 sizeof(struct ccw1
));
1183 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1184 (__u32
)__pa(&p_first
->read
);
1185 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1186 (__u32
)__pa(&p_first
->read
);
1188 /* chain in new set of blocks */
1189 privptr
->p_read_active_last
->next
= p_first
;
1190 privptr
->p_read_active_last
=p_last
;
1191 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1192 CLAW_DBF_TEXT(4, trace
, "addexit");
1194 } /* end of add_claw_reads */
1196 /*-------------------------------------------------------------------*
1197 * ccw_check_return_code *
1199 *-------------------------------------------------------------------*/
1202 ccw_check_return_code(struct ccw_device
*cdev
, int return_code
)
1204 CLAW_DBF_TEXT(4, trace
, "ccwret");
1205 if (return_code
!= 0) {
1206 switch (return_code
) {
1207 case -EBUSY
: /* BUSY is a transient state no action needed */
1210 dev_err(&cdev
->dev
, "The remote channel adapter is not"
1215 "The status of the remote channel adapter"
1219 dev_err(&cdev
->dev
, "The common device layer"
1220 " returned error code %d\n",
1224 CLAW_DBF_TEXT(4, trace
, "ccwret");
1225 } /* end of ccw_check_return_code */
1227 /*-------------------------------------------------------------------*
1228 * ccw_check_unit_check *
1229 *--------------------------------------------------------------------*/
1232 ccw_check_unit_check(struct chbk
* p_ch
, unsigned char sense
)
1234 struct net_device
*ndev
= p_ch
->ndev
;
1235 struct device
*dev
= &p_ch
->cdev
->dev
;
1237 CLAW_DBF_TEXT(4, trace
, "unitchek");
1238 dev_warn(dev
, "The communication peer of %s disconnected\n",
1243 dev_warn(dev
, "The remote channel adapter for"
1244 " %s has been reset\n",
1247 } else if (sense
& 0x20) {
1249 dev_warn(dev
, "A data streaming timeout occurred"
1252 } else if (sense
& 0x10) {
1253 dev_warn(dev
, "The remote channel adapter for %s"
1257 dev_warn(dev
, "A data transfer parity error occurred"
1261 } else if (sense
& 0x10) {
1262 dev_warn(dev
, "A read data parity error occurred"
1267 } /* end of ccw_check_unit_check */
1269 /*-------------------------------------------------------------------*
1271 *--------------------------------------------------------------------*/
1273 find_link(struct net_device
*dev
, char *host_name
, char *ws_name
)
1275 struct claw_privbk
*privptr
;
1276 struct claw_env
*p_env
;
1279 CLAW_DBF_TEXT(2, setup
, "findlink");
1280 privptr
= dev
->ml_priv
;
1281 p_env
=privptr
->p_env
;
1282 switch (p_env
->packing
)
1285 if ((memcmp(WS_APPL_NAME_PACKED
, host_name
, 8)!=0) ||
1286 (memcmp(WS_APPL_NAME_PACKED
, ws_name
, 8)!=0 ))
1291 if ((memcmp(WS_APPL_NAME_IP_NAME
, host_name
, 8)!=0) ||
1292 (memcmp(WS_APPL_NAME_IP_NAME
, ws_name
, 8)!=0 ))
1296 if ((memcmp(HOST_APPL_NAME
, host_name
, 8)!=0) ||
1297 (memcmp(p_env
->api_type
, ws_name
, 8)!=0))
1303 } /* end of find_link */
1305 /*-------------------------------------------------------------------*
1309 *-------------------------------------------------------------------*/
1312 claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
)
1315 struct claw_privbk
*privptr
;
1316 struct ccwbk
*p_this_ccw
;
1317 struct ccwbk
*p_first_ccw
;
1318 struct ccwbk
*p_last_ccw
;
1320 signed long len_of_data
;
1321 unsigned long bytesInThisBuffer
;
1322 unsigned char *pDataAddress
;
1323 struct endccw
*pEnd
;
1324 struct ccw1 tempCCW
;
1326 struct claw_env
*p_env
;
1328 struct clawph
*pk_head
;
1331 CLAW_DBF_TEXT(4, trace
, "hw_tx");
1332 privptr
= (struct claw_privbk
*)(dev
->ml_priv
);
1333 p_ch
= (struct chbk
*)&privptr
->channel
[WRITE_CHANNEL
];
1334 p_env
=privptr
->p_env
;
1335 claw_free_wrt_buf(dev
); /* Clean up free chain if posible */
1336 /* scan the write queue to free any completed write packets */
1339 if ((p_env
->packing
>= PACK_SEND
) &&
1340 (skb
->cb
[1] != 'P')) {
1341 skb_push(skb
,sizeof(struct clawph
));
1342 pk_head
=(struct clawph
*)skb
->data
;
1343 pk_head
->len
=skb
->len
-sizeof(struct clawph
);
1344 if (pk_head
->len
%4) {
1345 pk_head
->len
+= 4-(pk_head
->len
%4);
1346 skb_pad(skb
,4-(pk_head
->len
%4));
1347 skb_put(skb
,4-(pk_head
->len
%4));
1349 if (p_env
->packing
== DO_PACKED
)
1350 pk_head
->link_num
= linkid
;
1352 pk_head
->link_num
= 0;
1353 pk_head
->flag
= 0x00;
1358 if (claw_check_busy(dev
)) {
1359 if (privptr
->write_free_count
!=0) {
1360 claw_clear_busy(dev
);
1363 claw_strt_out_IO(dev
);
1364 claw_free_wrt_buf( dev
);
1365 if (privptr
->write_free_count
==0) {
1366 ch
= &privptr
->channel
[WRITE_CHANNEL
];
1367 atomic_inc(&skb
->users
);
1368 skb_queue_tail(&ch
->collect_queue
, skb
);
1372 claw_clear_busy(dev
);
1377 if (claw_test_and_setbit_busy(TB_TX
,dev
)) { /* set to busy */
1378 ch
= &privptr
->channel
[WRITE_CHANNEL
];
1379 atomic_inc(&skb
->users
);
1380 skb_queue_tail(&ch
->collect_queue
, skb
);
1381 claw_strt_out_IO(dev
);
1386 /* See how many write buffers are required to hold this data */
1387 numBuffers
= DIV_ROUND_UP(skb
->len
, privptr
->p_env
->write_size
);
1389 /* If that number of buffers isn't available, give up for now */
1390 if (privptr
->write_free_count
< numBuffers
||
1391 privptr
->p_write_free_chain
== NULL
) {
1393 claw_setbit_busy(TB_NOBUFFER
,dev
);
1394 ch
= &privptr
->channel
[WRITE_CHANNEL
];
1395 atomic_inc(&skb
->users
);
1396 skb_queue_tail(&ch
->collect_queue
, skb
);
1397 CLAW_DBF_TEXT(2, trace
, "clawbusy");
1400 pDataAddress
=skb
->data
;
1401 len_of_data
=skb
->len
;
1403 while (len_of_data
> 0) {
1404 p_this_ccw
=privptr
->p_write_free_chain
; /* get a block */
1405 if (p_this_ccw
== NULL
) { /* lost the race */
1406 ch
= &privptr
->channel
[WRITE_CHANNEL
];
1407 atomic_inc(&skb
->users
);
1408 skb_queue_tail(&ch
->collect_queue
, skb
);
1411 privptr
->p_write_free_chain
=p_this_ccw
->next
;
1412 p_this_ccw
->next
=NULL
;
1413 --privptr
->write_free_count
; /* -1 */
1414 if (len_of_data
>= privptr
->p_env
->write_size
)
1415 bytesInThisBuffer
= privptr
->p_env
->write_size
;
1417 bytesInThisBuffer
= len_of_data
;
1418 memcpy( p_this_ccw
->p_buffer
,pDataAddress
, bytesInThisBuffer
);
1419 len_of_data
-=bytesInThisBuffer
;
1420 pDataAddress
+=(unsigned long)bytesInThisBuffer
;
1421 /* setup write CCW */
1422 p_this_ccw
->write
.cmd_code
= (linkid
* 8) +1;
1423 if (len_of_data
>0) {
1424 p_this_ccw
->write
.cmd_code
+=MORE_to_COME_FLAG
;
1426 p_this_ccw
->write
.count
=bytesInThisBuffer
;
1427 /* now add to end of this chain */
1428 if (p_first_ccw
==NULL
) {
1429 p_first_ccw
=p_this_ccw
;
1431 if (p_last_ccw
!=NULL
) {
1432 p_last_ccw
->next
=p_this_ccw
;
1433 /* set up TIC ccws */
1434 p_last_ccw
->w_TIC_1
.cda
=
1435 (__u32
)__pa(&p_this_ccw
->write
);
1437 p_last_ccw
=p_this_ccw
; /* save new last block */
1440 /* FirstCCW and LastCCW now contain a new set of write channel
1441 * programs to append to the running channel program
1444 if (p_first_ccw
!=NULL
) {
1445 /* setup ending ccw sequence for this segment */
1446 pEnd
=privptr
->p_end_ccw
;
1448 pEnd
->write1
=0x00; /* second end ccw is now active */
1449 /* set up Tic CCWs */
1450 p_last_ccw
->w_TIC_1
.cda
=
1451 (__u32
)__pa(&pEnd
->write2_nop1
);
1452 pEnd
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1453 pEnd
->write2_nop2
.flags
=
1454 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1455 pEnd
->write2_nop2
.cda
=0;
1456 pEnd
->write2_nop2
.count
=1;
1458 else { /* end of if (pEnd->write1)*/
1459 pEnd
->write1
=0x01; /* first end ccw is now active */
1460 /* set up Tic CCWs */
1461 p_last_ccw
->w_TIC_1
.cda
=
1462 (__u32
)__pa(&pEnd
->write1_nop1
);
1463 pEnd
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1464 pEnd
->write1_nop2
.flags
=
1465 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1466 pEnd
->write1_nop2
.cda
=0;
1467 pEnd
->write1_nop2
.count
=1;
1468 } /* end if if (pEnd->write1) */
1470 if (privptr
->p_write_active_first
==NULL
) {
1471 privptr
->p_write_active_first
=p_first_ccw
;
1472 privptr
->p_write_active_last
=p_last_ccw
;
1475 /* set up Tic CCWs */
1477 tempCCW
.cda
=(__u32
)__pa(&p_first_ccw
->write
);
1480 tempCCW
.cmd_code
=CCW_CLAW_CMD_TIC
;
1485 * first set of ending CCW's is chained to the new write
1486 * chain, so the second set is chained to the active chain
1487 * Therefore modify the second set to point the new write chain.
1488 * make sure we update the CCW atomically
1489 * so channel does not fetch it when it's only half done
1491 memcpy( &pEnd
->write2_nop2
, &tempCCW
,
1492 sizeof(struct ccw1
));
1493 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1494 (__u32
)__pa(&p_first_ccw
->write
);
1498 /*make sure we update the CCW atomically
1499 *so channel does not fetch it when it's only half done
1501 memcpy(&pEnd
->write1_nop2
, &tempCCW
,
1502 sizeof(struct ccw1
));
1503 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1504 (__u32
)__pa(&p_first_ccw
->write
);
1506 } /* end if if (pEnd->write1) */
1508 privptr
->p_write_active_last
->next
=p_first_ccw
;
1509 privptr
->p_write_active_last
=p_last_ccw
;
1512 } /* endif (p_first_ccw!=NULL) */
1513 dev_kfree_skb_any(skb
);
1520 claw_strt_out_IO(dev
);
1521 /* if write free count is zero , set NOBUFFER */
1522 if (privptr
->write_free_count
==0) {
1523 claw_setbit_busy(TB_NOBUFFER
,dev
);
1526 claw_clearbit_busy(TB_TX
,dev
);
1529 } /* end of claw_hw_tx */
1531 /*-------------------------------------------------------------------*
1535 *--------------------------------------------------------------------*/
1538 init_ccw_bk(struct net_device
*dev
)
1541 __u32 ccw_blocks_required
;
1542 __u32 ccw_blocks_perpage
;
1543 __u32 ccw_pages_required
;
1544 __u32 claw_reads_perpage
=1;
1545 __u32 claw_read_pages
;
1546 __u32 claw_writes_perpage
=1;
1547 __u32 claw_write_pages
;
1549 struct ccwbk
*p_free_chain
;
1551 struct ccwbk
*p_last_CCWB
;
1552 struct ccwbk
*p_first_CCWB
;
1553 struct endccw
*p_endccw
=NULL
;
1554 addr_t real_address
;
1555 struct claw_privbk
*privptr
= dev
->ml_priv
;
1556 struct clawh
*pClawH
=NULL
;
1557 addr_t real_TIC_address
;
1559 CLAW_DBF_TEXT(4, trace
, "init_ccw");
1561 /* initialize statistics field */
1562 privptr
->active_link_ID
=0;
1563 /* initialize ccwbk pointers */
1564 privptr
->p_write_free_chain
=NULL
; /* pointer to free ccw chain*/
1565 privptr
->p_write_active_first
=NULL
; /* pointer to the first write ccw*/
1566 privptr
->p_write_active_last
=NULL
; /* pointer to the last write ccw*/
1567 privptr
->p_read_active_first
=NULL
; /* pointer to the first read ccw*/
1568 privptr
->p_read_active_last
=NULL
; /* pointer to the last read ccw */
1569 privptr
->p_end_ccw
=NULL
; /* pointer to ending ccw */
1570 privptr
->p_claw_signal_blk
=NULL
; /* pointer to signal block */
1571 privptr
->buffs_alloc
= 0;
1572 memset(&privptr
->end_ccw
, 0x00, sizeof(struct endccw
));
1573 memset(&privptr
->ctl_bk
, 0x00, sizeof(struct clawctl
));
1574 /* initialize free write ccwbk counter */
1575 privptr
->write_free_count
=0; /* number of free bufs on write chain */
1579 * We need 1 CCW block for each read buffer, 1 for each
1580 * write buffer, plus 1 for ClawSignalBlock
1582 ccw_blocks_required
=
1583 privptr
->p_env
->read_buffers
+privptr
->p_env
->write_buffers
+1;
1585 * compute number of CCW blocks that will fit in a page
1587 ccw_blocks_perpage
= PAGE_SIZE
/ CCWBK_SIZE
;
1589 DIV_ROUND_UP(ccw_blocks_required
, ccw_blocks_perpage
);
1592 * read and write sizes are set by 2 constants in claw.h
1593 * 4k and 32k. Unpacked values other than 4k are not going to
1594 * provide good performance. With packing buffers support 32k
1597 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1598 claw_reads_perpage
= PAGE_SIZE
/ privptr
->p_env
->read_size
;
1599 claw_read_pages
= DIV_ROUND_UP(privptr
->p_env
->read_buffers
,
1600 claw_reads_perpage
);
1602 else { /* > or equal */
1603 privptr
->p_buff_pages_perread
=
1604 DIV_ROUND_UP(privptr
->p_env
->read_size
, PAGE_SIZE
);
1605 claw_read_pages
= privptr
->p_env
->read_buffers
*
1606 privptr
->p_buff_pages_perread
;
1608 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1609 claw_writes_perpage
=
1610 PAGE_SIZE
/ privptr
->p_env
->write_size
;
1611 claw_write_pages
= DIV_ROUND_UP(privptr
->p_env
->write_buffers
,
1612 claw_writes_perpage
);
1615 else { /* > or equal */
1616 privptr
->p_buff_pages_perwrite
=
1617 DIV_ROUND_UP(privptr
->p_env
->read_size
, PAGE_SIZE
);
1618 claw_write_pages
= privptr
->p_env
->write_buffers
*
1619 privptr
->p_buff_pages_perwrite
;
1622 * allocate ccw_pages_required
1624 if (privptr
->p_buff_ccw
==NULL
) {
1625 privptr
->p_buff_ccw
=
1626 (void *)__get_free_pages(__GFP_DMA
,
1627 (int)pages_to_order_of_mag(ccw_pages_required
));
1628 if (privptr
->p_buff_ccw
==NULL
) {
1631 privptr
->p_buff_ccw_num
=ccw_pages_required
;
1633 memset(privptr
->p_buff_ccw
, 0x00,
1634 privptr
->p_buff_ccw_num
* PAGE_SIZE
);
1637 * obtain ending ccw block address
1640 privptr
->p_end_ccw
= (struct endccw
*)&privptr
->end_ccw
;
1641 real_address
= (__u32
)__pa(privptr
->p_end_ccw
);
1642 /* Initialize ending CCW block */
1643 p_endccw
=privptr
->p_end_ccw
;
1644 p_endccw
->real
=real_address
;
1645 p_endccw
->write1
=0x00;
1646 p_endccw
->read1
=0x00;
1649 p_endccw
->write1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1650 p_endccw
->write1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1651 p_endccw
->write1_nop1
.count
= 1;
1652 p_endccw
->write1_nop1
.cda
= 0;
1655 p_endccw
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1656 p_endccw
->write1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1657 p_endccw
->write1_nop2
.count
= 1;
1658 p_endccw
->write1_nop2
.cda
= 0;
1661 p_endccw
->write2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1662 p_endccw
->write2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1663 p_endccw
->write2_nop1
.count
= 1;
1664 p_endccw
->write2_nop1
.cda
= 0;
1667 p_endccw
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1668 p_endccw
->write2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1669 p_endccw
->write2_nop2
.count
= 1;
1670 p_endccw
->write2_nop2
.cda
= 0;
1673 p_endccw
->read1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1674 p_endccw
->read1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1675 p_endccw
->read1_nop1
.count
= 1;
1676 p_endccw
->read1_nop1
.cda
= 0;
1679 p_endccw
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1680 p_endccw
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1681 p_endccw
->read1_nop2
.count
= 1;
1682 p_endccw
->read1_nop2
.cda
= 0;
1685 p_endccw
->read2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1686 p_endccw
->read2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1687 p_endccw
->read2_nop1
.count
= 1;
1688 p_endccw
->read2_nop1
.cda
= 0;
1691 p_endccw
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1692 p_endccw
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1693 p_endccw
->read2_nop2
.count
= 1;
1694 p_endccw
->read2_nop2
.cda
= 0;
1697 * Build a chain of CCWs
1700 p_buff
=privptr
->p_buff_ccw
;
1703 for (i
=0 ; i
< ccw_pages_required
; i
++ ) {
1704 real_address
= (__u32
)__pa(p_buff
);
1706 for (j
=0 ; j
< ccw_blocks_perpage
; j
++) {
1707 p_buf
->next
= p_free_chain
;
1708 p_free_chain
= p_buf
;
1709 p_buf
->real
=(__u32
)__pa(p_buf
);
1715 * Initialize ClawSignalBlock
1718 if (privptr
->p_claw_signal_blk
==NULL
) {
1719 privptr
->p_claw_signal_blk
=p_free_chain
;
1720 p_free_chain
=p_free_chain
->next
;
1721 pClawH
=(struct clawh
*)privptr
->p_claw_signal_blk
;
1722 pClawH
->length
=0xffff;
1723 pClawH
->opcode
=0xff;
1724 pClawH
->flag
=CLAW_BUSY
;
1728 * allocate write_pages_required and add to free chain
1730 if (privptr
->p_buff_write
==NULL
) {
1731 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1732 privptr
->p_buff_write
=
1733 (void *)__get_free_pages(__GFP_DMA
,
1734 (int)pages_to_order_of_mag(claw_write_pages
));
1735 if (privptr
->p_buff_write
==NULL
) {
1736 privptr
->p_buff_ccw
=NULL
;
1740 * Build CLAW write free chain
1744 memset(privptr
->p_buff_write
, 0x00,
1745 ccw_pages_required
* PAGE_SIZE
);
1746 privptr
->p_write_free_chain
=NULL
;
1748 p_buff
=privptr
->p_buff_write
;
1750 for (i
=0 ; i
< privptr
->p_env
->write_buffers
; i
++) {
1751 p_buf
= p_free_chain
; /* get a CCW */
1752 p_free_chain
= p_buf
->next
;
1753 p_buf
->next
=privptr
->p_write_free_chain
;
1754 privptr
->p_write_free_chain
= p_buf
;
1755 p_buf
-> p_buffer
= (struct clawbuf
*)p_buff
;
1756 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
1757 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1758 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1759 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1760 p_buf
-> w_read_FF
.count
= 1;
1761 p_buf
-> w_read_FF
.cda
=
1762 (__u32
)__pa(&p_buf
-> header
.flag
);
1763 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1764 p_buf
-> w_TIC_1
.flags
= 0;
1765 p_buf
-> w_TIC_1
.count
= 0;
1767 if (((unsigned long)p_buff
+
1768 privptr
->p_env
->write_size
) >=
1769 ((unsigned long)(p_buff
+2*
1770 (privptr
->p_env
->write_size
) - 1) & PAGE_MASK
)) {
1771 p_buff
= p_buff
+privptr
->p_env
->write_size
;
1775 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1777 privptr
->p_write_free_chain
=NULL
;
1778 for (i
= 0; i
< privptr
->p_env
->write_buffers
; i
++) {
1779 p_buff
=(void *)__get_free_pages(__GFP_DMA
,
1780 (int)pages_to_order_of_mag(
1781 privptr
->p_buff_pages_perwrite
) );
1783 free_pages((unsigned long)privptr
->p_buff_ccw
,
1784 (int)pages_to_order_of_mag(
1785 privptr
->p_buff_ccw_num
));
1786 privptr
->p_buff_ccw
=NULL
;
1787 p_buf
=privptr
->p_buff_write
;
1788 while (p_buf
!=NULL
) {
1789 free_pages((unsigned long)
1791 (int)pages_to_order_of_mag(
1792 privptr
->p_buff_pages_perwrite
));
1796 } /* Error on get_pages */
1797 memset(p_buff
, 0x00, privptr
->p_env
->write_size
);
1798 p_buf
= p_free_chain
;
1799 p_free_chain
= p_buf
->next
;
1800 p_buf
->next
= privptr
->p_write_free_chain
;
1801 privptr
->p_write_free_chain
= p_buf
;
1802 privptr
->p_buff_write
= p_buf
;
1803 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1804 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
1805 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1806 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1807 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1808 p_buf
-> w_read_FF
.count
= 1;
1809 p_buf
-> w_read_FF
.cda
=
1810 (__u32
)__pa(&p_buf
-> header
.flag
);
1811 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1812 p_buf
-> w_TIC_1
.flags
= 0;
1813 p_buf
-> w_TIC_1
.count
= 0;
1814 } /* for all write_buffers */
1816 } /* else buffers are PAGE_SIZE or bigger */
1819 privptr
->p_buff_write_num
=claw_write_pages
;
1820 privptr
->write_free_count
=privptr
->p_env
->write_buffers
;
1824 * allocate read_pages_required and chain to free chain
1826 if (privptr
->p_buff_read
==NULL
) {
1827 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1828 privptr
->p_buff_read
=
1829 (void *)__get_free_pages(__GFP_DMA
,
1830 (int)pages_to_order_of_mag(claw_read_pages
) );
1831 if (privptr
->p_buff_read
==NULL
) {
1832 free_pages((unsigned long)privptr
->p_buff_ccw
,
1833 (int)pages_to_order_of_mag(
1834 privptr
->p_buff_ccw_num
));
1835 /* free the write pages size is < page size */
1836 free_pages((unsigned long)privptr
->p_buff_write
,
1837 (int)pages_to_order_of_mag(
1838 privptr
->p_buff_write_num
));
1839 privptr
->p_buff_ccw
=NULL
;
1840 privptr
->p_buff_write
=NULL
;
1843 memset(privptr
->p_buff_read
, 0x00, claw_read_pages
* PAGE_SIZE
);
1844 privptr
->p_buff_read_num
=claw_read_pages
;
1846 * Build CLAW read free chain
1849 p_buff
=privptr
->p_buff_read
;
1850 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
1851 p_buf
= p_free_chain
;
1852 p_free_chain
= p_buf
->next
;
1854 if (p_last_CCWB
==NULL
) {
1860 p_buf
->next
=p_first_CCWB
;
1862 (__u32
)__pa(&p_first_CCWB
-> read
);
1867 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1868 /* initialize read command */
1869 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
1870 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
1871 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1872 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
1874 /* initialize read_h command */
1875 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
1876 p_buf
-> read_h
.cda
=
1877 (__u32
)__pa(&(p_buf
->header
));
1878 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1879 p_buf
-> read_h
.count
= sizeof(struct clawh
);
1881 /* initialize Signal command */
1882 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
1883 p_buf
-> signal
.cda
=
1884 (__u32
)__pa(&(pClawH
->flag
));
1885 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1886 p_buf
-> signal
.count
= 1;
1888 /* initialize r_TIC_1 command */
1889 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1890 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
1891 p_buf
-> r_TIC_1
.flags
= 0;
1892 p_buf
-> r_TIC_1
.count
= 0;
1894 /* initialize r_read_FF command */
1895 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1896 p_buf
-> r_read_FF
.cda
=
1897 (__u32
)__pa(&(pClawH
->flag
));
1898 p_buf
-> r_read_FF
.flags
=
1899 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
1900 p_buf
-> r_read_FF
.count
= 1;
1902 /* initialize r_TIC_2 */
1903 memcpy(&p_buf
->r_TIC_2
,
1904 &p_buf
->r_TIC_1
, sizeof(struct ccw1
));
1906 /* initialize Header */
1907 p_buf
->header
.length
=0xffff;
1908 p_buf
->header
.opcode
=0xff;
1909 p_buf
->header
.flag
=CLAW_PENDING
;
1911 if (((unsigned long)p_buff
+privptr
->p_env
->read_size
) >=
1912 ((unsigned long)(p_buff
+2*(privptr
->p_env
->read_size
)
1915 p_buff
= p_buff
+privptr
->p_env
->read_size
;
1919 (void *)((unsigned long)
1920 (p_buff
+2*(privptr
->p_env
->read_size
)-1)
1923 } /* for read_buffers */
1924 } /* read_size < PAGE_SIZE */
1925 else { /* read Size >= PAGE_SIZE */
1926 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
1927 p_buff
= (void *)__get_free_pages(__GFP_DMA
,
1928 (int)pages_to_order_of_mag(
1929 privptr
->p_buff_pages_perread
));
1931 free_pages((unsigned long)privptr
->p_buff_ccw
,
1932 (int)pages_to_order_of_mag(privptr
->
1934 /* free the write pages */
1935 p_buf
=privptr
->p_buff_write
;
1936 while (p_buf
!=NULL
) {
1938 (unsigned long)p_buf
->p_buffer
,
1939 (int)pages_to_order_of_mag(
1940 privptr
->p_buff_pages_perwrite
));
1943 /* free any read pages already alloc */
1944 p_buf
=privptr
->p_buff_read
;
1945 while (p_buf
!=NULL
) {
1947 (unsigned long)p_buf
->p_buffer
,
1948 (int)pages_to_order_of_mag(
1949 privptr
->p_buff_pages_perread
));
1952 privptr
->p_buff_ccw
=NULL
;
1953 privptr
->p_buff_write
=NULL
;
1956 memset(p_buff
, 0x00, privptr
->p_env
->read_size
);
1957 p_buf
= p_free_chain
;
1958 privptr
->p_buff_read
= p_buf
;
1959 p_free_chain
= p_buf
->next
;
1961 if (p_last_CCWB
==NULL
) {
1967 p_buf
->next
=p_first_CCWB
;
1970 &p_first_CCWB
-> read
);
1974 /* save buff address */
1975 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1976 /* initialize read command */
1977 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
1978 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
1979 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1980 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
1982 /* initialize read_h command */
1983 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
1984 p_buf
-> read_h
.cda
=
1985 (__u32
)__pa(&(p_buf
->header
));
1986 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1987 p_buf
-> read_h
.count
= sizeof(struct clawh
);
1989 /* initialize Signal command */
1990 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
1991 p_buf
-> signal
.cda
=
1992 (__u32
)__pa(&(pClawH
->flag
));
1993 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1994 p_buf
-> signal
.count
= 1;
1996 /* initialize r_TIC_1 command */
1997 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1998 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
1999 p_buf
-> r_TIC_1
.flags
= 0;
2000 p_buf
-> r_TIC_1
.count
= 0;
2002 /* initialize r_read_FF command */
2003 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
2004 p_buf
-> r_read_FF
.cda
=
2005 (__u32
)__pa(&(pClawH
->flag
));
2006 p_buf
-> r_read_FF
.flags
=
2007 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
2008 p_buf
-> r_read_FF
.count
= 1;
2010 /* initialize r_TIC_2 */
2011 memcpy(&p_buf
->r_TIC_2
, &p_buf
->r_TIC_1
,
2012 sizeof(struct ccw1
));
2014 /* initialize Header */
2015 p_buf
->header
.length
=0xffff;
2016 p_buf
->header
.opcode
=0xff;
2017 p_buf
->header
.flag
=CLAW_PENDING
;
2019 } /* For read_buffers */
2020 } /* read_size >= PAGE_SIZE */
2021 } /* pBuffread = NULL */
2022 add_claw_reads( dev
,p_first_CCWB
, p_last_CCWB
);
2023 privptr
->buffs_alloc
= 1;
2026 } /* end of init_ccw_bk */
2028 /*-------------------------------------------------------------------*
2032 *--------------------------------------------------------------------*/
2035 probe_error( struct ccwgroup_device
*cgdev
)
2037 struct claw_privbk
*privptr
;
2039 CLAW_DBF_TEXT(4, trace
, "proberr");
2040 privptr
= dev_get_drvdata(&cgdev
->dev
);
2041 if (privptr
!= NULL
) {
2042 dev_set_drvdata(&cgdev
->dev
, NULL
);
2043 kfree(privptr
->p_env
);
2044 kfree(privptr
->p_mtc_envelope
);
2049 /*-------------------------------------------------------------------*
2050 * claw_process_control *
2053 *--------------------------------------------------------------------*/
2056 claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
)
2059 struct clawbuf
*p_buf
;
2060 struct clawctl ctlbk
;
2061 struct clawctl
*p_ctlbk
;
2062 char temp_host_name
[8];
2063 char temp_ws_name
[8];
2064 struct claw_privbk
*privptr
;
2065 struct claw_env
*p_env
;
2066 struct sysval
*p_sysval
;
2067 struct conncmd
*p_connect
=NULL
;
2069 struct chbk
*p_ch
= NULL
;
2070 struct device
*tdev
;
2071 CLAW_DBF_TEXT(2, setup
, "clw_cntl");
2072 udelay(1000); /* Wait a ms for the control packets to
2073 *catch up to each other */
2074 privptr
= dev
->ml_priv
;
2075 p_env
=privptr
->p_env
;
2076 tdev
= &privptr
->channel
[READ_CHANNEL
].cdev
->dev
;
2077 memcpy( &temp_host_name
, p_env
->host_name
, 8);
2078 memcpy( &temp_ws_name
, p_env
->adapter_name
, 8);
2079 dev_info(tdev
, "%s: CLAW device %.8s: "
2080 "Received Control Packet\n",
2081 dev
->name
, temp_ws_name
);
2082 if (privptr
->release_pend
==1) {
2085 p_buf
=p_ccw
->p_buffer
;
2087 if (p_env
->packing
== DO_PACKED
) { /* packing in progress?*/
2088 memcpy(p_ctlbk
, &p_buf
->buffer
[4], sizeof(struct clawctl
));
2090 memcpy(p_ctlbk
, p_buf
, sizeof(struct clawctl
));
2092 switch (p_ctlbk
->command
)
2094 case SYSTEM_VALIDATE_REQUEST
:
2095 if (p_ctlbk
->version
!= CLAW_VERSION_ID
) {
2096 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2097 CLAW_RC_WRONG_VERSION
);
2098 dev_warn(tdev
, "The communication peer of %s"
2099 " uses an incorrect API version %d\n",
2100 dev
->name
, p_ctlbk
->version
);
2102 p_sysval
= (struct sysval
*)&(p_ctlbk
->data
);
2103 dev_info(tdev
, "%s: Recv Sys Validate Request: "
2104 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2106 dev
->name
, p_ctlbk
->version
,
2108 p_ctlbk
->correlator
,
2110 p_sysval
->host_name
);
2111 if (memcmp(temp_host_name
, p_sysval
->host_name
, 8)) {
2112 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2113 CLAW_RC_NAME_MISMATCH
);
2114 CLAW_DBF_TEXT(2, setup
, "HSTBAD");
2115 CLAW_DBF_TEXT_(2, setup
, "%s", p_sysval
->host_name
);
2116 CLAW_DBF_TEXT_(2, setup
, "%s", temp_host_name
);
2118 "Host name %s for %s does not match the"
2119 " remote adapter name %s\n",
2120 p_sysval
->host_name
,
2124 if (memcmp(temp_ws_name
, p_sysval
->WS_name
, 8)) {
2125 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2126 CLAW_RC_NAME_MISMATCH
);
2127 CLAW_DBF_TEXT(2, setup
, "WSNBAD");
2128 CLAW_DBF_TEXT_(2, setup
, "%s", p_sysval
->WS_name
);
2129 CLAW_DBF_TEXT_(2, setup
, "%s", temp_ws_name
);
2130 dev_warn(tdev
, "Adapter name %s for %s does not match"
2131 " the remote host name %s\n",
2136 if ((p_sysval
->write_frame_size
< p_env
->write_size
) &&
2137 (p_env
->packing
== 0)) {
2138 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2139 CLAW_RC_HOST_RCV_TOO_SMALL
);
2141 "The local write buffer is smaller than the"
2142 " remote read buffer\n");
2143 CLAW_DBF_TEXT(2, setup
, "wrtszbad");
2145 if ((p_sysval
->read_frame_size
< p_env
->read_size
) &&
2146 (p_env
->packing
== 0)) {
2147 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2148 CLAW_RC_HOST_RCV_TOO_SMALL
);
2150 "The local read buffer is smaller than the"
2151 " remote write buffer\n");
2152 CLAW_DBF_TEXT(2, setup
, "rdsizbad");
2154 claw_snd_sys_validate_rsp(dev
, p_ctlbk
, 0);
2156 "CLAW device %.8s: System validate"
2157 " completed.\n", temp_ws_name
);
2159 "%s: sys Validate Rsize:%d Wsize:%d\n",
2160 dev
->name
, p_sysval
->read_frame_size
,
2161 p_sysval
->write_frame_size
);
2162 privptr
->system_validate_comp
= 1;
2163 if (strncmp(p_env
->api_type
, WS_APPL_NAME_PACKED
, 6) == 0)
2164 p_env
->packing
= PACKING_ASK
;
2165 claw_strt_conn_req(dev
);
2167 case SYSTEM_VALIDATE_RESPONSE
:
2168 p_sysval
= (struct sysval
*)&(p_ctlbk
->data
);
2170 "Settings for %s validated (version=%d, "
2171 "remote device=%d, rc=%d, adapter name=%.8s, "
2172 "host name=%.8s)\n",
2175 p_ctlbk
->correlator
,
2178 p_sysval
->host_name
);
2179 switch (p_ctlbk
->rc
) {
2181 dev_info(tdev
, "%s: CLAW device "
2182 "%.8s: System validate completed.\n",
2183 dev
->name
, temp_ws_name
);
2184 if (privptr
->system_validate_comp
== 0)
2185 claw_strt_conn_req(dev
);
2186 privptr
->system_validate_comp
= 1;
2188 case CLAW_RC_NAME_MISMATCH
:
2189 dev_warn(tdev
, "Validating %s failed because of"
2190 " a host or adapter name mismatch\n",
2193 case CLAW_RC_WRONG_VERSION
:
2194 dev_warn(tdev
, "Validating %s failed because of a"
2195 " version conflict\n",
2198 case CLAW_RC_HOST_RCV_TOO_SMALL
:
2199 dev_warn(tdev
, "Validating %s failed because of a"
2200 " frame size conflict\n",
2204 dev_warn(tdev
, "The communication peer of %s rejected"
2205 " the connection\n",
2211 case CONNECTION_REQUEST
:
2212 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2213 dev_info(tdev
, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2214 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2218 p_ctlbk
->correlator
,
2219 p_connect
->host_name
,
2220 p_connect
->WS_name
);
2221 if (privptr
->active_link_ID
!= 0) {
2222 claw_snd_disc(dev
, p_ctlbk
);
2223 dev_info(tdev
, "%s rejected a connection request"
2224 " because it is already active\n",
2227 if (p_ctlbk
->linkid
!= 1) {
2228 claw_snd_disc(dev
, p_ctlbk
);
2229 dev_info(tdev
, "%s rejected a request to open multiple"
2233 rc
= find_link(dev
, p_connect
->host_name
, p_connect
->WS_name
);
2235 claw_snd_disc(dev
, p_ctlbk
);
2236 dev_info(tdev
, "%s rejected a connection request"
2237 " because of a type mismatch\n",
2240 claw_send_control(dev
,
2241 CONNECTION_CONFIRM
, p_ctlbk
->linkid
,
2242 p_ctlbk
->correlator
,
2243 0, p_connect
->host_name
,
2244 p_connect
->WS_name
);
2245 if (p_env
->packing
== PACKING_ASK
) {
2246 p_env
->packing
= PACK_SEND
;
2247 claw_snd_conn_req(dev
, 0);
2249 dev_info(tdev
, "%s: CLAW device %.8s: Connection "
2250 "completed link_id=%d.\n",
2251 dev
->name
, temp_ws_name
,
2253 privptr
->active_link_ID
= p_ctlbk
->linkid
;
2254 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
2255 wake_up(&p_ch
->wait
); /* wake up claw_open ( WRITE) */
2257 case CONNECTION_RESPONSE
:
2258 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2259 dev_info(tdev
, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
2260 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2264 p_ctlbk
->correlator
,
2266 p_connect
->host_name
,
2267 p_connect
->WS_name
);
2269 if (p_ctlbk
->rc
!= 0) {
2270 dev_warn(tdev
, "The communication peer of %s rejected"
2271 " a connection request\n",
2276 p_connect
->host_name
, p_connect
->WS_name
);
2278 claw_snd_disc(dev
, p_ctlbk
);
2279 dev_warn(tdev
, "The communication peer of %s"
2280 " rejected a connection "
2281 "request because of a type mismatch\n",
2284 /* should be until CONNECTION_CONFIRM */
2285 privptr
->active_link_ID
= -(p_ctlbk
->linkid
);
2287 case CONNECTION_CONFIRM
:
2288 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2290 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2291 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2295 p_ctlbk
->correlator
,
2296 p_connect
->host_name
,
2297 p_connect
->WS_name
);
2298 if (p_ctlbk
->linkid
== -(privptr
->active_link_ID
)) {
2299 privptr
->active_link_ID
= p_ctlbk
->linkid
;
2300 if (p_env
->packing
> PACKING_ASK
) {
2302 "%s: Confirmed Now packing\n", dev
->name
);
2303 p_env
->packing
= DO_PACKED
;
2305 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
2306 wake_up(&p_ch
->wait
);
2308 dev_warn(tdev
, "Activating %s failed because of"
2309 " an incorrect link ID=%d\n",
2310 dev
->name
, p_ctlbk
->linkid
);
2311 claw_snd_disc(dev
, p_ctlbk
);
2315 dev_info(tdev
, "%s: Disconnect: "
2316 "Vers=%d,link_id=%d,Corr=%d\n",
2317 dev
->name
, p_ctlbk
->version
,
2318 p_ctlbk
->linkid
, p_ctlbk
->correlator
);
2319 if ((p_ctlbk
->linkid
== 2) &&
2320 (p_env
->packing
== PACK_SEND
)) {
2321 privptr
->active_link_ID
= 1;
2322 p_env
->packing
= DO_PACKED
;
2324 privptr
->active_link_ID
= 0;
2327 dev_warn(tdev
, "The communication peer of %s failed\n",
2331 dev_warn(tdev
, "The communication peer of %s sent"
2332 " an unknown command code\n",
2338 } /* end of claw_process_control */
2341 /*-------------------------------------------------------------------*
2342 * claw_send_control *
2344 *--------------------------------------------------------------------*/
2347 claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
2348 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
)
2350 struct claw_privbk
*privptr
;
2351 struct clawctl
*p_ctl
;
2352 struct sysval
*p_sysval
;
2353 struct conncmd
*p_connect
;
2354 struct sk_buff
*skb
;
2356 CLAW_DBF_TEXT(2, setup
, "sndcntl");
2357 privptr
= dev
->ml_priv
;
2358 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
2360 p_ctl
->command
=type
;
2361 p_ctl
->version
=CLAW_VERSION_ID
;
2363 p_ctl
->correlator
=correlator
;
2366 p_sysval
=(struct sysval
*)&p_ctl
->data
;
2367 p_connect
=(struct conncmd
*)&p_ctl
->data
;
2369 switch (p_ctl
->command
) {
2370 case SYSTEM_VALIDATE_REQUEST
:
2371 case SYSTEM_VALIDATE_RESPONSE
:
2372 memcpy(&p_sysval
->host_name
, local_name
, 8);
2373 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
2374 if (privptr
->p_env
->packing
> 0) {
2375 p_sysval
->read_frame_size
= DEF_PACK_BUFSIZE
;
2376 p_sysval
->write_frame_size
= DEF_PACK_BUFSIZE
;
2378 /* how big is the biggest group of packets */
2379 p_sysval
->read_frame_size
=
2380 privptr
->p_env
->read_size
;
2381 p_sysval
->write_frame_size
=
2382 privptr
->p_env
->write_size
;
2384 memset(&p_sysval
->reserved
, 0x00, 4);
2386 case CONNECTION_REQUEST
:
2387 case CONNECTION_RESPONSE
:
2388 case CONNECTION_CONFIRM
:
2390 memcpy(&p_sysval
->host_name
, local_name
, 8);
2391 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
2392 if (privptr
->p_env
->packing
> 0) {
2393 /* How big is the biggest packet */
2394 p_connect
->reserved1
[0]=CLAW_FRAME_SIZE
;
2395 p_connect
->reserved1
[1]=CLAW_FRAME_SIZE
;
2397 memset(&p_connect
->reserved1
, 0x00, 4);
2398 memset(&p_connect
->reserved2
, 0x00, 4);
2405 /* write Control Record to the device */
2408 skb
= dev_alloc_skb(sizeof(struct clawctl
));
2412 memcpy(skb_put(skb
, sizeof(struct clawctl
)),
2413 p_ctl
, sizeof(struct clawctl
));
2414 if (privptr
->p_env
->packing
>= PACK_SEND
)
2415 claw_hw_tx(skb
, dev
, 1);
2417 claw_hw_tx(skb
, dev
, 0);
2419 } /* end of claw_send_control */
2421 /*-------------------------------------------------------------------*
2422 * claw_snd_conn_req *
2424 *--------------------------------------------------------------------*/
2426 claw_snd_conn_req(struct net_device
*dev
, __u8 link
)
2429 struct claw_privbk
*privptr
= dev
->ml_priv
;
2430 struct clawctl
*p_ctl
;
2432 CLAW_DBF_TEXT(2, setup
, "snd_conn");
2434 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
2435 p_ctl
->linkid
= link
;
2436 if ( privptr
->system_validate_comp
==0x00 ) {
2439 if (privptr
->p_env
->packing
== PACKING_ASK
)
2440 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2441 WS_APPL_NAME_PACKED
, WS_APPL_NAME_PACKED
);
2442 if (privptr
->p_env
->packing
== PACK_SEND
) {
2443 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2444 WS_APPL_NAME_IP_NAME
, WS_APPL_NAME_IP_NAME
);
2446 if (privptr
->p_env
->packing
== 0)
2447 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2448 HOST_APPL_NAME
, privptr
->p_env
->api_type
);
2451 } /* end of claw_snd_conn_req */
2454 /*-------------------------------------------------------------------*
2457 *--------------------------------------------------------------------*/
2460 claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
)
2463 struct conncmd
* p_connect
;
2465 CLAW_DBF_TEXT(2, setup
, "snd_dsc");
2466 p_connect
=(struct conncmd
*)&p_ctl
->data
;
2468 rc
=claw_send_control(dev
, DISCONNECT
, p_ctl
->linkid
,
2469 p_ctl
->correlator
, 0,
2470 p_connect
->host_name
, p_connect
->WS_name
);
2472 } /* end of claw_snd_disc */
2475 /*-------------------------------------------------------------------*
2476 * claw_snd_sys_validate_rsp *
2478 *--------------------------------------------------------------------*/
2481 claw_snd_sys_validate_rsp(struct net_device
*dev
,
2482 struct clawctl
*p_ctl
, __u32 return_code
)
2484 struct claw_env
* p_env
;
2485 struct claw_privbk
*privptr
;
2488 CLAW_DBF_TEXT(2, setup
, "chkresp");
2489 privptr
= dev
->ml_priv
;
2490 p_env
=privptr
->p_env
;
2491 rc
=claw_send_control(dev
, SYSTEM_VALIDATE_RESPONSE
,
2496 p_env
->adapter_name
);
2498 } /* end of claw_snd_sys_validate_rsp */
2500 /*-------------------------------------------------------------------*
2501 * claw_strt_conn_req *
2503 *--------------------------------------------------------------------*/
2506 claw_strt_conn_req(struct net_device
*dev
)
2510 CLAW_DBF_TEXT(2, setup
, "conn_req");
2511 rc
=claw_snd_conn_req(dev
, 1);
2513 } /* end of claw_strt_conn_req */
2517 /*-------------------------------------------------------------------*
2519 *-------------------------------------------------------------------*/
2522 net_device_stats
*claw_stats(struct net_device
*dev
)
2524 struct claw_privbk
*privptr
;
2526 CLAW_DBF_TEXT(4, trace
, "stats");
2527 privptr
= dev
->ml_priv
;
2528 return &privptr
->stats
;
2529 } /* end of claw_stats */
2532 /*-------------------------------------------------------------------*
2535 *--------------------------------------------------------------------*/
2537 unpack_read(struct net_device
*dev
)
2539 struct sk_buff
*skb
;
2540 struct claw_privbk
*privptr
;
2541 struct claw_env
*p_env
;
2542 struct ccwbk
*p_this_ccw
;
2543 struct ccwbk
*p_first_ccw
;
2544 struct ccwbk
*p_last_ccw
;
2545 struct clawph
*p_packh
;
2547 struct clawctl
*p_ctlrec
=NULL
;
2548 struct device
*p_dev
;
2553 __u8 mtc_this_frm
=0;
2558 CLAW_DBF_TEXT(4, trace
, "unpkread");
2563 privptr
= dev
->ml_priv
;
2565 p_dev
= &privptr
->channel
[READ_CHANNEL
].cdev
->dev
;
2566 p_env
= privptr
->p_env
;
2567 p_this_ccw
=privptr
->p_read_active_first
;
2568 while (p_this_ccw
!=NULL
&& p_this_ccw
->header
.flag
!=CLAW_PENDING
) {
2571 p_this_ccw
->header
.flag
=CLAW_PENDING
;
2572 privptr
->p_read_active_first
=p_this_ccw
->next
;
2573 p_this_ccw
->next
=NULL
;
2574 p_packh
= (struct clawph
*)p_this_ccw
->p_buffer
;
2575 if ((p_env
->packing
== PACK_SEND
) &&
2576 (p_packh
->len
== 32) &&
2577 (p_packh
->link_num
== 0)) { /* is it a packed ctl rec? */
2578 p_packh
++; /* peek past pack header */
2579 p_ctlrec
= (struct clawctl
*)p_packh
;
2580 p_packh
--; /* un peek */
2581 if ((p_ctlrec
->command
== CONNECTION_RESPONSE
) ||
2582 (p_ctlrec
->command
== CONNECTION_CONFIRM
))
2583 p_env
->packing
= DO_PACKED
;
2585 if (p_env
->packing
== DO_PACKED
)
2586 link_num
=p_packh
->link_num
;
2588 link_num
=p_this_ccw
->header
.opcode
/ 8;
2589 if ((p_this_ccw
->header
.opcode
& MORE_to_COME_FLAG
)!=0) {
2591 if (p_this_ccw
->header
.length
!=
2592 privptr
->p_env
->read_size
) {
2594 "The communication peer of %s"
2596 " frame of length %02x\n",
2597 dev
->name
, p_this_ccw
->header
.length
);
2601 if (privptr
->mtc_skipping
) {
2603 * We're in the mode of skipping past a
2604 * multi-frame message
2605 * that we can't process for some reason or other.
2606 * The first frame without the More-To-Come flag is
2607 * the last frame of the skipped message.
2609 /* in case of More-To-Come not set in this frame */
2610 if (mtc_this_frm
==0) {
2611 privptr
->mtc_skipping
=0; /* Ok, the end */
2612 privptr
->mtc_logical_link
=-1;
2618 claw_process_control(dev
, p_this_ccw
);
2619 CLAW_DBF_TEXT(4, trace
, "UnpkCntl");
2623 if (p_env
->packing
== DO_PACKED
) {
2624 if (pack_off
> p_env
->read_size
)
2626 p_packd
= p_this_ccw
->p_buffer
+pack_off
;
2627 p_packh
= (struct clawph
*) p_packd
;
2628 if ((p_packh
->len
== 0) || /* done with this frame? */
2629 (p_packh
->flag
!= 0))
2631 bytes_to_mov
= p_packh
->len
;
2632 pack_off
+= bytes_to_mov
+sizeof(struct clawph
);
2635 bytes_to_mov
=p_this_ccw
->header
.length
;
2637 if (privptr
->mtc_logical_link
<0) {
2640 * if More-To-Come is set in this frame then we don't know
2641 * length of entire message, and hence have to allocate
2644 /* We are starting a new envelope */
2645 privptr
->mtc_offset
=0;
2646 privptr
->mtc_logical_link
=link_num
;
2649 if (bytes_to_mov
> (MAX_ENVELOPE_SIZE
- privptr
->mtc_offset
) ) {
2651 privptr
->stats
.rx_frame_errors
++;
2654 if (p_env
->packing
== DO_PACKED
) {
2655 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
2656 p_packd
+sizeof(struct clawph
), bytes_to_mov
);
2659 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
2660 p_this_ccw
->p_buffer
, bytes_to_mov
);
2662 if (mtc_this_frm
==0) {
2663 len_of_data
=privptr
->mtc_offset
+bytes_to_mov
;
2664 skb
=dev_alloc_skb(len_of_data
);
2666 memcpy(skb_put(skb
,len_of_data
),
2667 privptr
->p_mtc_envelope
,
2670 skb_reset_mac_header(skb
);
2671 skb
->protocol
=htons(ETH_P_IP
);
2672 skb
->ip_summed
=CHECKSUM_UNNECESSARY
;
2673 privptr
->stats
.rx_packets
++;
2674 privptr
->stats
.rx_bytes
+=len_of_data
;
2678 dev_info(p_dev
, "Allocating a buffer for"
2679 " incoming data failed\n");
2680 privptr
->stats
.rx_dropped
++;
2682 privptr
->mtc_offset
=0;
2683 privptr
->mtc_logical_link
=-1;
2686 privptr
->mtc_offset
+=bytes_to_mov
;
2688 if (p_env
->packing
== DO_PACKED
)
2692 * Remove ThisCCWblock from active read queue, and add it
2693 * to queue of free blocks to be reused.
2696 p_this_ccw
->header
.length
=0xffff;
2697 p_this_ccw
->header
.opcode
=0xff;
2699 * add this one to the free queue for later reuse
2701 if (p_first_ccw
==NULL
) {
2702 p_first_ccw
= p_this_ccw
;
2705 p_last_ccw
->next
= p_this_ccw
;
2707 p_last_ccw
= p_this_ccw
;
2709 * chain to next block on active read queue
2711 p_this_ccw
= privptr
->p_read_active_first
;
2712 CLAW_DBF_TEXT_(4, trace
, "rxpkt %d", p
);
2713 } /* end of while */
2715 /* check validity */
2717 CLAW_DBF_TEXT_(4, trace
, "rxfrm %d", i
);
2718 add_claw_reads(dev
, p_first_ccw
, p_last_ccw
);
2719 claw_strt_read(dev
, LOCK_YES
);
2721 } /* end of unpack_read */
2723 /*-------------------------------------------------------------------*
2726 *--------------------------------------------------------------------*/
2728 claw_strt_read (struct net_device
*dev
, int lock
)
2732 unsigned long saveflags
= 0;
2733 struct claw_privbk
*privptr
= dev
->ml_priv
;
2734 struct ccwbk
*p_ccwbk
;
2736 struct clawh
*p_clawh
;
2737 p_ch
= &privptr
->channel
[READ_CHANNEL
];
2739 CLAW_DBF_TEXT(4, trace
, "StRdNter");
2740 p_clawh
=(struct clawh
*)privptr
->p_claw_signal_blk
;
2741 p_clawh
->flag
=CLAW_IDLE
; /* 0x00 */
2743 if ((privptr
->p_write_active_first
!=NULL
&&
2744 privptr
->p_write_active_first
->header
.flag
!=CLAW_PENDING
) ||
2745 (privptr
->p_read_active_first
!=NULL
&&
2746 privptr
->p_read_active_first
->header
.flag
!=CLAW_PENDING
)) {
2747 p_clawh
->flag
=CLAW_BUSY
; /* 0xff */
2749 if (lock
==LOCK_YES
) {
2750 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
2752 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
2753 CLAW_DBF_TEXT(4, trace
, "HotRead");
2754 p_ccwbk
=privptr
->p_read_active_first
;
2755 parm
= (unsigned long) p_ch
;
2756 rc
= ccw_device_start (p_ch
->cdev
, &p_ccwbk
->read
, parm
,
2759 ccw_check_return_code(p_ch
->cdev
, rc
);
2763 CLAW_DBF_TEXT(2, trace
, "ReadAct");
2766 if (lock
==LOCK_YES
) {
2767 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
2769 CLAW_DBF_TEXT(4, trace
, "StRdExit");
2771 } /* end of claw_strt_read */
2773 /*-------------------------------------------------------------------*
2774 * claw_strt_out_IO *
2776 *--------------------------------------------------------------------*/
2779 claw_strt_out_IO( struct net_device
*dev
)
2783 struct claw_privbk
*privptr
;
2785 struct ccwbk
*p_first_ccw
;
2790 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
2791 p_ch
= &privptr
->channel
[WRITE_CHANNEL
];
2793 CLAW_DBF_TEXT(4, trace
, "strt_io");
2794 p_first_ccw
=privptr
->p_write_active_first
;
2796 if (p_ch
->claw_state
== CLAW_STOP
)
2798 if (p_first_ccw
== NULL
) {
2801 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
2802 parm
= (unsigned long) p_ch
;
2803 CLAW_DBF_TEXT(2, trace
, "StWrtIO");
2804 rc
= ccw_device_start(p_ch
->cdev
, &p_first_ccw
->write
, parm
,
2807 ccw_check_return_code(p_ch
->cdev
, rc
);
2810 dev
->trans_start
= jiffies
;
2812 } /* end of claw_strt_out_IO */
2814 /*-------------------------------------------------------------------*
2815 * Free write buffers *
2817 *--------------------------------------------------------------------*/
2820 claw_free_wrt_buf( struct net_device
*dev
)
2823 struct claw_privbk
*privptr
= (struct claw_privbk
*)dev
->ml_priv
;
2824 struct ccwbk
*p_first_ccw
;
2825 struct ccwbk
*p_last_ccw
;
2826 struct ccwbk
*p_this_ccw
;
2827 struct ccwbk
*p_next_ccw
;
2829 CLAW_DBF_TEXT(4, trace
, "freewrtb");
2830 /* scan the write queue to free any completed write packets */
2833 p_this_ccw
=privptr
->p_write_active_first
;
2834 while ( (p_this_ccw
!=NULL
) && (p_this_ccw
->header
.flag
!=CLAW_PENDING
))
2836 p_next_ccw
= p_this_ccw
->next
;
2837 if (((p_next_ccw
!=NULL
) &&
2838 (p_next_ccw
->header
.flag
!=CLAW_PENDING
)) ||
2839 ((p_this_ccw
== privptr
->p_write_active_last
) &&
2840 (p_this_ccw
->header
.flag
!=CLAW_PENDING
))) {
2841 /* The next CCW is OK or this is */
2842 /* the last CCW...free it @A1A */
2843 privptr
->p_write_active_first
=p_this_ccw
->next
;
2844 p_this_ccw
->header
.flag
=CLAW_PENDING
;
2845 p_this_ccw
->next
=privptr
->p_write_free_chain
;
2846 privptr
->p_write_free_chain
=p_this_ccw
;
2847 ++privptr
->write_free_count
;
2848 privptr
->stats
.tx_bytes
+= p_this_ccw
->write
.count
;
2849 p_this_ccw
=privptr
->p_write_active_first
;
2850 privptr
->stats
.tx_packets
++;
2856 if (privptr
->write_free_count
!=0) {
2857 claw_clearbit_busy(TB_NOBUFFER
,dev
);
2859 /* whole chain removed? */
2860 if (privptr
->p_write_active_first
==NULL
) {
2861 privptr
->p_write_active_last
=NULL
;
2863 CLAW_DBF_TEXT_(4, trace
, "FWC=%d", privptr
->write_free_count
);
2867 /*-------------------------------------------------------------------*
2868 * claw free netdevice *
2870 *--------------------------------------------------------------------*/
2872 claw_free_netdevice(struct net_device
* dev
, int free_dev
)
2874 struct claw_privbk
*privptr
;
2876 CLAW_DBF_TEXT(2, setup
, "free_dev");
2879 CLAW_DBF_TEXT_(2, setup
, "%s", dev
->name
);
2880 privptr
= dev
->ml_priv
;
2881 if (dev
->flags
& IFF_RUNNING
)
2884 privptr
->channel
[READ_CHANNEL
].ndev
= NULL
; /* say it's free */
2886 dev
->ml_priv
= NULL
;
2892 CLAW_DBF_TEXT(2, setup
, "free_ok");
2896 * Claw init netdevice
2897 * Initialize everything of the net device except the name and the
2900 static const struct net_device_ops claw_netdev_ops
= {
2901 .ndo_open
= claw_open
,
2902 .ndo_stop
= claw_release
,
2903 .ndo_get_stats
= claw_stats
,
2904 .ndo_start_xmit
= claw_tx
,
2905 .ndo_change_mtu
= claw_change_mtu
,
2909 claw_init_netdevice(struct net_device
* dev
)
2911 CLAW_DBF_TEXT(2, setup
, "init_dev");
2912 CLAW_DBF_TEXT_(2, setup
, "%s", dev
->name
);
2913 dev
->mtu
= CLAW_DEFAULT_MTU_SIZE
;
2914 dev
->hard_header_len
= 0;
2916 dev
->type
= ARPHRD_SLIP
;
2917 dev
->tx_queue_len
= 1300;
2918 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
2919 dev
->netdev_ops
= &claw_netdev_ops
;
2920 CLAW_DBF_TEXT(2, setup
, "initok");
2925 * Init a new channel in the privptr->channel[i].
2927 * @param cdev The ccw_device to be added.
2929 * @return 0 on success, !0 on error.
2932 add_channel(struct ccw_device
*cdev
,int i
,struct claw_privbk
*privptr
)
2935 struct ccw_dev_id dev_id
;
2937 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cdev
->dev
));
2938 privptr
->channel
[i
].flag
= i
+1; /* Read is 1 Write is 2 */
2939 p_ch
= &privptr
->channel
[i
];
2941 snprintf(p_ch
->id
, CLAW_ID_SIZE
, "cl-%s", dev_name(&cdev
->dev
));
2942 ccw_device_get_id(cdev
, &dev_id
);
2943 p_ch
->devno
= dev_id
.devno
;
2944 if ((p_ch
->irb
= kzalloc(sizeof (struct irb
),GFP_KERNEL
)) == NULL
) {
2953 * Setup an interface.
2955 * @param cgdev Device to be setup.
2957 * @returns 0 on success, !0 on failure.
2960 claw_new_device(struct ccwgroup_device
*cgdev
)
2962 struct claw_privbk
*privptr
;
2963 struct claw_env
*p_env
;
2964 struct net_device
*dev
;
2966 struct ccw_dev_id dev_id
;
2968 dev_info(&cgdev
->dev
, "add for %s\n",
2969 dev_name(&cgdev
->cdev
[READ_CHANNEL
]->dev
));
2970 CLAW_DBF_TEXT(2, setup
, "new_dev");
2971 privptr
= dev_get_drvdata(&cgdev
->dev
);
2972 dev_set_drvdata(&cgdev
->cdev
[READ_CHANNEL
]->dev
, privptr
);
2973 dev_set_drvdata(&cgdev
->cdev
[WRITE_CHANNEL
]->dev
, privptr
);
2976 p_env
= privptr
->p_env
;
2977 ccw_device_get_id(cgdev
->cdev
[READ_CHANNEL
], &dev_id
);
2978 p_env
->devno
[READ_CHANNEL
] = dev_id
.devno
;
2979 ccw_device_get_id(cgdev
->cdev
[WRITE_CHANNEL
], &dev_id
);
2980 p_env
->devno
[WRITE_CHANNEL
] = dev_id
.devno
;
2981 ret
= add_channel(cgdev
->cdev
[0],0,privptr
);
2983 ret
= add_channel(cgdev
->cdev
[1],1,privptr
);
2985 dev_warn(&cgdev
->dev
, "Creating a CLAW group device"
2986 " failed with error code %d\n", ret
);
2989 ret
= ccw_device_set_online(cgdev
->cdev
[READ_CHANNEL
]);
2991 dev_warn(&cgdev
->dev
,
2992 "Setting the read subchannel online"
2993 " failed with error code %d\n", ret
);
2996 ret
= ccw_device_set_online(cgdev
->cdev
[WRITE_CHANNEL
]);
2998 dev_warn(&cgdev
->dev
,
2999 "Setting the write subchannel online "
3000 "failed with error code %d\n", ret
);
3003 dev
= alloc_netdev(0,"claw%d",claw_init_netdevice
);
3005 dev_warn(&cgdev
->dev
,
3006 "Activating the CLAW device failed\n");
3009 dev
->ml_priv
= privptr
;
3010 dev_set_drvdata(&cgdev
->dev
, privptr
);
3011 dev_set_drvdata(&cgdev
->cdev
[READ_CHANNEL
]->dev
, privptr
);
3012 dev_set_drvdata(&cgdev
->cdev
[WRITE_CHANNEL
]->dev
, privptr
);
3014 SET_NETDEV_DEV(dev
, &cgdev
->dev
);
3015 if (register_netdev(dev
) != 0) {
3016 claw_free_netdevice(dev
, 1);
3017 CLAW_DBF_TEXT(2, trace
, "regfail");
3020 dev
->flags
&=~IFF_RUNNING
;
3021 if (privptr
->buffs_alloc
== 0) {
3022 ret
=init_ccw_bk(dev
);
3024 unregister_netdev(dev
);
3025 claw_free_netdevice(dev
,1);
3026 CLAW_DBF_TEXT(2, trace
, "ccwmem");
3030 privptr
->channel
[READ_CHANNEL
].ndev
= dev
;
3031 privptr
->channel
[WRITE_CHANNEL
].ndev
= dev
;
3032 privptr
->p_env
->ndev
= dev
;
3034 dev_info(&cgdev
->dev
, "%s:readsize=%d writesize=%d "
3035 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3036 dev
->name
, p_env
->read_size
,
3037 p_env
->write_size
, p_env
->read_buffers
,
3038 p_env
->write_buffers
, p_env
->devno
[READ_CHANNEL
],
3039 p_env
->devno
[WRITE_CHANNEL
]);
3040 dev_info(&cgdev
->dev
, "%s:host_name:%.8s, adapter_name "
3041 ":%.8s api_type: %.8s\n",
3042 dev
->name
, p_env
->host_name
,
3043 p_env
->adapter_name
, p_env
->api_type
);
3046 ccw_device_set_offline(cgdev
->cdev
[1]);
3047 ccw_device_set_offline(cgdev
->cdev
[0]);
3052 claw_purge_skb_queue(struct sk_buff_head
*q
)
3054 struct sk_buff
*skb
;
3056 CLAW_DBF_TEXT(4, trace
, "purgque");
3057 while ((skb
= skb_dequeue(q
))) {
3058 atomic_dec(&skb
->users
);
3059 dev_kfree_skb_any(skb
);
3064 * Shutdown an interface.
3066 * @param cgdev Device to be shut down.
3068 * @returns 0 on success, !0 on failure.
3071 claw_shutdown_device(struct ccwgroup_device
*cgdev
)
3073 struct claw_privbk
*priv
;
3074 struct net_device
*ndev
;
3077 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cgdev
->dev
));
3078 priv
= dev_get_drvdata(&cgdev
->dev
);
3081 ndev
= priv
->channel
[READ_CHANNEL
].ndev
;
3083 /* Close the device */
3084 dev_info(&cgdev
->dev
, "%s: shutting down\n",
3086 if (ndev
->flags
& IFF_RUNNING
)
3087 ret
= claw_release(ndev
);
3088 ndev
->flags
&=~IFF_RUNNING
;
3089 unregister_netdev(ndev
);
3090 ndev
->ml_priv
= NULL
; /* cgdev data, not ndev's to free */
3091 claw_free_netdevice(ndev
, 1);
3092 priv
->channel
[READ_CHANNEL
].ndev
= NULL
;
3093 priv
->channel
[WRITE_CHANNEL
].ndev
= NULL
;
3094 priv
->p_env
->ndev
= NULL
;
3096 ccw_device_set_offline(cgdev
->cdev
[1]);
3097 ccw_device_set_offline(cgdev
->cdev
[0]);
3102 claw_remove_device(struct ccwgroup_device
*cgdev
)
3104 struct claw_privbk
*priv
;
3107 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cgdev
->dev
));
3108 priv
= dev_get_drvdata(&cgdev
->dev
);
3110 dev_info(&cgdev
->dev
, " will be removed.\n");
3111 if (cgdev
->state
== CCWGROUP_ONLINE
)
3112 claw_shutdown_device(cgdev
);
3113 claw_remove_files(&cgdev
->dev
);
3114 kfree(priv
->p_mtc_envelope
);
3115 priv
->p_mtc_envelope
=NULL
;
3118 kfree(priv
->channel
[0].irb
);
3119 priv
->channel
[0].irb
=NULL
;
3120 kfree(priv
->channel
[1].irb
);
3121 priv
->channel
[1].irb
=NULL
;
3123 dev_set_drvdata(&cgdev
->dev
, NULL
);
3124 dev_set_drvdata(&cgdev
->cdev
[READ_CHANNEL
]->dev
, NULL
);
3125 dev_set_drvdata(&cgdev
->cdev
[WRITE_CHANNEL
]->dev
, NULL
);
3126 put_device(&cgdev
->dev
);
3136 claw_hname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3138 struct claw_privbk
*priv
;
3139 struct claw_env
* p_env
;
3141 priv
= dev_get_drvdata(dev
);
3144 p_env
= priv
->p_env
;
3145 return sprintf(buf
, "%s\n",p_env
->host_name
);
3149 claw_hname_write(struct device
*dev
, struct device_attribute
*attr
,
3150 const char *buf
, size_t count
)
3152 struct claw_privbk
*priv
;
3153 struct claw_env
* p_env
;
3155 priv
= dev_get_drvdata(dev
);
3158 p_env
= priv
->p_env
;
3159 if (count
> MAX_NAME_LEN
+1)
3161 memset(p_env
->host_name
, 0x20, MAX_NAME_LEN
);
3162 strncpy(p_env
->host_name
,buf
, count
);
3163 p_env
->host_name
[count
-1] = 0x20; /* clear extra 0x0a */
3164 p_env
->host_name
[MAX_NAME_LEN
] = 0x00;
3165 CLAW_DBF_TEXT(2, setup
, "HstnSet");
3166 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->host_name
);
3171 static DEVICE_ATTR(host_name
, 0644, claw_hname_show
, claw_hname_write
);
3174 claw_adname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3176 struct claw_privbk
*priv
;
3177 struct claw_env
* p_env
;
3179 priv
= dev_get_drvdata(dev
);
3182 p_env
= priv
->p_env
;
3183 return sprintf(buf
, "%s\n", p_env
->adapter_name
);
3187 claw_adname_write(struct device
*dev
, struct device_attribute
*attr
,
3188 const char *buf
, size_t count
)
3190 struct claw_privbk
*priv
;
3191 struct claw_env
* p_env
;
3193 priv
= dev_get_drvdata(dev
);
3196 p_env
= priv
->p_env
;
3197 if (count
> MAX_NAME_LEN
+1)
3199 memset(p_env
->adapter_name
, 0x20, MAX_NAME_LEN
);
3200 strncpy(p_env
->adapter_name
,buf
, count
);
3201 p_env
->adapter_name
[count
-1] = 0x20; /* clear extra 0x0a */
3202 p_env
->adapter_name
[MAX_NAME_LEN
] = 0x00;
3203 CLAW_DBF_TEXT(2, setup
, "AdnSet");
3204 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->adapter_name
);
3209 static DEVICE_ATTR(adapter_name
, 0644, claw_adname_show
, claw_adname_write
);
3212 claw_apname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3214 struct claw_privbk
*priv
;
3215 struct claw_env
* p_env
;
3217 priv
= dev_get_drvdata(dev
);
3220 p_env
= priv
->p_env
;
3221 return sprintf(buf
, "%s\n",
3226 claw_apname_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
;
3232 priv
= dev_get_drvdata(dev
);
3235 p_env
= priv
->p_env
;
3236 if (count
> MAX_NAME_LEN
+1)
3238 memset(p_env
->api_type
, 0x20, MAX_NAME_LEN
);
3239 strncpy(p_env
->api_type
,buf
, count
);
3240 p_env
->api_type
[count
-1] = 0x20; /* we get a loose 0x0a */
3241 p_env
->api_type
[MAX_NAME_LEN
] = 0x00;
3242 if(strncmp(p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
3243 p_env
->read_size
=DEF_PACK_BUFSIZE
;
3244 p_env
->write_size
=DEF_PACK_BUFSIZE
;
3245 p_env
->packing
=PACKING_ASK
;
3246 CLAW_DBF_TEXT(2, setup
, "PACKING");
3250 p_env
->read_size
=CLAW_FRAME_SIZE
;
3251 p_env
->write_size
=CLAW_FRAME_SIZE
;
3252 CLAW_DBF_TEXT(2, setup
, "ApiSet");
3254 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->api_type
);
3258 static DEVICE_ATTR(api_type
, 0644, claw_apname_show
, claw_apname_write
);
3261 claw_wbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3263 struct claw_privbk
*priv
;
3264 struct claw_env
* p_env
;
3266 priv
= dev_get_drvdata(dev
);
3269 p_env
= priv
->p_env
;
3270 return sprintf(buf
, "%d\n", p_env
->write_buffers
);
3274 claw_wbuff_write(struct device
*dev
, struct device_attribute
*attr
,
3275 const char *buf
, size_t count
)
3277 struct claw_privbk
*priv
;
3278 struct claw_env
* p_env
;
3281 priv
= dev_get_drvdata(dev
);
3284 p_env
= priv
->p_env
;
3285 sscanf(buf
, "%i", &nnn
);
3286 if (p_env
->packing
) {
3292 if ((nnn
> max
) || (nnn
< 2))
3294 p_env
->write_buffers
= nnn
;
3295 CLAW_DBF_TEXT(2, setup
, "Wbufset");
3296 CLAW_DBF_TEXT_(2, setup
, "WB=%d", p_env
->write_buffers
);
3300 static DEVICE_ATTR(write_buffer
, 0644, claw_wbuff_show
, claw_wbuff_write
);
3303 claw_rbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3305 struct claw_privbk
*priv
;
3306 struct claw_env
* p_env
;
3308 priv
= dev_get_drvdata(dev
);
3311 p_env
= priv
->p_env
;
3312 return sprintf(buf
, "%d\n", p_env
->read_buffers
);
3316 claw_rbuff_write(struct device
*dev
, struct device_attribute
*attr
,
3317 const char *buf
, size_t count
)
3319 struct claw_privbk
*priv
;
3320 struct claw_env
*p_env
;
3323 priv
= dev_get_drvdata(dev
);
3326 p_env
= priv
->p_env
;
3327 sscanf(buf
, "%i", &nnn
);
3328 if (p_env
->packing
) {
3334 if ((nnn
> max
) || (nnn
< 2))
3336 p_env
->read_buffers
= nnn
;
3337 CLAW_DBF_TEXT(2, setup
, "Rbufset");
3338 CLAW_DBF_TEXT_(2, setup
, "RB=%d", p_env
->read_buffers
);
3342 static DEVICE_ATTR(read_buffer
, 0644, claw_rbuff_show
, claw_rbuff_write
);
3344 static struct attribute
*claw_attr
[] = {
3345 &dev_attr_read_buffer
.attr
,
3346 &dev_attr_write_buffer
.attr
,
3347 &dev_attr_adapter_name
.attr
,
3348 &dev_attr_api_type
.attr
,
3349 &dev_attr_host_name
.attr
,
3353 static struct attribute_group claw_attr_group
= {
3358 claw_add_files(struct device
*dev
)
3360 CLAW_DBF_TEXT(2, setup
, "add_file");
3361 return sysfs_create_group(&dev
->kobj
, &claw_attr_group
);
3365 claw_remove_files(struct device
*dev
)
3367 CLAW_DBF_TEXT(2, setup
, "rem_file");
3368 sysfs_remove_group(&dev
->kobj
, &claw_attr_group
);
3371 /*--------------------------------------------------------------------*
3372 * claw_init and cleanup *
3373 *---------------------------------------------------------------------*/
3378 driver_remove_file(&claw_group_driver
.driver
,
3379 &driver_attr_group
);
3380 ccwgroup_driver_unregister(&claw_group_driver
);
3381 ccw_driver_unregister(&claw_ccw_driver
);
3382 root_device_unregister(claw_root_dev
);
3383 claw_unregister_debug_facility();
3384 pr_info("Driver unloaded\n");
3389 * Initialize module.
3390 * This is called just after the module is loaded.
3392 * @return 0 on success, !0 on error.
3399 pr_info("Loading %s\n", version
);
3400 ret
= claw_register_debug_facility();
3402 pr_err("Registering with the S/390 debug feature"
3403 " failed with error code %d\n", ret
);
3406 CLAW_DBF_TEXT(2, setup
, "init_mod");
3407 claw_root_dev
= root_device_register("claw");
3408 ret
= IS_ERR(claw_root_dev
) ? PTR_ERR(claw_root_dev
) : 0;
3411 ret
= ccw_driver_register(&claw_ccw_driver
);
3414 claw_group_driver
.driver
.groups
= claw_group_attr_groups
;
3415 ret
= ccwgroup_driver_register(&claw_group_driver
);
3421 ccw_driver_unregister(&claw_ccw_driver
);
3423 root_device_unregister(claw_root_dev
);
3425 CLAW_DBF_TEXT(2, setup
, "init_bad");
3426 claw_unregister_debug_facility();
3428 pr_err("Initializing the claw device driver failed\n");
3432 module_init(claw_init
);
3433 module_exit(claw_cleanup
);
3435 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3436 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3437 "Copyright 2000,2008 IBM Corporation\n");
3438 MODULE_LICENSE("GPL");