sbp2.c 63 KB

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