sbp2.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150
  1. /*
  2. * sbp2.c - SBP-2 protocol driver for IEEE-1394
  3. *
  4. * Copyright (C) 2000 James Goodwin, Filanet Corporation (www.filanet.com)
  5. * jamesg@filanet.com (JSG)
  6. *
  7. * Copyright (C) 2003 Ben Collins <bcollins@debian.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. /*
  24. * Brief Description:
  25. *
  26. * This driver implements the Serial Bus Protocol 2 (SBP-2) over IEEE-1394
  27. * under Linux. The SBP-2 driver is implemented as an IEEE-1394 high-level
  28. * driver. It also registers as a SCSI lower-level driver in order to accept
  29. * SCSI commands for transport using SBP-2.
  30. *
  31. * You may access any attached SBP-2 (usually storage devices) as regular
  32. * SCSI devices. E.g. mount /dev/sda1, fdisk, mkfs, etc..
  33. *
  34. * See http://www.t10.org/drafts.htm#sbp2 for the final draft of the SBP-2
  35. * specification and for where to purchase the official standard.
  36. *
  37. * TODO:
  38. * - look into possible improvements of the SCSI error handlers
  39. * - handle Unit_Characteristics.mgt_ORB_timeout and .ORB_size
  40. * - handle Logical_Unit_Number.ordered
  41. * - handle src == 1 in status blocks
  42. * - reimplement the DMA mapping in absence of physical DMA so that
  43. * bus_to_virt is no longer required
  44. * - debug the handling of absent physical DMA
  45. * - replace CONFIG_IEEE1394_SBP2_PHYS_DMA by automatic detection
  46. * (this is easy but depends on the previous two TODO items)
  47. * - make the parameter serialize_io configurable per device
  48. * - move all requests to fetch agent registers into non-atomic context,
  49. * replace all usages of sbp2util_node_write_no_wait by true transactions
  50. * Grep for inline FIXME comments below.
  51. */
  52. #include <linux/blkdev.h>
  53. #include <linux/compiler.h>
  54. #include <linux/delay.h>
  55. #include <linux/device.h>
  56. #include <linux/dma-mapping.h>
  57. #include <linux/gfp.h>
  58. #include <linux/init.h>
  59. #include <linux/kernel.h>
  60. #include <linux/list.h>
  61. #include <linux/mm.h>
  62. #include <linux/module.h>
  63. #include <linux/moduleparam.h>
  64. #include <linux/sched.h>
  65. #include <linux/slab.h>
  66. #include <linux/spinlock.h>
  67. #include <linux/stat.h>
  68. #include <linux/string.h>
  69. #include <linux/stringify.h>
  70. #include <linux/types.h>
  71. #include <linux/wait.h>
  72. #include <linux/workqueue.h>
  73. #include <linux/scatterlist.h>
  74. #include <asm/byteorder.h>
  75. #include <asm/errno.h>
  76. #include <asm/param.h>
  77. #include <asm/system.h>
  78. #include <asm/types.h>
  79. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  80. #include <asm/io.h> /* for bus_to_virt */
  81. #endif
  82. #include <scsi/scsi.h>
  83. #include <scsi/scsi_cmnd.h>
  84. #include <scsi/scsi_dbg.h>
  85. #include <scsi/scsi_device.h>
  86. #include <scsi/scsi_host.h>
  87. #include "csr1212.h"
  88. #include "highlevel.h"
  89. #include "hosts.h"
  90. #include "ieee1394.h"
  91. #include "ieee1394_core.h"
  92. #include "ieee1394_hotplug.h"
  93. #include "ieee1394_transactions.h"
  94. #include "ieee1394_types.h"
  95. #include "nodemgr.h"
  96. #include "sbp2.h"
  97. /*
  98. * Module load parameter definitions
  99. */
  100. /*
  101. * Change max_speed on module load if you have a bad IEEE-1394
  102. * controller that has trouble running 2KB packets at 400mb.
  103. *
  104. * NOTE: On certain OHCI parts I have seen short packets on async transmit
  105. * (probably due to PCI latency/throughput issues with the part). You can
  106. * bump down the speed if you are running into problems.
  107. */
  108. static int sbp2_max_speed = IEEE1394_SPEED_MAX;
  109. module_param_named(max_speed, sbp2_max_speed, int, 0644);
  110. MODULE_PARM_DESC(max_speed, "Force max speed "
  111. "(3 = 800Mb/s, 2 = 400Mb/s, 1 = 200Mb/s, 0 = 100Mb/s)");
  112. /*
  113. * Set serialize_io to 0 or N to use dynamically appended lists of command ORBs.
  114. * This is and always has been buggy in multiple subtle ways. See above TODOs.
  115. */
  116. static int sbp2_serialize_io = 1;
  117. module_param_named(serialize_io, sbp2_serialize_io, bool, 0444);
  118. MODULE_PARM_DESC(serialize_io, "Serialize requests coming from SCSI drivers "
  119. "(default = Y, faster but buggy = N)");
  120. /*
  121. * Adjust max_sectors if you'd like to influence how many sectors each SCSI
  122. * command can transfer at most. Please note that some older SBP-2 bridge
  123. * chips are broken for transfers greater or equal to 128KB, therefore
  124. * max_sectors used to be a safe 255 sectors for many years. We now have a
  125. * default of 0 here which means that we let the SCSI stack choose a limit.
  126. *
  127. * The SBP2_WORKAROUND_128K_MAX_TRANS flag, if set either in the workarounds
  128. * module parameter or in the sbp2_workarounds_table[], will override the
  129. * value of max_sectors. We should use sbp2_workarounds_table[] to cover any
  130. * bridge chip which becomes known to need the 255 sectors limit.
  131. */
  132. static int sbp2_max_sectors;
  133. module_param_named(max_sectors, sbp2_max_sectors, int, 0444);
  134. MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported "
  135. "(default = 0 = use SCSI stack's default)");
  136. /*
  137. * Exclusive login to sbp2 device? In most cases, the sbp2 driver should
  138. * do an exclusive login, as it's generally unsafe to have two hosts
  139. * talking to a single sbp2 device at the same time (filesystem coherency,
  140. * etc.). If you're running an sbp2 device that supports multiple logins,
  141. * and you're either running read-only filesystems or some sort of special
  142. * filesystem supporting multiple hosts, e.g. OpenGFS, Oracle Cluster
  143. * File System, or Lustre, then set exclusive_login to zero.
  144. *
  145. * So far only bridges from Oxford Semiconductor are known to support
  146. * concurrent logins. Depending on firmware, four or two concurrent logins
  147. * are possible on OXFW911 and newer Oxsemi bridges.
  148. */
  149. static int sbp2_exclusive_login = 1;
  150. module_param_named(exclusive_login, sbp2_exclusive_login, bool, 0644);
  151. MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device "
  152. "(default = Y, use N for concurrent initiators)");
  153. /*
  154. * If any of the following workarounds is required for your device to work,
  155. * please submit the kernel messages logged by sbp2 to the linux1394-devel
  156. * mailing list.
  157. *
  158. * - 128kB max transfer
  159. * Limit transfer size. Necessary for some old bridges.
  160. *
  161. * - 36 byte inquiry
  162. * When scsi_mod probes the device, let the inquiry command look like that
  163. * from MS Windows.
  164. *
  165. * - skip mode page 8
  166. * Suppress sending of mode_sense for mode page 8 if the device pretends to
  167. * support the SCSI Primary Block commands instead of Reduced Block Commands.
  168. *
  169. * - fix capacity
  170. * Tell sd_mod to correct the last sector number reported by read_capacity.
  171. * Avoids access beyond actual disk limits on devices with an off-by-one bug.
  172. * Don't use this with devices which don't have this bug.
  173. *
  174. * - delay inquiry
  175. * Wait extra SBP2_INQUIRY_DELAY seconds after login before SCSI inquiry.
  176. *
  177. * - power condition
  178. * Set the power condition field in the START STOP UNIT commands sent by
  179. * sd_mod on suspend, resume, and shutdown (if manage_start_stop is on).
  180. * Some disks need this to spin down or to resume properly.
  181. *
  182. * - override internal blacklist
  183. * Instead of adding to the built-in blacklist, use only the workarounds
  184. * specified in the module load parameter.
  185. * Useful if a blacklist entry interfered with a non-broken device.
  186. */
  187. static int sbp2_default_workarounds;
  188. module_param_named(workarounds, sbp2_default_workarounds, int, 0644);
  189. MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0"
  190. ", 128kB max transfer = " __stringify(SBP2_WORKAROUND_128K_MAX_TRANS)
  191. ", 36 byte inquiry = " __stringify(SBP2_WORKAROUND_INQUIRY_36)
  192. ", skip mode page 8 = " __stringify(SBP2_WORKAROUND_MODE_SENSE_8)
  193. ", fix capacity = " __stringify(SBP2_WORKAROUND_FIX_CAPACITY)
  194. ", delay inquiry = " __stringify(SBP2_WORKAROUND_DELAY_INQUIRY)
  195. ", set power condition in start stop unit = "
  196. __stringify(SBP2_WORKAROUND_POWER_CONDITION)
  197. ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE)
  198. ", or a combination)");
  199. /*
  200. * This influences the format of the sysfs attribute
  201. * /sys/bus/scsi/devices/.../ieee1394_id.
  202. *
  203. * The default format is like in older kernels: %016Lx:%d:%d
  204. * It contains the target's EUI-64, a number given to the logical unit by
  205. * the ieee1394 driver's nodemgr (starting at 0), and the LUN.
  206. *
  207. * The long format is: %016Lx:%06x:%04x
  208. * It contains the target's EUI-64, the unit directory's directory_ID as per
  209. * IEEE 1212 clause 7.7.19, and the LUN. This format comes closest to the
  210. * format of SBP(-3) target port and logical unit identifier as per SAM (SCSI
  211. * Architecture Model) rev.2 to 4 annex A. Therefore and because it is
  212. * independent of the implementation of the ieee1394 nodemgr, the longer format
  213. * is recommended for future use.
  214. */
  215. static int sbp2_long_sysfs_ieee1394_id;
  216. module_param_named(long_ieee1394_id, sbp2_long_sysfs_ieee1394_id, bool, 0644);
  217. MODULE_PARM_DESC(long_ieee1394_id, "8+3+2 bytes format of ieee1394_id in sysfs "
  218. "(default = backwards-compatible = N, SAM-conforming = Y)");
  219. #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args)
  220. #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
  221. /*
  222. * Globals
  223. */
  224. static void sbp2scsi_complete_all_commands(struct sbp2_lu *, u32);
  225. static void sbp2scsi_complete_command(struct sbp2_lu *, u32, struct scsi_cmnd *,
  226. void (*)(struct scsi_cmnd *));
  227. static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *);
  228. static int sbp2_start_device(struct sbp2_lu *);
  229. static void sbp2_remove_device(struct sbp2_lu *);
  230. static int sbp2_login_device(struct sbp2_lu *);
  231. static int sbp2_reconnect_device(struct sbp2_lu *);
  232. static int sbp2_logout_device(struct sbp2_lu *);
  233. static void sbp2_host_reset(struct hpsb_host *);
  234. static int sbp2_handle_status_write(struct hpsb_host *, int, int, quadlet_t *,
  235. u64, size_t, u16);
  236. static int sbp2_agent_reset(struct sbp2_lu *, int);
  237. static void sbp2_parse_unit_directory(struct sbp2_lu *,
  238. struct unit_directory *);
  239. static int sbp2_set_busy_timeout(struct sbp2_lu *);
  240. static int sbp2_max_speed_and_size(struct sbp2_lu *);
  241. static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC };
  242. static DEFINE_RWLOCK(sbp2_hi_logical_units_lock);
  243. static struct hpsb_highlevel sbp2_highlevel = {
  244. .name = SBP2_DEVICE_NAME,
  245. .host_reset = sbp2_host_reset,
  246. };
  247. static struct hpsb_address_ops sbp2_ops = {
  248. .write = sbp2_handle_status_write
  249. };
  250. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  251. static int sbp2_handle_physdma_write(struct hpsb_host *, int, int, quadlet_t *,
  252. u64, size_t, u16);
  253. static int sbp2_handle_physdma_read(struct hpsb_host *, int, quadlet_t *, u64,
  254. size_t, u16);
  255. static struct hpsb_address_ops sbp2_physdma_ops = {
  256. .read = sbp2_handle_physdma_read,
  257. .write = sbp2_handle_physdma_write,
  258. };
  259. #endif
  260. /*
  261. * Interface to driver core and IEEE 1394 core
  262. */
  263. static struct ieee1394_device_id sbp2_id_table[] = {
  264. {
  265. .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
  266. .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
  267. .version = SBP2_SW_VERSION_ENTRY & 0xffffff},
  268. {}
  269. };
  270. MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
  271. static int sbp2_probe(struct device *);
  272. static int sbp2_remove(struct device *);
  273. static int sbp2_update(struct unit_directory *);
  274. static struct hpsb_protocol_driver sbp2_driver = {
  275. .name = SBP2_DEVICE_NAME,
  276. .id_table = sbp2_id_table,
  277. .update = sbp2_update,
  278. .driver = {
  279. .probe = sbp2_probe,
  280. .remove = sbp2_remove,
  281. },
  282. };
  283. /*
  284. * Interface to SCSI core
  285. */
  286. static int sbp2scsi_queuecommand(struct scsi_cmnd *,
  287. void (*)(struct scsi_cmnd *));
  288. static int sbp2scsi_abort(struct scsi_cmnd *);
  289. static int sbp2scsi_reset(struct scsi_cmnd *);
  290. static int sbp2scsi_slave_alloc(struct scsi_device *);
  291. static int sbp2scsi_slave_configure(struct scsi_device *);
  292. static void sbp2scsi_slave_destroy(struct scsi_device *);
  293. static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *,
  294. struct device_attribute *, char *);
  295. static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL);
  296. static struct device_attribute *sbp2_sysfs_sdev_attrs[] = {
  297. &dev_attr_ieee1394_id,
  298. NULL
  299. };
  300. static struct scsi_host_template sbp2_shost_template = {
  301. .module = THIS_MODULE,
  302. .name = "SBP-2 IEEE-1394",
  303. .proc_name = SBP2_DEVICE_NAME,
  304. .queuecommand = sbp2scsi_queuecommand,
  305. .eh_abort_handler = sbp2scsi_abort,
  306. .eh_device_reset_handler = sbp2scsi_reset,
  307. .slave_alloc = sbp2scsi_slave_alloc,
  308. .slave_configure = sbp2scsi_slave_configure,
  309. .slave_destroy = sbp2scsi_slave_destroy,
  310. .this_id = -1,
  311. .sg_tablesize = SG_ALL,
  312. .use_clustering = ENABLE_CLUSTERING,
  313. .cmd_per_lun = SBP2_MAX_CMDS,
  314. .can_queue = SBP2_MAX_CMDS,
  315. .sdev_attrs = sbp2_sysfs_sdev_attrs,
  316. };
  317. /* for match-all entries in sbp2_workarounds_table */
  318. #define SBP2_ROM_VALUE_WILDCARD 0x1000000
  319. /*
  320. * List of devices with known bugs.
  321. *
  322. * The firmware_revision field, masked with 0xffff00, is the best indicator
  323. * for the type of bridge chip of a device. It yields a few false positives
  324. * but this did not break correctly behaving devices so far.
  325. */
  326. static const struct {
  327. u32 firmware_revision;
  328. u32 model_id;
  329. unsigned workarounds;
  330. } sbp2_workarounds_table[] = {
  331. /* DViCO Momobay CX-1 with TSB42AA9 bridge */ {
  332. .firmware_revision = 0x002800,
  333. .model_id = 0x001010,
  334. .workarounds = SBP2_WORKAROUND_INQUIRY_36 |
  335. SBP2_WORKAROUND_MODE_SENSE_8 |
  336. SBP2_WORKAROUND_POWER_CONDITION,
  337. },
  338. /* DViCO Momobay FX-3A with TSB42AA9A bridge */ {
  339. .firmware_revision = 0x002800,
  340. .model_id = 0x000000,
  341. .workarounds = SBP2_WORKAROUND_DELAY_INQUIRY |
  342. SBP2_WORKAROUND_POWER_CONDITION,
  343. },
  344. /* Initio bridges, actually only needed for some older ones */ {
  345. .firmware_revision = 0x000200,
  346. .model_id = SBP2_ROM_VALUE_WILDCARD,
  347. .workarounds = SBP2_WORKAROUND_INQUIRY_36,
  348. },
  349. /* PL-3507 bridge with Prolific firmware */ {
  350. .firmware_revision = 0x012800,
  351. .model_id = SBP2_ROM_VALUE_WILDCARD,
  352. .workarounds = SBP2_WORKAROUND_POWER_CONDITION,
  353. },
  354. /* Symbios bridge */ {
  355. .firmware_revision = 0xa0b800,
  356. .model_id = SBP2_ROM_VALUE_WILDCARD,
  357. .workarounds = SBP2_WORKAROUND_128K_MAX_TRANS,
  358. },
  359. /* Datafab MD2-FW2 with Symbios/LSILogic SYM13FW500 bridge */ {
  360. .firmware_revision = 0x002600,
  361. .model_id = SBP2_ROM_VALUE_WILDCARD,
  362. .workarounds = SBP2_WORKAROUND_128K_MAX_TRANS,
  363. },
  364. /* iPod 4th generation */ {
  365. .firmware_revision = 0x0a2700,
  366. .model_id = 0x000021,
  367. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  368. },
  369. /* iPod mini */ {
  370. .firmware_revision = 0x0a2700,
  371. .model_id = 0x000023,
  372. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  373. },
  374. /* iPod Photo */ {
  375. .firmware_revision = 0x0a2700,
  376. .model_id = 0x00007e,
  377. .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
  378. }
  379. };
  380. /**************************************
  381. * General utility functions
  382. **************************************/
  383. #ifndef __BIG_ENDIAN
  384. /*
  385. * Converts a buffer from be32 to cpu byte ordering. Length is in bytes.
  386. */
  387. static inline void sbp2util_be32_to_cpu_buffer(void *buffer, int length)
  388. {
  389. u32 *temp = buffer;
  390. for (length = (length >> 2); length--; )
  391. temp[length] = be32_to_cpu(temp[length]);
  392. }
  393. /*
  394. * Converts a buffer from cpu to be32 byte ordering. Length is in bytes.
  395. */
  396. static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length)
  397. {
  398. u32 *temp = buffer;
  399. for (length = (length >> 2); length--; )
  400. temp[length] = cpu_to_be32(temp[length]);
  401. }
  402. #else /* BIG_ENDIAN */
  403. /* Why waste the cpu cycles? */
  404. #define sbp2util_be32_to_cpu_buffer(x,y) do {} while (0)
  405. #define sbp2util_cpu_to_be32_buffer(x,y) do {} while (0)
  406. #endif
  407. static DECLARE_WAIT_QUEUE_HEAD(sbp2_access_wq);
  408. /*
  409. * Waits for completion of an SBP-2 access request.
  410. * Returns nonzero if timed out or prematurely interrupted.
  411. */
  412. static int sbp2util_access_timeout(struct sbp2_lu *lu, int timeout)
  413. {
  414. long leftover;
  415. leftover = wait_event_interruptible_timeout(
  416. sbp2_access_wq, lu->access_complete, timeout);
  417. lu->access_complete = 0;
  418. return leftover <= 0;
  419. }
  420. static void sbp2_free_packet(void *packet)
  421. {
  422. hpsb_free_tlabel(packet);
  423. hpsb_free_packet(packet);
  424. }
  425. /*
  426. * This is much like hpsb_node_write(), except it ignores the response
  427. * subaction and returns immediately. Can be used from atomic context.
  428. */
  429. static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr,
  430. quadlet_t *buf, size_t len)
  431. {
  432. struct hpsb_packet *packet;
  433. packet = hpsb_make_writepacket(ne->host, ne->nodeid, addr, buf, len);
  434. if (!packet)
  435. return -ENOMEM;
  436. hpsb_set_packet_complete_task(packet, sbp2_free_packet, packet);
  437. hpsb_node_fill_packet(ne, packet);
  438. if (hpsb_send_packet(packet) < 0) {
  439. sbp2_free_packet(packet);
  440. return -EIO;
  441. }
  442. return 0;
  443. }
  444. static void sbp2util_notify_fetch_agent(struct sbp2_lu *lu, u64 offset,
  445. quadlet_t *data, size_t len)
  446. {
  447. /* There is a small window after a bus reset within which the node
  448. * entry's generation is current but the reconnect wasn't completed. */
  449. if (unlikely(atomic_read(&lu->state) == SBP2LU_STATE_IN_RESET))
  450. return;
  451. if (hpsb_node_write(lu->ne, lu->command_block_agent_addr + offset,
  452. data, len))
  453. SBP2_ERR("sbp2util_notify_fetch_agent failed.");
  454. /* Now accept new SCSI commands, unless a bus reset happended during
  455. * hpsb_node_write. */
  456. if (likely(atomic_read(&lu->state) != SBP2LU_STATE_IN_RESET))
  457. scsi_unblock_requests(lu->shost);
  458. }
  459. static void sbp2util_write_orb_pointer(struct work_struct *work)
  460. {
  461. struct sbp2_lu *lu = container_of(work, struct sbp2_lu, protocol_work);
  462. quadlet_t data[2];
  463. data[0] = ORB_SET_NODE_ID(lu->hi->host->node_id);
  464. data[1] = lu->last_orb_dma;
  465. sbp2util_cpu_to_be32_buffer(data, 8);
  466. sbp2util_notify_fetch_agent(lu, SBP2_ORB_POINTER_OFFSET, data, 8);
  467. }
  468. static void sbp2util_write_doorbell(struct work_struct *work)
  469. {
  470. struct sbp2_lu *lu = container_of(work, struct sbp2_lu, protocol_work);
  471. sbp2util_notify_fetch_agent(lu, SBP2_DOORBELL_OFFSET, NULL, 4);
  472. }
  473. static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu)
  474. {
  475. struct sbp2_fwhost_info *hi = lu->hi;
  476. struct sbp2_command_info *cmd;
  477. int i, orbs = sbp2_serialize_io ? 2 : SBP2_MAX_CMDS;
  478. for (i = 0; i < orbs; i++) {
  479. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  480. if (!cmd)
  481. return -ENOMEM;
  482. cmd->command_orb_dma = dma_map_single(hi->host->device.parent,
  483. &cmd->command_orb,
  484. sizeof(struct sbp2_command_orb),
  485. DMA_TO_DEVICE);
  486. cmd->sge_dma = dma_map_single(hi->host->device.parent,
  487. &cmd->scatter_gather_element,
  488. sizeof(cmd->scatter_gather_element),
  489. DMA_TO_DEVICE);
  490. INIT_LIST_HEAD(&cmd->list);
  491. list_add_tail(&cmd->list, &lu->cmd_orb_completed);
  492. }
  493. return 0;
  494. }
  495. static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu,
  496. struct hpsb_host *host)
  497. {
  498. struct list_head *lh, *next;
  499. struct sbp2_command_info *cmd;
  500. unsigned long flags;
  501. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  502. if (!list_empty(&lu->cmd_orb_completed))
  503. list_for_each_safe(lh, next, &lu->cmd_orb_completed) {
  504. cmd = list_entry(lh, struct sbp2_command_info, list);
  505. dma_unmap_single(host->device.parent,
  506. cmd->command_orb_dma,
  507. sizeof(struct sbp2_command_orb),
  508. DMA_TO_DEVICE);
  509. dma_unmap_single(host->device.parent, cmd->sge_dma,
  510. sizeof(cmd->scatter_gather_element),
  511. DMA_TO_DEVICE);
  512. kfree(cmd);
  513. }
  514. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  515. return;
  516. }
  517. /*
  518. * Finds the sbp2_command for a given outstanding command ORB.
  519. * Only looks at the in-use list.
  520. */
  521. static struct sbp2_command_info *sbp2util_find_command_for_orb(
  522. struct sbp2_lu *lu, dma_addr_t orb)
  523. {
  524. struct sbp2_command_info *cmd;
  525. unsigned long flags;
  526. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  527. if (!list_empty(&lu->cmd_orb_inuse))
  528. list_for_each_entry(cmd, &lu->cmd_orb_inuse, list)
  529. if (cmd->command_orb_dma == orb) {
  530. spin_unlock_irqrestore(
  531. &lu->cmd_orb_lock, flags);
  532. return cmd;
  533. }
  534. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  535. return NULL;
  536. }
  537. /*
  538. * Finds the sbp2_command for a given outstanding SCpnt.
  539. * Only looks at the in-use list.
  540. * Must be called with lu->cmd_orb_lock held.
  541. */
  542. static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(
  543. struct sbp2_lu *lu, void *SCpnt)
  544. {
  545. struct sbp2_command_info *cmd;
  546. if (!list_empty(&lu->cmd_orb_inuse))
  547. list_for_each_entry(cmd, &lu->cmd_orb_inuse, list)
  548. if (cmd->Current_SCpnt == SCpnt)
  549. return cmd;
  550. return NULL;
  551. }
  552. static struct sbp2_command_info *sbp2util_allocate_command_orb(
  553. struct sbp2_lu *lu,
  554. struct scsi_cmnd *Current_SCpnt,
  555. void (*Current_done)(struct scsi_cmnd *))
  556. {
  557. struct list_head *lh;
  558. struct sbp2_command_info *cmd = NULL;
  559. unsigned long flags;
  560. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  561. if (!list_empty(&lu->cmd_orb_completed)) {
  562. lh = lu->cmd_orb_completed.next;
  563. list_del(lh);
  564. cmd = list_entry(lh, struct sbp2_command_info, list);
  565. cmd->Current_done = Current_done;
  566. cmd->Current_SCpnt = Current_SCpnt;
  567. list_add_tail(&cmd->list, &lu->cmd_orb_inuse);
  568. } else
  569. SBP2_ERR("%s: no orbs available", __func__);
  570. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  571. return cmd;
  572. }
  573. /*
  574. * Unmaps the DMAs of a command and moves the command to the completed ORB list.
  575. * Must be called with lu->cmd_orb_lock held.
  576. */
  577. static void sbp2util_mark_command_completed(struct sbp2_lu *lu,
  578. struct sbp2_command_info *cmd)
  579. {
  580. struct hpsb_host *host = lu->ud->ne->host;
  581. if (cmd->cmd_dma) {
  582. if (cmd->dma_type == CMD_DMA_SINGLE)
  583. dma_unmap_single(host->device.parent, cmd->cmd_dma,
  584. cmd->dma_size, cmd->dma_dir);
  585. else if (cmd->dma_type == CMD_DMA_PAGE)
  586. dma_unmap_page(host->device.parent, cmd->cmd_dma,
  587. cmd->dma_size, cmd->dma_dir);
  588. /* XXX: Check for CMD_DMA_NONE bug */
  589. cmd->dma_type = CMD_DMA_NONE;
  590. cmd->cmd_dma = 0;
  591. }
  592. if (cmd->sge_buffer) {
  593. dma_unmap_sg(host->device.parent, cmd->sge_buffer,
  594. cmd->dma_size, cmd->dma_dir);
  595. cmd->sge_buffer = NULL;
  596. }
  597. list_move_tail(&cmd->list, &lu->cmd_orb_completed);
  598. }
  599. /*
  600. * Is lu valid? Is the 1394 node still present?
  601. */
  602. static inline int sbp2util_node_is_available(struct sbp2_lu *lu)
  603. {
  604. return lu && lu->ne && !lu->ne->in_limbo;
  605. }
  606. /*********************************************
  607. * IEEE-1394 core driver stack related section
  608. *********************************************/
  609. static int sbp2_probe(struct device *dev)
  610. {
  611. struct unit_directory *ud;
  612. struct sbp2_lu *lu;
  613. ud = container_of(dev, struct unit_directory, device);
  614. /* Don't probe UD's that have the LUN flag. We'll probe the LUN(s)
  615. * instead. */
  616. if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY)
  617. return -ENODEV;
  618. lu = sbp2_alloc_device(ud);
  619. if (!lu)
  620. return -ENOMEM;
  621. sbp2_parse_unit_directory(lu, ud);
  622. return sbp2_start_device(lu);
  623. }
  624. static int sbp2_remove(struct device *dev)
  625. {
  626. struct unit_directory *ud;
  627. struct sbp2_lu *lu;
  628. struct scsi_device *sdev;
  629. ud = container_of(dev, struct unit_directory, device);
  630. lu = ud->device.driver_data;
  631. if (!lu)
  632. return 0;
  633. if (lu->shost) {
  634. /* Get rid of enqueued commands if there is no chance to
  635. * send them. */
  636. if (!sbp2util_node_is_available(lu))
  637. sbp2scsi_complete_all_commands(lu, DID_NO_CONNECT);
  638. /* scsi_remove_device() may trigger shutdown functions of SCSI
  639. * highlevel drivers which would deadlock if blocked. */
  640. atomic_set(&lu->state, SBP2LU_STATE_IN_SHUTDOWN);
  641. scsi_unblock_requests(lu->shost);
  642. }
  643. sdev = lu->sdev;
  644. if (sdev) {
  645. lu->sdev = NULL;
  646. scsi_remove_device(sdev);
  647. }
  648. sbp2_logout_device(lu);
  649. sbp2_remove_device(lu);
  650. return 0;
  651. }
  652. static int sbp2_update(struct unit_directory *ud)
  653. {
  654. struct sbp2_lu *lu = ud->device.driver_data;
  655. if (sbp2_reconnect_device(lu)) {
  656. /* Reconnect has failed. Perhaps we didn't reconnect fast
  657. * enough. Try a regular login, but first log out just in
  658. * case of any weirdness. */
  659. sbp2_logout_device(lu);
  660. if (sbp2_login_device(lu)) {
  661. /* Login failed too, just fail, and the backend
  662. * will call our sbp2_remove for us */
  663. SBP2_ERR("Failed to reconnect to sbp2 device!");
  664. return -EBUSY;
  665. }
  666. }
  667. sbp2_set_busy_timeout(lu);
  668. sbp2_agent_reset(lu, 1);
  669. sbp2_max_speed_and_size(lu);
  670. /* Complete any pending commands with busy (so they get retried)
  671. * and remove them from our queue. */
  672. sbp2scsi_complete_all_commands(lu, DID_BUS_BUSY);
  673. /* Accept new commands unless there was another bus reset in the
  674. * meantime. */
  675. if (hpsb_node_entry_valid(lu->ne)) {
  676. atomic_set(&lu->state, SBP2LU_STATE_RUNNING);
  677. scsi_unblock_requests(lu->shost);
  678. }
  679. return 0;
  680. }
  681. static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
  682. {
  683. struct sbp2_fwhost_info *hi;
  684. struct Scsi_Host *shost = NULL;
  685. struct sbp2_lu *lu = NULL;
  686. unsigned long flags;
  687. lu = kzalloc(sizeof(*lu), GFP_KERNEL);
  688. if (!lu) {
  689. SBP2_ERR("failed to create lu");
  690. goto failed_alloc;
  691. }
  692. lu->ne = ud->ne;
  693. lu->ud = ud;
  694. lu->speed_code = IEEE1394_SPEED_100;
  695. lu->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100];
  696. lu->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE;
  697. INIT_LIST_HEAD(&lu->cmd_orb_inuse);
  698. INIT_LIST_HEAD(&lu->cmd_orb_completed);
  699. INIT_LIST_HEAD(&lu->lu_list);
  700. spin_lock_init(&lu->cmd_orb_lock);
  701. atomic_set(&lu->state, SBP2LU_STATE_RUNNING);
  702. INIT_WORK(&lu->protocol_work, NULL);
  703. ud->device.driver_data = lu;
  704. hi = hpsb_get_hostinfo(&sbp2_highlevel, ud->ne->host);
  705. if (!hi) {
  706. hi = hpsb_create_hostinfo(&sbp2_highlevel, ud->ne->host,
  707. sizeof(*hi));
  708. if (!hi) {
  709. SBP2_ERR("failed to allocate hostinfo");
  710. goto failed_alloc;
  711. }
  712. hi->host = ud->ne->host;
  713. INIT_LIST_HEAD(&hi->logical_units);
  714. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  715. /* Handle data movement if physical dma is not
  716. * enabled or not supported on host controller */
  717. if (!hpsb_register_addrspace(&sbp2_highlevel, ud->ne->host,
  718. &sbp2_physdma_ops,
  719. 0x0ULL, 0xfffffffcULL)) {
  720. SBP2_ERR("failed to register lower 4GB address range");
  721. goto failed_alloc;
  722. }
  723. #endif
  724. }
  725. /* Prevent unloading of the 1394 host */
  726. if (!try_module_get(hi->host->driver->owner)) {
  727. SBP2_ERR("failed to get a reference on 1394 host driver");
  728. goto failed_alloc;
  729. }
  730. lu->hi = hi;
  731. write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  732. list_add_tail(&lu->lu_list, &hi->logical_units);
  733. write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  734. /* Register the status FIFO address range. We could use the same FIFO
  735. * for targets at different nodes. However we need different FIFOs per
  736. * target in order to support multi-unit devices.
  737. * The FIFO is located out of the local host controller's physical range
  738. * but, if possible, within the posted write area. Status writes will
  739. * then be performed as unified transactions. This slightly reduces
  740. * bandwidth usage, and some Prolific based devices seem to require it.
  741. */
  742. lu->status_fifo_addr = hpsb_allocate_and_register_addrspace(
  743. &sbp2_highlevel, ud->ne->host, &sbp2_ops,
  744. sizeof(struct sbp2_status_block), sizeof(quadlet_t),
  745. ud->ne->host->low_addr_space, CSR1212_ALL_SPACE_END);
  746. if (lu->status_fifo_addr == CSR1212_INVALID_ADDR_SPACE) {
  747. SBP2_ERR("failed to allocate status FIFO address range");
  748. goto failed_alloc;
  749. }
  750. shost = scsi_host_alloc(&sbp2_shost_template, sizeof(unsigned long));
  751. if (!shost) {
  752. SBP2_ERR("failed to register scsi host");
  753. goto failed_alloc;
  754. }
  755. shost->hostdata[0] = (unsigned long)lu;
  756. if (!scsi_add_host(shost, &ud->device)) {
  757. lu->shost = shost;
  758. return lu;
  759. }
  760. SBP2_ERR("failed to add scsi host");
  761. scsi_host_put(shost);
  762. failed_alloc:
  763. sbp2_remove_device(lu);
  764. return NULL;
  765. }
  766. static void sbp2_host_reset(struct hpsb_host *host)
  767. {
  768. struct sbp2_fwhost_info *hi;
  769. struct sbp2_lu *lu;
  770. unsigned long flags;
  771. hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
  772. if (!hi)
  773. return;
  774. read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  775. list_for_each_entry(lu, &hi->logical_units, lu_list)
  776. if (likely(atomic_read(&lu->state) !=
  777. SBP2LU_STATE_IN_SHUTDOWN)) {
  778. atomic_set(&lu->state, SBP2LU_STATE_IN_RESET);
  779. scsi_block_requests(lu->shost);
  780. }
  781. read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  782. }
  783. static int sbp2_start_device(struct sbp2_lu *lu)
  784. {
  785. struct sbp2_fwhost_info *hi = lu->hi;
  786. int error;
  787. lu->login_response = dma_alloc_coherent(hi->host->device.parent,
  788. sizeof(struct sbp2_login_response),
  789. &lu->login_response_dma, GFP_KERNEL);
  790. if (!lu->login_response)
  791. goto alloc_fail;
  792. lu->query_logins_orb = dma_alloc_coherent(hi->host->device.parent,
  793. sizeof(struct sbp2_query_logins_orb),
  794. &lu->query_logins_orb_dma, GFP_KERNEL);
  795. if (!lu->query_logins_orb)
  796. goto alloc_fail;
  797. lu->query_logins_response = dma_alloc_coherent(hi->host->device.parent,
  798. sizeof(struct sbp2_query_logins_response),
  799. &lu->query_logins_response_dma, GFP_KERNEL);
  800. if (!lu->query_logins_response)
  801. goto alloc_fail;
  802. lu->reconnect_orb = dma_alloc_coherent(hi->host->device.parent,
  803. sizeof(struct sbp2_reconnect_orb),
  804. &lu->reconnect_orb_dma, GFP_KERNEL);
  805. if (!lu->reconnect_orb)
  806. goto alloc_fail;
  807. lu->logout_orb = dma_alloc_coherent(hi->host->device.parent,
  808. sizeof(struct sbp2_logout_orb),
  809. &lu->logout_orb_dma, GFP_KERNEL);
  810. if (!lu->logout_orb)
  811. goto alloc_fail;
  812. lu->login_orb = dma_alloc_coherent(hi->host->device.parent,
  813. sizeof(struct sbp2_login_orb),
  814. &lu->login_orb_dma, GFP_KERNEL);
  815. if (!lu->login_orb)
  816. goto alloc_fail;
  817. if (sbp2util_create_command_orb_pool(lu))
  818. goto alloc_fail;
  819. /* Wait a second before trying to log in. Previously logged in
  820. * initiators need a chance to reconnect. */
  821. if (msleep_interruptible(1000)) {
  822. sbp2_remove_device(lu);
  823. return -EINTR;
  824. }
  825. if (sbp2_login_device(lu)) {
  826. sbp2_remove_device(lu);
  827. return -EBUSY;
  828. }
  829. sbp2_set_busy_timeout(lu);
  830. sbp2_agent_reset(lu, 1);
  831. sbp2_max_speed_and_size(lu);
  832. if (lu->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY)
  833. ssleep(SBP2_INQUIRY_DELAY);
  834. error = scsi_add_device(lu->shost, 0, lu->ud->id, 0);
  835. if (error) {
  836. SBP2_ERR("scsi_add_device failed");
  837. sbp2_logout_device(lu);
  838. sbp2_remove_device(lu);
  839. return error;
  840. }
  841. return 0;
  842. alloc_fail:
  843. SBP2_ERR("Could not allocate memory for lu");
  844. sbp2_remove_device(lu);
  845. return -ENOMEM;
  846. }
  847. static void sbp2_remove_device(struct sbp2_lu *lu)
  848. {
  849. struct sbp2_fwhost_info *hi;
  850. unsigned long flags;
  851. if (!lu)
  852. return;
  853. hi = lu->hi;
  854. if (!hi)
  855. goto no_hi;
  856. if (lu->shost) {
  857. scsi_remove_host(lu->shost);
  858. scsi_host_put(lu->shost);
  859. }
  860. flush_scheduled_work();
  861. sbp2util_remove_command_orb_pool(lu, hi->host);
  862. write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  863. list_del(&lu->lu_list);
  864. write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  865. if (lu->login_response)
  866. dma_free_coherent(hi->host->device.parent,
  867. sizeof(struct sbp2_login_response),
  868. lu->login_response,
  869. lu->login_response_dma);
  870. if (lu->login_orb)
  871. dma_free_coherent(hi->host->device.parent,
  872. sizeof(struct sbp2_login_orb),
  873. lu->login_orb,
  874. lu->login_orb_dma);
  875. if (lu->reconnect_orb)
  876. dma_free_coherent(hi->host->device.parent,
  877. sizeof(struct sbp2_reconnect_orb),
  878. lu->reconnect_orb,
  879. lu->reconnect_orb_dma);
  880. if (lu->logout_orb)
  881. dma_free_coherent(hi->host->device.parent,
  882. sizeof(struct sbp2_logout_orb),
  883. lu->logout_orb,
  884. lu->logout_orb_dma);
  885. if (lu->query_logins_orb)
  886. dma_free_coherent(hi->host->device.parent,
  887. sizeof(struct sbp2_query_logins_orb),
  888. lu->query_logins_orb,
  889. lu->query_logins_orb_dma);
  890. if (lu->query_logins_response)
  891. dma_free_coherent(hi->host->device.parent,
  892. sizeof(struct sbp2_query_logins_response),
  893. lu->query_logins_response,
  894. lu->query_logins_response_dma);
  895. if (lu->status_fifo_addr != CSR1212_INVALID_ADDR_SPACE)
  896. hpsb_unregister_addrspace(&sbp2_highlevel, hi->host,
  897. lu->status_fifo_addr);
  898. lu->ud->device.driver_data = NULL;
  899. module_put(hi->host->driver->owner);
  900. no_hi:
  901. kfree(lu);
  902. }
  903. #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA
  904. /*
  905. * Deal with write requests on adapters which do not support physical DMA or
  906. * have it switched off.
  907. */
  908. static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid,
  909. int destid, quadlet_t *data, u64 addr,
  910. size_t length, u16 flags)
  911. {
  912. memcpy(bus_to_virt((u32) addr), data, length);
  913. return RCODE_COMPLETE;
  914. }
  915. /*
  916. * Deal with read requests on adapters which do not support physical DMA or
  917. * have it switched off.
  918. */
  919. static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid,
  920. quadlet_t *data, u64 addr, size_t length,
  921. u16 flags)
  922. {
  923. memcpy(data, bus_to_virt((u32) addr), length);
  924. return RCODE_COMPLETE;
  925. }
  926. #endif
  927. /**************************************
  928. * SBP-2 protocol related section
  929. **************************************/
  930. static int sbp2_query_logins(struct sbp2_lu *lu)
  931. {
  932. struct sbp2_fwhost_info *hi = lu->hi;
  933. quadlet_t data[2];
  934. int max_logins;
  935. int active_logins;
  936. lu->query_logins_orb->reserved1 = 0x0;
  937. lu->query_logins_orb->reserved2 = 0x0;
  938. lu->query_logins_orb->query_response_lo = lu->query_logins_response_dma;
  939. lu->query_logins_orb->query_response_hi =
  940. ORB_SET_NODE_ID(hi->host->node_id);
  941. lu->query_logins_orb->lun_misc =
  942. ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST);
  943. lu->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1);
  944. lu->query_logins_orb->lun_misc |= ORB_SET_LUN(lu->lun);
  945. lu->query_logins_orb->reserved_resp_length =
  946. ORB_SET_QUERY_LOGINS_RESP_LENGTH(
  947. sizeof(struct sbp2_query_logins_response));
  948. lu->query_logins_orb->status_fifo_hi =
  949. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  950. lu->query_logins_orb->status_fifo_lo =
  951. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  952. sbp2util_cpu_to_be32_buffer(lu->query_logins_orb,
  953. sizeof(struct sbp2_query_logins_orb));
  954. memset(lu->query_logins_response, 0,
  955. sizeof(struct sbp2_query_logins_response));
  956. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  957. data[1] = lu->query_logins_orb_dma;
  958. sbp2util_cpu_to_be32_buffer(data, 8);
  959. hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  960. if (sbp2util_access_timeout(lu, 2*HZ)) {
  961. SBP2_INFO("Error querying logins to SBP-2 device - timed out");
  962. return -EIO;
  963. }
  964. if (lu->status_block.ORB_offset_lo != lu->query_logins_orb_dma) {
  965. SBP2_INFO("Error querying logins to SBP-2 device - timed out");
  966. return -EIO;
  967. }
  968. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  969. SBP2_INFO("Error querying logins to SBP-2 device - failed");
  970. return -EIO;
  971. }
  972. sbp2util_cpu_to_be32_buffer(lu->query_logins_response,
  973. sizeof(struct sbp2_query_logins_response));
  974. max_logins = RESPONSE_GET_MAX_LOGINS(
  975. lu->query_logins_response->length_max_logins);
  976. SBP2_INFO("Maximum concurrent logins supported: %d", max_logins);
  977. active_logins = RESPONSE_GET_ACTIVE_LOGINS(
  978. lu->query_logins_response->length_max_logins);
  979. SBP2_INFO("Number of active logins: %d", active_logins);
  980. if (active_logins >= max_logins) {
  981. return -EIO;
  982. }
  983. return 0;
  984. }
  985. static int sbp2_login_device(struct sbp2_lu *lu)
  986. {
  987. struct sbp2_fwhost_info *hi = lu->hi;
  988. quadlet_t data[2];
  989. if (!lu->login_orb)
  990. return -EIO;
  991. if (!sbp2_exclusive_login && sbp2_query_logins(lu)) {
  992. SBP2_INFO("Device does not support any more concurrent logins");
  993. return -EIO;
  994. }
  995. /* assume no password */
  996. lu->login_orb->password_hi = 0;
  997. lu->login_orb->password_lo = 0;
  998. lu->login_orb->login_response_lo = lu->login_response_dma;
  999. lu->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id);
  1000. lu->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST);
  1001. /* one second reconnect time */
  1002. lu->login_orb->lun_misc |= ORB_SET_RECONNECT(0);
  1003. lu->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(sbp2_exclusive_login);
  1004. lu->login_orb->lun_misc |= ORB_SET_NOTIFY(1);
  1005. lu->login_orb->lun_misc |= ORB_SET_LUN(lu->lun);
  1006. lu->login_orb->passwd_resp_lengths =
  1007. ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response));
  1008. lu->login_orb->status_fifo_hi =
  1009. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1010. lu->login_orb->status_fifo_lo =
  1011. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1012. sbp2util_cpu_to_be32_buffer(lu->login_orb,
  1013. sizeof(struct sbp2_login_orb));
  1014. memset(lu->login_response, 0, sizeof(struct sbp2_login_response));
  1015. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1016. data[1] = lu->login_orb_dma;
  1017. sbp2util_cpu_to_be32_buffer(data, 8);
  1018. hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1019. /* wait up to 20 seconds for login status */
  1020. if (sbp2util_access_timeout(lu, 20*HZ)) {
  1021. SBP2_ERR("Error logging into SBP-2 device - timed out");
  1022. return -EIO;
  1023. }
  1024. /* make sure that the returned status matches the login ORB */
  1025. if (lu->status_block.ORB_offset_lo != lu->login_orb_dma) {
  1026. SBP2_ERR("Error logging into SBP-2 device - timed out");
  1027. return -EIO;
  1028. }
  1029. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  1030. SBP2_ERR("Error logging into SBP-2 device - failed");
  1031. return -EIO;
  1032. }
  1033. sbp2util_cpu_to_be32_buffer(lu->login_response,
  1034. sizeof(struct sbp2_login_response));
  1035. lu->command_block_agent_addr =
  1036. ((u64)lu->login_response->command_block_agent_hi) << 32;
  1037. lu->command_block_agent_addr |=
  1038. ((u64)lu->login_response->command_block_agent_lo);
  1039. lu->command_block_agent_addr &= 0x0000ffffffffffffULL;
  1040. SBP2_INFO("Logged into SBP-2 device");
  1041. return 0;
  1042. }
  1043. static int sbp2_logout_device(struct sbp2_lu *lu)
  1044. {
  1045. struct sbp2_fwhost_info *hi = lu->hi;
  1046. quadlet_t data[2];
  1047. int error;
  1048. lu->logout_orb->reserved1 = 0x0;
  1049. lu->logout_orb->reserved2 = 0x0;
  1050. lu->logout_orb->reserved3 = 0x0;
  1051. lu->logout_orb->reserved4 = 0x0;
  1052. lu->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST);
  1053. lu->logout_orb->login_ID_misc |=
  1054. ORB_SET_LOGIN_ID(lu->login_response->length_login_ID);
  1055. lu->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
  1056. lu->logout_orb->reserved5 = 0x0;
  1057. lu->logout_orb->status_fifo_hi =
  1058. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1059. lu->logout_orb->status_fifo_lo =
  1060. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1061. sbp2util_cpu_to_be32_buffer(lu->logout_orb,
  1062. sizeof(struct sbp2_logout_orb));
  1063. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1064. data[1] = lu->logout_orb_dma;
  1065. sbp2util_cpu_to_be32_buffer(data, 8);
  1066. error = hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1067. if (error)
  1068. return error;
  1069. /* wait up to 1 second for the device to complete logout */
  1070. if (sbp2util_access_timeout(lu, HZ))
  1071. return -EIO;
  1072. SBP2_INFO("Logged out of SBP-2 device");
  1073. return 0;
  1074. }
  1075. static int sbp2_reconnect_device(struct sbp2_lu *lu)
  1076. {
  1077. struct sbp2_fwhost_info *hi = lu->hi;
  1078. quadlet_t data[2];
  1079. int error;
  1080. lu->reconnect_orb->reserved1 = 0x0;
  1081. lu->reconnect_orb->reserved2 = 0x0;
  1082. lu->reconnect_orb->reserved3 = 0x0;
  1083. lu->reconnect_orb->reserved4 = 0x0;
  1084. lu->reconnect_orb->login_ID_misc =
  1085. ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST);
  1086. lu->reconnect_orb->login_ID_misc |=
  1087. ORB_SET_LOGIN_ID(lu->login_response->length_login_ID);
  1088. lu->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1);
  1089. lu->reconnect_orb->reserved5 = 0x0;
  1090. lu->reconnect_orb->status_fifo_hi =
  1091. ORB_SET_STATUS_FIFO_HI(lu->status_fifo_addr, hi->host->node_id);
  1092. lu->reconnect_orb->status_fifo_lo =
  1093. ORB_SET_STATUS_FIFO_LO(lu->status_fifo_addr);
  1094. sbp2util_cpu_to_be32_buffer(lu->reconnect_orb,
  1095. sizeof(struct sbp2_reconnect_orb));
  1096. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1097. data[1] = lu->reconnect_orb_dma;
  1098. sbp2util_cpu_to_be32_buffer(data, 8);
  1099. error = hpsb_node_write(lu->ne, lu->management_agent_addr, data, 8);
  1100. if (error)
  1101. return error;
  1102. /* wait up to 1 second for reconnect status */
  1103. if (sbp2util_access_timeout(lu, HZ)) {
  1104. SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
  1105. return -EIO;
  1106. }
  1107. /* make sure that the returned status matches the reconnect ORB */
  1108. if (lu->status_block.ORB_offset_lo != lu->reconnect_orb_dma) {
  1109. SBP2_ERR("Error reconnecting to SBP-2 device - timed out");
  1110. return -EIO;
  1111. }
  1112. if (STATUS_TEST_RDS(lu->status_block.ORB_offset_hi_misc)) {
  1113. SBP2_ERR("Error reconnecting to SBP-2 device - failed");
  1114. return -EIO;
  1115. }
  1116. SBP2_INFO("Reconnected to SBP-2 device");
  1117. return 0;
  1118. }
  1119. /*
  1120. * Set the target node's Single Phase Retry limit. Affects the target's retry
  1121. * behaviour if our node is too busy to accept requests.
  1122. */
  1123. static int sbp2_set_busy_timeout(struct sbp2_lu *lu)
  1124. {
  1125. quadlet_t data;
  1126. data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE);
  1127. if (hpsb_node_write(lu->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4))
  1128. SBP2_ERR("%s error", __func__);
  1129. return 0;
  1130. }
  1131. static void sbp2_parse_unit_directory(struct sbp2_lu *lu,
  1132. struct unit_directory *ud)
  1133. {
  1134. struct csr1212_keyval *kv;
  1135. struct csr1212_dentry *dentry;
  1136. u64 management_agent_addr;
  1137. u32 unit_characteristics, firmware_revision;
  1138. unsigned workarounds;
  1139. int i;
  1140. management_agent_addr = 0;
  1141. unit_characteristics = 0;
  1142. firmware_revision = 0;
  1143. csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) {
  1144. switch (kv->key.id) {
  1145. case CSR1212_KV_ID_DEPENDENT_INFO:
  1146. if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET)
  1147. management_agent_addr =
  1148. CSR1212_REGISTER_SPACE_BASE +
  1149. (kv->value.csr_offset << 2);
  1150. else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE)
  1151. lu->lun = ORB_SET_LUN(kv->value.immediate);
  1152. break;
  1153. case SBP2_UNIT_CHARACTERISTICS_KEY:
  1154. /* FIXME: This is ignored so far.
  1155. * See SBP-2 clause 7.4.8. */
  1156. unit_characteristics = kv->value.immediate;
  1157. break;
  1158. case SBP2_FIRMWARE_REVISION_KEY:
  1159. firmware_revision = kv->value.immediate;
  1160. break;
  1161. default:
  1162. /* FIXME: Check for SBP2_DEVICE_TYPE_AND_LUN_KEY.
  1163. * Its "ordered" bit has consequences for command ORB
  1164. * list handling. See SBP-2 clauses 4.6, 7.4.11, 10.2 */
  1165. break;
  1166. }
  1167. }
  1168. workarounds = sbp2_default_workarounds;
  1169. if (!(workarounds & SBP2_WORKAROUND_OVERRIDE))
  1170. for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
  1171. if (sbp2_workarounds_table[i].firmware_revision !=
  1172. SBP2_ROM_VALUE_WILDCARD &&
  1173. sbp2_workarounds_table[i].firmware_revision !=
  1174. (firmware_revision & 0xffff00))
  1175. continue;
  1176. if (sbp2_workarounds_table[i].model_id !=
  1177. SBP2_ROM_VALUE_WILDCARD &&
  1178. sbp2_workarounds_table[i].model_id != ud->model_id)
  1179. continue;
  1180. workarounds |= sbp2_workarounds_table[i].workarounds;
  1181. break;
  1182. }
  1183. if (workarounds)
  1184. SBP2_INFO("Workarounds for node " NODE_BUS_FMT ": 0x%x "
  1185. "(firmware_revision 0x%06x, vendor_id 0x%06x,"
  1186. " model_id 0x%06x)",
  1187. NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid),
  1188. workarounds, firmware_revision,
  1189. ud->vendor_id ? ud->vendor_id : ud->ne->vendor_id,
  1190. ud->model_id);
  1191. /* We would need one SCSI host template for each target to adjust
  1192. * max_sectors on the fly, therefore warn only. */
  1193. if (workarounds & SBP2_WORKAROUND_128K_MAX_TRANS &&
  1194. (sbp2_max_sectors * 512) > (128 * 1024))
  1195. SBP2_INFO("Node " NODE_BUS_FMT ": Bridge only supports 128KB "
  1196. "max transfer size. WARNING: Current max_sectors "
  1197. "setting is larger than 128KB (%d sectors)",
  1198. NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid),
  1199. sbp2_max_sectors);
  1200. /* If this is a logical unit directory entry, process the parent
  1201. * to get the values. */
  1202. if (ud->flags & UNIT_DIRECTORY_LUN_DIRECTORY) {
  1203. struct unit_directory *parent_ud = container_of(
  1204. ud->device.parent, struct unit_directory, device);
  1205. sbp2_parse_unit_directory(lu, parent_ud);
  1206. } else {
  1207. lu->management_agent_addr = management_agent_addr;
  1208. lu->workarounds = workarounds;
  1209. if (ud->flags & UNIT_DIRECTORY_HAS_LUN)
  1210. lu->lun = ORB_SET_LUN(ud->lun);
  1211. }
  1212. }
  1213. #define SBP2_PAYLOAD_TO_BYTES(p) (1 << ((p) + 2))
  1214. /*
  1215. * This function is called in order to determine the max speed and packet
  1216. * size we can use in our ORBs. Note, that we (the driver and host) only
  1217. * initiate the transaction. The SBP-2 device actually transfers the data
  1218. * (by reading from the DMA area we tell it). This means that the SBP-2
  1219. * device decides the actual maximum data it can transfer. We just tell it
  1220. * the speed that it needs to use, and the max_rec the host supports, and
  1221. * it takes care of the rest.
  1222. */
  1223. static int sbp2_max_speed_and_size(struct sbp2_lu *lu)
  1224. {
  1225. struct sbp2_fwhost_info *hi = lu->hi;
  1226. u8 payload;
  1227. lu->speed_code = hi->host->speed[NODEID_TO_NODE(lu->ne->nodeid)];
  1228. if (lu->speed_code > sbp2_max_speed) {
  1229. lu->speed_code = sbp2_max_speed;
  1230. SBP2_INFO("Reducing speed to %s",
  1231. hpsb_speedto_str[sbp2_max_speed]);
  1232. }
  1233. /* Payload size is the lesser of what our speed supports and what
  1234. * our host supports. */
  1235. payload = min(sbp2_speedto_max_payload[lu->speed_code],
  1236. (u8) (hi->host->csr.max_rec - 1));
  1237. /* If physical DMA is off, work around limitation in ohci1394:
  1238. * packet size must not exceed PAGE_SIZE */
  1239. if (lu->ne->host->low_addr_space < (1ULL << 32))
  1240. while (SBP2_PAYLOAD_TO_BYTES(payload) + 24 > PAGE_SIZE &&
  1241. payload)
  1242. payload--;
  1243. SBP2_INFO("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]",
  1244. NODE_BUS_ARGS(hi->host, lu->ne->nodeid),
  1245. hpsb_speedto_str[lu->speed_code],
  1246. SBP2_PAYLOAD_TO_BYTES(payload));
  1247. lu->max_payload_size = payload;
  1248. return 0;
  1249. }
  1250. static int sbp2_agent_reset(struct sbp2_lu *lu, int wait)
  1251. {
  1252. quadlet_t data;
  1253. u64 addr;
  1254. int retval;
  1255. unsigned long flags;
  1256. /* flush lu->protocol_work */
  1257. if (wait)
  1258. flush_scheduled_work();
  1259. data = ntohl(SBP2_AGENT_RESET_DATA);
  1260. addr = lu->command_block_agent_addr + SBP2_AGENT_RESET_OFFSET;
  1261. if (wait)
  1262. retval = hpsb_node_write(lu->ne, addr, &data, 4);
  1263. else
  1264. retval = sbp2util_node_write_no_wait(lu->ne, addr, &data, 4);
  1265. if (retval < 0) {
  1266. SBP2_ERR("hpsb_node_write failed.\n");
  1267. return -EIO;
  1268. }
  1269. /* make sure that the ORB_POINTER is written on next command */
  1270. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1271. lu->last_orb = NULL;
  1272. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1273. return 0;
  1274. }
  1275. static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
  1276. struct sbp2_fwhost_info *hi,
  1277. struct sbp2_command_info *cmd,
  1278. unsigned int scsi_use_sg,
  1279. struct scatterlist *sg,
  1280. u32 orb_direction,
  1281. enum dma_data_direction dma_dir)
  1282. {
  1283. cmd->dma_dir = dma_dir;
  1284. orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
  1285. orb->misc |= ORB_SET_DIRECTION(orb_direction);
  1286. /* special case if only one element (and less than 64KB in size) */
  1287. if (scsi_use_sg == 1 && sg->length <= SBP2_MAX_SG_ELEMENT_LENGTH) {
  1288. cmd->dma_size = sg->length;
  1289. cmd->dma_type = CMD_DMA_PAGE;
  1290. cmd->cmd_dma = dma_map_page(hi->host->device.parent,
  1291. sg_page(sg), sg->offset,
  1292. cmd->dma_size, cmd->dma_dir);
  1293. orb->data_descriptor_lo = cmd->cmd_dma;
  1294. orb->misc |= ORB_SET_DATA_SIZE(cmd->dma_size);
  1295. } else {
  1296. struct sbp2_unrestricted_page_table *sg_element =
  1297. &cmd->scatter_gather_element[0];
  1298. u32 sg_count, sg_len;
  1299. dma_addr_t sg_addr;
  1300. int i, count = dma_map_sg(hi->host->device.parent, sg,
  1301. scsi_use_sg, dma_dir);
  1302. cmd->dma_size = scsi_use_sg;
  1303. cmd->sge_buffer = sg;
  1304. /* use page tables (s/g) */
  1305. orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
  1306. orb->data_descriptor_lo = cmd->sge_dma;
  1307. /* loop through and fill out our SBP-2 page tables
  1308. * (and split up anything too large) */
  1309. for (i = 0, sg_count = 0; i < count; i++, sg = sg_next(sg)) {
  1310. sg_len = sg_dma_len(sg);
  1311. sg_addr = sg_dma_address(sg);
  1312. while (sg_len) {
  1313. sg_element[sg_count].segment_base_lo = sg_addr;
  1314. if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) {
  1315. sg_element[sg_count].length_segment_base_hi =
  1316. PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH);
  1317. sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH;
  1318. sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH;
  1319. } else {
  1320. sg_element[sg_count].length_segment_base_hi =
  1321. PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len);
  1322. sg_len = 0;
  1323. }
  1324. sg_count++;
  1325. }
  1326. }
  1327. orb->misc |= ORB_SET_DATA_SIZE(sg_count);
  1328. sbp2util_cpu_to_be32_buffer(sg_element,
  1329. (sizeof(struct sbp2_unrestricted_page_table)) *
  1330. sg_count);
  1331. }
  1332. }
  1333. static void sbp2_create_command_orb(struct sbp2_lu *lu,
  1334. struct sbp2_command_info *cmd,
  1335. struct scsi_cmnd *SCpnt)
  1336. {
  1337. struct sbp2_fwhost_info *hi = lu->hi;
  1338. struct sbp2_command_orb *orb = &cmd->command_orb;
  1339. u32 orb_direction;
  1340. unsigned int scsi_request_bufflen = scsi_bufflen(SCpnt);
  1341. enum dma_data_direction dma_dir = SCpnt->sc_data_direction;
  1342. /*
  1343. * Set-up our command ORB.
  1344. *
  1345. * NOTE: We're doing unrestricted page tables (s/g), as this is
  1346. * best performance (at least with the devices I have). This means
  1347. * that data_size becomes the number of s/g elements, and
  1348. * page_size should be zero (for unrestricted).
  1349. */
  1350. orb->next_ORB_hi = ORB_SET_NULL_PTR(1);
  1351. orb->next_ORB_lo = 0x0;
  1352. orb->misc = ORB_SET_MAX_PAYLOAD(lu->max_payload_size);
  1353. orb->misc |= ORB_SET_SPEED(lu->speed_code);
  1354. orb->misc |= ORB_SET_NOTIFY(1);
  1355. if (dma_dir == DMA_NONE)
  1356. orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
  1357. else if (dma_dir == DMA_TO_DEVICE && scsi_request_bufflen)
  1358. orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA;
  1359. else if (dma_dir == DMA_FROM_DEVICE && scsi_request_bufflen)
  1360. orb_direction = ORB_DIRECTION_READ_FROM_MEDIA;
  1361. else {
  1362. SBP2_INFO("Falling back to DMA_NONE");
  1363. orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER;
  1364. }
  1365. /* set up our page table stuff */
  1366. if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) {
  1367. orb->data_descriptor_hi = 0x0;
  1368. orb->data_descriptor_lo = 0x0;
  1369. orb->misc |= ORB_SET_DIRECTION(1);
  1370. } else
  1371. sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_sg_count(SCpnt),
  1372. scsi_sglist(SCpnt),
  1373. orb_direction, dma_dir);
  1374. sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb));
  1375. memset(orb->cdb, 0, sizeof(orb->cdb));
  1376. memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);
  1377. }
  1378. static void sbp2_link_orb_command(struct sbp2_lu *lu,
  1379. struct sbp2_command_info *cmd)
  1380. {
  1381. struct sbp2_fwhost_info *hi = lu->hi;
  1382. struct sbp2_command_orb *last_orb;
  1383. dma_addr_t last_orb_dma;
  1384. u64 addr = lu->command_block_agent_addr;
  1385. quadlet_t data[2];
  1386. size_t length;
  1387. unsigned long flags;
  1388. dma_sync_single_for_device(hi->host->device.parent,
  1389. cmd->command_orb_dma,
  1390. sizeof(struct sbp2_command_orb),
  1391. DMA_TO_DEVICE);
  1392. dma_sync_single_for_device(hi->host->device.parent, cmd->sge_dma,
  1393. sizeof(cmd->scatter_gather_element),
  1394. DMA_TO_DEVICE);
  1395. /* check to see if there are any previous orbs to use */
  1396. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1397. last_orb = lu->last_orb;
  1398. last_orb_dma = lu->last_orb_dma;
  1399. if (!last_orb) {
  1400. /*
  1401. * last_orb == NULL means: We know that the target's fetch agent
  1402. * is not active right now.
  1403. */
  1404. addr += SBP2_ORB_POINTER_OFFSET;
  1405. data[0] = ORB_SET_NODE_ID(hi->host->node_id);
  1406. data[1] = cmd->command_orb_dma;
  1407. sbp2util_cpu_to_be32_buffer(data, 8);
  1408. length = 8;
  1409. } else {
  1410. /*
  1411. * last_orb != NULL means: We know that the target's fetch agent
  1412. * is (very probably) not dead or in reset state right now.
  1413. * We have an ORB already sent that we can append a new one to.
  1414. * The target's fetch agent may or may not have read this
  1415. * previous ORB yet.
  1416. */
  1417. dma_sync_single_for_cpu(hi->host->device.parent, last_orb_dma,
  1418. sizeof(struct sbp2_command_orb),
  1419. DMA_TO_DEVICE);
  1420. last_orb->next_ORB_lo = cpu_to_be32(cmd->command_orb_dma);
  1421. wmb();
  1422. /* Tells hardware that this pointer is valid */
  1423. last_orb->next_ORB_hi = 0;
  1424. dma_sync_single_for_device(hi->host->device.parent,
  1425. last_orb_dma,
  1426. sizeof(struct sbp2_command_orb),
  1427. DMA_TO_DEVICE);
  1428. addr += SBP2_DOORBELL_OFFSET;
  1429. data[0] = 0;
  1430. length = 4;
  1431. }
  1432. lu->last_orb = &cmd->command_orb;
  1433. lu->last_orb_dma = cmd->command_orb_dma;
  1434. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1435. if (sbp2util_node_write_no_wait(lu->ne, addr, data, length)) {
  1436. /*
  1437. * sbp2util_node_write_no_wait failed. We certainly ran out
  1438. * of transaction labels, perhaps just because there were no
  1439. * context switches which gave khpsbpkt a chance to collect
  1440. * free tlabels. Try again in non-atomic context. If necessary,
  1441. * the workqueue job will sleep to guaranteedly get a tlabel.
  1442. * We do not accept new commands until the job is over.
  1443. */
  1444. scsi_block_requests(lu->shost);
  1445. PREPARE_WORK(&lu->protocol_work,
  1446. last_orb ? sbp2util_write_doorbell:
  1447. sbp2util_write_orb_pointer);
  1448. schedule_work(&lu->protocol_work);
  1449. }
  1450. }
  1451. static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt,
  1452. void (*done)(struct scsi_cmnd *))
  1453. {
  1454. struct sbp2_command_info *cmd;
  1455. cmd = sbp2util_allocate_command_orb(lu, SCpnt, done);
  1456. if (!cmd)
  1457. return -EIO;
  1458. sbp2_create_command_orb(lu, cmd, SCpnt);
  1459. sbp2_link_orb_command(lu, cmd);
  1460. return 0;
  1461. }
  1462. /*
  1463. * Translates SBP-2 status into SCSI sense data for check conditions
  1464. */
  1465. static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status,
  1466. unchar *sense_data)
  1467. {
  1468. /* OK, it's pretty ugly... ;-) */
  1469. sense_data[0] = 0x70;
  1470. sense_data[1] = 0x0;
  1471. sense_data[2] = sbp2_status[9];
  1472. sense_data[3] = sbp2_status[12];
  1473. sense_data[4] = sbp2_status[13];
  1474. sense_data[5] = sbp2_status[14];
  1475. sense_data[6] = sbp2_status[15];
  1476. sense_data[7] = 10;
  1477. sense_data[8] = sbp2_status[16];
  1478. sense_data[9] = sbp2_status[17];
  1479. sense_data[10] = sbp2_status[18];
  1480. sense_data[11] = sbp2_status[19];
  1481. sense_data[12] = sbp2_status[10];
  1482. sense_data[13] = sbp2_status[11];
  1483. sense_data[14] = sbp2_status[20];
  1484. sense_data[15] = sbp2_status[21];
  1485. return sbp2_status[8] & 0x3f;
  1486. }
  1487. static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
  1488. int destid, quadlet_t *data, u64 addr,
  1489. size_t length, u16 fl)
  1490. {
  1491. struct sbp2_fwhost_info *hi;
  1492. struct sbp2_lu *lu = NULL, *lu_tmp;
  1493. struct scsi_cmnd *SCpnt = NULL;
  1494. struct sbp2_status_block *sb;
  1495. u32 scsi_status = SBP2_SCSI_STATUS_GOOD;
  1496. struct sbp2_command_info *cmd;
  1497. unsigned long flags;
  1498. if (unlikely(length < 8 || length > sizeof(struct sbp2_status_block))) {
  1499. SBP2_ERR("Wrong size of status block");
  1500. return RCODE_ADDRESS_ERROR;
  1501. }
  1502. if (unlikely(!host)) {
  1503. SBP2_ERR("host is NULL - this is bad!");
  1504. return RCODE_ADDRESS_ERROR;
  1505. }
  1506. hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
  1507. if (unlikely(!hi)) {
  1508. SBP2_ERR("host info is NULL - this is bad!");
  1509. return RCODE_ADDRESS_ERROR;
  1510. }
  1511. /* Find the unit which wrote the status. */
  1512. read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
  1513. list_for_each_entry(lu_tmp, &hi->logical_units, lu_list) {
  1514. if (lu_tmp->ne->nodeid == nodeid &&
  1515. lu_tmp->status_fifo_addr == addr) {
  1516. lu = lu_tmp;
  1517. break;
  1518. }
  1519. }
  1520. read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
  1521. if (unlikely(!lu)) {
  1522. SBP2_ERR("lu is NULL - device is gone?");
  1523. return RCODE_ADDRESS_ERROR;
  1524. }
  1525. /* Put response into lu status fifo buffer. The first two bytes
  1526. * come in big endian bit order. Often the target writes only a
  1527. * truncated status block, minimally the first two quadlets. The rest
  1528. * is implied to be zeros. */
  1529. sb = &lu->status_block;
  1530. memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent));
  1531. memcpy(sb, data, length);
  1532. sbp2util_be32_to_cpu_buffer(sb, 8);
  1533. /* Ignore unsolicited status. Handle command ORB status. */
  1534. if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2))
  1535. cmd = NULL;
  1536. else
  1537. cmd = sbp2util_find_command_for_orb(lu, sb->ORB_offset_lo);
  1538. if (cmd) {
  1539. dma_sync_single_for_cpu(hi->host->device.parent,
  1540. cmd->command_orb_dma,
  1541. sizeof(struct sbp2_command_orb),
  1542. DMA_TO_DEVICE);
  1543. dma_sync_single_for_cpu(hi->host->device.parent, cmd->sge_dma,
  1544. sizeof(cmd->scatter_gather_element),
  1545. DMA_TO_DEVICE);
  1546. /* Grab SCSI command pointers and check status. */
  1547. /*
  1548. * FIXME: If the src field in the status is 1, the ORB DMA must
  1549. * not be reused until status for a subsequent ORB is received.
  1550. */
  1551. SCpnt = cmd->Current_SCpnt;
  1552. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1553. sbp2util_mark_command_completed(lu, cmd);
  1554. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1555. if (SCpnt) {
  1556. u32 h = sb->ORB_offset_hi_misc;
  1557. u32 r = STATUS_GET_RESP(h);
  1558. if (r != RESP_STATUS_REQUEST_COMPLETE) {
  1559. SBP2_INFO("resp 0x%x, sbp_status 0x%x",
  1560. r, STATUS_GET_SBP_STATUS(h));
  1561. scsi_status =
  1562. r == RESP_STATUS_TRANSPORT_FAILURE ?
  1563. SBP2_SCSI_STATUS_BUSY :
  1564. SBP2_SCSI_STATUS_COMMAND_TERMINATED;
  1565. }
  1566. if (STATUS_GET_LEN(h) > 1)
  1567. scsi_status = sbp2_status_to_sense_data(
  1568. (unchar *)sb, SCpnt->sense_buffer);
  1569. if (STATUS_TEST_DEAD(h))
  1570. sbp2_agent_reset(lu, 0);
  1571. }
  1572. /* Check here to see if there are no commands in-use. If there
  1573. * are none, we know that the fetch agent left the active state
  1574. * _and_ that we did not reactivate it yet. Therefore clear
  1575. * last_orb so that next time we write directly to the
  1576. * ORB_POINTER register. That way the fetch agent does not need
  1577. * to refetch the next_ORB. */
  1578. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1579. if (list_empty(&lu->cmd_orb_inuse))
  1580. lu->last_orb = NULL;
  1581. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1582. } else {
  1583. /* It's probably status after a management request. */
  1584. if ((sb->ORB_offset_lo == lu->reconnect_orb_dma) ||
  1585. (sb->ORB_offset_lo == lu->login_orb_dma) ||
  1586. (sb->ORB_offset_lo == lu->query_logins_orb_dma) ||
  1587. (sb->ORB_offset_lo == lu->logout_orb_dma)) {
  1588. lu->access_complete = 1;
  1589. wake_up_interruptible(&sbp2_access_wq);
  1590. }
  1591. }
  1592. if (SCpnt)
  1593. sbp2scsi_complete_command(lu, scsi_status, SCpnt,
  1594. cmd->Current_done);
  1595. return RCODE_COMPLETE;
  1596. }
  1597. /**************************************
  1598. * SCSI interface related section
  1599. **************************************/
  1600. static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt,
  1601. void (*done)(struct scsi_cmnd *))
  1602. {
  1603. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1604. struct sbp2_fwhost_info *hi;
  1605. int result = DID_NO_CONNECT << 16;
  1606. if (unlikely(!sbp2util_node_is_available(lu)))
  1607. goto done;
  1608. hi = lu->hi;
  1609. if (unlikely(!hi)) {
  1610. SBP2_ERR("sbp2_fwhost_info is NULL - this is bad!");
  1611. goto done;
  1612. }
  1613. /* Multiple units are currently represented to the SCSI core as separate
  1614. * targets, not as one target with multiple LUs. Therefore return
  1615. * selection time-out to any IO directed at non-zero LUNs. */
  1616. if (unlikely(SCpnt->device->lun))
  1617. goto done;
  1618. if (unlikely(!hpsb_node_entry_valid(lu->ne))) {
  1619. SBP2_ERR("Bus reset in progress - rejecting command");
  1620. result = DID_BUS_BUSY << 16;
  1621. goto done;
  1622. }
  1623. /* Bidirectional commands are not yet implemented,
  1624. * and unknown transfer direction not handled. */
  1625. if (unlikely(SCpnt->sc_data_direction == DMA_BIDIRECTIONAL)) {
  1626. SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command");
  1627. result = DID_ERROR << 16;
  1628. goto done;
  1629. }
  1630. if (sbp2_send_command(lu, SCpnt, done)) {
  1631. SBP2_ERR("Error sending SCSI command");
  1632. sbp2scsi_complete_command(lu,
  1633. SBP2_SCSI_STATUS_SELECTION_TIMEOUT,
  1634. SCpnt, done);
  1635. }
  1636. return 0;
  1637. done:
  1638. SCpnt->result = result;
  1639. done(SCpnt);
  1640. return 0;
  1641. }
  1642. static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status)
  1643. {
  1644. struct sbp2_fwhost_info *hi = lu->hi;
  1645. struct list_head *lh;
  1646. struct sbp2_command_info *cmd;
  1647. unsigned long flags;
  1648. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1649. while (!list_empty(&lu->cmd_orb_inuse)) {
  1650. lh = lu->cmd_orb_inuse.next;
  1651. cmd = list_entry(lh, struct sbp2_command_info, list);
  1652. dma_sync_single_for_cpu(hi->host->device.parent,
  1653. cmd->command_orb_dma,
  1654. sizeof(struct sbp2_command_orb),
  1655. DMA_TO_DEVICE);
  1656. dma_sync_single_for_cpu(hi->host->device.parent, cmd->sge_dma,
  1657. sizeof(cmd->scatter_gather_element),
  1658. DMA_TO_DEVICE);
  1659. sbp2util_mark_command_completed(lu, cmd);
  1660. if (cmd->Current_SCpnt) {
  1661. cmd->Current_SCpnt->result = status << 16;
  1662. cmd->Current_done(cmd->Current_SCpnt);
  1663. }
  1664. }
  1665. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1666. return;
  1667. }
  1668. /*
  1669. * Complete a regular SCSI command. Can be called in atomic context.
  1670. */
  1671. static void sbp2scsi_complete_command(struct sbp2_lu *lu, u32 scsi_status,
  1672. struct scsi_cmnd *SCpnt,
  1673. void (*done)(struct scsi_cmnd *))
  1674. {
  1675. if (!SCpnt) {
  1676. SBP2_ERR("SCpnt is NULL");
  1677. return;
  1678. }
  1679. switch (scsi_status) {
  1680. case SBP2_SCSI_STATUS_GOOD:
  1681. SCpnt->result = DID_OK << 16;
  1682. break;
  1683. case SBP2_SCSI_STATUS_BUSY:
  1684. SBP2_ERR("SBP2_SCSI_STATUS_BUSY");
  1685. SCpnt->result = DID_BUS_BUSY << 16;
  1686. break;
  1687. case SBP2_SCSI_STATUS_CHECK_CONDITION:
  1688. SCpnt->result = CHECK_CONDITION << 1 | DID_OK << 16;
  1689. break;
  1690. case SBP2_SCSI_STATUS_SELECTION_TIMEOUT:
  1691. SBP2_ERR("SBP2_SCSI_STATUS_SELECTION_TIMEOUT");
  1692. SCpnt->result = DID_NO_CONNECT << 16;
  1693. scsi_print_command(SCpnt);
  1694. break;
  1695. case SBP2_SCSI_STATUS_CONDITION_MET:
  1696. case SBP2_SCSI_STATUS_RESERVATION_CONFLICT:
  1697. case SBP2_SCSI_STATUS_COMMAND_TERMINATED:
  1698. SBP2_ERR("Bad SCSI status = %x", scsi_status);
  1699. SCpnt->result = DID_ERROR << 16;
  1700. scsi_print_command(SCpnt);
  1701. break;
  1702. default:
  1703. SBP2_ERR("Unsupported SCSI status = %x", scsi_status);
  1704. SCpnt->result = DID_ERROR << 16;
  1705. }
  1706. /* If a bus reset is in progress and there was an error, complete
  1707. * the command as busy so that it will get retried. */
  1708. if (!hpsb_node_entry_valid(lu->ne)
  1709. && (scsi_status != SBP2_SCSI_STATUS_GOOD)) {
  1710. SBP2_ERR("Completing command with busy (bus reset)");
  1711. SCpnt->result = DID_BUS_BUSY << 16;
  1712. }
  1713. /* Tell the SCSI stack that we're done with this command. */
  1714. done(SCpnt);
  1715. }
  1716. static int sbp2scsi_slave_alloc(struct scsi_device *sdev)
  1717. {
  1718. struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0];
  1719. if (sdev->lun != 0 || sdev->id != lu->ud->id || sdev->channel != 0)
  1720. return -ENODEV;
  1721. lu->sdev = sdev;
  1722. sdev->allow_restart = 1;
  1723. /* SBP-2 requires quadlet alignment of the data buffers. */
  1724. blk_queue_update_dma_alignment(sdev->request_queue, 4 - 1);
  1725. if (lu->workarounds & SBP2_WORKAROUND_INQUIRY_36)
  1726. sdev->inquiry_len = 36;
  1727. return 0;
  1728. }
  1729. static int sbp2scsi_slave_configure(struct scsi_device *sdev)
  1730. {
  1731. struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0];
  1732. sdev->use_10_for_rw = 1;
  1733. if (sbp2_exclusive_login)
  1734. sdev->manage_start_stop = 1;
  1735. if (sdev->type == TYPE_ROM)
  1736. sdev->use_10_for_ms = 1;
  1737. if (sdev->type == TYPE_DISK &&
  1738. lu->workarounds & SBP2_WORKAROUND_MODE_SENSE_8)
  1739. sdev->skip_ms_page_8 = 1;
  1740. if (lu->workarounds & SBP2_WORKAROUND_FIX_CAPACITY)
  1741. sdev->fix_capacity = 1;
  1742. if (lu->workarounds & SBP2_WORKAROUND_POWER_CONDITION)
  1743. sdev->start_stop_pwr_cond = 1;
  1744. if (lu->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
  1745. blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
  1746. return 0;
  1747. }
  1748. static void sbp2scsi_slave_destroy(struct scsi_device *sdev)
  1749. {
  1750. ((struct sbp2_lu *)sdev->host->hostdata[0])->sdev = NULL;
  1751. return;
  1752. }
  1753. /*
  1754. * Called by scsi stack when something has really gone wrong.
  1755. * Usually called when a command has timed-out for some reason.
  1756. */
  1757. static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
  1758. {
  1759. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1760. struct sbp2_fwhost_info *hi = lu->hi;
  1761. struct sbp2_command_info *cmd;
  1762. unsigned long flags;
  1763. SBP2_INFO("aborting sbp2 command");
  1764. scsi_print_command(SCpnt);
  1765. if (sbp2util_node_is_available(lu)) {
  1766. sbp2_agent_reset(lu, 1);
  1767. /* Return a matching command structure to the free pool. */
  1768. spin_lock_irqsave(&lu->cmd_orb_lock, flags);
  1769. cmd = sbp2util_find_command_for_SCpnt(lu, SCpnt);
  1770. if (cmd) {
  1771. dma_sync_single_for_cpu(hi->host->device.parent,
  1772. cmd->command_orb_dma,
  1773. sizeof(struct sbp2_command_orb),
  1774. DMA_TO_DEVICE);
  1775. dma_sync_single_for_cpu(hi->host->device.parent,
  1776. cmd->sge_dma,
  1777. sizeof(cmd->scatter_gather_element),
  1778. DMA_TO_DEVICE);
  1779. sbp2util_mark_command_completed(lu, cmd);
  1780. if (cmd->Current_SCpnt) {
  1781. cmd->Current_SCpnt->result = DID_ABORT << 16;
  1782. cmd->Current_done(cmd->Current_SCpnt);
  1783. }
  1784. }
  1785. spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
  1786. sbp2scsi_complete_all_commands(lu, DID_BUS_BUSY);
  1787. }
  1788. return SUCCESS;
  1789. }
  1790. /*
  1791. * Called by scsi stack when something has really gone wrong.
  1792. */
  1793. static int sbp2scsi_reset(struct scsi_cmnd *SCpnt)
  1794. {
  1795. struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
  1796. SBP2_INFO("reset requested");
  1797. if (sbp2util_node_is_available(lu)) {
  1798. SBP2_INFO("generating sbp2 fetch agent reset");
  1799. sbp2_agent_reset(lu, 1);
  1800. }
  1801. return SUCCESS;
  1802. }
  1803. static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev,
  1804. struct device_attribute *attr,
  1805. char *buf)
  1806. {
  1807. struct scsi_device *sdev;
  1808. struct sbp2_lu *lu;
  1809. if (!(sdev = to_scsi_device(dev)))
  1810. return 0;
  1811. if (!(lu = (struct sbp2_lu *)sdev->host->hostdata[0]))
  1812. return 0;
  1813. if (sbp2_long_sysfs_ieee1394_id)
  1814. return sprintf(buf, "%016Lx:%06x:%04x\n",
  1815. (unsigned long long)lu->ne->guid,
  1816. lu->ud->directory_id, ORB_SET_LUN(lu->lun));
  1817. else
  1818. return sprintf(buf, "%016Lx:%d:%d\n",
  1819. (unsigned long long)lu->ne->guid,
  1820. lu->ud->id, ORB_SET_LUN(lu->lun));
  1821. }
  1822. MODULE_AUTHOR("Ben Collins <bcollins@debian.org>");
  1823. MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
  1824. MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
  1825. MODULE_LICENSE("GPL");
  1826. static int sbp2_module_init(void)
  1827. {
  1828. int ret;
  1829. if (sbp2_serialize_io) {
  1830. sbp2_shost_template.can_queue = 1;
  1831. sbp2_shost_template.cmd_per_lun = 1;
  1832. }
  1833. sbp2_shost_template.max_sectors = sbp2_max_sectors;
  1834. hpsb_register_highlevel(&sbp2_highlevel);
  1835. ret = hpsb_register_protocol(&sbp2_driver);
  1836. if (ret) {
  1837. SBP2_ERR("Failed to register protocol");
  1838. hpsb_unregister_highlevel(&sbp2_highlevel);
  1839. return ret;
  1840. }
  1841. return 0;
  1842. }
  1843. static void __exit sbp2_module_exit(void)
  1844. {
  1845. hpsb_unregister_protocol(&sbp2_driver);
  1846. hpsb_unregister_highlevel(&sbp2_highlevel);
  1847. }
  1848. module_init(sbp2_module_init);
  1849. module_exit(sbp2_module_exit);