Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson AB 2010 |
| 3 | * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com |
| 4 | * Author: Daniel Martensson / daniel.martensson@stericsson.com |
| 5 | * Dmitry.Tarnyagin / dmitry.tarnyagin@stericsson.com |
| 6 | * License terms: GNU General Public License (GPL) version 2. |
| 7 | */ |
| 8 | |
sjur.brandeland@stericsson.com | 39abbae | 2012-04-12 08:27:27 +0000 | [diff] [blame] | 9 | #define pr_fmt(fmt) KBUILD_MODNAME fmt |
| 10 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 11 | #include <linux/init.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/device.h> |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/list.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/if_arp.h> |
| 21 | #include <linux/timer.h> |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 22 | #include <net/rtnetlink.h> |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 23 | #include <linux/pkt_sched.h> |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 24 | #include <net/caif/caif_layer.h> |
| 25 | #include <net/caif/caif_hsi.h> |
| 26 | |
| 27 | MODULE_LICENSE("GPL"); |
| 28 | MODULE_AUTHOR("Daniel Martensson<daniel.martensson@stericsson.com>"); |
| 29 | MODULE_DESCRIPTION("CAIF HSI driver"); |
| 30 | |
| 31 | /* Returns the number of padding bytes for alignment. */ |
| 32 | #define PAD_POW2(x, pow) ((((x)&((pow)-1)) == 0) ? 0 :\ |
| 33 | (((pow)-((x)&((pow)-1))))) |
| 34 | |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 35 | static const struct cfhsi_config hsi_default_config = { |
Dmitry Tarnyagin | 28bd204 | 2011-10-13 11:29:27 +0000 | [diff] [blame] | 36 | |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 37 | /* Inactivity timeout on HSI, ms */ |
| 38 | .inactivity_timeout = HZ, |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 39 | |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 40 | /* Aggregation timeout (ms) of zero means no aggregation is done*/ |
| 41 | .aggregation_timeout = 1, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 42 | |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 43 | /* |
| 44 | * HSI link layer flow-control thresholds. |
| 45 | * Threshold values for the HSI packet queue. Flow-control will be |
| 46 | * asserted when the number of packets exceeds q_high_mark. It will |
| 47 | * not be de-asserted before the number of packets drops below |
| 48 | * q_low_mark. |
| 49 | * Warning: A high threshold value might increase throughput but it |
| 50 | * will at the same time prevent channel prioritization and increase |
| 51 | * the risk of flooding the modem. The high threshold should be above |
| 52 | * the low. |
| 53 | */ |
| 54 | .q_high_mark = 100, |
| 55 | .q_low_mark = 50, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 56 | |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 57 | /* |
| 58 | * HSI padding options. |
| 59 | * Warning: must be a base of 2 (& operation used) and can not be zero ! |
| 60 | */ |
| 61 | .head_align = 4, |
| 62 | .tail_align = 4, |
| 63 | }; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 64 | |
| 65 | #define ON 1 |
| 66 | #define OFF 0 |
| 67 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 68 | static LIST_HEAD(cfhsi_list); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 69 | |
| 70 | static void cfhsi_inactivity_tout(unsigned long arg) |
| 71 | { |
| 72 | struct cfhsi *cfhsi = (struct cfhsi *)arg; |
| 73 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 74 | netdev_dbg(cfhsi->ndev, "%s.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 75 | __func__); |
| 76 | |
| 77 | /* Schedule power down work queue. */ |
| 78 | if (!test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 79 | queue_work(cfhsi->wq, &cfhsi->wake_down_work); |
| 80 | } |
| 81 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 82 | static void cfhsi_update_aggregation_stats(struct cfhsi *cfhsi, |
| 83 | const struct sk_buff *skb, |
| 84 | int direction) |
| 85 | { |
| 86 | struct caif_payload_info *info; |
| 87 | int hpad, tpad, len; |
| 88 | |
| 89 | info = (struct caif_payload_info *)&skb->cb; |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 90 | hpad = 1 + PAD_POW2((info->hdr_len + 1), cfhsi->cfg.head_align); |
| 91 | tpad = PAD_POW2((skb->len + hpad), cfhsi->cfg.tail_align); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 92 | len = skb->len + hpad + tpad; |
| 93 | |
| 94 | if (direction > 0) |
| 95 | cfhsi->aggregation_len += len; |
| 96 | else if (direction < 0) |
| 97 | cfhsi->aggregation_len -= len; |
| 98 | } |
| 99 | |
| 100 | static bool cfhsi_can_send_aggregate(struct cfhsi *cfhsi) |
| 101 | { |
| 102 | int i; |
| 103 | |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 104 | if (cfhsi->cfg.aggregation_timeout == 0) |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 105 | return true; |
| 106 | |
| 107 | for (i = 0; i < CFHSI_PRIO_BEBK; ++i) { |
| 108 | if (cfhsi->qhead[i].qlen) |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | /* TODO: Use aggregation_len instead */ |
| 113 | if (cfhsi->qhead[CFHSI_PRIO_BEBK].qlen >= CFHSI_MAX_PKTS) |
| 114 | return true; |
| 115 | |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | static struct sk_buff *cfhsi_dequeue(struct cfhsi *cfhsi) |
| 120 | { |
| 121 | struct sk_buff *skb; |
| 122 | int i; |
| 123 | |
| 124 | for (i = 0; i < CFHSI_PRIO_LAST; ++i) { |
| 125 | skb = skb_dequeue(&cfhsi->qhead[i]); |
| 126 | if (skb) |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | return skb; |
| 131 | } |
| 132 | |
| 133 | static int cfhsi_tx_queue_len(struct cfhsi *cfhsi) |
| 134 | { |
| 135 | int i, len = 0; |
| 136 | for (i = 0; i < CFHSI_PRIO_LAST; ++i) |
| 137 | len += skb_queue_len(&cfhsi->qhead[i]); |
| 138 | return len; |
| 139 | } |
| 140 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 141 | static void cfhsi_abort_tx(struct cfhsi *cfhsi) |
| 142 | { |
| 143 | struct sk_buff *skb; |
| 144 | |
| 145 | for (;;) { |
| 146 | spin_lock_bh(&cfhsi->lock); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 147 | skb = cfhsi_dequeue(cfhsi); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 148 | if (!skb) |
| 149 | break; |
| 150 | |
| 151 | cfhsi->ndev->stats.tx_errors++; |
| 152 | cfhsi->ndev->stats.tx_dropped++; |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 153 | cfhsi_update_aggregation_stats(cfhsi, skb, -1); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 154 | spin_unlock_bh(&cfhsi->lock); |
| 155 | kfree_skb(skb); |
| 156 | } |
| 157 | cfhsi->tx_state = CFHSI_TX_STATE_IDLE; |
| 158 | if (!test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 159 | mod_timer(&cfhsi->inactivity_timer, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 160 | jiffies + cfhsi->cfg.inactivity_timeout); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 161 | spin_unlock_bh(&cfhsi->lock); |
| 162 | } |
| 163 | |
| 164 | static int cfhsi_flush_fifo(struct cfhsi *cfhsi) |
| 165 | { |
| 166 | char buffer[32]; /* Any reasonable value */ |
| 167 | size_t fifo_occupancy; |
| 168 | int ret; |
| 169 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 170 | netdev_dbg(cfhsi->ndev, "%s.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 171 | __func__); |
| 172 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 173 | do { |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 174 | ret = cfhsi->ops->cfhsi_fifo_occupancy(cfhsi->ops, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 175 | &fifo_occupancy); |
| 176 | if (ret) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 177 | netdev_warn(cfhsi->ndev, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 178 | "%s: can't get FIFO occupancy: %d.\n", |
| 179 | __func__, ret); |
| 180 | break; |
| 181 | } else if (!fifo_occupancy) |
| 182 | /* No more data, exitting normally */ |
| 183 | break; |
| 184 | |
| 185 | fifo_occupancy = min(sizeof(buffer), fifo_occupancy); |
| 186 | set_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits); |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 187 | ret = cfhsi->ops->cfhsi_rx(buffer, fifo_occupancy, |
| 188 | cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 189 | if (ret) { |
| 190 | clear_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits); |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 191 | netdev_warn(cfhsi->ndev, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 192 | "%s: can't read data: %d.\n", |
| 193 | __func__, ret); |
| 194 | break; |
| 195 | } |
| 196 | |
| 197 | ret = 5 * HZ; |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 198 | ret = wait_event_interruptible_timeout(cfhsi->flush_fifo_wait, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 199 | !test_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits), ret); |
| 200 | |
| 201 | if (ret < 0) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 202 | netdev_warn(cfhsi->ndev, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 203 | "%s: can't wait for flush complete: %d.\n", |
| 204 | __func__, ret); |
| 205 | break; |
| 206 | } else if (!ret) { |
| 207 | ret = -ETIMEDOUT; |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 208 | netdev_warn(cfhsi->ndev, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 209 | "%s: timeout waiting for flush complete.\n", |
| 210 | __func__); |
| 211 | break; |
| 212 | } |
| 213 | } while (1); |
| 214 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 215 | return ret; |
| 216 | } |
| 217 | |
| 218 | static int cfhsi_tx_frm(struct cfhsi_desc *desc, struct cfhsi *cfhsi) |
| 219 | { |
| 220 | int nfrms = 0; |
| 221 | int pld_len = 0; |
| 222 | struct sk_buff *skb; |
| 223 | u8 *pfrm = desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ; |
| 224 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 225 | skb = cfhsi_dequeue(cfhsi); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 226 | if (!skb) |
| 227 | return 0; |
| 228 | |
sjur.brandeland@stericsson.com | 94230fe | 2011-10-13 11:29:22 +0000 | [diff] [blame] | 229 | /* Clear offset. */ |
| 230 | desc->offset = 0; |
| 231 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 232 | /* Check if we can embed a CAIF frame. */ |
| 233 | if (skb->len < CFHSI_MAX_EMB_FRM_SZ) { |
| 234 | struct caif_payload_info *info; |
Sjur Brændeland | b42f7b5 | 2012-06-25 07:49:39 +0000 | [diff] [blame] | 235 | int hpad; |
| 236 | int tpad; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 237 | |
| 238 | /* Calculate needed head alignment and tail alignment. */ |
| 239 | info = (struct caif_payload_info *)&skb->cb; |
| 240 | |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 241 | hpad = 1 + PAD_POW2((info->hdr_len + 1), cfhsi->cfg.head_align); |
| 242 | tpad = PAD_POW2((skb->len + hpad), cfhsi->cfg.tail_align); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 243 | |
| 244 | /* Check if frame still fits with added alignment. */ |
| 245 | if ((skb->len + hpad + tpad) <= CFHSI_MAX_EMB_FRM_SZ) { |
| 246 | u8 *pemb = desc->emb_frm; |
| 247 | desc->offset = CFHSI_DESC_SHORT_SZ; |
| 248 | *pemb = (u8)(hpad - 1); |
| 249 | pemb += hpad; |
| 250 | |
| 251 | /* Update network statistics. */ |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 252 | spin_lock_bh(&cfhsi->lock); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 253 | cfhsi->ndev->stats.tx_packets++; |
| 254 | cfhsi->ndev->stats.tx_bytes += skb->len; |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 255 | cfhsi_update_aggregation_stats(cfhsi, skb, -1); |
| 256 | spin_unlock_bh(&cfhsi->lock); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 257 | |
| 258 | /* Copy in embedded CAIF frame. */ |
| 259 | skb_copy_bits(skb, 0, pemb, skb->len); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 260 | |
| 261 | /* Consume the SKB */ |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 262 | consume_skb(skb); |
| 263 | skb = NULL; |
| 264 | } |
sjur.brandeland@stericsson.com | 94230fe | 2011-10-13 11:29:22 +0000 | [diff] [blame] | 265 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 266 | |
| 267 | /* Create payload CAIF frames. */ |
| 268 | pfrm = desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ; |
| 269 | while (nfrms < CFHSI_MAX_PKTS) { |
| 270 | struct caif_payload_info *info; |
Sjur Brændeland | b42f7b5 | 2012-06-25 07:49:39 +0000 | [diff] [blame] | 271 | int hpad; |
| 272 | int tpad; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 273 | |
| 274 | if (!skb) |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 275 | skb = cfhsi_dequeue(cfhsi); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 276 | |
| 277 | if (!skb) |
| 278 | break; |
| 279 | |
| 280 | /* Calculate needed head alignment and tail alignment. */ |
| 281 | info = (struct caif_payload_info *)&skb->cb; |
| 282 | |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 283 | hpad = 1 + PAD_POW2((info->hdr_len + 1), cfhsi->cfg.head_align); |
| 284 | tpad = PAD_POW2((skb->len + hpad), cfhsi->cfg.tail_align); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 285 | |
| 286 | /* Fill in CAIF frame length in descriptor. */ |
| 287 | desc->cffrm_len[nfrms] = hpad + skb->len + tpad; |
| 288 | |
| 289 | /* Fill head padding information. */ |
| 290 | *pfrm = (u8)(hpad - 1); |
| 291 | pfrm += hpad; |
| 292 | |
| 293 | /* Update network statistics. */ |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 294 | spin_lock_bh(&cfhsi->lock); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 295 | cfhsi->ndev->stats.tx_packets++; |
| 296 | cfhsi->ndev->stats.tx_bytes += skb->len; |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 297 | cfhsi_update_aggregation_stats(cfhsi, skb, -1); |
| 298 | spin_unlock_bh(&cfhsi->lock); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 299 | |
| 300 | /* Copy in CAIF frame. */ |
| 301 | skb_copy_bits(skb, 0, pfrm, skb->len); |
| 302 | |
| 303 | /* Update payload length. */ |
| 304 | pld_len += desc->cffrm_len[nfrms]; |
| 305 | |
| 306 | /* Update frame pointer. */ |
| 307 | pfrm += skb->len + tpad; |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 308 | |
| 309 | /* Consume the SKB */ |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 310 | consume_skb(skb); |
| 311 | skb = NULL; |
| 312 | |
| 313 | /* Update number of frames. */ |
| 314 | nfrms++; |
| 315 | } |
| 316 | |
| 317 | /* Unused length fields should be zero-filled (according to SPEC). */ |
| 318 | while (nfrms < CFHSI_MAX_PKTS) { |
| 319 | desc->cffrm_len[nfrms] = 0x0000; |
| 320 | nfrms++; |
| 321 | } |
| 322 | |
| 323 | /* Check if we can piggy-back another descriptor. */ |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 324 | if (cfhsi_can_send_aggregate(cfhsi)) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 325 | desc->header |= CFHSI_PIGGY_DESC; |
| 326 | else |
| 327 | desc->header &= ~CFHSI_PIGGY_DESC; |
| 328 | |
| 329 | return CFHSI_DESC_SZ + pld_len; |
| 330 | } |
| 331 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 332 | static void cfhsi_start_tx(struct cfhsi *cfhsi) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 333 | { |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 334 | struct cfhsi_desc *desc = (struct cfhsi_desc *)cfhsi->tx_buf; |
| 335 | int len, res; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 336 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 337 | netdev_dbg(cfhsi->ndev, "%s.\n", __func__); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 338 | |
| 339 | if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 340 | return; |
| 341 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 342 | do { |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 343 | /* Create HSI frame. */ |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 344 | len = cfhsi_tx_frm(desc, cfhsi); |
| 345 | if (!len) { |
| 346 | spin_lock_bh(&cfhsi->lock); |
| 347 | if (unlikely(cfhsi_tx_queue_len(cfhsi))) { |
Dmitry Tarnyagin | fe47f12 | 2011-10-13 11:29:23 +0000 | [diff] [blame] | 348 | spin_unlock_bh(&cfhsi->lock); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 349 | res = -EAGAIN; |
| 350 | continue; |
Dmitry Tarnyagin | fe47f12 | 2011-10-13 11:29:23 +0000 | [diff] [blame] | 351 | } |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 352 | cfhsi->tx_state = CFHSI_TX_STATE_IDLE; |
| 353 | /* Start inactivity timer. */ |
| 354 | mod_timer(&cfhsi->inactivity_timer, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 355 | jiffies + cfhsi->cfg.inactivity_timeout); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 356 | spin_unlock_bh(&cfhsi->lock); |
| 357 | break; |
| 358 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 359 | |
| 360 | /* Set up new transfer. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 361 | res = cfhsi->ops->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->ops); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 362 | if (WARN_ON(res < 0)) |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 363 | netdev_err(cfhsi->ndev, "%s: TX error %d.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 364 | __func__, res); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 365 | } while (res < 0); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 366 | } |
Dmitry Tarnyagin | fe47f12 | 2011-10-13 11:29:23 +0000 | [diff] [blame] | 367 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 368 | static void cfhsi_tx_done(struct cfhsi *cfhsi) |
| 369 | { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 370 | netdev_dbg(cfhsi->ndev, "%s.\n", __func__); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 371 | |
| 372 | if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 373 | return; |
| 374 | |
| 375 | /* |
| 376 | * Send flow on if flow off has been previously signalled |
| 377 | * and number of packets is below low water mark. |
| 378 | */ |
| 379 | spin_lock_bh(&cfhsi->lock); |
| 380 | if (cfhsi->flow_off_sent && |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 381 | cfhsi_tx_queue_len(cfhsi) <= cfhsi->cfg.q_low_mark && |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 382 | cfhsi->cfdev.flowctrl) { |
| 383 | |
| 384 | cfhsi->flow_off_sent = 0; |
| 385 | cfhsi->cfdev.flowctrl(cfhsi->ndev, ON); |
| 386 | } |
| 387 | |
| 388 | if (cfhsi_can_send_aggregate(cfhsi)) { |
| 389 | spin_unlock_bh(&cfhsi->lock); |
| 390 | cfhsi_start_tx(cfhsi); |
| 391 | } else { |
| 392 | mod_timer(&cfhsi->aggregation_timer, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 393 | jiffies + cfhsi->cfg.aggregation_timeout); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 394 | spin_unlock_bh(&cfhsi->lock); |
| 395 | } |
| 396 | |
Dmitry Tarnyagin | fe47f12 | 2011-10-13 11:29:23 +0000 | [diff] [blame] | 397 | return; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 400 | static void cfhsi_tx_done_cb(struct cfhsi_cb_ops *cb_ops) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 401 | { |
| 402 | struct cfhsi *cfhsi; |
| 403 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 404 | cfhsi = container_of(cb_ops, struct cfhsi, cb_ops); |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 405 | netdev_dbg(cfhsi->ndev, "%s.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 406 | __func__); |
| 407 | |
| 408 | if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 409 | return; |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 410 | cfhsi_tx_done(cfhsi); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 413 | static int cfhsi_rx_desc(struct cfhsi_desc *desc, struct cfhsi *cfhsi) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 414 | { |
| 415 | int xfer_sz = 0; |
| 416 | int nfrms = 0; |
| 417 | u16 *plen = NULL; |
| 418 | u8 *pfrm = NULL; |
| 419 | |
| 420 | if ((desc->header & ~CFHSI_PIGGY_DESC) || |
| 421 | (desc->offset > CFHSI_MAX_EMB_FRM_SZ)) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 422 | netdev_err(cfhsi->ndev, "%s: Invalid descriptor.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 423 | __func__); |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 424 | return -EPROTO; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /* Check for embedded CAIF frame. */ |
| 428 | if (desc->offset) { |
| 429 | struct sk_buff *skb; |
| 430 | u8 *dst = NULL; |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 431 | int len = 0; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 432 | pfrm = ((u8 *)desc) + desc->offset; |
| 433 | |
| 434 | /* Remove offset padding. */ |
| 435 | pfrm += *pfrm + 1; |
| 436 | |
| 437 | /* Read length of CAIF frame (little endian). */ |
| 438 | len = *pfrm; |
| 439 | len |= ((*(pfrm+1)) << 8) & 0xFF00; |
| 440 | len += 2; /* Add FCS fields. */ |
| 441 | |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 442 | /* Sanity check length of CAIF frame. */ |
| 443 | if (unlikely(len > CFHSI_MAX_CAIF_FRAME_SZ)) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 444 | netdev_err(cfhsi->ndev, "%s: Invalid length.\n", |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 445 | __func__); |
| 446 | return -EPROTO; |
| 447 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 448 | |
| 449 | /* Allocate SKB (OK even in IRQ context). */ |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 450 | skb = alloc_skb(len + 1, GFP_ATOMIC); |
| 451 | if (!skb) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 452 | netdev_err(cfhsi->ndev, "%s: Out of memory !\n", |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 453 | __func__); |
| 454 | return -ENOMEM; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 455 | } |
| 456 | caif_assert(skb != NULL); |
| 457 | |
| 458 | dst = skb_put(skb, len); |
| 459 | memcpy(dst, pfrm, len); |
| 460 | |
| 461 | skb->protocol = htons(ETH_P_CAIF); |
| 462 | skb_reset_mac_header(skb); |
| 463 | skb->dev = cfhsi->ndev; |
| 464 | |
| 465 | /* |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 466 | * We are in a callback handler and |
| 467 | * unfortunately we don't know what context we're |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 468 | * running in. |
| 469 | */ |
| 470 | if (in_interrupt()) |
| 471 | netif_rx(skb); |
| 472 | else |
| 473 | netif_rx_ni(skb); |
| 474 | |
| 475 | /* Update network statistics. */ |
| 476 | cfhsi->ndev->stats.rx_packets++; |
| 477 | cfhsi->ndev->stats.rx_bytes += len; |
| 478 | } |
| 479 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 480 | /* Calculate transfer length. */ |
| 481 | plen = desc->cffrm_len; |
| 482 | while (nfrms < CFHSI_MAX_PKTS && *plen) { |
| 483 | xfer_sz += *plen; |
| 484 | plen++; |
| 485 | nfrms++; |
| 486 | } |
| 487 | |
| 488 | /* Check for piggy-backed descriptor. */ |
| 489 | if (desc->header & CFHSI_PIGGY_DESC) |
| 490 | xfer_sz += CFHSI_DESC_SZ; |
| 491 | |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 492 | if ((xfer_sz % 4) || (xfer_sz > (CFHSI_BUF_SZ_RX - CFHSI_DESC_SZ))) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 493 | netdev_err(cfhsi->ndev, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 494 | "%s: Invalid payload len: %d, ignored.\n", |
| 495 | __func__, xfer_sz); |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 496 | return -EPROTO; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 497 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 498 | return xfer_sz; |
| 499 | } |
| 500 | |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 501 | static int cfhsi_rx_desc_len(struct cfhsi_desc *desc) |
| 502 | { |
| 503 | int xfer_sz = 0; |
| 504 | int nfrms = 0; |
| 505 | u16 *plen; |
| 506 | |
| 507 | if ((desc->header & ~CFHSI_PIGGY_DESC) || |
| 508 | (desc->offset > CFHSI_MAX_EMB_FRM_SZ)) { |
| 509 | |
| 510 | pr_err("Invalid descriptor. %x %x\n", desc->header, |
| 511 | desc->offset); |
| 512 | return -EPROTO; |
| 513 | } |
| 514 | |
| 515 | /* Calculate transfer length. */ |
| 516 | plen = desc->cffrm_len; |
| 517 | while (nfrms < CFHSI_MAX_PKTS && *plen) { |
| 518 | xfer_sz += *plen; |
| 519 | plen++; |
| 520 | nfrms++; |
| 521 | } |
| 522 | |
| 523 | if (xfer_sz % 4) { |
| 524 | pr_err("Invalid payload len: %d, ignored.\n", xfer_sz); |
| 525 | return -EPROTO; |
| 526 | } |
| 527 | return xfer_sz; |
| 528 | } |
| 529 | |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 530 | static int cfhsi_rx_pld(struct cfhsi_desc *desc, struct cfhsi *cfhsi) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 531 | { |
| 532 | int rx_sz = 0; |
| 533 | int nfrms = 0; |
| 534 | u16 *plen = NULL; |
| 535 | u8 *pfrm = NULL; |
| 536 | |
| 537 | /* Sanity check header and offset. */ |
| 538 | if (WARN_ON((desc->header & ~CFHSI_PIGGY_DESC) || |
| 539 | (desc->offset > CFHSI_MAX_EMB_FRM_SZ))) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 540 | netdev_err(cfhsi->ndev, "%s: Invalid descriptor.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 541 | __func__); |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 542 | return -EPROTO; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /* Set frame pointer to start of payload. */ |
| 546 | pfrm = desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ; |
| 547 | plen = desc->cffrm_len; |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 548 | |
| 549 | /* Skip already processed frames. */ |
| 550 | while (nfrms < cfhsi->rx_state.nfrms) { |
| 551 | pfrm += *plen; |
| 552 | rx_sz += *plen; |
| 553 | plen++; |
| 554 | nfrms++; |
| 555 | } |
| 556 | |
| 557 | /* Parse payload. */ |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 558 | while (nfrms < CFHSI_MAX_PKTS && *plen) { |
| 559 | struct sk_buff *skb; |
| 560 | u8 *dst = NULL; |
| 561 | u8 *pcffrm = NULL; |
Sjur Brændeland | b42f7b5 | 2012-06-25 07:49:39 +0000 | [diff] [blame] | 562 | int len; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 563 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 564 | /* CAIF frame starts after head padding. */ |
| 565 | pcffrm = pfrm + *pfrm + 1; |
| 566 | |
| 567 | /* Read length of CAIF frame (little endian). */ |
| 568 | len = *pcffrm; |
| 569 | len |= ((*(pcffrm + 1)) << 8) & 0xFF00; |
| 570 | len += 2; /* Add FCS fields. */ |
| 571 | |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 572 | /* Sanity check length of CAIF frames. */ |
| 573 | if (unlikely(len > CFHSI_MAX_CAIF_FRAME_SZ)) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 574 | netdev_err(cfhsi->ndev, "%s: Invalid length.\n", |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 575 | __func__); |
| 576 | return -EPROTO; |
| 577 | } |
| 578 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 579 | /* Allocate SKB (OK even in IRQ context). */ |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 580 | skb = alloc_skb(len + 1, GFP_ATOMIC); |
| 581 | if (!skb) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 582 | netdev_err(cfhsi->ndev, "%s: Out of memory !\n", |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 583 | __func__); |
| 584 | cfhsi->rx_state.nfrms = nfrms; |
| 585 | return -ENOMEM; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 586 | } |
| 587 | caif_assert(skb != NULL); |
| 588 | |
| 589 | dst = skb_put(skb, len); |
| 590 | memcpy(dst, pcffrm, len); |
| 591 | |
| 592 | skb->protocol = htons(ETH_P_CAIF); |
| 593 | skb_reset_mac_header(skb); |
| 594 | skb->dev = cfhsi->ndev; |
| 595 | |
| 596 | /* |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 597 | * We're called in callback from HSI |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 598 | * and don't know the context we're running in. |
| 599 | */ |
| 600 | if (in_interrupt()) |
| 601 | netif_rx(skb); |
| 602 | else |
| 603 | netif_rx_ni(skb); |
| 604 | |
| 605 | /* Update network statistics. */ |
| 606 | cfhsi->ndev->stats.rx_packets++; |
| 607 | cfhsi->ndev->stats.rx_bytes += len; |
| 608 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 609 | pfrm += *plen; |
| 610 | rx_sz += *plen; |
| 611 | plen++; |
| 612 | nfrms++; |
| 613 | } |
| 614 | |
| 615 | return rx_sz; |
| 616 | } |
| 617 | |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 618 | static void cfhsi_rx_done(struct cfhsi *cfhsi) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 619 | { |
| 620 | int res; |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 621 | int desc_pld_len = 0, rx_len, rx_state; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 622 | struct cfhsi_desc *desc = NULL; |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 623 | u8 *rx_ptr, *rx_buf; |
| 624 | struct cfhsi_desc *piggy_desc = NULL; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 625 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 626 | desc = (struct cfhsi_desc *)cfhsi->rx_buf; |
| 627 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 628 | netdev_dbg(cfhsi->ndev, "%s\n", __func__); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 629 | |
| 630 | if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 631 | return; |
| 632 | |
| 633 | /* Update inactivity timer if pending. */ |
Dmitry Tarnyagin | 73033c9 | 2011-10-13 11:29:24 +0000 | [diff] [blame] | 634 | spin_lock_bh(&cfhsi->lock); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 635 | mod_timer_pending(&cfhsi->inactivity_timer, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 636 | jiffies + cfhsi->cfg.inactivity_timeout); |
Dmitry Tarnyagin | 73033c9 | 2011-10-13 11:29:24 +0000 | [diff] [blame] | 637 | spin_unlock_bh(&cfhsi->lock); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 638 | |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 639 | if (cfhsi->rx_state.state == CFHSI_RX_STATE_DESC) { |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 640 | desc_pld_len = cfhsi_rx_desc_len(desc); |
| 641 | |
| 642 | if (desc_pld_len < 0) |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 643 | goto out_of_sync; |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 644 | |
| 645 | rx_buf = cfhsi->rx_buf; |
| 646 | rx_len = desc_pld_len; |
| 647 | if (desc_pld_len > 0 && (desc->header & CFHSI_PIGGY_DESC)) |
| 648 | rx_len += CFHSI_DESC_SZ; |
| 649 | if (desc_pld_len == 0) |
| 650 | rx_buf = cfhsi->rx_flip_buf; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 651 | } else { |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 652 | rx_buf = cfhsi->rx_flip_buf; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 653 | |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 654 | rx_len = CFHSI_DESC_SZ; |
| 655 | if (cfhsi->rx_state.pld_len > 0 && |
| 656 | (desc->header & CFHSI_PIGGY_DESC)) { |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 657 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 658 | piggy_desc = (struct cfhsi_desc *) |
| 659 | (desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ + |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 660 | cfhsi->rx_state.pld_len); |
| 661 | |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 662 | cfhsi->rx_state.piggy_desc = true; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 663 | |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 664 | /* Extract payload len from piggy-backed descriptor. */ |
| 665 | desc_pld_len = cfhsi_rx_desc_len(piggy_desc); |
| 666 | if (desc_pld_len < 0) |
| 667 | goto out_of_sync; |
| 668 | |
Kim Lilliestierna XX | 4e7bb59 | 2012-06-25 07:49:36 +0000 | [diff] [blame] | 669 | if (desc_pld_len > 0) { |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 670 | rx_len = desc_pld_len; |
Kim Lilliestierna XX | 4e7bb59 | 2012-06-25 07:49:36 +0000 | [diff] [blame] | 671 | if (piggy_desc->header & CFHSI_PIGGY_DESC) |
| 672 | rx_len += CFHSI_DESC_SZ; |
| 673 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 674 | |
| 675 | /* |
| 676 | * Copy needed information from the piggy-backed |
| 677 | * descriptor to the descriptor in the start. |
| 678 | */ |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 679 | memcpy(rx_buf, (u8 *)piggy_desc, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 680 | CFHSI_DESC_SHORT_SZ); |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 681 | } |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 684 | if (desc_pld_len) { |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 685 | rx_state = CFHSI_RX_STATE_PAYLOAD; |
| 686 | rx_ptr = rx_buf + CFHSI_DESC_SZ; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 687 | } else { |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 688 | rx_state = CFHSI_RX_STATE_DESC; |
| 689 | rx_ptr = rx_buf; |
| 690 | rx_len = CFHSI_DESC_SZ; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 691 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 692 | |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 693 | /* Initiate next read */ |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 694 | if (test_bit(CFHSI_AWAKE, &cfhsi->bits)) { |
| 695 | /* Set up new transfer. */ |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 696 | netdev_dbg(cfhsi->ndev, "%s: Start RX.\n", |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 697 | __func__); |
| 698 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 699 | res = cfhsi->ops->cfhsi_rx(rx_ptr, rx_len, |
| 700 | cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 701 | if (WARN_ON(res < 0)) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 702 | netdev_err(cfhsi->ndev, "%s: RX error %d.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 703 | __func__, res); |
| 704 | cfhsi->ndev->stats.rx_errors++; |
| 705 | cfhsi->ndev->stats.rx_dropped++; |
| 706 | } |
| 707 | } |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 708 | |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 709 | if (cfhsi->rx_state.state == CFHSI_RX_STATE_DESC) { |
| 710 | /* Extract payload from descriptor */ |
| 711 | if (cfhsi_rx_desc(desc, cfhsi) < 0) |
| 712 | goto out_of_sync; |
| 713 | } else { |
| 714 | /* Extract payload */ |
| 715 | if (cfhsi_rx_pld(desc, cfhsi) < 0) |
| 716 | goto out_of_sync; |
| 717 | if (piggy_desc) { |
| 718 | /* Extract any payload in piggyback descriptor. */ |
| 719 | if (cfhsi_rx_desc(piggy_desc, cfhsi) < 0) |
| 720 | goto out_of_sync; |
Per Ellefsen | 3935600 | 2012-06-24 11:01:37 +0000 | [diff] [blame] | 721 | /* Mark no embedded frame after extracting it */ |
| 722 | piggy_desc->offset = 0; |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 723 | } |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 724 | } |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 725 | |
| 726 | /* Update state info */ |
| 727 | memset(&cfhsi->rx_state, 0, sizeof(cfhsi->rx_state)); |
| 728 | cfhsi->rx_state.state = rx_state; |
| 729 | cfhsi->rx_ptr = rx_ptr; |
| 730 | cfhsi->rx_len = rx_len; |
| 731 | cfhsi->rx_state.pld_len = desc_pld_len; |
| 732 | cfhsi->rx_state.piggy_desc = desc->header & CFHSI_PIGGY_DESC; |
| 733 | |
| 734 | if (rx_buf != cfhsi->rx_buf) |
| 735 | swap(cfhsi->rx_buf, cfhsi->rx_flip_buf); |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 736 | return; |
| 737 | |
| 738 | out_of_sync: |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 739 | netdev_err(cfhsi->ndev, "%s: Out of sync.\n", __func__); |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 740 | print_hex_dump_bytes("--> ", DUMP_PREFIX_NONE, |
| 741 | cfhsi->rx_buf, CFHSI_DESC_SZ); |
| 742 | schedule_work(&cfhsi->out_of_sync_work); |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | static void cfhsi_rx_slowpath(unsigned long arg) |
| 746 | { |
| 747 | struct cfhsi *cfhsi = (struct cfhsi *)arg; |
| 748 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 749 | netdev_dbg(cfhsi->ndev, "%s.\n", |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 750 | __func__); |
| 751 | |
| 752 | cfhsi_rx_done(cfhsi); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 755 | static void cfhsi_rx_done_cb(struct cfhsi_cb_ops *cb_ops) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 756 | { |
| 757 | struct cfhsi *cfhsi; |
| 758 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 759 | cfhsi = container_of(cb_ops, struct cfhsi, cb_ops); |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 760 | netdev_dbg(cfhsi->ndev, "%s.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 761 | __func__); |
| 762 | |
| 763 | if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 764 | return; |
| 765 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 766 | if (test_and_clear_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits)) |
| 767 | wake_up_interruptible(&cfhsi->flush_fifo_wait); |
| 768 | else |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 769 | cfhsi_rx_done(cfhsi); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static void cfhsi_wake_up(struct work_struct *work) |
| 773 | { |
| 774 | struct cfhsi *cfhsi = NULL; |
| 775 | int res; |
| 776 | int len; |
| 777 | long ret; |
| 778 | |
| 779 | cfhsi = container_of(work, struct cfhsi, wake_up_work); |
| 780 | |
| 781 | if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 782 | return; |
| 783 | |
| 784 | if (unlikely(test_bit(CFHSI_AWAKE, &cfhsi->bits))) { |
| 785 | /* It happenes when wakeup is requested by |
| 786 | * both ends at the same time. */ |
| 787 | clear_bit(CFHSI_WAKE_UP, &cfhsi->bits); |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 788 | clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 789 | return; |
| 790 | } |
| 791 | |
| 792 | /* Activate wake line. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 793 | cfhsi->ops->cfhsi_wake_up(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 794 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 795 | netdev_dbg(cfhsi->ndev, "%s: Start waiting.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 796 | __func__); |
| 797 | |
| 798 | /* Wait for acknowledge. */ |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 799 | ret = CFHSI_WAKE_TOUT; |
| 800 | ret = wait_event_interruptible_timeout(cfhsi->wake_up_wait, |
| 801 | test_and_clear_bit(CFHSI_WAKE_UP_ACK, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 802 | &cfhsi->bits), ret); |
| 803 | if (unlikely(ret < 0)) { |
| 804 | /* Interrupted by signal. */ |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 805 | netdev_err(cfhsi->ndev, "%s: Signalled: %ld.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 806 | __func__, ret); |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 807 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 808 | clear_bit(CFHSI_WAKE_UP, &cfhsi->bits); |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 809 | cfhsi->ops->cfhsi_wake_down(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 810 | return; |
| 811 | } else if (!ret) { |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 812 | bool ca_wake = false; |
| 813 | size_t fifo_occupancy = 0; |
| 814 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 815 | /* Wakeup timeout */ |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 816 | netdev_dbg(cfhsi->ndev, "%s: Timeout.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 817 | __func__); |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 818 | |
| 819 | /* Check FIFO to check if modem has sent something. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 820 | WARN_ON(cfhsi->ops->cfhsi_fifo_occupancy(cfhsi->ops, |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 821 | &fifo_occupancy)); |
| 822 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 823 | netdev_dbg(cfhsi->ndev, "%s: Bytes in FIFO: %u.\n", |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 824 | __func__, (unsigned) fifo_occupancy); |
| 825 | |
| 826 | /* Check if we misssed the interrupt. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 827 | WARN_ON(cfhsi->ops->cfhsi_get_peer_wake(cfhsi->ops, |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 828 | &ca_wake)); |
| 829 | |
| 830 | if (ca_wake) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 831 | netdev_err(cfhsi->ndev, "%s: CA Wake missed !.\n", |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 832 | __func__); |
| 833 | |
| 834 | /* Clear the CFHSI_WAKE_UP_ACK bit to prevent race. */ |
| 835 | clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits); |
| 836 | |
| 837 | /* Continue execution. */ |
| 838 | goto wake_ack; |
| 839 | } |
| 840 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 841 | clear_bit(CFHSI_WAKE_UP, &cfhsi->bits); |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 842 | cfhsi->ops->cfhsi_wake_down(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 843 | return; |
| 844 | } |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 845 | wake_ack: |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 846 | netdev_dbg(cfhsi->ndev, "%s: Woken.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 847 | __func__); |
| 848 | |
| 849 | /* Clear power up bit. */ |
| 850 | set_bit(CFHSI_AWAKE, &cfhsi->bits); |
| 851 | clear_bit(CFHSI_WAKE_UP, &cfhsi->bits); |
| 852 | |
| 853 | /* Resume read operation. */ |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 854 | netdev_dbg(cfhsi->ndev, "%s: Start RX.\n", __func__); |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 855 | res = cfhsi->ops->cfhsi_rx(cfhsi->rx_ptr, cfhsi->rx_len, cfhsi->ops); |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 856 | |
| 857 | if (WARN_ON(res < 0)) |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 858 | netdev_err(cfhsi->ndev, "%s: RX err %d.\n", __func__, res); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 859 | |
| 860 | /* Clear power up acknowledment. */ |
| 861 | clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits); |
| 862 | |
| 863 | spin_lock_bh(&cfhsi->lock); |
| 864 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 865 | /* Resume transmit if queues are not empty. */ |
| 866 | if (!cfhsi_tx_queue_len(cfhsi)) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 867 | netdev_dbg(cfhsi->ndev, "%s: Peer wake, start timer.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 868 | __func__); |
| 869 | /* Start inactivity timer. */ |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 870 | mod_timer(&cfhsi->inactivity_timer, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 871 | jiffies + cfhsi->cfg.inactivity_timeout); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 872 | spin_unlock_bh(&cfhsi->lock); |
| 873 | return; |
| 874 | } |
| 875 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 876 | netdev_dbg(cfhsi->ndev, "%s: Host wake.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 877 | __func__); |
| 878 | |
| 879 | spin_unlock_bh(&cfhsi->lock); |
| 880 | |
| 881 | /* Create HSI frame. */ |
| 882 | len = cfhsi_tx_frm((struct cfhsi_desc *)cfhsi->tx_buf, cfhsi); |
| 883 | |
| 884 | if (likely(len > 0)) { |
| 885 | /* Set up new transfer. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 886 | res = cfhsi->ops->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 887 | if (WARN_ON(res < 0)) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 888 | netdev_err(cfhsi->ndev, "%s: TX error %d.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 889 | __func__, res); |
| 890 | cfhsi_abort_tx(cfhsi); |
| 891 | } |
| 892 | } else { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 893 | netdev_err(cfhsi->ndev, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 894 | "%s: Failed to create HSI frame: %d.\n", |
| 895 | __func__, len); |
| 896 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | static void cfhsi_wake_down(struct work_struct *work) |
| 900 | { |
| 901 | long ret; |
| 902 | struct cfhsi *cfhsi = NULL; |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 903 | size_t fifo_occupancy = 0; |
| 904 | int retry = CFHSI_WAKE_TOUT; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 905 | |
| 906 | cfhsi = container_of(work, struct cfhsi, wake_down_work); |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 907 | netdev_dbg(cfhsi->ndev, "%s.\n", __func__); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 908 | |
| 909 | if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 910 | return; |
| 911 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 912 | /* Deactivate wake line. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 913 | cfhsi->ops->cfhsi_wake_down(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 914 | |
| 915 | /* Wait for acknowledge. */ |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 916 | ret = CFHSI_WAKE_TOUT; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 917 | ret = wait_event_interruptible_timeout(cfhsi->wake_down_wait, |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 918 | test_and_clear_bit(CFHSI_WAKE_DOWN_ACK, |
| 919 | &cfhsi->bits), ret); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 920 | if (ret < 0) { |
| 921 | /* Interrupted by signal. */ |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 922 | netdev_err(cfhsi->ndev, "%s: Signalled: %ld.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 923 | __func__, ret); |
| 924 | return; |
| 925 | } else if (!ret) { |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 926 | bool ca_wake = true; |
| 927 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 928 | /* Timeout */ |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 929 | netdev_err(cfhsi->ndev, "%s: Timeout.\n", __func__); |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 930 | |
| 931 | /* Check if we misssed the interrupt. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 932 | WARN_ON(cfhsi->ops->cfhsi_get_peer_wake(cfhsi->ops, |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 933 | &ca_wake)); |
| 934 | if (!ca_wake) |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 935 | netdev_err(cfhsi->ndev, "%s: CA Wake missed !.\n", |
Daniel Martensson | 5ea2ef5 | 2011-10-13 11:29:29 +0000 | [diff] [blame] | 936 | __func__); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 939 | /* Check FIFO occupancy. */ |
| 940 | while (retry) { |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 941 | WARN_ON(cfhsi->ops->cfhsi_fifo_occupancy(cfhsi->ops, |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 942 | &fifo_occupancy)); |
| 943 | |
| 944 | if (!fifo_occupancy) |
| 945 | break; |
| 946 | |
| 947 | set_current_state(TASK_INTERRUPTIBLE); |
| 948 | schedule_timeout(1); |
| 949 | retry--; |
| 950 | } |
| 951 | |
| 952 | if (!retry) |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 953 | netdev_err(cfhsi->ndev, "%s: FIFO Timeout.\n", __func__); |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 954 | |
| 955 | /* Clear AWAKE condition. */ |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 956 | clear_bit(CFHSI_AWAKE, &cfhsi->bits); |
| 957 | |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 958 | /* Cancel pending RX requests. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 959 | cfhsi->ops->cfhsi_rx_cancel(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 962 | static void cfhsi_out_of_sync(struct work_struct *work) |
| 963 | { |
| 964 | struct cfhsi *cfhsi = NULL; |
| 965 | |
| 966 | cfhsi = container_of(work, struct cfhsi, out_of_sync_work); |
| 967 | |
| 968 | rtnl_lock(); |
| 969 | dev_close(cfhsi->ndev); |
| 970 | rtnl_unlock(); |
| 971 | } |
| 972 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 973 | static void cfhsi_wake_up_cb(struct cfhsi_cb_ops *cb_ops) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 974 | { |
| 975 | struct cfhsi *cfhsi = NULL; |
| 976 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 977 | cfhsi = container_of(cb_ops, struct cfhsi, cb_ops); |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 978 | netdev_dbg(cfhsi->ndev, "%s.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 979 | __func__); |
| 980 | |
| 981 | set_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits); |
| 982 | wake_up_interruptible(&cfhsi->wake_up_wait); |
| 983 | |
| 984 | if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits)) |
| 985 | return; |
| 986 | |
| 987 | /* Schedule wake up work queue if the peer initiates. */ |
| 988 | if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits)) |
| 989 | queue_work(cfhsi->wq, &cfhsi->wake_up_work); |
| 990 | } |
| 991 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 992 | static void cfhsi_wake_down_cb(struct cfhsi_cb_ops *cb_ops) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 993 | { |
| 994 | struct cfhsi *cfhsi = NULL; |
| 995 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 996 | cfhsi = container_of(cb_ops, struct cfhsi, cb_ops); |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 997 | netdev_dbg(cfhsi->ndev, "%s.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 998 | __func__); |
| 999 | |
| 1000 | /* Initiating low power is only permitted by the host (us). */ |
| 1001 | set_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits); |
| 1002 | wake_up_interruptible(&cfhsi->wake_down_wait); |
| 1003 | } |
| 1004 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1005 | static void cfhsi_aggregation_tout(unsigned long arg) |
| 1006 | { |
| 1007 | struct cfhsi *cfhsi = (struct cfhsi *)arg; |
| 1008 | |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 1009 | netdev_dbg(cfhsi->ndev, "%s.\n", |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1010 | __func__); |
| 1011 | |
| 1012 | cfhsi_start_tx(cfhsi); |
| 1013 | } |
| 1014 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1015 | static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1016 | { |
| 1017 | struct cfhsi *cfhsi = NULL; |
| 1018 | int start_xfer = 0; |
| 1019 | int timer_active; |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1020 | int prio; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1021 | |
| 1022 | if (!dev) |
| 1023 | return -EINVAL; |
| 1024 | |
| 1025 | cfhsi = netdev_priv(dev); |
| 1026 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1027 | switch (skb->priority) { |
| 1028 | case TC_PRIO_BESTEFFORT: |
| 1029 | case TC_PRIO_FILLER: |
| 1030 | case TC_PRIO_BULK: |
| 1031 | prio = CFHSI_PRIO_BEBK; |
| 1032 | break; |
| 1033 | case TC_PRIO_INTERACTIVE_BULK: |
| 1034 | prio = CFHSI_PRIO_VI; |
| 1035 | break; |
| 1036 | case TC_PRIO_INTERACTIVE: |
| 1037 | prio = CFHSI_PRIO_VO; |
| 1038 | break; |
| 1039 | case TC_PRIO_CONTROL: |
| 1040 | default: |
| 1041 | prio = CFHSI_PRIO_CTL; |
| 1042 | break; |
| 1043 | } |
| 1044 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1045 | spin_lock_bh(&cfhsi->lock); |
| 1046 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1047 | /* Update aggregation statistics */ |
| 1048 | cfhsi_update_aggregation_stats(cfhsi, skb, 1); |
| 1049 | |
| 1050 | /* Queue the SKB */ |
| 1051 | skb_queue_tail(&cfhsi->qhead[prio], skb); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1052 | |
| 1053 | /* Sanity check; xmit should not be called after unregister_netdev */ |
| 1054 | if (WARN_ON(test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))) { |
| 1055 | spin_unlock_bh(&cfhsi->lock); |
| 1056 | cfhsi_abort_tx(cfhsi); |
| 1057 | return -EINVAL; |
| 1058 | } |
| 1059 | |
| 1060 | /* Send flow off if number of packets is above high water mark. */ |
| 1061 | if (!cfhsi->flow_off_sent && |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1062 | cfhsi_tx_queue_len(cfhsi) > cfhsi->cfg.q_high_mark && |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1063 | cfhsi->cfdev.flowctrl) { |
| 1064 | cfhsi->flow_off_sent = 1; |
| 1065 | cfhsi->cfdev.flowctrl(cfhsi->ndev, OFF); |
| 1066 | } |
| 1067 | |
| 1068 | if (cfhsi->tx_state == CFHSI_TX_STATE_IDLE) { |
| 1069 | cfhsi->tx_state = CFHSI_TX_STATE_XFER; |
| 1070 | start_xfer = 1; |
| 1071 | } |
| 1072 | |
Dmitry Tarnyagin | 73033c9 | 2011-10-13 11:29:24 +0000 | [diff] [blame] | 1073 | if (!start_xfer) { |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1074 | /* Send aggregate if it is possible */ |
| 1075 | bool aggregate_ready = |
| 1076 | cfhsi_can_send_aggregate(cfhsi) && |
| 1077 | del_timer(&cfhsi->aggregation_timer) > 0; |
Dmitry Tarnyagin | 73033c9 | 2011-10-13 11:29:24 +0000 | [diff] [blame] | 1078 | spin_unlock_bh(&cfhsi->lock); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1079 | if (aggregate_ready) |
| 1080 | cfhsi_start_tx(cfhsi); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1081 | return 0; |
Dmitry Tarnyagin | 73033c9 | 2011-10-13 11:29:24 +0000 | [diff] [blame] | 1082 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1083 | |
| 1084 | /* Delete inactivity timer if started. */ |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1085 | timer_active = del_timer_sync(&cfhsi->inactivity_timer); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1086 | |
Dmitry Tarnyagin | 73033c9 | 2011-10-13 11:29:24 +0000 | [diff] [blame] | 1087 | spin_unlock_bh(&cfhsi->lock); |
| 1088 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1089 | if (timer_active) { |
| 1090 | struct cfhsi_desc *desc = (struct cfhsi_desc *)cfhsi->tx_buf; |
| 1091 | int len; |
| 1092 | int res; |
| 1093 | |
| 1094 | /* Create HSI frame. */ |
| 1095 | len = cfhsi_tx_frm(desc, cfhsi); |
Roar Førde | f84ea77 | 2011-12-06 12:15:44 +0000 | [diff] [blame] | 1096 | WARN_ON(!len); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* Set up new transfer. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1099 | res = cfhsi->ops->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1100 | if (WARN_ON(res < 0)) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 1101 | netdev_err(cfhsi->ndev, "%s: TX error %d.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1102 | __func__, res); |
| 1103 | cfhsi_abort_tx(cfhsi); |
| 1104 | } |
| 1105 | } else { |
| 1106 | /* Schedule wake up work queue if the we initiate. */ |
| 1107 | if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits)) |
| 1108 | queue_work(cfhsi->wq, &cfhsi->wake_up_work); |
| 1109 | } |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1114 | static const struct net_device_ops cfhsi_netdevops; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1115 | |
| 1116 | static void cfhsi_setup(struct net_device *dev) |
| 1117 | { |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1118 | int i; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1119 | struct cfhsi *cfhsi = netdev_priv(dev); |
| 1120 | dev->features = 0; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1121 | dev->type = ARPHRD_CAIF; |
| 1122 | dev->flags = IFF_POINTOPOINT | IFF_NOARP; |
Sjur Brændeland | 34efc28 | 2012-03-04 08:38:58 +0000 | [diff] [blame] | 1123 | dev->mtu = CFHSI_MAX_CAIF_FRAME_SZ; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1124 | dev->tx_queue_len = 0; |
| 1125 | dev->destructor = free_netdev; |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1126 | dev->netdev_ops = &cfhsi_netdevops; |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1127 | for (i = 0; i < CFHSI_PRIO_LAST; ++i) |
| 1128 | skb_queue_head_init(&cfhsi->qhead[i]); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1129 | cfhsi->cfdev.link_select = CAIF_LINK_HIGH_BANDW; |
| 1130 | cfhsi->cfdev.use_frag = false; |
| 1131 | cfhsi->cfdev.use_stx = false; |
| 1132 | cfhsi->cfdev.use_fcs = false; |
| 1133 | cfhsi->ndev = dev; |
Sjur Brændeland | 7fa8ad6 | 2012-06-28 20:36:20 +0000 | [diff] [blame] | 1134 | cfhsi->cfg = hsi_default_config; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
sjur.brandeland@stericsson.com | 39abbae | 2012-04-12 08:27:27 +0000 | [diff] [blame] | 1137 | static int cfhsi_open(struct net_device *ndev) |
| 1138 | { |
| 1139 | struct cfhsi *cfhsi = netdev_priv(ndev); |
| 1140 | int res; |
| 1141 | |
| 1142 | clear_bit(CFHSI_SHUTDOWN, &cfhsi->bits); |
| 1143 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1144 | /* Initialize state vaiables. */ |
| 1145 | cfhsi->tx_state = CFHSI_TX_STATE_IDLE; |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 1146 | cfhsi->rx_state.state = CFHSI_RX_STATE_DESC; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1147 | |
| 1148 | /* Set flow info */ |
| 1149 | cfhsi->flow_off_sent = 0; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1150 | |
| 1151 | /* |
| 1152 | * Allocate a TX buffer with the size of a HSI packet descriptors |
| 1153 | * and the necessary room for CAIF payload frames. |
| 1154 | */ |
| 1155 | cfhsi->tx_buf = kzalloc(CFHSI_BUF_SZ_TX, GFP_KERNEL); |
| 1156 | if (!cfhsi->tx_buf) { |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1157 | res = -ENODEV; |
| 1158 | goto err_alloc_tx; |
| 1159 | } |
| 1160 | |
| 1161 | /* |
| 1162 | * Allocate a RX buffer with the size of two HSI packet descriptors and |
| 1163 | * the necessary room for CAIF payload frames. |
| 1164 | */ |
| 1165 | cfhsi->rx_buf = kzalloc(CFHSI_BUF_SZ_RX, GFP_KERNEL); |
| 1166 | if (!cfhsi->rx_buf) { |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1167 | res = -ENODEV; |
| 1168 | goto err_alloc_rx; |
| 1169 | } |
| 1170 | |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 1171 | cfhsi->rx_flip_buf = kzalloc(CFHSI_BUF_SZ_RX, GFP_KERNEL); |
| 1172 | if (!cfhsi->rx_flip_buf) { |
| 1173 | res = -ENODEV; |
| 1174 | goto err_alloc_rx_flip; |
| 1175 | } |
| 1176 | |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1177 | /* Initialize aggregation timeout */ |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1178 | cfhsi->cfg.aggregation_timeout = hsi_default_config.aggregation_timeout; |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1179 | |
Dmitry Tarnyagin | 28bd204 | 2011-10-13 11:29:27 +0000 | [diff] [blame] | 1180 | /* Initialize recieve vaiables. */ |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1181 | cfhsi->rx_ptr = cfhsi->rx_buf; |
| 1182 | cfhsi->rx_len = CFHSI_DESC_SZ; |
| 1183 | |
| 1184 | /* Initialize spin locks. */ |
| 1185 | spin_lock_init(&cfhsi->lock); |
| 1186 | |
| 1187 | /* Set up the driver. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1188 | cfhsi->cb_ops.tx_done_cb = cfhsi_tx_done_cb; |
| 1189 | cfhsi->cb_ops.rx_done_cb = cfhsi_rx_done_cb; |
| 1190 | cfhsi->cb_ops.wake_up_cb = cfhsi_wake_up_cb; |
| 1191 | cfhsi->cb_ops.wake_down_cb = cfhsi_wake_down_cb; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1192 | |
| 1193 | /* Initialize the work queues. */ |
| 1194 | INIT_WORK(&cfhsi->wake_up_work, cfhsi_wake_up); |
| 1195 | INIT_WORK(&cfhsi->wake_down_work, cfhsi_wake_down); |
Daniel Martensson | 5bbed92 | 2011-10-13 11:29:28 +0000 | [diff] [blame] | 1196 | INIT_WORK(&cfhsi->out_of_sync_work, cfhsi_out_of_sync); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1197 | |
| 1198 | /* Clear all bit fields. */ |
| 1199 | clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits); |
| 1200 | clear_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits); |
| 1201 | clear_bit(CFHSI_WAKE_UP, &cfhsi->bits); |
| 1202 | clear_bit(CFHSI_AWAKE, &cfhsi->bits); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1203 | |
| 1204 | /* Create work thread. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1205 | cfhsi->wq = create_singlethread_workqueue(cfhsi->ndev->name); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1206 | if (!cfhsi->wq) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 1207 | netdev_err(cfhsi->ndev, "%s: Failed to create work queue.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1208 | __func__); |
| 1209 | res = -ENODEV; |
| 1210 | goto err_create_wq; |
| 1211 | } |
| 1212 | |
| 1213 | /* Initialize wait queues. */ |
| 1214 | init_waitqueue_head(&cfhsi->wake_up_wait); |
| 1215 | init_waitqueue_head(&cfhsi->wake_down_wait); |
| 1216 | init_waitqueue_head(&cfhsi->flush_fifo_wait); |
| 1217 | |
| 1218 | /* Setup the inactivity timer. */ |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1219 | init_timer(&cfhsi->inactivity_timer); |
| 1220 | cfhsi->inactivity_timer.data = (unsigned long)cfhsi; |
| 1221 | cfhsi->inactivity_timer.function = cfhsi_inactivity_tout; |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 1222 | /* Setup the slowpath RX timer. */ |
| 1223 | init_timer(&cfhsi->rx_slowpath_timer); |
| 1224 | cfhsi->rx_slowpath_timer.data = (unsigned long)cfhsi; |
| 1225 | cfhsi->rx_slowpath_timer.function = cfhsi_rx_slowpath; |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1226 | /* Setup the aggregation timer. */ |
| 1227 | init_timer(&cfhsi->aggregation_timer); |
| 1228 | cfhsi->aggregation_timer.data = (unsigned long)cfhsi; |
| 1229 | cfhsi->aggregation_timer.function = cfhsi_aggregation_tout; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1230 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1231 | /* Activate HSI interface. */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1232 | res = cfhsi->ops->cfhsi_up(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1233 | if (res) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 1234 | netdev_err(cfhsi->ndev, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1235 | "%s: can't activate HSI interface: %d.\n", |
| 1236 | __func__, res); |
| 1237 | goto err_activate; |
| 1238 | } |
| 1239 | |
| 1240 | /* Flush FIFO */ |
| 1241 | res = cfhsi_flush_fifo(cfhsi); |
| 1242 | if (res) { |
Sjur Brændeland | 90de9bab | 2012-06-25 07:49:38 +0000 | [diff] [blame] | 1243 | netdev_err(cfhsi->ndev, "%s: Can't flush FIFO: %d.\n", |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1244 | __func__, res); |
| 1245 | goto err_net_reg; |
| 1246 | } |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1247 | return res; |
| 1248 | |
| 1249 | err_net_reg: |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1250 | cfhsi->ops->cfhsi_down(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1251 | err_activate: |
| 1252 | destroy_workqueue(cfhsi->wq); |
| 1253 | err_create_wq: |
sjur.brandeland@stericsson.com | 332ad43 | 2012-02-03 04:36:21 +0000 | [diff] [blame] | 1254 | kfree(cfhsi->rx_flip_buf); |
| 1255 | err_alloc_rx_flip: |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1256 | kfree(cfhsi->rx_buf); |
| 1257 | err_alloc_rx: |
| 1258 | kfree(cfhsi->tx_buf); |
| 1259 | err_alloc_tx: |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1260 | return res; |
| 1261 | } |
| 1262 | |
sjur.brandeland@stericsson.com | 39abbae | 2012-04-12 08:27:27 +0000 | [diff] [blame] | 1263 | static int cfhsi_close(struct net_device *ndev) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1264 | { |
sjur.brandeland@stericsson.com | 39abbae | 2012-04-12 08:27:27 +0000 | [diff] [blame] | 1265 | struct cfhsi *cfhsi = netdev_priv(ndev); |
sjur.brandeland@stericsson.com | 5f614e6 | 2012-04-12 08:18:08 +0000 | [diff] [blame] | 1266 | u8 *tx_buf, *rx_buf, *flip_buf; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1267 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1268 | /* going to shutdown driver */ |
| 1269 | set_bit(CFHSI_SHUTDOWN, &cfhsi->bits); |
| 1270 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1271 | /* Flush workqueue */ |
| 1272 | flush_workqueue(cfhsi->wq); |
| 1273 | |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 1274 | /* Delete timers if pending */ |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1275 | del_timer_sync(&cfhsi->inactivity_timer); |
Daniel Martensson | 687b13e | 2011-10-13 11:29:25 +0000 | [diff] [blame] | 1276 | del_timer_sync(&cfhsi->rx_slowpath_timer); |
Dmitry Tarnyagin | ece367d | 2012-04-12 08:27:25 +0000 | [diff] [blame] | 1277 | del_timer_sync(&cfhsi->aggregation_timer); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1278 | |
| 1279 | /* Cancel pending RX request (if any) */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1280 | cfhsi->ops->cfhsi_rx_cancel(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1281 | |
Daniel Martensson | ca63f8c | 2011-10-13 11:29:26 +0000 | [diff] [blame] | 1282 | /* Destroy workqueue */ |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1283 | destroy_workqueue(cfhsi->wq); |
| 1284 | |
| 1285 | /* Store bufferes: will be freed later. */ |
| 1286 | tx_buf = cfhsi->tx_buf; |
| 1287 | rx_buf = cfhsi->rx_buf; |
sjur.brandeland@stericsson.com | 5f614e6 | 2012-04-12 08:18:08 +0000 | [diff] [blame] | 1288 | flip_buf = cfhsi->rx_flip_buf; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1289 | /* Flush transmit queues. */ |
| 1290 | cfhsi_abort_tx(cfhsi); |
| 1291 | |
| 1292 | /* Deactivate interface */ |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1293 | cfhsi->ops->cfhsi_down(cfhsi->ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1294 | |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1295 | /* Free buffers. */ |
| 1296 | kfree(tx_buf); |
| 1297 | kfree(rx_buf); |
sjur.brandeland@stericsson.com | 5f614e6 | 2012-04-12 08:18:08 +0000 | [diff] [blame] | 1298 | kfree(flip_buf); |
sjur.brandeland@stericsson.com | 39abbae | 2012-04-12 08:27:27 +0000 | [diff] [blame] | 1299 | return 0; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1302 | static void cfhsi_uninit(struct net_device *dev) |
| 1303 | { |
| 1304 | struct cfhsi *cfhsi = netdev_priv(dev); |
| 1305 | ASSERT_RTNL(); |
| 1306 | symbol_put(cfhsi_get_device); |
| 1307 | list_del(&cfhsi->list); |
| 1308 | } |
| 1309 | |
Sjur Brændeland | 1c385f1 | 2012-06-25 07:49:42 +0000 | [diff] [blame] | 1310 | static const struct net_device_ops cfhsi_netdevops = { |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1311 | .ndo_uninit = cfhsi_uninit, |
sjur.brandeland@stericsson.com | 39abbae | 2012-04-12 08:27:27 +0000 | [diff] [blame] | 1312 | .ndo_open = cfhsi_open, |
| 1313 | .ndo_stop = cfhsi_close, |
| 1314 | .ndo_start_xmit = cfhsi_xmit |
| 1315 | }; |
| 1316 | |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1317 | static void cfhsi_netlink_parms(struct nlattr *data[], struct cfhsi *cfhsi) |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1318 | { |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1319 | int i; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1320 | |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1321 | if (!data) { |
| 1322 | pr_debug("no params data found\n"); |
| 1323 | return; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1324 | } |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1325 | |
| 1326 | i = __IFLA_CAIF_HSI_INACTIVITY_TOUT; |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1327 | /* |
| 1328 | * Inactivity timeout in millisecs. Lowest possible value is 1, |
| 1329 | * and highest possible is NEXT_TIMER_MAX_DELTA. |
| 1330 | */ |
| 1331 | if (data[i]) { |
| 1332 | u32 inactivity_timeout = nla_get_u32(data[i]); |
| 1333 | /* Pre-calculate inactivity timeout. */ |
| 1334 | cfhsi->cfg.inactivity_timeout = inactivity_timeout * HZ / 1000; |
| 1335 | if (cfhsi->cfg.inactivity_timeout == 0) |
| 1336 | cfhsi->cfg.inactivity_timeout = 1; |
| 1337 | else if (cfhsi->cfg.inactivity_timeout > NEXT_TIMER_MAX_DELTA) |
| 1338 | cfhsi->cfg.inactivity_timeout = NEXT_TIMER_MAX_DELTA; |
| 1339 | } |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1340 | |
| 1341 | i = __IFLA_CAIF_HSI_AGGREGATION_TOUT; |
| 1342 | if (data[i]) |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1343 | cfhsi->cfg.aggregation_timeout = nla_get_u32(data[i]); |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1344 | |
| 1345 | i = __IFLA_CAIF_HSI_HEAD_ALIGN; |
| 1346 | if (data[i]) |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1347 | cfhsi->cfg.head_align = nla_get_u32(data[i]); |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1348 | |
| 1349 | i = __IFLA_CAIF_HSI_TAIL_ALIGN; |
| 1350 | if (data[i]) |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1351 | cfhsi->cfg.tail_align = nla_get_u32(data[i]); |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1352 | |
| 1353 | i = __IFLA_CAIF_HSI_QHIGH_WATERMARK; |
| 1354 | if (data[i]) |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1355 | cfhsi->cfg.q_high_mark = nla_get_u32(data[i]); |
| 1356 | |
| 1357 | i = __IFLA_CAIF_HSI_QLOW_WATERMARK; |
| 1358 | if (data[i]) |
| 1359 | cfhsi->cfg.q_low_mark = nla_get_u32(data[i]); |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | static int caif_hsi_changelink(struct net_device *dev, struct nlattr *tb[], |
| 1363 | struct nlattr *data[]) |
| 1364 | { |
| 1365 | cfhsi_netlink_parms(data, netdev_priv(dev)); |
| 1366 | netdev_state_change(dev); |
| 1367 | return 0; |
| 1368 | } |
| 1369 | |
| 1370 | static const struct nla_policy caif_hsi_policy[__IFLA_CAIF_HSI_MAX + 1] = { |
| 1371 | [__IFLA_CAIF_HSI_INACTIVITY_TOUT] = { .type = NLA_U32, .len = 4 }, |
| 1372 | [__IFLA_CAIF_HSI_AGGREGATION_TOUT] = { .type = NLA_U32, .len = 4 }, |
| 1373 | [__IFLA_CAIF_HSI_HEAD_ALIGN] = { .type = NLA_U32, .len = 4 }, |
| 1374 | [__IFLA_CAIF_HSI_TAIL_ALIGN] = { .type = NLA_U32, .len = 4 }, |
| 1375 | [__IFLA_CAIF_HSI_QHIGH_WATERMARK] = { .type = NLA_U32, .len = 4 }, |
| 1376 | [__IFLA_CAIF_HSI_QLOW_WATERMARK] = { .type = NLA_U32, .len = 4 }, |
| 1377 | }; |
| 1378 | |
| 1379 | static size_t caif_hsi_get_size(const struct net_device *dev) |
| 1380 | { |
| 1381 | int i; |
| 1382 | size_t s = 0; |
| 1383 | for (i = __IFLA_CAIF_HSI_UNSPEC + 1; i < __IFLA_CAIF_HSI_MAX; i++) |
| 1384 | s += nla_total_size(caif_hsi_policy[i].len); |
| 1385 | return s; |
| 1386 | } |
| 1387 | |
| 1388 | static int caif_hsi_fill_info(struct sk_buff *skb, const struct net_device *dev) |
| 1389 | { |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1390 | struct cfhsi *cfhsi = netdev_priv(dev); |
| 1391 | |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1392 | if (nla_put_u32(skb, __IFLA_CAIF_HSI_INACTIVITY_TOUT, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1393 | cfhsi->cfg.inactivity_timeout) || |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1394 | nla_put_u32(skb, __IFLA_CAIF_HSI_AGGREGATION_TOUT, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1395 | cfhsi->cfg.aggregation_timeout) || |
| 1396 | nla_put_u32(skb, __IFLA_CAIF_HSI_HEAD_ALIGN, |
| 1397 | cfhsi->cfg.head_align) || |
| 1398 | nla_put_u32(skb, __IFLA_CAIF_HSI_TAIL_ALIGN, |
| 1399 | cfhsi->cfg.tail_align) || |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1400 | nla_put_u32(skb, __IFLA_CAIF_HSI_QHIGH_WATERMARK, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1401 | cfhsi->cfg.q_high_mark) || |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1402 | nla_put_u32(skb, __IFLA_CAIF_HSI_QLOW_WATERMARK, |
Sjur Brændeland | 91fa0cb | 2012-06-25 07:49:43 +0000 | [diff] [blame] | 1403 | cfhsi->cfg.q_low_mark)) |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1404 | return -EMSGSIZE; |
| 1405 | |
| 1406 | return 0; |
| 1407 | } |
| 1408 | |
| 1409 | static int caif_hsi_newlink(struct net *src_net, struct net_device *dev, |
| 1410 | struct nlattr *tb[], struct nlattr *data[]) |
| 1411 | { |
| 1412 | struct cfhsi *cfhsi = NULL; |
Sjur Brændeland | 7fa8ad6 | 2012-06-28 20:36:20 +0000 | [diff] [blame] | 1413 | struct cfhsi_ops *(*get_ops)(void); |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1414 | |
| 1415 | ASSERT_RTNL(); |
| 1416 | |
| 1417 | cfhsi = netdev_priv(dev); |
| 1418 | cfhsi_netlink_parms(data, cfhsi); |
| 1419 | dev_net_set(cfhsi->ndev, src_net); |
| 1420 | |
Sjur Brændeland | 7fa8ad6 | 2012-06-28 20:36:20 +0000 | [diff] [blame] | 1421 | get_ops = symbol_get(cfhsi_get_ops); |
| 1422 | if (!get_ops) { |
| 1423 | pr_err("%s: failed to get the cfhsi_ops\n", __func__); |
| 1424 | return -ENODEV; |
| 1425 | } |
| 1426 | |
| 1427 | /* Assign the HSI device. */ |
| 1428 | cfhsi->ops = (*get_ops)(); |
| 1429 | if (!cfhsi->ops) { |
| 1430 | pr_err("%s: failed to get the cfhsi_ops\n", __func__); |
| 1431 | goto err; |
| 1432 | } |
| 1433 | |
| 1434 | /* Assign the driver to this HSI device. */ |
| 1435 | cfhsi->ops->cb_ops = &cfhsi->cb_ops; |
| 1436 | if (register_netdevice(dev)) { |
| 1437 | pr_warn("%s: caif_hsi device registration failed\n", __func__); |
| 1438 | goto err; |
| 1439 | } |
| 1440 | /* Add CAIF HSI device to list. */ |
| 1441 | list_add_tail(&cfhsi->list, &cfhsi_list); |
| 1442 | |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1443 | return 0; |
Sjur Brændeland | 7fa8ad6 | 2012-06-28 20:36:20 +0000 | [diff] [blame] | 1444 | err: |
| 1445 | symbol_put(cfhsi_get_ops); |
| 1446 | return -ENODEV; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1449 | static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = { |
| 1450 | .kind = "cfhsi", |
| 1451 | .priv_size = sizeof(struct cfhsi), |
| 1452 | .setup = cfhsi_setup, |
| 1453 | .maxtype = __IFLA_CAIF_HSI_MAX, |
| 1454 | .policy = caif_hsi_policy, |
| 1455 | .newlink = caif_hsi_newlink, |
| 1456 | .changelink = caif_hsi_changelink, |
| 1457 | .get_size = caif_hsi_get_size, |
| 1458 | .fill_info = caif_hsi_fill_info, |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1459 | }; |
| 1460 | |
| 1461 | static void __exit cfhsi_exit_module(void) |
| 1462 | { |
| 1463 | struct list_head *list_node; |
| 1464 | struct list_head *n; |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1465 | struct cfhsi *cfhsi; |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1466 | |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1467 | rtnl_link_unregister(&caif_hsi_link_ops); |
| 1468 | |
| 1469 | rtnl_lock(); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1470 | list_for_each_safe(list_node, n, &cfhsi_list) { |
| 1471 | cfhsi = list_entry(list_node, struct cfhsi, list); |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1472 | unregister_netdev(cfhsi->ndev); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1473 | } |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1474 | rtnl_unlock(); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | static int __init cfhsi_init_module(void) |
| 1478 | { |
Sjur Brændeland | c412540 | 2012-06-25 07:49:41 +0000 | [diff] [blame] | 1479 | return rtnl_link_register(&caif_hsi_link_ops); |
Dmitry.Tarnyagin | 40d6904 | 2011-06-01 03:29:18 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | module_init(cfhsi_init_module); |
| 1483 | module_exit(cfhsi_exit_module); |