core-transaction.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. /*
  2. * Core IEEE1394 transaction logic
  3. *
  4. * Copyright (C) 2004-2006 Kristian Hoegsberg <krh@bitplanet.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <linux/bug.h>
  21. #include <linux/completion.h>
  22. #include <linux/device.h>
  23. #include <linux/errno.h>
  24. #include <linux/firewire.h>
  25. #include <linux/firewire-constants.h>
  26. #include <linux/fs.h>
  27. #include <linux/init.h>
  28. #include <linux/idr.h>
  29. #include <linux/jiffies.h>
  30. #include <linux/kernel.h>
  31. #include <linux/list.h>
  32. #include <linux/module.h>
  33. #include <linux/rculist.h>
  34. #include <linux/slab.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/string.h>
  37. #include <linux/timer.h>
  38. #include <linux/types.h>
  39. #include <linux/workqueue.h>
  40. #include <asm/byteorder.h>
  41. #include "core.h"
  42. #define HEADER_PRI(pri) ((pri) << 0)
  43. #define HEADER_TCODE(tcode) ((tcode) << 4)
  44. #define HEADER_RETRY(retry) ((retry) << 8)
  45. #define HEADER_TLABEL(tlabel) ((tlabel) << 10)
  46. #define HEADER_DESTINATION(destination) ((destination) << 16)
  47. #define HEADER_SOURCE(source) ((source) << 16)
  48. #define HEADER_RCODE(rcode) ((rcode) << 12)
  49. #define HEADER_OFFSET_HIGH(offset_high) ((offset_high) << 0)
  50. #define HEADER_DATA_LENGTH(length) ((length) << 16)
  51. #define HEADER_EXTENDED_TCODE(tcode) ((tcode) << 0)
  52. #define HEADER_GET_TCODE(q) (((q) >> 4) & 0x0f)
  53. #define HEADER_GET_TLABEL(q) (((q) >> 10) & 0x3f)
  54. #define HEADER_GET_RCODE(q) (((q) >> 12) & 0x0f)
  55. #define HEADER_GET_DESTINATION(q) (((q) >> 16) & 0xffff)
  56. #define HEADER_GET_SOURCE(q) (((q) >> 16) & 0xffff)
  57. #define HEADER_GET_OFFSET_HIGH(q) (((q) >> 0) & 0xffff)
  58. #define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff)
  59. #define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff)
  60. #define HEADER_DESTINATION_IS_BROADCAST(q) \
  61. (((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f))
  62. #define PHY_PACKET_CONFIG 0x0
  63. #define PHY_PACKET_LINK_ON 0x1
  64. #define PHY_PACKET_SELF_ID 0x2
  65. #define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22))
  66. #define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23))
  67. #define PHY_IDENTIFIER(id) ((id) << 30)
  68. /* returns 0 if the split timeout handler is already running */
  69. static int try_cancel_split_timeout(struct fw_transaction *t)
  70. {
  71. if (t->is_split_transaction)
  72. return del_timer(&t->split_timeout_timer);
  73. else
  74. return 1;
  75. }
  76. static int close_transaction(struct fw_transaction *transaction,
  77. struct fw_card *card, int rcode)
  78. {
  79. struct fw_transaction *t;
  80. unsigned long flags;
  81. spin_lock_irqsave(&card->lock, flags);
  82. list_for_each_entry(t, &card->transaction_list, link) {
  83. if (t == transaction) {
  84. if (!try_cancel_split_timeout(t)) {
  85. spin_unlock_irqrestore(&card->lock, flags);
  86. goto timed_out;
  87. }
  88. list_del_init(&t->link);
  89. card->tlabel_mask &= ~(1ULL << t->tlabel);
  90. break;
  91. }
  92. }
  93. spin_unlock_irqrestore(&card->lock, flags);
  94. if (&t->link != &card->transaction_list) {
  95. t->callback(card, rcode, NULL, 0, t->callback_data);
  96. return 0;
  97. }
  98. timed_out:
  99. return -ENOENT;
  100. }
  101. /*
  102. * Only valid for transactions that are potentially pending (ie have
  103. * been sent).
  104. */
  105. int fw_cancel_transaction(struct fw_card *card,
  106. struct fw_transaction *transaction)
  107. {
  108. /*
  109. * Cancel the packet transmission if it's still queued. That
  110. * will call the packet transmission callback which cancels
  111. * the transaction.
  112. */
  113. if (card->driver->cancel_packet(card, &transaction->packet) == 0)
  114. return 0;
  115. /*
  116. * If the request packet has already been sent, we need to see
  117. * if the transaction is still pending and remove it in that case.
  118. */
  119. return close_transaction(transaction, card, RCODE_CANCELLED);
  120. }
  121. EXPORT_SYMBOL(fw_cancel_transaction);
  122. static void split_transaction_timeout_callback(struct timer_list *timer)
  123. {
  124. struct fw_transaction *t = from_timer(t, timer, split_timeout_timer);
  125. struct fw_card *card = t->card;
  126. unsigned long flags;
  127. spin_lock_irqsave(&card->lock, flags);
  128. if (list_empty(&t->link)) {
  129. spin_unlock_irqrestore(&card->lock, flags);
  130. return;
  131. }
  132. list_del(&t->link);
  133. card->tlabel_mask &= ~(1ULL << t->tlabel);
  134. spin_unlock_irqrestore(&card->lock, flags);
  135. t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data);
  136. }
  137. static void start_split_transaction_timeout(struct fw_transaction *t,
  138. struct fw_card *card)
  139. {
  140. unsigned long flags;
  141. spin_lock_irqsave(&card->lock, flags);
  142. if (list_empty(&t->link) || WARN_ON(t->is_split_transaction)) {
  143. spin_unlock_irqrestore(&card->lock, flags);
  144. return;
  145. }
  146. t->is_split_transaction = true;
  147. mod_timer(&t->split_timeout_timer,
  148. jiffies + card->split_timeout_jiffies);
  149. spin_unlock_irqrestore(&card->lock, flags);
  150. }
  151. static void transmit_complete_callback(struct fw_packet *packet,
  152. struct fw_card *card, int status)
  153. {
  154. struct fw_transaction *t =
  155. container_of(packet, struct fw_transaction, packet);
  156. switch (status) {
  157. case ACK_COMPLETE:
  158. close_transaction(t, card, RCODE_COMPLETE);
  159. break;
  160. case ACK_PENDING:
  161. start_split_transaction_timeout(t, card);
  162. break;
  163. case ACK_BUSY_X:
  164. case ACK_BUSY_A:
  165. case ACK_BUSY_B:
  166. close_transaction(t, card, RCODE_BUSY);
  167. break;
  168. case ACK_DATA_ERROR:
  169. close_transaction(t, card, RCODE_DATA_ERROR);
  170. break;
  171. case ACK_TYPE_ERROR:
  172. close_transaction(t, card, RCODE_TYPE_ERROR);
  173. break;
  174. default:
  175. /*
  176. * In this case the ack is really a juju specific
  177. * rcode, so just forward that to the callback.
  178. */
  179. close_transaction(t, card, status);
  180. break;
  181. }
  182. }
  183. static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
  184. int destination_id, int source_id, int generation, int speed,
  185. unsigned long long offset, void *payload, size_t length)
  186. {
  187. int ext_tcode;
  188. if (tcode == TCODE_STREAM_DATA) {
  189. packet->header[0] =
  190. HEADER_DATA_LENGTH(length) |
  191. destination_id |
  192. HEADER_TCODE(TCODE_STREAM_DATA);
  193. packet->header_length = 4;
  194. packet->payload = payload;
  195. packet->payload_length = length;
  196. goto common;
  197. }
  198. if (tcode > 0x10) {
  199. ext_tcode = tcode & ~0x10;
  200. tcode = TCODE_LOCK_REQUEST;
  201. } else
  202. ext_tcode = 0;
  203. packet->header[0] =
  204. HEADER_RETRY(RETRY_X) |
  205. HEADER_TLABEL(tlabel) |
  206. HEADER_TCODE(tcode) |
  207. HEADER_DESTINATION(destination_id);
  208. packet->header[1] =
  209. HEADER_OFFSET_HIGH(offset >> 32) | HEADER_SOURCE(source_id);
  210. packet->header[2] =
  211. offset;
  212. switch (tcode) {
  213. case TCODE_WRITE_QUADLET_REQUEST:
  214. packet->header[3] = *(u32 *)payload;
  215. packet->header_length = 16;
  216. packet->payload_length = 0;
  217. break;
  218. case TCODE_LOCK_REQUEST:
  219. case TCODE_WRITE_BLOCK_REQUEST:
  220. packet->header[3] =
  221. HEADER_DATA_LENGTH(length) |
  222. HEADER_EXTENDED_TCODE(ext_tcode);
  223. packet->header_length = 16;
  224. packet->payload = payload;
  225. packet->payload_length = length;
  226. break;
  227. case TCODE_READ_QUADLET_REQUEST:
  228. packet->header_length = 12;
  229. packet->payload_length = 0;
  230. break;
  231. case TCODE_READ_BLOCK_REQUEST:
  232. packet->header[3] =
  233. HEADER_DATA_LENGTH(length) |
  234. HEADER_EXTENDED_TCODE(ext_tcode);
  235. packet->header_length = 16;
  236. packet->payload_length = 0;
  237. break;
  238. default:
  239. WARN(1, "wrong tcode %d\n", tcode);
  240. }
  241. common:
  242. packet->speed = speed;
  243. packet->generation = generation;
  244. packet->ack = 0;
  245. packet->payload_mapped = false;
  246. }
  247. static int allocate_tlabel(struct fw_card *card)
  248. {
  249. int tlabel;
  250. tlabel = card->current_tlabel;
  251. while (card->tlabel_mask & (1ULL << tlabel)) {
  252. tlabel = (tlabel + 1) & 0x3f;
  253. if (tlabel == card->current_tlabel)
  254. return -EBUSY;
  255. }
  256. card->current_tlabel = (tlabel + 1) & 0x3f;
  257. card->tlabel_mask |= 1ULL << tlabel;
  258. return tlabel;
  259. }
  260. /**
  261. * fw_send_request() - submit a request packet for transmission
  262. * @card: interface to send the request at
  263. * @t: transaction instance to which the request belongs
  264. * @tcode: transaction code
  265. * @destination_id: destination node ID, consisting of bus_ID and phy_ID
  266. * @generation: bus generation in which request and response are valid
  267. * @speed: transmission speed
  268. * @offset: 48bit wide offset into destination's address space
  269. * @payload: data payload for the request subaction
  270. * @length: length of the payload, in bytes
  271. * @callback: function to be called when the transaction is completed
  272. * @callback_data: data to be passed to the transaction completion callback
  273. *
  274. * Submit a request packet into the asynchronous request transmission queue.
  275. * Can be called from atomic context. If you prefer a blocking API, use
  276. * fw_run_transaction() in a context that can sleep.
  277. *
  278. * In case of lock requests, specify one of the firewire-core specific %TCODE_
  279. * constants instead of %TCODE_LOCK_REQUEST in @tcode.
  280. *
  281. * Make sure that the value in @destination_id is not older than the one in
  282. * @generation. Otherwise the request is in danger to be sent to a wrong node.
  283. *
  284. * In case of asynchronous stream packets i.e. %TCODE_STREAM_DATA, the caller
  285. * needs to synthesize @destination_id with fw_stream_packet_destination_id().
  286. * It will contain tag, channel, and sy data instead of a node ID then.
  287. *
  288. * The payload buffer at @data is going to be DMA-mapped except in case of
  289. * @length <= 8 or of local (loopback) requests. Hence make sure that the
  290. * buffer complies with the restrictions of the streaming DMA mapping API.
  291. * @payload must not be freed before the @callback is called.
  292. *
  293. * In case of request types without payload, @data is NULL and @length is 0.
  294. *
  295. * After the transaction is completed successfully or unsuccessfully, the
  296. * @callback will be called. Among its parameters is the response code which
  297. * is either one of the rcodes per IEEE 1394 or, in case of internal errors,
  298. * the firewire-core specific %RCODE_SEND_ERROR. The other firewire-core
  299. * specific rcodes (%RCODE_CANCELLED, %RCODE_BUSY, %RCODE_GENERATION,
  300. * %RCODE_NO_ACK) denote transaction timeout, busy responder, stale request
  301. * generation, or missing ACK respectively.
  302. *
  303. * Note some timing corner cases: fw_send_request() may complete much earlier
  304. * than when the request packet actually hits the wire. On the other hand,
  305. * transaction completion and hence execution of @callback may happen even
  306. * before fw_send_request() returns.
  307. */
  308. void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode,
  309. int destination_id, int generation, int speed,
  310. unsigned long long offset, void *payload, size_t length,
  311. fw_transaction_callback_t callback, void *callback_data)
  312. {
  313. unsigned long flags;
  314. int tlabel;
  315. /*
  316. * Allocate tlabel from the bitmap and put the transaction on
  317. * the list while holding the card spinlock.
  318. */
  319. spin_lock_irqsave(&card->lock, flags);
  320. tlabel = allocate_tlabel(card);
  321. if (tlabel < 0) {
  322. spin_unlock_irqrestore(&card->lock, flags);
  323. callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data);
  324. return;
  325. }
  326. t->node_id = destination_id;
  327. t->tlabel = tlabel;
  328. t->card = card;
  329. t->is_split_transaction = false;
  330. timer_setup(&t->split_timeout_timer,
  331. split_transaction_timeout_callback, 0);
  332. t->callback = callback;
  333. t->callback_data = callback_data;
  334. fw_fill_request(&t->packet, tcode, t->tlabel,
  335. destination_id, card->node_id, generation,
  336. speed, offset, payload, length);
  337. t->packet.callback = transmit_complete_callback;
  338. list_add_tail(&t->link, &card->transaction_list);
  339. spin_unlock_irqrestore(&card->lock, flags);
  340. card->driver->send_request(card, &t->packet);
  341. }
  342. EXPORT_SYMBOL(fw_send_request);
  343. struct transaction_callback_data {
  344. struct completion done;
  345. void *payload;
  346. int rcode;
  347. };
  348. static void transaction_callback(struct fw_card *card, int rcode,
  349. void *payload, size_t length, void *data)
  350. {
  351. struct transaction_callback_data *d = data;
  352. if (rcode == RCODE_COMPLETE)
  353. memcpy(d->payload, payload, length);
  354. d->rcode = rcode;
  355. complete(&d->done);
  356. }
  357. /**
  358. * fw_run_transaction() - send request and sleep until transaction is completed
  359. * @card: card interface for this request
  360. * @tcode: transaction code
  361. * @destination_id: destination node ID, consisting of bus_ID and phy_ID
  362. * @generation: bus generation in which request and response are valid
  363. * @speed: transmission speed
  364. * @offset: 48bit wide offset into destination's address space
  365. * @payload: data payload for the request subaction
  366. * @length: length of the payload, in bytes
  367. *
  368. * Returns the RCODE. See fw_send_request() for parameter documentation.
  369. * Unlike fw_send_request(), @data points to the payload of the request or/and
  370. * to the payload of the response. DMA mapping restrictions apply to outbound
  371. * request payloads of >= 8 bytes but not to inbound response payloads.
  372. */
  373. int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
  374. int generation, int speed, unsigned long long offset,
  375. void *payload, size_t length)
  376. {
  377. struct transaction_callback_data d;
  378. struct fw_transaction t;
  379. timer_setup_on_stack(&t.split_timeout_timer, NULL, 0);
  380. init_completion(&d.done);
  381. d.payload = payload;
  382. fw_send_request(card, &t, tcode, destination_id, generation, speed,
  383. offset, payload, length, transaction_callback, &d);
  384. wait_for_completion(&d.done);
  385. destroy_timer_on_stack(&t.split_timeout_timer);
  386. return d.rcode;
  387. }
  388. EXPORT_SYMBOL(fw_run_transaction);
  389. static DEFINE_MUTEX(phy_config_mutex);
  390. static DECLARE_COMPLETION(phy_config_done);
  391. static void transmit_phy_packet_callback(struct fw_packet *packet,
  392. struct fw_card *card, int status)
  393. {
  394. complete(&phy_config_done);
  395. }
  396. static struct fw_packet phy_config_packet = {
  397. .header_length = 12,
  398. .header[0] = TCODE_LINK_INTERNAL << 4,
  399. .payload_length = 0,
  400. .speed = SCODE_100,
  401. .callback = transmit_phy_packet_callback,
  402. };
  403. void fw_send_phy_config(struct fw_card *card,
  404. int node_id, int generation, int gap_count)
  405. {
  406. long timeout = DIV_ROUND_UP(HZ, 10);
  407. u32 data = PHY_IDENTIFIER(PHY_PACKET_CONFIG);
  408. if (node_id != FW_PHY_CONFIG_NO_NODE_ID)
  409. data |= PHY_CONFIG_ROOT_ID(node_id);
  410. if (gap_count == FW_PHY_CONFIG_CURRENT_GAP_COUNT) {
  411. gap_count = card->driver->read_phy_reg(card, 1);
  412. if (gap_count < 0)
  413. return;
  414. gap_count &= 63;
  415. if (gap_count == 63)
  416. return;
  417. }
  418. data |= PHY_CONFIG_GAP_COUNT(gap_count);
  419. mutex_lock(&phy_config_mutex);
  420. phy_config_packet.header[1] = data;
  421. phy_config_packet.header[2] = ~data;
  422. phy_config_packet.generation = generation;
  423. reinit_completion(&phy_config_done);
  424. card->driver->send_request(card, &phy_config_packet);
  425. wait_for_completion_timeout(&phy_config_done, timeout);
  426. mutex_unlock(&phy_config_mutex);
  427. }
  428. static struct fw_address_handler *lookup_overlapping_address_handler(
  429. struct list_head *list, unsigned long long offset, size_t length)
  430. {
  431. struct fw_address_handler *handler;
  432. list_for_each_entry_rcu(handler, list, link) {
  433. if (handler->offset < offset + length &&
  434. offset < handler->offset + handler->length)
  435. return handler;
  436. }
  437. return NULL;
  438. }
  439. static bool is_enclosing_handler(struct fw_address_handler *handler,
  440. unsigned long long offset, size_t length)
  441. {
  442. return handler->offset <= offset &&
  443. offset + length <= handler->offset + handler->length;
  444. }
  445. static struct fw_address_handler *lookup_enclosing_address_handler(
  446. struct list_head *list, unsigned long long offset, size_t length)
  447. {
  448. struct fw_address_handler *handler;
  449. list_for_each_entry_rcu(handler, list, link) {
  450. if (is_enclosing_handler(handler, offset, length))
  451. return handler;
  452. }
  453. return NULL;
  454. }
  455. static DEFINE_SPINLOCK(address_handler_list_lock);
  456. static LIST_HEAD(address_handler_list);
  457. const struct fw_address_region fw_high_memory_region =
  458. { .start = FW_MAX_PHYSICAL_RANGE, .end = 0xffffe0000000ULL, };
  459. EXPORT_SYMBOL(fw_high_memory_region);
  460. static const struct fw_address_region low_memory_region =
  461. { .start = 0x000000000000ULL, .end = FW_MAX_PHYSICAL_RANGE, };
  462. #if 0
  463. const struct fw_address_region fw_private_region =
  464. { .start = 0xffffe0000000ULL, .end = 0xfffff0000000ULL, };
  465. const struct fw_address_region fw_csr_region =
  466. { .start = CSR_REGISTER_BASE,
  467. .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM_END, };
  468. const struct fw_address_region fw_unit_space_region =
  469. { .start = 0xfffff0000900ULL, .end = 0x1000000000000ULL, };
  470. #endif /* 0 */
  471. static bool is_in_fcp_region(u64 offset, size_t length)
  472. {
  473. return offset >= (CSR_REGISTER_BASE | CSR_FCP_COMMAND) &&
  474. offset + length <= (CSR_REGISTER_BASE | CSR_FCP_END);
  475. }
  476. /**
  477. * fw_core_add_address_handler() - register for incoming requests
  478. * @handler: callback
  479. * @region: region in the IEEE 1212 node space address range
  480. *
  481. * region->start, ->end, and handler->length have to be quadlet-aligned.
  482. *
  483. * When a request is received that falls within the specified address range,
  484. * the specified callback is invoked. The parameters passed to the callback
  485. * give the details of the particular request.
  486. *
  487. * To be called in process context.
  488. * Return value: 0 on success, non-zero otherwise.
  489. *
  490. * The start offset of the handler's address region is determined by
  491. * fw_core_add_address_handler() and is returned in handler->offset.
  492. *
  493. * Address allocations are exclusive, except for the FCP registers.
  494. */
  495. int fw_core_add_address_handler(struct fw_address_handler *handler,
  496. const struct fw_address_region *region)
  497. {
  498. struct fw_address_handler *other;
  499. int ret = -EBUSY;
  500. if (region->start & 0xffff000000000003ULL ||
  501. region->start >= region->end ||
  502. region->end > 0x0001000000000000ULL ||
  503. handler->length & 3 ||
  504. handler->length == 0)
  505. return -EINVAL;
  506. spin_lock(&address_handler_list_lock);
  507. handler->offset = region->start;
  508. while (handler->offset + handler->length <= region->end) {
  509. if (is_in_fcp_region(handler->offset, handler->length))
  510. other = NULL;
  511. else
  512. other = lookup_overlapping_address_handler
  513. (&address_handler_list,
  514. handler->offset, handler->length);
  515. if (other != NULL) {
  516. handler->offset += other->length;
  517. } else {
  518. list_add_tail_rcu(&handler->link, &address_handler_list);
  519. ret = 0;
  520. break;
  521. }
  522. }
  523. spin_unlock(&address_handler_list_lock);
  524. return ret;
  525. }
  526. EXPORT_SYMBOL(fw_core_add_address_handler);
  527. /**
  528. * fw_core_remove_address_handler() - unregister an address handler
  529. * @handler: callback
  530. *
  531. * To be called in process context.
  532. *
  533. * When fw_core_remove_address_handler() returns, @handler->callback() is
  534. * guaranteed to not run on any CPU anymore.
  535. */
  536. void fw_core_remove_address_handler(struct fw_address_handler *handler)
  537. {
  538. spin_lock(&address_handler_list_lock);
  539. list_del_rcu(&handler->link);
  540. spin_unlock(&address_handler_list_lock);
  541. synchronize_rcu();
  542. }
  543. EXPORT_SYMBOL(fw_core_remove_address_handler);
  544. struct fw_request {
  545. struct fw_packet response;
  546. u32 request_header[4];
  547. int ack;
  548. u32 length;
  549. u32 data[0];
  550. };
  551. static void free_response_callback(struct fw_packet *packet,
  552. struct fw_card *card, int status)
  553. {
  554. struct fw_request *request;
  555. request = container_of(packet, struct fw_request, response);
  556. kfree(request);
  557. }
  558. int fw_get_response_length(struct fw_request *r)
  559. {
  560. int tcode, ext_tcode, data_length;
  561. tcode = HEADER_GET_TCODE(r->request_header[0]);
  562. switch (tcode) {
  563. case TCODE_WRITE_QUADLET_REQUEST:
  564. case TCODE_WRITE_BLOCK_REQUEST:
  565. return 0;
  566. case TCODE_READ_QUADLET_REQUEST:
  567. return 4;
  568. case TCODE_READ_BLOCK_REQUEST:
  569. data_length = HEADER_GET_DATA_LENGTH(r->request_header[3]);
  570. return data_length;
  571. case TCODE_LOCK_REQUEST:
  572. ext_tcode = HEADER_GET_EXTENDED_TCODE(r->request_header[3]);
  573. data_length = HEADER_GET_DATA_LENGTH(r->request_header[3]);
  574. switch (ext_tcode) {
  575. case EXTCODE_FETCH_ADD:
  576. case EXTCODE_LITTLE_ADD:
  577. return data_length;
  578. default:
  579. return data_length / 2;
  580. }
  581. default:
  582. WARN(1, "wrong tcode %d\n", tcode);
  583. return 0;
  584. }
  585. }
  586. void fw_fill_response(struct fw_packet *response, u32 *request_header,
  587. int rcode, void *payload, size_t length)
  588. {
  589. int tcode, tlabel, extended_tcode, source, destination;
  590. tcode = HEADER_GET_TCODE(request_header[0]);
  591. tlabel = HEADER_GET_TLABEL(request_header[0]);
  592. source = HEADER_GET_DESTINATION(request_header[0]);
  593. destination = HEADER_GET_SOURCE(request_header[1]);
  594. extended_tcode = HEADER_GET_EXTENDED_TCODE(request_header[3]);
  595. response->header[0] =
  596. HEADER_RETRY(RETRY_1) |
  597. HEADER_TLABEL(tlabel) |
  598. HEADER_DESTINATION(destination);
  599. response->header[1] =
  600. HEADER_SOURCE(source) |
  601. HEADER_RCODE(rcode);
  602. response->header[2] = 0;
  603. switch (tcode) {
  604. case TCODE_WRITE_QUADLET_REQUEST:
  605. case TCODE_WRITE_BLOCK_REQUEST:
  606. response->header[0] |= HEADER_TCODE(TCODE_WRITE_RESPONSE);
  607. response->header_length = 12;
  608. response->payload_length = 0;
  609. break;
  610. case TCODE_READ_QUADLET_REQUEST:
  611. response->header[0] |=
  612. HEADER_TCODE(TCODE_READ_QUADLET_RESPONSE);
  613. if (payload != NULL)
  614. response->header[3] = *(u32 *)payload;
  615. else
  616. response->header[3] = 0;
  617. response->header_length = 16;
  618. response->payload_length = 0;
  619. break;
  620. case TCODE_READ_BLOCK_REQUEST:
  621. case TCODE_LOCK_REQUEST:
  622. response->header[0] |= HEADER_TCODE(tcode + 2);
  623. response->header[3] =
  624. HEADER_DATA_LENGTH(length) |
  625. HEADER_EXTENDED_TCODE(extended_tcode);
  626. response->header_length = 16;
  627. response->payload = payload;
  628. response->payload_length = length;
  629. break;
  630. default:
  631. WARN(1, "wrong tcode %d\n", tcode);
  632. }
  633. response->payload_mapped = false;
  634. }
  635. EXPORT_SYMBOL(fw_fill_response);
  636. static u32 compute_split_timeout_timestamp(struct fw_card *card,
  637. u32 request_timestamp)
  638. {
  639. unsigned int cycles;
  640. u32 timestamp;
  641. cycles = card->split_timeout_cycles;
  642. cycles += request_timestamp & 0x1fff;
  643. timestamp = request_timestamp & ~0x1fff;
  644. timestamp += (cycles / 8000) << 13;
  645. timestamp |= cycles % 8000;
  646. return timestamp;
  647. }
  648. static struct fw_request *allocate_request(struct fw_card *card,
  649. struct fw_packet *p)
  650. {
  651. struct fw_request *request;
  652. u32 *data, length;
  653. int request_tcode;
  654. request_tcode = HEADER_GET_TCODE(p->header[0]);
  655. switch (request_tcode) {
  656. case TCODE_WRITE_QUADLET_REQUEST:
  657. data = &p->header[3];
  658. length = 4;
  659. break;
  660. case TCODE_WRITE_BLOCK_REQUEST:
  661. case TCODE_LOCK_REQUEST:
  662. data = p->payload;
  663. length = HEADER_GET_DATA_LENGTH(p->header[3]);
  664. break;
  665. case TCODE_READ_QUADLET_REQUEST:
  666. data = NULL;
  667. length = 4;
  668. break;
  669. case TCODE_READ_BLOCK_REQUEST:
  670. data = NULL;
  671. length = HEADER_GET_DATA_LENGTH(p->header[3]);
  672. break;
  673. default:
  674. fw_notice(card, "ERROR - corrupt request received - %08x %08x %08x\n",
  675. p->header[0], p->header[1], p->header[2]);
  676. return NULL;
  677. }
  678. request = kmalloc(sizeof(*request) + length, GFP_ATOMIC);
  679. if (request == NULL)
  680. return NULL;
  681. request->response.speed = p->speed;
  682. request->response.timestamp =
  683. compute_split_timeout_timestamp(card, p->timestamp);
  684. request->response.generation = p->generation;
  685. request->response.ack = 0;
  686. request->response.callback = free_response_callback;
  687. request->ack = p->ack;
  688. request->length = length;
  689. if (data)
  690. memcpy(request->data, data, length);
  691. memcpy(request->request_header, p->header, sizeof(p->header));
  692. return request;
  693. }
  694. void fw_send_response(struct fw_card *card,
  695. struct fw_request *request, int rcode)
  696. {
  697. if (WARN_ONCE(!request, "invalid for FCP address handlers"))
  698. return;
  699. /* unified transaction or broadcast transaction: don't respond */
  700. if (request->ack != ACK_PENDING ||
  701. HEADER_DESTINATION_IS_BROADCAST(request->request_header[0])) {
  702. kfree(request);
  703. return;
  704. }
  705. if (rcode == RCODE_COMPLETE)
  706. fw_fill_response(&request->response, request->request_header,
  707. rcode, request->data,
  708. fw_get_response_length(request));
  709. else
  710. fw_fill_response(&request->response, request->request_header,
  711. rcode, NULL, 0);
  712. card->driver->send_response(card, &request->response);
  713. }
  714. EXPORT_SYMBOL(fw_send_response);
  715. /**
  716. * fw_get_request_speed() - returns speed at which the @request was received
  717. * @request: firewire request data
  718. */
  719. int fw_get_request_speed(struct fw_request *request)
  720. {
  721. return request->response.speed;
  722. }
  723. EXPORT_SYMBOL(fw_get_request_speed);
  724. static void handle_exclusive_region_request(struct fw_card *card,
  725. struct fw_packet *p,
  726. struct fw_request *request,
  727. unsigned long long offset)
  728. {
  729. struct fw_address_handler *handler;
  730. int tcode, destination, source;
  731. destination = HEADER_GET_DESTINATION(p->header[0]);
  732. source = HEADER_GET_SOURCE(p->header[1]);
  733. tcode = HEADER_GET_TCODE(p->header[0]);
  734. if (tcode == TCODE_LOCK_REQUEST)
  735. tcode = 0x10 + HEADER_GET_EXTENDED_TCODE(p->header[3]);
  736. rcu_read_lock();
  737. handler = lookup_enclosing_address_handler(&address_handler_list,
  738. offset, request->length);
  739. if (handler)
  740. handler->address_callback(card, request,
  741. tcode, destination, source,
  742. p->generation, offset,
  743. request->data, request->length,
  744. handler->callback_data);
  745. rcu_read_unlock();
  746. if (!handler)
  747. fw_send_response(card, request, RCODE_ADDRESS_ERROR);
  748. }
  749. static void handle_fcp_region_request(struct fw_card *card,
  750. struct fw_packet *p,
  751. struct fw_request *request,
  752. unsigned long long offset)
  753. {
  754. struct fw_address_handler *handler;
  755. int tcode, destination, source;
  756. if ((offset != (CSR_REGISTER_BASE | CSR_FCP_COMMAND) &&
  757. offset != (CSR_REGISTER_BASE | CSR_FCP_RESPONSE)) ||
  758. request->length > 0x200) {
  759. fw_send_response(card, request, RCODE_ADDRESS_ERROR);
  760. return;
  761. }
  762. tcode = HEADER_GET_TCODE(p->header[0]);
  763. destination = HEADER_GET_DESTINATION(p->header[0]);
  764. source = HEADER_GET_SOURCE(p->header[1]);
  765. if (tcode != TCODE_WRITE_QUADLET_REQUEST &&
  766. tcode != TCODE_WRITE_BLOCK_REQUEST) {
  767. fw_send_response(card, request, RCODE_TYPE_ERROR);
  768. return;
  769. }
  770. rcu_read_lock();
  771. list_for_each_entry_rcu(handler, &address_handler_list, link) {
  772. if (is_enclosing_handler(handler, offset, request->length))
  773. handler->address_callback(card, NULL, tcode,
  774. destination, source,
  775. p->generation, offset,
  776. request->data,
  777. request->length,
  778. handler->callback_data);
  779. }
  780. rcu_read_unlock();
  781. fw_send_response(card, request, RCODE_COMPLETE);
  782. }
  783. void fw_core_handle_request(struct fw_card *card, struct fw_packet *p)
  784. {
  785. struct fw_request *request;
  786. unsigned long long offset;
  787. if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE)
  788. return;
  789. if (TCODE_IS_LINK_INTERNAL(HEADER_GET_TCODE(p->header[0]))) {
  790. fw_cdev_handle_phy_packet(card, p);
  791. return;
  792. }
  793. request = allocate_request(card, p);
  794. if (request == NULL) {
  795. /* FIXME: send statically allocated busy packet. */
  796. return;
  797. }
  798. offset = ((u64)HEADER_GET_OFFSET_HIGH(p->header[1]) << 32) |
  799. p->header[2];
  800. if (!is_in_fcp_region(offset, request->length))
  801. handle_exclusive_region_request(card, p, request, offset);
  802. else
  803. handle_fcp_region_request(card, p, request, offset);
  804. }
  805. EXPORT_SYMBOL(fw_core_handle_request);
  806. void fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
  807. {
  808. struct fw_transaction *t;
  809. unsigned long flags;
  810. u32 *data;
  811. size_t data_length;
  812. int tcode, tlabel, source, rcode;
  813. tcode = HEADER_GET_TCODE(p->header[0]);
  814. tlabel = HEADER_GET_TLABEL(p->header[0]);
  815. source = HEADER_GET_SOURCE(p->header[1]);
  816. rcode = HEADER_GET_RCODE(p->header[1]);
  817. spin_lock_irqsave(&card->lock, flags);
  818. list_for_each_entry(t, &card->transaction_list, link) {
  819. if (t->node_id == source && t->tlabel == tlabel) {
  820. if (!try_cancel_split_timeout(t)) {
  821. spin_unlock_irqrestore(&card->lock, flags);
  822. goto timed_out;
  823. }
  824. list_del_init(&t->link);
  825. card->tlabel_mask &= ~(1ULL << t->tlabel);
  826. break;
  827. }
  828. }
  829. spin_unlock_irqrestore(&card->lock, flags);
  830. if (&t->link == &card->transaction_list) {
  831. timed_out:
  832. fw_notice(card, "unsolicited response (source %x, tlabel %x)\n",
  833. source, tlabel);
  834. return;
  835. }
  836. /*
  837. * FIXME: sanity check packet, is length correct, does tcodes
  838. * and addresses match.
  839. */
  840. switch (tcode) {
  841. case TCODE_READ_QUADLET_RESPONSE:
  842. data = (u32 *) &p->header[3];
  843. data_length = 4;
  844. break;
  845. case TCODE_WRITE_RESPONSE:
  846. data = NULL;
  847. data_length = 0;
  848. break;
  849. case TCODE_READ_BLOCK_RESPONSE:
  850. case TCODE_LOCK_RESPONSE:
  851. data = p->payload;
  852. data_length = HEADER_GET_DATA_LENGTH(p->header[3]);
  853. break;
  854. default:
  855. /* Should never happen, this is just to shut up gcc. */
  856. data = NULL;
  857. data_length = 0;
  858. break;
  859. }
  860. /*
  861. * The response handler may be executed while the request handler
  862. * is still pending. Cancel the request handler.
  863. */
  864. card->driver->cancel_packet(card, &t->packet);
  865. t->callback(card, rcode, data, data_length, t->callback_data);
  866. }
  867. EXPORT_SYMBOL(fw_core_handle_response);
  868. /**
  869. * fw_rcode_string - convert a firewire result code to an error description
  870. * @rcode: the result code
  871. */
  872. const char *fw_rcode_string(int rcode)
  873. {
  874. static const char *const names[] = {
  875. [RCODE_COMPLETE] = "no error",
  876. [RCODE_CONFLICT_ERROR] = "conflict error",
  877. [RCODE_DATA_ERROR] = "data error",
  878. [RCODE_TYPE_ERROR] = "type error",
  879. [RCODE_ADDRESS_ERROR] = "address error",
  880. [RCODE_SEND_ERROR] = "send error",
  881. [RCODE_CANCELLED] = "timeout",
  882. [RCODE_BUSY] = "busy",
  883. [RCODE_GENERATION] = "bus reset",
  884. [RCODE_NO_ACK] = "no ack",
  885. };
  886. if ((unsigned int)rcode < ARRAY_SIZE(names) && names[rcode])
  887. return names[rcode];
  888. else
  889. return "unknown";
  890. }
  891. EXPORT_SYMBOL(fw_rcode_string);
  892. static const struct fw_address_region topology_map_region =
  893. { .start = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP,
  894. .end = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP_END, };
  895. static void handle_topology_map(struct fw_card *card, struct fw_request *request,
  896. int tcode, int destination, int source, int generation,
  897. unsigned long long offset, void *payload, size_t length,
  898. void *callback_data)
  899. {
  900. int start;
  901. if (!TCODE_IS_READ_REQUEST(tcode)) {
  902. fw_send_response(card, request, RCODE_TYPE_ERROR);
  903. return;
  904. }
  905. if ((offset & 3) > 0 || (length & 3) > 0) {
  906. fw_send_response(card, request, RCODE_ADDRESS_ERROR);
  907. return;
  908. }
  909. start = (offset - topology_map_region.start) / 4;
  910. memcpy(payload, &card->topology_map[start], length);
  911. fw_send_response(card, request, RCODE_COMPLETE);
  912. }
  913. static struct fw_address_handler topology_map = {
  914. .length = 0x400,
  915. .address_callback = handle_topology_map,
  916. };
  917. static const struct fw_address_region registers_region =
  918. { .start = CSR_REGISTER_BASE,
  919. .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, };
  920. static void update_split_timeout(struct fw_card *card)
  921. {
  922. unsigned int cycles;
  923. cycles = card->split_timeout_hi * 8000 + (card->split_timeout_lo >> 19);
  924. /* minimum per IEEE 1394, maximum which doesn't overflow OHCI */
  925. cycles = clamp(cycles, 800u, 3u * 8000u);
  926. card->split_timeout_cycles = cycles;
  927. card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000);
  928. }
  929. static void handle_registers(struct fw_card *card, struct fw_request *request,
  930. int tcode, int destination, int source, int generation,
  931. unsigned long long offset, void *payload, size_t length,
  932. void *callback_data)
  933. {
  934. int reg = offset & ~CSR_REGISTER_BASE;
  935. __be32 *data = payload;
  936. int rcode = RCODE_COMPLETE;
  937. unsigned long flags;
  938. switch (reg) {
  939. case CSR_PRIORITY_BUDGET:
  940. if (!card->priority_budget_implemented) {
  941. rcode = RCODE_ADDRESS_ERROR;
  942. break;
  943. }
  944. /* else fall through */
  945. case CSR_NODE_IDS:
  946. /*
  947. * per IEEE 1394-2008 8.3.22.3, not IEEE 1394.1-2004 3.2.8
  948. * and 9.6, but interoperable with IEEE 1394.1-2004 bridges
  949. */
  950. /* fall through */
  951. case CSR_STATE_CLEAR:
  952. case CSR_STATE_SET:
  953. case CSR_CYCLE_TIME:
  954. case CSR_BUS_TIME:
  955. case CSR_BUSY_TIMEOUT:
  956. if (tcode == TCODE_READ_QUADLET_REQUEST)
  957. *data = cpu_to_be32(card->driver->read_csr(card, reg));
  958. else if (tcode == TCODE_WRITE_QUADLET_REQUEST)
  959. card->driver->write_csr(card, reg, be32_to_cpu(*data));
  960. else
  961. rcode = RCODE_TYPE_ERROR;
  962. break;
  963. case CSR_RESET_START:
  964. if (tcode == TCODE_WRITE_QUADLET_REQUEST)
  965. card->driver->write_csr(card, CSR_STATE_CLEAR,
  966. CSR_STATE_BIT_ABDICATE);
  967. else
  968. rcode = RCODE_TYPE_ERROR;
  969. break;
  970. case CSR_SPLIT_TIMEOUT_HI:
  971. if (tcode == TCODE_READ_QUADLET_REQUEST) {
  972. *data = cpu_to_be32(card->split_timeout_hi);
  973. } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) {
  974. spin_lock_irqsave(&card->lock, flags);
  975. card->split_timeout_hi = be32_to_cpu(*data) & 7;
  976. update_split_timeout(card);
  977. spin_unlock_irqrestore(&card->lock, flags);
  978. } else {
  979. rcode = RCODE_TYPE_ERROR;
  980. }
  981. break;
  982. case CSR_SPLIT_TIMEOUT_LO:
  983. if (tcode == TCODE_READ_QUADLET_REQUEST) {
  984. *data = cpu_to_be32(card->split_timeout_lo);
  985. } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) {
  986. spin_lock_irqsave(&card->lock, flags);
  987. card->split_timeout_lo =
  988. be32_to_cpu(*data) & 0xfff80000;
  989. update_split_timeout(card);
  990. spin_unlock_irqrestore(&card->lock, flags);
  991. } else {
  992. rcode = RCODE_TYPE_ERROR;
  993. }
  994. break;
  995. case CSR_MAINT_UTILITY:
  996. if (tcode == TCODE_READ_QUADLET_REQUEST)
  997. *data = card->maint_utility_register;
  998. else if (tcode == TCODE_WRITE_QUADLET_REQUEST)
  999. card->maint_utility_register = *data;
  1000. else
  1001. rcode = RCODE_TYPE_ERROR;
  1002. break;
  1003. case CSR_BROADCAST_CHANNEL:
  1004. if (tcode == TCODE_READ_QUADLET_REQUEST)
  1005. *data = cpu_to_be32(card->broadcast_channel);
  1006. else if (tcode == TCODE_WRITE_QUADLET_REQUEST)
  1007. card->broadcast_channel =
  1008. (be32_to_cpu(*data) & BROADCAST_CHANNEL_VALID) |
  1009. BROADCAST_CHANNEL_INITIAL;
  1010. else
  1011. rcode = RCODE_TYPE_ERROR;
  1012. break;
  1013. case CSR_BUS_MANAGER_ID:
  1014. case CSR_BANDWIDTH_AVAILABLE:
  1015. case CSR_CHANNELS_AVAILABLE_HI:
  1016. case CSR_CHANNELS_AVAILABLE_LO:
  1017. /*
  1018. * FIXME: these are handled by the OHCI hardware and
  1019. * the stack never sees these request. If we add
  1020. * support for a new type of controller that doesn't
  1021. * handle this in hardware we need to deal with these
  1022. * transactions.
  1023. */
  1024. BUG();
  1025. break;
  1026. default:
  1027. rcode = RCODE_ADDRESS_ERROR;
  1028. break;
  1029. }
  1030. fw_send_response(card, request, rcode);
  1031. }
  1032. static struct fw_address_handler registers = {
  1033. .length = 0x400,
  1034. .address_callback = handle_registers,
  1035. };
  1036. static void handle_low_memory(struct fw_card *card, struct fw_request *request,
  1037. int tcode, int destination, int source, int generation,
  1038. unsigned long long offset, void *payload, size_t length,
  1039. void *callback_data)
  1040. {
  1041. /*
  1042. * This catches requests not handled by the physical DMA unit,
  1043. * i.e., wrong transaction types or unauthorized source nodes.
  1044. */
  1045. fw_send_response(card, request, RCODE_TYPE_ERROR);
  1046. }
  1047. static struct fw_address_handler low_memory = {
  1048. .length = FW_MAX_PHYSICAL_RANGE,
  1049. .address_callback = handle_low_memory,
  1050. };
  1051. MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>");
  1052. MODULE_DESCRIPTION("Core IEEE1394 transaction logic");
  1053. MODULE_LICENSE("GPL");
  1054. static const u32 vendor_textual_descriptor[] = {
  1055. /* textual descriptor leaf () */
  1056. 0x00060000,
  1057. 0x00000000,
  1058. 0x00000000,
  1059. 0x4c696e75, /* L i n u */
  1060. 0x78204669, /* x F i */
  1061. 0x72657769, /* r e w i */
  1062. 0x72650000, /* r e */
  1063. };
  1064. static const u32 model_textual_descriptor[] = {
  1065. /* model descriptor leaf () */
  1066. 0x00030000,
  1067. 0x00000000,
  1068. 0x00000000,
  1069. 0x4a756a75, /* J u j u */
  1070. };
  1071. static struct fw_descriptor vendor_id_descriptor = {
  1072. .length = ARRAY_SIZE(vendor_textual_descriptor),
  1073. .immediate = 0x03001f11,
  1074. .key = 0x81000000,
  1075. .data = vendor_textual_descriptor,
  1076. };
  1077. static struct fw_descriptor model_id_descriptor = {
  1078. .length = ARRAY_SIZE(model_textual_descriptor),
  1079. .immediate = 0x17023901,
  1080. .key = 0x81000000,
  1081. .data = model_textual_descriptor,
  1082. };
  1083. static int __init fw_core_init(void)
  1084. {
  1085. int ret;
  1086. fw_workqueue = alloc_workqueue("firewire", WQ_MEM_RECLAIM, 0);
  1087. if (!fw_workqueue)
  1088. return -ENOMEM;
  1089. ret = bus_register(&fw_bus_type);
  1090. if (ret < 0) {
  1091. destroy_workqueue(fw_workqueue);
  1092. return ret;
  1093. }
  1094. fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops);
  1095. if (fw_cdev_major < 0) {
  1096. bus_unregister(&fw_bus_type);
  1097. destroy_workqueue(fw_workqueue);
  1098. return fw_cdev_major;
  1099. }
  1100. fw_core_add_address_handler(&topology_map, &topology_map_region);
  1101. fw_core_add_address_handler(&registers, &registers_region);
  1102. fw_core_add_address_handler(&low_memory, &low_memory_region);
  1103. fw_core_add_descriptor(&vendor_id_descriptor);
  1104. fw_core_add_descriptor(&model_id_descriptor);
  1105. return 0;
  1106. }
  1107. static void __exit fw_core_cleanup(void)
  1108. {
  1109. unregister_chrdev(fw_cdev_major, "firewire");
  1110. bus_unregister(&fw_bus_type);
  1111. destroy_workqueue(fw_workqueue);
  1112. idr_destroy(&fw_device_idr);
  1113. }
  1114. module_init(fw_core_init);
  1115. module_exit(fw_core_cleanup);