Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 3 | * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved. |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | ************************************************************************** |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * nss_tstamp.c |
| 19 | * NSS Tstamp APIs |
| 20 | */ |
| 21 | |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 22 | #include <linux/ip.h> |
| 23 | #include <linux/ipv6.h> |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 24 | #include <linux/etherdevice.h> |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 25 | #include <linux/netdevice.h> |
| 26 | #include <net/route.h> |
| 27 | #include <net/ip6_route.h> |
| 28 | #include "nss_tx_rx_common.h" |
| 29 | #include "nss_tstamp.h" |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 30 | #include "nss_tstamp_stats.h" |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 31 | |
| 32 | #define NSS_TSTAMP_HEADER_SIZE max(sizeof(struct nss_tstamp_h2n_pre_hdr), sizeof(struct nss_tstamp_n2h_pre_hdr)) |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 33 | |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 34 | /* |
| 35 | * Notify data structure |
| 36 | */ |
| 37 | struct nss_tstamp_notify_data { |
| 38 | nss_tstamp_msg_callback_t tstamp_callback; |
| 39 | void *app_data; |
| 40 | }; |
| 41 | |
| 42 | static struct nss_tstamp_notify_data nss_tstamp_notify = { |
| 43 | .tstamp_callback = NULL, |
| 44 | .app_data = NULL, |
| 45 | }; |
| 46 | |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 47 | static struct net_device_stats *nss_tstamp_ndev_stats(struct net_device *ndev); |
| 48 | |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 49 | /* |
| 50 | * dummy netdevice ops |
| 51 | */ |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 52 | static const struct net_device_ops nss_tstamp_ndev_ops = { |
| 53 | .ndo_get_stats = nss_tstamp_ndev_stats, |
| 54 | }; |
| 55 | |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 56 | /* |
| 57 | * nss_tstamp_ndev_setup() |
| 58 | * Dummy setup for net_device handler |
| 59 | */ |
| 60 | static void nss_tstamp_ndev_setup(struct net_device *ndev) |
| 61 | { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * nss_tstamp_ndev_stats() |
| 67 | * Return net device stats |
| 68 | */ |
| 69 | static struct net_device_stats *nss_tstamp_ndev_stats(struct net_device *ndev) |
| 70 | { |
| 71 | return &ndev->stats; |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 72 | } |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 73 | |
| 74 | /* |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 75 | * nss_tstamp_verify_if_num() |
| 76 | * Verify if_num passed to us. |
| 77 | */ |
| 78 | static bool nss_tstamp_verify_if_num(uint32_t if_num) |
| 79 | { |
| 80 | return (if_num == NSS_TSTAMP_TX_INTERFACE) || (if_num == NSS_TSTAMP_RX_INTERFACE); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | /* |
| 85 | * nss_tstamp_interface_handler() |
| 86 | * Handle NSS -> HLOS messages for TSTAMP Statistics |
| 87 | */ |
| 88 | static void nss_tstamp_interface_handler(struct nss_ctx_instance *nss_ctx, |
| 89 | struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) |
| 90 | { |
| 91 | struct nss_tstamp_msg *ntm = (struct nss_tstamp_msg *)ncm; |
| 92 | nss_tstamp_msg_callback_t cb; |
| 93 | |
| 94 | if (!nss_tstamp_verify_if_num(ncm->interface)) { |
| 95 | nss_warning("%p: invalid interface %d for tstamp_tx", nss_ctx, ncm->interface); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Is this a valid request/response packet? |
| 101 | */ |
| 102 | if (ncm->type >= NSS_TSTAMP_MSG_TYPE_MAX) { |
| 103 | nss_warning("%p: received invalid message %d for tstamp", nss_ctx, ncm->type); |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_tstamp_msg)) { |
| 108 | nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm)); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * Log failures |
| 114 | */ |
| 115 | nss_core_log_msg_failures(nss_ctx, ncm); |
| 116 | |
| 117 | switch (ntm->cm.type) { |
| 118 | case NSS_TSTAMP_MSG_TYPE_SYNC_STATS: |
| 119 | nss_tstamp_stats_sync(nss_ctx, &ntm->msg.stats, ncm->interface); |
| 120 | break; |
| 121 | default: |
| 122 | nss_warning("%p: Unknown message type %d", |
| 123 | nss_ctx, ncm->type); |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Update the callback and app_data for NOTIFY messages |
| 129 | */ |
| 130 | if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) { |
| 131 | ncm->cb = (nss_ptr_t)nss_tstamp_notify.tstamp_callback; |
| 132 | ncm->app_data = (nss_ptr_t)nss_tstamp_notify.app_data; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Do we have a callback? |
| 137 | */ |
| 138 | if (!ncm->cb) { |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * callback |
| 144 | */ |
| 145 | cb = (nss_tstamp_msg_callback_t)ncm->cb; |
| 146 | cb((void *)ncm->app_data, ntm); |
| 147 | } |
| 148 | |
| 149 | /* |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 150 | * nss_tstamp_copy_data() |
| 151 | * Copy timestamps from received nss frame into skb |
| 152 | */ |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 153 | static void nss_tstamp_copy_data(struct nss_tstamp_n2h_pre_hdr *ntm, struct sk_buff *skb) |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 154 | { |
| 155 | struct skb_shared_hwtstamps *tstamp; |
| 156 | |
| 157 | tstamp = skb_hwtstamps(skb); |
| 158 | tstamp->hwtstamp = ktime_set(ntm->ts_data_hi, ntm->ts_data_lo); |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 159 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 16, 0)) |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 160 | tstamp->syststamp = ktime_set(ntm->ts_data_hi, ntm->ts_data_lo); |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 161 | #endif |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 165 | * nss_tstamp_get_dev() |
| 166 | * Get the net_device associated with the packet. |
| 167 | */ |
| 168 | static struct net_device *nss_tstamp_get_dev(struct sk_buff *skb) |
| 169 | { |
| 170 | struct dst_entry *dst; |
| 171 | struct net_device *dev; |
| 172 | struct rtable *rt; |
| 173 | struct flowi6 fl6; |
| 174 | uint32_t ip_addr; |
| 175 | |
| 176 | /* |
| 177 | * It seems like the data came over IPsec, hence indicate |
| 178 | * it to the Linux over this interface |
| 179 | */ |
| 180 | skb_reset_network_header(skb); |
| 181 | skb_reset_mac_header(skb); |
| 182 | |
| 183 | skb->pkt_type = PACKET_HOST; |
| 184 | |
| 185 | switch (ip_hdr(skb)->version) { |
| 186 | case IPVERSION: |
| 187 | ip_addr = ip_hdr(skb)->saddr; |
| 188 | |
| 189 | rt = ip_route_output(&init_net, ip_addr, 0, 0, 0); |
| 190 | if (IS_ERR(rt)) { |
| 191 | return NULL; |
| 192 | } |
| 193 | |
| 194 | dst = (struct dst_entry *)rt; |
| 195 | skb->protocol = cpu_to_be16(ETH_P_IP); |
| 196 | break; |
| 197 | |
| 198 | case 6: |
| 199 | memset(&fl6, 0, sizeof(fl6)); |
| 200 | memcpy(&fl6.daddr, &ipv6_hdr(skb)->saddr, sizeof(fl6.daddr)); |
| 201 | |
| 202 | dst = ip6_route_output(&init_net, NULL, &fl6); |
| 203 | if (IS_ERR(dst)) { |
| 204 | return NULL; |
| 205 | } |
| 206 | |
| 207 | skb->protocol = cpu_to_be16(ETH_P_IPV6); |
| 208 | break; |
| 209 | |
| 210 | default: |
| 211 | nss_warning("%p:could not get dev for the skb\n", skb); |
| 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | dev = dst->dev; |
| 216 | dev_hold(dev); |
| 217 | |
| 218 | dst_release(dst); |
| 219 | return dev; |
| 220 | } |
| 221 | |
| 222 | /* |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 223 | * nss_tstamp_buf_receive() |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 224 | * Receive nss exception packets. |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 225 | */ |
| 226 | static void nss_tstamp_buf_receive(struct net_device *ndev, struct sk_buff *skb, struct napi_struct *napi) |
| 227 | { |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 228 | struct nss_tstamp_n2h_pre_hdr *n2h_hdr = (struct nss_tstamp_n2h_pre_hdr *)skb->data; |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 229 | struct nss_ctx_instance *nss_ctx; |
Rakesh Nair | 7c43b54 | 2015-12-03 16:45:24 +0530 | [diff] [blame] | 230 | struct net_device *dev; |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 231 | uint32_t tstamp_sz; |
| 232 | |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 233 | BUG_ON(!n2h_hdr); |
| 234 | |
| 235 | tstamp_sz = n2h_hdr->ts_hdr_sz; |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 236 | if (tstamp_sz > (NSS_TSTAMP_HEADER_SIZE)) { |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 237 | goto free; |
| 238 | } |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 239 | |
| 240 | nss_ctx = &nss_top_main.nss[nss_top_main.tstamp_handler_id]; |
| 241 | BUG_ON(!nss_ctx); |
| 242 | |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 243 | skb_pull_inline(skb, tstamp_sz); |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * copy the time stamp and convert into ktime_t |
| 247 | */ |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 248 | nss_tstamp_copy_data(n2h_hdr, skb); |
| 249 | if (unlikely(n2h_hdr->ts_tx)) { |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 250 | /* |
| 251 | * We are in TX Path |
| 252 | */ |
| 253 | skb_tstamp_tx(skb, skb_hwtstamps(skb)); |
| 254 | |
| 255 | ndev->stats.tx_packets++; |
| 256 | ndev->stats.tx_bytes += skb->len; |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 257 | goto free; |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 261 | * We are in RX path. |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 262 | */ |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 263 | dev = nss_cmn_get_interface_dev(nss_ctx, n2h_hdr->ts_ifnum); |
| 264 | if (!dev) { |
| 265 | ndev->stats.rx_dropped++; |
| 266 | goto free; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * Hold the dev until we finish |
| 271 | */ |
| 272 | dev_hold(dev); |
| 273 | |
Rakesh Nair | 7c43b54 | 2015-12-03 16:45:24 +0530 | [diff] [blame] | 274 | switch(dev->type) { |
| 275 | case NSS_IPSEC_ARPHRD_IPSEC: |
| 276 | /* |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 277 | * Release the prev dev reference |
Rakesh Nair | 7c43b54 | 2015-12-03 16:45:24 +0530 | [diff] [blame] | 278 | */ |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 279 | dev_put(dev); |
Rakesh Nair | 7c43b54 | 2015-12-03 16:45:24 +0530 | [diff] [blame] | 280 | |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 281 | /* |
| 282 | * find the actual IPsec tunnel device |
| 283 | */ |
| 284 | dev = nss_tstamp_get_dev(skb); |
Rakesh Nair | 7c43b54 | 2015-12-03 16:45:24 +0530 | [diff] [blame] | 285 | break; |
| 286 | |
| 287 | default: |
| 288 | /* |
| 289 | * This is a plain non-encrypted data packet. |
| 290 | */ |
| 291 | skb->protocol = eth_type_trans(skb, dev); |
| 292 | break; |
| 293 | } |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 294 | |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 295 | skb->skb_iif = dev->ifindex; |
| 296 | skb->dev = dev; |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 297 | |
| 298 | ndev->stats.rx_packets++; |
| 299 | ndev->stats.rx_bytes += skb->len; |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 300 | |
| 301 | netif_receive_skb(skb); |
| 302 | |
| 303 | /* |
| 304 | * release the device as we are done |
| 305 | */ |
| 306 | dev_put(dev); |
| 307 | return; |
| 308 | free: |
| 309 | dev_kfree_skb_any(skb); |
| 310 | return; |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /* |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 314 | * nss_tstamp_tx_buf() |
| 315 | * Send data packet for tstamp processing |
| 316 | */ |
| 317 | nss_tx_status_t nss_tstamp_tx_buf(struct nss_ctx_instance *nss_ctx, struct sk_buff *skb, uint32_t if_num) |
| 318 | { |
| 319 | struct nss_tstamp_h2n_pre_hdr *h2n_hdr; |
| 320 | int extra_head; |
| 321 | int extra_tail = 0; |
| 322 | char *align_data; |
| 323 | uint32_t hdr_sz; |
| 324 | |
| 325 | nss_trace("%p: Tstamp If Tx packet, id:%d, data=%p", nss_ctx, NSS_TSTAMP_RX_INTERFACE, skb->data); |
| 326 | |
| 327 | /* |
| 328 | * header size + alignment size |
| 329 | */ |
| 330 | hdr_sz = NSS_TSTAMP_HEADER_SIZE; |
| 331 | extra_head = hdr_sz - skb_headroom(skb); |
| 332 | |
| 333 | /* |
| 334 | * Expand the head for h2n_hdr |
| 335 | */ |
| 336 | if (extra_head > 0) { |
| 337 | /* |
| 338 | * Try to accommodate using available tailroom. |
| 339 | */ |
| 340 | if (skb->end - skb->tail >= extra_head) |
| 341 | extra_tail = -extra_head; |
| 342 | if (pskb_expand_head(skb, extra_head, extra_tail, GFP_KERNEL)) { |
| 343 | nss_trace("%p: expand head room failed", nss_ctx); |
| 344 | return NSS_TX_FAILURE; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | align_data = PTR_ALIGN((skb->data - hdr_sz), sizeof(uint32_t)); |
| 349 | hdr_sz = (nss_ptr_t)skb->data - (nss_ptr_t)align_data; |
| 350 | |
| 351 | h2n_hdr = (struct nss_tstamp_h2n_pre_hdr *)skb_push(skb, hdr_sz); |
| 352 | h2n_hdr->ts_ifnum = if_num; |
| 353 | h2n_hdr->ts_tx_hdr_sz = hdr_sz; |
| 354 | |
Aniruddha Paul | 38d72f4 | 2019-08-20 16:51:31 +0530 | [diff] [blame] | 355 | return nss_core_send_packet(nss_ctx, skb, NSS_TSTAMP_RX_INTERFACE, H2N_BIT_FLAG_VIRTUAL_BUFFER | H2N_BIT_FLAG_BUFFER_REUSABLE); |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 356 | } |
| 357 | EXPORT_SYMBOL(nss_tstamp_tx_buf); |
| 358 | |
| 359 | |
| 360 | /* |
Rakesh Nair | f0140c8 | 2015-12-02 17:49:06 +0530 | [diff] [blame] | 361 | * nss_tstamp_register_netdev() |
mandrew | c00308f | 2016-11-15 23:25:08 +0530 | [diff] [blame] | 362 | * register dummy netdevice for tstamp interface |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 363 | */ |
Rakesh Nair | f0140c8 | 2015-12-02 17:49:06 +0530 | [diff] [blame] | 364 | struct net_device *nss_tstamp_register_netdev(void) |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 365 | { |
| 366 | struct net_device *ndev; |
| 367 | uint32_t err = 0; |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 368 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 369 | #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 16, 0)) |
Rakesh Nair | f0140c8 | 2015-12-02 17:49:06 +0530 | [diff] [blame] | 370 | ndev = alloc_netdev(sizeof(struct netdev_priv_instance), "qca-nss-tstamp", nss_tstamp_ndev_setup); |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 371 | #else |
| 372 | ndev = alloc_netdev(sizeof(struct netdev_priv_instance), "qca-nss-tstamp", NET_NAME_ENUM, nss_tstamp_ndev_setup); |
| 373 | #endif |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 374 | if (!ndev) { |
| 375 | nss_warning("Tstamp: Could not allocate tstamp net_device "); |
Rakesh Nair | f0140c8 | 2015-12-02 17:49:06 +0530 | [diff] [blame] | 376 | return NULL; |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | ndev->netdev_ops = &nss_tstamp_ndev_ops; |
| 380 | |
| 381 | err = register_netdev(ndev); |
| 382 | if (err) { |
| 383 | nss_warning("Tstamp: Could not register tstamp net_device "); |
| 384 | free_netdev(ndev); |
Rakesh Nair | f0140c8 | 2015-12-02 17:49:06 +0530 | [diff] [blame] | 385 | return NULL; |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 386 | } |
| 387 | |
Rakesh Nair | f0140c8 | 2015-12-02 17:49:06 +0530 | [diff] [blame] | 388 | return ndev; |
| 389 | } |
| 390 | |
| 391 | /* |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 392 | * nss_tstamp_notify_register() |
| 393 | * Register to receive tstamp notify messages. |
| 394 | */ |
| 395 | struct nss_ctx_instance *nss_tstamp_notify_register(nss_tstamp_msg_callback_t cb, void *app_data) |
| 396 | { |
| 397 | struct nss_ctx_instance *nss_ctx; |
| 398 | |
| 399 | nss_ctx = &nss_top_main.nss[nss_top_main.tstamp_handler_id]; |
| 400 | |
| 401 | nss_tstamp_notify.tstamp_callback = cb; |
| 402 | nss_tstamp_notify.app_data = app_data; |
| 403 | |
| 404 | return nss_ctx; |
| 405 | } |
| 406 | EXPORT_SYMBOL(nss_tstamp_notify_register); |
| 407 | |
| 408 | /* |
Rakesh Nair | f0140c8 | 2015-12-02 17:49:06 +0530 | [diff] [blame] | 409 | * nss_tstamp_register_handler() |
| 410 | */ |
| 411 | void nss_tstamp_register_handler(struct net_device *ndev) |
| 412 | { |
| 413 | uint32_t features = 0; |
| 414 | struct nss_ctx_instance *nss_ctx; |
| 415 | |
| 416 | nss_ctx = &nss_top_main.nss[nss_top_main.tstamp_handler_id]; |
Jackson Bockus | 7ca70ec | 2017-07-17 13:47:29 -0700 | [diff] [blame] | 417 | |
Cemil Coskun | 58d2773 | 2019-05-22 13:39:14 -0700 | [diff] [blame] | 418 | nss_core_register_subsys_dp(nss_ctx, NSS_TSTAMP_TX_INTERFACE, nss_tstamp_buf_receive, NULL, NULL, ndev, features); |
| 419 | |
| 420 | nss_core_register_handler(nss_ctx, NSS_TSTAMP_TX_INTERFACE, nss_tstamp_interface_handler, NULL); |
| 421 | |
| 422 | nss_core_register_handler(nss_ctx, NSS_TSTAMP_RX_INTERFACE, nss_tstamp_interface_handler, NULL); |
| 423 | |
| 424 | nss_tstamp_stats_dentry_create(); |
Rakesh Nair | 28212a4 | 2015-08-31 14:51:49 +0530 | [diff] [blame] | 425 | } |