sbp2.c 63 KB

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