blob: 6b1ff90d2f007b9d12cdc29e94ed929a064d1f52 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
4 *
Frank Pavlic8e84c802005-09-06 15:03:09 +02005 * Linux for zSeries version
Frank Blaschka88efc2c2009-06-16 10:30:33 +02006 * Copyright IBM Corp. 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Author(s) Original code written by:
Frank Blaschka88efc2c2009-06-16 10:30:33 +02008 * Kazuo Iimura <iimura@jp.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Rewritten by
Frank Blaschka88efc2c2009-06-16 10:30:33 +020010 * Andy Richter <richtera@us.ibm.com>
11 * Marc Price <mwprice@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
13 * sysfs parms:
14 * group x.x.rrrr,x.x.wwww
15 * read_buffer nnnnnnn
16 * write_buffer nnnnnn
17 * host_name aaaaaaaa
18 * adapter_name aaaaaaaa
19 * api_type aaaaaaaa
20 *
21 * eg.
22 * group 0.0.0200 0.0.0201
23 * read_buffer 25
24 * write_buffer 20
25 * host_name LINUX390
26 * adapter_name RS6K
27 * api_type TCPIP
28 *
29 * where
30 *
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
33 * up to CLAW_MAX_DEV
34 *
35 * rrrr - the first of 2 consecutive device addresses used for the
36 * CLAW protocol.
37 * The specified address is always used as the input (Read)
38 * channel and the next address is used as the output channel.
39 *
40 * wwww - the second of 2 consecutive device addresses used for
41 * the CLAW protocol.
42 * The specified address is always used as the output
43 * channel and the previous address is used as the input channel.
44 *
45 * read_buffer - specifies number of input buffers to allocate.
46 * write_buffer - specifies number of output buffers to allocate.
47 * host_name - host name
48 * adaptor_name - adaptor name
49 * api_type - API type TCPIP or API will be sent and expected
50 * as ws_name
51 *
52 * Note the following requirements:
53 * 1) host_name must match the configured adapter_name on the remote side
54 * 2) adaptor_name must match the configured host name on the remote side
55 *
56 * Change History
57 * 1.00 Initial release shipped
58 * 1.10 Changes for Buffer allocation
59 * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
60 * 1.25 Added Packing support
Andy Richterb805da72008-07-18 15:24:56 +020061 * 1.5
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 */
Andy Richter4811fcb2009-01-20 06:14:33 +000063
64#define KMSG_COMPONENT "claw"
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#include <asm/ccwdev.h>
67#include <asm/ccwgroup.h>
68#include <asm/debug.h>
69#include <asm/idals.h>
70#include <asm/io.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070071#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <linux/ctype.h>
73#include <linux/delay.h>
74#include <linux/errno.h>
75#include <linux/if_arp.h>
76#include <linux/init.h>
77#include <linux/interrupt.h>
78#include <linux/ip.h>
79#include <linux/kernel.h>
80#include <linux/module.h>
81#include <linux/netdevice.h>
82#include <linux/etherdevice.h>
83#include <linux/proc_fs.h>
84#include <linux/sched.h>
85#include <linux/signal.h>
86#include <linux/skbuff.h>
87#include <linux/slab.h>
88#include <linux/string.h>
89#include <linux/tcp.h>
90#include <linux/timer.h>
91#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#include "claw.h"
94
Andy Richterb805da72008-07-18 15:24:56 +020095/*
96 CLAW uses the s390dbf file system see claw_trace and claw_setup
Linus Torvalds1da177e2005-04-16 15:20:36 -070097*/
98
Andy Richter4811fcb2009-01-20 06:14:33 +000099static char version[] __initdata = "CLAW driver";
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100100static char debug_buffer[255];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/**
102 * Debug Facility Stuff
103 */
104static debug_info_t *claw_dbf_setup;
105static debug_info_t *claw_dbf_trace;
106
107/**
108 * CLAW Debug Facility functions
109 */
110static void
111claw_unregister_debug_facility(void)
112{
113 if (claw_dbf_setup)
114 debug_unregister(claw_dbf_setup);
115 if (claw_dbf_trace)
116 debug_unregister(claw_dbf_trace);
117}
118
119static int
120claw_register_debug_facility(void)
121{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700122 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
123 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 claw_unregister_debug_facility();
126 return -ENOMEM;
127 }
128 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
129 debug_set_level(claw_dbf_setup, 2);
130 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
131 debug_set_level(claw_dbf_trace, 2);
132 return 0;
133}
134
135static inline void
136claw_set_busy(struct net_device *dev)
137{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200138 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
141static inline void
142claw_clear_busy(struct net_device *dev)
143{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200144 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
148static inline int
149claw_check_busy(struct net_device *dev)
150{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200151 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
154static inline void
155claw_setbit_busy(int nr,struct net_device *dev)
156{
157 netif_stop_queue(dev);
Peter Tiedemann6951df32008-08-21 17:10:23 +0200158 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161static inline void
162claw_clearbit_busy(int nr,struct net_device *dev)
163{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200164 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 netif_wake_queue(dev);
166}
167
168static inline int
169claw_test_and_setbit_busy(int nr,struct net_device *dev)
170{
171 netif_stop_queue(dev);
172 return test_and_set_bit(nr,
Peter Tiedemann6951df32008-08-21 17:10:23 +0200173 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
176
177/* Functions for the DEV methods */
178
179static int claw_probe(struct ccwgroup_device *cgdev);
180static void claw_remove_device(struct ccwgroup_device *cgdev);
181static void claw_purge_skb_queue(struct sk_buff_head *q);
182static int claw_new_device(struct ccwgroup_device *cgdev);
183static int claw_shutdown_device(struct ccwgroup_device *cgdev);
184static int claw_tx(struct sk_buff *skb, struct net_device *dev);
185static int claw_change_mtu( struct net_device *dev, int new_mtu);
186static int claw_open(struct net_device *dev);
187static void claw_irq_handler(struct ccw_device *cdev,
188 unsigned long intparm, struct irb *irb);
189static void claw_irq_tasklet ( unsigned long data );
190static int claw_release(struct net_device *dev);
191static void claw_write_retry ( struct chbk * p_ch );
192static void claw_write_next ( struct chbk * p_ch );
193static void claw_timer ( struct chbk * p_ch );
194
195/* Functions */
196static int add_claw_reads(struct net_device *dev,
197 struct ccwbk* p_first, struct ccwbk* p_last);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100198static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
199static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200static int find_link(struct net_device *dev, char *host_name, char *ws_name );
201static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
202static int init_ccw_bk(struct net_device *dev);
203static void probe_error( struct ccwgroup_device *cgdev);
204static struct net_device_stats *claw_stats(struct net_device *dev);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100205static int pages_to_order_of_mag(int num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/* sysfs Functions */
Andy Richter4811fcb2009-01-20 06:14:33 +0000208static ssize_t claw_hname_show(struct device *dev,
209 struct device_attribute *attr, char *buf);
210static ssize_t claw_hname_write(struct device *dev,
211 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000213static ssize_t claw_adname_show(struct device *dev,
214 struct device_attribute *attr, char *buf);
215static ssize_t claw_adname_write(struct device *dev,
216 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000218static ssize_t claw_apname_show(struct device *dev,
219 struct device_attribute *attr, char *buf);
220static ssize_t claw_apname_write(struct device *dev,
221 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000223static ssize_t claw_wbuff_show(struct device *dev,
224 struct device_attribute *attr, char *buf);
225static ssize_t claw_wbuff_write(struct device *dev,
226 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000228static ssize_t claw_rbuff_show(struct device *dev,
229 struct device_attribute *attr, char *buf);
230static ssize_t claw_rbuff_write(struct device *dev,
231 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 const char *buf, size_t count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234/* Functions for System Validate */
235static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
236static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
237 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
238static int claw_snd_conn_req(struct net_device *dev, __u8 link);
239static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
240static int claw_snd_sys_validate_rsp(struct net_device *dev,
241 struct clawctl * p_ctl, __u32 return_code);
242static int claw_strt_conn_req(struct net_device *dev );
Andy Richterb805da72008-07-18 15:24:56 +0200243static void claw_strt_read(struct net_device *dev, int lock);
244static void claw_strt_out_IO(struct net_device *dev);
245static void claw_free_wrt_buf(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247/* Functions for unpack reads */
Andy Richterb805da72008-07-18 15:24:56 +0200248static void unpack_read(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200250static int claw_pm_prepare(struct ccwgroup_device *gdev)
251{
252 return -EPERM;
253}
254
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000255/* the root device for claw group devices */
256static struct device *claw_root_dev;
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/* ccwgroup table */
259
260static struct ccwgroup_driver claw_group_driver = {
Sebastian Ott3c190c52011-03-23 10:16:04 +0100261 .driver = {
262 .owner = THIS_MODULE,
263 .name = "claw",
264 },
Sebastian Ott2ced5512012-05-15 18:00:49 +0200265 .setup = claw_probe,
Sebastian Ott9814fdf2012-05-15 18:03:46 +0200266 .remove = claw_remove_device,
267 .set_online = claw_new_device,
268 .set_offline = claw_shutdown_device,
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200269 .prepare = claw_pm_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270};
271
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000272static struct ccw_device_id claw_ids[] = {
273 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
274 {},
275};
276MODULE_DEVICE_TABLE(ccw, claw_ids);
277
278static struct ccw_driver claw_ccw_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +0100279 .driver = {
280 .owner = THIS_MODULE,
281 .name = "claw",
282 },
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000283 .ids = claw_ids,
284 .probe = ccwgroup_probe_ccwdev,
285 .remove = ccwgroup_remove_ccwdev,
Peter Oberparleiterde400d62011-10-30 15:16:04 +0100286 .int_class = IOINT_CLW,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000287};
288
Sebastian Ott2ced5512012-05-15 18:00:49 +0200289static ssize_t claw_driver_group_store(struct device_driver *ddrv,
290 const char *buf, size_t count)
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000291{
292 int err;
Sebastian Ott9814fdf2012-05-15 18:03:46 +0200293 err = ccwgroup_create_dev(claw_root_dev, &claw_group_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000294 return err ? err : count;
295}
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000296static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
297
Sebastian Otta43f8de2012-05-15 18:06:29 +0200298static struct attribute *claw_drv_attrs[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000299 &driver_attr_group.attr,
300 NULL,
301};
Sebastian Otta43f8de2012-05-15 18:06:29 +0200302static struct attribute_group claw_drv_attr_group = {
303 .attrs = claw_drv_attrs,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000304};
Sebastian Otta43f8de2012-05-15 18:06:29 +0200305static const struct attribute_group *claw_drv_attr_groups[] = {
306 &claw_drv_attr_group,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000307 NULL,
308};
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311* Key functions
312*/
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314/*-------------------------------------------------------------------*
315 * claw_tx *
316 *-------------------------------------------------------------------*/
317
318static int
319claw_tx(struct sk_buff *skb, struct net_device *dev)
320{
321 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200322 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 unsigned long saveflags;
324 struct chbk *p_ch;
325
Andy Richterb805da72008-07-18 15:24:56 +0200326 CLAW_DBF_TEXT(4, trace, "claw_tx");
Heiko Carstens319cb0832010-08-12 01:58:27 +0000327 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
329 rc=claw_hw_tx( skb, dev, 1 );
330 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200331 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000332 if (rc)
333 rc = NETDEV_TX_BUSY;
Patrick McHardyec634fe2009-07-05 19:23:38 -0700334 else
335 rc = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return rc;
337} /* end of claw_tx */
338
339/*------------------------------------------------------------------*
340 * pack the collect queue into an skb and return it *
341 * If not packing just return the top skb from the queue *
342 *------------------------------------------------------------------*/
343
344static struct sk_buff *
345claw_pack_skb(struct claw_privbk *privptr)
346{
347 struct sk_buff *new_skb,*held_skb;
Heiko Carstens319cb0832010-08-12 01:58:27 +0000348 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 struct claw_env *p_env = privptr->p_env;
350 int pkt_cnt,pk_ind,so_far;
351
352 new_skb = NULL; /* assume no dice */
353 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200354 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700355 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 /* some data */
357 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200359 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 else
361 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200362 if (p_env->packing != DO_PACKED)
363 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 /* get a new SKB we will pack at least one */
365 new_skb = dev_alloc_skb(p_env->write_size);
366 if (new_skb == NULL) {
367 atomic_inc(&held_skb->users);
368 skb_queue_head(&p_ch->collect_queue,held_skb);
369 return NULL;
370 }
371 /* we have packed packet and a place to put it */
372 pk_ind = 1;
373 so_far = 0;
374 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
375 while ((pk_ind) && (held_skb != NULL)) {
376 if (held_skb->len+so_far <= p_env->write_size-8) {
377 memcpy(skb_put(new_skb,held_skb->len),
378 held_skb->data,held_skb->len);
379 privptr->stats.tx_packets++;
380 so_far += held_skb->len;
381 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200382 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 held_skb = skb_dequeue(&p_ch->collect_queue);
384 if (held_skb)
385 atomic_dec(&held_skb->users);
386 } else {
387 pk_ind = 0;
388 atomic_inc(&held_skb->users);
389 skb_queue_head(&p_ch->collect_queue,held_skb);
390 }
391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
Andy Richterb805da72008-07-18 15:24:56 +0200393 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return new_skb;
395}
396
397/*-------------------------------------------------------------------*
398 * claw_change_mtu *
399 * *
400 *-------------------------------------------------------------------*/
401
402static int
403claw_change_mtu(struct net_device *dev, int new_mtu)
404{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200405 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200407 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 buff_size = privptr->p_env->write_size;
409 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return -EINVAL;
411 }
412 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return 0;
414} /* end of claw_change_mtu */
415
416
417/*-------------------------------------------------------------------*
418 * claw_open *
419 * *
420 *-------------------------------------------------------------------*/
421static int
422claw_open(struct net_device *dev)
423{
424
425 int rc;
426 int i;
427 unsigned long saveflags=0;
428 unsigned long parm;
429 struct claw_privbk *privptr;
430 DECLARE_WAITQUEUE(wait, current);
431 struct timer_list timer;
432 struct ccwbk *p_buf;
433
Andy Richterb805da72008-07-18 15:24:56 +0200434 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200435 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 /* allocate and initialize CCW blocks */
437 if (privptr->buffs_alloc == 0) {
438 rc=init_ccw_bk(dev);
439 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200440 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 return -ENOMEM;
442 }
443 }
444 privptr->system_validate_comp=0;
445 privptr->release_pend=0;
446 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
447 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
448 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
449 privptr->p_env->packing=PACKING_ASK;
450 } else {
451 privptr->p_env->packing=0;
452 privptr->p_env->read_size=CLAW_FRAME_SIZE;
453 privptr->p_env->write_size=CLAW_FRAME_SIZE;
454 }
455 claw_set_busy(dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +0000456 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
457 (unsigned long) &privptr->channel[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200459 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 init_waitqueue_head(&privptr->channel[i].wait);
461 /* skb_queue_head_init(&p_ch->io_queue); */
Heiko Carstens319cb0832010-08-12 01:58:27 +0000462 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 skb_queue_head_init(
Heiko Carstens319cb0832010-08-12 01:58:27 +0000464 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 privptr->channel[i].flag_a = 0;
466 privptr->channel[i].IO_active = 0;
467 privptr->channel[i].flag &= ~CLAW_TIMER;
468 init_timer(&timer);
469 timer.function = (void *)claw_timer;
470 timer.data = (unsigned long)(&privptr->channel[i]);
471 timer.expires = jiffies + 15*HZ;
472 add_timer(&timer);
473 spin_lock_irqsave(get_ccwdev_lock(
474 privptr->channel[i].cdev), saveflags);
475 parm = (unsigned long) &privptr->channel[i];
476 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
477 rc = 0;
478 add_wait_queue(&privptr->channel[i].wait, &wait);
479 rc = ccw_device_halt(
480 (struct ccw_device *)privptr->channel[i].cdev,parm);
481 set_current_state(TASK_INTERRUPTIBLE);
482 spin_unlock_irqrestore(
483 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
484 schedule();
485 set_current_state(TASK_RUNNING);
486 remove_wait_queue(&privptr->channel[i].wait, &wait);
487 if(rc != 0)
488 ccw_check_return_code(privptr->channel[i].cdev, rc);
489 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
490 del_timer(&timer);
491 }
Heiko Carstens319cb0832010-08-12 01:58:27 +0000492 if ((((privptr->channel[READ_CHANNEL].last_dstat |
493 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
Heiko Carstens319cb0832010-08-12 01:58:27 +0000495 (((privptr->channel[READ_CHANNEL].flag |
496 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
497 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000498 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200499 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 for ( i = 0; i < 2; i++) {
502 spin_lock_irqsave(
503 get_ccwdev_lock(privptr->channel[i].cdev),
504 saveflags);
505 parm = (unsigned long) &privptr->channel[i];
506 privptr->channel[i].claw_state = CLAW_STOP;
507 rc = ccw_device_halt(
508 (struct ccw_device *)&privptr->channel[i].cdev,
509 parm);
510 spin_unlock_irqrestore(
511 get_ccwdev_lock(privptr->channel[i].cdev),
512 saveflags);
513 if (rc != 0) {
514 ccw_check_return_code(
515 privptr->channel[i].cdev, rc);
516 }
517 }
518 free_pages((unsigned long)privptr->p_buff_ccw,
519 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
520 if (privptr->p_env->read_size < PAGE_SIZE) {
521 free_pages((unsigned long)privptr->p_buff_read,
522 (int)pages_to_order_of_mag(
523 privptr->p_buff_read_num));
524 }
525 else {
526 p_buf=privptr->p_read_active_first;
527 while (p_buf!=NULL) {
528 free_pages((unsigned long)p_buf->p_buffer,
529 (int)pages_to_order_of_mag(
530 privptr->p_buff_pages_perread ));
531 p_buf=p_buf->next;
532 }
533 }
534 if (privptr->p_env->write_size < PAGE_SIZE ) {
535 free_pages((unsigned long)privptr->p_buff_write,
536 (int)pages_to_order_of_mag(
537 privptr->p_buff_write_num));
538 }
539 else {
540 p_buf=privptr->p_write_active_first;
541 while (p_buf!=NULL) {
542 free_pages((unsigned long)p_buf->p_buffer,
543 (int)pages_to_order_of_mag(
544 privptr->p_buff_pages_perwrite ));
545 p_buf=p_buf->next;
546 }
547 }
548 privptr->buffs_alloc = 0;
Heiko Carstens319cb0832010-08-12 01:58:27 +0000549 privptr->channel[READ_CHANNEL].flag = 0x00;
550 privptr->channel[WRITE_CHANNEL].flag = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 privptr->p_buff_ccw=NULL;
552 privptr->p_buff_read=NULL;
553 privptr->p_buff_write=NULL;
554 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200555 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 return -EIO;
557 }
558
559 /* Send SystemValidate command */
560
561 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200562 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 return 0;
564} /* end of claw_open */
565
566/*-------------------------------------------------------------------*
567* *
568* claw_irq_handler *
569* *
570*--------------------------------------------------------------------*/
571static void
572claw_irq_handler(struct ccw_device *cdev,
573 unsigned long intparm, struct irb *irb)
574{
575 struct chbk *p_ch = NULL;
576 struct claw_privbk *privptr = NULL;
577 struct net_device *dev = NULL;
578 struct claw_env *p_env;
579 struct chbk *p_ch_r=NULL;
580
Andy Richterb805da72008-07-18 15:24:56 +0200581 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 /* Bypass all 'unsolicited interrupts' */
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700583 privptr = dev_get_drvdata(&cdev->dev);
584 if (!privptr) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000585 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
586 " IRQ, c-%02x d-%02x\n",
587 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200588 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 return;
590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 /* Try to extract channel from driver data. */
Heiko Carstens319cb0832010-08-12 01:58:27 +0000593 if (privptr->channel[READ_CHANNEL].cdev == cdev)
594 p_ch = &privptr->channel[READ_CHANNEL];
595 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
596 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000598 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200599 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 return;
601 }
Andy Richterb805da72008-07-18 15:24:56 +0200602 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 dev = (struct net_device *) (p_ch->ndev);
605 p_env=privptr->p_env;
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 /* Copy interruption response block. */
608 memcpy(p_ch->irb, irb, sizeof(struct irb));
609
Andy Richterb805da72008-07-18 15:24:56 +0200610 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200611 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000612 dev_info(&cdev->dev,
613 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
615 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200616 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
617 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200618 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 /* return; */
620 }
621
622 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200623 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200627 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200630 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
631 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
632 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
633 (p_ch->irb->scsw.cmd.stctl ==
634 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
635 return;
636 wake_up(&p_ch->wait); /* wake up claw_release */
637 CLAW_DBF_TEXT(4, trace, "stop");
638 return;
639 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
640 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
641 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
642 (p_ch->irb->scsw.cmd.stctl ==
643 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
644 CLAW_DBF_TEXT(4, trace, "haltio");
645 return;
646 }
647 if (p_ch->flag == CLAW_READ) {
648 p_ch->claw_state = CLAW_START_READ;
649 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
650 } else if (p_ch->flag == CLAW_WRITE) {
651 p_ch->claw_state = CLAW_START_WRITE;
Andy Richter4811fcb2009-01-20 06:14:33 +0000652 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200653 claw_strt_read(dev, LOCK_NO);
654 claw_send_control(dev,
655 SYSTEM_VALIDATE_REQUEST,
656 0, 0, 0,
657 p_env->host_name,
658 p_env->adapter_name);
659 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000660 dev_warn(&cdev->dev, "The CLAW device received"
661 " an unexpected IRQ, "
662 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200663 irb->scsw.cmd.cstat,
664 irb->scsw.cmd.dstat);
665 return;
666 }
667 CLAW_DBF_TEXT(4, trace, "haltio");
668 return;
669 case CLAW_START_READ:
670 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
671 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
672 clear_bit(0, (void *)&p_ch->IO_active);
673 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
674 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
675 (p_ch->irb->ecw[0]) == 0) {
676 privptr->stats.rx_errors++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000677 dev_info(&cdev->dev,
678 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200679 "side recovers \n",
680 dev->name);
681 }
682 CLAW_DBF_TEXT(4, trace, "notrdy");
683 return;
684 }
685 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
686 (p_ch->irb->scsw.cmd.dstat == 0)) {
687 if (test_and_set_bit(CLAW_BH_ACTIVE,
688 (void *)&p_ch->flag_a) == 0)
689 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 else
Andy Richterb805da72008-07-18 15:24:56 +0200691 CLAW_DBF_TEXT(4, trace, "PCINoBH");
692 CLAW_DBF_TEXT(4, trace, "PCI_read");
693 return;
694 }
695 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
696 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
697 (p_ch->irb->scsw.cmd.stctl ==
698 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
699 CLAW_DBF_TEXT(4, trace, "SPend_rd");
700 return;
701 }
702 clear_bit(0, (void *)&p_ch->IO_active);
703 claw_clearbit_busy(TB_RETRY, dev);
704 if (test_and_set_bit(CLAW_BH_ACTIVE,
705 (void *)&p_ch->flag_a) == 0)
706 tasklet_schedule(&p_ch->tasklet);
707 else
708 CLAW_DBF_TEXT(4, trace, "RdBHAct");
709 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
710 return;
711 case CLAW_START_WRITE:
712 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000713 dev_info(&cdev->dev,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300714 "%s: Unit Check Occurred in "
Andy Richterb805da72008-07-18 15:24:56 +0200715 "write channel\n", dev->name);
716 clear_bit(0, (void *)&p_ch->IO_active);
717 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000718 dev_info(&cdev->dev,
719 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200720 "occurred:\n", dev->name);
721 init_timer(&p_ch->timer);
722 p_ch->timer.function =
723 (void *)claw_write_retry;
724 p_ch->timer.data = (unsigned long)p_ch;
725 p_ch->timer.expires = jiffies + 10*HZ;
726 add_timer(&p_ch->timer);
Andy Richter4811fcb2009-01-20 06:14:33 +0000727 dev_info(&cdev->dev,
728 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200729 "restarting\n", dev->name);
730 }
731 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
732 return;
733 }
734 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
735 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000736 dev_info(&cdev->dev,
737 "%s: Unit Exception "
738 "occurred in write channel\n",
739 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200740 }
741 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
742 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
743 (p_ch->irb->scsw.cmd.stctl ==
744 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
745 CLAW_DBF_TEXT(4, trace, "writeUE");
746 return;
747 }
748 clear_bit(0, (void *)&p_ch->IO_active);
749 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
750 claw_write_next(p_ch);
751 claw_clearbit_busy(TB_TX, dev);
752 claw_clear_busy(dev);
753 }
Heiko Carstens319cb0832010-08-12 01:58:27 +0000754 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +0200755 if (test_and_set_bit(CLAW_BH_ACTIVE,
756 (void *)&p_ch_r->flag_a) == 0)
757 tasklet_schedule(&p_ch_r->tasklet);
758 CLAW_DBF_TEXT(4, trace, "StWtExit");
759 return;
760 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000761 dev_warn(&cdev->dev,
762 "The CLAW device for %s received an unexpected IRQ\n",
763 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200764 CLAW_DBF_TEXT(2, trace, "badIRQ");
765 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 }
767
768} /* end of claw_irq_handler */
769
770
771/*-------------------------------------------------------------------*
772* claw_irq_tasklet *
773* *
774*--------------------------------------------------------------------*/
775static void
776claw_irq_tasklet ( unsigned long data )
777{
778 struct chbk * p_ch;
779 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 p_ch = (struct chbk *) data;
782 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200783 CLAW_DBF_TEXT(4, trace, "IRQtask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 unpack_read(dev);
785 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200786 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 return;
788} /* end of claw_irq_bh */
789
790/*-------------------------------------------------------------------*
791* claw_release *
792* *
793*--------------------------------------------------------------------*/
794static int
795claw_release(struct net_device *dev)
796{
797 int rc;
798 int i;
799 unsigned long saveflags;
800 unsigned long parm;
801 struct claw_privbk *privptr;
802 DECLARE_WAITQUEUE(wait, current);
803 struct ccwbk* p_this_ccw;
804 struct ccwbk* p_buf;
805
806 if (!dev)
807 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200808 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 if (!privptr)
810 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200811 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 privptr->release_pend=1;
813 claw_setbit_busy(TB_STOP,dev);
814 for ( i = 1; i >=0 ; i--) {
815 spin_lock_irqsave(
816 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
Heiko Carstens319cb0832010-08-12 01:58:27 +0000817 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 privptr->channel[i].claw_state = CLAW_STOP;
819 privptr->channel[i].IO_active = 0;
820 parm = (unsigned long) &privptr->channel[i];
Heiko Carstens319cb0832010-08-12 01:58:27 +0000821 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 claw_purge_skb_queue(
Heiko Carstens319cb0832010-08-12 01:58:27 +0000823 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
825 if (privptr->system_validate_comp==0x00) /* never opened? */
826 init_waitqueue_head(&privptr->channel[i].wait);
827 add_wait_queue(&privptr->channel[i].wait, &wait);
828 set_current_state(TASK_INTERRUPTIBLE);
829 spin_unlock_irqrestore(
830 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
831 schedule();
832 set_current_state(TASK_RUNNING);
833 remove_wait_queue(&privptr->channel[i].wait, &wait);
834 if (rc != 0) {
835 ccw_check_return_code(privptr->channel[i].cdev, rc);
836 }
837 }
838 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200839 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 privptr->pk_skb = NULL;
841 }
842 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200843 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return 0;
845 }
Andy Richterb805da72008-07-18 15:24:56 +0200846 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (privptr->p_buff_ccw != NULL) {
848 free_pages((unsigned long)privptr->p_buff_ccw,
849 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
850 }
Andy Richterb805da72008-07-18 15:24:56 +0200851 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 if (privptr->p_env->read_size < PAGE_SIZE) {
853 if (privptr->p_buff_read != NULL) {
854 free_pages((unsigned long)privptr->p_buff_read,
855 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
856 }
857 }
858 else {
859 p_buf=privptr->p_read_active_first;
860 while (p_buf!=NULL) {
861 free_pages((unsigned long)p_buf->p_buffer,
862 (int)pages_to_order_of_mag(
863 privptr->p_buff_pages_perread ));
864 p_buf=p_buf->next;
865 }
866 }
Andy Richterb805da72008-07-18 15:24:56 +0200867 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 if (privptr->p_env->write_size < PAGE_SIZE ) {
869 free_pages((unsigned long)privptr->p_buff_write,
870 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
871 }
872 else {
873 p_buf=privptr->p_write_active_first;
874 while (p_buf!=NULL) {
875 free_pages((unsigned long)p_buf->p_buffer,
876 (int)pages_to_order_of_mag(
877 privptr->p_buff_pages_perwrite ));
878 p_buf=p_buf->next;
879 }
880 }
Andy Richterb805da72008-07-18 15:24:56 +0200881 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 privptr->buffs_alloc = 0;
883 privptr->p_buff_ccw=NULL;
884 privptr->p_buff_read=NULL;
885 privptr->p_buff_write=NULL;
886 privptr->system_validate_comp=0;
887 privptr->release_pend=0;
888 /* Remove any writes that were pending and reset all reads */
889 p_this_ccw=privptr->p_read_active_first;
890 while (p_this_ccw!=NULL) {
891 p_this_ccw->header.length=0xffff;
892 p_this_ccw->header.opcode=0xff;
893 p_this_ccw->header.flag=0x00;
894 p_this_ccw=p_this_ccw->next;
895 }
896
897 while (privptr->p_write_active_first!=NULL) {
898 p_this_ccw=privptr->p_write_active_first;
899 p_this_ccw->header.flag=CLAW_PENDING;
900 privptr->p_write_active_first=p_this_ccw->next;
901 p_this_ccw->next=privptr->p_write_free_chain;
902 privptr->p_write_free_chain=p_this_ccw;
903 ++privptr->write_free_count;
904 }
905 privptr->p_write_active_last=NULL;
906 privptr->mtc_logical_link = -1;
907 privptr->mtc_skipping = 1;
908 privptr->mtc_offset=0;
909
Heiko Carstens319cb0832010-08-12 01:58:27 +0000910 if (((privptr->channel[READ_CHANNEL].last_dstat |
911 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Heiko Carstens319cb0832010-08-12 01:58:27 +0000913 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000914 "Deactivating %s completed with incorrect"
915 " subchannel status "
916 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 dev->name,
Heiko Carstens319cb0832010-08-12 01:58:27 +0000918 privptr->channel[READ_CHANNEL].last_dstat,
919 privptr->channel[WRITE_CHANNEL].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200920 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 }
Andy Richterb805da72008-07-18 15:24:56 +0200922 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 return 0;
924} /* end of claw_release */
925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926/*-------------------------------------------------------------------*
927* claw_write_retry *
928* *
929*--------------------------------------------------------------------*/
930
931static void
932claw_write_retry ( struct chbk *p_ch )
933{
934
935 struct net_device *dev=p_ch->ndev;
936
Andy Richterb805da72008-07-18 15:24:56 +0200937 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 return;
940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +0200942 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return;
944} /* end of claw_write_retry */
945
946
947/*-------------------------------------------------------------------*
948* claw_write_next *
949* *
950*--------------------------------------------------------------------*/
951
952static void
953claw_write_next ( struct chbk * p_ch )
954{
955
956 struct net_device *dev;
957 struct claw_privbk *privptr=NULL;
958 struct sk_buff *pk_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Andy Richterb805da72008-07-18 15:24:56 +0200960 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (p_ch->claw_state == CLAW_STOP)
962 return;
963 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200964 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 claw_free_wrt_buf( dev );
966 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -0700967 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 pk_skb = claw_pack_skb(privptr);
969 while (pk_skb != NULL) {
Heiko Carstens38ed18f2011-05-12 18:45:04 +0000970 claw_hw_tx(pk_skb, dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 if (privptr->write_free_count > 0) {
972 pk_skb = claw_pack_skb(privptr);
973 } else
974 pk_skb = NULL;
975 }
976 }
977 if (privptr->p_write_active_first!=NULL) {
978 claw_strt_out_IO(dev);
979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 return;
981} /* end of claw_write_next */
982
983/*-------------------------------------------------------------------*
984* *
985* claw_timer *
986*--------------------------------------------------------------------*/
987
988static void
989claw_timer ( struct chbk * p_ch )
990{
Andy Richterb805da72008-07-18 15:24:56 +0200991 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 p_ch->flag |= CLAW_TIMER;
993 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 return;
995} /* end of claw_timer */
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997/*
998*
999* functions
1000*/
1001
1002
1003/*-------------------------------------------------------------------*
1004* *
1005* pages_to_order_of_mag *
1006* *
1007* takes a number of pages from 1 to 512 and returns the *
1008* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1009* of magnitude get_free_pages() has an upper order of 9 *
1010*--------------------------------------------------------------------*/
1011
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001012static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013pages_to_order_of_mag(int num_of_pages)
1014{
1015 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001016 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001017
1018 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1020 /* 512 pages = 2Meg on 4k page systems */
1021 if (num_of_pages >= 512) {return 9; }
1022 /* we have two or more pages order is at least 1 */
1023 for (nump=2 ;nump <= 512;nump*=2) {
1024 if (num_of_pages <= nump)
1025 break;
1026 order_of_mag +=1;
1027 }
1028 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001029 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 return order_of_mag;
1031}
1032
1033/*-------------------------------------------------------------------*
1034* *
1035* add_claw_reads *
1036* *
1037*--------------------------------------------------------------------*/
1038static int
1039add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1040 struct ccwbk* p_last)
1041{
1042 struct claw_privbk *privptr;
1043 struct ccw1 temp_ccw;
1044 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001045 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001046 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 p_end = privptr->p_end_ccw;
1048
1049 /* first CCW and last CCW contains a new set of read channel programs
1050 * to apend the running channel programs
1051 */
1052 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001053 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 return 0;
1055 }
1056
1057 /* set up ending CCW sequence for this segment */
1058 if (p_end->read1) {
1059 p_end->read1=0x00; /* second ending CCW is now active */
1060 /* reset ending CCWs and setup TIC CCWs */
1061 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1062 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1063 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1064 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1065 p_end->read2_nop2.cda=0;
1066 p_end->read2_nop2.count=1;
1067 }
1068 else {
1069 p_end->read1=0x01; /* first ending CCW is now active */
1070 /* reset ending CCWs and setup TIC CCWs */
1071 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1072 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1073 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1074 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1075 p_end->read1_nop2.cda=0;
1076 p_end->read1_nop2.count=1;
1077 }
1078
1079 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001080 privptr->p_read_active_first = p_first; /* set new first */
1081 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 }
1083 else {
1084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 /* set up TIC ccw */
1086 temp_ccw.cda= (__u32)__pa(&p_first->read);
1087 temp_ccw.count=0;
1088 temp_ccw.flags=0;
1089 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1090
1091
1092 if (p_end->read1) {
1093
1094 /* first set of CCW's is chained to the new read */
1095 /* chain, so the second set is chained to the active chain. */
1096 /* Therefore modify the second set to point to the new */
1097 /* read chain set up TIC CCWs */
1098 /* make sure we update the CCW so channel doesn't fetch it */
1099 /* when it's only half done */
1100 memcpy( &p_end->read2_nop2, &temp_ccw ,
1101 sizeof(struct ccw1));
1102 privptr->p_read_active_last->r_TIC_1.cda=
1103 (__u32)__pa(&p_first->read);
1104 privptr->p_read_active_last->r_TIC_2.cda=
1105 (__u32)__pa(&p_first->read);
1106 }
1107 else {
1108 /* make sure we update the CCW so channel doesn't */
1109 /* fetch it when it is only half done */
1110 memcpy( &p_end->read1_nop2, &temp_ccw ,
1111 sizeof(struct ccw1));
1112 privptr->p_read_active_last->r_TIC_1.cda=
1113 (__u32)__pa(&p_first->read);
1114 privptr->p_read_active_last->r_TIC_2.cda=
1115 (__u32)__pa(&p_first->read);
1116 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001117 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 privptr->p_read_active_last->next = p_first;
1119 privptr->p_read_active_last=p_last;
1120 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001121 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 return 0;
1123} /* end of add_claw_reads */
1124
1125/*-------------------------------------------------------------------*
1126 * ccw_check_return_code *
1127 * *
1128 *-------------------------------------------------------------------*/
1129
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001130static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131ccw_check_return_code(struct ccw_device *cdev, int return_code)
1132{
Andy Richterb805da72008-07-18 15:24:56 +02001133 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 if (return_code != 0) {
1135 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001136 case -EBUSY: /* BUSY is a transient state no action needed */
1137 break;
1138 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001139 dev_err(&cdev->dev, "The remote channel adapter is not"
1140 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001141 break;
1142 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001143 dev_err(&cdev->dev,
1144 "The status of the remote channel adapter"
1145 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001146 break;
1147 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001148 dev_err(&cdev->dev, "The common device layer"
1149 " returned error code %d\n",
1150 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001151 }
1152 }
1153 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154} /* end of ccw_check_return_code */
1155
1156/*-------------------------------------------------------------------*
1157* ccw_check_unit_check *
1158*--------------------------------------------------------------------*/
1159
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001160static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1162{
Andy Richterb805da72008-07-18 15:24:56 +02001163 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001164 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Andy Richterb805da72008-07-18 15:24:56 +02001166 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001167 dev_warn(dev, "The communication peer of %s disconnected\n",
1168 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001170 if (sense & 0x40) {
1171 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001172 dev_warn(dev, "The remote channel adapter for"
1173 " %s has been reset\n",
1174 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001175 }
1176 } else if (sense & 0x20) {
1177 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001178 dev_warn(dev, "A data streaming timeout occurred"
1179 " for %s\n",
1180 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001181 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001182 dev_warn(dev, "The remote channel adapter for %s"
1183 " is faulty\n",
1184 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001185 } else {
1186 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001187 " for %s\n",
1188 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001189 }
1190 } else if (sense & 0x10) {
1191 dev_warn(dev, "A read data parity error occurred"
1192 " for %s\n",
1193 ndev->name);
1194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196} /* end of ccw_check_unit_check */
1197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198/*-------------------------------------------------------------------*
1199* find_link *
1200*--------------------------------------------------------------------*/
1201static int
1202find_link(struct net_device *dev, char *host_name, char *ws_name )
1203{
1204 struct claw_privbk *privptr;
1205 struct claw_env *p_env;
1206 int rc=0;
1207
Andy Richterb805da72008-07-18 15:24:56 +02001208 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001209 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 p_env=privptr->p_env;
1211 switch (p_env->packing)
1212 {
1213 case PACKING_ASK:
1214 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1215 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1216 rc = EINVAL;
1217 break;
1218 case DO_PACKED:
1219 case PACK_SEND:
1220 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1221 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1222 rc = EINVAL;
1223 break;
1224 default:
1225 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1226 (memcmp(p_env->api_type , ws_name, 8)!=0))
1227 rc = EINVAL;
1228 break;
1229 }
1230
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001231 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232} /* end of find_link */
1233
1234/*-------------------------------------------------------------------*
1235 * claw_hw_tx *
1236 * *
1237 * *
1238 *-------------------------------------------------------------------*/
1239
1240static int
1241claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1242{
1243 int rc=0;
1244 struct claw_privbk *privptr;
1245 struct ccwbk *p_this_ccw;
1246 struct ccwbk *p_first_ccw;
1247 struct ccwbk *p_last_ccw;
1248 __u32 numBuffers;
1249 signed long len_of_data;
1250 unsigned long bytesInThisBuffer;
1251 unsigned char *pDataAddress;
1252 struct endccw *pEnd;
1253 struct ccw1 tempCCW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 struct claw_env *p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 struct clawph *pk_head;
1256 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001257
1258 CLAW_DBF_TEXT(4, trace, "hw_tx");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001259 privptr = (struct claw_privbk *)(dev->ml_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1262 /* scan the write queue to free any completed write packets */
1263 p_first_ccw=NULL;
1264 p_last_ccw=NULL;
1265 if ((p_env->packing >= PACK_SEND) &&
1266 (skb->cb[1] != 'P')) {
1267 skb_push(skb,sizeof(struct clawph));
1268 pk_head=(struct clawph *)skb->data;
1269 pk_head->len=skb->len-sizeof(struct clawph);
1270 if (pk_head->len%4) {
1271 pk_head->len+= 4-(pk_head->len%4);
1272 skb_pad(skb,4-(pk_head->len%4));
1273 skb_put(skb,4-(pk_head->len%4));
1274 }
1275 if (p_env->packing == DO_PACKED)
1276 pk_head->link_num = linkid;
1277 else
1278 pk_head->link_num = 0;
1279 pk_head->flag = 0x00;
1280 skb_pad(skb,4);
1281 skb->cb[1] = 'P';
1282 }
1283 if (linkid == 0) {
1284 if (claw_check_busy(dev)) {
1285 if (privptr->write_free_count!=0) {
1286 claw_clear_busy(dev);
1287 }
1288 else {
1289 claw_strt_out_IO(dev );
1290 claw_free_wrt_buf( dev );
1291 if (privptr->write_free_count==0) {
Heiko Carstens319cb0832010-08-12 01:58:27 +00001292 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 atomic_inc(&skb->users);
1294 skb_queue_tail(&ch->collect_queue, skb);
1295 goto Done;
1296 }
1297 else {
1298 claw_clear_busy(dev);
1299 }
1300 }
1301 }
1302 /* tx lock */
1303 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Heiko Carstens319cb0832010-08-12 01:58:27 +00001304 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 atomic_inc(&skb->users);
1306 skb_queue_tail(&ch->collect_queue, skb);
1307 claw_strt_out_IO(dev );
1308 rc=-EBUSY;
1309 goto Done2;
1310 }
1311 }
1312 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001313 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
1315 /* If that number of buffers isn't available, give up for now */
1316 if (privptr->write_free_count < numBuffers ||
1317 privptr->p_write_free_chain == NULL ) {
1318
1319 claw_setbit_busy(TB_NOBUFFER,dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +00001320 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 atomic_inc(&skb->users);
1322 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001323 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 goto Done2;
1325 }
1326 pDataAddress=skb->data;
1327 len_of_data=skb->len;
1328
1329 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1331 if (p_this_ccw == NULL) { /* lost the race */
Heiko Carstens319cb0832010-08-12 01:58:27 +00001332 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 atomic_inc(&skb->users);
1334 skb_queue_tail(&ch->collect_queue, skb);
1335 goto Done2;
1336 }
1337 privptr->p_write_free_chain=p_this_ccw->next;
1338 p_this_ccw->next=NULL;
1339 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001340 if (len_of_data >= privptr->p_env->write_size)
1341 bytesInThisBuffer = privptr->p_env->write_size;
1342 else
1343 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1345 len_of_data-=bytesInThisBuffer;
1346 pDataAddress+=(unsigned long)bytesInThisBuffer;
1347 /* setup write CCW */
1348 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1349 if (len_of_data>0) {
1350 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1351 }
1352 p_this_ccw->write.count=bytesInThisBuffer;
1353 /* now add to end of this chain */
1354 if (p_first_ccw==NULL) {
1355 p_first_ccw=p_this_ccw;
1356 }
1357 if (p_last_ccw!=NULL) {
1358 p_last_ccw->next=p_this_ccw;
1359 /* set up TIC ccws */
1360 p_last_ccw->w_TIC_1.cda=
1361 (__u32)__pa(&p_this_ccw->write);
1362 }
1363 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
1365
1366 /* FirstCCW and LastCCW now contain a new set of write channel
1367 * programs to append to the running channel program
1368 */
1369
1370 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001371 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 pEnd=privptr->p_end_ccw;
1373 if (pEnd->write1) {
1374 pEnd->write1=0x00; /* second end ccw is now active */
1375 /* set up Tic CCWs */
1376 p_last_ccw->w_TIC_1.cda=
1377 (__u32)__pa(&pEnd->write2_nop1);
1378 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1379 pEnd->write2_nop2.flags =
1380 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1381 pEnd->write2_nop2.cda=0;
1382 pEnd->write2_nop2.count=1;
1383 }
1384 else { /* end of if (pEnd->write1)*/
1385 pEnd->write1=0x01; /* first end ccw is now active */
1386 /* set up Tic CCWs */
1387 p_last_ccw->w_TIC_1.cda=
1388 (__u32)__pa(&pEnd->write1_nop1);
1389 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1390 pEnd->write1_nop2.flags =
1391 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1392 pEnd->write1_nop2.cda=0;
1393 pEnd->write1_nop2.count=1;
1394 } /* end if if (pEnd->write1) */
1395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 if (privptr->p_write_active_first==NULL ) {
1397 privptr->p_write_active_first=p_first_ccw;
1398 privptr->p_write_active_last=p_last_ccw;
1399 }
1400 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 /* set up Tic CCWs */
1402
1403 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1404 tempCCW.count=0;
1405 tempCCW.flags=0;
1406 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1407
1408 if (pEnd->write1) {
1409
1410 /*
1411 * first set of ending CCW's is chained to the new write
1412 * chain, so the second set is chained to the active chain
1413 * Therefore modify the second set to point the new write chain.
1414 * make sure we update the CCW atomically
1415 * so channel does not fetch it when it's only half done
1416 */
1417 memcpy( &pEnd->write2_nop2, &tempCCW ,
1418 sizeof(struct ccw1));
1419 privptr->p_write_active_last->w_TIC_1.cda=
1420 (__u32)__pa(&p_first_ccw->write);
1421 }
1422 else {
1423
1424 /*make sure we update the CCW atomically
1425 *so channel does not fetch it when it's only half done
1426 */
1427 memcpy(&pEnd->write1_nop2, &tempCCW ,
1428 sizeof(struct ccw1));
1429 privptr->p_write_active_last->w_TIC_1.cda=
1430 (__u32)__pa(&p_first_ccw->write);
1431
1432 } /* end if if (pEnd->write1) */
1433
1434 privptr->p_write_active_last->next=p_first_ccw;
1435 privptr->p_write_active_last=p_last_ccw;
1436 }
1437
1438 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001439 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 claw_strt_out_IO(dev );
1441 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 if (privptr->write_free_count==0) {
1443 claw_setbit_busy(TB_NOBUFFER,dev);
1444 }
1445Done2:
1446 claw_clearbit_busy(TB_TX,dev);
1447Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 return(rc);
1449} /* end of claw_hw_tx */
1450
1451/*-------------------------------------------------------------------*
1452* *
1453* init_ccw_bk *
1454* *
1455*--------------------------------------------------------------------*/
1456
1457static int
1458init_ccw_bk(struct net_device *dev)
1459{
1460
1461 __u32 ccw_blocks_required;
1462 __u32 ccw_blocks_perpage;
1463 __u32 ccw_pages_required;
1464 __u32 claw_reads_perpage=1;
1465 __u32 claw_read_pages;
1466 __u32 claw_writes_perpage=1;
1467 __u32 claw_write_pages;
1468 void *p_buff=NULL;
1469 struct ccwbk*p_free_chain;
1470 struct ccwbk*p_buf;
1471 struct ccwbk*p_last_CCWB;
1472 struct ccwbk*p_first_CCWB;
1473 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001474 addr_t real_address;
1475 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 struct clawh *pClawH=NULL;
1477 addr_t real_TIC_address;
1478 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001479 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 /* initialize statistics field */
1482 privptr->active_link_ID=0;
1483 /* initialize ccwbk pointers */
1484 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1485 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1486 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1487 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1488 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1489 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1490 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1491 privptr->buffs_alloc = 0;
1492 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1493 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1494 /* initialize free write ccwbk counter */
1495 privptr->write_free_count=0; /* number of free bufs on write chain */
1496 p_last_CCWB = NULL;
1497 p_first_CCWB= NULL;
1498 /*
1499 * We need 1 CCW block for each read buffer, 1 for each
1500 * write buffer, plus 1 for ClawSignalBlock
1501 */
1502 ccw_blocks_required =
1503 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 /*
1505 * compute number of CCW blocks that will fit in a page
1506 */
1507 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1508 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001509 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 /*
1512 * read and write sizes are set by 2 constants in claw.h
1513 * 4k and 32k. Unpacked values other than 4k are not going to
1514 * provide good performance. With packing buffers support 32k
1515 * buffers are used.
1516 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001517 if (privptr->p_env->read_size < PAGE_SIZE) {
1518 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1519 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1520 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
1522 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001523 privptr->p_buff_pages_perread =
1524 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1525 claw_read_pages = privptr->p_env->read_buffers *
1526 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 }
1528 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001529 claw_writes_perpage =
1530 PAGE_SIZE / privptr->p_env->write_size;
1531 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1532 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
1534 }
1535 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001536 privptr->p_buff_pages_perwrite =
1537 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1538 claw_write_pages = privptr->p_env->write_buffers *
1539 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 /*
1542 * allocate ccw_pages_required
1543 */
1544 if (privptr->p_buff_ccw==NULL) {
1545 privptr->p_buff_ccw=
1546 (void *)__get_free_pages(__GFP_DMA,
1547 (int)pages_to_order_of_mag(ccw_pages_required ));
1548 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 return -ENOMEM;
1550 }
1551 privptr->p_buff_ccw_num=ccw_pages_required;
1552 }
1553 memset(privptr->p_buff_ccw, 0x00,
1554 privptr->p_buff_ccw_num * PAGE_SIZE);
1555
1556 /*
1557 * obtain ending ccw block address
1558 *
1559 */
1560 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1561 real_address = (__u32)__pa(privptr->p_end_ccw);
1562 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 p_endccw=privptr->p_end_ccw;
1564 p_endccw->real=real_address;
1565 p_endccw->write1=0x00;
1566 p_endccw->read1=0x00;
1567
1568 /* write1_nop1 */
1569 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1570 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1571 p_endccw->write1_nop1.count = 1;
1572 p_endccw->write1_nop1.cda = 0;
1573
1574 /* write1_nop2 */
1575 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1576 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1577 p_endccw->write1_nop2.count = 1;
1578 p_endccw->write1_nop2.cda = 0;
1579
1580 /* write2_nop1 */
1581 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1582 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1583 p_endccw->write2_nop1.count = 1;
1584 p_endccw->write2_nop1.cda = 0;
1585
1586 /* write2_nop2 */
1587 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1588 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1589 p_endccw->write2_nop2.count = 1;
1590 p_endccw->write2_nop2.cda = 0;
1591
1592 /* read1_nop1 */
1593 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1594 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1595 p_endccw->read1_nop1.count = 1;
1596 p_endccw->read1_nop1.cda = 0;
1597
1598 /* read1_nop2 */
1599 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1600 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1601 p_endccw->read1_nop2.count = 1;
1602 p_endccw->read1_nop2.cda = 0;
1603
1604 /* read2_nop1 */
1605 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1606 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1607 p_endccw->read2_nop1.count = 1;
1608 p_endccw->read2_nop1.cda = 0;
1609
1610 /* read2_nop2 */
1611 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1612 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1613 p_endccw->read2_nop2.count = 1;
1614 p_endccw->read2_nop2.cda = 0;
1615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 /*
1617 * Build a chain of CCWs
1618 *
1619 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 p_buff=privptr->p_buff_ccw;
1621
1622 p_free_chain=NULL;
1623 for (i=0 ; i < ccw_pages_required; i++ ) {
1624 real_address = (__u32)__pa(p_buff);
1625 p_buf=p_buff;
1626 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1627 p_buf->next = p_free_chain;
1628 p_free_chain = p_buf;
1629 p_buf->real=(__u32)__pa(p_buf);
1630 ++p_buf;
1631 }
1632 p_buff+=PAGE_SIZE;
1633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 /*
1635 * Initialize ClawSignalBlock
1636 *
1637 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 if (privptr->p_claw_signal_blk==NULL) {
1639 privptr->p_claw_signal_blk=p_free_chain;
1640 p_free_chain=p_free_chain->next;
1641 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1642 pClawH->length=0xffff;
1643 pClawH->opcode=0xff;
1644 pClawH->flag=CLAW_BUSY;
1645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 /*
1648 * allocate write_pages_required and add to free chain
1649 */
1650 if (privptr->p_buff_write==NULL) {
1651 if (privptr->p_env->write_size < PAGE_SIZE) {
1652 privptr->p_buff_write=
1653 (void *)__get_free_pages(__GFP_DMA,
1654 (int)pages_to_order_of_mag(claw_write_pages ));
1655 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 return -ENOMEM;
1658 }
1659 /*
1660 * Build CLAW write free chain
1661 *
1662 */
1663
1664 memset(privptr->p_buff_write, 0x00,
1665 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 privptr->p_write_free_chain=NULL;
1667
1668 p_buff=privptr->p_buff_write;
1669
1670 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1671 p_buf = p_free_chain; /* get a CCW */
1672 p_free_chain = p_buf->next;
1673 p_buf->next =privptr->p_write_free_chain;
1674 privptr->p_write_free_chain = p_buf;
1675 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1676 p_buf-> write.cda = (__u32)__pa(p_buff);
1677 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1678 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1679 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1680 p_buf-> w_read_FF.count = 1;
1681 p_buf-> w_read_FF.cda =
1682 (__u32)__pa(&p_buf-> header.flag);
1683 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1684 p_buf-> w_TIC_1.flags = 0;
1685 p_buf-> w_TIC_1.count = 0;
1686
Andy Richter4811fcb2009-01-20 06:14:33 +00001687 if (((unsigned long)p_buff +
1688 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001690 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1691 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 }
1693 }
1694 }
1695 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1696 {
1697 privptr->p_write_free_chain=NULL;
1698 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1699 p_buff=(void *)__get_free_pages(__GFP_DMA,
1700 (int)pages_to_order_of_mag(
1701 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 free_pages((unsigned long)privptr->p_buff_ccw,
1704 (int)pages_to_order_of_mag(
1705 privptr->p_buff_ccw_num));
1706 privptr->p_buff_ccw=NULL;
1707 p_buf=privptr->p_buff_write;
1708 while (p_buf!=NULL) {
1709 free_pages((unsigned long)
1710 p_buf->p_buffer,
1711 (int)pages_to_order_of_mag(
1712 privptr->p_buff_pages_perwrite));
1713 p_buf=p_buf->next;
1714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 return -ENOMEM;
1716 } /* Error on get_pages */
1717 memset(p_buff, 0x00, privptr->p_env->write_size );
1718 p_buf = p_free_chain;
1719 p_free_chain = p_buf->next;
1720 p_buf->next = privptr->p_write_free_chain;
1721 privptr->p_write_free_chain = p_buf;
1722 privptr->p_buff_write = p_buf;
1723 p_buf->p_buffer=(struct clawbuf *)p_buff;
1724 p_buf-> write.cda = (__u32)__pa(p_buff);
1725 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1726 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1727 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1728 p_buf-> w_read_FF.count = 1;
1729 p_buf-> w_read_FF.cda =
1730 (__u32)__pa(&p_buf-> header.flag);
1731 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1732 p_buf-> w_TIC_1.flags = 0;
1733 p_buf-> w_TIC_1.count = 0;
1734 } /* for all write_buffers */
1735
1736 } /* else buffers are PAGE_SIZE or bigger */
1737
1738 }
1739 privptr->p_buff_write_num=claw_write_pages;
1740 privptr->write_free_count=privptr->p_env->write_buffers;
1741
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 /*
1744 * allocate read_pages_required and chain to free chain
1745 */
1746 if (privptr->p_buff_read==NULL) {
1747 if (privptr->p_env->read_size < PAGE_SIZE) {
1748 privptr->p_buff_read=
1749 (void *)__get_free_pages(__GFP_DMA,
1750 (int)pages_to_order_of_mag(claw_read_pages) );
1751 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 free_pages((unsigned long)privptr->p_buff_ccw,
1753 (int)pages_to_order_of_mag(
1754 privptr->p_buff_ccw_num));
1755 /* free the write pages size is < page size */
1756 free_pages((unsigned long)privptr->p_buff_write,
1757 (int)pages_to_order_of_mag(
1758 privptr->p_buff_write_num));
1759 privptr->p_buff_ccw=NULL;
1760 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 return -ENOMEM;
1762 }
1763 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1764 privptr->p_buff_read_num=claw_read_pages;
1765 /*
1766 * Build CLAW read free chain
1767 *
1768 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 p_buff=privptr->p_buff_read;
1770 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1771 p_buf = p_free_chain;
1772 p_free_chain = p_buf->next;
1773
1774 if (p_last_CCWB==NULL) {
1775 p_buf->next=NULL;
1776 real_TIC_address=0;
1777 p_last_CCWB=p_buf;
1778 }
1779 else {
1780 p_buf->next=p_first_CCWB;
1781 real_TIC_address=
1782 (__u32)__pa(&p_first_CCWB -> read );
1783 }
1784
1785 p_first_CCWB=p_buf;
1786
1787 p_buf->p_buffer=(struct clawbuf *)p_buff;
1788 /* initialize read command */
1789 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1790 p_buf-> read.cda = (__u32)__pa(p_buff);
1791 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1792 p_buf-> read.count = privptr->p_env->read_size;
1793
1794 /* initialize read_h command */
1795 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1796 p_buf-> read_h.cda =
1797 (__u32)__pa(&(p_buf->header));
1798 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1799 p_buf-> read_h.count = sizeof(struct clawh);
1800
1801 /* initialize Signal command */
1802 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1803 p_buf-> signal.cda =
1804 (__u32)__pa(&(pClawH->flag));
1805 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1806 p_buf-> signal.count = 1;
1807
1808 /* initialize r_TIC_1 command */
1809 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1810 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1811 p_buf-> r_TIC_1.flags = 0;
1812 p_buf-> r_TIC_1.count = 0;
1813
1814 /* initialize r_read_FF command */
1815 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1816 p_buf-> r_read_FF.cda =
1817 (__u32)__pa(&(pClawH->flag));
1818 p_buf-> r_read_FF.flags =
1819 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1820 p_buf-> r_read_FF.count = 1;
1821
1822 /* initialize r_TIC_2 */
1823 memcpy(&p_buf->r_TIC_2,
1824 &p_buf->r_TIC_1, sizeof(struct ccw1));
1825
1826 /* initialize Header */
1827 p_buf->header.length=0xffff;
1828 p_buf->header.opcode=0xff;
1829 p_buf->header.flag=CLAW_PENDING;
1830
Andy Richter4811fcb2009-01-20 06:14:33 +00001831 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1832 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1833 -1)
1834 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 p_buff= p_buff+privptr->p_env->read_size;
1836 }
1837 else {
1838 p_buff=
1839 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001840 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 & PAGE_MASK) ;
1842 }
1843 } /* for read_buffers */
1844 } /* read_size < PAGE_SIZE */
1845 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1847 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001848 (int)pages_to_order_of_mag(
1849 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001852 (int)pages_to_order_of_mag(privptr->
1853 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 /* free the write pages */
1855 p_buf=privptr->p_buff_write;
1856 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001857 free_pages(
1858 (unsigned long)p_buf->p_buffer,
1859 (int)pages_to_order_of_mag(
1860 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 p_buf=p_buf->next;
1862 }
1863 /* free any read pages already alloc */
1864 p_buf=privptr->p_buff_read;
1865 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001866 free_pages(
1867 (unsigned long)p_buf->p_buffer,
1868 (int)pages_to_order_of_mag(
1869 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 p_buf=p_buf->next;
1871 }
1872 privptr->p_buff_ccw=NULL;
1873 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 return -ENOMEM;
1875 }
1876 memset(p_buff, 0x00, privptr->p_env->read_size);
1877 p_buf = p_free_chain;
1878 privptr->p_buff_read = p_buf;
1879 p_free_chain = p_buf->next;
1880
1881 if (p_last_CCWB==NULL) {
1882 p_buf->next=NULL;
1883 real_TIC_address=0;
1884 p_last_CCWB=p_buf;
1885 }
1886 else {
1887 p_buf->next=p_first_CCWB;
1888 real_TIC_address=
1889 (addr_t)__pa(
1890 &p_first_CCWB -> read );
1891 }
1892
1893 p_first_CCWB=p_buf;
1894 /* save buff address */
1895 p_buf->p_buffer=(struct clawbuf *)p_buff;
1896 /* initialize read command */
1897 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1898 p_buf-> read.cda = (__u32)__pa(p_buff);
1899 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1900 p_buf-> read.count = privptr->p_env->read_size;
1901
1902 /* initialize read_h command */
1903 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1904 p_buf-> read_h.cda =
1905 (__u32)__pa(&(p_buf->header));
1906 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1907 p_buf-> read_h.count = sizeof(struct clawh);
1908
1909 /* initialize Signal command */
1910 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1911 p_buf-> signal.cda =
1912 (__u32)__pa(&(pClawH->flag));
1913 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1914 p_buf-> signal.count = 1;
1915
1916 /* initialize r_TIC_1 command */
1917 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1918 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1919 p_buf-> r_TIC_1.flags = 0;
1920 p_buf-> r_TIC_1.count = 0;
1921
1922 /* initialize r_read_FF command */
1923 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1924 p_buf-> r_read_FF.cda =
1925 (__u32)__pa(&(pClawH->flag));
1926 p_buf-> r_read_FF.flags =
1927 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1928 p_buf-> r_read_FF.count = 1;
1929
1930 /* initialize r_TIC_2 */
1931 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1932 sizeof(struct ccw1));
1933
1934 /* initialize Header */
1935 p_buf->header.length=0xffff;
1936 p_buf->header.opcode=0xff;
1937 p_buf->header.flag=CLAW_PENDING;
1938
1939 } /* For read_buffers */
1940 } /* read_size >= PAGE_SIZE */
1941 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1943 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02001944
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 return 0;
1946} /* end of init_ccw_bk */
1947
1948/*-------------------------------------------------------------------*
1949* *
1950* probe_error *
1951* *
1952*--------------------------------------------------------------------*/
1953
1954static void
1955probe_error( struct ccwgroup_device *cgdev)
1956{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001957 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02001958
1959 CLAW_DBF_TEXT(4, trace, "proberr");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001960 privptr = dev_get_drvdata(&cgdev->dev);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001961 if (privptr != NULL) {
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001962 dev_set_drvdata(&cgdev->dev, NULL);
Jesper Juhl17fd6822005-11-07 01:01:30 -08001963 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001964 kfree(privptr->p_mtc_envelope);
1965 kfree(privptr);
1966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967} /* probe_error */
1968
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969/*-------------------------------------------------------------------*
1970* claw_process_control *
1971* *
1972* *
1973*--------------------------------------------------------------------*/
1974
1975static int
1976claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
1977{
1978
1979 struct clawbuf *p_buf;
1980 struct clawctl ctlbk;
1981 struct clawctl *p_ctlbk;
1982 char temp_host_name[8];
1983 char temp_ws_name[8];
1984 struct claw_privbk *privptr;
1985 struct claw_env *p_env;
1986 struct sysval *p_sysval;
1987 struct conncmd *p_connect=NULL;
1988 int rc;
1989 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02001990 struct device *tdev;
1991 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 udelay(1000); /* Wait a ms for the control packets to
1993 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02001994 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 p_env=privptr->p_env;
Heiko Carstens319cb0832010-08-12 01:58:27 +00001996 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 memcpy( &temp_host_name, p_env->host_name, 8);
1998 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00001999 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 "Received Control Packet\n",
2001 dev->name, temp_ws_name);
2002 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 return 0;
2004 }
2005 p_buf=p_ccw->p_buffer;
2006 p_ctlbk=&ctlbk;
2007 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2008 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2009 } else {
2010 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 switch (p_ctlbk->command)
2013 {
Andy Richterb805da72008-07-18 15:24:56 +02002014 case SYSTEM_VALIDATE_REQUEST:
2015 if (p_ctlbk->version != CLAW_VERSION_ID) {
2016 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2017 CLAW_RC_WRONG_VERSION);
Andy Richter4811fcb2009-01-20 06:14:33 +00002018 dev_warn(tdev, "The communication peer of %s"
2019 " uses an incorrect API version %d\n",
2020 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002021 }
2022 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002023 dev_info(tdev, "%s: Recv Sys Validate Request: "
2024 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2025 "Host name=%.8s\n",
2026 dev->name, p_ctlbk->version,
2027 p_ctlbk->linkid,
2028 p_ctlbk->correlator,
2029 p_sysval->WS_name,
2030 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002031 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2032 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2033 CLAW_RC_NAME_MISMATCH);
2034 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2035 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2036 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002037 dev_warn(tdev,
2038 "Host name %s for %s does not match the"
2039 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002040 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002041 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002042 temp_host_name);
2043 }
2044 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2045 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2046 CLAW_RC_NAME_MISMATCH);
2047 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2048 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2049 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002050 dev_warn(tdev, "Adapter name %s for %s does not match"
2051 " the remote host name %s\n",
2052 p_sysval->WS_name,
2053 dev->name,
2054 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002055 }
2056 if ((p_sysval->write_frame_size < p_env->write_size) &&
2057 (p_env->packing == 0)) {
2058 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2059 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002060 dev_warn(tdev,
2061 "The local write buffer is smaller than the"
2062 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002063 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2064 }
2065 if ((p_sysval->read_frame_size < p_env->read_size) &&
2066 (p_env->packing == 0)) {
2067 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2068 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002069 dev_warn(tdev,
2070 "The local read buffer is smaller than the"
2071 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002072 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2073 }
2074 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002075 dev_info(tdev,
2076 "CLAW device %.8s: System validate"
2077 " completed.\n", temp_ws_name);
2078 dev_info(tdev,
2079 "%s: sys Validate Rsize:%d Wsize:%d\n",
2080 dev->name, p_sysval->read_frame_size,
2081 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002082 privptr->system_validate_comp = 1;
2083 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2084 p_env->packing = PACKING_ASK;
2085 claw_strt_conn_req(dev);
2086 break;
2087 case SYSTEM_VALIDATE_RESPONSE:
2088 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002089 dev_info(tdev,
2090 "Settings for %s validated (version=%d, "
2091 "remote device=%d, rc=%d, adapter name=%.8s, "
2092 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002093 dev->name,
2094 p_ctlbk->version,
2095 p_ctlbk->correlator,
2096 p_ctlbk->rc,
2097 p_sysval->WS_name,
2098 p_sysval->host_name);
2099 switch (p_ctlbk->rc) {
2100 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002101 dev_info(tdev, "%s: CLAW device "
2102 "%.8s: System validate completed.\n",
2103 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002104 if (privptr->system_validate_comp == 0)
2105 claw_strt_conn_req(dev);
2106 privptr->system_validate_comp = 1;
2107 break;
2108 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002109 dev_warn(tdev, "Validating %s failed because of"
2110 " a host or adapter name mismatch\n",
2111 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002112 break;
2113 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002114 dev_warn(tdev, "Validating %s failed because of a"
2115 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002116 dev->name);
2117 break;
2118 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002119 dev_warn(tdev, "Validating %s failed because of a"
2120 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002121 dev->name);
2122 break;
2123 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002124 dev_warn(tdev, "The communication peer of %s rejected"
2125 " the connection\n",
2126 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002127 break;
2128 }
2129 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Andy Richterb805da72008-07-18 15:24:56 +02002131 case CONNECTION_REQUEST:
2132 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002133 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002134 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2135 dev->name,
2136 p_ctlbk->version,
2137 p_ctlbk->linkid,
2138 p_ctlbk->correlator,
2139 p_connect->host_name,
2140 p_connect->WS_name);
2141 if (privptr->active_link_ID != 0) {
2142 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002143 dev_info(tdev, "%s rejected a connection request"
2144 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002145 dev->name);
2146 }
2147 if (p_ctlbk->linkid != 1) {
2148 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002149 dev_info(tdev, "%s rejected a request to open multiple"
2150 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002151 dev->name);
2152 }
2153 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2154 if (rc != 0) {
2155 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002156 dev_info(tdev, "%s rejected a connection request"
2157 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002158 dev->name);
2159 }
2160 claw_send_control(dev,
2161 CONNECTION_CONFIRM, p_ctlbk->linkid,
2162 p_ctlbk->correlator,
2163 0, p_connect->host_name,
2164 p_connect->WS_name);
2165 if (p_env->packing == PACKING_ASK) {
2166 p_env->packing = PACK_SEND;
2167 claw_snd_conn_req(dev, 0);
2168 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002169 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002170 "completed link_id=%d.\n",
2171 dev->name, temp_ws_name,
2172 p_ctlbk->linkid);
2173 privptr->active_link_ID = p_ctlbk->linkid;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002174 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002175 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2176 break;
2177 case CONNECTION_RESPONSE:
2178 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002179 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002180 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2181 dev->name,
2182 p_ctlbk->version,
2183 p_ctlbk->linkid,
2184 p_ctlbk->correlator,
2185 p_ctlbk->rc,
2186 p_connect->host_name,
2187 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
Andy Richterb805da72008-07-18 15:24:56 +02002189 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002190 dev_warn(tdev, "The communication peer of %s rejected"
2191 " a connection request\n",
2192 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002193 return 1;
2194 }
2195 rc = find_link(dev,
2196 p_connect->host_name, p_connect->WS_name);
2197 if (rc != 0) {
2198 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002199 dev_warn(tdev, "The communication peer of %s"
2200 " rejected a connection "
2201 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002202 dev->name);
2203 }
2204 /* should be until CONNECTION_CONFIRM */
2205 privptr->active_link_ID = -(p_ctlbk->linkid);
2206 break;
2207 case CONNECTION_CONFIRM:
2208 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002209 dev_info(tdev,
2210 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002211 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2212 dev->name,
2213 p_ctlbk->version,
2214 p_ctlbk->linkid,
2215 p_ctlbk->correlator,
2216 p_connect->host_name,
2217 p_connect->WS_name);
2218 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2219 privptr->active_link_ID = p_ctlbk->linkid;
2220 if (p_env->packing > PACKING_ASK) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002221 dev_info(tdev,
2222 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 p_env->packing = DO_PACKED;
2224 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002225 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002226 wake_up(&p_ch->wait);
2227 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002228 dev_warn(tdev, "Activating %s failed because of"
2229 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002230 dev->name, p_ctlbk->linkid);
2231 claw_snd_disc(dev, p_ctlbk);
2232 }
2233 break;
2234 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002235 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002236 "Vers=%d,link_id=%d,Corr=%d\n",
2237 dev->name, p_ctlbk->version,
2238 p_ctlbk->linkid, p_ctlbk->correlator);
2239 if ((p_ctlbk->linkid == 2) &&
2240 (p_env->packing == PACK_SEND)) {
2241 privptr->active_link_ID = 1;
2242 p_env->packing = DO_PACKED;
2243 } else
2244 privptr->active_link_ID = 0;
2245 break;
2246 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002247 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002248 dev->name);
2249 break;
2250 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002251 dev_warn(tdev, "The communication peer of %s sent"
2252 " an unknown command code\n",
2253 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002254 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 }
2256
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 return 0;
2258} /* end of claw_process_control */
2259
2260
2261/*-------------------------------------------------------------------*
2262* claw_send_control *
2263* *
2264*--------------------------------------------------------------------*/
2265
2266static int
2267claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2268 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2269{
2270 struct claw_privbk *privptr;
2271 struct clawctl *p_ctl;
2272 struct sysval *p_sysval;
2273 struct conncmd *p_connect;
2274 struct sk_buff *skb;
2275
Andy Richterb805da72008-07-18 15:24:56 +02002276 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002277 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2279
2280 p_ctl->command=type;
2281 p_ctl->version=CLAW_VERSION_ID;
2282 p_ctl->linkid=link;
2283 p_ctl->correlator=correlator;
2284 p_ctl->rc=rc;
2285
2286 p_sysval=(struct sysval *)&p_ctl->data;
2287 p_connect=(struct conncmd *)&p_ctl->data;
2288
2289 switch (p_ctl->command) {
2290 case SYSTEM_VALIDATE_REQUEST:
2291 case SYSTEM_VALIDATE_RESPONSE:
2292 memcpy(&p_sysval->host_name, local_name, 8);
2293 memcpy(&p_sysval->WS_name, remote_name, 8);
2294 if (privptr->p_env->packing > 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002295 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2296 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002298 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002299 p_sysval->read_frame_size =
2300 privptr->p_env->read_size;
2301 p_sysval->write_frame_size =
2302 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 }
2304 memset(&p_sysval->reserved, 0x00, 4);
2305 break;
2306 case CONNECTION_REQUEST:
2307 case CONNECTION_RESPONSE:
2308 case CONNECTION_CONFIRM:
2309 case DISCONNECT:
2310 memcpy(&p_sysval->host_name, local_name, 8);
2311 memcpy(&p_sysval->WS_name, remote_name, 8);
2312 if (privptr->p_env->packing > 0) {
2313 /* How big is the biggest packet */
2314 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2315 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2316 } else {
2317 memset(&p_connect->reserved1, 0x00, 4);
2318 memset(&p_connect->reserved2, 0x00, 4);
2319 }
2320 break;
2321 default:
2322 break;
2323 }
2324
2325 /* write Control Record to the device */
2326
2327
2328 skb = dev_alloc_skb(sizeof(struct clawctl));
2329 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 return -ENOMEM;
2331 }
2332 memcpy(skb_put(skb, sizeof(struct clawctl)),
2333 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 if (privptr->p_env->packing >= PACK_SEND)
2335 claw_hw_tx(skb, dev, 1);
2336 else
2337 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 return 0;
2339} /* end of claw_send_control */
2340
2341/*-------------------------------------------------------------------*
2342* claw_snd_conn_req *
2343* *
2344*--------------------------------------------------------------------*/
2345static int
2346claw_snd_conn_req(struct net_device *dev, __u8 link)
2347{
2348 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002349 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 struct clawctl *p_ctl;
2351
Andy Richterb805da72008-07-18 15:24:56 +02002352 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 rc = 1;
2354 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2355 p_ctl->linkid = link;
2356 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 return rc;
2358 }
2359 if (privptr->p_env->packing == PACKING_ASK )
2360 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2361 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2362 if (privptr->p_env->packing == PACK_SEND) {
2363 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2364 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2365 }
2366 if (privptr->p_env->packing == 0)
2367 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2368 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 return rc;
2370
2371} /* end of claw_snd_conn_req */
2372
2373
2374/*-------------------------------------------------------------------*
2375* claw_snd_disc *
2376* *
2377*--------------------------------------------------------------------*/
2378
2379static int
2380claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2381{
2382 int rc;
2383 struct conncmd * p_connect;
2384
Andy Richterb805da72008-07-18 15:24:56 +02002385 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 p_connect=(struct conncmd *)&p_ctl->data;
2387
2388 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2389 p_ctl->correlator, 0,
2390 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 return rc;
2392} /* end of claw_snd_disc */
2393
2394
2395/*-------------------------------------------------------------------*
2396* claw_snd_sys_validate_rsp *
2397* *
2398*--------------------------------------------------------------------*/
2399
2400static int
2401claw_snd_sys_validate_rsp(struct net_device *dev,
2402 struct clawctl *p_ctl, __u32 return_code)
2403{
2404 struct claw_env * p_env;
2405 struct claw_privbk *privptr;
2406 int rc;
2407
Andy Richterb805da72008-07-18 15:24:56 +02002408 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002409 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 p_env=privptr->p_env;
2411 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2412 p_ctl->linkid,
2413 p_ctl->correlator,
2414 return_code,
2415 p_env->host_name,
2416 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 return rc;
2418} /* end of claw_snd_sys_validate_rsp */
2419
2420/*-------------------------------------------------------------------*
2421* claw_strt_conn_req *
2422* *
2423*--------------------------------------------------------------------*/
2424
2425static int
2426claw_strt_conn_req(struct net_device *dev )
2427{
2428 int rc;
2429
Andy Richterb805da72008-07-18 15:24:56 +02002430 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 return rc;
2433} /* end of claw_strt_conn_req */
2434
2435
2436
2437/*-------------------------------------------------------------------*
2438 * claw_stats *
2439 *-------------------------------------------------------------------*/
2440
2441static struct
2442net_device_stats *claw_stats(struct net_device *dev)
2443{
2444 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002445
2446 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002447 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 return &privptr->stats;
2449} /* end of claw_stats */
2450
2451
2452/*-------------------------------------------------------------------*
2453* unpack_read *
2454* *
2455*--------------------------------------------------------------------*/
2456static void
2457unpack_read(struct net_device *dev )
2458{
2459 struct sk_buff *skb;
2460 struct claw_privbk *privptr;
2461 struct claw_env *p_env;
2462 struct ccwbk *p_this_ccw;
2463 struct ccwbk *p_first_ccw;
2464 struct ccwbk *p_last_ccw;
2465 struct clawph *p_packh;
2466 void *p_packd;
2467 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002468 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469
2470 __u32 len_of_data;
2471 __u32 pack_off;
2472 __u8 link_num;
2473 __u8 mtc_this_frm=0;
2474 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 int i=0;
2476 int p=0;
2477
Andy Richterb805da72008-07-18 15:24:56 +02002478 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 p_first_ccw=NULL;
2480 p_last_ccw=NULL;
2481 p_packh=NULL;
2482 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002483 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002484
Heiko Carstens319cb0832010-08-12 01:58:27 +00002485 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 p_env = privptr->p_env;
2487 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 pack_off = 0;
2490 p = 0;
2491 p_this_ccw->header.flag=CLAW_PENDING;
2492 privptr->p_read_active_first=p_this_ccw->next;
2493 p_this_ccw->next=NULL;
2494 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2495 if ((p_env->packing == PACK_SEND) &&
2496 (p_packh->len == 32) &&
2497 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2498 p_packh++; /* peek past pack header */
2499 p_ctlrec = (struct clawctl *)p_packh;
2500 p_packh--; /* un peek */
2501 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2502 (p_ctlrec->command == CONNECTION_CONFIRM))
2503 p_env->packing = DO_PACKED;
2504 }
2505 if (p_env->packing == DO_PACKED)
2506 link_num=p_packh->link_num;
2507 else
2508 link_num=p_this_ccw->header.opcode / 8;
2509 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 mtc_this_frm=1;
2511 if (p_this_ccw->header.length!=
2512 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002513 dev_warn(p_dev,
2514 "The communication peer of %s"
2515 " sent a faulty"
2516 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 dev->name, p_this_ccw->header.length);
2518 }
2519 }
2520
2521 if (privptr->mtc_skipping) {
2522 /*
2523 * We're in the mode of skipping past a
2524 * multi-frame message
2525 * that we can't process for some reason or other.
2526 * The first frame without the More-To-Come flag is
2527 * the last frame of the skipped message.
2528 */
2529 /* in case of More-To-Come not set in this frame */
2530 if (mtc_this_frm==0) {
2531 privptr->mtc_skipping=0; /* Ok, the end */
2532 privptr->mtc_logical_link=-1;
2533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 goto NextFrame;
2535 }
2536
2537 if (link_num==0) {
2538 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002539 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 goto NextFrame;
2541 }
2542unpack_next:
2543 if (p_env->packing == DO_PACKED) {
2544 if (pack_off > p_env->read_size)
2545 goto NextFrame;
2546 p_packd = p_this_ccw->p_buffer+pack_off;
2547 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002548 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 (p_packh->flag != 0))
2550 goto NextFrame;
2551 bytes_to_mov = p_packh->len;
2552 pack_off += bytes_to_mov+sizeof(struct clawph);
2553 p++;
2554 } else {
2555 bytes_to_mov=p_this_ccw->header.length;
2556 }
2557 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
2559 /*
2560 * if More-To-Come is set in this frame then we don't know
2561 * length of entire message, and hence have to allocate
2562 * large buffer */
2563
2564 /* We are starting a new envelope */
2565 privptr->mtc_offset=0;
2566 privptr->mtc_logical_link=link_num;
2567 }
2568
2569 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2570 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 privptr->stats.rx_frame_errors++;
2572 goto NextFrame;
2573 }
2574 if (p_env->packing == DO_PACKED) {
2575 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2576 p_packd+sizeof(struct clawph), bytes_to_mov);
2577
2578 } else {
2579 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2580 p_this_ccw->p_buffer, bytes_to_mov);
2581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 if (mtc_this_frm==0) {
2583 len_of_data=privptr->mtc_offset+bytes_to_mov;
2584 skb=dev_alloc_skb(len_of_data);
2585 if (skb) {
2586 memcpy(skb_put(skb,len_of_data),
2587 privptr->p_mtc_envelope,
2588 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002590 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 skb->protocol=htons(ETH_P_IP);
2592 skb->ip_summed=CHECKSUM_UNNECESSARY;
2593 privptr->stats.rx_packets++;
2594 privptr->stats.rx_bytes+=len_of_data;
2595 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 }
2597 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002598 dev_info(p_dev, "Allocating a buffer for"
2599 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 }
2602 privptr->mtc_offset=0;
2603 privptr->mtc_logical_link=-1;
2604 }
2605 else {
2606 privptr->mtc_offset+=bytes_to_mov;
2607 }
2608 if (p_env->packing == DO_PACKED)
2609 goto unpack_next;
2610NextFrame:
2611 /*
2612 * Remove ThisCCWblock from active read queue, and add it
2613 * to queue of free blocks to be reused.
2614 */
2615 i++;
2616 p_this_ccw->header.length=0xffff;
2617 p_this_ccw->header.opcode=0xff;
2618 /*
2619 * add this one to the free queue for later reuse
2620 */
2621 if (p_first_ccw==NULL) {
2622 p_first_ccw = p_this_ccw;
2623 }
2624 else {
2625 p_last_ccw->next = p_this_ccw;
2626 }
2627 p_last_ccw = p_this_ccw;
2628 /*
2629 * chain to next block on active read queue
2630 */
2631 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002632 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 } /* end of while */
2634
2635 /* check validity */
2636
Andy Richterb805da72008-07-18 15:24:56 +02002637 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 return;
2641} /* end of unpack_read */
2642
2643/*-------------------------------------------------------------------*
2644* claw_strt_read *
2645* *
2646*--------------------------------------------------------------------*/
2647static void
2648claw_strt_read (struct net_device *dev, int lock )
2649{
2650 int rc = 0;
2651 __u32 parm;
2652 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002653 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 struct ccwbk*p_ccwbk;
2655 struct chbk *p_ch;
2656 struct clawh *p_clawh;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002657 p_ch = &privptr->channel[READ_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
Andy Richterb805da72008-07-18 15:24:56 +02002659 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2661 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2662
2663 if ((privptr->p_write_active_first!=NULL &&
2664 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2665 (privptr->p_read_active_first!=NULL &&
2666 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2667 p_clawh->flag=CLAW_BUSY; /* 0xff */
2668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 if (lock==LOCK_YES) {
2670 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2671 }
2672 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002673 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 p_ccwbk=privptr->p_read_active_first;
2675 parm = (unsigned long) p_ch;
2676 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2677 0xff, 0);
2678 if (rc != 0) {
2679 ccw_check_return_code(p_ch->cdev, rc);
2680 }
2681 }
2682 else {
Andy Richterb805da72008-07-18 15:24:56 +02002683 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 }
2685
2686 if (lock==LOCK_YES) {
2687 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2688 }
Andy Richterb805da72008-07-18 15:24:56 +02002689 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 return;
2691} /* end of claw_strt_read */
2692
2693/*-------------------------------------------------------------------*
2694* claw_strt_out_IO *
2695* *
2696*--------------------------------------------------------------------*/
2697
2698static void
2699claw_strt_out_IO( struct net_device *dev )
2700{
2701 int rc = 0;
2702 unsigned long parm;
2703 struct claw_privbk *privptr;
2704 struct chbk *p_ch;
2705 struct ccwbk *p_first_ccw;
2706
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 if (!dev) {
2708 return;
2709 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002710 privptr = (struct claw_privbk *)dev->ml_priv;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002711 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712
Andy Richterb805da72008-07-18 15:24:56 +02002713 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 p_first_ccw=privptr->p_write_active_first;
2715
2716 if (p_ch->claw_state == CLAW_STOP)
2717 return;
2718 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 return;
2720 }
2721 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2722 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002723 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002724 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2725 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 if (rc != 0) {
2727 ccw_check_return_code(p_ch->cdev, rc);
2728 }
2729 }
2730 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 return;
2732} /* end of claw_strt_out_IO */
2733
2734/*-------------------------------------------------------------------*
2735* Free write buffers *
2736* *
2737*--------------------------------------------------------------------*/
2738
2739static void
2740claw_free_wrt_buf( struct net_device *dev )
2741{
2742
Peter Tiedemann6951df32008-08-21 17:10:23 +02002743 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 struct ccwbk*p_this_ccw;
2745 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002746
2747 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 /* scan the write queue to free any completed write packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 p_this_ccw=privptr->p_write_active_first;
2750 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2751 {
2752 p_next_ccw = p_this_ccw->next;
2753 if (((p_next_ccw!=NULL) &&
2754 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2755 ((p_this_ccw == privptr->p_write_active_last) &&
2756 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2757 /* The next CCW is OK or this is */
2758 /* the last CCW...free it @A1A */
2759 privptr->p_write_active_first=p_this_ccw->next;
2760 p_this_ccw->header.flag=CLAW_PENDING;
2761 p_this_ccw->next=privptr->p_write_free_chain;
2762 privptr->p_write_free_chain=p_this_ccw;
2763 ++privptr->write_free_count;
2764 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2765 p_this_ccw=privptr->p_write_active_first;
2766 privptr->stats.tx_packets++;
2767 }
2768 else {
2769 break;
2770 }
2771 }
2772 if (privptr->write_free_count!=0) {
2773 claw_clearbit_busy(TB_NOBUFFER,dev);
2774 }
2775 /* whole chain removed? */
2776 if (privptr->p_write_active_first==NULL) {
2777 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 }
Andy Richterb805da72008-07-18 15:24:56 +02002779 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 return;
2781}
2782
2783/*-------------------------------------------------------------------*
2784* claw free netdevice *
2785* *
2786*--------------------------------------------------------------------*/
2787static void
2788claw_free_netdevice(struct net_device * dev, int free_dev)
2789{
2790 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791
Andy Richterb805da72008-07-18 15:24:56 +02002792 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 if (!dev)
2794 return;
Andy Richterb805da72008-07-18 15:24:56 +02002795 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002796 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 if (dev->flags & IFF_RUNNING)
2798 claw_release(dev);
2799 if (privptr) {
Heiko Carstens319cb0832010-08-12 01:58:27 +00002800 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002802 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803#ifdef MODULE
2804 if (free_dev) {
2805 free_netdev(dev);
2806 }
2807#endif
Andy Richterb805da72008-07-18 15:24:56 +02002808 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809}
2810
2811/**
2812 * Claw init netdevice
2813 * Initialize everything of the net device except the name and the
2814 * channel structs.
2815 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002816static const struct net_device_ops claw_netdev_ops = {
2817 .ndo_open = claw_open,
2818 .ndo_stop = claw_release,
2819 .ndo_get_stats = claw_stats,
2820 .ndo_start_xmit = claw_tx,
2821 .ndo_change_mtu = claw_change_mtu,
2822};
2823
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824static void
2825claw_init_netdevice(struct net_device * dev)
2826{
Andy Richterb805da72008-07-18 15:24:56 +02002827 CLAW_DBF_TEXT(2, setup, "init_dev");
2828 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 dev->hard_header_len = 0;
2831 dev->addr_len = 0;
2832 dev->type = ARPHRD_SLIP;
2833 dev->tx_queue_len = 1300;
2834 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002835 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002836 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 return;
2838}
2839
2840/**
2841 * Init a new channel in the privptr->channel[i].
2842 *
2843 * @param cdev The ccw_device to be added.
2844 *
2845 * @return 0 on success, !0 on error.
2846 */
2847static int
2848add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2849{
2850 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002851 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
Kay Sievers2a0217d2008-10-10 21:33:09 +02002853 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2855 p_ch = &privptr->channel[i];
2856 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002857 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002858 ccw_device_get_id(cdev, &dev_id);
2859 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002860 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 return -ENOMEM;
2862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 return 0;
2864}
2865
2866
2867/**
2868 *
2869 * Setup an interface.
2870 *
2871 * @param cgdev Device to be setup.
2872 *
2873 * @returns 0 on success, !0 on failure.
2874 */
2875static int
2876claw_new_device(struct ccwgroup_device *cgdev)
2877{
2878 struct claw_privbk *privptr;
2879 struct claw_env *p_env;
2880 struct net_device *dev;
2881 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002882 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883
Andy Richter4811fcb2009-01-20 06:14:33 +00002884 dev_info(&cgdev->dev, "add for %s\n",
Heiko Carstens319cb0832010-08-12 01:58:27 +00002885 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002886 CLAW_DBF_TEXT(2, setup, "new_dev");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002887 privptr = dev_get_drvdata(&cgdev->dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +00002888 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2889 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 if (!privptr)
2891 return -ENODEV;
2892 p_env = privptr->p_env;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002893 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2894 p_env->devno[READ_CHANNEL] = dev_id.devno;
2895 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2896 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 ret = add_channel(cgdev->cdev[0],0,privptr);
2898 if (ret == 0)
2899 ret = add_channel(cgdev->cdev[1],1,privptr);
2900 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002901 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2902 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002903 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002905 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002907 dev_warn(&cgdev->dev,
2908 "Setting the read subchannel online"
2909 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 goto out;
2911 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002912 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002914 dev_warn(&cgdev->dev,
2915 "Setting the write subchannel online "
2916 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 goto out;
2918 }
2919 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2920 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002921 dev_warn(&cgdev->dev,
2922 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 goto out;
2924 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002925 dev->ml_priv = privptr;
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002926 dev_set_drvdata(&cgdev->dev, privptr);
Heiko Carstens319cb0832010-08-12 01:58:27 +00002927 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2928 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 /* sysfs magic */
2930 SET_NETDEV_DEV(dev, &cgdev->dev);
2931 if (register_netdev(dev) != 0) {
2932 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02002933 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 goto out;
2935 }
2936 dev->flags &=~IFF_RUNNING;
2937 if (privptr->buffs_alloc == 0) {
2938 ret=init_ccw_bk(dev);
2939 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 unregister_netdev(dev);
2941 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02002942 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 goto out;
2944 }
2945 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002946 privptr->channel[READ_CHANNEL].ndev = dev;
2947 privptr->channel[WRITE_CHANNEL].ndev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 privptr->p_env->ndev = dev;
2949
Andy Richter4811fcb2009-01-20 06:14:33 +00002950 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2952 dev->name, p_env->read_size,
2953 p_env->write_size, p_env->read_buffers,
Heiko Carstens319cb0832010-08-12 01:58:27 +00002954 p_env->write_buffers, p_env->devno[READ_CHANNEL],
2955 p_env->devno[WRITE_CHANNEL]);
Andy Richter4811fcb2009-01-20 06:14:33 +00002956 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 ":%.8s api_type: %.8s\n",
2958 dev->name, p_env->host_name,
2959 p_env->adapter_name , p_env->api_type);
2960 return 0;
2961out:
2962 ccw_device_set_offline(cgdev->cdev[1]);
2963 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 return -ENODEV;
2965}
2966
2967static void
2968claw_purge_skb_queue(struct sk_buff_head *q)
2969{
2970 struct sk_buff *skb;
2971
Andy Richterb805da72008-07-18 15:24:56 +02002972 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 while ((skb = skb_dequeue(q))) {
2974 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02002975 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 }
2977}
2978
2979/**
2980 * Shutdown an interface.
2981 *
2982 * @param cgdev Device to be shut down.
2983 *
2984 * @returns 0 on success, !0 on failure.
2985 */
2986static int
2987claw_shutdown_device(struct ccwgroup_device *cgdev)
2988{
2989 struct claw_privbk *priv;
2990 struct net_device *ndev;
Heiko Carstens38ed18f2011-05-12 18:45:04 +00002991 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02002993 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002994 priv = dev_get_drvdata(&cgdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 if (!priv)
2996 return -ENODEV;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002997 ndev = priv->channel[READ_CHANNEL].ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 if (ndev) {
2999 /* Close the device */
Heiko Carstens319cb0832010-08-12 01:58:27 +00003000 dev_info(&cgdev->dev, "%s: shutting down\n",
Andy Richter4811fcb2009-01-20 06:14:33 +00003001 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 if (ndev->flags & IFF_RUNNING)
3003 ret = claw_release(ndev);
3004 ndev->flags &=~IFF_RUNNING;
3005 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003006 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 claw_free_netdevice(ndev, 1);
Heiko Carstens319cb0832010-08-12 01:58:27 +00003008 priv->channel[READ_CHANNEL].ndev = NULL;
3009 priv->channel[WRITE_CHANNEL].ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 priv->p_env->ndev = NULL;
3011 }
3012 ccw_device_set_offline(cgdev->cdev[1]);
3013 ccw_device_set_offline(cgdev->cdev[0]);
Heiko Carstens38ed18f2011-05-12 18:45:04 +00003014 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015}
3016
3017static void
3018claw_remove_device(struct ccwgroup_device *cgdev)
3019{
3020 struct claw_privbk *priv;
3021
Andy Richterb805da72008-07-18 15:24:56 +02003022 BUG_ON(!cgdev);
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003023 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003024 priv = dev_get_drvdata(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003025 BUG_ON(!priv);
Andy Richter4811fcb2009-01-20 06:14:33 +00003026 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 if (cgdev->state == CCWGROUP_ONLINE)
3028 claw_shutdown_device(cgdev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003029 kfree(priv->p_mtc_envelope);
3030 priv->p_mtc_envelope=NULL;
3031 kfree(priv->p_env);
3032 priv->p_env=NULL;
3033 kfree(priv->channel[0].irb);
3034 priv->channel[0].irb=NULL;
3035 kfree(priv->channel[1].irb);
3036 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 kfree(priv);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003038 dev_set_drvdata(&cgdev->dev, NULL);
Heiko Carstens319cb0832010-08-12 01:58:27 +00003039 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3040 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003042
3043 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044}
3045
3046
3047/*
3048 * sysfs attributes
3049 */
3050static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003051claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052{
3053 struct claw_privbk *priv;
3054 struct claw_env * p_env;
3055
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003056 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 if (!priv)
3058 return -ENODEV;
3059 p_env = priv->p_env;
3060 return sprintf(buf, "%s\n",p_env->host_name);
3061}
3062
3063static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003064claw_hname_write(struct device *dev, struct device_attribute *attr,
3065 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066{
3067 struct claw_privbk *priv;
3068 struct claw_env * p_env;
3069
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003070 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 if (!priv)
3072 return -ENODEV;
3073 p_env = priv->p_env;
3074 if (count > MAX_NAME_LEN+1)
3075 return -EINVAL;
3076 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3077 strncpy(p_env->host_name,buf, count);
3078 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3079 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003080 CLAW_DBF_TEXT(2, setup, "HstnSet");
3081 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
3083 return count;
3084}
3085
3086static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3087
3088static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003089claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090{
3091 struct claw_privbk *priv;
3092 struct claw_env * p_env;
3093
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003094 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 if (!priv)
3096 return -ENODEV;
3097 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003098 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
3101static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003102claw_adname_write(struct device *dev, struct device_attribute *attr,
3103 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104{
3105 struct claw_privbk *priv;
3106 struct claw_env * p_env;
3107
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003108 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 if (!priv)
3110 return -ENODEV;
3111 p_env = priv->p_env;
3112 if (count > MAX_NAME_LEN+1)
3113 return -EINVAL;
3114 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3115 strncpy(p_env->adapter_name,buf, count);
3116 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3117 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003118 CLAW_DBF_TEXT(2, setup, "AdnSet");
3119 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121 return count;
3122}
3123
3124static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3125
3126static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003127claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128{
3129 struct claw_privbk *priv;
3130 struct claw_env * p_env;
3131
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003132 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 if (!priv)
3134 return -ENODEV;
3135 p_env = priv->p_env;
3136 return sprintf(buf, "%s\n",
3137 p_env->api_type);
3138}
3139
3140static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003141claw_apname_write(struct device *dev, struct device_attribute *attr,
3142 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143{
3144 struct claw_privbk *priv;
3145 struct claw_env * p_env;
3146
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003147 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 if (!priv)
3149 return -ENODEV;
3150 p_env = priv->p_env;
3151 if (count > MAX_NAME_LEN+1)
3152 return -EINVAL;
3153 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3154 strncpy(p_env->api_type,buf, count);
3155 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3156 p_env->api_type[MAX_NAME_LEN] = 0x00;
3157 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3158 p_env->read_size=DEF_PACK_BUFSIZE;
3159 p_env->write_size=DEF_PACK_BUFSIZE;
3160 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003161 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 }
3163 else {
3164 p_env->packing=0;
3165 p_env->read_size=CLAW_FRAME_SIZE;
3166 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003167 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 }
Andy Richterb805da72008-07-18 15:24:56 +02003169 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 return count;
3171}
3172
3173static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3174
3175static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003176claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177{
3178 struct claw_privbk *priv;
3179 struct claw_env * p_env;
3180
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003181 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 if (!priv)
3183 return -ENODEV;
3184 p_env = priv->p_env;
3185 return sprintf(buf, "%d\n", p_env->write_buffers);
3186}
3187
3188static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003189claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3190 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191{
3192 struct claw_privbk *priv;
3193 struct claw_env * p_env;
3194 int nnn,max;
3195
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003196 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 if (!priv)
3198 return -ENODEV;
3199 p_env = priv->p_env;
3200 sscanf(buf, "%i", &nnn);
3201 if (p_env->packing) {
3202 max = 64;
3203 }
3204 else {
3205 max = 512;
3206 }
3207 if ((nnn > max ) || (nnn < 2))
3208 return -EINVAL;
3209 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003210 CLAW_DBF_TEXT(2, setup, "Wbufset");
3211 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 return count;
3213}
3214
3215static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3216
3217static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003218claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219{
3220 struct claw_privbk *priv;
3221 struct claw_env * p_env;
3222
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003223 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 if (!priv)
3225 return -ENODEV;
3226 p_env = priv->p_env;
3227 return sprintf(buf, "%d\n", p_env->read_buffers);
3228}
3229
3230static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003231claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3232 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233{
3234 struct claw_privbk *priv;
3235 struct claw_env *p_env;
3236 int nnn,max;
3237
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003238 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 if (!priv)
3240 return -ENODEV;
3241 p_env = priv->p_env;
3242 sscanf(buf, "%i", &nnn);
3243 if (p_env->packing) {
3244 max = 64;
3245 }
3246 else {
3247 max = 512;
3248 }
3249 if ((nnn > max ) || (nnn < 2))
3250 return -EINVAL;
3251 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003252 CLAW_DBF_TEXT(2, setup, "Rbufset");
3253 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 return count;
3255}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3257
3258static struct attribute *claw_attr[] = {
3259 &dev_attr_read_buffer.attr,
3260 &dev_attr_write_buffer.attr,
3261 &dev_attr_adapter_name.attr,
3262 &dev_attr_api_type.attr,
3263 &dev_attr_host_name.attr,
3264 NULL,
3265};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266static struct attribute_group claw_attr_group = {
3267 .attrs = claw_attr,
3268};
Sebastian Ott2ced5512012-05-15 18:00:49 +02003269static const struct attribute_group *claw_attr_groups[] = {
3270 &claw_attr_group,
3271 NULL,
3272};
3273static const struct device_type claw_devtype = {
3274 .name = "claw",
3275 .groups = claw_attr_groups,
3276};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
Sebastian Ott2ced5512012-05-15 18:00:49 +02003278/*----------------------------------------------------------------*
3279 * claw_probe *
3280 * this function is called for each CLAW device. *
3281 *----------------------------------------------------------------*/
3282static int claw_probe(struct ccwgroup_device *cgdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283{
Sebastian Ott2ced5512012-05-15 18:00:49 +02003284 struct claw_privbk *privptr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
Sebastian Ott2ced5512012-05-15 18:00:49 +02003286 CLAW_DBF_TEXT(2, setup, "probe");
3287 if (!get_device(&cgdev->dev))
3288 return -ENODEV;
3289 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
3290 dev_set_drvdata(&cgdev->dev, privptr);
3291 if (privptr == NULL) {
3292 probe_error(cgdev);
3293 put_device(&cgdev->dev);
3294 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3295 return -ENOMEM;
3296 }
3297 privptr->p_mtc_envelope = kzalloc(MAX_ENVELOPE_SIZE, GFP_KERNEL);
3298 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
3299 if ((privptr->p_mtc_envelope == NULL) || (privptr->p_env == NULL)) {
3300 probe_error(cgdev);
3301 put_device(&cgdev->dev);
3302 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3303 return -ENOMEM;
3304 }
3305 memcpy(privptr->p_env->adapter_name, WS_NAME_NOT_DEF, 8);
3306 memcpy(privptr->p_env->host_name, WS_NAME_NOT_DEF, 8);
3307 memcpy(privptr->p_env->api_type, WS_NAME_NOT_DEF, 8);
3308 privptr->p_env->packing = 0;
3309 privptr->p_env->write_buffers = 5;
3310 privptr->p_env->read_buffers = 5;
3311 privptr->p_env->read_size = CLAW_FRAME_SIZE;
3312 privptr->p_env->write_size = CLAW_FRAME_SIZE;
3313 privptr->p_env->p_priv = privptr;
3314 cgdev->cdev[0]->handler = claw_irq_handler;
3315 cgdev->cdev[1]->handler = claw_irq_handler;
3316 cgdev->dev.type = &claw_devtype;
3317 CLAW_DBF_TEXT(2, setup, "prbext 0");
3318
3319 return 0;
3320} /* end of claw_probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
3322/*--------------------------------------------------------------------*
3323* claw_init and cleanup *
3324*---------------------------------------------------------------------*/
3325
Sebastian Otta43f8de2012-05-15 18:06:29 +02003326static void __exit claw_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003328 ccwgroup_driver_unregister(&claw_group_driver);
3329 ccw_driver_unregister(&claw_ccw_driver);
3330 root_device_unregister(claw_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003332 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333}
3334
3335/**
3336 * Initialize module.
3337 * This is called just after the module is loaded.
3338 *
3339 * @return 0 on success, !0 on error.
3340 */
Sebastian Otta43f8de2012-05-15 18:06:29 +02003341static int __init claw_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342{
3343 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
Andy Richter4811fcb2009-01-20 06:14:33 +00003345 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 ret = claw_register_debug_facility();
3347 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003348 pr_err("Registering with the S/390 debug feature"
3349 " failed with error code %d\n", ret);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003350 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 }
Andy Richterb805da72008-07-18 15:24:56 +02003352 CLAW_DBF_TEXT(2, setup, "init_mod");
Ursula Braund950d172010-01-04 03:14:45 +00003353 claw_root_dev = root_device_register("claw");
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003354 ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0;
3355 if (ret)
3356 goto register_err;
3357 ret = ccw_driver_register(&claw_ccw_driver);
3358 if (ret)
3359 goto ccw_err;
Sebastian Otta43f8de2012-05-15 18:06:29 +02003360 claw_group_driver.driver.groups = claw_drv_attr_groups;
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003361 ret = ccwgroup_driver_register(&claw_group_driver);
3362 if (ret)
3363 goto ccwgroup_err;
3364 return 0;
3365
3366ccwgroup_err:
3367 ccw_driver_unregister(&claw_ccw_driver);
3368ccw_err:
3369 root_device_unregister(claw_root_dev);
3370register_err:
3371 CLAW_DBF_TEXT(2, setup, "init_bad");
3372 claw_unregister_debug_facility();
3373out_err:
3374 pr_err("Initializing the claw device driver failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 return ret;
3376}
3377
3378module_init(claw_init);
3379module_exit(claw_cleanup);
3380
Andy Richterb805da72008-07-18 15:24:56 +02003381MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3382MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3383 "Copyright 2000,2008 IBM Corporation\n");
3384MODULE_LICENSE("GPL");