Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * IUCV network driver |
| 3 | * |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2001, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 6 | * Author(s): |
| 7 | * Original netiucv driver: |
| 8 | * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com) |
| 9 | * Sysfs integration and all bugs therein: |
| 10 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
| 11 | * PM functions: |
| 12 | * Ursula Braun (ursula.braun@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
| 14 | * Documentation used: |
| 15 | * the source of the original IUCV driver by: |
| 16 | * Stefan Hegewald <hegewald@de.ibm.com> |
| 17 | * Hartmut Penner <hpenner@de.ibm.com> |
| 18 | * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
| 19 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 20 | * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000 |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by |
| 24 | * the Free Software Foundation; either version 2, or (at your option) |
| 25 | * any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 37 | |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 38 | #define KMSG_COMPONENT "netiucv" |
| 39 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #undef DEBUG |
| 42 | |
| 43 | #include <linux/module.h> |
| 44 | #include <linux/init.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/slab.h> |
| 47 | #include <linux/errno.h> |
| 48 | #include <linux/types.h> |
| 49 | #include <linux/interrupt.h> |
| 50 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/bitops.h> |
| 52 | |
| 53 | #include <linux/signal.h> |
| 54 | #include <linux/string.h> |
| 55 | #include <linux/device.h> |
| 56 | |
| 57 | #include <linux/ip.h> |
| 58 | #include <linux/if_arp.h> |
| 59 | #include <linux/tcp.h> |
| 60 | #include <linux/skbuff.h> |
| 61 | #include <linux/ctype.h> |
| 62 | #include <net/dst.h> |
| 63 | |
| 64 | #include <asm/io.h> |
| 65 | #include <asm/uaccess.h> |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 66 | #include <asm/ebcdic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 68 | #include <net/iucv/iucv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #include "fsm.h" |
| 70 | |
| 71 | MODULE_AUTHOR |
| 72 | ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)"); |
| 73 | MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver"); |
| 74 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 75 | /** |
| 76 | * Debug Facility stuff |
| 77 | */ |
| 78 | #define IUCV_DBF_SETUP_NAME "iucv_setup" |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 79 | #define IUCV_DBF_SETUP_LEN 64 |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 80 | #define IUCV_DBF_SETUP_PAGES 2 |
| 81 | #define IUCV_DBF_SETUP_NR_AREAS 1 |
| 82 | #define IUCV_DBF_SETUP_LEVEL 3 |
| 83 | |
| 84 | #define IUCV_DBF_DATA_NAME "iucv_data" |
| 85 | #define IUCV_DBF_DATA_LEN 128 |
| 86 | #define IUCV_DBF_DATA_PAGES 2 |
| 87 | #define IUCV_DBF_DATA_NR_AREAS 1 |
| 88 | #define IUCV_DBF_DATA_LEVEL 2 |
| 89 | |
| 90 | #define IUCV_DBF_TRACE_NAME "iucv_trace" |
| 91 | #define IUCV_DBF_TRACE_LEN 16 |
| 92 | #define IUCV_DBF_TRACE_PAGES 4 |
| 93 | #define IUCV_DBF_TRACE_NR_AREAS 1 |
| 94 | #define IUCV_DBF_TRACE_LEVEL 3 |
| 95 | |
| 96 | #define IUCV_DBF_TEXT(name,level,text) \ |
| 97 | do { \ |
| 98 | debug_text_event(iucv_dbf_##name,level,text); \ |
| 99 | } while (0) |
| 100 | |
| 101 | #define IUCV_DBF_HEX(name,level,addr,len) \ |
| 102 | do { \ |
| 103 | debug_event(iucv_dbf_##name,level,(void*)(addr),len); \ |
| 104 | } while (0) |
| 105 | |
| 106 | DECLARE_PER_CPU(char[256], iucv_dbf_txt_buf); |
| 107 | |
Peter Tiedemann | f33780d | 2008-02-08 13:09:05 +0100 | [diff] [blame] | 108 | #define IUCV_DBF_TEXT_(name, level, text...) \ |
| 109 | do { \ |
Hendrik Brueckner | 8e6a828 | 2013-09-18 17:21:34 +0200 | [diff] [blame] | 110 | if (debug_level_enabled(iucv_dbf_##name, level)) { \ |
Tejun Heo | 390dfd9 | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 111 | char* __buf = get_cpu_var(iucv_dbf_txt_buf); \ |
| 112 | sprintf(__buf, text); \ |
| 113 | debug_text_event(iucv_dbf_##name, level, __buf); \ |
Peter Tiedemann | f33780d | 2008-02-08 13:09:05 +0100 | [diff] [blame] | 114 | put_cpu_var(iucv_dbf_txt_buf); \ |
| 115 | } \ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 116 | } while (0) |
| 117 | |
| 118 | #define IUCV_DBF_SPRINTF(name,level,text...) \ |
| 119 | do { \ |
| 120 | debug_sprintf_event(iucv_dbf_trace, level, ##text ); \ |
| 121 | debug_sprintf_event(iucv_dbf_trace, level, text ); \ |
| 122 | } while (0) |
| 123 | |
| 124 | /** |
| 125 | * some more debug stuff |
| 126 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | #define PRINTK_HEADER " iucv: " /* for debugging */ |
| 128 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 129 | /* dummy device to make sure netiucv_pm functions are called */ |
| 130 | static struct device *netiucv_dev; |
| 131 | |
| 132 | static int netiucv_pm_prepare(struct device *); |
| 133 | static void netiucv_pm_complete(struct device *); |
| 134 | static int netiucv_pm_freeze(struct device *); |
| 135 | static int netiucv_pm_restore_thaw(struct device *); |
| 136 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 137 | static const struct dev_pm_ops netiucv_pm_ops = { |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 138 | .prepare = netiucv_pm_prepare, |
| 139 | .complete = netiucv_pm_complete, |
| 140 | .freeze = netiucv_pm_freeze, |
| 141 | .thaw = netiucv_pm_restore_thaw, |
| 142 | .restore = netiucv_pm_restore_thaw, |
| 143 | }; |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static struct device_driver netiucv_driver = { |
Cornelia Huck | 2219510 | 2008-02-08 13:09:02 +0100 | [diff] [blame] | 146 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | .name = "netiucv", |
| 148 | .bus = &iucv_bus, |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 149 | .pm = &netiucv_pm_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 152 | static int netiucv_callback_connreq(struct iucv_path *, |
| 153 | u8 ipvmid[8], u8 ipuser[16]); |
| 154 | static void netiucv_callback_connack(struct iucv_path *, u8 ipuser[16]); |
| 155 | static void netiucv_callback_connrej(struct iucv_path *, u8 ipuser[16]); |
| 156 | static void netiucv_callback_connsusp(struct iucv_path *, u8 ipuser[16]); |
| 157 | static void netiucv_callback_connres(struct iucv_path *, u8 ipuser[16]); |
| 158 | static void netiucv_callback_rx(struct iucv_path *, struct iucv_message *); |
| 159 | static void netiucv_callback_txdone(struct iucv_path *, struct iucv_message *); |
| 160 | |
| 161 | static struct iucv_handler netiucv_handler = { |
| 162 | .path_pending = netiucv_callback_connreq, |
| 163 | .path_complete = netiucv_callback_connack, |
| 164 | .path_severed = netiucv_callback_connrej, |
| 165 | .path_quiesced = netiucv_callback_connsusp, |
| 166 | .path_resumed = netiucv_callback_connres, |
| 167 | .message_pending = netiucv_callback_rx, |
| 168 | .message_complete = netiucv_callback_txdone |
| 169 | }; |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /** |
| 172 | * Per connection profiling data |
| 173 | */ |
| 174 | struct connection_profile { |
| 175 | unsigned long maxmulti; |
| 176 | unsigned long maxcqueue; |
| 177 | unsigned long doios_single; |
| 178 | unsigned long doios_multi; |
| 179 | unsigned long txlen; |
| 180 | unsigned long tx_time; |
Aya Mahfouz | ee6edb9 | 2015-01-16 14:05:45 +0100 | [diff] [blame] | 181 | unsigned long send_stamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | unsigned long tx_pending; |
| 183 | unsigned long tx_max_pending; |
| 184 | }; |
| 185 | |
| 186 | /** |
| 187 | * Representation of one iucv connection |
| 188 | */ |
| 189 | struct iucv_connection { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 190 | struct list_head list; |
| 191 | struct iucv_path *path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | struct sk_buff *rx_buff; |
| 193 | struct sk_buff *tx_buff; |
| 194 | struct sk_buff_head collect_queue; |
| 195 | struct sk_buff_head commit_queue; |
| 196 | spinlock_t collect_lock; |
| 197 | int collect_len; |
| 198 | int max_buffsize; |
| 199 | fsm_timer timer; |
| 200 | fsm_instance *fsm; |
| 201 | struct net_device *netdev; |
| 202 | struct connection_profile prof; |
| 203 | char userid[9]; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 204 | char userdata[17]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | /** |
| 208 | * Linked list of all connection structs. |
| 209 | */ |
Denis Cheng | c11ca97 | 2008-01-26 14:11:13 +0100 | [diff] [blame] | 210 | static LIST_HEAD(iucv_connection_list); |
Thomas Gleixner | bfac0d0 | 2007-06-20 13:02:55 +0200 | [diff] [blame] | 211 | static DEFINE_RWLOCK(iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * Representation of event-data for the |
| 215 | * connection state machine. |
| 216 | */ |
| 217 | struct iucv_event { |
| 218 | struct iucv_connection *conn; |
| 219 | void *data; |
| 220 | }; |
| 221 | |
| 222 | /** |
| 223 | * Private part of the network device structure |
| 224 | */ |
| 225 | struct netiucv_priv { |
| 226 | struct net_device_stats stats; |
| 227 | unsigned long tbusy; |
| 228 | fsm_instance *fsm; |
| 229 | struct iucv_connection *conn; |
| 230 | struct device *dev; |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 231 | int pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | /** |
| 235 | * Link level header for a packet. |
| 236 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 237 | struct ll_header { |
| 238 | u16 next; |
| 239 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 241 | #define NETIUCV_HDRLEN (sizeof(struct ll_header)) |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 242 | #define NETIUCV_BUFSIZE_MAX 65537 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX |
| 244 | #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN) |
| 245 | #define NETIUCV_MTU_DEFAULT 9216 |
| 246 | #define NETIUCV_QUEUELEN_DEFAULT 50 |
| 247 | #define NETIUCV_TIMEOUT_5SEC 5000 |
| 248 | |
| 249 | /** |
| 250 | * Compatibility macros for busy handling |
| 251 | * of network devices. |
| 252 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 253 | static inline void netiucv_clear_busy(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 255 | struct netiucv_priv *priv = netdev_priv(dev); |
| 256 | clear_bit(0, &priv->tbusy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | netif_wake_queue(dev); |
| 258 | } |
| 259 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 260 | static inline int netiucv_test_and_set_busy(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 262 | struct netiucv_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | netif_stop_queue(dev); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 264 | return test_and_set_bit(0, &priv->tbusy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 267 | static u8 iucvMagic_ascii[16] = { |
| 268 | 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 269 | 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 |
| 270 | }; |
| 271 | |
| 272 | static u8 iucvMagic_ebcdic[16] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
| 274 | 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 |
| 275 | }; |
| 276 | |
| 277 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | * Convert an iucv userId to its printable |
| 279 | * form (strip whitespace at end). |
| 280 | * |
| 281 | * @param An iucv userId |
| 282 | * |
| 283 | * @returns The printable string (static data!!) |
| 284 | */ |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 285 | static char *netiucv_printname(char *name, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 287 | static char tmp[17]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | char *p = tmp; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 289 | memcpy(tmp, name, len); |
| 290 | tmp[len] = '\0'; |
| 291 | while (*p && ((p - tmp) < len) && (!isspace(*p))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | p++; |
| 293 | *p = '\0'; |
| 294 | return tmp; |
| 295 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 296 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 297 | static char *netiucv_printuser(struct iucv_connection *conn) |
| 298 | { |
| 299 | static char tmp_uid[9]; |
| 300 | static char tmp_udat[17]; |
| 301 | static char buf[100]; |
| 302 | |
| 303 | if (memcmp(conn->userdata, iucvMagic_ebcdic, 16)) { |
| 304 | tmp_uid[8] = '\0'; |
| 305 | tmp_udat[16] = '\0'; |
| 306 | memcpy(tmp_uid, conn->userid, 8); |
| 307 | memcpy(tmp_uid, netiucv_printname(tmp_uid, 8), 8); |
| 308 | memcpy(tmp_udat, conn->userdata, 16); |
| 309 | EBCASC(tmp_udat, 16); |
| 310 | memcpy(tmp_udat, netiucv_printname(tmp_udat, 16), 16); |
| 311 | sprintf(buf, "%s.%s", tmp_uid, tmp_udat); |
| 312 | return buf; |
| 313 | } else |
| 314 | return netiucv_printname(conn->userid, 8); |
| 315 | } |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | /** |
| 318 | * States of the interface statemachine. |
| 319 | */ |
| 320 | enum dev_states { |
| 321 | DEV_STATE_STOPPED, |
| 322 | DEV_STATE_STARTWAIT, |
| 323 | DEV_STATE_STOPWAIT, |
| 324 | DEV_STATE_RUNNING, |
| 325 | /** |
| 326 | * MUST be always the last element!! |
| 327 | */ |
| 328 | NR_DEV_STATES |
| 329 | }; |
| 330 | |
| 331 | static const char *dev_state_names[] = { |
| 332 | "Stopped", |
| 333 | "StartWait", |
| 334 | "StopWait", |
| 335 | "Running", |
| 336 | }; |
| 337 | |
| 338 | /** |
| 339 | * Events of the interface statemachine. |
| 340 | */ |
| 341 | enum dev_events { |
| 342 | DEV_EVENT_START, |
| 343 | DEV_EVENT_STOP, |
| 344 | DEV_EVENT_CONUP, |
| 345 | DEV_EVENT_CONDOWN, |
| 346 | /** |
| 347 | * MUST be always the last element!! |
| 348 | */ |
| 349 | NR_DEV_EVENTS |
| 350 | }; |
| 351 | |
| 352 | static const char *dev_event_names[] = { |
| 353 | "Start", |
| 354 | "Stop", |
| 355 | "Connection up", |
| 356 | "Connection down", |
| 357 | }; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /** |
| 360 | * Events of the connection statemachine |
| 361 | */ |
| 362 | enum conn_events { |
| 363 | /** |
| 364 | * Events, representing callbacks from |
| 365 | * lowlevel iucv layer) |
| 366 | */ |
| 367 | CONN_EVENT_CONN_REQ, |
| 368 | CONN_EVENT_CONN_ACK, |
| 369 | CONN_EVENT_CONN_REJ, |
| 370 | CONN_EVENT_CONN_SUS, |
| 371 | CONN_EVENT_CONN_RES, |
| 372 | CONN_EVENT_RX, |
| 373 | CONN_EVENT_TXDONE, |
| 374 | |
| 375 | /** |
| 376 | * Events, representing errors return codes from |
| 377 | * calls to lowlevel iucv layer |
| 378 | */ |
| 379 | |
| 380 | /** |
| 381 | * Event, representing timer expiry. |
| 382 | */ |
| 383 | CONN_EVENT_TIMER, |
| 384 | |
| 385 | /** |
| 386 | * Events, representing commands from upper levels. |
| 387 | */ |
| 388 | CONN_EVENT_START, |
| 389 | CONN_EVENT_STOP, |
| 390 | |
| 391 | /** |
| 392 | * MUST be always the last element!! |
| 393 | */ |
| 394 | NR_CONN_EVENTS, |
| 395 | }; |
| 396 | |
| 397 | static const char *conn_event_names[] = { |
| 398 | "Remote connection request", |
| 399 | "Remote connection acknowledge", |
| 400 | "Remote connection reject", |
| 401 | "Connection suspended", |
| 402 | "Connection resumed", |
| 403 | "Data received", |
| 404 | "Data sent", |
| 405 | |
| 406 | "Timer", |
| 407 | |
| 408 | "Start", |
| 409 | "Stop", |
| 410 | }; |
| 411 | |
| 412 | /** |
| 413 | * States of the connection statemachine. |
| 414 | */ |
| 415 | enum conn_states { |
| 416 | /** |
| 417 | * Connection not assigned to any device, |
| 418 | * initial state, invalid |
| 419 | */ |
| 420 | CONN_STATE_INVALID, |
| 421 | |
| 422 | /** |
| 423 | * Userid assigned but not operating |
| 424 | */ |
| 425 | CONN_STATE_STOPPED, |
| 426 | |
| 427 | /** |
| 428 | * Connection registered, |
| 429 | * no connection request sent yet, |
| 430 | * no connection request received |
| 431 | */ |
| 432 | CONN_STATE_STARTWAIT, |
| 433 | |
| 434 | /** |
| 435 | * Connection registered and connection request sent, |
| 436 | * no acknowledge and no connection request received yet. |
| 437 | */ |
| 438 | CONN_STATE_SETUPWAIT, |
| 439 | |
| 440 | /** |
| 441 | * Connection up and running idle |
| 442 | */ |
| 443 | CONN_STATE_IDLE, |
| 444 | |
| 445 | /** |
| 446 | * Data sent, awaiting CONN_EVENT_TXDONE |
| 447 | */ |
| 448 | CONN_STATE_TX, |
| 449 | |
| 450 | /** |
| 451 | * Error during registration. |
| 452 | */ |
| 453 | CONN_STATE_REGERR, |
| 454 | |
| 455 | /** |
| 456 | * Error during registration. |
| 457 | */ |
| 458 | CONN_STATE_CONNERR, |
| 459 | |
| 460 | /** |
| 461 | * MUST be always the last element!! |
| 462 | */ |
| 463 | NR_CONN_STATES, |
| 464 | }; |
| 465 | |
| 466 | static const char *conn_state_names[] = { |
| 467 | "Invalid", |
| 468 | "Stopped", |
| 469 | "StartWait", |
| 470 | "SetupWait", |
| 471 | "Idle", |
| 472 | "TX", |
| 473 | "Terminating", |
| 474 | "Registration error", |
| 475 | "Connect error", |
| 476 | }; |
| 477 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /** |
| 480 | * Debug Facility Stuff |
| 481 | */ |
| 482 | static debug_info_t *iucv_dbf_setup = NULL; |
| 483 | static debug_info_t *iucv_dbf_data = NULL; |
| 484 | static debug_info_t *iucv_dbf_trace = NULL; |
| 485 | |
| 486 | DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf); |
| 487 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 488 | static void iucv_unregister_dbf_views(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { |
Markus Elfring | b646c08 | 2015-01-16 14:05:46 +0100 | [diff] [blame] | 490 | debug_unregister(iucv_dbf_setup); |
| 491 | debug_unregister(iucv_dbf_data); |
| 492 | debug_unregister(iucv_dbf_trace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 494 | static int iucv_register_dbf_views(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | { |
| 496 | iucv_dbf_setup = debug_register(IUCV_DBF_SETUP_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 497 | IUCV_DBF_SETUP_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | IUCV_DBF_SETUP_NR_AREAS, |
| 499 | IUCV_DBF_SETUP_LEN); |
| 500 | iucv_dbf_data = debug_register(IUCV_DBF_DATA_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 501 | IUCV_DBF_DATA_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | IUCV_DBF_DATA_NR_AREAS, |
| 503 | IUCV_DBF_DATA_LEN); |
| 504 | iucv_dbf_trace = debug_register(IUCV_DBF_TRACE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 505 | IUCV_DBF_TRACE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | IUCV_DBF_TRACE_NR_AREAS, |
| 507 | IUCV_DBF_TRACE_LEN); |
| 508 | |
| 509 | if ((iucv_dbf_setup == NULL) || (iucv_dbf_data == NULL) || |
| 510 | (iucv_dbf_trace == NULL)) { |
| 511 | iucv_unregister_dbf_views(); |
| 512 | return -ENOMEM; |
| 513 | } |
| 514 | debug_register_view(iucv_dbf_setup, &debug_hex_ascii_view); |
| 515 | debug_set_level(iucv_dbf_setup, IUCV_DBF_SETUP_LEVEL); |
| 516 | |
| 517 | debug_register_view(iucv_dbf_data, &debug_hex_ascii_view); |
| 518 | debug_set_level(iucv_dbf_data, IUCV_DBF_DATA_LEVEL); |
| 519 | |
| 520 | debug_register_view(iucv_dbf_trace, &debug_hex_ascii_view); |
| 521 | debug_set_level(iucv_dbf_trace, IUCV_DBF_TRACE_LEVEL); |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 526 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | * Callback-wrappers, called from lowlevel iucv layer. |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 528 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 530 | static void netiucv_callback_rx(struct iucv_path *path, |
| 531 | struct iucv_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 533 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | struct iucv_event ev; |
| 535 | |
| 536 | ev.conn = conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 537 | ev.data = msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | fsm_event(conn->fsm, CONN_EVENT_RX, &ev); |
| 539 | } |
| 540 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 541 | static void netiucv_callback_txdone(struct iucv_path *path, |
| 542 | struct iucv_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 544 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | struct iucv_event ev; |
| 546 | |
| 547 | ev.conn = conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 548 | ev.data = msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev); |
| 550 | } |
| 551 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 552 | static void netiucv_callback_connack(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 554 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 556 | fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 559 | static int netiucv_callback_connreq(struct iucv_path *path, |
| 560 | u8 ipvmid[8], u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 562 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | struct iucv_event ev; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 564 | static char tmp_user[9]; |
| 565 | static char tmp_udat[17]; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 566 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 568 | rc = -EINVAL; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 569 | memcpy(tmp_user, netiucv_printname(ipvmid, 8), 8); |
| 570 | memcpy(tmp_udat, ipuser, 16); |
| 571 | EBCASC(tmp_udat, 16); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 572 | read_lock_bh(&iucv_connection_rwlock); |
| 573 | list_for_each_entry(conn, &iucv_connection_list, list) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 574 | if (strncmp(ipvmid, conn->userid, 8) || |
| 575 | strncmp(ipuser, conn->userdata, 16)) |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 576 | continue; |
| 577 | /* Found a matching connection for this path. */ |
| 578 | conn->path = path; |
| 579 | ev.conn = conn; |
| 580 | ev.data = path; |
| 581 | fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev); |
| 582 | rc = 0; |
| 583 | } |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 584 | IUCV_DBF_TEXT_(setup, 2, "Connection requested for %s.%s\n", |
| 585 | tmp_user, netiucv_printname(tmp_udat, 16)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 586 | read_unlock_bh(&iucv_connection_rwlock); |
| 587 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 590 | static void netiucv_callback_connrej(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 592 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 594 | fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 597 | static void netiucv_callback_connsusp(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 599 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 601 | fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 604 | static void netiucv_callback_connres(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 606 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 608 | fsm_event(conn->fsm, CONN_EVENT_CONN_RES, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | /** |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 612 | * NOP action for statemachines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | */ |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 614 | static void netiucv_action_nop(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
| 616 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 617 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 618 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | * Actions of the connection statemachine |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 620 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 623 | * netiucv_unpack_skb |
| 624 | * @conn: The connection where this skb has been received. |
| 625 | * @pskb: The received skb. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 627 | * Unpack a just received skb and hand it over to upper layers. |
| 628 | * Helper function for conn_action_rx. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 630 | static void netiucv_unpack_skb(struct iucv_connection *conn, |
| 631 | struct sk_buff *pskb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
| 633 | struct net_device *dev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 634 | struct netiucv_priv *privptr = netdev_priv(dev); |
| 635 | u16 offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
| 637 | skb_put(pskb, NETIUCV_HDRLEN); |
| 638 | pskb->dev = dev; |
| 639 | pskb->ip_summed = CHECKSUM_NONE; |
| 640 | pskb->protocol = ntohs(ETH_P_IP); |
| 641 | |
| 642 | while (1) { |
| 643 | struct sk_buff *skb; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 644 | struct ll_header *header = (struct ll_header *) pskb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
| 646 | if (!header->next) |
| 647 | break; |
| 648 | |
| 649 | skb_pull(pskb, NETIUCV_HDRLEN); |
| 650 | header->next -= offset; |
| 651 | offset += header->next; |
| 652 | header->next -= NETIUCV_HDRLEN; |
| 653 | if (skb_tailroom(pskb) < header->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | IUCV_DBF_TEXT_(data, 2, "Illegal next field: %d > %d\n", |
| 655 | header->next, skb_tailroom(pskb)); |
| 656 | return; |
| 657 | } |
| 658 | skb_put(pskb, header->next); |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 659 | skb_reset_mac_header(pskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | skb = dev_alloc_skb(pskb->len); |
| 661 | if (!skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | IUCV_DBF_TEXT(data, 2, |
| 663 | "Out of memory in netiucv_unpack_skb\n"); |
| 664 | privptr->stats.rx_dropped++; |
| 665 | return; |
| 666 | } |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 667 | skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len), |
| 668 | pskb->len); |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 669 | skb_reset_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | skb->dev = pskb->dev; |
| 671 | skb->protocol = pskb->protocol; |
| 672 | pskb->ip_summed = CHECKSUM_UNNECESSARY; |
Julia Lawall | 9b3efc0 | 2007-12-10 17:17:37 -0800 | [diff] [blame] | 673 | privptr->stats.rx_packets++; |
| 674 | privptr->stats.rx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | /* |
| 676 | * Since receiving is always initiated from a tasklet (in iucv.c), |
| 677 | * we must use netif_rx_ni() instead of netif_rx() |
| 678 | */ |
| 679 | netif_rx_ni(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | skb_pull(pskb, header->next); |
| 681 | skb_put(pskb, NETIUCV_HDRLEN); |
| 682 | } |
| 683 | } |
| 684 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 685 | static void conn_action_rx(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 687 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 689 | struct iucv_message *msg = ev->data; |
| 690 | struct netiucv_priv *privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | int rc; |
| 692 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 693 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | if (!conn->netdev) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 696 | iucv_message_reject(conn->path, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 698 | "Received data for unlinked connection\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return; |
| 700 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 701 | if (msg->length > conn->max_buffsize) { |
| 702 | iucv_message_reject(conn->path, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | privptr->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | IUCV_DBF_TEXT_(data, 2, "msglen %d > max_buffsize %d\n", |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 705 | msg->length, conn->max_buffsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | return; |
| 707 | } |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 708 | conn->rx_buff->data = conn->rx_buff->head; |
| 709 | skb_reset_tail_pointer(conn->rx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | conn->rx_buff->len = 0; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 711 | rc = iucv_message_receive(conn->path, msg, 0, conn->rx_buff->data, |
| 712 | msg->length, NULL); |
| 713 | if (rc || msg->length < 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | privptr->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_receive\n", rc); |
| 716 | return; |
| 717 | } |
| 718 | netiucv_unpack_skb(conn, conn->rx_buff); |
| 719 | } |
| 720 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 721 | static void conn_action_txdone(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 723 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 725 | struct iucv_message *msg = ev->data; |
| 726 | struct iucv_message txmsg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | struct netiucv_priv *privptr = NULL; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 728 | u32 single_flag = msg->tag; |
| 729 | u32 txbytes = 0; |
| 730 | u32 txpackets = 0; |
| 731 | u32 stat_maxcq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | struct sk_buff *skb; |
| 733 | unsigned long saveflags; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 734 | struct ll_header header; |
| 735 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 737 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Ursula Braun | d239ae3 | 2013-12-16 09:44:51 +0100 | [diff] [blame] | 739 | if (!conn || !conn->netdev) { |
| 740 | IUCV_DBF_TEXT(data, 2, |
| 741 | "Send confirmation for unlinked connection\n"); |
| 742 | return; |
| 743 | } |
| 744 | privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | conn->prof.tx_pending--; |
| 746 | if (single_flag) { |
| 747 | if ((skb = skb_dequeue(&conn->commit_queue))) { |
| 748 | atomic_dec(&skb->users); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | if (privptr) { |
| 750 | privptr->stats.tx_packets++; |
| 751 | privptr->stats.tx_bytes += |
| 752 | (skb->len - NETIUCV_HDRLEN |
Ursula Braun | 998221c | 2009-11-12 21:46:30 +0000 | [diff] [blame] | 753 | - NETIUCV_HDRLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
Ursula Braun | 998221c | 2009-11-12 21:46:30 +0000 | [diff] [blame] | 755 | dev_kfree_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 758 | conn->tx_buff->data = conn->tx_buff->head; |
| 759 | skb_reset_tail_pointer(conn->tx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | conn->tx_buff->len = 0; |
| 761 | spin_lock_irqsave(&conn->collect_lock, saveflags); |
| 762 | while ((skb = skb_dequeue(&conn->collect_queue))) { |
| 763 | header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN; |
| 764 | memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, |
| 765 | NETIUCV_HDRLEN); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 766 | skb_copy_from_linear_data(skb, |
| 767 | skb_put(conn->tx_buff, skb->len), |
| 768 | skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | txbytes += skb->len; |
| 770 | txpackets++; |
| 771 | stat_maxcq++; |
| 772 | atomic_dec(&skb->users); |
| 773 | dev_kfree_skb_any(skb); |
| 774 | } |
| 775 | if (conn->collect_len > conn->prof.maxmulti) |
| 776 | conn->prof.maxmulti = conn->collect_len; |
| 777 | conn->collect_len = 0; |
| 778 | spin_unlock_irqrestore(&conn->collect_lock, saveflags); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 779 | if (conn->tx_buff->len == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | |
| 784 | header.next = 0; |
| 785 | memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
Aya Mahfouz | ee6edb9 | 2015-01-16 14:05:45 +0100 | [diff] [blame] | 786 | conn->prof.send_stamp = jiffies; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 787 | txmsg.class = 0; |
| 788 | txmsg.tag = 0; |
| 789 | rc = iucv_message_send(conn->path, &txmsg, 0, 0, |
| 790 | conn->tx_buff->data, conn->tx_buff->len); |
| 791 | conn->prof.doios_multi++; |
| 792 | conn->prof.txlen += conn->tx_buff->len; |
| 793 | conn->prof.tx_pending++; |
| 794 | if (conn->prof.tx_pending > conn->prof.tx_max_pending) |
| 795 | conn->prof.tx_max_pending = conn->prof.tx_pending; |
| 796 | if (rc) { |
| 797 | conn->prof.tx_pending--; |
| 798 | fsm_newstate(fi, CONN_STATE_IDLE); |
| 799 | if (privptr) |
| 800 | privptr->stats.tx_errors += txpackets; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 801 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc); |
| 802 | } else { |
| 803 | if (privptr) { |
| 804 | privptr->stats.tx_packets += txpackets; |
| 805 | privptr->stats.tx_bytes += txbytes; |
| 806 | } |
| 807 | if (stat_maxcq > conn->prof.maxcqueue) |
| 808 | conn->prof.maxcqueue = stat_maxcq; |
| 809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 812 | static void conn_action_connaccept(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 814 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 816 | struct iucv_path *path = ev->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 818 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 821 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 823 | conn->path = path; |
| 824 | path->msglim = NETIUCV_QUEUELEN_DEFAULT; |
| 825 | path->flags = 0; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 826 | rc = iucv_path_accept(path, &netiucv_handler, conn->userdata , conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | IUCV_DBF_TEXT_(setup, 2, "rc %d from iucv_accept", rc); |
| 829 | return; |
| 830 | } |
| 831 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 832 | netdev->tx_queue_len = conn->path->msglim; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev); |
| 834 | } |
| 835 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 836 | static void conn_action_connreject(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 838 | struct iucv_event *ev = arg; |
| 839 | struct iucv_path *path = ev->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 841 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 842 | iucv_path_sever(path, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 845 | static void conn_action_connack(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 847 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 849 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 851 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | fsm_deltimer(&conn->timer); |
| 853 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 854 | netdev->tx_queue_len = conn->path->msglim; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev); |
| 856 | } |
| 857 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 858 | static void conn_action_conntimsev(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 860 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 862 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | fsm_deltimer(&conn->timer); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 864 | iucv_path_sever(conn->path, conn->userdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 866 | } |
| 867 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 868 | static void conn_action_connsever(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 870 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 872 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 874 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
| 876 | fsm_deltimer(&conn->timer); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 877 | iucv_path_sever(conn->path, conn->userdata); |
| 878 | dev_info(privptr->dev, "The peer z/VM guest %s has closed the " |
| 879 | "connection\n", netiucv_printuser(conn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 881 | "conn_action_connsever: Remote dropped connection\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 883 | fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev); |
| 884 | } |
| 885 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 886 | static void conn_action_start(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 888 | struct iucv_connection *conn = arg; |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 889 | struct net_device *netdev = conn->netdev; |
| 890 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | int rc; |
| 892 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 893 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 895 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 897 | /* |
| 898 | * We must set the state before calling iucv_connect because the |
| 899 | * callback handler could be called at any point after the connection |
| 900 | * request is sent |
| 901 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
| 903 | fsm_newstate(fi, CONN_STATE_SETUPWAIT); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 904 | conn->path = iucv_path_alloc(NETIUCV_QUEUELEN_DEFAULT, 0, GFP_KERNEL); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 905 | IUCV_DBF_TEXT_(setup, 2, "%s: connecting to %s ...\n", |
| 906 | netdev->name, netiucv_printuser(conn)); |
| 907 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 908 | rc = iucv_path_connect(conn->path, &netiucv_handler, conn->userid, |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 909 | NULL, conn->userdata, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | switch (rc) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 911 | case 0: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 912 | netdev->tx_queue_len = conn->path->msglim; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 913 | fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC, |
| 914 | CONN_EVENT_TIMER, conn); |
| 915 | return; |
| 916 | case 11: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 917 | dev_warn(privptr->dev, |
| 918 | "The IUCV device failed to connect to z/VM guest %s\n", |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 919 | netiucv_printname(conn->userid, 8)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 920 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 921 | break; |
| 922 | case 12: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 923 | dev_warn(privptr->dev, |
| 924 | "The IUCV device failed to connect to the peer on z/VM" |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 925 | " guest %s\n", netiucv_printname(conn->userid, 8)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 926 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 927 | break; |
| 928 | case 13: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 929 | dev_err(privptr->dev, |
| 930 | "Connecting the IUCV device would exceed the maximum" |
| 931 | " number of IUCV connections\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 932 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 933 | break; |
| 934 | case 14: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 935 | dev_err(privptr->dev, |
| 936 | "z/VM guest %s has too many IUCV connections" |
| 937 | " to connect with the IUCV device\n", |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 938 | netiucv_printname(conn->userid, 8)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 939 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 940 | break; |
| 941 | case 15: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 942 | dev_err(privptr->dev, |
| 943 | "The IUCV device cannot connect to a z/VM guest with no" |
| 944 | " IUCV authorization\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 945 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 946 | break; |
| 947 | default: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 948 | dev_err(privptr->dev, |
| 949 | "Connecting the IUCV device failed with error %d\n", |
| 950 | rc); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 951 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 952 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | } |
| 954 | IUCV_DBF_TEXT_(setup, 5, "iucv_connect rc is %d\n", rc); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 955 | kfree(conn->path); |
| 956 | conn->path = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 959 | static void netiucv_purge_skb_queue(struct sk_buff_head *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | { |
| 961 | struct sk_buff *skb; |
| 962 | |
| 963 | while ((skb = skb_dequeue(q))) { |
| 964 | atomic_dec(&skb->users); |
| 965 | dev_kfree_skb_any(skb); |
| 966 | } |
| 967 | } |
| 968 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 969 | static void conn_action_stop(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 971 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | struct iucv_connection *conn = ev->conn; |
| 973 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 974 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 976 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
| 978 | fsm_deltimer(&conn->timer); |
| 979 | fsm_newstate(fi, CONN_STATE_STOPPED); |
| 980 | netiucv_purge_skb_queue(&conn->collect_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 981 | if (conn->path) { |
| 982 | IUCV_DBF_TEXT(trace, 5, "calling iucv_path_sever\n"); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 983 | iucv_path_sever(conn->path, conn->userdata); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 984 | kfree(conn->path); |
| 985 | conn->path = NULL; |
| 986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | netiucv_purge_skb_queue(&conn->commit_queue); |
| 988 | fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev); |
| 989 | } |
| 990 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 991 | static void conn_action_inval(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 993 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | struct net_device *netdev = conn->netdev; |
| 995 | |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 996 | IUCV_DBF_TEXT_(data, 2, "%s('%s'): conn_action_inval called\n", |
| 997 | netdev->name, conn->userid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | static const fsm_node conn_fsm[] = { |
| 1001 | { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval }, |
| 1002 | { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start }, |
| 1003 | |
| 1004 | { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop }, |
| 1005 | { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop }, |
| 1006 | { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop }, |
| 1007 | { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop }, |
| 1008 | { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop }, |
| 1009 | { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop }, |
| 1010 | { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop }, |
| 1011 | |
| 1012 | { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1013 | { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept }, |
| 1014 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept }, |
| 1015 | { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1016 | { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1017 | |
| 1018 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack }, |
| 1019 | { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev }, |
| 1020 | |
| 1021 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1022 | { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1023 | { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1024 | |
| 1025 | { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx }, |
| 1026 | { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx }, |
| 1027 | |
| 1028 | { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone }, |
| 1029 | { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone }, |
| 1030 | }; |
| 1031 | |
| 1032 | static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node); |
| 1033 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1034 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1035 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | * Actions for interface - statemachine. |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1037 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
| 1039 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1040 | * dev_action_start |
| 1041 | * @fi: An instance of an interface statemachine. |
| 1042 | * @event: The event, just happened. |
| 1043 | * @arg: Generic pointer, casted from struct net_device * upon call. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1045 | * Startup connection by sending CONN_EVENT_START to it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1047 | static void dev_action_start(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1049 | struct net_device *dev = arg; |
| 1050 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1052 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | fsm_newstate(fi, DEV_STATE_STARTWAIT); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1055 | fsm_event(privptr->conn->fsm, CONN_EVENT_START, privptr->conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * Shutdown connection by sending CONN_EVENT_STOP to it. |
| 1060 | * |
| 1061 | * @param fi An instance of an interface statemachine. |
| 1062 | * @param event The event, just happened. |
| 1063 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1064 | */ |
| 1065 | static void |
| 1066 | dev_action_stop(fsm_instance *fi, int event, void *arg) |
| 1067 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1068 | struct net_device *dev = arg; |
| 1069 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | struct iucv_event ev; |
| 1071 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1072 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
| 1074 | ev.conn = privptr->conn; |
| 1075 | |
| 1076 | fsm_newstate(fi, DEV_STATE_STOPWAIT); |
| 1077 | fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev); |
| 1078 | } |
| 1079 | |
| 1080 | /** |
| 1081 | * Called from connection statemachine |
| 1082 | * when a connection is up and running. |
| 1083 | * |
| 1084 | * @param fi An instance of an interface statemachine. |
| 1085 | * @param event The event, just happened. |
| 1086 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1087 | */ |
| 1088 | static void |
| 1089 | dev_action_connup(fsm_instance *fi, int event, void *arg) |
| 1090 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1091 | struct net_device *dev = arg; |
| 1092 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1094 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
| 1096 | switch (fsm_getstate(fi)) { |
| 1097 | case DEV_STATE_STARTWAIT: |
| 1098 | fsm_newstate(fi, DEV_STATE_RUNNING); |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 1099 | dev_info(privptr->dev, |
| 1100 | "The IUCV device has been connected" |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1101 | " successfully to %s\n", |
| 1102 | netiucv_printuser(privptr->conn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | IUCV_DBF_TEXT(setup, 3, |
| 1104 | "connection is up and running\n"); |
| 1105 | break; |
| 1106 | case DEV_STATE_STOPWAIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | IUCV_DBF_TEXT(data, 2, |
| 1108 | "dev_action_connup: in DEV_STATE_STOPWAIT\n"); |
| 1109 | break; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | /** |
| 1114 | * Called from connection statemachine |
| 1115 | * when a connection has been shutdown. |
| 1116 | * |
| 1117 | * @param fi An instance of an interface statemachine. |
| 1118 | * @param event The event, just happened. |
| 1119 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1120 | */ |
| 1121 | static void |
| 1122 | dev_action_conndown(fsm_instance *fi, int event, void *arg) |
| 1123 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1124 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
| 1126 | switch (fsm_getstate(fi)) { |
| 1127 | case DEV_STATE_RUNNING: |
| 1128 | fsm_newstate(fi, DEV_STATE_STARTWAIT); |
| 1129 | break; |
| 1130 | case DEV_STATE_STOPWAIT: |
| 1131 | fsm_newstate(fi, DEV_STATE_STOPPED); |
| 1132 | IUCV_DBF_TEXT(setup, 3, "connection is down\n"); |
| 1133 | break; |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | static const fsm_node dev_fsm[] = { |
| 1138 | { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start }, |
| 1139 | |
| 1140 | { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start }, |
| 1141 | { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown }, |
| 1142 | |
| 1143 | { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop }, |
| 1144 | { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup }, |
| 1145 | |
| 1146 | { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop }, |
| 1147 | { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown }, |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 1148 | { DEV_STATE_RUNNING, DEV_EVENT_CONUP, netiucv_action_nop }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | }; |
| 1150 | |
| 1151 | static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node); |
| 1152 | |
| 1153 | /** |
| 1154 | * Transmit a packet. |
| 1155 | * This is a helper function for netiucv_tx(). |
| 1156 | * |
| 1157 | * @param conn Connection to be used for sending. |
| 1158 | * @param skb Pointer to struct sk_buff of packet to send. |
| 1159 | * The linklevel header has already been set up |
| 1160 | * by netiucv_tx(). |
| 1161 | * |
| 1162 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1163 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1164 | static int netiucv_transmit_skb(struct iucv_connection *conn, |
| 1165 | struct sk_buff *skb) |
| 1166 | { |
| 1167 | struct iucv_message msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | unsigned long saveflags; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1169 | struct ll_header header; |
| 1170 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | |
| 1172 | if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) { |
| 1173 | int l = skb->len + NETIUCV_HDRLEN; |
| 1174 | |
| 1175 | spin_lock_irqsave(&conn->collect_lock, saveflags); |
| 1176 | if (conn->collect_len + l > |
| 1177 | (conn->max_buffsize - NETIUCV_HDRLEN)) { |
| 1178 | rc = -EBUSY; |
| 1179 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1180 | "EBUSY from netiucv_transmit_skb\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | } else { |
| 1182 | atomic_inc(&skb->users); |
| 1183 | skb_queue_tail(&conn->collect_queue, skb); |
| 1184 | conn->collect_len += l; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1185 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | } |
| 1187 | spin_unlock_irqrestore(&conn->collect_lock, saveflags); |
| 1188 | } else { |
| 1189 | struct sk_buff *nskb = skb; |
| 1190 | /** |
| 1191 | * Copy the skb to a new allocated skb in lowmem only if the |
| 1192 | * data is located above 2G in memory or tailroom is < 2. |
| 1193 | */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 1194 | unsigned long hi = ((unsigned long)(skb_tail_pointer(skb) + |
| 1195 | NETIUCV_HDRLEN)) >> 31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | int copied = 0; |
| 1197 | if (hi || (skb_tailroom(skb) < 2)) { |
| 1198 | nskb = alloc_skb(skb->len + NETIUCV_HDRLEN + |
| 1199 | NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA); |
| 1200 | if (!nskb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | IUCV_DBF_TEXT(data, 2, "alloc_skb failed\n"); |
| 1202 | rc = -ENOMEM; |
| 1203 | return rc; |
| 1204 | } else { |
| 1205 | skb_reserve(nskb, NETIUCV_HDRLEN); |
| 1206 | memcpy(skb_put(nskb, skb->len), |
| 1207 | skb->data, skb->len); |
| 1208 | } |
| 1209 | copied = 1; |
| 1210 | } |
| 1211 | /** |
| 1212 | * skb now is below 2G and has enough room. Add headers. |
| 1213 | */ |
| 1214 | header.next = nskb->len + NETIUCV_HDRLEN; |
| 1215 | memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
| 1216 | header.next = 0; |
| 1217 | memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
| 1218 | |
| 1219 | fsm_newstate(conn->fsm, CONN_STATE_TX); |
Aya Mahfouz | ee6edb9 | 2015-01-16 14:05:45 +0100 | [diff] [blame] | 1220 | conn->prof.send_stamp = jiffies; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1221 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1222 | msg.tag = 1; |
| 1223 | msg.class = 0; |
| 1224 | rc = iucv_message_send(conn->path, &msg, 0, 0, |
| 1225 | nskb->data, nskb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | conn->prof.doios_single++; |
| 1227 | conn->prof.txlen += skb->len; |
| 1228 | conn->prof.tx_pending++; |
| 1229 | if (conn->prof.tx_pending > conn->prof.tx_max_pending) |
| 1230 | conn->prof.tx_max_pending = conn->prof.tx_pending; |
| 1231 | if (rc) { |
| 1232 | struct netiucv_priv *privptr; |
| 1233 | fsm_newstate(conn->fsm, CONN_STATE_IDLE); |
| 1234 | conn->prof.tx_pending--; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1235 | privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | if (privptr) |
| 1237 | privptr->stats.tx_errors++; |
| 1238 | if (copied) |
| 1239 | dev_kfree_skb(nskb); |
| 1240 | else { |
| 1241 | /** |
| 1242 | * Remove our headers. They get added |
| 1243 | * again on retransmit. |
| 1244 | */ |
| 1245 | skb_pull(skb, NETIUCV_HDRLEN); |
| 1246 | skb_trim(skb, skb->len - NETIUCV_HDRLEN); |
| 1247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc); |
| 1249 | } else { |
| 1250 | if (copied) |
| 1251 | dev_kfree_skb(skb); |
| 1252 | atomic_inc(&nskb->users); |
| 1253 | skb_queue_tail(&conn->commit_queue, nskb); |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | return rc; |
| 1258 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1259 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1260 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | * Interface API for upper network layers |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1262 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
| 1264 | /** |
| 1265 | * Open an interface. |
| 1266 | * Called from generic network layer when ifconfig up is run. |
| 1267 | * |
| 1268 | * @param dev Pointer to interface struct. |
| 1269 | * |
| 1270 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1271 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1272 | static int netiucv_open(struct net_device *dev) |
| 1273 | { |
| 1274 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1275 | |
| 1276 | fsm_event(priv->fsm, DEV_EVENT_START, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | /** |
| 1281 | * Close an interface. |
| 1282 | * Called from generic network layer when ifconfig down is run. |
| 1283 | * |
| 1284 | * @param dev Pointer to interface struct. |
| 1285 | * |
| 1286 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1287 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1288 | static int netiucv_close(struct net_device *dev) |
| 1289 | { |
| 1290 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1291 | |
| 1292 | fsm_event(priv->fsm, DEV_EVENT_STOP, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | return 0; |
| 1294 | } |
| 1295 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1296 | static int netiucv_pm_prepare(struct device *dev) |
| 1297 | { |
| 1298 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | static void netiucv_pm_complete(struct device *dev) |
| 1303 | { |
| 1304 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1305 | return; |
| 1306 | } |
| 1307 | |
| 1308 | /** |
| 1309 | * netiucv_pm_freeze() - Freeze PM callback |
| 1310 | * @dev: netiucv device |
| 1311 | * |
| 1312 | * close open netiucv interfaces |
| 1313 | */ |
| 1314 | static int netiucv_pm_freeze(struct device *dev) |
| 1315 | { |
Martin Schwidefsky | 4f0076f | 2009-06-22 12:08:19 +0200 | [diff] [blame] | 1316 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1317 | struct net_device *ndev = NULL; |
| 1318 | int rc = 0; |
| 1319 | |
| 1320 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1321 | if (priv && priv->conn) |
| 1322 | ndev = priv->conn->netdev; |
| 1323 | if (!ndev) |
| 1324 | goto out; |
| 1325 | netif_device_detach(ndev); |
| 1326 | priv->pm_state = fsm_getstate(priv->fsm); |
| 1327 | rc = netiucv_close(ndev); |
| 1328 | out: |
| 1329 | return rc; |
| 1330 | } |
| 1331 | |
| 1332 | /** |
| 1333 | * netiucv_pm_restore_thaw() - Thaw and restore PM callback |
| 1334 | * @dev: netiucv device |
| 1335 | * |
| 1336 | * re-open netiucv interfaces closed during freeze |
| 1337 | */ |
| 1338 | static int netiucv_pm_restore_thaw(struct device *dev) |
| 1339 | { |
Martin Schwidefsky | 4f0076f | 2009-06-22 12:08:19 +0200 | [diff] [blame] | 1340 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1341 | struct net_device *ndev = NULL; |
| 1342 | int rc = 0; |
| 1343 | |
| 1344 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1345 | if (priv && priv->conn) |
| 1346 | ndev = priv->conn->netdev; |
| 1347 | if (!ndev) |
| 1348 | goto out; |
| 1349 | switch (priv->pm_state) { |
| 1350 | case DEV_STATE_RUNNING: |
| 1351 | case DEV_STATE_STARTWAIT: |
| 1352 | rc = netiucv_open(ndev); |
| 1353 | break; |
| 1354 | default: |
| 1355 | break; |
| 1356 | } |
| 1357 | netif_device_attach(ndev); |
| 1358 | out: |
| 1359 | return rc; |
| 1360 | } |
| 1361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | /** |
| 1363 | * Start transmission of a packet. |
| 1364 | * Called from generic network device layer. |
| 1365 | * |
| 1366 | * @param skb Pointer to buffer containing the packet. |
| 1367 | * @param dev Pointer to interface struct. |
| 1368 | * |
| 1369 | * @return 0 if packet consumed, !0 if packet rejected. |
| 1370 | * Note: If we return !0, then the packet is free'd by |
| 1371 | * the generic network layer. |
| 1372 | */ |
| 1373 | static int netiucv_tx(struct sk_buff *skb, struct net_device *dev) |
| 1374 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1375 | struct netiucv_priv *privptr = netdev_priv(dev); |
| 1376 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1378 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | /** |
| 1380 | * Some sanity checks ... |
| 1381 | */ |
| 1382 | if (skb == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | IUCV_DBF_TEXT(data, 2, "netiucv_tx: skb is NULL\n"); |
| 1384 | privptr->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1385 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | } |
| 1387 | if (skb_headroom(skb) < NETIUCV_HDRLEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | IUCV_DBF_TEXT(data, 2, |
| 1389 | "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n"); |
| 1390 | dev_kfree_skb(skb); |
| 1391 | privptr->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1392 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /** |
| 1396 | * If connection is not running, try to restart it |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1397 | * and throw away packet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | */ |
| 1399 | if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | dev_kfree_skb(skb); |
| 1401 | privptr->stats.tx_dropped++; |
| 1402 | privptr->stats.tx_errors++; |
| 1403 | privptr->stats.tx_carrier_errors++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1404 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | if (netiucv_test_and_set_busy(dev)) { |
| 1408 | IUCV_DBF_TEXT(data, 2, "EBUSY from netiucv_tx\n"); |
Ursula Braun | 4e584d6 | 2009-03-24 03:27:45 +0000 | [diff] [blame] | 1409 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | } |
| 1411 | dev->trans_start = jiffies; |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1412 | rc = netiucv_transmit_skb(privptr->conn, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | netiucv_clear_busy(dev); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1414 | return rc ? NETDEV_TX_BUSY : NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1418 | * netiucv_stats |
| 1419 | * @dev: Pointer to interface struct. |
| 1420 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | * Returns interface statistics of a device. |
| 1422 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1423 | * Returns pointer to stats struct of this interface. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1425 | static struct net_device_stats *netiucv_stats (struct net_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1427 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1428 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1429 | IUCV_DBF_TEXT(trace, 5, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1430 | return &priv->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1434 | * netiucv_change_mtu |
| 1435 | * @dev: Pointer to interface struct. |
| 1436 | * @new_mtu: The new MTU to use for this interface. |
| 1437 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | * Sets MTU of an interface. |
| 1439 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1440 | * Returns 0 on success, -EINVAL if MTU is out of valid range. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | * (valid range is 576 .. NETIUCV_MTU_MAX). |
| 1442 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1443 | static int netiucv_change_mtu(struct net_device * dev, int new_mtu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1445 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1446 | if (new_mtu < 576 || new_mtu > NETIUCV_MTU_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | IUCV_DBF_TEXT(setup, 2, "given MTU out of valid range\n"); |
| 1448 | return -EINVAL; |
| 1449 | } |
| 1450 | dev->mtu = new_mtu; |
| 1451 | return 0; |
| 1452 | } |
| 1453 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1454 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | * attributes in sysfs |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1456 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1458 | static ssize_t user_show(struct device *dev, struct device_attribute *attr, |
| 1459 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1461 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1463 | IUCV_DBF_TEXT(trace, 5, __func__); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1464 | return sprintf(buf, "%s\n", netiucv_printuser(priv->conn)); |
| 1465 | } |
| 1466 | |
| 1467 | static int netiucv_check_user(const char *buf, size_t count, char *username, |
| 1468 | char *userdata) |
| 1469 | { |
| 1470 | const char *p; |
| 1471 | int i; |
| 1472 | |
| 1473 | p = strchr(buf, '.'); |
| 1474 | if ((p && ((count > 26) || |
| 1475 | ((p - buf) > 8) || |
| 1476 | (buf + count - p > 18))) || |
| 1477 | (!p && (count > 9))) { |
| 1478 | IUCV_DBF_TEXT(setup, 2, "conn_write: too long\n"); |
| 1479 | return -EINVAL; |
| 1480 | } |
| 1481 | |
| 1482 | for (i = 0, p = buf; i < 8 && *p && *p != '.'; i++, p++) { |
| 1483 | if (isalnum(*p) || *p == '$') { |
| 1484 | username[i] = toupper(*p); |
| 1485 | continue; |
| 1486 | } |
| 1487 | if (*p == '\n') |
| 1488 | /* trailing lf, grr */ |
| 1489 | break; |
| 1490 | IUCV_DBF_TEXT_(setup, 2, |
| 1491 | "conn_write: invalid character %02x\n", *p); |
| 1492 | return -EINVAL; |
| 1493 | } |
| 1494 | while (i < 8) |
| 1495 | username[i++] = ' '; |
| 1496 | username[8] = '\0'; |
| 1497 | |
| 1498 | if (*p == '.') { |
| 1499 | p++; |
| 1500 | for (i = 0; i < 16 && *p; i++, p++) { |
| 1501 | if (*p == '\n') |
| 1502 | break; |
| 1503 | userdata[i] = toupper(*p); |
| 1504 | } |
| 1505 | while (i > 0 && i < 16) |
| 1506 | userdata[i++] = ' '; |
| 1507 | } else |
| 1508 | memcpy(userdata, iucvMagic_ascii, 16); |
| 1509 | userdata[16] = '\0'; |
| 1510 | ASCEBC(userdata, 16); |
| 1511 | |
| 1512 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1515 | static ssize_t user_write(struct device *dev, struct device_attribute *attr, |
| 1516 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1518 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | struct net_device *ndev = priv->conn->netdev; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1520 | char username[9]; |
| 1521 | char userdata[17]; |
| 1522 | int rc; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1523 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1525 | IUCV_DBF_TEXT(trace, 3, __func__); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1526 | rc = netiucv_check_user(buf, count, username, userdata); |
| 1527 | if (rc) |
| 1528 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1530 | if (memcmp(username, priv->conn->userid, 9) && |
| 1531 | (ndev->flags & (IFF_UP | IFF_RUNNING))) { |
| 1532 | /* username changed while the interface is active. */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1533 | IUCV_DBF_TEXT(setup, 2, "user_write: device active\n"); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 1534 | return -EPERM; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1535 | } |
| 1536 | read_lock_bh(&iucv_connection_rwlock); |
| 1537 | list_for_each_entry(cp, &iucv_connection_list, list) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1538 | if (!strncmp(username, cp->userid, 9) && |
| 1539 | !strncmp(userdata, cp->userdata, 17) && cp->netdev != ndev) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1540 | read_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1541 | IUCV_DBF_TEXT_(setup, 2, "user_write: Connection to %s " |
| 1542 | "already exists\n", netiucv_printuser(cp)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1543 | return -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | } |
| 1545 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1546 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | memcpy(priv->conn->userid, username, 9); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1548 | memcpy(priv->conn->userdata, userdata, 17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | static DEVICE_ATTR(user, 0644, user_show, user_write); |
| 1553 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1554 | static ssize_t buffer_show (struct device *dev, struct device_attribute *attr, |
| 1555 | char *buf) |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1556 | { |
| 1557 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1559 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | return sprintf(buf, "%d\n", priv->conn->max_buffsize); |
| 1561 | } |
| 1562 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1563 | static ssize_t buffer_write (struct device *dev, struct device_attribute *attr, |
| 1564 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1566 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | struct net_device *ndev = priv->conn->netdev; |
| 1568 | char *e; |
| 1569 | int bs1; |
| 1570 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1571 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | if (count >= 39) |
| 1573 | return -EINVAL; |
| 1574 | |
| 1575 | bs1 = simple_strtoul(buf, &e, 0); |
| 1576 | |
| 1577 | if (e && (!isspace(*e))) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1578 | IUCV_DBF_TEXT_(setup, 2, "buffer_write: invalid char %02x\n", |
| 1579 | *e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | return -EINVAL; |
| 1581 | } |
| 1582 | if (bs1 > NETIUCV_BUFSIZE_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | IUCV_DBF_TEXT_(setup, 2, |
| 1584 | "buffer_write: buffer size %d too large\n", |
| 1585 | bs1); |
| 1586 | return -EINVAL; |
| 1587 | } |
| 1588 | if ((ndev->flags & IFF_RUNNING) && |
| 1589 | (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | IUCV_DBF_TEXT_(setup, 2, |
| 1591 | "buffer_write: buffer size %d too small\n", |
| 1592 | bs1); |
| 1593 | return -EINVAL; |
| 1594 | } |
| 1595 | if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | IUCV_DBF_TEXT_(setup, 2, |
| 1597 | "buffer_write: buffer size %d too small\n", |
| 1598 | bs1); |
| 1599 | return -EINVAL; |
| 1600 | } |
| 1601 | |
| 1602 | priv->conn->max_buffsize = bs1; |
| 1603 | if (!(ndev->flags & IFF_RUNNING)) |
| 1604 | ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN; |
| 1605 | |
| 1606 | return count; |
| 1607 | |
| 1608 | } |
| 1609 | |
| 1610 | static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write); |
| 1611 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1612 | static ssize_t dev_fsm_show (struct device *dev, struct device_attribute *attr, |
| 1613 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1615 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1617 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm)); |
| 1619 | } |
| 1620 | |
| 1621 | static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL); |
| 1622 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1623 | static ssize_t conn_fsm_show (struct device *dev, |
| 1624 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1626 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1628 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm)); |
| 1630 | } |
| 1631 | |
| 1632 | static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL); |
| 1633 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1634 | static ssize_t maxmulti_show (struct device *dev, |
| 1635 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1637 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1639 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti); |
| 1641 | } |
| 1642 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1643 | static ssize_t maxmulti_write (struct device *dev, |
| 1644 | struct device_attribute *attr, |
| 1645 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1647 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1649 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | priv->conn->prof.maxmulti = 0; |
| 1651 | return count; |
| 1652 | } |
| 1653 | |
| 1654 | static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write); |
| 1655 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1656 | static ssize_t maxcq_show (struct device *dev, struct device_attribute *attr, |
| 1657 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1659 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1661 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue); |
| 1663 | } |
| 1664 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1665 | static ssize_t maxcq_write (struct device *dev, struct device_attribute *attr, |
| 1666 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1668 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1669 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1670 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | priv->conn->prof.maxcqueue = 0; |
| 1672 | return count; |
| 1673 | } |
| 1674 | |
| 1675 | static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write); |
| 1676 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1677 | static ssize_t sdoio_show (struct device *dev, struct device_attribute *attr, |
| 1678 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1680 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1682 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | return sprintf(buf, "%ld\n", priv->conn->prof.doios_single); |
| 1684 | } |
| 1685 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1686 | static ssize_t sdoio_write (struct device *dev, struct device_attribute *attr, |
| 1687 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1689 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1690 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1691 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | priv->conn->prof.doios_single = 0; |
| 1693 | return count; |
| 1694 | } |
| 1695 | |
| 1696 | static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write); |
| 1697 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1698 | static ssize_t mdoio_show (struct device *dev, struct device_attribute *attr, |
| 1699 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1701 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1703 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi); |
| 1705 | } |
| 1706 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1707 | static ssize_t mdoio_write (struct device *dev, struct device_attribute *attr, |
| 1708 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1710 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1711 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1712 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | priv->conn->prof.doios_multi = 0; |
| 1714 | return count; |
| 1715 | } |
| 1716 | |
| 1717 | static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write); |
| 1718 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1719 | static ssize_t txlen_show (struct device *dev, struct device_attribute *attr, |
| 1720 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1722 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1724 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | return sprintf(buf, "%ld\n", priv->conn->prof.txlen); |
| 1726 | } |
| 1727 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1728 | static ssize_t txlen_write (struct device *dev, struct device_attribute *attr, |
| 1729 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1731 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1732 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1733 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | priv->conn->prof.txlen = 0; |
| 1735 | return count; |
| 1736 | } |
| 1737 | |
| 1738 | static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write); |
| 1739 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1740 | static ssize_t txtime_show (struct device *dev, struct device_attribute *attr, |
| 1741 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1743 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1745 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_time); |
| 1747 | } |
| 1748 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1749 | static ssize_t txtime_write (struct device *dev, struct device_attribute *attr, |
| 1750 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1752 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1753 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1754 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | priv->conn->prof.tx_time = 0; |
| 1756 | return count; |
| 1757 | } |
| 1758 | |
| 1759 | static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write); |
| 1760 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1761 | static ssize_t txpend_show (struct device *dev, struct device_attribute *attr, |
| 1762 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1764 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1766 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending); |
| 1768 | } |
| 1769 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1770 | static ssize_t txpend_write (struct device *dev, struct device_attribute *attr, |
| 1771 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1773 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1775 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | priv->conn->prof.tx_pending = 0; |
| 1777 | return count; |
| 1778 | } |
| 1779 | |
| 1780 | static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write); |
| 1781 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1782 | static ssize_t txmpnd_show (struct device *dev, struct device_attribute *attr, |
| 1783 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1785 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1787 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending); |
| 1789 | } |
| 1790 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1791 | static ssize_t txmpnd_write (struct device *dev, struct device_attribute *attr, |
| 1792 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1794 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1796 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | priv->conn->prof.tx_max_pending = 0; |
| 1798 | return count; |
| 1799 | } |
| 1800 | |
| 1801 | static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write); |
| 1802 | |
| 1803 | static struct attribute *netiucv_attrs[] = { |
| 1804 | &dev_attr_buffer.attr, |
| 1805 | &dev_attr_user.attr, |
| 1806 | NULL, |
| 1807 | }; |
| 1808 | |
| 1809 | static struct attribute_group netiucv_attr_group = { |
| 1810 | .attrs = netiucv_attrs, |
| 1811 | }; |
| 1812 | |
| 1813 | static struct attribute *netiucv_stat_attrs[] = { |
| 1814 | &dev_attr_device_fsm_state.attr, |
| 1815 | &dev_attr_connection_fsm_state.attr, |
| 1816 | &dev_attr_max_tx_buffer_used.attr, |
| 1817 | &dev_attr_max_chained_skbs.attr, |
| 1818 | &dev_attr_tx_single_write_ops.attr, |
| 1819 | &dev_attr_tx_multi_write_ops.attr, |
| 1820 | &dev_attr_netto_bytes.attr, |
| 1821 | &dev_attr_max_tx_io_time.attr, |
| 1822 | &dev_attr_tx_pending.attr, |
| 1823 | &dev_attr_tx_max_pending.attr, |
| 1824 | NULL, |
| 1825 | }; |
| 1826 | |
| 1827 | static struct attribute_group netiucv_stat_attr_group = { |
| 1828 | .name = "stats", |
| 1829 | .attrs = netiucv_stat_attrs, |
| 1830 | }; |
| 1831 | |
frank.blaschka@de.ibm.com | 0b94529 | 2012-07-24 22:34:28 +0000 | [diff] [blame] | 1832 | static const struct attribute_group *netiucv_attr_groups[] = { |
| 1833 | &netiucv_stat_attr_group, |
| 1834 | &netiucv_attr_group, |
| 1835 | NULL, |
| 1836 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1838 | static int netiucv_register_device(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1840 | struct netiucv_priv *priv = netdev_priv(ndev); |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 1841 | struct device *dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | int ret; |
| 1843 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1844 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | |
| 1846 | if (dev) { |
Cornelia Huck | 1bf5b28 | 2008-10-10 21:33:10 +0200 | [diff] [blame] | 1847 | dev_set_name(dev, "net%s", ndev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | dev->bus = &iucv_bus; |
| 1849 | dev->parent = iucv_root; |
frank.blaschka@de.ibm.com | 0b94529 | 2012-07-24 22:34:28 +0000 | [diff] [blame] | 1850 | dev->groups = netiucv_attr_groups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | /* |
| 1852 | * The release function could be called after the |
| 1853 | * module has been unloaded. It's _only_ task is to |
| 1854 | * free the struct. Therefore, we specify kfree() |
| 1855 | * directly here. (Probably a little bit obfuscating |
| 1856 | * but legitime ...). |
| 1857 | */ |
| 1858 | dev->release = (void (*)(struct device *))kfree; |
| 1859 | dev->driver = &netiucv_driver; |
| 1860 | } else |
| 1861 | return -ENOMEM; |
| 1862 | |
| 1863 | ret = device_register(dev); |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 1864 | if (ret) { |
| 1865 | put_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | return ret; |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 1867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | priv->dev = dev; |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1869 | dev_set_drvdata(dev, priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1873 | static void netiucv_unregister_device(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1875 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | device_unregister(dev); |
| 1877 | } |
| 1878 | |
| 1879 | /** |
| 1880 | * Allocate and initialize a new connection structure. |
| 1881 | * Add it to the list of netiucv connections; |
| 1882 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1883 | static struct iucv_connection *netiucv_new_connection(struct net_device *dev, |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1884 | char *username, |
| 1885 | char *userdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1887 | struct iucv_connection *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1889 | conn = kzalloc(sizeof(*conn), GFP_KERNEL); |
| 1890 | if (!conn) |
| 1891 | goto out; |
| 1892 | skb_queue_head_init(&conn->collect_queue); |
| 1893 | skb_queue_head_init(&conn->commit_queue); |
| 1894 | spin_lock_init(&conn->collect_lock); |
| 1895 | conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT; |
| 1896 | conn->netdev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1898 | conn->rx_buff = alloc_skb(conn->max_buffsize, GFP_KERNEL | GFP_DMA); |
| 1899 | if (!conn->rx_buff) |
| 1900 | goto out_conn; |
| 1901 | conn->tx_buff = alloc_skb(conn->max_buffsize, GFP_KERNEL | GFP_DMA); |
| 1902 | if (!conn->tx_buff) |
| 1903 | goto out_rx; |
| 1904 | conn->fsm = init_fsm("netiucvconn", conn_state_names, |
| 1905 | conn_event_names, NR_CONN_STATES, |
| 1906 | NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN, |
| 1907 | GFP_KERNEL); |
| 1908 | if (!conn->fsm) |
| 1909 | goto out_tx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1911 | fsm_settimer(conn->fsm, &conn->timer); |
| 1912 | fsm_newstate(conn->fsm, CONN_STATE_INVALID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1914 | if (userdata) |
| 1915 | memcpy(conn->userdata, userdata, 17); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1916 | if (username) { |
| 1917 | memcpy(conn->userid, username, 9); |
| 1918 | fsm_newstate(conn->fsm, CONN_STATE_STOPPED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1920 | |
| 1921 | write_lock_bh(&iucv_connection_rwlock); |
| 1922 | list_add_tail(&conn->list, &iucv_connection_list); |
| 1923 | write_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | return conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1925 | |
| 1926 | out_tx: |
| 1927 | kfree_skb(conn->tx_buff); |
| 1928 | out_rx: |
| 1929 | kfree_skb(conn->rx_buff); |
| 1930 | out_conn: |
| 1931 | kfree(conn); |
| 1932 | out: |
| 1933 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | /** |
| 1937 | * Release a connection structure and remove it from the |
| 1938 | * list of netiucv connections. |
| 1939 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1940 | static void netiucv_remove_connection(struct iucv_connection *conn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1942 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1943 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1944 | write_lock_bh(&iucv_connection_rwlock); |
| 1945 | list_del_init(&conn->list); |
| 1946 | write_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | 0be4ace | 2007-05-02 15:18:44 +0200 | [diff] [blame] | 1947 | fsm_deltimer(&conn->timer); |
| 1948 | netiucv_purge_skb_queue(&conn->collect_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1949 | if (conn->path) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1950 | iucv_path_sever(conn->path, conn->userdata); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1951 | kfree(conn->path); |
| 1952 | conn->path = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | } |
Ursula Braun | 0be4ace | 2007-05-02 15:18:44 +0200 | [diff] [blame] | 1954 | netiucv_purge_skb_queue(&conn->commit_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1955 | kfree_fsm(conn->fsm); |
| 1956 | kfree_skb(conn->rx_buff); |
| 1957 | kfree_skb(conn->tx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * Release everything of a net device. |
| 1962 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1963 | static void netiucv_free_netdevice(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1965 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1967 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | |
| 1969 | if (!dev) |
| 1970 | return; |
| 1971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | if (privptr) { |
| 1973 | if (privptr->conn) |
| 1974 | netiucv_remove_connection(privptr->conn); |
| 1975 | if (privptr->fsm) |
| 1976 | kfree_fsm(privptr->fsm); |
| 1977 | privptr->conn = NULL; privptr->fsm = NULL; |
| 1978 | /* privptr gets freed by free_netdev() */ |
| 1979 | } |
| 1980 | free_netdev(dev); |
| 1981 | } |
| 1982 | |
| 1983 | /** |
| 1984 | * Initialize a net device. (Called from kernel in alloc_netdev()) |
| 1985 | */ |
Frank Blaschka | 4edd73b | 2009-01-09 03:43:58 +0000 | [diff] [blame] | 1986 | static const struct net_device_ops netiucv_netdev_ops = { |
| 1987 | .ndo_open = netiucv_open, |
| 1988 | .ndo_stop = netiucv_close, |
| 1989 | .ndo_get_stats = netiucv_stats, |
| 1990 | .ndo_start_xmit = netiucv_tx, |
| 1991 | .ndo_change_mtu = netiucv_change_mtu, |
| 1992 | }; |
| 1993 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1994 | static void netiucv_setup_netdevice(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | dev->mtu = NETIUCV_MTU_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | dev->destructor = netiucv_free_netdevice; |
| 1998 | dev->hard_header_len = NETIUCV_HDRLEN; |
| 1999 | dev->addr_len = 0; |
| 2000 | dev->type = ARPHRD_SLIP; |
| 2001 | dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT; |
| 2002 | dev->flags = IFF_POINTOPOINT | IFF_NOARP; |
Frank Blaschka | 4edd73b | 2009-01-09 03:43:58 +0000 | [diff] [blame] | 2003 | dev->netdev_ops = &netiucv_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | /** |
| 2007 | * Allocate and initialize everything of a net device. |
| 2008 | */ |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2009 | static struct net_device *netiucv_init_netdevice(char *username, char *userdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | { |
| 2011 | struct netiucv_priv *privptr; |
| 2012 | struct net_device *dev; |
| 2013 | |
| 2014 | dev = alloc_netdev(sizeof(struct netiucv_priv), "iucv%d", |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 2015 | NET_NAME_UNKNOWN, netiucv_setup_netdevice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | if (!dev) |
| 2017 | return NULL; |
Benjamin Poirier | aaf9522 | 2013-06-13 09:09:47 -0400 | [diff] [blame] | 2018 | rtnl_lock(); |
Ursula Braun | 1d50356 | 2011-11-15 02:31:14 +0000 | [diff] [blame] | 2019 | if (dev_alloc_name(dev, dev->name) < 0) |
| 2020 | goto out_netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2022 | privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | privptr->fsm = init_fsm("netiucvdev", dev_state_names, |
| 2024 | dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS, |
| 2025 | dev_fsm, DEV_FSM_LEN, GFP_KERNEL); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2026 | if (!privptr->fsm) |
| 2027 | goto out_netdev; |
| 2028 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2029 | privptr->conn = netiucv_new_connection(dev, username, userdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | if (!privptr->conn) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_new_connection\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2032 | goto out_fsm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | } |
| 2034 | fsm_newstate(privptr->fsm, DEV_STATE_STOPPED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | return dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2036 | |
| 2037 | out_fsm: |
| 2038 | kfree_fsm(privptr->fsm); |
| 2039 | out_netdev: |
Benjamin Poirier | aaf9522 | 2013-06-13 09:09:47 -0400 | [diff] [blame] | 2040 | rtnl_unlock(); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2041 | free_netdev(dev); |
| 2042 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2045 | static ssize_t conn_write(struct device_driver *drv, |
| 2046 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | { |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2048 | char username[9]; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2049 | char userdata[17]; |
| 2050 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | struct net_device *dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2052 | struct netiucv_priv *priv; |
| 2053 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2055 | IUCV_DBF_TEXT(trace, 3, __func__); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2056 | rc = netiucv_check_user(buf, count, username, userdata); |
| 2057 | if (rc) |
| 2058 | return rc; |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2059 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2060 | read_lock_bh(&iucv_connection_rwlock); |
| 2061 | list_for_each_entry(cp, &iucv_connection_list, list) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2062 | if (!strncmp(username, cp->userid, 9) && |
| 2063 | !strncmp(userdata, cp->userdata, 17)) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2064 | read_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2065 | IUCV_DBF_TEXT_(setup, 2, "conn_write: Connection to %s " |
| 2066 | "already exists\n", netiucv_printuser(cp)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2067 | return -EEXIST; |
| 2068 | } |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2069 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2070 | read_unlock_bh(&iucv_connection_rwlock); |
| 2071 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2072 | dev = netiucv_init_netdevice(username, userdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | if (!dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_init_netdevice\n"); |
| 2075 | return -ENODEV; |
| 2076 | } |
| 2077 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2078 | rc = netiucv_register_device(dev); |
| 2079 | if (rc) { |
Benjamin Poirier | aaf9522 | 2013-06-13 09:09:47 -0400 | [diff] [blame] | 2080 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | IUCV_DBF_TEXT_(setup, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2082 | "ret %d from netiucv_register_device\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | goto out_free_ndev; |
| 2084 | } |
| 2085 | |
| 2086 | /* sysfs magic */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2087 | priv = netdev_priv(dev); |
| 2088 | SET_NETDEV_DEV(dev, priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | |
Benjamin Poirier | aaf9522 | 2013-06-13 09:09:47 -0400 | [diff] [blame] | 2090 | rc = register_netdevice(dev); |
| 2091 | rtnl_unlock(); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2092 | if (rc) |
| 2093 | goto out_unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2095 | dev_info(priv->dev, "The IUCV interface to %s has been established " |
| 2096 | "successfully\n", |
| 2097 | netiucv_printuser(priv->conn)); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | return count; |
| 2100 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2101 | out_unreg: |
| 2102 | netiucv_unregister_device(priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | out_free_ndev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | netiucv_free_netdevice(dev); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2105 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 2108 | static DRIVER_ATTR(connection, 0200, NULL, conn_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2110 | static ssize_t remove_write (struct device_driver *drv, |
| 2111 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2113 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | struct net_device *ndev; |
| 2115 | struct netiucv_priv *priv; |
| 2116 | struct device *dev; |
| 2117 | char name[IFNAMSIZ]; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2118 | const char *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | int i; |
| 2120 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2121 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | |
| 2123 | if (count >= IFNAMSIZ) |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 2124 | count = IFNAMSIZ - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2126 | for (i = 0, p = buf; i < count && *p; i++, p++) { |
| 2127 | if (*p == '\n' || *p == ' ') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | /* trailing lf, grr */ |
| 2129 | break; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2130 | name[i] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | } |
| 2132 | name[i] = '\0'; |
| 2133 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2134 | read_lock_bh(&iucv_connection_rwlock); |
| 2135 | list_for_each_entry(cp, &iucv_connection_list, list) { |
| 2136 | ndev = cp->netdev; |
| 2137 | priv = netdev_priv(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | dev = priv->dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2139 | if (strncmp(name, ndev->name, count)) |
| 2140 | continue; |
| 2141 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | if (ndev->flags & (IFF_UP | IFF_RUNNING)) { |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2143 | dev_warn(dev, "The IUCV device is connected" |
| 2144 | " to %s and cannot be removed\n", |
| 2145 | priv->conn->userid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | IUCV_DBF_TEXT(data, 2, "remove_write: still active\n"); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 2147 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | } |
| 2149 | unregister_netdev(ndev); |
| 2150 | netiucv_unregister_device(dev); |
| 2151 | return count; |
| 2152 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2153 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | IUCV_DBF_TEXT(data, 2, "remove_write: unknown device\n"); |
| 2155 | return -EINVAL; |
| 2156 | } |
| 2157 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 2158 | static DRIVER_ATTR(remove, 0200, NULL, remove_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2160 | static struct attribute * netiucv_drv_attrs[] = { |
| 2161 | &driver_attr_connection.attr, |
| 2162 | &driver_attr_remove.attr, |
| 2163 | NULL, |
| 2164 | }; |
| 2165 | |
| 2166 | static struct attribute_group netiucv_drv_attr_group = { |
| 2167 | .attrs = netiucv_drv_attrs, |
| 2168 | }; |
| 2169 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 2170 | static const struct attribute_group *netiucv_drv_attr_groups[] = { |
Cornelia Huck | 5b88feb | 2007-12-05 12:50:28 +0100 | [diff] [blame] | 2171 | &netiucv_drv_attr_group, |
| 2172 | NULL, |
| 2173 | }; |
| 2174 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2175 | static void netiucv_banner(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | { |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2177 | pr_info("driver initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2180 | static void __exit netiucv_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2182 | struct iucv_connection *cp; |
| 2183 | struct net_device *ndev; |
| 2184 | struct netiucv_priv *priv; |
| 2185 | struct device *dev; |
| 2186 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2187 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2188 | while (!list_empty(&iucv_connection_list)) { |
| 2189 | cp = list_entry(iucv_connection_list.next, |
| 2190 | struct iucv_connection, list); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2191 | ndev = cp->netdev; |
| 2192 | priv = netdev_priv(ndev); |
| 2193 | dev = priv->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | |
| 2195 | unregister_netdev(ndev); |
| 2196 | netiucv_unregister_device(dev); |
| 2197 | } |
| 2198 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2199 | device_unregister(netiucv_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | driver_unregister(&netiucv_driver); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2201 | iucv_unregister(&netiucv_handler, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | iucv_unregister_dbf_views(); |
| 2203 | |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2204 | pr_info("driver unloaded\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | return; |
| 2206 | } |
| 2207 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2208 | static int __init netiucv_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2210 | int rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2211 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2212 | rc = iucv_register_dbf_views(); |
| 2213 | if (rc) |
| 2214 | goto out; |
| 2215 | rc = iucv_register(&netiucv_handler, 1); |
| 2216 | if (rc) |
| 2217 | goto out_dbf; |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2218 | IUCV_DBF_TEXT(trace, 3, __func__); |
Cornelia Huck | 0a0a831 | 2008-04-24 10:15:28 +0200 | [diff] [blame] | 2219 | netiucv_driver.groups = netiucv_drv_attr_groups; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2220 | rc = driver_register(&netiucv_driver); |
| 2221 | if (rc) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2222 | IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_register\n", rc); |
| 2223 | goto out_iucv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | } |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2225 | /* establish dummy device */ |
| 2226 | netiucv_dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 2227 | if (!netiucv_dev) { |
| 2228 | rc = -ENOMEM; |
| 2229 | goto out_driver; |
| 2230 | } |
| 2231 | dev_set_name(netiucv_dev, "netiucv"); |
| 2232 | netiucv_dev->bus = &iucv_bus; |
| 2233 | netiucv_dev->parent = iucv_root; |
| 2234 | netiucv_dev->release = (void (*)(struct device *))kfree; |
| 2235 | netiucv_dev->driver = &netiucv_driver; |
| 2236 | rc = device_register(netiucv_dev); |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 2237 | if (rc) { |
| 2238 | put_device(netiucv_dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2239 | goto out_driver; |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 2240 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2241 | netiucv_banner(); |
| 2242 | return rc; |
| 2243 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2244 | out_driver: |
| 2245 | driver_unregister(&netiucv_driver); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2246 | out_iucv: |
| 2247 | iucv_unregister(&netiucv_handler, 1); |
| 2248 | out_dbf: |
| 2249 | iucv_unregister_dbf_views(); |
| 2250 | out: |
| 2251 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | module_init(netiucv_init); |
| 2255 | module_exit(netiucv_exit); |
| 2256 | MODULE_LICENSE("GPL"); |