aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire
diff options
context:
space:
mode:
authorStefan Richter <stefanr@s5r6.in-berlin.de>2013-06-09 12:15:00 -0400
committerStefan Richter <stefanr@s5r6.in-berlin.de>2013-06-09 12:15:00 -0400
commit94a87157cde95d38b9cdf1116e4f0fd93f6d25df (patch)
tree42cb11cbab50860a66d3e4191c43a85cf42bd77f /drivers/firewire
parent317ddd256b9c24b0d78fa8018f80f1e495481a10 (diff)
firewire: introduce fw_driver.probe and .remove methods
FireWire upper layer drivers are converted from generic struct driver.probe() and .remove() to bus-specific struct fw_driver.probe() and .remove(). The new .probe() adds a const struct ieee1394_device_id *id argument, indicating the entry in the driver's device identifiers table which matched the fw_unit to be probed. This new argument is used by the snd-firewire-speakers driver to look up device-specific parameters and methods. There is at least one other FireWire audio driver currently in development in which this will be useful too. The new .remove() drops the unused error return code. Although all in-tree drivers are being converted to the new methods, support for the old methods is left in place in this commit. This allows public developer trees to merge this commit and then move to the new fw_driver methods. Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> Acked-by: Clemens Ladisch <clemens@ladisch.de> (for sound/firewire/) Cc: Peter Hurley <peter@hurleysoftware.com> (for drivers/staging/fwserial/)
Diffstat (limited to 'drivers/firewire')
-rw-r--r--drivers/firewire/core-device.c45
-rw-r--r--drivers/firewire/net.c50
-rw-r--r--drivers/firewire/sbp2.c17
3 files changed, 67 insertions, 45 deletions
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index 664a6ff0a823..c152edd6cd3a 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -165,25 +165,50 @@ static bool match_ids(const struct ieee1394_device_id *id_table, int *id)
165 return (match & id_table->match_flags) == id_table->match_flags; 165 return (match & id_table->match_flags) == id_table->match_flags;
166} 166}
167 167
168static bool is_fw_unit(struct device *dev); 168static const struct ieee1394_device_id *unit_match(struct device *dev,
169 169 struct device_driver *drv)
170static int fw_unit_match(struct device *dev, struct device_driver *drv)
171{ 170{
172 const struct ieee1394_device_id *id_table = 171 const struct ieee1394_device_id *id_table =
173 container_of(drv, struct fw_driver, driver)->id_table; 172 container_of(drv, struct fw_driver, driver)->id_table;
174 int id[] = {0, 0, 0, 0}; 173 int id[] = {0, 0, 0, 0};
175 174
176 /* We only allow binding to fw_units. */
177 if (!is_fw_unit(dev))
178 return 0;
179
180 get_modalias_ids(fw_unit(dev), id); 175 get_modalias_ids(fw_unit(dev), id);
181 176
182 for (; id_table->match_flags != 0; id_table++) 177 for (; id_table->match_flags != 0; id_table++)
183 if (match_ids(id_table, id)) 178 if (match_ids(id_table, id))
184 return 1; 179 return id_table;
185 180
186 return 0; 181 return NULL;
182}
183
184static bool is_fw_unit(struct device *dev);
185
186static int fw_unit_match(struct device *dev, struct device_driver *drv)
187{
188 /* We only allow binding to fw_units. */
189 return is_fw_unit(dev) && unit_match(dev, drv) != NULL;
190}
191
192static int fw_unit_probe(struct device *dev)
193{
194 struct fw_driver *driver =
195 container_of(dev->driver, struct fw_driver, driver);
196
197 if (driver->probe)
198 return driver->probe(fw_unit(dev), unit_match(dev, dev->driver));
199 else
200 return driver->driver.probe(dev);
201}
202
203static int fw_unit_remove(struct device *dev)
204{
205 struct fw_driver *driver =
206 container_of(dev->driver, struct fw_driver, driver);
207
208 if (driver->remove)
209 return driver->remove(fw_unit(dev)), 0;
210 else
211 return driver->driver.remove(dev);
187} 212}
188 213
189static int get_modalias(struct fw_unit *unit, char *buffer, size_t buffer_size) 214static int get_modalias(struct fw_unit *unit, char *buffer, size_t buffer_size)
@@ -213,6 +238,8 @@ static int fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env)
213struct bus_type fw_bus_type = { 238struct bus_type fw_bus_type = {
214 .name = "firewire", 239 .name = "firewire",
215 .match = fw_unit_match, 240 .match = fw_unit_match,
241 .probe = fw_unit_probe,
242 .remove = fw_unit_remove,
216}; 243};
217EXPORT_SYMBOL(fw_bus_type); 244EXPORT_SYMBOL(fw_bus_type);
218 245
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index 815b0fcbe918..6b895986dc22 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -1440,9 +1440,9 @@ static int fwnet_add_peer(struct fwnet_device *dev,
1440 return 0; 1440 return 0;
1441} 1441}
1442 1442
1443static int fwnet_probe(struct device *_dev) 1443static int fwnet_probe(struct fw_unit *unit,
1444 const struct ieee1394_device_id *id)
1444{ 1445{
1445 struct fw_unit *unit = fw_unit(_dev);
1446 struct fw_device *device = fw_parent_device(unit); 1446 struct fw_device *device = fw_parent_device(unit);
1447 struct fw_card *card = device->card; 1447 struct fw_card *card = device->card;
1448 struct net_device *net; 1448 struct net_device *net;
@@ -1526,6 +1526,24 @@ static int fwnet_probe(struct device *_dev)
1526 return ret; 1526 return ret;
1527} 1527}
1528 1528
1529/*
1530 * FIXME abort partially sent fragmented datagrams,
1531 * discard partially received fragmented datagrams
1532 */
1533static void fwnet_update(struct fw_unit *unit)
1534{
1535 struct fw_device *device = fw_parent_device(unit);
1536 struct fwnet_peer *peer = dev_get_drvdata(&unit->device);
1537 int generation;
1538
1539 generation = device->generation;
1540
1541 spin_lock_irq(&peer->dev->lock);
1542 peer->node_id = device->node_id;
1543 peer->generation = generation;
1544 spin_unlock_irq(&peer->dev->lock);
1545}
1546
1529static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev) 1547static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev)
1530{ 1548{
1531 struct fwnet_partial_datagram *pd, *pd_next; 1549 struct fwnet_partial_datagram *pd, *pd_next;
@@ -1542,9 +1560,9 @@ static void fwnet_remove_peer(struct fwnet_peer *peer, struct fwnet_device *dev)
1542 kfree(peer); 1560 kfree(peer);
1543} 1561}
1544 1562
1545static int fwnet_remove(struct device *_dev) 1563static void fwnet_remove(struct fw_unit *unit)
1546{ 1564{
1547 struct fwnet_peer *peer = dev_get_drvdata(_dev); 1565 struct fwnet_peer *peer = dev_get_drvdata(&unit->device);
1548 struct fwnet_device *dev = peer->dev; 1566 struct fwnet_device *dev = peer->dev;
1549 struct net_device *net; 1567 struct net_device *net;
1550 int i; 1568 int i;
@@ -1569,26 +1587,6 @@ static int fwnet_remove(struct device *_dev)
1569 } 1587 }
1570 1588
1571 mutex_unlock(&fwnet_device_mutex); 1589 mutex_unlock(&fwnet_device_mutex);
1572
1573 return 0;
1574}
1575
1576/*
1577 * FIXME abort partially sent fragmented datagrams,
1578 * discard partially received fragmented datagrams
1579 */
1580static void fwnet_update(struct fw_unit *unit)
1581{
1582 struct fw_device *device = fw_parent_device(unit);
1583 struct fwnet_peer *peer = dev_get_drvdata(&unit->device);
1584 int generation;
1585
1586 generation = device->generation;
1587
1588 spin_lock_irq(&peer->dev->lock);
1589 peer->node_id = device->node_id;
1590 peer->generation = generation;
1591 spin_unlock_irq(&peer->dev->lock);
1592} 1590}
1593 1591
1594static const struct ieee1394_device_id fwnet_id_table[] = { 1592static const struct ieee1394_device_id fwnet_id_table[] = {
@@ -1614,10 +1612,10 @@ static struct fw_driver fwnet_driver = {
1614 .owner = THIS_MODULE, 1612 .owner = THIS_MODULE,
1615 .name = KBUILD_MODNAME, 1613 .name = KBUILD_MODNAME,
1616 .bus = &fw_bus_type, 1614 .bus = &fw_bus_type,
1617 .probe = fwnet_probe,
1618 .remove = fwnet_remove,
1619 }, 1615 },
1616 .probe = fwnet_probe,
1620 .update = fwnet_update, 1617 .update = fwnet_update,
1618 .remove = fwnet_remove,
1621 .id_table = fwnet_id_table, 1619 .id_table = fwnet_id_table,
1622}; 1620};
1623 1621
diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c
index 47674b913843..281029daf98c 100644
--- a/drivers/firewire/sbp2.c
+++ b/drivers/firewire/sbp2.c
@@ -1128,11 +1128,10 @@ static void sbp2_init_workarounds(struct sbp2_target *tgt, u32 model,
1128} 1128}
1129 1129
1130static struct scsi_host_template scsi_driver_template; 1130static struct scsi_host_template scsi_driver_template;
1131static int sbp2_remove(struct device *dev); 1131static void sbp2_remove(struct fw_unit *unit);
1132 1132
1133static int sbp2_probe(struct device *dev) 1133static int sbp2_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
1134{ 1134{
1135 struct fw_unit *unit = fw_unit(dev);
1136 struct fw_device *device = fw_parent_device(unit); 1135 struct fw_device *device = fw_parent_device(unit);
1137 struct sbp2_target *tgt; 1136 struct sbp2_target *tgt;
1138 struct sbp2_logical_unit *lu; 1137 struct sbp2_logical_unit *lu;
@@ -1196,7 +1195,7 @@ static int sbp2_probe(struct device *dev)
1196 return 0; 1195 return 0;
1197 1196
1198 fail_remove: 1197 fail_remove:
1199 sbp2_remove(dev); 1198 sbp2_remove(unit);
1200 return -ENOMEM; 1199 return -ENOMEM;
1201 1200
1202 fail_shost_put: 1201 fail_shost_put:
@@ -1222,9 +1221,8 @@ static void sbp2_update(struct fw_unit *unit)
1222 } 1221 }
1223} 1222}
1224 1223
1225static int sbp2_remove(struct device *dev) 1224static void sbp2_remove(struct fw_unit *unit)
1226{ 1225{
1227 struct fw_unit *unit = fw_unit(dev);
1228 struct fw_device *device = fw_parent_device(unit); 1226 struct fw_device *device = fw_parent_device(unit);
1229 struct sbp2_target *tgt = dev_get_drvdata(&unit->device); 1227 struct sbp2_target *tgt = dev_get_drvdata(&unit->device);
1230 struct sbp2_logical_unit *lu, *next; 1228 struct sbp2_logical_unit *lu, *next;
@@ -1261,10 +1259,9 @@ static int sbp2_remove(struct device *dev)
1261 kfree(lu); 1259 kfree(lu);
1262 } 1260 }
1263 scsi_remove_host(shost); 1261 scsi_remove_host(shost);
1264 dev_notice(dev, "released target %d:0:0\n", shost->host_no); 1262 dev_notice(&unit->device, "released target %d:0:0\n", shost->host_no);
1265 1263
1266 scsi_host_put(shost); 1264 scsi_host_put(shost);
1267 return 0;
1268} 1265}
1269 1266
1270#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e 1267#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
@@ -1285,10 +1282,10 @@ static struct fw_driver sbp2_driver = {
1285 .owner = THIS_MODULE, 1282 .owner = THIS_MODULE,
1286 .name = KBUILD_MODNAME, 1283 .name = KBUILD_MODNAME,
1287 .bus = &fw_bus_type, 1284 .bus = &fw_bus_type,
1288 .probe = sbp2_probe,
1289 .remove = sbp2_remove,
1290 }, 1285 },
1286 .probe = sbp2_probe,
1291 .update = sbp2_update, 1287 .update = sbp2_update,
1288 .remove = sbp2_remove,
1292 .id_table = sbp2_id_table, 1289 .id_table = sbp2_id_table,
1293}; 1290};
1294 1291