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