1 /**********************************************************************
2  * Author: Cavium, Inc.
3  *
4  * Contact: support@cavium.com
5  *          Please include "LiquidIO" in the subject.
6  *
7  * Copyright (c) 2003-2017 Cavium, Inc.
8  *
9  * This file is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License, Version 2, as
11  * published by the Free Software Foundation.
12  *
13  * This file is distributed in the hope that it will be useful, but
14  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16  * NONINFRINGEMENT.  See the GNU General Public License for more details.
17  ***********************************************************************/
18 #include <linux/pci.h>
19 #include <linux/if_vlan.h>
20 #include "liquidio_common.h"
21 #include "octeon_droq.h"
22 #include "octeon_iq.h"
23 #include "response_manager.h"
24 #include "octeon_device.h"
25 #include "octeon_nic.h"
26 #include "octeon_main.h"
27 #include "octeon_network.h"
28 #include <net/switchdev.h>
29 #include "lio_vf_rep.h"
30 
31 static int lio_vf_rep_open(struct net_device *ndev);
32 static int lio_vf_rep_stop(struct net_device *ndev);
33 static netdev_tx_t lio_vf_rep_pkt_xmit(struct sk_buff *skb,
34 				       struct net_device *ndev);
35 static void lio_vf_rep_tx_timeout(struct net_device *netdev);
36 static int lio_vf_rep_phys_port_name(struct net_device *dev,
37 				     char *buf, size_t len);
38 static void lio_vf_rep_get_stats64(struct net_device *dev,
39 				   struct rtnl_link_stats64 *stats64);
40 static int lio_vf_rep_change_mtu(struct net_device *ndev, int new_mtu);
41 
42 static const struct net_device_ops lio_vf_rep_ndev_ops = {
43 	.ndo_open = lio_vf_rep_open,
44 	.ndo_stop = lio_vf_rep_stop,
45 	.ndo_start_xmit = lio_vf_rep_pkt_xmit,
46 	.ndo_tx_timeout = lio_vf_rep_tx_timeout,
47 	.ndo_get_phys_port_name = lio_vf_rep_phys_port_name,
48 	.ndo_get_stats64 = lio_vf_rep_get_stats64,
49 	.ndo_change_mtu = lio_vf_rep_change_mtu,
50 };
51 
52 static int
53 lio_vf_rep_send_soft_command(struct octeon_device *oct,
54 			     void *req, int req_size,
55 			     void *resp, int resp_size)
56 {
57 	int tot_resp_size = sizeof(struct lio_vf_rep_resp) + resp_size;
58 	struct octeon_soft_command *sc = NULL;
59 	struct lio_vf_rep_resp *rep_resp;
60 	void *sc_req;
61 	int err;
62 
63 	sc = (struct octeon_soft_command *)
64 		octeon_alloc_soft_command(oct, req_size,
65 					  tot_resp_size, 0);
66 	if (!sc)
67 		return -ENOMEM;
68 
69 	init_completion(&sc->complete);
70 	sc->sc_status = OCTEON_REQUEST_PENDING;
71 
72 	sc_req = (struct lio_vf_rep_req *)sc->virtdptr;
73 	memcpy(sc_req, req, req_size);
74 
75 	rep_resp = (struct lio_vf_rep_resp *)sc->virtrptr;
76 	memset(rep_resp, 0, tot_resp_size);
77 	WRITE_ONCE(rep_resp->status, 1);
78 
79 	sc->iq_no = 0;
80 	octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
81 				    OPCODE_NIC_VF_REP_CMD, 0, 0, 0);
82 
83 	err = octeon_send_soft_command(oct, sc);
84 	if (err == IQ_SEND_FAILED)
85 		goto free_buff;
86 
87 	err = wait_for_sc_completion_timeout(oct, sc, 0);
88 	if (err)
89 		return err;
90 
91 	err = READ_ONCE(rep_resp->status) ? -EBUSY : 0;
92 	if (err)
93 		dev_err(&oct->pci_dev->dev, "VF rep send config failed\n");
94 	else if (resp)
95 		memcpy(resp, (rep_resp + 1), resp_size);
96 
97 	WRITE_ONCE(sc->caller_is_done, true);
98 	return err;
99 
100 free_buff:
101 	octeon_free_soft_command(oct, sc);
102 
103 	return err;
104 }
105 
106 static int
107 lio_vf_rep_open(struct net_device *ndev)
108 {
109 	struct lio_vf_rep_desc *vf_rep = netdev_priv(ndev);
110 	struct lio_vf_rep_req rep_cfg;
111 	struct octeon_device *oct;
112 	int ret;
113 
114 	oct = vf_rep->oct;
115 
116 	memset(&rep_cfg, 0, sizeof(rep_cfg));
117 	rep_cfg.req_type = LIO_VF_REP_REQ_STATE;
118 	rep_cfg.ifidx = vf_rep->ifidx;
119 	rep_cfg.rep_state.state = LIO_VF_REP_STATE_UP;
120 
121 	ret = lio_vf_rep_send_soft_command(oct, &rep_cfg,
122 					   sizeof(rep_cfg), NULL, 0);
123 
124 	if (ret) {
125 		dev_err(&oct->pci_dev->dev,
126 			"VF_REP open failed with err %d\n", ret);
127 		return -EIO;
128 	}
129 
130 	atomic_set(&vf_rep->ifstate, (atomic_read(&vf_rep->ifstate) |
131 				      LIO_IFSTATE_RUNNING));
132 
133 	netif_carrier_on(ndev);
134 	netif_start_queue(ndev);
135 
136 	return 0;
137 }
138 
139 static int
140 lio_vf_rep_stop(struct net_device *ndev)
141 {
142 	struct lio_vf_rep_desc *vf_rep = netdev_priv(ndev);
143 	struct lio_vf_rep_req rep_cfg;
144 	struct octeon_device *oct;
145 	int ret;
146 
147 	oct = vf_rep->oct;
148 
149 	memset(&rep_cfg, 0, sizeof(rep_cfg));
150 	rep_cfg.req_type = LIO_VF_REP_REQ_STATE;
151 	rep_cfg.ifidx = vf_rep->ifidx;
152 	rep_cfg.rep_state.state = LIO_VF_REP_STATE_DOWN;
153 
154 	ret = lio_vf_rep_send_soft_command(oct, &rep_cfg,
155 					   sizeof(rep_cfg), NULL, 0);
156 
157 	if (ret) {
158 		dev_err(&oct->pci_dev->dev,
159 			"VF_REP dev stop failed with err %d\n", ret);
160 		return -EIO;
161 	}
162 
163 	atomic_set(&vf_rep->ifstate, (atomic_read(&vf_rep->ifstate) &
164 				      ~LIO_IFSTATE_RUNNING));
165 
166 	netif_tx_disable(ndev);
167 	netif_carrier_off(ndev);
168 
169 	return 0;
170 }
171 
172 static void
173 lio_vf_rep_tx_timeout(struct net_device *ndev)
174 {
175 	netif_trans_update(ndev);
176 
177 	netif_wake_queue(ndev);
178 }
179 
180 static void
181 lio_vf_rep_get_stats64(struct net_device *dev,
182 		       struct rtnl_link_stats64 *stats64)
183 {
184 	struct lio_vf_rep_desc *vf_rep = netdev_priv(dev);
185 
186 	/* Swap tx and rx stats as VF rep is a switch port */
187 	stats64->tx_packets = vf_rep->stats.rx_packets;
188 	stats64->tx_bytes   = vf_rep->stats.rx_bytes;
189 	stats64->tx_dropped = vf_rep->stats.rx_dropped;
190 
191 	stats64->rx_packets = vf_rep->stats.tx_packets;
192 	stats64->rx_bytes   = vf_rep->stats.tx_bytes;
193 	stats64->rx_dropped = vf_rep->stats.tx_dropped;
194 }
195 
196 static int
197 lio_vf_rep_change_mtu(struct net_device *ndev, int new_mtu)
198 {
199 	struct lio_vf_rep_desc *vf_rep = netdev_priv(ndev);
200 	struct lio_vf_rep_req rep_cfg;
201 	struct octeon_device *oct;
202 	int ret;
203 
204 	oct = vf_rep->oct;
205 
206 	memset(&rep_cfg, 0, sizeof(rep_cfg));
207 	rep_cfg.req_type = LIO_VF_REP_REQ_MTU;
208 	rep_cfg.ifidx = vf_rep->ifidx;
209 	rep_cfg.rep_mtu.mtu = cpu_to_be32(new_mtu);
210 
211 	ret = lio_vf_rep_send_soft_command(oct, &rep_cfg,
212 					   sizeof(rep_cfg), NULL, 0);
213 	if (ret) {
214 		dev_err(&oct->pci_dev->dev,
215 			"Change MTU failed with err %d\n", ret);
216 		return -EIO;
217 	}
218 
219 	ndev->mtu = new_mtu;
220 
221 	return 0;
222 }
223 
224 static int
225 lio_vf_rep_phys_port_name(struct net_device *dev,
226 			  char *buf, size_t len)
227 {
228 	struct lio_vf_rep_desc *vf_rep = netdev_priv(dev);
229 	struct octeon_device *oct = vf_rep->oct;
230 	int ret;
231 
232 	ret = snprintf(buf, len, "pf%dvf%d", oct->pf_num,
233 		       vf_rep->ifidx - oct->pf_num * 64 - 1);
234 	if (ret >= len)
235 		return -EOPNOTSUPP;
236 
237 	return 0;
238 }
239 
240 static struct net_device *
241 lio_vf_rep_get_ndev(struct octeon_device *oct, int ifidx)
242 {
243 	int vf_id, max_vfs = CN23XX_MAX_VFS_PER_PF + 1;
244 	int vfid_mask = max_vfs - 1;
245 
246 	if (ifidx <= oct->pf_num * max_vfs ||
247 	    ifidx >= oct->pf_num * max_vfs + max_vfs)
248 		return NULL;
249 
250 	/* ifidx 1-63 for PF0 VFs
251 	 * ifidx 65-127 for PF1 VFs
252 	 */
253 	vf_id = (ifidx & vfid_mask) - 1;
254 
255 	return oct->vf_rep_list.ndev[vf_id];
256 }
257 
258 static void
259 lio_vf_rep_copy_packet(struct octeon_device *oct,
260 		       struct sk_buff *skb,
261 		       int len)
262 {
263 	if (likely(len > MIN_SKB_SIZE)) {
264 		struct octeon_skb_page_info *pg_info;
265 		unsigned char *va;
266 
267 		pg_info = ((struct octeon_skb_page_info *)(skb->cb));
268 		if (pg_info->page) {
269 			va = page_address(pg_info->page) +
270 				pg_info->page_offset;
271 			memcpy(skb->data, va, MIN_SKB_SIZE);
272 			skb_put(skb, MIN_SKB_SIZE);
273 		}
274 
275 		skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
276 				pg_info->page,
277 				pg_info->page_offset + MIN_SKB_SIZE,
278 				len - MIN_SKB_SIZE,
279 				LIO_RXBUFFER_SZ);
280 	} else {
281 		struct octeon_skb_page_info *pg_info =
282 			((struct octeon_skb_page_info *)(skb->cb));
283 
284 		skb_copy_to_linear_data(skb, page_address(pg_info->page) +
285 					pg_info->page_offset, len);
286 		skb_put(skb, len);
287 		put_page(pg_info->page);
288 	}
289 }
290 
291 static int
292 lio_vf_rep_pkt_recv(struct octeon_recv_info *recv_info, void *buf)
293 {
294 	struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
295 	struct lio_vf_rep_desc *vf_rep;
296 	struct net_device *vf_ndev;
297 	struct octeon_device *oct;
298 	union octeon_rh *rh;
299 	struct sk_buff *skb;
300 	int i, ifidx;
301 
302 	oct = lio_get_device(recv_pkt->octeon_id);
303 	if (!oct)
304 		goto free_buffers;
305 
306 	skb = recv_pkt->buffer_ptr[0];
307 	rh = &recv_pkt->rh;
308 	ifidx = rh->r.ossp;
309 
310 	vf_ndev = lio_vf_rep_get_ndev(oct, ifidx);
311 	if (!vf_ndev)
312 		goto free_buffers;
313 
314 	vf_rep = netdev_priv(vf_ndev);
315 	if (!(atomic_read(&vf_rep->ifstate) & LIO_IFSTATE_RUNNING) ||
316 	    recv_pkt->buffer_count > 1)
317 		goto free_buffers;
318 
319 	skb->dev = vf_ndev;
320 
321 	/* Multiple buffers are not used for vf_rep packets.
322 	 * So just buffer_size[0] is valid.
323 	 */
324 	lio_vf_rep_copy_packet(oct, skb, recv_pkt->buffer_size[0]);
325 
326 	skb_pull(skb, rh->r_dh.len * BYTES_PER_DHLEN_UNIT);
327 	skb->protocol = eth_type_trans(skb, skb->dev);
328 	skb->ip_summed = CHECKSUM_NONE;
329 
330 	netif_rx(skb);
331 
332 	octeon_free_recv_info(recv_info);
333 
334 	return 0;
335 
336 free_buffers:
337 	for (i = 0; i < recv_pkt->buffer_count; i++)
338 		recv_buffer_free(recv_pkt->buffer_ptr[i]);
339 
340 	octeon_free_recv_info(recv_info);
341 
342 	return 0;
343 }
344 
345 static void
346 lio_vf_rep_packet_sent_callback(struct octeon_device *oct,
347 				u32 status, void *buf)
348 {
349 	struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
350 	struct sk_buff *skb = sc->ctxptr;
351 	struct net_device *ndev = skb->dev;
352 
353 	dma_unmap_single(&oct->pci_dev->dev, sc->dmadptr,
354 			 sc->datasize, DMA_TO_DEVICE);
355 	dev_kfree_skb_any(skb);
356 	octeon_free_soft_command(oct, sc);
357 
358 	if (octnet_iq_is_full(oct, sc->iq_no))
359 		return;
360 
361 	if (netif_queue_stopped(ndev))
362 		netif_wake_queue(ndev);
363 }
364 
365 static netdev_tx_t
366 lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
367 {
368 	struct lio_vf_rep_desc *vf_rep = netdev_priv(ndev);
369 	struct net_device *parent_ndev = vf_rep->parent_ndev;
370 	struct octeon_device *oct = vf_rep->oct;
371 	struct octeon_instr_pki_ih3 *pki_ih3;
372 	struct octeon_soft_command *sc;
373 	struct lio *parent_lio;
374 	int status;
375 
376 	parent_lio = GET_LIO(parent_ndev);
377 
378 	if (!(atomic_read(&vf_rep->ifstate) & LIO_IFSTATE_RUNNING) ||
379 	    skb->len <= 0)
380 		goto xmit_failed;
381 
382 	if (octnet_iq_is_full(vf_rep->oct, parent_lio->txq)) {
383 		dev_err(&oct->pci_dev->dev, "VF rep: Device IQ full\n");
384 		netif_stop_queue(ndev);
385 		return NETDEV_TX_BUSY;
386 	}
387 
388 	sc = (struct octeon_soft_command *)
389 		octeon_alloc_soft_command(oct, 0, 16, 0);
390 	if (!sc) {
391 		dev_err(&oct->pci_dev->dev, "VF rep: Soft command alloc failed\n");
392 		goto xmit_failed;
393 	}
394 
395 	/* Multiple buffers are not used for vf_rep packets. */
396 	if (skb_shinfo(skb)->nr_frags != 0) {
397 		dev_err(&oct->pci_dev->dev, "VF rep: nr_frags != 0. Dropping packet\n");
398 		octeon_free_soft_command(oct, sc);
399 		goto xmit_failed;
400 	}
401 
402 	sc->dmadptr = dma_map_single(&oct->pci_dev->dev,
403 				     skb->data, skb->len, DMA_TO_DEVICE);
404 	if (dma_mapping_error(&oct->pci_dev->dev, sc->dmadptr)) {
405 		dev_err(&oct->pci_dev->dev, "VF rep: DMA mapping failed\n");
406 		octeon_free_soft_command(oct, sc);
407 		goto xmit_failed;
408 	}
409 
410 	sc->virtdptr = skb->data;
411 	sc->datasize = skb->len;
412 	sc->ctxptr = skb;
413 	sc->iq_no = parent_lio->txq;
414 
415 	octeon_prepare_soft_command(oct, sc, OPCODE_NIC, OPCODE_NIC_VF_REP_PKT,
416 				    vf_rep->ifidx, 0, 0);
417 	pki_ih3 = (struct octeon_instr_pki_ih3 *)&sc->cmd.cmd3.pki_ih3;
418 	pki_ih3->tagtype = ORDERED_TAG;
419 
420 	sc->callback = lio_vf_rep_packet_sent_callback;
421 	sc->callback_arg = sc;
422 
423 	status = octeon_send_soft_command(oct, sc);
424 	if (status == IQ_SEND_FAILED) {
425 		dma_unmap_single(&oct->pci_dev->dev, sc->dmadptr,
426 				 sc->datasize, DMA_TO_DEVICE);
427 		octeon_free_soft_command(oct, sc);
428 		goto xmit_failed;
429 	}
430 
431 	if (status == IQ_SEND_STOP)
432 		netif_stop_queue(ndev);
433 
434 	netif_trans_update(ndev);
435 
436 	return NETDEV_TX_OK;
437 
438 xmit_failed:
439 	dev_kfree_skb_any(skb);
440 
441 	return NETDEV_TX_OK;
442 }
443 
444 static int
445 lio_vf_rep_attr_get(struct net_device *dev, struct switchdev_attr *attr)
446 {
447 	struct lio_vf_rep_desc *vf_rep = netdev_priv(dev);
448 	struct net_device *parent_ndev = vf_rep->parent_ndev;
449 	struct lio *lio = GET_LIO(parent_ndev);
450 
451 	switch (attr->id) {
452 	case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
453 		attr->u.ppid.id_len = ETH_ALEN;
454 		ether_addr_copy(attr->u.ppid.id,
455 				(void *)&lio->linfo.hw_addr + 2);
456 		break;
457 
458 	default:
459 		return -EOPNOTSUPP;
460 	}
461 
462 	return 0;
463 }
464 
465 static const struct switchdev_ops lio_vf_rep_switchdev_ops = {
466 	.switchdev_port_attr_get        = lio_vf_rep_attr_get,
467 };
468 
469 static void
470 lio_vf_rep_fetch_stats(struct work_struct *work)
471 {
472 	struct cavium_wk *wk = (struct cavium_wk *)work;
473 	struct lio_vf_rep_desc *vf_rep = wk->ctxptr;
474 	struct lio_vf_rep_stats stats;
475 	struct lio_vf_rep_req rep_cfg;
476 	struct octeon_device *oct;
477 	int ret;
478 
479 	oct = vf_rep->oct;
480 
481 	memset(&rep_cfg, 0, sizeof(rep_cfg));
482 	rep_cfg.req_type = LIO_VF_REP_REQ_STATS;
483 	rep_cfg.ifidx = vf_rep->ifidx;
484 
485 	ret = lio_vf_rep_send_soft_command(oct, &rep_cfg, sizeof(rep_cfg),
486 					   &stats, sizeof(stats));
487 
488 	if (!ret) {
489 		octeon_swap_8B_data((u64 *)&stats, (sizeof(stats) >> 3));
490 		memcpy(&vf_rep->stats, &stats, sizeof(stats));
491 	}
492 
493 	schedule_delayed_work(&vf_rep->stats_wk.work,
494 			      msecs_to_jiffies(LIO_VF_REP_STATS_POLL_TIME_MS));
495 }
496 
497 int
498 lio_vf_rep_create(struct octeon_device *oct)
499 {
500 	struct lio_vf_rep_desc *vf_rep;
501 	struct net_device *ndev;
502 	int i, num_vfs;
503 
504 	if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
505 		return 0;
506 
507 	if (!oct->sriov_info.sriov_enabled)
508 		return 0;
509 
510 	num_vfs = oct->sriov_info.num_vfs_alloced;
511 
512 	oct->vf_rep_list.num_vfs = 0;
513 	for (i = 0; i < num_vfs; i++) {
514 		ndev = alloc_etherdev(sizeof(struct lio_vf_rep_desc));
515 
516 		if (!ndev) {
517 			dev_err(&oct->pci_dev->dev,
518 				"VF rep device %d creation failed\n", i);
519 			goto cleanup;
520 		}
521 
522 		ndev->min_mtu = LIO_MIN_MTU_SIZE;
523 		ndev->max_mtu = LIO_MAX_MTU_SIZE;
524 		ndev->netdev_ops = &lio_vf_rep_ndev_ops;
525 		SWITCHDEV_SET_OPS(ndev, &lio_vf_rep_switchdev_ops);
526 
527 		vf_rep = netdev_priv(ndev);
528 		memset(vf_rep, 0, sizeof(*vf_rep));
529 
530 		vf_rep->ndev = ndev;
531 		vf_rep->oct = oct;
532 		vf_rep->parent_ndev = oct->props[0].netdev;
533 		vf_rep->ifidx = (oct->pf_num * 64) + i + 1;
534 
535 		eth_hw_addr_random(ndev);
536 
537 		if (register_netdev(ndev)) {
538 			dev_err(&oct->pci_dev->dev, "VF rep nerdev registration failed\n");
539 
540 			free_netdev(ndev);
541 			goto cleanup;
542 		}
543 
544 		netif_carrier_off(ndev);
545 
546 		INIT_DELAYED_WORK(&vf_rep->stats_wk.work,
547 				  lio_vf_rep_fetch_stats);
548 		vf_rep->stats_wk.ctxptr = (void *)vf_rep;
549 		schedule_delayed_work(&vf_rep->stats_wk.work,
550 				      msecs_to_jiffies
551 				      (LIO_VF_REP_STATS_POLL_TIME_MS));
552 		oct->vf_rep_list.num_vfs++;
553 		oct->vf_rep_list.ndev[i] = ndev;
554 	}
555 
556 	if (octeon_register_dispatch_fn(oct, OPCODE_NIC,
557 					OPCODE_NIC_VF_REP_PKT,
558 					lio_vf_rep_pkt_recv, oct)) {
559 		dev_err(&oct->pci_dev->dev, "VF rep Dispatch func registration failed\n");
560 
561 		goto cleanup;
562 	}
563 
564 	return 0;
565 
566 cleanup:
567 	for (i = 0; i < oct->vf_rep_list.num_vfs; i++) {
568 		ndev = oct->vf_rep_list.ndev[i];
569 		oct->vf_rep_list.ndev[i] = NULL;
570 		if (ndev) {
571 			vf_rep = netdev_priv(ndev);
572 			cancel_delayed_work_sync
573 				(&vf_rep->stats_wk.work);
574 			unregister_netdev(ndev);
575 			free_netdev(ndev);
576 		}
577 	}
578 
579 	oct->vf_rep_list.num_vfs = 0;
580 
581 	return -1;
582 }
583 
584 void
585 lio_vf_rep_destroy(struct octeon_device *oct)
586 {
587 	struct lio_vf_rep_desc *vf_rep;
588 	struct net_device *ndev;
589 	int i;
590 
591 	if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
592 		return;
593 
594 	if (!oct->sriov_info.sriov_enabled)
595 		return;
596 
597 	for (i = 0; i < oct->vf_rep_list.num_vfs; i++) {
598 		ndev = oct->vf_rep_list.ndev[i];
599 		oct->vf_rep_list.ndev[i] = NULL;
600 		if (ndev) {
601 			vf_rep = netdev_priv(ndev);
602 			cancel_delayed_work_sync
603 				(&vf_rep->stats_wk.work);
604 			netif_tx_disable(ndev);
605 			netif_carrier_off(ndev);
606 
607 			unregister_netdev(ndev);
608 			free_netdev(ndev);
609 		}
610 	}
611 
612 	oct->vf_rep_list.num_vfs = 0;
613 }
614 
615 static int
616 lio_vf_rep_netdev_event(struct notifier_block *nb,
617 			unsigned long event, void *ptr)
618 {
619 	struct net_device *ndev = netdev_notifier_info_to_dev(ptr);
620 	struct lio_vf_rep_desc *vf_rep;
621 	struct lio_vf_rep_req rep_cfg;
622 	struct octeon_device *oct;
623 	int ret;
624 
625 	switch (event) {
626 	case NETDEV_REGISTER:
627 	case NETDEV_CHANGENAME:
628 		break;
629 
630 	default:
631 		return NOTIFY_DONE;
632 	}
633 
634 	if (ndev->netdev_ops != &lio_vf_rep_ndev_ops)
635 		return NOTIFY_DONE;
636 
637 	vf_rep = netdev_priv(ndev);
638 	oct = vf_rep->oct;
639 
640 	if (strlen(ndev->name) > LIO_IF_NAME_SIZE) {
641 		dev_err(&oct->pci_dev->dev,
642 			"Device name change sync failed as the size is > %d\n",
643 			LIO_IF_NAME_SIZE);
644 		return NOTIFY_DONE;
645 	}
646 
647 	memset(&rep_cfg, 0, sizeof(rep_cfg));
648 	rep_cfg.req_type = LIO_VF_REP_REQ_DEVNAME;
649 	rep_cfg.ifidx = vf_rep->ifidx;
650 	strncpy(rep_cfg.rep_name.name, ndev->name, LIO_IF_NAME_SIZE);
651 
652 	ret = lio_vf_rep_send_soft_command(oct, &rep_cfg,
653 					   sizeof(rep_cfg), NULL, 0);
654 	if (ret)
655 		dev_err(&oct->pci_dev->dev,
656 			"vf_rep netdev name change failed with err %d\n", ret);
657 
658 	return NOTIFY_DONE;
659 }
660 
661 static struct notifier_block lio_vf_rep_netdev_notifier = {
662 	.notifier_call = lio_vf_rep_netdev_event,
663 };
664 
665 int
666 lio_vf_rep_modinit(void)
667 {
668 	if (register_netdevice_notifier(&lio_vf_rep_netdev_notifier)) {
669 		pr_err("netdev notifier registration failed\n");
670 		return -EFAULT;
671 	}
672 
673 	return 0;
674 }
675 
676 void
677 lio_vf_rep_modexit(void)
678 {
679 	if (unregister_netdevice_notifier(&lio_vf_rep_netdev_notifier))
680 		pr_err("netdev notifier unregister failed\n");
681 }
682