aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/caif/caif_hsi.c
diff options
context:
space:
mode:
authorsjur.brandeland@stericsson.com <sjur.brandeland@stericsson.com>2012-04-12 04:27:27 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-13 11:37:37 -0400
commit39abbaef19cd0a30be93794aa4773c779c3eb1f3 (patch)
treeea6312f6fcd60550360a362c33185917f3141127 /drivers/net/caif/caif_hsi.c
parent2df1fe7f1006f3c1d9ecbe9311701833c63c14cc (diff)
caif-hsi: Postpone init of HSI until open()
Do the initialization of the HSI interface when the interface is opened, instead of upon registration. When the interface is closed the HSI interface is de-initialized, allowing other modules to use the HSI interface. Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/caif/caif_hsi.c')
-rw-r--r--drivers/net/caif/caif_hsi.c97
1 files changed, 45 insertions, 52 deletions
diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
index 42539919db17..1520814c77c7 100644
--- a/drivers/net/caif/caif_hsi.c
+++ b/drivers/net/caif/caif_hsi.c
@@ -6,6 +6,8 @@
6 * License terms: GNU General Public License (GPL) version 2. 6 * License terms: GNU General Public License (GPL) version 2.
7 */ 7 */
8 8
9#define pr_fmt(fmt) KBUILD_MODNAME fmt
10
9#include <linux/init.h> 11#include <linux/init.h>
10#include <linux/module.h> 12#include <linux/module.h>
11#include <linux/device.h> 13#include <linux/device.h>
@@ -1127,21 +1129,7 @@ static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev)
1127 return 0; 1129 return 0;
1128} 1130}
1129 1131
1130static int cfhsi_open(struct net_device *dev) 1132static const struct net_device_ops cfhsi_ops;
1131{
1132 return 0;
1133}
1134
1135static int cfhsi_close(struct net_device *dev)
1136{
1137 return 0;
1138}
1139
1140static const struct net_device_ops cfhsi_ops = {
1141 .ndo_open = cfhsi_open,
1142 .ndo_stop = cfhsi_close,
1143 .ndo_start_xmit = cfhsi_xmit
1144};
1145 1133
1146static void cfhsi_setup(struct net_device *dev) 1134static void cfhsi_setup(struct net_device *dev)
1147{ 1135{
@@ -1167,7 +1155,7 @@ int cfhsi_probe(struct platform_device *pdev)
1167{ 1155{
1168 struct cfhsi *cfhsi = NULL; 1156 struct cfhsi *cfhsi = NULL;
1169 struct net_device *ndev; 1157 struct net_device *ndev;
1170 struct cfhsi_dev *dev; 1158
1171 int res; 1159 int res;
1172 1160
1173 ndev = alloc_netdev(sizeof(struct cfhsi), "cfhsi%d", cfhsi_setup); 1161 ndev = alloc_netdev(sizeof(struct cfhsi), "cfhsi%d", cfhsi_setup);
@@ -1178,6 +1166,34 @@ int cfhsi_probe(struct platform_device *pdev)
1178 cfhsi->ndev = ndev; 1166 cfhsi->ndev = ndev;
1179 cfhsi->pdev = pdev; 1167 cfhsi->pdev = pdev;
1180 1168
1169 /* Assign the HSI device. */
1170 cfhsi->dev = pdev->dev.platform_data;
1171
1172 /* Assign the driver to this HSI device. */
1173 cfhsi->dev->drv = &cfhsi->drv;
1174
1175 /* Register network device. */
1176 res = register_netdev(ndev);
1177 if (res) {
1178 dev_err(&ndev->dev, "%s: Registration error: %d.\n",
1179 __func__, res);
1180 free_netdev(ndev);
1181 }
1182 /* Add CAIF HSI device to list. */
1183 spin_lock(&cfhsi_list_lock);
1184 list_add_tail(&cfhsi->list, &cfhsi_list);
1185 spin_unlock(&cfhsi_list_lock);
1186
1187 return res;
1188}
1189
1190static int cfhsi_open(struct net_device *ndev)
1191{
1192 struct cfhsi *cfhsi = netdev_priv(ndev);
1193 int res;
1194
1195 clear_bit(CFHSI_SHUTDOWN, &cfhsi->bits);
1196
1181 /* Initialize state vaiables. */ 1197 /* Initialize state vaiables. */
1182 cfhsi->tx_state = CFHSI_TX_STATE_IDLE; 1198 cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
1183 cfhsi->rx_state.state = CFHSI_RX_STATE_DESC; 1199 cfhsi->rx_state.state = CFHSI_RX_STATE_DESC;
@@ -1187,12 +1203,6 @@ int cfhsi_probe(struct platform_device *pdev)
1187 cfhsi->q_low_mark = LOW_WATER_MARK; 1203 cfhsi->q_low_mark = LOW_WATER_MARK;
1188 cfhsi->q_high_mark = HIGH_WATER_MARK; 1204 cfhsi->q_high_mark = HIGH_WATER_MARK;
1189 1205
1190 /* Assign the HSI device. */
1191 dev = (struct cfhsi_dev *)pdev->dev.platform_data;
1192 cfhsi->dev = dev;
1193
1194 /* Assign the driver to this HSI device. */
1195 dev->drv = &cfhsi->drv;
1196 1206
1197 /* 1207 /*
1198 * Allocate a TX buffer with the size of a HSI packet descriptors 1208 * Allocate a TX buffer with the size of a HSI packet descriptors
@@ -1260,9 +1270,9 @@ int cfhsi_probe(struct platform_device *pdev)
1260 clear_bit(CFHSI_AWAKE, &cfhsi->bits); 1270 clear_bit(CFHSI_AWAKE, &cfhsi->bits);
1261 1271
1262 /* Create work thread. */ 1272 /* Create work thread. */
1263 cfhsi->wq = create_singlethread_workqueue(pdev->name); 1273 cfhsi->wq = create_singlethread_workqueue(cfhsi->pdev->name);
1264 if (!cfhsi->wq) { 1274 if (!cfhsi->wq) {
1265 dev_err(&ndev->dev, "%s: Failed to create work queue.\n", 1275 dev_err(&cfhsi->ndev->dev, "%s: Failed to create work queue.\n",
1266 __func__); 1276 __func__);
1267 res = -ENODEV; 1277 res = -ENODEV;
1268 goto err_create_wq; 1278 goto err_create_wq;
@@ -1286,11 +1296,6 @@ int cfhsi_probe(struct platform_device *pdev)
1286 cfhsi->aggregation_timer.data = (unsigned long)cfhsi; 1296 cfhsi->aggregation_timer.data = (unsigned long)cfhsi;
1287 cfhsi->aggregation_timer.function = cfhsi_aggregation_tout; 1297 cfhsi->aggregation_timer.function = cfhsi_aggregation_tout;
1288 1298
1289 /* Add CAIF HSI device to list. */
1290 spin_lock(&cfhsi_list_lock);
1291 list_add_tail(&cfhsi->list, &cfhsi_list);
1292 spin_unlock(&cfhsi_list_lock);
1293
1294 /* Activate HSI interface. */ 1299 /* Activate HSI interface. */
1295 res = cfhsi->dev->cfhsi_up(cfhsi->dev); 1300 res = cfhsi->dev->cfhsi_up(cfhsi->dev);
1296 if (res) { 1301 if (res) {
@@ -1303,15 +1308,7 @@ int cfhsi_probe(struct platform_device *pdev)
1303 /* Flush FIFO */ 1308 /* Flush FIFO */
1304 res = cfhsi_flush_fifo(cfhsi); 1309 res = cfhsi_flush_fifo(cfhsi);
1305 if (res) { 1310 if (res) {
1306 dev_err(&ndev->dev, "%s: Can't flush FIFO: %d.\n", 1311 dev_err(&cfhsi->ndev->dev, "%s: Can't flush FIFO: %d.\n",
1307 __func__, res);
1308 goto err_net_reg;
1309 }
1310
1311 /* Register network device. */
1312 res = register_netdev(ndev);
1313 if (res) {
1314 dev_err(&ndev->dev, "%s: Registration error: %d.\n",
1315 __func__, res); 1312 __func__, res);
1316 goto err_net_reg; 1313 goto err_net_reg;
1317 } 1314 }
@@ -1328,13 +1325,12 @@ int cfhsi_probe(struct platform_device *pdev)
1328 err_alloc_rx: 1325 err_alloc_rx:
1329 kfree(cfhsi->tx_buf); 1326 kfree(cfhsi->tx_buf);
1330 err_alloc_tx: 1327 err_alloc_tx:
1331 free_netdev(ndev);
1332
1333 return res; 1328 return res;
1334} 1329}
1335 1330
1336static void cfhsi_shutdown(struct cfhsi *cfhsi) 1331static int cfhsi_close(struct net_device *ndev)
1337{ 1332{
1333 struct cfhsi *cfhsi = netdev_priv(ndev);
1338 u8 *tx_buf, *rx_buf, *flip_buf; 1334 u8 *tx_buf, *rx_buf, *flip_buf;
1339 1335
1340 /* going to shutdown driver */ 1336 /* going to shutdown driver */
@@ -1364,15 +1360,19 @@ static void cfhsi_shutdown(struct cfhsi *cfhsi)
1364 /* Deactivate interface */ 1360 /* Deactivate interface */
1365 cfhsi->dev->cfhsi_down(cfhsi->dev); 1361 cfhsi->dev->cfhsi_down(cfhsi->dev);
1366 1362
1367 /* Finally unregister the network device. */
1368 unregister_netdev(cfhsi->ndev);
1369
1370 /* Free buffers. */ 1363 /* Free buffers. */
1371 kfree(tx_buf); 1364 kfree(tx_buf);
1372 kfree(rx_buf); 1365 kfree(rx_buf);
1373 kfree(flip_buf); 1366 kfree(flip_buf);
1367 return 0;
1374} 1368}
1375 1369
1370static const struct net_device_ops cfhsi_ops = {
1371 .ndo_open = cfhsi_open,
1372 .ndo_stop = cfhsi_close,
1373 .ndo_start_xmit = cfhsi_xmit
1374};
1375
1376int cfhsi_remove(struct platform_device *pdev) 1376int cfhsi_remove(struct platform_device *pdev)
1377{ 1377{
1378 struct list_head *list_node; 1378 struct list_head *list_node;
@@ -1389,10 +1389,6 @@ int cfhsi_remove(struct platform_device *pdev)
1389 /* Remove from list. */ 1389 /* Remove from list. */
1390 list_del(list_node); 1390 list_del(list_node);
1391 spin_unlock(&cfhsi_list_lock); 1391 spin_unlock(&cfhsi_list_lock);
1392
1393 /* Shutdown driver. */
1394 cfhsi_shutdown(cfhsi);
1395
1396 return 0; 1392 return 0;
1397 } 1393 }
1398 } 1394 }
@@ -1423,8 +1419,7 @@ static void __exit cfhsi_exit_module(void)
1423 list_del(list_node); 1419 list_del(list_node);
1424 spin_unlock(&cfhsi_list_lock); 1420 spin_unlock(&cfhsi_list_lock);
1425 1421
1426 /* Shutdown driver. */ 1422 unregister_netdevice(cfhsi->ndev);
1427 cfhsi_shutdown(cfhsi);
1428 1423
1429 spin_lock(&cfhsi_list_lock); 1424 spin_lock(&cfhsi_list_lock);
1430 } 1425 }
@@ -1449,8 +1444,6 @@ static int __init cfhsi_init_module(void)
1449 goto err_dev_register; 1444 goto err_dev_register;
1450 } 1445 }
1451 1446
1452 return result;
1453
1454 err_dev_register: 1447 err_dev_register:
1455 return result; 1448 return result;
1456} 1449}