zfcp_fsf.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include "zfcp_ext.h"
  12. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  13. #define ZFCP_REQ_NO_QTCB 0x00000008
  14. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  15. {
  16. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  17. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  18. "fsrth_1", NULL);
  19. }
  20. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  21. unsigned long timeout)
  22. {
  23. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  24. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  25. fsf_req->timer.expires = jiffies + timeout;
  26. add_timer(&fsf_req->timer);
  27. }
  28. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  29. {
  30. BUG_ON(!fsf_req->erp_action);
  31. fsf_req->timer.function = zfcp_erp_timeout_handler;
  32. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  33. fsf_req->timer.expires = jiffies + 30 * HZ;
  34. add_timer(&fsf_req->timer);
  35. }
  36. /* association between FSF command and FSF QTCB type */
  37. static u32 fsf_qtcb_type[] = {
  38. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  39. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  43. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  48. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  49. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  51. };
  52. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  53. {
  54. u16 subtable = table >> 16;
  55. u16 rule = table & 0xffff;
  56. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  57. if (subtable && subtable < ARRAY_SIZE(act_type))
  58. dev_warn(&adapter->ccw_device->dev,
  59. "Access denied according to ACT rule type %s, "
  60. "rule %d\n", act_type[subtable], rule);
  61. }
  62. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  63. struct zfcp_port *port)
  64. {
  65. struct fsf_qtcb_header *header = &req->qtcb->header;
  66. dev_warn(&req->adapter->ccw_device->dev,
  67. "Access denied to port 0x%016Lx\n",
  68. (unsigned long long)port->wwpn);
  69. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  70. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  71. zfcp_erp_port_access_denied(port, "fspad_1", req);
  72. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  73. }
  74. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  75. struct zfcp_unit *unit)
  76. {
  77. struct fsf_qtcb_header *header = &req->qtcb->header;
  78. dev_warn(&req->adapter->ccw_device->dev,
  79. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  80. (unsigned long long)unit->fcp_lun,
  81. (unsigned long long)unit->port->wwpn);
  82. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  83. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  84. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  85. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  86. }
  87. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  88. {
  89. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  90. "operational because of an unsupported FC class\n");
  91. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  92. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  93. }
  94. /**
  95. * zfcp_fsf_req_free - free memory used by fsf request
  96. * @fsf_req: pointer to struct zfcp_fsf_req
  97. */
  98. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  99. {
  100. if (likely(req->pool)) {
  101. mempool_free(req, req->pool);
  102. return;
  103. }
  104. if (req->qtcb) {
  105. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  106. return;
  107. }
  108. }
  109. /**
  110. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  111. * @adapter: pointer to struct zfcp_adapter
  112. *
  113. * Never ever call this without shutting down the adapter first.
  114. * Otherwise the adapter would continue using and corrupting s390 storage.
  115. * Included BUG_ON() call to ensure this is done.
  116. * ERP is supposed to be the only user of this function.
  117. */
  118. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  119. {
  120. struct zfcp_fsf_req *req, *tmp;
  121. unsigned long flags;
  122. LIST_HEAD(remove_queue);
  123. unsigned int i;
  124. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  125. spin_lock_irqsave(&adapter->req_list_lock, flags);
  126. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  127. list_splice_init(&adapter->req_list[i], &remove_queue);
  128. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  129. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  130. list_del(&req->list);
  131. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  132. zfcp_fsf_req_complete(req);
  133. }
  134. }
  135. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  136. {
  137. struct fsf_status_read_buffer *sr_buf = req->data;
  138. struct zfcp_adapter *adapter = req->adapter;
  139. struct zfcp_port *port;
  140. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  141. unsigned long flags;
  142. read_lock_irqsave(&zfcp_data.config_lock, flags);
  143. list_for_each_entry(port, &adapter->port_list_head, list)
  144. if (port->d_id == d_id) {
  145. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  146. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  147. return;
  148. }
  149. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  150. }
  151. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  152. struct fsf_link_down_info *link_down)
  153. {
  154. struct zfcp_adapter *adapter = req->adapter;
  155. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  156. return;
  157. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  158. zfcp_scsi_schedule_rports_block(adapter);
  159. if (!link_down)
  160. goto out;
  161. switch (link_down->error_code) {
  162. case FSF_PSQ_LINK_NO_LIGHT:
  163. dev_warn(&req->adapter->ccw_device->dev,
  164. "There is no light signal from the local "
  165. "fibre channel cable\n");
  166. break;
  167. case FSF_PSQ_LINK_WRAP_PLUG:
  168. dev_warn(&req->adapter->ccw_device->dev,
  169. "There is a wrap plug instead of a fibre "
  170. "channel cable\n");
  171. break;
  172. case FSF_PSQ_LINK_NO_FCP:
  173. dev_warn(&req->adapter->ccw_device->dev,
  174. "The adjacent fibre channel node does not "
  175. "support FCP\n");
  176. break;
  177. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  178. dev_warn(&req->adapter->ccw_device->dev,
  179. "The FCP device is suspended because of a "
  180. "firmware update\n");
  181. break;
  182. case FSF_PSQ_LINK_INVALID_WWPN:
  183. dev_warn(&req->adapter->ccw_device->dev,
  184. "The FCP device detected a WWPN that is "
  185. "duplicate or not valid\n");
  186. break;
  187. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  188. dev_warn(&req->adapter->ccw_device->dev,
  189. "The fibre channel fabric does not support NPIV\n");
  190. break;
  191. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  192. dev_warn(&req->adapter->ccw_device->dev,
  193. "The FCP adapter cannot support more NPIV ports\n");
  194. break;
  195. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  196. dev_warn(&req->adapter->ccw_device->dev,
  197. "The adjacent switch cannot support "
  198. "more NPIV ports\n");
  199. break;
  200. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  201. dev_warn(&req->adapter->ccw_device->dev,
  202. "The FCP adapter could not log in to the "
  203. "fibre channel fabric\n");
  204. break;
  205. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  206. dev_warn(&req->adapter->ccw_device->dev,
  207. "The WWPN assignment file on the FCP adapter "
  208. "has been damaged\n");
  209. break;
  210. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  211. dev_warn(&req->adapter->ccw_device->dev,
  212. "The mode table on the FCP adapter "
  213. "has been damaged\n");
  214. break;
  215. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  216. dev_warn(&req->adapter->ccw_device->dev,
  217. "All NPIV ports on the FCP adapter have "
  218. "been assigned\n");
  219. break;
  220. default:
  221. dev_warn(&req->adapter->ccw_device->dev,
  222. "The link between the FCP adapter and "
  223. "the FC fabric is down\n");
  224. }
  225. out:
  226. zfcp_erp_adapter_failed(adapter, id, req);
  227. }
  228. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  229. {
  230. struct fsf_status_read_buffer *sr_buf = req->data;
  231. struct fsf_link_down_info *ldi =
  232. (struct fsf_link_down_info *) &sr_buf->payload;
  233. switch (sr_buf->status_subtype) {
  234. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  235. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  236. break;
  237. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  238. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  239. break;
  240. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  241. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  242. };
  243. }
  244. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  245. {
  246. struct zfcp_adapter *adapter = req->adapter;
  247. struct fsf_status_read_buffer *sr_buf = req->data;
  248. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  249. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  250. mempool_free(sr_buf, adapter->pool.data_status_read);
  251. zfcp_fsf_req_free(req);
  252. return;
  253. }
  254. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  255. switch (sr_buf->status_type) {
  256. case FSF_STATUS_READ_PORT_CLOSED:
  257. zfcp_fsf_status_read_port_closed(req);
  258. break;
  259. case FSF_STATUS_READ_INCOMING_ELS:
  260. zfcp_fc_incoming_els(req);
  261. break;
  262. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  263. break;
  264. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  265. dev_warn(&adapter->ccw_device->dev,
  266. "The error threshold for checksum statistics "
  267. "has been exceeded\n");
  268. zfcp_hba_dbf_event_berr(adapter, req);
  269. break;
  270. case FSF_STATUS_READ_LINK_DOWN:
  271. zfcp_fsf_status_read_link_down(req);
  272. break;
  273. case FSF_STATUS_READ_LINK_UP:
  274. dev_info(&adapter->ccw_device->dev,
  275. "The local link has been restored\n");
  276. /* All ports should be marked as ready to run again */
  277. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  278. ZFCP_STATUS_COMMON_RUNNING,
  279. ZFCP_SET);
  280. zfcp_erp_adapter_reopen(adapter,
  281. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  282. ZFCP_STATUS_COMMON_ERP_FAILED,
  283. "fssrh_2", req);
  284. break;
  285. case FSF_STATUS_READ_NOTIFICATION_LOST:
  286. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  287. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  288. req);
  289. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  290. schedule_work(&adapter->scan_work);
  291. break;
  292. case FSF_STATUS_READ_CFDC_UPDATED:
  293. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  294. break;
  295. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  296. adapter->adapter_features = sr_buf->payload.word[0];
  297. break;
  298. }
  299. mempool_free(sr_buf, adapter->pool.data_status_read);
  300. zfcp_fsf_req_free(req);
  301. atomic_inc(&adapter->stat_miss);
  302. queue_work(zfcp_data.work_queue, &adapter->stat_work);
  303. }
  304. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  305. {
  306. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  307. case FSF_SQ_FCP_RSP_AVAILABLE:
  308. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  309. case FSF_SQ_NO_RETRY_POSSIBLE:
  310. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  311. return;
  312. case FSF_SQ_COMMAND_ABORTED:
  313. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  314. break;
  315. case FSF_SQ_NO_RECOM:
  316. dev_err(&req->adapter->ccw_device->dev,
  317. "The FCP adapter reported a problem "
  318. "that cannot be recovered\n");
  319. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  320. break;
  321. }
  322. /* all non-return stats set FSFREQ_ERROR*/
  323. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  324. }
  325. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  326. {
  327. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  328. return;
  329. switch (req->qtcb->header.fsf_status) {
  330. case FSF_UNKNOWN_COMMAND:
  331. dev_err(&req->adapter->ccw_device->dev,
  332. "The FCP adapter does not recognize the command 0x%x\n",
  333. req->qtcb->header.fsf_command);
  334. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  335. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  336. break;
  337. case FSF_ADAPTER_STATUS_AVAILABLE:
  338. zfcp_fsf_fsfstatus_qual_eval(req);
  339. break;
  340. }
  341. }
  342. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  343. {
  344. struct zfcp_adapter *adapter = req->adapter;
  345. struct fsf_qtcb *qtcb = req->qtcb;
  346. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  347. zfcp_hba_dbf_event_fsf_response(req);
  348. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  349. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  350. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  351. return;
  352. }
  353. switch (qtcb->prefix.prot_status) {
  354. case FSF_PROT_GOOD:
  355. case FSF_PROT_FSF_STATUS_PRESENTED:
  356. return;
  357. case FSF_PROT_QTCB_VERSION_ERROR:
  358. dev_err(&adapter->ccw_device->dev,
  359. "QTCB version 0x%x not supported by FCP adapter "
  360. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  361. psq->word[0], psq->word[1]);
  362. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  363. break;
  364. case FSF_PROT_ERROR_STATE:
  365. case FSF_PROT_SEQ_NUMB_ERROR:
  366. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  367. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  368. break;
  369. case FSF_PROT_UNSUPP_QTCB_TYPE:
  370. dev_err(&adapter->ccw_device->dev,
  371. "The QTCB type is not supported by the FCP adapter\n");
  372. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  373. break;
  374. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  375. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  376. &adapter->status);
  377. break;
  378. case FSF_PROT_DUPLICATE_REQUEST_ID:
  379. dev_err(&adapter->ccw_device->dev,
  380. "0x%Lx is an ambiguous request identifier\n",
  381. (unsigned long long)qtcb->bottom.support.req_handle);
  382. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  383. break;
  384. case FSF_PROT_LINK_DOWN:
  385. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  386. &psq->link_down_info);
  387. /* FIXME: reopening adapter now? better wait for link up */
  388. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  389. break;
  390. case FSF_PROT_REEST_QUEUE:
  391. /* All ports should be marked as ready to run again */
  392. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  393. ZFCP_STATUS_COMMON_RUNNING,
  394. ZFCP_SET);
  395. zfcp_erp_adapter_reopen(adapter,
  396. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  397. ZFCP_STATUS_COMMON_ERP_FAILED,
  398. "fspse_8", req);
  399. break;
  400. default:
  401. dev_err(&adapter->ccw_device->dev,
  402. "0x%x is not a valid transfer protocol status\n",
  403. qtcb->prefix.prot_status);
  404. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  405. }
  406. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  407. }
  408. /**
  409. * zfcp_fsf_req_complete - process completion of a FSF request
  410. * @fsf_req: The FSF request that has been completed.
  411. *
  412. * When a request has been completed either from the FCP adapter,
  413. * or it has been dismissed due to a queue shutdown, this function
  414. * is called to process the completion status and trigger further
  415. * events related to the FSF request.
  416. */
  417. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  418. {
  419. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  420. zfcp_fsf_status_read_handler(req);
  421. return;
  422. }
  423. del_timer(&req->timer);
  424. zfcp_fsf_protstatus_eval(req);
  425. zfcp_fsf_fsfstatus_eval(req);
  426. req->handler(req);
  427. if (req->erp_action)
  428. zfcp_erp_notify(req->erp_action, 0);
  429. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  430. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  431. zfcp_fsf_req_free(req);
  432. else
  433. /* notify initiator waiting for the requests completion */
  434. /*
  435. * FIXME: Race! We must not access fsf_req here as it might have been
  436. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  437. * flag. It's an improbable case. But, we have the same paranoia for
  438. * the cleanup flag already.
  439. * Might better be handled using complete()?
  440. * (setting the flag and doing wakeup ought to be atomic
  441. * with regard to checking the flag as long as waitqueue is
  442. * part of the to be released structure)
  443. */
  444. wake_up(&req->completion_wq);
  445. }
  446. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  447. {
  448. struct fsf_qtcb_bottom_config *bottom;
  449. struct zfcp_adapter *adapter = req->adapter;
  450. struct Scsi_Host *shost = adapter->scsi_host;
  451. bottom = &req->qtcb->bottom.config;
  452. if (req->data)
  453. memcpy(req->data, bottom, sizeof(*bottom));
  454. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  455. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  456. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  457. fc_host_speed(shost) = bottom->fc_link_speed;
  458. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  459. adapter->hydra_version = bottom->adapter_type;
  460. adapter->timer_ticks = bottom->timer_interval;
  461. if (fc_host_permanent_port_name(shost) == -1)
  462. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  463. switch (bottom->fc_topology) {
  464. case FSF_TOPO_P2P:
  465. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  466. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  467. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  468. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  469. break;
  470. case FSF_TOPO_FABRIC:
  471. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  472. break;
  473. case FSF_TOPO_AL:
  474. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  475. default:
  476. dev_err(&adapter->ccw_device->dev,
  477. "Unknown or unsupported arbitrated loop "
  478. "fibre channel topology detected\n");
  479. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  480. return -EIO;
  481. }
  482. return 0;
  483. }
  484. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  485. {
  486. struct zfcp_adapter *adapter = req->adapter;
  487. struct fsf_qtcb *qtcb = req->qtcb;
  488. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  489. struct Scsi_Host *shost = adapter->scsi_host;
  490. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  491. return;
  492. adapter->fsf_lic_version = bottom->lic_version;
  493. adapter->adapter_features = bottom->adapter_features;
  494. adapter->connection_features = bottom->connection_features;
  495. adapter->peer_wwpn = 0;
  496. adapter->peer_wwnn = 0;
  497. adapter->peer_d_id = 0;
  498. switch (qtcb->header.fsf_status) {
  499. case FSF_GOOD:
  500. if (zfcp_fsf_exchange_config_evaluate(req))
  501. return;
  502. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  503. dev_err(&adapter->ccw_device->dev,
  504. "FCP adapter maximum QTCB size (%d bytes) "
  505. "is too small\n",
  506. bottom->max_qtcb_size);
  507. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  508. return;
  509. }
  510. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  511. &adapter->status);
  512. break;
  513. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  514. fc_host_node_name(shost) = 0;
  515. fc_host_port_name(shost) = 0;
  516. fc_host_port_id(shost) = 0;
  517. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  518. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  519. adapter->hydra_version = 0;
  520. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  521. &adapter->status);
  522. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  523. &qtcb->header.fsf_status_qual.link_down_info);
  524. break;
  525. default:
  526. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  527. return;
  528. }
  529. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  530. adapter->hardware_version = bottom->hardware_version;
  531. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  532. min(FC_SERIAL_NUMBER_SIZE, 17));
  533. EBCASC(fc_host_serial_number(shost),
  534. min(FC_SERIAL_NUMBER_SIZE, 17));
  535. }
  536. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  537. dev_err(&adapter->ccw_device->dev,
  538. "The FCP adapter only supports newer "
  539. "control block versions\n");
  540. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  541. return;
  542. }
  543. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  544. dev_err(&adapter->ccw_device->dev,
  545. "The FCP adapter only supports older "
  546. "control block versions\n");
  547. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  548. }
  549. }
  550. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  551. {
  552. struct zfcp_adapter *adapter = req->adapter;
  553. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  554. struct Scsi_Host *shost = adapter->scsi_host;
  555. if (req->data)
  556. memcpy(req->data, bottom, sizeof(*bottom));
  557. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  558. fc_host_permanent_port_name(shost) = bottom->wwpn;
  559. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  560. } else
  561. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  562. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  563. fc_host_supported_speeds(shost) = bottom->supported_speed;
  564. }
  565. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  566. {
  567. struct fsf_qtcb *qtcb = req->qtcb;
  568. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  569. return;
  570. switch (qtcb->header.fsf_status) {
  571. case FSF_GOOD:
  572. zfcp_fsf_exchange_port_evaluate(req);
  573. break;
  574. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  575. zfcp_fsf_exchange_port_evaluate(req);
  576. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  577. &qtcb->header.fsf_status_qual.link_down_info);
  578. break;
  579. }
  580. }
  581. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  582. __releases(&adapter->req_q_lock)
  583. __acquires(&adapter->req_q_lock)
  584. {
  585. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  586. long ret;
  587. if (atomic_read(&req_q->count) <= -REQUEST_LIST_SIZE)
  588. return -EIO;
  589. if (atomic_read(&req_q->count) > 0)
  590. return 0;
  591. atomic_dec(&req_q->count);
  592. spin_unlock_bh(&adapter->req_q_lock);
  593. ret = wait_event_interruptible_timeout(adapter->request_wq,
  594. atomic_read(&req_q->count) >= 0,
  595. 5 * HZ);
  596. spin_lock_bh(&adapter->req_q_lock);
  597. atomic_inc(&req_q->count);
  598. if (ret > 0)
  599. return 0;
  600. if (!ret)
  601. atomic_inc(&adapter->qdio_outb_full);
  602. return -EIO;
  603. }
  604. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  605. {
  606. struct zfcp_fsf_req *req;
  607. req = mempool_alloc(pool, GFP_ATOMIC);
  608. if (!req)
  609. return NULL;
  610. memset(req, 0, sizeof(*req));
  611. req->pool = pool;
  612. return req;
  613. }
  614. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  615. {
  616. struct zfcp_fsf_req_qtcb *qtcb;
  617. if (likely(pool))
  618. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  619. else
  620. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  621. GFP_ATOMIC);
  622. if (unlikely(!qtcb))
  623. return NULL;
  624. memset(qtcb, 0, sizeof(*qtcb));
  625. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  626. qtcb->fsf_req.pool = pool;
  627. return &qtcb->fsf_req;
  628. }
  629. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  630. u32 fsf_cmd, int req_flags,
  631. mempool_t *pool)
  632. {
  633. struct qdio_buffer_element *sbale;
  634. struct zfcp_fsf_req *req;
  635. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  636. if (req_flags & ZFCP_REQ_NO_QTCB)
  637. req = zfcp_fsf_alloc_noqtcb(pool);
  638. else
  639. req = zfcp_fsf_alloc_qtcb(pool);
  640. if (unlikely(!req))
  641. return ERR_PTR(-EIO);
  642. if (adapter->req_no == 0)
  643. adapter->req_no++;
  644. INIT_LIST_HEAD(&req->list);
  645. init_timer(&req->timer);
  646. init_waitqueue_head(&req->completion_wq);
  647. req->adapter = adapter;
  648. req->fsf_command = fsf_cmd;
  649. req->req_id = adapter->req_no;
  650. req->sbal_number = 1;
  651. req->sbal_first = req_q->first;
  652. req->sbal_last = req_q->first;
  653. req->sbale_curr = 1;
  654. sbale = zfcp_qdio_sbale_req(req);
  655. sbale[0].addr = (void *) req->req_id;
  656. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  657. if (likely(req->qtcb)) {
  658. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  659. req->qtcb->prefix.req_id = req->req_id;
  660. req->qtcb->prefix.ulp_info = 26;
  661. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  662. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  663. req->qtcb->header.req_handle = req->req_id;
  664. req->qtcb->header.fsf_command = req->fsf_command;
  665. req->seq_no = adapter->fsf_req_seq_no;
  666. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  667. sbale[1].addr = (void *) req->qtcb;
  668. sbale[1].length = sizeof(struct fsf_qtcb);
  669. }
  670. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  671. zfcp_fsf_req_free(req);
  672. return ERR_PTR(-EIO);
  673. }
  674. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  675. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  676. return req;
  677. }
  678. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  679. {
  680. struct zfcp_adapter *adapter = req->adapter;
  681. unsigned long flags;
  682. int idx;
  683. /* put allocated FSF request into hash table */
  684. spin_lock_irqsave(&adapter->req_list_lock, flags);
  685. idx = zfcp_reqlist_hash(req->req_id);
  686. list_add_tail(&req->list, &adapter->req_list[idx]);
  687. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  688. req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
  689. req->issued = get_clock();
  690. if (zfcp_qdio_send(req)) {
  691. del_timer(&req->timer);
  692. spin_lock_irqsave(&adapter->req_list_lock, flags);
  693. /* lookup request again, list might have changed */
  694. if (zfcp_reqlist_find_safe(adapter, req))
  695. zfcp_reqlist_remove(adapter, req);
  696. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  697. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  698. return -EIO;
  699. }
  700. /* Don't increase for unsolicited status */
  701. if (req->qtcb)
  702. adapter->fsf_req_seq_no++;
  703. adapter->req_no++;
  704. return 0;
  705. }
  706. /**
  707. * zfcp_fsf_status_read - send status read request
  708. * @adapter: pointer to struct zfcp_adapter
  709. * @req_flags: request flags
  710. * Returns: 0 on success, ERROR otherwise
  711. */
  712. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  713. {
  714. struct zfcp_fsf_req *req;
  715. struct fsf_status_read_buffer *sr_buf;
  716. struct qdio_buffer_element *sbale;
  717. int retval = -EIO;
  718. spin_lock_bh(&adapter->req_q_lock);
  719. if (zfcp_fsf_req_sbal_get(adapter))
  720. goto out;
  721. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  722. ZFCP_REQ_NO_QTCB,
  723. adapter->pool.fsf_req_status_read);
  724. if (IS_ERR(req)) {
  725. retval = PTR_ERR(req);
  726. goto out;
  727. }
  728. sbale = zfcp_qdio_sbale_req(req);
  729. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  730. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  731. req->sbale_curr = 2;
  732. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  733. if (!sr_buf) {
  734. retval = -ENOMEM;
  735. goto failed_buf;
  736. }
  737. memset(sr_buf, 0, sizeof(*sr_buf));
  738. req->data = sr_buf;
  739. sbale = zfcp_qdio_sbale_curr(req);
  740. sbale->addr = (void *) sr_buf;
  741. sbale->length = sizeof(*sr_buf);
  742. retval = zfcp_fsf_req_send(req);
  743. if (retval)
  744. goto failed_req_send;
  745. goto out;
  746. failed_req_send:
  747. mempool_free(sr_buf, adapter->pool.data_status_read);
  748. failed_buf:
  749. zfcp_fsf_req_free(req);
  750. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  751. out:
  752. spin_unlock_bh(&adapter->req_q_lock);
  753. return retval;
  754. }
  755. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  756. {
  757. struct zfcp_unit *unit = req->data;
  758. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  759. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  760. return;
  761. switch (req->qtcb->header.fsf_status) {
  762. case FSF_PORT_HANDLE_NOT_VALID:
  763. if (fsq->word[0] == fsq->word[1]) {
  764. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  765. "fsafch1", req);
  766. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  767. }
  768. break;
  769. case FSF_LUN_HANDLE_NOT_VALID:
  770. if (fsq->word[0] == fsq->word[1]) {
  771. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  772. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  773. }
  774. break;
  775. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  776. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  777. break;
  778. case FSF_PORT_BOXED:
  779. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  780. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  781. ZFCP_STATUS_FSFREQ_RETRY;
  782. break;
  783. case FSF_LUN_BOXED:
  784. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  785. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  786. ZFCP_STATUS_FSFREQ_RETRY;
  787. break;
  788. case FSF_ADAPTER_STATUS_AVAILABLE:
  789. switch (fsq->word[0]) {
  790. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  791. zfcp_test_link(unit->port);
  792. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  793. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  794. break;
  795. }
  796. break;
  797. case FSF_GOOD:
  798. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  799. break;
  800. }
  801. }
  802. /**
  803. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  804. * @old_req_id: unsigned long
  805. * @unit: pointer to struct zfcp_unit
  806. * Returns: pointer to struct zfcp_fsf_req
  807. */
  808. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  809. struct zfcp_unit *unit)
  810. {
  811. struct qdio_buffer_element *sbale;
  812. struct zfcp_fsf_req *req = NULL;
  813. struct zfcp_adapter *adapter = unit->port->adapter;
  814. spin_lock_bh(&adapter->req_q_lock);
  815. if (zfcp_fsf_req_sbal_get(adapter))
  816. goto out;
  817. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  818. 0, adapter->pool.fsf_req_abort);
  819. if (IS_ERR(req)) {
  820. req = NULL;
  821. goto out;
  822. }
  823. if (unlikely(!(atomic_read(&unit->status) &
  824. ZFCP_STATUS_COMMON_UNBLOCKED)))
  825. goto out_error_free;
  826. sbale = zfcp_qdio_sbale_req(req);
  827. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  828. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  829. req->data = unit;
  830. req->handler = zfcp_fsf_abort_fcp_command_handler;
  831. req->qtcb->header.lun_handle = unit->handle;
  832. req->qtcb->header.port_handle = unit->port->handle;
  833. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  834. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  835. if (!zfcp_fsf_req_send(req))
  836. goto out;
  837. out_error_free:
  838. zfcp_fsf_req_free(req);
  839. req = NULL;
  840. out:
  841. spin_unlock_bh(&adapter->req_q_lock);
  842. return req;
  843. }
  844. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  845. {
  846. struct zfcp_adapter *adapter = req->adapter;
  847. struct zfcp_send_ct *send_ct = req->data;
  848. struct fsf_qtcb_header *header = &req->qtcb->header;
  849. send_ct->status = -EINVAL;
  850. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  851. goto skip_fsfstatus;
  852. switch (header->fsf_status) {
  853. case FSF_GOOD:
  854. zfcp_san_dbf_event_ct_response(req);
  855. send_ct->status = 0;
  856. break;
  857. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  858. zfcp_fsf_class_not_supp(req);
  859. break;
  860. case FSF_ADAPTER_STATUS_AVAILABLE:
  861. switch (header->fsf_status_qual.word[0]){
  862. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  863. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  864. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  865. break;
  866. }
  867. break;
  868. case FSF_ACCESS_DENIED:
  869. break;
  870. case FSF_PORT_BOXED:
  871. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  872. ZFCP_STATUS_FSFREQ_RETRY;
  873. break;
  874. case FSF_PORT_HANDLE_NOT_VALID:
  875. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  876. case FSF_GENERIC_COMMAND_REJECTED:
  877. case FSF_PAYLOAD_SIZE_MISMATCH:
  878. case FSF_REQUEST_SIZE_TOO_LARGE:
  879. case FSF_RESPONSE_SIZE_TOO_LARGE:
  880. case FSF_SBAL_MISMATCH:
  881. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  882. break;
  883. }
  884. skip_fsfstatus:
  885. if (send_ct->handler)
  886. send_ct->handler(send_ct->handler_data);
  887. }
  888. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  889. struct scatterlist *sg_req,
  890. struct scatterlist *sg_resp,
  891. int max_sbals)
  892. {
  893. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
  894. u32 feat = req->adapter->adapter_features;
  895. int bytes;
  896. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  897. if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
  898. !sg_is_last(sg_req) || !sg_is_last(sg_resp))
  899. return -EOPNOTSUPP;
  900. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  901. sbale[2].addr = sg_virt(sg_req);
  902. sbale[2].length = sg_req->length;
  903. sbale[3].addr = sg_virt(sg_resp);
  904. sbale[3].length = sg_resp->length;
  905. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  906. return 0;
  907. }
  908. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  909. sg_req, max_sbals);
  910. if (bytes <= 0)
  911. return -ENOMEM;
  912. req->qtcb->bottom.support.req_buf_length = bytes;
  913. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  914. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  915. sg_resp, max_sbals);
  916. if (bytes <= 0)
  917. return -ENOMEM;
  918. req->qtcb->bottom.support.resp_buf_length = bytes;
  919. return 0;
  920. }
  921. /**
  922. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  923. * @ct: pointer to struct zfcp_send_ct with data for request
  924. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  925. * @erp_action: if non-null the Generic Service request sent within ERP
  926. */
  927. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  928. struct zfcp_erp_action *erp_action)
  929. {
  930. struct zfcp_wka_port *wka_port = ct->wka_port;
  931. struct zfcp_adapter *adapter = wka_port->adapter;
  932. struct zfcp_fsf_req *req;
  933. int ret = -EIO;
  934. spin_lock_bh(&adapter->req_q_lock);
  935. if (zfcp_fsf_req_sbal_get(adapter))
  936. goto out;
  937. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  938. ZFCP_REQ_AUTO_CLEANUP, pool);
  939. if (IS_ERR(req)) {
  940. ret = PTR_ERR(req);
  941. goto out;
  942. }
  943. ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
  944. FSF_MAX_SBALS_PER_REQ);
  945. if (ret)
  946. goto failed_send;
  947. req->handler = zfcp_fsf_send_ct_handler;
  948. req->qtcb->header.port_handle = wka_port->handle;
  949. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  950. req->qtcb->bottom.support.timeout = ct->timeout;
  951. req->data = ct;
  952. zfcp_san_dbf_event_ct_request(req);
  953. if (erp_action) {
  954. erp_action->fsf_req = req;
  955. req->erp_action = erp_action;
  956. zfcp_fsf_start_erp_timer(req);
  957. } else
  958. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  959. ret = zfcp_fsf_req_send(req);
  960. if (ret)
  961. goto failed_send;
  962. goto out;
  963. failed_send:
  964. zfcp_fsf_req_free(req);
  965. if (erp_action)
  966. erp_action->fsf_req = NULL;
  967. out:
  968. spin_unlock_bh(&adapter->req_q_lock);
  969. return ret;
  970. }
  971. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  972. {
  973. struct zfcp_send_els *send_els = req->data;
  974. struct zfcp_port *port = send_els->port;
  975. struct fsf_qtcb_header *header = &req->qtcb->header;
  976. send_els->status = -EINVAL;
  977. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  978. goto skip_fsfstatus;
  979. switch (header->fsf_status) {
  980. case FSF_GOOD:
  981. zfcp_san_dbf_event_els_response(req);
  982. send_els->status = 0;
  983. break;
  984. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  985. zfcp_fsf_class_not_supp(req);
  986. break;
  987. case FSF_ADAPTER_STATUS_AVAILABLE:
  988. switch (header->fsf_status_qual.word[0]){
  989. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  990. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  991. zfcp_test_link(port);
  992. /*fall through */
  993. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  994. case FSF_SQ_RETRY_IF_POSSIBLE:
  995. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  996. break;
  997. }
  998. break;
  999. case FSF_ELS_COMMAND_REJECTED:
  1000. case FSF_PAYLOAD_SIZE_MISMATCH:
  1001. case FSF_REQUEST_SIZE_TOO_LARGE:
  1002. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1003. break;
  1004. case FSF_ACCESS_DENIED:
  1005. zfcp_fsf_access_denied_port(req, port);
  1006. break;
  1007. case FSF_SBAL_MISMATCH:
  1008. /* should never occure, avoided in zfcp_fsf_send_els */
  1009. /* fall through */
  1010. default:
  1011. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1012. break;
  1013. }
  1014. skip_fsfstatus:
  1015. if (send_els->handler)
  1016. send_els->handler(send_els->handler_data);
  1017. }
  1018. /**
  1019. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1020. * @els: pointer to struct zfcp_send_els with data for the command
  1021. */
  1022. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1023. {
  1024. struct zfcp_fsf_req *req;
  1025. struct zfcp_adapter *adapter = els->adapter;
  1026. struct fsf_qtcb_bottom_support *bottom;
  1027. int ret = -EIO;
  1028. spin_lock_bh(&adapter->req_q_lock);
  1029. if (zfcp_fsf_req_sbal_get(adapter))
  1030. goto out;
  1031. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1032. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1033. if (IS_ERR(req)) {
  1034. ret = PTR_ERR(req);
  1035. goto out;
  1036. }
  1037. ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
  1038. if (ret)
  1039. goto failed_send;
  1040. bottom = &req->qtcb->bottom.support;
  1041. req->handler = zfcp_fsf_send_els_handler;
  1042. bottom->d_id = els->d_id;
  1043. bottom->service_class = FSF_CLASS_3;
  1044. bottom->timeout = 2 * R_A_TOV;
  1045. req->data = els;
  1046. zfcp_san_dbf_event_els_request(req);
  1047. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1048. ret = zfcp_fsf_req_send(req);
  1049. if (ret)
  1050. goto failed_send;
  1051. goto out;
  1052. failed_send:
  1053. zfcp_fsf_req_free(req);
  1054. out:
  1055. spin_unlock_bh(&adapter->req_q_lock);
  1056. return ret;
  1057. }
  1058. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1059. {
  1060. struct qdio_buffer_element *sbale;
  1061. struct zfcp_fsf_req *req;
  1062. struct zfcp_adapter *adapter = erp_action->adapter;
  1063. int retval = -EIO;
  1064. spin_lock_bh(&adapter->req_q_lock);
  1065. if (zfcp_fsf_req_sbal_get(adapter))
  1066. goto out;
  1067. req = zfcp_fsf_req_create(adapter,
  1068. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1069. ZFCP_REQ_AUTO_CLEANUP,
  1070. adapter->pool.fsf_req_erp);
  1071. if (IS_ERR(req)) {
  1072. retval = PTR_ERR(req);
  1073. goto out;
  1074. }
  1075. sbale = zfcp_qdio_sbale_req(req);
  1076. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1077. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1078. req->qtcb->bottom.config.feature_selection =
  1079. FSF_FEATURE_CFDC |
  1080. FSF_FEATURE_LUN_SHARING |
  1081. FSF_FEATURE_NOTIFICATION_LOST |
  1082. FSF_FEATURE_UPDATE_ALERT;
  1083. req->erp_action = erp_action;
  1084. req->handler = zfcp_fsf_exchange_config_data_handler;
  1085. erp_action->fsf_req = req;
  1086. zfcp_fsf_start_erp_timer(req);
  1087. retval = zfcp_fsf_req_send(req);
  1088. if (retval) {
  1089. zfcp_fsf_req_free(req);
  1090. erp_action->fsf_req = NULL;
  1091. }
  1092. out:
  1093. spin_unlock_bh(&adapter->req_q_lock);
  1094. return retval;
  1095. }
  1096. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1097. struct fsf_qtcb_bottom_config *data)
  1098. {
  1099. struct qdio_buffer_element *sbale;
  1100. struct zfcp_fsf_req *req = NULL;
  1101. int retval = -EIO;
  1102. spin_lock_bh(&adapter->req_q_lock);
  1103. if (zfcp_fsf_req_sbal_get(adapter))
  1104. goto out;
  1105. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1106. 0, NULL);
  1107. if (IS_ERR(req)) {
  1108. retval = PTR_ERR(req);
  1109. goto out;
  1110. }
  1111. sbale = zfcp_qdio_sbale_req(req);
  1112. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1113. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1114. req->handler = zfcp_fsf_exchange_config_data_handler;
  1115. req->qtcb->bottom.config.feature_selection =
  1116. FSF_FEATURE_CFDC |
  1117. FSF_FEATURE_LUN_SHARING |
  1118. FSF_FEATURE_NOTIFICATION_LOST |
  1119. FSF_FEATURE_UPDATE_ALERT;
  1120. if (data)
  1121. req->data = data;
  1122. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1123. retval = zfcp_fsf_req_send(req);
  1124. out:
  1125. spin_unlock_bh(&adapter->req_q_lock);
  1126. if (!retval)
  1127. wait_event(req->completion_wq,
  1128. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1129. zfcp_fsf_req_free(req);
  1130. return retval;
  1131. }
  1132. /**
  1133. * zfcp_fsf_exchange_port_data - request information about local port
  1134. * @erp_action: ERP action for the adapter for which port data is requested
  1135. * Returns: 0 on success, error otherwise
  1136. */
  1137. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1138. {
  1139. struct qdio_buffer_element *sbale;
  1140. struct zfcp_fsf_req *req;
  1141. struct zfcp_adapter *adapter = erp_action->adapter;
  1142. int retval = -EIO;
  1143. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1144. return -EOPNOTSUPP;
  1145. spin_lock_bh(&adapter->req_q_lock);
  1146. if (zfcp_fsf_req_sbal_get(adapter))
  1147. goto out;
  1148. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1149. ZFCP_REQ_AUTO_CLEANUP,
  1150. adapter->pool.fsf_req_erp);
  1151. if (IS_ERR(req)) {
  1152. retval = PTR_ERR(req);
  1153. goto out;
  1154. }
  1155. sbale = zfcp_qdio_sbale_req(req);
  1156. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1157. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1158. req->handler = zfcp_fsf_exchange_port_data_handler;
  1159. req->erp_action = erp_action;
  1160. erp_action->fsf_req = req;
  1161. zfcp_fsf_start_erp_timer(req);
  1162. retval = zfcp_fsf_req_send(req);
  1163. if (retval) {
  1164. zfcp_fsf_req_free(req);
  1165. erp_action->fsf_req = NULL;
  1166. }
  1167. out:
  1168. spin_unlock_bh(&adapter->req_q_lock);
  1169. return retval;
  1170. }
  1171. /**
  1172. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1173. * @adapter: pointer to struct zfcp_adapter
  1174. * @data: pointer to struct fsf_qtcb_bottom_port
  1175. * Returns: 0 on success, error otherwise
  1176. */
  1177. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1178. struct fsf_qtcb_bottom_port *data)
  1179. {
  1180. struct qdio_buffer_element *sbale;
  1181. struct zfcp_fsf_req *req = NULL;
  1182. int retval = -EIO;
  1183. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1184. return -EOPNOTSUPP;
  1185. spin_lock_bh(&adapter->req_q_lock);
  1186. if (zfcp_fsf_req_sbal_get(adapter))
  1187. goto out;
  1188. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1189. NULL);
  1190. if (IS_ERR(req)) {
  1191. retval = PTR_ERR(req);
  1192. goto out;
  1193. }
  1194. if (data)
  1195. req->data = data;
  1196. sbale = zfcp_qdio_sbale_req(req);
  1197. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1198. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1199. req->handler = zfcp_fsf_exchange_port_data_handler;
  1200. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1201. retval = zfcp_fsf_req_send(req);
  1202. out:
  1203. spin_unlock_bh(&adapter->req_q_lock);
  1204. if (!retval)
  1205. wait_event(req->completion_wq,
  1206. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1207. zfcp_fsf_req_free(req);
  1208. return retval;
  1209. }
  1210. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1211. {
  1212. struct zfcp_port *port = req->data;
  1213. struct fsf_qtcb_header *header = &req->qtcb->header;
  1214. struct fsf_plogi *plogi;
  1215. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1216. return;
  1217. switch (header->fsf_status) {
  1218. case FSF_PORT_ALREADY_OPEN:
  1219. break;
  1220. case FSF_ACCESS_DENIED:
  1221. zfcp_fsf_access_denied_port(req, port);
  1222. break;
  1223. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1224. dev_warn(&req->adapter->ccw_device->dev,
  1225. "Not enough FCP adapter resources to open "
  1226. "remote port 0x%016Lx\n",
  1227. (unsigned long long)port->wwpn);
  1228. zfcp_erp_port_failed(port, "fsoph_1", req);
  1229. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1230. break;
  1231. case FSF_ADAPTER_STATUS_AVAILABLE:
  1232. switch (header->fsf_status_qual.word[0]) {
  1233. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1234. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1235. case FSF_SQ_NO_RETRY_POSSIBLE:
  1236. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1237. break;
  1238. }
  1239. break;
  1240. case FSF_GOOD:
  1241. port->handle = header->port_handle;
  1242. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1243. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1244. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1245. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1246. &port->status);
  1247. /* check whether D_ID has changed during open */
  1248. /*
  1249. * FIXME: This check is not airtight, as the FCP channel does
  1250. * not monitor closures of target port connections caused on
  1251. * the remote side. Thus, they might miss out on invalidating
  1252. * locally cached WWPNs (and other N_Port parameters) of gone
  1253. * target ports. So, our heroic attempt to make things safe
  1254. * could be undermined by 'open port' response data tagged with
  1255. * obsolete WWPNs. Another reason to monitor potential
  1256. * connection closures ourself at least (by interpreting
  1257. * incoming ELS' and unsolicited status). It just crosses my
  1258. * mind that one should be able to cross-check by means of
  1259. * another GID_PN straight after a port has been opened.
  1260. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1261. */
  1262. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1263. if (req->qtcb->bottom.support.els1_length >=
  1264. FSF_PLOGI_MIN_LEN) {
  1265. if (plogi->serv_param.wwpn != port->wwpn)
  1266. port->d_id = 0;
  1267. else {
  1268. port->wwnn = plogi->serv_param.wwnn;
  1269. zfcp_fc_plogi_evaluate(port, plogi);
  1270. }
  1271. }
  1272. break;
  1273. case FSF_UNKNOWN_OP_SUBTYPE:
  1274. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1275. break;
  1276. }
  1277. }
  1278. /**
  1279. * zfcp_fsf_open_port - create and send open port request
  1280. * @erp_action: pointer to struct zfcp_erp_action
  1281. * Returns: 0 on success, error otherwise
  1282. */
  1283. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1284. {
  1285. struct qdio_buffer_element *sbale;
  1286. struct zfcp_adapter *adapter = erp_action->adapter;
  1287. struct zfcp_fsf_req *req;
  1288. int retval = -EIO;
  1289. spin_lock_bh(&adapter->req_q_lock);
  1290. if (zfcp_fsf_req_sbal_get(adapter))
  1291. goto out;
  1292. req = zfcp_fsf_req_create(adapter,
  1293. FSF_QTCB_OPEN_PORT_WITH_DID,
  1294. ZFCP_REQ_AUTO_CLEANUP,
  1295. adapter->pool.fsf_req_erp);
  1296. if (IS_ERR(req)) {
  1297. retval = PTR_ERR(req);
  1298. goto out;
  1299. }
  1300. sbale = zfcp_qdio_sbale_req(req);
  1301. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1302. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1303. req->handler = zfcp_fsf_open_port_handler;
  1304. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1305. req->data = erp_action->port;
  1306. req->erp_action = erp_action;
  1307. erp_action->fsf_req = req;
  1308. zfcp_fsf_start_erp_timer(req);
  1309. retval = zfcp_fsf_req_send(req);
  1310. if (retval) {
  1311. zfcp_fsf_req_free(req);
  1312. erp_action->fsf_req = NULL;
  1313. }
  1314. out:
  1315. spin_unlock_bh(&adapter->req_q_lock);
  1316. return retval;
  1317. }
  1318. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1319. {
  1320. struct zfcp_port *port = req->data;
  1321. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1322. return;
  1323. switch (req->qtcb->header.fsf_status) {
  1324. case FSF_PORT_HANDLE_NOT_VALID:
  1325. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1326. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1327. break;
  1328. case FSF_ADAPTER_STATUS_AVAILABLE:
  1329. break;
  1330. case FSF_GOOD:
  1331. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1332. ZFCP_STATUS_COMMON_OPEN,
  1333. ZFCP_CLEAR);
  1334. break;
  1335. }
  1336. }
  1337. /**
  1338. * zfcp_fsf_close_port - create and send close port request
  1339. * @erp_action: pointer to struct zfcp_erp_action
  1340. * Returns: 0 on success, error otherwise
  1341. */
  1342. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1343. {
  1344. struct qdio_buffer_element *sbale;
  1345. struct zfcp_adapter *adapter = erp_action->adapter;
  1346. struct zfcp_fsf_req *req;
  1347. int retval = -EIO;
  1348. spin_lock_bh(&adapter->req_q_lock);
  1349. if (zfcp_fsf_req_sbal_get(adapter))
  1350. goto out;
  1351. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1352. ZFCP_REQ_AUTO_CLEANUP,
  1353. adapter->pool.fsf_req_erp);
  1354. if (IS_ERR(req)) {
  1355. retval = PTR_ERR(req);
  1356. goto out;
  1357. }
  1358. sbale = zfcp_qdio_sbale_req(req);
  1359. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1360. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1361. req->handler = zfcp_fsf_close_port_handler;
  1362. req->data = erp_action->port;
  1363. req->erp_action = erp_action;
  1364. req->qtcb->header.port_handle = erp_action->port->handle;
  1365. erp_action->fsf_req = req;
  1366. zfcp_fsf_start_erp_timer(req);
  1367. retval = zfcp_fsf_req_send(req);
  1368. if (retval) {
  1369. zfcp_fsf_req_free(req);
  1370. erp_action->fsf_req = NULL;
  1371. }
  1372. out:
  1373. spin_unlock_bh(&adapter->req_q_lock);
  1374. return retval;
  1375. }
  1376. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1377. {
  1378. struct zfcp_wka_port *wka_port = req->data;
  1379. struct fsf_qtcb_header *header = &req->qtcb->header;
  1380. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1381. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1382. goto out;
  1383. }
  1384. switch (header->fsf_status) {
  1385. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1386. dev_warn(&req->adapter->ccw_device->dev,
  1387. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1388. case FSF_ADAPTER_STATUS_AVAILABLE:
  1389. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1390. case FSF_ACCESS_DENIED:
  1391. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1392. break;
  1393. case FSF_PORT_ALREADY_OPEN:
  1394. break;
  1395. case FSF_GOOD:
  1396. wka_port->handle = header->port_handle;
  1397. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1398. }
  1399. out:
  1400. wake_up(&wka_port->completion_wq);
  1401. }
  1402. /**
  1403. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1404. * @wka_port: pointer to struct zfcp_wka_port
  1405. * Returns: 0 on success, error otherwise
  1406. */
  1407. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1408. {
  1409. struct qdio_buffer_element *sbale;
  1410. struct zfcp_adapter *adapter = wka_port->adapter;
  1411. struct zfcp_fsf_req *req;
  1412. int retval = -EIO;
  1413. spin_lock_bh(&adapter->req_q_lock);
  1414. if (zfcp_fsf_req_sbal_get(adapter))
  1415. goto out;
  1416. req = zfcp_fsf_req_create(adapter,
  1417. FSF_QTCB_OPEN_PORT_WITH_DID,
  1418. ZFCP_REQ_AUTO_CLEANUP,
  1419. adapter->pool.fsf_req_erp);
  1420. if (unlikely(IS_ERR(req))) {
  1421. retval = PTR_ERR(req);
  1422. goto out;
  1423. }
  1424. sbale = zfcp_qdio_sbale_req(req);
  1425. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1426. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1427. req->handler = zfcp_fsf_open_wka_port_handler;
  1428. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1429. req->data = wka_port;
  1430. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1431. retval = zfcp_fsf_req_send(req);
  1432. if (retval)
  1433. zfcp_fsf_req_free(req);
  1434. out:
  1435. spin_unlock_bh(&adapter->req_q_lock);
  1436. return retval;
  1437. }
  1438. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1439. {
  1440. struct zfcp_wka_port *wka_port = req->data;
  1441. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1442. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1443. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1444. }
  1445. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1446. wake_up(&wka_port->completion_wq);
  1447. }
  1448. /**
  1449. * zfcp_fsf_close_wka_port - create and send close wka port request
  1450. * @erp_action: pointer to struct zfcp_erp_action
  1451. * Returns: 0 on success, error otherwise
  1452. */
  1453. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1454. {
  1455. struct qdio_buffer_element *sbale;
  1456. struct zfcp_adapter *adapter = wka_port->adapter;
  1457. struct zfcp_fsf_req *req;
  1458. int retval = -EIO;
  1459. spin_lock_bh(&adapter->req_q_lock);
  1460. if (zfcp_fsf_req_sbal_get(adapter))
  1461. goto out;
  1462. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1463. ZFCP_REQ_AUTO_CLEANUP,
  1464. adapter->pool.fsf_req_erp);
  1465. if (unlikely(IS_ERR(req))) {
  1466. retval = PTR_ERR(req);
  1467. goto out;
  1468. }
  1469. sbale = zfcp_qdio_sbale_req(req);
  1470. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1471. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1472. req->handler = zfcp_fsf_close_wka_port_handler;
  1473. req->data = wka_port;
  1474. req->qtcb->header.port_handle = wka_port->handle;
  1475. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1476. retval = zfcp_fsf_req_send(req);
  1477. if (retval)
  1478. zfcp_fsf_req_free(req);
  1479. out:
  1480. spin_unlock_bh(&adapter->req_q_lock);
  1481. return retval;
  1482. }
  1483. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1484. {
  1485. struct zfcp_port *port = req->data;
  1486. struct fsf_qtcb_header *header = &req->qtcb->header;
  1487. struct zfcp_unit *unit;
  1488. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1489. return;
  1490. switch (header->fsf_status) {
  1491. case FSF_PORT_HANDLE_NOT_VALID:
  1492. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1493. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1494. break;
  1495. case FSF_ACCESS_DENIED:
  1496. zfcp_fsf_access_denied_port(req, port);
  1497. break;
  1498. case FSF_PORT_BOXED:
  1499. zfcp_erp_port_boxed(port, "fscpph2", req);
  1500. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1501. ZFCP_STATUS_FSFREQ_RETRY;
  1502. /* can't use generic zfcp_erp_modify_port_status because
  1503. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1504. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1505. list_for_each_entry(unit, &port->unit_list_head, list)
  1506. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1507. &unit->status);
  1508. break;
  1509. case FSF_ADAPTER_STATUS_AVAILABLE:
  1510. switch (header->fsf_status_qual.word[0]) {
  1511. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1512. /* fall through */
  1513. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1514. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1515. break;
  1516. }
  1517. break;
  1518. case FSF_GOOD:
  1519. /* can't use generic zfcp_erp_modify_port_status because
  1520. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1521. */
  1522. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1523. list_for_each_entry(unit, &port->unit_list_head, list)
  1524. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1525. &unit->status);
  1526. break;
  1527. }
  1528. }
  1529. /**
  1530. * zfcp_fsf_close_physical_port - close physical port
  1531. * @erp_action: pointer to struct zfcp_erp_action
  1532. * Returns: 0 on success
  1533. */
  1534. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1535. {
  1536. struct qdio_buffer_element *sbale;
  1537. struct zfcp_adapter *adapter = erp_action->adapter;
  1538. struct zfcp_fsf_req *req;
  1539. int retval = -EIO;
  1540. spin_lock_bh(&adapter->req_q_lock);
  1541. if (zfcp_fsf_req_sbal_get(adapter))
  1542. goto out;
  1543. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1544. ZFCP_REQ_AUTO_CLEANUP,
  1545. adapter->pool.fsf_req_erp);
  1546. if (IS_ERR(req)) {
  1547. retval = PTR_ERR(req);
  1548. goto out;
  1549. }
  1550. sbale = zfcp_qdio_sbale_req(req);
  1551. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1552. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1553. req->data = erp_action->port;
  1554. req->qtcb->header.port_handle = erp_action->port->handle;
  1555. req->erp_action = erp_action;
  1556. req->handler = zfcp_fsf_close_physical_port_handler;
  1557. erp_action->fsf_req = req;
  1558. zfcp_fsf_start_erp_timer(req);
  1559. retval = zfcp_fsf_req_send(req);
  1560. if (retval) {
  1561. zfcp_fsf_req_free(req);
  1562. erp_action->fsf_req = NULL;
  1563. }
  1564. out:
  1565. spin_unlock_bh(&adapter->req_q_lock);
  1566. return retval;
  1567. }
  1568. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1569. {
  1570. struct zfcp_adapter *adapter = req->adapter;
  1571. struct zfcp_unit *unit = req->data;
  1572. struct fsf_qtcb_header *header = &req->qtcb->header;
  1573. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1574. struct fsf_queue_designator *queue_designator =
  1575. &header->fsf_status_qual.fsf_queue_designator;
  1576. int exclusive, readwrite;
  1577. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1578. return;
  1579. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1580. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1581. ZFCP_STATUS_UNIT_SHARED |
  1582. ZFCP_STATUS_UNIT_READONLY,
  1583. &unit->status);
  1584. switch (header->fsf_status) {
  1585. case FSF_PORT_HANDLE_NOT_VALID:
  1586. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1587. /* fall through */
  1588. case FSF_LUN_ALREADY_OPEN:
  1589. break;
  1590. case FSF_ACCESS_DENIED:
  1591. zfcp_fsf_access_denied_unit(req, unit);
  1592. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1593. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1594. break;
  1595. case FSF_PORT_BOXED:
  1596. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1597. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1598. ZFCP_STATUS_FSFREQ_RETRY;
  1599. break;
  1600. case FSF_LUN_SHARING_VIOLATION:
  1601. if (header->fsf_status_qual.word[0])
  1602. dev_warn(&adapter->ccw_device->dev,
  1603. "LUN 0x%Lx on port 0x%Lx is already in "
  1604. "use by CSS%d, MIF Image ID %x\n",
  1605. (unsigned long long)unit->fcp_lun,
  1606. (unsigned long long)unit->port->wwpn,
  1607. queue_designator->cssid,
  1608. queue_designator->hla);
  1609. else
  1610. zfcp_act_eval_err(adapter,
  1611. header->fsf_status_qual.word[2]);
  1612. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1613. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1614. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1615. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1616. break;
  1617. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1618. dev_warn(&adapter->ccw_device->dev,
  1619. "No handle is available for LUN "
  1620. "0x%016Lx on port 0x%016Lx\n",
  1621. (unsigned long long)unit->fcp_lun,
  1622. (unsigned long long)unit->port->wwpn);
  1623. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1624. /* fall through */
  1625. case FSF_INVALID_COMMAND_OPTION:
  1626. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1627. break;
  1628. case FSF_ADAPTER_STATUS_AVAILABLE:
  1629. switch (header->fsf_status_qual.word[0]) {
  1630. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1631. zfcp_test_link(unit->port);
  1632. /* fall through */
  1633. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1634. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1635. break;
  1636. }
  1637. break;
  1638. case FSF_GOOD:
  1639. unit->handle = header->lun_handle;
  1640. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1641. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1642. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1643. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1644. exclusive = (bottom->lun_access_info &
  1645. FSF_UNIT_ACCESS_EXCLUSIVE);
  1646. readwrite = (bottom->lun_access_info &
  1647. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1648. if (!exclusive)
  1649. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1650. &unit->status);
  1651. if (!readwrite) {
  1652. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1653. &unit->status);
  1654. dev_info(&adapter->ccw_device->dev,
  1655. "SCSI device at LUN 0x%016Lx on port "
  1656. "0x%016Lx opened read-only\n",
  1657. (unsigned long long)unit->fcp_lun,
  1658. (unsigned long long)unit->port->wwpn);
  1659. }
  1660. if (exclusive && !readwrite) {
  1661. dev_err(&adapter->ccw_device->dev,
  1662. "Exclusive read-only access not "
  1663. "supported (unit 0x%016Lx, "
  1664. "port 0x%016Lx)\n",
  1665. (unsigned long long)unit->fcp_lun,
  1666. (unsigned long long)unit->port->wwpn);
  1667. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1668. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1669. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1670. } else if (!exclusive && readwrite) {
  1671. dev_err(&adapter->ccw_device->dev,
  1672. "Shared read-write access not "
  1673. "supported (unit 0x%016Lx, port "
  1674. "0x%016Lx)\n",
  1675. (unsigned long long)unit->fcp_lun,
  1676. (unsigned long long)unit->port->wwpn);
  1677. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1678. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1679. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1680. }
  1681. }
  1682. break;
  1683. }
  1684. }
  1685. /**
  1686. * zfcp_fsf_open_unit - open unit
  1687. * @erp_action: pointer to struct zfcp_erp_action
  1688. * Returns: 0 on success, error otherwise
  1689. */
  1690. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1691. {
  1692. struct qdio_buffer_element *sbale;
  1693. struct zfcp_adapter *adapter = erp_action->adapter;
  1694. struct zfcp_fsf_req *req;
  1695. int retval = -EIO;
  1696. spin_lock_bh(&adapter->req_q_lock);
  1697. if (zfcp_fsf_req_sbal_get(adapter))
  1698. goto out;
  1699. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1700. ZFCP_REQ_AUTO_CLEANUP,
  1701. adapter->pool.fsf_req_erp);
  1702. if (IS_ERR(req)) {
  1703. retval = PTR_ERR(req);
  1704. goto out;
  1705. }
  1706. sbale = zfcp_qdio_sbale_req(req);
  1707. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1708. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1709. req->qtcb->header.port_handle = erp_action->port->handle;
  1710. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1711. req->handler = zfcp_fsf_open_unit_handler;
  1712. req->data = erp_action->unit;
  1713. req->erp_action = erp_action;
  1714. erp_action->fsf_req = req;
  1715. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1716. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1717. zfcp_fsf_start_erp_timer(req);
  1718. retval = zfcp_fsf_req_send(req);
  1719. if (retval) {
  1720. zfcp_fsf_req_free(req);
  1721. erp_action->fsf_req = NULL;
  1722. }
  1723. out:
  1724. spin_unlock_bh(&adapter->req_q_lock);
  1725. return retval;
  1726. }
  1727. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1728. {
  1729. struct zfcp_unit *unit = req->data;
  1730. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1731. return;
  1732. switch (req->qtcb->header.fsf_status) {
  1733. case FSF_PORT_HANDLE_NOT_VALID:
  1734. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1735. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1736. break;
  1737. case FSF_LUN_HANDLE_NOT_VALID:
  1738. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1739. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1740. break;
  1741. case FSF_PORT_BOXED:
  1742. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1743. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1744. ZFCP_STATUS_FSFREQ_RETRY;
  1745. break;
  1746. case FSF_ADAPTER_STATUS_AVAILABLE:
  1747. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1748. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1749. zfcp_test_link(unit->port);
  1750. /* fall through */
  1751. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1752. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1753. break;
  1754. }
  1755. break;
  1756. case FSF_GOOD:
  1757. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1758. break;
  1759. }
  1760. }
  1761. /**
  1762. * zfcp_fsf_close_unit - close zfcp unit
  1763. * @erp_action: pointer to struct zfcp_unit
  1764. * Returns: 0 on success, error otherwise
  1765. */
  1766. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1767. {
  1768. struct qdio_buffer_element *sbale;
  1769. struct zfcp_adapter *adapter = erp_action->adapter;
  1770. struct zfcp_fsf_req *req;
  1771. int retval = -EIO;
  1772. spin_lock_bh(&adapter->req_q_lock);
  1773. if (zfcp_fsf_req_sbal_get(adapter))
  1774. goto out;
  1775. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1776. ZFCP_REQ_AUTO_CLEANUP,
  1777. adapter->pool.fsf_req_erp);
  1778. if (IS_ERR(req)) {
  1779. retval = PTR_ERR(req);
  1780. goto out;
  1781. }
  1782. sbale = zfcp_qdio_sbale_req(req);
  1783. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1784. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1785. req->qtcb->header.port_handle = erp_action->port->handle;
  1786. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1787. req->handler = zfcp_fsf_close_unit_handler;
  1788. req->data = erp_action->unit;
  1789. req->erp_action = erp_action;
  1790. erp_action->fsf_req = req;
  1791. zfcp_fsf_start_erp_timer(req);
  1792. retval = zfcp_fsf_req_send(req);
  1793. if (retval) {
  1794. zfcp_fsf_req_free(req);
  1795. erp_action->fsf_req = NULL;
  1796. }
  1797. out:
  1798. spin_unlock_bh(&adapter->req_q_lock);
  1799. return retval;
  1800. }
  1801. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1802. {
  1803. lat_rec->sum += lat;
  1804. lat_rec->min = min(lat_rec->min, lat);
  1805. lat_rec->max = max(lat_rec->max, lat);
  1806. }
  1807. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1808. {
  1809. struct fsf_qual_latency_info *lat_inf;
  1810. struct latency_cont *lat;
  1811. struct zfcp_unit *unit = req->unit;
  1812. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1813. switch (req->qtcb->bottom.io.data_direction) {
  1814. case FSF_DATADIR_READ:
  1815. lat = &unit->latencies.read;
  1816. break;
  1817. case FSF_DATADIR_WRITE:
  1818. lat = &unit->latencies.write;
  1819. break;
  1820. case FSF_DATADIR_CMND:
  1821. lat = &unit->latencies.cmd;
  1822. break;
  1823. default:
  1824. return;
  1825. }
  1826. spin_lock(&unit->latencies.lock);
  1827. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1828. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1829. lat->counter++;
  1830. spin_unlock(&unit->latencies.lock);
  1831. }
  1832. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1833. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1834. {
  1835. struct fsf_qual_latency_info *lat_inf;
  1836. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1837. struct request *req = scsi_cmnd->request;
  1838. struct zfcp_blk_drv_data trace;
  1839. int ticks = fsf_req->adapter->timer_ticks;
  1840. trace.flags = 0;
  1841. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1842. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1843. trace.flags |= ZFCP_BLK_LAT_VALID;
  1844. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1845. trace.channel_lat = lat_inf->channel_lat * ticks;
  1846. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1847. }
  1848. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1849. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1850. trace.inb_usage = fsf_req->qdio_inb_usage;
  1851. trace.outb_usage = fsf_req->qdio_outb_usage;
  1852. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1853. }
  1854. #else
  1855. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1856. {
  1857. }
  1858. #endif
  1859. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1860. {
  1861. struct scsi_cmnd *scpnt;
  1862. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1863. &(req->qtcb->bottom.io.fcp_rsp);
  1864. u32 sns_len;
  1865. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1866. unsigned long flags;
  1867. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1868. scpnt = req->data;
  1869. if (unlikely(!scpnt)) {
  1870. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1871. return;
  1872. }
  1873. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1874. set_host_byte(scpnt, DID_SOFT_ERROR);
  1875. goto skip_fsfstatus;
  1876. }
  1877. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1878. set_host_byte(scpnt, DID_ERROR);
  1879. goto skip_fsfstatus;
  1880. }
  1881. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1882. scpnt->result |= fcp_rsp_iu->scsi_status;
  1883. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1884. zfcp_fsf_req_latency(req);
  1885. zfcp_fsf_trace_latency(req);
  1886. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1887. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1888. set_host_byte(scpnt, DID_OK);
  1889. else {
  1890. set_host_byte(scpnt, DID_ERROR);
  1891. goto skip_fsfstatus;
  1892. }
  1893. }
  1894. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1895. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1896. fcp_rsp_iu->fcp_rsp_len;
  1897. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1898. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1899. memcpy(scpnt->sense_buffer,
  1900. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1901. }
  1902. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1903. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1904. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1905. scpnt->underflow)
  1906. set_host_byte(scpnt, DID_ERROR);
  1907. }
  1908. skip_fsfstatus:
  1909. if (scpnt->result != 0)
  1910. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1911. else if (scpnt->retries > 0)
  1912. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1913. else
  1914. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1915. scpnt->host_scribble = NULL;
  1916. (scpnt->scsi_done) (scpnt);
  1917. /*
  1918. * We must hold this lock until scsi_done has been called.
  1919. * Otherwise we may call scsi_done after abort regarding this
  1920. * command has completed.
  1921. * Note: scsi_done must not block!
  1922. */
  1923. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1924. }
  1925. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1926. {
  1927. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1928. &(req->qtcb->bottom.io.fcp_rsp);
  1929. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1930. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1931. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1932. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1933. }
  1934. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1935. {
  1936. struct zfcp_unit *unit;
  1937. struct fsf_qtcb_header *header = &req->qtcb->header;
  1938. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1939. unit = req->data;
  1940. else
  1941. unit = req->unit;
  1942. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1943. goto skip_fsfstatus;
  1944. switch (header->fsf_status) {
  1945. case FSF_HANDLE_MISMATCH:
  1946. case FSF_PORT_HANDLE_NOT_VALID:
  1947. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1948. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1949. break;
  1950. case FSF_FCPLUN_NOT_VALID:
  1951. case FSF_LUN_HANDLE_NOT_VALID:
  1952. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1953. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1954. break;
  1955. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1956. zfcp_fsf_class_not_supp(req);
  1957. break;
  1958. case FSF_ACCESS_DENIED:
  1959. zfcp_fsf_access_denied_unit(req, unit);
  1960. break;
  1961. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1962. dev_err(&req->adapter->ccw_device->dev,
  1963. "Incorrect direction %d, unit 0x%016Lx on port "
  1964. "0x%016Lx closed\n",
  1965. req->qtcb->bottom.io.data_direction,
  1966. (unsigned long long)unit->fcp_lun,
  1967. (unsigned long long)unit->port->wwpn);
  1968. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1969. req);
  1970. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1971. break;
  1972. case FSF_CMND_LENGTH_NOT_VALID:
  1973. dev_err(&req->adapter->ccw_device->dev,
  1974. "Incorrect CDB length %d, unit 0x%016Lx on "
  1975. "port 0x%016Lx closed\n",
  1976. req->qtcb->bottom.io.fcp_cmnd_length,
  1977. (unsigned long long)unit->fcp_lun,
  1978. (unsigned long long)unit->port->wwpn);
  1979. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1980. req);
  1981. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1982. break;
  1983. case FSF_PORT_BOXED:
  1984. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1985. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1986. ZFCP_STATUS_FSFREQ_RETRY;
  1987. break;
  1988. case FSF_LUN_BOXED:
  1989. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1990. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1991. ZFCP_STATUS_FSFREQ_RETRY;
  1992. break;
  1993. case FSF_ADAPTER_STATUS_AVAILABLE:
  1994. if (header->fsf_status_qual.word[0] ==
  1995. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1996. zfcp_test_link(unit->port);
  1997. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1998. break;
  1999. }
  2000. skip_fsfstatus:
  2001. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2002. zfcp_fsf_send_fcp_ctm_handler(req);
  2003. else {
  2004. zfcp_fsf_send_fcp_command_task_handler(req);
  2005. req->unit = NULL;
  2006. zfcp_unit_put(unit);
  2007. }
  2008. }
  2009. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2010. {
  2011. u32 *fcp_dl_ptr;
  2012. /*
  2013. * fcp_dl_addr = start address of fcp_cmnd structure +
  2014. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2015. * SEE FCP-2 documentation
  2016. */
  2017. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2018. (fcp_cmd->add_fcp_cdb_length << 2));
  2019. *fcp_dl_ptr = fcp_dl;
  2020. }
  2021. /**
  2022. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2023. * @unit: unit where command is sent to
  2024. * @scsi_cmnd: scsi command to be sent
  2025. */
  2026. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  2027. struct scsi_cmnd *scsi_cmnd)
  2028. {
  2029. struct zfcp_fsf_req *req;
  2030. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2031. unsigned int sbtype;
  2032. int real_bytes, retval = -EIO;
  2033. struct zfcp_adapter *adapter = unit->port->adapter;
  2034. if (unlikely(!(atomic_read(&unit->status) &
  2035. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2036. return -EBUSY;
  2037. spin_lock(&adapter->req_q_lock);
  2038. if (atomic_read(&adapter->req_q.count) <= 0) {
  2039. atomic_inc(&adapter->qdio_outb_full);
  2040. goto out;
  2041. }
  2042. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
  2043. ZFCP_REQ_AUTO_CLEANUP,
  2044. adapter->pool.fsf_req_scsi);
  2045. if (IS_ERR(req)) {
  2046. retval = PTR_ERR(req);
  2047. goto out;
  2048. }
  2049. zfcp_unit_get(unit);
  2050. req->unit = unit;
  2051. req->data = scsi_cmnd;
  2052. req->handler = zfcp_fsf_send_fcp_command_handler;
  2053. req->qtcb->header.lun_handle = unit->handle;
  2054. req->qtcb->header.port_handle = unit->port->handle;
  2055. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2056. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2057. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2058. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2059. /*
  2060. * set depending on data direction:
  2061. * data direction bits in SBALE (SB Type)
  2062. * data direction bits in QTCB
  2063. * data direction bits in FCP_CMND IU
  2064. */
  2065. switch (scsi_cmnd->sc_data_direction) {
  2066. case DMA_NONE:
  2067. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2068. sbtype = SBAL_FLAGS0_TYPE_READ;
  2069. break;
  2070. case DMA_FROM_DEVICE:
  2071. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2072. sbtype = SBAL_FLAGS0_TYPE_READ;
  2073. fcp_cmnd_iu->rddata = 1;
  2074. break;
  2075. case DMA_TO_DEVICE:
  2076. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2077. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2078. fcp_cmnd_iu->wddata = 1;
  2079. break;
  2080. case DMA_BIDIRECTIONAL:
  2081. default:
  2082. retval = -EIO;
  2083. goto failed_scsi_cmnd;
  2084. }
  2085. if (likely((scsi_cmnd->device->simple_tags) ||
  2086. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2087. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2088. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2089. else
  2090. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2091. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2092. fcp_cmnd_iu->add_fcp_cdb_length =
  2093. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2094. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2095. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2096. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2097. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2098. scsi_sglist(scsi_cmnd),
  2099. FSF_MAX_SBALS_PER_REQ);
  2100. if (unlikely(real_bytes < 0)) {
  2101. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2102. retval = -EIO;
  2103. else {
  2104. dev_err(&adapter->ccw_device->dev,
  2105. "Oversize data package, unit 0x%016Lx "
  2106. "on port 0x%016Lx closed\n",
  2107. (unsigned long long)unit->fcp_lun,
  2108. (unsigned long long)unit->port->wwpn);
  2109. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  2110. retval = -EINVAL;
  2111. }
  2112. goto failed_scsi_cmnd;
  2113. }
  2114. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2115. retval = zfcp_fsf_req_send(req);
  2116. if (unlikely(retval))
  2117. goto failed_scsi_cmnd;
  2118. goto out;
  2119. failed_scsi_cmnd:
  2120. zfcp_unit_put(unit);
  2121. zfcp_fsf_req_free(req);
  2122. scsi_cmnd->host_scribble = NULL;
  2123. out:
  2124. spin_unlock(&adapter->req_q_lock);
  2125. return retval;
  2126. }
  2127. /**
  2128. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2129. * @unit: pointer to struct zfcp_unit
  2130. * @tm_flags: unsigned byte for task management flags
  2131. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2132. */
  2133. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  2134. {
  2135. struct qdio_buffer_element *sbale;
  2136. struct zfcp_fsf_req *req = NULL;
  2137. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2138. struct zfcp_adapter *adapter = unit->port->adapter;
  2139. if (unlikely(!(atomic_read(&unit->status) &
  2140. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2141. return NULL;
  2142. spin_lock_bh(&adapter->req_q_lock);
  2143. if (zfcp_fsf_req_sbal_get(adapter))
  2144. goto out;
  2145. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
  2146. adapter->pool.fsf_req_scsi);
  2147. if (IS_ERR(req)) {
  2148. req = NULL;
  2149. goto out;
  2150. }
  2151. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2152. req->data = unit;
  2153. req->handler = zfcp_fsf_send_fcp_command_handler;
  2154. req->qtcb->header.lun_handle = unit->handle;
  2155. req->qtcb->header.port_handle = unit->port->handle;
  2156. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2157. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2158. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2159. sizeof(u32);
  2160. sbale = zfcp_qdio_sbale_req(req);
  2161. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2162. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2163. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2164. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2165. fcp_cmnd_iu->task_management_flags = tm_flags;
  2166. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2167. if (!zfcp_fsf_req_send(req))
  2168. goto out;
  2169. zfcp_fsf_req_free(req);
  2170. req = NULL;
  2171. out:
  2172. spin_unlock_bh(&adapter->req_q_lock);
  2173. return req;
  2174. }
  2175. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2176. {
  2177. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2178. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2179. }
  2180. /**
  2181. * zfcp_fsf_control_file - control file upload/download
  2182. * @adapter: pointer to struct zfcp_adapter
  2183. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2184. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2185. */
  2186. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2187. struct zfcp_fsf_cfdc *fsf_cfdc)
  2188. {
  2189. struct qdio_buffer_element *sbale;
  2190. struct zfcp_fsf_req *req = NULL;
  2191. struct fsf_qtcb_bottom_support *bottom;
  2192. int direction, retval = -EIO, bytes;
  2193. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2194. return ERR_PTR(-EOPNOTSUPP);
  2195. switch (fsf_cfdc->command) {
  2196. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2197. direction = SBAL_FLAGS0_TYPE_WRITE;
  2198. break;
  2199. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2200. direction = SBAL_FLAGS0_TYPE_READ;
  2201. break;
  2202. default:
  2203. return ERR_PTR(-EINVAL);
  2204. }
  2205. spin_lock_bh(&adapter->req_q_lock);
  2206. if (zfcp_fsf_req_sbal_get(adapter))
  2207. goto out;
  2208. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2209. if (IS_ERR(req)) {
  2210. retval = -EPERM;
  2211. goto out;
  2212. }
  2213. req->handler = zfcp_fsf_control_file_handler;
  2214. sbale = zfcp_qdio_sbale_req(req);
  2215. sbale[0].flags |= direction;
  2216. bottom = &req->qtcb->bottom.support;
  2217. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2218. bottom->option = fsf_cfdc->option;
  2219. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2220. FSF_MAX_SBALS_PER_REQ);
  2221. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2222. retval = -ENOMEM;
  2223. zfcp_fsf_req_free(req);
  2224. goto out;
  2225. }
  2226. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2227. retval = zfcp_fsf_req_send(req);
  2228. out:
  2229. spin_unlock_bh(&adapter->req_q_lock);
  2230. if (!retval) {
  2231. wait_event(req->completion_wq,
  2232. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2233. return req;
  2234. }
  2235. return ERR_PTR(retval);
  2236. }