sbp2.c 63 KB

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