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