zfcp_fsf.c 72 KB

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