sbp2.c 63 KB

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