zfcp_fsf.c 74 KB

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