@@ -12,6 +12,7 @@ static const char i40e_client_interface_version_str[] = I40E_CLIENT_VERSION_STR;
1212static struct i40e_client * registered_client ;
1313static LIST_HEAD (i40e_devices );
1414static DEFINE_MUTEX (i40e_device_mutex );
15+ DEFINE_IDA (i40e_client_ida );
1516
1617static int i40e_client_virtchnl_send (struct i40e_info * ldev ,
1718 struct i40e_client * client ,
@@ -275,6 +276,57 @@ void i40e_client_update_msix_info(struct i40e_pf *pf)
275276 cdev -> lan_info .msix_entries = & pf -> msix_entries [pf -> iwarp_base_vector ];
276277}
277278
279+ static void i40e_auxiliary_dev_release (struct device * dev )
280+ {
281+ struct i40e_auxiliary_device * i40e_aux_dev =
282+ container_of (dev , struct i40e_auxiliary_device , aux_dev .dev );
283+
284+ ida_free (& i40e_client_ida , i40e_aux_dev -> aux_dev .id );
285+ kfree (i40e_aux_dev );
286+ }
287+
288+ static int i40e_register_auxiliary_dev (struct i40e_info * ldev , const char * name )
289+ {
290+ struct i40e_auxiliary_device * i40e_aux_dev ;
291+ struct pci_dev * pdev = ldev -> pcidev ;
292+ struct auxiliary_device * aux_dev ;
293+ int ret ;
294+
295+ i40e_aux_dev = kzalloc (sizeof (* i40e_aux_dev ), GFP_KERNEL );
296+ if (!i40e_aux_dev )
297+ return - ENOMEM ;
298+
299+ i40e_aux_dev -> ldev = ldev ;
300+
301+ aux_dev = & i40e_aux_dev -> aux_dev ;
302+ aux_dev -> name = name ;
303+ aux_dev -> dev .parent = & pdev -> dev ;
304+ aux_dev -> dev .release = i40e_auxiliary_dev_release ;
305+ ldev -> aux_dev = aux_dev ;
306+
307+ ret = ida_alloc (& i40e_client_ida , GFP_KERNEL );
308+ if (ret < 0 ) {
309+ kfree (i40e_aux_dev );
310+ return ret ;
311+ }
312+ aux_dev -> id = ret ;
313+
314+ ret = auxiliary_device_init (aux_dev );
315+ if (ret < 0 ) {
316+ ida_free (& i40e_client_ida , aux_dev -> id );
317+ kfree (i40e_aux_dev );
318+ return ret ;
319+ }
320+
321+ ret = auxiliary_device_add (aux_dev );
322+ if (ret ) {
323+ auxiliary_device_uninit (aux_dev );
324+ return ret ;
325+ }
326+
327+ return ret ;
328+ }
329+
278330/**
279331 * i40e_client_add_instance - add a client instance struct to the instance list
280332 * @pf: pointer to the board struct
@@ -286,9 +338,6 @@ static void i40e_client_add_instance(struct i40e_pf *pf)
286338 struct netdev_hw_addr * mac = NULL ;
287339 struct i40e_vsi * vsi = pf -> vsi [pf -> lan_vsi ];
288340
289- if (!registered_client || pf -> cinst )
290- return ;
291-
292341 cdev = kzalloc (sizeof (* cdev ), GFP_KERNEL );
293342 if (!cdev )
294343 return ;
@@ -308,11 +357,8 @@ static void i40e_client_add_instance(struct i40e_pf *pf)
308357 cdev -> lan_info .fw_build = pf -> hw .aq .fw_build ;
309358 set_bit (__I40E_CLIENT_INSTANCE_NONE , & cdev -> state );
310359
311- if (i40e_client_get_params (vsi , & cdev -> lan_info .params )) {
312- kfree (cdev );
313- cdev = NULL ;
314- return ;
315- }
360+ if (i40e_client_get_params (vsi , & cdev -> lan_info .params ))
361+ goto free_cdev ;
316362
317363 mac = list_first_entry (& cdev -> lan_info .netdev -> dev_addrs .list ,
318364 struct netdev_hw_addr , list );
@@ -324,7 +370,17 @@ static void i40e_client_add_instance(struct i40e_pf *pf)
324370 cdev -> client = registered_client ;
325371 pf -> cinst = cdev ;
326372
327- i40e_client_update_msix_info (pf );
373+ cdev -> lan_info .msix_count = pf -> num_iwarp_msix ;
374+ cdev -> lan_info .msix_entries = & pf -> msix_entries [pf -> iwarp_base_vector ];
375+
376+ if (i40e_register_auxiliary_dev (& cdev -> lan_info , "iwarp" ))
377+ goto free_cdev ;
378+
379+ return ;
380+
381+ free_cdev :
382+ kfree (cdev );
383+ pf -> cinst = NULL ;
328384}
329385
330386/**
@@ -345,7 +401,7 @@ void i40e_client_del_instance(struct i40e_pf *pf)
345401 **/
346402void i40e_client_subtask (struct i40e_pf * pf )
347403{
348- struct i40e_client * client = registered_client ;
404+ struct i40e_client * client ;
349405 struct i40e_client_instance * cdev ;
350406 struct i40e_vsi * vsi = pf -> vsi [pf -> lan_vsi ];
351407 int ret = 0 ;
@@ -359,9 +415,11 @@ void i40e_client_subtask(struct i40e_pf *pf)
359415 test_bit (__I40E_CONFIG_BUSY , pf -> state ))
360416 return ;
361417
362- if (!client || !cdev )
418+ if (!cdev || !cdev -> client )
363419 return ;
364420
421+ client = cdev -> client ;
422+
365423 /* Here we handle client opens. If the client is down, and
366424 * the netdev is registered, then open the client.
367425 */
@@ -423,16 +481,8 @@ int i40e_lan_add_device(struct i40e_pf *pf)
423481 pf -> hw .pf_id , pf -> hw .bus .bus_id ,
424482 pf -> hw .bus .device , pf -> hw .bus .func );
425483
426- /* If a client has already been registered, we need to add an instance
427- * of it to our new LAN device.
428- */
429- if (registered_client )
430- i40e_client_add_instance (pf );
484+ i40e_client_add_instance (pf );
431485
432- /* Since in some cases register may have happened before a device gets
433- * added, we can schedule a subtask to go initiate the clients if
434- * they can be launched at probe time.
435- */
436486 set_bit (__I40E_CLIENT_SERVICE_REQUESTED , pf -> state );
437487 i40e_service_event_schedule (pf );
438488
@@ -449,9 +499,13 @@ int i40e_lan_add_device(struct i40e_pf *pf)
449499 **/
450500int i40e_lan_del_device (struct i40e_pf * pf )
451501{
502+ struct auxiliary_device * aux_dev = pf -> cinst -> lan_info .aux_dev ;
452503 struct i40e_device * ldev , * tmp ;
453504 int ret = - ENODEV ;
454505
506+ auxiliary_device_delete (aux_dev );
507+ auxiliary_device_uninit (aux_dev );
508+
455509 /* First, remove any client instance. */
456510 i40e_client_del_instance (pf );
457511
@@ -732,6 +786,42 @@ static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
732786 return err ;
733787}
734788
789+ void i40e_client_device_register (struct i40e_info * ldev , struct i40e_client * client )
790+ {
791+ struct i40e_pf * pf = ldev -> pf ;
792+
793+ pf -> cinst -> client = client ;
794+ set_bit (__I40E_CLIENT_SERVICE_REQUESTED , pf -> state );
795+ i40e_service_event_schedule (pf );
796+ }
797+ EXPORT_SYMBOL_GPL (i40e_client_device_register );
798+
799+ void i40e_client_device_unregister (struct i40e_info * ldev )
800+ {
801+ struct i40e_pf * pf = ldev -> pf ;
802+ struct i40e_client_instance * cdev = pf -> cinst ;
803+
804+ if (!cdev )
805+ return ;
806+
807+ while (test_and_set_bit (__I40E_SERVICE_SCHED , pf -> state ))
808+ usleep_range (500 , 1000 );
809+
810+ if (test_bit (__I40E_CLIENT_INSTANCE_OPENED , & cdev -> state )) {
811+ cdev -> client -> ops -> close (& cdev -> lan_info , cdev -> client , false);
812+ clear_bit (__I40E_CLIENT_INSTANCE_OPENED , & cdev -> state );
813+ i40e_client_release_qvlist (& cdev -> lan_info );
814+ }
815+
816+ pf -> cinst -> client = NULL ;
817+ clear_bit (__I40E_SERVICE_SCHED , pf -> state );
818+ }
819+ EXPORT_SYMBOL_GPL (i40e_client_device_unregister );
820+
821+ /* Retain these legacy global registration/unregistration calls till i40iw is
822+ * removed from the kernel. The irdma unified driver does not use these
823+ * exported symbols.
824+ */
735825/**
736826 * i40e_register_client - Register a i40e client driver with the L2 driver
737827 * @client: pointer to the i40e_client struct
0 commit comments