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