Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/net/ctcm_main.c |
| 3 | * |
Frank Blaschka | b8a2d42 | 2009-06-16 10:30:32 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2001, 2009 |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 5 | * Author(s): |
| 6 | * Original CTC driver(s): |
| 7 | * Fritz Elfert (felfert@millenux.com) |
| 8 | * Dieter Wellerdiek (wel@de.ibm.com) |
| 9 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 10 | * Denis Joseph Barrow (barrow_dj@yahoo.com) |
| 11 | * Jochen Roehrig (roehrig@de.ibm.com) |
| 12 | * Cornelia Huck <cornelia.huck@de.ibm.com> |
| 13 | * MPC additions: |
| 14 | * Belinda Thompson (belindat@us.ibm.com) |
| 15 | * Andy Richter (richtera@us.ibm.com) |
| 16 | * Revived by: |
| 17 | * Peter Tiedemann (ptiedem@de.ibm.com) |
| 18 | */ |
| 19 | |
| 20 | #undef DEBUG |
| 21 | #undef DEBUGDATA |
| 22 | #undef DEBUGCCW |
| 23 | |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 24 | #define KMSG_COMPONENT "ctcm" |
| 25 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 26 | |
Heiko Carstens | 85b81cd | 2011-01-05 12:47:37 +0100 | [diff] [blame] | 27 | #include <linux/kernel_stat.h> |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/errno.h> |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/interrupt.h> |
| 35 | #include <linux/timer.h> |
| 36 | #include <linux/bitops.h> |
| 37 | |
| 38 | #include <linux/signal.h> |
| 39 | #include <linux/string.h> |
| 40 | |
| 41 | #include <linux/ip.h> |
| 42 | #include <linux/if_arp.h> |
| 43 | #include <linux/tcp.h> |
| 44 | #include <linux/skbuff.h> |
| 45 | #include <linux/ctype.h> |
| 46 | #include <net/dst.h> |
| 47 | |
| 48 | #include <linux/io.h> |
| 49 | #include <asm/ccwdev.h> |
| 50 | #include <asm/ccwgroup.h> |
| 51 | #include <linux/uaccess.h> |
| 52 | |
| 53 | #include <asm/idals.h> |
| 54 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 55 | #include "ctcm_fsms.h" |
| 56 | #include "ctcm_main.h" |
| 57 | |
| 58 | /* Some common global variables */ |
| 59 | |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 60 | /** |
| 61 | * The root device for ctcm group devices |
| 62 | */ |
| 63 | static struct device *ctcm_root_dev; |
| 64 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 65 | /* |
| 66 | * Linked list of all detected channels. |
| 67 | */ |
| 68 | struct channel *channels; |
| 69 | |
| 70 | /** |
| 71 | * Unpack a just received skb and hand it over to |
| 72 | * upper layers. |
| 73 | * |
| 74 | * ch The channel where this skb has been received. |
| 75 | * pskb The received skb. |
| 76 | */ |
| 77 | void ctcm_unpack_skb(struct channel *ch, struct sk_buff *pskb) |
| 78 | { |
| 79 | struct net_device *dev = ch->netdev; |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 80 | struct ctcm_priv *priv = dev->ml_priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 81 | __u16 len = *((__u16 *) pskb->data); |
| 82 | |
| 83 | skb_put(pskb, 2 + LL_HEADER_LENGTH); |
| 84 | skb_pull(pskb, 2); |
| 85 | pskb->dev = dev; |
| 86 | pskb->ip_summed = CHECKSUM_UNNECESSARY; |
| 87 | while (len > 0) { |
| 88 | struct sk_buff *skb; |
| 89 | int skblen; |
| 90 | struct ll_header *header = (struct ll_header *)pskb->data; |
| 91 | |
| 92 | skb_pull(pskb, LL_HEADER_LENGTH); |
| 93 | if ((ch->protocol == CTCM_PROTO_S390) && |
| 94 | (header->type != ETH_P_IP)) { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 95 | if (!(ch->logflags & LOG_FLAG_ILLEGALPKT)) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 96 | ch->logflags |= LOG_FLAG_ILLEGALPKT; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 97 | /* |
| 98 | * Check packet type only if we stick strictly |
| 99 | * to S/390's protocol of OS390. This only |
| 100 | * supports IP. Otherwise allow any packet |
| 101 | * type. |
| 102 | */ |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 103 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 104 | "%s(%s): Illegal packet type 0x%04x" |
| 105 | " - dropping", |
| 106 | CTCM_FUNTAIL, dev->name, header->type); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 107 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 108 | priv->stats.rx_dropped++; |
| 109 | priv->stats.rx_frame_errors++; |
| 110 | return; |
| 111 | } |
| 112 | pskb->protocol = ntohs(header->type); |
Roel Kluin | fb8585f | 2009-03-24 03:27:48 +0000 | [diff] [blame] | 113 | if ((header->length <= LL_HEADER_LENGTH) || |
| 114 | (len <= LL_HEADER_LENGTH)) { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 115 | if (!(ch->logflags & LOG_FLAG_ILLEGALSIZE)) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 116 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 117 | "%s(%s): Illegal packet size %d(%d,%d)" |
| 118 | "- dropping", |
| 119 | CTCM_FUNTAIL, dev->name, |
| 120 | header->length, dev->mtu, len); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 121 | ch->logflags |= LOG_FLAG_ILLEGALSIZE; |
| 122 | } |
| 123 | |
| 124 | priv->stats.rx_dropped++; |
| 125 | priv->stats.rx_length_errors++; |
| 126 | return; |
| 127 | } |
| 128 | header->length -= LL_HEADER_LENGTH; |
| 129 | len -= LL_HEADER_LENGTH; |
| 130 | if ((header->length > skb_tailroom(pskb)) || |
| 131 | (header->length > len)) { |
| 132 | if (!(ch->logflags & LOG_FLAG_OVERRUN)) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 133 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 134 | "%s(%s): Packet size %d (overrun)" |
| 135 | " - dropping", CTCM_FUNTAIL, |
| 136 | dev->name, header->length); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 137 | ch->logflags |= LOG_FLAG_OVERRUN; |
| 138 | } |
| 139 | |
| 140 | priv->stats.rx_dropped++; |
| 141 | priv->stats.rx_length_errors++; |
| 142 | return; |
| 143 | } |
| 144 | skb_put(pskb, header->length); |
| 145 | skb_reset_mac_header(pskb); |
| 146 | len -= header->length; |
| 147 | skb = dev_alloc_skb(pskb->len); |
| 148 | if (!skb) { |
| 149 | if (!(ch->logflags & LOG_FLAG_NOMEM)) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 150 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 151 | "%s(%s): MEMORY allocation error", |
| 152 | CTCM_FUNTAIL, dev->name); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 153 | ch->logflags |= LOG_FLAG_NOMEM; |
| 154 | } |
| 155 | priv->stats.rx_dropped++; |
| 156 | return; |
| 157 | } |
| 158 | skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len), |
| 159 | pskb->len); |
| 160 | skb_reset_mac_header(skb); |
| 161 | skb->dev = pskb->dev; |
| 162 | skb->protocol = pskb->protocol; |
| 163 | pskb->ip_summed = CHECKSUM_UNNECESSARY; |
| 164 | skblen = skb->len; |
| 165 | /* |
| 166 | * reset logflags |
| 167 | */ |
| 168 | ch->logflags = 0; |
| 169 | priv->stats.rx_packets++; |
| 170 | priv->stats.rx_bytes += skblen; |
| 171 | netif_rx_ni(skb); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 172 | if (len > 0) { |
| 173 | skb_pull(pskb, header->length); |
| 174 | if (skb_tailroom(pskb) < LL_HEADER_LENGTH) { |
Joel A. Fowler | e2fc8cb | 2009-03-24 03:27:49 +0000 | [diff] [blame] | 175 | CTCM_DBF_DEV_NAME(TRACE, dev, |
| 176 | "Overrun in ctcm_unpack_skb"); |
| 177 | ch->logflags |= LOG_FLAG_OVERRUN; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | skb_put(pskb, LL_HEADER_LENGTH); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Release a specific channel in the channel list. |
| 187 | * |
| 188 | * ch Pointer to channel struct to be released. |
| 189 | */ |
| 190 | static void channel_free(struct channel *ch) |
| 191 | { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 192 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s)", CTCM_FUNTAIL, ch->id); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 193 | ch->flags &= ~CHANNEL_FLAGS_INUSE; |
| 194 | fsm_newstate(ch->fsm, CTC_STATE_IDLE); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Remove a specific channel in the channel list. |
| 199 | * |
| 200 | * ch Pointer to channel struct to be released. |
| 201 | */ |
| 202 | static void channel_remove(struct channel *ch) |
| 203 | { |
| 204 | struct channel **c = &channels; |
| 205 | char chid[CTCM_ID_SIZE+1]; |
| 206 | int ok = 0; |
| 207 | |
| 208 | if (ch == NULL) |
| 209 | return; |
| 210 | else |
| 211 | strncpy(chid, ch->id, CTCM_ID_SIZE); |
| 212 | |
| 213 | channel_free(ch); |
| 214 | while (*c) { |
| 215 | if (*c == ch) { |
| 216 | *c = ch->next; |
| 217 | fsm_deltimer(&ch->timer); |
| 218 | if (IS_MPC(ch)) |
| 219 | fsm_deltimer(&ch->sweep_timer); |
| 220 | |
| 221 | kfree_fsm(ch->fsm); |
| 222 | clear_normalized_cda(&ch->ccw[4]); |
| 223 | if (ch->trans_skb != NULL) { |
| 224 | clear_normalized_cda(&ch->ccw[1]); |
| 225 | dev_kfree_skb_any(ch->trans_skb); |
| 226 | } |
| 227 | if (IS_MPC(ch)) { |
| 228 | tasklet_kill(&ch->ch_tasklet); |
| 229 | tasklet_kill(&ch->ch_disc_tasklet); |
| 230 | kfree(ch->discontact_th); |
| 231 | } |
| 232 | kfree(ch->ccw); |
| 233 | kfree(ch->irb); |
| 234 | kfree(ch); |
| 235 | ok = 1; |
| 236 | break; |
| 237 | } |
| 238 | c = &((*c)->next); |
| 239 | } |
| 240 | |
| 241 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s) %s", CTCM_FUNTAIL, |
| 242 | chid, ok ? "OK" : "failed"); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Get a specific channel from the channel list. |
| 247 | * |
| 248 | * type Type of channel we are interested in. |
| 249 | * id Id of channel we are interested in. |
| 250 | * direction Direction we want to use this channel for. |
| 251 | * |
| 252 | * returns Pointer to a channel or NULL if no matching channel available. |
| 253 | */ |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 254 | static struct channel *channel_get(enum ctcm_channel_types type, |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 255 | char *id, int direction) |
| 256 | { |
| 257 | struct channel *ch = channels; |
| 258 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 259 | while (ch && (strncmp(ch->id, id, CTCM_ID_SIZE) || (ch->type != type))) |
| 260 | ch = ch->next; |
| 261 | if (!ch) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 262 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 263 | "%s(%d, %s, %d) not found in channel list\n", |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 264 | CTCM_FUNTAIL, type, id, direction); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 265 | } else { |
| 266 | if (ch->flags & CHANNEL_FLAGS_INUSE) |
| 267 | ch = NULL; |
| 268 | else { |
| 269 | ch->flags |= CHANNEL_FLAGS_INUSE; |
| 270 | ch->flags &= ~CHANNEL_FLAGS_RWMASK; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 271 | ch->flags |= (direction == CTCM_WRITE) |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 272 | ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ; |
| 273 | fsm_newstate(ch->fsm, CTC_STATE_STOPPED); |
| 274 | } |
| 275 | } |
| 276 | return ch; |
| 277 | } |
| 278 | |
| 279 | static long ctcm_check_irb_error(struct ccw_device *cdev, struct irb *irb) |
| 280 | { |
| 281 | if (!IS_ERR(irb)) |
| 282 | return 0; |
| 283 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 284 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_WARN, |
| 285 | "irb error %ld on device %s\n", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 286 | PTR_ERR(irb), dev_name(&cdev->dev)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 287 | |
| 288 | switch (PTR_ERR(irb)) { |
| 289 | case -EIO: |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 290 | dev_err(&cdev->dev, |
| 291 | "An I/O-error occurred on the CTCM device\n"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 292 | break; |
| 293 | case -ETIMEDOUT: |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 294 | dev_err(&cdev->dev, |
| 295 | "An adapter hardware operation timed out\n"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 296 | break; |
| 297 | default: |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 298 | dev_err(&cdev->dev, |
| 299 | "An error occurred on the adapter hardware\n"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 300 | } |
| 301 | return PTR_ERR(irb); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /** |
| 306 | * Check sense of a unit check. |
| 307 | * |
| 308 | * ch The channel, the sense code belongs to. |
| 309 | * sense The sense code to inspect. |
| 310 | */ |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 311 | static inline void ccw_unit_check(struct channel *ch, __u8 sense) |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 312 | { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 313 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG, |
| 314 | "%s(%s): %02x", |
| 315 | CTCM_FUNTAIL, ch->id, sense); |
| 316 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 317 | if (sense & SNS0_INTERVENTION_REQ) { |
| 318 | if (sense & 0x01) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 319 | if (ch->sense_rc != 0x01) { |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 320 | pr_notice( |
| 321 | "%s: The communication peer has " |
| 322 | "disconnected\n", ch->id); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 323 | ch->sense_rc = 0x01; |
| 324 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 325 | fsm_event(ch->fsm, CTC_EVENT_UC_RCRESET, ch); |
| 326 | } else { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 327 | if (ch->sense_rc != SNS0_INTERVENTION_REQ) { |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 328 | pr_notice( |
| 329 | "%s: The remote operating system is " |
| 330 | "not available\n", ch->id); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 331 | ch->sense_rc = SNS0_INTERVENTION_REQ; |
| 332 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 333 | fsm_event(ch->fsm, CTC_EVENT_UC_RSRESET, ch); |
| 334 | } |
| 335 | } else if (sense & SNS0_EQUIPMENT_CHECK) { |
| 336 | if (sense & SNS0_BUS_OUT_CHECK) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 337 | if (ch->sense_rc != SNS0_BUS_OUT_CHECK) { |
| 338 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN, |
| 339 | "%s(%s): remote HW error %02x", |
| 340 | CTCM_FUNTAIL, ch->id, sense); |
| 341 | ch->sense_rc = SNS0_BUS_OUT_CHECK; |
| 342 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 343 | fsm_event(ch->fsm, CTC_EVENT_UC_HWFAIL, ch); |
| 344 | } else { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 345 | if (ch->sense_rc != SNS0_EQUIPMENT_CHECK) { |
| 346 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN, |
| 347 | "%s(%s): remote read parity error %02x", |
| 348 | CTCM_FUNTAIL, ch->id, sense); |
| 349 | ch->sense_rc = SNS0_EQUIPMENT_CHECK; |
| 350 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 351 | fsm_event(ch->fsm, CTC_EVENT_UC_RXPARITY, ch); |
| 352 | } |
| 353 | } else if (sense & SNS0_BUS_OUT_CHECK) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 354 | if (ch->sense_rc != SNS0_BUS_OUT_CHECK) { |
| 355 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN, |
| 356 | "%s(%s): BUS OUT error %02x", |
| 357 | CTCM_FUNTAIL, ch->id, sense); |
| 358 | ch->sense_rc = SNS0_BUS_OUT_CHECK; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 359 | } |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 360 | if (sense & 0x04) /* data-streaming timeout */ |
| 361 | fsm_event(ch->fsm, CTC_EVENT_UC_TXTIMEOUT, ch); |
| 362 | else /* Data-transfer parity error */ |
| 363 | fsm_event(ch->fsm, CTC_EVENT_UC_TXPARITY, ch); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 364 | } else if (sense & SNS0_CMD_REJECT) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 365 | if (ch->sense_rc != SNS0_CMD_REJECT) { |
| 366 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN, |
| 367 | "%s(%s): Command rejected", |
| 368 | CTCM_FUNTAIL, ch->id); |
| 369 | ch->sense_rc = SNS0_CMD_REJECT; |
| 370 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 371 | } else if (sense == 0) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 372 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN, |
| 373 | "%s(%s): Unit check ZERO", |
| 374 | CTCM_FUNTAIL, ch->id); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 375 | fsm_event(ch->fsm, CTC_EVENT_UC_ZERO, ch); |
| 376 | } else { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 377 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN, |
| 378 | "%s(%s): Unit check code %02x unknown", |
| 379 | CTCM_FUNTAIL, ch->id, sense); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 380 | fsm_event(ch->fsm, CTC_EVENT_UC_UNKNOWN, ch); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | int ctcm_ch_alloc_buffer(struct channel *ch) |
| 385 | { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 386 | clear_normalized_cda(&ch->ccw[1]); |
| 387 | ch->trans_skb = __dev_alloc_skb(ch->max_bufsize, GFP_ATOMIC | GFP_DMA); |
| 388 | if (ch->trans_skb == NULL) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 389 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 390 | "%s(%s): %s trans_skb allocation error", |
| 391 | CTCM_FUNTAIL, ch->id, |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 392 | (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? |
| 393 | "RX" : "TX"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 394 | return -ENOMEM; |
| 395 | } |
| 396 | |
| 397 | ch->ccw[1].count = ch->max_bufsize; |
| 398 | if (set_normalized_cda(&ch->ccw[1], ch->trans_skb->data)) { |
| 399 | dev_kfree_skb(ch->trans_skb); |
| 400 | ch->trans_skb = NULL; |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 401 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 402 | "%s(%s): %s set norm_cda failed", |
| 403 | CTCM_FUNTAIL, ch->id, |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 404 | (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? |
| 405 | "RX" : "TX"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 406 | return -ENOMEM; |
| 407 | } |
| 408 | |
| 409 | ch->ccw[1].count = 0; |
| 410 | ch->trans_skb_data = ch->trans_skb->data; |
| 411 | ch->flags &= ~CHANNEL_FLAGS_BUFSIZE_CHANGED; |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * Interface API for upper network layers |
| 417 | */ |
| 418 | |
| 419 | /** |
| 420 | * Open an interface. |
| 421 | * Called from generic network layer when ifconfig up is run. |
| 422 | * |
| 423 | * dev Pointer to interface struct. |
| 424 | * |
| 425 | * returns 0 on success, -ERRNO on failure. (Never fails.) |
| 426 | */ |
| 427 | int ctcm_open(struct net_device *dev) |
| 428 | { |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 429 | struct ctcm_priv *priv = dev->ml_priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 430 | |
| 431 | CTCMY_DBF_DEV_NAME(SETUP, dev, ""); |
| 432 | if (!IS_MPC(priv)) |
| 433 | fsm_event(priv->fsm, DEV_EVENT_START, dev); |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Close an interface. |
| 439 | * Called from generic network layer when ifconfig down is run. |
| 440 | * |
| 441 | * dev Pointer to interface struct. |
| 442 | * |
| 443 | * returns 0 on success, -ERRNO on failure. (Never fails.) |
| 444 | */ |
| 445 | int ctcm_close(struct net_device *dev) |
| 446 | { |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 447 | struct ctcm_priv *priv = dev->ml_priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 448 | |
| 449 | CTCMY_DBF_DEV_NAME(SETUP, dev, ""); |
| 450 | if (!IS_MPC(priv)) |
| 451 | fsm_event(priv->fsm, DEV_EVENT_STOP, dev); |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | |
| 456 | /** |
| 457 | * Transmit a packet. |
| 458 | * This is a helper function for ctcm_tx(). |
| 459 | * |
| 460 | * ch Channel to be used for sending. |
| 461 | * skb Pointer to struct sk_buff of packet to send. |
| 462 | * The linklevel header has already been set up |
| 463 | * by ctcm_tx(). |
| 464 | * |
| 465 | * returns 0 on success, -ERRNO on failure. (Never fails.) |
| 466 | */ |
| 467 | static int ctcm_transmit_skb(struct channel *ch, struct sk_buff *skb) |
| 468 | { |
| 469 | unsigned long saveflags; |
| 470 | struct ll_header header; |
| 471 | int rc = 0; |
| 472 | __u16 block_len; |
| 473 | int ccw_idx; |
| 474 | struct sk_buff *nskb; |
| 475 | unsigned long hi; |
| 476 | |
| 477 | /* we need to acquire the lock for testing the state |
| 478 | * otherwise we can have an IRQ changing the state to |
| 479 | * TXIDLE after the test but before acquiring the lock. |
| 480 | */ |
| 481 | spin_lock_irqsave(&ch->collect_lock, saveflags); |
| 482 | if (fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) { |
| 483 | int l = skb->len + LL_HEADER_LENGTH; |
| 484 | |
| 485 | if (ch->collect_len + l > ch->max_bufsize - 2) { |
| 486 | spin_unlock_irqrestore(&ch->collect_lock, saveflags); |
| 487 | return -EBUSY; |
| 488 | } else { |
| 489 | atomic_inc(&skb->users); |
| 490 | header.length = l; |
| 491 | header.type = skb->protocol; |
| 492 | header.unused = 0; |
| 493 | memcpy(skb_push(skb, LL_HEADER_LENGTH), &header, |
| 494 | LL_HEADER_LENGTH); |
| 495 | skb_queue_tail(&ch->collect_queue, skb); |
| 496 | ch->collect_len += l; |
| 497 | } |
| 498 | spin_unlock_irqrestore(&ch->collect_lock, saveflags); |
| 499 | goto done; |
| 500 | } |
| 501 | spin_unlock_irqrestore(&ch->collect_lock, saveflags); |
| 502 | /* |
| 503 | * Protect skb against beeing free'd by upper |
| 504 | * layers. |
| 505 | */ |
| 506 | atomic_inc(&skb->users); |
| 507 | ch->prof.txlen += skb->len; |
| 508 | header.length = skb->len + LL_HEADER_LENGTH; |
| 509 | header.type = skb->protocol; |
| 510 | header.unused = 0; |
| 511 | memcpy(skb_push(skb, LL_HEADER_LENGTH), &header, LL_HEADER_LENGTH); |
| 512 | block_len = skb->len + 2; |
| 513 | *((__u16 *)skb_push(skb, 2)) = block_len; |
| 514 | |
| 515 | /* |
| 516 | * IDAL support in CTCM is broken, so we have to |
| 517 | * care about skb's above 2G ourselves. |
| 518 | */ |
| 519 | hi = ((unsigned long)skb_tail_pointer(skb) + LL_HEADER_LENGTH) >> 31; |
| 520 | if (hi) { |
| 521 | nskb = alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA); |
| 522 | if (!nskb) { |
| 523 | atomic_dec(&skb->users); |
| 524 | skb_pull(skb, LL_HEADER_LENGTH + 2); |
| 525 | ctcm_clear_busy(ch->netdev); |
| 526 | return -ENOMEM; |
| 527 | } else { |
| 528 | memcpy(skb_put(nskb, skb->len), skb->data, skb->len); |
| 529 | atomic_inc(&nskb->users); |
| 530 | atomic_dec(&skb->users); |
| 531 | dev_kfree_skb_irq(skb); |
| 532 | skb = nskb; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | ch->ccw[4].count = block_len; |
| 537 | if (set_normalized_cda(&ch->ccw[4], skb->data)) { |
| 538 | /* |
| 539 | * idal allocation failed, try via copying to |
| 540 | * trans_skb. trans_skb usually has a pre-allocated |
| 541 | * idal. |
| 542 | */ |
| 543 | if (ctcm_checkalloc_buffer(ch)) { |
| 544 | /* |
| 545 | * Remove our header. It gets added |
| 546 | * again on retransmit. |
| 547 | */ |
| 548 | atomic_dec(&skb->users); |
| 549 | skb_pull(skb, LL_HEADER_LENGTH + 2); |
| 550 | ctcm_clear_busy(ch->netdev); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 551 | return -ENOMEM; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | skb_reset_tail_pointer(ch->trans_skb); |
| 555 | ch->trans_skb->len = 0; |
| 556 | ch->ccw[1].count = skb->len; |
| 557 | skb_copy_from_linear_data(skb, |
| 558 | skb_put(ch->trans_skb, skb->len), skb->len); |
| 559 | atomic_dec(&skb->users); |
| 560 | dev_kfree_skb_irq(skb); |
| 561 | ccw_idx = 0; |
| 562 | } else { |
| 563 | skb_queue_tail(&ch->io_queue, skb); |
| 564 | ccw_idx = 3; |
| 565 | } |
| 566 | ch->retry = 0; |
| 567 | fsm_newstate(ch->fsm, CTC_STATE_TX); |
| 568 | fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch); |
| 569 | spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags); |
| 570 | ch->prof.send_stamp = current_kernel_time(); /* xtime */ |
| 571 | rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx], |
| 572 | (unsigned long)ch, 0xff, 0); |
| 573 | spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags); |
| 574 | if (ccw_idx == 3) |
| 575 | ch->prof.doios_single++; |
| 576 | if (rc != 0) { |
| 577 | fsm_deltimer(&ch->timer); |
| 578 | ctcm_ccw_check_rc(ch, rc, "single skb TX"); |
| 579 | if (ccw_idx == 3) |
| 580 | skb_dequeue_tail(&ch->io_queue); |
| 581 | /* |
| 582 | * Remove our header. It gets added |
| 583 | * again on retransmit. |
| 584 | */ |
| 585 | skb_pull(skb, LL_HEADER_LENGTH + 2); |
| 586 | } else if (ccw_idx == 0) { |
| 587 | struct net_device *dev = ch->netdev; |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 588 | struct ctcm_priv *priv = dev->ml_priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 589 | priv->stats.tx_packets++; |
| 590 | priv->stats.tx_bytes += skb->len - LL_HEADER_LENGTH; |
| 591 | } |
| 592 | done: |
| 593 | ctcm_clear_busy(ch->netdev); |
| 594 | return rc; |
| 595 | } |
| 596 | |
| 597 | static void ctcmpc_send_sweep_req(struct channel *rch) |
| 598 | { |
| 599 | struct net_device *dev = rch->netdev; |
| 600 | struct ctcm_priv *priv; |
| 601 | struct mpc_group *grp; |
| 602 | struct th_sweep *header; |
| 603 | struct sk_buff *sweep_skb; |
| 604 | struct channel *ch; |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 605 | /* int rc = 0; */ |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 606 | |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 607 | priv = dev->ml_priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 608 | grp = priv->mpcg; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 609 | ch = priv->channel[CTCM_WRITE]; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 610 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 611 | /* sweep processing is not complete until response and request */ |
| 612 | /* has completed for all read channels in group */ |
| 613 | if (grp->in_sweep == 0) { |
| 614 | grp->in_sweep = 1; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 615 | grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ]; |
| 616 | grp->sweep_req_pend_num = grp->active_channels[CTCM_READ]; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA); |
| 620 | |
| 621 | if (sweep_skb == NULL) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 622 | /* rc = -ENOMEM; */ |
| 623 | goto nomem; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | header = kmalloc(TH_SWEEP_LENGTH, gfp_type()); |
| 627 | |
| 628 | if (!header) { |
| 629 | dev_kfree_skb_any(sweep_skb); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 630 | /* rc = -ENOMEM; */ |
| 631 | goto nomem; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | header->th.th_seg = 0x00 ; |
| 635 | header->th.th_ch_flag = TH_SWEEP_REQ; /* 0x0f */ |
| 636 | header->th.th_blk_flag = 0x00; |
| 637 | header->th.th_is_xid = 0x00; |
| 638 | header->th.th_seq_num = 0x00; |
| 639 | header->sw.th_last_seq = ch->th_seq_num; |
| 640 | |
| 641 | memcpy(skb_put(sweep_skb, TH_SWEEP_LENGTH), header, TH_SWEEP_LENGTH); |
| 642 | |
| 643 | kfree(header); |
| 644 | |
| 645 | dev->trans_start = jiffies; |
| 646 | skb_queue_tail(&ch->sweep_queue, sweep_skb); |
| 647 | |
| 648 | fsm_addtimer(&ch->sweep_timer, 100, CTC_EVENT_RSWEEP_TIMER, ch); |
| 649 | |
| 650 | return; |
| 651 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 652 | nomem: |
| 653 | grp->in_sweep = 0; |
| 654 | ctcm_clear_busy(dev); |
| 655 | fsm_event(grp->fsm, MPCG_EVENT_INOP, dev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 656 | |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | /* |
| 661 | * MPC mode version of transmit_skb |
| 662 | */ |
| 663 | static int ctcmpc_transmit_skb(struct channel *ch, struct sk_buff *skb) |
| 664 | { |
| 665 | struct pdu *p_header; |
| 666 | struct net_device *dev = ch->netdev; |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 667 | struct ctcm_priv *priv = dev->ml_priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 668 | struct mpc_group *grp = priv->mpcg; |
| 669 | struct th_header *header; |
| 670 | struct sk_buff *nskb; |
| 671 | int rc = 0; |
| 672 | int ccw_idx; |
| 673 | unsigned long hi; |
| 674 | unsigned long saveflags = 0; /* avoids compiler warning */ |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 675 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 676 | CTCM_PR_DEBUG("Enter %s: %s, cp=%i ch=0x%p id=%s state=%s\n", |
| 677 | __func__, dev->name, smp_processor_id(), ch, |
| 678 | ch->id, fsm_getstate_str(ch->fsm)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 679 | |
| 680 | if ((fsm_getstate(ch->fsm) != CTC_STATE_TXIDLE) || grp->in_sweep) { |
| 681 | spin_lock_irqsave(&ch->collect_lock, saveflags); |
| 682 | atomic_inc(&skb->users); |
| 683 | p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type()); |
| 684 | |
| 685 | if (!p_header) { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 686 | spin_unlock_irqrestore(&ch->collect_lock, saveflags); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 687 | goto nomem_exit; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | p_header->pdu_offset = skb->len; |
| 691 | p_header->pdu_proto = 0x01; |
| 692 | p_header->pdu_flag = 0x00; |
| 693 | if (skb->protocol == ntohs(ETH_P_SNAP)) { |
| 694 | p_header->pdu_flag |= PDU_FIRST | PDU_CNTL; |
| 695 | } else { |
| 696 | p_header->pdu_flag |= PDU_FIRST; |
| 697 | } |
| 698 | p_header->pdu_seq = 0; |
| 699 | memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, |
| 700 | PDU_HEADER_LENGTH); |
| 701 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 702 | CTCM_PR_DEBUG("%s(%s): Put on collect_q - skb len: %04x \n" |
| 703 | "pdu header and data for up to 32 bytes:\n", |
| 704 | __func__, dev->name, skb->len); |
| 705 | CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 706 | |
| 707 | skb_queue_tail(&ch->collect_queue, skb); |
| 708 | ch->collect_len += skb->len; |
| 709 | kfree(p_header); |
| 710 | |
| 711 | spin_unlock_irqrestore(&ch->collect_lock, saveflags); |
| 712 | goto done; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | * Protect skb against beeing free'd by upper |
| 717 | * layers. |
| 718 | */ |
| 719 | atomic_inc(&skb->users); |
| 720 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 721 | /* |
| 722 | * IDAL support in CTCM is broken, so we have to |
| 723 | * care about skb's above 2G ourselves. |
| 724 | */ |
| 725 | hi = ((unsigned long)skb->tail + TH_HEADER_LENGTH) >> 31; |
| 726 | if (hi) { |
| 727 | nskb = __dev_alloc_skb(skb->len, GFP_ATOMIC | GFP_DMA); |
| 728 | if (!nskb) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 729 | goto nomem_exit; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 730 | } else { |
| 731 | memcpy(skb_put(nskb, skb->len), skb->data, skb->len); |
| 732 | atomic_inc(&nskb->users); |
| 733 | atomic_dec(&skb->users); |
| 734 | dev_kfree_skb_irq(skb); |
| 735 | skb = nskb; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | p_header = kmalloc(PDU_HEADER_LENGTH, gfp_type()); |
| 740 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 741 | if (!p_header) |
| 742 | goto nomem_exit; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 743 | |
| 744 | p_header->pdu_offset = skb->len; |
| 745 | p_header->pdu_proto = 0x01; |
| 746 | p_header->pdu_flag = 0x00; |
| 747 | p_header->pdu_seq = 0; |
| 748 | if (skb->protocol == ntohs(ETH_P_SNAP)) { |
| 749 | p_header->pdu_flag |= PDU_FIRST | PDU_CNTL; |
| 750 | } else { |
| 751 | p_header->pdu_flag |= PDU_FIRST; |
| 752 | } |
| 753 | memcpy(skb_push(skb, PDU_HEADER_LENGTH), p_header, PDU_HEADER_LENGTH); |
| 754 | |
| 755 | kfree(p_header); |
| 756 | |
| 757 | if (ch->collect_len > 0) { |
| 758 | spin_lock_irqsave(&ch->collect_lock, saveflags); |
| 759 | skb_queue_tail(&ch->collect_queue, skb); |
| 760 | ch->collect_len += skb->len; |
| 761 | skb = skb_dequeue(&ch->collect_queue); |
| 762 | ch->collect_len -= skb->len; |
| 763 | spin_unlock_irqrestore(&ch->collect_lock, saveflags); |
| 764 | } |
| 765 | |
| 766 | p_header = (struct pdu *)skb->data; |
| 767 | p_header->pdu_flag |= PDU_LAST; |
| 768 | |
| 769 | ch->prof.txlen += skb->len - PDU_HEADER_LENGTH; |
| 770 | |
| 771 | header = kmalloc(TH_HEADER_LENGTH, gfp_type()); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 772 | if (!header) |
| 773 | goto nomem_exit; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 774 | |
| 775 | header->th_seg = 0x00; |
| 776 | header->th_ch_flag = TH_HAS_PDU; /* Normal data */ |
| 777 | header->th_blk_flag = 0x00; |
| 778 | header->th_is_xid = 0x00; /* Just data here */ |
| 779 | ch->th_seq_num++; |
| 780 | header->th_seq_num = ch->th_seq_num; |
| 781 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 782 | CTCM_PR_DBGDATA("%s(%s) ToVTAM_th_seq= %08x\n" , |
| 783 | __func__, dev->name, ch->th_seq_num); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 784 | |
| 785 | /* put the TH on the packet */ |
| 786 | memcpy(skb_push(skb, TH_HEADER_LENGTH), header, TH_HEADER_LENGTH); |
| 787 | |
| 788 | kfree(header); |
| 789 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 790 | CTCM_PR_DBGDATA("%s(%s): skb len: %04x\n - pdu header and data for " |
| 791 | "up to 32 bytes sent to vtam:\n", |
| 792 | __func__, dev->name, skb->len); |
| 793 | CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 794 | |
| 795 | ch->ccw[4].count = skb->len; |
| 796 | if (set_normalized_cda(&ch->ccw[4], skb->data)) { |
| 797 | /* |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 798 | * idal allocation failed, try via copying to trans_skb. |
| 799 | * trans_skb usually has a pre-allocated idal. |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 800 | */ |
| 801 | if (ctcm_checkalloc_buffer(ch)) { |
| 802 | /* |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 803 | * Remove our header. |
| 804 | * It gets added again on retransmit. |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 805 | */ |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 806 | goto nomem_exit; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | skb_reset_tail_pointer(ch->trans_skb); |
| 810 | ch->trans_skb->len = 0; |
| 811 | ch->ccw[1].count = skb->len; |
| 812 | memcpy(skb_put(ch->trans_skb, skb->len), skb->data, skb->len); |
| 813 | atomic_dec(&skb->users); |
| 814 | dev_kfree_skb_irq(skb); |
| 815 | ccw_idx = 0; |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 816 | CTCM_PR_DBGDATA("%s(%s): trans_skb len: %04x\n" |
| 817 | "up to 32 bytes sent to vtam:\n", |
| 818 | __func__, dev->name, ch->trans_skb->len); |
| 819 | CTCM_D3_DUMP((char *)ch->trans_skb->data, |
| 820 | min_t(int, 32, ch->trans_skb->len)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 821 | } else { |
| 822 | skb_queue_tail(&ch->io_queue, skb); |
| 823 | ccw_idx = 3; |
| 824 | } |
| 825 | ch->retry = 0; |
| 826 | fsm_newstate(ch->fsm, CTC_STATE_TX); |
| 827 | fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch); |
| 828 | |
| 829 | if (do_debug_ccw) |
| 830 | ctcmpc_dumpit((char *)&ch->ccw[ccw_idx], |
| 831 | sizeof(struct ccw1) * 3); |
| 832 | |
| 833 | spin_lock_irqsave(get_ccwdev_lock(ch->cdev), saveflags); |
| 834 | ch->prof.send_stamp = current_kernel_time(); /* xtime */ |
| 835 | rc = ccw_device_start(ch->cdev, &ch->ccw[ccw_idx], |
| 836 | (unsigned long)ch, 0xff, 0); |
| 837 | spin_unlock_irqrestore(get_ccwdev_lock(ch->cdev), saveflags); |
| 838 | if (ccw_idx == 3) |
| 839 | ch->prof.doios_single++; |
| 840 | if (rc != 0) { |
| 841 | fsm_deltimer(&ch->timer); |
| 842 | ctcm_ccw_check_rc(ch, rc, "single skb TX"); |
| 843 | if (ccw_idx == 3) |
| 844 | skb_dequeue_tail(&ch->io_queue); |
| 845 | } else if (ccw_idx == 0) { |
| 846 | priv->stats.tx_packets++; |
| 847 | priv->stats.tx_bytes += skb->len - TH_HEADER_LENGTH; |
| 848 | } |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 849 | if (ch->th_seq_num > 0xf0000000) /* Chose at random. */ |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 850 | ctcmpc_send_sweep_req(ch); |
| 851 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 852 | goto done; |
| 853 | nomem_exit: |
| 854 | CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_CRIT, |
| 855 | "%s(%s): MEMORY allocation ERROR\n", |
| 856 | CTCM_FUNTAIL, ch->id); |
| 857 | rc = -ENOMEM; |
| 858 | atomic_dec(&skb->users); |
| 859 | dev_kfree_skb_any(skb); |
| 860 | fsm_event(priv->mpcg->fsm, MPCG_EVENT_INOP, dev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 861 | done: |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 862 | CTCM_PR_DEBUG("Exit %s(%s)\n", __func__, dev->name); |
| 863 | return rc; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Start transmission of a packet. |
| 868 | * Called from generic network device layer. |
| 869 | * |
| 870 | * skb Pointer to buffer containing the packet. |
| 871 | * dev Pointer to interface struct. |
| 872 | * |
| 873 | * returns 0 if packet consumed, !0 if packet rejected. |
| 874 | * Note: If we return !0, then the packet is free'd by |
| 875 | * the generic network layer. |
| 876 | */ |
| 877 | /* first merge version - leaving both functions separated */ |
| 878 | static int ctcm_tx(struct sk_buff *skb, struct net_device *dev) |
| 879 | { |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 880 | struct ctcm_priv *priv = dev->ml_priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 881 | |
| 882 | if (skb == NULL) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 883 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 884 | "%s(%s): NULL sk_buff passed", |
| 885 | CTCM_FUNTAIL, dev->name); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 886 | priv->stats.tx_dropped++; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 887 | return NETDEV_TX_OK; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 888 | } |
| 889 | if (skb_headroom(skb) < (LL_HEADER_LENGTH + 2)) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 890 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 891 | "%s(%s): Got sk_buff with head room < %ld bytes", |
| 892 | CTCM_FUNTAIL, dev->name, LL_HEADER_LENGTH + 2); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 893 | dev_kfree_skb(skb); |
| 894 | priv->stats.tx_dropped++; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 895 | return NETDEV_TX_OK; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /* |
| 899 | * If channels are not running, try to restart them |
| 900 | * and throw away packet. |
| 901 | */ |
| 902 | if (fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) { |
| 903 | fsm_event(priv->fsm, DEV_EVENT_START, dev); |
| 904 | dev_kfree_skb(skb); |
| 905 | priv->stats.tx_dropped++; |
| 906 | priv->stats.tx_errors++; |
| 907 | priv->stats.tx_carrier_errors++; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 908 | return NETDEV_TX_OK; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | if (ctcm_test_and_set_busy(dev)) |
Ursula Braun | 3a05d14 | 2009-03-24 03:27:47 +0000 | [diff] [blame] | 912 | return NETDEV_TX_BUSY; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 913 | |
| 914 | dev->trans_start = jiffies; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 915 | if (ctcm_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0) |
Ursula Braun | 3a05d14 | 2009-03-24 03:27:47 +0000 | [diff] [blame] | 916 | return NETDEV_TX_BUSY; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 917 | return NETDEV_TX_OK; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /* unmerged MPC variant of ctcm_tx */ |
| 921 | static int ctcmpc_tx(struct sk_buff *skb, struct net_device *dev) |
| 922 | { |
| 923 | int len = 0; |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 924 | struct ctcm_priv *priv = dev->ml_priv; |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 925 | struct mpc_group *grp = priv->mpcg; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 926 | struct sk_buff *newskb = NULL; |
| 927 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 928 | /* |
| 929 | * Some sanity checks ... |
| 930 | */ |
| 931 | if (skb == NULL) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 932 | CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR, |
| 933 | "%s(%s): NULL sk_buff passed", |
| 934 | CTCM_FUNTAIL, dev->name); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 935 | priv->stats.tx_dropped++; |
| 936 | goto done; |
| 937 | } |
| 938 | if (skb_headroom(skb) < (TH_HEADER_LENGTH + PDU_HEADER_LENGTH)) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 939 | CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR, |
| 940 | "%s(%s): Got sk_buff with head room < %ld bytes", |
| 941 | CTCM_FUNTAIL, dev->name, |
| 942 | TH_HEADER_LENGTH + PDU_HEADER_LENGTH); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 943 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 944 | CTCM_D3_DUMP((char *)skb->data, min_t(int, 32, skb->len)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 945 | |
| 946 | len = skb->len + TH_HEADER_LENGTH + PDU_HEADER_LENGTH; |
| 947 | newskb = __dev_alloc_skb(len, gfp_type() | GFP_DMA); |
| 948 | |
| 949 | if (!newskb) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 950 | CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_ERROR, |
| 951 | "%s: %s: __dev_alloc_skb failed", |
| 952 | __func__, dev->name); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 953 | |
| 954 | dev_kfree_skb_any(skb); |
| 955 | priv->stats.tx_dropped++; |
| 956 | priv->stats.tx_errors++; |
| 957 | priv->stats.tx_carrier_errors++; |
| 958 | fsm_event(grp->fsm, MPCG_EVENT_INOP, dev); |
| 959 | goto done; |
| 960 | } |
| 961 | newskb->protocol = skb->protocol; |
| 962 | skb_reserve(newskb, TH_HEADER_LENGTH + PDU_HEADER_LENGTH); |
| 963 | memcpy(skb_put(newskb, skb->len), skb->data, skb->len); |
| 964 | dev_kfree_skb_any(skb); |
| 965 | skb = newskb; |
| 966 | } |
| 967 | |
| 968 | /* |
| 969 | * If channels are not running, |
| 970 | * notify anybody about a link failure and throw |
| 971 | * away packet. |
| 972 | */ |
| 973 | if ((fsm_getstate(priv->fsm) != DEV_STATE_RUNNING) || |
| 974 | (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) { |
| 975 | dev_kfree_skb_any(skb); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 976 | CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR, |
| 977 | "%s(%s): inactive MPCGROUP - dropped", |
| 978 | CTCM_FUNTAIL, dev->name); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 979 | priv->stats.tx_dropped++; |
| 980 | priv->stats.tx_errors++; |
| 981 | priv->stats.tx_carrier_errors++; |
| 982 | goto done; |
| 983 | } |
| 984 | |
| 985 | if (ctcm_test_and_set_busy(dev)) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 986 | CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR, |
| 987 | "%s(%s): device busy - dropped", |
| 988 | CTCM_FUNTAIL, dev->name); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 989 | dev_kfree_skb_any(skb); |
| 990 | priv->stats.tx_dropped++; |
| 991 | priv->stats.tx_errors++; |
| 992 | priv->stats.tx_carrier_errors++; |
| 993 | fsm_event(grp->fsm, MPCG_EVENT_INOP, dev); |
| 994 | goto done; |
| 995 | } |
| 996 | |
| 997 | dev->trans_start = jiffies; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 998 | if (ctcmpc_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 999 | CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR, |
| 1000 | "%s(%s): device error - dropped", |
| 1001 | CTCM_FUNTAIL, dev->name); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1002 | dev_kfree_skb_any(skb); |
| 1003 | priv->stats.tx_dropped++; |
| 1004 | priv->stats.tx_errors++; |
| 1005 | priv->stats.tx_carrier_errors++; |
| 1006 | ctcm_clear_busy(dev); |
| 1007 | fsm_event(grp->fsm, MPCG_EVENT_INOP, dev); |
| 1008 | goto done; |
| 1009 | } |
| 1010 | ctcm_clear_busy(dev); |
| 1011 | done: |
| 1012 | if (do_debug) |
| 1013 | MPC_DBF_DEV_NAME(TRACE, dev, "exit"); |
| 1014 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1015 | return NETDEV_TX_OK; /* handle freeing of skb here */ |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | /** |
| 1020 | * Sets MTU of an interface. |
| 1021 | * |
| 1022 | * dev Pointer to interface struct. |
| 1023 | * new_mtu The new MTU to use for this interface. |
| 1024 | * |
| 1025 | * returns 0 on success, -EINVAL if MTU is out of valid range. |
| 1026 | * (valid range is 576 .. 65527). If VM is on the |
| 1027 | * remote side, maximum MTU is 32760, however this is |
| 1028 | * not checked here. |
| 1029 | */ |
| 1030 | static int ctcm_change_mtu(struct net_device *dev, int new_mtu) |
| 1031 | { |
| 1032 | struct ctcm_priv *priv; |
| 1033 | int max_bufsize; |
| 1034 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1035 | if (new_mtu < 576 || new_mtu > 65527) |
| 1036 | return -EINVAL; |
| 1037 | |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 1038 | priv = dev->ml_priv; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1039 | max_bufsize = priv->channel[CTCM_READ]->max_bufsize; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1040 | |
| 1041 | if (IS_MPC(priv)) { |
| 1042 | if (new_mtu > max_bufsize - TH_HEADER_LENGTH) |
| 1043 | return -EINVAL; |
| 1044 | dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH; |
| 1045 | } else { |
| 1046 | if (new_mtu > max_bufsize - LL_HEADER_LENGTH - 2) |
| 1047 | return -EINVAL; |
| 1048 | dev->hard_header_len = LL_HEADER_LENGTH + 2; |
| 1049 | } |
| 1050 | dev->mtu = new_mtu; |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | /** |
| 1055 | * Returns interface statistics of a device. |
| 1056 | * |
| 1057 | * dev Pointer to interface struct. |
| 1058 | * |
| 1059 | * returns Pointer to stats struct of this interface. |
| 1060 | */ |
| 1061 | static struct net_device_stats *ctcm_stats(struct net_device *dev) |
| 1062 | { |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 1063 | return &((struct ctcm_priv *)dev->ml_priv)->stats; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1066 | static void ctcm_free_netdevice(struct net_device *dev) |
| 1067 | { |
| 1068 | struct ctcm_priv *priv; |
| 1069 | struct mpc_group *grp; |
| 1070 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1071 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, |
| 1072 | "%s(%s)", CTCM_FUNTAIL, dev->name); |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 1073 | priv = dev->ml_priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1074 | if (priv) { |
| 1075 | grp = priv->mpcg; |
| 1076 | if (grp) { |
| 1077 | if (grp->fsm) |
| 1078 | kfree_fsm(grp->fsm); |
| 1079 | if (grp->xid_skb) |
| 1080 | dev_kfree_skb(grp->xid_skb); |
| 1081 | if (grp->rcvd_xid_skb) |
| 1082 | dev_kfree_skb(grp->rcvd_xid_skb); |
| 1083 | tasklet_kill(&grp->mpc_tasklet2); |
| 1084 | kfree(grp); |
| 1085 | priv->mpcg = NULL; |
| 1086 | } |
| 1087 | if (priv->fsm) { |
| 1088 | kfree_fsm(priv->fsm); |
| 1089 | priv->fsm = NULL; |
| 1090 | } |
| 1091 | kfree(priv->xid); |
| 1092 | priv->xid = NULL; |
| 1093 | /* |
| 1094 | * Note: kfree(priv); is done in "opposite" function of |
| 1095 | * allocator function probe_device which is remove_device. |
| 1096 | */ |
| 1097 | } |
| 1098 | #ifdef MODULE |
| 1099 | free_netdev(dev); |
| 1100 | #endif |
| 1101 | } |
| 1102 | |
| 1103 | struct mpc_group *ctcmpc_init_mpc_group(struct ctcm_priv *priv); |
| 1104 | |
Frank Blaschka | 69b3aa6 | 2009-01-09 03:43:57 +0000 | [diff] [blame] | 1105 | static const struct net_device_ops ctcm_netdev_ops = { |
| 1106 | .ndo_open = ctcm_open, |
| 1107 | .ndo_stop = ctcm_close, |
| 1108 | .ndo_get_stats = ctcm_stats, |
| 1109 | .ndo_change_mtu = ctcm_change_mtu, |
| 1110 | .ndo_start_xmit = ctcm_tx, |
| 1111 | }; |
| 1112 | |
| 1113 | static const struct net_device_ops ctcm_mpc_netdev_ops = { |
| 1114 | .ndo_open = ctcm_open, |
| 1115 | .ndo_stop = ctcm_close, |
| 1116 | .ndo_get_stats = ctcm_stats, |
| 1117 | .ndo_change_mtu = ctcm_change_mtu, |
| 1118 | .ndo_start_xmit = ctcmpc_tx, |
| 1119 | }; |
| 1120 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1121 | void static ctcm_dev_setup(struct net_device *dev) |
| 1122 | { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1123 | dev->type = ARPHRD_SLIP; |
| 1124 | dev->tx_queue_len = 100; |
| 1125 | dev->flags = IFF_POINTOPOINT | IFF_NOARP; |
| 1126 | } |
| 1127 | |
| 1128 | /* |
| 1129 | * Initialize everything of the net device except the name and the |
| 1130 | * channel structs. |
| 1131 | */ |
| 1132 | static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv) |
| 1133 | { |
| 1134 | struct net_device *dev; |
| 1135 | struct mpc_group *grp; |
| 1136 | if (!priv) |
| 1137 | return NULL; |
| 1138 | |
| 1139 | if (IS_MPC(priv)) |
| 1140 | dev = alloc_netdev(0, MPC_DEVICE_GENE, ctcm_dev_setup); |
| 1141 | else |
| 1142 | dev = alloc_netdev(0, CTC_DEVICE_GENE, ctcm_dev_setup); |
| 1143 | |
| 1144 | if (!dev) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1145 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT, |
| 1146 | "%s: MEMORY allocation ERROR", |
| 1147 | CTCM_FUNTAIL); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1148 | return NULL; |
| 1149 | } |
Peter Tiedemann | 261893d | 2008-08-21 17:10:24 +0200 | [diff] [blame] | 1150 | dev->ml_priv = priv; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1151 | priv->fsm = init_fsm("ctcmdev", dev_state_names, dev_event_names, |
| 1152 | CTCM_NR_DEV_STATES, CTCM_NR_DEV_EVENTS, |
| 1153 | dev_fsm, dev_fsm_len, GFP_KERNEL); |
| 1154 | if (priv->fsm == NULL) { |
| 1155 | CTCMY_DBF_DEV(SETUP, dev, "init_fsm error"); |
Vasiliy Kulikov | bc68580 | 2010-09-26 18:56:06 -0700 | [diff] [blame] | 1156 | free_netdev(dev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1157 | return NULL; |
| 1158 | } |
| 1159 | fsm_newstate(priv->fsm, DEV_STATE_STOPPED); |
| 1160 | fsm_settimer(priv->fsm, &priv->restart_timer); |
| 1161 | |
| 1162 | if (IS_MPC(priv)) { |
| 1163 | /* MPC Group Initializations */ |
| 1164 | grp = ctcmpc_init_mpc_group(priv); |
| 1165 | if (grp == NULL) { |
| 1166 | MPC_DBF_DEV(SETUP, dev, "init_mpc_group error"); |
Vasiliy Kulikov | bc68580 | 2010-09-26 18:56:06 -0700 | [diff] [blame] | 1167 | free_netdev(dev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1168 | return NULL; |
| 1169 | } |
| 1170 | tasklet_init(&grp->mpc_tasklet2, |
| 1171 | mpc_group_ready, (unsigned long)dev); |
| 1172 | dev->mtu = MPC_BUFSIZE_DEFAULT - |
| 1173 | TH_HEADER_LENGTH - PDU_HEADER_LENGTH; |
| 1174 | |
Frank Blaschka | 69b3aa6 | 2009-01-09 03:43:57 +0000 | [diff] [blame] | 1175 | dev->netdev_ops = &ctcm_mpc_netdev_ops; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1176 | dev->hard_header_len = TH_HEADER_LENGTH + PDU_HEADER_LENGTH; |
| 1177 | priv->buffer_size = MPC_BUFSIZE_DEFAULT; |
| 1178 | } else { |
| 1179 | dev->mtu = CTCM_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2; |
Frank Blaschka | 69b3aa6 | 2009-01-09 03:43:57 +0000 | [diff] [blame] | 1180 | dev->netdev_ops = &ctcm_netdev_ops; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1181 | dev->hard_header_len = LL_HEADER_LENGTH + 2; |
| 1182 | } |
| 1183 | |
| 1184 | CTCMY_DBF_DEV(SETUP, dev, "finished"); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1185 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1186 | return dev; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * Main IRQ handler. |
| 1191 | * |
| 1192 | * cdev The ccw_device the interrupt is for. |
| 1193 | * intparm interruption parameter. |
| 1194 | * irb interruption response block. |
| 1195 | */ |
| 1196 | static void ctcm_irq_handler(struct ccw_device *cdev, |
| 1197 | unsigned long intparm, struct irb *irb) |
| 1198 | { |
| 1199 | struct channel *ch; |
| 1200 | struct net_device *dev; |
| 1201 | struct ctcm_priv *priv; |
| 1202 | struct ccwgroup_device *cgdev; |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1203 | int cstat; |
| 1204 | int dstat; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1205 | |
Heiko Carstens | 85b81cd | 2011-01-05 12:47:37 +0100 | [diff] [blame] | 1206 | kstat_cpu(smp_processor_id()).irqs[IOINT_CTC]++; |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1207 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_DEBUG, |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1208 | "Enter %s(%s)", CTCM_FUNTAIL, dev_name(&cdev->dev)); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1209 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1210 | if (ctcm_check_irb_error(cdev, irb)) |
| 1211 | return; |
| 1212 | |
| 1213 | cgdev = dev_get_drvdata(&cdev->dev); |
| 1214 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1215 | cstat = irb->scsw.cmd.cstat; |
| 1216 | dstat = irb->scsw.cmd.dstat; |
| 1217 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1218 | /* Check for unsolicited interrupts. */ |
| 1219 | if (cgdev == NULL) { |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1220 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_ERROR, |
| 1221 | "%s(%s) unsolicited irq: c-%02x d-%02x\n", |
| 1222 | CTCM_FUNTAIL, dev_name(&cdev->dev), cstat, dstat); |
| 1223 | dev_warn(&cdev->dev, |
| 1224 | "The adapter received a non-specific IRQ\n"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1225 | return; |
| 1226 | } |
| 1227 | |
| 1228 | priv = dev_get_drvdata(&cgdev->dev); |
| 1229 | |
| 1230 | /* Try to extract channel from driver data. */ |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1231 | if (priv->channel[CTCM_READ]->cdev == cdev) |
| 1232 | ch = priv->channel[CTCM_READ]; |
| 1233 | else if (priv->channel[CTCM_WRITE]->cdev == cdev) |
| 1234 | ch = priv->channel[CTCM_WRITE]; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1235 | else { |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1236 | dev_err(&cdev->dev, |
| 1237 | "%s: Internal error: Can't determine channel for " |
| 1238 | "interrupt device %s\n", |
| 1239 | __func__, dev_name(&cdev->dev)); |
| 1240 | /* Explain: inconsistent internal structures */ |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1241 | return; |
| 1242 | } |
| 1243 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1244 | dev = ch->netdev; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1245 | if (dev == NULL) { |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1246 | dev_err(&cdev->dev, |
| 1247 | "%s Internal error: net_device is NULL, ch = 0x%p\n", |
| 1248 | __func__, ch); |
| 1249 | /* Explain: inconsistent internal structures */ |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1250 | return; |
| 1251 | } |
| 1252 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1253 | /* Copy interruption response block. */ |
| 1254 | memcpy(ch->irb, irb, sizeof(struct irb)); |
| 1255 | |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1256 | /* Issue error message and return on subchannel error code */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1257 | if (irb->scsw.cmd.cstat) { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1258 | fsm_event(ch->fsm, CTC_EVENT_SC_UNKNOWN, ch); |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1259 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN, |
| 1260 | "%s(%s): sub-ch check %s: cs=%02x ds=%02x", |
| 1261 | CTCM_FUNTAIL, dev->name, ch->id, cstat, dstat); |
| 1262 | dev_warn(&cdev->dev, |
| 1263 | "A check occurred on the subchannel\n"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1264 | return; |
| 1265 | } |
| 1266 | |
| 1267 | /* Check the reason-code of a unit check */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1268 | if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1269 | if ((irb->ecw[0] & ch->sense_rc) == 0) |
| 1270 | /* print it only once */ |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1271 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_WARN, |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1272 | "%s(%s): sense=%02x, ds=%02x", |
| 1273 | CTCM_FUNTAIL, ch->id, irb->ecw[0], dstat); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1274 | ccw_unit_check(ch, irb->ecw[0]); |
| 1275 | return; |
| 1276 | } |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1277 | if (irb->scsw.cmd.dstat & DEV_STAT_BUSY) { |
| 1278 | if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1279 | fsm_event(ch->fsm, CTC_EVENT_ATTNBUSY, ch); |
| 1280 | else |
| 1281 | fsm_event(ch->fsm, CTC_EVENT_BUSY, ch); |
| 1282 | return; |
| 1283 | } |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1284 | if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1285 | fsm_event(ch->fsm, CTC_EVENT_ATTN, ch); |
| 1286 | return; |
| 1287 | } |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 1288 | if ((irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || |
| 1289 | (irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || |
| 1290 | (irb->scsw.cmd.stctl == |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1291 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) |
| 1292 | fsm_event(ch->fsm, CTC_EVENT_FINSTAT, ch); |
| 1293 | else |
| 1294 | fsm_event(ch->fsm, CTC_EVENT_IRQ, ch); |
| 1295 | |
| 1296 | } |
| 1297 | |
| 1298 | /** |
| 1299 | * Add ctcm specific attributes. |
| 1300 | * Add ctcm private data. |
| 1301 | * |
| 1302 | * cgdev pointer to ccwgroup_device just added |
| 1303 | * |
| 1304 | * returns 0 on success, !0 on failure. |
| 1305 | */ |
| 1306 | static int ctcm_probe_device(struct ccwgroup_device *cgdev) |
| 1307 | { |
| 1308 | struct ctcm_priv *priv; |
| 1309 | int rc; |
| 1310 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1311 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, |
| 1312 | "%s %p", |
| 1313 | __func__, cgdev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1314 | |
| 1315 | if (!get_device(&cgdev->dev)) |
| 1316 | return -ENODEV; |
| 1317 | |
| 1318 | priv = kzalloc(sizeof(struct ctcm_priv), GFP_KERNEL); |
| 1319 | if (!priv) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1320 | CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, |
| 1321 | "%s: memory allocation failure", |
| 1322 | CTCM_FUNTAIL); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1323 | put_device(&cgdev->dev); |
| 1324 | return -ENOMEM; |
| 1325 | } |
| 1326 | |
| 1327 | rc = ctcm_add_files(&cgdev->dev); |
| 1328 | if (rc) { |
| 1329 | kfree(priv); |
| 1330 | put_device(&cgdev->dev); |
| 1331 | return rc; |
| 1332 | } |
| 1333 | priv->buffer_size = CTCM_BUFSIZE_DEFAULT; |
| 1334 | cgdev->cdev[0]->handler = ctcm_irq_handler; |
| 1335 | cgdev->cdev[1]->handler = ctcm_irq_handler; |
| 1336 | dev_set_drvdata(&cgdev->dev, priv); |
| 1337 | |
| 1338 | return 0; |
| 1339 | } |
| 1340 | |
| 1341 | /** |
| 1342 | * Add a new channel to the list of channels. |
| 1343 | * Keeps the channel list sorted. |
| 1344 | * |
| 1345 | * cdev The ccw_device to be added. |
| 1346 | * type The type class of the new channel. |
| 1347 | * priv Points to the private data of the ccwgroup_device. |
| 1348 | * |
| 1349 | * returns 0 on success, !0 on error. |
| 1350 | */ |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1351 | static int add_channel(struct ccw_device *cdev, enum ctcm_channel_types type, |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1352 | struct ctcm_priv *priv) |
| 1353 | { |
| 1354 | struct channel **c = &channels; |
| 1355 | struct channel *ch; |
| 1356 | int ccw_num; |
| 1357 | int rc = 0; |
| 1358 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1359 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, |
| 1360 | "%s(%s), type %d, proto %d", |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1361 | __func__, dev_name(&cdev->dev), type, priv->protocol); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1362 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1363 | ch = kzalloc(sizeof(struct channel), GFP_KERNEL); |
| 1364 | if (ch == NULL) |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1365 | return -ENOMEM; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1366 | |
| 1367 | ch->protocol = priv->protocol; |
| 1368 | if (IS_MPC(priv)) { |
Julia Lawall | ae57b20 | 2010-05-16 21:15:13 +0000 | [diff] [blame] | 1369 | ch->discontact_th = kzalloc(TH_HEADER_LENGTH, gfp_type()); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1370 | if (ch->discontact_th == NULL) |
| 1371 | goto nomem_return; |
| 1372 | |
| 1373 | ch->discontact_th->th_blk_flag = TH_DISCONTACT; |
| 1374 | tasklet_init(&ch->ch_disc_tasklet, |
| 1375 | mpc_action_send_discontact, (unsigned long)ch); |
| 1376 | |
| 1377 | tasklet_init(&ch->ch_tasklet, ctcmpc_bh, (unsigned long)ch); |
| 1378 | ch->max_bufsize = (MPC_BUFSIZE_DEFAULT - 35); |
| 1379 | ccw_num = 17; |
| 1380 | } else |
| 1381 | ccw_num = 8; |
| 1382 | |
Julia Lawall | ae57b20 | 2010-05-16 21:15:13 +0000 | [diff] [blame] | 1383 | ch->ccw = kzalloc(ccw_num * sizeof(struct ccw1), GFP_KERNEL | GFP_DMA); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1384 | if (ch->ccw == NULL) |
| 1385 | goto nomem_return; |
| 1386 | |
| 1387 | ch->cdev = cdev; |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 1388 | snprintf(ch->id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev->dev)); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1389 | ch->type = type; |
| 1390 | |
| 1391 | /** |
| 1392 | * "static" ccws are used in the following way: |
| 1393 | * |
| 1394 | * ccw[0..2] (Channel program for generic I/O): |
| 1395 | * 0: prepare |
| 1396 | * 1: read or write (depending on direction) with fixed |
| 1397 | * buffer (idal allocated once when buffer is allocated) |
| 1398 | * 2: nop |
| 1399 | * ccw[3..5] (Channel program for direct write of packets) |
| 1400 | * 3: prepare |
| 1401 | * 4: write (idal allocated on every write). |
| 1402 | * 5: nop |
| 1403 | * ccw[6..7] (Channel program for initial channel setup): |
| 1404 | * 6: set extended mode |
| 1405 | * 7: nop |
| 1406 | * |
| 1407 | * ch->ccw[0..5] are initialized in ch_action_start because |
| 1408 | * the channel's direction is yet unknown here. |
| 1409 | * |
| 1410 | * ccws used for xid2 negotiations |
| 1411 | * ch-ccw[8-14] need to be used for the XID exchange either |
| 1412 | * X side XID2 Processing |
| 1413 | * 8: write control |
| 1414 | * 9: write th |
| 1415 | * 10: write XID |
| 1416 | * 11: read th from secondary |
| 1417 | * 12: read XID from secondary |
| 1418 | * 13: read 4 byte ID |
| 1419 | * 14: nop |
| 1420 | * Y side XID Processing |
| 1421 | * 8: sense |
| 1422 | * 9: read th |
| 1423 | * 10: read XID |
| 1424 | * 11: write th |
| 1425 | * 12: write XID |
| 1426 | * 13: write 4 byte ID |
| 1427 | * 14: nop |
| 1428 | * |
| 1429 | * ccws used for double noop due to VM timing issues |
| 1430 | * which result in unrecoverable Busy on channel |
| 1431 | * 15: nop |
| 1432 | * 16: nop |
| 1433 | */ |
| 1434 | ch->ccw[6].cmd_code = CCW_CMD_SET_EXTENDED; |
| 1435 | ch->ccw[6].flags = CCW_FLAG_SLI; |
| 1436 | |
| 1437 | ch->ccw[7].cmd_code = CCW_CMD_NOOP; |
| 1438 | ch->ccw[7].flags = CCW_FLAG_SLI; |
| 1439 | |
| 1440 | if (IS_MPC(priv)) { |
| 1441 | ch->ccw[15].cmd_code = CCW_CMD_WRITE; |
| 1442 | ch->ccw[15].flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1443 | ch->ccw[15].count = TH_HEADER_LENGTH; |
| 1444 | ch->ccw[15].cda = virt_to_phys(ch->discontact_th); |
| 1445 | |
| 1446 | ch->ccw[16].cmd_code = CCW_CMD_NOOP; |
| 1447 | ch->ccw[16].flags = CCW_FLAG_SLI; |
| 1448 | |
| 1449 | ch->fsm = init_fsm(ch->id, ctc_ch_state_names, |
| 1450 | ctc_ch_event_names, CTC_MPC_NR_STATES, |
| 1451 | CTC_MPC_NR_EVENTS, ctcmpc_ch_fsm, |
| 1452 | mpc_ch_fsm_len, GFP_KERNEL); |
| 1453 | } else { |
| 1454 | ch->fsm = init_fsm(ch->id, ctc_ch_state_names, |
| 1455 | ctc_ch_event_names, CTC_NR_STATES, |
| 1456 | CTC_NR_EVENTS, ch_fsm, |
| 1457 | ch_fsm_len, GFP_KERNEL); |
| 1458 | } |
| 1459 | if (ch->fsm == NULL) |
| 1460 | goto free_return; |
| 1461 | |
| 1462 | fsm_newstate(ch->fsm, CTC_STATE_IDLE); |
| 1463 | |
| 1464 | ch->irb = kzalloc(sizeof(struct irb), GFP_KERNEL); |
| 1465 | if (ch->irb == NULL) |
| 1466 | goto nomem_return; |
| 1467 | |
| 1468 | while (*c && ctcm_less_than((*c)->id, ch->id)) |
| 1469 | c = &(*c)->next; |
| 1470 | |
| 1471 | if (*c && (!strncmp((*c)->id, ch->id, CTCM_ID_SIZE))) { |
| 1472 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, |
| 1473 | "%s (%s) already in list, using old entry", |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1474 | __func__, (*c)->id); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1475 | |
| 1476 | goto free_return; |
| 1477 | } |
| 1478 | |
| 1479 | spin_lock_init(&ch->collect_lock); |
| 1480 | |
| 1481 | fsm_settimer(ch->fsm, &ch->timer); |
| 1482 | skb_queue_head_init(&ch->io_queue); |
| 1483 | skb_queue_head_init(&ch->collect_queue); |
| 1484 | |
| 1485 | if (IS_MPC(priv)) { |
| 1486 | fsm_settimer(ch->fsm, &ch->sweep_timer); |
| 1487 | skb_queue_head_init(&ch->sweep_queue); |
| 1488 | } |
| 1489 | ch->next = *c; |
| 1490 | *c = ch; |
| 1491 | return 0; |
| 1492 | |
| 1493 | nomem_return: |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1494 | rc = -ENOMEM; |
| 1495 | |
| 1496 | free_return: /* note that all channel pointers are 0 or valid */ |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1497 | kfree(ch->ccw); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1498 | kfree(ch->discontact_th); |
| 1499 | kfree_fsm(ch->fsm); |
| 1500 | kfree(ch->irb); |
| 1501 | kfree(ch); |
| 1502 | return rc; |
| 1503 | } |
| 1504 | |
| 1505 | /* |
| 1506 | * Return type of a detected device. |
| 1507 | */ |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1508 | static enum ctcm_channel_types get_channel_type(struct ccw_device_id *id) |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1509 | { |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1510 | enum ctcm_channel_types type; |
| 1511 | type = (enum ctcm_channel_types)id->driver_info; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1512 | |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1513 | if (type == ctcm_channel_type_ficon) |
| 1514 | type = ctcm_channel_type_escon; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1515 | |
| 1516 | return type; |
| 1517 | } |
| 1518 | |
| 1519 | /** |
| 1520 | * |
| 1521 | * Setup an interface. |
| 1522 | * |
| 1523 | * cgdev Device to be setup. |
| 1524 | * |
| 1525 | * returns 0 on success, !0 on failure. |
| 1526 | */ |
| 1527 | static int ctcm_new_device(struct ccwgroup_device *cgdev) |
| 1528 | { |
| 1529 | char read_id[CTCM_ID_SIZE]; |
| 1530 | char write_id[CTCM_ID_SIZE]; |
| 1531 | int direction; |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1532 | enum ctcm_channel_types type; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1533 | struct ctcm_priv *priv; |
| 1534 | struct net_device *dev; |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1535 | struct ccw_device *cdev0; |
| 1536 | struct ccw_device *cdev1; |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1537 | struct channel *readc; |
| 1538 | struct channel *writec; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1539 | int ret; |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1540 | int result; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1541 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1542 | priv = dev_get_drvdata(&cgdev->dev); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1543 | if (!priv) { |
| 1544 | result = -ENODEV; |
| 1545 | goto out_err_result; |
| 1546 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1547 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1548 | cdev0 = cgdev->cdev[0]; |
| 1549 | cdev1 = cgdev->cdev[1]; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1550 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1551 | type = get_channel_type(&cdev0->id); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1552 | |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 1553 | snprintf(read_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev0->dev)); |
| 1554 | snprintf(write_id, CTCM_ID_SIZE, "ch-%s", dev_name(&cdev1->dev)); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1555 | |
| 1556 | ret = add_channel(cdev0, type, priv); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1557 | if (ret) { |
| 1558 | result = ret; |
| 1559 | goto out_err_result; |
| 1560 | } |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1561 | ret = add_channel(cdev1, type, priv); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1562 | if (ret) { |
| 1563 | result = ret; |
| 1564 | goto out_remove_channel1; |
| 1565 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1566 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1567 | ret = ccw_device_set_online(cdev0); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1568 | if (ret != 0) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1569 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE, |
| 1570 | "%s(%s) set_online rc=%d", |
| 1571 | CTCM_FUNTAIL, read_id, ret); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1572 | result = -EIO; |
| 1573 | goto out_remove_channel2; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1574 | } |
| 1575 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1576 | ret = ccw_device_set_online(cdev1); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1577 | if (ret != 0) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1578 | CTCM_DBF_TEXT_(TRACE, CTC_DBF_NOTICE, |
| 1579 | "%s(%s) set_online rc=%d", |
| 1580 | CTCM_FUNTAIL, write_id, ret); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1581 | |
| 1582 | result = -EIO; |
| 1583 | goto out_ccw1; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | dev = ctcm_init_netdevice(priv); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1587 | if (dev == NULL) { |
| 1588 | result = -ENODEV; |
| 1589 | goto out_ccw2; |
| 1590 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1591 | |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1592 | for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) { |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1593 | priv->channel[direction] = |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1594 | channel_get(type, direction == CTCM_READ ? |
| 1595 | read_id : write_id, direction); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1596 | if (priv->channel[direction] == NULL) { |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1597 | if (direction == CTCM_WRITE) |
| 1598 | channel_free(priv->channel[CTCM_READ]); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1599 | goto out_dev; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1600 | } |
| 1601 | priv->channel[direction]->netdev = dev; |
| 1602 | priv->channel[direction]->protocol = priv->protocol; |
| 1603 | priv->channel[direction]->max_bufsize = priv->buffer_size; |
| 1604 | } |
| 1605 | /* sysfs magic */ |
| 1606 | SET_NETDEV_DEV(dev, &cgdev->dev); |
| 1607 | |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1608 | if (register_netdev(dev)) { |
| 1609 | result = -ENODEV; |
| 1610 | goto out_dev; |
| 1611 | } |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1612 | |
| 1613 | if (ctcm_add_attributes(&cgdev->dev)) { |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1614 | result = -ENODEV; |
| 1615 | goto out_unregister; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name)); |
| 1619 | |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1620 | dev_info(&dev->dev, |
| 1621 | "setup OK : r/w = %s/%s, protocol : %d\n", |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1622 | priv->channel[CTCM_READ]->id, |
| 1623 | priv->channel[CTCM_WRITE]->id, priv->protocol); |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1624 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1625 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1626 | "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name, |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1627 | priv->channel[CTCM_READ]->id, |
| 1628 | priv->channel[CTCM_WRITE]->id, priv->protocol); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1629 | |
| 1630 | return 0; |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1631 | out_unregister: |
| 1632 | unregister_netdev(dev); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1633 | out_dev: |
| 1634 | ctcm_free_netdevice(dev); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1635 | out_ccw2: |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1636 | ccw_device_set_offline(cgdev->cdev[1]); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1637 | out_ccw1: |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1638 | ccw_device_set_offline(cgdev->cdev[0]); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1639 | out_remove_channel2: |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1640 | readc = channel_get(type, read_id, CTCM_READ); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1641 | channel_remove(readc); |
| 1642 | out_remove_channel1: |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1643 | writec = channel_get(type, write_id, CTCM_WRITE); |
Einar Lueck | a1c1f5e | 2009-10-14 22:54:59 +0000 | [diff] [blame] | 1644 | channel_remove(writec); |
| 1645 | out_err_result: |
| 1646 | return result; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | /** |
| 1650 | * Shutdown an interface. |
| 1651 | * |
| 1652 | * cgdev Device to be shut down. |
| 1653 | * |
| 1654 | * returns 0 on success, !0 on failure. |
| 1655 | */ |
| 1656 | static int ctcm_shutdown_device(struct ccwgroup_device *cgdev) |
| 1657 | { |
| 1658 | struct ctcm_priv *priv; |
| 1659 | struct net_device *dev; |
| 1660 | |
| 1661 | priv = dev_get_drvdata(&cgdev->dev); |
| 1662 | if (!priv) |
| 1663 | return -ENODEV; |
| 1664 | |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1665 | if (priv->channel[CTCM_READ]) { |
| 1666 | dev = priv->channel[CTCM_READ]->netdev; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1667 | CTCM_DBF_DEV(SETUP, dev, ""); |
| 1668 | /* Close the device */ |
| 1669 | ctcm_close(dev); |
| 1670 | dev->flags &= ~IFF_RUNNING; |
| 1671 | ctcm_remove_attributes(&cgdev->dev); |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1672 | channel_free(priv->channel[CTCM_READ]); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1673 | } else |
| 1674 | dev = NULL; |
| 1675 | |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1676 | if (priv->channel[CTCM_WRITE]) |
| 1677 | channel_free(priv->channel[CTCM_WRITE]); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1678 | |
| 1679 | if (dev) { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1680 | unregister_netdev(dev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1681 | ctcm_free_netdevice(dev); |
| 1682 | } |
| 1683 | |
| 1684 | if (priv->fsm) |
| 1685 | kfree_fsm(priv->fsm); |
| 1686 | |
| 1687 | ccw_device_set_offline(cgdev->cdev[1]); |
| 1688 | ccw_device_set_offline(cgdev->cdev[0]); |
| 1689 | |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1690 | if (priv->channel[CTCM_READ]) |
| 1691 | channel_remove(priv->channel[CTCM_READ]); |
| 1692 | if (priv->channel[CTCM_WRITE]) |
| 1693 | channel_remove(priv->channel[CTCM_WRITE]); |
| 1694 | priv->channel[CTCM_READ] = priv->channel[CTCM_WRITE] = NULL; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1695 | |
| 1696 | return 0; |
| 1697 | |
| 1698 | } |
| 1699 | |
| 1700 | |
| 1701 | static void ctcm_remove_device(struct ccwgroup_device *cgdev) |
| 1702 | { |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1703 | struct ctcm_priv *priv = dev_get_drvdata(&cgdev->dev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1704 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1705 | BUG_ON(priv == NULL); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1706 | |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1707 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, |
Ursula Braun | 8ac6d45 | 2009-05-19 21:38:38 +0000 | [diff] [blame] | 1708 | "removing device %p, proto : %d", |
| 1709 | cgdev, priv->protocol); |
Peter Tiedemann | aa3f2cb | 2008-07-18 15:24:57 +0200 | [diff] [blame] | 1710 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1711 | if (cgdev->state == CCWGROUP_ONLINE) |
| 1712 | ctcm_shutdown_device(cgdev); |
| 1713 | ctcm_remove_files(&cgdev->dev); |
| 1714 | dev_set_drvdata(&cgdev->dev, NULL); |
| 1715 | kfree(priv); |
| 1716 | put_device(&cgdev->dev); |
| 1717 | } |
| 1718 | |
Frank Blaschka | b8a2d42 | 2009-06-16 10:30:32 +0200 | [diff] [blame] | 1719 | static int ctcm_pm_suspend(struct ccwgroup_device *gdev) |
| 1720 | { |
| 1721 | struct ctcm_priv *priv = dev_get_drvdata(&gdev->dev); |
| 1722 | |
| 1723 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1724 | return 0; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1725 | netif_device_detach(priv->channel[CTCM_READ]->netdev); |
| 1726 | ctcm_close(priv->channel[CTCM_READ]->netdev); |
Frank Blaschka | 1e1815b | 2009-11-12 21:46:28 +0000 | [diff] [blame] | 1727 | if (!wait_event_timeout(priv->fsm->wait_q, |
| 1728 | fsm_getstate(priv->fsm) == DEV_STATE_STOPPED, CTCM_TIME_5_SEC)) { |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1729 | netif_device_attach(priv->channel[CTCM_READ]->netdev); |
Frank Blaschka | 1e1815b | 2009-11-12 21:46:28 +0000 | [diff] [blame] | 1730 | return -EBUSY; |
| 1731 | } |
Frank Blaschka | b8a2d42 | 2009-06-16 10:30:32 +0200 | [diff] [blame] | 1732 | ccw_device_set_offline(gdev->cdev[1]); |
| 1733 | ccw_device_set_offline(gdev->cdev[0]); |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | static int ctcm_pm_resume(struct ccwgroup_device *gdev) |
| 1738 | { |
| 1739 | struct ctcm_priv *priv = dev_get_drvdata(&gdev->dev); |
| 1740 | int rc; |
| 1741 | |
| 1742 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1743 | return 0; |
| 1744 | rc = ccw_device_set_online(gdev->cdev[1]); |
| 1745 | if (rc) |
| 1746 | goto err_out; |
| 1747 | rc = ccw_device_set_online(gdev->cdev[0]); |
| 1748 | if (rc) |
| 1749 | goto err_out; |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1750 | ctcm_open(priv->channel[CTCM_READ]->netdev); |
Frank Blaschka | b8a2d42 | 2009-06-16 10:30:32 +0200 | [diff] [blame] | 1751 | err_out: |
Ursula Braun | 3c09e26 | 2010-08-12 01:58:28 +0000 | [diff] [blame] | 1752 | netif_device_attach(priv->channel[CTCM_READ]->netdev); |
Frank Blaschka | b8a2d42 | 2009-06-16 10:30:32 +0200 | [diff] [blame] | 1753 | return rc; |
| 1754 | } |
| 1755 | |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1756 | static struct ccw_device_id ctcm_ids[] = { |
| 1757 | {CCW_DEVICE(0x3088, 0x08), .driver_info = ctcm_channel_type_parallel}, |
| 1758 | {CCW_DEVICE(0x3088, 0x1e), .driver_info = ctcm_channel_type_ficon}, |
| 1759 | {CCW_DEVICE(0x3088, 0x1f), .driver_info = ctcm_channel_type_escon}, |
| 1760 | {}, |
| 1761 | }; |
| 1762 | MODULE_DEVICE_TABLE(ccw, ctcm_ids); |
| 1763 | |
| 1764 | static struct ccw_driver ctcm_ccw_driver = { |
Sebastian Ott | 3bda058 | 2011-03-23 10:16:02 +0100 | [diff] [blame] | 1765 | .driver = { |
| 1766 | .owner = THIS_MODULE, |
| 1767 | .name = "ctcm", |
| 1768 | }, |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1769 | .ids = ctcm_ids, |
| 1770 | .probe = ccwgroup_probe_ccwdev, |
| 1771 | .remove = ccwgroup_remove_ccwdev, |
| 1772 | }; |
| 1773 | |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1774 | static struct ccwgroup_driver ctcm_group_driver = { |
Sebastian Ott | 3c190c5 | 2011-03-23 10:16:04 +0100 | [diff] [blame] | 1775 | .driver = { |
| 1776 | .owner = THIS_MODULE, |
| 1777 | .name = CTC_DRIVER_NAME, |
| 1778 | }, |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1779 | .max_slaves = 2, |
| 1780 | .driver_id = 0xC3E3C3D4, /* CTCM */ |
| 1781 | .probe = ctcm_probe_device, |
| 1782 | .remove = ctcm_remove_device, |
| 1783 | .set_online = ctcm_new_device, |
| 1784 | .set_offline = ctcm_shutdown_device, |
Frank Blaschka | b8a2d42 | 2009-06-16 10:30:32 +0200 | [diff] [blame] | 1785 | .freeze = ctcm_pm_suspend, |
| 1786 | .thaw = ctcm_pm_resume, |
| 1787 | .restore = ctcm_pm_resume, |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1788 | }; |
| 1789 | |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1790 | static ssize_t |
| 1791 | ctcm_driver_group_store(struct device_driver *ddrv, const char *buf, |
| 1792 | size_t count) |
| 1793 | { |
| 1794 | int err; |
| 1795 | |
| 1796 | err = ccwgroup_create_from_string(ctcm_root_dev, |
| 1797 | ctcm_group_driver.driver_id, |
| 1798 | &ctcm_ccw_driver, 2, buf); |
| 1799 | return err ? err : count; |
| 1800 | } |
| 1801 | |
| 1802 | static DRIVER_ATTR(group, 0200, NULL, ctcm_driver_group_store); |
| 1803 | |
| 1804 | static struct attribute *ctcm_group_attrs[] = { |
| 1805 | &driver_attr_group.attr, |
| 1806 | NULL, |
| 1807 | }; |
| 1808 | |
| 1809 | static struct attribute_group ctcm_group_attr_group = { |
| 1810 | .attrs = ctcm_group_attrs, |
| 1811 | }; |
| 1812 | |
Heiko Carstens | 302689a | 2009-11-17 06:47:02 -0800 | [diff] [blame] | 1813 | static const struct attribute_group *ctcm_group_attr_groups[] = { |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1814 | &ctcm_group_attr_group, |
| 1815 | NULL, |
| 1816 | }; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1817 | |
| 1818 | /* |
| 1819 | * Module related routines |
| 1820 | */ |
| 1821 | |
| 1822 | /* |
| 1823 | * Prepare to be unloaded. Free IRQ's and release all resources. |
| 1824 | * This is called just before this module is unloaded. It is |
| 1825 | * not called, if the usage count is !0, so we don't need to check |
| 1826 | * for that. |
| 1827 | */ |
| 1828 | static void __exit ctcm_exit(void) |
| 1829 | { |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1830 | driver_remove_file(&ctcm_group_driver.driver, &driver_attr_group); |
| 1831 | ccwgroup_driver_unregister(&ctcm_group_driver); |
| 1832 | ccw_driver_unregister(&ctcm_ccw_driver); |
| 1833 | root_device_unregister(ctcm_root_dev); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1834 | ctcm_unregister_dbf_views(); |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1835 | pr_info("CTCM driver unloaded\n"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | /* |
| 1839 | * Print Banner. |
| 1840 | */ |
| 1841 | static void print_banner(void) |
| 1842 | { |
Peter Tiedemann | 2a7c6f2 | 2008-12-25 13:39:54 +0100 | [diff] [blame] | 1843 | pr_info("CTCM driver initialized\n"); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | /** |
| 1847 | * Initialize module. |
| 1848 | * This is called just after the module is loaded. |
| 1849 | * |
| 1850 | * returns 0 on success, !0 on error. |
| 1851 | */ |
| 1852 | static int __init ctcm_init(void) |
| 1853 | { |
| 1854 | int ret; |
| 1855 | |
| 1856 | channels = NULL; |
| 1857 | |
| 1858 | ret = ctcm_register_dbf_views(); |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1859 | if (ret) |
| 1860 | goto out_err; |
| 1861 | ctcm_root_dev = root_device_register("ctcm"); |
| 1862 | ret = IS_ERR(ctcm_root_dev) ? PTR_ERR(ctcm_root_dev) : 0; |
| 1863 | if (ret) |
| 1864 | goto register_err; |
| 1865 | ret = ccw_driver_register(&ctcm_ccw_driver); |
| 1866 | if (ret) |
| 1867 | goto ccw_err; |
| 1868 | ctcm_group_driver.driver.groups = ctcm_group_attr_groups; |
| 1869 | ret = ccwgroup_driver_register(&ctcm_group_driver); |
| 1870 | if (ret) |
| 1871 | goto ccwgroup_err; |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1872 | print_banner(); |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 1873 | return 0; |
| 1874 | |
| 1875 | ccwgroup_err: |
| 1876 | ccw_driver_unregister(&ctcm_ccw_driver); |
| 1877 | ccw_err: |
| 1878 | root_device_unregister(ctcm_root_dev); |
| 1879 | register_err: |
| 1880 | ctcm_unregister_dbf_views(); |
| 1881 | out_err: |
| 1882 | pr_err("%s / Initializing the ctcm device driver failed, ret = %d\n", |
| 1883 | __func__, ret); |
Peter Tiedemann | 293d984 | 2008-02-08 00:03:49 +0100 | [diff] [blame] | 1884 | return ret; |
| 1885 | } |
| 1886 | |
| 1887 | module_init(ctcm_init); |
| 1888 | module_exit(ctcm_exit); |
| 1889 | |
| 1890 | MODULE_AUTHOR("Peter Tiedemann <ptiedem@de.ibm.com>"); |
| 1891 | MODULE_DESCRIPTION("Network driver for S/390 CTC + CTCMPC (SNA)"); |
| 1892 | MODULE_LICENSE("GPL"); |
| 1893 | |