| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 |  *    ESCON CLAW network driver | 
 | 3 |  * | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 4 |  *  Linux for zSeries version | 
| Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 5 |  *    Copyright IBM Corp. 2002, 2009 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 |  *  Author(s) Original code written by: | 
| Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 7 |  *		Kazuo Iimura <iimura@jp.ibm.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 |  *   	      Rewritten by | 
| Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 9 |  *		Andy Richter <richtera@us.ibm.com> | 
 | 10 |  *		Marc Price <mwprice@us.ibm.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 |  * | 
 | 12 |  *    sysfs parms: | 
 | 13 |  *   group x.x.rrrr,x.x.wwww | 
 | 14 |  *   read_buffer nnnnnnn | 
 | 15 |  *   write_buffer nnnnnn | 
 | 16 |  *   host_name  aaaaaaaa | 
 | 17 |  *   adapter_name aaaaaaaa | 
 | 18 |  *   api_type    aaaaaaaa | 
 | 19 |  * | 
 | 20 |  *  eg. | 
 | 21 |  *   group  0.0.0200 0.0.0201 | 
 | 22 |  *   read_buffer 25 | 
 | 23 |  *   write_buffer 20 | 
 | 24 |  *   host_name LINUX390 | 
 | 25 |  *   adapter_name RS6K | 
 | 26 |  *   api_type     TCPIP | 
 | 27 |  * | 
 | 28 |  *  where | 
 | 29 |  * | 
 | 30 |  *   The device id is decided by the order entries | 
 | 31 |  *   are added to the group the first is claw0 the second claw1 | 
 | 32 |  *   up to CLAW_MAX_DEV | 
 | 33 |  * | 
 | 34 |  *   rrrr     -	the first of 2 consecutive device addresses used for the | 
 | 35 |  *		CLAW protocol. | 
 | 36 |  *		The specified address is always used as the input (Read) | 
 | 37 |  *		channel and the next address is used as the output channel. | 
 | 38 |  * | 
 | 39 |  *   wwww     -	the second of 2 consecutive device addresses used for | 
 | 40 |  *		the CLAW protocol. | 
 | 41 |  *              The specified address is always used as the output | 
 | 42 |  *		channel and the previous address is used as the input channel. | 
 | 43 |  * | 
 | 44 |  *   read_buffer	-       specifies number of input buffers to allocate. | 
 | 45 |  *   write_buffer       -       specifies number of output buffers to allocate. | 
 | 46 |  *   host_name          -       host name | 
 | 47 |  *   adaptor_name       -       adaptor name | 
 | 48 |  *   api_type           -       API type TCPIP or API will be sent and expected | 
 | 49 |  *				as ws_name | 
 | 50 |  * | 
 | 51 |  *   Note the following requirements: | 
 | 52 |  *   1)  host_name must match the configured adapter_name on the remote side | 
 | 53 |  *   2)  adaptor_name must match the configured host name on the remote side | 
 | 54 |  * | 
 | 55 |  *  Change History | 
 | 56 |  *    1.00  Initial release shipped | 
 | 57 |  *    1.10  Changes for Buffer allocation | 
 | 58 |  *    1.15  Changed for 2.6 Kernel  No longer compiles on 2.4 or lower | 
 | 59 |  *    1.25  Added Packing support | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 60 |  *    1.5 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 |  */ | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 62 |  | 
 | 63 | #define KMSG_COMPONENT "claw" | 
 | 64 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include <asm/ccwdev.h> | 
 | 66 | #include <asm/ccwgroup.h> | 
 | 67 | #include <asm/debug.h> | 
 | 68 | #include <asm/idals.h> | 
 | 69 | #include <asm/io.h> | 
| Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 70 | #include <linux/bitops.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #include <linux/ctype.h> | 
 | 72 | #include <linux/delay.h> | 
 | 73 | #include <linux/errno.h> | 
 | 74 | #include <linux/if_arp.h> | 
 | 75 | #include <linux/init.h> | 
 | 76 | #include <linux/interrupt.h> | 
 | 77 | #include <linux/ip.h> | 
 | 78 | #include <linux/kernel.h> | 
 | 79 | #include <linux/module.h> | 
 | 80 | #include <linux/netdevice.h> | 
 | 81 | #include <linux/etherdevice.h> | 
 | 82 | #include <linux/proc_fs.h> | 
 | 83 | #include <linux/sched.h> | 
 | 84 | #include <linux/signal.h> | 
 | 85 | #include <linux/skbuff.h> | 
 | 86 | #include <linux/slab.h> | 
 | 87 | #include <linux/string.h> | 
 | 88 | #include <linux/tcp.h> | 
 | 89 | #include <linux/timer.h> | 
 | 90 | #include <linux/types.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | #include "claw.h" | 
 | 93 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 94 | /* | 
 | 95 |    CLAW uses the s390dbf file system  see claw_trace and claw_setup | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | */ | 
 | 97 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 98 | static char version[] __initdata = "CLAW driver"; | 
| Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 99 | static char debug_buffer[255]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /** | 
 | 101 |  * Debug Facility Stuff | 
 | 102 |  */ | 
 | 103 | static debug_info_t *claw_dbf_setup; | 
 | 104 | static debug_info_t *claw_dbf_trace; | 
 | 105 |  | 
 | 106 | /** | 
 | 107 |  *  CLAW Debug Facility functions | 
 | 108 |  */ | 
 | 109 | static void | 
 | 110 | claw_unregister_debug_facility(void) | 
 | 111 | { | 
 | 112 | 	if (claw_dbf_setup) | 
 | 113 | 		debug_unregister(claw_dbf_setup); | 
 | 114 | 	if (claw_dbf_trace) | 
 | 115 | 		debug_unregister(claw_dbf_trace); | 
 | 116 | } | 
 | 117 |  | 
 | 118 | static int | 
 | 119 | claw_register_debug_facility(void) | 
 | 120 | { | 
| Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 121 | 	claw_dbf_setup = debug_register("claw_setup", 2, 1, 8); | 
 | 122 | 	claw_dbf_trace = debug_register("claw_trace", 2, 2, 8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | 	if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | 		claw_unregister_debug_facility(); | 
 | 125 | 		return -ENOMEM; | 
 | 126 | 	} | 
 | 127 | 	debug_register_view(claw_dbf_setup, &debug_hex_ascii_view); | 
 | 128 | 	debug_set_level(claw_dbf_setup, 2); | 
 | 129 | 	debug_register_view(claw_dbf_trace, &debug_hex_ascii_view); | 
 | 130 | 	debug_set_level(claw_dbf_trace, 2); | 
 | 131 | 	return 0; | 
 | 132 | } | 
 | 133 |  | 
 | 134 | static inline void | 
 | 135 | claw_set_busy(struct net_device *dev) | 
 | 136 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 137 |  ((struct claw_privbk *)dev->ml_priv)->tbusy = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } | 
 | 139 |  | 
 | 140 | static inline void | 
 | 141 | claw_clear_busy(struct net_device *dev) | 
 | 142 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 143 | 	clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | 	netif_wake_queue(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } | 
 | 146 |  | 
 | 147 | static inline int | 
 | 148 | claw_check_busy(struct net_device *dev) | 
 | 149 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 150 | 	return ((struct claw_privbk *) dev->ml_priv)->tbusy; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } | 
 | 152 |  | 
 | 153 | static inline void | 
 | 154 | claw_setbit_busy(int nr,struct net_device *dev) | 
 | 155 | { | 
 | 156 | 	netif_stop_queue(dev); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 157 | 	set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } | 
 | 159 |  | 
 | 160 | static inline void | 
 | 161 | claw_clearbit_busy(int nr,struct net_device *dev) | 
 | 162 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 163 | 	clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | 	netif_wake_queue(dev); | 
 | 165 | } | 
 | 166 |  | 
 | 167 | static inline int | 
 | 168 | claw_test_and_setbit_busy(int nr,struct net_device *dev) | 
 | 169 | { | 
 | 170 | 	netif_stop_queue(dev); | 
 | 171 | 	return test_and_set_bit(nr, | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 172 | 		(void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } | 
 | 174 |  | 
 | 175 |  | 
 | 176 | /* Functions for the DEV methods */ | 
 | 177 |  | 
 | 178 | static int claw_probe(struct ccwgroup_device *cgdev); | 
 | 179 | static void claw_remove_device(struct ccwgroup_device *cgdev); | 
 | 180 | static void claw_purge_skb_queue(struct sk_buff_head *q); | 
 | 181 | static int claw_new_device(struct ccwgroup_device *cgdev); | 
 | 182 | static int claw_shutdown_device(struct ccwgroup_device *cgdev); | 
 | 183 | static int claw_tx(struct sk_buff *skb, struct net_device *dev); | 
 | 184 | static int claw_change_mtu( struct net_device *dev, int new_mtu); | 
 | 185 | static int claw_open(struct net_device *dev); | 
 | 186 | static void claw_irq_handler(struct ccw_device *cdev, | 
 | 187 | 	unsigned long intparm, struct irb *irb); | 
 | 188 | static void claw_irq_tasklet ( unsigned long data ); | 
 | 189 | static int claw_release(struct net_device *dev); | 
 | 190 | static void claw_write_retry ( struct chbk * p_ch ); | 
 | 191 | static void claw_write_next ( struct chbk * p_ch ); | 
 | 192 | static void claw_timer ( struct chbk * p_ch ); | 
 | 193 |  | 
 | 194 | /* Functions */ | 
 | 195 | static int add_claw_reads(struct net_device *dev, | 
 | 196 | 	struct ccwbk* p_first, struct ccwbk* p_last); | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 197 | static void ccw_check_return_code (struct ccw_device *cdev, int return_code); | 
 | 198 | static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | static int find_link(struct net_device *dev, char *host_name, char *ws_name ); | 
 | 200 | static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid); | 
 | 201 | static int init_ccw_bk(struct net_device *dev); | 
 | 202 | static void probe_error( struct ccwgroup_device *cgdev); | 
 | 203 | static struct net_device_stats *claw_stats(struct net_device *dev); | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 204 | static int pages_to_order_of_mag(int num_of_pages); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | /* sysfs Functions */ | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 207 | static ssize_t claw_hname_show(struct device *dev, | 
 | 208 | 	struct device_attribute *attr, char *buf); | 
 | 209 | static ssize_t claw_hname_write(struct device *dev, | 
 | 210 | 	struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | 	const char *buf, size_t count); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 212 | static ssize_t claw_adname_show(struct device *dev, | 
 | 213 | 	struct device_attribute *attr, char *buf); | 
 | 214 | static ssize_t claw_adname_write(struct device *dev, | 
 | 215 | 	struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | 	const char *buf, size_t count); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 217 | static ssize_t claw_apname_show(struct device *dev, | 
 | 218 | 	struct device_attribute *attr, char *buf); | 
 | 219 | static ssize_t claw_apname_write(struct device *dev, | 
 | 220 | 	struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | 	const char *buf, size_t count); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 222 | static ssize_t claw_wbuff_show(struct device *dev, | 
 | 223 | 	struct device_attribute *attr, char *buf); | 
 | 224 | static ssize_t claw_wbuff_write(struct device *dev, | 
 | 225 | 	struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | 	const char *buf, size_t count); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 227 | static ssize_t claw_rbuff_show(struct device *dev, | 
 | 228 | 	struct device_attribute *attr, char *buf); | 
 | 229 | static ssize_t claw_rbuff_write(struct device *dev, | 
 | 230 | 	struct device_attribute *attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | 	const char *buf, size_t count); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 |  | 
 | 233 | /*   Functions for System Validate  */ | 
 | 234 | static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw); | 
 | 235 | static int claw_send_control(struct net_device *dev, __u8 type, __u8 link, | 
 | 236 |        __u8 correlator, __u8 rc , char *local_name, char *remote_name); | 
 | 237 | static int claw_snd_conn_req(struct net_device *dev, __u8 link); | 
 | 238 | static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl); | 
 | 239 | static int claw_snd_sys_validate_rsp(struct net_device *dev, | 
 | 240 |         struct clawctl * p_ctl, __u32 return_code); | 
 | 241 | static int claw_strt_conn_req(struct net_device *dev ); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 242 | static void claw_strt_read(struct net_device *dev, int lock); | 
 | 243 | static void claw_strt_out_IO(struct net_device *dev); | 
 | 244 | static void claw_free_wrt_buf(struct net_device *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 |  | 
 | 246 | /* Functions for unpack reads   */ | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 247 | static void unpack_read(struct net_device *dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 |  | 
| Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 249 | static int claw_pm_prepare(struct ccwgroup_device *gdev) | 
 | 250 | { | 
 | 251 | 	return -EPERM; | 
 | 252 | } | 
 | 253 |  | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 254 | /* the root device for claw group devices */ | 
 | 255 | static struct device *claw_root_dev; | 
 | 256 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | /* ccwgroup table  */ | 
 | 258 |  | 
 | 259 | static struct ccwgroup_driver claw_group_driver = { | 
| Sebastian Ott | 3c190c5 | 2011-03-23 10:16:04 +0100 | [diff] [blame] | 260 | 	.driver = { | 
 | 261 | 		.owner	= THIS_MODULE, | 
 | 262 | 		.name	= "claw", | 
 | 263 | 	}, | 
| Sebastian Ott | 2ced551 | 2012-05-15 18:00:49 +0200 | [diff] [blame] | 264 | 	.setup	     = claw_probe, | 
| Sebastian Ott | 9814fdf | 2012-05-15 18:03:46 +0200 | [diff] [blame] | 265 | 	.remove      = claw_remove_device, | 
 | 266 | 	.set_online  = claw_new_device, | 
 | 267 | 	.set_offline = claw_shutdown_device, | 
| Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 268 | 	.prepare     = claw_pm_prepare, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | }; | 
 | 270 |  | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 271 | static struct ccw_device_id claw_ids[] = { | 
 | 272 | 	{CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw}, | 
 | 273 | 	{}, | 
 | 274 | }; | 
 | 275 | MODULE_DEVICE_TABLE(ccw, claw_ids); | 
 | 276 |  | 
 | 277 | static struct ccw_driver claw_ccw_driver = { | 
| Sebastian Ott | 3bda058 | 2011-03-23 10:16:02 +0100 | [diff] [blame] | 278 | 	.driver = { | 
 | 279 | 		.owner	= THIS_MODULE, | 
 | 280 | 		.name	= "claw", | 
 | 281 | 	}, | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 282 | 	.ids	= claw_ids, | 
 | 283 | 	.probe	= ccwgroup_probe_ccwdev, | 
 | 284 | 	.remove	= ccwgroup_remove_ccwdev, | 
| Peter Oberparleiter | de400d6 | 2011-10-30 15:16:04 +0100 | [diff] [blame] | 285 | 	.int_class = IOINT_CLW, | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 286 | }; | 
 | 287 |  | 
| Sebastian Ott | 2ced551 | 2012-05-15 18:00:49 +0200 | [diff] [blame] | 288 | static ssize_t claw_driver_group_store(struct device_driver *ddrv, | 
 | 289 | 				       const char *buf,	size_t count) | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 290 | { | 
 | 291 | 	int err; | 
| Sebastian Ott | 9814fdf | 2012-05-15 18:03:46 +0200 | [diff] [blame] | 292 | 	err = ccwgroup_create_dev(claw_root_dev, &claw_group_driver, 2, buf); | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 293 | 	return err ? err : count; | 
 | 294 | } | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 295 | static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store); | 
 | 296 |  | 
| Sebastian Ott | a43f8de | 2012-05-15 18:06:29 +0200 | [diff] [blame] | 297 | static struct attribute *claw_drv_attrs[] = { | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 298 | 	&driver_attr_group.attr, | 
 | 299 | 	NULL, | 
 | 300 | }; | 
| Sebastian Ott | a43f8de | 2012-05-15 18:06:29 +0200 | [diff] [blame] | 301 | static struct attribute_group claw_drv_attr_group = { | 
 | 302 | 	.attrs = claw_drv_attrs, | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 303 | }; | 
| Sebastian Ott | a43f8de | 2012-05-15 18:06:29 +0200 | [diff] [blame] | 304 | static const struct attribute_group *claw_drv_attr_groups[] = { | 
 | 305 | 	&claw_drv_attr_group, | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 306 | 	NULL, | 
 | 307 | }; | 
 | 308 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | *       Key functions | 
 | 311 | */ | 
 | 312 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | /*-------------------------------------------------------------------* | 
 | 314 |  *   claw_tx                                                         * | 
 | 315 |  *-------------------------------------------------------------------*/ | 
 | 316 |  | 
 | 317 | static int | 
 | 318 | claw_tx(struct sk_buff *skb, struct net_device *dev) | 
 | 319 | { | 
 | 320 |         int             rc; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 321 | 	struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | 	unsigned long saveflags; | 
 | 323 |         struct chbk *p_ch; | 
 | 324 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 325 | 	CLAW_DBF_TEXT(4, trace, "claw_tx"); | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 326 | 	p_ch = &privptr->channel[WRITE_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 |         spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags); | 
 | 328 |         rc=claw_hw_tx( skb, dev, 1 ); | 
 | 329 |         spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 330 | 	CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc); | 
| Ursula Braun | 8f0c40d | 2009-03-24 03:27:46 +0000 | [diff] [blame] | 331 | 	if (rc) | 
 | 332 | 		rc = NETDEV_TX_BUSY; | 
| Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 333 | 	else | 
 | 334 | 		rc = NETDEV_TX_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 |         return rc; | 
 | 336 | }   /*  end of claw_tx */ | 
 | 337 |  | 
 | 338 | /*------------------------------------------------------------------* | 
 | 339 |  *  pack the collect queue into an skb and return it                * | 
 | 340 |  *   If not packing just return the top skb from the queue          * | 
 | 341 |  *------------------------------------------------------------------*/ | 
 | 342 |  | 
 | 343 | static struct sk_buff * | 
 | 344 | claw_pack_skb(struct claw_privbk *privptr) | 
 | 345 | { | 
 | 346 | 	struct sk_buff *new_skb,*held_skb; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 347 | 	struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | 	struct claw_env  *p_env = privptr->p_env; | 
 | 349 | 	int	pkt_cnt,pk_ind,so_far; | 
 | 350 |  | 
 | 351 | 	new_skb = NULL;		/* assume no dice */ | 
 | 352 | 	pkt_cnt = 0; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 353 | 	CLAW_DBF_TEXT(4, trace, "PackSKBe"); | 
| David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 354 | 	if (!skb_queue_empty(&p_ch->collect_queue)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | 	/* some data */ | 
 | 356 | 		held_skb = skb_dequeue(&p_ch->collect_queue); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | 		if (held_skb) | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 358 | 			dev_kfree_skb_any(held_skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | 		else | 
 | 360 | 			return NULL; | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 361 | 		if (p_env->packing != DO_PACKED) | 
 | 362 | 			return held_skb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | 		/* get a new SKB we will pack at least one */ | 
 | 364 | 		new_skb = dev_alloc_skb(p_env->write_size); | 
 | 365 | 		if (new_skb == NULL) { | 
 | 366 | 			atomic_inc(&held_skb->users); | 
 | 367 | 			skb_queue_head(&p_ch->collect_queue,held_skb); | 
 | 368 | 			return NULL; | 
 | 369 | 		} | 
 | 370 | 		/* we have packed packet and a place to put it  */ | 
 | 371 | 		pk_ind = 1; | 
 | 372 | 		so_far = 0; | 
 | 373 | 		new_skb->cb[1] = 'P'; /* every skb on queue has pack header */ | 
 | 374 | 		while ((pk_ind) && (held_skb != NULL)) { | 
 | 375 | 			if (held_skb->len+so_far <= p_env->write_size-8) { | 
 | 376 | 				memcpy(skb_put(new_skb,held_skb->len), | 
 | 377 | 					held_skb->data,held_skb->len); | 
 | 378 | 				privptr->stats.tx_packets++; | 
 | 379 | 				so_far += held_skb->len; | 
 | 380 | 				pkt_cnt++; | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 381 | 				dev_kfree_skb_any(held_skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | 				held_skb = skb_dequeue(&p_ch->collect_queue); | 
 | 383 | 				if (held_skb) | 
 | 384 | 					atomic_dec(&held_skb->users); | 
 | 385 | 			} else { | 
 | 386 | 				pk_ind = 0; | 
 | 387 | 				atomic_inc(&held_skb->users); | 
 | 388 | 				skb_queue_head(&p_ch->collect_queue,held_skb); | 
 | 389 | 			} | 
 | 390 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | 	} | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 392 | 	CLAW_DBF_TEXT(4, trace, "PackSKBx"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | 	return new_skb; | 
 | 394 | } | 
 | 395 |  | 
 | 396 | /*-------------------------------------------------------------------* | 
 | 397 |  *   claw_change_mtu                                                 * | 
 | 398 |  *                                                                   * | 
 | 399 |  *-------------------------------------------------------------------*/ | 
 | 400 |  | 
 | 401 | static int | 
 | 402 | claw_change_mtu(struct net_device *dev, int new_mtu) | 
 | 403 | { | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 404 | 	struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | 	int buff_size; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 406 | 	CLAW_DBF_TEXT(4, trace, "setmtu"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | 	buff_size = privptr->p_env->write_size; | 
 | 408 |         if ((new_mtu < 60) || (new_mtu > buff_size)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 |                 return -EINVAL; | 
 | 410 |         } | 
 | 411 |         dev->mtu = new_mtu; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 |         return 0; | 
 | 413 | }  /*   end of claw_change_mtu */ | 
 | 414 |  | 
 | 415 |  | 
 | 416 | /*-------------------------------------------------------------------* | 
 | 417 |  *   claw_open                                                       * | 
 | 418 |  *                                                                   * | 
 | 419 |  *-------------------------------------------------------------------*/ | 
 | 420 | static int | 
 | 421 | claw_open(struct net_device *dev) | 
 | 422 | { | 
 | 423 |  | 
 | 424 |         int     rc; | 
 | 425 |         int     i; | 
 | 426 |         unsigned long       saveflags=0; | 
 | 427 |         unsigned long       parm; | 
 | 428 |         struct claw_privbk  *privptr; | 
 | 429 | 	DECLARE_WAITQUEUE(wait, current); | 
 | 430 |         struct timer_list  timer; | 
 | 431 |         struct ccwbk *p_buf; | 
 | 432 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 433 | 	CLAW_DBF_TEXT(4, trace, "open"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 434 | 	privptr = (struct claw_privbk *)dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 |         /*   allocate and initialize CCW blocks */ | 
 | 436 | 	if (privptr->buffs_alloc == 0) { | 
 | 437 | 	        rc=init_ccw_bk(dev); | 
 | 438 |         	if (rc) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 439 | 			CLAW_DBF_TEXT(2, trace, "openmem"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 |                 	return -ENOMEM; | 
 | 441 |         	} | 
 | 442 | 	} | 
 | 443 |         privptr->system_validate_comp=0; | 
 | 444 |         privptr->release_pend=0; | 
 | 445 | 	if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) { | 
 | 446 | 		privptr->p_env->read_size=DEF_PACK_BUFSIZE; | 
 | 447 | 		privptr->p_env->write_size=DEF_PACK_BUFSIZE; | 
 | 448 | 		privptr->p_env->packing=PACKING_ASK; | 
 | 449 | 	} else { | 
 | 450 | 		privptr->p_env->packing=0; | 
 | 451 | 		privptr->p_env->read_size=CLAW_FRAME_SIZE; | 
 | 452 | 		privptr->p_env->write_size=CLAW_FRAME_SIZE; | 
 | 453 | 	} | 
 | 454 |         claw_set_busy(dev); | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 455 | 	tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet, | 
 | 456 | 		(unsigned long) &privptr->channel[READ_CHANNEL]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 |         for ( i = 0; i < 2;  i++) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 458 | 		CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 |                 init_waitqueue_head(&privptr->channel[i].wait); | 
 | 460 | 		/* skb_queue_head_init(&p_ch->io_queue); */ | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 461 | 		if (i == WRITE_CHANNEL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | 			skb_queue_head_init( | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 463 | 				&privptr->channel[WRITE_CHANNEL].collect_queue); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 |                 privptr->channel[i].flag_a = 0; | 
 | 465 |                 privptr->channel[i].IO_active = 0; | 
 | 466 |                 privptr->channel[i].flag  &= ~CLAW_TIMER; | 
 | 467 |                 init_timer(&timer); | 
 | 468 |                 timer.function = (void *)claw_timer; | 
 | 469 |                 timer.data = (unsigned long)(&privptr->channel[i]); | 
 | 470 |                 timer.expires = jiffies + 15*HZ; | 
 | 471 |                 add_timer(&timer); | 
 | 472 |                 spin_lock_irqsave(get_ccwdev_lock( | 
 | 473 | 			privptr->channel[i].cdev), saveflags); | 
 | 474 |                 parm = (unsigned long) &privptr->channel[i]; | 
 | 475 |                 privptr->channel[i].claw_state = CLAW_START_HALT_IO; | 
 | 476 | 		rc = 0; | 
 | 477 | 		add_wait_queue(&privptr->channel[i].wait, &wait); | 
 | 478 |                 rc = ccw_device_halt( | 
 | 479 | 			(struct ccw_device *)privptr->channel[i].cdev,parm); | 
 | 480 |                 set_current_state(TASK_INTERRUPTIBLE); | 
 | 481 |                 spin_unlock_irqrestore( | 
 | 482 | 			get_ccwdev_lock(privptr->channel[i].cdev), saveflags); | 
 | 483 |                 schedule(); | 
 | 484 | 		set_current_state(TASK_RUNNING); | 
 | 485 |                 remove_wait_queue(&privptr->channel[i].wait, &wait); | 
 | 486 |                 if(rc != 0) | 
 | 487 |                         ccw_check_return_code(privptr->channel[i].cdev, rc); | 
 | 488 |                 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00) | 
 | 489 |                         del_timer(&timer); | 
 | 490 |         } | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 491 | 	if ((((privptr->channel[READ_CHANNEL].last_dstat | | 
 | 492 | 		privptr->channel[WRITE_CHANNEL].last_dstat) & | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 |            ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) || | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 494 | 	   (((privptr->channel[READ_CHANNEL].flag | | 
 | 495 | 		privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) { | 
 | 496 | 		dev_info(&privptr->channel[READ_CHANNEL].cdev->dev, | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 497 | 			"%s: remote side is not ready\n", dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 498 | 		CLAW_DBF_TEXT(2, trace, "notrdy"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 |  | 
 | 500 |                 for ( i = 0; i < 2;  i++) { | 
 | 501 |                         spin_lock_irqsave( | 
 | 502 | 				get_ccwdev_lock(privptr->channel[i].cdev), | 
 | 503 | 				saveflags); | 
 | 504 |                         parm = (unsigned long) &privptr->channel[i]; | 
 | 505 |                         privptr->channel[i].claw_state = CLAW_STOP; | 
 | 506 |                         rc = ccw_device_halt( | 
 | 507 | 				(struct ccw_device *)&privptr->channel[i].cdev, | 
 | 508 | 				parm); | 
 | 509 |                         spin_unlock_irqrestore( | 
 | 510 | 				get_ccwdev_lock(privptr->channel[i].cdev), | 
 | 511 | 				saveflags); | 
 | 512 |                         if (rc != 0) { | 
 | 513 |                                 ccw_check_return_code( | 
 | 514 | 					privptr->channel[i].cdev, rc); | 
 | 515 |                         } | 
 | 516 |                 } | 
 | 517 |                 free_pages((unsigned long)privptr->p_buff_ccw, | 
 | 518 | 			(int)pages_to_order_of_mag(privptr->p_buff_ccw_num)); | 
 | 519 |                 if (privptr->p_env->read_size < PAGE_SIZE) { | 
 | 520 |                         free_pages((unsigned long)privptr->p_buff_read, | 
 | 521 | 			       (int)pages_to_order_of_mag( | 
 | 522 | 			       		privptr->p_buff_read_num)); | 
 | 523 |                 } | 
 | 524 |                 else { | 
 | 525 |                         p_buf=privptr->p_read_active_first; | 
 | 526 |                         while (p_buf!=NULL) { | 
 | 527 |                                 free_pages((unsigned long)p_buf->p_buffer, | 
 | 528 | 				      (int)pages_to_order_of_mag( | 
 | 529 | 				      	privptr->p_buff_pages_perread )); | 
 | 530 |                                 p_buf=p_buf->next; | 
 | 531 |                         } | 
 | 532 |                 } | 
 | 533 |                 if (privptr->p_env->write_size < PAGE_SIZE ) { | 
 | 534 |                         free_pages((unsigned long)privptr->p_buff_write, | 
 | 535 | 			     (int)pages_to_order_of_mag( | 
 | 536 | 			     	privptr->p_buff_write_num)); | 
 | 537 |                 } | 
 | 538 |                 else { | 
 | 539 |                         p_buf=privptr->p_write_active_first; | 
 | 540 |                         while (p_buf!=NULL) { | 
 | 541 |                                 free_pages((unsigned long)p_buf->p_buffer, | 
 | 542 | 				     (int)pages_to_order_of_mag( | 
 | 543 | 				     	privptr->p_buff_pages_perwrite )); | 
 | 544 |                                 p_buf=p_buf->next; | 
 | 545 |                         } | 
 | 546 |                 } | 
 | 547 | 		privptr->buffs_alloc = 0; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 548 | 		privptr->channel[READ_CHANNEL].flag = 0x00; | 
 | 549 | 		privptr->channel[WRITE_CHANNEL].flag = 0x00; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 |                 privptr->p_buff_ccw=NULL; | 
 | 551 |                 privptr->p_buff_read=NULL; | 
 | 552 |                 privptr->p_buff_write=NULL; | 
 | 553 |                 claw_clear_busy(dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 554 | 		CLAW_DBF_TEXT(2, trace, "open EIO"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 |                 return -EIO; | 
 | 556 |         } | 
 | 557 |  | 
 | 558 |         /*   Send SystemValidate command */ | 
 | 559 |  | 
 | 560 |         claw_clear_busy(dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 561 | 	CLAW_DBF_TEXT(4, trace, "openok"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 |         return 0; | 
 | 563 | }    /*     end of claw_open    */ | 
 | 564 |  | 
 | 565 | /*-------------------------------------------------------------------* | 
 | 566 | *                                                                    * | 
 | 567 | *       claw_irq_handler                                             * | 
 | 568 | *                                                                    * | 
 | 569 | *--------------------------------------------------------------------*/ | 
 | 570 | static void | 
 | 571 | claw_irq_handler(struct ccw_device *cdev, | 
 | 572 | 	unsigned long intparm, struct irb *irb) | 
 | 573 | { | 
 | 574 |         struct chbk *p_ch = NULL; | 
 | 575 |         struct claw_privbk *privptr = NULL; | 
 | 576 |         struct net_device *dev = NULL; | 
 | 577 |         struct claw_env  *p_env; | 
 | 578 |         struct chbk *p_ch_r=NULL; | 
 | 579 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 580 | 	CLAW_DBF_TEXT(4, trace, "clawirq"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 |         /* Bypass all 'unsolicited interrupts' */ | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 582 | 	privptr = dev_get_drvdata(&cdev->dev); | 
 | 583 | 	if (!privptr) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 584 | 		dev_warn(&cdev->dev, "An uninitialized CLAW device received an" | 
 | 585 | 			" IRQ, c-%02x d-%02x\n", | 
 | 586 | 			irb->scsw.cmd.cstat, irb->scsw.cmd.dstat); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 587 | 		CLAW_DBF_TEXT(2, trace, "badirq"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 |                 return; | 
 | 589 |         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 |  | 
 | 591 | 	/* Try to extract channel from driver data. */ | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 592 | 	if (privptr->channel[READ_CHANNEL].cdev == cdev) | 
 | 593 | 		p_ch = &privptr->channel[READ_CHANNEL]; | 
 | 594 | 	else if (privptr->channel[WRITE_CHANNEL].cdev == cdev) | 
 | 595 | 		p_ch = &privptr->channel[WRITE_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | 	else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 597 | 		dev_warn(&cdev->dev, "The device is not a CLAW device\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 598 | 		CLAW_DBF_TEXT(2, trace, "badchan"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | 		return; | 
 | 600 | 	} | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 601 | 	CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 |  | 
 | 603 | 	dev = (struct net_device *) (p_ch->ndev); | 
 | 604 |         p_env=privptr->p_env; | 
 | 605 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | 	/* Copy interruption response block. */ | 
 | 607 | 	memcpy(p_ch->irb, irb, sizeof(struct irb)); | 
 | 608 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 609 | 	/* Check for good subchannel return code, otherwise info message */ | 
| Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 610 | 	if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 611 | 		dev_info(&cdev->dev, | 
 | 612 | 			"%s: subchannel check for device: %04x -" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | 			" Sch Stat %02x  Dev Stat %02x CPA - %04x\n", | 
 | 614 |                         dev->name, p_ch->devno, | 
| Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 615 | 			irb->scsw.cmd.cstat, irb->scsw.cmd.dstat, | 
 | 616 | 			irb->scsw.cmd.cpa); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 617 | 		CLAW_DBF_TEXT(2, trace, "chanchk"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 |                 /* return; */ | 
 | 619 |         } | 
 | 620 |  | 
 | 621 |         /* Check the reason-code of a unit check */ | 
| Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 622 | 	if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 |                 ccw_check_unit_check(p_ch, irb->ecw[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 |  | 
 | 625 |         /* State machine to bring the connection up, down and to restart */ | 
| Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 626 | 	p_ch->last_dstat = irb->scsw.cmd.dstat; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 |  | 
 | 628 |         switch (p_ch->claw_state) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 629 | 	case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */ | 
 | 630 | 		if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || | 
 | 631 | 		(p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || | 
 | 632 | 		(p_ch->irb->scsw.cmd.stctl == | 
 | 633 | 		(SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) | 
 | 634 | 			return; | 
 | 635 | 		wake_up(&p_ch->wait);   /* wake up claw_release */ | 
 | 636 | 		CLAW_DBF_TEXT(4, trace, "stop"); | 
 | 637 | 		return; | 
 | 638 | 	case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open  */ | 
 | 639 | 		if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || | 
 | 640 | 		(p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || | 
 | 641 | 		(p_ch->irb->scsw.cmd.stctl == | 
 | 642 | 		(SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { | 
 | 643 | 			CLAW_DBF_TEXT(4, trace, "haltio"); | 
 | 644 | 			return; | 
 | 645 | 		} | 
 | 646 | 		if (p_ch->flag == CLAW_READ) { | 
 | 647 | 			p_ch->claw_state = CLAW_START_READ; | 
 | 648 | 			wake_up(&p_ch->wait); /* wake claw_open (READ)*/ | 
 | 649 | 		} else if (p_ch->flag == CLAW_WRITE) { | 
 | 650 | 			p_ch->claw_state = CLAW_START_WRITE; | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 651 | 			/*      send SYSTEM_VALIDATE                    */ | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 652 | 			claw_strt_read(dev, LOCK_NO); | 
 | 653 | 			claw_send_control(dev, | 
 | 654 | 				SYSTEM_VALIDATE_REQUEST, | 
 | 655 | 				0, 0, 0, | 
 | 656 | 				p_env->host_name, | 
 | 657 | 				p_env->adapter_name); | 
 | 658 | 		} else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 659 | 			dev_warn(&cdev->dev, "The CLAW device received" | 
 | 660 | 				" an unexpected IRQ, " | 
 | 661 | 				"c-%02x d-%02x\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 662 | 				irb->scsw.cmd.cstat, | 
 | 663 | 				irb->scsw.cmd.dstat); | 
 | 664 | 			return; | 
 | 665 | 			} | 
 | 666 | 		CLAW_DBF_TEXT(4, trace, "haltio"); | 
 | 667 | 		return; | 
 | 668 | 	case CLAW_START_READ: | 
 | 669 | 		CLAW_DBF_TEXT(4, trace, "ReadIRQ"); | 
 | 670 | 		if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { | 
 | 671 | 			clear_bit(0, (void *)&p_ch->IO_active); | 
 | 672 | 			if ((p_ch->irb->ecw[0] & 0x41) == 0x41 || | 
 | 673 | 			    (p_ch->irb->ecw[0] & 0x40) == 0x40 || | 
 | 674 | 			    (p_ch->irb->ecw[0])        == 0) { | 
 | 675 | 				privptr->stats.rx_errors++; | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 676 | 				dev_info(&cdev->dev, | 
 | 677 | 					"%s: Restart is required after remote " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 678 | 					"side recovers \n", | 
 | 679 | 					dev->name); | 
 | 680 | 			} | 
 | 681 | 			CLAW_DBF_TEXT(4, trace, "notrdy"); | 
 | 682 | 			return; | 
 | 683 | 		} | 
 | 684 | 		if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) && | 
 | 685 | 			(p_ch->irb->scsw.cmd.dstat == 0)) { | 
 | 686 | 			if (test_and_set_bit(CLAW_BH_ACTIVE, | 
 | 687 | 				(void *)&p_ch->flag_a) == 0) | 
 | 688 | 				tasklet_schedule(&p_ch->tasklet); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | 			else | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 690 | 				CLAW_DBF_TEXT(4, trace, "PCINoBH"); | 
 | 691 | 			CLAW_DBF_TEXT(4, trace, "PCI_read"); | 
 | 692 | 			return; | 
 | 693 | 		} | 
 | 694 | 		if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || | 
 | 695 | 		 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || | 
 | 696 | 		 (p_ch->irb->scsw.cmd.stctl == | 
 | 697 | 		 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { | 
 | 698 | 			CLAW_DBF_TEXT(4, trace, "SPend_rd"); | 
 | 699 | 			return; | 
 | 700 | 		} | 
 | 701 | 		clear_bit(0, (void *)&p_ch->IO_active); | 
 | 702 | 		claw_clearbit_busy(TB_RETRY, dev); | 
 | 703 | 		if (test_and_set_bit(CLAW_BH_ACTIVE, | 
 | 704 | 			(void *)&p_ch->flag_a) == 0) | 
 | 705 | 			tasklet_schedule(&p_ch->tasklet); | 
 | 706 | 		else | 
 | 707 | 			CLAW_DBF_TEXT(4, trace, "RdBHAct"); | 
 | 708 | 		CLAW_DBF_TEXT(4, trace, "RdIRQXit"); | 
 | 709 | 		return; | 
 | 710 | 	case CLAW_START_WRITE: | 
 | 711 | 		if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 712 | 			dev_info(&cdev->dev, | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 713 | 				"%s: Unit Check Occurred in " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 714 | 				"write channel\n", dev->name); | 
 | 715 | 			clear_bit(0, (void *)&p_ch->IO_active); | 
 | 716 | 			if (p_ch->irb->ecw[0] & 0x80) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 717 | 				dev_info(&cdev->dev, | 
 | 718 | 					"%s: Resetting Event " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 719 | 					"occurred:\n", dev->name); | 
 | 720 | 				init_timer(&p_ch->timer); | 
 | 721 | 				p_ch->timer.function = | 
 | 722 | 					(void *)claw_write_retry; | 
 | 723 | 				p_ch->timer.data = (unsigned long)p_ch; | 
 | 724 | 				p_ch->timer.expires = jiffies + 10*HZ; | 
 | 725 | 				add_timer(&p_ch->timer); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 726 | 				dev_info(&cdev->dev, | 
 | 727 | 					"%s: write connection " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 728 | 					"restarting\n", dev->name); | 
 | 729 | 			} | 
 | 730 | 			CLAW_DBF_TEXT(4, trace, "rstrtwrt"); | 
 | 731 | 			return; | 
 | 732 | 		} | 
 | 733 | 		if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) { | 
 | 734 | 			clear_bit(0, (void *)&p_ch->IO_active); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 735 | 			dev_info(&cdev->dev, | 
 | 736 | 				"%s: Unit Exception " | 
 | 737 | 				"occurred in write channel\n", | 
 | 738 | 				dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 739 | 		} | 
 | 740 | 		if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || | 
 | 741 | 		(p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || | 
 | 742 | 		(p_ch->irb->scsw.cmd.stctl == | 
 | 743 | 		(SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { | 
 | 744 | 			CLAW_DBF_TEXT(4, trace, "writeUE"); | 
 | 745 | 			return; | 
 | 746 | 		} | 
 | 747 | 		clear_bit(0, (void *)&p_ch->IO_active); | 
 | 748 | 		if (claw_test_and_setbit_busy(TB_TX, dev) == 0) { | 
 | 749 | 			claw_write_next(p_ch); | 
 | 750 | 			claw_clearbit_busy(TB_TX, dev); | 
 | 751 | 			claw_clear_busy(dev); | 
 | 752 | 		} | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 753 | 		p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL]; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 754 | 		if (test_and_set_bit(CLAW_BH_ACTIVE, | 
 | 755 | 			(void *)&p_ch_r->flag_a) == 0) | 
 | 756 | 			tasklet_schedule(&p_ch_r->tasklet); | 
 | 757 | 		CLAW_DBF_TEXT(4, trace, "StWtExit"); | 
 | 758 | 		return; | 
 | 759 | 	default: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 760 | 		dev_warn(&cdev->dev, | 
 | 761 | 			"The CLAW device for %s received an unexpected IRQ\n", | 
 | 762 | 			 dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 763 | 		CLAW_DBF_TEXT(2, trace, "badIRQ"); | 
 | 764 | 		return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 |         } | 
 | 766 |  | 
 | 767 | }       /*   end of claw_irq_handler    */ | 
 | 768 |  | 
 | 769 |  | 
 | 770 | /*-------------------------------------------------------------------* | 
 | 771 | *       claw_irq_tasklet                                             * | 
 | 772 | *                                                                    * | 
 | 773 | *--------------------------------------------------------------------*/ | 
 | 774 | static void | 
 | 775 | claw_irq_tasklet ( unsigned long data ) | 
 | 776 | { | 
 | 777 | 	struct chbk * p_ch; | 
 | 778 |         struct net_device  *dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 |  | 
 | 780 | 	p_ch = (struct chbk *) data; | 
 | 781 |         dev = (struct net_device *)p_ch->ndev; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 782 | 	CLAW_DBF_TEXT(4, trace, "IRQtask"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 |         unpack_read(dev); | 
 | 784 |         clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 785 | 	CLAW_DBF_TEXT(4, trace, "TskletXt"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 |         return; | 
 | 787 | }       /*    end of claw_irq_bh    */ | 
 | 788 |  | 
 | 789 | /*-------------------------------------------------------------------* | 
 | 790 | *       claw_release                                                 * | 
 | 791 | *                                                                    * | 
 | 792 | *--------------------------------------------------------------------*/ | 
 | 793 | static int | 
 | 794 | claw_release(struct net_device *dev) | 
 | 795 | { | 
 | 796 |         int                rc; | 
 | 797 |         int                i; | 
 | 798 |         unsigned long      saveflags; | 
 | 799 |         unsigned long      parm; | 
 | 800 |         struct claw_privbk *privptr; | 
 | 801 |         DECLARE_WAITQUEUE(wait, current); | 
 | 802 |         struct ccwbk*             p_this_ccw; | 
 | 803 |         struct ccwbk*             p_buf; | 
 | 804 |  | 
 | 805 | 	if (!dev) | 
 | 806 |                 return 0; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 807 | 	privptr = (struct claw_privbk *)dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 |         if (!privptr) | 
 | 809 |                 return 0; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 810 | 	CLAW_DBF_TEXT(4, trace, "release"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 |         privptr->release_pend=1; | 
 | 812 |         claw_setbit_busy(TB_STOP,dev); | 
 | 813 |         for ( i = 1; i >=0 ;  i--) { | 
 | 814 |                 spin_lock_irqsave( | 
 | 815 | 			get_ccwdev_lock(privptr->channel[i].cdev), saveflags); | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 816 | 	     /*   del_timer(&privptr->channel[READ_CHANNEL].timer);  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 |  		privptr->channel[i].claw_state = CLAW_STOP; | 
 | 818 |                 privptr->channel[i].IO_active = 0; | 
 | 819 |                 parm = (unsigned long) &privptr->channel[i]; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 820 | 		if (i == WRITE_CHANNEL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | 			claw_purge_skb_queue( | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 822 | 				&privptr->channel[WRITE_CHANNEL].collect_queue); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 |                 rc = ccw_device_halt (privptr->channel[i].cdev, parm); | 
 | 824 | 	        if (privptr->system_validate_comp==0x00)  /* never opened? */ | 
 | 825 |                    init_waitqueue_head(&privptr->channel[i].wait); | 
 | 826 |                 add_wait_queue(&privptr->channel[i].wait, &wait); | 
 | 827 |                 set_current_state(TASK_INTERRUPTIBLE); | 
 | 828 | 	        spin_unlock_irqrestore( | 
 | 829 | 			get_ccwdev_lock(privptr->channel[i].cdev), saveflags); | 
 | 830 | 	        schedule(); | 
 | 831 | 		set_current_state(TASK_RUNNING); | 
 | 832 | 	        remove_wait_queue(&privptr->channel[i].wait, &wait); | 
 | 833 | 	        if (rc != 0) { | 
 | 834 |                         ccw_check_return_code(privptr->channel[i].cdev, rc); | 
 | 835 |                 } | 
 | 836 |         } | 
 | 837 | 	if (privptr->pk_skb != NULL) { | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 838 | 		dev_kfree_skb_any(privptr->pk_skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | 		privptr->pk_skb = NULL; | 
 | 840 | 	} | 
 | 841 | 	if(privptr->buffs_alloc != 1) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 842 | 		CLAW_DBF_TEXT(4, trace, "none2fre"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | 		return 0; | 
 | 844 | 	} | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 845 | 	CLAW_DBF_TEXT(4, trace, "freebufs"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | 	if (privptr->p_buff_ccw != NULL) { | 
 | 847 |         	free_pages((unsigned long)privptr->p_buff_ccw, | 
 | 848 | 	        	(int)pages_to_order_of_mag(privptr->p_buff_ccw_num)); | 
 | 849 | 	} | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 850 | 	CLAW_DBF_TEXT(4, trace, "freeread"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 |         if (privptr->p_env->read_size < PAGE_SIZE) { | 
 | 852 | 	    if (privptr->p_buff_read != NULL) { | 
 | 853 |                 free_pages((unsigned long)privptr->p_buff_read, | 
 | 854 | 		      (int)pages_to_order_of_mag(privptr->p_buff_read_num)); | 
 | 855 | 		} | 
 | 856 |         } | 
 | 857 |         else { | 
 | 858 |                 p_buf=privptr->p_read_active_first; | 
 | 859 |                 while (p_buf!=NULL) { | 
 | 860 |                         free_pages((unsigned long)p_buf->p_buffer, | 
 | 861 | 			     (int)pages_to_order_of_mag( | 
 | 862 | 			     	privptr->p_buff_pages_perread )); | 
 | 863 |                         p_buf=p_buf->next; | 
 | 864 |                 } | 
 | 865 |         } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 866 | 	 CLAW_DBF_TEXT(4, trace, "freewrit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 |         if (privptr->p_env->write_size < PAGE_SIZE ) { | 
 | 868 |                 free_pages((unsigned long)privptr->p_buff_write, | 
 | 869 | 		      (int)pages_to_order_of_mag(privptr->p_buff_write_num)); | 
 | 870 |         } | 
 | 871 |         else { | 
 | 872 |                 p_buf=privptr->p_write_active_first; | 
 | 873 |                 while (p_buf!=NULL) { | 
 | 874 |                         free_pages((unsigned long)p_buf->p_buffer, | 
 | 875 | 			      (int)pages_to_order_of_mag( | 
 | 876 | 			      privptr->p_buff_pages_perwrite )); | 
 | 877 |                         p_buf=p_buf->next; | 
 | 878 |                 } | 
 | 879 |         } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 880 | 	 CLAW_DBF_TEXT(4, trace, "clearptr"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | 	privptr->buffs_alloc = 0; | 
 | 882 |         privptr->p_buff_ccw=NULL; | 
 | 883 |         privptr->p_buff_read=NULL; | 
 | 884 |         privptr->p_buff_write=NULL; | 
 | 885 |         privptr->system_validate_comp=0; | 
 | 886 |         privptr->release_pend=0; | 
 | 887 |         /*      Remove any writes that were pending and reset all reads   */ | 
 | 888 |         p_this_ccw=privptr->p_read_active_first; | 
 | 889 |         while (p_this_ccw!=NULL) { | 
 | 890 |                 p_this_ccw->header.length=0xffff; | 
 | 891 |                 p_this_ccw->header.opcode=0xff; | 
 | 892 |                 p_this_ccw->header.flag=0x00; | 
 | 893 |                 p_this_ccw=p_this_ccw->next; | 
 | 894 |         } | 
 | 895 |  | 
 | 896 |         while (privptr->p_write_active_first!=NULL) { | 
 | 897 |                 p_this_ccw=privptr->p_write_active_first; | 
 | 898 |                 p_this_ccw->header.flag=CLAW_PENDING; | 
 | 899 |                 privptr->p_write_active_first=p_this_ccw->next; | 
 | 900 |                 p_this_ccw->next=privptr->p_write_free_chain; | 
 | 901 |                 privptr->p_write_free_chain=p_this_ccw; | 
 | 902 |                 ++privptr->write_free_count; | 
 | 903 |         } | 
 | 904 |         privptr->p_write_active_last=NULL; | 
 | 905 |         privptr->mtc_logical_link = -1; | 
 | 906 |         privptr->mtc_skipping = 1; | 
 | 907 |         privptr->mtc_offset=0; | 
 | 908 |  | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 909 | 	if (((privptr->channel[READ_CHANNEL].last_dstat | | 
 | 910 | 		privptr->channel[WRITE_CHANNEL].last_dstat) & | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | 		~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) { | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 912 | 		dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev, | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 913 | 			"Deactivating %s completed with incorrect" | 
 | 914 | 			" subchannel status " | 
 | 915 | 			"(read %02x, write %02x)\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 |                 dev->name, | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 917 | 		privptr->channel[READ_CHANNEL].last_dstat, | 
 | 918 | 		privptr->channel[WRITE_CHANNEL].last_dstat); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 919 | 		 CLAW_DBF_TEXT(2, trace, "badclose"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 |         } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 921 | 	CLAW_DBF_TEXT(4, trace, "rlsexit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 |         return 0; | 
 | 923 | }      /* end of claw_release     */ | 
 | 924 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | /*-------------------------------------------------------------------* | 
 | 926 | *       claw_write_retry                                             * | 
 | 927 | *                                                                    * | 
 | 928 | *--------------------------------------------------------------------*/ | 
 | 929 |  | 
 | 930 | static void | 
 | 931 | claw_write_retry ( struct chbk *p_ch ) | 
 | 932 | { | 
 | 933 |  | 
 | 934 |         struct net_device  *dev=p_ch->ndev; | 
 | 935 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 936 | 	CLAW_DBF_TEXT(4, trace, "w_retry"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 |         if (p_ch->claw_state == CLAW_STOP) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 |         	return; | 
 | 939 |         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | 	claw_strt_out_IO( dev ); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 941 | 	CLAW_DBF_TEXT(4, trace, "rtry_xit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 |         return; | 
 | 943 | }      /* end of claw_write_retry      */ | 
 | 944 |  | 
 | 945 |  | 
 | 946 | /*-------------------------------------------------------------------* | 
 | 947 | *       claw_write_next                                              * | 
 | 948 | *                                                                    * | 
 | 949 | *--------------------------------------------------------------------*/ | 
 | 950 |  | 
 | 951 | static void | 
 | 952 | claw_write_next ( struct chbk * p_ch ) | 
 | 953 | { | 
 | 954 |  | 
 | 955 |         struct net_device  *dev; | 
 | 956 |         struct claw_privbk *privptr=NULL; | 
 | 957 | 	struct sk_buff *pk_skb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 959 | 	CLAW_DBF_TEXT(4, trace, "claw_wrt"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 |         if (p_ch->claw_state == CLAW_STOP) | 
 | 961 |                 return; | 
 | 962 |         dev = (struct net_device *) p_ch->ndev; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 963 | 	privptr = (struct claw_privbk *) dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 |         claw_free_wrt_buf( dev ); | 
 | 965 | 	if ((privptr->write_free_count > 0) && | 
| David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 966 | 	    !skb_queue_empty(&p_ch->collect_queue)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | 	  	pk_skb = claw_pack_skb(privptr); | 
 | 968 | 		while (pk_skb != NULL) { | 
| Heiko Carstens | 38ed18f | 2011-05-12 18:45:04 +0000 | [diff] [blame] | 969 | 			claw_hw_tx(pk_skb, dev, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | 			if (privptr->write_free_count > 0) { | 
 | 971 | 	   			pk_skb = claw_pack_skb(privptr); | 
 | 972 | 			} else | 
 | 973 | 				pk_skb = NULL; | 
 | 974 | 		} | 
 | 975 | 	} | 
 | 976 |         if (privptr->p_write_active_first!=NULL) { | 
 | 977 |                 claw_strt_out_IO(dev); | 
 | 978 |         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 |         return; | 
 | 980 | }      /* end of claw_write_next      */ | 
 | 981 |  | 
 | 982 | /*-------------------------------------------------------------------* | 
 | 983 | *                                                                    * | 
 | 984 | *       claw_timer                                                   * | 
 | 985 | *--------------------------------------------------------------------*/ | 
 | 986 |  | 
 | 987 | static void | 
 | 988 | claw_timer ( struct chbk * p_ch ) | 
 | 989 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 990 | 	CLAW_DBF_TEXT(4, trace, "timer"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 |         p_ch->flag |= CLAW_TIMER; | 
 | 992 |         wake_up(&p_ch->wait); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 |         return; | 
 | 994 | }      /* end of claw_timer  */ | 
 | 995 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | /* | 
 | 997 | * | 
 | 998 | *       functions | 
 | 999 | */ | 
 | 1000 |  | 
 | 1001 |  | 
 | 1002 | /*-------------------------------------------------------------------* | 
 | 1003 | *                                                                    * | 
 | 1004 | *     pages_to_order_of_mag                                          * | 
 | 1005 | *                                                                    * | 
 | 1006 | *    takes a number of pages from 1 to 512 and returns the           * | 
 | 1007 | *    log(num_pages)/log(2) get_free_pages() needs a base 2 order     * | 
 | 1008 | *    of magnitude get_free_pages() has an upper order of 9           * | 
 | 1009 | *--------------------------------------------------------------------*/ | 
 | 1010 |  | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1011 | static int | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | pages_to_order_of_mag(int num_of_pages) | 
 | 1013 | { | 
 | 1014 | 	int	order_of_mag=1;		/* assume 2 pages */ | 
| Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1015 | 	int	nump; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1016 |  | 
 | 1017 | 	CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | 	if (num_of_pages == 1)   {return 0; }  /* magnitude of 0 = 1 page */ | 
 | 1019 | 	/* 512 pages = 2Meg on 4k page systems */ | 
 | 1020 | 	if (num_of_pages >= 512) {return 9; } | 
 | 1021 | 	/* we have two or more pages order is at least 1 */ | 
 | 1022 | 	for (nump=2 ;nump <= 512;nump*=2) { | 
 | 1023 | 	  if (num_of_pages <= nump) | 
 | 1024 | 		  break; | 
 | 1025 | 	  order_of_mag +=1; | 
 | 1026 | 	} | 
 | 1027 | 	if (order_of_mag > 9) { order_of_mag = 9; }  /* I know it's paranoid */ | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1028 | 	CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | 	return order_of_mag; | 
 | 1030 | } | 
 | 1031 |  | 
 | 1032 | /*-------------------------------------------------------------------* | 
 | 1033 | *                                                                    * | 
 | 1034 | *     add_claw_reads                                                 * | 
 | 1035 | *                                                                    * | 
 | 1036 | *--------------------------------------------------------------------*/ | 
 | 1037 | static int | 
 | 1038 | add_claw_reads(struct net_device *dev, struct ccwbk* p_first, | 
 | 1039 | 	struct ccwbk* p_last) | 
 | 1040 | { | 
 | 1041 |         struct claw_privbk *privptr; | 
 | 1042 |         struct ccw1  temp_ccw; | 
 | 1043 |         struct endccw * p_end; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1044 | 	CLAW_DBF_TEXT(4, trace, "addreads"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1045 | 	privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 |         p_end = privptr->p_end_ccw; | 
 | 1047 |  | 
 | 1048 |         /* first CCW and last CCW contains a new set of read channel programs | 
 | 1049 |         *       to apend the running channel programs | 
 | 1050 |         */ | 
 | 1051 |         if ( p_first==NULL) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1052 | 		CLAW_DBF_TEXT(4, trace, "addexit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 |                 return 0; | 
 | 1054 |         } | 
 | 1055 |  | 
 | 1056 |         /* set up ending CCW sequence for this segment */ | 
 | 1057 |         if (p_end->read1) { | 
 | 1058 |                 p_end->read1=0x00;    /*  second ending CCW is now active */ | 
 | 1059 |                 /*      reset ending CCWs and setup TIC CCWs              */ | 
 | 1060 |                 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1061 |                 p_end->read2_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
 | 1062 |                 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1); | 
 | 1063 |                 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1); | 
 | 1064 |                 p_end->read2_nop2.cda=0; | 
 | 1065 |                 p_end->read2_nop2.count=1; | 
 | 1066 |         } | 
 | 1067 |         else { | 
 | 1068 |                 p_end->read1=0x01;  /* first ending CCW is now active */ | 
 | 1069 |                 /*      reset ending CCWs and setup TIC CCWs          */ | 
 | 1070 |                 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1071 |                 p_end->read1_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
 | 1072 |                 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1); | 
 | 1073 |                 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1); | 
 | 1074 |                 p_end->read1_nop2.cda=0; | 
 | 1075 |                 p_end->read1_nop2.count=1; | 
 | 1076 |         } | 
 | 1077 |  | 
 | 1078 |         if ( privptr-> p_read_active_first ==NULL ) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1079 | 		privptr->p_read_active_first = p_first;  /*  set new first */ | 
 | 1080 | 		privptr->p_read_active_last  = p_last;   /*  set new last  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 |         } | 
 | 1082 |         else { | 
 | 1083 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 |                 /* set up TIC ccw  */ | 
 | 1085 |                 temp_ccw.cda= (__u32)__pa(&p_first->read); | 
 | 1086 |                 temp_ccw.count=0; | 
 | 1087 |                 temp_ccw.flags=0; | 
 | 1088 |                 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC; | 
 | 1089 |  | 
 | 1090 |  | 
 | 1091 |                 if (p_end->read1) { | 
 | 1092 |  | 
 | 1093 |                /* first set of CCW's is chained to the new read              */ | 
 | 1094 |                /* chain, so the second set is chained to the active chain.   */ | 
 | 1095 |                /* Therefore modify the second set to point to the new        */ | 
 | 1096 |                /* read chain set up TIC CCWs                                 */ | 
 | 1097 |                /* make sure we update the CCW so channel doesn't fetch it    */ | 
 | 1098 |                /* when it's only half done                                   */ | 
 | 1099 |                         memcpy( &p_end->read2_nop2, &temp_ccw , | 
 | 1100 | 				sizeof(struct ccw1)); | 
 | 1101 |                         privptr->p_read_active_last->r_TIC_1.cda= | 
 | 1102 | 				(__u32)__pa(&p_first->read); | 
 | 1103 |                         privptr->p_read_active_last->r_TIC_2.cda= | 
 | 1104 | 				(__u32)__pa(&p_first->read); | 
 | 1105 |                 } | 
 | 1106 |                 else { | 
 | 1107 |                         /* make sure we update the CCW so channel doesn't   */ | 
 | 1108 | 			/* fetch it when it is only half done               */ | 
 | 1109 |                         memcpy( &p_end->read1_nop2, &temp_ccw , | 
 | 1110 | 				sizeof(struct ccw1)); | 
 | 1111 |                         privptr->p_read_active_last->r_TIC_1.cda= | 
 | 1112 | 				(__u32)__pa(&p_first->read); | 
 | 1113 |                         privptr->p_read_active_last->r_TIC_2.cda= | 
 | 1114 | 				(__u32)__pa(&p_first->read); | 
 | 1115 |                 } | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1116 | 		/*      chain in new set of blocks                         */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 |                 privptr->p_read_active_last->next = p_first; | 
 | 1118 |                 privptr->p_read_active_last=p_last; | 
 | 1119 |         } /* end of if ( privptr-> p_read_active_first ==NULL)  */ | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1120 | 	CLAW_DBF_TEXT(4, trace, "addexit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 |         return 0; | 
 | 1122 | }    /*     end of add_claw_reads   */ | 
 | 1123 |  | 
 | 1124 | /*-------------------------------------------------------------------* | 
 | 1125 |  *   ccw_check_return_code                                           * | 
 | 1126 |  *                                                                   * | 
 | 1127 |  *-------------------------------------------------------------------*/ | 
 | 1128 |  | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1129 | static void | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | ccw_check_return_code(struct ccw_device *cdev, int return_code) | 
 | 1131 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1132 | 	CLAW_DBF_TEXT(4, trace, "ccwret"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 |         if (return_code != 0) { | 
 | 1134 |                 switch (return_code) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1135 | 		case -EBUSY: /* BUSY is a transient state no action needed */ | 
 | 1136 | 			break; | 
 | 1137 | 		case -ENODEV: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1138 | 			dev_err(&cdev->dev, "The remote channel adapter is not" | 
 | 1139 | 				" available\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1140 | 			break; | 
 | 1141 | 		case -EINVAL: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1142 | 			dev_err(&cdev->dev, | 
 | 1143 | 				"The status of the remote channel adapter" | 
 | 1144 | 				" is not valid\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1145 | 			break; | 
 | 1146 | 		default: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1147 | 			dev_err(&cdev->dev, "The common device layer" | 
 | 1148 | 				" returned error code %d\n", | 
 | 1149 | 				  return_code); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1150 | 		} | 
 | 1151 | 	} | 
 | 1152 | 	CLAW_DBF_TEXT(4, trace, "ccwret"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | }    /*    end of ccw_check_return_code   */ | 
 | 1154 |  | 
 | 1155 | /*-------------------------------------------------------------------* | 
 | 1156 | *       ccw_check_unit_check                                         * | 
 | 1157 | *--------------------------------------------------------------------*/ | 
 | 1158 |  | 
| Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1159 | static void | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | ccw_check_unit_check(struct chbk * p_ch, unsigned char sense ) | 
 | 1161 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1162 | 	struct net_device *ndev = p_ch->ndev; | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1163 | 	struct device *dev = &p_ch->cdev->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1165 | 	CLAW_DBF_TEXT(4, trace, "unitchek"); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1166 | 	dev_warn(dev, "The communication peer of %s disconnected\n", | 
 | 1167 | 		ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 |  | 
| Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1169 | 	if (sense & 0x40) { | 
 | 1170 | 		if (sense & 0x01) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1171 | 			dev_warn(dev, "The remote channel adapter for" | 
 | 1172 | 				" %s has been reset\n", | 
 | 1173 | 				ndev->name); | 
| Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1174 | 		} | 
 | 1175 | 	} else if (sense & 0x20) { | 
 | 1176 | 		if (sense & 0x04) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1177 | 			dev_warn(dev, "A data streaming timeout occurred" | 
 | 1178 | 				" for %s\n", | 
 | 1179 | 				ndev->name); | 
| Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1180 | 		} else if (sense & 0x10) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1181 | 			dev_warn(dev, "The remote channel adapter for %s" | 
 | 1182 | 				" is faulty\n", | 
 | 1183 | 				ndev->name); | 
| Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1184 | 		} else { | 
 | 1185 | 			dev_warn(dev, "A data transfer parity error occurred" | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1186 | 				" for %s\n", | 
 | 1187 | 				ndev->name); | 
| Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1188 | 		} | 
 | 1189 | 	} else if (sense & 0x10) { | 
 | 1190 | 		dev_warn(dev, "A read data parity error occurred" | 
 | 1191 | 			" for %s\n", | 
 | 1192 | 			ndev->name); | 
 | 1193 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | }   /*    end of ccw_check_unit_check    */ | 
 | 1196 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | /*-------------------------------------------------------------------* | 
 | 1198 | *               find_link                                            * | 
 | 1199 | *--------------------------------------------------------------------*/ | 
 | 1200 | static int | 
 | 1201 | find_link(struct net_device *dev, char *host_name, char *ws_name ) | 
 | 1202 | { | 
 | 1203 | 	struct claw_privbk *privptr; | 
 | 1204 | 	struct claw_env *p_env; | 
 | 1205 | 	int    rc=0; | 
 | 1206 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1207 | 	CLAW_DBF_TEXT(2, setup, "findlink"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1208 | 	privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 |         p_env=privptr->p_env; | 
 | 1210 | 	switch (p_env->packing) | 
 | 1211 | 	{ | 
 | 1212 | 		case  PACKING_ASK: | 
 | 1213 | 			if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) || | 
 | 1214 | 			    (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 )) | 
 | 1215 |         	             rc = EINVAL; | 
 | 1216 | 			break; | 
 | 1217 | 		case  DO_PACKED: | 
 | 1218 | 		case  PACK_SEND: | 
 | 1219 | 			if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) || | 
 | 1220 | 			    (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 )) | 
 | 1221 |         	        	rc = EINVAL; | 
 | 1222 | 			break; | 
 | 1223 | 		default: | 
 | 1224 | 	       		if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) || | 
 | 1225 | 		    	    (memcmp(p_env->api_type , ws_name, 8)!=0)) | 
 | 1226 |         	        	rc = EINVAL; | 
 | 1227 | 			break; | 
 | 1228 | 	} | 
 | 1229 |  | 
| Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1230 | 	return rc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | }    /*    end of find_link    */ | 
 | 1232 |  | 
 | 1233 | /*-------------------------------------------------------------------* | 
 | 1234 |  *   claw_hw_tx                                                      * | 
 | 1235 |  *                                                                   * | 
 | 1236 |  *                                                                   * | 
 | 1237 |  *-------------------------------------------------------------------*/ | 
 | 1238 |  | 
 | 1239 | static int | 
 | 1240 | claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid) | 
 | 1241 | { | 
 | 1242 |         int                             rc=0; | 
 | 1243 |         struct claw_privbk 		*privptr; | 
 | 1244 |         struct ccwbk           *p_this_ccw; | 
 | 1245 |         struct ccwbk           *p_first_ccw; | 
 | 1246 |         struct ccwbk           *p_last_ccw; | 
 | 1247 |         __u32                           numBuffers; | 
 | 1248 |         signed long                     len_of_data; | 
 | 1249 |         unsigned long                   bytesInThisBuffer; | 
 | 1250 |         unsigned char                   *pDataAddress; | 
 | 1251 |         struct endccw                   *pEnd; | 
 | 1252 |         struct ccw1                     tempCCW; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | 	struct claw_env			*p_env; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | 	struct clawph			*pk_head; | 
 | 1255 | 	struct chbk			*ch; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1256 |  | 
 | 1257 | 	CLAW_DBF_TEXT(4, trace, "hw_tx"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1258 | 	privptr = (struct claw_privbk *)(dev->ml_priv); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | 	p_env =privptr->p_env; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | 	claw_free_wrt_buf(dev);	/* Clean up free chain if posible */ | 
 | 1261 |         /*  scan the write queue to free any completed write packets   */ | 
 | 1262 |         p_first_ccw=NULL; | 
 | 1263 |         p_last_ccw=NULL; | 
 | 1264 | 	if ((p_env->packing >= PACK_SEND) && | 
 | 1265 |        	    (skb->cb[1] != 'P')) { | 
 | 1266 | 		skb_push(skb,sizeof(struct clawph)); | 
 | 1267 | 		pk_head=(struct clawph *)skb->data; | 
 | 1268 | 		pk_head->len=skb->len-sizeof(struct clawph); | 
 | 1269 | 		if (pk_head->len%4)  { | 
 | 1270 | 			pk_head->len+= 4-(pk_head->len%4); | 
 | 1271 | 			skb_pad(skb,4-(pk_head->len%4)); | 
 | 1272 | 			skb_put(skb,4-(pk_head->len%4)); | 
 | 1273 | 		} | 
 | 1274 | 		if (p_env->packing == DO_PACKED) | 
 | 1275 | 			pk_head->link_num = linkid; | 
 | 1276 | 		else | 
 | 1277 | 			pk_head->link_num = 0; | 
 | 1278 | 		pk_head->flag = 0x00; | 
 | 1279 | 		skb_pad(skb,4); | 
 | 1280 | 		skb->cb[1] = 'P'; | 
 | 1281 | 	} | 
 | 1282 |         if (linkid == 0) { | 
 | 1283 |         	if (claw_check_busy(dev)) { | 
 | 1284 |                 	if (privptr->write_free_count!=0) { | 
 | 1285 |                                 claw_clear_busy(dev); | 
 | 1286 |                         } | 
 | 1287 |                         else { | 
 | 1288 |                                 claw_strt_out_IO(dev ); | 
 | 1289 |                                 claw_free_wrt_buf( dev ); | 
 | 1290 |                                 if (privptr->write_free_count==0) { | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1291 | 					ch = &privptr->channel[WRITE_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | 					atomic_inc(&skb->users); | 
 | 1293 | 					skb_queue_tail(&ch->collect_queue, skb); | 
 | 1294 |                                 	goto Done; | 
 | 1295 |                                 } | 
 | 1296 |                                 else { | 
 | 1297 |                                 	claw_clear_busy(dev); | 
 | 1298 |                                 } | 
 | 1299 |                         } | 
 | 1300 |                 } | 
 | 1301 |                 /*  tx lock  */ | 
 | 1302 |                 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */ | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1303 | 			ch = &privptr->channel[WRITE_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | 			atomic_inc(&skb->users); | 
 | 1305 | 			skb_queue_tail(&ch->collect_queue, skb); | 
 | 1306 |                         claw_strt_out_IO(dev ); | 
 | 1307 |                         rc=-EBUSY; | 
 | 1308 |                         goto Done2; | 
 | 1309 |                 } | 
 | 1310 |         } | 
 | 1311 |         /*      See how many write buffers are required to hold this data */ | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1312 | 	numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 |  | 
 | 1314 |         /*      If that number of buffers isn't available, give up for now */ | 
 | 1315 |         if (privptr->write_free_count < numBuffers || | 
 | 1316 |             privptr->p_write_free_chain == NULL ) { | 
 | 1317 |  | 
 | 1318 |                 claw_setbit_busy(TB_NOBUFFER,dev); | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1319 | 		ch = &privptr->channel[WRITE_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | 		atomic_inc(&skb->users); | 
 | 1321 | 		skb_queue_tail(&ch->collect_queue, skb); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1322 | 		CLAW_DBF_TEXT(2, trace, "clawbusy"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 |                 goto Done2; | 
 | 1324 |         } | 
 | 1325 |         pDataAddress=skb->data; | 
 | 1326 |         len_of_data=skb->len; | 
 | 1327 |  | 
 | 1328 |         while (len_of_data > 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 |                 p_this_ccw=privptr->p_write_free_chain;  /* get a block */ | 
 | 1330 | 		if (p_this_ccw == NULL) { /* lost the race */ | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1331 | 			ch = &privptr->channel[WRITE_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | 			atomic_inc(&skb->users); | 
 | 1333 | 			skb_queue_tail(&ch->collect_queue, skb); | 
 | 1334 | 			goto Done2; | 
 | 1335 | 		} | 
 | 1336 |                 privptr->p_write_free_chain=p_this_ccw->next; | 
 | 1337 |                 p_this_ccw->next=NULL; | 
 | 1338 |                 --privptr->write_free_count; /* -1 */ | 
| Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1339 | 		if (len_of_data >= privptr->p_env->write_size) | 
 | 1340 | 			bytesInThisBuffer = privptr->p_env->write_size; | 
 | 1341 | 		else | 
 | 1342 | 			bytesInThisBuffer = len_of_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 |                 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer); | 
 | 1344 |                 len_of_data-=bytesInThisBuffer; | 
 | 1345 |                 pDataAddress+=(unsigned long)bytesInThisBuffer; | 
 | 1346 |                 /*      setup write CCW         */ | 
 | 1347 |                 p_this_ccw->write.cmd_code = (linkid * 8) +1; | 
 | 1348 |                 if (len_of_data>0) { | 
 | 1349 |                         p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG; | 
 | 1350 |                 } | 
 | 1351 |                 p_this_ccw->write.count=bytesInThisBuffer; | 
 | 1352 |                 /*      now add to end of this chain    */ | 
 | 1353 |                 if (p_first_ccw==NULL)    { | 
 | 1354 |                         p_first_ccw=p_this_ccw; | 
 | 1355 |                 } | 
 | 1356 |                 if (p_last_ccw!=NULL) { | 
 | 1357 |                         p_last_ccw->next=p_this_ccw; | 
 | 1358 |                         /*      set up TIC ccws         */ | 
 | 1359 |                         p_last_ccw->w_TIC_1.cda= | 
 | 1360 | 				(__u32)__pa(&p_this_ccw->write); | 
 | 1361 |                 } | 
 | 1362 |                 p_last_ccw=p_this_ccw;      /* save new last block */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 |         } | 
 | 1364 |  | 
 | 1365 |         /*      FirstCCW and LastCCW now contain a new set of write channel | 
 | 1366 |         *       programs to append to the running channel program | 
 | 1367 |         */ | 
 | 1368 |  | 
 | 1369 |         if (p_first_ccw!=NULL) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1370 | 		/*      setup ending ccw sequence for this segment           */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 |                 pEnd=privptr->p_end_ccw; | 
 | 1372 |                 if (pEnd->write1) { | 
 | 1373 |                         pEnd->write1=0x00;   /* second end ccw is now active */ | 
 | 1374 |                         /*      set up Tic CCWs         */ | 
 | 1375 |                         p_last_ccw->w_TIC_1.cda= | 
 | 1376 | 				(__u32)__pa(&pEnd->write2_nop1); | 
 | 1377 |                         pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1378 |                         pEnd->write2_nop2.flags    = | 
 | 1379 | 				CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
 | 1380 |                         pEnd->write2_nop2.cda=0; | 
 | 1381 |                         pEnd->write2_nop2.count=1; | 
 | 1382 |                 } | 
 | 1383 |                 else {  /*  end of if (pEnd->write1)*/ | 
 | 1384 |                         pEnd->write1=0x01;   /* first end ccw is now active */ | 
 | 1385 |                         /*      set up Tic CCWs         */ | 
 | 1386 |                         p_last_ccw->w_TIC_1.cda= | 
 | 1387 | 				(__u32)__pa(&pEnd->write1_nop1); | 
 | 1388 |                         pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1389 |                         pEnd->write1_nop2.flags    = | 
 | 1390 | 				CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
 | 1391 |                         pEnd->write1_nop2.cda=0; | 
 | 1392 |                         pEnd->write1_nop2.count=1; | 
 | 1393 |                 }  /* end if if (pEnd->write1) */ | 
 | 1394 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 |                 if (privptr->p_write_active_first==NULL ) { | 
 | 1396 |                         privptr->p_write_active_first=p_first_ccw; | 
 | 1397 |                         privptr->p_write_active_last=p_last_ccw; | 
 | 1398 |                 } | 
 | 1399 |                 else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 |                         /*      set up Tic CCWs         */ | 
 | 1401 |  | 
 | 1402 |                         tempCCW.cda=(__u32)__pa(&p_first_ccw->write); | 
 | 1403 |                         tempCCW.count=0; | 
 | 1404 |                         tempCCW.flags=0; | 
 | 1405 |                         tempCCW.cmd_code=CCW_CLAW_CMD_TIC; | 
 | 1406 |  | 
 | 1407 |                         if (pEnd->write1) { | 
 | 1408 |  | 
 | 1409 |                  /* | 
 | 1410 |                  * first set of ending CCW's is chained to the new write | 
 | 1411 |                  * chain, so the second set is chained to the active chain | 
 | 1412 |                  * Therefore modify the second set to point the new write chain. | 
 | 1413 |                  * make sure we update the CCW atomically | 
 | 1414 |                  * so channel does not fetch it when it's only half done | 
 | 1415 |                  */ | 
 | 1416 |                                 memcpy( &pEnd->write2_nop2, &tempCCW , | 
 | 1417 | 					sizeof(struct ccw1)); | 
 | 1418 |                                 privptr->p_write_active_last->w_TIC_1.cda= | 
 | 1419 | 					(__u32)__pa(&p_first_ccw->write); | 
 | 1420 |                         } | 
 | 1421 |                         else { | 
 | 1422 |  | 
 | 1423 |                         /*make sure we update the CCW atomically | 
 | 1424 |                          *so channel does not fetch it when it's only half done | 
 | 1425 |                          */ | 
 | 1426 |                                 memcpy(&pEnd->write1_nop2, &tempCCW , | 
 | 1427 | 					sizeof(struct ccw1)); | 
 | 1428 |                                 privptr->p_write_active_last->w_TIC_1.cda= | 
 | 1429 | 				        (__u32)__pa(&p_first_ccw->write); | 
 | 1430 |  | 
 | 1431 |                         } /* end if if (pEnd->write1) */ | 
 | 1432 |  | 
 | 1433 |                         privptr->p_write_active_last->next=p_first_ccw; | 
 | 1434 |                         privptr->p_write_active_last=p_last_ccw; | 
 | 1435 |                 } | 
 | 1436 |  | 
 | 1437 |         } /* endif (p_first_ccw!=NULL)  */ | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 1438 |         dev_kfree_skb_any(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 |         claw_strt_out_IO(dev ); | 
 | 1440 |         /*      if write free count is zero , set NOBUFFER       */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | 	if (privptr->write_free_count==0) { | 
 | 1442 | 		claw_setbit_busy(TB_NOBUFFER,dev); | 
 | 1443 |         } | 
 | 1444 | Done2: | 
 | 1445 | 	claw_clearbit_busy(TB_TX,dev); | 
 | 1446 | Done: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | 	return(rc); | 
 | 1448 | }    /*    end of claw_hw_tx    */ | 
 | 1449 |  | 
 | 1450 | /*-------------------------------------------------------------------* | 
 | 1451 | *                                                                    * | 
 | 1452 | *     init_ccw_bk                                                    * | 
 | 1453 | *                                                                    * | 
 | 1454 | *--------------------------------------------------------------------*/ | 
 | 1455 |  | 
 | 1456 | static int | 
 | 1457 | init_ccw_bk(struct net_device *dev) | 
 | 1458 | { | 
 | 1459 |  | 
 | 1460 |         __u32   ccw_blocks_required; | 
 | 1461 |         __u32   ccw_blocks_perpage; | 
 | 1462 |         __u32   ccw_pages_required; | 
 | 1463 |         __u32   claw_reads_perpage=1; | 
 | 1464 |         __u32   claw_read_pages; | 
 | 1465 |         __u32   claw_writes_perpage=1; | 
 | 1466 |         __u32   claw_write_pages; | 
 | 1467 |         void    *p_buff=NULL; | 
 | 1468 |         struct ccwbk*p_free_chain; | 
 | 1469 | 	struct ccwbk*p_buf; | 
 | 1470 | 	struct ccwbk*p_last_CCWB; | 
 | 1471 | 	struct ccwbk*p_first_CCWB; | 
 | 1472 |         struct endccw *p_endccw=NULL; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1473 | 	addr_t  real_address; | 
 | 1474 | 	struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 |         struct clawh *pClawH=NULL; | 
 | 1476 |         addr_t   real_TIC_address; | 
 | 1477 |         int i,j; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1478 | 	CLAW_DBF_TEXT(4, trace, "init_ccw"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 |  | 
 | 1480 |         /*  initialize  statistics field */ | 
 | 1481 |         privptr->active_link_ID=0; | 
 | 1482 |         /*  initialize  ccwbk pointers  */ | 
 | 1483 |         privptr->p_write_free_chain=NULL;   /* pointer to free ccw chain*/ | 
 | 1484 |         privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/ | 
 | 1485 |         privptr->p_write_active_last=NULL;  /* pointer to the last write ccw*/ | 
 | 1486 |         privptr->p_read_active_first=NULL;  /* pointer to the first read ccw*/ | 
 | 1487 |         privptr->p_read_active_last=NULL;   /* pointer to the last read ccw */ | 
 | 1488 |         privptr->p_end_ccw=NULL;            /* pointer to ending ccw        */ | 
 | 1489 |         privptr->p_claw_signal_blk=NULL;    /* pointer to signal block      */ | 
 | 1490 | 	privptr->buffs_alloc = 0; | 
 | 1491 |         memset(&privptr->end_ccw, 0x00, sizeof(struct endccw)); | 
 | 1492 |         memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl)); | 
 | 1493 |         /*  initialize  free write ccwbk counter  */ | 
 | 1494 |         privptr->write_free_count=0;  /* number of free bufs on write chain */ | 
 | 1495 |         p_last_CCWB = NULL; | 
 | 1496 |         p_first_CCWB= NULL; | 
 | 1497 |         /* | 
 | 1498 |         *  We need 1 CCW block for each read buffer, 1 for each | 
 | 1499 |         *  write buffer, plus 1 for ClawSignalBlock | 
 | 1500 |         */ | 
 | 1501 |         ccw_blocks_required = | 
 | 1502 | 		privptr->p_env->read_buffers+privptr->p_env->write_buffers+1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 |         /* | 
 | 1504 |         * compute number of CCW blocks that will fit in a page | 
 | 1505 |         */ | 
 | 1506 |         ccw_blocks_perpage= PAGE_SIZE /  CCWBK_SIZE; | 
 | 1507 |         ccw_pages_required= | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1508 | 		DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 |         /* | 
 | 1511 |          *  read and write sizes are set by 2 constants in claw.h | 
 | 1512 | 	 *  4k and 32k.  Unpacked values other than 4k are not going to | 
 | 1513 | 	 * provide good performance. With packing buffers support 32k | 
 | 1514 | 	 * buffers are used. | 
 | 1515 |          */ | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1516 | 	if (privptr->p_env->read_size < PAGE_SIZE) { | 
 | 1517 | 		claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size; | 
 | 1518 | 		claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers, | 
 | 1519 | 						claw_reads_perpage); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 |          } | 
 | 1521 |          else {       /* > or equal  */ | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1522 | 		privptr->p_buff_pages_perread = | 
 | 1523 | 			DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE); | 
 | 1524 | 		claw_read_pages = privptr->p_env->read_buffers * | 
 | 1525 | 					privptr->p_buff_pages_perread; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 |          } | 
 | 1527 |         if (privptr->p_env->write_size < PAGE_SIZE) { | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1528 | 		claw_writes_perpage = | 
 | 1529 | 			PAGE_SIZE / privptr->p_env->write_size; | 
 | 1530 | 		claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers, | 
 | 1531 | 						claw_writes_perpage); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 |  | 
 | 1533 |         } | 
 | 1534 |         else {      /* >  or equal  */ | 
| Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1535 | 		privptr->p_buff_pages_perwrite = | 
 | 1536 | 			DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE); | 
 | 1537 | 		claw_write_pages = privptr->p_env->write_buffers * | 
 | 1538 | 					privptr->p_buff_pages_perwrite; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 |         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 |         /* | 
 | 1541 |         *               allocate ccw_pages_required | 
 | 1542 |         */ | 
 | 1543 |         if (privptr->p_buff_ccw==NULL) { | 
 | 1544 |                 privptr->p_buff_ccw= | 
 | 1545 | 			(void *)__get_free_pages(__GFP_DMA, | 
 | 1546 | 		        (int)pages_to_order_of_mag(ccw_pages_required )); | 
 | 1547 |                 if (privptr->p_buff_ccw==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 |                         return -ENOMEM; | 
 | 1549 |                 } | 
 | 1550 |                 privptr->p_buff_ccw_num=ccw_pages_required; | 
 | 1551 |         } | 
 | 1552 |         memset(privptr->p_buff_ccw, 0x00, | 
 | 1553 | 		privptr->p_buff_ccw_num * PAGE_SIZE); | 
 | 1554 |  | 
 | 1555 |         /* | 
 | 1556 |         *               obtain ending ccw block address | 
 | 1557 |         * | 
 | 1558 |         */ | 
 | 1559 |         privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw; | 
 | 1560 |         real_address  = (__u32)__pa(privptr->p_end_ccw); | 
 | 1561 |         /*                              Initialize ending CCW block       */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 |         p_endccw=privptr->p_end_ccw; | 
 | 1563 |         p_endccw->real=real_address; | 
 | 1564 |         p_endccw->write1=0x00; | 
 | 1565 |         p_endccw->read1=0x00; | 
 | 1566 |  | 
 | 1567 |         /*      write1_nop1                                     */ | 
 | 1568 |         p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP; | 
 | 1569 |         p_endccw->write1_nop1.flags       = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1570 |         p_endccw->write1_nop1.count       = 1; | 
 | 1571 |         p_endccw->write1_nop1.cda         = 0; | 
 | 1572 |  | 
 | 1573 |         /*      write1_nop2                                     */ | 
 | 1574 |         p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1575 |         p_endccw->write1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
 | 1576 |         p_endccw->write1_nop2.count      = 1; | 
 | 1577 |         p_endccw->write1_nop2.cda        = 0; | 
 | 1578 |  | 
 | 1579 |         /*      write2_nop1                                     */ | 
 | 1580 |         p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP; | 
 | 1581 |         p_endccw->write2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1582 |         p_endccw->write2_nop1.count        = 1; | 
 | 1583 |         p_endccw->write2_nop1.cda          = 0; | 
 | 1584 |  | 
 | 1585 |         /*      write2_nop2                                     */ | 
 | 1586 |         p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1587 |         p_endccw->write2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
 | 1588 |         p_endccw->write2_nop2.count        = 1; | 
 | 1589 |         p_endccw->write2_nop2.cda          = 0; | 
 | 1590 |  | 
 | 1591 |         /*      read1_nop1                                      */ | 
 | 1592 |         p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP; | 
 | 1593 |         p_endccw->read1_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1594 |         p_endccw->read1_nop1.count        = 1; | 
 | 1595 |         p_endccw->read1_nop1.cda          = 0; | 
 | 1596 |  | 
 | 1597 |         /*      read1_nop2                                      */ | 
 | 1598 |         p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1599 |         p_endccw->read1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
 | 1600 |         p_endccw->read1_nop2.count        = 1; | 
 | 1601 |         p_endccw->read1_nop2.cda          = 0; | 
 | 1602 |  | 
 | 1603 |         /*      read2_nop1                                      */ | 
 | 1604 |         p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP; | 
 | 1605 |         p_endccw->read2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1606 |         p_endccw->read2_nop1.count        = 1; | 
 | 1607 |         p_endccw->read2_nop1.cda          = 0; | 
 | 1608 |  | 
 | 1609 |         /*      read2_nop2                                      */ | 
 | 1610 |         p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1611 |         p_endccw->read2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP; | 
 | 1612 |         p_endccw->read2_nop2.count        = 1; | 
 | 1613 |         p_endccw->read2_nop2.cda          = 0; | 
 | 1614 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 |         /* | 
 | 1616 |         *                               Build a chain of CCWs | 
 | 1617 |         * | 
 | 1618 |         */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 |         p_buff=privptr->p_buff_ccw; | 
 | 1620 |  | 
 | 1621 |         p_free_chain=NULL; | 
 | 1622 |         for (i=0 ; i < ccw_pages_required; i++ ) { | 
 | 1623 |                 real_address  = (__u32)__pa(p_buff); | 
 | 1624 |                 p_buf=p_buff; | 
 | 1625 |                 for (j=0 ; j < ccw_blocks_perpage ; j++) { | 
 | 1626 |                         p_buf->next  = p_free_chain; | 
 | 1627 |                         p_free_chain = p_buf; | 
 | 1628 |                         p_buf->real=(__u32)__pa(p_buf); | 
 | 1629 |                         ++p_buf; | 
 | 1630 |                 } | 
 | 1631 |                 p_buff+=PAGE_SIZE; | 
 | 1632 |         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 |         /* | 
 | 1634 |         *                               Initialize ClawSignalBlock | 
 | 1635 |         * | 
 | 1636 |         */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 |         if (privptr->p_claw_signal_blk==NULL) { | 
 | 1638 |                 privptr->p_claw_signal_blk=p_free_chain; | 
 | 1639 |                 p_free_chain=p_free_chain->next; | 
 | 1640 |                 pClawH=(struct clawh *)privptr->p_claw_signal_blk; | 
 | 1641 |                 pClawH->length=0xffff; | 
 | 1642 |                 pClawH->opcode=0xff; | 
 | 1643 |                 pClawH->flag=CLAW_BUSY; | 
 | 1644 |         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 |  | 
 | 1646 |         /* | 
 | 1647 |         *               allocate write_pages_required and add to free chain | 
 | 1648 |         */ | 
 | 1649 |         if (privptr->p_buff_write==NULL) { | 
 | 1650 |             if (privptr->p_env->write_size < PAGE_SIZE) { | 
 | 1651 |                 privptr->p_buff_write= | 
 | 1652 | 			(void *)__get_free_pages(__GFP_DMA, | 
 | 1653 | 			(int)pages_to_order_of_mag(claw_write_pages )); | 
 | 1654 |                 if (privptr->p_buff_write==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 |                         privptr->p_buff_ccw=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 |                         return -ENOMEM; | 
 | 1657 |                 } | 
 | 1658 |                 /* | 
 | 1659 |                 *                               Build CLAW write free chain | 
 | 1660 |                 * | 
 | 1661 |                 */ | 
 | 1662 |  | 
 | 1663 |                 memset(privptr->p_buff_write, 0x00, | 
 | 1664 | 			ccw_pages_required * PAGE_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 |                 privptr->p_write_free_chain=NULL; | 
 | 1666 |  | 
 | 1667 |                 p_buff=privptr->p_buff_write; | 
 | 1668 |  | 
 | 1669 |                 for (i=0 ; i< privptr->p_env->write_buffers ; i++) { | 
 | 1670 |                         p_buf        = p_free_chain;      /*  get a CCW */ | 
 | 1671 |                         p_free_chain = p_buf->next; | 
 | 1672 |                         p_buf->next  =privptr->p_write_free_chain; | 
 | 1673 |                         privptr->p_write_free_chain = p_buf; | 
 | 1674 |                         p_buf-> p_buffer	= (struct clawbuf *)p_buff; | 
 | 1675 |                         p_buf-> write.cda       = (__u32)__pa(p_buff); | 
 | 1676 |                         p_buf-> write.flags     = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1677 |                         p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1678 |                         p_buf-> w_read_FF.flags   = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1679 |                         p_buf-> w_read_FF.count   = 1; | 
 | 1680 |                         p_buf-> w_read_FF.cda     = | 
 | 1681 | 				(__u32)__pa(&p_buf-> header.flag); | 
 | 1682 |                         p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; | 
 | 1683 |                         p_buf-> w_TIC_1.flags      = 0; | 
 | 1684 |                         p_buf-> w_TIC_1.count      = 0; | 
 | 1685 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1686 | 			if (((unsigned long)p_buff + | 
 | 1687 | 					    privptr->p_env->write_size) >= | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | 			   ((unsigned long)(p_buff+2* | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1689 | 			    (privptr->p_env->write_size) - 1) & PAGE_MASK)) { | 
 | 1690 | 				p_buff = p_buff+privptr->p_env->write_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 |                         } | 
 | 1692 |                 } | 
 | 1693 |            } | 
 | 1694 |            else      /*  Buffers are => PAGE_SIZE. 1 buff per get_free_pages */ | 
 | 1695 |            { | 
 | 1696 |                privptr->p_write_free_chain=NULL; | 
 | 1697 |                for (i = 0; i< privptr->p_env->write_buffers ; i++) { | 
 | 1698 |                    p_buff=(void *)__get_free_pages(__GFP_DMA, | 
 | 1699 | 		        (int)pages_to_order_of_mag( | 
 | 1700 | 			privptr->p_buff_pages_perwrite) ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 |                    if (p_buff==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 |                         free_pages((unsigned long)privptr->p_buff_ccw, | 
 | 1703 | 			      (int)pages_to_order_of_mag( | 
 | 1704 | 			      		privptr->p_buff_ccw_num)); | 
 | 1705 |                         privptr->p_buff_ccw=NULL; | 
 | 1706 | 			p_buf=privptr->p_buff_write; | 
 | 1707 |                         while (p_buf!=NULL) { | 
 | 1708 |                                 free_pages((unsigned long) | 
 | 1709 | 					p_buf->p_buffer, | 
 | 1710 | 					(int)pages_to_order_of_mag( | 
 | 1711 | 					privptr->p_buff_pages_perwrite)); | 
 | 1712 |                                 p_buf=p_buf->next; | 
 | 1713 |                         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 |                         return -ENOMEM; | 
 | 1715 |                    }  /* Error on get_pages   */ | 
 | 1716 |                    memset(p_buff, 0x00, privptr->p_env->write_size ); | 
 | 1717 |                    p_buf         = p_free_chain; | 
 | 1718 |                    p_free_chain  = p_buf->next; | 
 | 1719 |                    p_buf->next   = privptr->p_write_free_chain; | 
 | 1720 |                    privptr->p_write_free_chain = p_buf; | 
 | 1721 |                    privptr->p_buff_write = p_buf; | 
 | 1722 |                    p_buf->p_buffer=(struct clawbuf *)p_buff; | 
 | 1723 |                    p_buf-> write.cda     = (__u32)__pa(p_buff); | 
 | 1724 |                    p_buf-> write.flags   = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1725 |                    p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1726 |                    p_buf-> w_read_FF.flags    = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1727 |                    p_buf-> w_read_FF.count    = 1; | 
 | 1728 |                    p_buf-> w_read_FF.cda      = | 
 | 1729 | 			(__u32)__pa(&p_buf-> header.flag); | 
 | 1730 |                    p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; | 
 | 1731 |                    p_buf-> w_TIC_1.flags   = 0; | 
 | 1732 |                    p_buf-> w_TIC_1.count   = 0; | 
 | 1733 |                }  /* for all write_buffers   */ | 
 | 1734 |  | 
 | 1735 |            }    /* else buffers are PAGE_SIZE or bigger */ | 
 | 1736 |  | 
 | 1737 |         } | 
 | 1738 |         privptr->p_buff_write_num=claw_write_pages; | 
 | 1739 |         privptr->write_free_count=privptr->p_env->write_buffers; | 
 | 1740 |  | 
 | 1741 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 |         /* | 
 | 1743 |         *               allocate read_pages_required and chain to free chain | 
 | 1744 |         */ | 
 | 1745 |         if (privptr->p_buff_read==NULL) { | 
 | 1746 |             if (privptr->p_env->read_size < PAGE_SIZE)  { | 
 | 1747 |                 privptr->p_buff_read= | 
 | 1748 | 			(void *)__get_free_pages(__GFP_DMA, | 
 | 1749 | 			(int)pages_to_order_of_mag(claw_read_pages) ); | 
 | 1750 |                 if (privptr->p_buff_read==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 |                         free_pages((unsigned long)privptr->p_buff_ccw, | 
 | 1752 | 				(int)pages_to_order_of_mag( | 
 | 1753 | 					privptr->p_buff_ccw_num)); | 
 | 1754 | 			/* free the write pages size is < page size  */ | 
 | 1755 |                         free_pages((unsigned long)privptr->p_buff_write, | 
 | 1756 | 				(int)pages_to_order_of_mag( | 
 | 1757 | 				privptr->p_buff_write_num)); | 
 | 1758 |                         privptr->p_buff_ccw=NULL; | 
 | 1759 |                         privptr->p_buff_write=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 |                         return -ENOMEM; | 
 | 1761 |                 } | 
 | 1762 |                 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE); | 
 | 1763 |                 privptr->p_buff_read_num=claw_read_pages; | 
 | 1764 |                 /* | 
 | 1765 |                 *                               Build CLAW read free chain | 
 | 1766 |                 * | 
 | 1767 |                 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 |                 p_buff=privptr->p_buff_read; | 
 | 1769 |                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) { | 
 | 1770 |                         p_buf        = p_free_chain; | 
 | 1771 |                         p_free_chain = p_buf->next; | 
 | 1772 |  | 
 | 1773 |                         if (p_last_CCWB==NULL) { | 
 | 1774 |                                 p_buf->next=NULL; | 
 | 1775 |                                 real_TIC_address=0; | 
 | 1776 |                                 p_last_CCWB=p_buf; | 
 | 1777 |                         } | 
 | 1778 |                         else { | 
 | 1779 |                                 p_buf->next=p_first_CCWB; | 
 | 1780 |                                 real_TIC_address= | 
 | 1781 | 				(__u32)__pa(&p_first_CCWB -> read ); | 
 | 1782 |                         } | 
 | 1783 |  | 
 | 1784 |                         p_first_CCWB=p_buf; | 
 | 1785 |  | 
 | 1786 |                         p_buf->p_buffer=(struct clawbuf *)p_buff; | 
 | 1787 |                         /*  initialize read command */ | 
 | 1788 |                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ; | 
 | 1789 |                         p_buf-> read.cda = (__u32)__pa(p_buff); | 
 | 1790 |                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1791 |                         p_buf-> read.count       = privptr->p_env->read_size; | 
 | 1792 |  | 
 | 1793 |                         /*  initialize read_h command */ | 
 | 1794 |                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER; | 
 | 1795 |                         p_buf-> read_h.cda = | 
 | 1796 | 				(__u32)__pa(&(p_buf->header)); | 
 | 1797 |                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1798 |                         p_buf-> read_h.count      = sizeof(struct clawh); | 
 | 1799 |  | 
 | 1800 |                         /*  initialize Signal command */ | 
 | 1801 |                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD; | 
 | 1802 |                         p_buf-> signal.cda = | 
 | 1803 | 				(__u32)__pa(&(pClawH->flag)); | 
 | 1804 |                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1805 |                         p_buf-> signal.count     = 1; | 
 | 1806 |  | 
 | 1807 |                         /*  initialize r_TIC_1 command */ | 
 | 1808 |                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; | 
 | 1809 |                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address; | 
 | 1810 |                         p_buf-> r_TIC_1.flags = 0; | 
 | 1811 |                         p_buf-> r_TIC_1.count      = 0; | 
 | 1812 |  | 
 | 1813 |                         /*  initialize r_read_FF command */ | 
 | 1814 |                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1815 |                         p_buf-> r_read_FF.cda = | 
 | 1816 | 				(__u32)__pa(&(pClawH->flag)); | 
 | 1817 |                         p_buf-> r_read_FF.flags = | 
 | 1818 | 				CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI; | 
 | 1819 |                         p_buf-> r_read_FF.count    = 1; | 
 | 1820 |  | 
 | 1821 |                         /*    initialize r_TIC_2          */ | 
 | 1822 |                         memcpy(&p_buf->r_TIC_2, | 
 | 1823 | 				&p_buf->r_TIC_1, sizeof(struct ccw1)); | 
 | 1824 |  | 
 | 1825 |                         /*     initialize Header     */ | 
 | 1826 |                         p_buf->header.length=0xffff; | 
 | 1827 |                         p_buf->header.opcode=0xff; | 
 | 1828 |                         p_buf->header.flag=CLAW_PENDING; | 
 | 1829 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1830 | 			if (((unsigned long)p_buff+privptr->p_env->read_size) >= | 
 | 1831 | 			  ((unsigned long)(p_buff+2*(privptr->p_env->read_size) | 
 | 1832 | 				 -1) | 
 | 1833 | 			   & PAGE_MASK)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 |                                 p_buff= p_buff+privptr->p_env->read_size; | 
 | 1835 |                         } | 
 | 1836 |                         else { | 
 | 1837 |                                 p_buff= | 
 | 1838 | 				(void *)((unsigned long) | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1839 | 					(p_buff+2*(privptr->p_env->read_size)-1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | 					 & PAGE_MASK) ; | 
 | 1841 |                         } | 
 | 1842 |                 }   /* for read_buffers   */ | 
 | 1843 |           }         /* read_size < PAGE_SIZE  */ | 
 | 1844 |           else {  /* read Size >= PAGE_SIZE  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 |                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) { | 
 | 1846 |                         p_buff = (void *)__get_free_pages(__GFP_DMA, | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1847 | 				(int)pages_to_order_of_mag( | 
 | 1848 | 					privptr->p_buff_pages_perread)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 |                         if (p_buff==NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 |                                 free_pages((unsigned long)privptr->p_buff_ccw, | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1851 | 					(int)pages_to_order_of_mag(privptr-> | 
 | 1852 | 					p_buff_ccw_num)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | 				/* free the write pages  */ | 
 | 1854 | 	                        p_buf=privptr->p_buff_write; | 
 | 1855 |                                 while (p_buf!=NULL) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1856 | 					free_pages( | 
 | 1857 | 					    (unsigned long)p_buf->p_buffer, | 
 | 1858 | 					    (int)pages_to_order_of_mag( | 
 | 1859 | 					    privptr->p_buff_pages_perwrite)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 |                                         p_buf=p_buf->next; | 
 | 1861 |                                 } | 
 | 1862 | 				/* free any read pages already alloc  */ | 
 | 1863 | 	                        p_buf=privptr->p_buff_read; | 
 | 1864 |                                 while (p_buf!=NULL) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1865 | 					free_pages( | 
 | 1866 | 					    (unsigned long)p_buf->p_buffer, | 
 | 1867 | 					    (int)pages_to_order_of_mag( | 
 | 1868 | 					     privptr->p_buff_pages_perread)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 |                                         p_buf=p_buf->next; | 
 | 1870 |                                 } | 
 | 1871 |                                 privptr->p_buff_ccw=NULL; | 
 | 1872 |                                 privptr->p_buff_write=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 |                                 return -ENOMEM; | 
 | 1874 |                         } | 
 | 1875 |                         memset(p_buff, 0x00, privptr->p_env->read_size); | 
 | 1876 |                         p_buf        = p_free_chain; | 
 | 1877 |                         privptr->p_buff_read = p_buf; | 
 | 1878 |                         p_free_chain = p_buf->next; | 
 | 1879 |  | 
 | 1880 |                         if (p_last_CCWB==NULL) { | 
 | 1881 |                                 p_buf->next=NULL; | 
 | 1882 |                                 real_TIC_address=0; | 
 | 1883 |                                 p_last_CCWB=p_buf; | 
 | 1884 |                         } | 
 | 1885 |                         else { | 
 | 1886 |                                 p_buf->next=p_first_CCWB; | 
 | 1887 |                                 real_TIC_address= | 
 | 1888 | 					(addr_t)__pa( | 
 | 1889 | 						&p_first_CCWB -> read ); | 
 | 1890 |                         } | 
 | 1891 |  | 
 | 1892 |                         p_first_CCWB=p_buf; | 
 | 1893 | 				/* save buff address */ | 
 | 1894 |                         p_buf->p_buffer=(struct clawbuf *)p_buff; | 
 | 1895 |                         /*  initialize read command */ | 
 | 1896 |                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ; | 
 | 1897 |                         p_buf-> read.cda = (__u32)__pa(p_buff); | 
 | 1898 |                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1899 |                         p_buf-> read.count       = privptr->p_env->read_size; | 
 | 1900 |  | 
 | 1901 |                         /*  initialize read_h command */ | 
 | 1902 |                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER; | 
 | 1903 |                         p_buf-> read_h.cda = | 
 | 1904 | 				(__u32)__pa(&(p_buf->header)); | 
 | 1905 |                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1906 |                         p_buf-> read_h.count      = sizeof(struct clawh); | 
 | 1907 |  | 
 | 1908 |                         /*  initialize Signal command */ | 
 | 1909 |                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD; | 
 | 1910 |                         p_buf-> signal.cda = | 
 | 1911 | 				(__u32)__pa(&(pClawH->flag)); | 
 | 1912 |                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC; | 
 | 1913 |                         p_buf-> signal.count     = 1; | 
 | 1914 |  | 
 | 1915 |                         /*  initialize r_TIC_1 command */ | 
 | 1916 |                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; | 
 | 1917 |                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address; | 
 | 1918 |                         p_buf-> r_TIC_1.flags = 0; | 
 | 1919 |                         p_buf-> r_TIC_1.count      = 0; | 
 | 1920 |  | 
 | 1921 |                         /*  initialize r_read_FF command */ | 
 | 1922 |                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF; | 
 | 1923 |                         p_buf-> r_read_FF.cda = | 
 | 1924 | 				(__u32)__pa(&(pClawH->flag)); | 
 | 1925 |                         p_buf-> r_read_FF.flags = | 
 | 1926 | 				CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI; | 
 | 1927 |                         p_buf-> r_read_FF.count    = 1; | 
 | 1928 |  | 
 | 1929 |                         /*    initialize r_TIC_2          */ | 
 | 1930 |                         memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1, | 
 | 1931 | 				sizeof(struct ccw1)); | 
 | 1932 |  | 
 | 1933 |                         /*     initialize Header     */ | 
 | 1934 |                         p_buf->header.length=0xffff; | 
 | 1935 |                         p_buf->header.opcode=0xff; | 
 | 1936 |                         p_buf->header.flag=CLAW_PENDING; | 
 | 1937 |  | 
 | 1938 |                 }    /* For read_buffers   */ | 
 | 1939 |           }     /*  read_size >= PAGE_SIZE   */ | 
 | 1940 |         }       /*  pBuffread = NULL */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 |         add_claw_reads( dev  ,p_first_CCWB , p_last_CCWB); | 
 | 1942 | 	privptr->buffs_alloc = 1; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1943 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 |         return 0; | 
 | 1945 | }    /*    end of init_ccw_bk */ | 
 | 1946 |  | 
 | 1947 | /*-------------------------------------------------------------------* | 
 | 1948 | *                                                                    * | 
 | 1949 | *       probe_error                                                  * | 
 | 1950 | *                                                                    * | 
 | 1951 | *--------------------------------------------------------------------*/ | 
 | 1952 |  | 
 | 1953 | static void | 
 | 1954 | probe_error( struct ccwgroup_device *cgdev) | 
 | 1955 | { | 
| Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 1956 | 	struct claw_privbk *privptr; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1957 |  | 
 | 1958 | 	CLAW_DBF_TEXT(4, trace, "proberr"); | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1959 | 	privptr = dev_get_drvdata(&cgdev->dev); | 
| Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 1960 | 	if (privptr != NULL) { | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1961 | 		dev_set_drvdata(&cgdev->dev, NULL); | 
| Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 1962 | 		kfree(privptr->p_env); | 
| Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 1963 | 		kfree(privptr->p_mtc_envelope); | 
 | 1964 | 		kfree(privptr); | 
 | 1965 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | }    /*    probe_error    */ | 
 | 1967 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | /*-------------------------------------------------------------------* | 
 | 1969 | *    claw_process_control                                            * | 
 | 1970 | *                                                                    * | 
 | 1971 | *                                                                    * | 
 | 1972 | *--------------------------------------------------------------------*/ | 
 | 1973 |  | 
 | 1974 | static int | 
 | 1975 | claw_process_control( struct net_device *dev, struct ccwbk * p_ccw) | 
 | 1976 | { | 
 | 1977 |  | 
 | 1978 |         struct clawbuf *p_buf; | 
 | 1979 |         struct clawctl  ctlbk; | 
 | 1980 |         struct clawctl *p_ctlbk; | 
 | 1981 |         char    temp_host_name[8]; | 
 | 1982 |         char    temp_ws_name[8]; | 
 | 1983 |         struct claw_privbk *privptr; | 
 | 1984 |         struct claw_env *p_env; | 
 | 1985 |         struct sysval *p_sysval; | 
 | 1986 |         struct conncmd *p_connect=NULL; | 
 | 1987 |         int rc; | 
 | 1988 |         struct chbk *p_ch = NULL; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1989 | 	struct device *tdev; | 
 | 1990 | 	CLAW_DBF_TEXT(2, setup, "clw_cntl"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 |         udelay(1000);  /* Wait a ms for the control packets to | 
 | 1992 | 			*catch up to each other */ | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1993 | 	privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 |         p_env=privptr->p_env; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1995 | 	tdev = &privptr->channel[READ_CHANNEL].cdev->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | 	memcpy( &temp_host_name, p_env->host_name, 8); | 
 | 1997 |         memcpy( &temp_ws_name, p_env->adapter_name , 8); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1998 | 	dev_info(tdev, "%s: CLAW device %.8s: " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | 		"Received Control Packet\n", | 
 | 2000 | 		dev->name, temp_ws_name); | 
 | 2001 |         if (privptr->release_pend==1) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 |                 return 0; | 
 | 2003 |         } | 
 | 2004 |         p_buf=p_ccw->p_buffer; | 
 | 2005 |         p_ctlbk=&ctlbk; | 
 | 2006 | 	if (p_env->packing == DO_PACKED) { /* packing in progress?*/ | 
 | 2007 | 		memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl)); | 
 | 2008 | 	} else { | 
 | 2009 | 		memcpy(p_ctlbk, p_buf, sizeof(struct clawctl)); | 
 | 2010 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 |         switch (p_ctlbk->command) | 
 | 2012 |         { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2013 | 	case SYSTEM_VALIDATE_REQUEST: | 
 | 2014 | 		if (p_ctlbk->version != CLAW_VERSION_ID) { | 
 | 2015 | 			claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
 | 2016 | 				CLAW_RC_WRONG_VERSION); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2017 | 			dev_warn(tdev, "The communication peer of %s" | 
 | 2018 | 				" uses an incorrect API version %d\n", | 
 | 2019 | 				dev->name, p_ctlbk->version); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2020 | 		} | 
 | 2021 | 		p_sysval = (struct sysval *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2022 | 		dev_info(tdev, "%s: Recv Sys Validate Request: " | 
 | 2023 | 			"Vers=%d,link_id=%d,Corr=%d,WS name=%.8s," | 
 | 2024 | 			"Host name=%.8s\n", | 
 | 2025 | 			dev->name, p_ctlbk->version, | 
 | 2026 | 			p_ctlbk->linkid, | 
 | 2027 | 			p_ctlbk->correlator, | 
 | 2028 | 			p_sysval->WS_name, | 
 | 2029 | 			p_sysval->host_name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2030 | 		if (memcmp(temp_host_name, p_sysval->host_name, 8)) { | 
 | 2031 | 			claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
 | 2032 | 				CLAW_RC_NAME_MISMATCH); | 
 | 2033 | 			CLAW_DBF_TEXT(2, setup, "HSTBAD"); | 
 | 2034 | 			CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name); | 
 | 2035 | 			CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2036 | 			dev_warn(tdev, | 
 | 2037 | 				"Host name %s for %s does not match the" | 
 | 2038 | 				" remote adapter name %s\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2039 | 				p_sysval->host_name, | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2040 | 				dev->name, | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2041 | 				temp_host_name); | 
 | 2042 | 		} | 
 | 2043 | 		if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) { | 
 | 2044 | 			claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
 | 2045 | 				CLAW_RC_NAME_MISMATCH); | 
 | 2046 | 			CLAW_DBF_TEXT(2, setup, "WSNBAD"); | 
 | 2047 | 			CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name); | 
 | 2048 | 			CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2049 | 			dev_warn(tdev, "Adapter name %s for %s does not match" | 
 | 2050 | 				" the remote host name %s\n", | 
 | 2051 | 				p_sysval->WS_name, | 
 | 2052 | 				dev->name, | 
 | 2053 | 				temp_ws_name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2054 | 		} | 
 | 2055 | 		if ((p_sysval->write_frame_size < p_env->write_size) && | 
 | 2056 | 		    (p_env->packing == 0)) { | 
 | 2057 | 			claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
 | 2058 | 				CLAW_RC_HOST_RCV_TOO_SMALL); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2059 | 			dev_warn(tdev, | 
 | 2060 | 				"The local write buffer is smaller than the" | 
 | 2061 | 				" remote read buffer\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2062 | 			CLAW_DBF_TEXT(2, setup, "wrtszbad"); | 
 | 2063 | 		} | 
 | 2064 | 		if ((p_sysval->read_frame_size < p_env->read_size) && | 
 | 2065 | 		    (p_env->packing == 0)) { | 
 | 2066 | 			claw_snd_sys_validate_rsp(dev, p_ctlbk, | 
 | 2067 | 				CLAW_RC_HOST_RCV_TOO_SMALL); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2068 | 			dev_warn(tdev, | 
 | 2069 | 				"The local read buffer is smaller than the" | 
 | 2070 | 				" remote write buffer\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2071 | 			CLAW_DBF_TEXT(2, setup, "rdsizbad"); | 
 | 2072 | 		} | 
 | 2073 | 		claw_snd_sys_validate_rsp(dev, p_ctlbk, 0); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2074 | 		dev_info(tdev, | 
 | 2075 | 			"CLAW device %.8s: System validate" | 
 | 2076 | 			" completed.\n", temp_ws_name); | 
 | 2077 | 		dev_info(tdev, | 
 | 2078 | 			"%s: sys Validate Rsize:%d Wsize:%d\n", | 
 | 2079 | 			dev->name, p_sysval->read_frame_size, | 
 | 2080 | 			p_sysval->write_frame_size); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2081 | 		privptr->system_validate_comp = 1; | 
 | 2082 | 		if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0) | 
 | 2083 | 			p_env->packing = PACKING_ASK; | 
 | 2084 | 		claw_strt_conn_req(dev); | 
 | 2085 | 		break; | 
 | 2086 | 	case SYSTEM_VALIDATE_RESPONSE: | 
 | 2087 | 		p_sysval = (struct sysval *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2088 | 		dev_info(tdev, | 
 | 2089 | 			"Settings for %s validated (version=%d, " | 
 | 2090 | 			"remote device=%d, rc=%d, adapter name=%.8s, " | 
 | 2091 | 			"host name=%.8s)\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2092 | 			dev->name, | 
 | 2093 | 			p_ctlbk->version, | 
 | 2094 | 			p_ctlbk->correlator, | 
 | 2095 | 			p_ctlbk->rc, | 
 | 2096 | 			p_sysval->WS_name, | 
 | 2097 | 			p_sysval->host_name); | 
 | 2098 | 		switch (p_ctlbk->rc) { | 
 | 2099 | 		case 0: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2100 | 			dev_info(tdev, "%s: CLAW device " | 
 | 2101 | 				"%.8s: System validate completed.\n", | 
 | 2102 | 				dev->name, temp_ws_name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2103 | 			if (privptr->system_validate_comp == 0) | 
 | 2104 | 				claw_strt_conn_req(dev); | 
 | 2105 | 			privptr->system_validate_comp = 1; | 
 | 2106 | 			break; | 
 | 2107 | 		case CLAW_RC_NAME_MISMATCH: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2108 | 			dev_warn(tdev, "Validating %s failed because of" | 
 | 2109 | 				" a host or adapter name mismatch\n", | 
 | 2110 | 				dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2111 | 			break; | 
 | 2112 | 		case CLAW_RC_WRONG_VERSION: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2113 | 			dev_warn(tdev, "Validating %s failed because of a" | 
 | 2114 | 				" version conflict\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2115 | 				dev->name); | 
 | 2116 | 			break; | 
 | 2117 | 		case CLAW_RC_HOST_RCV_TOO_SMALL: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2118 | 			dev_warn(tdev, "Validating %s failed because of a" | 
 | 2119 | 				" frame size conflict\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2120 | 				dev->name); | 
 | 2121 | 			break; | 
 | 2122 | 		default: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2123 | 			dev_warn(tdev, "The communication peer of %s rejected" | 
 | 2124 | 				" the connection\n", | 
 | 2125 | 				 dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2126 | 			break; | 
 | 2127 | 		} | 
 | 2128 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2130 | 	case CONNECTION_REQUEST: | 
 | 2131 | 		p_connect = (struct conncmd *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2132 | 		dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d," | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2133 | 			"Corr=%d,HOST appl=%.8s,WS appl=%.8s\n", | 
 | 2134 | 			dev->name, | 
 | 2135 | 			p_ctlbk->version, | 
 | 2136 | 			p_ctlbk->linkid, | 
 | 2137 | 			p_ctlbk->correlator, | 
 | 2138 | 			p_connect->host_name, | 
 | 2139 | 			p_connect->WS_name); | 
 | 2140 | 		if (privptr->active_link_ID != 0) { | 
 | 2141 | 			claw_snd_disc(dev, p_ctlbk); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2142 | 			dev_info(tdev, "%s rejected a connection request" | 
 | 2143 | 				" because it is already active\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2144 | 				dev->name); | 
 | 2145 | 		} | 
 | 2146 | 		if (p_ctlbk->linkid != 1) { | 
 | 2147 | 			claw_snd_disc(dev, p_ctlbk); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2148 | 			dev_info(tdev, "%s rejected a request to open multiple" | 
 | 2149 | 				" connections\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2150 | 				dev->name); | 
 | 2151 | 		} | 
 | 2152 | 		rc = find_link(dev, p_connect->host_name, p_connect->WS_name); | 
 | 2153 | 		if (rc != 0) { | 
 | 2154 | 			claw_snd_disc(dev, p_ctlbk); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2155 | 			dev_info(tdev, "%s rejected a connection request" | 
 | 2156 | 				" because of a type mismatch\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2157 | 				dev->name); | 
 | 2158 | 		} | 
 | 2159 | 		claw_send_control(dev, | 
 | 2160 | 			CONNECTION_CONFIRM, p_ctlbk->linkid, | 
 | 2161 | 			p_ctlbk->correlator, | 
 | 2162 | 			0, p_connect->host_name, | 
 | 2163 | 			p_connect->WS_name); | 
 | 2164 | 		if (p_env->packing == PACKING_ASK) { | 
 | 2165 | 			p_env->packing = PACK_SEND; | 
 | 2166 | 			claw_snd_conn_req(dev, 0); | 
 | 2167 | 		} | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2168 | 		dev_info(tdev, "%s: CLAW device %.8s: Connection " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2169 | 			"completed link_id=%d.\n", | 
 | 2170 | 			dev->name, temp_ws_name, | 
 | 2171 | 			p_ctlbk->linkid); | 
 | 2172 | 			privptr->active_link_ID = p_ctlbk->linkid; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2173 | 			p_ch = &privptr->channel[WRITE_CHANNEL]; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2174 | 			wake_up(&p_ch->wait);  /* wake up claw_open ( WRITE) */ | 
 | 2175 | 		break; | 
 | 2176 | 	case CONNECTION_RESPONSE: | 
 | 2177 | 		p_connect = (struct conncmd *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2178 | 		dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d," | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2179 | 			"Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n", | 
 | 2180 | 			dev->name, | 
 | 2181 | 			p_ctlbk->version, | 
 | 2182 | 			p_ctlbk->linkid, | 
 | 2183 | 			p_ctlbk->correlator, | 
 | 2184 | 			p_ctlbk->rc, | 
 | 2185 | 			p_connect->host_name, | 
 | 2186 | 			p_connect->WS_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2188 | 		if (p_ctlbk->rc != 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2189 | 			dev_warn(tdev, "The communication peer of %s rejected" | 
 | 2190 | 				" a connection request\n", | 
 | 2191 | 				dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2192 | 			return 1; | 
 | 2193 | 		} | 
 | 2194 | 		rc = find_link(dev, | 
 | 2195 | 			p_connect->host_name, p_connect->WS_name); | 
 | 2196 | 		if (rc != 0) { | 
 | 2197 | 			claw_snd_disc(dev, p_ctlbk); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2198 | 			dev_warn(tdev, "The communication peer of %s" | 
 | 2199 | 				" rejected a connection " | 
 | 2200 | 				"request because of a type mismatch\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2201 | 				 dev->name); | 
 | 2202 | 		} | 
 | 2203 | 		/* should be until CONNECTION_CONFIRM */ | 
 | 2204 | 		privptr->active_link_ID = -(p_ctlbk->linkid); | 
 | 2205 | 		break; | 
 | 2206 | 	case CONNECTION_CONFIRM: | 
 | 2207 | 		p_connect = (struct conncmd *)&(p_ctlbk->data); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2208 | 		dev_info(tdev, | 
 | 2209 | 			"%s: Recv Conn Confirm:Vers=%d,link_id=%d," | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2210 | 			"Corr=%d,Host appl=%.8s,WS appl=%.8s\n", | 
 | 2211 | 			dev->name, | 
 | 2212 | 			p_ctlbk->version, | 
 | 2213 | 			p_ctlbk->linkid, | 
 | 2214 | 			p_ctlbk->correlator, | 
 | 2215 | 			p_connect->host_name, | 
 | 2216 | 			p_connect->WS_name); | 
 | 2217 | 		if (p_ctlbk->linkid == -(privptr->active_link_ID)) { | 
 | 2218 | 			privptr->active_link_ID = p_ctlbk->linkid; | 
 | 2219 | 			if (p_env->packing > PACKING_ASK) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2220 | 				dev_info(tdev, | 
 | 2221 | 				"%s: Confirmed Now packing\n", dev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | 				p_env->packing = DO_PACKED; | 
 | 2223 | 			} | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2224 | 			p_ch = &privptr->channel[WRITE_CHANNEL]; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2225 | 			wake_up(&p_ch->wait); | 
 | 2226 | 		} else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2227 | 			dev_warn(tdev, "Activating %s failed because of" | 
 | 2228 | 				" an incorrect link ID=%d\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2229 | 				dev->name, p_ctlbk->linkid); | 
 | 2230 | 			claw_snd_disc(dev, p_ctlbk); | 
 | 2231 | 		} | 
 | 2232 | 		break; | 
 | 2233 | 	case DISCONNECT: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2234 | 		dev_info(tdev, "%s: Disconnect: " | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2235 | 			"Vers=%d,link_id=%d,Corr=%d\n", | 
 | 2236 | 			dev->name, p_ctlbk->version, | 
 | 2237 | 			p_ctlbk->linkid, p_ctlbk->correlator); | 
 | 2238 | 		if ((p_ctlbk->linkid == 2) && | 
 | 2239 | 		    (p_env->packing == PACK_SEND)) { | 
 | 2240 | 			privptr->active_link_ID = 1; | 
 | 2241 | 			p_env->packing = DO_PACKED; | 
 | 2242 | 		} else | 
 | 2243 | 			privptr->active_link_ID = 0; | 
 | 2244 | 		break; | 
 | 2245 | 	case CLAW_ERROR: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2246 | 		dev_warn(tdev, "The communication peer of %s failed\n", | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2247 | 			dev->name); | 
 | 2248 | 		break; | 
 | 2249 | 	default: | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2250 | 		dev_warn(tdev, "The communication peer of %s sent" | 
 | 2251 | 			" an unknown command code\n", | 
 | 2252 | 			dev->name); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2253 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 |         } | 
 | 2255 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 |         return 0; | 
 | 2257 | }   /*    end of claw_process_control    */ | 
 | 2258 |  | 
 | 2259 |  | 
 | 2260 | /*-------------------------------------------------------------------* | 
 | 2261 | *               claw_send_control                                    * | 
 | 2262 | *                                                                    * | 
 | 2263 | *--------------------------------------------------------------------*/ | 
 | 2264 |  | 
 | 2265 | static int | 
 | 2266 | claw_send_control(struct net_device *dev, __u8 type, __u8 link, | 
 | 2267 | 	 __u8 correlator, __u8 rc, char *local_name, char *remote_name) | 
 | 2268 | { | 
 | 2269 |         struct claw_privbk 		*privptr; | 
 | 2270 |         struct clawctl                  *p_ctl; | 
 | 2271 |         struct sysval                   *p_sysval; | 
 | 2272 |         struct conncmd                  *p_connect; | 
 | 2273 |         struct sk_buff 			*skb; | 
 | 2274 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2275 | 	CLAW_DBF_TEXT(2, setup, "sndcntl"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2276 | 	privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 |         p_ctl=(struct clawctl *)&privptr->ctl_bk; | 
 | 2278 |  | 
 | 2279 |         p_ctl->command=type; | 
 | 2280 |         p_ctl->version=CLAW_VERSION_ID; | 
 | 2281 |         p_ctl->linkid=link; | 
 | 2282 |         p_ctl->correlator=correlator; | 
 | 2283 |         p_ctl->rc=rc; | 
 | 2284 |  | 
 | 2285 |         p_sysval=(struct sysval *)&p_ctl->data; | 
 | 2286 |         p_connect=(struct conncmd *)&p_ctl->data; | 
 | 2287 |  | 
 | 2288 |         switch (p_ctl->command) { | 
 | 2289 |                 case SYSTEM_VALIDATE_REQUEST: | 
 | 2290 |                 case SYSTEM_VALIDATE_RESPONSE: | 
 | 2291 |                         memcpy(&p_sysval->host_name, local_name, 8); | 
 | 2292 |                         memcpy(&p_sysval->WS_name, remote_name, 8); | 
 | 2293 | 			if (privptr->p_env->packing > 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2294 | 				p_sysval->read_frame_size = DEF_PACK_BUFSIZE; | 
 | 2295 | 				p_sysval->write_frame_size = DEF_PACK_BUFSIZE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | 			} else { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2297 | 				/* how big is the biggest group of packets */ | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2298 | 			   p_sysval->read_frame_size = | 
 | 2299 | 				privptr->p_env->read_size; | 
 | 2300 | 			   p_sysval->write_frame_size = | 
 | 2301 | 				privptr->p_env->write_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | 			} | 
 | 2303 |                         memset(&p_sysval->reserved, 0x00, 4); | 
 | 2304 |                         break; | 
 | 2305 |                 case CONNECTION_REQUEST: | 
 | 2306 |                 case CONNECTION_RESPONSE: | 
 | 2307 |                 case CONNECTION_CONFIRM: | 
 | 2308 |                 case DISCONNECT: | 
 | 2309 |                         memcpy(&p_sysval->host_name, local_name, 8); | 
 | 2310 |                         memcpy(&p_sysval->WS_name, remote_name, 8); | 
 | 2311 | 			if (privptr->p_env->packing > 0) { | 
 | 2312 | 			/* How big is the biggest packet */ | 
 | 2313 | 				p_connect->reserved1[0]=CLAW_FRAME_SIZE; | 
 | 2314 |                         	p_connect->reserved1[1]=CLAW_FRAME_SIZE; | 
 | 2315 | 			} else { | 
 | 2316 | 	                        memset(&p_connect->reserved1, 0x00, 4); | 
 | 2317 |         	                memset(&p_connect->reserved2, 0x00, 4); | 
 | 2318 | 			} | 
 | 2319 |                         break; | 
 | 2320 |                 default: | 
 | 2321 |                         break; | 
 | 2322 |         } | 
 | 2323 |  | 
 | 2324 |         /*      write Control Record to the device                   */ | 
 | 2325 |  | 
 | 2326 |  | 
 | 2327 |         skb = dev_alloc_skb(sizeof(struct clawctl)); | 
 | 2328 |         if (!skb) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 |                 return -ENOMEM; | 
 | 2330 |         } | 
 | 2331 | 	memcpy(skb_put(skb, sizeof(struct clawctl)), | 
 | 2332 | 		p_ctl, sizeof(struct clawctl)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | 	if (privptr->p_env->packing >= PACK_SEND) | 
 | 2334 | 		claw_hw_tx(skb, dev, 1); | 
 | 2335 | 	else | 
 | 2336 |         	claw_hw_tx(skb, dev, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 |         return 0; | 
 | 2338 | }  /*   end of claw_send_control  */ | 
 | 2339 |  | 
 | 2340 | /*-------------------------------------------------------------------* | 
 | 2341 | *               claw_snd_conn_req                                    * | 
 | 2342 | *                                                                    * | 
 | 2343 | *--------------------------------------------------------------------*/ | 
 | 2344 | static int | 
 | 2345 | claw_snd_conn_req(struct net_device *dev, __u8 link) | 
 | 2346 | { | 
 | 2347 |         int                rc; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2348 | 	struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 |         struct clawctl 	   *p_ctl; | 
 | 2350 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2351 | 	CLAW_DBF_TEXT(2, setup, "snd_conn"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | 	rc = 1; | 
 | 2353 |         p_ctl=(struct clawctl *)&privptr->ctl_bk; | 
 | 2354 | 	p_ctl->linkid = link; | 
 | 2355 |         if ( privptr->system_validate_comp==0x00 ) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 |                 return rc; | 
 | 2357 |         } | 
 | 2358 | 	if (privptr->p_env->packing == PACKING_ASK ) | 
 | 2359 | 		rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, | 
 | 2360 |         		WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED); | 
 | 2361 | 	if (privptr->p_env->packing == PACK_SEND)  { | 
 | 2362 | 		rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, | 
 | 2363 |         		WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME); | 
 | 2364 | 	} | 
 | 2365 | 	if (privptr->p_env->packing == 0) | 
 | 2366 |         	rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, | 
 | 2367 |        			HOST_APPL_NAME, privptr->p_env->api_type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 |         return rc; | 
 | 2369 |  | 
 | 2370 | }  /*  end of claw_snd_conn_req */ | 
 | 2371 |  | 
 | 2372 |  | 
 | 2373 | /*-------------------------------------------------------------------* | 
 | 2374 | *               claw_snd_disc                                        * | 
 | 2375 | *                                                                    * | 
 | 2376 | *--------------------------------------------------------------------*/ | 
 | 2377 |  | 
 | 2378 | static int | 
 | 2379 | claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl) | 
 | 2380 | { | 
 | 2381 |         int rc; | 
 | 2382 |         struct conncmd *  p_connect; | 
 | 2383 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2384 | 	CLAW_DBF_TEXT(2, setup, "snd_dsc"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 |         p_connect=(struct conncmd *)&p_ctl->data; | 
 | 2386 |  | 
 | 2387 |         rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid, | 
 | 2388 | 		p_ctl->correlator, 0, | 
 | 2389 |                 p_connect->host_name, p_connect->WS_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 |         return rc; | 
 | 2391 | }     /*   end of claw_snd_disc    */ | 
 | 2392 |  | 
 | 2393 |  | 
 | 2394 | /*-------------------------------------------------------------------* | 
 | 2395 | *               claw_snd_sys_validate_rsp                            * | 
 | 2396 | *                                                                    * | 
 | 2397 | *--------------------------------------------------------------------*/ | 
 | 2398 |  | 
 | 2399 | static int | 
 | 2400 | claw_snd_sys_validate_rsp(struct net_device *dev, | 
 | 2401 | 	struct clawctl *p_ctl, __u32 return_code) | 
 | 2402 | { | 
 | 2403 |         struct claw_env *  p_env; | 
 | 2404 |         struct claw_privbk *privptr; | 
 | 2405 |         int    rc; | 
 | 2406 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2407 | 	CLAW_DBF_TEXT(2, setup, "chkresp"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2408 | 	privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 |         p_env=privptr->p_env; | 
 | 2410 |         rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE, | 
 | 2411 | 		p_ctl->linkid, | 
 | 2412 | 		p_ctl->correlator, | 
 | 2413 |                 return_code, | 
 | 2414 | 		p_env->host_name, | 
 | 2415 | 		p_env->adapter_name  ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 |         return rc; | 
 | 2417 | }     /*    end of claw_snd_sys_validate_rsp    */ | 
 | 2418 |  | 
 | 2419 | /*-------------------------------------------------------------------* | 
 | 2420 | *               claw_strt_conn_req                                   * | 
 | 2421 | *                                                                    * | 
 | 2422 | *--------------------------------------------------------------------*/ | 
 | 2423 |  | 
 | 2424 | static int | 
 | 2425 | claw_strt_conn_req(struct net_device *dev ) | 
 | 2426 | { | 
 | 2427 |         int rc; | 
 | 2428 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2429 | 	CLAW_DBF_TEXT(2, setup, "conn_req"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 |         rc=claw_snd_conn_req(dev, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 |         return rc; | 
 | 2432 | }    /*   end of claw_strt_conn_req   */ | 
 | 2433 |  | 
 | 2434 |  | 
 | 2435 |  | 
 | 2436 | /*-------------------------------------------------------------------* | 
 | 2437 |  *   claw_stats                                                      * | 
 | 2438 |  *-------------------------------------------------------------------*/ | 
 | 2439 |  | 
 | 2440 | static struct | 
 | 2441 | net_device_stats *claw_stats(struct net_device *dev) | 
 | 2442 | { | 
 | 2443 |         struct claw_privbk *privptr; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2444 |  | 
 | 2445 | 	CLAW_DBF_TEXT(4, trace, "stats"); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2446 | 	privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 |         return &privptr->stats; | 
 | 2448 | }     /*   end of claw_stats   */ | 
 | 2449 |  | 
 | 2450 |  | 
 | 2451 | /*-------------------------------------------------------------------* | 
 | 2452 | *       unpack_read                                                  * | 
 | 2453 | *                                                                    * | 
 | 2454 | *--------------------------------------------------------------------*/ | 
 | 2455 | static void | 
 | 2456 | unpack_read(struct net_device *dev ) | 
 | 2457 | { | 
 | 2458 |         struct sk_buff *skb; | 
 | 2459 |         struct claw_privbk *privptr; | 
 | 2460 | 	struct claw_env    *p_env; | 
 | 2461 |         struct ccwbk 	*p_this_ccw; | 
 | 2462 |         struct ccwbk 	*p_first_ccw; | 
 | 2463 |         struct ccwbk 	*p_last_ccw; | 
 | 2464 | 	struct clawph 	*p_packh; | 
 | 2465 | 	void		*p_packd; | 
 | 2466 | 	struct clawctl 	*p_ctlrec=NULL; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2467 | 	struct device	*p_dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 |  | 
 | 2469 |         __u32	len_of_data; | 
 | 2470 | 	__u32	pack_off; | 
 | 2471 |         __u8	link_num; | 
 | 2472 |         __u8 	mtc_this_frm=0; | 
 | 2473 |         __u32	bytes_to_mov; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 |         int	i=0; | 
 | 2475 | 	int     p=0; | 
 | 2476 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2477 | 	CLAW_DBF_TEXT(4, trace, "unpkread"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 |         p_first_ccw=NULL; | 
 | 2479 |         p_last_ccw=NULL; | 
 | 2480 | 	p_packh=NULL; | 
 | 2481 | 	p_packd=NULL; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2482 | 	privptr = dev->ml_priv; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2483 |  | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2484 | 	p_dev = &privptr->channel[READ_CHANNEL].cdev->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | 	p_env = privptr->p_env; | 
 | 2486 |         p_this_ccw=privptr->p_read_active_first; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | 	while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | 		pack_off = 0; | 
 | 2489 | 		p = 0; | 
 | 2490 | 		p_this_ccw->header.flag=CLAW_PENDING; | 
 | 2491 | 		privptr->p_read_active_first=p_this_ccw->next; | 
 | 2492 |                 p_this_ccw->next=NULL; | 
 | 2493 | 		p_packh = (struct clawph *)p_this_ccw->p_buffer; | 
 | 2494 | 		if ((p_env->packing == PACK_SEND) && | 
 | 2495 | 		    (p_packh->len == 32)           && | 
 | 2496 | 		    (p_packh->link_num == 0)) {   /* is it a packed ctl rec? */ | 
 | 2497 | 			p_packh++;  /* peek past pack header */ | 
 | 2498 | 			p_ctlrec = (struct clawctl *)p_packh; | 
 | 2499 | 			p_packh--;  /* un peek */ | 
 | 2500 | 			if ((p_ctlrec->command == CONNECTION_RESPONSE) || | 
 | 2501 | 		            (p_ctlrec->command == CONNECTION_CONFIRM)) | 
 | 2502 | 				p_env->packing = DO_PACKED; | 
 | 2503 | 		} | 
 | 2504 | 		if (p_env->packing == DO_PACKED) | 
 | 2505 | 			link_num=p_packh->link_num; | 
 | 2506 | 		else | 
 | 2507 | 	                link_num=p_this_ccw->header.opcode / 8; | 
 | 2508 |                 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 |                         mtc_this_frm=1; | 
 | 2510 |                         if (p_this_ccw->header.length!= | 
 | 2511 | 				privptr->p_env->read_size ) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2512 | 				dev_warn(p_dev, | 
 | 2513 | 					"The communication peer of %s" | 
 | 2514 | 					" sent a faulty" | 
 | 2515 | 					" frame of length %02x\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 |                                         dev->name, p_this_ccw->header.length); | 
 | 2517 |                         } | 
 | 2518 |                 } | 
 | 2519 |  | 
 | 2520 |                 if (privptr->mtc_skipping) { | 
 | 2521 |                         /* | 
 | 2522 |                         *   We're in the mode of skipping past a | 
 | 2523 | 			*   multi-frame message | 
 | 2524 |                         *   that we can't process for some reason or other. | 
 | 2525 |                         *   The first frame without the More-To-Come flag is | 
 | 2526 | 			*   the last frame of the skipped message. | 
 | 2527 |                         */ | 
 | 2528 |                         /*  in case of More-To-Come not set in this frame */ | 
 | 2529 |                         if (mtc_this_frm==0) { | 
 | 2530 |                                 privptr->mtc_skipping=0; /* Ok, the end */ | 
 | 2531 |                                 privptr->mtc_logical_link=-1; | 
 | 2532 |                         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 |                         goto NextFrame; | 
 | 2534 |                 } | 
 | 2535 |  | 
 | 2536 |                 if (link_num==0) { | 
 | 2537 |                         claw_process_control(dev, p_this_ccw); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2538 | 			CLAW_DBF_TEXT(4, trace, "UnpkCntl"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 |                         goto NextFrame; | 
 | 2540 |                 } | 
 | 2541 | unpack_next: | 
 | 2542 | 		if (p_env->packing == DO_PACKED) { | 
 | 2543 | 			if (pack_off > p_env->read_size) | 
 | 2544 | 				goto NextFrame; | 
 | 2545 | 			p_packd = p_this_ccw->p_buffer+pack_off; | 
 | 2546 | 			p_packh = (struct clawph *) p_packd; | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2547 | 			if ((p_packh->len == 0) || /* done with this frame? */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | 			    (p_packh->flag != 0)) | 
 | 2549 | 				goto NextFrame; | 
 | 2550 | 			bytes_to_mov = p_packh->len; | 
 | 2551 | 			pack_off += bytes_to_mov+sizeof(struct clawph); | 
 | 2552 | 			p++; | 
 | 2553 | 		} else { | 
 | 2554 |                 	bytes_to_mov=p_this_ccw->header.length; | 
 | 2555 | 		} | 
 | 2556 |                 if (privptr->mtc_logical_link<0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 |  | 
 | 2558 |                 /* | 
 | 2559 |                 *  if More-To-Come is set in this frame then we don't know | 
 | 2560 |                 *  length of entire message, and hence have to allocate | 
 | 2561 | 		*  large buffer   */ | 
 | 2562 |  | 
 | 2563 |                 /*      We are starting a new envelope  */ | 
 | 2564 |                 privptr->mtc_offset=0; | 
 | 2565 |                         privptr->mtc_logical_link=link_num; | 
 | 2566 |                 } | 
 | 2567 |  | 
 | 2568 |                 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) { | 
 | 2569 |                         /*      error     */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 |                         privptr->stats.rx_frame_errors++; | 
 | 2571 |                         goto NextFrame; | 
 | 2572 |                 } | 
 | 2573 | 		if (p_env->packing == DO_PACKED) { | 
 | 2574 | 			memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset, | 
 | 2575 | 				p_packd+sizeof(struct clawph), bytes_to_mov); | 
 | 2576 |  | 
 | 2577 | 		} else	{ | 
 | 2578 |                 	memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset, | 
 | 2579 |                         	p_this_ccw->p_buffer, bytes_to_mov); | 
 | 2580 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 |                 if (mtc_this_frm==0) { | 
 | 2582 |                         len_of_data=privptr->mtc_offset+bytes_to_mov; | 
 | 2583 |                         skb=dev_alloc_skb(len_of_data); | 
 | 2584 |                         if (skb) { | 
 | 2585 |                                 memcpy(skb_put(skb,len_of_data), | 
 | 2586 | 					privptr->p_mtc_envelope, | 
 | 2587 | 					len_of_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 |                                 skb->dev=dev; | 
| Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 2589 | 				skb_reset_mac_header(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 |                                 skb->protocol=htons(ETH_P_IP); | 
 | 2591 |                                 skb->ip_summed=CHECKSUM_UNNECESSARY; | 
 | 2592 |                                 privptr->stats.rx_packets++; | 
 | 2593 | 				privptr->stats.rx_bytes+=len_of_data; | 
 | 2594 |                                 netif_rx(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 |                         } | 
 | 2596 |                         else { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2597 | 				dev_info(p_dev, "Allocating a buffer for" | 
 | 2598 | 					" incoming data failed\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 |                                 privptr->stats.rx_dropped++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 |                         } | 
 | 2601 |                         privptr->mtc_offset=0; | 
 | 2602 |                         privptr->mtc_logical_link=-1; | 
 | 2603 |                 } | 
 | 2604 |                 else { | 
 | 2605 |                         privptr->mtc_offset+=bytes_to_mov; | 
 | 2606 |                 } | 
 | 2607 | 		if (p_env->packing == DO_PACKED) | 
 | 2608 | 			goto unpack_next; | 
 | 2609 | NextFrame: | 
 | 2610 |                 /* | 
 | 2611 |                 *   Remove ThisCCWblock from active read queue, and add it | 
 | 2612 |                 *   to queue of free blocks to be reused. | 
 | 2613 |                 */ | 
 | 2614 |                 i++; | 
 | 2615 |                 p_this_ccw->header.length=0xffff; | 
 | 2616 |                 p_this_ccw->header.opcode=0xff; | 
 | 2617 |                 /* | 
 | 2618 |                 *       add this one to the free queue for later reuse | 
 | 2619 |                 */ | 
 | 2620 |                 if (p_first_ccw==NULL) { | 
 | 2621 |                         p_first_ccw = p_this_ccw; | 
 | 2622 |                 } | 
 | 2623 |                 else { | 
 | 2624 |                         p_last_ccw->next = p_this_ccw; | 
 | 2625 |                 } | 
 | 2626 |                 p_last_ccw = p_this_ccw; | 
 | 2627 |                 /* | 
 | 2628 |                 *       chain to next block on active read queue | 
 | 2629 |                 */ | 
 | 2630 |                 p_this_ccw = privptr->p_read_active_first; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2631 | 		CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 |         } /* end of while */ | 
 | 2633 |  | 
 | 2634 |         /*      check validity                  */ | 
 | 2635 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2636 | 	CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 |         add_claw_reads(dev, p_first_ccw, p_last_ccw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 |         claw_strt_read(dev, LOCK_YES); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 |         return; | 
 | 2640 | }     /*  end of unpack_read   */ | 
 | 2641 |  | 
 | 2642 | /*-------------------------------------------------------------------* | 
 | 2643 | *       claw_strt_read                                               * | 
 | 2644 | *                                                                    * | 
 | 2645 | *--------------------------------------------------------------------*/ | 
 | 2646 | static void | 
 | 2647 | claw_strt_read (struct net_device *dev, int lock ) | 
 | 2648 | { | 
 | 2649 |         int        rc = 0; | 
 | 2650 |         __u32      parm; | 
 | 2651 |         unsigned long  saveflags = 0; | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2652 | 	struct claw_privbk *privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 |         struct ccwbk*p_ccwbk; | 
 | 2654 |         struct chbk *p_ch; | 
 | 2655 |         struct clawh *p_clawh; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2656 | 	p_ch = &privptr->channel[READ_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2658 | 	CLAW_DBF_TEXT(4, trace, "StRdNter"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 |         p_clawh=(struct clawh *)privptr->p_claw_signal_blk; | 
 | 2660 |         p_clawh->flag=CLAW_IDLE;    /* 0x00 */ | 
 | 2661 |  | 
 | 2662 |         if ((privptr->p_write_active_first!=NULL && | 
 | 2663 |              privptr->p_write_active_first->header.flag!=CLAW_PENDING) || | 
 | 2664 |             (privptr->p_read_active_first!=NULL && | 
 | 2665 |              privptr->p_read_active_first->header.flag!=CLAW_PENDING )) { | 
 | 2666 |                 p_clawh->flag=CLAW_BUSY;    /* 0xff */ | 
 | 2667 |         } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 |         if (lock==LOCK_YES) { | 
 | 2669 |                 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags); | 
 | 2670 |         } | 
 | 2671 |         if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2672 | 		CLAW_DBF_TEXT(4, trace, "HotRead"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 |                 p_ccwbk=privptr->p_read_active_first; | 
 | 2674 |                 parm = (unsigned long) p_ch; | 
 | 2675 |                 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm, | 
 | 2676 | 				       0xff, 0); | 
 | 2677 |                 if (rc != 0) { | 
 | 2678 |                         ccw_check_return_code(p_ch->cdev, rc); | 
 | 2679 |                 } | 
 | 2680 |         } | 
 | 2681 | 	else { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2682 | 		CLAW_DBF_TEXT(2, trace, "ReadAct"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | 	} | 
 | 2684 |  | 
 | 2685 |         if (lock==LOCK_YES) { | 
 | 2686 |                 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags); | 
 | 2687 |         } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2688 | 	CLAW_DBF_TEXT(4, trace, "StRdExit"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 |         return; | 
 | 2690 | }       /*    end of claw_strt_read    */ | 
 | 2691 |  | 
 | 2692 | /*-------------------------------------------------------------------* | 
 | 2693 | *       claw_strt_out_IO                                             * | 
 | 2694 | *                                                                    * | 
 | 2695 | *--------------------------------------------------------------------*/ | 
 | 2696 |  | 
 | 2697 | static void | 
 | 2698 | claw_strt_out_IO( struct net_device *dev ) | 
 | 2699 | { | 
 | 2700 |         int             	rc = 0; | 
 | 2701 |         unsigned long   	parm; | 
 | 2702 |         struct claw_privbk 	*privptr; | 
 | 2703 |         struct chbk     	*p_ch; | 
 | 2704 |         struct ccwbk   	*p_first_ccw; | 
 | 2705 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | 	if (!dev) { | 
 | 2707 | 		return; | 
 | 2708 | 	} | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2709 | 	privptr = (struct claw_privbk *)dev->ml_priv; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2710 | 	p_ch = &privptr->channel[WRITE_CHANNEL]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2712 | 	CLAW_DBF_TEXT(4, trace, "strt_io"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 |         p_first_ccw=privptr->p_write_active_first; | 
 | 2714 |  | 
 | 2715 |         if (p_ch->claw_state == CLAW_STOP) | 
 | 2716 |                 return; | 
 | 2717 |         if (p_first_ccw == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 |                 return; | 
 | 2719 |         } | 
 | 2720 |         if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) { | 
 | 2721 |                 parm = (unsigned long) p_ch; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2722 | 		CLAW_DBF_TEXT(2, trace, "StWrtIO"); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2723 | 		rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm, | 
 | 2724 | 				      0xff, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 |                 if (rc != 0) { | 
 | 2726 |                         ccw_check_return_code(p_ch->cdev, rc); | 
 | 2727 |                 } | 
 | 2728 |         } | 
 | 2729 |         dev->trans_start = jiffies; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 |         return; | 
 | 2731 | }       /*    end of claw_strt_out_IO    */ | 
 | 2732 |  | 
 | 2733 | /*-------------------------------------------------------------------* | 
 | 2734 | *       Free write buffers                                           * | 
 | 2735 | *                                                                    * | 
 | 2736 | *--------------------------------------------------------------------*/ | 
 | 2737 |  | 
 | 2738 | static void | 
 | 2739 | claw_free_wrt_buf( struct net_device *dev ) | 
 | 2740 | { | 
 | 2741 |  | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2742 | 	struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | 	struct ccwbk*p_this_ccw; | 
 | 2744 | 	struct ccwbk*p_next_ccw; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2745 |  | 
 | 2746 | 	CLAW_DBF_TEXT(4, trace, "freewrtb"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 |         /*  scan the write queue to free any completed write packets   */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 |         p_this_ccw=privptr->p_write_active_first; | 
 | 2749 |         while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING)) | 
 | 2750 |         { | 
 | 2751 |                 p_next_ccw = p_this_ccw->next; | 
 | 2752 |                 if (((p_next_ccw!=NULL) && | 
 | 2753 | 		     (p_next_ccw->header.flag!=CLAW_PENDING)) || | 
 | 2754 |                     ((p_this_ccw == privptr->p_write_active_last) && | 
 | 2755 |                      (p_this_ccw->header.flag!=CLAW_PENDING))) { | 
 | 2756 |                         /* The next CCW is OK or this is  */ | 
 | 2757 | 			/* the last CCW...free it   @A1A  */ | 
 | 2758 |                         privptr->p_write_active_first=p_this_ccw->next; | 
 | 2759 | 			p_this_ccw->header.flag=CLAW_PENDING; | 
 | 2760 |                         p_this_ccw->next=privptr->p_write_free_chain; | 
 | 2761 | 			privptr->p_write_free_chain=p_this_ccw; | 
 | 2762 |                         ++privptr->write_free_count; | 
 | 2763 | 			privptr->stats.tx_bytes+= p_this_ccw->write.count; | 
 | 2764 | 			p_this_ccw=privptr->p_write_active_first; | 
 | 2765 |                         privptr->stats.tx_packets++; | 
 | 2766 |                 } | 
 | 2767 |                 else { | 
 | 2768 | 			break; | 
 | 2769 |                 } | 
 | 2770 |         } | 
 | 2771 |         if (privptr->write_free_count!=0) { | 
 | 2772 |                 claw_clearbit_busy(TB_NOBUFFER,dev); | 
 | 2773 |         } | 
 | 2774 |         /*   whole chain removed?   */ | 
 | 2775 |         if (privptr->p_write_active_first==NULL) { | 
 | 2776 |                 privptr->p_write_active_last=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 |         } | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2778 | 	CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 |         return; | 
 | 2780 | } | 
 | 2781 |  | 
 | 2782 | /*-------------------------------------------------------------------* | 
 | 2783 | *       claw free netdevice                                          * | 
 | 2784 | *                                                                    * | 
 | 2785 | *--------------------------------------------------------------------*/ | 
 | 2786 | static void | 
 | 2787 | claw_free_netdevice(struct net_device * dev, int free_dev) | 
 | 2788 | { | 
 | 2789 | 	struct claw_privbk *privptr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2791 | 	CLAW_DBF_TEXT(2, setup, "free_dev"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | 	if (!dev) | 
 | 2793 | 		return; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2794 | 	CLAW_DBF_TEXT_(2, setup, "%s", dev->name); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2795 | 	privptr = dev->ml_priv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | 	if (dev->flags & IFF_RUNNING) | 
 | 2797 | 		claw_release(dev); | 
 | 2798 | 	if (privptr) { | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2799 | 		privptr->channel[READ_CHANNEL].ndev = NULL;  /* say it's free */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | 	} | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2801 | 	dev->ml_priv = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | #ifdef MODULE | 
 | 2803 | 	if (free_dev) { | 
 | 2804 | 		free_netdev(dev); | 
 | 2805 | 	} | 
 | 2806 | #endif | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2807 | 	CLAW_DBF_TEXT(2, setup, "free_ok"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | } | 
 | 2809 |  | 
 | 2810 | /** | 
 | 2811 |  * Claw init netdevice | 
 | 2812 |  * Initialize everything of the net device except the name and the | 
 | 2813 |  * channel structs. | 
 | 2814 |  */ | 
| Frank Blaschka | 2171dc1 | 2009-01-09 03:43:59 +0000 | [diff] [blame] | 2815 | static const struct net_device_ops claw_netdev_ops = { | 
 | 2816 | 	.ndo_open		= claw_open, | 
 | 2817 | 	.ndo_stop		= claw_release, | 
 | 2818 | 	.ndo_get_stats		= claw_stats, | 
 | 2819 | 	.ndo_start_xmit		= claw_tx, | 
 | 2820 | 	.ndo_change_mtu		= claw_change_mtu, | 
 | 2821 | }; | 
 | 2822 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | static void | 
 | 2824 | claw_init_netdevice(struct net_device * dev) | 
 | 2825 | { | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2826 | 	CLAW_DBF_TEXT(2, setup, "init_dev"); | 
 | 2827 | 	CLAW_DBF_TEXT_(2, setup, "%s", dev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | 	dev->mtu = CLAW_DEFAULT_MTU_SIZE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | 	dev->hard_header_len = 0; | 
 | 2830 | 	dev->addr_len = 0; | 
 | 2831 | 	dev->type = ARPHRD_SLIP; | 
 | 2832 | 	dev->tx_queue_len = 1300; | 
 | 2833 | 	dev->flags = IFF_POINTOPOINT | IFF_NOARP; | 
| Frank Blaschka | 2171dc1 | 2009-01-09 03:43:59 +0000 | [diff] [blame] | 2834 | 	dev->netdev_ops = &claw_netdev_ops; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2835 | 	CLAW_DBF_TEXT(2, setup, "initok"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | 	return; | 
 | 2837 | } | 
 | 2838 |  | 
 | 2839 | /** | 
 | 2840 |  * Init a new channel in the privptr->channel[i]. | 
 | 2841 |  * | 
 | 2842 |  * @param cdev  The ccw_device to be added. | 
 | 2843 |  * | 
 | 2844 |  * @return 0 on success, !0 on error. | 
 | 2845 |  */ | 
 | 2846 | static int | 
 | 2847 | add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr) | 
 | 2848 | { | 
 | 2849 | 	struct chbk *p_ch; | 
| Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2850 | 	struct ccw_dev_id dev_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 |  | 
| Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2852 | 	CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | 	privptr->channel[i].flag  = i+1;   /* Read is 1 Write is 2 */ | 
 | 2854 | 	p_ch = &privptr->channel[i]; | 
 | 2855 | 	p_ch->cdev = cdev; | 
| Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2856 | 	snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev)); | 
| Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2857 | 	ccw_device_get_id(cdev, &dev_id); | 
 | 2858 | 	p_ch->devno = dev_id.devno; | 
| Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 2859 | 	if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | 		return -ENOMEM; | 
 | 2861 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | 	return 0; | 
 | 2863 | } | 
 | 2864 |  | 
 | 2865 |  | 
 | 2866 | /** | 
 | 2867 |  * | 
 | 2868 |  * Setup an interface. | 
 | 2869 |  * | 
 | 2870 |  * @param cgdev  Device to be setup. | 
 | 2871 |  * | 
 | 2872 |  * @returns 0 on success, !0 on failure. | 
 | 2873 |  */ | 
 | 2874 | static int | 
 | 2875 | claw_new_device(struct ccwgroup_device *cgdev) | 
 | 2876 | { | 
 | 2877 | 	struct claw_privbk *privptr; | 
 | 2878 | 	struct claw_env *p_env; | 
 | 2879 | 	struct net_device *dev; | 
 | 2880 | 	int ret; | 
| Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2881 | 	struct ccw_dev_id dev_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2883 | 	dev_info(&cgdev->dev, "add for %s\n", | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2884 | 		 dev_name(&cgdev->cdev[READ_CHANNEL]->dev)); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2885 | 	CLAW_DBF_TEXT(2, setup, "new_dev"); | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2886 | 	privptr = dev_get_drvdata(&cgdev->dev); | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2887 | 	dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr); | 
 | 2888 | 	dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | 	if (!privptr) | 
 | 2890 | 		return -ENODEV; | 
 | 2891 | 	p_env = privptr->p_env; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2892 | 	ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id); | 
 | 2893 | 	p_env->devno[READ_CHANNEL] = dev_id.devno; | 
 | 2894 | 	ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id); | 
 | 2895 | 	p_env->devno[WRITE_CHANNEL] = dev_id.devno; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | 	ret = add_channel(cgdev->cdev[0],0,privptr); | 
 | 2897 | 	if (ret == 0) | 
 | 2898 | 		ret = add_channel(cgdev->cdev[1],1,privptr); | 
 | 2899 | 	if (ret != 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2900 | 		dev_warn(&cgdev->dev, "Creating a CLAW group device" | 
 | 2901 | 			" failed with error code %d\n", ret); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2902 | 		goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | 	} | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2904 | 	ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | 	if (ret != 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2906 | 		dev_warn(&cgdev->dev, | 
 | 2907 | 			"Setting the read subchannel online" | 
 | 2908 | 			" failed with error code %d\n", ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | 		goto out; | 
 | 2910 | 	} | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2911 | 	ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | 	if (ret != 0) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2913 | 		dev_warn(&cgdev->dev, | 
 | 2914 | 			"Setting the write subchannel online " | 
 | 2915 | 			"failed with error code %d\n", ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | 		goto out; | 
 | 2917 | 	} | 
 | 2918 | 	dev = alloc_netdev(0,"claw%d",claw_init_netdevice); | 
 | 2919 | 	if (!dev) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2920 | 		dev_warn(&cgdev->dev, | 
 | 2921 | 			"Activating the CLAW device failed\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | 		goto out; | 
 | 2923 | 	} | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2924 | 	dev->ml_priv = privptr; | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2925 | 	dev_set_drvdata(&cgdev->dev, privptr); | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2926 | 	dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr); | 
 | 2927 | 	dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | 	/* sysfs magic */ | 
 | 2929 |         SET_NETDEV_DEV(dev, &cgdev->dev); | 
 | 2930 | 	if (register_netdev(dev) != 0) { | 
 | 2931 | 		claw_free_netdevice(dev, 1); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2932 | 		CLAW_DBF_TEXT(2, trace, "regfail"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | 		goto out; | 
 | 2934 | 	} | 
 | 2935 | 	dev->flags &=~IFF_RUNNING; | 
 | 2936 | 	if (privptr->buffs_alloc == 0) { | 
 | 2937 | 	        ret=init_ccw_bk(dev); | 
 | 2938 | 		if (ret !=0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | 			unregister_netdev(dev); | 
 | 2940 | 			claw_free_netdevice(dev,1); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2941 | 			CLAW_DBF_TEXT(2, trace, "ccwmem"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | 			goto out; | 
 | 2943 | 		} | 
 | 2944 | 	} | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2945 | 	privptr->channel[READ_CHANNEL].ndev = dev; | 
 | 2946 | 	privptr->channel[WRITE_CHANNEL].ndev = dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | 	privptr->p_env->ndev = dev; | 
 | 2948 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2949 | 	dev_info(&cgdev->dev, "%s:readsize=%d  writesize=%d " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | 		"readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n", | 
 | 2951 |                 dev->name, p_env->read_size, | 
 | 2952 | 		p_env->write_size, p_env->read_buffers, | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2953 | 		p_env->write_buffers, p_env->devno[READ_CHANNEL], | 
 | 2954 | 		p_env->devno[WRITE_CHANNEL]); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2955 | 	dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | 		":%.8s api_type: %.8s\n", | 
 | 2957 |                 dev->name, p_env->host_name, | 
 | 2958 | 		p_env->adapter_name , p_env->api_type); | 
 | 2959 | 	return 0; | 
 | 2960 | out: | 
 | 2961 | 	ccw_device_set_offline(cgdev->cdev[1]); | 
 | 2962 | 	ccw_device_set_offline(cgdev->cdev[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | 	return -ENODEV; | 
 | 2964 | } | 
 | 2965 |  | 
 | 2966 | static void | 
 | 2967 | claw_purge_skb_queue(struct sk_buff_head *q) | 
 | 2968 | { | 
 | 2969 |         struct sk_buff *skb; | 
 | 2970 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2971 | 	CLAW_DBF_TEXT(4, trace, "purgque"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 |         while ((skb = skb_dequeue(q))) { | 
 | 2973 |                 atomic_dec(&skb->users); | 
| Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 2974 |                 dev_kfree_skb_any(skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 |         } | 
 | 2976 | } | 
 | 2977 |  | 
 | 2978 | /** | 
 | 2979 |  * Shutdown an interface. | 
 | 2980 |  * | 
 | 2981 |  * @param cgdev  Device to be shut down. | 
 | 2982 |  * | 
 | 2983 |  * @returns 0 on success, !0 on failure. | 
 | 2984 |  */ | 
 | 2985 | static int | 
 | 2986 | claw_shutdown_device(struct ccwgroup_device *cgdev) | 
 | 2987 | { | 
 | 2988 | 	struct claw_privbk *priv; | 
 | 2989 | 	struct net_device *ndev; | 
| Heiko Carstens | 38ed18f | 2011-05-12 18:45:04 +0000 | [diff] [blame] | 2990 | 	int ret = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 |  | 
| Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 2992 | 	CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev)); | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2993 | 	priv = dev_get_drvdata(&cgdev->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | 	if (!priv) | 
 | 2995 | 		return -ENODEV; | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2996 | 	ndev = priv->channel[READ_CHANNEL].ndev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | 	if (ndev) { | 
 | 2998 | 		/* Close the device */ | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2999 | 		dev_info(&cgdev->dev, "%s: shutting down\n", | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3000 | 			ndev->name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | 		if (ndev->flags & IFF_RUNNING) | 
 | 3002 | 			ret = claw_release(ndev); | 
 | 3003 | 		ndev->flags &=~IFF_RUNNING; | 
 | 3004 | 		unregister_netdev(ndev); | 
| Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 3005 | 		ndev->ml_priv = NULL;  /* cgdev data, not ndev's to free */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | 		claw_free_netdevice(ndev, 1); | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 3007 | 		priv->channel[READ_CHANNEL].ndev = NULL; | 
 | 3008 | 		priv->channel[WRITE_CHANNEL].ndev = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | 		priv->p_env->ndev = NULL; | 
 | 3010 | 	} | 
 | 3011 | 	ccw_device_set_offline(cgdev->cdev[1]); | 
 | 3012 | 	ccw_device_set_offline(cgdev->cdev[0]); | 
| Heiko Carstens | 38ed18f | 2011-05-12 18:45:04 +0000 | [diff] [blame] | 3013 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | } | 
 | 3015 |  | 
 | 3016 | static void | 
 | 3017 | claw_remove_device(struct ccwgroup_device *cgdev) | 
 | 3018 | { | 
 | 3019 | 	struct claw_privbk *priv; | 
 | 3020 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3021 | 	BUG_ON(!cgdev); | 
| Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 3022 | 	CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev)); | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3023 | 	priv = dev_get_drvdata(&cgdev->dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3024 | 	BUG_ON(!priv); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3025 | 	dev_info(&cgdev->dev, " will be removed.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | 	if (cgdev->state == CCWGROUP_ONLINE) | 
 | 3027 | 		claw_shutdown_device(cgdev); | 
| Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 3028 | 	kfree(priv->p_mtc_envelope); | 
 | 3029 | 	priv->p_mtc_envelope=NULL; | 
 | 3030 | 	kfree(priv->p_env); | 
 | 3031 | 	priv->p_env=NULL; | 
 | 3032 | 	kfree(priv->channel[0].irb); | 
 | 3033 | 	priv->channel[0].irb=NULL; | 
 | 3034 | 	kfree(priv->channel[1].irb); | 
 | 3035 | 	priv->channel[1].irb=NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | 	kfree(priv); | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3037 | 	dev_set_drvdata(&cgdev->dev, NULL); | 
| Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 3038 | 	dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL); | 
 | 3039 | 	dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | 	put_device(&cgdev->dev); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3041 |  | 
 | 3042 | 	return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | } | 
 | 3044 |  | 
 | 3045 |  | 
 | 3046 | /* | 
 | 3047 |  * sysfs attributes | 
 | 3048 |  */ | 
 | 3049 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3050 | claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | { | 
 | 3052 | 	struct claw_privbk *priv; | 
 | 3053 | 	struct claw_env *  p_env; | 
 | 3054 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3055 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | 	if (!priv) | 
 | 3057 | 		return -ENODEV; | 
 | 3058 | 	p_env = priv->p_env; | 
 | 3059 | 	return sprintf(buf, "%s\n",p_env->host_name); | 
 | 3060 | } | 
 | 3061 |  | 
 | 3062 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3063 | claw_hname_write(struct device *dev, struct device_attribute *attr, | 
 | 3064 | 	 const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | { | 
 | 3066 | 	struct claw_privbk *priv; | 
 | 3067 | 	struct claw_env *  p_env; | 
 | 3068 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3069 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | 	if (!priv) | 
 | 3071 | 		return -ENODEV; | 
 | 3072 | 	p_env = priv->p_env; | 
 | 3073 | 	if (count > MAX_NAME_LEN+1) | 
 | 3074 | 		return -EINVAL; | 
 | 3075 | 	memset(p_env->host_name, 0x20, MAX_NAME_LEN); | 
 | 3076 | 	strncpy(p_env->host_name,buf, count); | 
 | 3077 | 	p_env->host_name[count-1] = 0x20;  /* clear extra 0x0a */ | 
 | 3078 | 	p_env->host_name[MAX_NAME_LEN] = 0x00; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3079 | 	CLAW_DBF_TEXT(2, setup, "HstnSet"); | 
 | 3080 | 	CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 |  | 
 | 3082 | 	return count; | 
 | 3083 | } | 
 | 3084 |  | 
 | 3085 | static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write); | 
 | 3086 |  | 
 | 3087 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3088 | claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | { | 
 | 3090 | 	struct claw_privbk *priv; | 
 | 3091 | 	struct claw_env *  p_env; | 
 | 3092 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3093 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | 	if (!priv) | 
 | 3095 | 		return -ENODEV; | 
 | 3096 | 	p_env = priv->p_env; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3097 | 	return sprintf(buf, "%s\n", p_env->adapter_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | } | 
 | 3099 |  | 
 | 3100 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3101 | claw_adname_write(struct device *dev, struct device_attribute *attr, | 
 | 3102 | 	 const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | { | 
 | 3104 | 	struct claw_privbk *priv; | 
 | 3105 | 	struct claw_env *  p_env; | 
 | 3106 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3107 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | 	if (!priv) | 
 | 3109 | 		return -ENODEV; | 
 | 3110 | 	p_env = priv->p_env; | 
 | 3111 | 	if (count > MAX_NAME_LEN+1) | 
 | 3112 | 		return -EINVAL; | 
 | 3113 | 	memset(p_env->adapter_name, 0x20, MAX_NAME_LEN); | 
 | 3114 | 	strncpy(p_env->adapter_name,buf, count); | 
 | 3115 | 	p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */ | 
 | 3116 | 	p_env->adapter_name[MAX_NAME_LEN] = 0x00; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3117 | 	CLAW_DBF_TEXT(2, setup, "AdnSet"); | 
 | 3118 | 	CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 |  | 
 | 3120 | 	return count; | 
 | 3121 | } | 
 | 3122 |  | 
 | 3123 | static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write); | 
 | 3124 |  | 
 | 3125 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3126 | claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | { | 
 | 3128 | 	struct claw_privbk *priv; | 
 | 3129 | 	struct claw_env *  p_env; | 
 | 3130 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3131 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | 	if (!priv) | 
 | 3133 | 		return -ENODEV; | 
 | 3134 | 	p_env = priv->p_env; | 
 | 3135 | 	return sprintf(buf, "%s\n", | 
 | 3136 | 		       p_env->api_type); | 
 | 3137 | } | 
 | 3138 |  | 
 | 3139 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3140 | claw_apname_write(struct device *dev, struct device_attribute *attr, | 
 | 3141 | 	const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | { | 
 | 3143 | 	struct claw_privbk *priv; | 
 | 3144 | 	struct claw_env *  p_env; | 
 | 3145 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3146 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | 	if (!priv) | 
 | 3148 | 		return -ENODEV; | 
 | 3149 | 	p_env = priv->p_env; | 
 | 3150 | 	if (count > MAX_NAME_LEN+1) | 
 | 3151 | 		return -EINVAL; | 
 | 3152 | 	memset(p_env->api_type, 0x20, MAX_NAME_LEN); | 
 | 3153 | 	strncpy(p_env->api_type,buf, count); | 
 | 3154 | 	p_env->api_type[count-1] = 0x20;  /* we get a loose 0x0a */ | 
 | 3155 | 	p_env->api_type[MAX_NAME_LEN] = 0x00; | 
 | 3156 | 	if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) { | 
 | 3157 | 		p_env->read_size=DEF_PACK_BUFSIZE; | 
 | 3158 | 		p_env->write_size=DEF_PACK_BUFSIZE; | 
 | 3159 | 		p_env->packing=PACKING_ASK; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3160 | 		CLAW_DBF_TEXT(2, setup, "PACKING"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | 	} | 
 | 3162 | 	else { | 
 | 3163 | 		p_env->packing=0; | 
 | 3164 | 		p_env->read_size=CLAW_FRAME_SIZE; | 
 | 3165 | 		p_env->write_size=CLAW_FRAME_SIZE; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3166 | 		CLAW_DBF_TEXT(2, setup, "ApiSet"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | 	} | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3168 | 	CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | 	return count; | 
 | 3170 | } | 
 | 3171 |  | 
 | 3172 | static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write); | 
 | 3173 |  | 
 | 3174 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3175 | claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | { | 
 | 3177 | 	struct claw_privbk *priv; | 
 | 3178 | 	struct claw_env * p_env; | 
 | 3179 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3180 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | 	if (!priv) | 
 | 3182 | 		return -ENODEV; | 
 | 3183 | 	p_env = priv->p_env; | 
 | 3184 | 	return sprintf(buf, "%d\n", p_env->write_buffers); | 
 | 3185 | } | 
 | 3186 |  | 
 | 3187 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3188 | claw_wbuff_write(struct device *dev, struct device_attribute *attr, | 
 | 3189 | 	const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | { | 
 | 3191 | 	struct claw_privbk *priv; | 
 | 3192 | 	struct claw_env *  p_env; | 
 | 3193 | 	int nnn,max; | 
 | 3194 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3195 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | 	if (!priv) | 
 | 3197 | 		return -ENODEV; | 
 | 3198 | 	p_env = priv->p_env; | 
 | 3199 | 	sscanf(buf, "%i", &nnn); | 
 | 3200 | 	if (p_env->packing) { | 
 | 3201 | 		max = 64; | 
 | 3202 | 	} | 
 | 3203 | 	else { | 
 | 3204 | 		max = 512; | 
 | 3205 | 	} | 
 | 3206 | 	if ((nnn > max ) || (nnn < 2)) | 
 | 3207 | 		return -EINVAL; | 
 | 3208 | 	p_env->write_buffers = nnn; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3209 | 	CLAW_DBF_TEXT(2, setup, "Wbufset"); | 
 | 3210 | 	CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | 	return count; | 
 | 3212 | } | 
 | 3213 |  | 
 | 3214 | static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write); | 
 | 3215 |  | 
 | 3216 | static ssize_t | 
| Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3217 | claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | { | 
 | 3219 | 	struct claw_privbk *priv; | 
 | 3220 | 	struct claw_env *  p_env; | 
 | 3221 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3222 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | 	if (!priv) | 
 | 3224 | 		return -ENODEV; | 
 | 3225 | 	p_env = priv->p_env; | 
 | 3226 | 	return sprintf(buf, "%d\n", p_env->read_buffers); | 
 | 3227 | } | 
 | 3228 |  | 
 | 3229 | static ssize_t | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3230 | claw_rbuff_write(struct device *dev, struct device_attribute *attr, | 
 | 3231 | 	const char *buf, size_t count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | { | 
 | 3233 | 	struct claw_privbk *priv; | 
 | 3234 | 	struct claw_env *p_env; | 
 | 3235 | 	int nnn,max; | 
 | 3236 |  | 
| Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3237 | 	priv = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | 	if (!priv) | 
 | 3239 | 		return -ENODEV; | 
 | 3240 | 	p_env = priv->p_env; | 
 | 3241 | 	sscanf(buf, "%i", &nnn); | 
 | 3242 | 	if (p_env->packing) { | 
 | 3243 | 		max = 64; | 
 | 3244 | 	} | 
 | 3245 | 	else { | 
 | 3246 | 		max = 512; | 
 | 3247 | 	} | 
 | 3248 | 	if ((nnn > max ) || (nnn < 2)) | 
 | 3249 | 		return -EINVAL; | 
 | 3250 | 	p_env->read_buffers = nnn; | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3251 | 	CLAW_DBF_TEXT(2, setup, "Rbufset"); | 
 | 3252 | 	CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | 	return count; | 
 | 3254 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write); | 
 | 3256 |  | 
 | 3257 | static struct attribute *claw_attr[] = { | 
 | 3258 | 	&dev_attr_read_buffer.attr, | 
 | 3259 | 	&dev_attr_write_buffer.attr, | 
 | 3260 | 	&dev_attr_adapter_name.attr, | 
 | 3261 | 	&dev_attr_api_type.attr, | 
 | 3262 | 	&dev_attr_host_name.attr, | 
 | 3263 | 	NULL, | 
 | 3264 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | static struct attribute_group claw_attr_group = { | 
 | 3266 | 	.attrs = claw_attr, | 
 | 3267 | }; | 
| Sebastian Ott | 2ced551 | 2012-05-15 18:00:49 +0200 | [diff] [blame] | 3268 | static const struct attribute_group *claw_attr_groups[] = { | 
 | 3269 | 	&claw_attr_group, | 
 | 3270 | 	NULL, | 
 | 3271 | }; | 
 | 3272 | static const struct device_type claw_devtype = { | 
 | 3273 | 	.name = "claw", | 
 | 3274 | 	.groups = claw_attr_groups, | 
 | 3275 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 |  | 
| Sebastian Ott | 2ced551 | 2012-05-15 18:00:49 +0200 | [diff] [blame] | 3277 | /*----------------------------------------------------------------* | 
 | 3278 |  *   claw_probe 						  * | 
 | 3279 |  *	this function is called for each CLAW device.		  * | 
 | 3280 |  *----------------------------------------------------------------*/ | 
 | 3281 | static int claw_probe(struct ccwgroup_device *cgdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | { | 
| Sebastian Ott | 2ced551 | 2012-05-15 18:00:49 +0200 | [diff] [blame] | 3283 | 	struct claw_privbk *privptr = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 |  | 
| Sebastian Ott | 2ced551 | 2012-05-15 18:00:49 +0200 | [diff] [blame] | 3285 | 	CLAW_DBF_TEXT(2, setup, "probe"); | 
 | 3286 | 	if (!get_device(&cgdev->dev)) | 
 | 3287 | 		return -ENODEV; | 
 | 3288 | 	privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL); | 
 | 3289 | 	dev_set_drvdata(&cgdev->dev, privptr); | 
 | 3290 | 	if (privptr == NULL) { | 
 | 3291 | 		probe_error(cgdev); | 
 | 3292 | 		put_device(&cgdev->dev); | 
 | 3293 | 		CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM); | 
 | 3294 | 		return -ENOMEM; | 
 | 3295 | 	} | 
 | 3296 | 	privptr->p_mtc_envelope = kzalloc(MAX_ENVELOPE_SIZE, GFP_KERNEL); | 
 | 3297 | 	privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL); | 
 | 3298 | 	if ((privptr->p_mtc_envelope == NULL) || (privptr->p_env == NULL)) { | 
 | 3299 | 		probe_error(cgdev); | 
 | 3300 | 		put_device(&cgdev->dev); | 
 | 3301 | 		CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM); | 
 | 3302 | 		return -ENOMEM; | 
 | 3303 | 	} | 
 | 3304 | 	memcpy(privptr->p_env->adapter_name, WS_NAME_NOT_DEF, 8); | 
 | 3305 | 	memcpy(privptr->p_env->host_name, WS_NAME_NOT_DEF, 8); | 
 | 3306 | 	memcpy(privptr->p_env->api_type, WS_NAME_NOT_DEF, 8); | 
 | 3307 | 	privptr->p_env->packing = 0; | 
 | 3308 | 	privptr->p_env->write_buffers = 5; | 
 | 3309 | 	privptr->p_env->read_buffers = 5; | 
 | 3310 | 	privptr->p_env->read_size = CLAW_FRAME_SIZE; | 
 | 3311 | 	privptr->p_env->write_size = CLAW_FRAME_SIZE; | 
 | 3312 | 	privptr->p_env->p_priv = privptr; | 
 | 3313 | 	cgdev->cdev[0]->handler = claw_irq_handler; | 
 | 3314 | 	cgdev->cdev[1]->handler = claw_irq_handler; | 
 | 3315 | 	cgdev->dev.type = &claw_devtype; | 
 | 3316 | 	CLAW_DBF_TEXT(2, setup, "prbext 0"); | 
 | 3317 |  | 
 | 3318 | 	return 0; | 
 | 3319 | }  /*  end of claw_probe       */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 |  | 
 | 3321 | /*--------------------------------------------------------------------* | 
 | 3322 | *    claw_init  and cleanup                                           * | 
 | 3323 | *---------------------------------------------------------------------*/ | 
 | 3324 |  | 
| Sebastian Ott | a43f8de | 2012-05-15 18:06:29 +0200 | [diff] [blame] | 3325 | static void __exit claw_cleanup(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | { | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 3327 | 	ccwgroup_driver_unregister(&claw_group_driver); | 
 | 3328 | 	ccw_driver_unregister(&claw_ccw_driver); | 
 | 3329 | 	root_device_unregister(claw_root_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | 	claw_unregister_debug_facility(); | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3331 | 	pr_info("Driver unloaded\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | } | 
 | 3333 |  | 
 | 3334 | /** | 
 | 3335 |  * Initialize module. | 
 | 3336 |  * This is called just after the module is loaded. | 
 | 3337 |  * | 
 | 3338 |  * @return 0 on success, !0 on error. | 
 | 3339 |  */ | 
| Sebastian Ott | a43f8de | 2012-05-15 18:06:29 +0200 | [diff] [blame] | 3340 | static int __init claw_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | { | 
 | 3342 | 	int ret = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 |  | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3344 | 	pr_info("Loading %s\n", version); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | 	ret = claw_register_debug_facility(); | 
 | 3346 | 	if (ret) { | 
| Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3347 | 		pr_err("Registering with the S/390 debug feature" | 
 | 3348 | 			" failed with error code %d\n", ret); | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 3349 | 		goto out_err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | 	} | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3351 | 	CLAW_DBF_TEXT(2, setup, "init_mod"); | 
| Ursula Braun | d950d17 | 2010-01-04 03:14:45 +0000 | [diff] [blame] | 3352 | 	claw_root_dev = root_device_register("claw"); | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 3353 | 	ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0; | 
 | 3354 | 	if (ret) | 
 | 3355 | 		goto register_err; | 
 | 3356 | 	ret = ccw_driver_register(&claw_ccw_driver); | 
 | 3357 | 	if (ret) | 
 | 3358 | 		goto ccw_err; | 
| Sebastian Ott | a43f8de | 2012-05-15 18:06:29 +0200 | [diff] [blame] | 3359 | 	claw_group_driver.driver.groups = claw_drv_attr_groups; | 
| Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 3360 | 	ret = ccwgroup_driver_register(&claw_group_driver); | 
 | 3361 | 	if (ret) | 
 | 3362 | 		goto ccwgroup_err; | 
 | 3363 | 	return 0; | 
 | 3364 |  | 
 | 3365 | ccwgroup_err: | 
 | 3366 | 	ccw_driver_unregister(&claw_ccw_driver); | 
 | 3367 | ccw_err: | 
 | 3368 | 	root_device_unregister(claw_root_dev); | 
 | 3369 | register_err: | 
 | 3370 | 	CLAW_DBF_TEXT(2, setup, "init_bad"); | 
 | 3371 | 	claw_unregister_debug_facility(); | 
 | 3372 | out_err: | 
 | 3373 | 	pr_err("Initializing the claw device driver failed\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | 	return ret; | 
 | 3375 | } | 
 | 3376 |  | 
 | 3377 | module_init(claw_init); | 
 | 3378 | module_exit(claw_cleanup); | 
 | 3379 |  | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3380 | MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>"); | 
 | 3381 | MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \ | 
| Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 3382 | 			"Copyright IBM Corp. 2000, 2008\n"); | 
| Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3383 | MODULE_LICENSE("GPL"); |