zfcp_fsf.c 69 KB

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