core-card.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/bug.h>
  19. #include <linux/completion.h>
  20. #include <linux/crc-itu-t.h>
  21. #include <linux/device.h>
  22. #include <linux/errno.h>
  23. #include <linux/firewire.h>
  24. #include <linux/firewire-constants.h>
  25. #include <linux/jiffies.h>
  26. #include <linux/kernel.h>
  27. #include <linux/kref.h>
  28. #include <linux/list.h>
  29. #include <linux/module.h>
  30. #include <linux/mutex.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/atomic.h>
  34. #include <asm/byteorder.h>
  35. #include "core.h"
  36. #define define_fw_printk_level(func, kern_level) \
  37. void func(const struct fw_card *card, const char *fmt, ...) \
  38. { \
  39. struct va_format vaf; \
  40. va_list args; \
  41. \
  42. va_start(args, fmt); \
  43. vaf.fmt = fmt; \
  44. vaf.va = &args; \
  45. printk(kern_level KBUILD_MODNAME " %s: %pV", \
  46. dev_name(card->device), &vaf); \
  47. va_end(args); \
  48. }
  49. define_fw_printk_level(fw_err, KERN_ERR);
  50. define_fw_printk_level(fw_notice, KERN_NOTICE);
  51. int fw_compute_block_crc(__be32 *block)
  52. {
  53. int length;
  54. u16 crc;
  55. length = (be32_to_cpu(block[0]) >> 16) & 0xff;
  56. crc = crc_itu_t(0, (u8 *)&block[1], length * 4);
  57. *block |= cpu_to_be32(crc);
  58. return length;
  59. }
  60. static DEFINE_MUTEX(card_mutex);
  61. static LIST_HEAD(card_list);
  62. static LIST_HEAD(descriptor_list);
  63. static int descriptor_count;
  64. static __be32 tmp_config_rom[256];
  65. /* ROM header, bus info block, root dir header, capabilities = 7 quadlets */
  66. static size_t config_rom_length = 1 + 4 + 1 + 1;
  67. #define BIB_CRC(v) ((v) << 0)
  68. #define BIB_CRC_LENGTH(v) ((v) << 16)
  69. #define BIB_INFO_LENGTH(v) ((v) << 24)
  70. #define BIB_BUS_NAME 0x31333934 /* "1394" */
  71. #define BIB_LINK_SPEED(v) ((v) << 0)
  72. #define BIB_GENERATION(v) ((v) << 4)
  73. #define BIB_MAX_ROM(v) ((v) << 8)
  74. #define BIB_MAX_RECEIVE(v) ((v) << 12)
  75. #define BIB_CYC_CLK_ACC(v) ((v) << 16)
  76. #define BIB_PMC ((1) << 27)
  77. #define BIB_BMC ((1) << 28)
  78. #define BIB_ISC ((1) << 29)
  79. #define BIB_CMC ((1) << 30)
  80. #define BIB_IRMC ((1) << 31)
  81. #define NODE_CAPABILITIES 0x0c0083c0 /* per IEEE 1394 clause 8.3.2.6.5.2 */
  82. /*
  83. * IEEE-1394 specifies a default SPLIT_TIMEOUT value of 800 cycles (100 ms),
  84. * but we have to make it longer because there are many devices whose firmware
  85. * is just too slow for that.
  86. */
  87. #define DEFAULT_SPLIT_TIMEOUT (2 * 8000)
  88. #define CANON_OUI 0x000085
  89. static void generate_config_rom(struct fw_card *card, __be32 *config_rom)
  90. {
  91. struct fw_descriptor *desc;
  92. int i, j, k, length;
  93. /*
  94. * Initialize contents of config rom buffer. On the OHCI
  95. * controller, block reads to the config rom accesses the host
  96. * memory, but quadlet read access the hardware bus info block
  97. * registers. That's just crack, but it means we should make
  98. * sure the contents of bus info block in host memory matches
  99. * the version stored in the OHCI registers.
  100. */
  101. config_rom[0] = cpu_to_be32(
  102. BIB_CRC_LENGTH(4) | BIB_INFO_LENGTH(4) | BIB_CRC(0));
  103. config_rom[1] = cpu_to_be32(BIB_BUS_NAME);
  104. config_rom[2] = cpu_to_be32(
  105. BIB_LINK_SPEED(card->link_speed) |
  106. BIB_GENERATION(card->config_rom_generation++ % 14 + 2) |
  107. BIB_MAX_ROM(2) |
  108. BIB_MAX_RECEIVE(card->max_receive) |
  109. BIB_BMC | BIB_ISC | BIB_CMC | BIB_IRMC);
  110. config_rom[3] = cpu_to_be32(card->guid >> 32);
  111. config_rom[4] = cpu_to_be32(card->guid);
  112. /* Generate root directory. */
  113. config_rom[6] = cpu_to_be32(NODE_CAPABILITIES);
  114. i = 7;
  115. j = 7 + descriptor_count;
  116. /* Generate root directory entries for descriptors. */
  117. list_for_each_entry (desc, &descriptor_list, link) {
  118. if (desc->immediate > 0)
  119. config_rom[i++] = cpu_to_be32(desc->immediate);
  120. config_rom[i] = cpu_to_be32(desc->key | (j - i));
  121. i++;
  122. j += desc->length;
  123. }
  124. /* Update root directory length. */
  125. config_rom[5] = cpu_to_be32((i - 5 - 1) << 16);
  126. /* End of root directory, now copy in descriptors. */
  127. list_for_each_entry (desc, &descriptor_list, link) {
  128. for (k = 0; k < desc->length; k++)
  129. config_rom[i + k] = cpu_to_be32(desc->data[k]);
  130. i += desc->length;
  131. }
  132. /* Calculate CRCs for all blocks in the config rom. This
  133. * assumes that CRC length and info length are identical for
  134. * the bus info block, which is always the case for this
  135. * implementation. */
  136. for (i = 0; i < j; i += length + 1)
  137. length = fw_compute_block_crc(config_rom + i);
  138. WARN_ON(j != config_rom_length);
  139. }
  140. static void update_config_roms(void)
  141. {
  142. struct fw_card *card;
  143. list_for_each_entry (card, &card_list, link) {
  144. generate_config_rom(card, tmp_config_rom);
  145. card->driver->set_config_rom(card, tmp_config_rom,
  146. config_rom_length);
  147. }
  148. }
  149. static size_t required_space(struct fw_descriptor *desc)
  150. {
  151. /* descriptor + entry into root dir + optional immediate entry */
  152. return desc->length + 1 + (desc->immediate > 0 ? 1 : 0);
  153. }
  154. int fw_core_add_descriptor(struct fw_descriptor *desc)
  155. {
  156. size_t i;
  157. int ret;
  158. /*
  159. * Check descriptor is valid; the length of all blocks in the
  160. * descriptor has to add up to exactly the length of the
  161. * block.
  162. */
  163. i = 0;
  164. while (i < desc->length)
  165. i += (desc->data[i] >> 16) + 1;
  166. if (i != desc->length)
  167. return -EINVAL;
  168. mutex_lock(&card_mutex);
  169. if (config_rom_length + required_space(desc) > 256) {
  170. ret = -EBUSY;
  171. } else {
  172. list_add_tail(&desc->link, &descriptor_list);
  173. config_rom_length += required_space(desc);
  174. descriptor_count++;
  175. if (desc->immediate > 0)
  176. descriptor_count++;
  177. update_config_roms();
  178. ret = 0;
  179. }
  180. mutex_unlock(&card_mutex);
  181. return ret;
  182. }
  183. EXPORT_SYMBOL(fw_core_add_descriptor);
  184. void fw_core_remove_descriptor(struct fw_descriptor *desc)
  185. {
  186. mutex_lock(&card_mutex);
  187. list_del(&desc->link);
  188. config_rom_length -= required_space(desc);
  189. descriptor_count--;
  190. if (desc->immediate > 0)
  191. descriptor_count--;
  192. update_config_roms();
  193. mutex_unlock(&card_mutex);
  194. }
  195. EXPORT_SYMBOL(fw_core_remove_descriptor);
  196. static int reset_bus(struct fw_card *card, bool short_reset)
  197. {
  198. int reg = short_reset ? 5 : 1;
  199. int bit = short_reset ? PHY_BUS_SHORT_RESET : PHY_BUS_RESET;
  200. return card->driver->update_phy_reg(card, reg, 0, bit);
  201. }
  202. void fw_schedule_bus_reset(struct fw_card *card, bool delayed, bool short_reset)
  203. {
  204. /* We don't try hard to sort out requests of long vs. short resets. */
  205. card->br_short = short_reset;
  206. /* Use an arbitrary short delay to combine multiple reset requests. */
  207. fw_card_get(card);
  208. if (!queue_delayed_work(fw_workqueue, &card->br_work,
  209. delayed ? DIV_ROUND_UP(HZ, 100) : 0))
  210. fw_card_put(card);
  211. }
  212. EXPORT_SYMBOL(fw_schedule_bus_reset);
  213. static void br_work(struct work_struct *work)
  214. {
  215. struct fw_card *card = container_of(work, struct fw_card, br_work.work);
  216. /* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */
  217. if (card->reset_jiffies != 0 &&
  218. time_before64(get_jiffies_64(), card->reset_jiffies + 2 * HZ)) {
  219. if (!queue_delayed_work(fw_workqueue, &card->br_work, 2 * HZ))
  220. fw_card_put(card);
  221. return;
  222. }
  223. fw_send_phy_config(card, FW_PHY_CONFIG_NO_NODE_ID, card->generation,
  224. FW_PHY_CONFIG_CURRENT_GAP_COUNT);
  225. reset_bus(card, card->br_short);
  226. fw_card_put(card);
  227. }
  228. static void allocate_broadcast_channel(struct fw_card *card, int generation)
  229. {
  230. int channel, bandwidth = 0;
  231. if (!card->broadcast_channel_allocated) {
  232. fw_iso_resource_manage(card, generation, 1ULL << 31,
  233. &channel, &bandwidth, true);
  234. if (channel != 31) {
  235. fw_notice(card, "failed to allocate broadcast channel\n");
  236. return;
  237. }
  238. card->broadcast_channel_allocated = true;
  239. }
  240. device_for_each_child(card->device, (void *)(long)generation,
  241. fw_device_set_broadcast_channel);
  242. }
  243. static const char gap_count_table[] = {
  244. 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40
  245. };
  246. void fw_schedule_bm_work(struct fw_card *card, unsigned long delay)
  247. {
  248. fw_card_get(card);
  249. if (!schedule_delayed_work(&card->bm_work, delay))
  250. fw_card_put(card);
  251. }
  252. static void bm_work(struct work_struct *work)
  253. {
  254. struct fw_card *card = container_of(work, struct fw_card, bm_work.work);
  255. struct fw_device *root_device, *irm_device;
  256. struct fw_node *root_node;
  257. int root_id, new_root_id, irm_id, bm_id, local_id;
  258. int gap_count, generation, grace, rcode;
  259. bool do_reset = false;
  260. bool root_device_is_running;
  261. bool root_device_is_cmc;
  262. bool irm_is_1394_1995_only;
  263. bool keep_this_irm;
  264. __be32 transaction_data[2];
  265. spin_lock_irq(&card->lock);
  266. if (card->local_node == NULL) {
  267. spin_unlock_irq(&card->lock);
  268. goto out_put_card;
  269. }
  270. generation = card->generation;
  271. root_node = card->root_node;
  272. fw_node_get(root_node);
  273. root_device = root_node->data;
  274. root_device_is_running = root_device &&
  275. atomic_read(&root_device->state) == FW_DEVICE_RUNNING;
  276. root_device_is_cmc = root_device && root_device->cmc;
  277. irm_device = card->irm_node->data;
  278. irm_is_1394_1995_only = irm_device && irm_device->config_rom &&
  279. (irm_device->config_rom[2] & 0x000000f0) == 0;
  280. /* Canon MV5i works unreliably if it is not root node. */
  281. keep_this_irm = irm_device && irm_device->config_rom &&
  282. irm_device->config_rom[3] >> 8 == CANON_OUI;
  283. root_id = root_node->node_id;
  284. irm_id = card->irm_node->node_id;
  285. local_id = card->local_node->node_id;
  286. grace = time_after64(get_jiffies_64(),
  287. card->reset_jiffies + DIV_ROUND_UP(HZ, 8));
  288. if ((is_next_generation(generation, card->bm_generation) &&
  289. !card->bm_abdicate) ||
  290. (card->bm_generation != generation && grace)) {
  291. /*
  292. * This first step is to figure out who is IRM and
  293. * then try to become bus manager. If the IRM is not
  294. * well defined (e.g. does not have an active link
  295. * layer or does not responds to our lock request, we
  296. * will have to do a little vigilante bus management.
  297. * In that case, we do a goto into the gap count logic
  298. * so that when we do the reset, we still optimize the
  299. * gap count. That could well save a reset in the
  300. * next generation.
  301. */
  302. if (!card->irm_node->link_on) {
  303. new_root_id = local_id;
  304. fw_notice(card, "%s, making local node (%02x) root\n",
  305. "IRM has link off", new_root_id);
  306. goto pick_me;
  307. }
  308. if (irm_is_1394_1995_only && !keep_this_irm) {
  309. new_root_id = local_id;
  310. fw_notice(card, "%s, making local node (%02x) root\n",
  311. "IRM is not 1394a compliant", new_root_id);
  312. goto pick_me;
  313. }
  314. transaction_data[0] = cpu_to_be32(0x3f);
  315. transaction_data[1] = cpu_to_be32(local_id);
  316. spin_unlock_irq(&card->lock);
  317. rcode = fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
  318. irm_id, generation, SCODE_100,
  319. CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID,
  320. transaction_data, 8);
  321. if (rcode == RCODE_GENERATION)
  322. /* Another bus reset, BM work has been rescheduled. */
  323. goto out;
  324. bm_id = be32_to_cpu(transaction_data[0]);
  325. spin_lock_irq(&card->lock);
  326. if (rcode == RCODE_COMPLETE && generation == card->generation)
  327. card->bm_node_id =
  328. bm_id == 0x3f ? local_id : 0xffc0 | bm_id;
  329. spin_unlock_irq(&card->lock);
  330. if (rcode == RCODE_COMPLETE && bm_id != 0x3f) {
  331. /* Somebody else is BM. Only act as IRM. */
  332. if (local_id == irm_id)
  333. allocate_broadcast_channel(card, generation);
  334. goto out;
  335. }
  336. if (rcode == RCODE_SEND_ERROR) {
  337. /*
  338. * We have been unable to send the lock request due to
  339. * some local problem. Let's try again later and hope
  340. * that the problem has gone away by then.
  341. */
  342. fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8));
  343. goto out;
  344. }
  345. spin_lock_irq(&card->lock);
  346. if (rcode != RCODE_COMPLETE && !keep_this_irm) {
  347. /*
  348. * The lock request failed, maybe the IRM
  349. * isn't really IRM capable after all. Let's
  350. * do a bus reset and pick the local node as
  351. * root, and thus, IRM.
  352. */
  353. new_root_id = local_id;
  354. fw_notice(card, "BM lock failed (%s), making local node (%02x) root\n",
  355. fw_rcode_string(rcode), new_root_id);
  356. goto pick_me;
  357. }
  358. } else if (card->bm_generation != generation) {
  359. /*
  360. * We weren't BM in the last generation, and the last
  361. * bus reset is less than 125ms ago. Reschedule this job.
  362. */
  363. spin_unlock_irq(&card->lock);
  364. fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8));
  365. goto out;
  366. }
  367. /*
  368. * We're bus manager for this generation, so next step is to
  369. * make sure we have an active cycle master and do gap count
  370. * optimization.
  371. */
  372. card->bm_generation = generation;
  373. if (root_device == NULL) {
  374. /*
  375. * Either link_on is false, or we failed to read the
  376. * config rom. In either case, pick another root.
  377. */
  378. new_root_id = local_id;
  379. } else if (!root_device_is_running) {
  380. /*
  381. * If we haven't probed this device yet, bail out now
  382. * and let's try again once that's done.
  383. */
  384. spin_unlock_irq(&card->lock);
  385. goto out;
  386. } else if (root_device_is_cmc) {
  387. /*
  388. * We will send out a force root packet for this
  389. * node as part of the gap count optimization.
  390. */
  391. new_root_id = root_id;
  392. } else {
  393. /*
  394. * Current root has an active link layer and we
  395. * successfully read the config rom, but it's not
  396. * cycle master capable.
  397. */
  398. new_root_id = local_id;
  399. }
  400. pick_me:
  401. /*
  402. * Pick a gap count from 1394a table E-1. The table doesn't cover
  403. * the typically much larger 1394b beta repeater delays though.
  404. */
  405. if (!card->beta_repeaters_present &&
  406. root_node->max_hops < ARRAY_SIZE(gap_count_table))
  407. gap_count = gap_count_table[root_node->max_hops];
  408. else
  409. gap_count = 63;
  410. /*
  411. * Finally, figure out if we should do a reset or not. If we have
  412. * done less than 5 resets with the same physical topology and we
  413. * have either a new root or a new gap count setting, let's do it.
  414. */
  415. if (card->bm_retries++ < 5 &&
  416. (card->gap_count != gap_count || new_root_id != root_id))
  417. do_reset = true;
  418. spin_unlock_irq(&card->lock);
  419. if (do_reset) {
  420. fw_notice(card, "phy config: new root=%x, gap_count=%d\n",
  421. new_root_id, gap_count);
  422. fw_send_phy_config(card, new_root_id, generation, gap_count);
  423. reset_bus(card, true);
  424. /* Will allocate broadcast channel after the reset. */
  425. goto out;
  426. }
  427. if (root_device_is_cmc) {
  428. /*
  429. * Make sure that the cycle master sends cycle start packets.
  430. */
  431. transaction_data[0] = cpu_to_be32(CSR_STATE_BIT_CMSTR);
  432. rcode = fw_run_transaction(card, TCODE_WRITE_QUADLET_REQUEST,
  433. root_id, generation, SCODE_100,
  434. CSR_REGISTER_BASE + CSR_STATE_SET,
  435. transaction_data, 4);
  436. if (rcode == RCODE_GENERATION)
  437. goto out;
  438. }
  439. if (local_id == irm_id)
  440. allocate_broadcast_channel(card, generation);
  441. out:
  442. fw_node_put(root_node);
  443. out_put_card:
  444. fw_card_put(card);
  445. }
  446. void fw_card_initialize(struct fw_card *card,
  447. const struct fw_card_driver *driver,
  448. struct device *device)
  449. {
  450. static atomic_t index = ATOMIC_INIT(-1);
  451. card->index = atomic_inc_return(&index);
  452. card->driver = driver;
  453. card->device = device;
  454. card->current_tlabel = 0;
  455. card->tlabel_mask = 0;
  456. card->split_timeout_hi = DEFAULT_SPLIT_TIMEOUT / 8000;
  457. card->split_timeout_lo = (DEFAULT_SPLIT_TIMEOUT % 8000) << 19;
  458. card->split_timeout_cycles = DEFAULT_SPLIT_TIMEOUT;
  459. card->split_timeout_jiffies =
  460. DIV_ROUND_UP(DEFAULT_SPLIT_TIMEOUT * HZ, 8000);
  461. card->color = 0;
  462. card->broadcast_channel = BROADCAST_CHANNEL_INITIAL;
  463. kref_init(&card->kref);
  464. init_completion(&card->done);
  465. INIT_LIST_HEAD(&card->transaction_list);
  466. INIT_LIST_HEAD(&card->phy_receiver_list);
  467. spin_lock_init(&card->lock);
  468. card->local_node = NULL;
  469. INIT_DELAYED_WORK(&card->br_work, br_work);
  470. INIT_DELAYED_WORK(&card->bm_work, bm_work);
  471. }
  472. EXPORT_SYMBOL(fw_card_initialize);
  473. int fw_card_add(struct fw_card *card,
  474. u32 max_receive, u32 link_speed, u64 guid)
  475. {
  476. int ret;
  477. card->max_receive = max_receive;
  478. card->link_speed = link_speed;
  479. card->guid = guid;
  480. mutex_lock(&card_mutex);
  481. generate_config_rom(card, tmp_config_rom);
  482. ret = card->driver->enable(card, tmp_config_rom, config_rom_length);
  483. if (ret == 0)
  484. list_add_tail(&card->link, &card_list);
  485. mutex_unlock(&card_mutex);
  486. return ret;
  487. }
  488. EXPORT_SYMBOL(fw_card_add);
  489. /*
  490. * The next few functions implement a dummy driver that is used once a card
  491. * driver shuts down an fw_card. This allows the driver to cleanly unload,
  492. * as all IO to the card will be handled (and failed) by the dummy driver
  493. * instead of calling into the module. Only functions for iso context
  494. * shutdown still need to be provided by the card driver.
  495. *
  496. * .read/write_csr() should never be called anymore after the dummy driver
  497. * was bound since they are only used within request handler context.
  498. * .set_config_rom() is never called since the card is taken out of card_list
  499. * before switching to the dummy driver.
  500. */
  501. static int dummy_read_phy_reg(struct fw_card *card, int address)
  502. {
  503. return -ENODEV;
  504. }
  505. static int dummy_update_phy_reg(struct fw_card *card, int address,
  506. int clear_bits, int set_bits)
  507. {
  508. return -ENODEV;
  509. }
  510. static void dummy_send_request(struct fw_card *card, struct fw_packet *packet)
  511. {
  512. packet->callback(packet, card, RCODE_CANCELLED);
  513. }
  514. static void dummy_send_response(struct fw_card *card, struct fw_packet *packet)
  515. {
  516. packet->callback(packet, card, RCODE_CANCELLED);
  517. }
  518. static int dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet)
  519. {
  520. return -ENOENT;
  521. }
  522. static int dummy_enable_phys_dma(struct fw_card *card,
  523. int node_id, int generation)
  524. {
  525. return -ENODEV;
  526. }
  527. static struct fw_iso_context *dummy_allocate_iso_context(struct fw_card *card,
  528. int type, int channel, size_t header_size)
  529. {
  530. return ERR_PTR(-ENODEV);
  531. }
  532. static int dummy_start_iso(struct fw_iso_context *ctx,
  533. s32 cycle, u32 sync, u32 tags)
  534. {
  535. return -ENODEV;
  536. }
  537. static int dummy_set_iso_channels(struct fw_iso_context *ctx, u64 *channels)
  538. {
  539. return -ENODEV;
  540. }
  541. static int dummy_queue_iso(struct fw_iso_context *ctx, struct fw_iso_packet *p,
  542. struct fw_iso_buffer *buffer, unsigned long payload)
  543. {
  544. return -ENODEV;
  545. }
  546. static void dummy_flush_queue_iso(struct fw_iso_context *ctx)
  547. {
  548. }
  549. static int dummy_flush_iso_completions(struct fw_iso_context *ctx)
  550. {
  551. return -ENODEV;
  552. }
  553. static const struct fw_card_driver dummy_driver_template = {
  554. .read_phy_reg = dummy_read_phy_reg,
  555. .update_phy_reg = dummy_update_phy_reg,
  556. .send_request = dummy_send_request,
  557. .send_response = dummy_send_response,
  558. .cancel_packet = dummy_cancel_packet,
  559. .enable_phys_dma = dummy_enable_phys_dma,
  560. .allocate_iso_context = dummy_allocate_iso_context,
  561. .start_iso = dummy_start_iso,
  562. .set_iso_channels = dummy_set_iso_channels,
  563. .queue_iso = dummy_queue_iso,
  564. .flush_queue_iso = dummy_flush_queue_iso,
  565. .flush_iso_completions = dummy_flush_iso_completions,
  566. };
  567. void fw_card_release(struct kref *kref)
  568. {
  569. struct fw_card *card = container_of(kref, struct fw_card, kref);
  570. complete(&card->done);
  571. }
  572. EXPORT_SYMBOL_GPL(fw_card_release);
  573. void fw_core_remove_card(struct fw_card *card)
  574. {
  575. struct fw_card_driver dummy_driver = dummy_driver_template;
  576. card->driver->update_phy_reg(card, 4,
  577. PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
  578. fw_schedule_bus_reset(card, false, true);
  579. mutex_lock(&card_mutex);
  580. list_del_init(&card->link);
  581. mutex_unlock(&card_mutex);
  582. /* Switch off most of the card driver interface. */
  583. dummy_driver.free_iso_context = card->driver->free_iso_context;
  584. dummy_driver.stop_iso = card->driver->stop_iso;
  585. card->driver = &dummy_driver;
  586. fw_destroy_nodes(card);
  587. /* Wait for all users, especially device workqueue jobs, to finish. */
  588. fw_card_put(card);
  589. wait_for_completion(&card->done);
  590. WARN_ON(!list_empty(&card->transaction_list));
  591. }
  592. EXPORT_SYMBOL(fw_core_remove_card);