zfcp_fsf.c 71 KB

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