blob: 213e54ee8a6660de47b05825f4ba5265bccd3463 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * ESCON CLAW network driver
3 *
Frank Pavlic8e84c802005-09-06 15:03:09 +02004 * Linux for zSeries version
Frank Blaschka88efc2c2009-06-16 10:30:33 +02005 * Copyright IBM Corp. 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Author(s) Original code written by:
Frank Blaschka88efc2c2009-06-16 10:30:33 +02007 * Kazuo Iimura <iimura@jp.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Rewritten by
Frank Blaschka88efc2c2009-06-16 10:30:33 +02009 * Andy Richter <richtera@us.ibm.com>
10 * Marc Price <mwprice@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * sysfs parms:
13 * group x.x.rrrr,x.x.wwww
14 * read_buffer nnnnnnn
15 * write_buffer nnnnnn
16 * host_name aaaaaaaa
17 * adapter_name aaaaaaaa
18 * api_type aaaaaaaa
19 *
20 * eg.
21 * group 0.0.0200 0.0.0201
22 * read_buffer 25
23 * write_buffer 20
24 * host_name LINUX390
25 * adapter_name RS6K
26 * api_type TCPIP
27 *
28 * where
29 *
30 * The device id is decided by the order entries
31 * are added to the group the first is claw0 the second claw1
32 * up to CLAW_MAX_DEV
33 *
34 * rrrr - the first of 2 consecutive device addresses used for the
35 * CLAW protocol.
36 * The specified address is always used as the input (Read)
37 * channel and the next address is used as the output channel.
38 *
39 * wwww - the second of 2 consecutive device addresses used for
40 * the CLAW protocol.
41 * The specified address is always used as the output
42 * channel and the previous address is used as the input channel.
43 *
44 * read_buffer - specifies number of input buffers to allocate.
45 * write_buffer - specifies number of output buffers to allocate.
46 * host_name - host name
47 * adaptor_name - adaptor name
48 * api_type - API type TCPIP or API will be sent and expected
49 * as ws_name
50 *
51 * Note the following requirements:
52 * 1) host_name must match the configured adapter_name on the remote side
53 * 2) adaptor_name must match the configured host name on the remote side
54 *
55 * Change History
56 * 1.00 Initial release shipped
57 * 1.10 Changes for Buffer allocation
58 * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
59 * 1.25 Added Packing support
Andy Richterb805da72008-07-18 15:24:56 +020060 * 1.5
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 */
Andy Richter4811fcb2009-01-20 06:14:33 +000062
63#define KMSG_COMPONENT "claw"
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#include <asm/ccwdev.h>
66#include <asm/ccwgroup.h>
67#include <asm/debug.h>
68#include <asm/idals.h>
69#include <asm/io.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070070#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include <linux/ctype.h>
72#include <linux/delay.h>
73#include <linux/errno.h>
74#include <linux/if_arp.h>
75#include <linux/init.h>
76#include <linux/interrupt.h>
77#include <linux/ip.h>
78#include <linux/kernel.h>
79#include <linux/module.h>
80#include <linux/netdevice.h>
81#include <linux/etherdevice.h>
82#include <linux/proc_fs.h>
83#include <linux/sched.h>
84#include <linux/signal.h>
85#include <linux/skbuff.h>
86#include <linux/slab.h>
87#include <linux/string.h>
88#include <linux/tcp.h>
89#include <linux/timer.h>
90#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#include "claw.h"
93
Andy Richterb805da72008-07-18 15:24:56 +020094/*
95 CLAW uses the s390dbf file system see claw_trace and claw_setup
Linus Torvalds1da177e2005-04-16 15:20:36 -070096*/
97
Andy Richter4811fcb2009-01-20 06:14:33 +000098static char version[] __initdata = "CLAW driver";
Heiko Carstens2b67fc42007-02-05 21:16:47 +010099static char debug_buffer[255];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100/**
101 * Debug Facility Stuff
102 */
103static debug_info_t *claw_dbf_setup;
104static debug_info_t *claw_dbf_trace;
105
106/**
107 * CLAW Debug Facility functions
108 */
109static void
110claw_unregister_debug_facility(void)
111{
112 if (claw_dbf_setup)
113 debug_unregister(claw_dbf_setup);
114 if (claw_dbf_trace)
115 debug_unregister(claw_dbf_trace);
116}
117
118static int
119claw_register_debug_facility(void)
120{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700121 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
122 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 claw_unregister_debug_facility();
125 return -ENOMEM;
126 }
127 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
128 debug_set_level(claw_dbf_setup, 2);
129 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
130 debug_set_level(claw_dbf_trace, 2);
131 return 0;
132}
133
134static inline void
135claw_set_busy(struct net_device *dev)
136{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200137 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
140static inline void
141claw_clear_busy(struct net_device *dev)
142{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200143 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
147static inline int
148claw_check_busy(struct net_device *dev)
149{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200150 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
153static inline void
154claw_setbit_busy(int nr,struct net_device *dev)
155{
156 netif_stop_queue(dev);
Peter Tiedemann6951df32008-08-21 17:10:23 +0200157 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160static inline void
161claw_clearbit_busy(int nr,struct net_device *dev)
162{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200163 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 netif_wake_queue(dev);
165}
166
167static inline int
168claw_test_and_setbit_busy(int nr,struct net_device *dev)
169{
170 netif_stop_queue(dev);
171 return test_and_set_bit(nr,
Peter Tiedemann6951df32008-08-21 17:10:23 +0200172 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
175
176/* Functions for the DEV methods */
177
178static int claw_probe(struct ccwgroup_device *cgdev);
179static void claw_remove_device(struct ccwgroup_device *cgdev);
180static void claw_purge_skb_queue(struct sk_buff_head *q);
181static int claw_new_device(struct ccwgroup_device *cgdev);
182static int claw_shutdown_device(struct ccwgroup_device *cgdev);
183static int claw_tx(struct sk_buff *skb, struct net_device *dev);
184static int claw_change_mtu( struct net_device *dev, int new_mtu);
185static int claw_open(struct net_device *dev);
186static void claw_irq_handler(struct ccw_device *cdev,
187 unsigned long intparm, struct irb *irb);
188static void claw_irq_tasklet ( unsigned long data );
189static int claw_release(struct net_device *dev);
190static void claw_write_retry ( struct chbk * p_ch );
191static void claw_write_next ( struct chbk * p_ch );
192static void claw_timer ( struct chbk * p_ch );
193
194/* Functions */
195static int add_claw_reads(struct net_device *dev,
196 struct ccwbk* p_first, struct ccwbk* p_last);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100197static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
198static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199static int find_link(struct net_device *dev, char *host_name, char *ws_name );
200static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
201static int init_ccw_bk(struct net_device *dev);
202static void probe_error( struct ccwgroup_device *cgdev);
203static struct net_device_stats *claw_stats(struct net_device *dev);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100204static int pages_to_order_of_mag(int num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/* sysfs Functions */
Andy Richter4811fcb2009-01-20 06:14:33 +0000207static ssize_t claw_hname_show(struct device *dev,
208 struct device_attribute *attr, char *buf);
209static ssize_t claw_hname_write(struct device *dev,
210 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000212static ssize_t claw_adname_show(struct device *dev,
213 struct device_attribute *attr, char *buf);
214static ssize_t claw_adname_write(struct device *dev,
215 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000217static ssize_t claw_apname_show(struct device *dev,
218 struct device_attribute *attr, char *buf);
219static ssize_t claw_apname_write(struct device *dev,
220 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000222static ssize_t claw_wbuff_show(struct device *dev,
223 struct device_attribute *attr, char *buf);
224static ssize_t claw_wbuff_write(struct device *dev,
225 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000227static ssize_t claw_rbuff_show(struct device *dev,
228 struct device_attribute *attr, char *buf);
229static ssize_t claw_rbuff_write(struct device *dev,
230 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 const char *buf, size_t count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233/* Functions for System Validate */
234static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
235static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
236 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
237static int claw_snd_conn_req(struct net_device *dev, __u8 link);
238static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
239static int claw_snd_sys_validate_rsp(struct net_device *dev,
240 struct clawctl * p_ctl, __u32 return_code);
241static int claw_strt_conn_req(struct net_device *dev );
Andy Richterb805da72008-07-18 15:24:56 +0200242static void claw_strt_read(struct net_device *dev, int lock);
243static void claw_strt_out_IO(struct net_device *dev);
244static void claw_free_wrt_buf(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246/* Functions for unpack reads */
Andy Richterb805da72008-07-18 15:24:56 +0200247static void unpack_read(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200249static int claw_pm_prepare(struct ccwgroup_device *gdev)
250{
251 return -EPERM;
252}
253
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000254/* the root device for claw group devices */
255static struct device *claw_root_dev;
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257/* ccwgroup table */
258
259static struct ccwgroup_driver claw_group_driver = {
Sebastian Ott3c190c52011-03-23 10:16:04 +0100260 .driver = {
261 .owner = THIS_MODULE,
262 .name = "claw",
263 },
Sebastian Ott2ced5512012-05-15 18:00:49 +0200264 .setup = claw_probe,
Sebastian Ott9814fdf2012-05-15 18:03:46 +0200265 .remove = claw_remove_device,
266 .set_online = claw_new_device,
267 .set_offline = claw_shutdown_device,
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200268 .prepare = claw_pm_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269};
270
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000271static struct ccw_device_id claw_ids[] = {
272 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
273 {},
274};
275MODULE_DEVICE_TABLE(ccw, claw_ids);
276
277static struct ccw_driver claw_ccw_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +0100278 .driver = {
279 .owner = THIS_MODULE,
280 .name = "claw",
281 },
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000282 .ids = claw_ids,
283 .probe = ccwgroup_probe_ccwdev,
284 .remove = ccwgroup_remove_ccwdev,
Heiko Carstens420f42e2013-01-02 15:18:18 +0100285 .int_class = IRQIO_CLW,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000286};
287
Sebastian Ott2ced5512012-05-15 18:00:49 +0200288static ssize_t claw_driver_group_store(struct device_driver *ddrv,
289 const char *buf, size_t count)
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000290{
291 int err;
Sebastian Ott9814fdf2012-05-15 18:03:46 +0200292 err = ccwgroup_create_dev(claw_root_dev, &claw_group_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000293 return err ? err : count;
294}
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000295static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
296
Sebastian Otta43f8de2012-05-15 18:06:29 +0200297static struct attribute *claw_drv_attrs[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000298 &driver_attr_group.attr,
299 NULL,
300};
Sebastian Otta43f8de2012-05-15 18:06:29 +0200301static struct attribute_group claw_drv_attr_group = {
302 .attrs = claw_drv_attrs,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000303};
Sebastian Otta43f8de2012-05-15 18:06:29 +0200304static const struct attribute_group *claw_drv_attr_groups[] = {
305 &claw_drv_attr_group,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000306 NULL,
307};
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310* Key functions
311*/
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313/*-------------------------------------------------------------------*
314 * claw_tx *
315 *-------------------------------------------------------------------*/
316
317static int
318claw_tx(struct sk_buff *skb, struct net_device *dev)
319{
320 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200321 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 unsigned long saveflags;
323 struct chbk *p_ch;
324
Andy Richterb805da72008-07-18 15:24:56 +0200325 CLAW_DBF_TEXT(4, trace, "claw_tx");
Heiko Carstens319cb0832010-08-12 01:58:27 +0000326 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
328 rc=claw_hw_tx( skb, dev, 1 );
329 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200330 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000331 if (rc)
332 rc = NETDEV_TX_BUSY;
Patrick McHardyec634fe2009-07-05 19:23:38 -0700333 else
334 rc = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 return rc;
336} /* end of claw_tx */
337
338/*------------------------------------------------------------------*
339 * pack the collect queue into an skb and return it *
340 * If not packing just return the top skb from the queue *
341 *------------------------------------------------------------------*/
342
343static struct sk_buff *
344claw_pack_skb(struct claw_privbk *privptr)
345{
346 struct sk_buff *new_skb,*held_skb;
Heiko Carstens319cb0832010-08-12 01:58:27 +0000347 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 struct claw_env *p_env = privptr->p_env;
349 int pkt_cnt,pk_ind,so_far;
350
351 new_skb = NULL; /* assume no dice */
352 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200353 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700354 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 /* some data */
356 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200358 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 else
360 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200361 if (p_env->packing != DO_PACKED)
362 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* get a new SKB we will pack at least one */
364 new_skb = dev_alloc_skb(p_env->write_size);
365 if (new_skb == NULL) {
366 atomic_inc(&held_skb->users);
367 skb_queue_head(&p_ch->collect_queue,held_skb);
368 return NULL;
369 }
370 /* we have packed packet and a place to put it */
371 pk_ind = 1;
372 so_far = 0;
373 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
374 while ((pk_ind) && (held_skb != NULL)) {
375 if (held_skb->len+so_far <= p_env->write_size-8) {
376 memcpy(skb_put(new_skb,held_skb->len),
377 held_skb->data,held_skb->len);
378 privptr->stats.tx_packets++;
379 so_far += held_skb->len;
380 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200381 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 held_skb = skb_dequeue(&p_ch->collect_queue);
383 if (held_skb)
384 atomic_dec(&held_skb->users);
385 } else {
386 pk_ind = 0;
387 atomic_inc(&held_skb->users);
388 skb_queue_head(&p_ch->collect_queue,held_skb);
389 }
390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 }
Andy Richterb805da72008-07-18 15:24:56 +0200392 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return new_skb;
394}
395
396/*-------------------------------------------------------------------*
397 * claw_change_mtu *
398 * *
399 *-------------------------------------------------------------------*/
400
401static int
402claw_change_mtu(struct net_device *dev, int new_mtu)
403{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200404 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200406 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 buff_size = privptr->p_env->write_size;
408 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 return -EINVAL;
410 }
411 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return 0;
413} /* end of claw_change_mtu */
414
415
416/*-------------------------------------------------------------------*
417 * claw_open *
418 * *
419 *-------------------------------------------------------------------*/
420static int
421claw_open(struct net_device *dev)
422{
423
424 int rc;
425 int i;
426 unsigned long saveflags=0;
427 unsigned long parm;
428 struct claw_privbk *privptr;
429 DECLARE_WAITQUEUE(wait, current);
430 struct timer_list timer;
431 struct ccwbk *p_buf;
432
Andy Richterb805da72008-07-18 15:24:56 +0200433 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200434 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 /* allocate and initialize CCW blocks */
436 if (privptr->buffs_alloc == 0) {
437 rc=init_ccw_bk(dev);
438 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200439 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return -ENOMEM;
441 }
442 }
443 privptr->system_validate_comp=0;
444 privptr->release_pend=0;
445 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
446 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
447 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
448 privptr->p_env->packing=PACKING_ASK;
449 } else {
450 privptr->p_env->packing=0;
451 privptr->p_env->read_size=CLAW_FRAME_SIZE;
452 privptr->p_env->write_size=CLAW_FRAME_SIZE;
453 }
454 claw_set_busy(dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +0000455 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
456 (unsigned long) &privptr->channel[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200458 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 init_waitqueue_head(&privptr->channel[i].wait);
460 /* skb_queue_head_init(&p_ch->io_queue); */
Heiko Carstens319cb0832010-08-12 01:58:27 +0000461 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 skb_queue_head_init(
Heiko Carstens319cb0832010-08-12 01:58:27 +0000463 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 privptr->channel[i].flag_a = 0;
465 privptr->channel[i].IO_active = 0;
466 privptr->channel[i].flag &= ~CLAW_TIMER;
467 init_timer(&timer);
468 timer.function = (void *)claw_timer;
469 timer.data = (unsigned long)(&privptr->channel[i]);
470 timer.expires = jiffies + 15*HZ;
471 add_timer(&timer);
472 spin_lock_irqsave(get_ccwdev_lock(
473 privptr->channel[i].cdev), saveflags);
474 parm = (unsigned long) &privptr->channel[i];
475 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
476 rc = 0;
477 add_wait_queue(&privptr->channel[i].wait, &wait);
478 rc = ccw_device_halt(
479 (struct ccw_device *)privptr->channel[i].cdev,parm);
480 set_current_state(TASK_INTERRUPTIBLE);
481 spin_unlock_irqrestore(
482 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
483 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 remove_wait_queue(&privptr->channel[i].wait, &wait);
485 if(rc != 0)
486 ccw_check_return_code(privptr->channel[i].cdev, rc);
487 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
488 del_timer(&timer);
489 }
Heiko Carstens319cb0832010-08-12 01:58:27 +0000490 if ((((privptr->channel[READ_CHANNEL].last_dstat |
491 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
Heiko Carstens319cb0832010-08-12 01:58:27 +0000493 (((privptr->channel[READ_CHANNEL].flag |
494 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
495 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000496 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200497 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 for ( i = 0; i < 2; i++) {
500 spin_lock_irqsave(
501 get_ccwdev_lock(privptr->channel[i].cdev),
502 saveflags);
503 parm = (unsigned long) &privptr->channel[i];
504 privptr->channel[i].claw_state = CLAW_STOP;
505 rc = ccw_device_halt(
506 (struct ccw_device *)&privptr->channel[i].cdev,
507 parm);
508 spin_unlock_irqrestore(
509 get_ccwdev_lock(privptr->channel[i].cdev),
510 saveflags);
511 if (rc != 0) {
512 ccw_check_return_code(
513 privptr->channel[i].cdev, rc);
514 }
515 }
516 free_pages((unsigned long)privptr->p_buff_ccw,
517 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
518 if (privptr->p_env->read_size < PAGE_SIZE) {
519 free_pages((unsigned long)privptr->p_buff_read,
520 (int)pages_to_order_of_mag(
521 privptr->p_buff_read_num));
522 }
523 else {
524 p_buf=privptr->p_read_active_first;
525 while (p_buf!=NULL) {
526 free_pages((unsigned long)p_buf->p_buffer,
527 (int)pages_to_order_of_mag(
528 privptr->p_buff_pages_perread ));
529 p_buf=p_buf->next;
530 }
531 }
532 if (privptr->p_env->write_size < PAGE_SIZE ) {
533 free_pages((unsigned long)privptr->p_buff_write,
534 (int)pages_to_order_of_mag(
535 privptr->p_buff_write_num));
536 }
537 else {
538 p_buf=privptr->p_write_active_first;
539 while (p_buf!=NULL) {
540 free_pages((unsigned long)p_buf->p_buffer,
541 (int)pages_to_order_of_mag(
542 privptr->p_buff_pages_perwrite ));
543 p_buf=p_buf->next;
544 }
545 }
546 privptr->buffs_alloc = 0;
Heiko Carstens319cb0832010-08-12 01:58:27 +0000547 privptr->channel[READ_CHANNEL].flag = 0x00;
548 privptr->channel[WRITE_CHANNEL].flag = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 privptr->p_buff_ccw=NULL;
550 privptr->p_buff_read=NULL;
551 privptr->p_buff_write=NULL;
552 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200553 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 return -EIO;
555 }
556
557 /* Send SystemValidate command */
558
559 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200560 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 return 0;
562} /* end of claw_open */
563
564/*-------------------------------------------------------------------*
565* *
566* claw_irq_handler *
567* *
568*--------------------------------------------------------------------*/
569static void
570claw_irq_handler(struct ccw_device *cdev,
571 unsigned long intparm, struct irb *irb)
572{
573 struct chbk *p_ch = NULL;
574 struct claw_privbk *privptr = NULL;
575 struct net_device *dev = NULL;
576 struct claw_env *p_env;
577 struct chbk *p_ch_r=NULL;
578
Andy Richterb805da72008-07-18 15:24:56 +0200579 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 /* Bypass all 'unsolicited interrupts' */
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700581 privptr = dev_get_drvdata(&cdev->dev);
582 if (!privptr) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000583 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
584 " IRQ, c-%02x d-%02x\n",
585 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200586 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 return;
588 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 /* Try to extract channel from driver data. */
Heiko Carstens319cb0832010-08-12 01:58:27 +0000591 if (privptr->channel[READ_CHANNEL].cdev == cdev)
592 p_ch = &privptr->channel[READ_CHANNEL];
593 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
594 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000596 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200597 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 return;
599 }
Andy Richterb805da72008-07-18 15:24:56 +0200600 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 dev = (struct net_device *) (p_ch->ndev);
603 p_env=privptr->p_env;
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /* Copy interruption response block. */
606 memcpy(p_ch->irb, irb, sizeof(struct irb));
607
Andy Richterb805da72008-07-18 15:24:56 +0200608 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200609 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000610 dev_info(&cdev->dev,
611 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
613 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200614 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
615 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200616 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 /* return; */
618 }
619
620 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200621 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200625 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200628 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
629 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
630 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
631 (p_ch->irb->scsw.cmd.stctl ==
632 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
633 return;
634 wake_up(&p_ch->wait); /* wake up claw_release */
635 CLAW_DBF_TEXT(4, trace, "stop");
636 return;
637 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
638 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
639 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
640 (p_ch->irb->scsw.cmd.stctl ==
641 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
642 CLAW_DBF_TEXT(4, trace, "haltio");
643 return;
644 }
645 if (p_ch->flag == CLAW_READ) {
646 p_ch->claw_state = CLAW_START_READ;
647 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
648 } else if (p_ch->flag == CLAW_WRITE) {
649 p_ch->claw_state = CLAW_START_WRITE;
Andy Richter4811fcb2009-01-20 06:14:33 +0000650 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200651 claw_strt_read(dev, LOCK_NO);
652 claw_send_control(dev,
653 SYSTEM_VALIDATE_REQUEST,
654 0, 0, 0,
655 p_env->host_name,
656 p_env->adapter_name);
657 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000658 dev_warn(&cdev->dev, "The CLAW device received"
659 " an unexpected IRQ, "
660 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200661 irb->scsw.cmd.cstat,
662 irb->scsw.cmd.dstat);
663 return;
664 }
665 CLAW_DBF_TEXT(4, trace, "haltio");
666 return;
667 case CLAW_START_READ:
668 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
669 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
670 clear_bit(0, (void *)&p_ch->IO_active);
671 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
672 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
673 (p_ch->irb->ecw[0]) == 0) {
674 privptr->stats.rx_errors++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000675 dev_info(&cdev->dev,
676 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200677 "side recovers \n",
678 dev->name);
679 }
680 CLAW_DBF_TEXT(4, trace, "notrdy");
681 return;
682 }
683 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
684 (p_ch->irb->scsw.cmd.dstat == 0)) {
685 if (test_and_set_bit(CLAW_BH_ACTIVE,
686 (void *)&p_ch->flag_a) == 0)
687 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 else
Andy Richterb805da72008-07-18 15:24:56 +0200689 CLAW_DBF_TEXT(4, trace, "PCINoBH");
690 CLAW_DBF_TEXT(4, trace, "PCI_read");
691 return;
692 }
693 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
694 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
695 (p_ch->irb->scsw.cmd.stctl ==
696 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
697 CLAW_DBF_TEXT(4, trace, "SPend_rd");
698 return;
699 }
700 clear_bit(0, (void *)&p_ch->IO_active);
701 claw_clearbit_busy(TB_RETRY, dev);
702 if (test_and_set_bit(CLAW_BH_ACTIVE,
703 (void *)&p_ch->flag_a) == 0)
704 tasklet_schedule(&p_ch->tasklet);
705 else
706 CLAW_DBF_TEXT(4, trace, "RdBHAct");
707 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
708 return;
709 case CLAW_START_WRITE:
710 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000711 dev_info(&cdev->dev,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300712 "%s: Unit Check Occurred in "
Andy Richterb805da72008-07-18 15:24:56 +0200713 "write channel\n", dev->name);
714 clear_bit(0, (void *)&p_ch->IO_active);
715 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000716 dev_info(&cdev->dev,
717 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200718 "occurred:\n", dev->name);
719 init_timer(&p_ch->timer);
720 p_ch->timer.function =
721 (void *)claw_write_retry;
722 p_ch->timer.data = (unsigned long)p_ch;
723 p_ch->timer.expires = jiffies + 10*HZ;
724 add_timer(&p_ch->timer);
Andy Richter4811fcb2009-01-20 06:14:33 +0000725 dev_info(&cdev->dev,
726 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200727 "restarting\n", dev->name);
728 }
729 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
730 return;
731 }
732 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
733 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000734 dev_info(&cdev->dev,
735 "%s: Unit Exception "
736 "occurred in write channel\n",
737 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200738 }
739 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
740 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
741 (p_ch->irb->scsw.cmd.stctl ==
742 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
743 CLAW_DBF_TEXT(4, trace, "writeUE");
744 return;
745 }
746 clear_bit(0, (void *)&p_ch->IO_active);
747 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
748 claw_write_next(p_ch);
749 claw_clearbit_busy(TB_TX, dev);
750 claw_clear_busy(dev);
751 }
Heiko Carstens319cb0832010-08-12 01:58:27 +0000752 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +0200753 if (test_and_set_bit(CLAW_BH_ACTIVE,
754 (void *)&p_ch_r->flag_a) == 0)
755 tasklet_schedule(&p_ch_r->tasklet);
756 CLAW_DBF_TEXT(4, trace, "StWtExit");
757 return;
758 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000759 dev_warn(&cdev->dev,
760 "The CLAW device for %s received an unexpected IRQ\n",
761 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200762 CLAW_DBF_TEXT(2, trace, "badIRQ");
763 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765
766} /* end of claw_irq_handler */
767
768
769/*-------------------------------------------------------------------*
770* claw_irq_tasklet *
771* *
772*--------------------------------------------------------------------*/
773static void
774claw_irq_tasklet ( unsigned long data )
775{
776 struct chbk * p_ch;
777 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 p_ch = (struct chbk *) data;
780 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200781 CLAW_DBF_TEXT(4, trace, "IRQtask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 unpack_read(dev);
783 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200784 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 return;
786} /* end of claw_irq_bh */
787
788/*-------------------------------------------------------------------*
789* claw_release *
790* *
791*--------------------------------------------------------------------*/
792static int
793claw_release(struct net_device *dev)
794{
795 int rc;
796 int i;
797 unsigned long saveflags;
798 unsigned long parm;
799 struct claw_privbk *privptr;
800 DECLARE_WAITQUEUE(wait, current);
801 struct ccwbk* p_this_ccw;
802 struct ccwbk* p_buf;
803
804 if (!dev)
805 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200806 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 if (!privptr)
808 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200809 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 privptr->release_pend=1;
811 claw_setbit_busy(TB_STOP,dev);
812 for ( i = 1; i >=0 ; i--) {
813 spin_lock_irqsave(
814 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
Heiko Carstens319cb0832010-08-12 01:58:27 +0000815 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 privptr->channel[i].claw_state = CLAW_STOP;
817 privptr->channel[i].IO_active = 0;
818 parm = (unsigned long) &privptr->channel[i];
Heiko Carstens319cb0832010-08-12 01:58:27 +0000819 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 claw_purge_skb_queue(
Heiko Carstens319cb0832010-08-12 01:58:27 +0000821 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
823 if (privptr->system_validate_comp==0x00) /* never opened? */
824 init_waitqueue_head(&privptr->channel[i].wait);
825 add_wait_queue(&privptr->channel[i].wait, &wait);
826 set_current_state(TASK_INTERRUPTIBLE);
827 spin_unlock_irqrestore(
828 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
829 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 remove_wait_queue(&privptr->channel[i].wait, &wait);
831 if (rc != 0) {
832 ccw_check_return_code(privptr->channel[i].cdev, rc);
833 }
834 }
835 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200836 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 privptr->pk_skb = NULL;
838 }
839 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200840 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 return 0;
842 }
Andy Richterb805da72008-07-18 15:24:56 +0200843 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 if (privptr->p_buff_ccw != NULL) {
845 free_pages((unsigned long)privptr->p_buff_ccw,
846 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
847 }
Andy Richterb805da72008-07-18 15:24:56 +0200848 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 if (privptr->p_env->read_size < PAGE_SIZE) {
850 if (privptr->p_buff_read != NULL) {
851 free_pages((unsigned long)privptr->p_buff_read,
852 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
853 }
854 }
855 else {
856 p_buf=privptr->p_read_active_first;
857 while (p_buf!=NULL) {
858 free_pages((unsigned long)p_buf->p_buffer,
859 (int)pages_to_order_of_mag(
860 privptr->p_buff_pages_perread ));
861 p_buf=p_buf->next;
862 }
863 }
Andy Richterb805da72008-07-18 15:24:56 +0200864 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if (privptr->p_env->write_size < PAGE_SIZE ) {
866 free_pages((unsigned long)privptr->p_buff_write,
867 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
868 }
869 else {
870 p_buf=privptr->p_write_active_first;
871 while (p_buf!=NULL) {
872 free_pages((unsigned long)p_buf->p_buffer,
873 (int)pages_to_order_of_mag(
874 privptr->p_buff_pages_perwrite ));
875 p_buf=p_buf->next;
876 }
877 }
Andy Richterb805da72008-07-18 15:24:56 +0200878 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 privptr->buffs_alloc = 0;
880 privptr->p_buff_ccw=NULL;
881 privptr->p_buff_read=NULL;
882 privptr->p_buff_write=NULL;
883 privptr->system_validate_comp=0;
884 privptr->release_pend=0;
885 /* Remove any writes that were pending and reset all reads */
886 p_this_ccw=privptr->p_read_active_first;
887 while (p_this_ccw!=NULL) {
888 p_this_ccw->header.length=0xffff;
889 p_this_ccw->header.opcode=0xff;
890 p_this_ccw->header.flag=0x00;
891 p_this_ccw=p_this_ccw->next;
892 }
893
894 while (privptr->p_write_active_first!=NULL) {
895 p_this_ccw=privptr->p_write_active_first;
896 p_this_ccw->header.flag=CLAW_PENDING;
897 privptr->p_write_active_first=p_this_ccw->next;
898 p_this_ccw->next=privptr->p_write_free_chain;
899 privptr->p_write_free_chain=p_this_ccw;
900 ++privptr->write_free_count;
901 }
902 privptr->p_write_active_last=NULL;
903 privptr->mtc_logical_link = -1;
904 privptr->mtc_skipping = 1;
905 privptr->mtc_offset=0;
906
Heiko Carstens319cb0832010-08-12 01:58:27 +0000907 if (((privptr->channel[READ_CHANNEL].last_dstat |
908 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Heiko Carstens319cb0832010-08-12 01:58:27 +0000910 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000911 "Deactivating %s completed with incorrect"
912 " subchannel status "
913 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 dev->name,
Heiko Carstens319cb0832010-08-12 01:58:27 +0000915 privptr->channel[READ_CHANNEL].last_dstat,
916 privptr->channel[WRITE_CHANNEL].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200917 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 }
Andy Richterb805da72008-07-18 15:24:56 +0200919 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 return 0;
921} /* end of claw_release */
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923/*-------------------------------------------------------------------*
924* claw_write_retry *
925* *
926*--------------------------------------------------------------------*/
927
928static void
929claw_write_retry ( struct chbk *p_ch )
930{
931
932 struct net_device *dev=p_ch->ndev;
933
Andy Richterb805da72008-07-18 15:24:56 +0200934 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 return;
937 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +0200939 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 return;
941} /* end of claw_write_retry */
942
943
944/*-------------------------------------------------------------------*
945* claw_write_next *
946* *
947*--------------------------------------------------------------------*/
948
949static void
950claw_write_next ( struct chbk * p_ch )
951{
952
953 struct net_device *dev;
954 struct claw_privbk *privptr=NULL;
955 struct sk_buff *pk_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Andy Richterb805da72008-07-18 15:24:56 +0200957 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 if (p_ch->claw_state == CLAW_STOP)
959 return;
960 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200961 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 claw_free_wrt_buf( dev );
963 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -0700964 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 pk_skb = claw_pack_skb(privptr);
966 while (pk_skb != NULL) {
Heiko Carstens38ed18f2011-05-12 18:45:04 +0000967 claw_hw_tx(pk_skb, dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 if (privptr->write_free_count > 0) {
969 pk_skb = claw_pack_skb(privptr);
970 } else
971 pk_skb = NULL;
972 }
973 }
974 if (privptr->p_write_active_first!=NULL) {
975 claw_strt_out_IO(dev);
976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 return;
978} /* end of claw_write_next */
979
980/*-------------------------------------------------------------------*
981* *
982* claw_timer *
983*--------------------------------------------------------------------*/
984
985static void
986claw_timer ( struct chbk * p_ch )
987{
Andy Richterb805da72008-07-18 15:24:56 +0200988 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 p_ch->flag |= CLAW_TIMER;
990 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 return;
992} /* end of claw_timer */
993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994/*
995*
996* functions
997*/
998
999
1000/*-------------------------------------------------------------------*
1001* *
1002* pages_to_order_of_mag *
1003* *
1004* takes a number of pages from 1 to 512 and returns the *
1005* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1006* of magnitude get_free_pages() has an upper order of 9 *
1007*--------------------------------------------------------------------*/
1008
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001009static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010pages_to_order_of_mag(int num_of_pages)
1011{
1012 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001013 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001014
1015 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1017 /* 512 pages = 2Meg on 4k page systems */
1018 if (num_of_pages >= 512) {return 9; }
1019 /* we have two or more pages order is at least 1 */
1020 for (nump=2 ;nump <= 512;nump*=2) {
1021 if (num_of_pages <= nump)
1022 break;
1023 order_of_mag +=1;
1024 }
1025 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001026 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 return order_of_mag;
1028}
1029
1030/*-------------------------------------------------------------------*
1031* *
1032* add_claw_reads *
1033* *
1034*--------------------------------------------------------------------*/
1035static int
1036add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1037 struct ccwbk* p_last)
1038{
1039 struct claw_privbk *privptr;
1040 struct ccw1 temp_ccw;
1041 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001042 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001043 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 p_end = privptr->p_end_ccw;
1045
1046 /* first CCW and last CCW contains a new set of read channel programs
1047 * to apend the running channel programs
1048 */
1049 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001050 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 return 0;
1052 }
1053
1054 /* set up ending CCW sequence for this segment */
1055 if (p_end->read1) {
1056 p_end->read1=0x00; /* second ending CCW is now active */
1057 /* reset ending CCWs and setup TIC CCWs */
1058 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1059 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1060 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1061 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1062 p_end->read2_nop2.cda=0;
1063 p_end->read2_nop2.count=1;
1064 }
1065 else {
1066 p_end->read1=0x01; /* first ending CCW is now active */
1067 /* reset ending CCWs and setup TIC CCWs */
1068 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1069 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1070 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1071 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1072 p_end->read1_nop2.cda=0;
1073 p_end->read1_nop2.count=1;
1074 }
1075
1076 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001077 privptr->p_read_active_first = p_first; /* set new first */
1078 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 }
1080 else {
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 /* set up TIC ccw */
1083 temp_ccw.cda= (__u32)__pa(&p_first->read);
1084 temp_ccw.count=0;
1085 temp_ccw.flags=0;
1086 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1087
1088
1089 if (p_end->read1) {
1090
1091 /* first set of CCW's is chained to the new read */
1092 /* chain, so the second set is chained to the active chain. */
1093 /* Therefore modify the second set to point to the new */
1094 /* read chain set up TIC CCWs */
1095 /* make sure we update the CCW so channel doesn't fetch it */
1096 /* when it's only half done */
1097 memcpy( &p_end->read2_nop2, &temp_ccw ,
1098 sizeof(struct ccw1));
1099 privptr->p_read_active_last->r_TIC_1.cda=
1100 (__u32)__pa(&p_first->read);
1101 privptr->p_read_active_last->r_TIC_2.cda=
1102 (__u32)__pa(&p_first->read);
1103 }
1104 else {
1105 /* make sure we update the CCW so channel doesn't */
1106 /* fetch it when it is only half done */
1107 memcpy( &p_end->read1_nop2, &temp_ccw ,
1108 sizeof(struct ccw1));
1109 privptr->p_read_active_last->r_TIC_1.cda=
1110 (__u32)__pa(&p_first->read);
1111 privptr->p_read_active_last->r_TIC_2.cda=
1112 (__u32)__pa(&p_first->read);
1113 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001114 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 privptr->p_read_active_last->next = p_first;
1116 privptr->p_read_active_last=p_last;
1117 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001118 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 return 0;
1120} /* end of add_claw_reads */
1121
1122/*-------------------------------------------------------------------*
1123 * ccw_check_return_code *
1124 * *
1125 *-------------------------------------------------------------------*/
1126
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001127static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128ccw_check_return_code(struct ccw_device *cdev, int return_code)
1129{
Andy Richterb805da72008-07-18 15:24:56 +02001130 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 if (return_code != 0) {
1132 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001133 case -EBUSY: /* BUSY is a transient state no action needed */
1134 break;
1135 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001136 dev_err(&cdev->dev, "The remote channel adapter is not"
1137 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001138 break;
1139 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001140 dev_err(&cdev->dev,
1141 "The status of the remote channel adapter"
1142 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001143 break;
1144 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001145 dev_err(&cdev->dev, "The common device layer"
1146 " returned error code %d\n",
1147 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001148 }
1149 }
1150 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151} /* end of ccw_check_return_code */
1152
1153/*-------------------------------------------------------------------*
1154* ccw_check_unit_check *
1155*--------------------------------------------------------------------*/
1156
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001157static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1159{
Andy Richterb805da72008-07-18 15:24:56 +02001160 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001161 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Andy Richterb805da72008-07-18 15:24:56 +02001163 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001164 dev_warn(dev, "The communication peer of %s disconnected\n",
1165 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001167 if (sense & 0x40) {
1168 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001169 dev_warn(dev, "The remote channel adapter for"
1170 " %s has been reset\n",
1171 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001172 }
1173 } else if (sense & 0x20) {
1174 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001175 dev_warn(dev, "A data streaming timeout occurred"
1176 " for %s\n",
1177 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001178 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001179 dev_warn(dev, "The remote channel adapter for %s"
1180 " is faulty\n",
1181 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001182 } else {
1183 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001184 " for %s\n",
1185 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001186 }
1187 } else if (sense & 0x10) {
1188 dev_warn(dev, "A read data parity error occurred"
1189 " for %s\n",
1190 ndev->name);
1191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193} /* end of ccw_check_unit_check */
1194
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195/*-------------------------------------------------------------------*
1196* find_link *
1197*--------------------------------------------------------------------*/
1198static int
1199find_link(struct net_device *dev, char *host_name, char *ws_name )
1200{
1201 struct claw_privbk *privptr;
1202 struct claw_env *p_env;
1203 int rc=0;
1204
Andy Richterb805da72008-07-18 15:24:56 +02001205 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001206 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 p_env=privptr->p_env;
1208 switch (p_env->packing)
1209 {
1210 case PACKING_ASK:
1211 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1212 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1213 rc = EINVAL;
1214 break;
1215 case DO_PACKED:
1216 case PACK_SEND:
1217 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1218 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1219 rc = EINVAL;
1220 break;
1221 default:
1222 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1223 (memcmp(p_env->api_type , ws_name, 8)!=0))
1224 rc = EINVAL;
1225 break;
1226 }
1227
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001228 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229} /* end of find_link */
1230
1231/*-------------------------------------------------------------------*
1232 * claw_hw_tx *
1233 * *
1234 * *
1235 *-------------------------------------------------------------------*/
1236
1237static int
1238claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1239{
1240 int rc=0;
1241 struct claw_privbk *privptr;
1242 struct ccwbk *p_this_ccw;
1243 struct ccwbk *p_first_ccw;
1244 struct ccwbk *p_last_ccw;
1245 __u32 numBuffers;
1246 signed long len_of_data;
1247 unsigned long bytesInThisBuffer;
1248 unsigned char *pDataAddress;
1249 struct endccw *pEnd;
1250 struct ccw1 tempCCW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 struct claw_env *p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 struct clawph *pk_head;
1253 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001254
1255 CLAW_DBF_TEXT(4, trace, "hw_tx");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001256 privptr = (struct claw_privbk *)(dev->ml_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1259 /* scan the write queue to free any completed write packets */
1260 p_first_ccw=NULL;
1261 p_last_ccw=NULL;
1262 if ((p_env->packing >= PACK_SEND) &&
1263 (skb->cb[1] != 'P')) {
1264 skb_push(skb,sizeof(struct clawph));
1265 pk_head=(struct clawph *)skb->data;
1266 pk_head->len=skb->len-sizeof(struct clawph);
1267 if (pk_head->len%4) {
1268 pk_head->len+= 4-(pk_head->len%4);
1269 skb_pad(skb,4-(pk_head->len%4));
1270 skb_put(skb,4-(pk_head->len%4));
1271 }
1272 if (p_env->packing == DO_PACKED)
1273 pk_head->link_num = linkid;
1274 else
1275 pk_head->link_num = 0;
1276 pk_head->flag = 0x00;
1277 skb_pad(skb,4);
1278 skb->cb[1] = 'P';
1279 }
1280 if (linkid == 0) {
1281 if (claw_check_busy(dev)) {
1282 if (privptr->write_free_count!=0) {
1283 claw_clear_busy(dev);
1284 }
1285 else {
1286 claw_strt_out_IO(dev );
1287 claw_free_wrt_buf( dev );
1288 if (privptr->write_free_count==0) {
Heiko Carstens319cb0832010-08-12 01:58:27 +00001289 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 atomic_inc(&skb->users);
1291 skb_queue_tail(&ch->collect_queue, skb);
1292 goto Done;
1293 }
1294 else {
1295 claw_clear_busy(dev);
1296 }
1297 }
1298 }
1299 /* tx lock */
1300 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Heiko Carstens319cb0832010-08-12 01:58:27 +00001301 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 atomic_inc(&skb->users);
1303 skb_queue_tail(&ch->collect_queue, skb);
1304 claw_strt_out_IO(dev );
1305 rc=-EBUSY;
1306 goto Done2;
1307 }
1308 }
1309 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001310 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 /* If that number of buffers isn't available, give up for now */
1313 if (privptr->write_free_count < numBuffers ||
1314 privptr->p_write_free_chain == NULL ) {
1315
1316 claw_setbit_busy(TB_NOBUFFER,dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +00001317 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 atomic_inc(&skb->users);
1319 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001320 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 goto Done2;
1322 }
1323 pDataAddress=skb->data;
1324 len_of_data=skb->len;
1325
1326 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1328 if (p_this_ccw == NULL) { /* lost the race */
Heiko Carstens319cb0832010-08-12 01:58:27 +00001329 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 atomic_inc(&skb->users);
1331 skb_queue_tail(&ch->collect_queue, skb);
1332 goto Done2;
1333 }
1334 privptr->p_write_free_chain=p_this_ccw->next;
1335 p_this_ccw->next=NULL;
1336 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001337 if (len_of_data >= privptr->p_env->write_size)
1338 bytesInThisBuffer = privptr->p_env->write_size;
1339 else
1340 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1342 len_of_data-=bytesInThisBuffer;
1343 pDataAddress+=(unsigned long)bytesInThisBuffer;
1344 /* setup write CCW */
1345 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1346 if (len_of_data>0) {
1347 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1348 }
1349 p_this_ccw->write.count=bytesInThisBuffer;
1350 /* now add to end of this chain */
1351 if (p_first_ccw==NULL) {
1352 p_first_ccw=p_this_ccw;
1353 }
1354 if (p_last_ccw!=NULL) {
1355 p_last_ccw->next=p_this_ccw;
1356 /* set up TIC ccws */
1357 p_last_ccw->w_TIC_1.cda=
1358 (__u32)__pa(&p_this_ccw->write);
1359 }
1360 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
1362
1363 /* FirstCCW and LastCCW now contain a new set of write channel
1364 * programs to append to the running channel program
1365 */
1366
1367 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001368 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 pEnd=privptr->p_end_ccw;
1370 if (pEnd->write1) {
1371 pEnd->write1=0x00; /* second end ccw is now active */
1372 /* set up Tic CCWs */
1373 p_last_ccw->w_TIC_1.cda=
1374 (__u32)__pa(&pEnd->write2_nop1);
1375 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1376 pEnd->write2_nop2.flags =
1377 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1378 pEnd->write2_nop2.cda=0;
1379 pEnd->write2_nop2.count=1;
1380 }
1381 else { /* end of if (pEnd->write1)*/
1382 pEnd->write1=0x01; /* first end ccw is now active */
1383 /* set up Tic CCWs */
1384 p_last_ccw->w_TIC_1.cda=
1385 (__u32)__pa(&pEnd->write1_nop1);
1386 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1387 pEnd->write1_nop2.flags =
1388 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1389 pEnd->write1_nop2.cda=0;
1390 pEnd->write1_nop2.count=1;
1391 } /* end if if (pEnd->write1) */
1392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 if (privptr->p_write_active_first==NULL ) {
1394 privptr->p_write_active_first=p_first_ccw;
1395 privptr->p_write_active_last=p_last_ccw;
1396 }
1397 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 /* set up Tic CCWs */
1399
1400 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1401 tempCCW.count=0;
1402 tempCCW.flags=0;
1403 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1404
1405 if (pEnd->write1) {
1406
1407 /*
1408 * first set of ending CCW's is chained to the new write
1409 * chain, so the second set is chained to the active chain
1410 * Therefore modify the second set to point the new write chain.
1411 * make sure we update the CCW atomically
1412 * so channel does not fetch it when it's only half done
1413 */
1414 memcpy( &pEnd->write2_nop2, &tempCCW ,
1415 sizeof(struct ccw1));
1416 privptr->p_write_active_last->w_TIC_1.cda=
1417 (__u32)__pa(&p_first_ccw->write);
1418 }
1419 else {
1420
1421 /*make sure we update the CCW atomically
1422 *so channel does not fetch it when it's only half done
1423 */
1424 memcpy(&pEnd->write1_nop2, &tempCCW ,
1425 sizeof(struct ccw1));
1426 privptr->p_write_active_last->w_TIC_1.cda=
1427 (__u32)__pa(&p_first_ccw->write);
1428
1429 } /* end if if (pEnd->write1) */
1430
1431 privptr->p_write_active_last->next=p_first_ccw;
1432 privptr->p_write_active_last=p_last_ccw;
1433 }
1434
1435 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001436 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 claw_strt_out_IO(dev );
1438 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 if (privptr->write_free_count==0) {
1440 claw_setbit_busy(TB_NOBUFFER,dev);
1441 }
1442Done2:
1443 claw_clearbit_busy(TB_TX,dev);
1444Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 return(rc);
1446} /* end of claw_hw_tx */
1447
1448/*-------------------------------------------------------------------*
1449* *
1450* init_ccw_bk *
1451* *
1452*--------------------------------------------------------------------*/
1453
1454static int
1455init_ccw_bk(struct net_device *dev)
1456{
1457
1458 __u32 ccw_blocks_required;
1459 __u32 ccw_blocks_perpage;
1460 __u32 ccw_pages_required;
1461 __u32 claw_reads_perpage=1;
1462 __u32 claw_read_pages;
1463 __u32 claw_writes_perpage=1;
1464 __u32 claw_write_pages;
1465 void *p_buff=NULL;
1466 struct ccwbk*p_free_chain;
1467 struct ccwbk*p_buf;
1468 struct ccwbk*p_last_CCWB;
1469 struct ccwbk*p_first_CCWB;
1470 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001471 addr_t real_address;
1472 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 struct clawh *pClawH=NULL;
1474 addr_t real_TIC_address;
1475 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001476 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 /* initialize statistics field */
1479 privptr->active_link_ID=0;
1480 /* initialize ccwbk pointers */
1481 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1482 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1483 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1484 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1485 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1486 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1487 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1488 privptr->buffs_alloc = 0;
1489 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1490 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1491 /* initialize free write ccwbk counter */
1492 privptr->write_free_count=0; /* number of free bufs on write chain */
1493 p_last_CCWB = NULL;
1494 p_first_CCWB= NULL;
1495 /*
1496 * We need 1 CCW block for each read buffer, 1 for each
1497 * write buffer, plus 1 for ClawSignalBlock
1498 */
1499 ccw_blocks_required =
1500 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 /*
1502 * compute number of CCW blocks that will fit in a page
1503 */
1504 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1505 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001506 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 /*
1509 * read and write sizes are set by 2 constants in claw.h
1510 * 4k and 32k. Unpacked values other than 4k are not going to
1511 * provide good performance. With packing buffers support 32k
1512 * buffers are used.
1513 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001514 if (privptr->p_env->read_size < PAGE_SIZE) {
1515 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1516 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1517 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 }
1519 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001520 privptr->p_buff_pages_perread =
1521 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1522 claw_read_pages = privptr->p_env->read_buffers *
1523 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 }
1525 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001526 claw_writes_perpage =
1527 PAGE_SIZE / privptr->p_env->write_size;
1528 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1529 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
1531 }
1532 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001533 privptr->p_buff_pages_perwrite =
1534 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1535 claw_write_pages = privptr->p_env->write_buffers *
1536 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 /*
1539 * allocate ccw_pages_required
1540 */
1541 if (privptr->p_buff_ccw==NULL) {
1542 privptr->p_buff_ccw=
1543 (void *)__get_free_pages(__GFP_DMA,
1544 (int)pages_to_order_of_mag(ccw_pages_required ));
1545 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 return -ENOMEM;
1547 }
1548 privptr->p_buff_ccw_num=ccw_pages_required;
1549 }
1550 memset(privptr->p_buff_ccw, 0x00,
1551 privptr->p_buff_ccw_num * PAGE_SIZE);
1552
1553 /*
1554 * obtain ending ccw block address
1555 *
1556 */
1557 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1558 real_address = (__u32)__pa(privptr->p_end_ccw);
1559 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 p_endccw=privptr->p_end_ccw;
1561 p_endccw->real=real_address;
1562 p_endccw->write1=0x00;
1563 p_endccw->read1=0x00;
1564
1565 /* write1_nop1 */
1566 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1567 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1568 p_endccw->write1_nop1.count = 1;
1569 p_endccw->write1_nop1.cda = 0;
1570
1571 /* write1_nop2 */
1572 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1573 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1574 p_endccw->write1_nop2.count = 1;
1575 p_endccw->write1_nop2.cda = 0;
1576
1577 /* write2_nop1 */
1578 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1579 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1580 p_endccw->write2_nop1.count = 1;
1581 p_endccw->write2_nop1.cda = 0;
1582
1583 /* write2_nop2 */
1584 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1585 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1586 p_endccw->write2_nop2.count = 1;
1587 p_endccw->write2_nop2.cda = 0;
1588
1589 /* read1_nop1 */
1590 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1591 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1592 p_endccw->read1_nop1.count = 1;
1593 p_endccw->read1_nop1.cda = 0;
1594
1595 /* read1_nop2 */
1596 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1597 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1598 p_endccw->read1_nop2.count = 1;
1599 p_endccw->read1_nop2.cda = 0;
1600
1601 /* read2_nop1 */
1602 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1603 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1604 p_endccw->read2_nop1.count = 1;
1605 p_endccw->read2_nop1.cda = 0;
1606
1607 /* read2_nop2 */
1608 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1609 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1610 p_endccw->read2_nop2.count = 1;
1611 p_endccw->read2_nop2.cda = 0;
1612
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 /*
1614 * Build a chain of CCWs
1615 *
1616 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 p_buff=privptr->p_buff_ccw;
1618
1619 p_free_chain=NULL;
1620 for (i=0 ; i < ccw_pages_required; i++ ) {
1621 real_address = (__u32)__pa(p_buff);
1622 p_buf=p_buff;
1623 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1624 p_buf->next = p_free_chain;
1625 p_free_chain = p_buf;
1626 p_buf->real=(__u32)__pa(p_buf);
1627 ++p_buf;
1628 }
1629 p_buff+=PAGE_SIZE;
1630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 /*
1632 * Initialize ClawSignalBlock
1633 *
1634 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 if (privptr->p_claw_signal_blk==NULL) {
1636 privptr->p_claw_signal_blk=p_free_chain;
1637 p_free_chain=p_free_chain->next;
1638 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1639 pClawH->length=0xffff;
1640 pClawH->opcode=0xff;
1641 pClawH->flag=CLAW_BUSY;
1642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
1644 /*
1645 * allocate write_pages_required and add to free chain
1646 */
1647 if (privptr->p_buff_write==NULL) {
1648 if (privptr->p_env->write_size < PAGE_SIZE) {
1649 privptr->p_buff_write=
1650 (void *)__get_free_pages(__GFP_DMA,
1651 (int)pages_to_order_of_mag(claw_write_pages ));
1652 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 return -ENOMEM;
1655 }
1656 /*
1657 * Build CLAW write free chain
1658 *
1659 */
1660
1661 memset(privptr->p_buff_write, 0x00,
1662 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 privptr->p_write_free_chain=NULL;
1664
1665 p_buff=privptr->p_buff_write;
1666
1667 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1668 p_buf = p_free_chain; /* get a CCW */
1669 p_free_chain = p_buf->next;
1670 p_buf->next =privptr->p_write_free_chain;
1671 privptr->p_write_free_chain = p_buf;
1672 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1673 p_buf-> write.cda = (__u32)__pa(p_buff);
1674 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1675 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1676 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1677 p_buf-> w_read_FF.count = 1;
1678 p_buf-> w_read_FF.cda =
1679 (__u32)__pa(&p_buf-> header.flag);
1680 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1681 p_buf-> w_TIC_1.flags = 0;
1682 p_buf-> w_TIC_1.count = 0;
1683
Andy Richter4811fcb2009-01-20 06:14:33 +00001684 if (((unsigned long)p_buff +
1685 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001687 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1688 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 }
1690 }
1691 }
1692 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1693 {
1694 privptr->p_write_free_chain=NULL;
1695 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1696 p_buff=(void *)__get_free_pages(__GFP_DMA,
1697 (int)pages_to_order_of_mag(
1698 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 free_pages((unsigned long)privptr->p_buff_ccw,
1701 (int)pages_to_order_of_mag(
1702 privptr->p_buff_ccw_num));
1703 privptr->p_buff_ccw=NULL;
1704 p_buf=privptr->p_buff_write;
1705 while (p_buf!=NULL) {
1706 free_pages((unsigned long)
1707 p_buf->p_buffer,
1708 (int)pages_to_order_of_mag(
1709 privptr->p_buff_pages_perwrite));
1710 p_buf=p_buf->next;
1711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 return -ENOMEM;
1713 } /* Error on get_pages */
1714 memset(p_buff, 0x00, privptr->p_env->write_size );
1715 p_buf = p_free_chain;
1716 p_free_chain = p_buf->next;
1717 p_buf->next = privptr->p_write_free_chain;
1718 privptr->p_write_free_chain = p_buf;
1719 privptr->p_buff_write = p_buf;
1720 p_buf->p_buffer=(struct clawbuf *)p_buff;
1721 p_buf-> write.cda = (__u32)__pa(p_buff);
1722 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1723 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1724 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1725 p_buf-> w_read_FF.count = 1;
1726 p_buf-> w_read_FF.cda =
1727 (__u32)__pa(&p_buf-> header.flag);
1728 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1729 p_buf-> w_TIC_1.flags = 0;
1730 p_buf-> w_TIC_1.count = 0;
1731 } /* for all write_buffers */
1732
1733 } /* else buffers are PAGE_SIZE or bigger */
1734
1735 }
1736 privptr->p_buff_write_num=claw_write_pages;
1737 privptr->write_free_count=privptr->p_env->write_buffers;
1738
1739
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 /*
1741 * allocate read_pages_required and chain to free chain
1742 */
1743 if (privptr->p_buff_read==NULL) {
1744 if (privptr->p_env->read_size < PAGE_SIZE) {
1745 privptr->p_buff_read=
1746 (void *)__get_free_pages(__GFP_DMA,
1747 (int)pages_to_order_of_mag(claw_read_pages) );
1748 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 free_pages((unsigned long)privptr->p_buff_ccw,
1750 (int)pages_to_order_of_mag(
1751 privptr->p_buff_ccw_num));
1752 /* free the write pages size is < page size */
1753 free_pages((unsigned long)privptr->p_buff_write,
1754 (int)pages_to_order_of_mag(
1755 privptr->p_buff_write_num));
1756 privptr->p_buff_ccw=NULL;
1757 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 return -ENOMEM;
1759 }
1760 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1761 privptr->p_buff_read_num=claw_read_pages;
1762 /*
1763 * Build CLAW read free chain
1764 *
1765 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 p_buff=privptr->p_buff_read;
1767 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1768 p_buf = p_free_chain;
1769 p_free_chain = p_buf->next;
1770
1771 if (p_last_CCWB==NULL) {
1772 p_buf->next=NULL;
1773 real_TIC_address=0;
1774 p_last_CCWB=p_buf;
1775 }
1776 else {
1777 p_buf->next=p_first_CCWB;
1778 real_TIC_address=
1779 (__u32)__pa(&p_first_CCWB -> read );
1780 }
1781
1782 p_first_CCWB=p_buf;
1783
1784 p_buf->p_buffer=(struct clawbuf *)p_buff;
1785 /* initialize read command */
1786 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1787 p_buf-> read.cda = (__u32)__pa(p_buff);
1788 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1789 p_buf-> read.count = privptr->p_env->read_size;
1790
1791 /* initialize read_h command */
1792 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1793 p_buf-> read_h.cda =
1794 (__u32)__pa(&(p_buf->header));
1795 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1796 p_buf-> read_h.count = sizeof(struct clawh);
1797
1798 /* initialize Signal command */
1799 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1800 p_buf-> signal.cda =
1801 (__u32)__pa(&(pClawH->flag));
1802 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1803 p_buf-> signal.count = 1;
1804
1805 /* initialize r_TIC_1 command */
1806 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1807 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1808 p_buf-> r_TIC_1.flags = 0;
1809 p_buf-> r_TIC_1.count = 0;
1810
1811 /* initialize r_read_FF command */
1812 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1813 p_buf-> r_read_FF.cda =
1814 (__u32)__pa(&(pClawH->flag));
1815 p_buf-> r_read_FF.flags =
1816 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1817 p_buf-> r_read_FF.count = 1;
1818
1819 /* initialize r_TIC_2 */
1820 memcpy(&p_buf->r_TIC_2,
1821 &p_buf->r_TIC_1, sizeof(struct ccw1));
1822
1823 /* initialize Header */
1824 p_buf->header.length=0xffff;
1825 p_buf->header.opcode=0xff;
1826 p_buf->header.flag=CLAW_PENDING;
1827
Andy Richter4811fcb2009-01-20 06:14:33 +00001828 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1829 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1830 -1)
1831 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 p_buff= p_buff+privptr->p_env->read_size;
1833 }
1834 else {
1835 p_buff=
1836 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001837 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 & PAGE_MASK) ;
1839 }
1840 } /* for read_buffers */
1841 } /* read_size < PAGE_SIZE */
1842 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1844 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001845 (int)pages_to_order_of_mag(
1846 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001849 (int)pages_to_order_of_mag(privptr->
1850 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 /* free the write pages */
1852 p_buf=privptr->p_buff_write;
1853 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001854 free_pages(
1855 (unsigned long)p_buf->p_buffer,
1856 (int)pages_to_order_of_mag(
1857 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 p_buf=p_buf->next;
1859 }
1860 /* free any read pages already alloc */
1861 p_buf=privptr->p_buff_read;
1862 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001863 free_pages(
1864 (unsigned long)p_buf->p_buffer,
1865 (int)pages_to_order_of_mag(
1866 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 p_buf=p_buf->next;
1868 }
1869 privptr->p_buff_ccw=NULL;
1870 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 return -ENOMEM;
1872 }
1873 memset(p_buff, 0x00, privptr->p_env->read_size);
1874 p_buf = p_free_chain;
1875 privptr->p_buff_read = p_buf;
1876 p_free_chain = p_buf->next;
1877
1878 if (p_last_CCWB==NULL) {
1879 p_buf->next=NULL;
1880 real_TIC_address=0;
1881 p_last_CCWB=p_buf;
1882 }
1883 else {
1884 p_buf->next=p_first_CCWB;
1885 real_TIC_address=
1886 (addr_t)__pa(
1887 &p_first_CCWB -> read );
1888 }
1889
1890 p_first_CCWB=p_buf;
1891 /* save buff address */
1892 p_buf->p_buffer=(struct clawbuf *)p_buff;
1893 /* initialize read command */
1894 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1895 p_buf-> read.cda = (__u32)__pa(p_buff);
1896 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1897 p_buf-> read.count = privptr->p_env->read_size;
1898
1899 /* initialize read_h command */
1900 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1901 p_buf-> read_h.cda =
1902 (__u32)__pa(&(p_buf->header));
1903 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1904 p_buf-> read_h.count = sizeof(struct clawh);
1905
1906 /* initialize Signal command */
1907 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1908 p_buf-> signal.cda =
1909 (__u32)__pa(&(pClawH->flag));
1910 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1911 p_buf-> signal.count = 1;
1912
1913 /* initialize r_TIC_1 command */
1914 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1915 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1916 p_buf-> r_TIC_1.flags = 0;
1917 p_buf-> r_TIC_1.count = 0;
1918
1919 /* initialize r_read_FF command */
1920 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1921 p_buf-> r_read_FF.cda =
1922 (__u32)__pa(&(pClawH->flag));
1923 p_buf-> r_read_FF.flags =
1924 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1925 p_buf-> r_read_FF.count = 1;
1926
1927 /* initialize r_TIC_2 */
1928 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1929 sizeof(struct ccw1));
1930
1931 /* initialize Header */
1932 p_buf->header.length=0xffff;
1933 p_buf->header.opcode=0xff;
1934 p_buf->header.flag=CLAW_PENDING;
1935
1936 } /* For read_buffers */
1937 } /* read_size >= PAGE_SIZE */
1938 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1940 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02001941
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 return 0;
1943} /* end of init_ccw_bk */
1944
1945/*-------------------------------------------------------------------*
1946* *
1947* probe_error *
1948* *
1949*--------------------------------------------------------------------*/
1950
1951static void
1952probe_error( struct ccwgroup_device *cgdev)
1953{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001954 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02001955
1956 CLAW_DBF_TEXT(4, trace, "proberr");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001957 privptr = dev_get_drvdata(&cgdev->dev);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001958 if (privptr != NULL) {
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001959 dev_set_drvdata(&cgdev->dev, NULL);
Jesper Juhl17fd6822005-11-07 01:01:30 -08001960 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001961 kfree(privptr->p_mtc_envelope);
1962 kfree(privptr);
1963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964} /* probe_error */
1965
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966/*-------------------------------------------------------------------*
1967* claw_process_control *
1968* *
1969* *
1970*--------------------------------------------------------------------*/
1971
1972static int
1973claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
1974{
1975
1976 struct clawbuf *p_buf;
1977 struct clawctl ctlbk;
1978 struct clawctl *p_ctlbk;
1979 char temp_host_name[8];
1980 char temp_ws_name[8];
1981 struct claw_privbk *privptr;
1982 struct claw_env *p_env;
1983 struct sysval *p_sysval;
1984 struct conncmd *p_connect=NULL;
1985 int rc;
1986 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02001987 struct device *tdev;
1988 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 udelay(1000); /* Wait a ms for the control packets to
1990 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02001991 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 p_env=privptr->p_env;
Heiko Carstens319cb0832010-08-12 01:58:27 +00001993 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 memcpy( &temp_host_name, p_env->host_name, 8);
1995 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00001996 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 "Received Control Packet\n",
1998 dev->name, temp_ws_name);
1999 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 return 0;
2001 }
2002 p_buf=p_ccw->p_buffer;
2003 p_ctlbk=&ctlbk;
2004 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2005 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2006 } else {
2007 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 switch (p_ctlbk->command)
2010 {
Andy Richterb805da72008-07-18 15:24:56 +02002011 case SYSTEM_VALIDATE_REQUEST:
2012 if (p_ctlbk->version != CLAW_VERSION_ID) {
2013 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2014 CLAW_RC_WRONG_VERSION);
Andy Richter4811fcb2009-01-20 06:14:33 +00002015 dev_warn(tdev, "The communication peer of %s"
2016 " uses an incorrect API version %d\n",
2017 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002018 }
2019 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002020 dev_info(tdev, "%s: Recv Sys Validate Request: "
2021 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2022 "Host name=%.8s\n",
2023 dev->name, p_ctlbk->version,
2024 p_ctlbk->linkid,
2025 p_ctlbk->correlator,
2026 p_sysval->WS_name,
2027 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002028 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2029 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2030 CLAW_RC_NAME_MISMATCH);
2031 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2032 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2033 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002034 dev_warn(tdev,
2035 "Host name %s for %s does not match the"
2036 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002037 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002038 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002039 temp_host_name);
2040 }
2041 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2042 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2043 CLAW_RC_NAME_MISMATCH);
2044 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2045 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2046 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002047 dev_warn(tdev, "Adapter name %s for %s does not match"
2048 " the remote host name %s\n",
2049 p_sysval->WS_name,
2050 dev->name,
2051 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002052 }
2053 if ((p_sysval->write_frame_size < p_env->write_size) &&
2054 (p_env->packing == 0)) {
2055 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2056 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002057 dev_warn(tdev,
2058 "The local write buffer is smaller than the"
2059 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002060 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2061 }
2062 if ((p_sysval->read_frame_size < p_env->read_size) &&
2063 (p_env->packing == 0)) {
2064 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2065 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002066 dev_warn(tdev,
2067 "The local read buffer is smaller than the"
2068 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002069 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2070 }
2071 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002072 dev_info(tdev,
2073 "CLAW device %.8s: System validate"
2074 " completed.\n", temp_ws_name);
2075 dev_info(tdev,
2076 "%s: sys Validate Rsize:%d Wsize:%d\n",
2077 dev->name, p_sysval->read_frame_size,
2078 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002079 privptr->system_validate_comp = 1;
2080 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2081 p_env->packing = PACKING_ASK;
2082 claw_strt_conn_req(dev);
2083 break;
2084 case SYSTEM_VALIDATE_RESPONSE:
2085 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002086 dev_info(tdev,
2087 "Settings for %s validated (version=%d, "
2088 "remote device=%d, rc=%d, adapter name=%.8s, "
2089 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002090 dev->name,
2091 p_ctlbk->version,
2092 p_ctlbk->correlator,
2093 p_ctlbk->rc,
2094 p_sysval->WS_name,
2095 p_sysval->host_name);
2096 switch (p_ctlbk->rc) {
2097 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002098 dev_info(tdev, "%s: CLAW device "
2099 "%.8s: System validate completed.\n",
2100 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002101 if (privptr->system_validate_comp == 0)
2102 claw_strt_conn_req(dev);
2103 privptr->system_validate_comp = 1;
2104 break;
2105 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002106 dev_warn(tdev, "Validating %s failed because of"
2107 " a host or adapter name mismatch\n",
2108 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002109 break;
2110 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002111 dev_warn(tdev, "Validating %s failed because of a"
2112 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002113 dev->name);
2114 break;
2115 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002116 dev_warn(tdev, "Validating %s failed because of a"
2117 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002118 dev->name);
2119 break;
2120 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002121 dev_warn(tdev, "The communication peer of %s rejected"
2122 " the connection\n",
2123 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002124 break;
2125 }
2126 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
Andy Richterb805da72008-07-18 15:24:56 +02002128 case CONNECTION_REQUEST:
2129 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002130 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002131 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2132 dev->name,
2133 p_ctlbk->version,
2134 p_ctlbk->linkid,
2135 p_ctlbk->correlator,
2136 p_connect->host_name,
2137 p_connect->WS_name);
2138 if (privptr->active_link_ID != 0) {
2139 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002140 dev_info(tdev, "%s rejected a connection request"
2141 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002142 dev->name);
2143 }
2144 if (p_ctlbk->linkid != 1) {
2145 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002146 dev_info(tdev, "%s rejected a request to open multiple"
2147 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002148 dev->name);
2149 }
2150 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2151 if (rc != 0) {
2152 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002153 dev_info(tdev, "%s rejected a connection request"
2154 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002155 dev->name);
2156 }
2157 claw_send_control(dev,
2158 CONNECTION_CONFIRM, p_ctlbk->linkid,
2159 p_ctlbk->correlator,
2160 0, p_connect->host_name,
2161 p_connect->WS_name);
2162 if (p_env->packing == PACKING_ASK) {
2163 p_env->packing = PACK_SEND;
2164 claw_snd_conn_req(dev, 0);
2165 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002166 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002167 "completed link_id=%d.\n",
2168 dev->name, temp_ws_name,
2169 p_ctlbk->linkid);
2170 privptr->active_link_ID = p_ctlbk->linkid;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002171 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002172 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2173 break;
2174 case CONNECTION_RESPONSE:
2175 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002176 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002177 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2178 dev->name,
2179 p_ctlbk->version,
2180 p_ctlbk->linkid,
2181 p_ctlbk->correlator,
2182 p_ctlbk->rc,
2183 p_connect->host_name,
2184 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Andy Richterb805da72008-07-18 15:24:56 +02002186 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002187 dev_warn(tdev, "The communication peer of %s rejected"
2188 " a connection request\n",
2189 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002190 return 1;
2191 }
2192 rc = find_link(dev,
2193 p_connect->host_name, p_connect->WS_name);
2194 if (rc != 0) {
2195 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002196 dev_warn(tdev, "The communication peer of %s"
2197 " rejected a connection "
2198 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002199 dev->name);
2200 }
2201 /* should be until CONNECTION_CONFIRM */
2202 privptr->active_link_ID = -(p_ctlbk->linkid);
2203 break;
2204 case CONNECTION_CONFIRM:
2205 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002206 dev_info(tdev,
2207 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002208 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2209 dev->name,
2210 p_ctlbk->version,
2211 p_ctlbk->linkid,
2212 p_ctlbk->correlator,
2213 p_connect->host_name,
2214 p_connect->WS_name);
2215 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2216 privptr->active_link_ID = p_ctlbk->linkid;
2217 if (p_env->packing > PACKING_ASK) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002218 dev_info(tdev,
2219 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 p_env->packing = DO_PACKED;
2221 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002222 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002223 wake_up(&p_ch->wait);
2224 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002225 dev_warn(tdev, "Activating %s failed because of"
2226 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002227 dev->name, p_ctlbk->linkid);
2228 claw_snd_disc(dev, p_ctlbk);
2229 }
2230 break;
2231 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002232 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002233 "Vers=%d,link_id=%d,Corr=%d\n",
2234 dev->name, p_ctlbk->version,
2235 p_ctlbk->linkid, p_ctlbk->correlator);
2236 if ((p_ctlbk->linkid == 2) &&
2237 (p_env->packing == PACK_SEND)) {
2238 privptr->active_link_ID = 1;
2239 p_env->packing = DO_PACKED;
2240 } else
2241 privptr->active_link_ID = 0;
2242 break;
2243 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002244 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002245 dev->name);
2246 break;
2247 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002248 dev_warn(tdev, "The communication peer of %s sent"
2249 " an unknown command code\n",
2250 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002251 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 }
2253
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 return 0;
2255} /* end of claw_process_control */
2256
2257
2258/*-------------------------------------------------------------------*
2259* claw_send_control *
2260* *
2261*--------------------------------------------------------------------*/
2262
2263static int
2264claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2265 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2266{
2267 struct claw_privbk *privptr;
2268 struct clawctl *p_ctl;
2269 struct sysval *p_sysval;
2270 struct conncmd *p_connect;
2271 struct sk_buff *skb;
2272
Andy Richterb805da72008-07-18 15:24:56 +02002273 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002274 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2276
2277 p_ctl->command=type;
2278 p_ctl->version=CLAW_VERSION_ID;
2279 p_ctl->linkid=link;
2280 p_ctl->correlator=correlator;
2281 p_ctl->rc=rc;
2282
2283 p_sysval=(struct sysval *)&p_ctl->data;
2284 p_connect=(struct conncmd *)&p_ctl->data;
2285
2286 switch (p_ctl->command) {
2287 case SYSTEM_VALIDATE_REQUEST:
2288 case SYSTEM_VALIDATE_RESPONSE:
2289 memcpy(&p_sysval->host_name, local_name, 8);
2290 memcpy(&p_sysval->WS_name, remote_name, 8);
2291 if (privptr->p_env->packing > 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002292 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2293 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002295 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002296 p_sysval->read_frame_size =
2297 privptr->p_env->read_size;
2298 p_sysval->write_frame_size =
2299 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 }
2301 memset(&p_sysval->reserved, 0x00, 4);
2302 break;
2303 case CONNECTION_REQUEST:
2304 case CONNECTION_RESPONSE:
2305 case CONNECTION_CONFIRM:
2306 case DISCONNECT:
2307 memcpy(&p_sysval->host_name, local_name, 8);
2308 memcpy(&p_sysval->WS_name, remote_name, 8);
2309 if (privptr->p_env->packing > 0) {
2310 /* How big is the biggest packet */
2311 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2312 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2313 } else {
2314 memset(&p_connect->reserved1, 0x00, 4);
2315 memset(&p_connect->reserved2, 0x00, 4);
2316 }
2317 break;
2318 default:
2319 break;
2320 }
2321
2322 /* write Control Record to the device */
2323
2324
2325 skb = dev_alloc_skb(sizeof(struct clawctl));
2326 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 return -ENOMEM;
2328 }
2329 memcpy(skb_put(skb, sizeof(struct clawctl)),
2330 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 if (privptr->p_env->packing >= PACK_SEND)
2332 claw_hw_tx(skb, dev, 1);
2333 else
2334 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 return 0;
2336} /* end of claw_send_control */
2337
2338/*-------------------------------------------------------------------*
2339* claw_snd_conn_req *
2340* *
2341*--------------------------------------------------------------------*/
2342static int
2343claw_snd_conn_req(struct net_device *dev, __u8 link)
2344{
2345 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002346 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 struct clawctl *p_ctl;
2348
Andy Richterb805da72008-07-18 15:24:56 +02002349 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 rc = 1;
2351 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2352 p_ctl->linkid = link;
2353 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 return rc;
2355 }
2356 if (privptr->p_env->packing == PACKING_ASK )
2357 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2358 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2359 if (privptr->p_env->packing == PACK_SEND) {
2360 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2361 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2362 }
2363 if (privptr->p_env->packing == 0)
2364 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2365 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 return rc;
2367
2368} /* end of claw_snd_conn_req */
2369
2370
2371/*-------------------------------------------------------------------*
2372* claw_snd_disc *
2373* *
2374*--------------------------------------------------------------------*/
2375
2376static int
2377claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2378{
2379 int rc;
2380 struct conncmd * p_connect;
2381
Andy Richterb805da72008-07-18 15:24:56 +02002382 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 p_connect=(struct conncmd *)&p_ctl->data;
2384
2385 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2386 p_ctl->correlator, 0,
2387 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 return rc;
2389} /* end of claw_snd_disc */
2390
2391
2392/*-------------------------------------------------------------------*
2393* claw_snd_sys_validate_rsp *
2394* *
2395*--------------------------------------------------------------------*/
2396
2397static int
2398claw_snd_sys_validate_rsp(struct net_device *dev,
2399 struct clawctl *p_ctl, __u32 return_code)
2400{
2401 struct claw_env * p_env;
2402 struct claw_privbk *privptr;
2403 int rc;
2404
Andy Richterb805da72008-07-18 15:24:56 +02002405 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002406 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 p_env=privptr->p_env;
2408 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2409 p_ctl->linkid,
2410 p_ctl->correlator,
2411 return_code,
2412 p_env->host_name,
2413 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 return rc;
2415} /* end of claw_snd_sys_validate_rsp */
2416
2417/*-------------------------------------------------------------------*
2418* claw_strt_conn_req *
2419* *
2420*--------------------------------------------------------------------*/
2421
2422static int
2423claw_strt_conn_req(struct net_device *dev )
2424{
2425 int rc;
2426
Andy Richterb805da72008-07-18 15:24:56 +02002427 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 return rc;
2430} /* end of claw_strt_conn_req */
2431
2432
2433
2434/*-------------------------------------------------------------------*
2435 * claw_stats *
2436 *-------------------------------------------------------------------*/
2437
2438static struct
2439net_device_stats *claw_stats(struct net_device *dev)
2440{
2441 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002442
2443 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002444 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 return &privptr->stats;
2446} /* end of claw_stats */
2447
2448
2449/*-------------------------------------------------------------------*
2450* unpack_read *
2451* *
2452*--------------------------------------------------------------------*/
2453static void
2454unpack_read(struct net_device *dev )
2455{
2456 struct sk_buff *skb;
2457 struct claw_privbk *privptr;
2458 struct claw_env *p_env;
2459 struct ccwbk *p_this_ccw;
2460 struct ccwbk *p_first_ccw;
2461 struct ccwbk *p_last_ccw;
2462 struct clawph *p_packh;
2463 void *p_packd;
2464 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002465 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
2467 __u32 len_of_data;
2468 __u32 pack_off;
2469 __u8 link_num;
2470 __u8 mtc_this_frm=0;
2471 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 int i=0;
2473 int p=0;
2474
Andy Richterb805da72008-07-18 15:24:56 +02002475 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 p_first_ccw=NULL;
2477 p_last_ccw=NULL;
2478 p_packh=NULL;
2479 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002480 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002481
Heiko Carstens319cb0832010-08-12 01:58:27 +00002482 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 p_env = privptr->p_env;
2484 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 pack_off = 0;
2487 p = 0;
2488 p_this_ccw->header.flag=CLAW_PENDING;
2489 privptr->p_read_active_first=p_this_ccw->next;
2490 p_this_ccw->next=NULL;
2491 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2492 if ((p_env->packing == PACK_SEND) &&
2493 (p_packh->len == 32) &&
2494 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2495 p_packh++; /* peek past pack header */
2496 p_ctlrec = (struct clawctl *)p_packh;
2497 p_packh--; /* un peek */
2498 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2499 (p_ctlrec->command == CONNECTION_CONFIRM))
2500 p_env->packing = DO_PACKED;
2501 }
2502 if (p_env->packing == DO_PACKED)
2503 link_num=p_packh->link_num;
2504 else
2505 link_num=p_this_ccw->header.opcode / 8;
2506 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 mtc_this_frm=1;
2508 if (p_this_ccw->header.length!=
2509 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002510 dev_warn(p_dev,
2511 "The communication peer of %s"
2512 " sent a faulty"
2513 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 dev->name, p_this_ccw->header.length);
2515 }
2516 }
2517
2518 if (privptr->mtc_skipping) {
2519 /*
2520 * We're in the mode of skipping past a
2521 * multi-frame message
2522 * that we can't process for some reason or other.
2523 * The first frame without the More-To-Come flag is
2524 * the last frame of the skipped message.
2525 */
2526 /* in case of More-To-Come not set in this frame */
2527 if (mtc_this_frm==0) {
2528 privptr->mtc_skipping=0; /* Ok, the end */
2529 privptr->mtc_logical_link=-1;
2530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 goto NextFrame;
2532 }
2533
2534 if (link_num==0) {
2535 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002536 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 goto NextFrame;
2538 }
2539unpack_next:
2540 if (p_env->packing == DO_PACKED) {
2541 if (pack_off > p_env->read_size)
2542 goto NextFrame;
2543 p_packd = p_this_ccw->p_buffer+pack_off;
2544 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002545 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 (p_packh->flag != 0))
2547 goto NextFrame;
2548 bytes_to_mov = p_packh->len;
2549 pack_off += bytes_to_mov+sizeof(struct clawph);
2550 p++;
2551 } else {
2552 bytes_to_mov=p_this_ccw->header.length;
2553 }
2554 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
2556 /*
2557 * if More-To-Come is set in this frame then we don't know
2558 * length of entire message, and hence have to allocate
2559 * large buffer */
2560
2561 /* We are starting a new envelope */
2562 privptr->mtc_offset=0;
2563 privptr->mtc_logical_link=link_num;
2564 }
2565
2566 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2567 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 privptr->stats.rx_frame_errors++;
2569 goto NextFrame;
2570 }
2571 if (p_env->packing == DO_PACKED) {
2572 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2573 p_packd+sizeof(struct clawph), bytes_to_mov);
2574
2575 } else {
2576 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2577 p_this_ccw->p_buffer, bytes_to_mov);
2578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 if (mtc_this_frm==0) {
2580 len_of_data=privptr->mtc_offset+bytes_to_mov;
2581 skb=dev_alloc_skb(len_of_data);
2582 if (skb) {
2583 memcpy(skb_put(skb,len_of_data),
2584 privptr->p_mtc_envelope,
2585 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002587 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 skb->protocol=htons(ETH_P_IP);
2589 skb->ip_summed=CHECKSUM_UNNECESSARY;
2590 privptr->stats.rx_packets++;
2591 privptr->stats.rx_bytes+=len_of_data;
2592 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 }
2594 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002595 dev_info(p_dev, "Allocating a buffer for"
2596 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 }
2599 privptr->mtc_offset=0;
2600 privptr->mtc_logical_link=-1;
2601 }
2602 else {
2603 privptr->mtc_offset+=bytes_to_mov;
2604 }
2605 if (p_env->packing == DO_PACKED)
2606 goto unpack_next;
2607NextFrame:
2608 /*
2609 * Remove ThisCCWblock from active read queue, and add it
2610 * to queue of free blocks to be reused.
2611 */
2612 i++;
2613 p_this_ccw->header.length=0xffff;
2614 p_this_ccw->header.opcode=0xff;
2615 /*
2616 * add this one to the free queue for later reuse
2617 */
2618 if (p_first_ccw==NULL) {
2619 p_first_ccw = p_this_ccw;
2620 }
2621 else {
2622 p_last_ccw->next = p_this_ccw;
2623 }
2624 p_last_ccw = p_this_ccw;
2625 /*
2626 * chain to next block on active read queue
2627 */
2628 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002629 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 } /* end of while */
2631
2632 /* check validity */
2633
Andy Richterb805da72008-07-18 15:24:56 +02002634 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 return;
2638} /* end of unpack_read */
2639
2640/*-------------------------------------------------------------------*
2641* claw_strt_read *
2642* *
2643*--------------------------------------------------------------------*/
2644static void
2645claw_strt_read (struct net_device *dev, int lock )
2646{
2647 int rc = 0;
2648 __u32 parm;
2649 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002650 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct ccwbk*p_ccwbk;
2652 struct chbk *p_ch;
2653 struct clawh *p_clawh;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002654 p_ch = &privptr->channel[READ_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Andy Richterb805da72008-07-18 15:24:56 +02002656 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2658 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2659
2660 if ((privptr->p_write_active_first!=NULL &&
2661 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2662 (privptr->p_read_active_first!=NULL &&
2663 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2664 p_clawh->flag=CLAW_BUSY; /* 0xff */
2665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 if (lock==LOCK_YES) {
2667 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2668 }
2669 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002670 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 p_ccwbk=privptr->p_read_active_first;
2672 parm = (unsigned long) p_ch;
2673 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2674 0xff, 0);
2675 if (rc != 0) {
2676 ccw_check_return_code(p_ch->cdev, rc);
2677 }
2678 }
2679 else {
Andy Richterb805da72008-07-18 15:24:56 +02002680 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 }
2682
2683 if (lock==LOCK_YES) {
2684 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2685 }
Andy Richterb805da72008-07-18 15:24:56 +02002686 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 return;
2688} /* end of claw_strt_read */
2689
2690/*-------------------------------------------------------------------*
2691* claw_strt_out_IO *
2692* *
2693*--------------------------------------------------------------------*/
2694
2695static void
2696claw_strt_out_IO( struct net_device *dev )
2697{
2698 int rc = 0;
2699 unsigned long parm;
2700 struct claw_privbk *privptr;
2701 struct chbk *p_ch;
2702 struct ccwbk *p_first_ccw;
2703
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 if (!dev) {
2705 return;
2706 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002707 privptr = (struct claw_privbk *)dev->ml_priv;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002708 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
Andy Richterb805da72008-07-18 15:24:56 +02002710 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 p_first_ccw=privptr->p_write_active_first;
2712
2713 if (p_ch->claw_state == CLAW_STOP)
2714 return;
2715 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 return;
2717 }
2718 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2719 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002720 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002721 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2722 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 if (rc != 0) {
2724 ccw_check_return_code(p_ch->cdev, rc);
2725 }
2726 }
2727 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 return;
2729} /* end of claw_strt_out_IO */
2730
2731/*-------------------------------------------------------------------*
2732* Free write buffers *
2733* *
2734*--------------------------------------------------------------------*/
2735
2736static void
2737claw_free_wrt_buf( struct net_device *dev )
2738{
2739
Peter Tiedemann6951df32008-08-21 17:10:23 +02002740 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 struct ccwbk*p_this_ccw;
2742 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002743
2744 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 /* scan the write queue to free any completed write packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 p_this_ccw=privptr->p_write_active_first;
2747 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2748 {
2749 p_next_ccw = p_this_ccw->next;
2750 if (((p_next_ccw!=NULL) &&
2751 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2752 ((p_this_ccw == privptr->p_write_active_last) &&
2753 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2754 /* The next CCW is OK or this is */
2755 /* the last CCW...free it @A1A */
2756 privptr->p_write_active_first=p_this_ccw->next;
2757 p_this_ccw->header.flag=CLAW_PENDING;
2758 p_this_ccw->next=privptr->p_write_free_chain;
2759 privptr->p_write_free_chain=p_this_ccw;
2760 ++privptr->write_free_count;
2761 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2762 p_this_ccw=privptr->p_write_active_first;
2763 privptr->stats.tx_packets++;
2764 }
2765 else {
2766 break;
2767 }
2768 }
2769 if (privptr->write_free_count!=0) {
2770 claw_clearbit_busy(TB_NOBUFFER,dev);
2771 }
2772 /* whole chain removed? */
2773 if (privptr->p_write_active_first==NULL) {
2774 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 }
Andy Richterb805da72008-07-18 15:24:56 +02002776 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 return;
2778}
2779
2780/*-------------------------------------------------------------------*
2781* claw free netdevice *
2782* *
2783*--------------------------------------------------------------------*/
2784static void
2785claw_free_netdevice(struct net_device * dev, int free_dev)
2786{
2787 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788
Andy Richterb805da72008-07-18 15:24:56 +02002789 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 if (!dev)
2791 return;
Andy Richterb805da72008-07-18 15:24:56 +02002792 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002793 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 if (dev->flags & IFF_RUNNING)
2795 claw_release(dev);
2796 if (privptr) {
Heiko Carstens319cb0832010-08-12 01:58:27 +00002797 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002799 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800#ifdef MODULE
2801 if (free_dev) {
2802 free_netdev(dev);
2803 }
2804#endif
Andy Richterb805da72008-07-18 15:24:56 +02002805 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806}
2807
2808/**
2809 * Claw init netdevice
2810 * Initialize everything of the net device except the name and the
2811 * channel structs.
2812 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002813static const struct net_device_ops claw_netdev_ops = {
2814 .ndo_open = claw_open,
2815 .ndo_stop = claw_release,
2816 .ndo_get_stats = claw_stats,
2817 .ndo_start_xmit = claw_tx,
2818 .ndo_change_mtu = claw_change_mtu,
2819};
2820
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821static void
2822claw_init_netdevice(struct net_device * dev)
2823{
Andy Richterb805da72008-07-18 15:24:56 +02002824 CLAW_DBF_TEXT(2, setup, "init_dev");
2825 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 dev->hard_header_len = 0;
2828 dev->addr_len = 0;
2829 dev->type = ARPHRD_SLIP;
2830 dev->tx_queue_len = 1300;
2831 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002832 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002833 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 return;
2835}
2836
2837/**
2838 * Init a new channel in the privptr->channel[i].
2839 *
2840 * @param cdev The ccw_device to be added.
2841 *
2842 * @return 0 on success, !0 on error.
2843 */
2844static int
2845add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2846{
2847 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002848 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
Kay Sievers2a0217d2008-10-10 21:33:09 +02002850 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2852 p_ch = &privptr->channel[i];
2853 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002854 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002855 ccw_device_get_id(cdev, &dev_id);
2856 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002857 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 return -ENOMEM;
2859 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 return 0;
2861}
2862
2863
2864/**
2865 *
2866 * Setup an interface.
2867 *
2868 * @param cgdev Device to be setup.
2869 *
2870 * @returns 0 on success, !0 on failure.
2871 */
2872static int
2873claw_new_device(struct ccwgroup_device *cgdev)
2874{
2875 struct claw_privbk *privptr;
2876 struct claw_env *p_env;
2877 struct net_device *dev;
2878 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002879 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880
Andy Richter4811fcb2009-01-20 06:14:33 +00002881 dev_info(&cgdev->dev, "add for %s\n",
Heiko Carstens319cb0832010-08-12 01:58:27 +00002882 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002883 CLAW_DBF_TEXT(2, setup, "new_dev");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002884 privptr = dev_get_drvdata(&cgdev->dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +00002885 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2886 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 if (!privptr)
2888 return -ENODEV;
2889 p_env = privptr->p_env;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002890 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2891 p_env->devno[READ_CHANNEL] = dev_id.devno;
2892 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2893 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 ret = add_channel(cgdev->cdev[0],0,privptr);
2895 if (ret == 0)
2896 ret = add_channel(cgdev->cdev[1],1,privptr);
2897 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002898 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2899 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002900 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002902 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002904 dev_warn(&cgdev->dev,
2905 "Setting the read subchannel online"
2906 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 goto out;
2908 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002909 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002911 dev_warn(&cgdev->dev,
2912 "Setting the write subchannel online "
2913 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 goto out;
2915 }
Tom Gundersenc835a672014-07-14 16:37:24 +02002916 dev = alloc_netdev(0, "claw%d", NET_NAME_UNKNOWN, claw_init_netdevice);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002918 dev_warn(&cgdev->dev,
2919 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 goto out;
2921 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002922 dev->ml_priv = privptr;
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002923 dev_set_drvdata(&cgdev->dev, privptr);
Heiko Carstens319cb0832010-08-12 01:58:27 +00002924 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2925 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 /* sysfs magic */
2927 SET_NETDEV_DEV(dev, &cgdev->dev);
2928 if (register_netdev(dev) != 0) {
2929 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02002930 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 goto out;
2932 }
2933 dev->flags &=~IFF_RUNNING;
2934 if (privptr->buffs_alloc == 0) {
2935 ret=init_ccw_bk(dev);
2936 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 unregister_netdev(dev);
2938 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02002939 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 goto out;
2941 }
2942 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002943 privptr->channel[READ_CHANNEL].ndev = dev;
2944 privptr->channel[WRITE_CHANNEL].ndev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 privptr->p_env->ndev = dev;
2946
Andy Richter4811fcb2009-01-20 06:14:33 +00002947 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2949 dev->name, p_env->read_size,
2950 p_env->write_size, p_env->read_buffers,
Heiko Carstens319cb0832010-08-12 01:58:27 +00002951 p_env->write_buffers, p_env->devno[READ_CHANNEL],
2952 p_env->devno[WRITE_CHANNEL]);
Andy Richter4811fcb2009-01-20 06:14:33 +00002953 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 ":%.8s api_type: %.8s\n",
2955 dev->name, p_env->host_name,
2956 p_env->adapter_name , p_env->api_type);
2957 return 0;
2958out:
2959 ccw_device_set_offline(cgdev->cdev[1]);
2960 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 return -ENODEV;
2962}
2963
2964static void
2965claw_purge_skb_queue(struct sk_buff_head *q)
2966{
2967 struct sk_buff *skb;
2968
Andy Richterb805da72008-07-18 15:24:56 +02002969 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 while ((skb = skb_dequeue(q))) {
2971 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02002972 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 }
2974}
2975
2976/**
2977 * Shutdown an interface.
2978 *
2979 * @param cgdev Device to be shut down.
2980 *
2981 * @returns 0 on success, !0 on failure.
2982 */
2983static int
2984claw_shutdown_device(struct ccwgroup_device *cgdev)
2985{
2986 struct claw_privbk *priv;
2987 struct net_device *ndev;
Heiko Carstens38ed18f2011-05-12 18:45:04 +00002988 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02002990 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002991 priv = dev_get_drvdata(&cgdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 if (!priv)
2993 return -ENODEV;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002994 ndev = priv->channel[READ_CHANNEL].ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 if (ndev) {
2996 /* Close the device */
Heiko Carstens319cb0832010-08-12 01:58:27 +00002997 dev_info(&cgdev->dev, "%s: shutting down\n",
Andy Richter4811fcb2009-01-20 06:14:33 +00002998 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 if (ndev->flags & IFF_RUNNING)
3000 ret = claw_release(ndev);
3001 ndev->flags &=~IFF_RUNNING;
3002 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003003 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 claw_free_netdevice(ndev, 1);
Heiko Carstens319cb0832010-08-12 01:58:27 +00003005 priv->channel[READ_CHANNEL].ndev = NULL;
3006 priv->channel[WRITE_CHANNEL].ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 priv->p_env->ndev = NULL;
3008 }
3009 ccw_device_set_offline(cgdev->cdev[1]);
3010 ccw_device_set_offline(cgdev->cdev[0]);
Heiko Carstens38ed18f2011-05-12 18:45:04 +00003011 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012}
3013
3014static void
3015claw_remove_device(struct ccwgroup_device *cgdev)
3016{
3017 struct claw_privbk *priv;
3018
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003019 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003020 priv = dev_get_drvdata(&cgdev->dev);
Andy Richter4811fcb2009-01-20 06:14:33 +00003021 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 if (cgdev->state == CCWGROUP_ONLINE)
3023 claw_shutdown_device(cgdev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003024 kfree(priv->p_mtc_envelope);
3025 priv->p_mtc_envelope=NULL;
3026 kfree(priv->p_env);
3027 priv->p_env=NULL;
3028 kfree(priv->channel[0].irb);
3029 priv->channel[0].irb=NULL;
3030 kfree(priv->channel[1].irb);
3031 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 kfree(priv);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003033 dev_set_drvdata(&cgdev->dev, NULL);
Heiko Carstens319cb0832010-08-12 01:58:27 +00003034 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3035 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003037
3038 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039}
3040
3041
3042/*
3043 * sysfs attributes
3044 */
3045static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003046claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047{
3048 struct claw_privbk *priv;
3049 struct claw_env * p_env;
3050
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003051 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 if (!priv)
3053 return -ENODEV;
3054 p_env = priv->p_env;
3055 return sprintf(buf, "%s\n",p_env->host_name);
3056}
3057
3058static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003059claw_hname_write(struct device *dev, struct device_attribute *attr,
3060 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061{
3062 struct claw_privbk *priv;
3063 struct claw_env * p_env;
3064
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003065 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 if (!priv)
3067 return -ENODEV;
3068 p_env = priv->p_env;
3069 if (count > MAX_NAME_LEN+1)
3070 return -EINVAL;
3071 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3072 strncpy(p_env->host_name,buf, count);
3073 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3074 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003075 CLAW_DBF_TEXT(2, setup, "HstnSet");
3076 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
3078 return count;
3079}
3080
3081static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3082
3083static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003084claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085{
3086 struct claw_privbk *priv;
3087 struct claw_env * p_env;
3088
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003089 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 if (!priv)
3091 return -ENODEV;
3092 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003093 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094}
3095
3096static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003097claw_adname_write(struct device *dev, struct device_attribute *attr,
3098 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099{
3100 struct claw_privbk *priv;
3101 struct claw_env * p_env;
3102
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003103 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 if (!priv)
3105 return -ENODEV;
3106 p_env = priv->p_env;
3107 if (count > MAX_NAME_LEN+1)
3108 return -EINVAL;
3109 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3110 strncpy(p_env->adapter_name,buf, count);
3111 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3112 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003113 CLAW_DBF_TEXT(2, setup, "AdnSet");
3114 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
3116 return count;
3117}
3118
3119static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3120
3121static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003122claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123{
3124 struct claw_privbk *priv;
3125 struct claw_env * p_env;
3126
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003127 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 if (!priv)
3129 return -ENODEV;
3130 p_env = priv->p_env;
3131 return sprintf(buf, "%s\n",
3132 p_env->api_type);
3133}
3134
3135static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003136claw_apname_write(struct device *dev, struct device_attribute *attr,
3137 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138{
3139 struct claw_privbk *priv;
3140 struct claw_env * p_env;
3141
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003142 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 if (!priv)
3144 return -ENODEV;
3145 p_env = priv->p_env;
3146 if (count > MAX_NAME_LEN+1)
3147 return -EINVAL;
3148 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3149 strncpy(p_env->api_type,buf, count);
3150 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3151 p_env->api_type[MAX_NAME_LEN] = 0x00;
3152 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3153 p_env->read_size=DEF_PACK_BUFSIZE;
3154 p_env->write_size=DEF_PACK_BUFSIZE;
3155 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003156 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 }
3158 else {
3159 p_env->packing=0;
3160 p_env->read_size=CLAW_FRAME_SIZE;
3161 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003162 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 }
Andy Richterb805da72008-07-18 15:24:56 +02003164 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 return count;
3166}
3167
3168static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3169
3170static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003171claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172{
3173 struct claw_privbk *priv;
3174 struct claw_env * p_env;
3175
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003176 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 if (!priv)
3178 return -ENODEV;
3179 p_env = priv->p_env;
3180 return sprintf(buf, "%d\n", p_env->write_buffers);
3181}
3182
3183static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003184claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3185 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186{
3187 struct claw_privbk *priv;
3188 struct claw_env * p_env;
3189 int nnn,max;
3190
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003191 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 if (!priv)
3193 return -ENODEV;
3194 p_env = priv->p_env;
3195 sscanf(buf, "%i", &nnn);
3196 if (p_env->packing) {
3197 max = 64;
3198 }
3199 else {
3200 max = 512;
3201 }
3202 if ((nnn > max ) || (nnn < 2))
3203 return -EINVAL;
3204 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003205 CLAW_DBF_TEXT(2, setup, "Wbufset");
3206 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 return count;
3208}
3209
3210static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3211
3212static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003213claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214{
3215 struct claw_privbk *priv;
3216 struct claw_env * p_env;
3217
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003218 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 if (!priv)
3220 return -ENODEV;
3221 p_env = priv->p_env;
3222 return sprintf(buf, "%d\n", p_env->read_buffers);
3223}
3224
3225static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003226claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3227 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228{
3229 struct claw_privbk *priv;
3230 struct claw_env *p_env;
3231 int nnn,max;
3232
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003233 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 if (!priv)
3235 return -ENODEV;
3236 p_env = priv->p_env;
3237 sscanf(buf, "%i", &nnn);
3238 if (p_env->packing) {
3239 max = 64;
3240 }
3241 else {
3242 max = 512;
3243 }
3244 if ((nnn > max ) || (nnn < 2))
3245 return -EINVAL;
3246 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003247 CLAW_DBF_TEXT(2, setup, "Rbufset");
3248 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 return count;
3250}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3252
3253static struct attribute *claw_attr[] = {
3254 &dev_attr_read_buffer.attr,
3255 &dev_attr_write_buffer.attr,
3256 &dev_attr_adapter_name.attr,
3257 &dev_attr_api_type.attr,
3258 &dev_attr_host_name.attr,
3259 NULL,
3260};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261static struct attribute_group claw_attr_group = {
3262 .attrs = claw_attr,
3263};
Sebastian Ott2ced5512012-05-15 18:00:49 +02003264static const struct attribute_group *claw_attr_groups[] = {
3265 &claw_attr_group,
3266 NULL,
3267};
3268static const struct device_type claw_devtype = {
3269 .name = "claw",
3270 .groups = claw_attr_groups,
3271};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272
Sebastian Ott2ced5512012-05-15 18:00:49 +02003273/*----------------------------------------------------------------*
3274 * claw_probe *
3275 * this function is called for each CLAW device. *
3276 *----------------------------------------------------------------*/
3277static int claw_probe(struct ccwgroup_device *cgdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278{
Sebastian Ott2ced5512012-05-15 18:00:49 +02003279 struct claw_privbk *privptr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280
Sebastian Ott2ced5512012-05-15 18:00:49 +02003281 CLAW_DBF_TEXT(2, setup, "probe");
3282 if (!get_device(&cgdev->dev))
3283 return -ENODEV;
3284 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
3285 dev_set_drvdata(&cgdev->dev, privptr);
3286 if (privptr == NULL) {
3287 probe_error(cgdev);
3288 put_device(&cgdev->dev);
3289 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3290 return -ENOMEM;
3291 }
3292 privptr->p_mtc_envelope = kzalloc(MAX_ENVELOPE_SIZE, GFP_KERNEL);
3293 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
3294 if ((privptr->p_mtc_envelope == NULL) || (privptr->p_env == NULL)) {
3295 probe_error(cgdev);
3296 put_device(&cgdev->dev);
3297 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3298 return -ENOMEM;
3299 }
3300 memcpy(privptr->p_env->adapter_name, WS_NAME_NOT_DEF, 8);
3301 memcpy(privptr->p_env->host_name, WS_NAME_NOT_DEF, 8);
3302 memcpy(privptr->p_env->api_type, WS_NAME_NOT_DEF, 8);
3303 privptr->p_env->packing = 0;
3304 privptr->p_env->write_buffers = 5;
3305 privptr->p_env->read_buffers = 5;
3306 privptr->p_env->read_size = CLAW_FRAME_SIZE;
3307 privptr->p_env->write_size = CLAW_FRAME_SIZE;
3308 privptr->p_env->p_priv = privptr;
3309 cgdev->cdev[0]->handler = claw_irq_handler;
3310 cgdev->cdev[1]->handler = claw_irq_handler;
3311 cgdev->dev.type = &claw_devtype;
3312 CLAW_DBF_TEXT(2, setup, "prbext 0");
3313
3314 return 0;
3315} /* end of claw_probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
3317/*--------------------------------------------------------------------*
3318* claw_init and cleanup *
3319*---------------------------------------------------------------------*/
3320
Sebastian Otta43f8de2012-05-15 18:06:29 +02003321static void __exit claw_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003323 ccwgroup_driver_unregister(&claw_group_driver);
3324 ccw_driver_unregister(&claw_ccw_driver);
3325 root_device_unregister(claw_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003327 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328}
3329
3330/**
3331 * Initialize module.
3332 * This is called just after the module is loaded.
3333 *
3334 * @return 0 on success, !0 on error.
3335 */
Sebastian Otta43f8de2012-05-15 18:06:29 +02003336static int __init claw_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337{
3338 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
Andy Richter4811fcb2009-01-20 06:14:33 +00003340 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 ret = claw_register_debug_facility();
3342 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003343 pr_err("Registering with the S/390 debug feature"
3344 " failed with error code %d\n", ret);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003345 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 }
Andy Richterb805da72008-07-18 15:24:56 +02003347 CLAW_DBF_TEXT(2, setup, "init_mod");
Ursula Braund950d172010-01-04 03:14:45 +00003348 claw_root_dev = root_device_register("claw");
Frank Blaschka16dc2c42014-04-28 10:05:10 +02003349 ret = PTR_ERR_OR_ZERO(claw_root_dev);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003350 if (ret)
3351 goto register_err;
3352 ret = ccw_driver_register(&claw_ccw_driver);
3353 if (ret)
3354 goto ccw_err;
Sebastian Otta43f8de2012-05-15 18:06:29 +02003355 claw_group_driver.driver.groups = claw_drv_attr_groups;
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003356 ret = ccwgroup_driver_register(&claw_group_driver);
3357 if (ret)
3358 goto ccwgroup_err;
3359 return 0;
3360
3361ccwgroup_err:
3362 ccw_driver_unregister(&claw_ccw_driver);
3363ccw_err:
3364 root_device_unregister(claw_root_dev);
3365register_err:
3366 CLAW_DBF_TEXT(2, setup, "init_bad");
3367 claw_unregister_debug_facility();
3368out_err:
3369 pr_err("Initializing the claw device driver failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 return ret;
3371}
3372
3373module_init(claw_init);
3374module_exit(claw_cleanup);
3375
Andy Richterb805da72008-07-18 15:24:56 +02003376MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3377MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02003378 "Copyright IBM Corp. 2000, 2008\n");
Andy Richterb805da72008-07-18 15:24:56 +02003379MODULE_LICENSE("GPL");