blob: 4c3d4f67514983267b1641003fd66a2f7d47548d [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);
233static int claw_add_files(struct device *dev);
234static void claw_remove_files(struct device *dev);
235
236/* Functions for System Validate */
237static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
238static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
239 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
240static int claw_snd_conn_req(struct net_device *dev, __u8 link);
241static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
242static int claw_snd_sys_validate_rsp(struct net_device *dev,
243 struct clawctl * p_ctl, __u32 return_code);
244static int claw_strt_conn_req(struct net_device *dev );
Andy Richterb805da72008-07-18 15:24:56 +0200245static void claw_strt_read(struct net_device *dev, int lock);
246static void claw_strt_out_IO(struct net_device *dev);
247static void claw_free_wrt_buf(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249/* Functions for unpack reads */
Andy Richterb805da72008-07-18 15:24:56 +0200250static void unpack_read(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200252static int claw_pm_prepare(struct ccwgroup_device *gdev)
253{
254 return -EPERM;
255}
256
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000257/* the root device for claw group devices */
258static struct device *claw_root_dev;
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260/* ccwgroup table */
261
262static struct ccwgroup_driver claw_group_driver = {
Sebastian Ott3c190c52011-03-23 10:16:04 +0100263 .driver = {
264 .owner = THIS_MODULE,
265 .name = "claw",
266 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 .max_slaves = 2,
268 .driver_id = 0xC3D3C1E6,
269 .probe = claw_probe,
270 .remove = claw_remove_device,
271 .set_online = claw_new_device,
272 .set_offline = claw_shutdown_device,
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200273 .prepare = claw_pm_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274};
275
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000276static struct ccw_device_id claw_ids[] = {
277 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
278 {},
279};
280MODULE_DEVICE_TABLE(ccw, claw_ids);
281
282static struct ccw_driver claw_ccw_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +0100283 .driver = {
284 .owner = THIS_MODULE,
285 .name = "claw",
286 },
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000287 .ids = claw_ids,
288 .probe = ccwgroup_probe_ccwdev,
289 .remove = ccwgroup_remove_ccwdev,
Peter Oberparleiterde400d62011-10-30 15:16:04 +0100290 .int_class = IOINT_CLW,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000291};
292
293static ssize_t
294claw_driver_group_store(struct device_driver *ddrv, const char *buf,
295 size_t count)
296{
297 int err;
298 err = ccwgroup_create_from_string(claw_root_dev,
299 claw_group_driver.driver_id,
Ursula Braune48d24a2010-07-22 23:15:07 +0000300 &claw_ccw_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000301 return err ? err : count;
302}
303
304static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
305
306static struct attribute *claw_group_attrs[] = {
307 &driver_attr_group.attr,
308 NULL,
309};
310
311static struct attribute_group claw_group_attr_group = {
312 .attrs = claw_group_attrs,
313};
314
Heiko Carstens302689a2009-11-17 06:47:02 -0800315static const struct attribute_group *claw_group_attr_groups[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000316 &claw_group_attr_group,
317 NULL,
318};
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321* Key functions
322*/
323
324/*----------------------------------------------------------------*
325 * claw_probe *
326 * this function is called for each CLAW device. *
327 *----------------------------------------------------------------*/
328static int
329claw_probe(struct ccwgroup_device *cgdev)
330{
331 int rc;
332 struct claw_privbk *privptr=NULL;
333
Andy Richterb805da72008-07-18 15:24:56 +0200334 CLAW_DBF_TEXT(2, setup, "probe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (!get_device(&cgdev->dev))
336 return -ENODEV;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800337 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700338 dev_set_drvdata(&cgdev->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 if (privptr == NULL) {
340 probe_error(cgdev);
341 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200342 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 return -ENOMEM;
344 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700345 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
346 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
348 probe_error(cgdev);
349 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200350 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 return -ENOMEM;
352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
354 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
355 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
356 privptr->p_env->packing = 0;
357 privptr->p_env->write_buffers = 5;
358 privptr->p_env->read_buffers = 5;
359 privptr->p_env->read_size = CLAW_FRAME_SIZE;
360 privptr->p_env->write_size = CLAW_FRAME_SIZE;
361 rc = claw_add_files(&cgdev->dev);
362 if (rc) {
363 probe_error(cgdev);
364 put_device(&cgdev->dev);
Andy Richter4811fcb2009-01-20 06:14:33 +0000365 dev_err(&cgdev->dev, "Creating the /proc files for a new"
366 " CLAW device failed\n");
Andy Richterb805da72008-07-18 15:24:56 +0200367 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 return rc;
369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 privptr->p_env->p_priv = privptr;
371 cgdev->cdev[0]->handler = claw_irq_handler;
372 cgdev->cdev[1]->handler = claw_irq_handler;
Andy Richterb805da72008-07-18 15:24:56 +0200373 CLAW_DBF_TEXT(2, setup, "prbext 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 return 0;
376} /* end of claw_probe */
377
378/*-------------------------------------------------------------------*
379 * claw_tx *
380 *-------------------------------------------------------------------*/
381
382static int
383claw_tx(struct sk_buff *skb, struct net_device *dev)
384{
385 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200386 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 unsigned long saveflags;
388 struct chbk *p_ch;
389
Andy Richterb805da72008-07-18 15:24:56 +0200390 CLAW_DBF_TEXT(4, trace, "claw_tx");
Heiko Carstens319cb0832010-08-12 01:58:27 +0000391 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
393 rc=claw_hw_tx( skb, dev, 1 );
394 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200395 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000396 if (rc)
397 rc = NETDEV_TX_BUSY;
Patrick McHardyec634fe2009-07-05 19:23:38 -0700398 else
399 rc = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 return rc;
401} /* end of claw_tx */
402
403/*------------------------------------------------------------------*
404 * pack the collect queue into an skb and return it *
405 * If not packing just return the top skb from the queue *
406 *------------------------------------------------------------------*/
407
408static struct sk_buff *
409claw_pack_skb(struct claw_privbk *privptr)
410{
411 struct sk_buff *new_skb,*held_skb;
Heiko Carstens319cb0832010-08-12 01:58:27 +0000412 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 struct claw_env *p_env = privptr->p_env;
414 int pkt_cnt,pk_ind,so_far;
415
416 new_skb = NULL; /* assume no dice */
417 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200418 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700419 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 /* some data */
421 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200423 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 else
425 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200426 if (p_env->packing != DO_PACKED)
427 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 /* get a new SKB we will pack at least one */
429 new_skb = dev_alloc_skb(p_env->write_size);
430 if (new_skb == NULL) {
431 atomic_inc(&held_skb->users);
432 skb_queue_head(&p_ch->collect_queue,held_skb);
433 return NULL;
434 }
435 /* we have packed packet and a place to put it */
436 pk_ind = 1;
437 so_far = 0;
438 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
439 while ((pk_ind) && (held_skb != NULL)) {
440 if (held_skb->len+so_far <= p_env->write_size-8) {
441 memcpy(skb_put(new_skb,held_skb->len),
442 held_skb->data,held_skb->len);
443 privptr->stats.tx_packets++;
444 so_far += held_skb->len;
445 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200446 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 held_skb = skb_dequeue(&p_ch->collect_queue);
448 if (held_skb)
449 atomic_dec(&held_skb->users);
450 } else {
451 pk_ind = 0;
452 atomic_inc(&held_skb->users);
453 skb_queue_head(&p_ch->collect_queue,held_skb);
454 }
455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
Andy Richterb805da72008-07-18 15:24:56 +0200457 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return new_skb;
459}
460
461/*-------------------------------------------------------------------*
462 * claw_change_mtu *
463 * *
464 *-------------------------------------------------------------------*/
465
466static int
467claw_change_mtu(struct net_device *dev, int new_mtu)
468{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200469 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200471 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 buff_size = privptr->p_env->write_size;
473 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return -EINVAL;
475 }
476 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 return 0;
478} /* end of claw_change_mtu */
479
480
481/*-------------------------------------------------------------------*
482 * claw_open *
483 * *
484 *-------------------------------------------------------------------*/
485static int
486claw_open(struct net_device *dev)
487{
488
489 int rc;
490 int i;
491 unsigned long saveflags=0;
492 unsigned long parm;
493 struct claw_privbk *privptr;
494 DECLARE_WAITQUEUE(wait, current);
495 struct timer_list timer;
496 struct ccwbk *p_buf;
497
Andy Richterb805da72008-07-18 15:24:56 +0200498 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200499 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* allocate and initialize CCW blocks */
501 if (privptr->buffs_alloc == 0) {
502 rc=init_ccw_bk(dev);
503 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200504 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 return -ENOMEM;
506 }
507 }
508 privptr->system_validate_comp=0;
509 privptr->release_pend=0;
510 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
511 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
512 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
513 privptr->p_env->packing=PACKING_ASK;
514 } else {
515 privptr->p_env->packing=0;
516 privptr->p_env->read_size=CLAW_FRAME_SIZE;
517 privptr->p_env->write_size=CLAW_FRAME_SIZE;
518 }
519 claw_set_busy(dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +0000520 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
521 (unsigned long) &privptr->channel[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200523 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 init_waitqueue_head(&privptr->channel[i].wait);
525 /* skb_queue_head_init(&p_ch->io_queue); */
Heiko Carstens319cb0832010-08-12 01:58:27 +0000526 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 skb_queue_head_init(
Heiko Carstens319cb0832010-08-12 01:58:27 +0000528 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 privptr->channel[i].flag_a = 0;
530 privptr->channel[i].IO_active = 0;
531 privptr->channel[i].flag &= ~CLAW_TIMER;
532 init_timer(&timer);
533 timer.function = (void *)claw_timer;
534 timer.data = (unsigned long)(&privptr->channel[i]);
535 timer.expires = jiffies + 15*HZ;
536 add_timer(&timer);
537 spin_lock_irqsave(get_ccwdev_lock(
538 privptr->channel[i].cdev), saveflags);
539 parm = (unsigned long) &privptr->channel[i];
540 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
541 rc = 0;
542 add_wait_queue(&privptr->channel[i].wait, &wait);
543 rc = ccw_device_halt(
544 (struct ccw_device *)privptr->channel[i].cdev,parm);
545 set_current_state(TASK_INTERRUPTIBLE);
546 spin_unlock_irqrestore(
547 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
548 schedule();
549 set_current_state(TASK_RUNNING);
550 remove_wait_queue(&privptr->channel[i].wait, &wait);
551 if(rc != 0)
552 ccw_check_return_code(privptr->channel[i].cdev, rc);
553 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
554 del_timer(&timer);
555 }
Heiko Carstens319cb0832010-08-12 01:58:27 +0000556 if ((((privptr->channel[READ_CHANNEL].last_dstat |
557 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
Heiko Carstens319cb0832010-08-12 01:58:27 +0000559 (((privptr->channel[READ_CHANNEL].flag |
560 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
561 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000562 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200563 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 for ( i = 0; i < 2; i++) {
566 spin_lock_irqsave(
567 get_ccwdev_lock(privptr->channel[i].cdev),
568 saveflags);
569 parm = (unsigned long) &privptr->channel[i];
570 privptr->channel[i].claw_state = CLAW_STOP;
571 rc = ccw_device_halt(
572 (struct ccw_device *)&privptr->channel[i].cdev,
573 parm);
574 spin_unlock_irqrestore(
575 get_ccwdev_lock(privptr->channel[i].cdev),
576 saveflags);
577 if (rc != 0) {
578 ccw_check_return_code(
579 privptr->channel[i].cdev, rc);
580 }
581 }
582 free_pages((unsigned long)privptr->p_buff_ccw,
583 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
584 if (privptr->p_env->read_size < PAGE_SIZE) {
585 free_pages((unsigned long)privptr->p_buff_read,
586 (int)pages_to_order_of_mag(
587 privptr->p_buff_read_num));
588 }
589 else {
590 p_buf=privptr->p_read_active_first;
591 while (p_buf!=NULL) {
592 free_pages((unsigned long)p_buf->p_buffer,
593 (int)pages_to_order_of_mag(
594 privptr->p_buff_pages_perread ));
595 p_buf=p_buf->next;
596 }
597 }
598 if (privptr->p_env->write_size < PAGE_SIZE ) {
599 free_pages((unsigned long)privptr->p_buff_write,
600 (int)pages_to_order_of_mag(
601 privptr->p_buff_write_num));
602 }
603 else {
604 p_buf=privptr->p_write_active_first;
605 while (p_buf!=NULL) {
606 free_pages((unsigned long)p_buf->p_buffer,
607 (int)pages_to_order_of_mag(
608 privptr->p_buff_pages_perwrite ));
609 p_buf=p_buf->next;
610 }
611 }
612 privptr->buffs_alloc = 0;
Heiko Carstens319cb0832010-08-12 01:58:27 +0000613 privptr->channel[READ_CHANNEL].flag = 0x00;
614 privptr->channel[WRITE_CHANNEL].flag = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 privptr->p_buff_ccw=NULL;
616 privptr->p_buff_read=NULL;
617 privptr->p_buff_write=NULL;
618 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200619 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 return -EIO;
621 }
622
623 /* Send SystemValidate command */
624
625 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200626 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return 0;
628} /* end of claw_open */
629
630/*-------------------------------------------------------------------*
631* *
632* claw_irq_handler *
633* *
634*--------------------------------------------------------------------*/
635static void
636claw_irq_handler(struct ccw_device *cdev,
637 unsigned long intparm, struct irb *irb)
638{
639 struct chbk *p_ch = NULL;
640 struct claw_privbk *privptr = NULL;
641 struct net_device *dev = NULL;
642 struct claw_env *p_env;
643 struct chbk *p_ch_r=NULL;
644
Andy Richterb805da72008-07-18 15:24:56 +0200645 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 /* Bypass all 'unsolicited interrupts' */
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700647 privptr = dev_get_drvdata(&cdev->dev);
648 if (!privptr) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000649 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
650 " IRQ, c-%02x d-%02x\n",
651 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200652 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 return;
654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 /* Try to extract channel from driver data. */
Heiko Carstens319cb0832010-08-12 01:58:27 +0000657 if (privptr->channel[READ_CHANNEL].cdev == cdev)
658 p_ch = &privptr->channel[READ_CHANNEL];
659 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
660 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000662 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200663 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 return;
665 }
Andy Richterb805da72008-07-18 15:24:56 +0200666 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668 dev = (struct net_device *) (p_ch->ndev);
669 p_env=privptr->p_env;
670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 /* Copy interruption response block. */
672 memcpy(p_ch->irb, irb, sizeof(struct irb));
673
Andy Richterb805da72008-07-18 15:24:56 +0200674 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200675 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000676 dev_info(&cdev->dev,
677 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
679 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200680 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
681 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200682 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 /* return; */
684 }
685
686 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200687 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200691 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200694 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
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 return;
700 wake_up(&p_ch->wait); /* wake up claw_release */
701 CLAW_DBF_TEXT(4, trace, "stop");
702 return;
703 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
704 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
705 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
706 (p_ch->irb->scsw.cmd.stctl ==
707 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
708 CLAW_DBF_TEXT(4, trace, "haltio");
709 return;
710 }
711 if (p_ch->flag == CLAW_READ) {
712 p_ch->claw_state = CLAW_START_READ;
713 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
714 } else if (p_ch->flag == CLAW_WRITE) {
715 p_ch->claw_state = CLAW_START_WRITE;
Andy Richter4811fcb2009-01-20 06:14:33 +0000716 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200717 claw_strt_read(dev, LOCK_NO);
718 claw_send_control(dev,
719 SYSTEM_VALIDATE_REQUEST,
720 0, 0, 0,
721 p_env->host_name,
722 p_env->adapter_name);
723 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000724 dev_warn(&cdev->dev, "The CLAW device received"
725 " an unexpected IRQ, "
726 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200727 irb->scsw.cmd.cstat,
728 irb->scsw.cmd.dstat);
729 return;
730 }
731 CLAW_DBF_TEXT(4, trace, "haltio");
732 return;
733 case CLAW_START_READ:
734 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
735 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
736 clear_bit(0, (void *)&p_ch->IO_active);
737 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
738 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
739 (p_ch->irb->ecw[0]) == 0) {
740 privptr->stats.rx_errors++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000741 dev_info(&cdev->dev,
742 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200743 "side recovers \n",
744 dev->name);
745 }
746 CLAW_DBF_TEXT(4, trace, "notrdy");
747 return;
748 }
749 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
750 (p_ch->irb->scsw.cmd.dstat == 0)) {
751 if (test_and_set_bit(CLAW_BH_ACTIVE,
752 (void *)&p_ch->flag_a) == 0)
753 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 else
Andy Richterb805da72008-07-18 15:24:56 +0200755 CLAW_DBF_TEXT(4, trace, "PCINoBH");
756 CLAW_DBF_TEXT(4, trace, "PCI_read");
757 return;
758 }
759 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
760 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
761 (p_ch->irb->scsw.cmd.stctl ==
762 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
763 CLAW_DBF_TEXT(4, trace, "SPend_rd");
764 return;
765 }
766 clear_bit(0, (void *)&p_ch->IO_active);
767 claw_clearbit_busy(TB_RETRY, dev);
768 if (test_and_set_bit(CLAW_BH_ACTIVE,
769 (void *)&p_ch->flag_a) == 0)
770 tasklet_schedule(&p_ch->tasklet);
771 else
772 CLAW_DBF_TEXT(4, trace, "RdBHAct");
773 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
774 return;
775 case CLAW_START_WRITE:
776 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000777 dev_info(&cdev->dev,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300778 "%s: Unit Check Occurred in "
Andy Richterb805da72008-07-18 15:24:56 +0200779 "write channel\n", dev->name);
780 clear_bit(0, (void *)&p_ch->IO_active);
781 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000782 dev_info(&cdev->dev,
783 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200784 "occurred:\n", dev->name);
785 init_timer(&p_ch->timer);
786 p_ch->timer.function =
787 (void *)claw_write_retry;
788 p_ch->timer.data = (unsigned long)p_ch;
789 p_ch->timer.expires = jiffies + 10*HZ;
790 add_timer(&p_ch->timer);
Andy Richter4811fcb2009-01-20 06:14:33 +0000791 dev_info(&cdev->dev,
792 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200793 "restarting\n", dev->name);
794 }
795 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
796 return;
797 }
798 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
799 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000800 dev_info(&cdev->dev,
801 "%s: Unit Exception "
802 "occurred in write channel\n",
803 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200804 }
805 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
806 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
807 (p_ch->irb->scsw.cmd.stctl ==
808 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
809 CLAW_DBF_TEXT(4, trace, "writeUE");
810 return;
811 }
812 clear_bit(0, (void *)&p_ch->IO_active);
813 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
814 claw_write_next(p_ch);
815 claw_clearbit_busy(TB_TX, dev);
816 claw_clear_busy(dev);
817 }
Heiko Carstens319cb0832010-08-12 01:58:27 +0000818 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +0200819 if (test_and_set_bit(CLAW_BH_ACTIVE,
820 (void *)&p_ch_r->flag_a) == 0)
821 tasklet_schedule(&p_ch_r->tasklet);
822 CLAW_DBF_TEXT(4, trace, "StWtExit");
823 return;
824 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000825 dev_warn(&cdev->dev,
826 "The CLAW device for %s received an unexpected IRQ\n",
827 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200828 CLAW_DBF_TEXT(2, trace, "badIRQ");
829 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 }
831
832} /* end of claw_irq_handler */
833
834
835/*-------------------------------------------------------------------*
836* claw_irq_tasklet *
837* *
838*--------------------------------------------------------------------*/
839static void
840claw_irq_tasklet ( unsigned long data )
841{
842 struct chbk * p_ch;
843 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 p_ch = (struct chbk *) data;
846 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200847 CLAW_DBF_TEXT(4, trace, "IRQtask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 unpack_read(dev);
849 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200850 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 return;
852} /* end of claw_irq_bh */
853
854/*-------------------------------------------------------------------*
855* claw_release *
856* *
857*--------------------------------------------------------------------*/
858static int
859claw_release(struct net_device *dev)
860{
861 int rc;
862 int i;
863 unsigned long saveflags;
864 unsigned long parm;
865 struct claw_privbk *privptr;
866 DECLARE_WAITQUEUE(wait, current);
867 struct ccwbk* p_this_ccw;
868 struct ccwbk* p_buf;
869
870 if (!dev)
871 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200872 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 if (!privptr)
874 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200875 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 privptr->release_pend=1;
877 claw_setbit_busy(TB_STOP,dev);
878 for ( i = 1; i >=0 ; i--) {
879 spin_lock_irqsave(
880 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
Heiko Carstens319cb0832010-08-12 01:58:27 +0000881 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 privptr->channel[i].claw_state = CLAW_STOP;
883 privptr->channel[i].IO_active = 0;
884 parm = (unsigned long) &privptr->channel[i];
Heiko Carstens319cb0832010-08-12 01:58:27 +0000885 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 claw_purge_skb_queue(
Heiko Carstens319cb0832010-08-12 01:58:27 +0000887 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
889 if (privptr->system_validate_comp==0x00) /* never opened? */
890 init_waitqueue_head(&privptr->channel[i].wait);
891 add_wait_queue(&privptr->channel[i].wait, &wait);
892 set_current_state(TASK_INTERRUPTIBLE);
893 spin_unlock_irqrestore(
894 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
895 schedule();
896 set_current_state(TASK_RUNNING);
897 remove_wait_queue(&privptr->channel[i].wait, &wait);
898 if (rc != 0) {
899 ccw_check_return_code(privptr->channel[i].cdev, rc);
900 }
901 }
902 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200903 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 privptr->pk_skb = NULL;
905 }
906 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200907 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 return 0;
909 }
Andy Richterb805da72008-07-18 15:24:56 +0200910 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (privptr->p_buff_ccw != NULL) {
912 free_pages((unsigned long)privptr->p_buff_ccw,
913 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
914 }
Andy Richterb805da72008-07-18 15:24:56 +0200915 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (privptr->p_env->read_size < PAGE_SIZE) {
917 if (privptr->p_buff_read != NULL) {
918 free_pages((unsigned long)privptr->p_buff_read,
919 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
920 }
921 }
922 else {
923 p_buf=privptr->p_read_active_first;
924 while (p_buf!=NULL) {
925 free_pages((unsigned long)p_buf->p_buffer,
926 (int)pages_to_order_of_mag(
927 privptr->p_buff_pages_perread ));
928 p_buf=p_buf->next;
929 }
930 }
Andy Richterb805da72008-07-18 15:24:56 +0200931 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if (privptr->p_env->write_size < PAGE_SIZE ) {
933 free_pages((unsigned long)privptr->p_buff_write,
934 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
935 }
936 else {
937 p_buf=privptr->p_write_active_first;
938 while (p_buf!=NULL) {
939 free_pages((unsigned long)p_buf->p_buffer,
940 (int)pages_to_order_of_mag(
941 privptr->p_buff_pages_perwrite ));
942 p_buf=p_buf->next;
943 }
944 }
Andy Richterb805da72008-07-18 15:24:56 +0200945 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 privptr->buffs_alloc = 0;
947 privptr->p_buff_ccw=NULL;
948 privptr->p_buff_read=NULL;
949 privptr->p_buff_write=NULL;
950 privptr->system_validate_comp=0;
951 privptr->release_pend=0;
952 /* Remove any writes that were pending and reset all reads */
953 p_this_ccw=privptr->p_read_active_first;
954 while (p_this_ccw!=NULL) {
955 p_this_ccw->header.length=0xffff;
956 p_this_ccw->header.opcode=0xff;
957 p_this_ccw->header.flag=0x00;
958 p_this_ccw=p_this_ccw->next;
959 }
960
961 while (privptr->p_write_active_first!=NULL) {
962 p_this_ccw=privptr->p_write_active_first;
963 p_this_ccw->header.flag=CLAW_PENDING;
964 privptr->p_write_active_first=p_this_ccw->next;
965 p_this_ccw->next=privptr->p_write_free_chain;
966 privptr->p_write_free_chain=p_this_ccw;
967 ++privptr->write_free_count;
968 }
969 privptr->p_write_active_last=NULL;
970 privptr->mtc_logical_link = -1;
971 privptr->mtc_skipping = 1;
972 privptr->mtc_offset=0;
973
Heiko Carstens319cb0832010-08-12 01:58:27 +0000974 if (((privptr->channel[READ_CHANNEL].last_dstat |
975 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Heiko Carstens319cb0832010-08-12 01:58:27 +0000977 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000978 "Deactivating %s completed with incorrect"
979 " subchannel status "
980 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 dev->name,
Heiko Carstens319cb0832010-08-12 01:58:27 +0000982 privptr->channel[READ_CHANNEL].last_dstat,
983 privptr->channel[WRITE_CHANNEL].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200984 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 }
Andy Richterb805da72008-07-18 15:24:56 +0200986 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 return 0;
988} /* end of claw_release */
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990/*-------------------------------------------------------------------*
991* claw_write_retry *
992* *
993*--------------------------------------------------------------------*/
994
995static void
996claw_write_retry ( struct chbk *p_ch )
997{
998
999 struct net_device *dev=p_ch->ndev;
1000
Andy Richterb805da72008-07-18 15:24:56 +02001001 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 return;
1004 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +02001006 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 return;
1008} /* end of claw_write_retry */
1009
1010
1011/*-------------------------------------------------------------------*
1012* claw_write_next *
1013* *
1014*--------------------------------------------------------------------*/
1015
1016static void
1017claw_write_next ( struct chbk * p_ch )
1018{
1019
1020 struct net_device *dev;
1021 struct claw_privbk *privptr=NULL;
1022 struct sk_buff *pk_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Andy Richterb805da72008-07-18 15:24:56 +02001024 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 if (p_ch->claw_state == CLAW_STOP)
1026 return;
1027 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001028 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 claw_free_wrt_buf( dev );
1030 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -07001031 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 pk_skb = claw_pack_skb(privptr);
1033 while (pk_skb != NULL) {
Heiko Carstens38ed18f2011-05-12 18:45:04 +00001034 claw_hw_tx(pk_skb, dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (privptr->write_free_count > 0) {
1036 pk_skb = claw_pack_skb(privptr);
1037 } else
1038 pk_skb = NULL;
1039 }
1040 }
1041 if (privptr->p_write_active_first!=NULL) {
1042 claw_strt_out_IO(dev);
1043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 return;
1045} /* end of claw_write_next */
1046
1047/*-------------------------------------------------------------------*
1048* *
1049* claw_timer *
1050*--------------------------------------------------------------------*/
1051
1052static void
1053claw_timer ( struct chbk * p_ch )
1054{
Andy Richterb805da72008-07-18 15:24:56 +02001055 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 p_ch->flag |= CLAW_TIMER;
1057 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 return;
1059} /* end of claw_timer */
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061/*
1062*
1063* functions
1064*/
1065
1066
1067/*-------------------------------------------------------------------*
1068* *
1069* pages_to_order_of_mag *
1070* *
1071* takes a number of pages from 1 to 512 and returns the *
1072* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1073* of magnitude get_free_pages() has an upper order of 9 *
1074*--------------------------------------------------------------------*/
1075
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001076static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077pages_to_order_of_mag(int num_of_pages)
1078{
1079 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001080 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001081
1082 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1084 /* 512 pages = 2Meg on 4k page systems */
1085 if (num_of_pages >= 512) {return 9; }
1086 /* we have two or more pages order is at least 1 */
1087 for (nump=2 ;nump <= 512;nump*=2) {
1088 if (num_of_pages <= nump)
1089 break;
1090 order_of_mag +=1;
1091 }
1092 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001093 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 return order_of_mag;
1095}
1096
1097/*-------------------------------------------------------------------*
1098* *
1099* add_claw_reads *
1100* *
1101*--------------------------------------------------------------------*/
1102static int
1103add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1104 struct ccwbk* p_last)
1105{
1106 struct claw_privbk *privptr;
1107 struct ccw1 temp_ccw;
1108 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001109 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001110 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 p_end = privptr->p_end_ccw;
1112
1113 /* first CCW and last CCW contains a new set of read channel programs
1114 * to apend the running channel programs
1115 */
1116 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001117 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 return 0;
1119 }
1120
1121 /* set up ending CCW sequence for this segment */
1122 if (p_end->read1) {
1123 p_end->read1=0x00; /* second ending CCW is now active */
1124 /* reset ending CCWs and setup TIC CCWs */
1125 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1126 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1127 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1128 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1129 p_end->read2_nop2.cda=0;
1130 p_end->read2_nop2.count=1;
1131 }
1132 else {
1133 p_end->read1=0x01; /* first ending CCW is now active */
1134 /* reset ending CCWs and setup TIC CCWs */
1135 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1136 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1137 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1138 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1139 p_end->read1_nop2.cda=0;
1140 p_end->read1_nop2.count=1;
1141 }
1142
1143 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001144 privptr->p_read_active_first = p_first; /* set new first */
1145 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 }
1147 else {
1148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 /* set up TIC ccw */
1150 temp_ccw.cda= (__u32)__pa(&p_first->read);
1151 temp_ccw.count=0;
1152 temp_ccw.flags=0;
1153 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1154
1155
1156 if (p_end->read1) {
1157
1158 /* first set of CCW's is chained to the new read */
1159 /* chain, so the second set is chained to the active chain. */
1160 /* Therefore modify the second set to point to the new */
1161 /* read chain set up TIC CCWs */
1162 /* make sure we update the CCW so channel doesn't fetch it */
1163 /* when it's only half done */
1164 memcpy( &p_end->read2_nop2, &temp_ccw ,
1165 sizeof(struct ccw1));
1166 privptr->p_read_active_last->r_TIC_1.cda=
1167 (__u32)__pa(&p_first->read);
1168 privptr->p_read_active_last->r_TIC_2.cda=
1169 (__u32)__pa(&p_first->read);
1170 }
1171 else {
1172 /* make sure we update the CCW so channel doesn't */
1173 /* fetch it when it is only half done */
1174 memcpy( &p_end->read1_nop2, &temp_ccw ,
1175 sizeof(struct ccw1));
1176 privptr->p_read_active_last->r_TIC_1.cda=
1177 (__u32)__pa(&p_first->read);
1178 privptr->p_read_active_last->r_TIC_2.cda=
1179 (__u32)__pa(&p_first->read);
1180 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001181 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 privptr->p_read_active_last->next = p_first;
1183 privptr->p_read_active_last=p_last;
1184 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001185 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 return 0;
1187} /* end of add_claw_reads */
1188
1189/*-------------------------------------------------------------------*
1190 * ccw_check_return_code *
1191 * *
1192 *-------------------------------------------------------------------*/
1193
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001194static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195ccw_check_return_code(struct ccw_device *cdev, int return_code)
1196{
Andy Richterb805da72008-07-18 15:24:56 +02001197 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 if (return_code != 0) {
1199 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001200 case -EBUSY: /* BUSY is a transient state no action needed */
1201 break;
1202 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001203 dev_err(&cdev->dev, "The remote channel adapter is not"
1204 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001205 break;
1206 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001207 dev_err(&cdev->dev,
1208 "The status of the remote channel adapter"
1209 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001210 break;
1211 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001212 dev_err(&cdev->dev, "The common device layer"
1213 " returned error code %d\n",
1214 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001215 }
1216 }
1217 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218} /* end of ccw_check_return_code */
1219
1220/*-------------------------------------------------------------------*
1221* ccw_check_unit_check *
1222*--------------------------------------------------------------------*/
1223
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001224static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1226{
Andy Richterb805da72008-07-18 15:24:56 +02001227 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001228 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Andy Richterb805da72008-07-18 15:24:56 +02001230 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001231 dev_warn(dev, "The communication peer of %s disconnected\n",
1232 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001234 if (sense & 0x40) {
1235 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001236 dev_warn(dev, "The remote channel adapter for"
1237 " %s has been reset\n",
1238 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001239 }
1240 } else if (sense & 0x20) {
1241 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001242 dev_warn(dev, "A data streaming timeout occurred"
1243 " for %s\n",
1244 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001245 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001246 dev_warn(dev, "The remote channel adapter for %s"
1247 " is faulty\n",
1248 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001249 } else {
1250 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001251 " for %s\n",
1252 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001253 }
1254 } else if (sense & 0x10) {
1255 dev_warn(dev, "A read data parity error occurred"
1256 " for %s\n",
1257 ndev->name);
1258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260} /* end of ccw_check_unit_check */
1261
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262/*-------------------------------------------------------------------*
1263* find_link *
1264*--------------------------------------------------------------------*/
1265static int
1266find_link(struct net_device *dev, char *host_name, char *ws_name )
1267{
1268 struct claw_privbk *privptr;
1269 struct claw_env *p_env;
1270 int rc=0;
1271
Andy Richterb805da72008-07-18 15:24:56 +02001272 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001273 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 p_env=privptr->p_env;
1275 switch (p_env->packing)
1276 {
1277 case PACKING_ASK:
1278 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1279 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1280 rc = EINVAL;
1281 break;
1282 case DO_PACKED:
1283 case PACK_SEND:
1284 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1285 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1286 rc = EINVAL;
1287 break;
1288 default:
1289 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1290 (memcmp(p_env->api_type , ws_name, 8)!=0))
1291 rc = EINVAL;
1292 break;
1293 }
1294
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001295 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296} /* end of find_link */
1297
1298/*-------------------------------------------------------------------*
1299 * claw_hw_tx *
1300 * *
1301 * *
1302 *-------------------------------------------------------------------*/
1303
1304static int
1305claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1306{
1307 int rc=0;
1308 struct claw_privbk *privptr;
1309 struct ccwbk *p_this_ccw;
1310 struct ccwbk *p_first_ccw;
1311 struct ccwbk *p_last_ccw;
1312 __u32 numBuffers;
1313 signed long len_of_data;
1314 unsigned long bytesInThisBuffer;
1315 unsigned char *pDataAddress;
1316 struct endccw *pEnd;
1317 struct ccw1 tempCCW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 struct claw_env *p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 struct clawph *pk_head;
1320 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001321
1322 CLAW_DBF_TEXT(4, trace, "hw_tx");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001323 privptr = (struct claw_privbk *)(dev->ml_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1326 /* scan the write queue to free any completed write packets */
1327 p_first_ccw=NULL;
1328 p_last_ccw=NULL;
1329 if ((p_env->packing >= PACK_SEND) &&
1330 (skb->cb[1] != 'P')) {
1331 skb_push(skb,sizeof(struct clawph));
1332 pk_head=(struct clawph *)skb->data;
1333 pk_head->len=skb->len-sizeof(struct clawph);
1334 if (pk_head->len%4) {
1335 pk_head->len+= 4-(pk_head->len%4);
1336 skb_pad(skb,4-(pk_head->len%4));
1337 skb_put(skb,4-(pk_head->len%4));
1338 }
1339 if (p_env->packing == DO_PACKED)
1340 pk_head->link_num = linkid;
1341 else
1342 pk_head->link_num = 0;
1343 pk_head->flag = 0x00;
1344 skb_pad(skb,4);
1345 skb->cb[1] = 'P';
1346 }
1347 if (linkid == 0) {
1348 if (claw_check_busy(dev)) {
1349 if (privptr->write_free_count!=0) {
1350 claw_clear_busy(dev);
1351 }
1352 else {
1353 claw_strt_out_IO(dev );
1354 claw_free_wrt_buf( dev );
1355 if (privptr->write_free_count==0) {
Heiko Carstens319cb0832010-08-12 01:58:27 +00001356 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 atomic_inc(&skb->users);
1358 skb_queue_tail(&ch->collect_queue, skb);
1359 goto Done;
1360 }
1361 else {
1362 claw_clear_busy(dev);
1363 }
1364 }
1365 }
1366 /* tx lock */
1367 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Heiko Carstens319cb0832010-08-12 01:58:27 +00001368 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 atomic_inc(&skb->users);
1370 skb_queue_tail(&ch->collect_queue, skb);
1371 claw_strt_out_IO(dev );
1372 rc=-EBUSY;
1373 goto Done2;
1374 }
1375 }
1376 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001377 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
1379 /* If that number of buffers isn't available, give up for now */
1380 if (privptr->write_free_count < numBuffers ||
1381 privptr->p_write_free_chain == NULL ) {
1382
1383 claw_setbit_busy(TB_NOBUFFER,dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +00001384 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 atomic_inc(&skb->users);
1386 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001387 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 goto Done2;
1389 }
1390 pDataAddress=skb->data;
1391 len_of_data=skb->len;
1392
1393 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1395 if (p_this_ccw == NULL) { /* lost the race */
Heiko Carstens319cb0832010-08-12 01:58:27 +00001396 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 atomic_inc(&skb->users);
1398 skb_queue_tail(&ch->collect_queue, skb);
1399 goto Done2;
1400 }
1401 privptr->p_write_free_chain=p_this_ccw->next;
1402 p_this_ccw->next=NULL;
1403 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001404 if (len_of_data >= privptr->p_env->write_size)
1405 bytesInThisBuffer = privptr->p_env->write_size;
1406 else
1407 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1409 len_of_data-=bytesInThisBuffer;
1410 pDataAddress+=(unsigned long)bytesInThisBuffer;
1411 /* setup write CCW */
1412 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1413 if (len_of_data>0) {
1414 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1415 }
1416 p_this_ccw->write.count=bytesInThisBuffer;
1417 /* now add to end of this chain */
1418 if (p_first_ccw==NULL) {
1419 p_first_ccw=p_this_ccw;
1420 }
1421 if (p_last_ccw!=NULL) {
1422 p_last_ccw->next=p_this_ccw;
1423 /* set up TIC ccws */
1424 p_last_ccw->w_TIC_1.cda=
1425 (__u32)__pa(&p_this_ccw->write);
1426 }
1427 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 }
1429
1430 /* FirstCCW and LastCCW now contain a new set of write channel
1431 * programs to append to the running channel program
1432 */
1433
1434 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001435 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 pEnd=privptr->p_end_ccw;
1437 if (pEnd->write1) {
1438 pEnd->write1=0x00; /* second end ccw is now active */
1439 /* set up Tic CCWs */
1440 p_last_ccw->w_TIC_1.cda=
1441 (__u32)__pa(&pEnd->write2_nop1);
1442 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1443 pEnd->write2_nop2.flags =
1444 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1445 pEnd->write2_nop2.cda=0;
1446 pEnd->write2_nop2.count=1;
1447 }
1448 else { /* end of if (pEnd->write1)*/
1449 pEnd->write1=0x01; /* first end ccw is now active */
1450 /* set up Tic CCWs */
1451 p_last_ccw->w_TIC_1.cda=
1452 (__u32)__pa(&pEnd->write1_nop1);
1453 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1454 pEnd->write1_nop2.flags =
1455 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1456 pEnd->write1_nop2.cda=0;
1457 pEnd->write1_nop2.count=1;
1458 } /* end if if (pEnd->write1) */
1459
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 if (privptr->p_write_active_first==NULL ) {
1461 privptr->p_write_active_first=p_first_ccw;
1462 privptr->p_write_active_last=p_last_ccw;
1463 }
1464 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 /* set up Tic CCWs */
1466
1467 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1468 tempCCW.count=0;
1469 tempCCW.flags=0;
1470 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1471
1472 if (pEnd->write1) {
1473
1474 /*
1475 * first set of ending CCW's is chained to the new write
1476 * chain, so the second set is chained to the active chain
1477 * Therefore modify the second set to point the new write chain.
1478 * make sure we update the CCW atomically
1479 * so channel does not fetch it when it's only half done
1480 */
1481 memcpy( &pEnd->write2_nop2, &tempCCW ,
1482 sizeof(struct ccw1));
1483 privptr->p_write_active_last->w_TIC_1.cda=
1484 (__u32)__pa(&p_first_ccw->write);
1485 }
1486 else {
1487
1488 /*make sure we update the CCW atomically
1489 *so channel does not fetch it when it's only half done
1490 */
1491 memcpy(&pEnd->write1_nop2, &tempCCW ,
1492 sizeof(struct ccw1));
1493 privptr->p_write_active_last->w_TIC_1.cda=
1494 (__u32)__pa(&p_first_ccw->write);
1495
1496 } /* end if if (pEnd->write1) */
1497
1498 privptr->p_write_active_last->next=p_first_ccw;
1499 privptr->p_write_active_last=p_last_ccw;
1500 }
1501
1502 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001503 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 claw_strt_out_IO(dev );
1505 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 if (privptr->write_free_count==0) {
1507 claw_setbit_busy(TB_NOBUFFER,dev);
1508 }
1509Done2:
1510 claw_clearbit_busy(TB_TX,dev);
1511Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 return(rc);
1513} /* end of claw_hw_tx */
1514
1515/*-------------------------------------------------------------------*
1516* *
1517* init_ccw_bk *
1518* *
1519*--------------------------------------------------------------------*/
1520
1521static int
1522init_ccw_bk(struct net_device *dev)
1523{
1524
1525 __u32 ccw_blocks_required;
1526 __u32 ccw_blocks_perpage;
1527 __u32 ccw_pages_required;
1528 __u32 claw_reads_perpage=1;
1529 __u32 claw_read_pages;
1530 __u32 claw_writes_perpage=1;
1531 __u32 claw_write_pages;
1532 void *p_buff=NULL;
1533 struct ccwbk*p_free_chain;
1534 struct ccwbk*p_buf;
1535 struct ccwbk*p_last_CCWB;
1536 struct ccwbk*p_first_CCWB;
1537 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001538 addr_t real_address;
1539 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 struct clawh *pClawH=NULL;
1541 addr_t real_TIC_address;
1542 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001543 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
1545 /* initialize statistics field */
1546 privptr->active_link_ID=0;
1547 /* initialize ccwbk pointers */
1548 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1549 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1550 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1551 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1552 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1553 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1554 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1555 privptr->buffs_alloc = 0;
1556 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1557 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1558 /* initialize free write ccwbk counter */
1559 privptr->write_free_count=0; /* number of free bufs on write chain */
1560 p_last_CCWB = NULL;
1561 p_first_CCWB= NULL;
1562 /*
1563 * We need 1 CCW block for each read buffer, 1 for each
1564 * write buffer, plus 1 for ClawSignalBlock
1565 */
1566 ccw_blocks_required =
1567 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 /*
1569 * compute number of CCW blocks that will fit in a page
1570 */
1571 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1572 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001573 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 /*
1576 * read and write sizes are set by 2 constants in claw.h
1577 * 4k and 32k. Unpacked values other than 4k are not going to
1578 * provide good performance. With packing buffers support 32k
1579 * buffers are used.
1580 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001581 if (privptr->p_env->read_size < PAGE_SIZE) {
1582 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1583 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1584 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 }
1586 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001587 privptr->p_buff_pages_perread =
1588 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1589 claw_read_pages = privptr->p_env->read_buffers *
1590 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 }
1592 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001593 claw_writes_perpage =
1594 PAGE_SIZE / privptr->p_env->write_size;
1595 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1596 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
1598 }
1599 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001600 privptr->p_buff_pages_perwrite =
1601 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1602 claw_write_pages = privptr->p_env->write_buffers *
1603 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 /*
1606 * allocate ccw_pages_required
1607 */
1608 if (privptr->p_buff_ccw==NULL) {
1609 privptr->p_buff_ccw=
1610 (void *)__get_free_pages(__GFP_DMA,
1611 (int)pages_to_order_of_mag(ccw_pages_required ));
1612 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 return -ENOMEM;
1614 }
1615 privptr->p_buff_ccw_num=ccw_pages_required;
1616 }
1617 memset(privptr->p_buff_ccw, 0x00,
1618 privptr->p_buff_ccw_num * PAGE_SIZE);
1619
1620 /*
1621 * obtain ending ccw block address
1622 *
1623 */
1624 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1625 real_address = (__u32)__pa(privptr->p_end_ccw);
1626 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 p_endccw=privptr->p_end_ccw;
1628 p_endccw->real=real_address;
1629 p_endccw->write1=0x00;
1630 p_endccw->read1=0x00;
1631
1632 /* write1_nop1 */
1633 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1634 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1635 p_endccw->write1_nop1.count = 1;
1636 p_endccw->write1_nop1.cda = 0;
1637
1638 /* write1_nop2 */
1639 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1640 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1641 p_endccw->write1_nop2.count = 1;
1642 p_endccw->write1_nop2.cda = 0;
1643
1644 /* write2_nop1 */
1645 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1646 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1647 p_endccw->write2_nop1.count = 1;
1648 p_endccw->write2_nop1.cda = 0;
1649
1650 /* write2_nop2 */
1651 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1652 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1653 p_endccw->write2_nop2.count = 1;
1654 p_endccw->write2_nop2.cda = 0;
1655
1656 /* read1_nop1 */
1657 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1658 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1659 p_endccw->read1_nop1.count = 1;
1660 p_endccw->read1_nop1.cda = 0;
1661
1662 /* read1_nop2 */
1663 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1664 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1665 p_endccw->read1_nop2.count = 1;
1666 p_endccw->read1_nop2.cda = 0;
1667
1668 /* read2_nop1 */
1669 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1670 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1671 p_endccw->read2_nop1.count = 1;
1672 p_endccw->read2_nop1.cda = 0;
1673
1674 /* read2_nop2 */
1675 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1676 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1677 p_endccw->read2_nop2.count = 1;
1678 p_endccw->read2_nop2.cda = 0;
1679
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 /*
1681 * Build a chain of CCWs
1682 *
1683 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 p_buff=privptr->p_buff_ccw;
1685
1686 p_free_chain=NULL;
1687 for (i=0 ; i < ccw_pages_required; i++ ) {
1688 real_address = (__u32)__pa(p_buff);
1689 p_buf=p_buff;
1690 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1691 p_buf->next = p_free_chain;
1692 p_free_chain = p_buf;
1693 p_buf->real=(__u32)__pa(p_buf);
1694 ++p_buf;
1695 }
1696 p_buff+=PAGE_SIZE;
1697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 /*
1699 * Initialize ClawSignalBlock
1700 *
1701 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 if (privptr->p_claw_signal_blk==NULL) {
1703 privptr->p_claw_signal_blk=p_free_chain;
1704 p_free_chain=p_free_chain->next;
1705 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1706 pClawH->length=0xffff;
1707 pClawH->opcode=0xff;
1708 pClawH->flag=CLAW_BUSY;
1709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
1711 /*
1712 * allocate write_pages_required and add to free chain
1713 */
1714 if (privptr->p_buff_write==NULL) {
1715 if (privptr->p_env->write_size < PAGE_SIZE) {
1716 privptr->p_buff_write=
1717 (void *)__get_free_pages(__GFP_DMA,
1718 (int)pages_to_order_of_mag(claw_write_pages ));
1719 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 return -ENOMEM;
1722 }
1723 /*
1724 * Build CLAW write free chain
1725 *
1726 */
1727
1728 memset(privptr->p_buff_write, 0x00,
1729 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 privptr->p_write_free_chain=NULL;
1731
1732 p_buff=privptr->p_buff_write;
1733
1734 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1735 p_buf = p_free_chain; /* get a CCW */
1736 p_free_chain = p_buf->next;
1737 p_buf->next =privptr->p_write_free_chain;
1738 privptr->p_write_free_chain = p_buf;
1739 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1740 p_buf-> write.cda = (__u32)__pa(p_buff);
1741 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1742 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1743 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1744 p_buf-> w_read_FF.count = 1;
1745 p_buf-> w_read_FF.cda =
1746 (__u32)__pa(&p_buf-> header.flag);
1747 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1748 p_buf-> w_TIC_1.flags = 0;
1749 p_buf-> w_TIC_1.count = 0;
1750
Andy Richter4811fcb2009-01-20 06:14:33 +00001751 if (((unsigned long)p_buff +
1752 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001754 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1755 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 }
1757 }
1758 }
1759 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1760 {
1761 privptr->p_write_free_chain=NULL;
1762 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1763 p_buff=(void *)__get_free_pages(__GFP_DMA,
1764 (int)pages_to_order_of_mag(
1765 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 free_pages((unsigned long)privptr->p_buff_ccw,
1768 (int)pages_to_order_of_mag(
1769 privptr->p_buff_ccw_num));
1770 privptr->p_buff_ccw=NULL;
1771 p_buf=privptr->p_buff_write;
1772 while (p_buf!=NULL) {
1773 free_pages((unsigned long)
1774 p_buf->p_buffer,
1775 (int)pages_to_order_of_mag(
1776 privptr->p_buff_pages_perwrite));
1777 p_buf=p_buf->next;
1778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 return -ENOMEM;
1780 } /* Error on get_pages */
1781 memset(p_buff, 0x00, privptr->p_env->write_size );
1782 p_buf = p_free_chain;
1783 p_free_chain = p_buf->next;
1784 p_buf->next = privptr->p_write_free_chain;
1785 privptr->p_write_free_chain = p_buf;
1786 privptr->p_buff_write = p_buf;
1787 p_buf->p_buffer=(struct clawbuf *)p_buff;
1788 p_buf-> write.cda = (__u32)__pa(p_buff);
1789 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1790 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1791 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1792 p_buf-> w_read_FF.count = 1;
1793 p_buf-> w_read_FF.cda =
1794 (__u32)__pa(&p_buf-> header.flag);
1795 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1796 p_buf-> w_TIC_1.flags = 0;
1797 p_buf-> w_TIC_1.count = 0;
1798 } /* for all write_buffers */
1799
1800 } /* else buffers are PAGE_SIZE or bigger */
1801
1802 }
1803 privptr->p_buff_write_num=claw_write_pages;
1804 privptr->write_free_count=privptr->p_env->write_buffers;
1805
1806
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 /*
1808 * allocate read_pages_required and chain to free chain
1809 */
1810 if (privptr->p_buff_read==NULL) {
1811 if (privptr->p_env->read_size < PAGE_SIZE) {
1812 privptr->p_buff_read=
1813 (void *)__get_free_pages(__GFP_DMA,
1814 (int)pages_to_order_of_mag(claw_read_pages) );
1815 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 free_pages((unsigned long)privptr->p_buff_ccw,
1817 (int)pages_to_order_of_mag(
1818 privptr->p_buff_ccw_num));
1819 /* free the write pages size is < page size */
1820 free_pages((unsigned long)privptr->p_buff_write,
1821 (int)pages_to_order_of_mag(
1822 privptr->p_buff_write_num));
1823 privptr->p_buff_ccw=NULL;
1824 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 return -ENOMEM;
1826 }
1827 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1828 privptr->p_buff_read_num=claw_read_pages;
1829 /*
1830 * Build CLAW read free chain
1831 *
1832 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 p_buff=privptr->p_buff_read;
1834 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1835 p_buf = p_free_chain;
1836 p_free_chain = p_buf->next;
1837
1838 if (p_last_CCWB==NULL) {
1839 p_buf->next=NULL;
1840 real_TIC_address=0;
1841 p_last_CCWB=p_buf;
1842 }
1843 else {
1844 p_buf->next=p_first_CCWB;
1845 real_TIC_address=
1846 (__u32)__pa(&p_first_CCWB -> read );
1847 }
1848
1849 p_first_CCWB=p_buf;
1850
1851 p_buf->p_buffer=(struct clawbuf *)p_buff;
1852 /* initialize read command */
1853 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1854 p_buf-> read.cda = (__u32)__pa(p_buff);
1855 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1856 p_buf-> read.count = privptr->p_env->read_size;
1857
1858 /* initialize read_h command */
1859 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1860 p_buf-> read_h.cda =
1861 (__u32)__pa(&(p_buf->header));
1862 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1863 p_buf-> read_h.count = sizeof(struct clawh);
1864
1865 /* initialize Signal command */
1866 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1867 p_buf-> signal.cda =
1868 (__u32)__pa(&(pClawH->flag));
1869 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1870 p_buf-> signal.count = 1;
1871
1872 /* initialize r_TIC_1 command */
1873 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1874 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1875 p_buf-> r_TIC_1.flags = 0;
1876 p_buf-> r_TIC_1.count = 0;
1877
1878 /* initialize r_read_FF command */
1879 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1880 p_buf-> r_read_FF.cda =
1881 (__u32)__pa(&(pClawH->flag));
1882 p_buf-> r_read_FF.flags =
1883 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1884 p_buf-> r_read_FF.count = 1;
1885
1886 /* initialize r_TIC_2 */
1887 memcpy(&p_buf->r_TIC_2,
1888 &p_buf->r_TIC_1, sizeof(struct ccw1));
1889
1890 /* initialize Header */
1891 p_buf->header.length=0xffff;
1892 p_buf->header.opcode=0xff;
1893 p_buf->header.flag=CLAW_PENDING;
1894
Andy Richter4811fcb2009-01-20 06:14:33 +00001895 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1896 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1897 -1)
1898 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 p_buff= p_buff+privptr->p_env->read_size;
1900 }
1901 else {
1902 p_buff=
1903 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001904 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 & PAGE_MASK) ;
1906 }
1907 } /* for read_buffers */
1908 } /* read_size < PAGE_SIZE */
1909 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1911 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001912 (int)pages_to_order_of_mag(
1913 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001916 (int)pages_to_order_of_mag(privptr->
1917 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 /* free the write pages */
1919 p_buf=privptr->p_buff_write;
1920 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001921 free_pages(
1922 (unsigned long)p_buf->p_buffer,
1923 (int)pages_to_order_of_mag(
1924 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 p_buf=p_buf->next;
1926 }
1927 /* free any read pages already alloc */
1928 p_buf=privptr->p_buff_read;
1929 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001930 free_pages(
1931 (unsigned long)p_buf->p_buffer,
1932 (int)pages_to_order_of_mag(
1933 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 p_buf=p_buf->next;
1935 }
1936 privptr->p_buff_ccw=NULL;
1937 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 return -ENOMEM;
1939 }
1940 memset(p_buff, 0x00, privptr->p_env->read_size);
1941 p_buf = p_free_chain;
1942 privptr->p_buff_read = p_buf;
1943 p_free_chain = p_buf->next;
1944
1945 if (p_last_CCWB==NULL) {
1946 p_buf->next=NULL;
1947 real_TIC_address=0;
1948 p_last_CCWB=p_buf;
1949 }
1950 else {
1951 p_buf->next=p_first_CCWB;
1952 real_TIC_address=
1953 (addr_t)__pa(
1954 &p_first_CCWB -> read );
1955 }
1956
1957 p_first_CCWB=p_buf;
1958 /* save buff address */
1959 p_buf->p_buffer=(struct clawbuf *)p_buff;
1960 /* initialize read command */
1961 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1962 p_buf-> read.cda = (__u32)__pa(p_buff);
1963 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1964 p_buf-> read.count = privptr->p_env->read_size;
1965
1966 /* initialize read_h command */
1967 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1968 p_buf-> read_h.cda =
1969 (__u32)__pa(&(p_buf->header));
1970 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1971 p_buf-> read_h.count = sizeof(struct clawh);
1972
1973 /* initialize Signal command */
1974 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1975 p_buf-> signal.cda =
1976 (__u32)__pa(&(pClawH->flag));
1977 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1978 p_buf-> signal.count = 1;
1979
1980 /* initialize r_TIC_1 command */
1981 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1982 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1983 p_buf-> r_TIC_1.flags = 0;
1984 p_buf-> r_TIC_1.count = 0;
1985
1986 /* initialize r_read_FF command */
1987 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1988 p_buf-> r_read_FF.cda =
1989 (__u32)__pa(&(pClawH->flag));
1990 p_buf-> r_read_FF.flags =
1991 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1992 p_buf-> r_read_FF.count = 1;
1993
1994 /* initialize r_TIC_2 */
1995 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1996 sizeof(struct ccw1));
1997
1998 /* initialize Header */
1999 p_buf->header.length=0xffff;
2000 p_buf->header.opcode=0xff;
2001 p_buf->header.flag=CLAW_PENDING;
2002
2003 } /* For read_buffers */
2004 } /* read_size >= PAGE_SIZE */
2005 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
2007 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02002008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 return 0;
2010} /* end of init_ccw_bk */
2011
2012/*-------------------------------------------------------------------*
2013* *
2014* probe_error *
2015* *
2016*--------------------------------------------------------------------*/
2017
2018static void
2019probe_error( struct ccwgroup_device *cgdev)
2020{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002021 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002022
2023 CLAW_DBF_TEXT(4, trace, "proberr");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002024 privptr = dev_get_drvdata(&cgdev->dev);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002025 if (privptr != NULL) {
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002026 dev_set_drvdata(&cgdev->dev, NULL);
Jesper Juhl17fd6822005-11-07 01:01:30 -08002027 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002028 kfree(privptr->p_mtc_envelope);
2029 kfree(privptr);
2030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031} /* probe_error */
2032
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033/*-------------------------------------------------------------------*
2034* claw_process_control *
2035* *
2036* *
2037*--------------------------------------------------------------------*/
2038
2039static int
2040claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2041{
2042
2043 struct clawbuf *p_buf;
2044 struct clawctl ctlbk;
2045 struct clawctl *p_ctlbk;
2046 char temp_host_name[8];
2047 char temp_ws_name[8];
2048 struct claw_privbk *privptr;
2049 struct claw_env *p_env;
2050 struct sysval *p_sysval;
2051 struct conncmd *p_connect=NULL;
2052 int rc;
2053 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002054 struct device *tdev;
2055 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 udelay(1000); /* Wait a ms for the control packets to
2057 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02002058 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 p_env=privptr->p_env;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002060 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 memcpy( &temp_host_name, p_env->host_name, 8);
2062 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00002063 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 "Received Control Packet\n",
2065 dev->name, temp_ws_name);
2066 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 return 0;
2068 }
2069 p_buf=p_ccw->p_buffer;
2070 p_ctlbk=&ctlbk;
2071 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2072 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2073 } else {
2074 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 switch (p_ctlbk->command)
2077 {
Andy Richterb805da72008-07-18 15:24:56 +02002078 case SYSTEM_VALIDATE_REQUEST:
2079 if (p_ctlbk->version != CLAW_VERSION_ID) {
2080 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2081 CLAW_RC_WRONG_VERSION);
Andy Richter4811fcb2009-01-20 06:14:33 +00002082 dev_warn(tdev, "The communication peer of %s"
2083 " uses an incorrect API version %d\n",
2084 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002085 }
2086 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002087 dev_info(tdev, "%s: Recv Sys Validate Request: "
2088 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2089 "Host name=%.8s\n",
2090 dev->name, p_ctlbk->version,
2091 p_ctlbk->linkid,
2092 p_ctlbk->correlator,
2093 p_sysval->WS_name,
2094 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002095 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2096 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2097 CLAW_RC_NAME_MISMATCH);
2098 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2099 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2100 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002101 dev_warn(tdev,
2102 "Host name %s for %s does not match the"
2103 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002104 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002105 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002106 temp_host_name);
2107 }
2108 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2109 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2110 CLAW_RC_NAME_MISMATCH);
2111 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2112 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2113 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002114 dev_warn(tdev, "Adapter name %s for %s does not match"
2115 " the remote host name %s\n",
2116 p_sysval->WS_name,
2117 dev->name,
2118 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002119 }
2120 if ((p_sysval->write_frame_size < p_env->write_size) &&
2121 (p_env->packing == 0)) {
2122 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2123 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002124 dev_warn(tdev,
2125 "The local write buffer is smaller than the"
2126 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002127 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2128 }
2129 if ((p_sysval->read_frame_size < p_env->read_size) &&
2130 (p_env->packing == 0)) {
2131 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2132 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002133 dev_warn(tdev,
2134 "The local read buffer is smaller than the"
2135 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002136 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2137 }
2138 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002139 dev_info(tdev,
2140 "CLAW device %.8s: System validate"
2141 " completed.\n", temp_ws_name);
2142 dev_info(tdev,
2143 "%s: sys Validate Rsize:%d Wsize:%d\n",
2144 dev->name, p_sysval->read_frame_size,
2145 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002146 privptr->system_validate_comp = 1;
2147 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2148 p_env->packing = PACKING_ASK;
2149 claw_strt_conn_req(dev);
2150 break;
2151 case SYSTEM_VALIDATE_RESPONSE:
2152 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002153 dev_info(tdev,
2154 "Settings for %s validated (version=%d, "
2155 "remote device=%d, rc=%d, adapter name=%.8s, "
2156 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002157 dev->name,
2158 p_ctlbk->version,
2159 p_ctlbk->correlator,
2160 p_ctlbk->rc,
2161 p_sysval->WS_name,
2162 p_sysval->host_name);
2163 switch (p_ctlbk->rc) {
2164 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002165 dev_info(tdev, "%s: CLAW device "
2166 "%.8s: System validate completed.\n",
2167 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002168 if (privptr->system_validate_comp == 0)
2169 claw_strt_conn_req(dev);
2170 privptr->system_validate_comp = 1;
2171 break;
2172 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002173 dev_warn(tdev, "Validating %s failed because of"
2174 " a host or adapter name mismatch\n",
2175 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002176 break;
2177 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002178 dev_warn(tdev, "Validating %s failed because of a"
2179 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002180 dev->name);
2181 break;
2182 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002183 dev_warn(tdev, "Validating %s failed because of a"
2184 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002185 dev->name);
2186 break;
2187 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002188 dev_warn(tdev, "The communication peer of %s rejected"
2189 " the connection\n",
2190 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002191 break;
2192 }
2193 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Andy Richterb805da72008-07-18 15:24:56 +02002195 case CONNECTION_REQUEST:
2196 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002197 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002198 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2199 dev->name,
2200 p_ctlbk->version,
2201 p_ctlbk->linkid,
2202 p_ctlbk->correlator,
2203 p_connect->host_name,
2204 p_connect->WS_name);
2205 if (privptr->active_link_ID != 0) {
2206 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002207 dev_info(tdev, "%s rejected a connection request"
2208 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002209 dev->name);
2210 }
2211 if (p_ctlbk->linkid != 1) {
2212 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002213 dev_info(tdev, "%s rejected a request to open multiple"
2214 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002215 dev->name);
2216 }
2217 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2218 if (rc != 0) {
2219 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002220 dev_info(tdev, "%s rejected a connection request"
2221 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002222 dev->name);
2223 }
2224 claw_send_control(dev,
2225 CONNECTION_CONFIRM, p_ctlbk->linkid,
2226 p_ctlbk->correlator,
2227 0, p_connect->host_name,
2228 p_connect->WS_name);
2229 if (p_env->packing == PACKING_ASK) {
2230 p_env->packing = PACK_SEND;
2231 claw_snd_conn_req(dev, 0);
2232 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002233 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002234 "completed link_id=%d.\n",
2235 dev->name, temp_ws_name,
2236 p_ctlbk->linkid);
2237 privptr->active_link_ID = p_ctlbk->linkid;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002238 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002239 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2240 break;
2241 case CONNECTION_RESPONSE:
2242 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002243 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002244 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2245 dev->name,
2246 p_ctlbk->version,
2247 p_ctlbk->linkid,
2248 p_ctlbk->correlator,
2249 p_ctlbk->rc,
2250 p_connect->host_name,
2251 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
Andy Richterb805da72008-07-18 15:24:56 +02002253 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002254 dev_warn(tdev, "The communication peer of %s rejected"
2255 " a connection request\n",
2256 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002257 return 1;
2258 }
2259 rc = find_link(dev,
2260 p_connect->host_name, p_connect->WS_name);
2261 if (rc != 0) {
2262 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002263 dev_warn(tdev, "The communication peer of %s"
2264 " rejected a connection "
2265 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002266 dev->name);
2267 }
2268 /* should be until CONNECTION_CONFIRM */
2269 privptr->active_link_ID = -(p_ctlbk->linkid);
2270 break;
2271 case CONNECTION_CONFIRM:
2272 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002273 dev_info(tdev,
2274 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002275 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2276 dev->name,
2277 p_ctlbk->version,
2278 p_ctlbk->linkid,
2279 p_ctlbk->correlator,
2280 p_connect->host_name,
2281 p_connect->WS_name);
2282 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2283 privptr->active_link_ID = p_ctlbk->linkid;
2284 if (p_env->packing > PACKING_ASK) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002285 dev_info(tdev,
2286 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 p_env->packing = DO_PACKED;
2288 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002289 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002290 wake_up(&p_ch->wait);
2291 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002292 dev_warn(tdev, "Activating %s failed because of"
2293 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002294 dev->name, p_ctlbk->linkid);
2295 claw_snd_disc(dev, p_ctlbk);
2296 }
2297 break;
2298 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002299 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002300 "Vers=%d,link_id=%d,Corr=%d\n",
2301 dev->name, p_ctlbk->version,
2302 p_ctlbk->linkid, p_ctlbk->correlator);
2303 if ((p_ctlbk->linkid == 2) &&
2304 (p_env->packing == PACK_SEND)) {
2305 privptr->active_link_ID = 1;
2306 p_env->packing = DO_PACKED;
2307 } else
2308 privptr->active_link_ID = 0;
2309 break;
2310 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002311 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002312 dev->name);
2313 break;
2314 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002315 dev_warn(tdev, "The communication peer of %s sent"
2316 " an unknown command code\n",
2317 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002318 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 return 0;
2322} /* end of claw_process_control */
2323
2324
2325/*-------------------------------------------------------------------*
2326* claw_send_control *
2327* *
2328*--------------------------------------------------------------------*/
2329
2330static int
2331claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2332 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2333{
2334 struct claw_privbk *privptr;
2335 struct clawctl *p_ctl;
2336 struct sysval *p_sysval;
2337 struct conncmd *p_connect;
2338 struct sk_buff *skb;
2339
Andy Richterb805da72008-07-18 15:24:56 +02002340 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002341 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2343
2344 p_ctl->command=type;
2345 p_ctl->version=CLAW_VERSION_ID;
2346 p_ctl->linkid=link;
2347 p_ctl->correlator=correlator;
2348 p_ctl->rc=rc;
2349
2350 p_sysval=(struct sysval *)&p_ctl->data;
2351 p_connect=(struct conncmd *)&p_ctl->data;
2352
2353 switch (p_ctl->command) {
2354 case SYSTEM_VALIDATE_REQUEST:
2355 case SYSTEM_VALIDATE_RESPONSE:
2356 memcpy(&p_sysval->host_name, local_name, 8);
2357 memcpy(&p_sysval->WS_name, remote_name, 8);
2358 if (privptr->p_env->packing > 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002359 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2360 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002362 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002363 p_sysval->read_frame_size =
2364 privptr->p_env->read_size;
2365 p_sysval->write_frame_size =
2366 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 }
2368 memset(&p_sysval->reserved, 0x00, 4);
2369 break;
2370 case CONNECTION_REQUEST:
2371 case CONNECTION_RESPONSE:
2372 case CONNECTION_CONFIRM:
2373 case DISCONNECT:
2374 memcpy(&p_sysval->host_name, local_name, 8);
2375 memcpy(&p_sysval->WS_name, remote_name, 8);
2376 if (privptr->p_env->packing > 0) {
2377 /* How big is the biggest packet */
2378 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2379 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2380 } else {
2381 memset(&p_connect->reserved1, 0x00, 4);
2382 memset(&p_connect->reserved2, 0x00, 4);
2383 }
2384 break;
2385 default:
2386 break;
2387 }
2388
2389 /* write Control Record to the device */
2390
2391
2392 skb = dev_alloc_skb(sizeof(struct clawctl));
2393 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 return -ENOMEM;
2395 }
2396 memcpy(skb_put(skb, sizeof(struct clawctl)),
2397 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 if (privptr->p_env->packing >= PACK_SEND)
2399 claw_hw_tx(skb, dev, 1);
2400 else
2401 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 return 0;
2403} /* end of claw_send_control */
2404
2405/*-------------------------------------------------------------------*
2406* claw_snd_conn_req *
2407* *
2408*--------------------------------------------------------------------*/
2409static int
2410claw_snd_conn_req(struct net_device *dev, __u8 link)
2411{
2412 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002413 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 struct clawctl *p_ctl;
2415
Andy Richterb805da72008-07-18 15:24:56 +02002416 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 rc = 1;
2418 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2419 p_ctl->linkid = link;
2420 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 return rc;
2422 }
2423 if (privptr->p_env->packing == PACKING_ASK )
2424 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2425 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2426 if (privptr->p_env->packing == PACK_SEND) {
2427 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2428 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2429 }
2430 if (privptr->p_env->packing == 0)
2431 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2432 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 return rc;
2434
2435} /* end of claw_snd_conn_req */
2436
2437
2438/*-------------------------------------------------------------------*
2439* claw_snd_disc *
2440* *
2441*--------------------------------------------------------------------*/
2442
2443static int
2444claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2445{
2446 int rc;
2447 struct conncmd * p_connect;
2448
Andy Richterb805da72008-07-18 15:24:56 +02002449 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 p_connect=(struct conncmd *)&p_ctl->data;
2451
2452 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2453 p_ctl->correlator, 0,
2454 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 return rc;
2456} /* end of claw_snd_disc */
2457
2458
2459/*-------------------------------------------------------------------*
2460* claw_snd_sys_validate_rsp *
2461* *
2462*--------------------------------------------------------------------*/
2463
2464static int
2465claw_snd_sys_validate_rsp(struct net_device *dev,
2466 struct clawctl *p_ctl, __u32 return_code)
2467{
2468 struct claw_env * p_env;
2469 struct claw_privbk *privptr;
2470 int rc;
2471
Andy Richterb805da72008-07-18 15:24:56 +02002472 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002473 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 p_env=privptr->p_env;
2475 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2476 p_ctl->linkid,
2477 p_ctl->correlator,
2478 return_code,
2479 p_env->host_name,
2480 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 return rc;
2482} /* end of claw_snd_sys_validate_rsp */
2483
2484/*-------------------------------------------------------------------*
2485* claw_strt_conn_req *
2486* *
2487*--------------------------------------------------------------------*/
2488
2489static int
2490claw_strt_conn_req(struct net_device *dev )
2491{
2492 int rc;
2493
Andy Richterb805da72008-07-18 15:24:56 +02002494 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 return rc;
2497} /* end of claw_strt_conn_req */
2498
2499
2500
2501/*-------------------------------------------------------------------*
2502 * claw_stats *
2503 *-------------------------------------------------------------------*/
2504
2505static struct
2506net_device_stats *claw_stats(struct net_device *dev)
2507{
2508 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002509
2510 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002511 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 return &privptr->stats;
2513} /* end of claw_stats */
2514
2515
2516/*-------------------------------------------------------------------*
2517* unpack_read *
2518* *
2519*--------------------------------------------------------------------*/
2520static void
2521unpack_read(struct net_device *dev )
2522{
2523 struct sk_buff *skb;
2524 struct claw_privbk *privptr;
2525 struct claw_env *p_env;
2526 struct ccwbk *p_this_ccw;
2527 struct ccwbk *p_first_ccw;
2528 struct ccwbk *p_last_ccw;
2529 struct clawph *p_packh;
2530 void *p_packd;
2531 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002532 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
2534 __u32 len_of_data;
2535 __u32 pack_off;
2536 __u8 link_num;
2537 __u8 mtc_this_frm=0;
2538 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 int i=0;
2540 int p=0;
2541
Andy Richterb805da72008-07-18 15:24:56 +02002542 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 p_first_ccw=NULL;
2544 p_last_ccw=NULL;
2545 p_packh=NULL;
2546 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002547 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002548
Heiko Carstens319cb0832010-08-12 01:58:27 +00002549 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 p_env = privptr->p_env;
2551 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 pack_off = 0;
2554 p = 0;
2555 p_this_ccw->header.flag=CLAW_PENDING;
2556 privptr->p_read_active_first=p_this_ccw->next;
2557 p_this_ccw->next=NULL;
2558 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2559 if ((p_env->packing == PACK_SEND) &&
2560 (p_packh->len == 32) &&
2561 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2562 p_packh++; /* peek past pack header */
2563 p_ctlrec = (struct clawctl *)p_packh;
2564 p_packh--; /* un peek */
2565 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2566 (p_ctlrec->command == CONNECTION_CONFIRM))
2567 p_env->packing = DO_PACKED;
2568 }
2569 if (p_env->packing == DO_PACKED)
2570 link_num=p_packh->link_num;
2571 else
2572 link_num=p_this_ccw->header.opcode / 8;
2573 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 mtc_this_frm=1;
2575 if (p_this_ccw->header.length!=
2576 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002577 dev_warn(p_dev,
2578 "The communication peer of %s"
2579 " sent a faulty"
2580 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 dev->name, p_this_ccw->header.length);
2582 }
2583 }
2584
2585 if (privptr->mtc_skipping) {
2586 /*
2587 * We're in the mode of skipping past a
2588 * multi-frame message
2589 * that we can't process for some reason or other.
2590 * The first frame without the More-To-Come flag is
2591 * the last frame of the skipped message.
2592 */
2593 /* in case of More-To-Come not set in this frame */
2594 if (mtc_this_frm==0) {
2595 privptr->mtc_skipping=0; /* Ok, the end */
2596 privptr->mtc_logical_link=-1;
2597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 goto NextFrame;
2599 }
2600
2601 if (link_num==0) {
2602 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002603 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 goto NextFrame;
2605 }
2606unpack_next:
2607 if (p_env->packing == DO_PACKED) {
2608 if (pack_off > p_env->read_size)
2609 goto NextFrame;
2610 p_packd = p_this_ccw->p_buffer+pack_off;
2611 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002612 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 (p_packh->flag != 0))
2614 goto NextFrame;
2615 bytes_to_mov = p_packh->len;
2616 pack_off += bytes_to_mov+sizeof(struct clawph);
2617 p++;
2618 } else {
2619 bytes_to_mov=p_this_ccw->header.length;
2620 }
2621 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
2623 /*
2624 * if More-To-Come is set in this frame then we don't know
2625 * length of entire message, and hence have to allocate
2626 * large buffer */
2627
2628 /* We are starting a new envelope */
2629 privptr->mtc_offset=0;
2630 privptr->mtc_logical_link=link_num;
2631 }
2632
2633 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2634 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 privptr->stats.rx_frame_errors++;
2636 goto NextFrame;
2637 }
2638 if (p_env->packing == DO_PACKED) {
2639 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2640 p_packd+sizeof(struct clawph), bytes_to_mov);
2641
2642 } else {
2643 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2644 p_this_ccw->p_buffer, bytes_to_mov);
2645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 if (mtc_this_frm==0) {
2647 len_of_data=privptr->mtc_offset+bytes_to_mov;
2648 skb=dev_alloc_skb(len_of_data);
2649 if (skb) {
2650 memcpy(skb_put(skb,len_of_data),
2651 privptr->p_mtc_envelope,
2652 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002654 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 skb->protocol=htons(ETH_P_IP);
2656 skb->ip_summed=CHECKSUM_UNNECESSARY;
2657 privptr->stats.rx_packets++;
2658 privptr->stats.rx_bytes+=len_of_data;
2659 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 }
2661 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002662 dev_info(p_dev, "Allocating a buffer for"
2663 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 }
2666 privptr->mtc_offset=0;
2667 privptr->mtc_logical_link=-1;
2668 }
2669 else {
2670 privptr->mtc_offset+=bytes_to_mov;
2671 }
2672 if (p_env->packing == DO_PACKED)
2673 goto unpack_next;
2674NextFrame:
2675 /*
2676 * Remove ThisCCWblock from active read queue, and add it
2677 * to queue of free blocks to be reused.
2678 */
2679 i++;
2680 p_this_ccw->header.length=0xffff;
2681 p_this_ccw->header.opcode=0xff;
2682 /*
2683 * add this one to the free queue for later reuse
2684 */
2685 if (p_first_ccw==NULL) {
2686 p_first_ccw = p_this_ccw;
2687 }
2688 else {
2689 p_last_ccw->next = p_this_ccw;
2690 }
2691 p_last_ccw = p_this_ccw;
2692 /*
2693 * chain to next block on active read queue
2694 */
2695 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002696 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 } /* end of while */
2698
2699 /* check validity */
2700
Andy Richterb805da72008-07-18 15:24:56 +02002701 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 return;
2705} /* end of unpack_read */
2706
2707/*-------------------------------------------------------------------*
2708* claw_strt_read *
2709* *
2710*--------------------------------------------------------------------*/
2711static void
2712claw_strt_read (struct net_device *dev, int lock )
2713{
2714 int rc = 0;
2715 __u32 parm;
2716 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002717 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 struct ccwbk*p_ccwbk;
2719 struct chbk *p_ch;
2720 struct clawh *p_clawh;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002721 p_ch = &privptr->channel[READ_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
Andy Richterb805da72008-07-18 15:24:56 +02002723 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2725 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2726
2727 if ((privptr->p_write_active_first!=NULL &&
2728 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2729 (privptr->p_read_active_first!=NULL &&
2730 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2731 p_clawh->flag=CLAW_BUSY; /* 0xff */
2732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 if (lock==LOCK_YES) {
2734 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2735 }
2736 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002737 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 p_ccwbk=privptr->p_read_active_first;
2739 parm = (unsigned long) p_ch;
2740 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2741 0xff, 0);
2742 if (rc != 0) {
2743 ccw_check_return_code(p_ch->cdev, rc);
2744 }
2745 }
2746 else {
Andy Richterb805da72008-07-18 15:24:56 +02002747 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 }
2749
2750 if (lock==LOCK_YES) {
2751 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2752 }
Andy Richterb805da72008-07-18 15:24:56 +02002753 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 return;
2755} /* end of claw_strt_read */
2756
2757/*-------------------------------------------------------------------*
2758* claw_strt_out_IO *
2759* *
2760*--------------------------------------------------------------------*/
2761
2762static void
2763claw_strt_out_IO( struct net_device *dev )
2764{
2765 int rc = 0;
2766 unsigned long parm;
2767 struct claw_privbk *privptr;
2768 struct chbk *p_ch;
2769 struct ccwbk *p_first_ccw;
2770
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 if (!dev) {
2772 return;
2773 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002774 privptr = (struct claw_privbk *)dev->ml_priv;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002775 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
Andy Richterb805da72008-07-18 15:24:56 +02002777 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 p_first_ccw=privptr->p_write_active_first;
2779
2780 if (p_ch->claw_state == CLAW_STOP)
2781 return;
2782 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 return;
2784 }
2785 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2786 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002787 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002788 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2789 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 if (rc != 0) {
2791 ccw_check_return_code(p_ch->cdev, rc);
2792 }
2793 }
2794 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 return;
2796} /* end of claw_strt_out_IO */
2797
2798/*-------------------------------------------------------------------*
2799* Free write buffers *
2800* *
2801*--------------------------------------------------------------------*/
2802
2803static void
2804claw_free_wrt_buf( struct net_device *dev )
2805{
2806
Peter Tiedemann6951df32008-08-21 17:10:23 +02002807 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 struct ccwbk*p_this_ccw;
2809 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002810
2811 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 /* scan the write queue to free any completed write packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 p_this_ccw=privptr->p_write_active_first;
2814 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2815 {
2816 p_next_ccw = p_this_ccw->next;
2817 if (((p_next_ccw!=NULL) &&
2818 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2819 ((p_this_ccw == privptr->p_write_active_last) &&
2820 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2821 /* The next CCW is OK or this is */
2822 /* the last CCW...free it @A1A */
2823 privptr->p_write_active_first=p_this_ccw->next;
2824 p_this_ccw->header.flag=CLAW_PENDING;
2825 p_this_ccw->next=privptr->p_write_free_chain;
2826 privptr->p_write_free_chain=p_this_ccw;
2827 ++privptr->write_free_count;
2828 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2829 p_this_ccw=privptr->p_write_active_first;
2830 privptr->stats.tx_packets++;
2831 }
2832 else {
2833 break;
2834 }
2835 }
2836 if (privptr->write_free_count!=0) {
2837 claw_clearbit_busy(TB_NOBUFFER,dev);
2838 }
2839 /* whole chain removed? */
2840 if (privptr->p_write_active_first==NULL) {
2841 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 }
Andy Richterb805da72008-07-18 15:24:56 +02002843 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 return;
2845}
2846
2847/*-------------------------------------------------------------------*
2848* claw free netdevice *
2849* *
2850*--------------------------------------------------------------------*/
2851static void
2852claw_free_netdevice(struct net_device * dev, int free_dev)
2853{
2854 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855
Andy Richterb805da72008-07-18 15:24:56 +02002856 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 if (!dev)
2858 return;
Andy Richterb805da72008-07-18 15:24:56 +02002859 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002860 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 if (dev->flags & IFF_RUNNING)
2862 claw_release(dev);
2863 if (privptr) {
Heiko Carstens319cb0832010-08-12 01:58:27 +00002864 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002866 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867#ifdef MODULE
2868 if (free_dev) {
2869 free_netdev(dev);
2870 }
2871#endif
Andy Richterb805da72008-07-18 15:24:56 +02002872 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873}
2874
2875/**
2876 * Claw init netdevice
2877 * Initialize everything of the net device except the name and the
2878 * channel structs.
2879 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002880static const struct net_device_ops claw_netdev_ops = {
2881 .ndo_open = claw_open,
2882 .ndo_stop = claw_release,
2883 .ndo_get_stats = claw_stats,
2884 .ndo_start_xmit = claw_tx,
2885 .ndo_change_mtu = claw_change_mtu,
2886};
2887
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888static void
2889claw_init_netdevice(struct net_device * dev)
2890{
Andy Richterb805da72008-07-18 15:24:56 +02002891 CLAW_DBF_TEXT(2, setup, "init_dev");
2892 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 dev->hard_header_len = 0;
2895 dev->addr_len = 0;
2896 dev->type = ARPHRD_SLIP;
2897 dev->tx_queue_len = 1300;
2898 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002899 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002900 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 return;
2902}
2903
2904/**
2905 * Init a new channel in the privptr->channel[i].
2906 *
2907 * @param cdev The ccw_device to be added.
2908 *
2909 * @return 0 on success, !0 on error.
2910 */
2911static int
2912add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2913{
2914 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002915 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
Kay Sievers2a0217d2008-10-10 21:33:09 +02002917 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2919 p_ch = &privptr->channel[i];
2920 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002921 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002922 ccw_device_get_id(cdev, &dev_id);
2923 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002924 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 return -ENOMEM;
2926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 return 0;
2928}
2929
2930
2931/**
2932 *
2933 * Setup an interface.
2934 *
2935 * @param cgdev Device to be setup.
2936 *
2937 * @returns 0 on success, !0 on failure.
2938 */
2939static int
2940claw_new_device(struct ccwgroup_device *cgdev)
2941{
2942 struct claw_privbk *privptr;
2943 struct claw_env *p_env;
2944 struct net_device *dev;
2945 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002946 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947
Andy Richter4811fcb2009-01-20 06:14:33 +00002948 dev_info(&cgdev->dev, "add for %s\n",
Heiko Carstens319cb0832010-08-12 01:58:27 +00002949 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002950 CLAW_DBF_TEXT(2, setup, "new_dev");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002951 privptr = dev_get_drvdata(&cgdev->dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +00002952 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2953 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 if (!privptr)
2955 return -ENODEV;
2956 p_env = privptr->p_env;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002957 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2958 p_env->devno[READ_CHANNEL] = dev_id.devno;
2959 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2960 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 ret = add_channel(cgdev->cdev[0],0,privptr);
2962 if (ret == 0)
2963 ret = add_channel(cgdev->cdev[1],1,privptr);
2964 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002965 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2966 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002967 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002969 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002971 dev_warn(&cgdev->dev,
2972 "Setting the read subchannel online"
2973 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 goto out;
2975 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002976 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002978 dev_warn(&cgdev->dev,
2979 "Setting the write subchannel online "
2980 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 goto out;
2982 }
2983 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2984 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002985 dev_warn(&cgdev->dev,
2986 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 goto out;
2988 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002989 dev->ml_priv = privptr;
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002990 dev_set_drvdata(&cgdev->dev, privptr);
Heiko Carstens319cb0832010-08-12 01:58:27 +00002991 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2992 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 /* sysfs magic */
2994 SET_NETDEV_DEV(dev, &cgdev->dev);
2995 if (register_netdev(dev) != 0) {
2996 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02002997 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 goto out;
2999 }
3000 dev->flags &=~IFF_RUNNING;
3001 if (privptr->buffs_alloc == 0) {
3002 ret=init_ccw_bk(dev);
3003 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 unregister_netdev(dev);
3005 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02003006 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 goto out;
3008 }
3009 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00003010 privptr->channel[READ_CHANNEL].ndev = dev;
3011 privptr->channel[WRITE_CHANNEL].ndev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 privptr->p_env->ndev = dev;
3013
Andy Richter4811fcb2009-01-20 06:14:33 +00003014 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3016 dev->name, p_env->read_size,
3017 p_env->write_size, p_env->read_buffers,
Heiko Carstens319cb0832010-08-12 01:58:27 +00003018 p_env->write_buffers, p_env->devno[READ_CHANNEL],
3019 p_env->devno[WRITE_CHANNEL]);
Andy Richter4811fcb2009-01-20 06:14:33 +00003020 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 ":%.8s api_type: %.8s\n",
3022 dev->name, p_env->host_name,
3023 p_env->adapter_name , p_env->api_type);
3024 return 0;
3025out:
3026 ccw_device_set_offline(cgdev->cdev[1]);
3027 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 return -ENODEV;
3029}
3030
3031static void
3032claw_purge_skb_queue(struct sk_buff_head *q)
3033{
3034 struct sk_buff *skb;
3035
Andy Richterb805da72008-07-18 15:24:56 +02003036 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 while ((skb = skb_dequeue(q))) {
3038 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02003039 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 }
3041}
3042
3043/**
3044 * Shutdown an interface.
3045 *
3046 * @param cgdev Device to be shut down.
3047 *
3048 * @returns 0 on success, !0 on failure.
3049 */
3050static int
3051claw_shutdown_device(struct ccwgroup_device *cgdev)
3052{
3053 struct claw_privbk *priv;
3054 struct net_device *ndev;
Heiko Carstens38ed18f2011-05-12 18:45:04 +00003055 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003057 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003058 priv = dev_get_drvdata(&cgdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 if (!priv)
3060 return -ENODEV;
Heiko Carstens319cb0832010-08-12 01:58:27 +00003061 ndev = priv->channel[READ_CHANNEL].ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 if (ndev) {
3063 /* Close the device */
Heiko Carstens319cb0832010-08-12 01:58:27 +00003064 dev_info(&cgdev->dev, "%s: shutting down\n",
Andy Richter4811fcb2009-01-20 06:14:33 +00003065 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 if (ndev->flags & IFF_RUNNING)
3067 ret = claw_release(ndev);
3068 ndev->flags &=~IFF_RUNNING;
3069 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003070 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 claw_free_netdevice(ndev, 1);
Heiko Carstens319cb0832010-08-12 01:58:27 +00003072 priv->channel[READ_CHANNEL].ndev = NULL;
3073 priv->channel[WRITE_CHANNEL].ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 priv->p_env->ndev = NULL;
3075 }
3076 ccw_device_set_offline(cgdev->cdev[1]);
3077 ccw_device_set_offline(cgdev->cdev[0]);
Heiko Carstens38ed18f2011-05-12 18:45:04 +00003078 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079}
3080
3081static void
3082claw_remove_device(struct ccwgroup_device *cgdev)
3083{
3084 struct claw_privbk *priv;
3085
Andy Richterb805da72008-07-18 15:24:56 +02003086 BUG_ON(!cgdev);
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003087 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003088 priv = dev_get_drvdata(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003089 BUG_ON(!priv);
Andy Richter4811fcb2009-01-20 06:14:33 +00003090 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 if (cgdev->state == CCWGROUP_ONLINE)
3092 claw_shutdown_device(cgdev);
3093 claw_remove_files(&cgdev->dev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003094 kfree(priv->p_mtc_envelope);
3095 priv->p_mtc_envelope=NULL;
3096 kfree(priv->p_env);
3097 priv->p_env=NULL;
3098 kfree(priv->channel[0].irb);
3099 priv->channel[0].irb=NULL;
3100 kfree(priv->channel[1].irb);
3101 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 kfree(priv);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003103 dev_set_drvdata(&cgdev->dev, NULL);
Heiko Carstens319cb0832010-08-12 01:58:27 +00003104 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3105 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003107
3108 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109}
3110
3111
3112/*
3113 * sysfs attributes
3114 */
3115static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003116claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117{
3118 struct claw_privbk *priv;
3119 struct claw_env * p_env;
3120
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003121 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 if (!priv)
3123 return -ENODEV;
3124 p_env = priv->p_env;
3125 return sprintf(buf, "%s\n",p_env->host_name);
3126}
3127
3128static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003129claw_hname_write(struct device *dev, struct device_attribute *attr,
3130 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131{
3132 struct claw_privbk *priv;
3133 struct claw_env * p_env;
3134
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003135 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 if (!priv)
3137 return -ENODEV;
3138 p_env = priv->p_env;
3139 if (count > MAX_NAME_LEN+1)
3140 return -EINVAL;
3141 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3142 strncpy(p_env->host_name,buf, count);
3143 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3144 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003145 CLAW_DBF_TEXT(2, setup, "HstnSet");
3146 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
3148 return count;
3149}
3150
3151static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3152
3153static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003154claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155{
3156 struct claw_privbk *priv;
3157 struct claw_env * p_env;
3158
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003159 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 if (!priv)
3161 return -ENODEV;
3162 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003163 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164}
3165
3166static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003167claw_adname_write(struct device *dev, struct device_attribute *attr,
3168 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
3170 struct claw_privbk *priv;
3171 struct claw_env * p_env;
3172
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003173 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 if (!priv)
3175 return -ENODEV;
3176 p_env = priv->p_env;
3177 if (count > MAX_NAME_LEN+1)
3178 return -EINVAL;
3179 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3180 strncpy(p_env->adapter_name,buf, count);
3181 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3182 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003183 CLAW_DBF_TEXT(2, setup, "AdnSet");
3184 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
3186 return count;
3187}
3188
3189static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3190
3191static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003192claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193{
3194 struct claw_privbk *priv;
3195 struct claw_env * p_env;
3196
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003197 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 if (!priv)
3199 return -ENODEV;
3200 p_env = priv->p_env;
3201 return sprintf(buf, "%s\n",
3202 p_env->api_type);
3203}
3204
3205static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003206claw_apname_write(struct device *dev, struct device_attribute *attr,
3207 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208{
3209 struct claw_privbk *priv;
3210 struct claw_env * p_env;
3211
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003212 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 if (!priv)
3214 return -ENODEV;
3215 p_env = priv->p_env;
3216 if (count > MAX_NAME_LEN+1)
3217 return -EINVAL;
3218 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3219 strncpy(p_env->api_type,buf, count);
3220 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3221 p_env->api_type[MAX_NAME_LEN] = 0x00;
3222 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3223 p_env->read_size=DEF_PACK_BUFSIZE;
3224 p_env->write_size=DEF_PACK_BUFSIZE;
3225 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003226 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 }
3228 else {
3229 p_env->packing=0;
3230 p_env->read_size=CLAW_FRAME_SIZE;
3231 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003232 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 }
Andy Richterb805da72008-07-18 15:24:56 +02003234 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 return count;
3236}
3237
3238static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3239
3240static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003241claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242{
3243 struct claw_privbk *priv;
3244 struct claw_env * p_env;
3245
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003246 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 if (!priv)
3248 return -ENODEV;
3249 p_env = priv->p_env;
3250 return sprintf(buf, "%d\n", p_env->write_buffers);
3251}
3252
3253static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003254claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3255 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256{
3257 struct claw_privbk *priv;
3258 struct claw_env * p_env;
3259 int nnn,max;
3260
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003261 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 if (!priv)
3263 return -ENODEV;
3264 p_env = priv->p_env;
3265 sscanf(buf, "%i", &nnn);
3266 if (p_env->packing) {
3267 max = 64;
3268 }
3269 else {
3270 max = 512;
3271 }
3272 if ((nnn > max ) || (nnn < 2))
3273 return -EINVAL;
3274 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003275 CLAW_DBF_TEXT(2, setup, "Wbufset");
3276 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 return count;
3278}
3279
3280static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3281
3282static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003283claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284{
3285 struct claw_privbk *priv;
3286 struct claw_env * p_env;
3287
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003288 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 if (!priv)
3290 return -ENODEV;
3291 p_env = priv->p_env;
3292 return sprintf(buf, "%d\n", p_env->read_buffers);
3293}
3294
3295static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003296claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3297 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298{
3299 struct claw_privbk *priv;
3300 struct claw_env *p_env;
3301 int nnn,max;
3302
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003303 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 if (!priv)
3305 return -ENODEV;
3306 p_env = priv->p_env;
3307 sscanf(buf, "%i", &nnn);
3308 if (p_env->packing) {
3309 max = 64;
3310 }
3311 else {
3312 max = 512;
3313 }
3314 if ((nnn > max ) || (nnn < 2))
3315 return -EINVAL;
3316 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003317 CLAW_DBF_TEXT(2, setup, "Rbufset");
3318 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 return count;
3320}
3321
3322static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3323
3324static struct attribute *claw_attr[] = {
3325 &dev_attr_read_buffer.attr,
3326 &dev_attr_write_buffer.attr,
3327 &dev_attr_adapter_name.attr,
3328 &dev_attr_api_type.attr,
3329 &dev_attr_host_name.attr,
3330 NULL,
3331};
3332
3333static struct attribute_group claw_attr_group = {
3334 .attrs = claw_attr,
3335};
3336
3337static int
3338claw_add_files(struct device *dev)
3339{
Andy Richterb805da72008-07-18 15:24:56 +02003340 CLAW_DBF_TEXT(2, setup, "add_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3342}
3343
3344static void
3345claw_remove_files(struct device *dev)
3346{
Andy Richterb805da72008-07-18 15:24:56 +02003347 CLAW_DBF_TEXT(2, setup, "rem_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3349}
3350
3351/*--------------------------------------------------------------------*
3352* claw_init and cleanup *
3353*---------------------------------------------------------------------*/
3354
3355static void __exit
3356claw_cleanup(void)
3357{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003358 driver_remove_file(&claw_group_driver.driver,
3359 &driver_attr_group);
3360 ccwgroup_driver_unregister(&claw_group_driver);
3361 ccw_driver_unregister(&claw_ccw_driver);
3362 root_device_unregister(claw_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003364 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365
3366}
3367
3368/**
3369 * Initialize module.
3370 * This is called just after the module is loaded.
3371 *
3372 * @return 0 on success, !0 on error.
3373 */
3374static int __init
3375claw_init(void)
3376{
3377 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
Andy Richter4811fcb2009-01-20 06:14:33 +00003379 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 ret = claw_register_debug_facility();
3381 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003382 pr_err("Registering with the S/390 debug feature"
3383 " failed with error code %d\n", ret);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003384 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 }
Andy Richterb805da72008-07-18 15:24:56 +02003386 CLAW_DBF_TEXT(2, setup, "init_mod");
Ursula Braund950d172010-01-04 03:14:45 +00003387 claw_root_dev = root_device_register("claw");
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003388 ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0;
3389 if (ret)
3390 goto register_err;
3391 ret = ccw_driver_register(&claw_ccw_driver);
3392 if (ret)
3393 goto ccw_err;
3394 claw_group_driver.driver.groups = claw_group_attr_groups;
3395 ret = ccwgroup_driver_register(&claw_group_driver);
3396 if (ret)
3397 goto ccwgroup_err;
3398 return 0;
3399
3400ccwgroup_err:
3401 ccw_driver_unregister(&claw_ccw_driver);
3402ccw_err:
3403 root_device_unregister(claw_root_dev);
3404register_err:
3405 CLAW_DBF_TEXT(2, setup, "init_bad");
3406 claw_unregister_debug_facility();
3407out_err:
3408 pr_err("Initializing the claw device driver failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 return ret;
3410}
3411
3412module_init(claw_init);
3413module_exit(claw_cleanup);
3414
Andy Richterb805da72008-07-18 15:24:56 +02003415MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3416MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3417 "Copyright 2000,2008 IBM Corporation\n");
3418MODULE_LICENSE("GPL");