zfcp_fsf.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548
  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. fc_host_supported_fc4s(shost)[2] = 1; /* FCP */
  452. fc_host_active_fc4s(shost)[2] = 1; /* FCP */
  453. adapter->hydra_version = bottom->adapter_type;
  454. adapter->timer_ticks = bottom->timer_interval;
  455. if (fc_host_permanent_port_name(shost) == -1)
  456. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  457. switch (bottom->fc_topology) {
  458. case FSF_TOPO_P2P:
  459. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  460. adapter->peer_wwpn = plogi->fl_wwpn;
  461. adapter->peer_wwnn = plogi->fl_wwnn;
  462. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  463. break;
  464. case FSF_TOPO_FABRIC:
  465. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  466. break;
  467. case FSF_TOPO_AL:
  468. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  469. /* fall through */
  470. default:
  471. dev_err(&adapter->ccw_device->dev,
  472. "Unknown or unsupported arbitrated loop "
  473. "fibre channel topology detected\n");
  474. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  475. return -EIO;
  476. }
  477. return 0;
  478. }
  479. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  480. {
  481. struct zfcp_adapter *adapter = req->adapter;
  482. struct fsf_qtcb *qtcb = req->qtcb;
  483. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  484. struct Scsi_Host *shost = adapter->scsi_host;
  485. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  486. return;
  487. adapter->fsf_lic_version = bottom->lic_version;
  488. adapter->adapter_features = bottom->adapter_features;
  489. adapter->connection_features = bottom->connection_features;
  490. adapter->peer_wwpn = 0;
  491. adapter->peer_wwnn = 0;
  492. adapter->peer_d_id = 0;
  493. switch (qtcb->header.fsf_status) {
  494. case FSF_GOOD:
  495. if (zfcp_fsf_exchange_config_evaluate(req))
  496. return;
  497. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  498. dev_err(&adapter->ccw_device->dev,
  499. "FCP adapter maximum QTCB size (%d bytes) "
  500. "is too small\n",
  501. bottom->max_qtcb_size);
  502. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  503. return;
  504. }
  505. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  506. &adapter->status);
  507. break;
  508. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  509. fc_host_node_name(shost) = 0;
  510. fc_host_port_name(shost) = 0;
  511. fc_host_port_id(shost) = 0;
  512. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  513. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  514. adapter->hydra_version = 0;
  515. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  516. &adapter->status);
  517. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  518. &qtcb->header.fsf_status_qual.link_down_info);
  519. break;
  520. default:
  521. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  522. return;
  523. }
  524. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  525. adapter->hardware_version = bottom->hardware_version;
  526. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  527. min(FC_SERIAL_NUMBER_SIZE, 17));
  528. EBCASC(fc_host_serial_number(shost),
  529. min(FC_SERIAL_NUMBER_SIZE, 17));
  530. }
  531. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  532. dev_err(&adapter->ccw_device->dev,
  533. "The FCP adapter only supports newer "
  534. "control block versions\n");
  535. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  536. return;
  537. }
  538. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  539. dev_err(&adapter->ccw_device->dev,
  540. "The FCP adapter only supports older "
  541. "control block versions\n");
  542. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  543. }
  544. }
  545. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  546. {
  547. struct zfcp_adapter *adapter = req->adapter;
  548. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  549. struct Scsi_Host *shost = adapter->scsi_host;
  550. if (req->data)
  551. memcpy(req->data, bottom, sizeof(*bottom));
  552. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  553. fc_host_permanent_port_name(shost) = bottom->wwpn;
  554. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  555. } else
  556. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  557. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  558. fc_host_supported_speeds(shost) = bottom->supported_speed;
  559. }
  560. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  561. {
  562. struct fsf_qtcb *qtcb = req->qtcb;
  563. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  564. return;
  565. switch (qtcb->header.fsf_status) {
  566. case FSF_GOOD:
  567. zfcp_fsf_exchange_port_evaluate(req);
  568. break;
  569. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  570. zfcp_fsf_exchange_port_evaluate(req);
  571. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  572. &qtcb->header.fsf_status_qual.link_down_info);
  573. break;
  574. }
  575. }
  576. static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
  577. {
  578. struct zfcp_qdio_queue *req_q = &qdio->req_q;
  579. spin_lock_bh(&qdio->req_q_lock);
  580. if (atomic_read(&req_q->count))
  581. return 1;
  582. spin_unlock_bh(&qdio->req_q_lock);
  583. return 0;
  584. }
  585. static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
  586. {
  587. struct zfcp_adapter *adapter = qdio->adapter;
  588. long ret;
  589. spin_unlock_bh(&qdio->req_q_lock);
  590. ret = wait_event_interruptible_timeout(qdio->req_q_wq,
  591. zfcp_fsf_sbal_check(qdio), 5 * HZ);
  592. if (ret > 0)
  593. return 0;
  594. if (!ret) {
  595. atomic_inc(&qdio->req_q_full);
  596. /* assume hanging outbound queue, try queue recovery */
  597. zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
  598. }
  599. spin_lock_bh(&qdio->req_q_lock);
  600. return -EIO;
  601. }
  602. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  603. {
  604. struct zfcp_fsf_req *req;
  605. if (likely(pool))
  606. req = mempool_alloc(pool, GFP_ATOMIC);
  607. else
  608. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  609. if (unlikely(!req))
  610. return NULL;
  611. memset(req, 0, sizeof(*req));
  612. req->pool = pool;
  613. return req;
  614. }
  615. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  616. {
  617. struct fsf_qtcb *qtcb;
  618. if (likely(pool))
  619. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  620. else
  621. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  622. if (unlikely(!qtcb))
  623. return NULL;
  624. memset(qtcb, 0, sizeof(*qtcb));
  625. return qtcb;
  626. }
  627. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  628. u32 fsf_cmd, mempool_t *pool)
  629. {
  630. struct qdio_buffer_element *sbale;
  631. struct zfcp_qdio_queue *req_q = &qdio->req_q;
  632. struct zfcp_adapter *adapter = qdio->adapter;
  633. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  634. if (unlikely(!req))
  635. return ERR_PTR(-ENOMEM);
  636. if (adapter->req_no == 0)
  637. adapter->req_no++;
  638. INIT_LIST_HEAD(&req->list);
  639. init_timer(&req->timer);
  640. init_completion(&req->completion);
  641. req->adapter = adapter;
  642. req->fsf_command = fsf_cmd;
  643. req->req_id = adapter->req_no;
  644. req->queue_req.sbal_number = 1;
  645. req->queue_req.sbal_first = req_q->first;
  646. req->queue_req.sbal_last = req_q->first;
  647. req->queue_req.sbale_curr = 1;
  648. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  649. sbale[0].addr = (void *) req->req_id;
  650. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  651. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  652. if (likely(pool))
  653. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  654. else
  655. req->qtcb = zfcp_qtcb_alloc(NULL);
  656. if (unlikely(!req->qtcb)) {
  657. zfcp_fsf_req_free(req);
  658. return ERR_PTR(-ENOMEM);
  659. }
  660. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  661. req->qtcb->prefix.req_id = req->req_id;
  662. req->qtcb->prefix.ulp_info = 26;
  663. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  664. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  665. req->qtcb->header.req_handle = req->req_id;
  666. req->qtcb->header.fsf_command = req->fsf_command;
  667. req->seq_no = adapter->fsf_req_seq_no;
  668. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  669. sbale[1].addr = (void *) req->qtcb;
  670. sbale[1].length = sizeof(struct fsf_qtcb);
  671. }
  672. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  673. zfcp_fsf_req_free(req);
  674. return ERR_PTR(-EIO);
  675. }
  676. return req;
  677. }
  678. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  679. {
  680. struct zfcp_adapter *adapter = req->adapter;
  681. struct zfcp_qdio *qdio = adapter->qdio;
  682. unsigned long flags;
  683. int idx;
  684. int with_qtcb = (req->qtcb != NULL);
  685. /* put allocated FSF request into hash table */
  686. spin_lock_irqsave(&adapter->req_list_lock, flags);
  687. idx = zfcp_reqlist_hash(req->req_id);
  688. list_add_tail(&req->list, &adapter->req_list[idx]);
  689. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  690. req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
  691. req->issued = get_clock();
  692. if (zfcp_qdio_send(qdio, &req->queue_req)) {
  693. del_timer(&req->timer);
  694. spin_lock_irqsave(&adapter->req_list_lock, flags);
  695. /* lookup request again, list might have changed */
  696. if (zfcp_reqlist_find_safe(adapter, req))
  697. zfcp_reqlist_remove(adapter, req);
  698. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  699. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  700. return -EIO;
  701. }
  702. /* Don't increase for unsolicited status */
  703. if (with_qtcb)
  704. adapter->fsf_req_seq_no++;
  705. adapter->req_no++;
  706. return 0;
  707. }
  708. /**
  709. * zfcp_fsf_status_read - send status read request
  710. * @adapter: pointer to struct zfcp_adapter
  711. * @req_flags: request flags
  712. * Returns: 0 on success, ERROR otherwise
  713. */
  714. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  715. {
  716. struct zfcp_adapter *adapter = qdio->adapter;
  717. struct zfcp_fsf_req *req;
  718. struct fsf_status_read_buffer *sr_buf;
  719. struct qdio_buffer_element *sbale;
  720. int retval = -EIO;
  721. spin_lock_bh(&qdio->req_q_lock);
  722. if (zfcp_fsf_req_sbal_get(qdio))
  723. goto out;
  724. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
  725. adapter->pool.status_read_req);
  726. if (IS_ERR(req)) {
  727. retval = PTR_ERR(req);
  728. goto out;
  729. }
  730. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  731. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  732. req->queue_req.sbale_curr = 2;
  733. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  734. if (!sr_buf) {
  735. retval = -ENOMEM;
  736. goto failed_buf;
  737. }
  738. memset(sr_buf, 0, sizeof(*sr_buf));
  739. req->data = sr_buf;
  740. sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
  741. sbale->addr = (void *) sr_buf;
  742. sbale->length = sizeof(*sr_buf);
  743. retval = zfcp_fsf_req_send(req);
  744. if (retval)
  745. goto failed_req_send;
  746. goto out;
  747. failed_req_send:
  748. mempool_free(sr_buf, adapter->pool.status_read_data);
  749. failed_buf:
  750. zfcp_fsf_req_free(req);
  751. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  752. out:
  753. spin_unlock_bh(&qdio->req_q_lock);
  754. return retval;
  755. }
  756. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  757. {
  758. struct zfcp_unit *unit = req->data;
  759. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  760. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  761. return;
  762. switch (req->qtcb->header.fsf_status) {
  763. case FSF_PORT_HANDLE_NOT_VALID:
  764. if (fsq->word[0] == fsq->word[1]) {
  765. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  766. "fsafch1", req);
  767. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  768. }
  769. break;
  770. case FSF_LUN_HANDLE_NOT_VALID:
  771. if (fsq->word[0] == fsq->word[1]) {
  772. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  773. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  774. }
  775. break;
  776. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  777. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  778. break;
  779. case FSF_PORT_BOXED:
  780. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  781. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  782. break;
  783. case FSF_LUN_BOXED:
  784. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  785. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  786. break;
  787. case FSF_ADAPTER_STATUS_AVAILABLE:
  788. switch (fsq->word[0]) {
  789. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  790. zfcp_fc_test_link(unit->port);
  791. /* fall through */
  792. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  793. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  794. break;
  795. }
  796. break;
  797. case FSF_GOOD:
  798. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  799. break;
  800. }
  801. }
  802. /**
  803. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  804. * @old_req_id: unsigned long
  805. * @unit: pointer to struct zfcp_unit
  806. * Returns: pointer to struct zfcp_fsf_req
  807. */
  808. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  809. struct zfcp_unit *unit)
  810. {
  811. struct qdio_buffer_element *sbale;
  812. struct zfcp_fsf_req *req = NULL;
  813. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  814. spin_lock_bh(&qdio->req_q_lock);
  815. if (zfcp_fsf_req_sbal_get(qdio))
  816. goto out;
  817. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  818. qdio->adapter->pool.scsi_abort);
  819. if (IS_ERR(req)) {
  820. req = NULL;
  821. goto out;
  822. }
  823. if (unlikely(!(atomic_read(&unit->status) &
  824. ZFCP_STATUS_COMMON_UNBLOCKED)))
  825. goto out_error_free;
  826. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  827. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  828. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  829. req->data = unit;
  830. req->handler = zfcp_fsf_abort_fcp_command_handler;
  831. req->qtcb->header.lun_handle = unit->handle;
  832. req->qtcb->header.port_handle = unit->port->handle;
  833. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  834. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  835. if (!zfcp_fsf_req_send(req))
  836. goto out;
  837. out_error_free:
  838. zfcp_fsf_req_free(req);
  839. req = NULL;
  840. out:
  841. spin_unlock_bh(&qdio->req_q_lock);
  842. return req;
  843. }
  844. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  845. {
  846. struct zfcp_adapter *adapter = req->adapter;
  847. struct zfcp_fsf_ct_els *ct = req->data;
  848. struct fsf_qtcb_header *header = &req->qtcb->header;
  849. ct->status = -EINVAL;
  850. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  851. goto skip_fsfstatus;
  852. switch (header->fsf_status) {
  853. case FSF_GOOD:
  854. zfcp_dbf_san_ct_response(req);
  855. ct->status = 0;
  856. break;
  857. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  858. zfcp_fsf_class_not_supp(req);
  859. break;
  860. case FSF_ADAPTER_STATUS_AVAILABLE:
  861. switch (header->fsf_status_qual.word[0]){
  862. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  863. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  864. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  865. break;
  866. }
  867. break;
  868. case FSF_ACCESS_DENIED:
  869. break;
  870. case FSF_PORT_BOXED:
  871. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  872. break;
  873. case FSF_PORT_HANDLE_NOT_VALID:
  874. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  875. /* fall through */
  876. case FSF_GENERIC_COMMAND_REJECTED:
  877. case FSF_PAYLOAD_SIZE_MISMATCH:
  878. case FSF_REQUEST_SIZE_TOO_LARGE:
  879. case FSF_RESPONSE_SIZE_TOO_LARGE:
  880. case FSF_SBAL_MISMATCH:
  881. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  882. break;
  883. }
  884. skip_fsfstatus:
  885. if (ct->handler)
  886. ct->handler(ct->handler_data);
  887. }
  888. static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
  889. struct scatterlist *sg_req,
  890. struct scatterlist *sg_resp)
  891. {
  892. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  893. sbale[2].addr = sg_virt(sg_req);
  894. sbale[2].length = sg_req->length;
  895. sbale[3].addr = sg_virt(sg_resp);
  896. sbale[3].length = sg_resp->length;
  897. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  898. }
  899. static int zfcp_fsf_one_sbal(struct scatterlist *sg)
  900. {
  901. return sg_is_last(sg) && sg->length <= PAGE_SIZE;
  902. }
  903. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  904. struct scatterlist *sg_req,
  905. struct scatterlist *sg_resp,
  906. int max_sbals)
  907. {
  908. struct zfcp_adapter *adapter = req->adapter;
  909. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
  910. &req->queue_req);
  911. u32 feat = adapter->adapter_features;
  912. int bytes;
  913. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  914. if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
  915. return -EOPNOTSUPP;
  916. zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
  917. return 0;
  918. }
  919. /* use single, unchained SBAL if it can hold the request */
  920. if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
  921. zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
  922. return 0;
  923. }
  924. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
  925. SBAL_FLAGS0_TYPE_WRITE_READ,
  926. sg_req, max_sbals);
  927. if (bytes <= 0)
  928. return -EIO;
  929. req->qtcb->bottom.support.req_buf_length = bytes;
  930. req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  931. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
  932. SBAL_FLAGS0_TYPE_WRITE_READ,
  933. sg_resp, max_sbals);
  934. req->qtcb->bottom.support.resp_buf_length = bytes;
  935. if (bytes <= 0)
  936. return -EIO;
  937. return 0;
  938. }
  939. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  940. struct scatterlist *sg_req,
  941. struct scatterlist *sg_resp,
  942. int max_sbals, unsigned int timeout)
  943. {
  944. int ret;
  945. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
  946. if (ret)
  947. return ret;
  948. /* common settings for ct/gs and els requests */
  949. if (timeout > 255)
  950. timeout = 255; /* max value accepted by hardware */
  951. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  952. req->qtcb->bottom.support.timeout = timeout;
  953. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  954. return 0;
  955. }
  956. /**
  957. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  958. * @ct: pointer to struct zfcp_send_ct with data for request
  959. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  960. */
  961. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  962. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  963. unsigned int timeout)
  964. {
  965. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  966. struct zfcp_fsf_req *req;
  967. int ret = -EIO;
  968. spin_lock_bh(&qdio->req_q_lock);
  969. if (zfcp_fsf_req_sbal_get(qdio))
  970. goto out;
  971. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
  972. if (IS_ERR(req)) {
  973. ret = PTR_ERR(req);
  974. goto out;
  975. }
  976. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  977. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
  978. FSF_MAX_SBALS_PER_REQ, timeout);
  979. if (ret)
  980. goto failed_send;
  981. req->handler = zfcp_fsf_send_ct_handler;
  982. req->qtcb->header.port_handle = wka_port->handle;
  983. req->data = ct;
  984. zfcp_dbf_san_ct_request(req, wka_port->d_id);
  985. ret = zfcp_fsf_req_send(req);
  986. if (ret)
  987. goto failed_send;
  988. goto out;
  989. failed_send:
  990. zfcp_fsf_req_free(req);
  991. out:
  992. spin_unlock_bh(&qdio->req_q_lock);
  993. return ret;
  994. }
  995. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  996. {
  997. struct zfcp_fsf_ct_els *send_els = req->data;
  998. struct zfcp_port *port = send_els->port;
  999. struct fsf_qtcb_header *header = &req->qtcb->header;
  1000. send_els->status = -EINVAL;
  1001. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1002. goto skip_fsfstatus;
  1003. switch (header->fsf_status) {
  1004. case FSF_GOOD:
  1005. zfcp_dbf_san_els_response(req);
  1006. send_els->status = 0;
  1007. break;
  1008. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1009. zfcp_fsf_class_not_supp(req);
  1010. break;
  1011. case FSF_ADAPTER_STATUS_AVAILABLE:
  1012. switch (header->fsf_status_qual.word[0]){
  1013. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1014. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1015. case FSF_SQ_RETRY_IF_POSSIBLE:
  1016. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1017. break;
  1018. }
  1019. break;
  1020. case FSF_ELS_COMMAND_REJECTED:
  1021. case FSF_PAYLOAD_SIZE_MISMATCH:
  1022. case FSF_REQUEST_SIZE_TOO_LARGE:
  1023. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1024. break;
  1025. case FSF_ACCESS_DENIED:
  1026. if (port)
  1027. zfcp_fsf_access_denied_port(req, port);
  1028. break;
  1029. case FSF_SBAL_MISMATCH:
  1030. /* should never occure, avoided in zfcp_fsf_send_els */
  1031. /* fall through */
  1032. default:
  1033. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1034. break;
  1035. }
  1036. skip_fsfstatus:
  1037. if (send_els->handler)
  1038. send_els->handler(send_els->handler_data);
  1039. }
  1040. /**
  1041. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1042. * @els: pointer to struct zfcp_send_els with data for the command
  1043. */
  1044. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  1045. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  1046. {
  1047. struct zfcp_fsf_req *req;
  1048. struct zfcp_qdio *qdio = adapter->qdio;
  1049. int ret = -EIO;
  1050. spin_lock_bh(&qdio->req_q_lock);
  1051. if (zfcp_fsf_req_sbal_get(qdio))
  1052. goto out;
  1053. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
  1054. if (IS_ERR(req)) {
  1055. ret = PTR_ERR(req);
  1056. goto out;
  1057. }
  1058. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1059. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
  1060. if (ret)
  1061. goto failed_send;
  1062. hton24(req->qtcb->bottom.support.d_id, d_id);
  1063. req->handler = zfcp_fsf_send_els_handler;
  1064. req->data = els;
  1065. zfcp_dbf_san_els_request(req);
  1066. ret = zfcp_fsf_req_send(req);
  1067. if (ret)
  1068. goto failed_send;
  1069. goto out;
  1070. failed_send:
  1071. zfcp_fsf_req_free(req);
  1072. out:
  1073. spin_unlock_bh(&qdio->req_q_lock);
  1074. return ret;
  1075. }
  1076. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1077. {
  1078. struct qdio_buffer_element *sbale;
  1079. struct zfcp_fsf_req *req;
  1080. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1081. int retval = -EIO;
  1082. spin_lock_bh(&qdio->req_q_lock);
  1083. if (zfcp_fsf_req_sbal_get(qdio))
  1084. goto out;
  1085. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1086. qdio->adapter->pool.erp_req);
  1087. if (IS_ERR(req)) {
  1088. retval = PTR_ERR(req);
  1089. goto out;
  1090. }
  1091. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1092. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1093. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1094. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1095. req->qtcb->bottom.config.feature_selection =
  1096. FSF_FEATURE_CFDC |
  1097. FSF_FEATURE_LUN_SHARING |
  1098. FSF_FEATURE_NOTIFICATION_LOST |
  1099. FSF_FEATURE_UPDATE_ALERT;
  1100. req->erp_action = erp_action;
  1101. req->handler = zfcp_fsf_exchange_config_data_handler;
  1102. erp_action->fsf_req = req;
  1103. zfcp_fsf_start_erp_timer(req);
  1104. retval = zfcp_fsf_req_send(req);
  1105. if (retval) {
  1106. zfcp_fsf_req_free(req);
  1107. erp_action->fsf_req = NULL;
  1108. }
  1109. out:
  1110. spin_unlock_bh(&qdio->req_q_lock);
  1111. return retval;
  1112. }
  1113. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1114. struct fsf_qtcb_bottom_config *data)
  1115. {
  1116. struct qdio_buffer_element *sbale;
  1117. struct zfcp_fsf_req *req = NULL;
  1118. int retval = -EIO;
  1119. spin_lock_bh(&qdio->req_q_lock);
  1120. if (zfcp_fsf_req_sbal_get(qdio))
  1121. goto out_unlock;
  1122. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
  1123. if (IS_ERR(req)) {
  1124. retval = PTR_ERR(req);
  1125. goto out_unlock;
  1126. }
  1127. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1128. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1129. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1130. req->handler = zfcp_fsf_exchange_config_data_handler;
  1131. req->qtcb->bottom.config.feature_selection =
  1132. FSF_FEATURE_CFDC |
  1133. FSF_FEATURE_LUN_SHARING |
  1134. FSF_FEATURE_NOTIFICATION_LOST |
  1135. FSF_FEATURE_UPDATE_ALERT;
  1136. if (data)
  1137. req->data = data;
  1138. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1139. retval = zfcp_fsf_req_send(req);
  1140. spin_unlock_bh(&qdio->req_q_lock);
  1141. if (!retval)
  1142. wait_for_completion(&req->completion);
  1143. zfcp_fsf_req_free(req);
  1144. return retval;
  1145. out_unlock:
  1146. spin_unlock_bh(&qdio->req_q_lock);
  1147. return retval;
  1148. }
  1149. /**
  1150. * zfcp_fsf_exchange_port_data - request information about local port
  1151. * @erp_action: ERP action for the adapter for which port data is requested
  1152. * Returns: 0 on success, error otherwise
  1153. */
  1154. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1155. {
  1156. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1157. struct qdio_buffer_element *sbale;
  1158. struct zfcp_fsf_req *req;
  1159. int retval = -EIO;
  1160. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1161. return -EOPNOTSUPP;
  1162. spin_lock_bh(&qdio->req_q_lock);
  1163. if (zfcp_fsf_req_sbal_get(qdio))
  1164. goto out;
  1165. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1166. qdio->adapter->pool.erp_req);
  1167. if (IS_ERR(req)) {
  1168. retval = PTR_ERR(req);
  1169. goto out;
  1170. }
  1171. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1172. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1173. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1174. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1175. req->handler = zfcp_fsf_exchange_port_data_handler;
  1176. req->erp_action = erp_action;
  1177. erp_action->fsf_req = req;
  1178. zfcp_fsf_start_erp_timer(req);
  1179. retval = zfcp_fsf_req_send(req);
  1180. if (retval) {
  1181. zfcp_fsf_req_free(req);
  1182. erp_action->fsf_req = NULL;
  1183. }
  1184. out:
  1185. spin_unlock_bh(&qdio->req_q_lock);
  1186. return retval;
  1187. }
  1188. /**
  1189. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1190. * @qdio: pointer to struct zfcp_qdio
  1191. * @data: pointer to struct fsf_qtcb_bottom_port
  1192. * Returns: 0 on success, error otherwise
  1193. */
  1194. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1195. struct fsf_qtcb_bottom_port *data)
  1196. {
  1197. struct qdio_buffer_element *sbale;
  1198. struct zfcp_fsf_req *req = NULL;
  1199. int retval = -EIO;
  1200. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1201. return -EOPNOTSUPP;
  1202. spin_lock_bh(&qdio->req_q_lock);
  1203. if (zfcp_fsf_req_sbal_get(qdio))
  1204. goto out_unlock;
  1205. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
  1206. if (IS_ERR(req)) {
  1207. retval = PTR_ERR(req);
  1208. goto out_unlock;
  1209. }
  1210. if (data)
  1211. req->data = data;
  1212. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1213. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1214. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1215. req->handler = zfcp_fsf_exchange_port_data_handler;
  1216. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1217. retval = zfcp_fsf_req_send(req);
  1218. spin_unlock_bh(&qdio->req_q_lock);
  1219. if (!retval)
  1220. wait_for_completion(&req->completion);
  1221. zfcp_fsf_req_free(req);
  1222. return retval;
  1223. out_unlock:
  1224. spin_unlock_bh(&qdio->req_q_lock);
  1225. return retval;
  1226. }
  1227. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1228. {
  1229. struct zfcp_port *port = req->data;
  1230. struct fsf_qtcb_header *header = &req->qtcb->header;
  1231. struct fc_els_flogi *plogi;
  1232. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1233. goto out;
  1234. switch (header->fsf_status) {
  1235. case FSF_PORT_ALREADY_OPEN:
  1236. break;
  1237. case FSF_ACCESS_DENIED:
  1238. zfcp_fsf_access_denied_port(req, port);
  1239. break;
  1240. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1241. dev_warn(&req->adapter->ccw_device->dev,
  1242. "Not enough FCP adapter resources to open "
  1243. "remote port 0x%016Lx\n",
  1244. (unsigned long long)port->wwpn);
  1245. zfcp_erp_port_failed(port, "fsoph_1", req);
  1246. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1247. break;
  1248. case FSF_ADAPTER_STATUS_AVAILABLE:
  1249. switch (header->fsf_status_qual.word[0]) {
  1250. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1251. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1252. case FSF_SQ_NO_RETRY_POSSIBLE:
  1253. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1254. break;
  1255. }
  1256. break;
  1257. case FSF_GOOD:
  1258. port->handle = header->port_handle;
  1259. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1260. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1261. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1262. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1263. &port->status);
  1264. /* check whether D_ID has changed during open */
  1265. /*
  1266. * FIXME: This check is not airtight, as the FCP channel does
  1267. * not monitor closures of target port connections caused on
  1268. * the remote side. Thus, they might miss out on invalidating
  1269. * locally cached WWPNs (and other N_Port parameters) of gone
  1270. * target ports. So, our heroic attempt to make things safe
  1271. * could be undermined by 'open port' response data tagged with
  1272. * obsolete WWPNs. Another reason to monitor potential
  1273. * connection closures ourself at least (by interpreting
  1274. * incoming ELS' and unsolicited status). It just crosses my
  1275. * mind that one should be able to cross-check by means of
  1276. * another GID_PN straight after a port has been opened.
  1277. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1278. */
  1279. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1280. if (req->qtcb->bottom.support.els1_length >=
  1281. FSF_PLOGI_MIN_LEN)
  1282. zfcp_fc_plogi_evaluate(port, plogi);
  1283. break;
  1284. case FSF_UNKNOWN_OP_SUBTYPE:
  1285. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1286. break;
  1287. }
  1288. out:
  1289. put_device(&port->sysfs_device);
  1290. }
  1291. /**
  1292. * zfcp_fsf_open_port - create and send open port request
  1293. * @erp_action: pointer to struct zfcp_erp_action
  1294. * Returns: 0 on success, error otherwise
  1295. */
  1296. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1297. {
  1298. struct qdio_buffer_element *sbale;
  1299. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1300. struct zfcp_port *port = erp_action->port;
  1301. struct zfcp_fsf_req *req;
  1302. int retval = -EIO;
  1303. spin_lock_bh(&qdio->req_q_lock);
  1304. if (zfcp_fsf_req_sbal_get(qdio))
  1305. goto out;
  1306. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1307. qdio->adapter->pool.erp_req);
  1308. if (IS_ERR(req)) {
  1309. retval = PTR_ERR(req);
  1310. goto out;
  1311. }
  1312. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1313. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1314. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1315. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1316. req->handler = zfcp_fsf_open_port_handler;
  1317. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1318. req->data = port;
  1319. req->erp_action = erp_action;
  1320. erp_action->fsf_req = req;
  1321. get_device(&port->sysfs_device);
  1322. zfcp_fsf_start_erp_timer(req);
  1323. retval = zfcp_fsf_req_send(req);
  1324. if (retval) {
  1325. zfcp_fsf_req_free(req);
  1326. erp_action->fsf_req = NULL;
  1327. put_device(&port->sysfs_device);
  1328. }
  1329. out:
  1330. spin_unlock_bh(&qdio->req_q_lock);
  1331. return retval;
  1332. }
  1333. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1334. {
  1335. struct zfcp_port *port = req->data;
  1336. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1337. return;
  1338. switch (req->qtcb->header.fsf_status) {
  1339. case FSF_PORT_HANDLE_NOT_VALID:
  1340. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1341. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1342. break;
  1343. case FSF_ADAPTER_STATUS_AVAILABLE:
  1344. break;
  1345. case FSF_GOOD:
  1346. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1347. ZFCP_STATUS_COMMON_OPEN,
  1348. ZFCP_CLEAR);
  1349. break;
  1350. }
  1351. }
  1352. /**
  1353. * zfcp_fsf_close_port - create and send close port request
  1354. * @erp_action: pointer to struct zfcp_erp_action
  1355. * Returns: 0 on success, error otherwise
  1356. */
  1357. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1358. {
  1359. struct qdio_buffer_element *sbale;
  1360. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1361. struct zfcp_fsf_req *req;
  1362. int retval = -EIO;
  1363. spin_lock_bh(&qdio->req_q_lock);
  1364. if (zfcp_fsf_req_sbal_get(qdio))
  1365. goto out;
  1366. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1367. qdio->adapter->pool.erp_req);
  1368. if (IS_ERR(req)) {
  1369. retval = PTR_ERR(req);
  1370. goto out;
  1371. }
  1372. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1373. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1374. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1375. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1376. req->handler = zfcp_fsf_close_port_handler;
  1377. req->data = erp_action->port;
  1378. req->erp_action = erp_action;
  1379. req->qtcb->header.port_handle = erp_action->port->handle;
  1380. erp_action->fsf_req = req;
  1381. zfcp_fsf_start_erp_timer(req);
  1382. retval = zfcp_fsf_req_send(req);
  1383. if (retval) {
  1384. zfcp_fsf_req_free(req);
  1385. erp_action->fsf_req = NULL;
  1386. }
  1387. out:
  1388. spin_unlock_bh(&qdio->req_q_lock);
  1389. return retval;
  1390. }
  1391. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1392. {
  1393. struct zfcp_fc_wka_port *wka_port = req->data;
  1394. struct fsf_qtcb_header *header = &req->qtcb->header;
  1395. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1396. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1397. goto out;
  1398. }
  1399. switch (header->fsf_status) {
  1400. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1401. dev_warn(&req->adapter->ccw_device->dev,
  1402. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1403. /* fall through */
  1404. case FSF_ADAPTER_STATUS_AVAILABLE:
  1405. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1406. /* fall through */
  1407. case FSF_ACCESS_DENIED:
  1408. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1409. break;
  1410. case FSF_GOOD:
  1411. wka_port->handle = header->port_handle;
  1412. /* fall through */
  1413. case FSF_PORT_ALREADY_OPEN:
  1414. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1415. }
  1416. out:
  1417. wake_up(&wka_port->completion_wq);
  1418. }
  1419. /**
  1420. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1421. * @wka_port: pointer to struct zfcp_fc_wka_port
  1422. * Returns: 0 on success, error otherwise
  1423. */
  1424. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1425. {
  1426. struct qdio_buffer_element *sbale;
  1427. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1428. struct zfcp_fsf_req *req;
  1429. int retval = -EIO;
  1430. spin_lock_bh(&qdio->req_q_lock);
  1431. if (zfcp_fsf_req_sbal_get(qdio))
  1432. goto out;
  1433. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1434. qdio->adapter->pool.erp_req);
  1435. if (unlikely(IS_ERR(req))) {
  1436. retval = PTR_ERR(req);
  1437. goto out;
  1438. }
  1439. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1440. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1441. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1442. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1443. req->handler = zfcp_fsf_open_wka_port_handler;
  1444. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1445. req->data = wka_port;
  1446. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1447. retval = zfcp_fsf_req_send(req);
  1448. if (retval)
  1449. zfcp_fsf_req_free(req);
  1450. out:
  1451. spin_unlock_bh(&qdio->req_q_lock);
  1452. return retval;
  1453. }
  1454. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1455. {
  1456. struct zfcp_fc_wka_port *wka_port = req->data;
  1457. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1458. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1459. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1460. }
  1461. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1462. wake_up(&wka_port->completion_wq);
  1463. }
  1464. /**
  1465. * zfcp_fsf_close_wka_port - create and send close wka port request
  1466. * @wka_port: WKA port to open
  1467. * Returns: 0 on success, error otherwise
  1468. */
  1469. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1470. {
  1471. struct qdio_buffer_element *sbale;
  1472. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1473. struct zfcp_fsf_req *req;
  1474. int retval = -EIO;
  1475. spin_lock_bh(&qdio->req_q_lock);
  1476. if (zfcp_fsf_req_sbal_get(qdio))
  1477. goto out;
  1478. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1479. qdio->adapter->pool.erp_req);
  1480. if (unlikely(IS_ERR(req))) {
  1481. retval = PTR_ERR(req);
  1482. goto out;
  1483. }
  1484. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1485. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1486. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1487. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1488. req->handler = zfcp_fsf_close_wka_port_handler;
  1489. req->data = wka_port;
  1490. req->qtcb->header.port_handle = wka_port->handle;
  1491. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1492. retval = zfcp_fsf_req_send(req);
  1493. if (retval)
  1494. zfcp_fsf_req_free(req);
  1495. out:
  1496. spin_unlock_bh(&qdio->req_q_lock);
  1497. return retval;
  1498. }
  1499. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1500. {
  1501. struct zfcp_port *port = req->data;
  1502. struct fsf_qtcb_header *header = &req->qtcb->header;
  1503. struct zfcp_unit *unit;
  1504. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1505. return;
  1506. switch (header->fsf_status) {
  1507. case FSF_PORT_HANDLE_NOT_VALID:
  1508. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1509. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1510. break;
  1511. case FSF_ACCESS_DENIED:
  1512. zfcp_fsf_access_denied_port(req, port);
  1513. break;
  1514. case FSF_PORT_BOXED:
  1515. /* can't use generic zfcp_erp_modify_port_status because
  1516. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1517. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1518. read_lock(&port->unit_list_lock);
  1519. list_for_each_entry(unit, &port->unit_list, list)
  1520. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1521. &unit->status);
  1522. read_unlock(&port->unit_list_lock);
  1523. zfcp_erp_port_boxed(port, "fscpph2", req);
  1524. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1525. break;
  1526. case FSF_ADAPTER_STATUS_AVAILABLE:
  1527. switch (header->fsf_status_qual.word[0]) {
  1528. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1529. /* fall through */
  1530. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1531. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1532. break;
  1533. }
  1534. break;
  1535. case FSF_GOOD:
  1536. /* can't use generic zfcp_erp_modify_port_status because
  1537. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1538. */
  1539. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1540. read_lock(&port->unit_list_lock);
  1541. list_for_each_entry(unit, &port->unit_list, list)
  1542. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1543. &unit->status);
  1544. read_unlock(&port->unit_list_lock);
  1545. break;
  1546. }
  1547. }
  1548. /**
  1549. * zfcp_fsf_close_physical_port - close physical port
  1550. * @erp_action: pointer to struct zfcp_erp_action
  1551. * Returns: 0 on success
  1552. */
  1553. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1554. {
  1555. struct qdio_buffer_element *sbale;
  1556. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1557. struct zfcp_fsf_req *req;
  1558. int retval = -EIO;
  1559. spin_lock_bh(&qdio->req_q_lock);
  1560. if (zfcp_fsf_req_sbal_get(qdio))
  1561. goto out;
  1562. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1563. qdio->adapter->pool.erp_req);
  1564. if (IS_ERR(req)) {
  1565. retval = PTR_ERR(req);
  1566. goto out;
  1567. }
  1568. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1569. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1570. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1571. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1572. req->data = erp_action->port;
  1573. req->qtcb->header.port_handle = erp_action->port->handle;
  1574. req->erp_action = erp_action;
  1575. req->handler = zfcp_fsf_close_physical_port_handler;
  1576. erp_action->fsf_req = req;
  1577. zfcp_fsf_start_erp_timer(req);
  1578. retval = zfcp_fsf_req_send(req);
  1579. if (retval) {
  1580. zfcp_fsf_req_free(req);
  1581. erp_action->fsf_req = NULL;
  1582. }
  1583. out:
  1584. spin_unlock_bh(&qdio->req_q_lock);
  1585. return retval;
  1586. }
  1587. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1588. {
  1589. struct zfcp_adapter *adapter = req->adapter;
  1590. struct zfcp_unit *unit = req->data;
  1591. struct fsf_qtcb_header *header = &req->qtcb->header;
  1592. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1593. struct fsf_queue_designator *queue_designator =
  1594. &header->fsf_status_qual.fsf_queue_designator;
  1595. int exclusive, readwrite;
  1596. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1597. return;
  1598. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1599. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1600. ZFCP_STATUS_UNIT_SHARED |
  1601. ZFCP_STATUS_UNIT_READONLY,
  1602. &unit->status);
  1603. switch (header->fsf_status) {
  1604. case FSF_PORT_HANDLE_NOT_VALID:
  1605. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1606. /* fall through */
  1607. case FSF_LUN_ALREADY_OPEN:
  1608. break;
  1609. case FSF_ACCESS_DENIED:
  1610. zfcp_fsf_access_denied_unit(req, unit);
  1611. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1612. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1613. break;
  1614. case FSF_PORT_BOXED:
  1615. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1616. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1617. break;
  1618. case FSF_LUN_SHARING_VIOLATION:
  1619. if (header->fsf_status_qual.word[0])
  1620. dev_warn(&adapter->ccw_device->dev,
  1621. "LUN 0x%Lx on port 0x%Lx is already in "
  1622. "use by CSS%d, MIF Image ID %x\n",
  1623. (unsigned long long)unit->fcp_lun,
  1624. (unsigned long long)unit->port->wwpn,
  1625. queue_designator->cssid,
  1626. queue_designator->hla);
  1627. else
  1628. zfcp_act_eval_err(adapter,
  1629. header->fsf_status_qual.word[2]);
  1630. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1631. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1632. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1633. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1634. break;
  1635. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1636. dev_warn(&adapter->ccw_device->dev,
  1637. "No handle is available for LUN "
  1638. "0x%016Lx on port 0x%016Lx\n",
  1639. (unsigned long long)unit->fcp_lun,
  1640. (unsigned long long)unit->port->wwpn);
  1641. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1642. /* fall through */
  1643. case FSF_INVALID_COMMAND_OPTION:
  1644. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1645. break;
  1646. case FSF_ADAPTER_STATUS_AVAILABLE:
  1647. switch (header->fsf_status_qual.word[0]) {
  1648. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1649. zfcp_fc_test_link(unit->port);
  1650. /* fall through */
  1651. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1652. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1653. break;
  1654. }
  1655. break;
  1656. case FSF_GOOD:
  1657. unit->handle = header->lun_handle;
  1658. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1659. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1660. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1661. !zfcp_ccw_priv_sch(adapter)) {
  1662. exclusive = (bottom->lun_access_info &
  1663. FSF_UNIT_ACCESS_EXCLUSIVE);
  1664. readwrite = (bottom->lun_access_info &
  1665. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1666. if (!exclusive)
  1667. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1668. &unit->status);
  1669. if (!readwrite) {
  1670. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1671. &unit->status);
  1672. dev_info(&adapter->ccw_device->dev,
  1673. "SCSI device at LUN 0x%016Lx on port "
  1674. "0x%016Lx opened read-only\n",
  1675. (unsigned long long)unit->fcp_lun,
  1676. (unsigned long long)unit->port->wwpn);
  1677. }
  1678. if (exclusive && !readwrite) {
  1679. dev_err(&adapter->ccw_device->dev,
  1680. "Exclusive read-only access not "
  1681. "supported (unit 0x%016Lx, "
  1682. "port 0x%016Lx)\n",
  1683. (unsigned long long)unit->fcp_lun,
  1684. (unsigned long long)unit->port->wwpn);
  1685. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1686. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1687. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1688. } else if (!exclusive && readwrite) {
  1689. dev_err(&adapter->ccw_device->dev,
  1690. "Shared read-write access not "
  1691. "supported (unit 0x%016Lx, port "
  1692. "0x%016Lx)\n",
  1693. (unsigned long long)unit->fcp_lun,
  1694. (unsigned long long)unit->port->wwpn);
  1695. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1696. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1697. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1698. }
  1699. }
  1700. break;
  1701. }
  1702. }
  1703. /**
  1704. * zfcp_fsf_open_unit - open unit
  1705. * @erp_action: pointer to struct zfcp_erp_action
  1706. * Returns: 0 on success, error otherwise
  1707. */
  1708. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1709. {
  1710. struct qdio_buffer_element *sbale;
  1711. struct zfcp_adapter *adapter = erp_action->adapter;
  1712. struct zfcp_qdio *qdio = adapter->qdio;
  1713. struct zfcp_fsf_req *req;
  1714. int retval = -EIO;
  1715. spin_lock_bh(&qdio->req_q_lock);
  1716. if (zfcp_fsf_req_sbal_get(qdio))
  1717. goto out;
  1718. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1719. adapter->pool.erp_req);
  1720. if (IS_ERR(req)) {
  1721. retval = PTR_ERR(req);
  1722. goto out;
  1723. }
  1724. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1725. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1726. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1727. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1728. req->qtcb->header.port_handle = erp_action->port->handle;
  1729. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1730. req->handler = zfcp_fsf_open_unit_handler;
  1731. req->data = erp_action->unit;
  1732. req->erp_action = erp_action;
  1733. erp_action->fsf_req = req;
  1734. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1735. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1736. zfcp_fsf_start_erp_timer(req);
  1737. retval = zfcp_fsf_req_send(req);
  1738. if (retval) {
  1739. zfcp_fsf_req_free(req);
  1740. erp_action->fsf_req = NULL;
  1741. }
  1742. out:
  1743. spin_unlock_bh(&qdio->req_q_lock);
  1744. return retval;
  1745. }
  1746. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1747. {
  1748. struct zfcp_unit *unit = req->data;
  1749. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1750. return;
  1751. switch (req->qtcb->header.fsf_status) {
  1752. case FSF_PORT_HANDLE_NOT_VALID:
  1753. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1754. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1755. break;
  1756. case FSF_LUN_HANDLE_NOT_VALID:
  1757. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1758. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1759. break;
  1760. case FSF_PORT_BOXED:
  1761. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1762. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1763. break;
  1764. case FSF_ADAPTER_STATUS_AVAILABLE:
  1765. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1766. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1767. zfcp_fc_test_link(unit->port);
  1768. /* fall through */
  1769. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1771. break;
  1772. }
  1773. break;
  1774. case FSF_GOOD:
  1775. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1776. break;
  1777. }
  1778. }
  1779. /**
  1780. * zfcp_fsf_close_unit - close zfcp unit
  1781. * @erp_action: pointer to struct zfcp_unit
  1782. * Returns: 0 on success, error otherwise
  1783. */
  1784. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1785. {
  1786. struct qdio_buffer_element *sbale;
  1787. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1788. struct zfcp_fsf_req *req;
  1789. int retval = -EIO;
  1790. spin_lock_bh(&qdio->req_q_lock);
  1791. if (zfcp_fsf_req_sbal_get(qdio))
  1792. goto out;
  1793. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1794. qdio->adapter->pool.erp_req);
  1795. if (IS_ERR(req)) {
  1796. retval = PTR_ERR(req);
  1797. goto out;
  1798. }
  1799. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1800. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1801. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1802. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1803. req->qtcb->header.port_handle = erp_action->port->handle;
  1804. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1805. req->handler = zfcp_fsf_close_unit_handler;
  1806. req->data = erp_action->unit;
  1807. req->erp_action = erp_action;
  1808. erp_action->fsf_req = req;
  1809. zfcp_fsf_start_erp_timer(req);
  1810. retval = zfcp_fsf_req_send(req);
  1811. if (retval) {
  1812. zfcp_fsf_req_free(req);
  1813. erp_action->fsf_req = NULL;
  1814. }
  1815. out:
  1816. spin_unlock_bh(&qdio->req_q_lock);
  1817. return retval;
  1818. }
  1819. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1820. {
  1821. lat_rec->sum += lat;
  1822. lat_rec->min = min(lat_rec->min, lat);
  1823. lat_rec->max = max(lat_rec->max, lat);
  1824. }
  1825. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1826. {
  1827. struct fsf_qual_latency_info *lat_in;
  1828. struct latency_cont *lat = NULL;
  1829. struct zfcp_unit *unit = req->unit;
  1830. struct zfcp_blk_drv_data blktrc;
  1831. int ticks = req->adapter->timer_ticks;
  1832. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1833. blktrc.flags = 0;
  1834. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1835. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1836. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1837. blktrc.inb_usage = req->queue_req.qdio_inb_usage;
  1838. blktrc.outb_usage = req->queue_req.qdio_outb_usage;
  1839. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1840. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1841. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1842. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1843. switch (req->qtcb->bottom.io.data_direction) {
  1844. case FSF_DATADIR_READ:
  1845. lat = &unit->latencies.read;
  1846. break;
  1847. case FSF_DATADIR_WRITE:
  1848. lat = &unit->latencies.write;
  1849. break;
  1850. case FSF_DATADIR_CMND:
  1851. lat = &unit->latencies.cmd;
  1852. break;
  1853. }
  1854. if (lat) {
  1855. spin_lock(&unit->latencies.lock);
  1856. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1857. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1858. lat->counter++;
  1859. spin_unlock(&unit->latencies.lock);
  1860. }
  1861. }
  1862. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1863. sizeof(blktrc));
  1864. }
  1865. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1866. {
  1867. struct scsi_cmnd *scpnt;
  1868. struct fcp_resp_with_ext *fcp_rsp;
  1869. unsigned long flags;
  1870. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1871. scpnt = req->data;
  1872. if (unlikely(!scpnt)) {
  1873. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1874. return;
  1875. }
  1876. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1877. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1878. goto skip_fsfstatus;
  1879. }
  1880. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1881. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1882. zfcp_fsf_req_trace(req, scpnt);
  1883. skip_fsfstatus:
  1884. if (scpnt->result != 0)
  1885. zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
  1886. else if (scpnt->retries > 0)
  1887. zfcp_dbf_scsi_result("retr", 4, req->adapter->dbf, scpnt, req);
  1888. else
  1889. zfcp_dbf_scsi_result("norm", 6, req->adapter->dbf, scpnt, req);
  1890. scpnt->host_scribble = NULL;
  1891. (scpnt->scsi_done) (scpnt);
  1892. /*
  1893. * We must hold this lock until scsi_done has been called.
  1894. * Otherwise we may call scsi_done after abort regarding this
  1895. * command has completed.
  1896. * Note: scsi_done must not block!
  1897. */
  1898. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1899. }
  1900. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1901. {
  1902. struct fcp_resp_with_ext *fcp_rsp;
  1903. struct fcp_resp_rsp_info *rsp_info;
  1904. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1905. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1906. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1907. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1908. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1909. }
  1910. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1911. {
  1912. struct zfcp_unit *unit;
  1913. struct fsf_qtcb_header *header = &req->qtcb->header;
  1914. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1915. unit = req->data;
  1916. else
  1917. unit = req->unit;
  1918. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1919. goto skip_fsfstatus;
  1920. switch (header->fsf_status) {
  1921. case FSF_HANDLE_MISMATCH:
  1922. case FSF_PORT_HANDLE_NOT_VALID:
  1923. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1924. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1925. break;
  1926. case FSF_FCPLUN_NOT_VALID:
  1927. case FSF_LUN_HANDLE_NOT_VALID:
  1928. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1929. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1930. break;
  1931. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1932. zfcp_fsf_class_not_supp(req);
  1933. break;
  1934. case FSF_ACCESS_DENIED:
  1935. zfcp_fsf_access_denied_unit(req, unit);
  1936. break;
  1937. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1938. dev_err(&req->adapter->ccw_device->dev,
  1939. "Incorrect direction %d, unit 0x%016Lx on port "
  1940. "0x%016Lx closed\n",
  1941. req->qtcb->bottom.io.data_direction,
  1942. (unsigned long long)unit->fcp_lun,
  1943. (unsigned long long)unit->port->wwpn);
  1944. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1945. req);
  1946. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1947. break;
  1948. case FSF_CMND_LENGTH_NOT_VALID:
  1949. dev_err(&req->adapter->ccw_device->dev,
  1950. "Incorrect CDB length %d, unit 0x%016Lx on "
  1951. "port 0x%016Lx closed\n",
  1952. req->qtcb->bottom.io.fcp_cmnd_length,
  1953. (unsigned long long)unit->fcp_lun,
  1954. (unsigned long long)unit->port->wwpn);
  1955. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1956. req);
  1957. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1958. break;
  1959. case FSF_PORT_BOXED:
  1960. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1961. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1962. break;
  1963. case FSF_LUN_BOXED:
  1964. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1965. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1966. break;
  1967. case FSF_ADAPTER_STATUS_AVAILABLE:
  1968. if (header->fsf_status_qual.word[0] ==
  1969. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1970. zfcp_fc_test_link(unit->port);
  1971. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1972. break;
  1973. }
  1974. skip_fsfstatus:
  1975. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1976. zfcp_fsf_send_fcp_ctm_handler(req);
  1977. else {
  1978. zfcp_fsf_send_fcp_command_task_handler(req);
  1979. req->unit = NULL;
  1980. put_device(&unit->sysfs_device);
  1981. }
  1982. }
  1983. /**
  1984. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1985. * @unit: unit where command is sent to
  1986. * @scsi_cmnd: scsi command to be sent
  1987. */
  1988. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  1989. struct scsi_cmnd *scsi_cmnd)
  1990. {
  1991. struct zfcp_fsf_req *req;
  1992. struct fcp_cmnd *fcp_cmnd;
  1993. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  1994. int real_bytes, retval = -EIO;
  1995. struct zfcp_adapter *adapter = unit->port->adapter;
  1996. struct zfcp_qdio *qdio = adapter->qdio;
  1997. if (unlikely(!(atomic_read(&unit->status) &
  1998. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1999. return -EBUSY;
  2000. spin_lock(&qdio->req_q_lock);
  2001. if (atomic_read(&qdio->req_q.count) <= 0) {
  2002. atomic_inc(&qdio->req_q_full);
  2003. goto out;
  2004. }
  2005. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2006. adapter->pool.scsi_req);
  2007. if (IS_ERR(req)) {
  2008. retval = PTR_ERR(req);
  2009. goto out;
  2010. }
  2011. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  2012. get_device(&unit->sysfs_device);
  2013. req->unit = unit;
  2014. req->data = scsi_cmnd;
  2015. req->handler = zfcp_fsf_send_fcp_command_handler;
  2016. req->qtcb->header.lun_handle = unit->handle;
  2017. req->qtcb->header.port_handle = unit->port->handle;
  2018. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2019. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2020. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2021. /*
  2022. * set depending on data direction:
  2023. * data direction bits in SBALE (SB Type)
  2024. * data direction bits in QTCB
  2025. */
  2026. switch (scsi_cmnd->sc_data_direction) {
  2027. case DMA_NONE:
  2028. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2029. break;
  2030. case DMA_FROM_DEVICE:
  2031. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2032. break;
  2033. case DMA_TO_DEVICE:
  2034. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2035. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2036. break;
  2037. case DMA_BIDIRECTIONAL:
  2038. goto failed_scsi_cmnd;
  2039. }
  2040. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2041. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
  2042. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
  2043. scsi_sglist(scsi_cmnd),
  2044. FSF_MAX_SBALS_PER_REQ);
  2045. if (unlikely(real_bytes < 0)) {
  2046. if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
  2047. dev_err(&adapter->ccw_device->dev,
  2048. "Oversize data package, unit 0x%016Lx "
  2049. "on port 0x%016Lx closed\n",
  2050. (unsigned long long)unit->fcp_lun,
  2051. (unsigned long long)unit->port->wwpn);
  2052. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  2053. retval = -EINVAL;
  2054. }
  2055. goto failed_scsi_cmnd;
  2056. }
  2057. retval = zfcp_fsf_req_send(req);
  2058. if (unlikely(retval))
  2059. goto failed_scsi_cmnd;
  2060. goto out;
  2061. failed_scsi_cmnd:
  2062. put_device(&unit->sysfs_device);
  2063. zfcp_fsf_req_free(req);
  2064. scsi_cmnd->host_scribble = NULL;
  2065. out:
  2066. spin_unlock(&qdio->req_q_lock);
  2067. return retval;
  2068. }
  2069. /**
  2070. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2071. * @unit: pointer to struct zfcp_unit
  2072. * @tm_flags: unsigned byte for task management flags
  2073. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2074. */
  2075. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  2076. {
  2077. struct qdio_buffer_element *sbale;
  2078. struct zfcp_fsf_req *req = NULL;
  2079. struct fcp_cmnd *fcp_cmnd;
  2080. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  2081. if (unlikely(!(atomic_read(&unit->status) &
  2082. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2083. return NULL;
  2084. spin_lock_bh(&qdio->req_q_lock);
  2085. if (zfcp_fsf_req_sbal_get(qdio))
  2086. goto out;
  2087. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2088. qdio->adapter->pool.scsi_req);
  2089. if (IS_ERR(req)) {
  2090. req = NULL;
  2091. goto out;
  2092. }
  2093. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2094. req->data = unit;
  2095. req->handler = zfcp_fsf_send_fcp_command_handler;
  2096. req->qtcb->header.lun_handle = unit->handle;
  2097. req->qtcb->header.port_handle = unit->port->handle;
  2098. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2099. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2100. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2101. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  2102. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2103. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2104. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2105. zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
  2106. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2107. if (!zfcp_fsf_req_send(req))
  2108. goto out;
  2109. zfcp_fsf_req_free(req);
  2110. req = NULL;
  2111. out:
  2112. spin_unlock_bh(&qdio->req_q_lock);
  2113. return req;
  2114. }
  2115. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2116. {
  2117. }
  2118. /**
  2119. * zfcp_fsf_control_file - control file upload/download
  2120. * @adapter: pointer to struct zfcp_adapter
  2121. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2122. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2123. */
  2124. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2125. struct zfcp_fsf_cfdc *fsf_cfdc)
  2126. {
  2127. struct qdio_buffer_element *sbale;
  2128. struct zfcp_qdio *qdio = adapter->qdio;
  2129. struct zfcp_fsf_req *req = NULL;
  2130. struct fsf_qtcb_bottom_support *bottom;
  2131. int direction, retval = -EIO, bytes;
  2132. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2133. return ERR_PTR(-EOPNOTSUPP);
  2134. switch (fsf_cfdc->command) {
  2135. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2136. direction = SBAL_FLAGS0_TYPE_WRITE;
  2137. break;
  2138. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2139. direction = SBAL_FLAGS0_TYPE_READ;
  2140. break;
  2141. default:
  2142. return ERR_PTR(-EINVAL);
  2143. }
  2144. spin_lock_bh(&qdio->req_q_lock);
  2145. if (zfcp_fsf_req_sbal_get(qdio))
  2146. goto out;
  2147. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
  2148. if (IS_ERR(req)) {
  2149. retval = -EPERM;
  2150. goto out;
  2151. }
  2152. req->handler = zfcp_fsf_control_file_handler;
  2153. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  2154. sbale[0].flags |= direction;
  2155. bottom = &req->qtcb->bottom.support;
  2156. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2157. bottom->option = fsf_cfdc->option;
  2158. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
  2159. direction, fsf_cfdc->sg,
  2160. FSF_MAX_SBALS_PER_REQ);
  2161. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2162. zfcp_fsf_req_free(req);
  2163. goto out;
  2164. }
  2165. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2166. retval = zfcp_fsf_req_send(req);
  2167. out:
  2168. spin_unlock_bh(&qdio->req_q_lock);
  2169. if (!retval) {
  2170. wait_for_completion(&req->completion);
  2171. return req;
  2172. }
  2173. return ERR_PTR(retval);
  2174. }
  2175. /**
  2176. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2177. * @adapter: pointer to struct zfcp_adapter
  2178. * @sbal_idx: response queue index of SBAL to be processed
  2179. */
  2180. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2181. {
  2182. struct zfcp_adapter *adapter = qdio->adapter;
  2183. struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
  2184. struct qdio_buffer_element *sbale;
  2185. struct zfcp_fsf_req *fsf_req;
  2186. unsigned long flags, req_id;
  2187. int idx;
  2188. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2189. sbale = &sbal->element[idx];
  2190. req_id = (unsigned long) sbale->addr;
  2191. spin_lock_irqsave(&adapter->req_list_lock, flags);
  2192. fsf_req = zfcp_reqlist_find(adapter, req_id);
  2193. if (!fsf_req)
  2194. /*
  2195. * Unknown request means that we have potentially memory
  2196. * corruption and must stop the machine immediately.
  2197. */
  2198. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2199. req_id, dev_name(&adapter->ccw_device->dev));
  2200. list_del(&fsf_req->list);
  2201. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  2202. fsf_req->queue_req.sbal_response = sbal_idx;
  2203. fsf_req->queue_req.qdio_inb_usage =
  2204. atomic_read(&qdio->resp_q.count);
  2205. zfcp_fsf_req_complete(fsf_req);
  2206. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2207. break;
  2208. }
  2209. }