25
25
/* Memory sizes for the buffers sent to/from the ES2 controller */
26
26
#define ES2_GBUF_MSG_SIZE_MAX 2048
27
27
28
+ /* Memory sizes for the ARPC buffers */
29
+ #define ARPC_IN_SIZE_MAX 128
30
+
28
31
static const struct usb_device_id id_table [] = {
29
32
{ USB_DEVICE (0x18d1 , 0x1eaf ) },
30
33
{ },
@@ -36,6 +39,12 @@ MODULE_DEVICE_TABLE(usb, id_table);
36
39
/* Number of bulk in and bulk out couple */
37
40
#define NUM_BULKS 7
38
41
42
+ /* Expected number of bulk out endpoints */
43
+ #define NUM_BULKS_OUT NUM_BULKS
44
+
45
+ /* Expected number of bulk in endpoints (including ARPC endpoint) */
46
+ #define NUM_BULKS_IN (NUM_BULKS + 1)
47
+
39
48
/*
40
49
* Number of CPort IN urbs in flight at any point in time.
41
50
* Adjust if we are having stalls in the USB buffer due to not enough urbs in
@@ -48,6 +57,11 @@ MODULE_DEVICE_TABLE(usb, id_table);
48
57
*/
49
58
#define NUM_CPORT_OUT_URB (8 * NUM_BULKS)
50
59
60
+ /*
61
+ * Number of ARPC in urbs in flight at any point in time.
62
+ */
63
+ #define NUM_ARPC_IN_URB 2
64
+
51
65
/*
52
66
* @endpoint: bulk in endpoint for CPort data
53
67
* @urb: array of urbs for the CPort in messages
@@ -85,6 +99,9 @@ struct es2_cport_out {
85
99
* @apb_log_dentry: file system entry for the log file interface
86
100
* @apb_log_enable_dentry: file system entry for enabling logging
87
101
* @apb_log_fifo: kernel FIFO to carry logged data
102
+ * @arpc_urb: array of urbs for the ARPC in messages
103
+ * @arpc_buffer: array of buffers for the @arpc_urb urbs
104
+ * @arpc_endpoint_in: bulk in endpoint for APBridgeA RPC
88
105
*/
89
106
struct es2_ap_dev {
90
107
struct usb_device * usb_dev ;
@@ -106,6 +123,10 @@ struct es2_ap_dev {
106
123
struct dentry * apb_log_dentry ;
107
124
struct dentry * apb_log_enable_dentry ;
108
125
DECLARE_KFIFO (apb_log_fifo , char , APB1_LOG_SIZE );
126
+
127
+ __u8 arpc_endpoint_in ;
128
+ struct urb * arpc_urb [NUM_ARPC_IN_URB ];
129
+ u8 * arpc_buffer [NUM_ARPC_IN_URB ];
109
130
};
110
131
111
132
/**
@@ -344,6 +365,45 @@ static void es2_cport_in_disable(struct es2_ap_dev *es2,
344
365
}
345
366
}
346
367
368
+ static int es2_arpc_in_enable (struct es2_ap_dev * es2 )
369
+ {
370
+ struct urb * urb ;
371
+ int ret ;
372
+ int i ;
373
+
374
+ for (i = 0 ; i < NUM_ARPC_IN_URB ; ++ i ) {
375
+ urb = es2 -> arpc_urb [i ];
376
+
377
+ ret = usb_submit_urb (urb , GFP_KERNEL );
378
+ if (ret ) {
379
+ dev_err (& es2 -> usb_dev -> dev ,
380
+ "failed to submit arpc in-urb: %d\n" , ret );
381
+ goto err_kill_urbs ;
382
+ }
383
+ }
384
+
385
+ return 0 ;
386
+
387
+ err_kill_urbs :
388
+ for (-- i ; i >= 0 ; -- i ) {
389
+ urb = es2 -> arpc_urb [i ];
390
+ usb_kill_urb (urb );
391
+ }
392
+
393
+ return ret ;
394
+ }
395
+
396
+ static void es2_arpc_in_disable (struct es2_ap_dev * es2 )
397
+ {
398
+ struct urb * urb ;
399
+ int i ;
400
+
401
+ for (i = 0 ; i < NUM_ARPC_IN_URB ; ++ i ) {
402
+ urb = es2 -> arpc_urb [i ];
403
+ usb_kill_urb (urb );
404
+ }
405
+ }
406
+
347
407
static struct urb * next_free_urb (struct es2_ap_dev * es2 , gfp_t gfp_mask )
348
408
{
349
409
struct urb * urb = NULL ;
@@ -899,6 +959,16 @@ static void es2_destroy(struct es2_ap_dev *es2)
899
959
es2 -> cport_out_urb_busy [i ] = false; /* just to be anal */
900
960
}
901
961
962
+ for (i = 0 ; i < NUM_ARPC_IN_URB ; ++ i ) {
963
+ struct urb * urb = es2 -> arpc_urb [i ];
964
+
965
+ if (!urb )
966
+ break ;
967
+ usb_free_urb (urb );
968
+ kfree (es2 -> arpc_buffer [i ]);
969
+ es2 -> arpc_buffer [i ] = NULL ;
970
+ }
971
+
902
972
for (bulk_in = 0 ; bulk_in < NUM_BULKS ; bulk_in ++ ) {
903
973
struct es2_cport_in * cport_in = & es2 -> cport_in [bulk_in ];
904
974
@@ -991,6 +1061,31 @@ static void cport_out_callback(struct urb *urb)
991
1061
free_urb (es2 , urb );
992
1062
}
993
1063
1064
+ static void arpc_in_callback (struct urb * urb )
1065
+ {
1066
+ struct device * dev = & urb -> dev -> dev ;
1067
+ int status = check_urb_status (urb );
1068
+ int retval ;
1069
+
1070
+ if (status ) {
1071
+ if ((status == - EAGAIN ) || (status == - EPROTO ))
1072
+ goto exit ;
1073
+
1074
+ /* The urb is being unlinked */
1075
+ if (status == - ENOENT || status == - ESHUTDOWN )
1076
+ return ;
1077
+
1078
+ dev_err (dev , "arpc in-urb error %d (dropped)\n" , status );
1079
+ return ;
1080
+ }
1081
+
1082
+ exit :
1083
+ /* put our urb back in the request pool */
1084
+ retval = usb_submit_urb (urb , GFP_ATOMIC );
1085
+ if (retval )
1086
+ dev_err (dev , "failed to resubmit arpc in-urb: %d\n" , retval );
1087
+ }
1088
+
994
1089
#define APB1_LOG_MSG_SIZE 64
995
1090
static void apb_log_get (struct es2_ap_dev * es2 , char * buf )
996
1091
{
@@ -1225,8 +1320,13 @@ static int ap_probe(struct usb_interface *interface,
1225
1320
endpoint = & iface_desc -> endpoint [i ].desc ;
1226
1321
1227
1322
if (usb_endpoint_is_bulk_in (endpoint )) {
1228
- es2 -> cport_in [bulk_in ++ ].endpoint =
1229
- endpoint -> bEndpointAddress ;
1323
+ if (bulk_in < NUM_BULKS )
1324
+ es2 -> cport_in [bulk_in ].endpoint =
1325
+ endpoint -> bEndpointAddress ;
1326
+ else
1327
+ es2 -> arpc_endpoint_in =
1328
+ endpoint -> bEndpointAddress ;
1329
+ bulk_in ++ ;
1230
1330
} else if (usb_endpoint_is_bulk_out (endpoint )) {
1231
1331
es2 -> cport_out [bulk_out ++ ].endpoint =
1232
1332
endpoint -> bEndpointAddress ;
@@ -1236,7 +1336,7 @@ static int ap_probe(struct usb_interface *interface,
1236
1336
endpoint -> bEndpointAddress );
1237
1337
}
1238
1338
}
1239
- if (bulk_in != NUM_BULKS || bulk_out != NUM_BULKS ) {
1339
+ if (bulk_in != NUM_BULKS_IN || bulk_out != NUM_BULKS_OUT ) {
1240
1340
dev_err (& udev -> dev , "Not enough endpoints found in device, aborting!\n" );
1241
1341
retval = - ENODEV ;
1242
1342
goto error ;
@@ -1271,6 +1371,32 @@ static int ap_probe(struct usb_interface *interface,
1271
1371
}
1272
1372
}
1273
1373
1374
+ /* Allocate buffers for ARPC in messages */
1375
+ for (i = 0 ; i < NUM_ARPC_IN_URB ; ++ i ) {
1376
+ struct urb * urb ;
1377
+ u8 * buffer ;
1378
+
1379
+ urb = usb_alloc_urb (0 , GFP_KERNEL );
1380
+ if (!urb ) {
1381
+ retval = - ENOMEM ;
1382
+ goto error ;
1383
+ }
1384
+ buffer = kmalloc (ARPC_IN_SIZE_MAX , GFP_KERNEL );
1385
+ if (!buffer ) {
1386
+ retval = - ENOMEM ;
1387
+ goto error ;
1388
+ }
1389
+
1390
+ usb_fill_bulk_urb (urb , udev ,
1391
+ usb_rcvbulkpipe (udev ,
1392
+ es2 -> arpc_endpoint_in ),
1393
+ buffer , ARPC_IN_SIZE_MAX ,
1394
+ arpc_in_callback , es2 );
1395
+
1396
+ es2 -> arpc_urb [i ] = urb ;
1397
+ es2 -> arpc_buffer [i ] = buffer ;
1398
+ }
1399
+
1274
1400
/* Allocate urbs for our CPort OUT messages */
1275
1401
for (i = 0 ; i < NUM_CPORT_OUT_URB ; ++ i ) {
1276
1402
struct urb * urb ;
@@ -1291,9 +1417,12 @@ static int ap_probe(struct usb_interface *interface,
1291
1417
gb_debugfs_get (), es2 ,
1292
1418
& apb_log_enable_fops );
1293
1419
1420
+ if (es2_arpc_in_enable (es2 ))
1421
+ goto error ;
1422
+
1294
1423
retval = gb_hd_add (hd );
1295
1424
if (retval )
1296
- goto error ;
1425
+ goto err_disable_arpc_in ;
1297
1426
1298
1427
for (i = 0 ; i < NUM_BULKS ; ++ i ) {
1299
1428
retval = es2_cport_in_enable (es2 , & es2 -> cport_in [i ]);
@@ -1307,6 +1436,8 @@ static int ap_probe(struct usb_interface *interface,
1307
1436
for (-- i ; i >= 0 ; -- i )
1308
1437
es2_cport_in_disable (es2 , & es2 -> cport_in [i ]);
1309
1438
gb_hd_del (hd );
1439
+ err_disable_arpc_in :
1440
+ es2_arpc_in_disable (es2 );
1310
1441
error :
1311
1442
es2_destroy (es2 );
1312
1443
@@ -1322,6 +1453,7 @@ static void ap_disconnect(struct usb_interface *interface)
1322
1453
1323
1454
for (i = 0 ; i < NUM_BULKS ; ++ i )
1324
1455
es2_cport_in_disable (es2 , & es2 -> cport_in [i ]);
1456
+ es2_arpc_in_disable (es2 );
1325
1457
1326
1458
es2_destroy (es2 );
1327
1459
}
0 commit comments