zfcp_fsf.c 74 KB

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